[gtk+/wip/ebassi/combo: 10/16] Add a getter for the item text
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/ebassi/combo: 10/16] Add a getter for the item text
- Date: Mon, 10 Aug 2015 12:16:28 +0000 (UTC)
commit 4fe89fcb0dd85831278bf22b7ed094be457f4653
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Jan 6 09:18:38 2015 -0500
Add a getter for the item text
This can be used to check for the presence of items as well.
gtk/gtkcombo.c | 14 ++++++++++++++
gtk/gtkcombo.h | 4 ++++
tests/testnewcombo.c | 32 ++++++++++++++++++++++++++++++++
3 files changed, 50 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkcombo.c b/gtk/gtkcombo.c
index 8215397..72d6753 100644
--- a/gtk/gtkcombo.c
+++ b/gtk/gtkcombo.c
@@ -1598,6 +1598,20 @@ gtk_combo_add_item (GtkCombo *combo,
collapse (combo, list);
}
+const gchar *
+gtk_combo_item_get_text (GtkCombo *combo,
+ const gchar *id)
+{
+ GtkWidget *item;
+
+ g_return_val_if_fail (GTK_IS_COMBO (combo), NULL);
+
+ if (!find_item (combo, id, &item, NULL))
+ return NULL;
+
+ return GTK_COMBO_ROW (item)->text;
+}
+
/**
* gtk_combo_item_set_sort_key:
* @combo: a #GtkCombo
diff --git a/gtk/gtkcombo.h b/gtk/gtkcombo.h
index 417f228..2e85dfb 100644
--- a/gtk/gtkcombo.h
+++ b/gtk/gtkcombo.h
@@ -59,6 +59,10 @@ void gtk_combo_remove_item (GtkCombo *combo,
const gchar *id);
GDK_AVAILABLE_IN_3_16
+const gchar *gtk_combo_item_get_text (GtkCombo *combo,
+ const gchar *id);
+
+GDK_AVAILABLE_IN_3_16
void gtk_combo_item_set_sort_key (GtkCombo *combo,
const gchar *id,
const gchar *sort);
diff --git a/tests/testnewcombo.c b/tests/testnewcombo.c
index 434befc..f36f36c 100644
--- a/tests/testnewcombo.c
+++ b/tests/testnewcombo.c
@@ -68,6 +68,27 @@ string_to_bool (GBinding *binding,
return TRUE;
}
+static gboolean
+selected_to_string (GBinding *binding,
+ const GValue *from_value,
+ GValue *to_value,
+ gpointer data)
+{
+ const gchar *id;
+ const gchar *text;
+
+ id = g_value_get_string (from_value);
+
+ if (id != NULL)
+ text = gtk_combo_item_get_text (GTK_COMBO (g_binding_get_source (binding)), id);
+ else
+ text = "";
+
+ g_value_set_string (to_value, text);
+
+ return TRUE;
+}
+
int
main (int argc, char *argv[])
{
@@ -262,6 +283,17 @@ main (int argc, char *argv[])
label, "label",
G_BINDING_SYNC_CREATE);
gtk_container_add (GTK_CONTAINER (box2), label);
+ box2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
+ gtk_widget_set_halign (box2, GTK_ALIGN_CENTER);
+ gtk_container_add (GTK_CONTAINER (box), box2);
+ label = gtk_label_new ("Label:");
+ gtk_container_add (GTK_CONTAINER (box2), label);
+ label = gtk_label_new ("");
+ g_object_bind_property_full (combo, "selected",
+ label, "label",
+ G_BINDING_SYNC_CREATE,
+ selected_to_string, NULL, NULL, NULL);
+ gtk_container_add (GTK_CONTAINER (box2), label);
gtk_widget_show_all (window);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]