[gtk+] fontchooserwidget: Inherit from GtkWidget



commit fc22543b4136e393227228badaacf29a94773158
Author: Timm Bäder <mail baedert org>
Date:   Sat Mar 25 20:49:00 2017 +0100

    fontchooserwidget: Inherit from GtkWidget

 gtk/gtkfontchooserwidget.c     |   62 +++++++++++++++++++++++++++++++++++++++-
 gtk/gtkfontchooserwidget.h     |    6 ++--
 gtk/ui/gtkfontchooserdialog.ui |    3 --
 gtk/ui/gtkfontchooserwidget.ui |    7 +---
 4 files changed, 66 insertions(+), 12 deletions(-)
---
diff --git a/gtk/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c
index d533591..54e86b9 100644
--- a/gtk/gtkfontchooserwidget.c
+++ b/gtk/gtkfontchooserwidget.c
@@ -81,6 +81,7 @@
 
 struct _GtkFontChooserWidgetPrivate
 {
+  GtkWidget    *grid;
   GtkWidget    *search_entry;
   GtkWidget    *family_face_list;
   GtkTreeViewColumn *family_face_column;
@@ -171,7 +172,7 @@ static void     gtk_font_chooser_widget_cell_data_func         (GtkTreeViewColum
 
 static void gtk_font_chooser_widget_iface_init (GtkFontChooserIface *iface);
 
-G_DEFINE_TYPE_WITH_CODE (GtkFontChooserWidget, gtk_font_chooser_widget, GTK_TYPE_BOX,
+G_DEFINE_TYPE_WITH_CODE (GtkFontChooserWidget, gtk_font_chooser_widget, GTK_TYPE_WIDGET,
                          G_ADD_PRIVATE (GtkFontChooserWidget)
                          G_IMPLEMENT_INTERFACE (GTK_TYPE_FONT_CHOOSER,
                                                 gtk_font_chooser_widget_iface_init))
@@ -565,6 +566,58 @@ row_deleted_cb  (GtkTreeModel *model,
 }
 
 static void
+gtk_font_chooser_widget_measure (GtkWidget       *widget,
+                                 GtkOrientation  orientation,
+                                 int             for_size,
+                                 int            *minimum,
+                                 int            *natural,
+                                 int            *minimum_baseline,
+                                 int            *natural_baseline)
+{
+  GtkFontChooserWidget *self = GTK_FONT_CHOOSER_WIDGET (widget);
+  GtkFontChooserWidgetPrivate *priv = gtk_font_chooser_widget_get_instance_private (self);
+
+  gtk_widget_measure (priv->grid, orientation, for_size,
+                      minimum, natural,
+                      minimum_baseline, natural_baseline);
+}
+
+static void
+gtk_font_chooser_widget_snapshot (GtkWidget   *widget,
+                                  GtkSnapshot *snapshot)
+{
+  GtkFontChooserWidget *self = GTK_FONT_CHOOSER_WIDGET (widget);
+  GtkFontChooserWidgetPrivate *priv = gtk_font_chooser_widget_get_instance_private (self);
+
+  gtk_widget_snapshot_child (widget, priv->grid, snapshot);
+}
+
+static void
+gtk_font_chooser_widget_size_allocate (GtkWidget     *widget,
+                                       GtkAllocation *allocation)
+{
+  GtkFontChooserWidget *self = GTK_FONT_CHOOSER_WIDGET (widget);
+  GtkFontChooserWidgetPrivate *priv = gtk_font_chooser_widget_get_instance_private (self);
+
+  gtk_widget_size_allocate (priv->grid, allocation);
+}
+
+static void
+gtk_font_chooser_widget_dispose (GObject *object)
+{
+  GtkFontChooserWidget *self = GTK_FONT_CHOOSER_WIDGET (object);
+  GtkFontChooserWidgetPrivate *priv = gtk_font_chooser_widget_get_instance_private (self);
+
+  if (priv->grid)
+    {
+      gtk_widget_unparent (priv->grid);
+      priv->grid = NULL;
+    }
+
+  G_OBJECT_CLASS (gtk_font_chooser_widget_parent_class)->dispose (object);
+}
+
+static void
 gtk_font_chooser_widget_class_init (GtkFontChooserWidgetClass *klass)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
@@ -575,8 +628,12 @@ gtk_font_chooser_widget_class_init (GtkFontChooserWidgetClass *klass)
 
   widget_class->screen_changed = gtk_font_chooser_widget_screen_changed;
   widget_class->style_updated = gtk_font_chooser_widget_style_updated;
+  widget_class->measure = gtk_font_chooser_widget_measure;
+  widget_class->size_allocate = gtk_font_chooser_widget_size_allocate;
+  widget_class->snapshot = gtk_font_chooser_widget_snapshot;
 
   gobject_class->finalize = gtk_font_chooser_widget_finalize;
+  gobject_class->dispose = gtk_font_chooser_widget_dispose;
   gobject_class->set_property = gtk_font_chooser_widget_set_property;
   gobject_class->get_property = gtk_font_chooser_widget_get_property;
 
@@ -597,6 +654,7 @@ gtk_font_chooser_widget_class_init (GtkFontChooserWidgetClass *klass)
   gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, preview);
   gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, size_spin);
   gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, size_slider);
