user32: Handle magic font size 0x7fff in dialog templates correctly. (try 4)

Koro webmaster at korosoft.net
Thu Apr 9 10:26:03 CDT 2009


Hi,

This is a patch that implements the specific case when the font size
member of a dialog template is set to 0x7fff. Wine currently handles it
incorrectly.

This is try #4 because I took the time to write a proper testcase and
get it accepted first. I also made sure that this patch follows all
coding style guidelines (that I know of).

Here's the relevant testcase (initial wine-patches message and actual
commit):

http://www.winehq.org/pipermail/wine-patches/2009-March/070976.html
http://www.winehq.org/pipermail/wine-cvs/2009-March/054215.html

Patch as attachment.

Thanks.


-------------- next part --------------
>From f0f99836d9071c4af3f88bd8f7146e41b788ec37 Mon Sep 17 00:00:00 2001
From: Patrick Gauthier <webmaster at korosoft.net>
Date: Thu, 9 Apr 2009 08:56:18 -0400
Subject: user32: Handle magic font size 0x7fff in dialog templates correctly. (try 4)

---
 dlls/user32/dialog.c       |   76 +++++++++++++++++++++++++++++++++----------
 dlls/user32/tests/dialog.c |    2 +-
 2 files changed, 59 insertions(+), 19 deletions(-)

diff --git a/dlls/user32/dialog.c b/dlls/user32/dialog.c
index bbe3ee2..f0917b1 100644
--- a/dlls/user32/dialog.c
+++ b/dlls/user32/dialog.c
@@ -74,6 +74,7 @@ typedef struct
     LPCWSTR    menuName;
     LPCWSTR    className;
     LPCWSTR    caption;
+    BOOL       useMessageFont;
     INT16      pointSize;
     WORD       weight;
     BOOL       italic;
@@ -427,6 +428,7 @@ static LPCSTR DIALOG_ParseTemplate32( LPCSTR template, DLG_TEMPLATE * result )
 
     /* Get the font name */
 
+    result->useMessageFont = FALSE;
     result->pointSize = 0;
     result->faceName = NULL;
     result->weight = FW_DONTCARE;
@@ -436,16 +438,36 @@ static LPCSTR DIALOG_ParseTemplate32( LPCSTR template, DLG_TEMPLATE * result )
     {
         result->pointSize = GET_WORD(p);
         p++;
-        if (result->dialogEx)
+
+        /* If pointSize is 0x7fff, it means that we need to use the font
+         * in NONCLIENTMETRICSW.lfMessageFont, and NOT read the weight,
+         * italic, and facename from the dialog template.
+         */
+        if (result->pointSize == 0x7fff)
         {
-            result->weight = GET_WORD(p); p++;
-            result->italic = LOBYTE(GET_WORD(p)); p++;
+            /* We could call SystemParametersInfo here, but then we'd have
+             * to convert from pixel size to point size (which can be
+             * imprecise). Instead, we'll set a flag that will be picked
+             * up by DIALOG_CreateIndirect.
+             */
+
+            result->useMessageFont = TRUE;
+            TRACE(" FONT: Using message box font\n");
+        }
+        else
+        {
+            if (result->dialogEx)
+            {
+                result->weight = GET_WORD(p); p++;
+                result->italic = LOBYTE(GET_WORD(p)); p++;
+            }
+            result->faceName = p;
+            p += strlenW( result->faceName ) + 1;
+
+            TRACE(" FONT %d, %s, %d, %s\n",
+                  result->pointSize, debugstr_w( result->faceName ),
+                  result->weight, result->italic ? "TRUE" : "FALSE" );
         }
-        result->faceName = p;
-        p += strlenW( result->faceName ) + 1;
-        TRACE(" FONT %d, %s, %d, %s\n",
-              result->pointSize, debugstr_w( result->faceName ),
-              result->weight, result->italic ? "TRUE" : "FALSE" );
     }
 
     /* First control is on dword boundary */
@@ -492,16 +514,34 @@ static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCVOID dlgTemplate,
 
     if (template.style & DS_SETFONT)
     {
-          /* We convert the size to pixels and then make it -ve.  This works
-           * for both +ve and -ve template.pointSize */
-        HDC dc;
-        int pixels;
-        dc = GetDC(0);
-        pixels = MulDiv(template.pointSize, GetDeviceCaps(dc , LOGPIXELSY), 72);
-        hUserFont = CreateFontW( -pixels, 0, 0, 0, template.weight,
-                                          template.italic, FALSE, FALSE, DEFAULT_CHARSET, 0, 0,
-                                          PROOF_QUALITY, FF_DONTCARE,
-                                          template.faceName );
+        HDC dc = GetDC(0);
+        
+        if (template.useMessageFont)
+        {
+            /* We get the message font from the non-client metrics */
+            NONCLIENTMETRICSW ncMetrics;
+
+            ncMetrics.cbSize = sizeof(NONCLIENTMETRICSW);
+            if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS,
+                sizeof(NONCLIENTMETRICSW),
+                &ncMetrics,
+                0L))
+            {
+                hUserFont = CreateFontIndirectW( &ncMetrics.lfMessageFont );
+            }
+        }
+        else
+        {
+            /* We convert the size to pixels and then make it -ve.  This works
+             * for both +ve and -ve template.pointSize */
+            int pixels;
+            pixels = MulDiv(template.pointSize, GetDeviceCaps(dc , LOGPIXELSY), 72);
+            hUserFont = CreateFontW( -pixels, 0, 0, 0, template.weight,
+                                              template.italic, FALSE, FALSE, DEFAULT_CHARSET, 0, 0,
+                                              PROOF_QUALITY, FF_DONTCARE,
+                                              template.faceName );
+        }
+
         if (hUserFont)
         {
             SIZE charSize;
diff --git a/dlls/user32/tests/dialog.c b/dlls/user32/tests/dialog.c
index 7f8dfae..060625c 100644
--- a/dlls/user32/tests/dialog.c
+++ b/dlls/user32/tests/dialog.c
@@ -999,7 +999,7 @@ static void test_MessageBoxFontTest(void)
     hDlg = CreateDialogIndirectParamW(g_hinst, (LPCDLGTEMPLATE)dlgTemplate, NULL, messageBoxFontDlgWinProc, 0);
     if (!hDlg)
     {
-        todo_wine win_skip("dialog wasn't created\n");
+        win_skip("dialog wasn't created\n");
         return;
     }
 
-- 
1.5.4.3




More information about the wine-patches mailing list