[RAPPS] CMainWindow: remove unused functions , and the globals g_MainWindow and hListView
[reactos.git] / base / applications / rapps / gui.cpp
index 89eb62e..55df515 100644 (file)
@@ -26,8 +26,6 @@
 #define LISTVIEW_ICON_SIZE 24
 #define TREEVIEW_ICON_SIZE 24
 
-HWND hListView = NULL;
-
 INT GetSystemColorDepth()
 {
     DEVMODEW pDevMode;
@@ -508,32 +506,6 @@ public:
         bIsAscending = !bIsAscending;
     }
 
-    PVOID GetLParam(INT Index)
-    {
-        INT ItemIndex;
-        LVITEMW Item;
-
-        if (Index == -1)
-        {
-            ItemIndex = (INT) SendMessage(LVM_GETNEXTITEM, -1, LVNI_FOCUSED);
-            if (ItemIndex == -1)
-                return NULL;
-        }
-        else
-        {
-            ItemIndex = Index;
-        }
-
-        ZeroMemory(&Item, sizeof(Item));
-
-        Item.mask = LVIF_PARAM;
-        Item.iItem = ItemIndex;
-        if (!GetItem(&Item))
-            return NULL;
-
-        return (PVOID) Item.lParam;
-    }
-
     BOOL AddColumn(INT Index, ATL::CStringW& Text, INT Width, INT Format)
     {
         return AddColumn(Index, const_cast<LPWSTR>(Text.GetString()), Width, Format);
@@ -799,11 +771,15 @@ class CMainWindow :
     BOOL bSearchEnabled;
     BOOL bUpdating;
 
+    ATL::CStringW szSearchPattern;
+    INT SelectedEnumType;
+
 public:
     CMainWindow() :
         m_ClientPanel(NULL),
         pLink(NULL),
-        bSearchEnabled(FALSE)
+        bSearchEnabled(FALSE),
+        SelectedEnumType(ENUM_ALL_INSTALLED)
     {
     }
 
@@ -902,8 +878,7 @@ private:
         m_ListView->m_HorizontalAlignment = UiAlign_Stretch;
         m_HSplitter->First().Append(m_ListView);
 
-        hListView = m_ListView->Create(m_hWnd);
-        return hListView != NULL;
+        return m_ListView->Create(m_hWnd) != NULL;
     }
 
     BOOL CreateRichEdit()
@@ -1094,6 +1069,61 @@ private:
 
     }
 
