# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1056408618 0 # Node ID dd04a4d781f8c158784dd0b1834d4161723d73a3 # Parent f1f188c678f3bc93f70246386800283a5bd24c84 Fixes GDI font object leak when calling dw_window_set_font() on render widgets (perhaps others as well) on Windows. diff -r f1f188c678f3 -r dd04a4d781f8 dw.h --- a/dw.h Mon Jun 23 17:24:54 2003 +0000 +++ b/dw.h Mon Jun 23 22:50:18 2003 +0000 @@ -433,6 +433,7 @@ int vcenter; HWND clickdefault; HBRUSH hbrush; + HFONT hfont; char fontname[128]; WNDPROC pOldProc; UserData *root; diff -r f1f188c678f3 -r dd04a4d781f8 win/dw.c --- a/win/dw.c Mon Jun 23 17:24:54 2003 +0000 +++ b/win/dw.c Mon Jun 23 22:50:18 2003 +0000 @@ -3448,6 +3448,9 @@ if(cinfo) { strcpy(cinfo->fontname, fontname); + if(!oldfont) + oldfont = cinfo->hfont; + cinfo->hfont = hfont; } else { @@ -6918,8 +6921,9 @@ { HDC hdc; int size = 9, z, mustdelete = 0; - HFONT hFont, oldFont; + HFONT hFont = 0, oldFont = 0; int threadid = dw_thread_id(); + ColorInfo *cinfo; if(threadid < 0 || threadid >= THREAD_LIMIT) threadid = 0; @@ -6931,21 +6935,19 @@ else return; - { - ColorInfo *cinfo; - - if(handle) - cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); - else - cinfo = (ColorInfo *)GetWindowLongPtr(pixmap->handle, GWLP_USERDATA); - - if(cinfo) - { - hFont = _acquire_font(handle, cinfo->fontname); - mustdelete = 1; - } - } - oldFont = SelectObject(hdc, hFont); + if(handle) + cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); + else + cinfo = (ColorInfo *)GetWindowLongPtr(pixmap->handle, GWLP_USERDATA); + + if(cinfo) + { + hFont = _acquire_font(handle, cinfo->fontname); + mustdelete = 1; + } + + if(hFont) + oldFont = SelectObject(hdc, hFont); SetTextColor(hdc, _foreground[threadid]); if(_background[threadid] == DW_RGB_TRANSPARENT) SetBkMode(hdc, TRANSPARENT); @@ -6955,7 +6957,8 @@ SetBkColor(hdc, _background[threadid]); } TextOut(hdc, x, y, text, strlen(text)); - SelectObject(hdc, oldFont); + if(oldFont) + SelectObject(hdc, oldFont); if(mustdelete) DeleteObject(hFont); if(!pixmap)