[RAPPS]
authorThomas Faber <thomas.faber@reactos.org>
Sat, 18 Jan 2014 14:11:19 +0000 (14:11 +0000)
committerThomas Faber <thomas.faber@reactos.org>
Sat, 18 Jan 2014 14:11:19 +0000 (14:11 +0000)
- Allow double-clicking to install programs. Based on patch by Edijs Kolesnikovičs and Yuntian Zhang.
CORE-4357 #resolve #comment Thanks guys, this was a major annoyance.

svn path=/trunk/; revision=61675

reactos/base/applications/rapps/listview.c
reactos/base/applications/rapps/misc.c
reactos/base/applications/rapps/rapps.h
reactos/base/applications/rapps/richedit.c
reactos/base/applications/rapps/winmain.c

index f343e99..7c65cab 100644 (file)
@@ -105,7 +105,7 @@ CreateListView(HWND hwnd)
                                 WS_CHILD | WS_VISIBLE | LVS_SORTASCENDING | LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS,
                                 205, 28, 465, 250,
                                 hwnd,
-                                NULL,
+                                GetSubMenu(LoadMenuW(hInst, MAKEINTRESOURCEW(IDR_APPLICATIONMENU)), 0),
                                 hInst,
                                 NULL);
 
index aa944a6..2bb16b6 100644 (file)
@@ -149,17 +149,35 @@ SetWelcomeText(VOID)
 }
 
 VOID
-ShowPopupMenu(HWND hwnd, UINT MenuID)
+ShowPopupMenu(HWND hwnd, UINT MenuID, UINT DefaultItem)
 {
-    HMENU hPopupMenu = GetSubMenu(LoadMenuW(hInst, MAKEINTRESOURCEW(MenuID)), 0);
+    HMENU hMenu = NULL;
+    HMENU hPopupMenu;
+    MENUITEMINFO mii;
     POINT pt;
 
+    if (MenuID)
+    {
+        hMenu = LoadMenuW(hInst, MAKEINTRESOURCEW(MenuID));
+        hPopupMenu = GetSubMenu(hMenu, 0);
+    }
+    else
+        hPopupMenu = GetMenu(hwnd);
+
+    ZeroMemory(&mii, sizeof(mii));
+    mii.cbSize = sizeof(mii);
+    mii.fMask = MIIM_STATE;
+    GetMenuItemInfo(hPopupMenu, DefaultItem, FALSE, &mii);
+    if (!(mii.fState & MFS_GRAYED))
+        SetMenuDefaultItem(hPopupMenu, DefaultItem, FALSE);
+
     GetCursorPos(&pt);
 
     SetForegroundWindow(hwnd);
     TrackPopupMenu(hPopupMenu, 0, pt.x, pt.y, 0, hMainWnd, NULL);
 
-    DestroyMenu(hPopupMenu);
+    if (hMenu)
+        DestroyMenu(hMenu);
 }
 
 BOOL
index 7841890..7d29c2f 100644 (file)
@@ -149,7 +149,7 @@ int GetClientWindowWidth(HWND hwnd);
 int GetClientWindowHeight(HWND hwnd);
 VOID CopyTextToClipboard(LPCWSTR lpszText);
 VOID SetWelcomeText(VOID);
-VOID ShowPopupMenu(HWND hwnd, UINT MenuID);
+VOID ShowPopupMenu(HWND hwnd, UINT MenuID, UINT DefaultItem);
 BOOL StartProcess(LPWSTR lpPath, BOOL Wait);
 BOOL GetStorageDirectory(PWCHAR lpDirectory, DWORD cch);
 BOOL ExtractFilesFromCab(LPWSTR lpCabName, LPWSTR lpOutputPath);
index 97aa9c6..970a328 100644 (file)
@@ -36,7 +36,7 @@ RichEditOnLink(HWND hwnd, ENLINK *Link)
             SendMessageW(hRichEdit, EM_SETSEL, Link->chrg.cpMin, Link->chrg.cpMax);
             SendMessageW(hRichEdit, EM_GETSELTEXT, 0, (LPARAM)pLink);
 
-            ShowPopupMenu(hwnd, IDR_LINKMENU);
+            ShowPopupMenu(hwnd, IDR_LINKMENU, -1);
         }
         break;
     }
index 1fb11ad..f88eb94 100644 (file)
@@ -588,6 +588,25 @@ MainWndOnSize(HWND hwnd, WPARAM wParam, LPARAM lParam)
     EndDeferWindowPos(hdwp);
 }
 
