From a3669332df65cfae18e7540a267bc3400a64aa09 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 10 Apr 2006 01:39:38 +0000 Subject: [PATCH] use wxGTK_CONV instead of directly using wxConvLocal (simplifies code avoiding needless #ifdefs and prepares for further wxGTK_CONV changes) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38646 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/gtk/dcclient.cpp | 27 +++++---------------- src/gtk/textctrl.cpp | 56 ++++++++++++++------------------------------ src/gtk/window.cpp | 20 ++++------------ 3 files changed, 29 insertions(+), 74 deletions(-) diff --git a/src/gtk/dcclient.cpp b/src/gtk/dcclient.cpp index c855efcc0a..78269d6bbe 100644 --- a/src/gtk/dcclient.cpp +++ b/src/gtk/dcclient.cpp @@ -22,6 +22,7 @@ #include "wx/fontutil.h" #include "wx/gtk/win_gtk.h" +#include "wx/gtk/private.h" #include "wx/math.h" // for floating-point functions @@ -1496,16 +1497,11 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y ) bool underlined = m_font.Ok() && m_font.GetUnderlined(); -#if wxUSE_UNICODE - const wxCharBuffer data = wxConvUTF8.cWC2MB( text ); -#else - const wxWCharBuffer wdata = wxConvLocal.cMB2WC( text ); - if ( !wdata ) + const wxCharBuffer data = wxGTK_CONV( text ); + if ( !data ) return; - const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata ); -#endif - size_t datalen = strlen((const char*)data); - pango_layout_set_text( m_layout, (const char*) data, datalen); + const size_t datalen = strlen(data); + pango_layout_set_text( m_layout, data, datalen); if (underlined) { @@ -1709,18 +1705,7 @@ void wxWindowDC::DoGetTextExtent(const wxString &string, pango_layout_set_font_description( m_layout, theFont->GetNativeFontInfo()->description ); // Set layout's text -#if wxUSE_UNICODE - const wxCharBuffer data = wxConvUTF8.cWC2MB( string ); - const char *dataUTF8 = (const char *)data; -#else - const wxWCharBuffer wdata = wxConvLocal.cMB2WC( string ); - if ( !wdata ) - return; - - const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata ); - const char *dataUTF8 = (const char *)data; -#endif - + const wxCharBuffer dataUTF8 = wxGTK_CONV(string); if ( !dataUTF8 ) { // hardly ideal, but what else can we do if conversion failed? diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 112af870c3..5a550f140b 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -744,19 +744,18 @@ wxString wxTextCtrl::GetValue() const gtk_text_buffer_get_end_iter( m_buffer, &end ); gchar *text = gtk_text_buffer_get_text( m_buffer, &start, &end, TRUE ); -#if wxUSE_UNICODE - wxWCharBuffer buffer( wxConvUTF8.cMB2WX( text ) ); -#else - wxCharBuffer buffer( wxConvLocal.cWC2WX( wxConvUTF8.cMB2WC( text ) ) ); -#endif - if ( buffer ) - tmp = buffer; + const wxWxCharBuffer buf = wxGTK_CONV_BACK(text); + if ( buf ) + tmp = buf; g_free( text ); } else { - tmp = wxGTK_CONV_BACK( gtk_entry_get_text( GTK_ENTRY(m_text) ) ); + const gchar *text = gtk_entry_get_text( GTK_ENTRY(m_text) ); + const wxWxCharBuffer buf = wxGTK_CONV_BACK( text ); + if ( buf ) + tmp = buf; } return tmp; @@ -768,20 +767,16 @@ void wxTextCtrl::SetValue( const wxString &value ) if (m_windowStyle & wxTE_MULTILINE) { -#if wxUSE_UNICODE - wxCharBuffer buffer( wxConvUTF8.cWX2MB( value) ); -#else - wxCharBuffer buffer( wxConvUTF8.cWC2MB( wxConvLocal.cWX2WC( value ) ) ); -#endif - if (gtk_text_buffer_get_char_count(m_buffer) != 0) - IgnoreNextTextUpdate(); - + const wxCharBuffer buffer(wxGTK_CONV(value)); if ( !buffer ) { // what else can we do? at least don't crash... return; } + if (gtk_text_buffer_get_char_count(m_buffer) != 0) + IgnoreNextTextUpdate(); + gtk_text_buffer_set_text( m_buffer, buffer, strlen(buffer) ); } else @@ -804,6 +799,13 @@ void wxTextCtrl::WriteText( const wxString &text ) if ( text.empty() ) return; + const wxCharBuffer buffer(wxGTK_CONV(text)); + if ( !buffer ) + { + // what else can we do? at least don't crash... + return; + } + // gtk_text_changed_callback() will set m_modified to true but m_modified // shouldn't be changed by the program writing to the text control itself, // so save the old value and restore when we're done @@ -811,17 +813,6 @@ void wxTextCtrl::WriteText( const wxString &text ) if ( m_windowStyle & wxTE_MULTILINE ) { -#if wxUSE_UNICODE - wxCharBuffer buffer( wxConvUTF8.cWX2MB( text ) ); -#else - wxCharBuffer buffer( wxConvUTF8.cWC2MB( wxConvLocal.cWX2WC( text ) ) ); -#endif - if ( !buffer ) - { - // what else can we do? at least don't crash... - return; - } - // TODO: Call whatever is needed to delete the selection. wxGtkTextInsert( m_text, m_buffer, m_defaultStyle, buffer ); @@ -841,17 +832,6 @@ void wxTextCtrl::WriteText( const wxString &text ) // This moves the cursor pos to behind the inserted text. gint len = gtk_editable_get_position(GTK_EDITABLE(m_text)); -#if wxUSE_UNICODE - wxCharBuffer buffer( wxConvUTF8.cWX2MB( text ) ); -#else - wxCharBuffer buffer( wxConvUTF8.cWC2MB( wxConvLocal.cWX2WC( text ) ) ); -#endif - if ( !buffer ) - { - // what else can we do? at least don't crash... - return; - } - gtk_editable_insert_text( GTK_EDITABLE(m_text), buffer, strlen(buffer), &len ); // Bring entry's cursor uptodate. diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 2e80d539f4..aede8763ff 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -1198,13 +1198,8 @@ gtk_wxwindow_commit_cb (GtkIMContext *context, window, window->m_imData->lastKeyEvent); } -#if wxUSE_UNICODE - const wxWCharBuffer data = wxConvUTF8.cMB2WC( (char*)str ); -#else - const wxWCharBuffer wdata = wxConvUTF8.cMB2WC( (char*)str ); - const wxCharBuffer data = wxConvLocal.cWC2MB( wdata ); -#endif // wxUSE_UNICODE - if( !(const wxChar*)data ) + const wxWxCharBuffer data(wxGTK_CONV_BACK(str)); + if( !data ) return; bool ret = false; @@ -3443,14 +3438,9 @@ void wxWindowGTK::GetTextExtent( const wxString& string, PangoLayout *layout = pango_layout_new(context); pango_layout_set_font_description(layout, desc); { -#if wxUSE_UNICODE - const wxCharBuffer data = wxConvUTF8.cWC2MB( string ); - pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data )); -#else - const wxWCharBuffer wdata = wxConvLocal.cMB2WC( string ); - const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata ); - pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data )); -#endif + const wxCharBuffer data = wxGTK_CONV( string ); + if ( data ) + pango_layout_set_text(layout, data, strlen(data)); } PangoRectangle rect; -- 2.45.2