[gtk+/wip/csoriano/bookmarks] Redo font map support in GtkFontChooser



commit a75e60bd13a2ccfeb6181b9d18c63a94c373a35e
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Jun 12 23:55:30 2015 -0400

    Redo font map support in GtkFontChooser
    
    We can't add properties to the interface, since it breaks
    3rd party implementations of the GtkFontChooser interface.
    These exist, for example in gnumeric.
    
    So, instead of a new property, add getter/setter vfuncs.

 gtk/gtkfontbutton.c        |   24 ++++++++++++++----------
 gtk/gtkfontchooser.c       |   20 +++++---------------
 gtk/gtkfontchooser.h       |    7 ++++++-
 gtk/gtkfontchooserutils.c  |   18 +++++++++++++++---
 gtk/gtkfontchooserutils.h  |    1 -
 gtk/gtkfontchooserwidget.c |   24 ++++++++++++++----------
 6 files changed, 54 insertions(+), 40 deletions(-)
---
diff --git a/gtk/gtkfontbutton.c b/gtk/gtkfontbutton.c
index 492c4d2..98620c1 100644
--- a/gtk/gtkfontbutton.c
+++ b/gtk/gtkfontbutton.c
@@ -386,9 +386,11 @@ gtk_font_button_get_font_desc (GtkFontButton *font_button)
 }
 
 static void