+    VOID RemoveSelectedAppFromRegistry()
+    {
+        PINSTALLED_INFO Info;
+        WCHAR szFullName[MAX_PATH] = L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\";
+        ATL::CStringW szMsgText, szMsgTitle;
+        INT ItemIndex = m_ListView->GetNextItem(-1, LVNI_FOCUSED);
+
+        if (!IsInstalledEnum(SelectedEnumType))
+            return;
+
+        Info = reinterpret_cast<PINSTALLED_INFO>(m_ListView->GetItemData(ItemIndex));
+        if (!Info || !Info->hSubKey || (ItemIndex == -1)) 
+            return;
+
+        if (!szMsgText.LoadStringW(IDS_APP_REG_REMOVE) ||
+            !szMsgTitle.LoadStringW(IDS_INFORMATION))
+            return;
+
+        if (MessageBoxW(szMsgText, szMsgTitle, MB_YESNO | MB_ICONQUESTION) == IDYES)
+        {
+            ATL::CStringW::CopyChars(szFullName,
+                                     MAX_PATH,
+                                     Info->szKeyName.GetString(),
+                                     MAX_PATH - wcslen(szFullName));
+
+            if (RegDeleteKeyW(Info->hRootKey, szFullName) == ERROR_SUCCESS)
+            {
+                m_ListView->DeleteItem(ItemIndex);
+                return;
+            }
+
+            if (!szMsgText.LoadStringW(IDS_UNABLE_TO_REMOVE))
+                return;
+
+            MessageBoxW(szMsgText.GetString(), NULL, MB_OK | MB_ICONERROR);
+        }
+    }
+
+    BOOL UninstallSelectedApp(BOOL bModify)
+    {
+        WCHAR szAppName[MAX_STR_LEN];
+
+        if (!IsInstalledEnum(SelectedEnumType))
+            return FALSE;
+
+        INT ItemIndex = m_ListView->GetNextItem(-1, LVNI_FOCUSED);
+        if (ItemIndex == -1)
+            return FALSE;
+
+        m_ListView->GetItemText(ItemIndex, 0, szAppName, _countof(szAppName));
+        WriteLogMessage(EVENTLOG_SUCCESS, MSG_SUCCESS_REMOVE, szAppName);
+
+        PINSTALLED_INFO ItemInfo = (PINSTALLED_INFO)m_ListView->GetItemData(ItemIndex);
+        return UninstallApplication(ItemInfo, bModify);
+    }
     BOOL ProcessWindowMessage(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam, LRESULT& theResult, DWORD dwMapId)
     {
         theResult = 0;
@@ -1553,17 +1583,17 @@ private:
             break;
 
         case ID_UNINSTALL:
-            if (UninstallApplication(-1, FALSE))
+            if (UninstallSelectedApp(FALSE))
                 UpdateApplicationsList(-1);
             break;
 
         case ID_MODIFY:
-            if (UninstallApplication(-1, TRUE))
+            if (UninstallSelectedApp(TRUE))
                 UpdateApplicationsList(-1);
             break;
 
         case ID_REGREMOVE:
-            RemoveAppFromRegistry(-1);
+            RemoveSelectedAppFromRegistry();
             break;
 
         case ID_REFRESH:
@@ -1596,7 +1626,7 @@ private:
 
         while (Count >= 0)
         {
-            Info = (PINSTALLED_INFO) ListViewGetlParam(Count);
+            Info = (PINSTALLED_INFO) m_ListView->GetItemData(Count);
             if (Info)
             {
                 RegCloseKey(Info->hSubKey);
@@ -1651,7 +1681,7 @@ private:
         INT Index;
         HICON hIcon = NULL;
 
-        HIMAGELIST hImageListView = ListView_GetImageList(hListView, LVSIL_SMALL);
+        HIMAGELIST hImageListView = (HIMAGELIST)m_ListView->SendMessage(LVM_GETIMAGELIST, LVSIL_SMALL, 0);
 
         if (!SearchPatternMatch(Info->m_szName.GetString(), szSearchPattern) &&
             !SearchPatternMatch(Info->m_szDesc.GetString(), szSearchPattern))
@@ -1825,116 +1855,37 @@ public:
 
         return CWindowImpl::Create(NULL, r, szWindowName.GetString(), WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
     }
-
-    CStatusBar * GetStatusBar()
-    {
-        return m_StatusBar;
-    }
-
-    CAppsListView * GetListView()
-    {
-        return m_ListView;
-    }
-
-    CRichEdit * GetRichEdit()
-    {
-        return m_RichEdit;
-    }
-
-    CAvailableApps * GetAvailableApps()
-    {
-        return &m_AvailableApps;
-    }
 };
 
-// global interface
-CMainWindow * g_MainWindow;
-
-HWND CreateMainWindow()
-{
-    g_MainWindow = new CMainWindow();
-    return g_MainWindow->Create();
-}
-
-DWORD_PTR ListViewGetlParam(INT item)
-{
-    if (item < 0)
-    {
-        item = g_MainWindow->GetListView()->GetSelectionMark();
-    }
-    return g_MainWindow->GetListView()->GetItemData(item);
-}
-
-VOID SetStatusBarText(LPCWSTR szText)
-{
-    g_MainWindow->GetStatusBar()->SetText(szText);
-}
-
-INT ListViewAddItem(INT ItemIndex, INT IconIndex, LPWSTR lpName, LPARAM lParam)
-{
-    return g_MainWindow->GetListView()->AddItem(ItemIndex, IconIndex, lpName, lParam);
-}
-
-VOID NewRichEditText(LPCWSTR szText, DWORD flags)
-{
-    g_MainWindow->GetRichEdit()->SetText(szText, flags);
-}
-
-VOID InsertRichEditText(LPCWSTR szText, DWORD flags)
-{
-    g_MainWindow->GetRichEdit()->InsertText(szText, flags);
-}
-
-CAvailableApps* GetAvailableApps()
-{
-    return g_MainWindow->GetAvailableApps();
-}
-
-// ATL version of functions above
-VOID SetStatusBarText(const ATL::CStringW& szText)
-{
-    SetStatusBarText(szText.GetString());
-}
-
-INT ListViewAddItem(INT ItemIndex, INT IconIndex, const ATL::CStringW& Name, LPARAM lParam)
-{
-    return ListViewAddItem(ItemIndex, IconIndex, const_cast<LPWSTR>(Name.GetString()), lParam);
-}
-
-VOID NewRichEditText(const ATL::CStringW& szText, DWORD flags)
-{
-    NewRichEditText(szText.GetString(), flags);
-}
-
-VOID InsertRichEditText(const ATL::CStringW& szText, DWORD flags)
-{
-    InsertRichEditText(szText.GetString(), flags);
-}
-
 VOID ShowMainWindow(INT nShowCmd)
 {
     HACCEL KeyBrd;
     MSG Msg;
 
-    hMainWnd = CreateMainWindow();
+    CMainWindow* wnd = new CMainWindow();
+    if (!wnd)
+        return;
 
-    if (hMainWnd)
-    {
-        /* Maximize it if we must */
-        ShowWindow(hMainWnd, ((SettingsInfo.bSaveWndPos && SettingsInfo.Maximized) ? SW_MAXIMIZE : nShowCmd));
-        UpdateWindow(hMainWnd);
+    hMainWnd = wnd->Create();
+    if (!hMainWnd)
+        return;
 
-        /* Load the menu hotkeys */
-        KeyBrd = LoadAcceleratorsW(NULL, MAKEINTRESOURCEW(HOTKEYS));
+    /* Maximize it if we must */
+    ShowWindow(hMainWnd, ((SettingsInfo.bSaveWndPos && SettingsInfo.Maximized) ? SW_MAXIMIZE : nShowCmd));
+    UpdateWindow(hMainWnd);
 
-        /* Message Loop */
-        while (GetMessageW(&Msg, NULL, 0, 0))
+    /* Load the menu hotkeys */
+    KeyBrd = LoadAcceleratorsW(NULL, MAKEINTRESOURCEW(HOTKEYS));
+
+    /* Message Loop */
+    while (GetMessageW(&Msg, NULL, 0, 0))
+    {
+        if (!TranslateAcceleratorW(hMainWnd, KeyBrd, &Msg))
         {
-            if (!TranslateAcceleratorW(hMainWnd, KeyBrd, &Msg))
-            {
-                TranslateMessage(&Msg);
-                DispatchMessageW(&Msg);
-            }
+            TranslateMessage(&Msg);
+            DispatchMessageW(&Msg);
         }
-    }    
+    }
+
+    delete wnd;
 }