summaryrefslogtreecommitdiff
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
parentb7ddf0b2e5047a3ed9b4f357ebeb90308d5c2479 (diff)
downloadgtk+-ad98e728845244e5275bcdf13eb8580140fc86a3.tar.gz
dropdown: Add GtkDropDown:selected-item
This is the same readonly property we have in GtkSingleSelection. Fixes: #2861
-rw-r--r--docs/reference/gtk/gtk4-sections.txt1
-rw-r--r--gtk/gtkdropdown.c37
-rw-r--r--gtk/gtkdropdown.h3
3 files changed, 41 insertions, 0 deletions
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index c61cd3452c..59df2f46e8 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -7540,6 +7540,7 @@ gtk_drop_down_set_model
gtk_drop_down_get_model
gtk_drop_down_set_selected
gtk_drop_down_get_selected
+gtk_drop_down_get_selected_item
gtk_drop_down_set_factory
gtk_drop_down_get_factory
gtk_drop_down_set_list_factory
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
diff --git a/gtk/gtkdropdown.h b/gtk/gtkdropdown.h
index 84813b3877..0795d0f77b 100644
--- a/gtk/gtkdropdown.h
+++ b/gtk/gtkdropdown.h
@@ -50,6 +50,9 @@ GDK_AVAILABLE_IN_ALL
guint gtk_drop_down_get_selected (GtkDropDown *self);
GDK_AVAILABLE_IN_ALL
+gpointer gtk_drop_down_get_selected_item (GtkDropDown *self);
+
+GDK_AVAILABLE_IN_ALL
void gtk_drop_down_set_factory (GtkDropDown *self,
GtkListItemFactory *factory);
GDK_AVAILABLE_IN_ALL