regedit sort

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I believe this shows up a bug in our listview control code: Try
selecting an 
item and clicking the sort header to change the sort order. The
current item 
is correct but the selection isn't updated...

License: X11

ChangeLog:

  Jon Griffiths <jon_p_griffiths@xxxxxxxxx>

  +programs/regedit/listview.c
    Sort the listview when clicking the Name or Type Headers



__________________________________
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/
diff -u wine/programs/regedit/listview.c wine-develop/programs/regedit/listview.c
--- wine/programs/regedit/listview.c	2003-12-09 12:50:21.000000000 +0000
+++ wine-develop/programs/regedit/listview.c	2003-12-09 21:48:24.000000000 +0000
@@ -30,12 +30,21 @@
 #include <windowsx.h>
 #include "main.h"
 
+typedef struct tagLINE_INFO
+{
+    DWORD dwValType;
+    LPTSTR name;
+    void* val;
+    size_t val_len;
+} LINE_INFO;
 
 /*******************************************************************************
  * Global and Local Variables:
  */
 
 static WNDPROC g_orgListWndProc;
+static DWORD g_columnToSort = ~0UL;
+static BOOL  g_invertSort = FALSE;
 
 #define MAX_LIST_COLUMNS (IDS_LIST_COLUMN_LAST - IDS_LIST_COLUMN_FIRST + 1)
 static int default_column_widths[MAX_LIST_COLUMNS] = { 200, 175, 400 };
@@ -47,9 +56,16 @@
  */
 static void AddEntryToList(HWND hwndLV, LPTSTR Name, DWORD dwValType, void* ValBuf, DWORD dwCount)
 {
+    LINE_INFO* linfo;
     LVITEM item;
     int index;
 
+    linfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(LINE_INFO) + dwCount);
+    linfo->dwValType = dwValType;
+    linfo->val_len = dwCount;
+    memcpy(&linfo[1], ValBuf, dwCount);
+    linfo->name = _tcsdup(Name);
+
     item.mask = LVIF_TEXT | LVIF_PARAM;
     item.iItem = 0;/*idx;  */
     item.iSubItem = 0;
@@ -60,7 +76,8 @@
     if (item.cchTextMax == 0)
         item.pszText = LPSTR_TEXTCALLBACK;
     item.iImage = 0;
-    item.lParam = (LPARAM)dwValType;
+    item.lParam = (LPARAM)linfo;
+
     /*    item.lParam = (LPARAM)ValBuf; */
 #if (_WIN32_IE >= 0x0300)
     item.iIndent = 0;
@@ -138,7 +155,7 @@
         plvdi->item.pszText = _T("(Default)");
         break;
     case 1:
-        switch (plvdi->item.lParam) {
+        switch (((LINE_INFO*)plvdi->item.lParam)->dwValType) {
         case REG_SZ:
             plvdi->item.pszText = _T("REG_SZ");
             break;
@@ -184,17 +201,23 @@
     }
 }
 
-#if 0
 static int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
 {
-    TCHAR buf1[1000];
-    TCHAR buf2[1000];
-
-    ListView_GetItemText((HWND)lParamSort, lParam1, 0, buf1, sizeof(buf1));
-    ListView_GetItemText((HWND)lParamSort, lParam2, 0, buf2, sizeof(buf2));
-    return _tcscmp(buf1, buf2);
+    LINE_INFO*l, *r;
+    l = (LINE_INFO*)lParam1;
+    r = (LINE_INFO*)lParam2;
+        
+    if (g_columnToSort == ~0UL) 
+        g_columnToSort = 0;
+    
+    if (g_columnToSort == 1 && l->dwValType != r->dwValType)
+        return g_invertSort ? (int)r->dwValType - (int)l->dwValType : (int)l->dwValType - (int)r->dwValType;
+    if (g_columnToSort == 2)
+    {
+        /* FIXME: Sort on value */
+    }
+    return g_invertSort ? _tcscmp(r->name, l->name) : _tcscmp(l->name, r->name);
 }
-#endif
 
 static void ListViewPopUpMenu(HWND hWnd, POINT pt)
 {}
@@ -223,6 +246,17 @@
         case LVN_GETDISPINFO:
             OnGetDispInfo((NMLVDISPINFO*)lParam);
             break;
+        case LVN_COLUMNCLICK:
+            if (g_columnToSort == ((LPNMLISTVIEW)lParam)->iSubItem)
+                g_invertSort = !g_invertSort;
+            else
+            {
+                g_columnToSort = ((LPNMLISTVIEW)lParam)->iSubItem;
+                g_invertSort = FALSE;
+            }
+                    
+            ListView_SortItems(hWnd, CompareFunc, hWnd);
+            break;
         case NM_DBLCLK: {
                 NMITEMACTIVATE* nmitem = (LPNMITEMACTIVATE)lParam;
                 LVHITTESTINFO info;
@@ -316,6 +350,16 @@
 BOOL RefreshListView(HWND hwndLV, HKEY hKey, LPTSTR keyPath)
 {
     if (hwndLV != NULL) {
+        INT count, i;
+        count = ListView_GetItemCount(hwndLV);
+        for (i = 0; i < count; i++)
+        {
+            LVITEM item;
+            ListView_GetItem(hwndLV, &item);
+            free(((LINE_INFO*)item.lParam)->name);
+            HeapFree(GetProcessHeap(), 0, (void*)item.lParam);
+        }
+        g_columnToSort = ~0UL;
         ListView_DeleteAllItems(hwndLV);
     }
 
@@ -356,8 +400,7 @@
                 HeapFree(GetProcessHeap(), 0, ValBuf);
                 HeapFree(GetProcessHeap(), 0, ValName);
             }
-            /*ListView_SortItemsEx(hwndLV, CompareFunc, hwndLV); */
-            /*            SendMessage(hwndLV, LVM_SORTITEMSEX, (WPARAM)CompareFunc, (LPARAM)hwndLV); */
+            ListView_SortItems(hwndLV, CompareFunc, hwndLV); 
             ShowWindow(hwndLV, SW_SHOW);
             RegCloseKey(hNewKey);
         }

[Index of Archives]     [Gimp for Windows]     [Red Hat]     [Samba]     [Yosemite Camping]     [Graphics Cards]     [Wine Home]

  Powered by Linux