diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | gtk/gtkentry.c | 60 | ||||
-rw-r--r-- | tests/testentryicons.c | 62 |
3 files changed, 88 insertions, 41 deletions
@@ -1,5 +1,12 @@ 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. + +2008-12-26 Matthias Clasen <mclasen@redhat.com> + * gtk/gtkentry.c: Fix interaction between icons and widget sensitivity. Also fix a few typos. diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c index 8c563124ed..cd66d240aa 100644 --- a/gtk/gtkentry.c +++ b/gtk/gtkentry.c @@ -2124,6 +2124,11 @@ update_cursors (GtkWidget *widget) 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_entry_button_press (GtkWidget *widget, 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 @@ gtk_entry_button_release (GtkWidget *widget, 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_entry_get_icon_at_pos (GtkEntry *entry, } /** - * 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_entry_set_icon_drag_source (GtkEntry *entry, } /** - * 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 diff --git a/tests/testentryicons.c b/tests/testentryicons.c index 1b27a610f2..540f04a364 100644 --- a/tests/testentryicons.c +++ b/tests/testentryicons.c @@ -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 @@ properties_cb (GtkWidget *button, 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 @@ main (int argc, char **argv) GtkWidget *entry; GtkWidget *button; GIcon *icon; + GtkTargetList *tlist; gtk_init (&argc, &argv); @@ -84,7 +115,7 @@ main (int argc, char **argv) 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 @@ main (int argc, char **argv) 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 @@ main (int argc, char **argv) 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 @@ main (int argc, char **argv) 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); |