]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkselection.c
Remove GtkObject completely
[~andy/gtk] / gtk / gtkselection.c
index 8adffcb6136059163b8a8c6f4cbd145164a8ac8d..0a18fba6b74cddd55417ff406d683143d3ffac9f 100644 (file)
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
  */
 
-#include <config.h>
+#include "config.h"
 #include <stdarg.h>
 #include <string.h>
 #include "gdk.h"
 
 #include "gtkmain.h"
+#include "gtkdebug.h"
 #include "gtkselection.h"
 #include "gtktextbufferrichtext.h"
 #include "gtkintl.h"
@@ -70,8 +71,6 @@
 #include "win32/gdkwin32.h"
 #endif
 
-#include "gtkalias.h"
-
 #undef DEBUG_SELECTION
 
 /* Maximum size of a sent chunk, in bytes. Also the default size of
@@ -94,6 +93,7 @@ enum {
   MULTIPLE,
   TARGETS,
   TIMESTAMP,
+  SAVE_TARGETS,
   LAST_ATOM
 };
 
@@ -634,8 +634,8 @@ gtk_target_table_free (GtkTargetEntry *targets,
 
 /**
  * gtk_selection_owner_set_for_display:
- * @display: the #Gdkdisplay where the selection is set 
- * @widget: new selection owner (a #GdkWidget), or %NULL.
+ * @display: the #Gdkdisplay where the selection is set
+ * @widget: (allow-none): new selection owner (a #GdkWidget), or %NULL.
  * @selection: an interned atom representing the selection to claim.
  * @time_: timestamp with which to claim the selection
  *
@@ -659,13 +659,13 @@ gtk_selection_owner_set_for_display (GdkDisplay   *display,
 
   g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
   g_return_val_if_fail (selection != GDK_NONE, FALSE);
-  g_return_val_if_fail (widget == NULL || GTK_WIDGET_REALIZED (widget), FALSE);
+  g_return_val_if_fail (widget == NULL || gtk_widget_get_realized (widget), FALSE);
   g_return_val_if_fail (widget == NULL || gtk_widget_get_display (widget) == display, FALSE);
   
   if (widget == NULL)
     window = NULL;
   else
-    window = widget->window;
+    window = gtk_widget_get_window (widget);
 
   tmp_list = current_selections;
   while (tmp_list)
@@ -720,8 +720,8 @@ gtk_selection_owner_set_for_display (GdkDisplay   *display,
       if (old_owner && old_owner != widget)
        {
          GdkEvent *event = gdk_event_new (GDK_SELECTION_CLEAR);
-         
-         event->selection.window = g_object_ref (old_owner->window);
+
+          event->selection.window = g_object_ref (gtk_widget_get_window (old_owner));
          event->selection.selection = selection;
          event->selection.time = time;
          
@@ -737,7 +737,7 @@ gtk_selection_owner_set_for_display (GdkDisplay   *display,
 
 /**
  * gtk_selection_owner_set:
- * @widget:  a #GtkWidget, or %NULL.
+ * @widget: (allow-none):  a #GtkWidget, or %NULL.
  * @selection:  an interned atom representing the selection to claim
  * @time_: timestamp with which to claim the selection
  * 
@@ -753,7 +753,7 @@ gtk_selection_owner_set (GtkWidget *widget,
 {
   GdkDisplay *display;
   
-  g_return_val_if_fail (widget == NULL || GTK_WIDGET_REALIZED (widget), FALSE);
+  g_return_val_if_fail (widget == NULL || gtk_widget_get_realized (widget), FALSE);
   g_return_val_if_fail (selection != GDK_NONE, FALSE);
 
   if (widget)
@@ -894,7 +894,7 @@ gtk_selection_add_target (GtkWidget     *widget,
   list = gtk_selection_target_list_get (widget, selection);
   gtk_target_list_add (list, target, 0, info);
 #ifdef GDK_WINDOWING_WIN32
-  gdk_win32_selection_add_targets (widget->window, selection, 1, &target);
+  gdk_win32_selection_add_targets (gtk_widget_get_window (widget), selection, 1, &target);
 #endif
 }
 
@@ -930,7 +930,7 @@ gtk_selection_add_targets (GtkWidget            *widget,
 
     for (i = 0; i < ntargets; ++i)
       atoms[i] = gdk_atom_intern (targets[i].target, FALSE);
-    gdk_win32_selection_add_targets (widget->window, selection, ntargets, atoms);
+    gdk_win32_selection_add_targets (gtk_widget_get_window (widget), selection, ntargets, atoms);
     g_free (atoms);
   }
 #endif
@@ -1008,7 +1008,7 @@ gtk_selection_remove_all (GtkWidget *widget)
        In emergency, you could use #GDK_CURRENT_TIME
  * 
  * Requests the contents of a selection. When received, 
- * a "selection_received" signal will be generated.
+ * a "selection-received" signal will be generated.
  * 
  * Return value: %TRUE if requested succeeded. %FALSE if we could not process
  *          request. (e.g., there was already a request in process for
@@ -1031,7 +1031,7 @@ gtk_selection_convert (GtkWidget *widget,
   if (initialize)
     gtk_selection_init ();
   
-  if (!GTK_WIDGET_REALIZED (widget))
+  if (!gtk_widget_get_realized (widget))
     gtk_widget_realize (widget);
   
   /* Check to see if there are already any retrievals in progress for
@@ -1067,6 +1067,7 @@ gtk_selection_convert (GtkWidget *widget,
   if (owner_window != NULL)
     {
       GtkWidget *owner_widget;
+      gpointer owner_widget_ptr;
       GtkSelectionData selection_data;
       
       selection_data.selection = selection;
@@ -1075,7 +1076,8 @@ gtk_selection_convert (GtkWidget *widget,
       selection_data.length = -1;
       selection_data.display = display;
       
-      gdk_window_get_user_data (owner_window, (gpointer *)&owner_widget);
+      gdk_window_get_user_data (owner_window, &owner_widget_ptr);
+      owner_widget = owner_widget_ptr;
       
       if (owner_widget != NULL)
        {
@@ -1102,7 +1104,7 @@ gtk_selection_convert (GtkWidget *widget,
   /* Otherwise, we need to go through X */
   
   current_retrievals = g_list_append (current_retrievals, info);
