Alexandre Julliard : user32: Implement GetDpiForSystem().

Alexandre Julliard julliard at winehq.org
Thu Mar 29 19:13:29 CDT 2018


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

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Thu Mar 29 14:54:08 2018 +0200

user32: Implement GetDpiForSystem().

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

---

 dlls/user32/sysparams.c | 64 ++++++++++++++++++++++---------------------------
 dlls/user32/user32.spec |  1 +
 include/winuser.h       |  1 +
 3 files changed, 30 insertions(+), 36 deletions(-)

diff --git a/dlls/user32/sysparams.c b/dlls/user32/sysparams.c
index 4824ad2..454d58c 100644
--- a/dlls/user32/sysparams.c
+++ b/dlls/user32/sysparams.c
@@ -625,19 +625,6 @@ void release_display_dc( HDC hdc )
     LeaveCriticalSection( &display_dc_section );
 }
 
-static inline int get_display_dpi(void)
-{
-    static int display_dpi;
-    HDC hdc;
-    if (!display_dpi)
-    {
-        hdc = get_display_dc();
-        display_dpi = GetDeviceCaps( hdc, LOGPIXELSY );
-        release_display_dc( hdc );
-    }
-    return display_dpi;
-}
-
 static INT CALLBACK real_fontname_proc(const LOGFONTW *lf, const TEXTMETRICW *ntm, DWORD type, LPARAM lparam)
 {
     const ENUMLOGFONTW *elf = (const ENUMLOGFONTW *)lf;
@@ -768,7 +755,7 @@ static BOOL get_twips_entry( union sysparam_all_entry *entry, UINT int_param, vo
              *       Technical Reference to the Windows 2000 Registry ->
              *       HKEY_CURRENT_USER -> Control Panel -> Desktop -> WindowMetrics
              */
-            if (val < 0) val = (-val * get_display_dpi() + 720) / 1440;
+            if (val < 0) val = (-val * GetDpiForSystem() + 720) / 1440;
             entry->uint.val = val;
         }
     }
