From c5c528fc7fc25fc4381db46bcb51dd408ce7cf89 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 3 Nov 2001 17:06:29 +0000 Subject: [PATCH] implemented Freeze/Thaw() for the generic listctrl git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12287 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/generic/listctrl.h | 24 ++++++++++++--------- samples/listctrl/listtest.cpp | 21 +++++++++++++++++- samples/listctrl/listtest.h | 4 ++++ src/generic/listctrl.cpp | 40 +++++++++++++++++++++++++++++++++-- 4 files changed, 76 insertions(+), 13 deletions(-) diff --git a/include/wx/generic/listctrl.h b/include/wx/generic/listctrl.h index 6d72b00492..5b3ab33687 100644 --- a/include/wx/generic/listctrl.h +++ b/include/wx/generic/listctrl.h @@ -158,20 +158,24 @@ public: // We have to hand down a few functions - bool SetBackgroundColour( const wxColour &colour ); - bool SetForegroundColour( const wxColour &colour ); - bool SetFont( const wxFont &font ); + virtual void Freeze(); + virtual void Thaw(); + + virtual bool SetBackgroundColour( const wxColour &colour ); + virtual bool SetForegroundColour( const wxColour &colour ); + virtual wxColour GetBackgroundColour() const; + virtual wxColour GetForegroundColour() const; + virtual bool SetFont( const wxFont &font ); + virtual bool SetCursor( const wxCursor &cursor ); #if wxUSE_DRAG_AND_DROP - void SetDropTarget( wxDropTarget *dropTarget ); - wxDropTarget *GetDropTarget() const; + virtual void SetDropTarget( wxDropTarget *dropTarget ); + virtual wxDropTarget *GetDropTarget() const; #endif - bool SetCursor( const wxCursor &cursor ); - wxColour GetBackgroundColour() const; - wxColour GetForegroundColour() const; - bool DoPopupMenu( wxMenu *menu, int x, int y ); - void SetFocus(); + virtual bool DoPopupMenu( wxMenu *menu, int x, int y ); + + virtual void SetFocus(); // implementation // -------------- diff --git a/samples/listctrl/listtest.cpp b/samples/listctrl/listtest.cpp index bcf0dddac5..9796a033b7 100644 --- a/samples/listctrl/listtest.cpp +++ b/samples/listctrl/listtest.cpp @@ -73,6 +73,8 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(LIST_TOGGLE_MULTI_SEL, MyFrame::OnToggleMultiSel) EVT_MENU(LIST_SHOW_COL_INFO, MyFrame::OnShowColInfo) EVT_MENU(LIST_SHOW_SEL_INFO, MyFrame::OnShowSelInfo) + EVT_MENU(LIST_FREEZE, MyFrame::OnFreeze) + EVT_MENU(LIST_THAW, MyFrame::OnThaw) EVT_UPDATE_UI(LIST_SHOW_COL_INFO, MyFrame::OnUpdateShowColInfo) END_EVENT_TABLE() @@ -188,7 +190,7 @@ MyFrame::MyFrame(const wxChar *title, int x, int y, int w, int h) wxMenu *menuList = new wxMenu; menuList->Append(LIST_FOCUS_LAST, _T("&Make last item current\tCtrl-L")); - menuList->Append(LIST_TOGGLE_FIRST, _T("&Toggle first item\tCtrl-T")); + menuList->Append(LIST_TOGGLE_FIRST, _T("To&ggle first item\tCtrl-G")); menuList->Append(LIST_DESELECT_ALL, _T("&Deselect All\tCtrl-D")); menuList->Append(LIST_SELECT_ALL, _T("S&elect All\tCtrl-A")); menuList->AppendSeparator(); @@ -201,6 +203,9 @@ MyFrame::MyFrame(const wxChar *title, int x, int y, int w, int h) menuList->Append(LIST_DELETE, _T("&Delete first item\tCtrl-X")); menuList->Append(LIST_DELETE_ALL, _T("Delete &all items")); menuList->AppendSeparator(); + menuList->Append(LIST_FREEZE, _T("Free&ze\tCtrl-Z")); + menuList->Append(LIST_THAW, _T("Tha&w\tCtrl-W")); + menuList->AppendSeparator(); menuList->Append(LIST_TOGGLE_MULTI_SEL, _T("&Multiple selection\tCtrl-M"), _T("Toggle multiple selection"), TRUE); @@ -260,6 +265,20 @@ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) dialog.ShowModal(); } +void MyFrame::OnFreeze(wxCommandEvent& event) +{ + wxLogMessage(_T("Freezing the control")); + + m_listCtrl->Freeze(); +} + +void MyFrame::OnThaw(wxCommandEvent& event) +{ + wxLogMessage(_T("Thawing the control")); + + m_listCtrl->Thaw(); +} + void MyFrame::OnFocusLast(wxCommandEvent& WXUNUSED(event)) { long index = m_listCtrl->GetItemCount() - 1; diff --git a/samples/listctrl/listtest.h b/samples/listctrl/listtest.h index b3464b74db..803fd1396e 100644 --- a/samples/listctrl/listtest.h +++ b/samples/listctrl/listtest.h @@ -103,6 +103,8 @@ public: void OnToggleMultiSel(wxCommandEvent& event); void OnShowColInfo(wxCommandEvent& event); void OnShowSelInfo(wxCommandEvent& event); + void OnFreeze(wxCommandEvent& event); + void OnThaw(wxCommandEvent& event); void OnUpdateShowColInfo(wxUpdateUIEvent& event); @@ -152,6 +154,8 @@ enum LIST_SHOW_COL_INFO, LIST_SHOW_SEL_INFO, LIST_FOCUS_LAST, + LIST_FREEZE, + LIST_THAW, LIST_CTRL = 1000 }; diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index b4c6644be4..16ec1bbabc 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -611,7 +611,13 @@ public: // bring the current item into view void MoveToFocus() { MoveToItem(m_current); } + // start editing the label of the given item void EditLabel( long item ); + + // suspend/resume redrawing the control + void Freeze(); + void Thaw(); + void OnRenameTimer(); void OnRenameAccept(); @@ -843,6 +849,9 @@ private: wxBrush *m_highlightBrush, *m_highlightUnfocusedBrush; + // if this is > 0, the control is frozen and doesn't redraw itself + size_t m_freezeCount; + DECLARE_DYNAMIC_CLASS(wxListMainWindow); DECLARE_EVENT_TABLE() }; @@ -2227,6 +2236,8 @@ void wxListMainWindow::Init() m_currentEdit = m_lineLastClicked = m_lineBeforeLastClicked = (size_t)-1; + + m_freezeCount = 0; } void wxListMainWindow::InitScrolling() @@ -2662,15 +2673,30 @@ void wxListMainWindow::RefreshSelected() #endif // !__WXGTK__/__WXGTK__ } +void wxListMainWindow::Freeze() +{ + m_freezeCount++; +} + +void wxListMainWindow::Thaw() +{ + wxCHECK_RET( m_freezeCount > 0, _T("thawing unfrozen list control?") ); + + if ( !--m_freezeCount ) + { + Refresh(); + } +} + void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) { // Note: a wxPaintDC must be constructed even if no drawing is // done (a Windows requirement). wxPaintDC dc( this ); - if ( IsEmpty() ) + if ( IsEmpty() || m_freezeCount ) { - // empty control. nothing to draw + // nothing to draw or not the moment to draw it return; } @@ -5210,4 +5236,14 @@ void wxListCtrl::RefreshItems(long itemFrom, long itemTo) m_mainWin->RefreshLines(itemFrom, itemTo); } +void wxListCtrl::Freeze() +{ + m_mainWin->Freeze(); +} + +void wxListCtrl::Thaw() +{ + m_mainWin->Thaw(); +} + #endif // wxUSE_LISTCTRL -- 2.45.2