comparison win/dw.c @ 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
comparison
equal deleted inserted replaced
454:f1f188c678f3 455:dd04a4d781f8
3446 if(fontname) 3446 if(fontname)
3447 { 3447 {
3448 if(cinfo) 3448 if(cinfo)
3449 { 3449 {
3450 strcpy(cinfo->fontname, fontname); 3450 strcpy(cinfo->fontname, fontname);
3451 if(!oldfont)
3452 oldfont = cinfo->hfont;
3453 cinfo->hfont = hfont;
3451 } 3454 }
3452 else 3455 else
3453 { 3456 {
3454 cinfo = calloc(1, sizeof(ColorInfo)); 3457 cinfo = calloc(1, sizeof(ColorInfo));
3455 cinfo->fore = cinfo->back = -1; 3458 cinfo->fore = cinfo->back = -1;
6916 */ 6919 */
6917 void API dw_draw_text(HWND handle, HPIXMAP pixmap, int x, int y, char *text) 6920 void API dw_draw_text(HWND handle, HPIXMAP pixmap, int x, int y, char *text)
6918 { 6921 {
6919 HDC hdc; 6922 HDC hdc;
6920 int size = 9, z, mustdelete = 0; 6923 int size = 9, z, mustdelete = 0;
6921 HFONT hFont, oldFont; 6924 HFONT hFont = 0, oldFont = 0;
6922 int threadid = dw_thread_id(); 6925 int threadid = dw_thread_id();
6926 ColorInfo *cinfo;
6923 6927
6924 if(threadid < 0 || threadid >= THREAD_LIMIT) 6928 if(threadid < 0 || threadid >= THREAD_LIMIT)
6925 threadid = 0; 6929 threadid = 0;
6926 6930
6927 if(handle) 6931 if(handle)
6929 else if(pixmap) 6933 else if(pixmap)
6930 hdc = pixmap->hdc; 6934 hdc = pixmap->hdc;
6931 else 6935 else
6932 return; 6936 return;
6933 6937
6934 { 6938 if(handle)
6935 ColorInfo *cinfo; 6939 cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA);
6936 6940 else
6937 if(handle) 6941 cinfo = (ColorInfo *)GetWindowLongPtr(pixmap->handle, GWLP_USERDATA);
6938 cinfo = (ColorInfo *)GetWindowLongPtr(handle, GWLP_USERDATA); 6942
6939 else 6943 if(cinfo)
6940 cinfo = (ColorInfo *)GetWindowLongPtr(pixmap->handle, GWLP_USERDATA); 6944 {
6941 6945 hFont = _acquire_font(handle, cinfo->fontname);
6942 if(cinfo) 6946 mustdelete = 1;
6943 { 6947 }
6944 hFont = _acquire_font(handle, cinfo->fontname); 6948
6945 mustdelete = 1; 6949 if(hFont)
6946 } 6950 oldFont = SelectObject(hdc, hFont);
6947 }
6948 oldFont = SelectObject(hdc, hFont);
6949 SetTextColor(hdc, _foreground[threadid]); 6951 SetTextColor(hdc, _foreground[threadid]);
6950 if(_background[threadid] == DW_RGB_TRANSPARENT) 6952 if(_background[threadid] == DW_RGB_TRANSPARENT)
6951 SetBkMode(hdc, TRANSPARENT); 6953 SetBkMode(hdc, TRANSPARENT);
6952 else 6954 else
6953 { 6955 {
6954 SetBkMode(hdc, OPAQUE); 6956 SetBkMode(hdc, OPAQUE);
6955 SetBkColor(hdc, _background[threadid]); 6957 SetBkColor(hdc, _background[threadid]);
6956 } 6958 }
6957 TextOut(hdc, x, y, text, strlen(text)); 6959 TextOut(hdc, x, y, text, strlen(text));
6958 SelectObject(hdc, oldFont); 6960 if(oldFont)
6961 SelectObject(hdc, oldFont);
6959 if(mustdelete) 6962 if(mustdelete)
6960 DeleteObject(hFont); 6963 DeleteObject(hFont);
6961 if(!pixmap) 6964 if(!pixmap)
6962 ReleaseDC(handle, hdc); 6965 ReleaseDC(handle, hdc);
6963 } 6966 }