Mercurial > dwindows
changeset 455:dd04a4d781f8
Fixes GDI font object leak when calling dw_window_set_font() on
render widgets (perhaps others as well) on Windows.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Mon, 23 Jun 2003 22:50:18 +0000 |
parents | f1f188c678f3 |
children | 935436731b41 |
files | dw.h win/dw.c |
diffstat | 2 files changed, 21 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- 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;
--- 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)