-  gdk_selection_convert (widget->window, selection, target, time_);
+  gdk_selection_convert (gtk_widget_get_window (widget), selection, target, time_);
   gdk_threads_add_timeout (1000,
       (GSourceFunc) gtk_selection_retrieval_timeout, info);
   
@@ -1110,21 +1112,21 @@ gtk_selection_convert (GtkWidget *widget,
 }
 
 /**
- * gtk_selection_data_set_target:
+ * gtk_selection_data_get_selection:
  * @selection_data: a pointer to a #GtkSelectionData structure.
- * @target: target of the selection
  *
- * Sets the target of the selection.
+ * Retrieves the selection #GdkAtom of the selection data.
+ *
+ * Returns: the selection #GdkAtom of the selection data.
  *
- * Since: GSEAL-branch
+ * Since: 2.16
  **/
-void
-gtk_selection_data_set_target (GtkSelectionData *selection_data,
-                              GdkAtom           target)
+GdkAtom
+gtk_selection_data_get_selection (GtkSelectionData *selection_data)
 {
-  g_return_if_fail (selection_data != NULL);
+  g_return_val_if_fail (selection_data != NULL, 0);
 
-  selection_data->target = target;
+  return selection_data->selection;
 }
 
 /**
@@ -1133,7 +1135,9 @@ gtk_selection_data_set_target (GtkSelectionData *selection_data,
  *
  * Retrieves the target of the selection.
  *
- * Since: GSEAL-branch
+ * Returns:  the target of the selection.
+ *
+ * Since: 2.14
  **/
 GdkAtom
 gtk_selection_data_get_target (GtkSelectionData *selection_data)
