Merge branch 'activate-signal-dropdown-combobox' into 'master'

Add activate signal to DropDown and ComboBox

See merge request GNOME/gtk!3935
This commit is contained in:
Matthias Clasen 2021-11-04 01:19:43 +00:00
commit 8c63244855
3 changed files with 70 additions and 2 deletions

View File

@ -172,6 +172,7 @@ typedef struct
*/
enum {
ACTIVATE,
CHANGED,
MOVE_ACTIVE,
POPUP,
@ -346,6 +347,14 @@ gtk_combo_box_measure (GtkWidget *widget,
minimum_baseline, natural_baseline);
}
static void
gtk_combo_box_activate (GtkComboBox *combo_box)
{
GtkComboBoxPrivate *priv = gtk_combo_box_get_instance_private (combo_box);
gtk_widget_activate (priv->button);
}
static void
gtk_combo_box_size_allocate (GtkWidget *widget,
int width,
@ -419,9 +428,32 @@ gtk_combo_box_class_init (GtkComboBoxClass *klass)
object_class->set_property = gtk_combo_box_set_property;
object_class->get_property = gtk_combo_box_get_property;
klass->activate = gtk_combo_box_activate;
klass->format_entry_text = gtk_combo_box_format_entry_text;
/* signals */
/**
* GtkComboBox::activate:
* @widget: the object which received the signal.
*
* Emitted to when the combo box is activated.
*
* The `::activate` signal on `GtkComboBox` is an action signal and
* emitting it causes the combo box to pop up its dropdown.
*
* Since: 4.6
*/
combo_box_signals[ACTIVATE] =
g_signal_new (I_ ("activate"),
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkComboBoxClass, activate),
NULL, NULL,
NULL,
G_TYPE_NONE, 0);
gtk_widget_class_set_activate_signal (widget_class, combo_box_signals[ACTIVATE]);
/**
* GtkComboBox::changed:
* @widget: the object which received the signal
@ -2272,7 +2304,7 @@ gtk_combo_box_mnemonic_activate (GtkWidget *widget,
gtk_widget_grab_focus (priv->child);
}
else
gtk_widget_grab_focus (priv->button);
gtk_widget_mnemonic_activate (priv->button, group_cycling);
return TRUE;
}

View File

@ -60,10 +60,11 @@ struct _GtkComboBoxClass
void (* changed) (GtkComboBox *combo_box);
char *(* format_entry_text) (GtkComboBox *combo_box,
const char *path);
void (* activate) (GtkComboBox *combo_box);
/*< private >*/
gpointer padding[8];
gpointer padding[7];
};

View File

@ -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);