gtk+ r19590 - in trunk: . gtk



Author: matthiasc
Date: Sat Feb 16 02:31:33 2008
New Revision: 19590
URL: http://svn.gnome.org/viewvc/gtk+?rev=19590&view=rev

Log:
2008-02-15  Matthias Clasen  <mclasen redhat com>

        * gtk/gtkentry.c:
        * gtk/gtkfilesel.c:
        * gtk/gtklabel.c:
        * gtk/gtkpathbar.c: Use gtk_drag_*_add_{text,uri}_targets
        instead of hardcoded target tables.  (#516092, Christian Persch)




Modified:
   trunk/ChangeLog
   trunk/gtk/gtkentry.c
   trunk/gtk/gtkfilesel.c
   trunk/gtk/gtklabel.c
   trunk/gtk/gtkpathbar.c
   trunk/gtk/gtkrecentchooserdefault.c

Modified: trunk/gtk/gtkentry.c
==============================================================================
--- trunk/gtk/gtkentry.c	(original)
+++ trunk/gtk/gtkentry.c	Sat Feb 16 02:31:33 2008
@@ -4276,35 +4276,25 @@
 static void
 gtk_entry_update_primary_selection (GtkEntry *entry)
 {
-  static GtkTargetEntry targets[] = {
-    { "UTF8_STRING", 0, 0 },
-    { "STRING", 0, 0 },
-    { "TEXT",   0, 0 }, 
-    { "COMPOUND_TEXT", 0, 0 },
-    { "text/plain;charset=utf-8",   0, 0 }, 
-    { NULL,   0, 0 },
-    { "text/plain", 0, 0 }
-  };
-  
+  GtkTargetList *list;
+  GtkTargetEntry *targets;
   GtkClipboard *clipboard;
   gint start, end;
-
-  if (targets[5].target == NULL)
-    {
-      const gchar *charset;
-
-      g_get_charset (&charset);
-      targets[5].target = g_strdup_printf ("text/plain;charset=%s", charset);
-    }
+  gint n_targets;
 
   if (!GTK_WIDGET_REALIZED (entry))
     return;
 
+  list = gtk_target_list_new (NULL, 0);
+  gtk_target_list_add_text_targets (list, 0);
+
+  targets = gtk_target_table_new_from_list (list, &n_targets);
+
   clipboard = gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_PRIMARY);
   
   if (gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), &start, &end))
     {
-      if (!gtk_clipboard_set_with_owner (clipboard, targets, G_N_ELEMENTS (targets),
+      if (!gtk_clipboard_set_with_owner (clipboard, targets, n_targets,
 					 primary_get_cb, primary_clear_cb, G_OBJECT (entry)))
 	primary_clear_cb (clipboard, entry);
     }
@@ -4313,6 +4303,9 @@
       if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (entry))
 	gtk_clipboard_clear (clipboard);
     }
+
+  gtk_target_table_free (targets, n_targets);
+  gtk_target_list_unref (list);
 }
 
 /* Public API
@@ -5201,7 +5194,7 @@
       gboolean show_input_method_menu;
       gboolean show_unicode_menu;
       
-        clipboard_contains_text = gtk_selection_data_targets_include_text (data);
+      clipboard_contains_text = gtk_selection_data_targets_include_text (data);
       if (entry->popup_menu)
 	gtk_widget_destroy (entry->popup_menu);
       

Modified: trunk/gtk/gtkfilesel.c
==============================================================================
--- trunk/gtk/gtkfilesel.c	(original)
+++ trunk/gtk/gtkfilesel.c	Sat Feb 16 02:31:33 2008
@@ -831,49 +831,6 @@
   gtk_widget_pop_composite_child ();
 }
 
-static gchar *
-uri_list_extract_first_uri (const gchar* uri_list)
-{
-  const gchar *p, *q;
-  
-  g_return_val_if_fail (uri_list != NULL, NULL);
-  
-  p = uri_list;
-  /* We don't actually try to validate the URI according to RFC
-   * 2396, or even check for allowed characters - we just ignore
-   * comments and trim whitespace off the ends.  We also
-   * allow LF delimination as well as the specified CRLF.
-   *
-   * We do allow comments like specified in RFC 2483.
-   */
-  while (p)
-    {
-      if (*p != '#')
-	{
-	  while (g_ascii_isspace(*p))
-	    p++;
-	  
-	  q = p;
-	  while (*q && (*q != '\n') && (*q != '\r'))
-	    q++;
-	  
-	  if (q > p)
-	    {
-	      q--;
-	      while (q > p && g_ascii_isspace (*q))
-		q--;
-
-	      if (q > p)
-		return g_strndup (p, q - p + 1);
-	    }
-	}
-      p = strchr (p, '\n');
-      if (p)
-	p++;
-    }
-  return NULL;
-}
-
 static void
 dnd_really_drop  (GtkWidget *dialog, gint response_id, GtkFileSelection *fs)
 {
@@ -889,7 +846,6 @@
   gtk_widget_destroy (dialog);
 }
 
