]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkclipboard.c
Declare gtk_tree_row_reference_get_type(). It is already used by a macro
[~andy/gtk] / gtk / gtkclipboard.c
index 847bb85c4dea019400af7ef838c8d4f789128a96..8415918d4525a3cc0c845ffc44e664fef7f17fc0 100644 (file)
@@ -24,7 +24,6 @@
 #include "gtkclipboard.h"
 #include "gtkinvisible.h"
 #include "gtkmain.h"
-#include "gtksignal.h"
 
 #ifdef GDK_WINDOWING_X11
 #include "x11/gdkx.h"
 #include "win32/gdkwin32.h"
 #endif
 
+typedef struct _GtkClipboardClass GtkClipboardClass;
+
 typedef struct _RequestContentsInfo RequestContentsInfo;
 typedef struct _RequestTextInfo RequestTextInfo;
 
 struct _GtkClipboard 
 {
+  GObject parent_instance;
+
   GdkAtom selection;
 
   GtkClipboardGetFunc get_func;
@@ -52,6 +55,11 @@ struct _GtkClipboard
   GdkDisplay *display;
 };
 
+struct _GtkClipboardClass
+{
+  GObjectClass parent_class;
+};
+
 struct _RequestContentsInfo
 {
   GtkClipboardReceivedFunc callback;
@@ -64,6 +72,9 @@ struct _RequestTextInfo
   gpointer user_data;
 };
 
