]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkobject.c
Make the new GtkAction code work with PolicyKit-gnome's use of actions.
[~andy/gtk] / gtk / gtkobject.c
index 5e069909081b4213701fd8612d8461ff28b8221c..a90f26bb6936cfb9ebf0a9d0df4ad5dba6d70b97 100644 (file)
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
  */
 
-#include <config.h>
+#include "config.h"
+
 #include <stdarg.h>
 #include <string.h>
 #include <stdio.h>
-#include "gtkalias.h"
+
+#undef GTK_DISABLE_DEPRECATED
+
 #include "gtkobject.h"
+#include "gtkintl.h"
 #include "gtkmarshalers.h"
-#include "gtksignal.h"
+#include "gtkprivate.h"
+
+#include "gtkalias.h"
 
 
 enum {
@@ -44,7 +50,6 @@ enum {
 };
 
 
-extern void      gtk_object_init_type           (void);        /* for gtktypeutils.h */
 static void       gtk_object_base_class_init     (GtkObjectClass *class);
 static void       gtk_object_base_class_finalize (GtkObjectClass *class);
 static void       gtk_object_class_init          (GtkObjectClass *klass);
@@ -80,7 +85,7 @@ gtk_object_get_type (void)
 
   if (!object_type)
     {
-      static const GTypeInfo object_info =
+      const GTypeInfo object_info =
       {
        sizeof (GtkObjectClass),
        (GBaseInitFunc) gtk_object_base_class_init,
@@ -94,7 +99,7 @@ gtk_object_get_type (void)
        NULL,           /* value_table */
       };
       
-      object_type = g_type_register_static (G_TYPE_OBJECT, "GtkObject"
+      object_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, I_("GtkObject")
                                            &object_info, G_TYPE_FLAG_ABSTRACT);
     }
 
@@ -211,7 +216,7 @@ gtk_arg_proxy_get_property (GObject     *object,
 
 void
 gtk_object_add_arg_type (const gchar *arg_name,
-                        GtkType      arg_type,
+                        GType        arg_type,
                         guint        arg_flags,
                         guint        arg_id)
 {
@@ -228,7 +233,7 @@ gtk_object_add_arg_type (const gchar *arg_name,
     g_return_if_fail ((arg_flags & G_PARAM_CONSTRUCT_ONLY) == 0);
   if (arg_flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY))
     g_return_if_fail (arg_flags & G_PARAM_WRITABLE);
-  g_return_if_fail ((arg_flags & ~(G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY)) == 0);
+  g_return_if_fail ((arg_flags & ~(G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_NAME)) == 0);
 
   pname = strchr (arg_name, ':');
   g_return_if_fail (pname && pname[1] == ':');
@@ -312,13 +317,46 @@ gtk_object_add_arg_type (const gchar *arg_name,
   g_object_class_install_property (oclass, arg_id, pspec);
 }
 
+static guint (*gobject_floating_flag_handler) (GtkObject*,gint) = NULL;
+
+static guint
+gtk_object_floating_flag_handler (GtkObject *object,
+                                  gint       job)
+{
+  /* FIXME: remove this whole thing once GTK+ breaks ABI */
+  if (!GTK_IS_OBJECT (object))
+    return gobject_floating_flag_handler (object, job);
+  switch (job)
+    {
+      guint32 oldvalue;
+    case +1:    /* force floating if possible */
+      do
+        oldvalue = g_atomic_int_get (&object->flags);
+      while (!g_atomic_int_compare_and_exchange (&object->flags, oldvalue, oldvalue | GTK_FLOATING));
+      return oldvalue & GTK_FLOATING;
+    case -1:    /* sink if possible */
+      do
+        oldvalue = g_atomic_int_get (&object->flags);
+      while (!g_atomic_int_compare_and_exchange (&object->flags, oldvalue, oldvalue & ~(guint32) GTK_FLOATING));
+      return oldvalue & GTK_FLOATING;
+    default:    /* check floating */
+      return 0 != (g_atomic_int_get (&object->flags) & GTK_FLOATING);
+    }
+}
+
 static void
 gtk_object_class_init (GtkObjectClass *class)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (class);
+  gboolean is_glib_2_10_1;
 
   parent_class = g_type_class_ref (G_TYPE_OBJECT);
 
+  is_glib_2_10_1 = g_object_compat_control (3, &gobject_floating_flag_handler);
+  if (!is_glib_2_10_1)
+    g_error ("this version of Gtk+ requires GLib-2.10.1");
+  g_object_compat_control (2, gtk_object_floating_flag_handler);
+
   gobject_class->set_property = gtk_object_set_property;
   gobject_class->get_property = gtk_object_get_property;
   gobject_class->dispose = gtk_object_dispose;
@@ -328,11 +366,12 @@ gtk_object_class_init (GtkObjectClass *class)
 
   g_object_class_install_property (gobject_class,
                                   PROP_USER_DATA,
-                                  g_param_spec_pointer ("user_data", "User Data",
-                                                        "Anonymous User Data Pointer",
-                                                        G_PARAM_READABLE | G_PARAM_WRITABLE));
+                                  g_param_spec_pointer ("user-data", 
+                                                        P_("User Data"),
+                                                        P_("Anonymous User Data Pointer"),
+                                                        GTK_PARAM_READWRITE));
   object_signals[DESTROY] =
-    g_signal_new ("destroy",
+    g_signal_new (I_("destroy"),
                  G_TYPE_FROM_CLASS (gobject_class),
                  G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
                  G_STRUCT_OFFSET (GtkObjectClass, destroy),
@@ -345,7 +384,12 @@ static void
 gtk_object_init (GtkObject      *object,
                 GtkObjectClass *klass)
 {
-  GTK_OBJECT_FLAGS (object) = GTK_FLOATING;
+  gboolean was_floating;
+  /* sink the GInitiallyUnowned floating flag */
+  was_floating = gobject_floating_flag_handler (object, -1);
+  /* set GTK_FLOATING via gtk_object_floating_flag_handler */
+  if (was_floating)
+    g_object_force_floating (G_OBJECT (object));
 }
 
 /********************************************
@@ -393,13 +437,12 @@ gtk_object_finalize (GObject *gobject)
 {
   GtkObject *object = GTK_OBJECT (gobject);
 
-  if (GTK_OBJECT_FLOATING (object))
+  if (g_object_is_floating (object))
     {
       g_warning ("A floating object was finalized. This means that someone\n"
                 "called g_object_unref() on an object that had only a floating\n"
                 "reference; the initial floating reference is not owned by anyone\n"
-                "and must be removed with gtk_object_sink() after a normal\n"
-                "reference is obtained with g_object_ref().");
+                "and must be removed with g_object_ref_sink().");
     }
   
   gtk_object_notify_weaks (object);
@@ -421,7 +464,7 @@ gtk_object_set_property (GObject      *object,
   switch (property_id)
     {
     case PROP_USER_DATA:
-      g_object_set_data (G_OBJECT (object), "user_data", g_value_get_pointer (value));
+      g_object_set_data (G_OBJECT (object), I_("user_data"), g_value_get_pointer (value));
       break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -446,24 +489,12 @@ gtk_object_get_property (GObject     *object,
     }
 }
 
-/*****************************************
- * gtk_object_sink:
- *
- *   arguments:
- *
- *   results:
- *****************************************/
-
 void
 gtk_object_sink (GtkObject *object)
 {
   g_return_if_fail (GTK_IS_OBJECT (object));
-
-  if (GTK_OBJECT_FLOATING (object))
-    {
-      GTK_OBJECT_UNSET_FLAGS (object, GTK_FLOATING);
-      g_object_unref (object);
-    }
+  g_object_ref_sink (object);
+  g_object_unref (object);
 }
 
 /*****************************************
@@ -489,15 +520,15 @@ typedef struct _GtkWeakRef        GtkWeakRef;
 
 struct _GtkWeakRef
 {
-  GtkWeakRef      *next;
-  GtkDestroyNotify  notify;
-  gpointer          data;
+  GtkWeakRef    *next;
+  GDestroyNotify  notify;
+  gpointer        data;
 };
 
 void
-gtk_object_weakref (GtkObject        *object,
-                   GtkDestroyNotify  notify,
-                   gpointer          data)
+gtk_object_weakref (GtkObject      *object,
+                   GDestroyNotify  notify,
+                   gpointer        data)
 {
   GtkWeakRef *weak;
 
@@ -515,9 +546,9 @@ gtk_object_weakref (GtkObject        *object,
 }
 
 void
-gtk_object_weakunref (GtkObject        *object,
-                     GtkDestroyNotify  notify,
-                     gpointer          data)
+gtk_object_weakunref (GtkObject      *object,
+                     GDestroyNotify  notify,
+                     gpointer        data)
 {
   GtkWeakRef *weaks, *w, **wp;
 
@@ -562,7 +593,7 @@ gtk_object_notify_weaks (GtkObject *object)
 }
 
 GtkObject*
-gtk_object_new (GtkType      object_type,
+gtk_object_new (GType        object_type,
                const gchar *first_property_name,
                ...)
 {
@@ -633,10 +664,10 @@ gtk_object_set_data (GtkObject        *object,
 }
 
 void
-gtk_object_set_data_by_id_full (GtkObject        *object,
-                               GQuark            data_id,
-                               gpointer          data,
-                               GtkDestroyNotify  destroy)
+gtk_object_set_data_by_id_full (GtkObject      *object,
+                               GQuark          data_id,
+                               gpointer        data,
+                               GDestroyNotify  destroy)
 {
   g_return_if_fail (GTK_IS_OBJECT (object));
 
@@ -644,10 +675,10 @@ gtk_object_set_data_by_id_full (GtkObject        *object,
 }
 
 void
-gtk_object_set_data_full (GtkObject        *object,
-                         const gchar      *key,
-                         gpointer          data,
-                         GtkDestroyNotify  destroy)
+gtk_object_set_data_full (GtkObject      *object,
+                         const gchar    *key,
+                         gpointer        data,
+                         GDestroyNotify  destroy)
 {
   g_return_if_fail (GTK_IS_OBJECT (object));
   g_return_if_fail (key != NULL);
@@ -744,3 +775,6 @@ gtk_object_unref (GtkObject *object)
 
   g_object_unref ((GObject*) object);
 }
+
+#define __GTK_OBJECT_C__
+#include "gtkaliasdef.c"