[NETCFGX] NetPropPageProvider: Handle the Min and Max values for INT, LONG and WORD...
[reactos.git] / dll / win32 / netcfgx / propertypage.c
index 1c37083..a7ded46 100644 (file)
@@ -43,6 +43,20 @@ typedef struct _PARAMETER
 
     INT iBase;
     INT iStep;
+
+    union
+    {
+        struct
+        {
+            LONG lMin;
+            LONG lMax;
+        } l;
+        struct
+        {
+            DWORD dwMin;
+            DWORD dwMax;
+        } dw;
+    } u;
 } PARAMETER, *PPARAMETER;
 
 typedef struct _PARAMETER_ARRAY
@@ -199,6 +213,76 @@ GetIntValue(
 }
 
 
+static DWORD
+GetLongValue(
+    _In_ HKEY hKey,
+    _In_ PWSTR pValueName,
+    _In_ LONG lDefault,
+    _Out_ PLONG pValue)
+{
+    WCHAR szBuffer[24];
+    DWORD dwLength = 0;
+    DWORD dwRegType;
+    PWSTR ptr = NULL;
+
+    dwLength = sizeof(szBuffer);
+    RegQueryValueExW(hKey,
+                     pValueName,
+                     NULL,
+                     &dwRegType,
+                     (LPBYTE)szBuffer,
+                     &dwLength);
+
+    if (dwRegType == REG_SZ && dwLength >= sizeof(WCHAR))
+    {
+        *pValue = wcstol(szBuffer, &ptr, 10);
+        if (*pValue == 0 && ptr != NULL)
+            *pValue = lDefault;
+    }
+    else
+    {
+        *pValue = lDefault;
+    }
+
+    return ERROR_SUCCESS;
+}
+
+
+static DWORD
+GetDWordValue(
+    _In_ HKEY hKey,
+    _In_ PWSTR pValueName,
+    _In_ DWORD dwDefault,
+    _Out_ PDWORD pValue)
+{
+    WCHAR szBuffer[24];
+    DWORD dwLength = 0;
+    DWORD dwRegType;
+    PWSTR ptr = NULL;
+
+    dwLength = sizeof(szBuffer);
+    RegQueryValueExW(hKey,
+                     pValueName,
+                     NULL,
+                     &dwRegType,
+                     (LPBYTE)szBuffer,
+                     &dwLength);
+
+    if (dwRegType == REG_SZ && dwLength >= sizeof(WCHAR))
+    {
+        *pValue = wcstoul(szBuffer, &ptr, 10);
+        if (*pValue == 0 && ptr != NULL)
+            *pValue = dwDefault;
+    }
+    else
+    {
+        *pValue = dwDefault;
+    }
+
+    return ERROR_SUCCESS;
+}
+
+
 static
 DWORD
 GetEnumOptions(
@@ -279,7 +363,7 @@ GetEnumOptions(
                                 &dwValueLength);
         if (dwError == ERROR_NO_MORE_ITEMS)
         {
-            dwError == ERROR_SUCCESS;
+            dwError = ERROR_SUCCESS;
             goto done;
         }
         else if (dwError != ERROR_SUCCESS)
@@ -350,6 +434,8 @@ BuildParameterArray(
     DWORD dwSubKeys, dwMaxSubKeyLen, dwKeyLen, dwIndex;
     PWSTR pszType = NULL;
     LONG lError;
+    LONG lDefaultMin, lDefaultMax;
+    DWORD dwDefaultMin, dwDefaultMax;
     BOOL ret = FALSE;
 
     hDriverKey = SetupDiOpenDevRegKey(DeviceInfoSet,
@@ -493,7 +579,55 @@ BuildParameterArray(
                 ParamArray->Array[dwIndex].Type == WORD_TYPE ||
                 ParamArray->Array[dwIndex].Type == DWORD_TYPE)
             {
-                /* FIXME: Read Min and Max values */
+                if (ParamArray->Array[dwIndex].Type == INT_TYPE)
+                {
+                    lDefaultMin = -32768L; //MIN_SHORT;
+                    lDefaultMax = 32767L;  //MAX_SHORT;
+                }
+                else if (ParamArray->Array[dwIndex].Type == LONG_TYPE)
+                {
+                    lDefaultMin = (-2147483647L - 1); // MIN_LONG;
+                    lDefaultMax = 2147483647L;        // MAX_LONG;
+                }
+                else if (ParamArray->Array[dwIndex].Type == WORD_TYPE)
+                {
+                    dwDefaultMin = 0UL;
+                    dwDefaultMax = 65535UL; // MAX_WORD;
+                }
+#if 0
+                else if (ParamArray->Array[dwIndex].Type == DWORD_TYPE)
+                {
+                    dwDefaultMin = 0UL;
+                    dwDefaultMax = 4294967295UL; //MAX_DWORD;
+                }
+#endif
+
+                if (ParamArray->Array[dwIndex].Type == INT_TYPE ||
+                    ParamArray->Array[dwIndex].Type == LONG_TYPE)
+                {
+                    GetLongValue(hParamKey,
+                                 L"Min",
+                                 lDefaultMin,
+                                 &ParamArray->Array[dwIndex].u.l.lMin);
+
+                    GetLongValue(hParamKey,
+                                 L"Max",
+                                 lDefaultMax,
+                                 &ParamArray->Array[dwIndex].u.l.lMax);
+                }
+                else if (ParamArray->Array[dwIndex].Type == WORD_TYPE ||
+                         ParamArray->Array[dwIndex].Type == DWORD_TYPE)
+                {
+                    GetDWordValue(hParamKey,
+                                  L"Min",
+                                  dwDefaultMin,
+                                  &ParamArray->Array[dwIndex].u.dw.dwMin);
+
+                    GetDWordValue(hParamKey,
+                                  L"Max",
+                                  dwDefaultMax,
+                                  &ParamArray->Array[dwIndex].u.dw.dwMax);
+                }
 
                 GetIntValue(hParamKey,
                             L"Base",
@@ -692,14 +826,29 @@ DisplayParameter(
             ShowWindow(GetDlgItem(hwnd, IDC_PROPERTY_VALUE_LIST), SW_HIDE);
 
             hwndControl = GetDlgItem(hwnd, IDC_PROPERTY_VALUE_UPDN);
-            EnableWindow(hwndControl, Parameter->bPresent);
-            ShowWindow(hwndControl, SW_SHOW);
+
+            if (Parameter->Type != DWORD_TYPE)
+            {
+                EnableWindow(hwndControl, Parameter->bPresent);
+                ShowWindow(hwndControl, SW_SHOW);
+            }
 
             if (Parameter->Type == WORD_TYPE || Parameter->Type == DWORD_TYPE)
                 SendMessage(hwndControl, UDM_SETBASE, Parameter->iBase, 0);
             else
                 SendMessage(hwndControl, UDM_SETBASE, 10, 0);
 
+            if (Parameter->Type == INT_TYPE || Parameter->Type == LONG_TYPE)
+            {
+                TRACE("SetMin %ld  SetMax %ld\n", Parameter->u.l.lMin, Parameter->u.l.lMax);
+                SendMessage(hwndControl, UDM_SETRANGE32, Parameter->u.l.lMin, Parameter->u.l.lMax);
+            }
+            else if (Parameter->Type == WORD_TYPE)
+            {
+                TRACE("SetMin %lu  SetMax %lu\n", Parameter->u.dw.dwMin, Parameter->u.dw.dwMax);
+                SendMessage(hwndControl, UDM_SETRANGE32, (INT)Parameter->u.dw.dwMin, (INT)Parameter->u.dw.dwMax);
+            }
+
             hwndControl = GetDlgItem(hwnd, IDC_PROPERTY_VALUE_EDIT);
             EnableWindow(hwndControl, Parameter->bPresent);
             ShowWindow(hwndControl, SW_SHOW);
@@ -789,6 +938,7 @@ OnInitDialog(
     HWND hwndControl;
     PWSTR pszText;
     DWORD i;
+    INT idx;
 
     TRACE("OnInitDialog()\n");
 
@@ -811,13 +961,15 @@ OnInitDialog(
             else
                 pszText = pParamArray->Array[i].pszName;
 
-            ListBox_AddString(hwndControl, pszText);
+            idx = ListBox_AddString(hwndControl, pszText);
+            if (idx != LB_ERR)
+                ListBox_SetItemData(hwndControl, idx, (LPARAM)&pParamArray->Array[i]);
         }
 
         if (pParamArray->dwCount > 0)
         {
             ListBox_SetCurSel(hwndControl, 0);
-            pParamArray->pCurrentParam = &pParamArray->Array[0];
+            pParamArray->pCurrentParam = (PPARAMETER)ListBox_GetItemData(hwndControl, 0);
             DisplayParameter(hwnd, pParamArray->pCurrentParam);
         }
     }
@@ -855,7 +1007,7 @@ OnCommand(
         iIndex = ListBox_GetCurSel((HWND)lParam);
         if (iIndex != LB_ERR && iIndex < pParamArray->dwCount)
         {
-            pParamArray->pCurrentParam = &pParamArray->Array[iIndex];
+            pParamArray->pCurrentParam = (PPARAMETER)ListBox_GetItemData((HWND)lParam, iIndex);
             DisplayParameter(hwnd, pParamArray->pCurrentParam);
         }
     }