[DEVMGMT_NEW]
authorChristoph von Wittich <christoph_vw@reactos.org>
Sun, 31 May 2015 09:14:29 +0000 (09:14 +0000)
committerChristoph von Wittich <christoph_vw@reactos.org>
Sun, 31 May 2015 09:14:29 +0000 (09:14 +0000)
enable/disable context menu items on selection change

svn path=/trunk/; revision=67981

reactos/base/applications/mscutils/devmgmt_new/DeviceView.cpp
reactos/base/applications/mscutils/devmgmt_new/DeviceView.h
reactos/base/applications/mscutils/devmgmt_new/MainWindow.cpp

index c67b7d2..bcc10ea 100644 (file)
@@ -112,6 +112,30 @@ CDeviceView::Uninitialize()
     return TRUE;
 }
 
+BOOL CDeviceView::HasChildItem(
+    _In_ HTREEITEM Item)
+{
+    return (TreeView_GetChild(m_hTreeView, Item) != NULL);
+}
+
+BOOL CDeviceView::IsRootItem(
+    _In_ HTREEITEM Item)
+{
+    return (TreeView_GetRoot(m_hTreeView) == Item);
+}
+
+BOOL CDeviceView::IsRootItemSelected()
+{
+    return (TreeView_GetRoot(m_hTreeView) == TreeView_GetSelection(m_hTreeView));
+}
+
+VOID CDeviceView::EnableContextMenuItem(
+    _In_ UINT Id,
+    _In_ UINT Enabled)
+{
+    EnableMenuItem(m_hShortcutMenu, Id, Enabled);
+}
+
 VOID
 CDeviceView::ShowContextMenu(
     _In_ INT xPos,
index 72ede93..b70ed48 100644 (file)
@@ -34,6 +34,11 @@ public:
     BOOL Initialize();
     BOOL Uninitialize();
 
+    VOID EnableContextMenuItem(
+        _In_ UINT Id,
+        _In_ UINT Enabled
+        );
+    
     VOID ShowContextMenu(
         _In_ INT xPos,
         _In_ INT yPos
@@ -49,12 +54,27 @@ public:
     VOID Refresh();
     VOID DisplayPropertySheet();
     VOID SetFocus();
-
+    
+    BOOL IsRootItemSelected();
+    
+    BOOL IsRootItem(
+        _In_ HTREEITEM Item
+        );
+    
+    BOOL HasChildItem(
+        _In_ HTREEITEM Item
+        );
+    
     VOID SetDeviceListType(ListDevices List)
     {
         m_ListDevices = List;
     }
 
+    ListDevices GetDeviceListType()
+    {
+        return m_ListDevices;
+    }
+    
     VOID ShowHiddenDevices(_In_ BOOL ShowHidden)
     {
         m_ShowHidden = ShowHidden;
index 1994233..6569fcf 100644 (file)
@@ -429,7 +429,61 @@ CMainWindow::OnNotify(LPARAM lParam)
 
             break;
         }
+        
+        case TVN_SELCHANGED:
+        {
+            LPNM_TREEVIEW pnmtv = (LPNM_TREEVIEW)lParam;
+            ListDevices ListType = m_DeviceView->GetDeviceListType();
+            
+            if (ListType == DevicesByType)
+            {
+                if (!m_DeviceView->HasChildItem(pnmtv->itemNew.hItem))
+                {
+                    SendMessage(m_hToolBar,
+                                TB_SETSTATE,
+                                IDC_PROP,
+                                (LPARAM)MAKELONG(TBSTATE_ENABLED, 0));
+
+                    EnableMenuItem(GetMenu(m_hMainWnd), IDC_PROP, MF_ENABLED);
+                    m_DeviceView->EnableContextMenuItem(IDC_PROP, MF_ENABLED);
+                }
+                else
+                {
+                    SendMessage(m_hToolBar,
+                                TB_SETSTATE,
+                                IDC_PROP,
+                                (LPARAM)MAKELONG(TBSTATE_INDETERMINATE, 0));
 
+                    EnableMenuItem(GetMenu(m_hMainWnd), IDC_PROP, MF_GRAYED);
+                    m_DeviceView->EnableContextMenuItem(IDC_PROP, MF_GRAYED);
+                }
+            }
+            else if (ListType == DevicesByConnection)
+            {
+                if (m_DeviceView->IsRootItem(pnmtv->itemNew.hItem))
+                {
+                    SendMessage(m_hToolBar,
+                                TB_SETSTATE,
+                                IDC_PROP,
+                                (LPARAM)MAKELONG(TBSTATE_INDETERMINATE, 0));
+
+                    EnableMenuItem(GetMenu(m_hMainWnd), IDC_PROP, MF_GRAYED);
+                    m_DeviceView->EnableContextMenuItem(IDC_PROP, MF_GRAYED);
+                }
+                else
+                {
+                    SendMessage(m_hToolBar,
+                                TB_SETSTATE,
+                                IDC_PROP,
+                                (LPARAM)MAKELONG(TBSTATE_ENABLED, 0));
+
+                    EnableMenuItem(GetMenu(m_hMainWnd), IDC_PROP, MF_ENABLED);
+                    m_DeviceView->EnableContextMenuItem(IDC_PROP, MF_ENABLED);
+                }
+            }
+        }
+        break;
+        
         case NM_DBLCLK:
         {
             m_DeviceView->DisplayPropertySheet();
@@ -438,7 +492,18 @@ CMainWindow::OnNotify(LPARAM lParam)
 
         case NM_RETURN:
         {
-            m_DeviceView->DisplayPropertySheet();
+            ListDevices ListType = m_DeviceView->GetDeviceListType();
+            if (ListType == DevicesByType)
+            {
+                m_DeviceView->DisplayPropertySheet();
+            }
+            else if (ListType == DevicesByConnection)
+            {
+                if (!m_DeviceView->IsRootItemSelected())
+                {
+                    m_DeviceView->DisplayPropertySheet();
+                }
+            }    
             break;
         }
     }