From 7d7eee09b570b10988a85a3d7e48b37ba4c5d9b0 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Tue, 15 May 2018 12:37:28 +0200 Subject: [PATCH] winecfg: Constrain DPI values to the commonly supported ones. Signed-off-by: Alexandre Julliard --- 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 110856a5365..f2c24a2012f 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 2be6832d253..fbc6716e94e 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; } }