[MAGNIFY] Minor fixes for zoom handling.
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sat, 15 Jun 2019 16:33:28 +0000 (18:33 +0200)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sat, 15 Jun 2019 16:33:28 +0000 (18:33 +0200)
- Zoom factor is unsigned.
- It is comprised between 1 and 9, other values are invalid.
- Check for value validity when reading the zoom string from the combo-list.

base/applications/magnify/magnifier.c
base/applications/magnify/magnifier.h
base/applications/magnify/settings.c

index 13a0a3c..3b3cc92 100644 (file)
@@ -404,8 +404,8 @@ void Draw(HDC aDc)
             DeleteDC(hdcOffscreen);
         }
 
             DeleteDC(hdcOffscreen);
         }
 
-        sourceWidth  = AppWidth / iZoom;
-        sourceHeight = AppHeight / iZoom;
+        sourceWidth  = AppWidth / uiZoom;
+        sourceHeight = AppHeight / uiZoom;
 
          /* Create a memory DC compatible with client area DC */
         hdcOffscreen = CreateCompatibleDC(desktopHdc);
 
          /* Create a memory DC compatible with client area DC */
         hdcOffscreen = CreateCompatibleDC(desktopHdc);
@@ -882,7 +882,7 @@ INT_PTR CALLBACK OptionsProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPar
             break;
         case WM_INITDIALOG:
         {
             break;
         case WM_INITDIALOG:
         {
-            // Add the zoom items...
+            /* Add the zoom items */
             SendDlgItemMessage(hDlg, IDC_ZOOM, CB_ADDSTRING, 0, (LPARAM)("1"));
             SendDlgItemMessage(hDlg, IDC_ZOOM, CB_ADDSTRING, 0, (LPARAM)("2"));
             SendDlgItemMessage(hDlg, IDC_ZOOM, CB_ADDSTRING, 0, (LPARAM)("3"));
             SendDlgItemMessage(hDlg, IDC_ZOOM, CB_ADDSTRING, 0, (LPARAM)("1"));
             SendDlgItemMessage(hDlg, IDC_ZOOM, CB_ADDSTRING, 0, (LPARAM)("2"));
             SendDlgItemMessage(hDlg, IDC_ZOOM, CB_ADDSTRING, 0, (LPARAM)("3"));
@@ -891,8 +891,10 @@ INT_PTR CALLBACK OptionsProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPar
             SendDlgItemMessage(hDlg, IDC_ZOOM, CB_ADDSTRING, 0, (LPARAM)("6"));
             SendDlgItemMessage(hDlg, IDC_ZOOM, CB_ADDSTRING, 0, (LPARAM)("7"));
             SendDlgItemMessage(hDlg, IDC_ZOOM, CB_ADDSTRING, 0, (LPARAM)("8"));
             SendDlgItemMessage(hDlg, IDC_ZOOM, CB_ADDSTRING, 0, (LPARAM)("6"));
             SendDlgItemMessage(hDlg, IDC_ZOOM, CB_ADDSTRING, 0, (LPARAM)("7"));
             SendDlgItemMessage(hDlg, IDC_ZOOM, CB_ADDSTRING, 0, (LPARAM)("8"));
+            SendDlgItemMessage(hDlg, IDC_ZOOM, CB_ADDSTRING, 0, (LPARAM)("9"));
 
 
-            SendDlgItemMessage(hDlg, IDC_ZOOM, CB_SETCURSEL, iZoom - 1, 0);
+            if (uiZoom >= 1 && uiZoom <= 9)
+                SendDlgItemMessage(hDlg, IDC_ZOOM, CB_SETCURSEL, uiZoom - 1, 0);
 
             if (bFollowMouse)
                 SendDlgItemMessage(hDlg,IDC_FOLLOWMOUSECHECK,BM_SETCHECK , wParam ,0);
 
             if (bFollowMouse)
                 SendDlgItemMessage(hDlg,IDC_FOLLOWMOUSECHECK,BM_SETCHECK , wParam ,0);
@@ -936,7 +938,10 @@ INT_PTR CALLBACK OptionsProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPar
                     /* Get index of current selection and the text of that selection */
                     int currentSelectionIndex = ComboBox_GetCurSel(hCombo);  
                     ComboBox_GetLBText(hCombo, currentSelectionIndex, currentZoomValue);
                     /* Get index of current selection and the text of that selection */
                     int currentSelectionIndex = ComboBox_GetCurSel(hCombo);  
                     ComboBox_GetLBText(hCombo, currentSelectionIndex, currentZoomValue);
-                    iZoom = _ttoi(currentZoomValue);
+                    uiZoom = (UINT)_ttoi(currentZoomValue);
+                    /* The zoom factor cannot be smaller than 1 (and not zero) or greater than 9 */
+                    if (uiZoom < 1 || uiZoom > 9)
+                        uiZoom = 1;
 
                     /* Trigger the Draw function to rezoom (which will be set false automatically after rezooming) */
                     bRecreateOffscreenDC = TRUE;
 
                     /* Trigger the Draw function to rezoom (which will be set false automatically after rezooming) */
                     bRecreateOffscreenDC = TRUE;
index 7f29006..01e742d 100644 (file)
@@ -24,7 +24,7 @@
 #include <stdarg.h>
 #include <windef.h>
 
 #include <stdarg.h>
 #include <windef.h>
 
-extern int iZoom;
+extern UINT uiZoom;
 
 struct _AppBarConfig_t {
     DWORD cbSize;
 
 struct _AppBarConfig_t {
     DWORD cbSize;
index a6d4cf0..ab6c585 100644 (file)
@@ -12,7 +12,7 @@
 #include <tchar.h>
 #include <winreg.h>
 
 #include <tchar.h>
 #include <winreg.h>
 
-int iZoom = 3;
+UINT uiZoom = 3;
 
 BOOL bShowWarning = TRUE;
 
 
 BOOL bShowWarning = TRUE;
 
@@ -50,38 +50,38 @@ void LoadSettings()
             }
         }
 
             }
         }
 
