[gtk/text: 13/30] entry completion: Make this work again



commit c962e9040090d8b33aaa057c01df13c3c7322cef
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Feb 17 23:03:27 2019 -0500

    entry completion: Make this work again
    
    Connect to GtkText signals where necessary.

 gtk/gtkentrycompletion.c | 110 +++++++++++++++++++++--------------------------
 1 file changed, 49 insertions(+), 61 deletions(-)
---
diff --git a/gtk/gtkentrycompletion.c b/gtk/gtkentrycompletion.c
index 6d43daff98..5657a19d46 100644
--- a/gtk/gtkentrycompletion.c
+++ b/gtk/gtkentrycompletion.c
@@ -67,6 +67,7 @@
 #include "gtkentrycompletion.h"
 
 #include "gtkentryprivate.h"
+#include "gtktextprivate.h"
 #include "gtkcelllayout.h"
 #include "gtkcellareabox.h"
 
@@ -496,8 +497,9 @@ propagate_to_entry (GtkEventControllerKey *key,
                     GtkEntryCompletion    *completion)
 {
   GtkEntryCompletionPrivate *priv = completion->priv;
+  GtkText *text = gtk_entry_get_text_widget (GTK_ENTRY (priv->entry));
 
-  return gtk_event_controller_key_forward (key, priv->entry);
+  return gtk_event_controller_key_forward (key, GTK_WIDGET (text));
 }
 
 static void
@@ -894,6 +896,7 @@ gtk_entry_completion_list_activated (GtkTreeView       *treeview,
   gboolean entry_set;
   GtkTreeModel *model;
   GtkTreeIter child_iter;
+  GtkText *text = gtk_entry_get_text_widget (GTK_ENTRY (completion->priv->entry));
 
   gtk_tree_model_get_iter (GTK_TREE_MODEL (completion->priv->filter_model), &iter, path);
   gtk_tree_model_filter_convert_iter_to_child_iter (completion->priv->filter_model,
@@ -901,12 +904,10 @@ gtk_entry_completion_list_activated (GtkTreeView       *treeview,
                                                     &iter);
   model = gtk_tree_model_filter_get_model (completion->priv->filter_model);
 
-  g_signal_handler_block (completion->priv->entry,
-                          completion->priv->changed_id);
+  g_signal_handler_block (text, completion->priv->changed_id);
   g_signal_emit (completion, entry_completion_signals[MATCH_SELECTED],
                  0, model, &child_iter, &entry_set);
-  g_signal_handler_unblock (completion->priv->entry,
-                            completion->priv->changed_id);
+  g_signal_handler_unblock (text, completion->priv->changed_id);
 
   _gtk_entry_completion_popdown (completion);
 }
@@ -1493,14 +1494,15 @@ static void
 gtk_entry_completion_popup (GtkEntryCompletion *completion)
 {
   GtkWidget *toplevel;
+  GtkText *text = gtk_entry_get_text_widget (GTK_ENTRY (completion->priv->entry));
 
   if (gtk_widget_get_mapped (completion->priv->popup_window))
     return;
 
-  if (!gtk_widget_get_mapped (completion->priv->entry))
+  if (!gtk_widget_get_mapped (GTK_WIDGET (text)))
     return;
 
-  if (!gtk_widget_has_focus (completion->priv->entry))
+  if (!gtk_widget_has_focus (GTK_WIDGET (text)))
     return;
 
   if (completion->priv->has_grab)
@@ -1709,29 +1711,30 @@ gtk_entry_completion_get_completion_prefix (GtkEntryCompletion *completion)
 
 static void
 gtk_entry_completion_insert_completion_text (GtkEntryCompletion *completion,
-                                             const gchar *text)
+                                             const gchar        *new_text)
 {
   GtkEntryCompletionPrivate *priv = completion->priv;
   gint len;
+  GtkText *text = gtk_entry_get_text_widget (GTK_ENTRY (priv->entry));
 
   priv = completion->priv;
 
   if (priv->changed_id > 0)
-    g_signal_handler_block (priv->entry, priv->changed_id);
+    g_signal_handler_block (text, priv->changed_id);
 
   if (priv->insert_text_id > 0)
-    g_signal_handler_block (priv->entry, priv->insert_text_id);
+    g_signal_handler_block (text, priv->insert_text_id);
 
-  gtk_entry_set_text (GTK_ENTRY (priv->entry), text);
+  gtk_editable_set_text (GTK_EDITABLE (priv->entry), new_text);
 
   len = strlen (priv->completion_prefix);
   gtk_editable_select_region (GTK_EDITABLE (priv->entry), len, -1);
 
   if (priv->changed_id > 0)
-    g_signal_handler_unblock (priv->entry, priv->changed_id);
+    g_signal_handler_unblock (text, priv->changed_id);
 
   if (priv->insert_text_id > 0)
-    g_signal_handler_unblock (priv->entry, priv->insert_text_id);
+    g_signal_handler_unblock (text, priv->insert_text_id);
 }
 
 static gboolean
@@ -1766,13 +1769,13 @@ gtk_entry_completion_insert_prefix (GtkEntryCompletion *completion)
 {
   gboolean done;
   gchar *prefix;
+  GtkText *text = gtk_entry_get_text_widget (GTK_ENTRY (completion->priv->entry));
 
   if (completion->priv->insert_text_id > 0)
-    g_signal_handler_block (completion->priv->entry,
-                            completion->priv->insert_text_id);
+    g_signal_handler_block (text, completion->priv->insert_text_id);
 
   prefix = gtk_entry_completion_compute_prefix (completion,
-                                                gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)));
+                                                gtk_editable_get_text (GTK_EDITABLE 
(completion->priv->entry)));
 
   if (prefix)
     {
@@ -1782,8 +1785,7 @@ gtk_entry_completion_insert_prefix (GtkEntryCompletion *completion)
     }
 
   if (completion->priv->insert_text_id > 0)
