# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1306400762 0 # Node ID 860d6e73f8bb0a5ef09c145f6b4acdd8cf42cc3d # Parent 2c2fcfeeffcc892484d9692793bb77353073a9ef Attempt at fixing dw_window_set/get_font() on Groupboxes on Windows. diff -r 2c2fcfeeffcc -r 860d6e73f8bb win/dw.c --- 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; }