From 30083ad8e7c0eb9ea3dcf4f2588149eeb7fe3e32 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 27 Feb 2007 15:41:56 +0000 Subject: [PATCH] Support encodings in wxGTK_CONV_BACK() in the same way as we do it in wxGTK_CONV(), i.e. return the string containing text in ISO-8859-1 encoding and not UTF-8 if the controls font was set to have ISO-8859-1 encoding git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44577 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/private.h | 38 +++++++++++++++++++++++++++++++++++--- src/gtk/aboutdlg.cpp | 2 +- src/gtk/font.cpp | 2 +- src/gtk/menu.cpp | 5 +++-- src/gtk/utilsgtk.cpp | 11 +++++++++++ src/gtk/window.cpp | 17 ++++++----------- src/unix/fontutil.cpp | 6 ++---- 7 files changed, 59 insertions(+), 22 deletions(-) diff --git a/include/wx/gtk/private.h b/include/wx/gtk/private.h index 7352f87369..d5afceb68e 100644 --- a/include/wx/gtk/private.h +++ b/include/wx/gtk/private.h @@ -28,15 +28,23 @@ #define wxGTK_CONV_ENC(s, enc) wxGTK_CONV((s)) #define wxGTK_CONV_FONT(s, font) wxGTK_CONV((s)) #define wxGTK_CONV_SYS(s) wxGTK_CONV((s)) + #define wxGTK_CONV_BACK(s) wxConvUTF8.cMB2WX((s)) + #define wxGTK_CONV_BACK_ENC(s, enc) wxGTK_CONV_BACK(s) + #define wxGTK_CONV_BACK_FONT(s, font) wxGTK_CONV_BACK(s) + #define wxGTK_CONV_BACK_SYS(s) wxGTK_CONV_BACK(s) #else #include "wx/font.h" - // convert the text in given encoding to UTF-8 used by wxGTK + // convert the text between the given encoding and UTF-8 used by wxGTK extern wxCharBuffer wxConvertToGTK(const wxString& s, wxFontEncoding enc = wxFONTENCODING_SYSTEM); + extern wxCharBuffer + wxConvertFromGTK(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) { @@ -44,11 +52,35 @@ : wxFONTENCODING_SYSTEM); } + inline wxCharBuffer wxConvertFromGTK(const wxString& s, const wxFont& font) + { + return wxConvertFromGTK(s, font.Ok() ? font.GetEncoding() + : wxFONTENCODING_SYSTEM); + } + + // more helpers: allow passing GTK+ strings directly + inline wxCharBuffer + wxConvertFromGTK(const wxGtkString& gs, + wxFontEncoding enc = wxFONTENCODING_SYSTEM) + { + return wxConvertFromGTK(gs.c_str(), enc); + } + + inline wxCharBuffer + wxConvertFromGTK(const wxGtkString& gs, const wxFont& font) + { + return wxConvertFromGTK(gs.c_str(), font); + } + + #define wxGTK_CONV(s) wxGTK_CONV_FONT((s), m_font) #define wxGTK_CONV_ENC(s, enc) wxConvertToGTK((s), (enc)) #define wxGTK_CONV_FONT(s, font) wxConvertToGTK((s), (font)) - #define wxGTK_CONV(s) wxGTK_CONV_FONT((s), m_font) #define wxGTK_CONV_SYS(s) wxConvertToGTK((s)) - #define wxGTK_CONV_BACK(s) wxConvLocal.cWC2WX(wxConvUTF8.cMB2WC((s))) + + #define wxGTK_CONV_BACK(s) wxConvertFromGTK((s), m_font) + #define wxGTK_CONV_BACK_ENC(s, enc) wxConvertFromGTK((s), (enc)) + #define wxGTK_CONV_BACK_FONT(s, font) wxConvertFromGTK((s), (font)) + #define wxGTK_CONV_BACK_SYS(s) wxConvertFromGTK((s)) #endif // Some deprecated GTK+ prototypes we still use often diff --git a/src/gtk/aboutdlg.cpp b/src/gtk/aboutdlg.cpp index b6d960990b..d8058f0336 100644 --- a/src/gtk/aboutdlg.cpp +++ b/src/gtk/aboutdlg.cpp @@ -93,7 +93,7 @@ wxGtkAboutDialogOnLink(GtkAboutDialog * WXUNUSED(about), const gchar *link, gpointer WXUNUSED(data)) { - wxLaunchDefaultBrowser(wxGTK_CONV_BACK(link)); + wxLaunchDefaultBrowser(wxGTK_CONV_BACK_SYS(link)); } void wxAboutBox(const wxAboutDialogInfo& info) diff --git a/src/gtk/font.cpp b/src/gtk/font.cpp index e355db0f1c..11e7b20c64 100644 --- a/src/gtk/font.cpp +++ b/src/gtk/font.cpp @@ -201,7 +201,7 @@ void wxFontRefData::InitFromNative() PangoFontDescription *desc = m_nativeFontInfo.description; // init fields - m_faceName = wxGTK_CONV_BACK( pango_font_description_get_family( desc ) ); + m_faceName = wxGTK_CONV_BACK_SYS(pango_font_description_get_family(desc)); // Pango sometimes needs to have a size int pango_size = pango_font_description_get_size( desc ); diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index 7f4d87855d..78539a50de 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -1547,8 +1547,9 @@ static wxString GetGtkHotKey( const wxMenuItem& item ) default: if ( code < 127 ) { - wxString name = wxGTK_CONV_BACK( gdk_keyval_name((guint)code) ); - if ( name ) + const wxString + name = wxGTK_CONV_BACK_SYS(gdk_keyval_name((guint)code)); + if ( !name.empty() ) { hotkey << name; break; diff --git a/src/gtk/utilsgtk.cpp b/src/gtk/utilsgtk.cpp index 72757f441b..698225a0be 100644 --- a/src/gtk/utilsgtk.cpp +++ b/src/gtk/utilsgtk.cpp @@ -209,6 +209,17 @@ wxCharBuffer wxConvertToGTK(const wxString& s, wxFontEncoding enc) return wxConvUTF8.cWC2MB(wbuf); } +wxCharBuffer wxConvertFromGTK(const wxString& s, wxFontEncoding enc) +{ + // this conversion should never fail as GTK+ always uses UTF-8 internally + // so there are no complications here + const wxWCharBuffer wbuf(wxConvUTF8.cMB2WC(s)); + if ( enc == wxFONTENCODING_SYSTEM ) + return wxConvUI->cWC2MB(wbuf); + + return wxCSConv(enc).cWC2MB(wbuf); +} + #endif // !wxUSE_UNICODE // ---------------------------------------------------------------------------- diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index dd6be8cf36..a9a67e6c68 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -1158,7 +1158,7 @@ gtk_wxwindow_commit_cb (GtkIMContext *context, window, window->m_imData->lastKeyEvent); } - const wxWxCharBuffer data(wxGTK_CONV_BACK(str)); + const wxWxCharBuffer data(wxGTK_CONV_BACK_SYS(str)); if( !data ) return; @@ -2137,16 +2137,11 @@ void gtk_window_size_callback( GtkWidget *WXUNUSED(widget), if ((client_width == win->m_oldClientWidth) && (client_height == win->m_oldClientHeight)) return; -#if 0 - wxPrintf( wxT("size_allocate ") ); - if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) - wxPrintf( win->GetClassInfo()->GetClassName() ); - wxPrintf( wxT(" %d %d %d %d\n"), - alloc->x, - alloc->y, - alloc->width, - alloc->height ); -#endif + if ( !client_width && !client_height ) + { + // the window is currently unmapped, don't generate size events + return; + } win->m_oldClientWidth = client_width; win->m_oldClientHeight = client_height; diff --git a/src/unix/fontutil.cpp b/src/unix/fontutil.cpp index d9eab1961d..1a19014406 100644 --- a/src/unix/fontutil.cpp +++ b/src/unix/fontutil.cpp @@ -136,9 +136,7 @@ bool wxNativeFontInfo::GetUnderlined() const wxString wxNativeFontInfo::GetFaceName() const { - wxString tmp = wxGTK_CONV_BACK( pango_font_description_get_family( description ) ); - - return tmp; + return wxGTK_CONV_BACK_SYS(pango_font_description_get_family(description)); } wxFontFamily wxNativeFontInfo::GetFamily() const @@ -327,7 +325,7 @@ wxString wxNativeFontInfo::ToString() const { wxGtkString str(pango_font_description_to_string( description )); - return wxGTK_CONV_BACK(str); + return wxGTK_CONV_BACK_SYS(str); } bool wxNativeFontInfo::FromUserString(const wxString& s) -- 2.45.2