[gtk+] Revert "tool button: Use G_DEFINE_TYPE"



commit 1c4a7bd552ea2f954c91e7a2169166140122e24a
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Sep 14 11:15:32 2015 -0400

    Revert "tool button: Use G_DEFINE_TYPE"
    
    This reverts commit 4e56dfad0e33187d019c44ecfb5e7e99cf2da535.
    
    It turns out that GtkToolButton is playing games with the class
    pointer inside instance_init, so leave it alone.

 gtk/gtktoolbutton.c |   69 +++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 54 insertions(+), 15 deletions(-)
---
diff --git a/gtk/gtktoolbutton.c b/gtk/gtktoolbutton.c
index 5cdbcc1..8ccf3cf 100644
--- a/gtk/gtktoolbutton.c
+++ b/gtk/gtktoolbutton.c
@@ -82,6 +82,9 @@ enum {
   PROP_ACTION_TARGET
 };
 
+static void gtk_tool_button_init          (GtkToolButton      *button,
+                                          GtkToolButtonClass *klass);
+static void gtk_tool_button_class_init    (GtkToolButtonClass *klass);
 static void gtk_tool_button_set_property  (GObject            *object,
                                           guint               prop_id,
                                           const GValue       *value,
@@ -127,14 +130,47 @@ struct _GtkToolButtonPrivate
   guint contents_invalid : 1;
 };
 
+static GObjectClass        *parent_class = NULL;
 static GtkActivatableIface *parent_activatable_iface;
 static guint                toolbutton_signals[LAST_SIGNAL] = { 0 };
 
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-G_DEFINE_TYPE_WITH_CODE (GtkToolButton, gtk_tool_button, GTK_TYPE_TOOL_ITEM,
-                         G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIONABLE, gtk_tool_button_actionable_iface_init)
-                         G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE, 
gtk_tool_button_activatable_interface_init))
-G_GNUC_END_IGNORE_DEPRECATIONS
+GType
+gtk_tool_button_get_type (void)
+{
+  static GType g_define_type_id = 0;
+
+  if (!g_define_type_id)
+    {
+      const GInterfaceInfo actionable_info =
+      {
+        (GInterfaceInitFunc) gtk_tool_button_actionable_iface_init,
+        (GInterfaceFinalizeFunc) NULL,
+        NULL
+      };
+      const GInterfaceInfo activatable_info =
+      {
+        (GInterfaceInitFunc) gtk_tool_button_activatable_interface_init,
+        (GInterfaceFinalizeFunc) NULL,
+        NULL
+      };
+
+      g_define_type_id = g_type_register_static_simple (GTK_TYPE_TOOL_ITEM,
+                                                        I_("GtkToolButton"),
+                                                        sizeof (GtkToolButtonClass),
+                                                        (GClassInitFunc) gtk_tool_button_class_init,
+                                                        sizeof (GtkToolButton),
+                                                        (GInstanceInitFunc) gtk_tool_button_init,
+                                                        0);
+
+      G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
+      g_type_add_interface_static (g_define_type_id,
+                                   GTK_TYPE_ACTIONABLE, &actionable_info);
+      g_type_add_interface_static (g_define_type_id,
+                                   GTK_TYPE_ACTIVATABLE, &activatable_info);
+      G_GNUC_END_IGNORE_DEPRECATIONS;
+    }
+  return g_define_type_id;
+}
 
 static void
 gtk_tool_button_class_init (GtkToolButtonClass *klass)
@@ -142,11 +178,13 @@ gtk_tool_button_class_init (GtkToolButtonClass *klass)
   GObjectClass *object_class;
   GtkWidgetClass *widget_class;
   GtkToolItemClass *tool_item_class;
-
+  
+  parent_class = g_type_class_peek_parent (klass);
+  
   object_class = (GObjectClass *)klass;
   widget_class = (GtkWidgetClass *)klass;
   tool_item_class = (GtkToolItemClass *)klass;
-
+  
   object_class->set_property = gtk_tool_button_set_property;
   object_class->get_property = gtk_tool_button_get_property;
   object_class->notify = gtk_tool_button_property_notify;
@@ -156,7 +194,7 @@ gtk_tool_button_class_init (GtkToolButtonClass *klass)
 
   tool_item_class->create_menu_proxy = gtk_tool_button_create_menu_proxy;
   tool_item_class->toolbar_reconfigured = gtk_tool_button_toolbar_reconfigured;
-
+  
   klass->button_type = GTK_TYPE_BUTTON;
 
   /* Properties are interpreted like this:
@@ -293,7 +331,8 @@ gtk_tool_button_class_init (GtkToolButtonClass *klass)
 }
 
 static void
-gtk_tool_button_init (GtkToolButton *button)
+gtk_tool_button_init (GtkToolButton      *button,
+                     GtkToolButtonClass *klass)
 {
   GtkToolItem *toolitem = GTK_TOOL_ITEM (button);
 
@@ -306,7 +345,7 @@ gtk_tool_button_init (GtkToolButton *button)
   gtk_tool_item_set_homogeneous (toolitem, TRUE);
 
   /* create button */
-  button->priv->button = g_object_new (GTK_TOOL_BUTTON_GET_CLASS (button)->button_type, NULL);
+  button->priv->button = g_object_new (klass->button_type, NULL);
   gtk_button_set_focus_on_click (GTK_BUTTON (button->priv->button), FALSE);
   g_signal_connect_object (button->priv->button, "clicked",
                           G_CALLBACK (button_clicked), button, 0);
@@ -658,8 +697,8 @@ gtk_tool_button_property_notify (GObject          *object,
       strcmp ("is-important", pspec->name) == 0)
     gtk_tool_button_construct_contents (GTK_TOOL_ITEM (object));
 
-  if (G_OBJECT_CLASS (gtk_tool_button_parent_class)->notify)
-    G_OBJECT_CLASS (gtk_tool_button_parent_class)->notify (object, pspec);
+  if (parent_class->notify)
+    parent_class->notify (object, pspec);
 }
 
 static void
@@ -759,8 +798,8 @@ gtk_tool_button_finalize (GObject *object)
 
   if (button->priv->icon_widget)
     g_object_unref (button->priv->icon_widget);
-
-  G_OBJECT_CLASS (gtk_tool_button_parent_class)->finalize (object);
+  
+  parent_class->finalize (object);
 }
 
 static GtkWidget *
@@ -930,7 +969,7 @@ gtk_tool_button_update_icon_spacing (GtkToolButton *button)
 static void
 gtk_tool_button_style_updated (GtkWidget *widget)
 {
-  GTK_WIDGET_CLASS (gtk_tool_button_parent_class)->style_updated (widget);
+  GTK_WIDGET_CLASS (parent_class)->style_updated (widget);
 
   gtk_tool_button_update_icon_spacing (GTK_TOOL_BUTTON (widget));
 }


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