From fc3ebc1877ffaed88c4fafb205f4e7e92bb98f76 Mon Sep 17 00:00:00 2001 From: Ged Murphy Date: Wed, 17 Jun 2015 08:15:08 +0000 Subject: [PATCH] [DEVMGR] - Add the (not yet dynamic) context menu - Implement right click node select svn path=/trunk/; revision=68167 --- .../dll/win32/devmgr/devmgmt/DeviceView.cpp | 88 ++++++++++++++++--- reactos/dll/win32/devmgr/devmgmt/DeviceView.h | 20 +++-- .../dll/win32/devmgr/devmgmt/MainWindow.cpp | 37 +++----- reactos/dll/win32/devmgr/devmgmt/MainWindow.h | 2 +- .../dll/win32/devmgr/devmgmt/lang/en-US.rc | 11 ++- 5 files changed, 113 insertions(+), 45 deletions(-) diff --git a/reactos/dll/win32/devmgr/devmgmt/DeviceView.cpp b/reactos/dll/win32/devmgr/devmgmt/DeviceView.cpp index d844cc93dce..258055be1c8 100644 --- a/reactos/dll/win32/devmgr/devmgmt/DeviceView.cpp +++ b/reactos/dll/win32/devmgr/devmgmt/DeviceView.cpp @@ -34,7 +34,7 @@ struct RefreshThreadData { CDeviceView *This; BOOL ScanForChanges; - BOOL UpdateView; +BOOL UpdateView; }; @@ -46,7 +46,8 @@ CDeviceView::CDeviceView( m_hMainWnd(hMainWnd), m_hTreeView(NULL), m_hPropertyDialog(NULL), - m_hShortcutMenu(NULL), + m_hMenu(NULL), + m_hContextMenu(NULL), m_ViewType(DevicesByType), m_ShowHidden(FALSE), m_RootClassImage(-1), @@ -72,7 +73,7 @@ CDeviceView::Initialize() WC_TREEVIEW, NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | TVS_HASLINES | - TVS_HASBUTTONS | TVS_SHOWSELALWAYS | TVS_LINESATROOT, + TVS_HASBUTTONS | TVS_SHOWSELALWAYS | TVS_LINESATROOT, 0, 0, 0, 0, m_hMainWnd, (HMENU)IDC_TREEVIEW, @@ -89,6 +90,11 @@ CDeviceView::Initialize() SetWindowTheme(m_hTreeView, L"explorer", NULL); } + // Create the context menu and make properties the default item + m_hMenu = LoadMenuW(g_hInstance, MAKEINTRESOURCEW(IDR_POPUP)); + m_hContextMenu = GetSubMenu(m_hMenu, 0); + SetMenuDefaultItem(m_hContextMenu, IDC_PROPERTIES, FALSE); + return !!(m_hTreeView); } @@ -103,11 +109,13 @@ CDeviceView::Uninitialize() ZeroMemory(&m_ImageListData, sizeof(SP_CLASSIMAGELIST_DATA)); } + DestroyMenu(m_hMenu); + return true; } -void -CDeviceView::Size( +LRESULT +CDeviceView::OnSize( _In_ int x, _In_ int y, _In_ int cx, @@ -122,12 +130,64 @@ CDeviceView::Size( cx, cy, SWP_NOZORDER); + + return 0; } +LRESULT +CDeviceView::OnRightClick( + _In_ LPNMHDR NmHdr + ) +{ + HTREEITEM hItem = TreeView_GetNextItem(NmHdr->hwndFrom, 0, TVGN_DROPHILITE); + if (hItem) + { + TreeView_SelectItem(NmHdr->hwndFrom, hItem); + } + + return 0; +} + +LRESULT +CDeviceView::OnContextMenu( + _In_ LPARAM lParam + ) +{ + HTREEITEM hSelected = TreeView_GetSelection(m_hTreeView); + + RECT rc; + if (TreeView_GetItemRect(m_hTreeView, + hSelected, + &rc, + TRUE)) + { + POINT pt; + if (GetCursorPos(&pt) && + ScreenToClient(m_hTreeView, &pt) && + PtInRect(&rc, pt)) + { + INT xPos = GET_X_LPARAM(lParam); + INT yPos = GET_Y_LPARAM(lParam); + + TrackPopupMenuEx(m_hContextMenu, + TPM_RIGHTBUTTON, + xPos, + yPos, + m_hMainWnd, + NULL); + } + } + + return 0; +} + + void -CDeviceView::Refresh(_In_ ViewType Type, - _In_ bool ScanForChanges, - _In_ bool UpdateView) +CDeviceView::Refresh( + _In_ ViewType Type, + _In_ bool ScanForChanges, + _In_ bool UpdateView + ) { // Enum devices on a seperate thread to keep the gui responsive @@ -192,7 +252,9 @@ CDeviceView::SetFocus() } bool -CDeviceView::HasProperties(_In_ LPTV_ITEMW TvItem) +CDeviceView::HasProperties( + _In_ LPTV_ITEMW TvItem + ) { CNode *Node = GetNode(TvItem); if (Node) @@ -203,7 +265,9 @@ CDeviceView::HasProperties(_In_ LPTV_ITEMW TvItem) } bool -CDeviceView::IsDisabled(_In_ LPTV_ITEMW TvItem) +CDeviceView::IsDisabled( + _In_ LPTV_ITEMW TvItem + ) { CNode *Node = GetNode(TvItem); if (Node) @@ -214,7 +278,9 @@ CDeviceView::IsDisabled(_In_ LPTV_ITEMW TvItem) } bool -CDeviceView::CanDisable(_In_ LPTV_ITEMW TvItem) +CDeviceView::CanDisable( + _In_ LPTV_ITEMW TvItem + ) { CNode *Node = GetNode(TvItem); if (Node) diff --git a/reactos/dll/win32/devmgr/devmgmt/DeviceView.h b/reactos/dll/win32/devmgr/devmgmt/DeviceView.h index 26cbecf5bc6..9b41308798c 100644 --- a/reactos/dll/win32/devmgr/devmgmt/DeviceView.h +++ b/reactos/dll/win32/devmgr/devmgmt/DeviceView.h @@ -20,7 +20,8 @@ class CDeviceView HWND m_hMainWnd; HWND m_hTreeView; HWND m_hPropertyDialog; - HWND m_hShortcutMenu; + HMENU m_hMenu; + HMENU m_hContextMenu; ViewType m_ViewType; HTREEITEM m_hTreeRoot; @@ -39,13 +40,21 @@ public: bool Initialize(); bool Uninitialize(); - VOID Size( + LRESULT OnSize( _In_ int x, _In_ int y, _In_ int cx, _In_ int cy ); + LRESULT OnRightClick( + _In_ LPNMHDR NmHdr + ); + + LRESULT OnContextMenu( + _In_ LPARAM lParam + ); + VOID Refresh( _In_ ViewType Type, _In_ bool ScanForChanges, @@ -55,12 +64,7 @@ public: VOID DisplayPropertySheet(); VOID SetFocus(); - //VOID SetDeviceListType(ListDevices List) - //{ - // m_ListDevices = List; - //} - - VOID ShowHiddenDevices(_In_ bool ShowHidden) + VOID SetHiddenDevices(_In_ bool ShowHidden) { m_ShowHidden = ShowHidden; } diff --git a/reactos/dll/win32/devmgr/devmgmt/MainWindow.cpp b/reactos/dll/win32/devmgr/devmgmt/MainWindow.cpp index b708b8dd9b2..8b3242aba4d 100644 --- a/reactos/dll/win32/devmgr/devmgmt/MainWindow.cpp +++ b/reactos/dll/win32/devmgr/devmgmt/MainWindow.cpp @@ -16,7 +16,6 @@ #define BTN_PROPERTIES 0 #define BTN_SCAN_HARDWARE 1 -#define BTN_SEPERATOR -1 #define BTN_ENABLE_DRV 2 #define BTN_DISABLE_DRV 3 #define BTN_UPDATE_DRV 4 @@ -124,7 +123,7 @@ CMainWindow::Initialize(LPCTSTR lpCaption, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, CW_USEDEFAULT, CW_USEDEFAULT, - 500, + 550, 500, NULL, NULL, @@ -230,9 +229,6 @@ CMainWindow::ScanForHardwareChanges() return true; } - - - bool CMainWindow::CreateToolBar() { @@ -311,7 +307,7 @@ CMainWindow::CreateStatusBar() return bRet; } -void CMainWindow::UpdateContext(_In_ LPTV_ITEMW TvItem) +void CMainWindow::UpdateUiContext(_In_ LPTV_ITEMW TvItem) { WORD State; @@ -437,10 +433,10 @@ CMainWindow::OnSize() lvHeight = rcClient.bottom - iToolHeight - iStatusHeight; // Resize the device view - m_DeviceView->Size(0, - iToolHeight, - rcClient.right, - lvHeight); + m_DeviceView->OnSize(0, + iToolHeight, + rcClient.right, + lvHeight); return 0; } @@ -449,27 +445,20 @@ LRESULT CMainWindow::OnNotify(LPARAM lParam) { LPNMHDR NmHdr = (LPNMHDR)lParam; + LRESULT Ret; switch (NmHdr->code) { case TVN_SELCHANGED: { LPNMTREEVIEW NmTreeView = (LPNMTREEVIEW)lParam; - UpdateContext(&NmTreeView->itemNew); + UpdateUiContext(&NmTreeView->itemNew); break; } - case TVN_DELETEITEMW: + case NM_RCLICK: { - LPNMTREEVIEW NmTreeView = (LPNMTREEVIEW)lParam; - NmTreeView->action = NmTreeView->action; - - break; - } - - case NM_DBLCLK: - { - m_DeviceView->DisplayPropertySheet(); + Ret = m_DeviceView->OnRightClick(NmHdr); break; } @@ -486,7 +475,7 @@ CMainWindow::OnNotify(LPARAM lParam) LRESULT CMainWindow::OnContext(LPARAM lParam) { - return 0; + return m_DeviceView->OnContextMenu(lParam); } LRESULT @@ -535,12 +524,12 @@ CMainWindow::OnCommand(WPARAM wParam, if (CurCheckState == MF_CHECKED) { // Inform the device view of the change - m_DeviceView->ShowHiddenDevices(false); + m_DeviceView->SetHiddenDevices(false); NewCheckState = MF_UNCHECKED; } else if (CurCheckState == MF_UNCHECKED) { - m_DeviceView->ShowHiddenDevices(true); + m_DeviceView->SetHiddenDevices(true); NewCheckState = MF_CHECKED; } else diff --git a/reactos/dll/win32/devmgr/devmgmt/MainWindow.h b/reactos/dll/win32/devmgr/devmgmt/MainWindow.h index ebb0600e78a..7c6bbbe7c95 100644 --- a/reactos/dll/win32/devmgr/devmgmt/MainWindow.h +++ b/reactos/dll/win32/devmgr/devmgmt/MainWindow.h @@ -44,7 +44,7 @@ private: bool CreateToolBar(); bool CreateStatusBar(); - void UpdateContext(_In_ LPTV_ITEMW TvItem); + void UpdateUiContext(_In_ LPTV_ITEMW TvItem); bool StatusBarLoadString( HWND hStatusBar, diff --git a/reactos/dll/win32/devmgr/devmgmt/lang/en-US.rc b/reactos/dll/win32/devmgr/devmgmt/lang/en-US.rc index caf82ca4c4c..527f4a94cdf 100644 --- a/reactos/dll/win32/devmgr/devmgmt/lang/en-US.rc +++ b/reactos/dll/win32/devmgr/devmgmt/lang/en-US.rc @@ -9,6 +9,7 @@ BEGIN POPUP "Action" BEGIN MENUITEM "Update driver software..." IDC_UPDATE_DRV + MENUITEM "Enable" IDC_ENABLE_DRV MENUITEM "Disable" IDC_DISABLE_DRV MENUITEM "Uninstall" IDC_UNINSTALL_DRV MENUITEM SEPARATOR @@ -36,7 +37,15 @@ IDR_POPUP MENU BEGIN POPUP "popup" BEGIN - MENUITEM "Properties", IDC_PROPERTIES, GRAYED + MENUITEM "Update driver software..." IDC_UPDATE_DRV + MENUITEM "Enable" IDC_ENABLE_DRV + MENUITEM "Disable" IDC_DISABLE_DRV + MENUITEM "Uninstall" IDC_UNINSTALL_DRV + MENUITEM SEPARATOR + MENUITEM "Scan for hardware changes" IDC_SCAN_HARDWARE + MENUITEM "Add hardware" IDC_ADD_HARDWARE, GRAYED + MENUITEM SEPARATOR + MENUITEM "Properties", IDC_PROPERTIES END END