summaryrefslogtreecommitdiff
path: root/gtk/gtkdropdown.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2020-06-20 13:11:48 -0400
committerMatthias Clasen <mclasen@redhat.com>2020-06-20 13:11:48 -0400
commitad98e728845244e5275bcdf13eb8580140fc86a3 (patch)
treeb566705a438756e8c26beaef453b055a89719db8 /gtk/gtkdropdown.c
parentb7ddf0b2e5047a3ed9b4f357ebeb90308d5c2479 (diff)
downloadgtk+-ad98e728845244e5275bcdf13eb8580140fc86a3.tar.gz
dropdown: Add GtkDropDown:selected-item
This is the same readonly property we have in GtkSingleSelection. Fixes: #2861
Diffstat (limited to 'gtk/gtkdropdown.c')
-rw-r--r--gtk/gtkdropdown.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/gtk/gtkdropdown.c b/gtk/gtkdropdown.c
index c0a37f4089..a95775eab6 100644
--- a/gtk/gtkdropdown.c
+++ b/gtk/gtkdropdown.c
@@ -131,6 +131,7 @@ enum
PROP_LIST_FACTORY,
PROP_MODEL,
PROP_SELECTED,
+ PROP_SELECTED_ITEM,
PROP_ENABLE_SEARCH,
PROP_EXPRESSION,
@@ -314,6 +315,10 @@ gtk_drop_down_get_property (GObject *object,
g_value_set_uint (value, gtk_drop_down_get_selected (self));
break;
+ case PROP_SELECTED_ITEM:
+ g_value_set_object (value, gtk_drop_down_get_selected_item (self));
+ break;
+
case PROP_ENABLE_SEARCH:
g_value_set_boolean (value, self->enable_search);
break;
@@ -489,6 +494,18 @@ gtk_drop_down_class_init (GtkDropDownClass *klass)
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
/**
+ * GtkDropDown:selected-item:
+ *
+ * The selected item.
+ */
+ properties[PROP_SELECTED_ITEM] =
+ g_param_spec_object ("selected-item",
+ P_("Selected Item"),
+ P_("The selected item"),
+ G_TYPE_OBJECT,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
+ /**
* GtkDropDown:enable-search:
*
* Whether to show a search entry in the popup.
@@ -794,6 +811,7 @@ gtk_drop_down_set_selected (GtkDropDown *self,
gtk_single_selection_set_selected (GTK_SINGLE_SELECTION (self->selection), position);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SELECTED]);
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SELECTED_ITEM]);
}
/**
@@ -817,6 +835,25 @@ gtk_drop_down_get_selected (GtkDropDown *self)
}
/**
+ * gtk_drop_down_get_selected_item:
+ * @self: a #GtkDropDown
+ *
+ * Gets the selected item. If no item is selected, %NULL is returned.
+ *
+ * Returns: (transfer none): The selected item
+ */
+gpointer
+gtk_drop_down_get_selected_item (GtkDropDown *self)
+{
+ g_return_val_if_fail (GTK_IS_DROP_DOWN (self), NULL);
+
+ if (self->selection == NULL)
+ return NULL;
+
+ return gtk_single_selection_get_selected_item (GTK_SINGLE_SELECTION (self->selection));
+}
+
+/**
* gtk_drop_down_set_enable_search:
* @self: a #GtkDropDown
* @enable_search: whether to enable search