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



commit 1453a7b73c6afbe8c683f2faca30503a4fdc4293
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 | 163 +++++++++++------------------------------------------
 gtk/gtkwidget.c    |  20 +++++--
 2 files changed, 49 insertions(+), 134 deletions(-)
---
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c
index 47c375c6ef..bbc6968bdf 100644
--- a/gtk/gtkcontainer.c
+++ b/gtk/gtkcontainer.c
@@ -51,14 +51,14 @@
  * @Short_description: Base class for widgets which contain other widgets
  * @Title: GtkContainer
  *
- * A GTK+ user interface is constructed by nesting widgets inside widgets.
+ * A GTK user interface is constructed by nesting widgets inside widgets.
  * Container widgets are the inner nodes in the resulting tree of widgets:
  * they contain other widgets. So, for example, you might have a #GtkWindow
  * containing a #GtkFrame containing a #GtkLabel. If you wanted an image instead
  * of a textual label inside the frame, you might replace the #GtkLabel widget
  * with a #GtkImage widget.
  *
- * There are two major kinds of container widgets in GTK+. Both are subclasses
+ * There are two major kinds of container widgets in GTK. Both are subclasses
  * of the abstract GtkContainer base class.
  *
  * The first type of container widget has a single child widget and derives
@@ -81,6 +81,7 @@
  * If the GtkContainer implementation has internal children, they should be added
  * with gtk_widget_set_parent() on init() and removed with gtk_widget_unparent()
  * in the #GtkWidgetClass.destroy() implementation.
+ *
  * See more about implementing custom widgets at https://wiki.gnome.org/HowDoI/CustomWidgets
  */
 
@@ -98,15 +99,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);
@@ -117,7 +110,6 @@ static void     gtk_container_compute_expand       (GtkWidget         *widget,
                                                     gboolean          *vexpand_p);
 static void     gtk_container_real_set_focus_child (GtkContainer      *container,
                                                     GtkWidget         *widget);
-
 static void     gtk_container_children_callback    (GtkWidget         *widget,
                                                     gpointer           client_data);
 static GtkSizeRequestMode gtk_container_get_request_mode (GtkWidget   *widget);
@@ -127,80 +119,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)
@@ -208,8 +136,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");
 
@@ -243,19 +169,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,
@@ -266,13 +182,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
     {
@@ -280,6 +192,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
@@ -290,37 +209,31 @@ gtk_container_buildable_add_child (GtkBuildable  *buildable,
  * children can be added, e.g. for a #GtkPaned which already has two
  * children.
  *
- * Returns: a #GType.
+ * Returns: a #GType
  **/
 GType
 gtk_container_child_type (GtkContainer *container)
 {
-  GType slot;
-  GtkContainerClass *class;
-
   g_return_val_if_fail (GTK_IS_CONTAINER (container), 0);
 
-  class = GTK_CONTAINER_GET_CLASS (container);
-  if (class->child_type)
-    slot = class->child_type (container);
+  if (GTK_CONTAINER_GET_CLASS (container)->child_type)
+    return GTK_CONTAINER_GET_CLASS (container)->child_type (container);
   else
-    slot = G_TYPE_NONE;
-
-  return slot;
+    return G_TYPE_NONE;
 }
 
 static void
-gtk_container_add_unimplemented (GtkContainer     *container,
-                                 GtkWidget        *widget)
+gtk_container_add_unimplemented (GtkContainer *container,
+                                 GtkWidget    *widget)
 {
-  g_warning ("GtkContainerClass::add not implemented for '%s'", g_type_name (G_TYPE_FROM_INSTANCE 
(container)));
+  g_warning ("GtkContainerClass::add not implemented for '%s'", G_OBJECT_TYPE_NAME (container));
 }
 
 static void
-gtk_container_remove_unimplemented (GtkContainer     *container,
-                                    GtkWidget        *widget)
+gtk_container_remove_unimplemented (GtkContainer *container,
+                                    GtkWidget    *widget)
 {
-  g_warning ("GtkContainerClass::remove not implemented for '%s'", g_type_name (G_TYPE_FROM_INSTANCE 
(container)));
+  g_warning ("GtkContainerClass::remove not implemented for '%s'", G_OBJECT_TYPE_NAME (container));
 }
 
 static void
@@ -376,9 +289,9 @@ gtk_container_add (GtkContainer *container,
       g_warning ("Attempting to add a widget with type %s to a container of "
                  "type %s, but the widget is already inside a container of type %s, "
                  "please remove the widget from its existing container first." ,
-                 g_type_name (G_OBJECT_TYPE (widget)),
-                 g_type_name (G_OBJECT_TYPE (container)),
-                 g_type_name (G_OBJECT_TYPE (parent)));
+                 G_OBJECT_TYPE_NAME (widget),
+                 G_OBJECT_TYPE_NAME (container),
+                 G_OBJECT_TYPE_NAME (parent));
       return;
     }
 
@@ -584,9 +497,7 @@ gtk_container_forall (GtkContainer *container,
   g_return_if_fail (GTK_IS_CONTAINER (container));
   g_return_if_fail (callback != NULL);
 
-  gtk_widget_forall (GTK_WIDGET (container),
-                     callback,
-                     callback_data);
+  gtk_widget_forall (GTK_WIDGET (container), callback, callback_data);
 }
 
 /**
@@ -612,15 +523,11 @@ gtk_container_foreach (GtkContainer *container,
                        GtkCallback   callback,
                        gpointer      callback_data)
 {
-  GtkContainerClass *class;
-
   g_return_if_fail (GTK_IS_CONTAINER (container));
   g_return_if_fail (callback != NULL);
 
-  class = GTK_CONTAINER_GET_CLASS (container);
-
-  if (class->forall)
-    class->forall (container, callback, callback_data);
+  if (GTK_CONTAINER_GET_CLASS (container)->forall)
+    GTK_CONTAINER_GET_CLASS (container)->forall (container, callback, callback_data);
 }
 
 /**
@@ -746,10 +653,8 @@ gtk_container_real_get_path_for_child (GtkContainer *container,
                                        GtkWidget    *child)
 {
   GtkWidgetPath *path;
-  GtkWidget *widget = GTK_WIDGET (container);
-
-  path = _gtk_widget_create_path (widget);
 
+  path = _gtk_widget_create_path (GTK_WIDGET (container));
   gtk_widget_path_append_for_widget (path, child);
 
   return path;
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]