]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkentry.c
GtkBubbleWindow: rework how drawing is done
[~andy/gtk] / gtk / gtkentry.c
index 27fceb1bcb24e1c5363d2b32d9d03ae1933c26db..159120473c8a323d598478645894c51c5ee1e856 100644 (file)
@@ -67,6 +67,7 @@
 #include "gtkstylecontextprivate.h"
 #include "gtktexthandleprivate.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_all            : 1;
 };
 
 struct _EntryIconInfo
@@ -318,7 +320,8 @@ enum {
   PROP_COMPLETION,
   PROP_INPUT_PURPOSE,
   PROP_INPUT_HINTS,
-  PROP_ATTRIBUTES
+  PROP_ATTRIBUTES,
+  PROP_POPULATE_ALL
 };
 
 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-all:
+   *
+   * If ::populate-all 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_ALL,
+                                   g_param_spec_boolean ("populate-all",
+                                                         P_("Populate all"),
+                                                         P_("Whether to emit ::populate-popup for touch popups"),
+                                                         FALSE,
+                                                         GTK_PARAM_READWRITE));
+  
   /**
    * GtkEntry:icon-prelight:
    *
@@ -1480,13 +1498,20 @@ 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 container 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, which
+   * will be a #GtkMenu in this case.
+   *
+   * If #GtkEntry::populate-all is %TRUE, this signal will
+   * also be emitted to populate touch popups. In this case,
+   * @widget will be a different container, e.g. a #GtkToolbar.
+   * The signal handler should not make assumptions about the
+   * type of @widget.
    */
   signals[POPULATE_POPUP] =
     g_signal_new (I_("populate-popup"),
@@ -1496,7 +1521,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 +2263,10 @@ gtk_entry_set_property (GObject         *object,
       gtk_entry_set_attributes (entry, g_value_get_boxed (value));
       break;
 
+    case PROP_POPULATE_ALL:
+      entry->priv->populate_all = g_value_get_boolean (value);
+      break;
+
     case PROP_SCROLL_OFFSET:
     case PROP_CURSOR_POSITION:
     default:
@@ -2474,6 +2503,10 @@ gtk_entry_get_property (GObject         *object,
       g_value_set_boxed (value, priv->attrs);
       break;
 
+    case PROP_POPULATE_ALL:
+      g_value_set_boolean (value, priv->populate_all);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -9262,7 +9295,7 @@ activate_bubble_cb (GtkWidget *item,
 {
   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));
+  _gtk_bubble_window_popdown (GTK_BUBBLE_WINDOW (entry->priv->selection_bubble));
 }
 
 static void
@@ -9306,8 +9339,8 @@ bubble_targets_received (GtkClipboard     *clipboard,
   if (priv->selection_bubble)
     gtk_widget_destroy (priv->selection_bubble);
 
-  priv->selection_bubble = gtk_bubble_window_new ();
-  toolbar = gtk_toolbar_new ();
+  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);
@@ -9325,6 +9358,9 @@ bubble_targets_received (GtkClipboard     *clipboard,
   append_bubble_action (entry, toolbar, GTK_STOCK_PASTE, "paste-clipboard",
                         priv->editable && has_clipboard);
 
+  if (priv->populate_all)
+    g_signal_emit (entry, signals[POPULATE_POPUP], 0, toolbar);
+
   gtk_widget_get_allocation (GTK_WIDGET (entry), &allocation);
 
   gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &start_x, NULL);
@@ -9349,8 +9385,8 @@ bubble_targets_received (GtkClipboard     *clipboard,
       rect.width = 0;
     }
 
-  gtk_bubble_window_popup (GTK_BUBBLE_WINDOW (priv->selection_bubble),
-                           priv->text_area, &rect, GTK_POS_TOP);
+  _gtk_bubble_window_popup (GTK_BUBBLE_WINDOW (priv->selection_bubble),
+                            priv->text_area, &rect, GTK_POS_TOP);
 
   priv->selection_bubble_timeout_id = 0;
 }
@@ -9375,7 +9411,7 @@ gtk_entry_selection_bubble_popup_unset (GtkEntry *entry)
   priv = entry->priv;
 
   if (priv->selection_bubble)
-    gtk_bubble_window_popdown (GTK_BUBBLE_WINDOW (priv->selection_bubble));
+    _gtk_bubble_window_popdown (GTK_BUBBLE_WINDOW (priv->selection_bubble));
 
   if (priv->selection_bubble_timeout_id)
     {