[libadwaita/wip/cdavis/entry-row-extra-props] entry-row: Add additional properties from GtkText




commit 73a5718c9b6d13340f719c3f85be5cef342a24f2
Author: Christopher Davis <christopherdavis gnome org>
Date:   Tue Jul 5 14:56:49 2022 -0400

    entry-row: Add additional properties from GtkText
    
    This commit adds three properties from GtkText:
    
    * input-hints
    * input-purpose
    * enable-emoji-completion
    
    Previously app developers would have needed to get
    the internal GtkText in order to access these.
    Now we provide our own accessors, similar to
    GtkEntry.
    
    Closes https://gitlab.gnome.org/GNOME/libadwaita/-/issues/504

 src/adw-entry-row.c | 200 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/adw-entry-row.h |  18 +++++
 2 files changed, 218 insertions(+)
---
diff --git a/src/adw-entry-row.c b/src/adw-entry-row.c
index 1dfff162..007551da 100644
--- a/src/adw-entry-row.c
+++ b/src/adw-entry-row.c
@@ -95,6 +95,9 @@ static GtkBuildableIface *parent_buildable_iface;
 enum {
   PROP_0,
   PROP_SHOW_APPLY_BUTTON,
+  PROP_INPUT_HINTS,
+  PROP_INPUT_PURPOSE,
+  PROP_ENABLE_EMOJI_COMPLETION,
   PROP_LAST_PROP,
 };
 