@@ -1143,31 +1147,15 @@ gtk_selection_data_get_target (GtkSelectionData *selection_data)
   return selection_data->target;
 }
 
-/**
- * gtk_selection_data_set_data_type:
- * @selection_data: a pointer to a #GtkSelectionData structure.
- * @data_type: data type of the selection
- *
- * Sets the data type of the selection.
- *
- * Since: GSEAL-branch
- **/
-void
-gtk_selection_data_set_data_type (GtkSelectionData *selection_data,
-                                 GdkAtom           data_type)
-{
-  g_return_if_fail (selection_data != NULL);
-
-  selection_data->type = data_type;
-}
-
 /**
  * gtk_selection_data_get_data_type:
  * @selection_data: a pointer to a #GtkSelectionData structure.
  *
  * Retrieves the data type of the selection.
  *
- * Since: GSEAL-branch
+ * Returns:  the data type of the selection.
+ *
+ * Since: 2.14
  **/
 GdkAtom
 gtk_selection_data_get_data_type (GtkSelectionData *selection_data)
@@ -1177,31 +1165,15 @@ gtk_selection_data_get_data_type (GtkSelectionData *selection_data)
   return selection_data->type;
 }
 
-/**
- * gtk_selection_data_set_format:
- * @selection_data: a pointer to a #GtkSelectionData structure.
- * @format: format of the selection
- *
- * Sets the format of the selection.
- *
- * Since: GSEAL-branch
- **/
-void
-gtk_selection_data_set_format (GtkSelectionData *selection_data,
-                              gint              format)
-{
-  g_return_if_fail (selection_data != NULL);
-
-  selection_data->format = format;
-}
-
 /**
  * gtk_selection_data_get_format:
  * @selection_data: a pointer to a #GtkSelectionData structure.
  *
  * Retrieves the format of the selection.
  *
- * Since: GSEAL-branch
+ * Returns: the format of the selection.
+ *
+ * Since: 2.14
  **/
 gint
 gtk_selection_data_get_format (GtkSelectionData *selection_data)
@@ -1211,32 +1183,15 @@ gtk_selection_data_get_format (GtkSelectionData *selection_data)
   return selection_data->format;
 }
 
-/**
- * gtk_selection_data_set_data:
- * @selection_data: a pointer to a #GtkSelectionData structure.
- * @data: data of the selection
- *
- * Sets the raw data of the selection.
- *
- * Since: GSEAL-branch
- **/
-void
-gtk_selection_data_set_data (GtkSelectionData *selection_data,
-                            const guchar     *data)
-{
-  g_return_if_fail (selection_data != NULL);
-
-  g_free (selection_data->data);
-  selection_data->data = (guchar*) g_strdup (data);
-}
-
 /**
  * gtk_selection_data_get_data:
  * @selection_data: a pointer to a #GtkSelectionData structure.
  *
  * Retrieves the raw data of the selection.
  *
- * Since: GSEAL-branch
+ * Returns: the raw data of the selection.
+ *
+ * Since: 2.14
  **/
 const guchar*
 gtk_selection_data_get_data (GtkSelectionData *selection_data)
@@ -1246,36 +1201,20 @@ gtk_selection_data_get_data (GtkSelectionData *selection_data)
   return selection_data->data;
 }
 
-/**
- * gtk_selection_data_set_target:
- * @selection_data: a pointer to a #GtkSelectionData structure.
- * @length: length of the selection
- *
- * Sets the length of the selection.
- *
- * Since: GSEAL-branch
- **/
-void
-gtk_selection_data_set_length (GtkSelectionData *selection_data,
-                              gint             length)
-{
-  g_return_if_fail (selection_data != NULL);
-
-  selection_data->length = length;
-}
-
 /**
  * gtk_selection_data_get_length:
  * @selection_data: a pointer to a #GtkSelectionData structure.
  *
- * Retrieves the length of the selection.
+ * Retrieves the length of the raw data of the selection.
  *
- * Since: GSEAL-branch
- **/
+ * Returns: the length of the data of the selection.
+ *
+ * Since: 2.14
+ */
 gint
 gtk_selection_data_get_length (GtkSelectionData *selection_data)
 {
-  g_return_val_if_fail (selection_data != NULL, 0);
+  g_return_val_if_fail (selection_data != NULL, -1);
 
   return selection_data->length;
 }
