]> saetta.ns0.it Git - libgtkform/commitdiff
Added and managed class GtkFormGroup.
authorAndrea Zagli <azagli@libero.it>
Sun, 25 Jul 2010 14:56:49 +0000 (16:56 +0200)
committerAndrea Zagli <azagli@libero.it>
Sun, 25 Jul 2010 14:56:49 +0000 (16:56 +0200)
Added property "field" to GtkFormWidget.
Added functions GtkForm::add_group and GtkForm::get_group_by_name.
Bugfixes.

14 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.args
docs/reference/tmpl/widget.sgml
src/Makefile.am
src/field.c
src/form.c
src/form.h
src/group.c [new file with mode: 0644]
src/group.h [new file with mode: 0644]
src/widget.c

index c0e1c82288bcb33203da97f363b0218c15ec2a7a..3fe147f4862c777cb01eed7d1857b4e6422f1590 100644 (file)
@@ -1,4 +1,4 @@
-<!ELEMENT gtkform (gtkbuilder-file?, table?, widget+)>
+<!ELEMENT gtkform (gtkbuilder-file?, table?, widget+, group*)>
 
 <!ELEMENT gtkbuilder-file (#PCDATA)>
 
@@ -46,3 +46,9 @@
 <!ELEMENT auto-increment (#PCDATA)>
 <!ELEMENT datetime-type (date | time | datetime)>
 <!ELEMENT display-format (#PCDATA)>
+
+<!ELEMENT group (widget*, field*)>
+
+<!ATTLIST group
+       name  CDATA  #REQUIRED
+>
index a307ffdcff8ec280cc33f37c38d170f69002a6da..8f94da569509cb2b7b368baf7f9184bf8bef6332 100644 (file)
@@ -34,6 +34,27 @@ gtk_form_widget_check_set_value_stringify
 gtk_form_widget_check_set_editable
 </SECTION>
 
+<SECTION>
+<FILE>group</FILE>
+<TITLE>GtkFormGroup</TITLE>
+TYPE_GTK_FORM_GROUP
+GTK_FORM_GROUP
+GTK_FORM_GROUP_CLASS
+IS_GTK_FORM_GROUP
+IS_GTK_FORM_GROUP_CLASS
+GTK_FORM_GROUP_GET_CLASS
+GtkFormGroup
+GtkFormGroupClass
+gtk_form_group_get_type
+gtk_form_group_new
+gtk_form_group_get_name
+gtk_form_group_add_widget
+gtk_form_group_add_field
+gtk_form_group_clear
+gtk_form_group_set_from_datamodel
+gtk_form_group_set_from_hashtable
+</SECTION>
+
 <SECTION>
 <FILE>fieldboolean</FILE>
 <TITLE>GtkFormFieldBoolean</TITLE>
@@ -295,6 +316,8 @@ gtk_form_fill_from_datamodel
 gtk_form_fill_from_table
 gtk_form_get_values_as_hashtable
 gtk_form_fill_from_hashtable
+gtk_form_add_group
+gtk_form_get_group_by_name
 </SECTION>
 
 <SECTION>
index 7751923e1442a96644b500f27c87591c389bce0d..91ca611c33c603164e7fbf906f0884629484b416 100644 (file)
@@ -137,6 +137,90 @@ GtkFormWidget *fwidget, const gchar *value
 GtkFormWidget *fwidget, gboolean editable 
 </FUNCTION>
 <MACRO>
+<NAME>TYPE_GTK_FORM_GROUP</NAME>
+#define TYPE_GTK_FORM_GROUP                 (gtk_form_group_get_type ())
+</MACRO>
+<MACRO>
+<NAME>GTK_FORM_GROUP</NAME>
+#define GTK_FORM_GROUP(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_GTK_FORM_GROUP, GtkFormGroup))
+</MACRO>
+<MACRO>
+<NAME>GTK_FORM_GROUP_CLASS</NAME>
+#define GTK_FORM_GROUP_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_GTK_FORM_GROUP, GtkFormGroupClass))
+</MACRO>
+<MACRO>
+<NAME>IS_GTK_FORM_GROUP</NAME>
+#define IS_GTK_FORM_GROUP(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_GTK_FORM_GROUP))
+</MACRO>
+<MACRO>
+<NAME>IS_GTK_FORM_GROUP_CLASS</NAME>
+#define IS_GTK_FORM_GROUP_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_GTK_FORM_GROUP))
+</MACRO>
+<MACRO>
+<NAME>GTK_FORM_GROUP_GET_CLASS</NAME>
+#define GTK_FORM_GROUP_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_GTK_FORM_GROUP, GtkFormGroupClass))
+</MACRO>
+<STRUCT>
+<NAME>GtkFormGroup</NAME>
+</STRUCT>
+<STRUCT>
+<NAME>GtkFormGroupClass</NAME>
+</STRUCT>
+<STRUCT>
+<NAME>GtkFormGroup</NAME>
+struct _GtkFormGroup
+       {
+               GObject parent;
+       };
+</STRUCT>
+<STRUCT>
+<NAME>GtkFormGroupClass</NAME>
+struct _GtkFormGroupClass
+       {
+               GObjectClass parent_class;
+       };
+</STRUCT>
+<FUNCTION>
+<NAME>gtk_form_group_get_type</NAME>
+<RETURNS>GType </RETURNS>
+void 
+</FUNCTION>
+<FUNCTION>
+<NAME>gtk_form_group_new</NAME>
+<RETURNS>GtkFormGroup *</RETURNS>
+const gchar *name 
+</FUNCTION>
+<FUNCTION>
+<NAME>gtk_form_group_get_name</NAME>
+<RETURNS>gchar *</RETURNS>
+GtkFormGroup *group 
+</FUNCTION>
+<FUNCTION>
+<NAME>gtk_form_group_add_widget</NAME>
+<RETURNS>gboolean </RETURNS>
+GtkFormGroup *group, GtkFormWidget *fwidget 
+</FUNCTION>
+<FUNCTION>
+<NAME>gtk_form_group_add_field</NAME>
+<RETURNS>gboolean </RETURNS>
+GtkFormGroup *group, GtkFormField *field 
+</FUNCTION>
+<FUNCTION>
+<NAME>gtk_form_group_clear</NAME>
+<RETURNS>gboolean </RETURNS>
+GtkFormGroup *group 
+</FUNCTION>
+<FUNCTION>
+<NAME>gtk_form_group_set_from_datamodel</NAME>
+<RETURNS>gboolean </RETURNS>
+GtkFormGroup *group, GdaDataModel *dm, gint row 
+</FUNCTION>
+<FUNCTION>
+<NAME>gtk_form_group_set_from_hashtable</NAME>
+<RETURNS>gboolean </RETURNS>
+GtkFormGroup *group, GHashTable *hashtable 
+</FUNCTION>
+<MACRO>
 <NAME>TYPE_GTK_FORM_FIELD_BOOLEAN</NAME>
 #define TYPE_GTK_FORM_FIELD_BOOLEAN                 (gtk_form_field_boolean_get_type ())
 </MACRO>
@@ -1269,6 +1353,16 @@ GtkForm *form
 <RETURNS>gboolean </RETURNS>
 GtkForm *form, GHashTable *hashtable 
 </FUNCTION>
+<FUNCTION>
+<NAME>gtk_form_add_group</NAME>
+<RETURNS>gboolean </RETURNS>
+GtkForm *form, GtkFormGroup *group 
+</FUNCTION>
+<FUNCTION>
+<NAME>gtk_form_get_group_by_name</NAME>
+<RETURNS>GtkFormGroup *</RETURNS>
+GtkForm *form, const gchar *group_name 
+</FUNCTION>
 <MACRO>
 <NAME>TYPE_GTK_FORM_WIDGET_COMBO_BOX</NAME>
 #define TYPE_GTK_FORM_WIDGET_COMBO_BOX                 (gtk_form_widget_combo_box_get_type ())
index a2b03d3b3190e1b1277dcf0f34a07b25035c4d8d..f3d9712f9b9b6f8a46a2ca613ab6989caac4a21f 100644 (file)
@@ -1,7 +1,7 @@
 8% symbol docs coverage.
-27 symbols documented.
+28 symbols documented.
 2 symbols incomplete.
-305 not documented.
+314 not documented.
 
 
 GTK_FORM
@@ -112,6 +112,7 @@ TYPE_GTK_FORM_WIDGET_SPIN
 TYPE_GTK_FORM_WIDGET_TEXTVIEW
 gtk_form_add_field
 gtk_form_add_fields
+gtk_form_add_group
 gtk_form_check
 gtk_form_clear
 gtk_form_field_boolean_clear
@@ -200,6 +201,7 @@ 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_group_by_name
 gtk_form_get_gtkbuilder
 gtk_form_get_key
 gtk_form_get_objects
@@ -210,6 +212,13 @@ gtk_form_get_type
 gtk_form_get_values_as_hashtable
 gtk_form_get_widget_from_form_widget_name
 gtk_form_get_widget_from_name
+gtk_form_group_add_field
+gtk_form_group_add_widget
+gtk_form_group_clear
+gtk_form_group_get_name
+gtk_form_group_new
+gtk_form_group_set_from_datamodel
+gtk_form_group_set_from_hashtable
 gtk_form_is_changed
 gtk_form_key_add_field
 gtk_form_key_add_fields
index 3cb8dad475507458dc0c9ba04f73b26d3fd572cf..54d74f89e38e3f2a462575ae37cc8499b06a9040 100644 (file)
@@ -1,13 +1,22 @@
+GTK_FORM_GROUP
+GTK_FORM_GROUP_CLASS
+GTK_FORM_GROUP_GET_CLASS
 GTK_FORM_WIDGET_RADIO
 GTK_FORM_WIDGET_RADIO_CLASS
 GTK_FORM_WIDGET_RADIO_GET_CLASS
+GtkFormGroup
+GtkFormGroupClass
 GtkFormWidgetOnChangeOpType
 GtkFormWidgetOnChangeOpUpdateWhen
 GtkFormWidgetRadio
 GtkFormWidgetRadioClass
+IS_GTK_FORM_GROUP
+IS_GTK_FORM_GROUP_CLASS
 IS_GTK_FORM_WIDGET_RADIO
 IS_GTK_FORM_WIDGET_RADIO_CLASS
+TYPE_GTK_FORM_GROUP
 TYPE_GTK_FORM_WIDGET_RADIO
+gtk_form_add_group
 gtk_form_field_boolean_set_as_origin
 gtk_form_field_boolean_set_from_hashtable
 gtk_form_field_boolean_str_to_boolean
@@ -41,6 +50,7 @@ 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_group_by_name
 gtk_form_get_gtkbuilder
 gtk_form_get_key
 gtk_form_get_objects_by_name
@@ -48,6 +58,14 @@ gtk_form_get_table
 gtk_form_get_values_as_hashtable
 gtk_form_get_widget_from_form_widget_name
 gtk_form_get_widgets
+gtk_form_group_add_field
+gtk_form_group_add_widget
+gtk_form_group_clear
+gtk_form_group_get_name
+gtk_form_group_get_type
+gtk_form_group_new
+gtk_form_group_set_from_datamodel
+gtk_form_group_set_from_hashtable
 gtk_form_is_changed
 gtk_form_load_from_file
 gtk_form_load_from_xml
index 671dc7b92b59561bb628c535eb1459efb541ab84..fa1ddc6f9d078818e8bba8bba29e581f03dc7f42 100644 (file)
 <DEFAULT>""</DEFAULT>
 </ARG>
 
+<ARG>
+<NAME>GtkFormWidget::field</NAME>
+<TYPE>GtkFormField*</TYPE>
+<RANGE></RANGE>
+<FLAGS>rw</FLAGS>
+<NICK>GtkFormField</NICK>
+<BLURB>The GtkFormField.</BLURB>
+<DEFAULT></DEFAULT>
+</ARG>
+
 <ARG>
 <NAME>GtkFormWidget::form</NAME>
 <TYPE>GtkForm*</TYPE>
index 7357bec7e0a22775ce4c894af0ed403ca2437239..53f816917bb4aaf4ff13426238fe77a7b7afd022 100644 (file)
@@ -73,6 +73,11 @@ FormWidget
 </para>
 
 
+<!-- ##### ARG GtkFormWidget:field ##### -->
+<para>
+
+</para>
+
 <!-- ##### ARG GtkFormWidget:form ##### -->
 <para>
 
index 6cbeba00881a1f7605efc2e5c491ab65d19273bb..b14a76c916395b7cf5fd57a9990a49e4f4ce0c3f 100644 (file)
@@ -21,7 +21,8 @@ libgtkform_la_SOURCES = form.c \
                      widgetlabel.c \
                      widgetradio.c \
                      widgetspin.c \
-                     widgettextview.c
+                     widgettextview.c \
+                     group.c
 
 libgtkform_la_LDFLAGS = -no-undefined
 
@@ -40,6 +41,7 @@ libgtkform_include_HEADERS = form.h \
                   widgetlabel.h \
                   widgetradio.h \
                   widgetspin.h \
-                  widgettextview.h
+                  widgettextview.h \
+                  group.h
 
 libgtkform_includedir = $(includedir)/libgtkform
index bcf07a6f476800024a5a27087a59f56c79634ce3..a0d7fe642329589f2071579ad1629931393ec2f8 100644 (file)
@@ -450,6 +450,7 @@ gtk_form_field_set_property (GObject *object,
 
                        case PROP_WIDGET:
                                priv->widget = g_value_get_object (value);
+                               g_object_set (G_OBJECT (priv->widget), "field", field, NULL);
                                break;
 
                        default:
index ef59ed41d5db1e2490492b411fb5275674b13c0f..d3541ce235c3f4973a52d18d863ffddfe80dec9f 100644 (file)
@@ -58,6 +58,7 @@ static void gtk_form_class_init (GtkFormClass *class);
 static void gtk_form_init (GtkForm *form);
 
 static void parse_widget_on_change (GtkForm *form, xmlNodePtr xnode, GtkFormWidget *fwidget);
+static void parse_group (GtkForm *form, xmlNodePtr xnode);
 
 static void gtk_form_set_property (GObject *object,
                                guint property_id,
@@ -84,6 +85,8 @@ struct _GtkFormPrivate
                gchar quote;
 
                GdaEx *gdaex;
+
+               GSList *groups;
        };
 
 G_DEFINE_TYPE (GtkForm, gtk_form, G_TYPE_OBJECT)
@@ -134,6 +137,7 @@ gtk_form_init (GtkForm *form)
        priv->fields = NULL;
        priv->key = NULL;
        priv->gdaex = NULL;
+       priv->groups = NULL;
 }
 
 /**
@@ -265,6 +269,54 @@ parse_widget_on_change (GtkForm *form, xmlNodePtr xnode, GtkFormWidget *fwidget)
                }
 }
 
+static void
+parse_group (GtkForm *form, xmlNodePtr xnode)
+{
+       xmlNodePtr child;
+       gchar *name;
+       GtkFormGroup *group;
+
+       gchar *ele_name;
+       GtkFormWidget *fwidget;
+       GtkFormField *field;
+
+       name = (gchar *)xmlGetProp (xnode, "name");
+
+       group = gtk_form_group_new (name);
+       gtk_form_add_group (form, group);
+
+       child = xnode->children;
+       while (child != NULL)
+               {
+                       if (xmlStrcmp (child->name, (const xmlChar *)"widget") == 0)
+                               {
+                                       ele_name = (gchar *)xmlNodeGetContent (child);
+                                       if (ele_name != NULL)
+                                               {
+                                                       fwidget = gtk_form_get_form_widget_from_name (form, g_strstrip (ele_name));
+                                                       if (fwidget != NULL)
+                                                               {
+                                                                       gtk_form_group_add_widget (group, fwidget);
+                                                               }
+                                               }
+                               }
+                       else if (xmlStrcmp (child->name, (const xmlChar *)"field") == 0)
+                               {
+                                       ele_name = (gchar *)xmlNodeGetContent (child);
+                                       if (ele_name != NULL)
+                                               {
+                                                       field = gtk_form_get_form_field_from_name (form, g_strstrip (ele_name));
+                                                       if (field != NULL)
+                                                               {
+                                                                       gtk_form_group_add_field (group, field);
+                                                               }
+                                               }
+                               }
+
+                       child = child->next;
+               }
+}
+
 /**
  * gtk_form_load_from_xml:
  * @form:
@@ -614,6 +666,10 @@ gtk_form_load_from_xml (GtkForm *form, xmlDoc *xmldoc, GtkBuilder *gtkbuilder)
                                                                                        g_warning (_("Widget of type Â«%s» not found."), type);
                                                                                }
                                                                }
+                                                       else if (xmlStrcmp (cur->name, (const xmlChar *)"group") == 0)
+                                                               {
+                                                                       parse_group (form, cur);
+                                                               }
 
                                                        cur = cur->next;
                                                }
@@ -1774,6 +1830,75 @@ gtk_form_fill_from_hashtable (GtkForm *form, GHashTable *hashtable)
        return ret;
 }
 
+/**
+ * gtk_form_add_group:
+ * @form:
+ * @group:
+ *
+  */
+gboolean
+gtk_form_add_group (GtkForm *form, GtkFormGroup *group)
+{
+       gboolean ret;
+
+       g_return_val_if_fail (IS_GTK_FORM (form), FALSE);
+       g_return_val_if_fail (IS_GTK_FORM_GROUP (group), FALSE);
+
+       GtkFormPrivate *priv;
+
+       ret = FALSE;
+
+       priv = GTK_FORM_GET_PRIVATE (form);
+
+       priv->groups = g_slist_append (priv->groups, group);
+
+       ret = TRUE;
+
+       return ret;
+}
+
+/**
+ * gtk_form_get_group_by_name:
+ * @form:
+ * @group_name:
+ *
+ */
+GtkFormGroup
+*gtk_form_get_group_by_name (GtkForm *form, const gchar *group_name)
+{
+       GtkFormGroup *g;
+
+       gchar *new_g_name;
+       GSList *gs;
+       gchar *g_name;
+
+       g_return_val_if_fail (IS_GTK_FORM (form), NULL);
+       g_return_val_if_fail (group_name != NULL, NULL);
+
+       new_g_name = g_strstrip (g_strdup (group_name));
+
+       g_return_val_if_fail (g_strcmp0 (new_g_name, "") != 0, NULL);
+
+       GtkFormPrivate *priv = GTK_FORM_GET_PRIVATE (form);
+
+       g = NULL;
+
+       gs = priv->groups;
+       while (gs != NULL)
+               {
+                       g_name = gtk_form_group_get_name ((GtkFormGroup *)gs->data);
+                       if (g_strcmp0 (g_name, new_g_name) == 0)
+                               {
+                                       g = (GtkFormGroup *)gs->data;
+                                       break;
+                               }
+
+                       gs = gs->next;
+               }
+
+       return g;
+}
+
 /* PRIVATE */
 static void
 gtk_form_set_property (GObject *object,
index 24060e7e2b77868414884fef0d02c231f76a3766..eedfe4886d0ea6b34bb3060cb0a4f4fdda0e5370 100644 (file)
@@ -25,6 +25,7 @@
 #include "field.h"
 #include "widget.h"
 #include "key.h"
+#include "group.h"
 
 
 G_BEGIN_DECLS
@@ -118,6 +119,8 @@ gboolean gtk_form_fill_from_table (GtkForm *form);
 GHashTable *gtk_form_get_values_as_hashtable (GtkForm *form);
 gboolean gtk_form_fill_from_hashtable (GtkForm *form, GHashTable *hashtable);
 
+gboolean gtk_form_add_group (GtkForm *form, GtkFormGroup *group);
+GtkFormGroup *gtk_form_get_group_by_name (GtkForm *form, const gchar *group_name);
 
 G_END_DECLS
 
diff --git a/src/group.c b/src/group.c
new file mode 100644 (file)
index 0000000..a2278f0
--- /dev/null
@@ -0,0 +1,286 @@
+/*
+ * 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 "group.h"
+
+enum
+{
+       PROP_0,
+       PROP_NAME
+};
+
+static void gtk_form_group_class_init (GtkFormGroupClass *klass);
+static void gtk_form_group_init (GtkFormGroup *gtk_form_group);
+
+static void gtk_form_group_set_property (GObject *object,
+                                     guint property_id,
+                                     const GValue *value,
+                                     GParamSpec *pspec);
+static void gtk_form_group_get_property (GObject *object,
+                                     guint property_id,
+                                     GValue *value,
+                                     GParamSpec *pspec);
+
+#define GTK_FORM_GROUP_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_GTK_FORM_GROUP, GtkFormGroupPrivate))
+
+typedef struct _GtkFormGroupPrivate GtkFormGroupPrivate;
+struct _GtkFormGroupPrivate
+       {
+               gchar *name;
+
+               GSList *elements; /* GtkFormWidgets and GtkFormFields */
+       };
+
+
+G_DEFINE_TYPE (GtkFormGroup, gtk_form_group, G_TYPE_OBJECT)
+
+static void
+gtk_form_group_class_init (GtkFormGroupClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+       object_class->set_property = gtk_form_group_set_property;
+       object_class->get_property = gtk_form_group_get_property;
+
+       g_object_class_install_property (object_class, PROP_NAME,
+                                        g_param_spec_string ("name",
+                                                             "Group's name'",
+                                                             "Group's name",
+                                                             "",
+                                                             G_PARAM_READWRITE));
+
+       g_type_class_add_private (object_class, sizeof (GtkFormGroupPrivate));
+}
+
+static void
+gtk_form_group_init (GtkFormGroup *gtk_form_group)
+{
+       GtkFormGroupPrivate *priv = GTK_FORM_GROUP_GET_PRIVATE (gtk_form_group);
+
+       priv->name = NULL;
+}
+
+/**
+ * gtk_form_group_new:
+ * @name:
+ *
+ * Returns: the newly created #GtkFormGroup.
+ */
+GtkFormGroup
+*gtk_form_group_new (const gchar *name)
+{
+       GtkFormGroup *g;
+
+       g = g_object_new (TYPE_GTK_FORM_GROUP, NULL);
+
+       g_object_set (G_OBJECT (g), "name", name, NULL);
+
+       return g;
+}
+
+/**
+ * gtk_form_group_get_name:
+ * @group: a #GtkFormGroup object.
+ *
+ * Returns: the group's name.
+ */
+gchar
+*gtk_form_group_get_name (GtkFormGroup *group)
+{
+       GtkFormGroupPrivate *priv = GTK_FORM_GROUP_GET_PRIVATE (group);
+
+       return g_strdup (priv->name);
+}
+
+/**
+ * gtk_form_group_add_widget:
+ * @group:
+ * @fwidget:
+ *
+ */
+gboolean
+gtk_form_group_add_widget (GtkFormGroup *group, GtkFormWidget *fwidget)
+{
+       gboolean ret;
+
+       g_return_val_if_fail (IS_GTK_FORM_GROUP (group), FALSE);
+       g_return_val_if_fail (IS_GTK_FORM_WIDGET (fwidget), FALSE);
+
+       GtkFormGroupPrivate *priv = GTK_FORM_GROUP_GET_PRIVATE (group);
+
+       ret = FALSE;
+
+       priv->elements = g_slist_append (priv->elements, (gpointer)fwidget);
+
+       ret = TRUE;
+
+       return ret;
+}
+
+/**
+ * gtk_form_group_add_field:
+ * @group:
+ * @field:
+ *
+ */
+gboolean
+gtk_form_group_add_field (GtkFormGroup *group, GtkFormField *field)
+{
+       gboolean ret;
+
+       g_return_val_if_fail (IS_GTK_FORM_GROUP (group), FALSE);
+       g_return_val_if_fail (IS_GTK_FORM_FIELD (field), FALSE);
+
+       GtkFormGroupPrivate *priv = GTK_FORM_GROUP_GET_PRIVATE (group);
+
+       ret = FALSE;
+
+       priv->elements = g_slist_append (priv->elements, (gpointer)field);
+
+       ret = TRUE;
+
+       return ret;
+}
+
+/**
+ * gtk_form_group_clear:
+ * @group: a #GtkFormGroup object.
+ *
+ */
+gboolean
+gtk_form_group_clear (GtkFormGroup *group)
+{
+       gboolean ret;
+
+       GSList *els;
+
+       GtkFormGroupPrivate *priv = GTK_FORM_GROUP_GET_PRIVATE (group);
+
+       g_return_val_if_fail (IS_GTK_FORM_GROUP (group), FALSE);
+
+       els = priv->elements;
+       while (els != NULL)
+               {
+                       if (IS_GTK_FORM_WIDGET ((GtkFormWidget *)els->data))
+                               {
+                                       gtk_form_widget_set_value_stringify ((GtkFormWidget *)els->data, "");
+                               }
+                       else if (IS_GTK_FORM_FIELD ((GtkFormField *)els->data))
+                               {
+                                       gtk_form_field_clear ((GtkFormField *)els->data);
+                               }
+
+                       els = g_slist_next (els);
+               }
+
+       ret = TRUE;
+
+       return ret;
+}
+
+/**
+ * gtk_form_group_set_from_datamodel:
+ * @group: a #GtkFormGroup object.
+ * @dm: a #GdaDataModel object.
+ * @row: the row number to return.
+ *
+ */
+gboolean
+gtk_form_group_set_from_datamodel (GtkFormGroup *group, GdaDataModel *dm, gint row)
+{
+       gboolean ret = FALSE;
+
+       GtkFormGroupPrivate *priv = GTK_FORM_GROUP_GET_PRIVATE (group);
+
+       g_return_val_if_fail (GDA_IS_DATA_MODEL (dm), FALSE);
+
+       /*if (IS_GTK_FORM_GROUP (group) && GTK_FORM_GROUP_GET_CLASS (group)->set_from_datamodel != NULL)
+               {
+                       ret = GTK_FORM_GROUP_GET_CLASS (group)->set_from_datamodel (group, dm, row);
+               }*/
+
+       return ret;
+}
+
+/**
+ * gtk_form_group_set_from_hashtable:
+ * @group: a #GtkFormGroup object.
+ * @hashtable: a #GHashTable object.
+ *
+ */
+gboolean
+gtk_form_group_set_from_hashtable (GtkFormGroup *group, GHashTable *hashtable)
+{
+       gboolean ret = FALSE;
+
+       GtkFormGroupPrivate *priv = GTK_FORM_GROUP_GET_PRIVATE (group);
+
+       g_return_val_if_fail (hashtable != NULL, FALSE);
+
+       /*if (IS_GTK_FORM_GROUP (group) && GTK_FORM_GROUP_GET_CLASS (group)->set_from_hashtable != NULL)
+               {
+                       ret = GTK_FORM_GROUP_GET_CLASS (group)->set_from_hashtable (group, hashtable);
+               }*/
+
+       return ret;
+}
+
+/* PRIVATE */
+static void
+gtk_form_group_set_property (GObject *object,
+                         guint property_id,
+                         const GValue *value,
+                         GParamSpec *pspec)
+{
+       GtkFormGroup *group = (GtkFormGroup *)object;
+
+       GtkFormGroupPrivate *priv = GTK_FORM_GROUP_GET_PRIVATE (group);
+
+       switch (property_id)
+               {
+                       case PROP_NAME:
+                               priv->name = g_strstrip (g_value_dup_string (value));
+                               break;
+
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                               break;
+         }
+}
+
+static void
+gtk_form_group_get_property (GObject *object,
+                         guint property_id,
+                         GValue *value,
+                         GParamSpec *pspec)
+{
+       GtkFormGroup *group = (GtkFormGroup *)object;
+
+       GtkFormGroupPrivate *priv = GTK_FORM_GROUP_GET_PRIVATE (group);
+
+       switch (property_id)
+               {
+                       case PROP_NAME:
+                               g_value_set_string (value, gtk_form_group_get_name (group));
+                               break;
+
+                       default:
+                               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+                               break;
+         }
+}
diff --git a/src/group.h b/src/group.h
new file mode 100644 (file)
index 0000000..3a58b66
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * 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_GROUP_H__
+#define __LIBGTK_FORM_GROUP_H__
+
+#include <glib.h>
+
+#include <libgdaex.h>
+
+#include "widget.h"
+#include "field.h"
+
+
+G_BEGIN_DECLS
+
+
+#define TYPE_GTK_FORM_GROUP                 (gtk_form_group_get_type ())
+#define GTK_FORM_GROUP(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_GTK_FORM_GROUP, GtkFormGroup))
+#define GTK_FORM_GROUP_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_GTK_FORM_GROUP, GtkFormGroupClass))
+#define IS_GTK_FORM_GROUP(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_GTK_FORM_GROUP))
+#define IS_GTK_FORM_GROUP_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_GTK_FORM_GROUP))
+#define GTK_FORM_GROUP_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_GTK_FORM_GROUP, GtkFormGroupClass))
+
+
+typedef struct _GtkFormGroup GtkFormGroup;
+typedef struct _GtkFormGroupClass GtkFormGroupClass;
+
+struct _GtkFormGroup
+       {
+               GObject parent;
+       };
+
+struct _GtkFormGroupClass
+       {
+               GObjectClass parent_class;
+       };
+
+GType gtk_form_group_get_type (void) G_GNUC_CONST;
+
+GtkFormGroup *gtk_form_group_new (const gchar *name);
+
+gchar *gtk_form_group_get_name (GtkFormGroup *group);
+
+gboolean gtk_form_group_add_widget (GtkFormGroup *group, GtkFormWidget *fwidget);
+gboolean gtk_form_group_add_field (GtkFormGroup *group, GtkFormField *field);
+
+gboolean gtk_form_group_clear (GtkFormGroup *group);
+
+gboolean gtk_form_group_set_from_datamodel (GtkFormGroup *group, GdaDataModel *dm, gint row);
+gboolean gtk_form_group_set_from_hashtable (GtkFormGroup *group, GHashTable *hashtable);
+
+
+G_END_DECLS
+
+
+#endif /* __LIBGTK_FORM_GROUP_H__ */
index a2a80672154cd1c304f9c3b31055452cef51dafa..8ae68073e8bdaf717e46044a7f90a18987023838 100644 (file)
 
 #include "form.h"
 #include "widget.h"
+#include "field.h"
 
 enum
 {
        PROP_0,
        PROP_FORM,
+       PROP_FIELD,
        PROP_WIDGET,
        PROP_NAME,
        PROP_LABEL
@@ -63,6 +65,8 @@ struct _GtkFormWidgetPrivate
 
                GtkWidget *label;
 
+               GtkFormField *field;
+
                GSList *on_change_ops; /* GtkFormOnChangeOp */
        };
 
@@ -88,6 +92,13 @@ gtk_form_widget_class_init (GtkFormWidgetClass *klass)
                                                              TYPE_GTK_FORM,
                                                              G_PARAM_READWRITE));
 
+       g_object_class_install_property (object_class, PROP_FIELD,
+                                        g_param_spec_object ("field",
+                                                             "GtkFormField",
+                                                             "The GtkFormField",
+                                                             TYPE_GTK_FORM_FIELD,
+                                                             G_PARAM_READWRITE));
+
        g_object_class_install_property (object_class, PROP_WIDGET,
                                         g_param_spec_object ("widget",
                                                              "GtkWidget",
@@ -118,6 +129,7 @@ gtk_form_widget_init (GtkFormWidget *gtk_form_widget)
        GtkFormWidgetPrivate *priv = GTK_FORM_WIDGET_GET_PRIVATE (gtk_form_widget);
 
        priv->form = NULL;
+       priv->field = NULL;
        priv->widget = NULL;
        priv->widget_name = NULL;
        priv->label = NULL;
@@ -350,6 +362,10 @@ execute_on_change_op (GtkFormWidget *fwidget, GtkFormWidgetOnChangeOpUpdate *op)
                                                        gtk_form_widget_set_value_stringify (gtk_form_get_form_widget_from_name (priv->form, op->form_widget_name),
                                                                                         gdaex_data_model_get_value_stringify_at ((GdaDataModel *)res, 0, 0));
                                                }
+                                       else
+                                               {
+                                                       gtk_form_widget_set_value_stringify (gtk_form_get_form_widget_from_name (priv->form, op->form_widget_name), "");
+                                               }
                                }
                }
        else
