]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkselection.c
Unbreak GtkComboBox::button-sensitivity
[~andy/gtk] / gtk / gtkselection.c
index 5a419bcad9c3ea4b87f710a0ee01cf8438413cdc..7195b86a51f062de0b5a3fe4904088f425b8e9e8 100644 (file)
@@ -51,7 +51,7 @@
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
  */
 
-#include <config.h>
+#include "config.h"
 #include <stdarg.h>
 #include <string.h>
 #include "gdk.h"
@@ -94,6 +94,7 @@ enum {
   MULTIPLE,
   TARGETS,
   TIMESTAMP,
+  SAVE_TARGETS,
   LAST_ATOM
 };
 
@@ -338,7 +339,8 @@ gtk_target_list_add_text_targets (GtkTargetList *list,
   gtk_target_list_add (list, text_atom, 0, info);  
   gtk_target_list_add (list, GDK_TARGET_STRING, 0, info);  
   gtk_target_list_add (list, text_plain_utf8_atom, 0, info);  
-  gtk_target_list_add (list, text_plain_locale_atom, 0, info);  
+  if (!g_get_charset (NULL))
+    gtk_target_list_add (list, text_plain_locale_atom, 0, info);  
   gtk_target_list_add (list, text_plain_atom, 0, info);  
 }
 
@@ -951,7 +953,9 @@ gtk_selection_remove_all (GtkWidget *widget)
   GList *tmp_list;
   GList *next;
   GtkSelectionInfo *selection_info;
-  
+
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+
   /* Remove pending requests/incrs for this widget */
   
   tmp_list = current_retrievals;