+BOOL IsSelectedNodeInstalled(void)
+{
+    HTREEITEM hSelectedItem = TreeView_GetSelection(hTreeView);
+    TV_ITEM tItem;
+
+    tItem.mask = TVIF_PARAM | TVIF_HANDLE;
+    tItem.hItem = hSelectedItem;
+    TreeView_GetItem(hTreeView, &tItem);
+    switch (tItem.lParam)
+    {
+        case IDS_INSTALLED:
+        case IDS_APPLICATIONS:
+        case IDS_UPDATES:
+            return TRUE;
+        default:
+            return FALSE;
+    }
+}
+
 LRESULT CALLBACK
 MainWindowProc(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
 {
@@ -692,6 +711,42 @@ MainWindowProc(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
                                 break;
                         }
                     }
+
+                    /* Disable/enable items based on treeview selection */
+                    if (IsSelectedNodeInstalled())
+                    {
+                        EnableMenuItem(GetMenu(hwnd), ID_REGREMOVE, MF_ENABLED);
+                        EnableMenuItem(GetMenu(hwnd), ID_INSTALL, MF_GRAYED);
+                        EnableMenuItem(GetMenu(hwnd), ID_UNINSTALL, MF_ENABLED);
+                        EnableMenuItem(GetMenu(hwnd), ID_MODIFY, MF_ENABLED);
+
+                        EnableMenuItem(GetMenu(hListView), ID_REGREMOVE, MF_ENABLED);
+                        EnableMenuItem(GetMenu(hListView), ID_INSTALL, MF_GRAYED);
+                        EnableMenuItem(GetMenu(hListView), ID_UNINSTALL, MF_ENABLED);
+                        EnableMenuItem(GetMenu(hListView), ID_MODIFY, MF_ENABLED);
+
+                        SendMessage(hToolBar, TB_ENABLEBUTTON, ID_REGREMOVE, TRUE);
+                        SendMessage(hToolBar, TB_ENABLEBUTTON, ID_INSTALL, FALSE);
+                        SendMessage(hToolBar, TB_ENABLEBUTTON, ID_UNINSTALL, TRUE);
+                        SendMessage(hToolBar, TB_ENABLEBUTTON, ID_MODIFY, TRUE);
+                    }
+                    else
+                    {
+                        EnableMenuItem(GetMenu(hwnd), ID_REGREMOVE, MF_GRAYED);
+                        EnableMenuItem(GetMenu(hwnd), ID_INSTALL, MF_ENABLED);
+                        EnableMenuItem(GetMenu(hwnd), ID_UNINSTALL, MF_GRAYED);
+                        EnableMenuItem(GetMenu(hwnd), ID_MODIFY, MF_GRAYED);
+
+                        EnableMenuItem(GetMenu(hListView), ID_REGREMOVE, MF_GRAYED);
+                        EnableMenuItem(GetMenu(hListView), ID_INSTALL, MF_ENABLED);
+                        EnableMenuItem(GetMenu(hListView), ID_UNINSTALL, MF_GRAYED);
+                        EnableMenuItem(GetMenu(hListView), ID_MODIFY, MF_GRAYED);
+
+                        SendMessage(hToolBar, TB_ENABLEBUTTON, ID_REGREMOVE, FALSE);
+                        SendMessage(hToolBar, TB_ENABLEBUTTON, ID_INSTALL, TRUE);
+                        SendMessage(hToolBar, TB_ENABLEBUTTON, ID_UNINSTALL, FALSE);
+                        SendMessage(hToolBar, TB_ENABLEBUTTON, ID_MODIFY, FALSE);
+                    }
                 }
                 break;
 
@@ -734,19 +789,34 @@ MainWindowProc(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
                 break;
 
                 case NM_CLICK:
-                    if (data->hwndFrom == hListView)
+                {
+                    if (data->hwndFrom == hListView && ((LPNMLISTVIEW)lParam)->iItem != -1)
                     {
                         if (IS_INSTALLED_ENUM(SelectedEnumType))
                             ShowInstalledAppInfo(-1);
                         if (IS_AVAILABLE_ENUM(SelectedEnumType))
                             ShowAvailableAppInfo(-1);
                     }
-                    break;
+                }
+                break;
+
+                case NM_DBLCLK:
+                {
+                    if (data->hwndFrom == hListView && ((LPNMLISTVIEW)lParam)->iItem != -1)
+                    {
+                        SendMessage(hwnd, WM_COMMAND, ID_INSTALL, 0);   //Won't do anything if the program is already installed
+                    }
+                }
+                break;
 
                 case NM_RCLICK:
-                    if (data->hwndFrom == hListView)
-                        ShowPopupMenu(hListView, IDR_APPLICATIONMENU);
-                    break;
+                {
+                    if (data->hwndFrom == hListView && ((LPNMLISTVIEW)lParam)->iItem != -1)
+                    {
+                        ShowPopupMenu(hListView, 0, ID_INSTALL);
+                    }
+                }
+                break;
 
                 case EN_LINK:
                     RichEditOnLink(hwnd, (ENLINK*)lParam);