changeset 1039:860d6e73f8bb

Attempt at fixing dw_window_set/get_font() on Groupboxes on Windows.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 26 May 2011 09:06:02 +0000
parents 2c2fcfeeffcc
children 7ea8a428e0cc
files win/dw.c
diffstat 1 files changed, 44 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/win/dw.c	Thu May 26 07:57:10 2011 +0000
+++ b/win/dw.c	Thu May 26 09:06:02 2011 +0000
@@ -4061,47 +4061,50 @@
  */
 int API dw_window_set_font(HWND handle, char *fontname)
 {
-   HFONT oldfont = (HFONT)SendMessage(handle, WM_GETFONT, 0, 0);
-   HFONT hfont = _acquire_font(handle, fontname);
-   ColorInfo *cinfo;
-   Box *thisbox;
-   char tmpbuf[100];
-
-   cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA);
-
-   if (fontname)
-   {
-      GetClassName(handle, tmpbuf, 99);
-      if ( strnicmp( tmpbuf, FRAMECLASSNAME, strlen(FRAMECLASSNAME)) == 0 )
-      {
-         /* groupbox */
-         thisbox = (Box *)GetWindowLongPtr( handle, GWLP_USERDATA );
-         if ( thisbox && thisbox->grouphwnd != (HWND)NULL )
-         {
+    HFONT hfont, oldfont;
+    ColorInfo *cinfo;
+    char tmpbuf[100];
+
+    cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA);
+
+    GetClassName(handle, tmpbuf, 99);
+    if ( strnicmp( tmpbuf, FRAMECLASSNAME, strlen(FRAMECLASSNAME)+1) == 0 )
+    {
+        /* groupbox */
+        Box *thisbox = (Box *)GetWindowLongPtr( handle, GWLP_USERDATA );
+        if ( thisbox && thisbox->grouphwnd != (HWND)NULL )
+        {
             handle = thisbox->grouphwnd;
-         }
-      }
-      if(cinfo)
-      {
-         strcpy(cinfo->fontname, fontname);
-         if(!oldfont)
-            oldfont = cinfo->hfont;
-         cinfo->hfont = hfont;
-      }
-      else
-      {
-         cinfo = calloc(1, sizeof(ColorInfo));
-         cinfo->fore = cinfo->back = -1;
-
-         strcpy(cinfo->fontname, fontname);
-
-         cinfo->pOldProc = SubclassWindow(handle, _colorwndproc);
-         SetWindowLongPtr(handle, GWLP_USERDATA, (LONG_PTR)cinfo);
-      }
-   }
-   SendMessage(handle, WM_SETFONT, (WPARAM)hfont, (LPARAM)TRUE);
-   if(oldfont)
-      DeleteObject(oldfont);
+        }
+    }
+        
+    /* This needs to be after we get the correct handle */
+    oldfont = (HFONT)SendMessage(handle, WM_GETFONT, 0, 0);
+    hfont = _acquire_font(handle, fontname);
+    
+    if (fontname)
+    {
+        if(cinfo)
+        {
+            strcpy(cinfo->fontname, fontname);
+            if(!oldfont)
+                oldfont = cinfo->hfont;
+            cinfo->hfont = hfont;
+        }
+        else
+        {
+            cinfo = calloc(1, sizeof(ColorInfo));
+            cinfo->fore = cinfo->back = -1;
+
+            strcpy(cinfo->fontname, fontname);
+
+            cinfo->pOldProc = SubclassWindow(handle, _colorwndproc);
+            SetWindowLongPtr(handle, GWLP_USERDATA, (LONG_PTR)cinfo);
+        }
+    }
+    SendMessage(handle, WM_SETFONT, (WPARAM)hfont, (LPARAM)TRUE);
+    if(oldfont)
+        DeleteObject(oldfont);
    return 0;
 }
 
@@ -4122,7 +4125,7 @@
    char tmpbuf[100];
 
    GetClassName(handle, tmpbuf, 99);
-   if ( strnicmp( tmpbuf, FRAMECLASSNAME, strlen(FRAMECLASSNAME)) == 0 )
+   if ( strnicmp( tmpbuf, FRAMECLASSNAME, strlen(FRAMECLASSNAME)+1) == 0 )
    {
       /* groupbox */
       thisbox = (Box *)GetWindowLongPtr( handle, GWLP_USERDATA );
@@ -4503,7 +4506,6 @@
                             NULL);
 
    SetWindowLongPtr(hwndframe, GWLP_USERDATA, (LONG_PTR)newbox);
-fprintf(stderr,"in groupbox\n");
    return hwndframe;
 }