more unicode fixes

svn: r964
This commit is contained in:
Matthew Flatt 2005-10-04 16:00:30 +00:00
parent eec8a3ec9a
commit dd555a65e1
13 changed files with 84 additions and 65 deletions

View File

@ -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);
};

View File

@ -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(&currentX, &currentY);
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, &current_width, &cyf,NULL,NULL,font);
GetWindowTextW(button, buf, 300);
GetLabelExtent(wxStripMenuCodes(wxNARROW_STRING(buf)), &current_width, &cyf);
// If we're prepared to use the existing width, then...
if (width == -1 && ((sizeFlags & wxSIZE_AUTO_WIDTH) != wxSIZE_AUTO_WIDTH))

View File

@ -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), &current_width, &cyf,NULL,NULL,font);
GetWindowTextW(button, buf, 300);
GetLabelExtent(wxStripMenuCodes(wxNARROW_STRING(buf)), &current_width, &cyf);
if (width < 0)
width = (int)(current_width + RADIO_SIZE);
if (height<0)

View File

@ -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));

View File

@ -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));

View File

@ -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);

View File

@ -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;
}
}

View File

@ -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();

View File

@ -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, &current_width, &cyf, NULL, NULL,font);
GetWindowTextW((HWND)ms_handle, buf, 300);
GetTextExtent(wxStripMenuCodes(wxNARROW_STRING(buf)), &current_width, &cyf, NULL, NULL,font);
GetSize(&ww, &hh);

View File

@ -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)),
&current_width, &cyf,NULL,NULL, font);
GetLabelExtent(wxStripMenuCodes(wxNARROW_STRING((wchar_t*)wxBuffer)),
&current_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)),
&current_width, &cyf, NULL, NULL, font);
GetLabelExtent(wxStripMenuCodes(wxNARROW_STRING((wchar_t *)wxBuffer)),
&current_width, &cyf);
eachWidth = (int)(current_width + RADIO_SIZE);
eachHeight = (int)cyf;
} else {

View File

@ -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) {

View File

@ -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];

View File

@ -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