+  gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserWidget, grid);
 
   gtk_widget_class_bind_template_callback (widget_class, text_changed_cb);
   gtk_widget_class_bind_template_callback (widget_class, stop_search_cb);
@@ -621,6 +679,8 @@ gtk_font_chooser_widget_init (GtkFontChooserWidget *fontchooser)
   fontchooser->priv = gtk_font_chooser_widget_get_instance_private (fontchooser);
   priv = fontchooser->priv;
 
+  gtk_widget_set_has_window (GTK_WIDGET (fontchooser), FALSE);
+
   gtk_widget_init_template (GTK_WIDGET (fontchooser));
 
   /* Default preview string  */
diff --git a/gtk/gtkfontchooserwidget.h b/gtk/gtkfontchooserwidget.h
index ae4a764..a367091 100644
--- a/gtk/gtkfontchooserwidget.h
+++ b/gtk/gtkfontchooserwidget.h
@@ -22,7 +22,7 @@
 #error "Only <gtk/gtk.h> can be included directly."
 #endif
 
-#include <gtk/gtkbox.h>
+#include <gtk/gtkwidget.h>
 
 G_BEGIN_DECLS
 
@@ -39,7 +39,7 @@ typedef struct _GtkFontChooserWidgetClass         GtkFontChooserWidgetClass;
 
 struct _GtkFontChooserWidget
 {
-  GtkBox parent_instance;
+  GtkWidget parent_instance;
 
   /*< private >*/
   GtkFontChooserWidgetPrivate *priv;
@@ -51,7 +51,7 @@ struct _GtkFontChooserWidget
  */
 struct _GtkFontChooserWidgetClass
 {
-  GtkBoxClass parent_class;
+  GtkWidgetClass parent_class;
 
   /*< private >*/
 
diff --git a/gtk/ui/gtkfontchooserdialog.ui b/gtk/ui/gtkfontchooserdialog.ui
index ff5a957..2b505d0 100644
--- a/gtk/ui/gtkfontchooserdialog.ui
+++ b/gtk/ui/gtkfontchooserdialog.ui
@@ -12,9 +12,6 @@
         <child>
           <object class="GtkFontChooserWidget" id="fontchooser">
             <property name="visible">1</property>
-            <property name="orientation">vertical</property>
-            <property name="spacing">6</property>
-            <property name="margin">5</property>
             <signal name="font-activated" handler="font_activated_cb" swapped="no"/>
           </object>
           <packing>
diff --git a/gtk/ui/gtkfontchooserwidget.ui b/gtk/ui/gtkfontchooserwidget.ui
index bb27c83..34f0abe 100644
--- a/gtk/ui/gtkfontchooserwidget.ui
+++ b/gtk/ui/gtkfontchooserwidget.ui
@@ -30,9 +30,9 @@
     <property name="page-increment">10</property>
     <signal name="value-changed" handler="size_change_cb" swapped="no"/>
   </object>
-  <template class="GtkFontChooserWidget" parent="GtkBox">
+  <template class="GtkFontChooserWidget" parent="GtkWidget">
     <child>
-      <object class="GtkGrid" id="grid1">
+      <object class="GtkGrid" id="grid">
         <property name="visible">1</property>
         <property name="row-spacing">6</property>
         <property name="column-spacing">6</property>
@@ -205,9 +205,6 @@
           </packing>
         </child>
       </object>
-      <packing>
-        <property name="expand">1</property>
-      </packing>
     </child>
   </template>
   <object class="GThemedIcon" id="fonticon">


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