[gtk/child-properties-be-gone] container: Reduce boilerplate



commit 24bda9ecd2152074dd16380b791bb0ae92d9da10
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Apr 5 04:43:36 2019 +0000

    container: Reduce boilerplate
    
    We no longer need to hand-roll the type registration,
    since we no longer install our own param spec pool.

 gtk/gtkcontainer.c | 109 +++++++----------------------------------------------
 gtk/gtkwidget.c    |  20 +++++++---
 2 files changed, 29 insertions(+), 100 deletions(-)
---
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c
index 3963e4ea32..41a74e4663 100644
--- a/gtk/gtkcontainer.c
+++ b/gtk/gtkcontainer.c
@@ -109,15 +109,7 @@ enum {
   LAST_SIGNAL
 };
 
-#define PARAM_SPEC_PARAM_ID(pspec)              ((pspec)->param_id)
-#define PARAM_SPEC_SET_PARAM_ID(pspec, id)      ((pspec)->param_id = (id))
-
-
 /* --- prototypes --- */
-static void     gtk_container_base_class_init      (GtkContainerClass *klass);
-static void     gtk_container_base_class_finalize  (GtkContainerClass *klass);
-static void     gtk_container_class_init           (GtkContainerClass *klass);
-static void     gtk_container_init                 (GtkContainer      *container);
 static void     gtk_container_destroy              (GtkWidget         *widget);
 static void     gtk_container_add_unimplemented    (GtkContainer      *container,
                                                     GtkWidget         *widget);
@@ -138,80 +130,16 @@ static GtkWidgetPath * gtk_container_real_get_path_for_child (GtkContainer *cont
 
 /* GtkBuildable */
 static void gtk_container_buildable_init           (GtkBuildableIface *iface);
-static void gtk_container_buildable_add_child      (GtkBuildable *buildable,
-                                                    GtkBuilder   *builder,
-                                                    GObject      *child,
-                                                    const gchar  *type);
+static GtkBuildableIface    *parent_buildable_iface;
 
-/* --- variables --- */
 static GQuark                vadjustment_key_id;
 static GQuark                hadjustment_key_id;
 static guint                 container_signals[LAST_SIGNAL] = { 0 };
-static gint                  GtkContainer_private_offset;
-static GtkWidgetClass       *gtk_container_parent_class = NULL;
-static GtkBuildableIface    *parent_buildable_iface;
-
-
-/* --- functions --- */
-static inline gpointer
-gtk_container_get_instance_private (GtkContainer *self)
-{
-  return G_STRUCT_MEMBER_P (self, GtkContainer_private_offset);
-}
-
-GType
-gtk_container_get_type (void)
-{
-  static GType container_type = 0;
 
-  if (!container_type)
-    {
-      const GTypeInfo container_info =
-      {
-        sizeof (GtkContainerClass),
-        (GBaseInitFunc) gtk_container_base_class_init,
-        (GBaseFinalizeFunc) gtk_container_base_class_finalize,
-        (GClassInitFunc) gtk_container_class_init,
-        NULL        /* class_finalize */,
-        NULL        /* class_data */,
-        sizeof (GtkContainer),
-        0           /* n_preallocs */,
-        (GInstanceInitFunc) gtk_container_init,
-        NULL,       /* value_table */
-      };
-
-      const GInterfaceInfo buildable_info =
-      {
-        (GInterfaceInitFunc) gtk_container_buildable_init,
-        NULL,
-        NULL
-      };
-
-      container_type =
-        g_type_register_static (GTK_TYPE_WIDGET, I_("GtkContainer"),
-                                &container_info, G_TYPE_FLAG_ABSTRACT);
-
-      GtkContainer_private_offset =
-        g_type_add_instance_private (container_type, sizeof (GtkContainerPrivate));
-
-      g_type_add_interface_static (container_type,
-                                   GTK_TYPE_BUILDABLE,
-                                   &buildable_info);
-
-    }
-
-  return container_type;
-}
-
-static void
-gtk_container_base_class_init (GtkContainerClass *class)
-{
-}
-
-static void
-gtk_container_base_class_finalize (GtkContainerClass *class)
-{
-}
+G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GtkContainer, gtk_container, GTK_TYPE_WIDGET,
+                                  G_ADD_PRIVATE (GtkContainer)
+                                  G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
+                                                         gtk_container_buildable_init))
 
 static void
 gtk_container_class_init (GtkContainerClass *class)
@@ -219,8 +147,6 @@ gtk_container_class_init (GtkContainerClass *class)
   GObjectClass *gobject_class = G_OBJECT_CLASS (class);
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
 
