gtk+ r21942 - in trunk: . gtk tests



Author: matthiasc
Date: Sat Dec 27 04:56:55 2008
New Revision: 21942
URL: http://svn.gnome.org/viewvc/gtk+?rev=21942&view=rev

Log:
2008-12-26  Matthias Clasen  <mclasen redhat com>

        * gtk/gtkentry.c: Don't emit ::icon-pressed on nonactivatable
        icons. Fix up docs to match actual api.

        * tests/testentryicons.c: Reshuffle tests a bit. Add a DND test.




Modified:
   trunk/ChangeLog
   trunk/gtk/gtkentry.c
   trunk/tests/testentryicons.c

Modified: trunk/gtk/gtkentry.c
==============================================================================
--- trunk/gtk/gtkentry.c	(original)
+++ trunk/gtk/gtkentry.c	Sat Dec 27 04:56:55 2008
@@ -2124,6 +2124,11 @@
           if (icon_info->pixbuf != NULL)
             gdk_window_show (icon_info->window);
 
+          /* The icon windows are not children of the visible entry window,
+           * thus we can't just inherit the xterm cursor. Slight complication 
+           * here is that for the entry, insensitive => arrow cursor, but for 
+           * an icon in a sensitive entry, insensitive => xterm cursor.
+           */
           if (GTK_WIDGET_IS_SENSITIVE (widget) && 
               (icon_info->insensitive || 
                (icon_info->nonactivatable && icon_info->target_list == NULL)))
@@ -3114,15 +3119,12 @@
               gtk_widget_queue_draw (widget);
             }
 
-          if (icon_info->target_list != NULL)
-            {
-              priv->start_x = event->x;
-              priv->start_y = event->y;
-
-              icon_info->pressed = TRUE;
-            }
+          priv->start_x = event->x;
+          priv->start_y = event->y;
+          icon_info->pressed = TRUE;
 
-          g_signal_emit (entry, signals[ICON_PRESSED], 0, i, event);
+          if (!icon_info->nonactivatable)
+            g_signal_emit (entry, signals[ICON_PRESSED], 0, i, event);
 
           return TRUE;
         }