@@ -1005,7 +1009,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
@@ -1064,6 +1068,7 @@ gtk_selection_convert (GtkWidget *widget,
   if (owner_window != NULL)
     {
       GtkWidget *owner_widget;
+      gpointer owner_widget_ptr;
       GtkSelectionData selection_data;
       
       selection_data.selection = selection;
@@ -1072,7 +1077,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)
        {
@@ -1106,6 +1112,131 @@ gtk_selection_convert (GtkWidget *widget,
   return TRUE;
 }
 
+/**
+ * gtk_selection_data_get_selection:
+ * @selection_data: a pointer to a #GtkSelectionData structure.
+ *
+ * Retrieves the selection #GdkAtom of the selection data.
+ *
+ * Returns: the selection #GdkAtom of the selection data.
+ *
+ * Since: 2.16
+ **/
+GdkAtom
+gtk_selection_data_get_selection (GtkSelectionData *selection_data)
+{
+  g_return_val_if_fail (selection_data != NULL, 0);
+
+  return selection_data->selection;
+}
+
+/**
+ * gtk_selection_data_get_target:
+ * @selection_data: a pointer to a #GtkSelectionData structure.
+ *
+ * Retrieves the target of the selection.
+ *
+ * Returns:  the target of the selection.
+ *
+ * Since: 2.14
+ **/
+GdkAtom
+gtk_selection_data_get_target (GtkSelectionData *selection_data)
+{
+  g_return_val_if_fail (selection_data != NULL, 0);
+
+  return selection_data->target;
+}
+
+/**
+ * gtk_selection_data_get_data_type:
+ * @selection_data: a pointer to a #GtkSelectionData structure.
+ *
+ * Retrieves the data type of the selection.
+ *
+ * Returns:  the data type of the selection.
+ *
+ * Since: 2.14
+ **/
+GdkAtom
+gtk_selection_data_get_data_type (GtkSelectionData *selection_data)
+{
+  g_return_val_if_fail (selection_data != NULL, 0);
+
+  return selection_data->type;
+}
+
+/**
+ * gtk_selection_data_get_format:
+ * @selection_data: a pointer to a #GtkSelectionData structure.
+ *
+ * Retrieves the format of the selection.
+ *
+ * Returns: the format of the selection.
+ *
+ * Since: 2.14
+ **/
+gint
+gtk_selection_data_get_format (GtkSelectionData *selection_data)
+{
+  g_return_val_if_fail (selection_data != NULL, 0);
+
+  return selection_data->format;
+}
+
+/**
+ * gtk_selection_data_get_data:
+ * @selection_data: a pointer to a #GtkSelectionData structure.
+ *
+ * Retrieves the raw data of the selection.
+ *
+ * Returns: the raw data of the selection.
+ *
+ * Since: 2.14
+ **/
+const guchar*
+gtk_selection_data_get_data (GtkSelectionData *selection_data)
+{
+  g_return_val_if_fail (selection_data != NULL, NULL);
+
+  return selection_data->data;
+}
+
+/**
+ * gtk_selection_data_get_length:
+ * @selection_data: a pointer to a #GtkSelectionData structure.
+ *
+ * Retrieves the length of the raw data of the selection.
+ *
+ * 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, -1);
+
+  return selection_data->length;
+}
+
+/**
+ * gtk_selection_data_get_display:
+ * @selection_data: a pointer to a #GtkSelectionData structure.
+ *
+ * Retrieves the display of the selection.
+ *
+ * Returns: the display of the selection.
+ *
+ * Since: 2.14
+ **/
+GdkDisplay *
+gtk_selection_data_get_display (GtkSelectionData *selection_data)
+{
+  g_return_val_if_fail (selection_data != NULL, NULL);
+
+  return selection_data->display;
+}
 
 /**
  * gtk_selection_data_set:
@@ -1126,6 +1257,8 @@ gtk_selection_data_set (GtkSelectionData *selection_data,
                        const guchar     *data,
                        gint              length)
 {
+  g_return_if_fail (selection_data != NULL);
+
   g_free (selection_data->data);
   
   selection_data->type = type;
@@ -1366,6 +1499,8 @@ gtk_selection_data_set_text (GtkSelectionData     *selection_data,
                             const gchar          *str,
                             gint                  len)
 {
+  g_return_val_if_fail (selection_data != NULL, FALSE);
+
   if (len < 0)
     len = strlen (str);
   
@@ -1416,6 +1551,8 @@ gtk_selection_data_get_text (GtkSelectionData *selection_data)
 {
   guchar *result = NULL;
 
+  g_return_val_if_fail (selection_data != NULL, NULL);
+
   init_atoms ();
   
   if (selection_data->length >= 0 &&
@@ -1474,6 +1611,9 @@ gtk_selection_data_set_pixbuf (GtkSelectionData *selection_data,
   gchar *str, *type;
   gsize len;
 
+  g_return_val_if_fail (selection_data != NULL, FALSE);
+  g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), FALSE);
+
   formats = gdk_pixbuf_get_formats ();
 
   for (f = formats; f; f = f->next)
@@ -1532,6 +1672,8 @@ gtk_selection_data_get_pixbuf (GtkSelectionData *selection_data)
   GdkPixbufLoader *loader;
   GdkPixbuf *result = NULL;
 
+  g_return_val_if_fail (selection_data != NULL, NULL);
+
   if (selection_data->length > 0)
     {
       loader = gdk_pixbuf_loader_new ();
@@ -1555,7 +1697,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
@@ -1570,6 +1712,9 @@ gboolean
 gtk_selection_data_set_uris (GtkSelectionData  *selection_data,
                             gchar            **uris)
 {
+  g_return_val_if_fail (selection_data != NULL, FALSE);
+  g_return_val_if_fail (uris != NULL, FALSE);
+
   init_atoms ();
 
   if (selection_data->target == text_uri_list_atom)
@@ -1624,6 +1769,8 @@ gtk_selection_data_get_uris (GtkSelectionData *selection_data)
 {
   gchar **result = NULL;
 
+  g_return_val_if_fail (selection_data != NULL, NULL);
+
   init_atoms ();
   
   if (selection_data->length >= 0 &&
@@ -1666,9 +1813,14 @@ gtk_selection_data_get_targets (GtkSelectionData  *selection_data,
                                GdkAtom          **targets,
                                gint              *n_atoms)
 {
+  g_return_val_if_fail (selection_data != NULL, FALSE);
+
+  /* As usual, java gets it wrong and sets the type to TARGETS, not ATOM 
+   */
   if (selection_data->length >= 0 &&
       selection_data->format == 32 &&
-      selection_data->type == GDK_SELECTION_TYPE_ATOM)
+      (selection_data->type == GDK_SELECTION_TYPE_ATOM ||
+       selection_data->type == gtk_selection_atoms[TARGETS]))
     {
       if (targets)
        *targets = g_memdup (selection_data->data, selection_data->length);
@@ -1703,11 +1855,13 @@ gtk_selection_data_get_targets (GtkSelectionData  *selection_data,
  **/
 gboolean 
 gtk_targets_include_text (GdkAtom *targets,
-                          gint     n_targets)
+                          gint     n_targets)
 {
   gint i;
   gboolean result = FALSE;
 
+  g_return_val_if_fail (targets != NULL || n_targets == 0, FALSE);
+
   /* Keep in sync with gtk_target_list_add_text_targets()
    */
  
@@ -1755,6 +1909,7 @@ gtk_targets_include_rich_text (GdkAtom       *targets,
   gint i, j;
   gboolean result = FALSE;
 
+  g_return_val_if_fail (targets != NULL || n_targets == 0, FALSE);
   g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), FALSE);
 
   init_atoms ();
@@ -1798,6 +1953,8 @@ gtk_selection_data_targets_include_text (GtkSelectionData *selection_data)
   gint n_targets;
   gboolean result = FALSE;
 
+  g_return_val_if_fail (selection_data != NULL, FALSE);
+
   init_atoms ();
 
   if (gtk_selection_data_get_targets (selection_data, &targets, &n_targets))
@@ -1832,6 +1989,7 @@ gtk_selection_data_targets_include_rich_text (GtkSelectionData *selection_data,
   gint n_targets;
   gboolean result = FALSE;
 
+  g_return_val_if_fail (selection_data != NULL, FALSE);
   g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), FALSE);
 
   init_atoms ();
@@ -1870,6 +2028,8 @@ gtk_targets_include_image (GdkAtom *targets,
   gint i;
   gboolean result = FALSE;
 
+  g_return_val_if_fail (targets != NULL || n_targets == 0, FALSE);
+
   list = gtk_target_list_new (NULL, 0);
   gtk_target_list_add_image_targets (list, 0, writable);
   for (i = 0; i < n_targets && !result; i++)
@@ -1912,6 +2072,8 @@ gtk_selection_data_targets_include_image (GtkSelectionData *selection_data,
   gint n_targets;
   gboolean result = FALSE;
 
+  g_return_val_if_fail (selection_data != NULL, FALSE);
+
   init_atoms ();
 
   if (gtk_selection_data_get_targets (selection_data, &targets, &n_targets))
@@ -1943,6 +2105,8 @@ gtk_targets_include_uri (GdkAtom *targets,
   gint i;
   gboolean result = FALSE;
 
+  g_return_val_if_fail (targets != NULL || n_targets == 0, FALSE);
+
   /* Keep in sync with gtk_target_list_add_uri_targets()
    */
 
@@ -1969,7 +2133,7 @@ gtk_targets_include_uri (GdkAtom *targets,
  * provide a list or URIs.
  * 
  * Return value: %TRUE if @selection_data holds a list of targets,
- *   and a suitable target for text is included, otherwise %FALSE.
+ *   and a suitable target for URI lists is included, otherwise %FALSE.
  *
  * Since: 2.10
  **/
@@ -1980,6 +2144,8 @@ gtk_selection_data_targets_include_uri (GtkSelectionData *selection_data)
   gint n_targets;
   gboolean result = FALSE;
 
+  g_return_val_if_fail (selection_data != NULL, FALSE);
+
   init_atoms ();
 
   if (gtk_selection_data_get_targets (selection_data, &targets, &n_targets))
@@ -2007,6 +2173,7 @@ 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;
 }
@@ -2016,7 +2183,7 @@ gtk_selection_init (void)
  * @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
@@ -2024,7 +2191,7 @@ gtk_selection_init (void)
  * Since: 2.2
  *
  * Deprecated: 2.4: Instead of calling this function, chain up from
- * your selection_clear_event handler. Calling this function
+ * your selection-clear-event handler. Calling this function
  * from any other context is illegal. 
  **/
 gboolean
@@ -2212,7 +2379,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;
@@ -2502,7 +2668,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:
@@ -2591,7 +2757,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:
@@ -2746,7 +2912,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)
@@ -2772,7 +2938,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);
 }
 
@@ -2803,11 +2969,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);
     }
@@ -2896,6 +3063,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, "", 0);
+    }
   else
     {
       data->length = -1;