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
This commit is contained in:
Vadim Zeitlin
2006-04-10 22:22:13 +00:00
parent 0e05227246
commit 5f11fef543
7 changed files with 57 additions and 21 deletions

View File

@@ -163,6 +163,7 @@ wxMSW:
wxGTK: wxGTK:
- Fixed handling of font encoding in non-Unicode build
- wxEVT_MENU_CLOSE and wxEVT_MENU_OPENED for popup menus are now generated. - wxEVT_MENU_CLOSE and wxEVT_MENU_OPENED for popup menus are now generated.
- Implemented wxCURSOR_BLANK support. - Implemented wxCURSOR_BLANK support.
- wxSlider generates all scroll events now and not only wxEVT_SCROLL_THUMBTRACK. - wxSlider generates all scroll events now and not only wxEVT_SCROLL_THUMBTRACK.

View File

@@ -24,10 +24,24 @@
#if wxUSE_UNICODE #if wxUSE_UNICODE
#define wxGTK_CONV(s) wxConvUTF8.cWX2MB(s) #define wxGTK_CONV(s) wxConvUTF8.cWX2MB(s)
#define wxGTK_CONV_SYS(s, enc) wxGTK_CONV(s)
#define wxGTK_CONV_BACK(s) wxConvUTF8.cMB2WX(s) #define wxGTK_CONV_BACK(s) wxConvUTF8.cMB2WX(s)
#else #else
#define wxGTK_CONV(s) wxConvUTF8.cWC2MB( wxConvLocal.cWX2WC(s) ) // convert the text in given encoding to UTF-8 used by wxGTK
#define wxGTK_CONV_BACK(s) wxConvLocal.cWC2WX( (wxConvUTF8.cMB2WC( s ) ) ) 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 #endif
// Some deprecated GTK+ prototypes we still use often // Some deprecated GTK+ prototypes we still use often

View File

@@ -96,7 +96,7 @@ wxColour wxColour::CreateByName(const wxString& name)
wxColour col; wxColour col;
GdkColor colGDK; GdkColor colGDK;
if ( gdk_color_parse( wxGTK_CONV( name ), &colGDK ) ) if ( gdk_color_parse( wxGTK_CONV_SYS( name ), &colGDK ) )
{ {
wxColourRefData *refData = new wxColourRefData; wxColourRefData *refData = new wxColourRefData;
refData->m_color = colGDK; refData->m_color = colGDK;

View File

@@ -116,7 +116,7 @@ private:
m_weight; m_weight;
bool m_underlined; bool m_underlined;
wxString m_faceName; wxString m_faceName;
wxFontEncoding m_encoding; // Unused under GTK 2.0 wxFontEncoding m_encoding;
bool m_noAA; // No anti-aliasing bool m_noAA; // No anti-aliasing
// The native font info, basicly an XFLD under GTK 1.2 and // 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 // And set its values
if (!m_faceName.empty()) 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 else
{ {
@@ -228,8 +229,8 @@ void wxFontRefData::InitFromNative()
// Pango description are never underlined (?) // Pango description are never underlined (?)
m_underlined = FALSE; m_underlined = FALSE;
// Cannot we choose that // always with GTK+ 2
m_encoding = wxFONTENCODING_SYSTEM; m_encoding = wxFONTENCODING_UTF8;
} }
wxFontRefData::wxFontRefData( const wxFontRefData& data ) wxFontRefData::wxFontRefData( const wxFontRefData& data )
@@ -485,15 +486,14 @@ bool wxFont::GetUnderlined() const
wxFontEncoding wxFont::GetEncoding() 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; return M_FONTDATA->m_encoding;
} }
bool wxFont::GetNoAntiAliasing() const bool wxFont::GetNoAntiAliasing() const
{ {
wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT, wxT("invalid font") ); wxCHECK_MSG( Ok(), false, wxT("invalid font") );
return M_FONTDATA->m_noAA; return M_FONTDATA->m_noAA;
} }

View File

@@ -747,7 +747,7 @@ void wxMenuItem::SetText( const wxString& str )
oldLabel.Replace(wxT("_"), wxT("")); oldLabel.Replace(wxT("_"), wxT(""));
wxString label1 = wxStripMenuCodes(str); wxString label1 = wxStripMenuCodes(str);
wxString oldhotkey = GetHotKey(); // Store the old hotkey in Ctrl-foo format wxString oldhotkey = GetHotKey(); // Store the old hotkey in Ctrl-foo format
wxCharBuffer oldbuf = wxGTK_CONV( GetGtkHotKey(*this) ); // and as <control>foo wxCharBuffer oldbuf = wxGTK_CONV_SYS( GetGtkHotKey(*this) ); // and as <control>foo
DoSetText(str); DoSetText(str);
@@ -763,7 +763,7 @@ void wxMenuItem::SetText( const wxString& str )
else else
label = GTK_LABEL( GTK_BIN(m_menuItem)->child ); 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; guint accel_key;
@@ -777,7 +777,7 @@ void wxMenuItem::SetText( const wxString& str )
accel_mods ); 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); gtk_accelerator_parse( (const char*) buf, &accel_key, &accel_mods);
if (accel_key != 0) if (accel_key != 0)
{ {
@@ -954,7 +954,7 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
text = mitem->GetText(); text = mitem->GetText();
const wxBitmap *bitmap = &mitem->GetBitmap(); 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; GtkWidget *image;
if (bitmap->HasPixbuf()) if (bitmap->HasPixbuf())
@@ -985,7 +985,7 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
{ {
case wxITEM_CHECK: 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; m_prevRadio = NULL;
break; break;
} }
@@ -996,12 +996,14 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
if ( m_prevRadio == NULL ) if ( m_prevRadio == NULL )
{ {
// start of a new radio group // 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 else // continue the radio group
{ {
group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (m_prevRadio)); 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; break;
} }
@@ -1012,7 +1014,7 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
case wxITEM_NORMAL: 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; m_prevRadio = NULL;
break; break;
} }
@@ -1022,7 +1024,7 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
guint accel_key; guint accel_key;
GdkModifierType accel_mods; 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() ); // 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); gtk_accelerator_parse( (const char*) buf, &accel_key, &accel_mods);

View File

@@ -180,6 +180,25 @@ wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
return wxGenericFindWindowAtPoint(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 // subprocess routines

View File

@@ -256,7 +256,7 @@ void wxNativeFontInfo::SetUnderlined(bool WXUNUSED(underlined))
void wxNativeFontInfo::SetFaceName(const wxString& facename) 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)) void wxNativeFontInfo::SetFamily(wxFontFamily WXUNUSED(family))
@@ -276,7 +276,7 @@ bool wxNativeFontInfo::FromString(const wxString& s)
if (description) if (description)
pango_font_description_free( 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; return true;
} }