[gtk+/wip/matthiasc/emoji-picker: 6/10] Add emoji completion to GtkEntry



commit d8ab62276bc61981a92a3ccb124c36e7d4e3d050
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Aug 19 14:08:15 2017 -0400

    Add emoji completion to GtkEntry
    
    This functionality has to be enabled using the enable-emoji-completion
    property.

 gtk/gtkentry.c |   40 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 40 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index 5badc77..4745c2b 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -71,6 +71,7 @@
 #include "gtkcssnodeprivate.h"
 #include "gtkimageprivate.h"
 #include "gtkemojichooser.h"
+#include "gtkemojicompletion.h"
 
 #include "a11y/gtkentryaccessible.h"
 
@@ -244,6 +245,7 @@ struct _GtkEntryPrivate
 
   guint         editable                : 1;
   guint         show_emoji_icon         : 1;
+  guint         enable_emoji_completion : 1;
   guint         in_drag                 : 1;
   guint         overwrite_mode          : 1;
   guint         visible                 : 1;
@@ -365,6 +367,7 @@ enum {
   PROP_POPULATE_ALL,
   PROP_TABS,
   PROP_SHOW_EMOJI_ICON,
+  PROP_ENABLE_EMOJI_COMPLETION,
   PROP_EDITING_CANCELED,
   NUM_PROPERTIES = PROP_EDITING_CANCELED
 };
@@ -652,6 +655,8 @@ static void         buffer_disconnect_signals          (GtkEntry       *entry);
 static GtkEntryBuffer *get_buffer                      (GtkEntry       *entry);
 static void         set_show_emoji_icon                (GtkEntry       *entry,
                                                         gboolean        value);
+static void         set_enable_emoji_completion        (GtkEntry       *entry,
+                                                        gboolean        value);
 
 static void     gtk_entry_measure (GtkWidget           *widget,
                                    GtkOrientation       orientation,
@@ -1398,6 +1403,13 @@ gtk_entry_class_init (GtkEntryClass *class)
                             FALSE,
                             GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
 
+  entry_props[PROP_ENABLE_EMOJI_COMPLETION] =
+      g_param_spec_boolean ("enable-emoji-completion",
+                            P_("Enable Emoji completion"),
+                            P_("Whether to suggest Emoji replacements"),
+                            FALSE,
+                            GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
+
   g_object_class_install_properties (gobject_class, NUM_PROPERTIES, entry_props);
 
   /**
@@ -2182,6 +2194,10 @@ gtk_entry_set_property (GObject         *object,
       set_show_emoji_icon (entry, g_value_get_boolean (value));
       break;
 
+    case PROP_ENABLE_EMOJI_COMPLETION:
+      set_enable_emoji_completion (entry, g_value_get_boolean (value));
+      break;
+
     case PROP_SCROLL_OFFSET:
     case PROP_CURSOR_POSITION:
     default:
@@ -2414,6 +2430,10 @@ gtk_entry_get_property (GObject         *object,
       g_value_set_boolean (value, priv->show_emoji_icon);
       break;
 
+    case PROP_ENABLE_EMOJI_COMPLETION:
+      g_value_set_boolean (value, priv->enable_emoji_completion);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -9952,3 +9972,23 @@ set_show_emoji_icon (GtkEntry *entry,
   g_object_notify_by_pspec (G_OBJECT (entry), entry_props[PROP_SHOW_EMOJI_ICON]);
   gtk_widget_queue_resize (GTK_WIDGET (entry));
 }
+
+static void
+set_enable_emoji_completion (GtkEntry *entry,
+                             gboolean  value)
+{
+  GtkEntryPrivate *priv = entry->priv;
+
+  if (priv->enable_emoji_completion == value)
+    return;
+
+  priv->enable_emoji_completion = value;
+
+  if (priv->enable_emoji_completion)
+    g_object_set_data_full (G_OBJECT (entry), "emoji-completion-popup",
+                            gtk_emoji_completion_new (entry), (GDestroyNotify)gtk_widget_destroy);
+  else
+    g_object_set_data (G_OBJECT (entry), "emoji-completion-popup", NULL);
+
+  g_object_notify_by_pspec (G_OBJECT (entry), entry_props[PROP_ENABLE_EMOJI_COMPLETION]);
+}


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