[RAPPS] move the message proc to gui.cpp
[reactos.git] / base / applications / rapps / gui.cpp
index cae703f..f515143 100644 (file)
@@ -348,7 +348,7 @@ public:
             return FALSE;
         }
 
-        ImageList_Destroy((HIMAGELIST) SetImageList(hImageList));
+        ImageList_Destroy(SetImageList(hImageList));
 
         AddButtons(_countof(Buttons), Buttons);
 
@@ -388,14 +388,17 @@ class CAppsListView :
     };
 
     BOOL bHasAllChecked;
-    BOOL bAscending;
+    BOOL bIsAscending;
     BOOL bHasCheckboxes;
 
+    INT nLastHeaderID;
+
 public:
     CAppsListView() :
         bHasAllChecked(FALSE),
-        bAscending(TRUE),
-        bHasCheckboxes(FALSE)
+        bIsAscending(TRUE),
+        bHasCheckboxes(FALSE),
+        nLastHeaderID(-1)
     {
     }
 
@@ -415,11 +418,40 @@ public:
 
     VOID ColumnClick(LPNMLISTVIEW pnmv)
     {
-        SortContext ctx = {this, pnmv->iSubItem};
+        HWND hHeader;
+        HDITEMW hColumn;
+        INT nHeaderID = pnmv->iSubItem;
+
+        if ((GetWindowLongPtr(GWL_STYLE) & ~LVS_NOSORTHEADER) == 0)
+            return;
+
+        hHeader = (HWND) SendMessage(LVM_GETHEADER, 0, 0);
+        ZeroMemory(&hColumn, sizeof(hColumn));
+
+        /* If the sorting column changed, remove the sorting style from the old column */
+        if ((nLastHeaderID != -1) && (nLastHeaderID != nHeaderID))
+        {
+            hColumn.mask = HDI_FORMAT;
+            Header_GetItem(hHeader, nLastHeaderID, &hColumn);
+            hColumn.fmt &= ~(HDF_SORTUP | HDF_SORTDOWN);
+            Header_SetItem(hHeader, nLastHeaderID, &hColumn);
+        }
 
+        /* Set the sorting style to the new column */
+        hColumn.mask = HDI_FORMAT;
+        Header_GetItem(hHeader, nHeaderID, &hColumn);
+
+        hColumn.fmt &= (bIsAscending ? ~HDF_SORTDOWN : ~HDF_SORTUP);
+        hColumn.fmt |= (bIsAscending ? HDF_SORTUP : HDF_SORTDOWN);
+        Header_SetItem(hHeader, nHeaderID, &hColumn);
+
+        /* Sort the list, using the current values of nHeaderID and bIsAscending */
+        SortContext ctx = {this, nHeaderID};
         SortItems(s_CompareFunc, &ctx);
 
-        bAscending = !bAscending;
+        /* Save new values */
+        nLastHeaderID = nHeaderID;
+        bIsAscending = !bIsAscending;
     }
 
     PVOID GetLParam(INT Index)
@@ -507,12 +539,7 @@ public:
         GetItemText(Index, iSubItem, Item2.GetBuffer(MAX_STR_LEN), MAX_STR_LEN);
         Item2.ReleaseBuffer();
 
-        if (bAscending)
-            return Item2 == Item1;
-        else
-            return Item1 == Item2;
-
-        return 0;
+        return bIsAscending ? Item1.Compare(Item2) : Item2.Compare(Item1);
     }
 
     HWND Create(HWND hwndParent)
@@ -668,7 +695,7 @@ public:
     const INT m_Width;
     const INT m_Height;
 
-    CSearchBar() : m_Width(200), m_Height(22) 
+    CSearchBar() : m_Width(200), m_Height(22)
     {
     }
 
@@ -775,6 +802,7 @@ private:
         AddCategory(hRootItemAvailable, IDS_CAT_TOOLS, IDI_CAT_TOOLS);
         AddCategory(hRootItemAvailable, IDS_CAT_DRIVERS, IDI_CAT_DRIVERS);
         AddCategory(hRootItemAvailable, IDS_CAT_LIBS, IDI_CAT_LIBS);
+        AddCategory(hRootItemAvailable, IDS_CAT_THEMES, IDI_CAT_THEMES);
         AddCategory(hRootItemAvailable, IDS_CAT_OTHER, IDI_CAT_OTHER);
 
         m_TreeView->SetImageList();
@@ -939,6 +967,8 @@ private:
 
     VOID OnSize(HWND hwnd, WPARAM wParam, LPARAM lParam)
     {
+        if (wParam == SIZE_MINIMIZED)
+            return;
 
         /* Size status bar */
         m_StatusBar->SendMessage(WM_SIZE, 0, 0);
@@ -1107,6 +1137,10 @@ private:
                         UpdateApplicationsList(ENUM_CAT_VIDEO);
                         break;
 
+                    case IDS_CAT_THEMES:
+                        UpdateApplicationsList(ENUM_CAT_THEMES);
+                        break;
+
                     case IDS_SELECTEDFORINST:
                         UpdateApplicationsList(ENUM_CAT_SELECTED);
                         break;
@@ -1427,6 +1461,10 @@ private:
             PostMessageW(WM_CLOSE, 0, 0);
             break;
 
+        case ID_SEARCH:
+            ::SetFocus(m_SearchBar->m_hWnd);
+            break;
+
         case ID_INSTALL:
             if (IsAvailableEnum(SelectedEnumType))
             {
@@ -1434,6 +1472,7 @@ private:
                 {
                     CDownloadManager::DownloadListOfApplications(m_AvailableApps.GetSelected());
                     UpdateApplicationsList(-1);
+                    m_ListView->SetSelected(-1, FALSE);
                 }
                 else if (CDownloadManager::DownloadApplication(m_ListView->GetSelectedData()))
                 {
@@ -1613,7 +1652,7 @@ private:
 
         m_ListView->DeleteAllItems();
 
-        // Create new ImageList 
+        // Create new ImageList
         hImageListView = ImageList_Create(LISTVIEW_ICON_SIZE,
                                           LISTVIEW_ICON_SIZE,
                                           GetSystemColorDepth() | ILC_MASK,
@@ -1790,3 +1829,31 @@ VOID InsertRichEditText(const ATL::CStringW& szText, DWORD flags)
 {
     InsertRichEditText(szText.GetString(), flags);
 }
+
+VOID ShowMainWindow(INT nShowCmd)
+{
+    HACCEL KeyBrd;
+    MSG Msg;
+
+    hMainWnd = CreateMainWindow();
+
+    if (hMainWnd)
+    {
+        /* Maximize it if we must */
+        ShowWindow(hMainWnd, ((SettingsInfo.bSaveWndPos && SettingsInfo.Maximized) ? SW_MAXIMIZE : nShowCmd));
+        UpdateWindow(hMainWnd);
+
+        /* Load the menu hotkeys */
+        KeyBrd = LoadAcceleratorsW(NULL, MAKEINTRESOURCEW(HOTKEYS));
+
+        /* Message Loop */
+        while (GetMessageW(&Msg, NULL, 0, 0))
+        {
+            if (!TranslateAcceleratorW(hMainWnd, KeyBrd, &Msg))
+            {
+                TranslateMessage(&Msg);
+                DispatchMessageW(&Msg);
+            }
+        }
+    }    
+}