@@ -1286,7 +1225,9 @@ gtk_selection_data_get_length (GtkSelectionData *selection_data)
  *
  * Retrieves the display of the selection.
  *
- * Since: GSEAL-branch
+ * Returns: (transfer none): the display of the selection.
+ *
+ * Since: 2.14
  **/
 GdkDisplay *
 gtk_selection_data_get_display (GtkSelectionData *selection_data)
@@ -1717,7 +1658,7 @@ gtk_selection_data_set_pixbuf (GtkSelectionData *selection_data,
  * 
  * Gets the contents of the selection data as a #GdkPixbuf.
  * 
- * Return value: if the selection data contained a recognized
+ * Return value: (transfer full): if the selection data contained a recognized
  *   image type and it could be converted to a #GdkPixbuf, a 
  *   newly allocated pixbuf is returned, otherwise %NULL.
  *   If the result is non-%NULL it must be freed with g_object_unref().
@@ -1755,7 +1696,7 @@ gtk_selection_data_get_pixbuf (GtkSelectionData *selection_data)
 /**
  * gtk_selection_data_set_uris:
  * @selection_data: a #GtkSelectionData
- * @uris: a %NULL-terminated array of strings hilding URIs
+ * @uris: a %NULL-terminated array of strings holding URIs
  * 
  * Sets the contents of the selection from a list of URIs.
  * The string is converted to the form determined by
@@ -1814,10 +1755,11 @@ gtk_selection_data_set_uris (GtkSelectionData  *selection_data,
  * @selection_data: a #GtkSelectionData
  * 
  * Gets the contents of the selection data as array of URIs.
- * 
- * Return value: if the selection data contains a list of
+ *
+ * Return value:  (array zero-terminated=1) (element-type utf8) (transfer full): if
+ *   the selection data contains a list of
  *   URIs, a newly allocated %NULL-terminated string array
- *   containing the URIs, otherwise %NULL. If the result is 
+ *   containing the URIs, otherwise %NULL. If the result is
  *   non-%NULL it must be freed with g_strfreev().
  *
  * Since: 2.6
@@ -2228,28 +2170,23 @@ gtk_selection_init (void)
   gtk_selection_atoms[MULTIPLE] = gdk_atom_intern_static_string ("MULTIPLE");
   gtk_selection_atoms[TIMESTAMP] = gdk_atom_intern_static_string ("TIMESTAMP");
   gtk_selection_atoms[TARGETS] = gdk_atom_intern_static_string ("TARGETS");
+  gtk_selection_atoms[SAVE_TARGETS] = gdk_atom_intern_static_string ("SAVE_TARGETS");
 
   initialize = FALSE;
 }
 
 /**
- * gtk_selection_clear:
+ * _gtk_selection_clear:
  * @widget: a #GtkWidget
  * @event: the event
  * 
- * The default handler for the GtkWidget::selection_clear_event
+ * The default handler for the #GtkWidget::selection-clear-event
  * signal. 
  * 
  * Return value: %TRUE if the event was handled, otherwise false
- * 
- * Since: 2.2
- *
- * Deprecated: 2.4: Instead of calling this function, chain up from
- * your selection_clear_event handler. Calling this function
- * from any other context is illegal. 
  **/
 gboolean
-gtk_selection_clear (GtkWidget         *widget,
+_gtk_selection_clear (GtkWidget         *widget,
                     GdkEventSelection *event)
 {
   /* Note that we filter clear events in gdkselection-x11.c, so
@@ -2362,10 +2299,10 @@ _gtk_selection_request (GtkWidget *widget,
                                                 event->time);
          g_free (mult_atoms);
          g_slice_free (GtkIncrInfo, info);
-          gdk_error_trap_pop ();
+          gdk_error_trap_pop_ignored ();
          return TRUE;
        }
-      gdk_error_trap_pop ();
+      gdk_error_trap_pop_ignored ();
 
       /* This is annoying; the ICCCM doesn't specify the property type
        * used for the property contents, so the autoconversion for
@@ -2433,7 +2370,6 @@ _gtk_selection_request (GtkWidget *widget,
 #endif
       
       gtk_selection_invoke_handler (widget, &data, event->time);
-      
       if (data.length < 0)
        {
          info->conversions[i].property = GDK_NONE;
@@ -2581,7 +2517,7 @@ _gtk_selection_incr_event (GdkWindow         *window,
   g_message ("PropertyDelete, property %ld", event->atom);
 #endif
 
-  selection_max_size = GTK_SELECTION_MAX_SIZE (gdk_drawable_get_display (window));  
+  selection_max_size = GTK_SELECTION_MAX_SIZE (gdk_window_get_display (window));  
 
   /* Now find the appropriate ongoing INCR */
   tmp_list = current_incrs;
@@ -2723,7 +2659,7 @@ gtk_selection_incr_timeout (GtkIncrInfo *info)
 
 /*************************************************************
  * _gtk_selection_notify:
- *     Handler for "selection_notify_event" signals on windows
+ *     Handler for "selection-notify-event" signals on windows
  *     where a retrieval is currently in process. The selection
  *     owner has responded to our conversion request.
  *   arguments:
@@ -2735,21 +2671,24 @@ gtk_selection_incr_timeout (GtkIncrInfo *info)
  *************************************************************/
 
 gboolean
-_gtk_selection_notify (GtkWidget              *widget,
+_gtk_selection_notify (GtkWidget        *widget,
                       GdkEventSelection *event)
 {
   GList *tmp_list;
   GtkRetrievalInfo *info = NULL;
+  GdkWindow *window;
   guchar  *buffer = NULL;
   gint length;
   GdkAtom type;
   gint   format;
-  
+
 #ifdef DEBUG_SELECTION
   g_message ("Initial receipt of selection %ld, target %ld (property = %ld)",
             event->selection, event->target, event->property);
 #endif
-  
+
+  window = gtk_widget_get_window (widget);
+
   tmp_list = current_retrievals;
   while (tmp_list)
     {
@@ -2763,7 +2702,7 @@ _gtk_selection_notify (GtkWidget         *widget,
     return FALSE;
 
   if (event->property != GDK_NONE)
-    length = gdk_selection_property_get (widget->window, &buffer, 
+    length = gdk_selection_property_get (window, &buffer,
                                         &type, &format);
   else
     length = 0; /* silence gcc */
@@ -2787,8 +2726,8 @@ _gtk_selection_notify (GtkWidget         *widget,
       info->notify_time = event->time;
       info->idle_time = 0;
       info->offset = 0;                /* Mark as OK to proceed */
-      gdk_window_set_events (widget->window,
-                            gdk_window_get_events (widget->window)
+      gdk_window_set_events (window,
+                             gdk_window_get_events (window)
                             | GDK_PROPERTY_CHANGE_MASK);
     }
   else
@@ -2802,9 +2741,9 @@ _gtk_selection_notify (GtkWidget         *widget,
                                      type, format, 
                                      buffer, length, event->time);
     }
-  
-  gdk_property_delete (widget->window, event->property);
-  
+
+  gdk_property_delete (window, event->property);
+
   g_free (buffer);
   
   return TRUE;
@@ -2812,7 +2751,7 @@ _gtk_selection_notify (GtkWidget         *widget,
 
 /*************************************************************
  * _gtk_selection_property_notify:
- *     Handler for "property_notify_event" signals on windows
+ *     Handler for "property-notify-event" signals on windows
  *     where a retrieval is currently in process. The selection
  *     owner has added more data.
  *   arguments:
@@ -2829,6 +2768,7 @@ _gtk_selection_property_notify (GtkWidget *widget,
 {
   GList *tmp_list;
   GtkRetrievalInfo *info = NULL;
+  GdkWindow *window;
   guchar *new_buffer;
   int length;
   GdkAtom type;
@@ -2865,11 +2805,12 @@ _gtk_selection_property_notify (GtkWidget       *widget,
     return FALSE;
   
   info->idle_time = 0;
-  
-  length = gdk_selection_property_get (widget->window, &new_buffer, 
+
+  window = gtk_widget_get_window (widget);
+  length = gdk_selection_property_get (window, &new_buffer,
                                       &type, &format);
-  gdk_property_delete (widget->window, event->atom);
-  
+  gdk_property_delete (window, event->atom);
+
   /* We could do a lot better efficiency-wise by paying attention to
      what length was sent in the initial INCR transaction, instead of
      doing memory allocation at every step. But its only guaranteed to
@@ -2967,7 +2908,7 @@ gtk_selection_retrieval_timeout (GtkRetrievalInfo *info)
 
 /*************************************************************
  * gtk_selection_retrieval_report:
- *     Emits a "selection_received" signal.
+ *     Emits a "selection-received" signal.
  *   arguments:
  *     info:     information about the retrieval that completed
  *     buffer:   buffer containing data (NULL => errror)
@@ -2993,7 +2934,7 @@ gtk_selection_retrieval_report (GtkRetrievalInfo *info,
   data.display = gtk_widget_get_display (info->widget);
   
   g_signal_emit_by_name (info->widget,
-                        "selection_received", 
+                        "selection-received", 
                         &data, time);
 }
 
@@ -3024,11 +2965,12 @@ gtk_selection_invoke_handler (GtkWidget        *widget,
   g_return_if_fail (widget != NULL);
 
   target_list = gtk_selection_target_list_get (widget, data->selection);
-  if (target_list && 
+  if (data->target != gtk_selection_atoms[SAVE_TARGETS] &&
+      target_list &&
       gtk_target_list_find (target_list, data->target, &info))
     {
       g_signal_emit_by_name (widget,
-                            "selection_get",
+                            "selection-get",
                             data,
                             info, time);
     }
@@ -3117,6 +3059,12 @@ gtk_selection_default_handler (GtkWidget *widget,
          tmp_list = tmp_list->next;
        }
     }
+  else if (data->target == gtk_selection_atoms[SAVE_TARGETS])
+    {
+      gtk_selection_data_set (data,
+                             gdk_atom_intern_static_string ("NULL"),
+                             32, NULL, 0);
+    }
   else
     {
       data->length = -1;
@@ -3168,31 +3116,13 @@ gtk_selection_data_free (GtkSelectionData *data)
   g_slice_free (GtkSelectionData, data);
 }
 
-GType
-gtk_selection_data_get_type (void)
-{
-  static GType our_type = 0;
-  
-  if (our_type == 0)
-    our_type = g_boxed_type_register_static (I_("GtkSelectionData"),
-                                            (GBoxedCopyFunc) gtk_selection_data_copy,
-                                            (GBoxedFreeFunc) gtk_selection_data_free);
-
-  return our_type;
-}
-
-GType
-gtk_target_list_get_type (void)
-{
-  static GType our_type = 0;
-
-  if (our_type == 0)
-    our_type = g_boxed_type_register_static (I_("GtkTargetList"),
-                                            (GBoxedCopyFunc) gtk_target_list_ref,
-                                            (GBoxedFreeFunc) gtk_target_list_unref);
+G_DEFINE_BOXED_TYPE (GtkSelectionData, gtk_selection_data,
+                     gtk_selection_data_copy,
+                     gtk_selection_data_free)
 
-  return our_type;
-}
+G_DEFINE_BOXED_TYPE (GtkTargetList, gtk_target_list,
+                     gtk_target_list_ref,
+                     gtk_target_list_unref)
 
 static int 
 gtk_selection_bytes_per_item (gint format)
@@ -3213,6 +3143,3 @@ gtk_selection_bytes_per_item (gint format)
     }
   return 0;
 }
-
-#define __GTK_SELECTION_C__
-#include "gtkaliasdef.c"