diff --git a/src/wxwindow/include/msw/wx_item.h b/src/wxwindow/include/msw/wx_item.h index 94d09b31da..fc5112c6dc 100644 --- a/src/wxwindow/include/msw/wx_item.h +++ b/src/wxwindow/include/msw/wx_item.h @@ -54,6 +54,8 @@ class wxItem: public wxbItem virtual Bool MSWOnDraw(DRAWITEMSTRUCT *WXUNUSED(item)) { return FALSE; }; virtual Bool MSWOnMeasure(MEASUREITEMSTRUCT *WXUNUSED(item)) { return FALSE; }; + void GetLabelExtent(const char *string, double *x, double *y); + void SetFont(wxFont *f); }; diff --git a/src/wxwindow/src/msw/wx_buttn.cxx b/src/wxwindow/src/msw/wx_buttn.cxx index 916a684342..4dd784a590 100644 --- a/src/wxwindow/src/msw/wx_buttn.cxx +++ b/src/wxwindow/src/msw/wx_buttn.cxx @@ -182,7 +182,7 @@ void wxButton::SetSize(int x, int y, int width, int height, int sizeFlags) int ww, hh; double current_width; double cyf; - char buf[300]; + wchar_t buf[300]; GetPosition(¤tX, ¤tY); if (x == -1) @@ -192,8 +192,8 @@ void wxButton::SetSize(int x, int y, int width, int height, int sizeFlags) GetSize(&ww, &hh); - GetWindowText(button, buf, 300); - GetTextExtent(buf, ¤t_width, &cyf,NULL,NULL,font); + GetWindowTextW(button, buf, 300); + GetLabelExtent(wxStripMenuCodes(wxNARROW_STRING(buf)), ¤t_width, &cyf); // If we're prepared to use the existing width, then... if (width == -1 && ((sizeFlags & wxSIZE_AUTO_WIDTH) != wxSIZE_AUTO_WIDTH)) diff --git a/src/wxwindow/src/msw/wx_check.cxx b/src/wxwindow/src/msw/wx_check.cxx index 591a3ab90a..3f4a3b0700 100644 --- a/src/wxwindow/src/msw/wx_check.cxx +++ b/src/wxwindow/src/msw/wx_check.cxx @@ -178,7 +178,7 @@ void wxCheckBox::SetLabel(wxBitmap *bitmap) void wxCheckBox::SetSize(int x, int y, int width, int height, int WXUNUSED(sizeFlags)) { int currentX, currentY; - char buf[300]; + wchar_t buf[300]; double current_width; int cx; int cy; @@ -194,8 +194,8 @@ void wxCheckBox::SetSize(int x, int y, int width, int height, int WXUNUSED(sizeF if (checkWidth < 0) { wxGetCharSize(button, &cx, &cy, font); - GetWindowText(button, buf, 300); - GetTextExtent(wxStripMenuCodes(buf), ¤t_width, &cyf,NULL,NULL,font); + GetWindowTextW(button, buf, 300); + GetLabelExtent(wxStripMenuCodes(wxNARROW_STRING(buf)), ¤t_width, &cyf); if (width < 0) width = (int)(current_width + RADIO_SIZE); if (height<0) diff --git a/src/wxwindow/src/msw/wx_choic.cxx b/src/wxwindow/src/msw/wx_choic.cxx index 123e46d1b9..c5abe90b4a 100644 --- a/src/wxwindow/src/msw/wx_choic.cxx +++ b/src/wxwindow/src/msw/wx_choic.cxx @@ -251,7 +251,7 @@ void wxChoice::SetSize(int x, int y, int width, int height, int sizeFlags) { char *s; s = GetString(i); - GetTextExtent(s, &len, &ht, NULL, NULL,font); + GetLabelExtent(s, &len, &ht); if ( len > longest) longest = len; } @@ -268,8 +268,8 @@ void wxChoice::SetSize(int x, int y, int width, int height, int sizeFlags) // Find size of label wxGetCharSize((HWND)ms_handle, &clx, &cly,font); GetWindowTextW(static_label, (wchar_t *)wxBuffer, 300); - GetTextExtent(wxNARROW_STRING((wchar_t*)wxBuffer), - &label_width, &label_height, NULL, NULL,font); + GetLabelExtent(wxStripMenuCodes(wxNARROW_STRING((wchar_t*)wxBuffer)), + &label_width, &label_height); // Given size is total label + edit size, so find individual // control sizes on that basis. @@ -402,7 +402,7 @@ void wxChoice::SetLabel(char *label) ::ScreenToClient(cparent->handle, &point); } - GetTextExtent(label, &w, &h, NULL, NULL,font); + GetLabelExtent(wxStripMenuCodes(label), &w, &h); MoveWindow(static_label, point.x, point.y, (int)(w + 10), (int)h, TRUE); SetWindowTextW(static_label, wxWIDE_STRING(label)); diff --git a/src/wxwindow/src/msw/wx_gauge.cxx b/src/wxwindow/src/msw/wx_gauge.cxx index f2a6b3248c..559236a979 100644 --- a/src/wxwindow/src/msw/wx_gauge.cxx +++ b/src/wxwindow/src/msw/wx_gauge.cxx @@ -138,8 +138,8 @@ void wxGauge::SetSize(int x, int y, int width, int height, int sizeFlags) // Find size of label wxGetCharSize((HWND)ms_handle, &clx, &cly, font); GetWindowTextW(static_label, (wchar_t *)wxBuffer, 300); - GetTextExtent(wxStripMenuCodes(wxNARROW_STRING((wchar_t *)wxBuffer)), - &label_width, &label_height, NULL, NULL, font); + GetLabelExtent(wxStripMenuCodes(wxNARROW_STRING((wchar_t *)wxBuffer)), + &label_width, &label_height); // Given size is total label + edit size, find individual // control sizes on that basis. @@ -278,7 +278,7 @@ void wxGauge::SetLabel(char *label) ::ScreenToClient(cparent->handle, &point); } - GetTextExtent(label, &w, &h, NULL, NULL, font); + GetLabelExtent(wxStripMenuCodes(label), &w, &h); MoveWindow(static_label, point.x, point.y, (int)(w + 10), (int)h, TRUE); SetWindowTextW(static_label, wxWIDE_STRING(label)); diff --git a/src/wxwindow/src/msw/wx_gdi.cxx b/src/wxwindow/src/msw/wx_gdi.cxx index adaf419b1c..3aa493af99 100644 --- a/src/wxwindow/src/msw/wx_gdi.cxx +++ b/src/wxwindow/src/msw/wx_gdi.cxx @@ -196,6 +196,7 @@ static int glyph_exists_in_selected_font(HDC hdc, int c) typedef struct { HDC hdc; int c; + int just_tt; wchar_t *face; } GlyphFindData; @@ -213,7 +214,12 @@ static int CALLBACK glyph_exists(ENUMLOGFONTW FAR* lpelf, /* This font might work... */ int ok = 1; - if (type == TRUETYPE_FONTTYPE) { + if (gfd->just_tt) + ok = (type == TRUETYPE_FONTTYPE); + else + ok = (type != TRUETYPE_FONTTYPE); + + if (ok && (type == TRUETYPE_FONTTYPE)) { /* Use the unicode bitfield to avoid unnecessary font loading */ DWORD *usb; int x; @@ -258,7 +264,15 @@ Bool wxFont::GlyphAvailable(int c, HDC hdc, int screen_font) gfd.c = c; gfd.face = NULL; - return !EnumFontFamiliesW(hdc, NULL, (FONTENUMPROCW)glyph_exists, (LPARAM)&gfd); + gfd.just_tt = 1; + if (!EnumFontFamiliesW(hdc, NULL, (FONTENUMPROCW)glyph_exists, (LPARAM)&gfd)) + return 1; + + gfd.just_tt = 0; + if (!EnumFontFamiliesW(hdc, NULL, (FONTENUMPROCW)glyph_exists, (LPARAM)&gfd)) + return 1; + + return 0; } Bool wxFont::GlyphAvailableNow(int c, HDC hdc, int screen_font) @@ -338,6 +352,7 @@ wxFont *wxFont::Substitute(int c, HDC dc, Bool screen_font) if (node) sub = (wxFont *)node->Data(); else { + int found; GlyphFindData gfd; wchar_t facebuf[LF_FACESIZE]; @@ -345,7 +360,15 @@ wxFont *wxFont::Substitute(int c, HDC dc, Bool screen_font) gfd.c = c; gfd.face = facebuf; - if (!EnumFontFamiliesW(dc, NULL, (FONTENUMPROCW)glyph_exists, (LPARAM)&gfd)) { + gfd.just_tt = 1; + found = !EnumFontFamiliesW(dc, NULL, (FONTENUMPROCW)glyph_exists, (LPARAM)&gfd); + + if (!found) { + gfd.just_tt = 0; + found = !EnumFontFamiliesW(dc, NULL, (FONTENUMPROCW)glyph_exists, (LPARAM)&gfd); + } + + if (found) { /* Found substitute font */ int sid; sid = wxTheFontNameDirectory->FindOrCreateFontId(wxNARROW_STRING(facebuf), family); diff --git a/src/wxwindow/src/msw/wx_item.cxx b/src/wxwindow/src/msw/wx_item.cxx index 9aebc388bd..0bb8dee688 100644 --- a/src/wxwindow/src/msw/wx_item.cxx +++ b/src/wxwindow/src/msw/wx_item.cxx @@ -538,3 +538,15 @@ int wxGetControlFontSize() { return 8; } + +void wxItem::GetLabelExtent(const char *string, double *x, double *y) +{ + GetTextExtent(string, x, y, NULL, NULL, font); + if (y && ms_handle) { + /* Keep min height consistent, even with substitutions */ + int cx, cy; + wxGetCharSize((HWND)ms_handle, &cx, &cy, font); + if (*y < cy) + *y = cy; + } +} diff --git a/src/wxwindow/src/msw/wx_menu.cxx b/src/wxwindow/src/msw/wx_menu.cxx index 53ce1eae30..2705a80e57 100644 --- a/src/wxwindow/src/msw/wx_menu.cxx +++ b/src/wxwindow/src/msw/wx_menu.cxx @@ -394,7 +394,7 @@ void wxMenu::SetLabel(long Id,char *label) char *wxMenu::GetLabel(long Id) { - static char tmp[128]; + static wchar_t tmp[128]; int len, pos; wxMenuItem *item; HMENU mh; @@ -406,12 +406,12 @@ char *wxMenu::GetLabel(long Id) mh = ms_handle ? (HMENU)ms_handle : (HMENU)save_ms_handle; if (mh) - len = GetMenuString(mh,pos,tmp,127,MF_BYPOSITION); + len = GetMenuStringW(mh,pos,tmp,127,MF_BYPOSITION); else len = 0; tmp[len] = '\0'; - return copystring(tmp); + return copystring(wxNARROW_STRING(tmp)); } BOOL wxMenu::MSWCommand(UINT WXUNUSED(param), WORD menuId) @@ -663,9 +663,9 @@ void wxMenuBar::SetLabelTop(int pos,char *label) HMENU popup; was_flag &= 0xff; popup = GetSubMenu((HMENU)ms_handle,pos); - ModifyMenu((HMENU)ms_handle,pos,MF_BYPOSITION|MF_STRING|was_flag,(UINT)popup,label); + ModifyMenuW((HMENU)ms_handle,pos,MF_BYPOSITION|MF_STRING|was_flag,(UINT)popup,wxWIDE_STRING(label)); } else - ModifyMenu((HMENU)ms_handle,pos,MF_BYPOSITION|MF_STRING|was_flag,pos,label); + ModifyMenuW((HMENU)ms_handle,pos,MF_BYPOSITION|MF_STRING|was_flag,pos,wxWIDE_STRING(label)); if (menu_bar_frame) { menu_bar_frame->DrawMenuBar(); diff --git a/src/wxwindow/src/msw/wx_messg.cxx b/src/wxwindow/src/msw/wx_messg.cxx index 9debe148c2..271a3d3240 100644 --- a/src/wxwindow/src/msw/wx_messg.cxx +++ b/src/wxwindow/src/msw/wx_messg.cxx @@ -156,7 +156,7 @@ void wxMessage::SetSize(int x, int y, int width, int height, int sizeFlags) int currentX, currentY; int actualWidth = width; int actualHeight = height; - char buf[300]; + wchar_t buf[300]; double current_width; double cyf; int ww, hh; @@ -167,8 +167,8 @@ void wxMessage::SetSize(int x, int y, int width, int height, int sizeFlags) if (y == -1) y = currentY; - GetWindowText((HWND)ms_handle, buf, 300); - GetTextExtent(buf, ¤t_width, &cyf, NULL, NULL,font); + GetWindowTextW((HWND)ms_handle, buf, 300); + GetTextExtent(wxStripMenuCodes(wxNARROW_STRING(buf)), ¤t_width, &cyf, NULL, NULL,font); GetSize(&ww, &hh); diff --git a/src/wxwindow/src/msw/wx_rbox.cxx b/src/wxwindow/src/msw/wx_rbox.cxx index 36fcfa91c8..aee3d118b7 100644 --- a/src/wxwindow/src/msw/wx_rbox.cxx +++ b/src/wxwindow/src/msw/wx_rbox.cxx @@ -484,8 +484,8 @@ void wxRadioBox::SetSize(int x, int y, int width, int height, int WXUNUSED(sizeF if ((style & HAS_LABEL)) { int char_width, ignored; GetWindowTextW((HWND)ms_handle, (wchar_t *)wxBuffer, 300); - GetTextExtent(wxStripMenuCodes(wxNARROW_STRING((wchar_t*)wxBuffer)), - &label_width, &label_height, NULL, NULL, font); + GetLabelExtent(wxStripMenuCodes(wxNARROW_STRING((wchar_t*)wxBuffer)), + &label_width, &label_height); wxGetCharSize(wnd, &char_width, &ignored, font); } else { label_height = 0; @@ -498,8 +498,8 @@ void wxRadioBox::SetSize(int x, int y, int width, int height, int WXUNUSED(sizeF if (radioWidth[i] < 0) { // It's a labelled toggle GetWindowTextW(radioButtons[i], (wchar_t *)wxBuffer, 300); - GetTextExtent(wxStripMenuCodes(wxNARROW_STRING((wchar_t*)wxBuffer)), - ¤t_width, &cyf,NULL,NULL, font); + GetLabelExtent(wxStripMenuCodes(wxNARROW_STRING((wchar_t*)wxBuffer)), + ¤t_width, &cyf); eachWidth = (int)(current_width + RADIO_SIZE); eachHeight = (int)cyf; } else { @@ -579,8 +579,8 @@ void wxRadioBox::SetSize(int x, int y, int width, int height, int WXUNUSED(sizeF if (radioWidth[i] < 0) { // It's a labeled item GetWindowTextW(radioButtons[i], (wchar_t *)wxBuffer, 300); - GetTextExtent(wxStripMenuCodes(wxNARROW_STRING((wchar_t *)wxBuffer)), - ¤t_width, &cyf, NULL, NULL, font); + GetLabelExtent(wxStripMenuCodes(wxNARROW_STRING((wchar_t *)wxBuffer)), + ¤t_width, &cyf); eachWidth = (int)(current_width + RADIO_SIZE); eachHeight = (int)cyf; } else { diff --git a/src/wxwindow/src/msw/wx_slidr.cxx b/src/wxwindow/src/msw/wx_slidr.cxx index 849191c8d9..81dee5b436 100644 --- a/src/wxwindow/src/msw/wx_slidr.cxx +++ b/src/wxwindow/src/msw/wx_slidr.cxx @@ -300,7 +300,7 @@ void wxSlider::SetLabel(char *label) ::ScreenToClient(cparent->handle, &point); } - GetTextExtent(label, &w, &h, NULL, NULL,font); + GetLabelExtent(wxStripMenuCodes(label), &w, &h); MoveWindow(static_label, point.x, point.y, (int)(w + 10), (int)h, TRUE); SetWindowTextW(static_label, wxWIDE_STRING(label)); @@ -431,7 +431,7 @@ void wxSlider::SetSize(int x, int y, int width, int height, int sizeFlags) wchar_t wbuf[300]; wxGetCharSize((HWND)ms_handle, &cxs, &cys, font); GetWindowTextW(static_label, wbuf, 300); - GetTextExtent(wxStripMenuCodes(wxNARROW_STRING(wbuf)), &label_width, &cyf, NULL, NULL, font); + GetLabelExtent(wxStripMenuCodes(wxNARROW_STRING(wbuf)), &label_width, &cyf); } if ((windowStyle & wxVERTICAL) != wxVERTICAL) { diff --git a/src/wxwindow/src/msw/wx_win.cxx b/src/wxwindow/src/msw/wx_win.cxx index b332fb9fe9..f1b792bdf9 100644 --- a/src/wxwindow/src/msw/wx_win.cxx +++ b/src/wxwindow/src/msw/wx_win.cxx @@ -704,48 +704,26 @@ Bool wxWindow::Show(Bool show) return TRUE; } +static wxMemoryDC *measure_dc; + void wxWindow::GetTextExtent(const char *string, double *x, double *y, double *descent, double *externalLeading, wxFont *theFont, Bool use16bit) { wxFont *fontToUse = theFont; - HWND hWnd; - HDC dc; - HFONT fnt = 0; - HFONT was = 0; - SIZE sizeRect; - TEXTMETRIC tm; - int len; - wchar_t *ws; if (!fontToUse) fontToUse = font; - - hWnd = GetHWND(); - dc = wxwmGetDC(hWnd); - if (fontToUse && (fnt = fontToUse->GetInternalFont(dc))) - was = (HFONT)SelectObject(dc, fnt); - else { - fnt = (HFONT)SendMessage(hWnd, WM_GETFONT, 0, 0L); - if (fnt) - was = (HFONT)SelectObject(dc, fnt); + if (!measure_dc) { + wxBitmap *bm; + wxREGGLOB(measure_dc); + bm = new wxBitmap(1, 1, 0); + measure_dc = new wxMemoryDC(); + measure_dc->SelectObject(bm); } - ws = wxWIDE_STRING((char *)string); - len = wx_wstrlen(ws); - GetTextExtentPointW(dc, len ? ws : L" ", len ? len : 1, &sizeRect); - GetTextMetrics(dc, &tm); - - if (fontToUse && fnt && was) - SelectObject(dc,was); - - wxwmReleaseDC(hWnd, dc); - - *x = (len ? (double)sizeRect.cx : (double)0.0); - *y = (double)sizeRect.cy; - if (descent) *descent = (double)tm.tmDescent; - if (externalLeading) *externalLeading = (double)tm.tmExternalLeading; + measure_dc->GetTextExtent(string, x, y, descent, externalLeading, fontToUse, 1, use16bit); } void wxWindow::Refresh(void) @@ -1449,8 +1427,8 @@ void wxWnd::Create(wxWnd *parent, char *wclass, wxWindow *wx_win, char *title, if (is_dialog) { /* Creating a dialog */ - handle = ::CreateDialog(wxhInstance, dialog_template, hParent, - (DLGPROC)wxDlgProc); + handle = ::CreateDialogW(wxhInstance, wxWIDE_STRING(dialog_template), hParent, + (DLGPROC)wxDlgProc); if (handle == 0) { char buf[300]; diff --git a/src/wxwindow/src/msw/wximgfil.cxx b/src/wxwindow/src/msw/wximgfil.cxx index f250809f49..438172f643 100644 --- a/src/wxwindow/src/msw/wximgfil.cxx +++ b/src/wxwindow/src/msw/wximgfil.cxx @@ -488,6 +488,10 @@ ushort wxGIF::decoder(ushort linewidth) { stack[sp++] = suffix[code]; code = prefix[code]; + if (code >= slot) { + ++bad_code_count; + code = oc; + } } /* Push the last character on the stack, and set up the new