From bfdd6261f294238f108911892f2413f33759d8ce Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Sun, 5 Apr 2020 09:48:14 +0200 Subject: [PATCH] [HOTPLUG] Add the context menu to the device tree view --- dll/cpl/hotplug/hotplug.c | 74 ++++++++++++++++++++++++++++++++--- dll/cpl/hotplug/lang/de-DE.rc | 12 ++++++ dll/cpl/hotplug/lang/en-US.rc | 12 ++++++ dll/cpl/hotplug/resource.h | 12 ++++-- 4 files changed, 102 insertions(+), 8 deletions(-) diff --git a/dll/cpl/hotplug/hotplug.c b/dll/cpl/hotplug/hotplug.c index 7e0d32a80d4..acb872883b7 100644 --- a/dll/cpl/hotplug/hotplug.c +++ b/dll/cpl/hotplug/hotplug.c @@ -18,6 +18,7 @@ typedef struct _HOTPLUG_DATA { SP_CLASSIMAGELIST_DATA ImageListData; + HMENU hPopupMenu; DWORD dwFlags; } HOTPLUG_DATA, *PHOTPLUG_DATA; @@ -234,11 +235,9 @@ EnumHotpluggedDevices( int idev; DWORD dwCapabilities, dwSize; ULONG ulStatus, ulProblem; - HTREEITEM hTreeItem; CONFIGRET cr; - DPRINT1("EnumHotpluggedDevices()\n"); TreeView_DeleteAllItems(hwndDeviceTree); @@ -299,6 +298,50 @@ EnumHotpluggedDevices( } +static +VOID +UpdateButtons( + HWND hwndDlg) +{ + BOOL bEnabled; + + bEnabled = (TreeView_GetCount(GetDlgItem(hwndDlg, IDC_SAFE_REMOVE_DEVICE_TREE)) != 0); + + EnableWindow(GetDlgItem(hwndDlg, IDC_SAFE_REMOVE_PROPERTIES), bEnabled); + EnableWindow(GetDlgItem(hwndDlg, IDC_SAFE_REMOVE_STOP), bEnabled); +} + + +static +VOID +ShowContextMenu( + HWND hwndDlg, + HWND hwndTreeView, + PHOTPLUG_DATA pHotplugData) +{ + HTREEITEM hTreeItem; + RECT rc; + POINT pt; + + hTreeItem = TreeView_GetSelection(hwndTreeView); + if (hTreeItem == NULL) + return; + + TreeView_GetItemRect(hwndTreeView, hTreeItem, &rc, TRUE); + + pt.x = (rc.left + rc.right) / 2; + pt.y = (rc.top + rc.bottom) / 2; + ClientToScreen(hwndTreeView, &pt); + TrackPopupMenu(GetSubMenu(pHotplugData->hPopupMenu, 0), + TPM_LEFTALIGN | TPM_TOPALIGN, + pt.x, + pt.y, + 0, + hwndDlg, + NULL); +} + + INT_PTR CALLBACK SafeRemovalDlgProc( @@ -309,14 +352,12 @@ SafeRemovalDlgProc( { PHOTPLUG_DATA pHotplugData; - UNREFERENCED_PARAMETER(lParam); - pHotplugData = (PHOTPLUG_DATA)GetWindowLongPtr(hwndDlg, DWLP_USER); switch (uMsg) { case WM_INITDIALOG: - pHotplugData = HeapAlloc(GetProcessHeap(), 0, sizeof(HOTPLUG_DATA)); + pHotplugData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(HOTPLUG_DATA)); if (pHotplugData != NULL) { SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pHotplugData); @@ -324,6 +365,8 @@ SafeRemovalDlgProc( pHotplugData->ImageListData.cbSize = sizeof(pHotplugData->ImageListData); SetupDiGetClassImageList(&pHotplugData->ImageListData); + pHotplugData->hPopupMenu = LoadMenu(hApplet, MAKEINTRESOURCE(IDM_POPUP_DEVICE_TREE)); + pHotplugData->dwFlags = GetHotPlugFlags(); if (pHotplugData->dwFlags & HOTPLUG_DISPLAY_DEVICE_COMPONENTS) @@ -335,6 +378,7 @@ SafeRemovalDlgProc( EnumHotpluggedDevices(GetDlgItem(hwndDlg, IDC_SAFE_REMOVE_DEVICE_TREE), pHotplugData); + UpdateButtons(hwndDlg); } return TRUE; @@ -384,6 +428,23 @@ SafeRemovalDlgProc( { EnumHotpluggedDevices(GetDlgItem(hwndDlg, IDC_SAFE_REMOVE_DEVICE_TREE), pHotplugData); + UpdateButtons(hwndDlg); + } + } + break; + + case WM_NOTIFY: + if (((LPNMHDR)lParam)->idFrom == IDC_SAFE_REMOVE_DEVICE_TREE) + { + if (((LPNMHDR)lParam)->code == NM_RCLICK) + { + if (pHotplugData != NULL) + { + ShowContextMenu(hwndDlg, + ((LPNMHDR)lParam)->hwndFrom, + pHotplugData); + return TRUE; + } } } break; @@ -396,6 +457,9 @@ SafeRemovalDlgProc( case WM_DESTROY: if (pHotplugData != NULL) { + if (pHotplugData->hPopupMenu != NULL) + DestroyMenu(pHotplugData->hPopupMenu); + SetupDiDestroyClassImageList(&pHotplugData->ImageListData); HeapFree(GetProcessHeap(), 0, pHotplugData); diff --git a/dll/cpl/hotplug/lang/de-DE.rc b/dll/cpl/hotplug/lang/de-DE.rc index 46e04653c88..f1f2366abe9 100644 --- a/dll/cpl/hotplug/lang/de-DE.rc +++ b/dll/cpl/hotplug/lang/de-DE.rc @@ -16,3 +16,15 @@ BEGIN AUTOCHECKBOX "&Gerätekomponenten anzeigen", IDC_SAFE_REMOVE_DISPLAY_COMPONENTS, 7, 208, 112, 10, WS_CHILD | WS_VISIBLE | WS_TABSTOP PUSHBUTTON "&Schließen", IDCLOSE, 216, 224, 55, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP END + + +/* Menus */ + +IDM_POPUP_DEVICE_TREE MENU +BEGIN + POPUP "" + BEGIN + MENUITEM "Beenden", IDM_STOP + MENUITEM "Eigenschaften", IDM_PROPERTIES + END +END diff --git a/dll/cpl/hotplug/lang/en-US.rc b/dll/cpl/hotplug/lang/en-US.rc index 1ac4e2e06e2..77aa94c1cb2 100644 --- a/dll/cpl/hotplug/lang/en-US.rc +++ b/dll/cpl/hotplug/lang/en-US.rc @@ -16,3 +16,15 @@ BEGIN AUTOCHECKBOX "&Display device components", IDC_SAFE_REMOVE_DISPLAY_COMPONENTS, 7, 208, 112, 10, WS_CHILD | WS_VISIBLE | WS_TABSTOP PUSHBUTTON "&Close", IDCLOSE, 216, 224, 55, 14, WS_CHILD | WS_VISIBLE | WS_TABSTOP END + + +/* Menus */ + +IDM_POPUP_DEVICE_TREE MENU +BEGIN + POPUP "" + BEGIN + MENUITEM "Stop", IDM_STOP + MENUITEM "Properties", IDM_PROPERTIES + END +END diff --git a/dll/cpl/hotplug/resource.h b/dll/cpl/hotplug/resource.h index 5ad44b59c03..af8d359670d 100644 --- a/dll/cpl/hotplug/resource.h +++ b/dll/cpl/hotplug/resource.h @@ -1,9 +1,9 @@ #pragma once -/* Icon ids */ +/* Icon IDs */ #define IDI_HOTPLUG 100 -/* Dialog ids */ +/* Dialog IDs */ #define IDC_STATIC -1 #define IDD_SAFE_REMOVE_HARDWARE_DIALOG 300 @@ -16,6 +16,12 @@ #define IDD_CONFIRM_STOP_HARDWARE_DIALOG 310 -/* Resource strings ids */ +/* Menu IDs */ +#define IDM_POPUP_DEVICE_TREE 500 +#define IDM_STOP 501 +#define IDM_PROPERTIES 502 + +/* Resource strings IDs */ #define IDS_CPLNAME 1000 #define IDS_CPLDESCRIPTION 1001 +