@@ -339,11 +342,17 @@ adw_entry_row_get_property (GObject     *object,
                             GParamSpec  *pspec)
 {
   AdwEntryRow *self = ADW_ENTRY_ROW (object);
+  AdwEntryRowPrivate *priv = adw_entry_row_get_instance_private (self);
 
   if (gtk_editable_delegate_get_property (object, prop_id, value, pspec))
     return;
 
   switch (prop_id) {
+  case PROP_INPUT_HINTS:
+  case PROP_INPUT_PURPOSE:
+  case PROP_ENABLE_EMOJI_COMPLETION:
+    g_object_get_property (G_OBJECT (priv->text), pspec->name, value);
+    break;
   case PROP_SHOW_APPLY_BUTTON:
     g_value_set_boolean (value, adw_entry_row_get_show_apply_button (self));
     break;
@@ -359,6 +368,7 @@ adw_entry_row_set_property (GObject       *object,
                             GParamSpec    *pspec)
 {
   AdwEntryRow *self = ADW_ENTRY_ROW (object);
+  AdwEntryRowPrivate *priv = adw_entry_row_get_instance_private (self);
 
   if (gtk_editable_delegate_set_property (object, prop_id, value, pspec))
   {
@@ -372,6 +382,11 @@ adw_entry_row_set_property (GObject       *object,
   }
 
   switch (prop_id) {
+  case PROP_INPUT_HINTS:
+  case PROP_INPUT_PURPOSE:
+  case PROP_ENABLE_EMOJI_COMPLETION:
+    g_object_set_property (G_OBJECT (priv->text), pspec->name, value);
+    break;
   case PROP_SHOW_APPLY_BUTTON:
     adw_entry_row_set_show_apply_button (self, g_value_get_boolean (value));
     break;
@@ -427,6 +442,54 @@ adw_entry_row_class_init (AdwEntryRowClass *klass)
                           FALSE,
                           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
 
+  /**
+   * AdwEntryRow:input-hints: (attributes org.gtk.Property.get=adw_entry_row_get_input_hints 
org.gtk.Property.set=adw_entry_row_set_input_hints)
+   *
+   * Additional hints that allow input methods to fine-tune their behavior.
+   *
+   * Also see [property@Gtk.Entry:input-purpose]
+   *
+   * Since: 1.2
+   */
+  props[PROP_INPUT_HINTS] =
+      g_param_spec_flags ("input-hints", NULL, NULL,
+                          GTK_TYPE_INPUT_HINTS,
+                          GTK_INPUT_HINT_NONE,
+                          G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+
+
+  /**
+   * AdwEntryRow:input-purpose: (attributes org.gtk.Property.get=adw_entry_row_get_input_purpose 
org.gtk.Property.set=adw_entry_row_set_input_purpose)
+   *
+   * The purpose of this text field.
+   *
+   * This property can be used by on-screen keyboards and other input
+   * methods to adjust their behaviour.
+   *
+   * Note that setting the purpose to %GTK_INPUT_PURPOSE_PASSWORD or
+   * %GTK_INPUT_PURPOSE_PIN is independent from setting
+   * [property@Gtk.Entry:visibility].
+   *
+   * Since: 1.2
+   */
+  props[PROP_INPUT_PURPOSE] =
+      g_param_spec_enum ("input-purpose", NULL, NULL,
+                         GTK_TYPE_INPUT_PURPOSE,
+                         GTK_INPUT_PURPOSE_FREE_FORM,
+                         G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+  /**
+   * AdwEntryRow:enable-emoji-completion: (attributes 
org.gtk.Property.get=adw_entry_row_get_enable_emoji_completion 
org.gtk.Property.set=adw_entry_row_set_enable_emoji_completion)
+   *
+   * Whether to suggest Emoji replacements for :-delimited names
+   * like `:heart:`.
+   *
+   * Since: 1.2
+   */
+  props[PROP_ENABLE_EMOJI_COMPLETION] =
+      g_param_spec_boolean ("enable-emoji-completion", NULL, NULL,
+                            FALSE,
+                            G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+
   g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
 
   gtk_editable_install_properties (object_class, PROP_LAST_PROP);
@@ -695,6 +758,143 @@ adw_entry_row_set_show_apply_button (AdwEntryRow *self,
   g_object_notify_by_pspec (G_OBJECT (self), props[PROP_SHOW_APPLY_BUTTON]);
 }
 
+/**
+ * adw_entry_row_get_input_hints: (attributes org.gtk.Method.get_property=input-hints)
+ * @self: an entry row
+ *
+ * Gets the input hints of @self
+ *
+ * Returns: The input hints
+ * Since: 1.2
+ */
+GtkInputHints
+adw_entry_row_get_input_hints (AdwEntryRow *self)
+{
+  AdwEntryRowPrivate *priv;
+
+  g_return_val_if_fail (ADW_IS_ENTRY_ROW (self), GTK_INPUT_HINT_NONE);
+
+  priv = adw_entry_row_get_instance_private (self);
+
+  return gtk_text_get_input_hints (GTK_TEXT (priv->text));
+}
+
+/**
+ * adw_entry_row_set_input_hints: (attributes org.gtk.Method.set_property=input-hints)
+ * @self: an entry row
+ * @hints: the hints
+ *
+ * Set additional hints which allow input methods to
+ * fine-tune their behavior.
+ *
+ * Since: 1.2
+ */
+void
+adw_entry_row_set_input_hints (AdwEntryRow   *self,
+                               GtkInputHints  hints)
+{
+  AdwEntryRowPrivate *priv;
+
+  g_return_if_fail (ADW_IS_ENTRY_ROW (self));
+
+  priv = adw_entry_row_get_instance_private (self);
+
+  gtk_text_set_input_hints (GTK_TEXT (priv->text), hints);
+
+  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_INPUT_HINTS]);
+}
+
+/**
+ * adw_entry_row_get_input_purpose: (attributes org.gtk.Method.get_property=input-purpose)
+ * @self: an entry row
+ *
+ * Gets the input purpose of @self
+ *
+ * Returns: the input purpose
+ * Since: 1.2
+ */
+GtkInputPurpose
+adw_entry_row_get_input_purpose (AdwEntryRow *self)
+{
+  AdwEntryRowPrivate *priv;
+
+  g_return_val_if_fail (ADW_IS_ENTRY_ROW (self), GTK_INPUT_PURPOSE_FREE_FORM);
+
+  priv = adw_entry_row_get_instance_private (self);
+
+  return gtk_text_get_input_purpose (GTK_TEXT (priv->text));
+}
+
+/**
+ * adw_entry_row_set_input_purpose: (attributes org.gtk.Method.set_property=input-purpose)
+ * @self: an entry row
+ * @purpose: the purpose
+ *
+ * Sets the input purpose which can be used by input methods
+ * to adjust their behavior.
+ *
+ * Since: 1.2
+ */
+void
+adw_entry_row_set_input_purpose (AdwEntryRow     *self,
+                                 GtkInputPurpose  purpose)
+{
+  AdwEntryRowPrivate *priv;
+
+  g_return_if_fail (ADW_IS_ENTRY_ROW (self));
+
+  priv = adw_entry_row_get_instance_private (self);
+
+  gtk_text_set_input_purpose (GTK_TEXT (priv->text), purpose);
+
+  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_INPUT_PURPOSE]);
+}
+
+/**
+ * adw_entry_row_get_enable_emoji_completion: (attributes 
org.gtk.Method.get_property=enable-emoji-completion)
+ * @self: an entry row
+ *
+ * Gets whether or not :-delimited emoji completion is enabled on @self
+ *
+ * Returns: whether or not emoji completion is enabled
+ * Since: 1.2
+ */
+gboolean
+adw_entry_row_get_enable_emoji_completion (AdwEntryRow *self)
+{
+  AdwEntryRowPrivate *priv;
+
+  g_return_val_if_fail (ADW_IS_ENTRY_ROW (self), FALSE);
+
+  priv = adw_entry_row_get_instance_private (self);
+
+  return gtk_text_get_enable_emoji_completion (GTK_TEXT (priv->text));
+}
+
+/**
+ * adw_entry_row_set_enable_emoji_completion: (attributes 
org.gtk.Method.get_property=enable-emoji-completion)
+ * @self: an entry row
+ * @enable_emoji_completion: Whether emoji completion should be enabled or not
+ *
+ * Sets whether or not :-delimited emoji completion is enabled on @self
+ *
+ * Since: 1.2
+ */
+void
+adw_entry_row_set_enable_emoji_completion (AdwEntryRow *self,
+                                           gboolean     enable_emoji_completion)
+{
+  AdwEntryRowPrivate *priv;
+
+  g_return_if_fail (ADW_IS_ENTRY_ROW (self));
+
+  priv = adw_entry_row_get_instance_private (self);
+
+  gtk_text_set_enable_emoji_completion (GTK_TEXT (priv->text), enable_emoji_completion);
+
+  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_ENABLE_EMOJI_COMPLETION]);
+}
+
 void
 adw_entry_row_set_indicator_icon_name (AdwEntryRow *self,
                                        const char  *icon_name)
diff --git a/src/adw-entry-row.h b/src/adw-entry-row.h
index b4e68ddd..9f818816 100644
--- a/src/adw-entry-row.h
+++ b/src/adw-entry-row.h
@@ -50,4 +50,22 @@ ADW_AVAILABLE_IN_1_2
 void     adw_entry_row_set_show_apply_button (AdwEntryRow *self,
                                               gboolean     show_apply_button);
 
+ADW_AVAILABLE_IN_1_2
+GtkInputHints adw_entry_row_get_input_hints (AdwEntryRow  *self);
+ADW_AVAILABLE_IN_1_2
+void          adw_entry_row_set_input_hints (AdwEntryRow  *self,
+                                             GtkInputHints hints);
+
+ADW_AVAILABLE_IN_1_2
+GtkInputPurpose adw_entry_row_get_input_purpose (AdwEntryRow    *self);
+ADW_AVAILABLE_IN_1_2
+void            adw_entry_row_set_input_purpose (AdwEntryRow    *self,
+                                                 GtkInputPurpose purpose);
+
+ADW_AVAILABLE_IN_1_2
+gboolean adw_entry_row_get_enable_emoji_completion (AdwEntryRow *self);
+ADW_AVAILABLE_IN_1_2
+void     adw_entry_row_set_enable_emoji_completion (AdwEntryRow *self,
+                                                    gboolean     enable_emoji_completion);
+
 G_END_DECLS


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