+static void gtk_clipboard_class_init (GtkClipboardClass *class);
+static void gtk_clipboard_finalize   (GObject           *object);
+
 static void clipboard_unset    (GtkClipboard     *clipboard);
 static void selection_received (GtkWidget        *widget,
                                GtkSelectionData *selection_data,
@@ -81,7 +92,67 @@ static GQuark request_contents_key_id = 0;
 
 static const gchar *clipboards_owned_key = "gtk-clipboards-owned";
 static GQuark clipboards_owned_key_id = 0;
+
+static GObjectClass *parent_class;
+
+GType
+gtk_clipboard_get_type (void)
+{
+  static GType clipboard_type = 0;
   
+  if (!clipboard_type)
+    {
+      static const GTypeInfo clipboard_info =
+      {
+       sizeof (GtkClipboardClass),
+       NULL,           /* base_init */
+       NULL,           /* base_finalize */
+       (GClassInitFunc) gtk_clipboard_class_init,
+       NULL,           /* class_finalize */
+       NULL,           /* class_data */
+       sizeof (GtkClipboard),
+       0,              /* n_preallocs */
+       (GInstanceInitFunc) NULL,
+      };
+      
+      clipboard_type = g_type_register_static (G_TYPE_OBJECT, "GtkClipboard",
+                                              &clipboard_info, 0);
+    }
+  
+  return clipboard_type;
+}
+
+static void
+gtk_clipboard_class_init (GtkClipboardClass *class)
+{
+  GObjectClass *gobject_class = G_OBJECT_CLASS (class);
+
+  parent_class = g_type_class_peek_parent (class);
+  
+  gobject_class->finalize = gtk_clipboard_finalize;
+}
+
+static void
+gtk_clipboard_finalize   (GObject *object)
+{
+  clipboard_unset (GTK_CLIPBOARD (object));
+}
+
+static void
+clipboard_display_closed (GdkDisplay   *display,
+                         gboolean      is_error,
+                         GtkClipboard *clipboard)
+{
+  GSList *clipboards;
+
+  clipboards = g_object_get_data (G_OBJECT (display), "gtk-clipboard-list");
+  g_object_run_dispose (G_OBJECT (clipboard));
+  g_object_unref (clipboard);
+  clipboards = g_slist_remove (clipboards, clipboard);
+  
+  g_object_set_data (G_OBJECT (display), "gtk-clipboard-list", clipboards);
+}
+
 /**
  * gtk_clipboard_get_for_display:
  * @display: the display for which the clipboard is to be retrieved or created
@@ -119,6 +190,8 @@ static GQuark clipboards_owned_key_id = 0;
  *             be created. Once a clipboard object has
  *             been created, it is persistent for all time and
  *             cannot be freed.
+ *
+ * Since: 2.2
  **/
 GtkClipboard *
 gtk_clipboard_get_for_display (GdkDisplay *display, GdkAtom selection)
@@ -128,6 +201,7 @@ gtk_clipboard_get_for_display (GdkDisplay *display, GdkAtom selection)
   GSList *tmp_list;
 
   g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
+  g_return_val_if_fail (!display->closed, NULL);
 
   if (selection == GDK_NONE)
     selection = GDK_SELECTION_CLIPBOARD;
@@ -146,11 +220,13 @@ gtk_clipboard_get_for_display (GdkDisplay *display, GdkAtom selection)
 
   if (!tmp_list)
     {
-      clipboard = g_new0 (GtkClipboard, 1);
+      clipboard = g_object_new (GTK_TYPE_CLIPBOARD, NULL);
       clipboard->selection = selection;
       clipboard->display = display;
       clipboards = g_slist_prepend (clipboards, clipboard);
       g_object_set_data (G_OBJECT (display), "gtk-clipboard-list", clipboards);
+      g_signal_connect (display, "closed",
+                       G_CALLBACK (clipboard_display_closed), clipboard);
     }
   
   return clipboard;
@@ -173,14 +249,14 @@ gtk_clipboard_get_for_display (GdkDisplay *display, GdkAtom selection)
 GtkClipboard *
 gtk_clipboard_get (GdkAtom selection)
 {
-  return gtk_clipboard_get_for_display (gdk_get_default_display (), selection);
+  return gtk_clipboard_get_for_display (gdk_display_get_default (), selection);
 }
 
 static void 
 selection_get_cb (GtkWidget          *widget,
                  GtkSelectionData   *selection_data,
-                 guint               time,
-                 guint               info)
+                 guint               info,
+                 guint               time)
 {
   GtkClipboard *clipboard = gtk_widget_get_clipboard (widget, selection_data->selection);
 
@@ -209,18 +285,18 @@ make_clipboard_widget (GdkDisplay *display,
 {
   GtkWidget *widget = gtk_invisible_new_for_screen (gdk_display_get_default_screen (display));
 
-  gtk_signal_connect (GTK_OBJECT (widget), "selection_received",
-                     GTK_SIGNAL_FUNC (selection_received), NULL);
+  g_signal_connect (widget, "selection_received",
+                   G_CALLBACK (selection_received), NULL);
 
   if (provider)
     {
       /* We need this for gdk_x11_get_server_time() */
       gtk_widget_add_events (widget, GDK_PROPERTY_CHANGE_MASK);
       
-      gtk_signal_connect (GTK_OBJECT (widget), "selection_get",
-                         GTK_SIGNAL_FUNC (selection_get_cb), NULL);
-      gtk_signal_connect (GTK_OBJECT (widget), "selection_clear_event",
-                         GTK_SIGNAL_FUNC (selection_clear_event_cb), NULL);
+      g_signal_connect (widget, "selection_get",
+                       G_CALLBACK (selection_get_cb), NULL);
+      g_signal_connect (widget, "selection_clear_event",
+                       G_CALLBACK (selection_clear_event_cb), NULL);
     }
 
   return widget;
@@ -608,9 +684,7 @@ set_request_contents_info (GtkWidget           *widget,
   if (!request_contents_key_id)
     request_contents_key_id = g_quark_from_static_string (request_contents_key);
 
-  gtk_object_set_data_by_id (GTK_OBJECT (widget),
-                            request_contents_key_id,
-                            info);
+  g_object_set_qdata (G_OBJECT (widget), request_contents_key_id, info);
 }
 
 static RequestContentsInfo *
@@ -619,8 +693,7 @@ get_request_contents_info (GtkWidget *widget)
   if (!request_contents_key_id)
     return NULL;
   else
-    return gtk_object_get_data_by_id (GTK_OBJECT (widget),
-                                     request_contents_key_id);
+    return g_object_get_qdata (G_OBJECT (widget), request_contents_key_id);
 }
 
 static void 
@@ -777,7 +850,7 @@ clipboard_received_func (GtkClipboard     *clipboard,
   if (selection_data->length >= 0)
     results->data = gtk_selection_data_copy (selection_data);
   
-  g_main_quit (results->loop);
+  g_main_loop_quit (results->loop);
 }
 
 /**
@@ -805,20 +878,20 @@ gtk_clipboard_wait_for_contents (GtkClipboard *clipboard,
   g_return_val_if_fail (target != GDK_NONE, NULL);
   
   results.data = NULL;
-  results.loop = g_main_new (TRUE);
+  results.loop = g_main_loop_new (NULL, TRUE);
 
   gtk_clipboard_request_contents (clipboard, target, 
                                  clipboard_received_func,
                                  &results);
 
-  if (g_main_is_running (results.loop))
+  if (g_main_loop_is_running (results.loop))
     {
       GDK_THREADS_LEAVE ();
-      g_main_run (results.loop);
+      g_main_loop_run (results.loop);
       GDK_THREADS_ENTER ();
     }
 
-  g_main_destroy (results.loop);
+  g_main_loop_unref (results.loop);
 
   return results.data;
 }
@@ -831,7 +904,7 @@ clipboard_text_received_func (GtkClipboard *clipboard,
   WaitResults *results = data;
 
   results->data = g_strdup (text);
-  g_main_quit (results->loop);
+  g_main_loop_quit (results->loop);
 }
 
 
@@ -860,20 +933,20 @@ gtk_clipboard_wait_for_text (GtkClipboard *clipboard)
   g_return_val_if_fail (clipboard != NULL, NULL);
   
   results.data = NULL;
-  results.loop = g_main_new (TRUE);
+  results.loop = g_main_loop_new (NULL, TRUE);
 
   gtk_clipboard_request_text (clipboard,
                              clipboard_text_received_func,
                              &results);
 
-  if (g_main_is_running (results.loop))
+  if (g_main_loop_is_running (results.loop))
     {
       GDK_THREADS_LEAVE ();
-      g_main_run (results.loop);
+      g_main_loop_run (results.loop);
       GDK_THREADS_ENTER ();
     }
 
-  g_main_destroy (results.loop);
+  g_main_loop_unref (results.loop);
 
   return results.data;
 }
@@ -884,6 +957,8 @@ gtk_clipboard_wait_for_text (GtkClipboard *clipboard)
  * Gets the #GdkDisplay associated with @clipboard
  *
  * Return value: the #GdkDisplay associated with @clipboard
+ *
+ * Since: 2.2
  **/
 GdkDisplay *
 gtk_clipboard_get_display (GtkClipboard *clipboard)