@@ -3288,33 +3290,31 @@
 
   for (i = 0; i < MAX_ICONS; i++)
     {
-      if ((icon_info = priv->icons[i]) != NULL)
-        {
-          GdkWindow *icon_window = icon_info->window;
+      icon_info = priv->icons[i];
 
-          if (icon_info->insensitive)
-            continue;
+      if (!icon_info || icon_info->insensitive)
+        continue;
 
-          if (event->window == icon_window)
-            {
-              gint width, height;
+      if (event->window == icon_info->window)
+        {
+          gint width, height;
 
-              gdk_drawable_get_size (icon_window, &width, &height);
+          gdk_drawable_get_size (icon_info->window, &width, &height);
 
-              icon_info->pressed = FALSE;
+          icon_info->pressed = FALSE;
 
-              if (should_prelight (entry, i) &&
-                  event->x >= 0 && event->y >= 0 &&
-                  event->x < width && event->y < height)
-                {
-                  icon_info->prelight = TRUE;
-                  gtk_widget_queue_draw (widget);
-                }
+          if (should_prelight (entry, i) &&
+              event->x >= 0 && event->y >= 0 &&
+              event->x < width && event->y < height)
+            {
+              icon_info->prelight = TRUE;
+              gtk_widget_queue_draw (widget);
+            }
 
-              g_signal_emit (entry, signals[ICON_RELEASED], 0, i, event);
+          if (!icon_info->nonactivatable)
+            g_signal_emit (entry, signals[ICON_RELEASED], 0, i, event);
 
-              return TRUE;
-            }
+          return TRUE;
         }
     }
 
@@ -7482,7 +7482,7 @@
 }
 
 /**
- * gtk_icon_entry_set_icon_drag_source:
+ * gtk_entry_set_icon_drag_source:
  * @entry: a #GtkIconEntry
  * @icon_pos: icon position
  * @target_list: the targets (data formats) in which the data can be provided
@@ -7524,7 +7524,7 @@
 }
 
 /**
- * gtk_icon_entry_get_current_icon_drag_source:
+ * gtk_entry_get_current_icon_drag_source:
  * @entry: a #GtkIconEntry
  *
  * Returns the index of the icon which is the source of the current

Modified: trunk/tests/testentryicons.c
==============================================================================
--- trunk/tests/testentryicons.c	(original)
+++ trunk/tests/testentryicons.c	Sat Dec 27 04:56:55 2008
@@ -2,13 +2,6 @@
 #include <stdio.h>
 #include "prop-editor.h"
 
-static void
-clear_pressed (GtkEntry *entry, gint icon, GdkEvent *event, gpointer data)
-{
-   if (icon == GTK_ENTRY_ICON_SECONDARY)
-     gtk_entry_set_text (entry, "");
-}
-
 static gboolean
 delete_event_cb (GtkWidget *editor,
                  gint       response,
@@ -40,6 +33,43 @@
   gtk_window_present (GTK_WINDOW (editor));
 }
 
+static void
+clear_pressed (GtkEntry *entry, gint icon, GdkEvent *event, gpointer data)
+{
+   if (icon == GTK_ENTRY_ICON_SECONDARY)
+     gtk_entry_set_text (entry, "");
+}
+
+static void
+drag_data_get_cb (GtkWidget        *widget,
+                  GdkDragContext   *context,
+                  GtkSelectionData *data,
+                  guint             info,
+                  guint             time,
+                  gpointer          user_data)
+{
+  gint pos;
+
+  pos = gtk_entry_get_current_icon_drag_source (GTK_ENTRY (widget));
+
+  if (pos == GTK_ENTRY_ICON_PRIMARY)
+    {
+#if 0
+      gint start, end;
+      
+      if (gtk_editable_get_selection_bounds (GTK_EDITABLE (widget), &start, &end))
+        {
+          gchar *str;
+          
+          str = gtk_editable_get_chars (GTK_EDITABLE (widget), start, end);
+          gtk_selection_data_set_text (data, str, -1);
+          g_free (str);
+        }
+#else
+      gtk_selection_data_set_text (data, "XXX", -1);
+#endif
+    }
+}
 
 int
 main (int argc, char **argv)
@@ -50,6 +80,7 @@
   GtkWidget *entry;
   GtkWidget *button;
   GIcon *icon;
+  GtkTargetList *tlist;
 
   gtk_init (&argc, &argv);
 
@@ -84,7 +115,7 @@
 				 GTK_ENTRY_ICON_PRIMARY,
 				 icon);
   gtk_entry_set_icon_sensitive (GTK_ENTRY (entry),
-				GTK_ENTRY_ICON_PRIMARY,
+			        GTK_ENTRY_ICON_PRIMARY,
 				FALSE);
 
   gtk_entry_set_icon_tooltip_text (GTK_ENTRY (entry),
@@ -118,6 +149,14 @@
   gtk_entry_set_icon_tooltip_text (GTK_ENTRY (entry),
 				   GTK_ENTRY_ICON_PRIMARY,
 				   "Save a file");
+  tlist = gtk_target_list_new (NULL, 0);
+  gtk_target_list_add_text_targets (tlist, 0);
+  gtk_entry_set_icon_drag_source (GTK_ENTRY (entry),
+                                  GTK_ENTRY_ICON_PRIMARY,
+                                  tlist, GDK_ACTION_COPY); 
+  g_signal_connect (entry, "drag-data-get", 
+                    G_CALLBACK (drag_data_get_cb), NULL);
+  gtk_target_list_unref (tlist);
 
   button = gtk_button_new_with_label ("Properties");
   gtk_table_attach (GTK_TABLE (table), button, 2, 3, 1, 2,
@@ -144,9 +183,6 @@
   gtk_entry_set_icon_from_stock (GTK_ENTRY (entry),
 				 GTK_ENTRY_ICON_SECONDARY,
 				 GTK_STOCK_CLEAR);
-  gtk_entry_set_icon_activatable (GTK_ENTRY (entry),
-				  GTK_ENTRY_ICON_SECONDARY,
-                                  FALSE);
 
   g_signal_connect (entry, "icon-pressed", G_CALLBACK (clear_pressed), NULL);
 
@@ -173,6 +209,10 @@
 				 GTK_ENTRY_ICON_PRIMARY,
 				 GTK_STOCK_DIALOG_AUTHENTICATION);
 
+  gtk_entry_set_icon_activatable (GTK_ENTRY (entry),
+				  GTK_ENTRY_ICON_PRIMARY,
+				  FALSE);
+
   button = gtk_button_new_with_label ("Properties");
   gtk_table_attach (GTK_TABLE (table), button, 2, 3, 3, 4,
 		    GTK_FILL, GTK_FILL, 0, 0);



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