diff options
author | Matthias Clasen <mclasen@redhat.com> | 2018-01-18 19:58:27 -0500 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2018-01-18 19:58:27 -0500 |
commit | ef72f3cbceb77e065ba73662eccb663b2b1ba771 (patch) | |
tree | bdbaaa5b286538e1c9faeee5c11704b8345a69f5 | |
parent | 5f675181ceec8cc73a48b8caca44d1218194cdc4 (diff) | |
download | gtk+-ef72f3cbceb77e065ba73662eccb663b2b1ba771.tar.gz |
font chooser: Fix property notification
We must notify the font and font-desc properties when the
list selection changes, and return NULL values for them
when there is no selection in the list.
-rw-r--r-- | gtk/gtkfontchooserwidget.c | 34 | ||||
-rw-r--r-- | gtk/ui/gtkfontchooserwidget.ui | 1 |
2 files changed, 32 insertions, 3 deletions
diff --git a/gtk/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c index 37e7398745..25060277c7 100644 --- a/gtk/gtkfontchooserwidget.c +++ b/gtk/gtkfontchooserwidget.c @@ -176,6 +176,9 @@ static void gtk_font_chooser_widget_cell_data_func (GtkTreeViewColum GtkTreeIter *iter, gpointer user_data); +static void selection_changed (GtkTreeSelection *selection, + GtkFontChooserWidget *fontchooser); + static void gtk_font_chooser_widget_iface_init (GtkFontChooserIface *iface); G_DEFINE_TYPE_WITH_CODE (GtkFontChooserWidget, gtk_font_chooser_widget, GTK_TYPE_BOX, @@ -613,6 +616,7 @@ gtk_font_chooser_widget_class_init (GtkFontChooserWidgetClass *klass) gtk_widget_class_bind_template_callback (widget_class, row_deleted_cb); gtk_widget_class_bind_template_callback (widget_class, size_change_cb); gtk_widget_class_bind_template_callback (widget_class, output_cb); + gtk_widget_class_bind_template_callback (widget_class, selection_changed); gtk_widget_class_set_css_name (widget_class, "fontchooser"); } @@ -1083,20 +1087,36 @@ static gint gtk_font_chooser_widget_get_size (GtkFontChooser *chooser) { GtkFontChooserWidget *fontchooser = GTK_FONT_CHOOSER_WIDGET (chooser); + PangoFontDescription *desc = gtk_font_chooser_widget_get_font_desc (fontchooser); + + if (desc) + return pango_font_description_get_size (desc); - return pango_font_description_get_size (fontchooser->priv->font_desc); + return -1; } static gchar * gtk_font_chooser_widget_get_font (GtkFontChooserWidget *fontchooser) { - return pango_font_description_to_string (fontchooser->priv->font_desc); + PangoFontDescription *desc = gtk_font_chooser_widget_get_font_desc (fontchooser); + + if (desc) + return pango_font_description_to_string (desc); + + return NULL; } static PangoFontDescription * gtk_font_chooser_widget_get_font_desc (GtkFontChooserWidget *fontchooser) { - return fontchooser->priv->font_desc; + GtkFontChooserWidgetPrivate *priv = fontchooser->priv; + GtkTreeSelection *selection; + + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->family_face_list)); + if (gtk_tree_selection_count_selected_rows (selection) > 0) + return fontchooser->priv->font_desc; + + return NULL; } static void @@ -1110,6 +1130,14 @@ gtk_font_chooser_widget_set_font (GtkFontChooserWidget *fontchooser, } static void +selection_changed (GtkTreeSelection *selection, + GtkFontChooserWidget *fontchooser) +{ + g_object_notify (G_OBJECT (fontchooser), "font"); + g_object_notify (G_OBJECT (fontchooser), "font-desc"); +} + +static void gtk_font_chooser_widget_ensure_selection (GtkFontChooserWidget *fontchooser) { GtkFontChooserWidgetPrivate *priv = fontchooser->priv; diff --git a/gtk/ui/gtkfontchooserwidget.ui b/gtk/ui/gtkfontchooserwidget.ui index 48786f1463..efce5d3555 100644 --- a/gtk/ui/gtkfontchooserwidget.ui +++ b/gtk/ui/gtkfontchooserwidget.ui @@ -89,6 +89,7 @@ <child internal-child="selection"> <object class="GtkTreeSelection" id="treeview-selection1"> <property name="mode">browse</property> + <signal name="changed" handler="selection_changed"/> </object> </child> <child> |