-  gtk_container_parent_class = g_type_class_peek_parent (class);
-
   vadjustment_key_id = g_quark_from_static_string ("gtk-vadjustment");
   hadjustment_key_id = g_quark_from_static_string ("gtk-hadjustment");
 
@@ -254,19 +180,9 @@ gtk_container_class_init (GtkContainerClass *class)
                   G_TYPE_NONE, 1,
                   GTK_TYPE_WIDGET);
 
-  if (GtkContainer_private_offset != 0)
-    g_type_class_adjust_private_offset (class, &GtkContainer_private_offset);
-
   gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_CONTAINER_ACCESSIBLE);
 }
 
-static void
-gtk_container_buildable_init (GtkBuildableIface *iface)
-{
-  parent_buildable_iface = g_type_interface_peek_parent (iface);
-  iface->add_child = gtk_container_buildable_add_child;
-}
-
 static void
 gtk_container_buildable_add_child (GtkBuildable  *buildable,
                                    GtkBuilder    *builder,
@@ -277,13 +193,9 @@ gtk_container_buildable_add_child (GtkBuildable  *buildable,
       _gtk_widget_get_parent (GTK_WIDGET (child)) == NULL)
     {
       if (type)
-        {
-          GTK_BUILDER_WARN_INVALID_CHILD_TYPE (buildable, type);
-        }
+        GTK_BUILDER_WARN_INVALID_CHILD_TYPE (buildable, type);
       else
-        {
-          gtk_container_add (GTK_CONTAINER (buildable), GTK_WIDGET (child));
-        }
+        gtk_container_add (GTK_CONTAINER (buildable), GTK_WIDGET (child));
     }
   else
     {
@@ -291,6 +203,13 @@ gtk_container_buildable_add_child (GtkBuildable  *buildable,
     }
 }
 
+static void
+gtk_container_buildable_init (GtkBuildableIface *iface)
+{
+  parent_buildable_iface = g_type_interface_peek_parent (iface);
+  iface->add_child = gtk_container_buildable_add_child;
+}
+
 /**
  * gtk_container_child_type:
  * @container: a #GtkContainer
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index c7011be782..64deee9542 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -686,6 +686,11 @@ static gboolean         gtk_widget_buildable_custom_tag_start   (GtkBuildable
                                                                  const gchar      *tagname,
                                                                  GMarkupParser    *parser,
                                                                  gpointer         *data);
+static void             gtk_widget_buildable_custom_tag_end     (GtkBuildable     *buildable,
+                                                                 GtkBuilder       *builder,
+                                                                 GObject          *child,
+                                                                 const gchar      *tagname,
+                                                                 gpointer          data);
 static void             gtk_widget_buildable_custom_finished    (GtkBuildable     *buildable,
                                                                  GtkBuilder       *builder,
                                                                  GObject          *child,
@@ -2987,7 +2992,6 @@ void
 gtk_widget_unparent (GtkWidget *widget)
 {
   GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
-  GObjectNotifyQueue *nqueue;
   GtkWidget *old_parent;
   GtkWidget *old_prev_sibling;
   GtkWidget *toplevel;
@@ -3002,7 +3006,6 @@ gtk_widget_unparent (GtkWidget *widget)
   gtk_widget_push_verify_invariants (widget);
 
   g_object_freeze_notify (G_OBJECT (widget));
-  nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
 
   toplevel = _gtk_widget_get_toplevel (widget);
   if (_gtk_widget_is_toplevel (toplevel))
@@ -3091,9 +3094,6 @@ gtk_widget_unparent (GtkWidget *widget)
 
   g_object_notify_by_pspec (G_OBJECT (widget), widget_props[PROP_PARENT]);
   g_object_thaw_notify (G_OBJECT (widget));
-  if (!priv->parent)
-    g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
-  g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
 
   gtk_widget_pop_verify_invariants (widget);
   g_object_unref (widget);
@@ -9469,6 +9469,7 @@ gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
   iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
   iface->parser_finished = gtk_widget_buildable_parser_finished;
   iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
+  iface->custom_tag_end = gtk_widget_buildable_custom_tag_end;
   iface->custom_finished = gtk_widget_buildable_custom_finished;
   iface->add_child = gtk_widget_buildable_add_child;
 }
@@ -10137,6 +10138,15 @@ gtk_widget_buildable_custom_tag_start (GtkBuildable     *buildable,
   return FALSE;
 }
 
+static void
+gtk_widget_buildable_custom_tag_end (GtkBuildable  *buildable,
+                                     GtkBuilder    *builder,
+                                     GObject       *child,
+                                     const gchar   *tagname,
+                                     gpointer       data)
+{
+}
+
 void
 _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
                                           GtkWidget *toplevel,


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