@@ -952,13 +939,13 @@ static BOOL get_font_entry( union sysparam_all_entry *entry, UINT int_param, voi
         {
         case sizeof(font):
             if (font.lfHeight > 0) /* positive height value means points ( inch/72 ) */
-                font.lfHeight = -MulDiv( font.lfHeight, get_display_dpi(), 72 );
+                font.lfHeight = -MulDiv( font.lfHeight, GetDpiForSystem(), 72 );
             entry->font.val = font;
             break;
         case sizeof(LOGFONT16): /* win9x-winME format */
             SYSPARAMS_LogFont16To32W( (LOGFONT16 *)&font, &entry->font.val );
             if (entry->font.val.lfHeight > 0)
-                entry->font.val.lfHeight = -MulDiv( entry->font.val.lfHeight, get_display_dpi(), 72 );
+                entry->font.val.lfHeight = -MulDiv( entry->font.val.lfHeight, GetDpiForSystem(), 72 );
             break;
         default:
             WARN( "Unknown format in key %s value %s\n",
@@ -1509,9 +1496,7 @@ BOOL WINAPI SystemParametersInfoW( UINT uiAction, UINT uiParam,
             ret = get_entry( &entry_ICONHORIZONTALSPACING, uiParam, pvParam );
         else
         {
-            int min_val = 32;
-            if (IsProcessDPIAware())
-                min_val = MulDiv( min_val, get_display_dpi(), USER_DEFAULT_SCREEN_DPI );
+            int min_val = MulDiv( 32, GetDpiForSystem(), USER_DEFAULT_SCREEN_DPI );
             ret = set_entry( &entry_ICONHORIZONTALSPACING, max( min_val, uiParam ), pvParam, fWinIni );
         }
         break;
@@ -1552,9 +1537,7 @@ BOOL WINAPI SystemParametersInfoW( UINT uiAction, UINT uiParam,
             ret = get_entry( &entry_ICONVERTICALSPACING, uiParam, pvParam );
         else
         {
-            int min_val = 32;
-            if (IsProcessDPIAware())
-                min_val = MulDiv( min_val, get_display_dpi(), USER_DEFAULT_SCREEN_DPI );
+            int min_val = MulDiv( 32, GetDpiForSystem(), USER_DEFAULT_SCREEN_DPI );
             ret = set_entry( &entry_ICONVERTICALSPACING, max( min_val, uiParam ), pvParam, fWinIni );
         }
         break;
@@ -2435,18 +2418,12 @@ INT WINAPI GetSystemMetrics( INT index )
         return max( 8, ret );
     case SM_CXICON:
     case SM_CYICON:
-        ret = 32;
-        if (IsProcessDPIAware())
-            ret = MulDiv( ret, get_display_dpi(), USER_DEFAULT_SCREEN_DPI );
-        return ret;
+        return MulDiv( 32, GetDpiForSystem(), USER_DEFAULT_SCREEN_DPI );
     case SM_CXCURSOR:
     case SM_CYCURSOR:
-        if (IsProcessDPIAware())
-        {
-            ret = MulDiv( 32, get_display_dpi(), USER_DEFAULT_SCREEN_DPI );
-            if (ret >= 64) return 64;
-            if (ret >= 48) return 48;
-        }
+        ret = MulDiv( 32, GetDpiForSystem(), USER_DEFAULT_SCREEN_DPI );
+        if (ret >= 64) return 64;
+        if (ret >= 48) return 48;
         return 32;
     case SM_CYMENU:
         return GetSystemMetrics(SM_CYMENUSIZE) + 1;
@@ -2537,10 +2514,7 @@ INT WINAPI GetSystemMetrics( INT index )
         return GetSystemMetrics(SM_CYMINIMIZED) + max( 0, (INT)ret );
     case SM_CXSMICON:
     case SM_CYSMICON:
-        ret = 16;
-        if (IsProcessDPIAware())
-            ret = MulDiv( ret, get_display_dpi(), USER_DEFAULT_SCREEN_DPI ) & ~1;
-        return ret;
+        return MulDiv( 16, GetDpiForSystem(), USER_DEFAULT_SCREEN_DPI ) & ~1;
     case SM_CYSMCAPTION:
         return GetSystemMetrics(SM_CYSMSIZE) + 1;
     case SM_CXSMSIZE:
@@ -2963,6 +2937,24 @@ BOOL WINAPI IsProcessDPIAware(void)
     return TRUE;
 }
 
+/***********************************************************************
+ *              GetDpiForSystem   (USER32.@)
+ */
+UINT WINAPI GetDpiForSystem(void)
+{
+    static int display_dpi;
+
+    if (!IsProcessDPIAware()) return USER_DEFAULT_SCREEN_DPI;
+
+    if (!display_dpi)
+    {
+        HDC hdc = get_display_dc();
+        display_dpi = GetDeviceCaps( hdc, LOGPIXELSY );
+        release_display_dc( hdc );
+    }
+    return display_dpi;
+}
+
 /**********************************************************************
  *              SetThreadDpiAwarenessContext   (USER32.@)
  */
diff --git a/dlls/user32/user32.spec b/dlls/user32/user32.spec
index 1bcdf2c..05bdae4 100644
--- a/dlls/user32/user32.spec
+++ b/dlls/user32/user32.spec
@@ -292,6 +292,7 @@
 @ stdcall GetDlgItemTextA(long long ptr long)
 @ stdcall GetDlgItemTextW(long long ptr long)
 @ stdcall GetDoubleClickTime()
+@ stdcall GetDpiForSystem()
 @ stdcall GetFocus()
 @ stdcall GetForegroundWindow()
 @ stdcall GetGestureConfig(long long long ptr ptr long)
diff --git a/include/winuser.h b/include/winuser.h
index d587859..18a6e3a 100644
--- a/include/winuser.h
+++ b/include/winuser.h
@@ -3675,6 +3675,7 @@ WINUSERAPI UINT        WINAPI GetDlgItemTextA(HWND,INT,LPSTR,INT);
 WINUSERAPI UINT        WINAPI GetDlgItemTextW(HWND,INT,LPWSTR,INT);
 #define                       GetDlgItemText WINELIB_NAME_AW(GetDlgItemText)
 WINUSERAPI UINT        WINAPI GetDoubleClickTime(void);
+WINUSERAPI UINT        WINAPI GetDpiForSystem(void);
 WINUSERAPI HWND        WINAPI GetFocus(void);
 WINUSERAPI HWND        WINAPI GetForegroundWindow(void);
 WINUSERAPI BOOL        WINAPI GetGestureConfig(HWND,DWORD,DWORD,UINT*,GESTURECONFIG*,UINT);




More information about the wine-cvs mailing list