[gtk: 2/4] dropdown: Make DropDown activatable




commit 3918cdd989a96855d0c41db7a83feb4cf554a3f4
Author: Maximiliano Sandoval R <msandova gnome org>
Date:   Fri Sep 10 15:42:47 2021 +0200

    dropdown: Make DropDown activatable
    
    The activation is simply forwarded to the button
    within.

 gtk/gtkdropdown.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
---
diff --git a/gtk/gtkdropdown.c b/gtk/gtkdropdown.c
index 94ee484c14..30cb3fa172 100644
--- a/gtk/gtkdropdown.c
+++ b/gtk/gtkdropdown.c
@@ -126,9 +126,16 @@ enum
   N_PROPS
 };
 
+enum
+{
+  ACTIVATE,
+  LAST_SIGNAL
+};
+
 G_DEFINE_TYPE (GtkDropDown, gtk_drop_down, GTK_TYPE_WIDGET)
 
 static GParamSpec *properties[N_PROPS] = { NULL, };
+static guint signals[LAST_SIGNAL] = { 0 };
 
 static void
 button_toggled (GtkWidget *widget,
@@ -203,6 +210,12 @@ selection_changed (GtkSingleSelection *selection,
   g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SELECTED_ITEM]);
 }
 
+static void
+gtk_drop_down_activate (GtkDropDown *self)
+{
+  gtk_widget_activate (self->button);
+}
+
 static void
 update_filter (GtkDropDown *self)
 {
@@ -547,6 +560,28 @@ gtk_drop_down_class_init (GtkDropDownClass *klass)
 
   g_object_class_install_properties (gobject_class, N_PROPS, properties);
 
+  /**
+   * GtkDropDown::activate:
+   * @widget: the object which received the signal.
+   *
+   * Emitted to when the drop down is activated.
+   *
+   * The `::activate` signal on `GtkDropDown` is an action signal and
+   * emitting it causes the drop down to pop up its dropdown.
+   *
+   * Since: 4.6
+   */
+  signals[ACTIVATE] =
+      g_signal_new_class_handler (I_ ("activate"),
+                                  G_OBJECT_CLASS_TYPE (gobject_class),
+                                  G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
+                                  G_CALLBACK (gtk_drop_down_activate),
+                                  NULL, NULL,
+                                  NULL,
+                                  G_TYPE_NONE, 0);
+
+  gtk_widget_class_set_activate_signal (widget_class, signals[ACTIVATE]);
+
   gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/ui/gtkdropdown.ui");
   gtk_widget_class_bind_template_child (widget_class, GtkDropDown, arrow);
   gtk_widget_class_bind_template_child (widget_class, GtkDropDown, button);


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