display the device properties when double-clicking a device
[reactos.git] / reactos / lib / devmgr / hwpage.c
index fac1f52..3fc516b 100644 (file)
@@ -30,8 +30,6 @@
 #define NDEBUG
 #include <debug.h>
 
-typedef VOID (WINAPI *PINITCOMMONCONTROLS)(VOID);
-
 typedef enum
 {
     HWPD_STANDARDLIST = 0,
@@ -126,12 +124,30 @@ InitializeDevicesList(IN PHARDWARE_PAGE_DATA hpd)
 }
 
 
+static BOOL
+DisplaySelectedDeviceProperties(IN PHARDWARE_PAGE_DATA hpd)
+{
+    PHWDEVINFO HwDevInfo;
+    BOOL Ret = FALSE;
+
+    HwDevInfo = (PHWDEVINFO)ListViewGetSelectedItemData(hpd->hWndDevList);
+    if (HwDevInfo != NULL)
+    {
+        Ret = DisplayDeviceAdvancedProperties(hpd->hWnd,
+                                              HwDevInfo->ClassDevInfo->hDevInfo,
+                                              &HwDevInfo->DevInfoData,
+                                              hpd->hComCtl32) != -1;
+    }
+
+    return Ret;
+}
+
+
 static VOID
 UpdateControlStates(IN PHARDWARE_PAGE_DATA hpd)
 {
     PHWDEVINFO HwDevInfo;
     HWND hBtnTroubleShoot, hBtnProperties;
-    DWORD RegDataType;
     
     hBtnTroubleShoot = GetDlgItem(hpd->hWnd,
                                   IDC_TROUBLESHOOT);
@@ -145,19 +161,12 @@ UpdateControlStates(IN PHARDWARE_PAGE_DATA hpd)
         WCHAR szBuffer[256];
         LPWSTR szFormatted = NULL;
 
-        if (!SetupDiGetDeviceRegistryProperty(HwDevInfo->ClassDevInfo->hDevInfo,
-                                              &HwDevInfo->DevInfoData,
-                                              SPDRP_MFG,
-                                              &RegDataType,
-                                              (PBYTE)szBuffer,
-                                              sizeof(szBuffer),
-                                              NULL) ||
-            RegDataType != REG_SZ)
-        {
-            /* FIXME - check string for NULL termination! */
-            szBuffer[0] = L'\0';
-        }
-        if (LoadAndFormatString(hDllInstance,
+        /* get the manufacturer string */
+        if (GetDeviceManufacturerString(HwDevInfo->ClassDevInfo->hDevInfo,
+                                        &HwDevInfo->DevInfoData,
+                                        szBuffer,
+                                        sizeof(szBuffer) / sizeof(szBuffer[0])) &&
+            LoadAndFormatString(hDllInstance,
                                 IDS_MANUFACTURER,
                                 &szFormatted,
                                 szBuffer) != 0)
@@ -168,7 +177,35 @@ UpdateControlStates(IN PHARDWARE_PAGE_DATA hpd)
             LocalFree((HLOCAL)szFormatted);
         }
 
-        /* FIXME - Display location and status */
+        /* get the location string */
+        if (GetDeviceLocationString(HwDevInfo->DevInfoData.DevInst,
+                                    szBuffer,
+                                    sizeof(szBuffer) / sizeof(szBuffer[0])) &&
+            LoadAndFormatString(hDllInstance,
+                                IDS_LOCATION,
+                                &szFormatted,
+                                szBuffer) != 0)
+        {
+            SetDlgItemText(hpd->hWnd,
+                           IDC_LOCATION,
+                           szFormatted);
+            LocalFree((HLOCAL)szFormatted);
+        }
+
+        if (GetDeviceStatusString(HwDevInfo->ClassDevInfo->hDevInfo,
+                                  &HwDevInfo->DevInfoData,
+                                  szBuffer,
+                                  sizeof(szBuffer) / sizeof(szBuffer[0])) &&
+            LoadAndFormatString(hDllInstance,
+                                IDS_STATUS,
+                                &szFormatted,
+                                szBuffer) != 0)
+        {
+            SetDlgItemText(hpd->hWnd,
+                           IDC_STATUS,
+                           szFormatted);
+            LocalFree((HLOCAL)szFormatted);
+        }
     }
     else
     {
@@ -186,10 +223,11 @@ UpdateControlStates(IN PHARDWARE_PAGE_DATA hpd)
 
     EnableWindow(hBtnTroubleShoot,
                  HwDevInfo != NULL);
-    EnableWindow(hBtnTroubleShoot,
-                 hBtnProperties != NULL);
+    EnableWindow(hBtnProperties,
+                 HwDevInfo != NULL);
 }
 
+
 static VOID
 FreeDevicesList(IN PHARDWARE_PAGE_DATA hpd)
 {
@@ -198,14 +236,15 @@ FreeDevicesList(IN PHARDWARE_PAGE_DATA hpd)
     ClassDevInfo = hpd->ClassDevInfo;
     LastClassDevInfo = ClassDevInfo + hpd->NumberOfGuids;
 
-    /* free the device info set handles */
+    /* free the device info set handles and structures */
     while (ClassDevInfo != LastClassDevInfo)
     {
         if (ClassDevInfo->hDevInfo != INVALID_HANDLE_VALUE)
         {
             SetupDiDestroyDeviceInfoList(ClassDevInfo->hDevInfo);
+            ClassDevInfo->hDevInfo = INVALID_HANDLE_VALUE;
         }
-        ClassDevInfo->hDevInfo = NULL;
+
         ClassDevInfo->ItemCount = 0;
         ClassDevInfo->ImageIndex = 0;
 
@@ -236,6 +275,8 @@ BuildDevicesList(IN PHARDWARE_PAGE_DATA hpd)
     while (ClassDevInfo != LastClassDevInfo)
     {
         ClassDevInfo->ImageIndex = -1;
+
+        /* open a class device handle for the GUID we're processing */
         ClassDevInfo->hDevInfo = SetupDiGetClassDevs(&ClassDevInfo->Guid,
                                                      NULL,
                                                      hpd->hWnd,
@@ -248,6 +289,7 @@ BuildDevicesList(IN PHARDWARE_PAGE_DATA hpd)
                                       &ClassDevInfo->Guid,
                                       &ClassDevInfo->ImageIndex);
 
+            /* enumerate all devices in the class */
             while (SetupDiEnumDeviceInfo(ClassDevInfo->hDevInfo,
                                          MemberIndex++,
                                          &DevInfoData))
@@ -282,6 +324,7 @@ BuildDevicesList(IN PHARDWARE_PAGE_DATA hpd)
                     }
                 }
 
+                /* save all information for the current device */
                 ClassDevInfo->HwDevInfo[ClassDevInfo->ItemCount].ClassDevInfo = ClassDevInfo;
                 ClassDevInfo->HwDevInfo[ClassDevInfo->ItemCount++].DevInfoData = DevInfoData;
             }
@@ -293,7 +336,7 @@ BuildDevicesList(IN PHARDWARE_PAGE_DATA hpd)
 
 
 static VOID
-FillDevicesList(IN PHARDWARE_PAGE_DATA hpd)
+FillDevicesListViewControl(IN PHARDWARE_PAGE_DATA hpd)
 {
     PHWCLASSDEVINFO ClassDevInfo, LastClassDevInfo;
     PHWDEVINFO HwDevInfo, LastHwDevInfo;
@@ -318,6 +361,7 @@ FillDevicesList(IN PHARDWARE_PAGE_DATA hpd)
                 INT iItem;
                 LVITEM li;
 
+                /* get the device name */
                 if ((SetupDiGetDeviceRegistryProperty(ClassDevInfo->hDevInfo,
                                                       &HwDevInfo->DevInfoData,
                                                       SPDRP_FRIENDLYNAME,
@@ -351,10 +395,10 @@ FillDevicesList(IN PHARDWARE_PAGE_DATA hpd)
                     {
                         ItemCount++;
 
-                        if (SetupDiGetClassDescription(&ClassDevInfo->Guid,
-                                                       szBuffer,
-                                                       sizeof(szBuffer) / sizeof(szBuffer[0]),
-                                                       NULL))
+                        /* get the device type for the second column */
+                        if (GetDeviceTypeString(&HwDevInfo->DevInfoData,
+                                                szBuffer,
+                                                sizeof(szBuffer) / sizeof(szBuffer[0])))
                         {
                             li.mask = LVIF_TEXT;
                             li.iItem = iItem;
@@ -657,6 +701,31 @@ HardwareDlgProc(IN HWND hwndDlg,
                             }
                             break;
                         }
+
+                        case NM_DBLCLK:
+                        {
+                            DisplaySelectedDeviceProperties(hpd);
+                            break;
+                        }
+                    }
+                }
+                break;
+            }
+
+            case WM_COMMAND:
+            {
+                switch (LOWORD(wParam))
+                {
+                    case IDC_TROUBLESHOOT:
+                    {
+                        /* FIXME - start the help using the command in the window text */
+                        break;
+                    }
+
+                    case IDC_PROPERTIES:
+                    {
+                        DisplaySelectedDeviceProperties(hpd);
+                        break;
                     }
                 }
                 break;
@@ -745,7 +814,7 @@ HardwareDlgProc(IN HWND hwndDlg,
                     InitializeDevicesList(hpd);
 
                     /* fill the devices list view control */
-                    FillDevicesList(hpd);
+                    FillDevicesListViewControl(hpd);
 
                     /* decide whether to show or hide the troubleshoot button */
                     EnableTroubleShoot(hpd,
@@ -800,20 +869,13 @@ HardwareDlgProc(IN HWND hwndDlg,
  *   hWndParent:     Handle to the parent window
  *   lpGuids:        An array of guids of devices that are to be listed
  *   uNumberOfGuids: Numbers of guids in the Guids array
- *   Unknown:        Unknown parameter, see NOTEs
+ *   DisplayMode:    Sets the size of the device list view control
  *
  * RETURN VALUE
  *   Returns the handle of the hardware page window that has been created or
  *   NULL if it failed.
  *
- * REVISIONS
- *   13-05-2005 first working version (Sebastian Gasiorek <zebasoftis@gmail.com>)
- *
- * TODO
- *   missing: device icon in list view, Troubleshoot button, device properties,
- *            status description,
- *            devices should be visible afer PSN_SETACTIVE message
- *
+ * @implemented
  */
 HWND
 WINAPI
@@ -823,7 +885,6 @@ DeviceCreateHardwarePageEx(IN HWND hWndParent,
                            IN HWPAGE_DISPLAYMODE DisplayMode)
 {
     PHARDWARE_PAGE_DATA hpd;
-    PINITCOMMONCONTROLS pInitCommonControls;
 
     /* allocate the HARDWARE_PAGE_DATA structure. Make sure it is
        zeroed because the initialization code assumes that in
@@ -846,25 +907,17 @@ DeviceCreateHardwarePageEx(IN HWND hWndParent,
              i < uNumberOfGuids;
              i++)
         {
+            hpd->ClassDevInfo[i].hDevInfo = INVALID_HANDLE_VALUE;
             hpd->ClassDevInfo[i].Guid = lpGuids[i];
         }
 
         /* load comctl32.dll dynamically */
-        hpd->hComCtl32 = LoadLibrary(TEXT("comctl32.dll"));
+        hpd->hComCtl32 = LoadAndInitComctl32();
         if (hpd->hComCtl32 == NULL)
         {
             goto Cleanup;
         }
 
-        /* initialize the common controls */
-        pInitCommonControls = (PINITCOMMONCONTROLS)GetProcAddress(hpd->hComCtl32,
-                                                                  "InitCommonControls");
-        if (pInitCommonControls == NULL)
-        {
-            goto Cleanup;
-        }
-        pInitCommonControls();
-
         /* create the dialog */
         hWnd = CreateDialogParam(hDllInstance,
                                  MAKEINTRESOURCE(IDD_HARDWARE), 
@@ -909,10 +962,7 @@ Cleanup:
  *   Returns the handle of the hardware page window that has been created or
  *   NULL if it failed.
  *
- * REVISIONS
- *
- * NOTE
- *
+ * @implemented
  */
 HWND
 WINAPI