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 MSWOnDraw(DRAWITEMSTRUCT *WXUNUSED(item)) { return FALSE; };
virtual Bool MSWOnMeasure(MEASUREITEMSTRUCT *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); 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; int ww, hh;
double current_width; double current_width;
double cyf; double cyf;
char buf[300]; wchar_t buf[300];
GetPosition(&currentX, &currentY); GetPosition(&currentX, &currentY);
if (x == -1) if (x == -1)
@ -192,8 +192,8 @@ void wxButton::SetSize(int x, int y, int width, int height, int sizeFlags)
GetSize(&ww, &hh); GetSize(&ww, &hh);
GetWindowText(button, buf, 300); GetWindowTextW(button, buf, 300);
GetTextExtent(buf, &current_width, &cyf,NULL,NULL,font); GetLabelExtent(wxStripMenuCodes(wxNARROW_STRING(buf)), &current_width, &cyf);
// If we're prepared to use the existing width, then... // If we're prepared to use the existing width, then...
if (width == -1 && ((sizeFlags & wxSIZE_AUTO_WIDTH) != wxSIZE_AUTO_WIDTH)) 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)) void wxCheckBox::SetSize(int x, int y, int width, int height, int WXUNUSED(sizeFlags))
{ {
int currentX, currentY; int currentX, currentY;
char buf[300]; wchar_t buf[300];
double current_width; double current_width;
int cx; int cx;
int cy; int cy;
@ -194,8 +194,8 @@ void wxCheckBox::SetSize(int x, int y, int width, int height, int WXUNUSED(sizeF
if (checkWidth < 0) { if (checkWidth < 0) {
wxGetCharSize(button, &cx, &cy, font); wxGetCharSize(button, &cx, &cy, font);
GetWindowText(button, buf, 300); GetWindowTextW(button, buf, 300);
GetTextExtent(wxStripMenuCodes(buf), &current_width, &cyf,NULL,NULL,font); GetLabelExtent(wxStripMenuCodes(wxNARROW_STRING(buf)), &current_width, &cyf);
if (width < 0) if (width < 0)
width = (int)(current_width + RADIO_SIZE); width = (int)(current_width + RADIO_SIZE);
if (height<0) if (height<0)

View File

@ -251,7 +251,7 @@ void wxChoice::SetSize(int x, int y, int width, int height, int sizeFlags)
{ {
char *s; char *s;
s = GetString(i); s = GetString(i);
GetTextExtent(s, &len, &ht, NULL, NULL,font); GetLabelExtent(s, &len, &ht);
if ( len > longest) longest = len; 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 // Find size of label
wxGetCharSize((HWND)ms_handle, &clx, &cly,font); wxGetCharSize((HWND)ms_handle, &clx, &cly,font);
GetWindowTextW(static_label, (wchar_t *)wxBuffer, 300); GetWindowTextW(static_label, (wchar_t *)wxBuffer, 300);
GetTextExtent(wxNARROW_STRING((wchar_t*)wxBuffer), GetLabelExtent(wxStripMenuCodes(wxNARROW_STRING((wchar_t*)wxBuffer)),
&label_width, &label_height, NULL, NULL,font); &label_width, &label_height);
// Given size is total label + edit size, so find individual // Given size is total label + edit size, so find individual
// control sizes on that basis. // control sizes on that basis.
@ -402,7 +402,7 @@ void wxChoice::SetLabel(char *label)
::ScreenToClient(cparent->handle, &point); ::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, MoveWindow(static_label, point.x, point.y, (int)(w + 10), (int)h,
TRUE); TRUE);
SetWindowTextW(static_label, wxWIDE_STRING(label)); 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 // Find size of label
wxGetCharSize((HWND)ms_handle, &clx, &cly, font); wxGetCharSize((HWND)ms_handle, &clx, &cly, font);
GetWindowTextW(static_label, (wchar_t *)wxBuffer, 300); GetWindowTextW(static_label, (wchar_t *)wxBuffer, 300);
GetTextExtent(wxStripMenuCodes(wxNARROW_STRING((wchar_t *)wxBuffer)), GetLabelExtent(wxStripMenuCodes(wxNARROW_STRING((wchar_t *)wxBuffer)),
&label_width, &label_height, NULL, NULL, font); &label_width, &label_height);
// Given size is total label + edit size, find individual // Given size is total label + edit size, find individual
// control sizes on that basis. // control sizes on that basis.
@ -278,7 +278,7 @@ void wxGauge::SetLabel(char *label)
::ScreenToClient(cparent->handle, &point); ::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, MoveWindow(static_label, point.x, point.y, (int)(w + 10), (int)h,
TRUE); TRUE);
SetWindowTextW(static_label, wxWIDE_STRING(label)); 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 { typedef struct {
HDC hdc; HDC hdc;
int c; int c;
int just_tt;
wchar_t *face; wchar_t *face;
} GlyphFindData; } GlyphFindData;
@ -213,7 +214,12 @@ static int CALLBACK glyph_exists(ENUMLOGFONTW FAR* lpelf,
/* This font might work... */ /* This font might work... */
int ok = 1; 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 */ /* Use the unicode bitfield to avoid unnecessary font loading */
DWORD *usb; DWORD *usb;
int x; int x;
@ -258,7 +264,15 @@ Bool wxFont::GlyphAvailable(int c, HDC hdc, int screen_font)
gfd.c = c; gfd.c = c;
gfd.face = NULL; 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) 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) if (node)
sub = (wxFont *)node->Data(); sub = (wxFont *)node->Data();
else { else {
int found;
GlyphFindData gfd; GlyphFindData gfd;
wchar_t facebuf[LF_FACESIZE]; wchar_t facebuf[LF_FACESIZE];
@ -345,7 +360,15 @@ wxFont *wxFont::Substitute(int c, HDC dc, Bool screen_font)
gfd.c = c; gfd.c = c;
gfd.face = facebuf; 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 */ /* Found substitute font */
int sid; int sid;
sid = wxTheFontNameDirectory->FindOrCreateFontId(wxNARROW_STRING(facebuf), family); sid = wxTheFontNameDirectory->FindOrCreateFontId(wxNARROW_STRING(facebuf), family);

View File

@ -538,3 +538,15 @@ int wxGetControlFontSize()
{ {
return 8; 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) char *wxMenu::GetLabel(long Id)
{ {
static char tmp[128]; static wchar_t tmp[128];
int len, pos; int len, pos;
wxMenuItem *item; wxMenuItem *item;
HMENU mh; HMENU mh;
@ -406,12 +406,12 @@ char *wxMenu::GetLabel(long Id)
mh = ms_handle ? (HMENU)ms_handle : (HMENU)save_ms_handle; mh = ms_handle ? (HMENU)ms_handle : (HMENU)save_ms_handle;
if (mh) if (mh)
len = GetMenuString(mh,pos,tmp,127,MF_BYPOSITION); len = GetMenuStringW(mh,pos,tmp,127,MF_BYPOSITION);
else else
len = 0; len = 0;
tmp[len] = '\0'; tmp[len] = '\0';
return copystring(tmp); return copystring(wxNARROW_STRING(tmp));
} }
BOOL wxMenu::MSWCommand(UINT WXUNUSED(param), WORD menuId) BOOL wxMenu::MSWCommand(UINT WXUNUSED(param), WORD menuId)
@ -663,9 +663,9 @@ void wxMenuBar::SetLabelTop(int pos,char *label)
HMENU popup; HMENU popup;
was_flag &= 0xff; was_flag &= 0xff;
popup = GetSubMenu((HMENU)ms_handle,pos); 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 } 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) { if (menu_bar_frame) {
menu_bar_frame->DrawMenuBar(); 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 currentX, currentY;
int actualWidth = width; int actualWidth = width;
int actualHeight = height; int actualHeight = height;
char buf[300]; wchar_t buf[300];
double current_width; double current_width;
double cyf; double cyf;
int ww, hh; int ww, hh;
@ -167,8 +167,8 @@ void wxMessage::SetSize(int x, int y, int width, int height, int sizeFlags)
if (y == -1) if (y == -1)
y = currentY; y = currentY;
GetWindowText((HWND)ms_handle, buf, 300); GetWindowTextW((HWND)ms_handle, buf, 300);
GetTextExtent(buf, &current_width, &cyf, NULL, NULL,font); GetTextExtent(wxStripMenuCodes(wxNARROW_STRING(buf)), &current_width, &cyf, NULL, NULL,font);
GetSize(&ww, &hh); 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)) { if ((style & HAS_LABEL)) {
int char_width, ignored; int char_width, ignored;
GetWindowTextW((HWND)ms_handle, (wchar_t *)wxBuffer, 300); GetWindowTextW((HWND)ms_handle, (wchar_t *)wxBuffer, 300);
GetTextExtent(wxStripMenuCodes(wxNARROW_STRING((wchar_t*)wxBuffer)), GetLabelExtent(wxStripMenuCodes(wxNARROW_STRING((wchar_t*)wxBuffer)),
&label_width, &label_height, NULL, NULL, font); &label_width, &label_height);
wxGetCharSize(wnd, &char_width, &ignored, font); wxGetCharSize(wnd, &char_width, &ignored, font);
} else { } else {
label_height = 0; 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) { if (radioWidth[i] < 0) {
// It's a labelled toggle // It's a labelled toggle
GetWindowTextW(radioButtons[i], (wchar_t *)wxBuffer, 300); GetWindowTextW(radioButtons[i], (wchar_t *)wxBuffer, 300);
GetTextExtent(wxStripMenuCodes(wxNARROW_STRING((wchar_t*)wxBuffer)), GetLabelExtent(wxStripMenuCodes(wxNARROW_STRING((wchar_t*)wxBuffer)),
&current_width, &cyf,NULL,NULL, font); &current_width, &cyf);
eachWidth = (int)(current_width + RADIO_SIZE); eachWidth = (int)(current_width + RADIO_SIZE);
eachHeight = (int)cyf; eachHeight = (int)cyf;
} else { } else {
@ -579,8 +579,8 @@ void wxRadioBox::SetSize(int x, int y, int width, int height, int WXUNUSED(sizeF
if (radioWidth[i] < 0) { if (radioWidth[i] < 0) {
// It's a labeled item // It's a labeled item
GetWindowTextW(radioButtons[i], (wchar_t *)wxBuffer, 300); GetWindowTextW(radioButtons[i], (wchar_t *)wxBuffer, 300);
GetTextExtent(wxStripMenuCodes(wxNARROW_STRING((wchar_t *)wxBuffer)), GetLabelExtent(wxStripMenuCodes(wxNARROW_STRING((wchar_t *)wxBuffer)),
&current_width, &cyf, NULL, NULL, font); &current_width, &cyf);
eachWidth = (int)(current_width + RADIO_SIZE); eachWidth = (int)(current_width + RADIO_SIZE);
eachHeight = (int)cyf; eachHeight = (int)cyf;
} else { } else {

View File

@ -300,7 +300,7 @@ void wxSlider::SetLabel(char *label)
::ScreenToClient(cparent->handle, &point); ::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, MoveWindow(static_label, point.x, point.y, (int)(w + 10), (int)h,
TRUE); TRUE);
SetWindowTextW(static_label, wxWIDE_STRING(label)); 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]; wchar_t wbuf[300];
wxGetCharSize((HWND)ms_handle, &cxs, &cys, font); wxGetCharSize((HWND)ms_handle, &cxs, &cys, font);
GetWindowTextW(static_label, wbuf, 300); 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) { if ((windowStyle & wxVERTICAL) != wxVERTICAL) {

View File

@ -704,48 +704,26 @@ Bool wxWindow::Show(Bool show)
return TRUE; return TRUE;
} }
static wxMemoryDC *measure_dc;
void wxWindow::GetTextExtent(const char *string, double *x, double *y, void wxWindow::GetTextExtent(const char *string, double *x, double *y,
double *descent, double *externalLeading, double *descent, double *externalLeading,
wxFont *theFont, Bool use16bit) wxFont *theFont, Bool use16bit)
{ {
wxFont *fontToUse = theFont; wxFont *fontToUse = theFont;
HWND hWnd;
HDC dc;
HFONT fnt = 0;
HFONT was = 0;
SIZE sizeRect;
TEXTMETRIC tm;
int len;
wchar_t *ws;
if (!fontToUse) if (!fontToUse)
fontToUse = font; fontToUse = font;
hWnd = GetHWND(); if (!measure_dc) {
dc = wxwmGetDC(hWnd); wxBitmap *bm;
wxREGGLOB(measure_dc);
if (fontToUse && (fnt = fontToUse->GetInternalFont(dc))) bm = new wxBitmap(1, 1, 0);
was = (HFONT)SelectObject(dc, fnt); measure_dc = new wxMemoryDC();
else { measure_dc->SelectObject(bm);
fnt = (HFONT)SendMessage(hWnd, WM_GETFONT, 0, 0L);
if (fnt)
was = (HFONT)SelectObject(dc, fnt);
} }
ws = wxWIDE_STRING((char *)string); measure_dc->GetTextExtent(string, x, y, descent, externalLeading, fontToUse, 1, use16bit);
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;
} }
void wxWindow::Refresh(void) void wxWindow::Refresh(void)
@ -1449,8 +1427,8 @@ void wxWnd::Create(wxWnd *parent, char *wclass, wxWindow *wx_win, char *title,
if (is_dialog) { if (is_dialog) {
/* Creating a dialog */ /* Creating a dialog */
handle = ::CreateDialog(wxhInstance, dialog_template, hParent, handle = ::CreateDialogW(wxhInstance, wxWIDE_STRING(dialog_template), hParent,
(DLGPROC)wxDlgProc); (DLGPROC)wxDlgProc);
if (handle == 0) { if (handle == 0) {
char buf[300]; char buf[300];

View File

@ -488,6 +488,10 @@ ushort wxGIF::decoder(ushort linewidth)
{ {
stack[sp++] = suffix[code]; stack[sp++] = suffix[code];
code = prefix[code]; code = prefix[code];
if (code >= slot) {
++bad_code_count;
code = oc;
}
} }
/* Push the last character on the stack, and set up the new /* Push the last character on the stack, and set up the new