diff --git a/widget/src/gtk/nsButton.cpp b/widget/src/gtk/nsButton.cpp index 543b2600dfee..2b3f215b9fd6 100644 --- a/widget/src/gtk/nsButton.cpp +++ b/widget/src/gtk/nsButton.cpp @@ -132,3 +132,23 @@ NS_METHOD nsButton::GetLabel(nsString& aBuffer) return (NS_OK); } + +//------------------------------------------------------------------------- +// +// set font for button +// +//------------------------------------------------------------------------- +/* virtual */ +void nsButton::SetFontNative(GdkFont *aFont) +{ + GtkStyle *style = gtk_style_copy(GTK_BIN (mWidget)->child->style); + // gtk_style_copy ups the ref count of the font + gdk_font_unref (style->font); + + style->font = aFont; + gdk_font_ref(style->font); + + gtk_widget_set_style(GTK_BIN (mWidget)->child, style); + + gtk_style_unref(style); +} diff --git a/widget/src/gtk/nsButton.h b/widget/src/gtk/nsButton.h index 1ee9b16891f0..ec72aea014e7 100644 --- a/widget/src/gtk/nsButton.h +++ b/widget/src/gtk/nsButton.h @@ -46,6 +46,8 @@ public: virtual PRBool OnPaint(nsPaintEvent & aEvent) { return PR_FALSE; } virtual PRBool OnResize(nsRect &aRect) { return PR_FALSE; } + virtual void SetFontNative(GdkFont *aFont); + protected: NS_METHOD CreateNative(GtkWidget *parentWindow); diff --git a/widget/src/gtk/nsComboBox.cpp b/widget/src/gtk/nsComboBox.cpp index f158e547409f..2a32c7102acc 100644 --- a/widget/src/gtk/nsComboBox.cpp +++ b/widget/src/gtk/nsComboBox.cpp @@ -352,3 +352,23 @@ nsComboBox::OnUnmapSignal(GtkWidget * aWidget) InitEvent(event, NS_CONTROL_CHANGE, &point); DispatchWindowEvent(&event); } + +//------------------------------------------------------------------------- +// +// Get handle for style +// +//------------------------------------------------------------------------- +/*virtual*/ +void nsComboBox::SetFontNative(GdkFont *aFont) +{ + GtkStyle *style = gtk_style_copy(GTK_WIDGET (g_list_nth_data(gtk_container_children(GTK_CONTAINER (mWidget)),0))->style); + // gtk_style_copy ups the ref count of the font + gdk_font_unref (style->font); + + style->font = aFont; + gdk_font_ref(style->font); + + gtk_widget_set_style(GTK_BIN (mWidget)->child, style); + + gtk_style_unref(style); +} diff --git a/widget/src/gtk/nsComboBox.h b/widget/src/gtk/nsComboBox.h index 8d7079af4bb2..df8dd7725e39 100644 --- a/widget/src/gtk/nsComboBox.h +++ b/widget/src/gtk/nsComboBox.h @@ -59,6 +59,8 @@ public: PRInt32 GetSelectedCount(); NS_IMETHOD GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize); + virtual void SetFontNative(GdkFont *aFont); + protected: NS_IMETHOD CreateNative(GtkWidget *parentWindow); virtual void InitCallbacks(char * aName = nsnull); diff --git a/widget/src/gtk/nsListBox.cpp b/widget/src/gtk/nsListBox.cpp index 346b9430a301..c74a619f99e9 100644 --- a/widget/src/gtk/nsListBox.cpp +++ b/widget/src/gtk/nsListBox.cpp @@ -393,3 +393,23 @@ nsListBox::OnDestroySignal(GtkWidget* aGtkWidget) nsWidget::OnDestroySignal(aGtkWidget); } } + +//------------------------------------------------------------------------- +// +// set font for listbox +// +//------------------------------------------------------------------------- +/*virtual*/ +void nsListBox::SetFontNative(GdkFont *aFont) +{ + GtkStyle *style = gtk_style_copy(GTK_WIDGET (g_list_nth_data(gtk_container_children(GTK_CONTAINER (mWidget)),0))->style); + // gtk_style_copy ups the ref count of the font + gdk_font_unref (style->font); + + style->font = aFont; + gdk_font_ref(style->font); + + gtk_widget_set_style(GTK_WIDGET (g_list_nth_data(gtk_container_children(GTK_CONTAINER (mWidget)),0)), style); + + gtk_style_unref(style); +} diff --git a/widget/src/gtk/nsListBox.h b/widget/src/gtk/nsListBox.h index 710ee9500a12..92026454a2f6 100644 --- a/widget/src/gtk/nsListBox.h +++ b/widget/src/gtk/nsListBox.h @@ -59,6 +59,8 @@ public: NS_IMETHOD SelectItem(PRInt32 aPosition); NS_IMETHOD Deselect() ; + virtual void SetFontNative(GdkFont *aFont); + protected: NS_IMETHOD CreateNative(GtkWidget *parentWindow); virtual void InitCallbacks(char * aName = nsnull); diff --git a/widget/src/gtk/nsWidget.cpp b/widget/src/gtk/nsWidget.cpp index 46682f3cfa82..99ec1afae42f 100644 --- a/widget/src/gtk/nsWidget.cpp +++ b/widget/src/gtk/nsWidget.cpp @@ -434,22 +434,8 @@ NS_METHOD nsWidget::SetFont(const nsFont &aFont) return NS_ERROR_FAILURE; } - if (mWidget) { - gtk_widget_ensure_style(mWidget); - - GtkStyle *style = gtk_style_copy(mWidget->style); - // gtk_style_copy ups the ref count of the font - gdk_font_unref (style->font); - - GdkFont *font = (GdkFont *)fontHandle; - style->font = font; - gdk_font_ref(style->font); - - gtk_widget_set_style(mWidget, style); - - gtk_style_unref(style); - } - + if (mWidget) + SetFontNative((GdkFont *)fontHandle); } NS_RELEASE(mFontMetrics); return NS_OK; @@ -1807,3 +1793,21 @@ nsWidget::GetWindowForSetBackground() return gdk_window; } + + +////////////////////////////////////////////////////////////////////// +// default setfont for most widgets +/*virtual*/ +void nsWidget::SetFontNative(GdkFont *aFont) +{ + GtkStyle *style = gtk_style_copy(mWidget->style); + // gtk_style_copy ups the ref count of the font + gdk_font_unref (style->font); + + style->font = aFont; + gdk_font_ref(style->font); + + gtk_widget_set_style(mWidget, style); + + gtk_style_unref(style); +} diff --git a/widget/src/gtk/nsWidget.h b/widget/src/gtk/nsWidget.h index 560cccb3806c..f59444ef44ea 100644 --- a/widget/src/gtk/nsWidget.h +++ b/widget/src/gtk/nsWidget.h @@ -154,6 +154,9 @@ class nsWidget : public nsBaseWidget // Return the Gdk window whose background should change virtual GdkWindow * GetWindowForSetBackground(); + // Sets font for widgets + virtual void SetFontNative(GdkFont *aFont); + ////////////////////////////////////////////////////////////////// // // GTK signal installers