-
 static void
 filenames_dropped (GtkWidget        *widget,
 		   GdkDragContext   *context,
@@ -899,22 +855,21 @@
 		   guint             info,
 		   guint             time)
 {
-  char *uri = NULL;
+  char **uris = NULL;
   char *filename = NULL;
   char *hostname;
   const char *this_hostname;
   GError *error = NULL;
-	
-  if (!selection_data->data)
-    return;
 
-  uri = uri_list_extract_first_uri ((char *)selection_data->data);
-  
-  if (!uri)
-    return;
+  uris = gtk_selection_data_get_uris (selection_data);
+  if (!uris || !uris[0])
+    {
+      g_strfreev (uris);
+      return;
+    }
 
-  filename = g_filename_from_uri (uri, &hostname, &error);
-  g_free (uri);
+  filename = g_filename_from_uri (uris[0], &hostname, &error);
+  g_strfreev (uris);
   
   if (!filename)
     {
@@ -963,16 +918,6 @@
   g_free (filename);
 }
 
-enum
-{
-  TARGET_URILIST,
-  TARGET_UTF8_STRING,
-  TARGET_STRING,
-  TARGET_TEXT,
-  TARGET_COMPOUND_TEXT
-};
-
-
 static void
 filenames_drag_get (GtkWidget        *widget,
 		    GdkDragContext   *context,
@@ -982,64 +927,57 @@
 		    GtkFileSelection *filesel)
 {
   const gchar *file;
-  gchar *uri_list;
-  const char *hostname;
-  GError *error;
+  gchar *filename_utf8;
 
   file = gtk_file_selection_get_filename (filesel);
+  if (!file)
+    return;
 
-  if (file)
+  if (gtk_targets_include_uri (&selection_data->target, 1))
     {
-      if (info == TARGET_URILIST)
-	{
-	  hostname = g_get_host_name ();
-	  
-	  error = NULL;
-	  uri_list = g_filename_to_uri (file, hostname, &error);
-	  if (!uri_list)
-	    {
-	      g_warning ("Error getting filename: %s\n",
-			 error->message);
-	      g_error_free (error);
-	      return;
-	    }
+      gchar *file_uri;
+      const char *hostname;
+      GError *error;
+      char *uris[2];
+
+      hostname = g_get_host_name ();
+
+      error = NULL;
+      file_uri = g_filename_to_uri (file, hostname, &error);
+      if (!file_uri)
+        {
+          g_warning ("Error getting filename: %s\n",
+                      error->message);
+          g_error_free (error);
+          return;
+        }
 	  
-	  gtk_selection_data_set (selection_data,
-				  selection_data->target, 8,
-				  (void *)uri_list, strlen((char *)uri_list));
-	  g_free (uri_list);
-	}
-      else
-	{
-	  gchar *filename_utf8 = g_filename_to_utf8 (file, -1, NULL, NULL, NULL);
-	  g_assert (filename_utf8);
-	  gtk_selection_data_set_text (selection_data, filename_utf8, -1);
-	  g_free (filename_utf8);
-	}
+      uris[0] = file_uri;
+      uris[1] = NULL;
+      gtk_selection_data_set_uris (selection_data, uris);
+      g_free (file_uri);
+
+      return;
     }
+	  
+  filename_utf8 = g_filename_to_utf8 (file, -1, NULL, NULL, NULL);
+  if (!filename_utf8)
+    return;
+
+  gtk_selection_data_set_text (selection_data, filename_utf8, -1);
+  g_free (filename_utf8);
 }
 
 static void
 file_selection_setup_dnd (GtkFileSelection *filesel)
 {
   GtkWidget *eventbox;
-  static const GtkTargetEntry drop_types[] = {
-    { "text/uri-list", 0, TARGET_URILIST}
-  };
-  static const gint n_drop_types = sizeof(drop_types)/sizeof(drop_types[0]);
-  static const GtkTargetEntry drag_types[] = {
-    { "text/uri-list", 0, TARGET_URILIST},
-    { "UTF8_STRING", 0, TARGET_UTF8_STRING },
-    { "STRING", 0, 0 },
-    { "TEXT",   0, 0 }, 
-    { "COMPOUND_TEXT", 0, 0 }
-  };
-  static const gint n_drag_types = sizeof(drag_types)/sizeof(drag_types[0]);
 
   gtk_drag_dest_set (GTK_WIDGET (filesel),
 		     GTK_DEST_DEFAULT_ALL,
-		     drop_types, n_drop_types,
+		     NULL, 0,
 		     GDK_ACTION_COPY);
+  gtk_drag_dest_add_uri_targets (GTK_WIDGET (filesel));
 
   g_signal_connect (filesel, "drag_data_received",
 		    G_CALLBACK (filenames_dropped), NULL);
@@ -1047,8 +985,10 @@
   eventbox = gtk_widget_get_parent (filesel->selection_text);
   gtk_drag_source_set (eventbox,
 		       GDK_BUTTON1_MASK,
-		       drag_types, n_drag_types,
+		       NULL, 0,
 		       GDK_ACTION_COPY);
+  gtk_drag_source_add_uri_targets (eventbox);
+  gtk_drag_source_add_text_targets (eventbox);
 
   g_signal_connect (eventbox, "drag_data_get",
 		    G_CALLBACK (filenames_drag_get), filesel);

Modified: trunk/gtk/gtklabel.c
==============================================================================
--- trunk/gtk/gtklabel.c	(original)
+++ trunk/gtk/gtklabel.c	Sat Feb 16 02:31:33 2008
@@ -3413,13 +3413,6 @@
                                gint      anchor_index,
                                gint      end_index)
 {
-  static const GtkTargetEntry targets[] = {
-    { "STRING", 0, 0 },
-    { "TEXT",   0, 0 }, 
-    { "COMPOUND_TEXT", 0, 0 },
-    { "UTF8_STRING", 0, 0 }
-  };
-
   g_return_if_fail (GTK_IS_LABEL (label));
   
   if (label->select_info)
@@ -3438,12 +3431,22 @@
       
       if (anchor_index != end_index)
         {
+          GtkTargetList *list;
+          GtkTargetEntry *targets;
+          gint n_targets;
+
+          list = gtk_target_list_new (NULL, 0);
+          gtk_target_list_add_text_targets (list, 0);
+          targets = gtk_target_table_new_from_list (list, &n_targets);
+
           gtk_clipboard_set_with_owner (clipboard,
-                                        targets,
-                                        G_N_ELEMENTS (targets),
+                                        targets, n_targets,
                                         get_text_callback,
                                         clear_text_callback,
                                         G_OBJECT (label));
+
+          gtk_target_table_free (targets, n_targets);
+          gtk_target_list_unref (list);
         }
       else
         {

Modified: trunk/gtk/gtkpathbar.c
==============================================================================
--- trunk/gtk/gtkpathbar.c	(original)
+++ trunk/gtk/gtkpathbar.c	Sat Feb 16 02:31:33 2008
@@ -1344,10 +1344,6 @@
 		       gboolean     current_dir,
 		       gboolean     file_is_hidden)
 {
-  const GtkTargetEntry targets[] = {
-    { "text/uri-list", 0, 0 }
-  };
-
   AtkObject *atk_obj;
   GtkWidget *child = NULL;
   GtkWidget *label_alignment = NULL;
@@ -1414,9 +1410,9 @@
 
   gtk_drag_source_set (button_data->button,
 		       GDK_BUTTON1_MASK,
-		       targets,
-		       G_N_ELEMENTS (targets),
+		       NULL, 0,
 		       GDK_ACTION_COPY);
+  gtk_drag_source_add_uri_targets (button_data->button);
   g_signal_connect (button_data->button, "drag_data_get",
 		    G_CALLBACK (button_drag_data_get_cb), button_data);
 

Modified: trunk/gtk/gtkrecentchooserdefault.c
==============================================================================
--- trunk/gtk/gtkrecentchooserdefault.c	(original)
+++ trunk/gtk/gtkrecentchooserdefault.c	Sat Feb 16 02:31:33 2008
@@ -153,15 +153,6 @@
   LOAD_FINISHED  /* the model is fully loaded and inserted */
 };
 
-enum {
-  TEXT_URI_LIST
-};
-
-/* Target types for DnD from the file list */
-static const GtkTargetEntry recent_list_source_targets[] = {
-  { "text/uri-list", 0, TEXT_URI_LIST }
-};
-
 /* Icon size for if we can't get it from the theme */
 #define FALLBACK_ICON_SIZE  48
 #define FALLBACK_ITEM_LIMIT 20
@@ -451,9 +442,9 @@
   /* drag and drop */
   gtk_drag_source_set (impl->recent_view,
 		       GDK_BUTTON1_MASK,
-		       recent_list_source_targets,
-		       G_N_ELEMENTS (recent_list_source_targets),
+		       NULL, 0,
 		       GDK_ACTION_COPY);
+  gtk_drag_source_add_uri_targets (impl->recent_view);
 
   impl->filter_combo_hbox = gtk_hbox_new (FALSE, 12);
   
@@ -1535,25 +1526,23 @@
 			      gpointer          data)
 {
   GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (data);
-  DragData *drag_data;
+  DragData drag_data;
   gsize n_uris;
   
   n_uris = gtk_tree_selection_count_selected_rows (impl->selection);
   if (n_uris == 0)
-	  return;
+    return;
 
-  drag_data = g_new (DragData, 1);
-  drag_data->uri_list = g_new0 (gchar *, n_uris + 1);
-  drag_data->next_pos = 0;
+  drag_data.uri_list = g_new0 (gchar *, n_uris + 1);
+  drag_data.next_pos = 0;
   
   gtk_tree_selection_selected_foreach (impl->selection,
       				       append_uri_to_urilist,
-      				       drag_data);
+      				       &drag_data);
   
-  gtk_selection_data_set_uris (selection_data, drag_data->uri_list);
+  gtk_selection_data_set_uris (selection_data, drag_data.uri_list);
 
-  g_strfreev (drag_data->uri_list);
-  g_free (drag_data);
+  g_strfreev (drag_data.uri_list);
 }
 
 static gboolean



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]