-    g_signal_handler_unblock (completion->priv->entry,
-                              completion->priv->insert_text_id);
+    g_signal_handler_unblock (text, completion->priv->insert_text_id);
 }
 
 /**
@@ -2066,6 +2068,7 @@ gtk_entry_completion_key_pressed (GtkEventControllerKey *controller,
   gint matches, actions = 0;
   GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
   GtkWidget *widget = completion->priv->entry;
+  GtkText *text = gtk_entry_get_text_widget (GTK_ENTRY (widget));
 
   if (!completion->priv->popup_completion)
     return FALSE;
@@ -2296,10 +2299,10 @@ keypress_completion_out:
             {
               gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, 
&iter);
               child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
-              g_signal_handler_block (widget, completion->priv->changed_id);
+              g_signal_handler_block (text, completion->priv->changed_id);
               g_signal_emit_by_name (completion, "match-selected",
                                      child_model, &child_iter, &entry_set);
-              g_signal_handler_unblock (widget, completion->priv->changed_id);
+              g_signal_handler_unblock (text, completion->priv->changed_id);
 
               if (!entry_set)
                 {
@@ -2349,7 +2352,6 @@ gtk_entry_completion_changed (GtkWidget *widget,
                               gpointer   user_data)
 {
   GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (user_data);
-  GtkEntry *entry = GTK_ENTRY (widget);
   GdkDevice *device;
 
   if (!completion->priv->popup_completion)
@@ -2362,12 +2364,12 @@ gtk_entry_completion_changed (GtkWidget *widget,
       completion->priv->completion_timeout = 0;
     }
 
-  if (!gtk_entry_get_text (entry))
+  if (!gtk_editable_get_text (GTK_EDITABLE (widget)))
     return;
 
   /* no need to normalize for this test */
   if (completion->priv->minimum_key_length > 0 &&
-      strcmp ("", gtk_entry_get_text (entry)) == 0)
+      strcmp ("", gtk_editable_get_text (GTK_EDITABLE (widget))) == 0)
     {
       if (gtk_widget_get_visible (completion->priv->popup_window))
         _gtk_entry_completion_popdown (completion);
@@ -2401,11 +2403,10 @@ check_completion_callback (GtkEntryCompletion *completion)
 }
 
 static void
