[SERVMAN]
authorEric Kohl <eric.kohl@reactos.org>
Sun, 3 Apr 2016 22:13:01 +0000 (22:13 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Sun, 3 Apr 2016 22:13:01 +0000 (22:13 +0000)
Improved column ordering.
Patch by Carlo Bramini.
CORE-10674 #resolve #comment Thanks a lot!

svn path=/trunk/; revision=71098

reactos/base/applications/mscutils/servman/listview.c
reactos/base/applications/mscutils/servman/mainwnd.c
reactos/base/applications/mscutils/servman/precomp.h
reactos/base/applications/mscutils/servman/servman.c

index 25c4e10..a9f6dcf 100644 (file)
@@ -9,6 +9,27 @@
 
 #include "precomp.h"
 
 
 #include "precomp.h"
 
+typedef struct _COLUMN_LIST
+{
+    int  iSubItem;
+    int  cx;
+    UINT idsText;
+} COLUMN_LIST;
+
+static const COLUMN_LIST Columns[] =
+{
+    /* name */
+    { LVNAME,    150, IDS_FIRSTCOLUMN  },
+    /* description */
+    { LVDESC,    240, IDS_SECONDCOLUMN },
+    /* status */
+    { LVSTATUS,   55, IDS_THIRDCOLUMN  },
+    /* startup type */
+    { LVSTARTUP,  80, IDS_FOURTHCOLUMN },
+    /* logon as */
+    { LVLOGONAS, 100, IDS_FITHCOLUMN   },
+};
+
 VOID
 SetListViewStyle(HWND hListView,
                  DWORD View)
 VOID
 SetListViewStyle(HWND hListView,
                  DWORD View)
@@ -336,6 +357,8 @@ CreateListView(PMAIN_WND_INFO Info)
 {
     LVCOLUMNW lvc = { 0 };
     WCHAR szTemp[256];
 {
     LVCOLUMNW lvc = { 0 };
     WCHAR szTemp[256];
+    HDITEM hdi;
+    int i, n;
 
     Info->hListView = CreateWindowExW(WS_EX_CLIENTEDGE,
                                       WC_LISTVIEWW,
 
     Info->hListView = CreateWindowExW(WS_EX_CLIENTEDGE,
                                       WC_LISTVIEWW,
@@ -356,72 +379,32 @@ CreateListView(PMAIN_WND_INFO Info)
         return FALSE;
     }
 
         return FALSE;
     }
 
+    Info->hHeader = ListView_GetHeader(Info->hListView);
+
     (void)ListView_SetExtendedListViewStyle(Info->hListView,
                                             LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP);/*LVS_EX_GRIDLINES |*/
 
     lvc.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH  | LVCF_FMT;
     lvc.fmt  = LVCFMT_LEFT;
     (void)ListView_SetExtendedListViewStyle(Info->hListView,
                                             LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP);/*LVS_EX_GRIDLINES |*/
 
     lvc.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH  | LVCF_FMT;
     lvc.fmt  = LVCFMT_LEFT;
+    lvc.pszText = szTemp;
 
     /* Add columns to the list-view */
 
     /* Add columns to the list-view */
-    /* name */
-    lvc.iSubItem = LVNAME;
-    lvc.cx       = 150;
-    LoadStringW(hInstance,
-                IDS_FIRSTCOLUMN,
-                szTemp,
-                sizeof(szTemp) / sizeof(WCHAR));
-    lvc.pszText  = szTemp;
-    (void)ListView_InsertColumn(Info->hListView,
-                                0,
-                                &lvc);
+    for (n = 0; n < sizeof(Columns) / sizeof(Columns[0]); n++)
+    {
+        lvc.iSubItem = Columns[n].iSubItem;
+        lvc.cx = Columns[n].cx;
 
 
-    /* description */
-    lvc.iSubItem = LVDESC;
-    lvc.cx       = 240;
-    LoadStringW(hInstance,
-                IDS_SECONDCOLUMN,
-                szTemp,
-                sizeof(szTemp) / sizeof(WCHAR));
-    lvc.pszText  = szTemp;
-    (void)ListView_InsertColumn(Info->hListView,
-                                1,
-                                &lvc);
+        LoadStringW(hInstance,
+                    Columns[n].idsText,
+                    szTemp,
+                    sizeof(szTemp) / sizeof(szTemp[0]));
 
 
-    /* status */
-    lvc.iSubItem = LVSTATUS;
-    lvc.cx       = 55;
-    LoadStringW(hInstance,
-                IDS_THIRDCOLUMN,
-                szTemp,
-                sizeof(szTemp) / sizeof(WCHAR));
-    lvc.pszText  = szTemp;
-    (void)ListView_InsertColumn(Info->hListView,
-                                2,
-                                &lvc);
+        i = ListView_InsertColumn(Info->hListView, Columns[n].iSubItem, &lvc);
 
 
-    /* startup type */
-    lvc.iSubItem = LVSTARTUP;
-    lvc.cx       = 80;
-    LoadStringW(hInstance,
-                IDS_FOURTHCOLUMN,
-                szTemp,
-                sizeof(szTemp) / sizeof(WCHAR));
-    lvc.pszText  = szTemp;
-    (void)ListView_InsertColumn(Info->hListView,
-                                3,
-                                &lvc);
-
-    /* logon as */
-    lvc.iSubItem = LVLOGONAS;
-    lvc.cx       = 100;
-    LoadStringW(hInstance,
-                IDS_FITHCOLUMN,
-                szTemp,
-                sizeof(szTemp) / sizeof(WCHAR));
-    lvc.pszText  = szTemp;
-    (void)ListView_InsertColumn(Info->hListView,
-                                4,
-                                &lvc);
+        hdi.mask = HDI_LPARAM;
+        hdi.lParam = ORD_ASCENDING;
+        (void)Header_SetItem(Info->hHeader, i, &hdi);
+    }
 
     InitListViewImage(Info);
 
 
     InitListViewImage(Info);
 
index df4dbcf..c1e659f 100644 (file)
 
 static const WCHAR szMainWndClass[] = L"ServManWndClass";
 
 
 static const WCHAR szMainWndClass[] = L"ServManWndClass";
 
-BOOL bSortAscending = TRUE;
-
-/* Temporary copy for access from list-view sort CompareFunc */
-HWND hListView;
-
 /* Toolbar buttons */
 static const TBBUTTON Buttons [] =
 {   /* iBitmap, idCommand, fsState, fsStyle, bReserved[2], dwData, iString */
 /* Toolbar buttons */
 static const TBBUTTON Buttons [] =
 {   /* iBitmap, idCommand, fsState, fsStyle, bReserved[2], dwData, iString */
@@ -246,21 +241,13 @@ VOID SetMenuAndButtonStates(PMAIN_WND_INFO Info)
 static INT CALLBACK
 CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
 {
 static INT CALLBACK
 CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
 {
+    PMAIN_WND_INFO Info = (PMAIN_WND_INFO)lParamSort;
     WCHAR Item1[256], Item2[256];
     WCHAR Item1[256], Item2[256];
-    LVFINDINFO IndexInfo;
-    INT Index;
-
-    IndexInfo.flags = LVFI_PARAM;
 
 
-    IndexInfo.lParam = lParam1;
-    Index = ListView_FindItem(hListView, -1, &IndexInfo);
-    ListView_GetItemText(hListView, Index, (INT)lParamSort, Item1, sizeof(Item1) / sizeof(WCHAR));
+    ListView_GetItemText(Info->hListView, lParam1, Info->SortSelection, Item1, sizeof(Item1) / sizeof(WCHAR));
+    ListView_GetItemText(Info->hListView, lParam2, Info->SortSelection, Item2, sizeof(Item2) / sizeof(WCHAR));
 
 
-    IndexInfo.lParam = lParam2;
-    Index = ListView_FindItem(hListView, -1, &IndexInfo);
-    ListView_GetItemText(hListView, Index, (INT)lParamSort, Item2, sizeof(Item2) / sizeof(WCHAR));
-
-    return bSortAscending ? wcscmp(Item1, Item2) : wcscmp(Item2, Item1);
+    return wcscmp(Item1, Item2) * Info->SortDirection;
 }
 
 
 }
 
 
@@ -737,23 +724,26 @@ MainWndProc(HWND hwnd,
 
                 case LVN_COLUMNCLICK:
                 {
 
                 case LVN_COLUMNCLICK:
                 {
-                    static int iLastSortColumn = 0;
                     LPNMLISTVIEW pnmv = (LPNMLISTVIEW) lParam;
                     LPNMLISTVIEW pnmv = (LPNMLISTVIEW) lParam;
+                    HDITEM       hdi;
+
+                    /* get pending sort direction for clicked column */
+                    hdi.mask = HDI_LPARAM;
+                    (void)Header_GetItem(Info->hHeader, pnmv->iSubItem, &hdi);
 
                     /* get new sort parameters */
 
                     /* get new sort parameters */
-                    if (pnmv->iSubItem == iLastSortColumn)
-                        bSortAscending = !bSortAscending;
-                    else
-                    {
-                        iLastSortColumn = pnmv->iSubItem;
-                        bSortAscending = TRUE;
-                    }
+                    Info->SortSelection = pnmv->iSubItem;
+                    Info->SortDirection = hdi.lParam;
+
+                    /* set new sort direction and save */
+                    hdi.lParam = (hdi.lParam == ORD_ASCENDING) ?
+                                 ORD_DESCENDING : ORD_ASCENDING;
+
+                    (void)Header_SetItem(Info->hHeader, pnmv->iSubItem, &hdi);
 
 
-                    /* store a copy to have access from callback */
-                    hListView = Info->hListView;
-                    (void)ListView_SortItems(Info->hListView,
-                                             CompareFunc,
-                                             pnmv->iSubItem);
+                    (void)ListView_SortItemsEx(Info->hListView,
+                                               CompareFunc,
+                                               (LPARAM)Info);
                 }
                 break;
                 case LVN_ITEMCHANGED:
                 }
                 break;
                 case LVN_ITEMCHANGED:
index 8c72c4d..590eee7 100644 (file)
 #define ACTION_RESUME   4
 #define ACTION_RESTART  5
 
 #define ACTION_RESUME   4
 #define ACTION_RESTART  5
 
+#define ORD_ASCENDING   1
+#define ORD_DESCENDING  -1
+
 typedef struct _MAIN_WND_INFO
 {
     HWND  hMainWnd;
     HWND  hListView;
     HWND  hStatus;
     HWND  hTool;
 typedef struct _MAIN_WND_INFO
 {
     HWND  hMainWnd;
     HWND  hListView;
     HWND  hStatus;
     HWND  hTool;
+    HWND  hHeader;
     HMENU hShortcutMenu;
     int   nCmdShow;
 
     HMENU hShortcutMenu;
     int   nCmdShow;
 
@@ -59,6 +63,9 @@ typedef struct _MAIN_WND_INFO
     ENUM_SERVICE_STATUS_PROCESS *pCurrentService;
 
     INT SelectedItem;/* selection number in the list view */
     ENUM_SERVICE_STATUS_PROCESS *pCurrentService;
 
     INT SelectedItem;/* selection number in the list view */
+    INT SortSelection;
+    INT SortDirection;
+
     BOOL bDlgOpen;
     BOOL bInMenuLoop;
     BOOL bIsUserAnAdmin;
     BOOL bDlgOpen;
     BOOL bInMenuLoop;
     BOOL bIsUserAnAdmin;
index 36caee5..d1a2ddd 100644 (file)
@@ -41,7 +41,7 @@ wWinMain(HINSTANCE hThisInstance,
     ProcessHeap = GetProcessHeap();
 
     icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
     ProcessHeap = GetProcessHeap();
 
     icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
-    icex.dwICC = ICC_BAR_CLASSES | ICC_COOL_CLASSES;
+    icex.dwICC = ICC_WIN95_CLASSES | ICC_COOL_CLASSES;
     InitCommonControlsEx(&icex);
 
     if (!AllocAndLoadString(&lpAppName,
     InitCommonControlsEx(&icex);
 
     if (!AllocAndLoadString(&lpAppName,