]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkclipboard.c
GtkToggleButton: Make it able to be prelight and active at the same time.
[~andy/gtk] / gtk / gtkclipboard.c
index 5b57f3d2adfa3eb93f666fc939e57400507ea219..7273bd3944f1ddbbaef537b6097ca2df1fb2f428 100644 (file)
@@ -1,4 +1,4 @@
-/* GTK - The GTK+ Toolkit
+/* GTK - The GIMP Toolkit
  * Copyright (C) 2000 Red Hat, Inc.
  * Copyright (C) 2004 Nokia Corporation
  *
@@ -29,7 +29,6 @@
 #include "gtkmarshalers.h"
 #include "gtktextbufferrichtext.h"
 #include "gtkintl.h"
-#include "gtkalias.h"
 
 #ifdef GDK_WINDOWING_X11
 #include "x11/gdkx.h"
@@ -72,7 +71,7 @@ struct _GtkClipboard
   GdkAtom *cached_targets;
   gint     n_cached_targets;
 
-  guint      notify_signal_id;
+  gulong     notify_signal_id;
   gboolean   storing_selection;
   GMainLoop *store_loop;
   guint      store_timeout;
@@ -186,7 +185,7 @@ gtk_clipboard_class_init (GtkClipboardClass *class)
    * Since: 2.6
    */ 
   clipboard_signals[OWNER_CHANGE] =
