]> saetta.ns0.it Git - libgtkform/commitdiff
Added radio button widget.
authorAndrea Zagli <azagli@libero.it>
Sun, 21 Feb 2010 10:15:34 +0000 (11:15 +0100)
committerAndrea Zagli <azagli@libero.it>
Sun, 21 Feb 2010 10:15:34 +0000 (11:15 +0100)
13 files changed:
data/gtkform.dtd
docs/reference/libgtkform-decl-list.txt
docs/reference/libgtkform-decl.txt
docs/reference/libgtkform-undocumented.txt
docs/reference/libgtkform-unused.txt
docs/reference/libgtkform.types
src/Makefile.am
src/form.c
src/form.h
src/widgetradio.c [new file with mode: 0644]
src/widgetradio.h [new file with mode: 0644]
test/test.gui
test/test.xml

index f2de6e0f147da8fd42b2594612d4f1195af454a6..7d94ff50f9c4c73d380c2b47ddcef8b874211f09 100644 (file)
@@ -4,16 +4,18 @@
 
 <!ELEMENT table (#PCDATA)>
 
-<!ELEMENT widget (column-field?, field?)>
+<!ELEMENT widget (column-field?, return-value?, field?)>
 
 <!ATTLIST widget
-       type  (checkbox | combobox | entry | label | spin | textview)  #REQUIRED
+       type  (checkbox | combobox | entry | label | radio | spin | textview)  #REQUIRED
        name  CDATA  #REQUIRED
        label  CDATA  #IMPLIED
 >
 
 <!ELEMENT column-field (#PCDATA)>
 
+<!ELEMENT return-value (#PCDATA)>
+
 <!ELEMENT field (no-save?, obligatory?, default?, is-key?, type?, display-format?)>
 
 <!ATTLIST field
index 55687e3e244b57f0ec57ac9d4bfa78c8a8a7db5a..78b3d2f0be1bb56fad1ddf01c84c5a837db070d9 100644 (file)
@@ -250,6 +250,8 @@ gtk_form_remove_field
 gtk_form_add_fields
 gtk_form_get_form_field_from_name
 gtk_form_get_form_widget_from_name
+gtk_form_get_form_field_from_widget
+gtk_form_get_form_widget_from_widget
 gtk_form_get_widgets
 gtk_form_get_objects_by_name
 gtk_form_clear
@@ -298,6 +300,25 @@ gtk_form_widget_entry_set_value_stringify
 gtk_form_widget_entry_set_editable
 </SECTION>
 
+<SECTION>
+<FILE>widgetradio</FILE>
+TYPE_GTK_FORM_WIDGET_RADIO
+GTK_FORM_WIDGET_RADIO
+GTK_FORM_WIDGET_RADIO_CLASS
+IS_GTK_FORM_WIDGET_RADIO
+IS_GTK_FORM_WIDGET_RADIO_CLASS
+GTK_FORM_WIDGET_RADIO_GET_CLASS
+<TITLE>GtkFormWidgetRadio</TITLE>
+GtkFormWidgetRadio
+gtk_form_widget_radio_get_type
+gtk_form_widget_radio_new
+gtk_form_widget_radio_get_value_stringify
+gtk_form_widget_radio_set_value_stringify
+gtk_form_widget_radio_set_editable
+gtk_form_widget_radio_set_return_value
+gtk_form_widget_radio_get_return_value
+</SECTION>
+
 <SECTION>
 <FILE>fieldinteger</FILE>
 TYPE_GTK_FORM_FIELD_INTEGER
index 24aeb33594dddb8c1f03848a263946b726e69442..3705d6ca93b5ad70607bbaeb2b1bdf3fa376ec49 100644 (file)
@@ -1093,6 +1093,16 @@ GtkForm *form, const gchar *field_name
 GtkForm *form, const gchar *widget_name 
 </FUNCTION>
 <FUNCTION>
+<NAME>gtk_form_get_form_field_from_widget</NAME>
+<RETURNS>GtkFormField *</RETURNS>
+GtkForm *form, GtkWidget *widget 
+</FUNCTION>
+<FUNCTION>
+<NAME>gtk_form_get_form_widget_from_widget</NAME>
+<RETURNS>GtkFormWidget *</RETURNS>
+GtkForm *form, GtkWidget *widget 
+</FUNCTION>
+<FUNCTION>
 <NAME>gtk_form_get_widgets</NAME>
 <RETURNS>GtkWidget **</RETURNS>
 GtkForm *form 
@@ -1296,6 +1306,85 @@ GtkFormWidget *fwidget, const gchar *value
 GtkFormWidget *fwidget, gboolean editable 
 </FUNCTION>
 <MACRO>
+<NAME>TYPE_GTK_FORM_WIDGET_RADIO</NAME>
+#define TYPE_GTK_FORM_WIDGET_RADIO                 (gtk_form_widget_radio_get_type ())
+</MACRO>
+<MACRO>
+<NAME>GTK_FORM_WIDGET_RADIO</NAME>
+#define GTK_FORM_WIDGET_RADIO(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_GTK_FORM_WIDGET_RADIO, GtkFormWidgetRadio))
+</MACRO>
+<MACRO>
+<NAME>GTK_FORM_WIDGET_RADIO_CLASS</NAME>
+#define GTK_FORM_WIDGET_RADIO_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_GTK_FORM_WIDGET_RADIO, GtkFormWidgetRadioClass))
+</MACRO>
+<MACRO>
+<NAME>IS_GTK_FORM_WIDGET_RADIO</NAME>
+#define IS_GTK_FORM_WIDGET_RADIO(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_GTK_FORM_WIDGET_RADIO))
+</MACRO>
+<MACRO>
+<NAME>IS_GTK_FORM_WIDGET_RADIO_CLASS</NAME>
+#define IS_GTK_FORM_WIDGET_RADIO_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_GTK_FORM_WIDGET_RADIO))
+</MACRO>
+<MACRO>
+<NAME>GTK_FORM_WIDGET_RADIO_GET_CLASS</NAME>
+#define GTK_FORM_WIDGET_RADIO_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_GTK_FORM_WIDGET_RADIO, GtkFormWidgetRadioClass))
+</MACRO>
+<STRUCT>
+<NAME>GtkFormWidgetRadio</NAME>
+</STRUCT>
+<STRUCT>
+<NAME>GtkFormWidgetRadioClass</NAME>
+</STRUCT>
+<STRUCT>
+<NAME>GtkFormWidgetRadio</NAME>
+struct _GtkFormWidgetRadio
+       {
+               GtkFormWidget parent;
+       };
+</STRUCT>
+<STRUCT>
+<NAME>GtkFormWidgetRadioClass</NAME>
+struct _GtkFormWidgetRadioClass
+       {
+               GtkFormWidgetClass parent_class;
+       };
+</STRUCT>
+<FUNCTION>
+<NAME>gtk_form_widget_radio_get_type</NAME>
+<RETURNS>GType </RETURNS>
+void 
+</FUNCTION>
+<FUNCTION>
+<NAME>gtk_form_widget_radio_new</NAME>
+<RETURNS>GtkFormWidget *</RETURNS>
+void 
+</FUNCTION>
+<FUNCTION>
+<NAME>gtk_form_widget_radio_get_value_stringify</NAME>
+<RETURNS>gchar *</RETURNS>
+GtkFormWidget *widget 
+</FUNCTION>
+<FUNCTION>
+<NAME>gtk_form_widget_radio_set_value_stringify</NAME>
+<RETURNS>gboolean </RETURNS>
+GtkFormWidget *fwidget, const gchar *value 
+</FUNCTION>
+<FUNCTION>
+<NAME>gtk_form_widget_radio_set_editable</NAME>
+<RETURNS>void </RETURNS>
+GtkFormWidget *fwidget, gboolean editable 
+</FUNCTION>
+<FUNCTION>
+<NAME>gtk_form_widget_radio_set_return_value</NAME>
+<RETURNS>void </RETURNS>
+GtkFormWidgetRadio *fwidget, const gchar *value 
+</FUNCTION>
+<FUNCTION>
+<NAME>gtk_form_widget_radio_get_return_value</NAME>
+<RETURNS>gchar *</RETURNS>
+GtkFormWidgetRadio *fwidget 
+</FUNCTION>
+<MACRO>
 <NAME>TYPE_GTK_FORM_FIELD_INTEGER</NAME>
 #define TYPE_GTK_FORM_FIELD_INTEGER                 (gtk_form_field_integer_get_type ())
 </MACRO>
index 6141135c4595e187ffcfbe855eb387187e04e994..5872155a07438443dff485474335ea317fd577b8 100644 (file)
@@ -1,7 +1,7 @@
 7% symbol docs coverage.
 22 symbols documented.
 1 symbols incomplete.
-277 not documented.
+285 not documented.
 
 
 GTK_FORM
@@ -187,7 +187,9 @@ gtk_form_filed_boolean_is_changed
 gtk_form_fill_from_datamodel
 gtk_form_get_field_from_name
 gtk_form_get_form_field_from_name
+gtk_form_get_form_field_from_widget
 gtk_form_get_form_widget_from_name
+gtk_form_get_form_widget_from_widget
 gtk_form_get_gtkbuilder
 gtk_form_get_key
 gtk_form_get_objects
@@ -239,6 +241,12 @@ gtk_form_widget_label_get_value_stringify
 gtk_form_widget_label_new
 gtk_form_widget_label_set_value_stringify
 gtk_form_widget_new
+gtk_form_widget_radio_get_return_value
+gtk_form_widget_radio_get_value_stringify
+gtk_form_widget_radio_new
+gtk_form_widget_radio_set_editable
+gtk_form_widget_radio_set_return_value
+gtk_form_widget_radio_set_value_stringify
 gtk_form_widget_set_editable
 gtk_form_widget_set_from_gtkbuilder
 gtk_form_widget_set_label
index d4a9e2d2620c7a8e3981ee72de5305339be821ab..22253c2d83b84a5fb1a1edbd9c75086fd3d66cb2 100644 (file)
@@ -1,3 +1,6 @@
+GTK_FORM_WIDGET_RADIO
+GTK_FORM_WIDGET_RADIO_CLASS
+GTK_FORM_WIDGET_RADIO_GET_CLASS
 GtkFormClass
 GtkFormFieldBooleanClass
 GtkFormFieldClass
@@ -11,8 +14,13 @@ GtkFormWidgetClass
 GtkFormWidgetComboBoxClass
 GtkFormWidgetEntryClass
 GtkFormWidgetLabelClass
+GtkFormWidgetRadio
+GtkFormWidgetRadioClass
 GtkFormWidgetSpinClass
 GtkFormWidgetTextviewClass
+IS_GTK_FORM_WIDGET_RADIO
+IS_GTK_FORM_WIDGET_RADIO_CLASS
+TYPE_GTK_FORM_WIDGET_RADIO
 gtk_form_field_boolean_set_as_origin
 gtk_form_field_boolean_str_to_boolean
 gtk_form_field_datetime_get_gdate_from_tm
@@ -33,7 +41,9 @@ gtk_form_field_text_is_changed
 gtk_form_field_text_set_as_origin
 gtk_form_filed_boolean_is_changed
 gtk_form_get_form_field_from_name
+gtk_form_get_form_field_from_widget
 gtk_form_get_form_widget_from_name
+gtk_form_get_form_widget_from_widget
 gtk_form_get_gtkbuilder
 gtk_form_get_key
 gtk_form_get_objects_by_name
@@ -47,4 +57,11 @@ gtk_form_set_key
 gtk_form_set_sensitive_by_name
 gtk_form_set_table
 gtk_form_widget_get_label
+gtk_form_widget_radio_get_return_value
+gtk_form_widget_radio_get_type
+gtk_form_widget_radio_get_value_stringify
+gtk_form_widget_radio_new
+gtk_form_widget_radio_set_editable
+gtk_form_widget_radio_set_return_value
+gtk_form_widget_radio_set_value_stringify
 gtk_form_widget_set_label
index a45c49bfb81a334d4d1f6922d6209b126e3c66fa..9d91c418f589277c532ed0e56135e4f728fe4110 100644 (file)
@@ -1,15 +1,17 @@
-gtk_form_widget_spin_get_type
-gtk_form_widget_check_get_type
+gtk_form_get_type
+gtk_form_field_get_type
 gtk_form_field_boolean_get_type
-gtk_form_widget_get_type
-gtk_form_field_text_get_type
 gtk_form_field_datetime_get_type
-gtk_form_widget_label_get_type
 gtk_form_field_float_get_type
+gtk_form_field_integer_get_type
+gtk_form_field_text_get_type
 gtk_form_key_get_type
+gtk_form_widget_get_type
+gtk_form_widget_check_get_type
+gtk_form_widget_entry_get_type
+gtk_form_widget_label_get_type
+gtk_form_widget_radio_get_type
+gtk_form_widget_spin_get_type
 gtk_form_widget_textview_get_type
-gtk_form_field_get_type
-gtk_form_get_type
 gtk_form_widget_combo_box_get_type
-gtk_form_widget_entry_get_type
-gtk_form_field_integer_get_type
+
index d60344aef17615057ed39e1f069f8486b54b5c2c..6b39fa35655714465dd3dd07f35f7f26c8ab0a90 100644 (file)
@@ -18,6 +18,7 @@ libgtkform_la_SOURCES = form.c \
                      widgetcombobox.c \
                      widgetentry.c \
                      widgetlabel.c \
+                     widgetradio.c \
                      widgetspin.c \
                      widgettextview.c
 
@@ -36,6 +37,7 @@ libgtkform_include_HEADERS = form.h \
                   widgetcombobox.h \
                   widgetentry.h \
                   widgetlabel.h \
+                  widgetradio.h \
                   widgetspin.h \
                   widgettextview.h
 
index f698a11e400fe8364515feba3cf2b492b511067a..a1f5151ba7375686e6a5a6eb7c060087d5febdd9 100644 (file)
@@ -40,6 +40,7 @@
 #include "widgetcombobox.h"
 #include "widgetentry.h"
 #include "widgetlabel.h"
+#include "widgetradio.h"
 #include "widgetspin.h"
 #include "widgettextview.h"
 
@@ -246,6 +247,10 @@ GtkForm
                                                                                {
                                                                                        widget = gtk_form_widget_label_new ();
                                                                                }
+                                                                       else if (g_strcmp0 (type, "radio") == 0)
+                                                                               {
+                                                                                       widget = gtk_form_widget_radio_new ();
+                                                                               }
                                                                        else if (g_strcmp0 (type, "spin") == 0)
                                                                                {
                                                                                        widget = gtk_form_widget_spin_new ();
@@ -254,6 +259,10 @@ GtkForm
                                                                                {
                                                                                        widget = gtk_form_widget_textview_new ();
                                                                                }
+                                                                       else
+                                                                               {
+                                                                                       g_warning (_("Unknown type «%s»."), type);
+                                                                               }
 
                                                                        if (widget != NULL)
                                                                                {
@@ -272,7 +281,8 @@ GtkForm
                                                                                                                                {
                                                                                                                                        gtk_form_widget_set_label (widget, wlabel);
                                                                                                                                }
-                                                                                                                       else if (g_strcmp0 (type, "checkbox") == 0
+                                                                                                                       else if ((g_strcmp0 (type, "checkbox") == 0
+                                                                                                                                 || g_strcmp0 (type, "radio") == 0)
                                                                                                                                 && g_strcmp0 (label, name) == 0)
                                                                                                                                {
                                                                                                                                        gtk_form_widget_set_label (widget, wlabel);
@@ -293,6 +303,12 @@ GtkForm
                                                                                                                        g_object_set (G_OBJECT (widget), "column-field",
                                                                                                                                              strtol ((gchar *)xmlNodeGetContent (node_widget), NULL, 10), NULL);
                                                                                                                }
+                                                                                                       else if (xmlStrcmp (node_widget->name, (const xmlChar *)"return-value") == 0
+                                                                                                                        && IS_GTK_FORM_WIDGET_RADIO (widget))
+                                                                                                               {
+                                                                                                                       g_object_set (G_OBJECT (widget), "return-value",
+                                                                                                                                             xmlNodeGetContent (node_widget), NULL);
+                                                                                                               }
                                                                                                        else if (xmlStrcmp (node_widget->name, (const xmlChar *)"field") == 0)
                                                                                                                {
                                                                                                                        field = NULL;
@@ -669,6 +685,7 @@ GtkFormField
        GtkFormPrivate *priv;
 
        g_return_val_if_fail (IS_GTK_FORM (form), NULL);
+       g_return_val_if_fail (field_name != NULL, NULL);
 
        priv = GTK_FORM_GET_PRIVATE (form);
 
@@ -725,6 +742,77 @@ GtkFormWidget
        return widget_ret;
 }
 
+/**
+ * gtk_form_get_form_field_from_widget:
+ * @form: a #GtkForm object.
+ * @widget: a #GtkWidget object.
+ *
+ */
+GtkFormField
+*gtk_form_get_form_field_from_widget (GtkForm *form, GtkWidget *widget)
+{
+       GtkFormWidget *fwidget = NULL;
+       GtkFormField *field = NULL;
+       GtkFormWidget *widget_ret = NULL;
+       GtkFormPrivate *priv;
+
+       g_return_val_if_fail (IS_GTK_FORM (form), NULL);
+       g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
+
+       priv = GTK_FORM_GET_PRIVATE (form);
+
+       GSList *fields = priv->fields;
+       while (fields != NULL)
+               {
+                       fwidget = gtk_form_field_get_form_widget ((GtkFormField *)fields->data);
+
+                       if (gtk_form_widget_get_widget (fwidget) == widget)
+                               {
+                                       field = (GtkFormField *)fields->data;
+                                       break;
+                               }
+
+                       fields = g_slist_next (fields);
+               }
+
+       return field;
+}
+
+/**
+ * gtk_form_get_form_widget_from_widget:
+ * @form: a #GtkForm object.
+ * @widget: a #GtkWidget object.
+ *
+ */
+GtkFormWidget
+*gtk_form_get_form_widget_from_widget (GtkForm *form, GtkWidget *widget)
+{
+       GtkFormWidget *fwidget = NULL;
+       GtkFormWidget *widget_ret = NULL;
+       GtkFormPrivate *priv;
+
+       g_return_val_if_fail (IS_GTK_FORM (form), NULL);
+       g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
+
+       priv = GTK_FORM_GET_PRIVATE (form);
+
+       GSList *fields = priv->fields;
+       while (fields != NULL)
+               {
+                       fwidget = gtk_form_field_get_form_widget ((GtkFormField *)fields->data);
+
+                       if (gtk_form_widget_get_widget (fwidget) == widget)
+                               {
+                                       widget_ret = fwidget;
+                                       break;
+                               }
+
+                       fields = g_slist_next (fields);
+               }
+
+       return widget_ret;
+}
+
 /**
  * gtk_form_get_objects:
  * @form: a #GtkForm object.
index 210149747be5206c1b277d94b4ba6c99cd4c3cdb..6a3c3055eb019ece33584c063b105e5c5676495e 100644 (file)
@@ -74,6 +74,9 @@ gboolean gtk_form_add_fields (GtkForm *form, ...);
 GtkFormField *gtk_form_get_form_field_from_name (GtkForm *form, const gchar *field_name);
 GtkFormWidget *gtk_form_get_form_widget_from_name (GtkForm *form, const gchar *widget_name);
 
+GtkFormField *gtk_form_get_form_field_from_widget (GtkForm *form, GtkWidget *widget);
+GtkFormWidget *gtk_form_get_form_widget_from_widget (GtkForm *form, GtkWidget *widget);
+
 GtkWidget **gtk_form_get_widgets (GtkForm *form);
 GObject **gtk_form_get_objects_by_name (GtkForm *form, ...);
 
diff --git a/src/widgetradio.c b/src/widgetradio.c
new file mode 100644 (file)
index 0000000..6fd4352
--- /dev/null
@@ -0,0 +1,308 @@
+/*
+ * Copyright (C) 2005-2010 Andrea Zagli <azagli@libero.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include <string.h>
+
+#include <gtk/gtk.h>
+
+#include "widgetradio.h"
+
+enum
+{
+       PROP_0,
+       PROP_RETURN_VALUE
+};
+
+static void gtk_form_widget_radio_class_init (GtkFormWidgetRadioClass *klass);
+static void gtk_form_widget_radio_init (GtkFormWidgetRadio *gtk_form_widget_radio);
+
+static void gtk_form_widget_radio_set_property (GObject *object,
+                                            guint property_id,
+                                            const GValue *value,
+                                            GParamSpec *pspec);
+static void gtk_form_widget_radio_get_property (GObject *object,
+                                            guint property_id,
+                                            GValue *value,
+                                            GParamSpec *pspec);
+
+static gboolean check_value (const gchar *value);
+
+#define GTK_FORM_WIDGET_RADIO_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_GTK_FORM_WIDGET_RADIO, GtkFormWidgetRadioPrivate))
+
+typedef struct _GtkFormWidgetRadioPrivate GtkFormWidgetRadioPrivate;
+struct _GtkFormWidgetRadioPrivate
+       {
+               gchar *value;
+       };
+
+
+G_DEFINE_TYPE (GtkFormWidgetRadio, gtk_form_widget_radio, TYPE_GTK_FORM_WIDGET)
+
+static void
+gtk_form_widget_radio_class_init (GtkFormWidgetRadioClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       GtkFormWidgetClass *widget_class = GTK_FORM_WIDGET_CLASS (klass);
+
+       object_class->set_property = gtk_form_widget_radio_set_property;
+       object_class->get_property = gtk_form_widget_radio_get_property;
+
+       widget_class->get_value_stringify = gtk_form_widget_radio_get_value_stringify;
+       widget_class->set_value_stringify = gtk_form_widget_radio_set_value_stringify;
+       widget_class->set_editable = gtk_form_widget_radio_set_editable;
+
+       g_object_class_install_property (object_class, PROP_RETURN_VALUE,
+                                        g_param_spec_string ("return-value",
+                                                          "Return value",
+                                                          "Return value",
+                                                          "",
+                                                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+       g_type_class_add_private (object_class, sizeof (GtkFormWidgetRadioPrivate));
+}
+
+static void
+gtk_form_widget_radio_init (GtkFormWidgetRadio *gtk_form_widget_radio)
+{
+}
+
+/**
+ * gtk_form_widget_radio_new:
+ *
+ * Returns: the newly created #GtkFormWidgetRadio.
+ */
+GtkFormWidget
+*gtk_form_widget_radio_new ()
+{
+       return g_object_new (TYPE_GTK_FORM_WIDGET_RADIO, NULL);
+}
+
+/**
+ * gtk_form_widget_radio_get_value_stringify:
+ * @widget:
+ *
+ */
+gchar
+*gtk_form_widget_radio_get_value_stringify (GtkFormWidget *fwidget)
+{
+       GSList *group;
+       GtkWidget *w;
+       gchar *ret;
+       GtkFormWidgetRadioPrivate *priv;
+
+       g_return_val_if_fail (IS_GTK_FORM_WIDGET_RADIO (fwidget), "");
+
+       priv = GTK_FORM_WIDGET_RADIO_GET_PRIVATE (fwidget);
+
+       w = gtk_form_widget_get_widget (fwidget);
+
+       ret = g_strdup ("");
+
+       /* always returns the value of the group's active radio button */
+       group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (w));
+       while (group != NULL)
+               {
+                       if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (group->data)))
+                               {
+                                       ret = g_strdup ((const gchar*)g_object_get_data (G_OBJECT (group->data), "return-value"));
+                                       if (ret == NULL)
+                                               {
+                                                       ret = g_strdup ("");
+                                               }
+                                       break;
+                               }
+
+                       group = g_slist_next (group);
+               }
+
+       return ret;
+}
+
+/**
+ * gtk_form_widget_radio_set_value_stringify:
+ * @fwidget:
+ * @value:
+ *
+ */
+gboolean
+gtk_form_widget_radio_set_value_stringify (GtkFormWidget *fwidget, const gchar *value)
+{
+       gboolean ret = FALSE;
+       GtkWidget *w;
+       gboolean active;
+
+       g_return_val_if_fail (IS_GTK_FORM_WIDGET_RADIO (fwidget), FALSE);
+
+       active = FALSE;
+
+       g_object_get (G_OBJECT (fwidget),
+                     "widget", &w,
+                     NULL);
+
+       active = check_value (value);
+
+       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), active);
+
+       ret = TRUE;
+
+       return ret;
+}
+
+/**
+ * gtk_form_widget_radio_set_editable:
+ * @fwidget: a #GtkFormWidget object.
+ * @editable:
+ *
+ */
+void
+gtk_form_widget_radio_set_editable (GtkFormWidget *fwidget, gboolean editable)
+{
+       GtkWidget *w;
+
+       g_return_if_fail (IS_GTK_FORM_WIDGET_RADIO (fwidget));
+
+       g_object_get (G_OBJECT (fwidget),
+                     "widget", &w,
+                     NULL);
+
+       gtk_widget_set_sensitive (w, editable);
+}
+
+/**
+ * gtk_form_widget_radio_set_return_value:
+ * @fwidget: a #GtkFormWidgetRadio object.
+ * @value:
+ *
+ */
+void
+gtk_form_widget_radio_set_return_value (GtkFormWidgetRadio *fwidget, const gchar *value)
+{
+       GtkFormWidgetRadioPrivate *priv;
+       GtkWidget *widget;
+
+       g_return_if_fail (IS_GTK_FORM_WIDGET_RADIO (fwidget));
+
+       priv = GTK_FORM_WIDGET_RADIO_GET_PRIVATE (fwidget);
+
+       if (value == NULL)
+               {
+                       priv->value = g_strdup ("");
+               }
+       else
+               {
+                       priv->value = g_strdup (value);
+               }
+
+       widget = gtk_form_widget_get_widget (GTK_FORM_WIDGET (fwidget));
+       if (GTK_IS_WIDGET (widget))
+               {
+                       g_object_set_data (G_OBJECT (widget), "return-value", (gpointer)priv->value);
+               }
+}
+
+/**
+ * gtk_form_widget_radio_get_return_value:
+ * @fwidget: a #GtkFormWidgetRadio object.
+ *
+ */
+gchar
+*gtk_form_widget_radio_get_return_value (GtkFormWidgetRadio *fwidget)
+{
+       GtkFormWidgetRadioPrivate *priv;
+
+       g_return_val_if_fail (IS_GTK_FORM_WIDGET_RADIO (fwidget), NULL);
+
+       priv = GTK_FORM_WIDGET_RADIO_GET_PRIVATE (fwidget);
+
+       return g_strdup (priv->value);
+}
+
+/* PRIVATE */
+static void
+gtk_form_widget_radio_set_property (GObject *object,
+                                guint property_id,
+                                const GValue *value,
+                                GParamSpec *pspec)
+{
+       GtkFormWidgetRadio *widget_radio = (GtkFormWidgetRadio *)object;
+
+       GtkFormWidgetRadioPrivate *priv = GTK_FORM_WIDGET_RADIO_GET_PRIVATE (widget_radio);
+
+       switch (property_id)
+               {
+                       case PROP_RETURN_VALUE:
+                               gtk_form_widget_radio_set_return_value (widget_radio, g_value_get_string (value));
+                               break;
+
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                               break;
+         }
+}
+
+static void
+gtk_form_widget_radio_get_property (GObject *object,
+                                guint property_id,
+                                GValue *value,
+                                GParamSpec *pspec)
+{
+       GtkFormWidgetRadio *widget_radio = (GtkFormWidgetRadio *)object;
+
+       GtkFormWidgetRadioPrivate *priv = GTK_FORM_WIDGET_RADIO_GET_PRIVATE (widget_radio);
+
+       switch (property_id)
+               {
+                       case PROP_RETURN_VALUE:
+                               g_value_set_string (value, gtk_form_widget_radio_get_return_value (widget_radio));
+                               break;
+
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                               break;
+         }
+}
+
+static gboolean
+check_value (const gchar *value)
+{
+       gchar *str_value;
+       gboolean active;
+
+       active = FALSE;
+
+       str_value = g_strstrip (g_strdup (value));
+
+       if (strcmp (str_value, "0") == 0
+           || strcasecmp (str_value, "f") == 0
+           || strcasecmp (str_value, "false") == 0
+           || strcasecmp (str_value, "n") == 0
+           || strcasecmp (str_value, "no") == 0)
+               {
+                       active = FALSE;
+               }
+       else if (strcmp (str_value, "1") == 0
+           || strcasecmp (str_value, "t") == 0
+           || strcasecmp (str_value, "true") == 0
+           || strcasecmp (str_value, "y") == 0
+           || strcasecmp (str_value, "yes") == 0)
+               {
+                       active = TRUE;
+               }
+
+       return active;
+}
diff --git a/src/widgetradio.h b/src/widgetradio.h
new file mode 100644 (file)
index 0000000..19d0fba
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2005-2010 Andrea Zagli <azagli@libero.it>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef __LIBGTK_FORM_WIDGET_RADIO_H__
+#define __LIBGTK_FORM_WIDGET_RADIO_H__
+
+#include "widget.h"
+
+
+G_BEGIN_DECLS
+
+
+#define TYPE_GTK_FORM_WIDGET_RADIO                 (gtk_form_widget_radio_get_type ())
+#define GTK_FORM_WIDGET_RADIO(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_GTK_FORM_WIDGET_RADIO, GtkFormWidgetRadio))
+#define GTK_FORM_WIDGET_RADIO_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_GTK_FORM_WIDGET_RADIO, GtkFormWidgetRadioClass))
+#define IS_GTK_FORM_WIDGET_RADIO(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_GTK_FORM_WIDGET_RADIO))
+#define IS_GTK_FORM_WIDGET_RADIO_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_GTK_FORM_WIDGET_RADIO))
+#define GTK_FORM_WIDGET_RADIO_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_GTK_FORM_WIDGET_RADIO, GtkFormWidgetRadioClass))
+
+
+typedef struct _GtkFormWidgetRadio GtkFormWidgetRadio;
+typedef struct _GtkFormWidgetRadioClass GtkFormWidgetRadioClass;
+
+struct _GtkFormWidgetRadio
+       {
+               GtkFormWidget parent;
+       };
+
+struct _GtkFormWidgetRadioClass
+       {
+               GtkFormWidgetClass parent_class;
+       };
+
+GType gtk_form_widget_radio_get_type (void) G_GNUC_CONST;
+
+GtkFormWidget *gtk_form_widget_radio_new (void);
+
+gchar *gtk_form_widget_radio_get_value_stringify (GtkFormWidget *widget);
+
+gboolean gtk_form_widget_radio_set_value_stringify (GtkFormWidget *fwidget, const gchar *value);
+
+void gtk_form_widget_radio_set_editable (GtkFormWidget *fwidget, gboolean editable);
+
+void gtk_form_widget_radio_set_return_value (GtkFormWidgetRadio *fwidget, const gchar *value);
+gchar *gtk_form_widget_radio_get_return_value (GtkFormWidgetRadio *fwidget);
+
+
+G_END_DECLS
+
+
+#endif /* __LIBGTK_FORM_WIDGET_RADIO_H__ */
index 7b33d2193ae48bb0508984ff13d750dc91185bcc..f56655880784dccf4b50b9aa4c8bd357702d4627 100644 (file)
@@ -12,6 +12,7 @@
       <object class="GtkVBox" id="vbox1">
         <property name="visible">True</property>
         <property name="border_width">3</property>
+        <property name="orientation">vertical</property>
         <child>
           <object class="GtkTable" id="table1">
             <property name="visible">True</property>
               <object class="GtkScrolledWindow" id="scrolledwindow2">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
+                <property name="shadow_type">etched-in</property>
                 <child>
                   <object class="GtkTextView" id="txtvDescription">
                     <property name="visible">True</property>
               </packing>
             </child>
             <child>
-              <placeholder/>
+              <object class="GtkLabel" id="label3">
+                <property name="visible">True</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">Radio (sex)</property>
+              </object>
+              <packing>
+                <property name="top_attach">9</property>
+                <property name="bottom_attach">10</property>
+              </packing>
             </child>
             <child>
-              <placeholder/>
+              <object class="GtkHBox" id="hbox2">
+                <property name="visible">True</property>
+                <child>
+                  <object class="GtkRadioButton" id="rbtnNone">
+                    <property name="label" translatable="yes">None</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="active">True</property>
+                    <property name="draw_indicator">True</property>
+                  </object>
+                  <packing>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkRadioButton" id="rbtnMale">
+                    <property name="label" translatable="yes">Male</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="active">True</property>
+                    <property name="draw_indicator">True</property>
+                    <property name="group">rbtnNone</property>
+                  </object>
+                  <packing>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkRadioButton" id="rbtnFemale">
+                    <property name="label" translatable="yes">Female</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="active">True</property>
+                    <property name="draw_indicator">True</property>
+                    <property name="group">rbtnNone</property>
+                  </object>
+                  <packing>
+                    <property name="position">2</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="right_attach">2</property>
+                <property name="top_attach">9</property>
+                <property name="bottom_attach">10</property>
+              </packing>
             </child>
           </object>
           <packing>
               <object class="GtkScrolledWindow" id="scrolledwindow1">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
-                <property name="shadow_type">in</property>
+                <property name="shadow_type">etched-in</property>
                 <child>
                   <object class="GtkTextView" id="txtvSql">
                     <property name="visible">True</property>
index 40c1dcab3f67f9c2aa07721f16a7130008ac5479..1325c1a0fae7978f760e82dbf5fbbd07518bca95 100644 (file)
@@ -63,4 +63,22 @@ and  t       a       b</default>
                </field>
        </widget>
 
+       <widget type="radio" name="rbtnNone">
+               <return-value />
+               <field type="text" name="sex">
+               </field>
+       </widget>
+
+       <widget type="radio" name="rbtnMale">
+               <return-value>M</return-value>
+               <field type="text" name="sex">
+               </field>
+       </widget>
+
+       <widget type="radio" name="rbtnFemale">
+               <return-value>F</return-value>
+               <field type="text" name="sex">
+               </field>
+       </widget>
+
 </gtkform>