[gtk+/radio-group-2: 2/3] Add a GtkRadioGroup::active-value property
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/radio-group-2: 2/3] Add a GtkRadioGroup::active-value property
- Date: Tue, 30 Nov 2010 14:39:30 +0000 (UTC)
commit d285e9dbf57717c4ad4d64ebcbbe11dfe8ea1ede
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Nov 30 09:34:05 2010 -0500
Add a GtkRadioGroup::active-value property
This is only supported for radio groups which contain radio actions,
and in that case is just the ::string-value property of the active item.
The property is readable and writable. Setting it has the effect of
changing the active item, if any of the items has a matching string-value.
This property is intended for easy binding to settings.
gtk/gtkradiogroup.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++-
gtk/gtkradiogroup.h | 13 +++++++----
2 files changed, 62 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkradiogroup.c b/gtk/gtkradiogroup.c
index 2c19633..9831f32 100644
--- a/gtk/gtkradiogroup.c
+++ b/gtk/gtkradiogroup.c
@@ -26,6 +26,7 @@
#include "config.h"
#include "gtkradiogroupprivate.h"
+#include "gtkradioaction.h"
#include "gtkprivate.h"
#include "gtkmarshalers.h"
#include "gtkintl.h"
@@ -56,7 +57,8 @@ struct _GtkRadioGroupPrivate
enum {
PROP_0,
- PROP_ACTIVE_ITEM
+ PROP_ACTIVE_ITEM,
+ PROP_ACTIVE_VALUE
};
@@ -102,6 +104,14 @@ gtk_radio_group_class_init (GtkRadioGroupClass *class)
GTK_PARAM_READABLE));
class->active_changed = NULL;
+ g_object_class_install_property (gobject_class,
+ PROP_ACTIVE_VALUE,
+ g_param_spec_string ("active-value",
+ P_("Active value"),
+ P_("The value of the active item in the radio group"),
+ NULL,
+ GTK_PARAM_READWRITE));
+
/**
* GtkRadioGroup::active-changed:
* @radio_group: the radio group on which the signal is emitted
@@ -147,6 +157,9 @@ gtk_radio_group_set_property (GObject *object,
switch (prop_id)
{
+ case PROP_ACTIVE_VALUE:
+ gtk_radio_group_set_active_value (radio_group, g_value_get_string (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -168,6 +181,9 @@ gtk_radio_group_get_property (GObject *object,
case PROP_ACTIVE_ITEM:
g_value_set_object (value, radio_group->priv->active);
break;
+ case PROP_ACTIVE_VALUE:
+ g_value_set_string (value, gtk_radio_group_get_active_value (radio_group));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -302,5 +318,42 @@ void
_gtk_radio_group_emit_active_changed (GtkRadioGroup *radio_group)
{
g_object_notify (G_OBJECT (radio_group), "active-item");
+ g_object_notify (G_OBJECT (radio_group), "active-value");
g_signal_emit (radio_group, signals[ACTIVE_CHANGED], 0, radio_group->priv->active);
}
+
+void
+gtk_radio_group_set_active_value (GtkRadioGroup *radio_group,
+ const gchar *value)
+{
+ GSList *l;
+
+ for (l = radio_group->priv->items; l; l = l->next)
+ {
+ GObject *item = l->data;
+
+ if (GTK_IS_RADIO_ACTION (item))
+ {
+ const gchar *s;
+
+ s = gtk_radio_action_get_string_value (GTK_RADIO_ACTION (item));
+
+ if (strcmp (value, s) == 0)
+ {
+ _gtk_radio_group_set_active_item (radio_group, item);
+ _gtk_radio_group_emit_active_changed (radio_group);
+
+ break;
+ }
+ }
+ }
+}
+
+const gchar *
+gtk_radio_group_get_active_value (GtkRadioGroup *radio_group)
+{
+ if (GTK_IS_RADIO_ACTION (radio_group->priv->active))
+ return gtk_radio_action_get_string_value (GTK_RADIO_ACTION (radio_group->priv->active));
+ else
+ return NULL;
+}
diff --git a/gtk/gtkradiogroup.h b/gtk/gtkradiogroup.h
index dc3058f..115a5ee 100644
--- a/gtk/gtkradiogroup.h
+++ b/gtk/gtkradiogroup.h
@@ -70,11 +70,14 @@ struct _GtkRadioGroupClass
};
-GType gtk_radio_group_get_type (void) G_GNUC_CONST;
-
-GtkRadioGroup* gtk_radio_group_new (void);
-GSList * gtk_radio_group_get_items (GtkRadioGroup *radio_group);
-GObject * gtk_radio_group_get_active_item (GtkRadioGroup *radio_group);
+GType gtk_radio_group_get_type (void) G_GNUC_CONST;
+
+GtkRadioGroup* gtk_radio_group_new (void);
+GSList * gtk_radio_group_get_items (GtkRadioGroup *radio_group);
+GObject * gtk_radio_group_get_active_item (GtkRadioGroup *radio_group);
+void gtk_radio_group_set_active_value (GtkRadioGroup *radio_group,
+ const gchar *value);
+const gchar * gtk_radio_group_get_active_value (GtkRadioGroup *radio_group);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]