-    g_signal_new (I_("owner_change"),
+    g_signal_new (I_("owner-change"),
                  G_TYPE_FROM_CLASS (gobject_class),
                  G_SIGNAL_RUN_FIRST,
                  G_STRUCT_OFFSET (GtkClipboardClass, owner_change),
@@ -236,6 +235,7 @@ gtk_clipboard_finalize (GObject *object)
     g_signal_handler_disconnect (clipboard_widget, clipboard->notify_signal_id);
   
   g_free (clipboard->storable_targets);
+  g_free (clipboard->cached_targets);
 
   G_OBJECT_CLASS (gtk_clipboard_parent_class)->finalize (object);
 }
@@ -286,7 +286,7 @@ clipboard_display_closed (GdkDisplay   *display,
  * if your application called "Foo" has a special-purpose
  * clipboard, you might call it "_FOO_SPECIAL_CLIPBOARD".
  * 
- * Return value: the appropriate clipboard object. If no
+ * Return value: (transfer none): the appropriate clipboard object. If no
  *             clipboard already exists, a new one will
  *             be created. Once a clipboard object has
  *             been created, it is persistent and, since
@@ -299,6 +299,7 @@ GtkClipboard *
 gtk_clipboard_get_for_display (GdkDisplay *display, 
                               GdkAtom     selection)
 {
+  g_return_val_if_fail (display != NULL, NULL); /* See bgo#463773; this is needed because Flash Player sucks */
   g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
   g_return_val_if_fail (!display->closed, NULL);
 
@@ -307,20 +308,17 @@ gtk_clipboard_get_for_display (GdkDisplay *display,
 
 
 /**
- * gtk_clipboard_get():
- * @selection: a #GdkAtom which identifies the clipboard
- *             to use.
- * 
+ * gtk_clipboard_get:
+ * @selection: a #GdkAtom which identifies the clipboard to use
+ *
  * Returns the clipboard object for the given selection.
  * See gtk_clipboard_get_for_display() for complete details.
- * 
- * Return value: the appropriate clipboard object. If no
- *             clipboard already exists, a new one will
- *             be created. Once a clipboard object has
- *             been created, it is persistent and, since
- *             it is owned by GTK+, must not be freed or
- *             unrefd.
- **/
+ *
+ * Return value: (transfer none): the appropriate clipboard object. If no clipboard
+ *     already exists, a new one will be created. Once a clipboard
+ *     object has been created, it is persistent and, since it is
+ *     owned by GTK+, must not be freed or unreffed.
+ */
 GtkClipboard *
 gtk_clipboard_get (GdkAtom selection)
 {
@@ -361,7 +359,7 @@ make_clipboard_widget (GdkDisplay *display,
 {
   GtkWidget *widget = gtk_invisible_new_for_screen (gdk_display_get_default_screen (display));
 
-  g_signal_connect (widget, "selection_received",
+  g_signal_connect (widget, "selection-received",
                    G_CALLBACK (selection_received), NULL);
 
   if (provider)
@@ -369,9 +367,9 @@ make_clipboard_widget (GdkDisplay *display,
       /* We need this for gdk_x11_get_server_time() */
       gtk_widget_add_events (widget, GDK_PROPERTY_CHANGE_MASK);
       
-      g_signal_connect (widget, "selection_get",
+      g_signal_connect (widget, "selection-get",
                        G_CALLBACK (selection_get_cb), NULL);
-      g_signal_connect (widget, "selection_clear_event",
+      g_signal_connect (widget, "selection-clear-event",
                        G_CALLBACK (selection_clear_event_cb), NULL);
     }
 
@@ -415,7 +413,7 @@ clipboard_get_timestamp (GtkClipboard *clipboard)
   if (timestamp == GDK_CURRENT_TIME)
     {
 #ifdef GDK_WINDOWING_X11
-      timestamp = gdk_x11_get_server_time (clipboard_widget->window);
+      timestamp = gdk_x11_get_server_time (gtk_widget_get_window (clipboard_widget));
 #elif defined GDK_WINDOWING_WIN32
       timestamp = GetMessageTime ();
 #endif
@@ -514,6 +512,13 @@ gtk_clipboard_set_contents (GtkClipboard         *clipboard,
     {
       clipboard->have_selection = TRUE;
 
+      if (clipboard->n_cached_targets != -1)
+        {
+          g_free (clipboard->cached_targets);
+         clipboard->cached_targets = NULL;
+          clipboard->n_cached_targets = -1;
+        }
+
       if (!(clipboard->have_owner && have_owner) ||
          clipboard->user_data != user_data)
        {
@@ -558,22 +563,23 @@ gtk_clipboard_set_contents (GtkClipboard         *clipboard,
 
 /**
  * gtk_clipboard_set_with_data:
- * @clipboard:  a #GtkClipboard
- * @targets:    array containing information about the available forms for the
- *              clipboard data
- * @n_targets:  number of elements in @targets
- * @get_func:   function to call to get the actual clipboard data
- * @clear_func: when the clipboard contents are set again, this function will
- *              be called, and @get_func will not be subsequently called.
- * @user_data:  user data to pass to @get_func and @clear_func.
- * 
+ * @clipboard: a #GtkClipboard
+ * @targets: array containing information about the available forms for the
+ *     clipboard data
+ * @n_targets: number of elements in @targets
+ * @get_func: (scope async): function to call to get the actual clipboard data
+ * @clear_func: (scope async): when the clipboard contents are set again,
+ *     this function will be called, and @get_func will not be subsequently
+ *     called.
+ * @user_data: user data to pass to @get_func and @clear_func.
+ *
  * Virtually sets the contents of the specified clipboard by providing
  * a list of supported formats for the clipboard data and a function
  * to call to get the actual data when it is requested.
- * 
- * Return value: %TRUE if setting the clipboard data succeeded. If setting
- *               the clipboard data failed the provided callback functions
- *               will be ignored.
+ *
+ * Return value: %TRUE if setting the clipboard data succeeded.
+ *    If setting the clipboard data failed the provided callback
+ *    functions will be ignored.
  **/
 gboolean
 gtk_clipboard_set_with_data (GtkClipboard          *clipboard,
@@ -594,27 +600,28 @@ gtk_clipboard_set_with_data (GtkClipboard          *clipboard,
 
 /**
  * gtk_clipboard_set_with_owner:
- * @clipboard:  a #GtkClipboard
- * @targets:    array containing information about the available forms for the
- *              clipboard data
- * @n_targets:  number of elements in @targets
- * @get_func:   function to call to get the actual clipboard data
- * @clear_func: when the clipboard contents are set again, this function will
- *              be called, and @get_func will not be subsequently called.
- * @owner:      an object that "owns" the data. This object will be passed
- *              to the callbacks when called. 
- * 
+ * @clipboard: a #GtkClipboard
+ * @targets: array containing information about the available forms for
+ *     the clipboard data
+ * @n_targets: number of elements in @targets
+ * @get_func: (scope async): function to call to get the actual clipboard data
+ * @clear_func: (scope async): when the clipboard contents are set again,
+ *     this function will be called, and @get_func will not be subsequently
+ *     called
+ * @owner: an object that "owns" the data. This object will be passed
+ *     to the callbacks when called
+ *
  * Virtually sets the contents of the specified clipboard by providing
  * a list of supported formats for the clipboard data and a function
  * to call to get the actual data when it is requested.
  *
  * The difference between this function and gtk_clipboard_set_with_data()
  * is that instead of an generic @user_data pointer, a #GObject is passed
- * in. 
- * 
- * Return value: %TRUE if setting the clipboard data succeeded. If setting
- *               the clipboard data failed the provided callback functions
- *               will be ignored.
+ * in.
+ *
+ * Return value: %TRUE if setting the clipboard data succeeded.
+ *     If setting the clipboard data failed the provided callback
+ *     functions will be ignored.
  **/
 gboolean
 gtk_clipboard_set_with_owner (GtkClipboard          *clipboard,
@@ -637,13 +644,14 @@ gtk_clipboard_set_with_owner (GtkClipboard          *clipboard,
 /**
  * gtk_clipboard_get_owner:
  * @clipboard: a #GtkClipboard
- * 
- * If the clipboard contents callbacks were set with 
- * gtk_clipboard_set_with_owner(), and the gtk_clipboard_set_with_data() or 
- * gtk_clipboard_clear() has not subsequently called, returns the owner set 
+ *
+ * If the clipboard contents callbacks were set with
+ * gtk_clipboard_set_with_owner(), and the gtk_clipboard_set_with_data() or
+ * gtk_clipboard_clear() has not subsequently called, returns the owner set
  * by gtk_clipboard_set_with_owner().
- * 
- * Return value: the owner of the clipboard, if any; otherwise %NULL.
+ *
+ * Return value: (transfer none): the owner of the clipboard, if any;
+ *     otherwise %NULL.
  **/
 GObject *
 gtk_clipboard_get_owner (GtkClipboard *clipboard)
@@ -869,14 +877,13 @@ selection_received (GtkWidget            *widget,
 /**
  * gtk_clipboard_request_contents:
  * @clipboard: a #GtkClipboard
- * @target:    an atom representing the form into which the clipboard
- *             owner should convert the selection.
- * @callback:  A function to call when the results are received
- *             (or the retrieval fails). If the retrieval fails
- *             the length field of @selection_data will be
- *             negative.
+ * @target: an atom representing the form into which the clipboard
+ *     owner should convert the selection.
+ * @callback: (scope async): A function to call when the results are received
+ *     (or the retrieval fails). If the retrieval fails the length field of
+ *     @selection_data will be negative.
  * @user_data: user data to pass to @callback
- * 
+ *
  * Requests the contents of clipboard as the given target.
  * When the results of the result are later received the supplied callback
  * will be called.
@@ -952,14 +959,13 @@ request_text_received_func (GtkClipboard     *clipboard,
 /**
  * gtk_clipboard_request_text:
  * @clipboard: a #GtkClipboard
- * @callback:  a function to call when the text is received,
- *             or the retrieval fails. (It will always be called
- *             one way or the other.)
+ * @callback: (scope async): a function to call when the text is received,
+ *     or the retrieval fails. (It will always be called one way or the other.)
  * @user_data: user data to pass to @callback.
- * 
+ *
  * Requests the contents of the clipboard as text. When the text is
  * later received, it will be converted to UTF-8 if necessary, and
- * @callback will be called. 
+ * @callback will be called.
  *
  * The @text parameter to @callback will contain the resulting text if
  * the request succeeded, or %NULL if it failed. This could happen for
@@ -1016,10 +1022,9 @@ request_rich_text_received_func (GtkClipboard     *clipboard,
 /**
  * gtk_clipboard_request_rich_text:
  * @clipboard: a #GtkClipboard
- * @buffer:    a #GtkTextBuffer
- * @callback:  a function to call when the text is received,
- *             or the retrieval fails. (It will always be called
- *             one way or the other.)
+ * @buffer: a #GtkTextBuffer
+ * @callback: (scope async): a function to call when the text is received,
+ *     or the retrieval fails. (It will always be called one way or the other.)
  * @user_data: user data to pass to @callback.
  *
  * Requests the contents of the clipboard as rich text. When the rich
@@ -1109,19 +1114,18 @@ request_image_received_func (GtkClipboard     *clipboard,
 /**
  * gtk_clipboard_request_image:
  * @clipboard: a #GtkClipboard
- * @callback:  a function to call when the image is received,
- *             or the retrieval fails. (It will always be called
- *             one way or the other.)
+ * @callback: (scope async): a function to call when the image is received,
+ *     or the retrieval fails. (It will always be called one way or the other.)
  * @user_data: user data to pass to @callback.
- * 
+ *
  * Requests the contents of the clipboard as image. When the image is
  * later received, it will be converted to a #GdkPixbuf, and
- * @callback will be called. 
+ * @callback will be called.
  *
- * The @pixbuf parameter to @callback will contain the resulting 
- * #GdkPixbuf if the request succeeded, or %NULL if it failed. This 
- * could happen for various reasons, in particular if the clipboard 
- * was empty or if the contents of the clipboard could not be 
+ * The @pixbuf parameter to @callback will contain the resulting
+ * #GdkPixbuf if the request succeeded, or %NULL if it failed. This
+ * could happen for various reasons, in particular if the clipboard
+ * was empty or if the contents of the clipboard could not be
  * converted into an image.
  *
  * Since: 2.6
@@ -1164,11 +1168,10 @@ request_uris_received_func (GtkClipboard     *clipboard,
 /**
  * gtk_clipboard_request_uris:
  * @clipboard: a #GtkClipboard
- * @callback:  a function to call when the URIs are received,
- *             or the retrieval fails. (It will always be called
- *             one way or the other.)
+ * @callback: (scope async): a function to call when the URIs are received,
+ *     or the retrieval fails. (It will always be called one way or the other.)
  * @user_data: user data to pass to @callback.
- * 
+ *
  * Requests the contents of the clipboard as URIs. When the URIs are
  * later received @callback will be called.
  *
@@ -1218,13 +1221,13 @@ request_targets_received_func (GtkClipboard     *clipboard,
 /**
  * gtk_clipboard_request_targets:
  * @clipboard: a #GtkClipboard
- * @callback:  a function to call when the targets are received,
- *             or the retrieval fails. (It will always be called
- *             one way or the other.)
+ * @callback: (scope async): a function to call when the targets are
+ *     received, or the retrieval fails. (It will always be called
+ *     one way or the other.)
  * @user_data: user data to pass to @callback.
- * 
- * Requests the contents of the clipboard as list of supported targets. 
- * When the list is later received, @callback will be called. 
+ *
+ * Requests the contents of the clipboard as list of supported targets.
+ * When the list is later received, @callback will be called.
  *
  * The @targets parameter to @callback will contain the resulting targets if
  * the request succeeded, or %NULL if it failed.
@@ -1461,18 +1464,18 @@ clipboard_image_received_func (GtkClipboard *clipboard,
 /**
  * gtk_clipboard_wait_for_image:
  * @clipboard: a #GtkClipboard
- * 
+ *
  * Requests the contents of the clipboard as image and converts
  * the result to a #GdkPixbuf. This function waits for
  * the data to be received using the main loop, so events,
  * timeouts, etc, may be dispatched during the wait.
- * 
- * Return value: a newly-allocated #GdkPixbuf object which must
- *               be disposed with g_object_unref(), or %NULL if 
- *               retrieving the selection data failed. (This 
- *               could happen for various reasons, in particular 
- *               if the clipboard was empty or if the contents of 
- *               the clipboard could not be converted into an image.)
+ *
+ * Return value: (transfer full): a newly-allocated #GdkPixbuf
+ *     object which must be disposed with g_object_unref(), or
+ *     %NULL if retrieving the selection data failed. (This could
+ *     happen for various reasons, in particular if the clipboard
+ *     was empty or if the contents of the clipboard could not be
+ *     converted into an image.)
  *
  * Since: 2.6
  **/
@@ -1520,12 +1523,13 @@ clipboard_uris_received_func (GtkClipboard *clipboard,
  * Requests the contents of the clipboard as URIs. This function waits
  * for the data to be received using the main loop, so events,
  * timeouts, etc, may be dispatched during the wait.
- * 
- * Return value: a newly-allocated %NULL-terminated array of strings which must
+ *
+ * Return value: (array zero-terminated=1) (element-type utf8) (transfer full): a newly-allocated
+ *              %NULL-terminated array of strings which must
  *               be freed with g_strfreev(), or %NULL if
- *               retrieving the selection data failed. (This 
- *               could happen for various reasons, in particular 
- *               if the clipboard was empty or if the contents of 
+ *               retrieving the selection data failed. (This
+ *               could happen for various reasons, in particular
+ *               if the clipboard was empty or if the contents of
  *               the clipboard could not be converted into URI form.)
  *
  * Since: 2.14
@@ -1562,7 +1566,7 @@ gtk_clipboard_wait_for_uris (GtkClipboard *clipboard)
  *
  * Gets the #GdkDisplay associated with @clipboard
  *
- * Return value: the #GdkDisplay associated with @clipboard
+ * Return value: (transfer none): the #GdkDisplay associated with @clipboard
  *
  * Since: 2.2
  **/
@@ -1840,8 +1844,9 @@ gtk_clipboard_owner_change (GtkClipboard        *clipboard,
 {
   if (clipboard->n_cached_targets != -1)
     {
-      clipboard->n_cached_targets = -1;
       g_free (clipboard->cached_targets);
+      clipboard->cached_targets = NULL;
+      clipboard->n_cached_targets = -1;
     }
 }
 
@@ -1900,7 +1905,7 @@ _gtk_clipboard_handle_event (GdkEventOwnerChange *event)
   GdkDisplay *display;
   GtkClipboard *clipboard;
   
-  display = gdk_drawable_get_display (event->window);
+  display = gdk_window_get_display (event->window);
   clipboard = clipboard_peek (display, event->selection, TRUE);
       
   if (clipboard)
@@ -1919,8 +1924,9 @@ gtk_clipboard_store_timeout (GtkClipboard *clipboard)
 /**
  * gtk_clipboard_set_can_store:
  * @clipboard: a #GtkClipboard
- * @targets: array containing information about which forms should be stored
- *           or %NULL to indicate that all forms should be stored.
+ * @targets: (allow-none): array containing information about which forms 
+ *           should be stored or %NULL to indicate that all forms should 
+ *           be stored.
  * @n_targets: number of elements in @targets
  *
  * Hints that the clipboard data should be stored somewhere when the
@@ -2011,11 +2017,13 @@ gtk_clipboard_store (GtkClipboard *clipboard)
   g_object_ref (clipboard);
 
   clipboard_widget = get_clipboard_widget (clipboard->display);
-  clipboard->notify_signal_id = g_signal_connect (clipboard_widget, "selection_notify_event",
-                                                 G_CALLBACK (gtk_clipboard_selection_notify), clipboard);
-  
+  clipboard->notify_signal_id = g_signal_connect (clipboard_widget,
+                                                 "selection-notify-event",
+                                                 G_CALLBACK (gtk_clipboard_selection_notify),
+                                                 clipboard);
+
   gdk_display_store_clipboard (clipboard->display,
-                              clipboard_widget->window,
+                               gtk_widget_get_window (clipboard_widget),
                               clipboard_get_timestamp (clipboard),
                               clipboard->storable_targets,
                               clipboard->n_storable_targets);
@@ -2023,7 +2031,7 @@ gtk_clipboard_store (GtkClipboard *clipboard)
   clipboard->storing_selection = TRUE;
 
   clipboard->store_loop = g_main_loop_new (NULL, TRUE);
-  clipboard->store_timeout = g_timeout_add (10000, (GSourceFunc) gtk_clipboard_store_timeout, clipboard);
+  clipboard->store_timeout = g_timeout_add_seconds (10, (GSourceFunc) gtk_clipboard_store_timeout, clipboard);
 
   if (g_main_loop_is_running (clipboard->store_loop))
     {
@@ -2071,6 +2079,3 @@ _gtk_clipboard_store_all (void)
   g_slist_free (displays);
   
 }
-
-#define __GTK_CLIPBOARD_C__
-#include "gtkaliasdef.c"