-gtk_font_button_set_font_map (GtkFontButton *font_button,
-                              PangoFontMap  *font_map)
+gtk_font_button_font_chooser_set_font_map (GtkFontChooser *chooser,
+                                           PangoFontMap   *font_map)
 {
+  GtkFontButton *font_button = GTK_FONT_BUTTON (chooser);
+
   if (g_set_object (&font_button->priv->font_map, font_map))
     {
       PangoContext *context;
@@ -398,11 +400,17 @@ gtk_font_button_set_font_map (GtkFontButton *font_button,
 
       context = gtk_widget_get_pango_context (font_button->priv->font_label);
       pango_context_set_font_map (context, font_map);
-
-      g_object_notify (G_OBJECT (font_button), "font-map");
     }
 }
 
+static PangoFontMap *
+gtk_font_button_font_chooser_get_font_map (GtkFontChooser *chooser)
+{
+  GtkFontButton *font_button = GTK_FONT_BUTTON (chooser);
+
+  return font_button->priv->font_map;
+}
+
 static void
 gtk_font_button_font_chooser_notify (GObject    *object,
                                      GParamSpec *pspec,
@@ -421,6 +429,8 @@ gtk_font_button_font_chooser_iface_init (GtkFontChooserIface *iface)
   iface->get_font_face = gtk_font_button_font_chooser_get_font_face;
   iface->get_font_size = gtk_font_button_font_chooser_get_font_size;
   iface->set_filter_func = gtk_font_button_font_chooser_set_filter_func;
+  iface->set_font_map = gtk_font_button_font_chooser_set_font_map;
+  iface->get_font_map = gtk_font_button_font_chooser_get_font_map;
 }
 
 G_DEFINE_TYPE_WITH_CODE (GtkFontButton, gtk_font_button, GTK_TYPE_BUTTON,
@@ -655,9 +665,6 @@ gtk_font_button_set_property (GObject      *object,
     case PROP_SHOW_SIZE:
       gtk_font_button_set_show_size (font_button, g_value_get_boolean (value));
       break;
-    case GTK_FONT_CHOOSER_PROP_FONT_MAP:
-      gtk_font_button_set_font_map (font_button, g_value_get_object (value));
-      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
       break;
@@ -702,9 +709,6 @@ gtk_font_button_get_property (GObject    *object,
     case PROP_SHOW_SIZE:
       g_value_set_boolean (value, gtk_font_button_get_show_size (font_button));
       break;
-    case GTK_FONT_CHOOSER_PROP_FONT_MAP:
-      g_value_set_object (value, font_button->priv->font_map);
-      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
       break;
diff --git a/gtk/gtkfontchooser.c b/gtk/gtkfontchooser.c
index d295ce0..e2ed3a0 100644
--- a/gtk/gtkfontchooser.c
+++ b/gtk/gtkfontchooser.c
@@ -106,18 +106,6 @@ gtk_font_chooser_default_init (GtkFontChooserInterface *iface)
                           GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
 
   /**
-   * GtkFontChooser:font-map:
-   *
-   * A custom font map to use for this widget, instead of the
-   * default one.
-   *
-   * Since: 3.18
-   */
-  g_object_interface_install_property (iface,
-      g_param_spec_object ("font-map", P_("Font map"), P_("A custom PangoFontMap"),
-                           PANGO_TYPE_FONT_MAP,
-                           GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
-  /**
    * GtkFontChooser::font-activated:
    * @self: the object which received the signal
    * @fontname: the font name
@@ -466,7 +454,8 @@ gtk_font_chooser_set_font_map (GtkFontChooser *fontchooser,
   g_return_if_fail (GTK_IS_FONT_CHOOSER (fontchooser));
   g_return_if_fail (fontmap == NULL || PANGO_IS_FONT_MAP (fontmap));
 
-  g_object_set (fontchooser, "font-map", fontmap, NULL);
+  if (GTK_FONT_CHOOSER_GET_IFACE (fontchooser)->set_font_map)
+    GTK_FONT_CHOOSER_GET_IFACE (fontchooser)->set_font_map (fontchooser, fontmap);
 }
 
 /**
@@ -483,11 +472,12 @@ gtk_font_chooser_set_font_map (GtkFontChooser *fontchooser,
 PangoFontMap *
 gtk_font_chooser_get_font_map (GtkFontChooser *fontchooser)
 {
-  PangoFontMap *fontmap;
+  PangoFontMap *fontmap = NULL;
 
   g_return_val_if_fail (GTK_IS_FONT_CHOOSER (fontchooser), NULL);
 
-  g_object_get (fontchooser, "font-map", &fontmap, NULL);
+  if (GTK_FONT_CHOOSER_GET_IFACE (fontchooser)->get_font_map)
+    fontmap = GTK_FONT_CHOOSER_GET_IFACE (fontchooser)->get_font_map (fontchooser);
 
   return fontmap;
 }
diff --git a/gtk/gtkfontchooser.h b/gtk/gtkfontchooser.h
index 84693c1..98e3baf 100644
--- a/gtk/gtkfontchooser.h
+++ b/gtk/gtkfontchooser.h
@@ -70,8 +70,13 @@ struct _GtkFontChooserIface
   void (* font_activated) (GtkFontChooser *chooser,
                            const gchar    *fontname);
 
+  /* More methods */
+  void              (* set_font_map)            (GtkFontChooser   *fontchooser,
+                                                 PangoFontMap     *map);
+  PangoFontMap *    (* get_font_map)            (GtkFontChooser   *fontchooser);
+
    /* Padding */
-  gpointer padding[12];
+  gpointer padding[10];
 };
 
 GDK_AVAILABLE_IN_3_2
diff --git a/gtk/gtkfontchooserutils.c b/gtk/gtkfontchooserutils.c
index ff8ca68..36ebd8b 100644
--- a/gtk/gtkfontchooserutils.c
+++ b/gtk/gtkfontchooserutils.c
@@ -64,6 +64,19 @@ delegate_set_filter_func (GtkFontChooser    *chooser,
 }
 
 static void
+delegate_set_font_map (GtkFontChooser *chooser,
+                       PangoFontMap   *map)
+{
+  gtk_font_chooser_set_font_map (get_delegate (chooser), map);
+}
+
+static PangoFontMap *
+delegate_get_font_map (GtkFontChooser *chooser)
+{
+  return gtk_font_chooser_get_font_map (get_delegate (chooser));
+}
+
+static void
 delegate_notify (GObject    *object,
                  GParamSpec *pspec,
                  gpointer    user_data)
@@ -121,9 +134,6 @@ _gtk_font_chooser_install_properties (GObjectClass *klass)
   g_object_class_override_property (klass,
                                     GTK_FONT_CHOOSER_PROP_SHOW_PREVIEW_ENTRY,
                                     "show-preview-entry");
-  g_object_class_override_property (klass,
-                                    GTK_FONT_CHOOSER_PROP_FONT_MAP,
-                                    "font-map");
 }
 
 /**
@@ -144,6 +154,8 @@ _gtk_font_chooser_delegate_iface_init (GtkFontChooserIface *iface)
   iface->get_font_face = delegate_get_font_face;
   iface->get_font_size = delegate_get_font_size;
   iface->set_filter_func = delegate_set_filter_func;
+  iface->set_font_map = delegate_set_font_map;
+  iface->get_font_map = delegate_get_font_map;
 }
 
 /**
diff --git a/gtk/gtkfontchooserutils.h b/gtk/gtkfontchooserutils.h
index 0a8f9f8..7c92a64 100644
--- a/gtk/gtkfontchooserutils.h
+++ b/gtk/gtkfontchooserutils.h
@@ -37,7 +37,6 @@ typedef enum {
   GTK_FONT_CHOOSER_PROP_FONT_DESC,
   GTK_FONT_CHOOSER_PROP_PREVIEW_TEXT,
   GTK_FONT_CHOOSER_PROP_SHOW_PREVIEW_ENTRY,
-  GTK_FONT_CHOOSER_PROP_FONT_MAP,
   GTK_FONT_CHOOSER_PROP_LAST
 } GtkFontChooserProp;
 
diff --git a/gtk/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c
index 93fa54a..e0b16bf 100644
--- a/gtk/gtkfontchooserwidget.c
+++ b/gtk/gtkfontchooserwidget.c
@@ -171,8 +171,6 @@ static void     gtk_font_chooser_widget_cell_data_func         (GtkTreeViewColum
                                                                GtkTreeModel      *tree_model,
                                                                GtkTreeIter       *iter,
                                                                gpointer           user_data);
-static void    gtk_font_chooser_widget_set_font_map            (GtkFontChooserWidget *fontchooser,
-                                                                PangoFontMap         *fontmap);
 
 static void gtk_font_chooser_widget_iface_init (GtkFontChooserIface *iface);
 
@@ -203,9 +201,6 @@ gtk_font_chooser_widget_set_property (GObject         *object,
     case GTK_FONT_CHOOSER_PROP_SHOW_PREVIEW_ENTRY:
       gtk_font_chooser_widget_set_show_preview_entry (fontchooser, g_value_get_boolean (value));
       break;
-    case GTK_FONT_CHOOSER_PROP_FONT_MAP:
-      gtk_font_chooser_widget_set_font_map (fontchooser, g_value_get_object (value));
-      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -234,9 +229,6 @@ gtk_font_chooser_widget_get_property (GObject         *object,
     case GTK_FONT_CHOOSER_PROP_SHOW_PREVIEW_ENTRY:
       g_value_set_boolean (value, gtk_font_chooser_widget_get_show_preview_entry (fontchooser));
       break;
-    case GTK_FONT_CHOOSER_PROP_FONT_MAP:
-      g_value_set_object (value, fontchooser->priv->font_map);
-      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -1237,9 +1229,10 @@ gtk_font_chooser_widget_set_show_preview_entry (GtkFontChooserWidget *fontchoose
 }
 
 static void
-gtk_font_chooser_widget_set_font_map (GtkFontChooserWidget *fontchooser,
-                                      PangoFontMap         *fontmap)
+gtk_font_chooser_widget_set_font_map (GtkFontChooser *chooser,
+                                      PangoFontMap   *fontmap)
 {
+  GtkFontChooserWidget *fontchooser = GTK_FONT_CHOOSER_WIDGET (chooser);
   GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
 
   if (g_set_object (&priv->font_map, fontmap))
@@ -1261,6 +1254,15 @@ gtk_font_chooser_widget_set_font_map (GtkFontChooserWidget *fontchooser,
     }
 }
 
+static PangoFontMap *
+gtk_font_chooser_widget_get_font_map (GtkFontChooser *chooser)
+{
+  GtkFontChooserWidget *fontchooser = GTK_FONT_CHOOSER_WIDGET (chooser);
+  GtkFontChooserWidgetPrivate *priv = fontchooser->priv;
+
+  return priv->font_map;
+}
+
 static void
 gtk_font_chooser_widget_set_filter_func (GtkFontChooser  *chooser,
                                          GtkFontFilterFunc filter,
@@ -1287,4 +1289,6 @@ gtk_font_chooser_widget_iface_init (GtkFontChooserIface *iface)
   iface->get_font_face = gtk_font_chooser_widget_get_face;
   iface->get_font_size = gtk_font_chooser_widget_get_size;
   iface->set_filter_func = gtk_font_chooser_widget_set_filter_func;
+  iface->set_font_map = gtk_font_chooser_widget_set_font_map;
+  iface->get_font_map = gtk_font_chooser_widget_get_font_map;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]