Alexandre Julliard : winecfg: Constrain DPI values to the commonly supported ones.

Alexandre Julliard julliard at winehq.org
Tue May 15 16:25:22 CDT 2018


Module: wine
Branch: master
Commit: 7d7eee09b570b10988a85a3d7e48b37ba4c5d9b0
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=7d7eee09b570b10988a85a3d7e48b37ba4c5d9b0

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Tue May 15 12:37:28 2018 +0200

winecfg: Constrain DPI values to the commonly supported ones.

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 programs/winecfg/winecfg.h   |  2 ++
 programs/winecfg/x11drvdlg.c | 21 ++++++++++++++++-----
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/programs/winecfg/winecfg.h b/programs/winecfg/winecfg.h
index 110856a..f2c24a2 100644
--- a/programs/winecfg/winecfg.h
+++ b/programs/winecfg/winecfg.h
@@ -38,6 +38,8 @@
 #define IS_OPTION_FALSE(ch) \
     ((ch) == 'n' || (ch) == 'N' || (ch) == 'f' || (ch) == 'F' || (ch) == '0')
 
+#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
+
 extern WCHAR* current_app; /* NULL means editing global settings  */
 
 /* Use get_reg_key and set_reg_key to alter registry settings. The changes made through
diff --git a/programs/winecfg/x11drvdlg.c b/programs/winecfg/x11drvdlg.c
index 2be6832..fbc6716 100644
--- a/programs/winecfg/x11drvdlg.c
+++ b/programs/winecfg/x11drvdlg.c
@@ -53,6 +53,7 @@ static const WCHAR explorerW[] = {'E','x','p','l','o','r','e','r',0};
 static const WCHAR explorer_desktopsW[] = {'E','x','p','l','o','r','e','r','\\',
                                            'D','e','s','k','t','o','p','s',0};
 
+static const UINT dpi_values[] = { 96, 120, 144, 168, 192, 216, 240, 288, 336, 384, 432, 480 };
 
 static BOOL updating_ui;
 
@@ -258,6 +259,15 @@ static void init_dpi_editbox(HWND hDlg)
     updating_ui = FALSE;
 }
 
+static int get_trackbar_pos( UINT dpi )
+{
+    UINT i;
+
+    for (i = 0; i < ARRAY_SIZE(dpi_values) - 1; i++)
+        if ((dpi_values[i] + dpi_values[i + 1]) / 2 >= dpi) break;
+    return i;
+}
+
 static void init_trackbar(HWND hDlg)
 {
     HWND hTrackBar = GetDlgItem(hDlg, IDC_RES_TRACKBAR);
@@ -267,8 +277,9 @@ static void init_trackbar(HWND hDlg)
 
     dwLogpixels = read_logpixels_reg();
 
-    SendMessageW(hTrackBar, TBM_SETRANGE, TRUE, MAKELONG(MINDPI, MAXDPI));
-    SendMessageW(hTrackBar, TBM_SETPOS, TRUE, dwLogpixels);
+    SendMessageW(hTrackBar, TBM_SETRANGE, TRUE, MAKELONG(0, ARRAY_SIZE(dpi_values)-1));
+    SendMessageW(hTrackBar, TBM_SETPAGESIZE, 0, 1);
+    SendMessageW(hTrackBar, TBM_SETPOS, TRUE, get_trackbar_pos(dwLogpixels));
 
     updating_ui = FALSE;
 }
@@ -297,7 +308,7 @@ static void update_dpi_trackbar_from_edit(HWND hDlg, BOOL fix)
 
     if (dpi >= MINDPI && dpi <= MAXDPI)
     {
-        SendDlgItemMessageW(hDlg, IDC_RES_TRACKBAR, TBM_SETPOS, TRUE, dpi);
+        SendDlgItemMessageW(hDlg, IDC_RES_TRACKBAR, TBM_SETPOS, TRUE, get_trackbar_pos(dpi));
         set_reg_key_dwordW(HKEY_CURRENT_USER, logpixels_reg, logpixels, dpi);
     }
 
@@ -416,9 +427,9 @@ GraphDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 	    switch (wParam) {
 		default: {
 		    int i = SendMessageW(GetDlgItem(hDlg, IDC_RES_TRACKBAR), TBM_GETPOS, 0, 0);
-		    SetDlgItemInt(hDlg, IDC_RES_DPIEDIT, i, TRUE);
+		    SetDlgItemInt(hDlg, IDC_RES_DPIEDIT, dpi_values[i], TRUE);
 		    update_font_preview(hDlg);
-		    set_reg_key_dwordW(HKEY_CURRENT_USER, logpixels_reg, logpixels, i);
+		    set_reg_key_dwordW(HKEY_CURRENT_USER, logpixels_reg, logpixels, dpi_values[i]);
 		    break;
 		}
 	    }




More information about the wine-cvs mailing list