]> git.saurik.com Git - wxWidgets.git/commitdiff
wxGenericListCtrl::SetItemState(-1) now changes the state of all items (patch 1101650)
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 19 Feb 2005 17:07:17 +0000 (17:07 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 19 Feb 2005 17:07:17 +0000 (17:07 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32195 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
src/generic/listctrl.cpp

index 2d49150533520e6936a36f2f30360feb1304eb34..8710399209a807b114d1133760e1b8bc01e7c03f 100644 (file)
@@ -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:
 
index 25d1f61b83d15858c47370b288e6129aaa47b074..93b61273da26dbb5e5e2a285b50482918f4686b8 100644 (file)
@@ -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;