From: Vadim Zeitlin Date: Mon, 10 Apr 2006 22:22:13 +0000 (+0000) Subject: use the encoding of the font which is used to draw the text when convering it to... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/5f11fef5435283f9d2465f7eaccdd72d2f3fb1ef use the encoding of the font which is used to draw the text when convering it to UTF-8 in wxGTK_CONV; the old wxGTK_CONV renamed to wxGTK_CONV_SYS (uses system encoding) and used in the contexts where no font is available git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38661 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index e24ae287c8..5c760e6de0 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -163,6 +163,7 @@ wxMSW: wxGTK: +- Fixed handling of font encoding in non-Unicode build - wxEVT_MENU_CLOSE and wxEVT_MENU_OPENED for popup menus are now generated. - Implemented wxCURSOR_BLANK support. - wxSlider generates all scroll events now and not only wxEVT_SCROLL_THUMBTRACK. diff --git a/include/wx/gtk/private.h b/include/wx/gtk/private.h index 2ce2865725..f3219f75a1 100644 --- a/include/wx/gtk/private.h +++ b/include/wx/gtk/private.h @@ -24,10 +24,24 @@ #if wxUSE_UNICODE #define wxGTK_CONV(s) wxConvUTF8.cWX2MB(s) + #define wxGTK_CONV_SYS(s, enc) wxGTK_CONV(s) #define wxGTK_CONV_BACK(s) wxConvUTF8.cMB2WX(s) #else - #define wxGTK_CONV(s) wxConvUTF8.cWC2MB( wxConvLocal.cWX2WC(s) ) - #define wxGTK_CONV_BACK(s) wxConvLocal.cWC2WX( (wxConvUTF8.cMB2WC( s ) ) ) + // convert the text in given encoding to UTF-8 used by wxGTK + extern wxCharBuffer + wxConvertToGTK(const wxString& s, + wxFontEncoding enc = wxFONTENCODING_SYSTEM); + + // helper: use the encoding of the given font if it's valid + inline wxCharBuffer wxConvertToGTK(const wxString& s, const wxFont& font) + { + return wxConvertToGTK(s, font.Ok() ? font.GetEncoding() + : wxFONTENCODING_SYSTEM); + } + + #define wxGTK_CONV(s) wxConvertToGTK((s), m_font) + #define wxGTK_CONV_SYS(s) wxConvertToGTK(s) + #define wxGTK_CONV_BACK(s) wxConvLocal.cWC2WX( wxConvUTF8.cMB2WC((s)) ) #endif // Some deprecated GTK+ prototypes we still use often diff --git a/src/gtk/colour.cpp b/src/gtk/colour.cpp index ff7c526c45..d43c586444 100644 --- a/src/gtk/colour.cpp +++ b/src/gtk/colour.cpp @@ -96,7 +96,7 @@ wxColour wxColour::CreateByName(const wxString& name) wxColour col; GdkColor colGDK; - if ( gdk_color_parse( wxGTK_CONV( name ), &colGDK ) ) + if ( gdk_color_parse( wxGTK_CONV_SYS( name ), &colGDK ) ) { wxColourRefData *refData = new wxColourRefData; refData->m_color = colGDK; diff --git a/src/gtk/font.cpp b/src/gtk/font.cpp index 04da6ccac7..30330dd02d 100644 --- a/src/gtk/font.cpp +++ b/src/gtk/font.cpp @@ -116,7 +116,7 @@ private: m_weight; bool m_underlined; wxString m_faceName; - wxFontEncoding m_encoding; // Unused under GTK 2.0 + wxFontEncoding m_encoding; bool m_noAA; // No anti-aliasing // The native font info, basicly an XFLD under GTK 1.2 and @@ -163,7 +163,8 @@ void wxFontRefData::Init(int pointSize, // And set its values if (!m_faceName.empty()) { - pango_font_description_set_family( m_nativeFontInfo.description, wxGTK_CONV(m_faceName) ); + pango_font_description_set_family( m_nativeFontInfo.description, + wxGTK_CONV_SYS(m_faceName) ); } else { @@ -228,8 +229,8 @@ void wxFontRefData::InitFromNative() // Pango description are never underlined (?) m_underlined = FALSE; - // Cannot we choose that - m_encoding = wxFONTENCODING_SYSTEM; + // always with GTK+ 2 + m_encoding = wxFONTENCODING_UTF8; } wxFontRefData::wxFontRefData( const wxFontRefData& data ) @@ -485,15 +486,14 @@ bool wxFont::GetUnderlined() const wxFontEncoding wxFont::GetEncoding() const { - wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT, wxT("invalid font") ); + wxCHECK_MSG( Ok(), wxFONTENCODING_SYSTEM, wxT("invalid font") ); - // m_encoding is unused in wxGTK2, return encoding that the user set. return M_FONTDATA->m_encoding; } bool wxFont::GetNoAntiAliasing() const { - wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT, wxT("invalid font") ); + wxCHECK_MSG( Ok(), false, wxT("invalid font") ); return M_FONTDATA->m_noAA; } diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index 08dae1a867..f02968fc17 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -747,7 +747,7 @@ void wxMenuItem::SetText( const wxString& str ) oldLabel.Replace(wxT("_"), wxT("")); wxString label1 = wxStripMenuCodes(str); wxString oldhotkey = GetHotKey(); // Store the old hotkey in Ctrl-foo format - wxCharBuffer oldbuf = wxGTK_CONV( GetGtkHotKey(*this) ); // and as foo + wxCharBuffer oldbuf = wxGTK_CONV_SYS( GetGtkHotKey(*this) ); // and as foo DoSetText(str); @@ -763,7 +763,7 @@ void wxMenuItem::SetText( const wxString& str ) else label = GTK_LABEL( GTK_BIN(m_menuItem)->child ); - gtk_label_set_text_with_mnemonic( GTK_LABEL(label), wxGTK_CONV(m_text) ); + gtk_label_set_text_with_mnemonic( GTK_LABEL(label), wxGTK_CONV_SYS(m_text) ); } guint accel_key; @@ -777,7 +777,7 @@ void wxMenuItem::SetText( const wxString& str ) accel_mods ); } - wxCharBuffer buf = wxGTK_CONV( GetGtkHotKey(*this) ); + wxCharBuffer buf = wxGTK_CONV_SYS( GetGtkHotKey(*this) ); gtk_accelerator_parse( (const char*) buf, &accel_key, &accel_mods); if (accel_key != 0) { @@ -954,7 +954,7 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos) text = mitem->GetText(); const wxBitmap *bitmap = &mitem->GetBitmap(); - menuItem = gtk_image_menu_item_new_with_mnemonic( wxGTK_CONV( text ) ); + menuItem = gtk_image_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text ) ); GtkWidget *image; if (bitmap->HasPixbuf()) @@ -985,7 +985,7 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos) { case wxITEM_CHECK: { - menuItem = gtk_check_menu_item_new_with_mnemonic( wxGTK_CONV( text ) ); + menuItem = gtk_check_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text ) ); m_prevRadio = NULL; break; } @@ -996,12 +996,14 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos) if ( m_prevRadio == NULL ) { // start of a new radio group - m_prevRadio = menuItem = gtk_radio_menu_item_new_with_mnemonic( group, wxGTK_CONV( text ) ); + m_prevRadio = menuItem = + gtk_radio_menu_item_new_with_mnemonic( group, wxGTK_CONV_SYS( text ) ); } else // continue the radio group { group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (m_prevRadio)); - m_prevRadio = menuItem = gtk_radio_menu_item_new_with_mnemonic( group, wxGTK_CONV( text ) ); + m_prevRadio = menuItem = + gtk_radio_menu_item_new_with_mnemonic( group, wxGTK_CONV_SYS( text ) ); } break; } @@ -1012,7 +1014,7 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos) case wxITEM_NORMAL: { - menuItem = gtk_menu_item_new_with_mnemonic( wxGTK_CONV( text ) ); + menuItem = gtk_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text ) ); m_prevRadio = NULL; break; } @@ -1022,7 +1024,7 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos) guint accel_key; GdkModifierType accel_mods; - wxCharBuffer buf = wxGTK_CONV( GetGtkHotKey(*mitem) ); + wxCharBuffer buf = wxGTK_CONV_SYS( GetGtkHotKey(*mitem) ); // wxPrintf( wxT("item: %s hotkey %s\n"), mitem->GetText().c_str(), GetGtkHotKey(*mitem).c_str() ); gtk_accelerator_parse( (const char*) buf, &accel_key, &accel_mods); diff --git a/src/gtk/utilsgtk.cpp b/src/gtk/utilsgtk.cpp index 4b321c358f..d0fd5c36a0 100644 --- a/src/gtk/utilsgtk.cpp +++ b/src/gtk/utilsgtk.cpp @@ -180,6 +180,25 @@ wxWindow* wxFindWindowAtPoint(const wxPoint& pt) return wxGenericFindWindowAtPoint(pt); } +#if !wxUSE_UNICODE + +wxCharBuffer wxConvertToGTK(const wxString& s, wxFontEncoding enc) +{ + if ( enc == wxFONTENCODING_UTF8 ) + { + // no need for conversion at all + return wxCharBuffer(s); + } + + const wxWCharBuffer wbuf = wxCSConv(enc).cMB2WC(s); + wxCharBuffer buf; + if ( wbuf ) + buf = wxConvUTF8.cWC2MB(wbuf); + + return buf; +} + +#endif // !wxUSE_UNICODE // ---------------------------------------------------------------------------- // subprocess routines diff --git a/src/unix/fontutil.cpp b/src/unix/fontutil.cpp index ea483ebed5..c29cc1aaf0 100644 --- a/src/unix/fontutil.cpp +++ b/src/unix/fontutil.cpp @@ -256,7 +256,7 @@ void wxNativeFontInfo::SetUnderlined(bool WXUNUSED(underlined)) void wxNativeFontInfo::SetFaceName(const wxString& facename) { - pango_font_description_set_family( description, wxGTK_CONV(facename) ); + pango_font_description_set_family(description, wxGTK_CONV_SYS(facename)); } void wxNativeFontInfo::SetFamily(wxFontFamily WXUNUSED(family)) @@ -276,7 +276,7 @@ bool wxNativeFontInfo::FromString(const wxString& s) if (description) pango_font_description_free( description ); - description = pango_font_description_from_string( wxGTK_CONV( s ) ); + description = pango_font_description_from_string( wxGTK_CONV_SYS( s ) ); return true; }