From 288059b2b9d1d4b562e1a0d06f7026936793bc79 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Fri, 31 Jan 2003 10:31:05 +0000 Subject: [PATCH] Corrected GTK2 creation of default font. Removed ugly SET_STYLE_FONT code. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@19031 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/gtk/choice.cpp | 2 +- src/gtk/settings.cpp | 17 ++--------------- src/gtk/tbargtk.cpp | 4 ---- src/gtk/tooltip.cpp | 4 ---- src/gtk/window.cpp | 10 +++++++--- src/gtk1/choice.cpp | 2 +- src/gtk1/settings.cpp | 17 ++--------------- src/gtk1/tbargtk.cpp | 4 ---- src/gtk1/tooltip.cpp | 4 ---- src/gtk1/window.cpp | 10 +++++++--- 10 files changed, 20 insertions(+), 54 deletions(-) diff --git a/src/gtk/choice.cpp b/src/gtk/choice.cpp index c9251f3982..4edcdc8b94 100644 --- a/src/gtk/choice.cpp +++ b/src/gtk/choice.cpp @@ -474,7 +474,7 @@ wxSize wxChoice::DoGetBestSize() const if ( ret.x < 80 ) ret.x = 80; - ret.y = 16 + gdk_char_height(GET_STYLE_FONT( m_widget->style ), 'H' ); + ret.y = 16 + GetCharHeight(); return ret; } diff --git a/src/gtk/settings.cpp b/src/gtk/settings.cpp index 736ed76aba..227599ef0b 100644 --- a/src/gtk/settings.cpp +++ b/src/gtk/settings.cpp @@ -328,21 +328,8 @@ wxFont wxSystemSettingsNative::GetFont( wxSystemFont index ) if (!g_systemFont) { #ifdef __WXGTK20__ - GtkWidget *widget = gtk_button_new(); - GtkStyle *def = gtk_rc_get_style( widget ); - if (!def) - def = gtk_widget_get_default_style(); - if (def) - { - wxNativeFontInfo info; - info.description = def->font_desc; - g_systemFont = new wxFont(info); - } - else - { - g_systemFont = new wxFont( 12, wxSWISS, wxNORMAL, wxNORMAL ); - } - gtk_widget_destroy( widget ); + const gchar *font_name = _gtk_rc_context_get_default_font_name (gtk_settings_get_default ()); + g_systemFont = new wxFont( wxString::FromAscii( font_name ) ); #else g_systemFont = new wxFont( 12, wxSWISS, wxNORMAL, wxNORMAL ); #endif diff --git a/src/gtk/tbargtk.cpp b/src/gtk/tbargtk.cpp index bd6f38fd3b..2ce4bc754c 100644 --- a/src/gtk/tbargtk.cpp +++ b/src/gtk/tbargtk.cpp @@ -343,10 +343,6 @@ bool wxToolBar::Create( wxWindow *parent, g_style->bg[GTK_STATE_NORMAL] = *m_bg; -#ifndef __WXGTK20__ - SET_STYLE_FONT(g_style, GtkGetDefaultGuiFont()); -#endif - gtk_widget_set_style( GTK_TOOLBAR(m_toolbar)->tooltips->tip_window, g_style ); m_parent->DoAddChild( this ); diff --git a/src/gtk/tooltip.cpp b/src/gtk/tooltip.cpp index 03f7ebfe98..a8e42e4d07 100644 --- a/src/gtk/tooltip.cpp +++ b/src/gtk/tooltip.cpp @@ -76,10 +76,6 @@ void wxToolTip::Apply( wxWindow *win ) g_style->fg[GTK_STATE_NORMAL] = ss_fg; g_style->bg[GTK_STATE_NORMAL] = ss_bg; -#ifndef __WXGTK20__ - SET_STYLE_FONT( g_style, GtkGetDefaultGuiFont() ); -#endif - gtk_widget_set_style( ss_tooltips->tip_window, g_style ); #else // GTK+ 1.0 gtk_tooltips_set_colors( ss_tooltips, &ss_bg, &ss_fg ); diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 7d50b4b936..a2c0ea57b2 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -4145,12 +4145,16 @@ void wxWindowGTK::SetWidgetStyle() GtkStyle *style = GetWidgetStyle(); -#ifndef __WXGTK20__ if (m_font != wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT )) { - SET_STYLE_FONT(style, m_font.GetInternalFont( 1.0 )); - } +#ifdef __WXGTK20__ + pango_font_description_free( style->font_desc ); + pango_font_description_copy( m_font.GetNativeFontInfo()->description ); +#else + gdk_font_unref( style->font ); + style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) ) #endif + } if (m_foregroundColour.Ok()) { diff --git a/src/gtk1/choice.cpp b/src/gtk1/choice.cpp index c9251f3982..4edcdc8b94 100644 --- a/src/gtk1/choice.cpp +++ b/src/gtk1/choice.cpp @@ -474,7 +474,7 @@ wxSize wxChoice::DoGetBestSize() const if ( ret.x < 80 ) ret.x = 80; - ret.y = 16 + gdk_char_height(GET_STYLE_FONT( m_widget->style ), 'H' ); + ret.y = 16 + GetCharHeight(); return ret; } diff --git a/src/gtk1/settings.cpp b/src/gtk1/settings.cpp index 736ed76aba..227599ef0b 100644 --- a/src/gtk1/settings.cpp +++ b/src/gtk1/settings.cpp @@ -328,21 +328,8 @@ wxFont wxSystemSettingsNative::GetFont( wxSystemFont index ) if (!g_systemFont) { #ifdef __WXGTK20__ - GtkWidget *widget = gtk_button_new(); - GtkStyle *def = gtk_rc_get_style( widget ); - if (!def) - def = gtk_widget_get_default_style(); - if (def) - { - wxNativeFontInfo info; - info.description = def->font_desc; - g_systemFont = new wxFont(info); - } - else - { - g_systemFont = new wxFont( 12, wxSWISS, wxNORMAL, wxNORMAL ); - } - gtk_widget_destroy( widget ); + const gchar *font_name = _gtk_rc_context_get_default_font_name (gtk_settings_get_default ()); + g_systemFont = new wxFont( wxString::FromAscii( font_name ) ); #else g_systemFont = new wxFont( 12, wxSWISS, wxNORMAL, wxNORMAL ); #endif diff --git a/src/gtk1/tbargtk.cpp b/src/gtk1/tbargtk.cpp index bd6f38fd3b..2ce4bc754c 100644 --- a/src/gtk1/tbargtk.cpp +++ b/src/gtk1/tbargtk.cpp @@ -343,10 +343,6 @@ bool wxToolBar::Create( wxWindow *parent, g_style->bg[GTK_STATE_NORMAL] = *m_bg; -#ifndef __WXGTK20__ - SET_STYLE_FONT(g_style, GtkGetDefaultGuiFont()); -#endif - gtk_widget_set_style( GTK_TOOLBAR(m_toolbar)->tooltips->tip_window, g_style ); m_parent->DoAddChild( this ); diff --git a/src/gtk1/tooltip.cpp b/src/gtk1/tooltip.cpp index 03f7ebfe98..a8e42e4d07 100644 --- a/src/gtk1/tooltip.cpp +++ b/src/gtk1/tooltip.cpp @@ -76,10 +76,6 @@ void wxToolTip::Apply( wxWindow *win ) g_style->fg[GTK_STATE_NORMAL] = ss_fg; g_style->bg[GTK_STATE_NORMAL] = ss_bg; -#ifndef __WXGTK20__ - SET_STYLE_FONT( g_style, GtkGetDefaultGuiFont() ); -#endif - gtk_widget_set_style( ss_tooltips->tip_window, g_style ); #else // GTK+ 1.0 gtk_tooltips_set_colors( ss_tooltips, &ss_bg, &ss_fg ); diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index 7d50b4b936..a2c0ea57b2 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -4145,12 +4145,16 @@ void wxWindowGTK::SetWidgetStyle() GtkStyle *style = GetWidgetStyle(); -#ifndef __WXGTK20__ if (m_font != wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT )) { - SET_STYLE_FONT(style, m_font.GetInternalFont( 1.0 )); - } +#ifdef __WXGTK20__ + pango_font_description_free( style->font_desc ); + pango_font_description_copy( m_font.GetNativeFontInfo()->description ); +#else + gdk_font_unref( style->font ); + style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) ) #endif + } if (m_foregroundColour.Ok()) { -- 2.47.2