X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtkentry.c;h=3354c90a5091f5ea38577db0fd6282a0b1688c63;hb=190dcfe050814e979c364bf74ae83530aba4c686;hp=a5c13e2c7a24248b1d17e7e220a9924d7a4fcc89;hpb=ceeed09d0780e5a2227fcfdb3e13f7530aa5fcf2;p=~andy%2Fgtk diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c index a5c13e2c7..3354c90a5 100644 --- a/gtk/gtkentry.c +++ b/gtk/gtkentry.c @@ -66,7 +66,8 @@ #include "gtkwidgetprivate.h" #include "gtkstylecontextprivate.h" #include "gtktexthandleprivate.h" -#include "gtkselectionwindowprivate.h" +#include "gtkbubblewindowprivate.h" +#include "gtktoolbar.h" #include "a11y/gtkentryaccessible.h" @@ -222,6 +223,7 @@ struct _GtkEntryPrivate guint truncate_multiline : 1; guint cursor_handle_dragged : 1; guint selection_handle_dragged : 1; + guint populate_toolbar : 1; }; struct _EntryIconInfo @@ -318,7 +320,8 @@ enum { PROP_COMPLETION, PROP_INPUT_PURPOSE, PROP_INPUT_HINTS, - PROP_ATTRIBUTES + PROP_ATTRIBUTES, + PROP_POPULATE_TOOLBAR }; static guint signals[LAST_SIGNAL] = { 0 }; @@ -1422,6 +1425,21 @@ gtk_entry_class_init (GtkEntryClass *class) PANGO_TYPE_ATTR_LIST, GTK_PARAM_READWRITE)); + /** GtkEntry:populate-toolbar: + * + * If ::populate-toolbar is %TRUE, the #GtkEntry::populate-popup + * signal is also emitted for touch popups. + * + * Since: 3.8 + */ + g_object_class_install_property (gobject_class, + PROP_POPULATE_TOOLBAR, + g_param_spec_boolean ("populate-toolbar", + P_("Populate toolbar"), + P_("Whether to emit ::populate-popup for touch popups"), + FALSE, + GTK_PARAM_READWRITE)); + /** * GtkEntry:icon-prelight: * @@ -1480,13 +1498,17 @@ gtk_entry_class_init (GtkEntryClass *class) /** * GtkEntry::populate-popup: * @entry: The entry on which the signal is emitted - * @menu: the menu that is being populated + * @popup: the menu or toolbar that is being populated * - * The ::populate-popup signal gets emitted before showing the - * context menu of the entry. + * The ::populate-popup signal gets emitted before showing the + * context menu of the entry. * * If you need to add items to the context menu, connect - * to this signal and append your menuitems to the @menu. + * to this signal and append your items to the @widget. + * + * If #GtkEntry::populate-toolbar is %TRUE, this signal will + * also be emitted to populate touch popups. In this case, + * @widget will be a toolbar instead of a menu. */ signals[POPULATE_POPUP] = g_signal_new (I_("populate-popup"), @@ -1496,7 +1518,7 @@ gtk_entry_class_init (GtkEntryClass *class) NULL, NULL, _gtk_marshal_VOID__OBJECT, G_TYPE_NONE, 1, - GTK_TYPE_MENU); + GTK_TYPE_WIDGET); /* Action signals */ @@ -2238,6 +2260,10 @@ gtk_entry_set_property (GObject *object, gtk_entry_set_attributes (entry, g_value_get_boxed (value)); break; + case PROP_POPULATE_TOOLBAR: + entry->priv->populate_toolbar = g_value_get_boolean (value); + break; + case PROP_SCROLL_OFFSET: case PROP_CURSOR_POSITION: default: @@ -2474,6 +2500,10 @@ gtk_entry_get_property (GObject *object, g_value_set_boxed (value, priv->attrs); break; + case PROP_POPULATE_TOOLBAR: + g_value_set_boolean (value, priv->populate_toolbar); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -9256,8 +9286,34 @@ gtk_entry_popup_menu (GtkWidget *widget) return TRUE; } -static gboolean -gtk_entry_selection_bubble_popup_cb (gpointer user_data) +static void +activate_bubble_cb (GtkWidget *item, + GtkEntry *entry) +{ + const gchar *signal = g_object_get_data (G_OBJECT (item), "gtk-signal"); + g_signal_emit_by_name (entry, signal); + gtk_bubble_window_popdown (GTK_BUBBLE_WINDOW (entry->priv->selection_bubble)); +} + +static void +append_bubble_action (GtkEntry *entry, + GtkWidget *toolbar, + const gchar *stock_id, + const gchar *signal, + gboolean sensitive) +{ + GtkToolItem *item = gtk_tool_button_new_from_stock (stock_id); + g_object_set_data (G_OBJECT (item), I_("gtk-signal"), (char *)signal); + g_signal_connect (item, "clicked", G_CALLBACK (activate_bubble_cb), entry); + gtk_widget_set_sensitive (GTK_WIDGET (item), sensitive); + gtk_widget_show (GTK_WIDGET (item)); + gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1); +} + +static void +bubble_targets_received (GtkClipboard *clipboard, + GtkSelectionData *data, + gpointer user_data) { GtkEntry *entry = user_data; GtkEntryPrivate *priv = entry->priv; @@ -9265,33 +9321,42 @@ gtk_entry_selection_bubble_popup_cb (gpointer user_data) GtkAllocation allocation; gint start_x, end_x; gboolean has_selection; + gboolean has_clipboard; + DisplayMode mode; + GtkWidget *toolbar; has_selection = gtk_editable_get_selection_bounds (GTK_EDITABLE (entry), NULL, NULL); if (!has_selection && !priv->editable) { priv->selection_bubble_timeout_id = 0; - return FALSE; + return; } if (priv->selection_bubble) gtk_widget_destroy (priv->selection_bubble); - priv->selection_bubble = gtk_selection_window_new (); - g_signal_connect_swapped (priv->selection_bubble, "cut", - G_CALLBACK (gtk_entry_cut_clipboard), - entry); - g_signal_connect_swapped (priv->selection_bubble, "copy", - G_CALLBACK (gtk_entry_copy_clipboard), - entry); - g_signal_connect_swapped (priv->selection_bubble, "paste", - G_CALLBACK (gtk_entry_paste_clipboard), - entry); - - gtk_selection_window_set_editable (GTK_SELECTION_WINDOW (priv->selection_bubble), - priv->editable); - gtk_selection_window_set_has_selection (GTK_SELECTION_WINDOW (priv->selection_bubble), - has_selection); + priv->selection_bubble = gtk_bubble_window_new (); + toolbar = GTK_WIDGET (gtk_toolbar_new ()); + gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_TEXT); + gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), FALSE); + gtk_widget_show (toolbar); + gtk_container_add (GTK_CONTAINER (priv->selection_bubble), toolbar); + + has_clipboard = gtk_selection_data_targets_include_text (data); + mode = gtk_entry_get_display_mode (entry); + + append_bubble_action (entry, toolbar, GTK_STOCK_CUT, "cut-clipboard", + priv->editable && has_selection && mode == DISPLAY_NORMAL); + + append_bubble_action (entry, toolbar, GTK_STOCK_COPY, "copy-clipboard", + has_selection && mode == DISPLAY_NORMAL); + + append_bubble_action (entry, toolbar, GTK_STOCK_PASTE, "paste-clipboard", + priv->editable && has_clipboard); + + if (priv->populate_toolbar) + g_signal_emit (entry, signals[POPULATE_POPUP], 0, toolbar); gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation); @@ -9321,7 +9386,18 @@ gtk_entry_selection_bubble_popup_cb (gpointer user_data) priv->text_area, &rect, GTK_POS_TOP); priv->selection_bubble_timeout_id = 0; - return FALSE; +} + +static gboolean +gtk_entry_selection_bubble_popup_cb (gpointer user_data) +{ + GtkEntry *entry = user_data; + + gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (entry), GDK_SELECTION_CLIPBOARD), + gdk_atom_intern_static_string ("TARGETS"), + bubble_targets_received, + entry); + return G_SOURCE_REMOVE; } static void