-clear_completion_callback (GtkEntry   *entry,
-                           GParamSpec *pspec)
+clear_completion_callback (GObject            *text,
+                           GParamSpec         *pspec,
+                           GtkEntryCompletion *completion)
 {
-  GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
-      
   if (!completion->priv->inline_completion)
     return;
 
@@ -2415,22 +2416,20 @@ clear_completion_callback (GtkEntry   *entry,
 }
 
 static gboolean
-accept_completion_callback (GtkEntry *entry)
+accept_completion_callback (GtkEntryCompletion *completion)
 {
-  GtkEntryCompletion *completion = gtk_entry_get_completion (entry);
-
   if (!completion->priv->inline_completion)
     return FALSE;
 
   if (completion->priv->has_completion)
-    gtk_editable_set_position (GTK_EDITABLE (entry),
-                               gtk_entry_buffer_get_length (gtk_entry_get_buffer (entry)));
+    gtk_editable_set_position (GTK_EDITABLE (completion->priv->entry),
+                               gtk_entry_buffer_get_length (gtk_entry_get_buffer (GTK_ENTRY 
(completion->priv->entry))));
 
   return FALSE;
 }
 
 static void
-completion_insert_text_callback (GtkEntry           *entry,
+completion_insert_text_callback (GtkText            *entry,
                                  const gchar        *text,
                                  gint                length,
                                  gint                position,
@@ -2457,26 +2456,21 @@ connect_completion_signals (GtkEntryCompletion *completion)
 {
   GtkEntryCompletionPrivate *priv = completion->priv;
   GtkEventController *controller;
+  GtkText *text = gtk_entry_get_text_widget (GTK_ENTRY (priv->entry));
 
   controller = priv->entry_key_controller = gtk_event_controller_key_new ();
   g_signal_connect (controller, "key-pressed",
                     G_CALLBACK (gtk_entry_completion_key_pressed), completion);
-  g_signal_connect_swapped (controller, "focus-out",
-                            G_CALLBACK (accept_completion_callback),
-                            completion->priv->entry);
-  gtk_widget_add_controller (completion->priv->entry, controller);
+  g_signal_connect_swapped (controller, "focus-out", G_CALLBACK (accept_completion_callback), completion);
+  gtk_widget_add_controller (GTK_WIDGET (text), controller);
 
   completion->priv->changed_id =
-    g_signal_connect (completion->priv->entry, "changed",
-                      G_CALLBACK (gtk_entry_completion_changed), completion);
+    g_signal_connect (text, "changed", G_CALLBACK (gtk_entry_completion_changed), completion);
 
     completion->priv->insert_text_id =
-      g_signal_connect (completion->priv->entry, "insert-text",
-                        G_CALLBACK (completion_insert_text_callback), completion);
-    g_signal_connect (completion->priv->entry, "notify",
-                      G_CALLBACK (clear_completion_callback), completion);
-    g_signal_connect (completion->priv->entry, "activate",
-                      G_CALLBACK (accept_completion_callback), completion);
+      g_signal_connect (text, "insert-text", G_CALLBACK (completion_insert_text_callback), completion);
+    g_signal_connect (text, "notify", G_CALLBACK (clear_completion_callback), completion);
+    g_signal_connect_swapped (text, "activate", G_CALLBACK (accept_completion_callback), completion);
 }
 
 static void
@@ -2512,31 +2506,25 @@ unset_accessible_relation (GtkWidget *window,
 static void
 disconnect_completion_signals (GtkEntryCompletion *completion)
 {
-  gtk_widget_remove_controller (completion->priv->entry,
-                                completion->priv->entry_key_controller);
+  GtkText *text = gtk_entry_get_text_widget (GTK_ENTRY (completion->priv->entry));
+
+  gtk_widget_remove_controller (GTK_WIDGET (text), completion->priv->entry_key_controller);
 
   if (completion->priv->changed_id > 0 &&
-      g_signal_handler_is_connected (completion->priv->entry,
-                                     completion->priv->changed_id))
+      g_signal_handler_is_connected (text, completion->priv->changed_id))
     {
-      g_signal_handler_disconnect (completion->priv->entry,
-                                   completion->priv->changed_id);
+      g_signal_handler_disconnect (text, completion->priv->changed_id);
       completion->priv->changed_id = 0;
     }
   if (completion->priv->insert_text_id > 0 &&
-      g_signal_handler_is_connected (completion->priv->entry,
-                                     completion->priv->insert_text_id))
+      g_signal_handler_is_connected (text, completion->priv->insert_text_id))
     {
-      g_signal_handler_disconnect (completion->priv->entry,
-                                   completion->priv->insert_text_id);
+      g_signal_handler_disconnect (text, completion->priv->insert_text_id);
       completion->priv->insert_text_id = 0;
     }
-  g_signal_handlers_disconnect_by_func (completion->priv->entry,
-                                        G_CALLBACK (completion_insert_text_callback), completion);
-  g_signal_handlers_disconnect_by_func (completion->priv->entry,
-                                        G_CALLBACK (clear_completion_callback), completion);
-  g_signal_handlers_disconnect_by_func (completion->priv->entry,
-                                        G_CALLBACK (accept_completion_callback), completion);
+  g_signal_handlers_disconnect_by_func (text, G_CALLBACK (completion_insert_text_callback), completion);
+  g_signal_handlers_disconnect_by_func (text, G_CALLBACK (clear_completion_callback), completion);
+  g_signal_handlers_disconnect_by_func (text, G_CALLBACK (accept_completion_callback), completion);
 }
 
 void


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