-        len = 4;
+        len = sizeof(value);
         if (RegQueryValueEx(hkey, _T("StationaryMagLevel"),  0, 0, (BYTE *)&value, &len) == ERROR_SUCCESS)
         {
             if (value >= 0 && value <= 9)
         if (RegQueryValueEx(hkey, _T("StationaryMagLevel"),  0, 0, (BYTE *)&value, &len) == ERROR_SUCCESS)
         {
             if (value >= 0 && value <= 9)
-                iZoom  = value;
+                uiZoom = value;
         }
 
         }
 
-        len = 4;
+        len = sizeof(value);
         if (RegQueryValueEx(hkey, _T("ShowWarning"), 0, 0, (BYTE *)&value, &len) == ERROR_SUCCESS)
             bShowWarning = (value == 0 ? FALSE : TRUE);
 
         if (RegQueryValueEx(hkey, _T("ShowWarning"), 0, 0, (BYTE *)&value, &len) == ERROR_SUCCESS)
             bShowWarning = (value == 0 ? FALSE : TRUE);
 
-        len = 4;
+        len = sizeof(value);
         if (RegQueryValueEx(hkey, _T("StationaryInvertColors"), 0, 0, (BYTE *)&value, &len) == ERROR_SUCCESS)
             bInvertColors = (value == 0 ? FALSE : TRUE);
 
         if (RegQueryValueEx(hkey, _T("StationaryInvertColors"), 0, 0, (BYTE *)&value, &len) == ERROR_SUCCESS)
             bInvertColors = (value == 0 ? FALSE : TRUE);
 
-        len = 4;
+        len = sizeof(value);
         if (RegQueryValueEx(hkey, _T("StationaryStartMinimized"), 0, 0, (BYTE *)&value, &len) == ERROR_SUCCESS)
             bStartMinimized = (value == 0 ? FALSE : TRUE);
 
         if (RegQueryValueEx(hkey, _T("StationaryStartMinimized"), 0, 0, (BYTE *)&value, &len) == ERROR_SUCCESS)
             bStartMinimized = (value == 0 ? FALSE : TRUE);
 
-        len = 4;
+        len = sizeof(value);
         if (RegQueryValueEx(hkey, _T("StationaryTrackCursor"), 0, 0, (BYTE *)&value, &len) == ERROR_SUCCESS)
             bFollowMouse = (value == 0 ? FALSE : TRUE);
 
         if (RegQueryValueEx(hkey, _T("StationaryTrackCursor"), 0, 0, (BYTE *)&value, &len) == ERROR_SUCCESS)
             bFollowMouse = (value == 0 ? FALSE : TRUE);
 
-        len = 4;
+        len = sizeof(value);
         if (RegQueryValueEx(hkey, _T("StationaryTrackFocus"), 0, 0, (BYTE *)&value, &len) == ERROR_SUCCESS)
             bFollowFocus = (value == 0 ? FALSE : TRUE);
 
         if (RegQueryValueEx(hkey, _T("StationaryTrackFocus"), 0, 0, (BYTE *)&value, &len) == ERROR_SUCCESS)
             bFollowFocus = (value == 0 ? FALSE : TRUE);
 
-        len = 4;
+        len = sizeof(value);
         if (RegQueryValueEx(hkey, _T("StationaryTrackSecondaryFocus"), 0, 0, (BYTE *)&value, &len) == ERROR_SUCCESS)
             bFollowFocus = (value == 0 ? FALSE : TRUE);
 
         if (RegQueryValueEx(hkey, _T("StationaryTrackSecondaryFocus"), 0, 0, (BYTE *)&value, &len) == ERROR_SUCCESS)
             bFollowFocus = (value == 0 ? FALSE : TRUE);
 
-        len = 4;
+        len = sizeof(value);
         if (RegQueryValueEx(hkey, _T("StationaryTrackText"), 0, 0, (BYTE *)&value, &len) == ERROR_SUCCESS)
             bFollowCaret = (value == 0 ? FALSE : TRUE);
 
         if (RegQueryValueEx(hkey, _T("StationaryTrackText"), 0, 0, (BYTE *)&value, &len) == ERROR_SUCCESS)
             bFollowCaret = (value == 0 ? FALSE : TRUE);
 
@@ -98,7 +98,7 @@ void SaveSettings()
     {
         RegSetValueEx(hkey, _T("AppBar"), 0, REG_BINARY, (BYTE *)&AppBarConfig, sizeof(AppBarConfig));
 
     {
         RegSetValueEx(hkey, _T("AppBar"), 0, REG_BINARY, (BYTE *)&AppBarConfig, sizeof(AppBarConfig));
 
-        value = iZoom;
+        value = uiZoom;
         RegSetValueEx(hkey, _T("StationaryMagLevel"), 0, REG_DWORD, (BYTE *)&value, sizeof(value));
 
         value = bShowWarning;
         RegSetValueEx(hkey, _T("StationaryMagLevel"), 0, REG_DWORD, (BYTE *)&value, sizeof(value));
 
         value = bShowWarning;