]> git.saurik.com Git - wxWidgets.git/commitdiff
Moved fix from 2.2 branch that allows the attributes in MSW wxListCtrl
authorRobin Dunn <robin@alldunn.com>
Tue, 14 Aug 2001 05:35:09 +0000 (05:35 +0000)
committerRobin Dunn <robin@alldunn.com>
Tue, 14 Aug 2001 05:35:09 +0000 (05:35 +0000)
to move with their items when the list is sorted.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11372 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/hash.cpp
src/msw/listctrl.cpp

index 900219c6d1197056c7c3ef23503e024c61b72b9e..2909e481837ec5223adf08894e59b5404082ad23 100644 (file)
@@ -681,11 +681,14 @@ void wxHashTable::DeleteContents (bool flag)
 
 void wxHashTable::Clear ()
 {
-  int i;
-  for (i = 0; i < n; i++)
+    int i;
+    if (hash_table)
     {
-      if (hash_table[i])
-        hash_table[i]->Clear ();
+        for (i = 0; i < n; i++)
+        {
+            if (hash_table[i])
+                hash_table[i]->Clear ();
+        }
     }
   m_count = 0;
 }
index 5b030dd30474ab0fb83dec8d430df7b5d117c7eb..904294c968611604cefa6baf4e4d482039d9e39d 100644 (file)
@@ -1376,11 +1376,74 @@ bool wxListCtrl::ScrollList(int dx, int dy)
 // or zero if the two items are equivalent.
 
 // data is arbitrary data to be passed to the sort function.
+
+// FIXME: this is horrible and MT-unsafe and everything else but I don't have
+//        time for anything better right now (VZ)
+static long gs_sortData = 0;
+static wxListCtrl *gs_sortCtrl = NULL;
+static wxListCtrlCompare gs_sortFunction = NULL;
+
+int wxCMPFUNC_CONV wxListCtrlCompareFn(const void *arg1, const void *arg2)
+{
+    int n1 = *(const int *)arg1,
+        n2 = *(const int *)arg2;
+
+    return gs_sortFunction(gs_sortCtrl->GetItemData(n1),
+                           gs_sortCtrl->GetItemData(n2),
+                           gs_sortData);
+}
+
 bool wxListCtrl::SortItems(wxListCtrlCompare fn, long data)
 {
-    return (ListView_SortItems(GetHwnd(), (PFNLVCOMPARE) fn, data) != 0);
+    // sort the attributes too
+    if ( m_hasAnyAttr )
+    {
+        int n,
+            count = GetItemCount();
+        int *aItems = new int[count];
+        for ( n = 0; n < count; n++ )
+        {
+            aItems[n] = n;
+        }
+
+        gs_sortData = data;
+        gs_sortCtrl = this;
+        gs_sortFunction = fn;
+
+        qsort(aItems, count, sizeof(int), wxListCtrlCompareFn);
+
+        gs_sortData = 0;
+        gs_sortCtrl = NULL;
+        gs_sortFunction = NULL;
+
+        wxHashTable attrsNew(wxKEY_INTEGER, 1000);
+        for ( n = 0; n < count; n++ )
+        {
+            wxObject *attr = m_attrs.Delete(n);
+            if ( attr )
+            {
+                attrsNew.Put(aItems[n], attr);
+            }
+        }
+
+        m_attrs.Destroy();
+        m_attrs = attrsNew;
+
+        delete [] aItems;
+    }
+
+    if ( !ListView_SortItems(GetHwnd(), (PFNLVCOMPARE)fn, data) )
+    {
+        wxLogDebug(_T("ListView_SortItems() failed"));
+
+        return FALSE;
+    }
+
+    return TRUE;
 }
 
+
+
 // ----------------------------------------------------------------------------
 // message processing
 // ----------------------------------------------------------------------------