[SERVMAN]
[reactos.git] / reactos / base / applications / mscutils / servman / mainwnd.c
index 8d0ba98..a28e9c8 100644 (file)
@@ -13,9 +13,6 @@
 
 static const WCHAR szMainWndClass[] = L"ServManWndClass";
 
-BOOL bSortAscending = TRUE;
-
-
 /* Toolbar buttons */
 static const TBBUTTON Buttons [] =
 {   /* iBitmap, idCommand, fsState, fsStyle, bReserved[2], dwData, iString */
@@ -23,7 +20,7 @@ static const TBBUTTON Buttons [] =
     {TBICON_REFRESH, ID_REFRESH, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0},          /* refresh */
     {TBICON_EXPORT,  ID_EXPORT,  TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0},          /* export */
 
-    /* Note: First item for a seperator is its width in pixels */
+    /* Note: First item for a separator is its width in pixels */
     {15, 0, TBSTATE_ENABLED, BTNS_SEP, {0}, 0, 0},                                  /* separator */
 
     {TBICON_CREATE,  ID_CREATE,  TBSTATE_INDETERMINATE, BTNS_BUTTON, {0}, 0, 0 },         /* create */
@@ -244,20 +241,13 @@ VOID SetMenuAndButtonStates(PMAIN_WND_INFO Info)
 static INT CALLBACK
 CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
 {
-    ENUM_SERVICE_STATUS_PROCESS *Param1;
-    ENUM_SERVICE_STATUS_PROCESS *Param2;
-//    INT iSubItem = (LPARAM)lParamSort;
+    PMAIN_WND_INFO Info = (PMAIN_WND_INFO)lParamSort;
+    WCHAR Item1[256], Item2[256];
 
-    if (bSortAscending) {
-        Param1 = (ENUM_SERVICE_STATUS_PROCESS *)lParam1;
-        Param2 = (ENUM_SERVICE_STATUS_PROCESS *)lParam2;
-    }
-    else
-    {
-        Param1 = (ENUM_SERVICE_STATUS_PROCESS *)lParam2;
-        Param2 = (ENUM_SERVICE_STATUS_PROCESS *)lParam1;
-    }
-    return _wcsicmp(Param1->lpDisplayName, Param2->lpDisplayName);
+    ListView_GetItemText(Info->hListView, lParam1, Info->SortSelection, Item1, sizeof(Item1) / sizeof(WCHAR));
+    ListView_GetItemText(Info->hListView, lParam2, Info->SortSelection, Item2, sizeof(Item2) / sizeof(WCHAR));
+
+    return wcscmp(Item1, Item2) * Info->SortDirection;
 }
 
 
@@ -475,7 +465,8 @@ MainWndCommand(PMAIN_WND_INFO Info,
             RunActionWithProgress(Info->hMainWnd,
                                   Info->pCurrentService->lpServiceName,
                                   Info->pCurrentService->lpDisplayName,
-                                  ACTION_START);
+                                  ACTION_START,
+                                  NULL); //FIXME: Add start params
 
             UpdateServiceStatus(Info->pCurrentService);
             ChangeListViewText(Info, Info->pCurrentService, LVSTATUS);
@@ -489,7 +480,8 @@ MainWndCommand(PMAIN_WND_INFO Info,
             RunActionWithProgress(Info->hMainWnd,
                                   Info->pCurrentService->lpServiceName,
                                   Info->pCurrentService->lpDisplayName,
-                                  ACTION_STOP);
+                                  ACTION_STOP,
+                                  NULL);
 
             UpdateServiceStatus(Info->pCurrentService);
             ChangeListViewText(Info, Info->pCurrentService, LVSTATUS);
@@ -502,7 +494,8 @@ MainWndCommand(PMAIN_WND_INFO Info,
             RunActionWithProgress(Info->hMainWnd,
                                   Info->pCurrentService->lpServiceName,
                                   Info->pCurrentService->lpDisplayName,
-                                  ACTION_PAUSE);
+                                  ACTION_PAUSE,
+                                  NULL);
 
             UpdateServiceStatus(Info->pCurrentService);
             ChangeListViewText(Info, Info->pCurrentService, LVSTATUS);
@@ -514,7 +507,8 @@ MainWndCommand(PMAIN_WND_INFO Info,
             RunActionWithProgress(Info->hMainWnd,
                                   Info->pCurrentService->lpServiceName,
                                   Info->pCurrentService->lpDisplayName,
-                                  ACTION_RESUME);
+                                  ACTION_RESUME,
+                                  NULL);
 
             UpdateServiceStatus(Info->pCurrentService);
             ChangeListViewText(Info, Info->pCurrentService, LVSTATUS);
@@ -526,7 +520,8 @@ MainWndCommand(PMAIN_WND_INFO Info,
             RunActionWithProgress(Info->hMainWnd,
                                   Info->pCurrentService->lpServiceName,
                                   Info->pCurrentService->lpDisplayName,
-                                  ACTION_RESTART);
+                                  ACTION_RESTART,
+                                  NULL);
 
             UpdateServiceStatus(Info->pCurrentService);
             ChangeListViewText(Info, Info->pCurrentService, LVSTATUS);
@@ -550,8 +545,9 @@ MainWndCommand(PMAIN_WND_INFO Info,
         break;
 
         case ID_VIEW_LARGE:
-            SetListViewStyle(Info->hListView,
-                             LVS_ICON);
+            SetListViewStyle(Info->hListView, LVS_ICON);
+            ListView_Arrange(Info->hListView, LVA_DEFAULT);
+
             CheckMenuRadioItem(GetMenu(Info->hMainWnd),
                                ID_VIEW_LARGE,
                                ID_VIEW_DETAILS,
@@ -560,8 +556,9 @@ MainWndCommand(PMAIN_WND_INFO Info,
         break;
 
         case ID_VIEW_SMALL:
-            SetListViewStyle(Info->hListView,
-                             LVS_SMALLICON);
+            SetListViewStyle(Info->hListView, LVS_SMALLICON);
+            ListView_Arrange(Info->hListView, LVA_DEFAULT);
+
             CheckMenuRadioItem(GetMenu(Info->hMainWnd),
                                ID_VIEW_LARGE,
                                ID_VIEW_DETAILS,
@@ -728,14 +725,27 @@ MainWndProc(HWND hwnd,
                 case LVN_COLUMNCLICK:
                 {
                     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 */
+                    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);
 
-                    (void)ListView_SortItems(Info->hListView,
-                                             CompareFunc,
-                                             pnmv->iSubItem);
-                    bSortAscending = !bSortAscending;
+                    (void)ListView_SortItemsEx(Info->hListView,
+                                               CompareFunc,
+                                               (LPARAM)Info);
                 }
                 break;
-
                 case LVN_ITEMCHANGED:
                 {
                     LPNMLISTVIEW pnmv = (LPNMLISTVIEW) lParam;
@@ -870,10 +880,7 @@ MainWndProc(HWND hwnd,
 
         case WM_CLOSE:
         {
-            HeapFree(ProcessHeap,
-                     0,
-                     Info->pAllServices);
-
+            FreeServiceList(Info);
             DestroyMenu(Info->hShortcutMenu);
             DestroyWindow(hwnd);
         }