@@ -404,26 +420,29 @@ gtk_form_widget_set_value_stringify (GtkFormWidget *fwidget, const gchar *value)
                        ret = GTK_FORM_WIDGET_GET_CLASS (fwidget)->set_value_stringify (fwidget, value);
                }
 
-       ops = priv->on_change_ops;
-       while (ops != NULL)
+       if (ret)
                {
-                       op = (GtkFormWidgetOnChangeOp *)ops->data;
-                       switch (op->type)
+                       ops = priv->on_change_ops;
+                       while (ops != NULL)
                                {
-                                       case GTK_FORM_WIDGET_ON_CHANGE_OP_UPDATE:
+                                       op = (GtkFormWidgetOnChangeOp *)ops->data;
+                                       switch (op->type)
                                                {
-                                                       GtkFormWidgetOnChangeOpUpdate *op_update = (GtkFormWidgetOnChangeOpUpdate *)op;
-                                                       if (IS_GTK_FORM (priv->form)
-                                                               && (op_update->when == GTK_FORM_WIDGET_ON_CHANGE_OP_UPDATE_AFTER
-                                                                   || op_update->when == GTK_FORM_WIDGET_ON_CHANGE_OP_UPDATE_BOTH))
+                                                       case GTK_FORM_WIDGET_ON_CHANGE_OP_UPDATE:
                                                                {
-                                                                       execute_on_change_op (fwidget, op_update);
+                                                                       GtkFormWidgetOnChangeOpUpdate *op_update = (GtkFormWidgetOnChangeOpUpdate *)op;
+                                                                       if (IS_GTK_FORM (priv->form)
+                                                                               && (op_update->when == GTK_FORM_WIDGET_ON_CHANGE_OP_UPDATE_AFTER
+                                                                                       || op_update->when == GTK_FORM_WIDGET_ON_CHANGE_OP_UPDATE_BOTH))
+                                                                               {
+                                                                                       execute_on_change_op (fwidget, op_update);
+                                                                               }
                                                                }
+                                                               break;
                                                }
-                                               break;
-                               }
 
-                       ops = g_slist_next (ops);
+                                       ops = g_slist_next (ops);
+                               }
                }
 
        return ret;
@@ -518,6 +537,10 @@ gtk_form_widget_set_property (GObject *object,
                                priv->form = g_value_get_object (value);
                                break;
 
+                       case PROP_FIELD:
+                               priv->field = g_value_get_object (value);
+                               break;
+
                        case PROP_WIDGET:
                                priv->widget = g_value_get_object (value);
                                break;
@@ -552,6 +575,10 @@ gtk_form_widget_get_property (GObject *object,
                                g_value_set_object (value, priv->form);
                                break;
 
+                       case PROP_FIELD:
+                               g_value_set_object (value, priv->field);
+                               break;
+
                        case PROP_WIDGET:
                                g_value_set_object (value, priv->widget);
                                break;