From: Vadim Zeitlin Date: Sat, 19 Feb 2005 17:07:17 +0000 (+0000) Subject: wxGenericListCtrl::SetItemState(-1) now changes the state of all items (patch 1101650) X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/0afa5859ab8f7bb5fe67cc46446632368c56f624?ds=inline wxGenericListCtrl::SetItemState(-1) now changes the state of all items (patch 1101650) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32195 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index 2d49150533..8710399209 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -72,6 +72,8 @@ All (GUI): - wxProgressDialog accepts smooth gauge again (wxPD_SMOOTH style) - wxProgressDialog new style: wxPD_CAN_SKIP which provides skipping some parts of the progress (with new "Skip" button in dialog) +- wxGenericListCtrl::SetItemState(-1) now changes the state of all items as + in wxMSW version (Gunnar Roth) Unix: diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 25d1f61b83..93b61273da 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -644,6 +644,7 @@ public: void SetItem( wxListItem &item ); void GetItem( wxListItem &item ) const; void SetItemState( long item, long state, long stateMask ); + void SetItemStateAll( long state, long stateMask ); int GetItemState( long item, long stateMask ) const; void GetItemRect( long index, wxRect &rect ) const; wxRect GetViewRect() const; @@ -3635,8 +3636,58 @@ void wxListMainWindow::SetItem( wxListItem &item ) RefreshRect(rectItem); } +void wxListMainWindow::SetItemStateAll(long state, long stateMask) +{ + if ( IsEmpty() ) + return; + + // first deal with selection + if ( stateMask & wxLIST_STATE_SELECTED ) + { + // set/clear select state + if ( IsVirtual() ) + { + // optimized version for virtual listctrl. + m_selStore.SelectRange(0, GetItemCount() - 1, state == wxLIST_STATE_SELECTED); + Refresh(); + } + else if ( state & wxLIST_STATE_SELECTED ) + { + const long count = GetItemCount(); + for( long i = 0; i < count; i++ ) + { + SetItemState( i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED ); + } + + } + else + { + // clear for non virtual (somewhat optimized by using GetNextItem()) + long i = -1; + while ( (i = GetNextItem(i, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED)) != -1 ) + { + SetItemState( i, 0, wxLIST_STATE_SELECTED ); + } + } + } + + if ( HasCurrent() && (state == 0) && (stateMask & wxLIST_STATE_FOCUSED) ) + { + // unfocus all: only one item can be focussed, so clearing focus for + // all items is simply clearing focus of the focussed item. + SetItemState(m_current, state, stateMask); + } + //(setting focus to all items makes no sense, so it is not handled here.) +} + void wxListMainWindow::SetItemState( long litem, long state, long stateMask ) { + if ( litem == -1 ) + { + SetItemStateAll(state, stateMask); + return; + } + wxCHECK_RET( litem >= 0 && (size_t)litem < GetItemCount(), _T("invalid list ctrl item index in SetItem") ); @@ -4624,7 +4675,7 @@ void wxGenericListCtrl::CalculateAndSetHeaderHeight() { #ifdef __WXMAC__ SInt32 h ; - GetThemeMetric( kThemeMetricListHeaderHeight, &h ); + GetThemeMetric( kThemeMetricListHeaderHeight, &h ); #else // we use 'g' to get the descent, too int w, h, d;