summaryrefslogtreecommitdiff
path: root/src/fl_font_win32.cxx
diff options
context:
space:
mode:
authorFabien Costantini <fabien@onepost.net>2008-12-04 17:33:30 +0000
committerFabien Costantini <fabien@onepost.net>2008-12-04 17:33:30 +0000
commit899184656a08484f2a0afcdf87796a042f1dba63 (patch)
tree4cb4797040c656c50c7583b7f936ea9e145f2bad /src/fl_font_win32.cxx
parent73a2fa5b99fda883323cd53346f564c14060a01d (diff)
STR#2086 related Fixes :
This one was really tough to track, understand: In fact, the problem was comming from the misplacement of the menu window, which itself came from invalid measurement, which itself came from invalid fl_witdh() measurement, but only when fl_gc is not valid because fl_width() relies on Win32 on the call of GetTextExtentPoint32W which can't succeed if the HDC(here fl_gc) is not valid ! Now the fix: A best-effort algorithm has been furthered to supply a valid fltk hdc if we can have one or a screen hdc if no fltk window is found by fl::first_window(). Note that when fl_gc is NULL inside fl_width() call, it can happen that Fl_Window::current() is not null but invalid (already deleted). Finally, in the case of the buggy menu window observed here, this fl_gc was set to NULL just after an Fl_Menu_Window deletion and re-creation in Fl_Menu_Item::pulldown(). Also added a comment to describe the new fl_width() behavior. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6540 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/fl_font_win32.cxx')
-rw-r--r--src/fl_font_win32.cxx15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/fl_font_win32.cxx b/src/fl_font_win32.cxx
index 42ca214d3..0155dfcea 100644
--- a/src/fl_font_win32.cxx
+++ b/src/fl_font_win32.cxx
@@ -182,11 +182,24 @@ double fl_width(unsigned int c) {
fl_fontsize->width[r] = (int*) malloc(sizeof(int) * 0x0400);
SIZE s;
unsigned short i = 0, ii = r * 0x400;
+ // The following code is a best effort algorithm to further a valid fl_gc
+ // if no fl_gc is available at the time we call fl_width()
+ // We first choose a gc from the first fltk window,
+ // if it is null then the gc from the current screen (GetDC(NULL)).
+ // This should solve STR #2086
+ HDC gc = fl_gc;
+ HWND hWnd = 0;
+ if (!gc) {
+ gc = GetDC(hWnd);
+ }
+ if (!gc)
+ Fl::fatal("Invalid graphic context: fl_width() failed because no valid HDC was found!");
for (; i < 0x400; i++) {
- GetTextExtentPoint32W(fl_gc, (WCHAR*)&ii, 1, &s);
+ GetTextExtentPoint32W(gc, (WCHAR*)&ii, 1, &s);
fl_fontsize->width[r][i] = s.cx;
ii++;
}
+ if (gc && gc!=fl_gc) ReleaseDC(hWnd, gc);
}
return (double) fl_fontsize->width[r][c & 0x03FF];
}