From: Andrea Zagli Date: Sun, 25 Jul 2010 14:56:49 +0000 (+0200) Subject: Added and managed class GtkFormGroup. X-Git-Tag: 0.1.4~5 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=61ea968a667b819f4c352d0bfb4f26068d18c322;p=libgtkform Added and managed class GtkFormGroup. Added property "field" to GtkFormWidget. Added functions GtkForm::add_group and GtkForm::get_group_by_name. Bugfixes. --- diff --git a/data/gtkform.dtd b/data/gtkform.dtd index c0e1c82..3fe147f 100644 --- a/data/gtkform.dtd +++ b/data/gtkform.dtd @@ -1,4 +1,4 @@ - + @@ -46,3 +46,9 @@ + + + + diff --git a/docs/reference/libgtkform-decl-list.txt b/docs/reference/libgtkform-decl-list.txt index a307ffd..8f94da5 100644 --- a/docs/reference/libgtkform-decl-list.txt +++ b/docs/reference/libgtkform-decl-list.txt @@ -34,6 +34,27 @@ gtk_form_widget_check_set_value_stringify gtk_form_widget_check_set_editable +
+group +GtkFormGroup +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 +
+
fieldboolean GtkFormFieldBoolean @@ -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
diff --git a/docs/reference/libgtkform-decl.txt b/docs/reference/libgtkform-decl.txt index 7751923..91ca611 100644 --- a/docs/reference/libgtkform-decl.txt +++ b/docs/reference/libgtkform-decl.txt @@ -137,6 +137,90 @@ GtkFormWidget *fwidget, const gchar *value GtkFormWidget *fwidget, gboolean editable +TYPE_GTK_FORM_GROUP +#define TYPE_GTK_FORM_GROUP (gtk_form_group_get_type ()) + + +GTK_FORM_GROUP +#define GTK_FORM_GROUP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_GTK_FORM_GROUP, GtkFormGroup)) + + +GTK_FORM_GROUP_CLASS +#define GTK_FORM_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_GTK_FORM_GROUP, GtkFormGroupClass)) + + +IS_GTK_FORM_GROUP +#define IS_GTK_FORM_GROUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_GTK_FORM_GROUP)) + + +IS_GTK_FORM_GROUP_CLASS +#define IS_GTK_FORM_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_GTK_FORM_GROUP)) + + +GTK_FORM_GROUP_GET_CLASS +#define GTK_FORM_GROUP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_GTK_FORM_GROUP, GtkFormGroupClass)) + + +GtkFormGroup + + +GtkFormGroupClass + + +GtkFormGroup +struct _GtkFormGroup + { + GObject parent; + }; + + +GtkFormGroupClass +struct _GtkFormGroupClass + { + GObjectClass parent_class; + }; + + +gtk_form_group_get_type +GType +void + + +gtk_form_group_new +GtkFormGroup * +const gchar *name + + +gtk_form_group_get_name +gchar * +GtkFormGroup *group + + +gtk_form_group_add_widget +gboolean +GtkFormGroup *group, GtkFormWidget *fwidget + + +gtk_form_group_add_field +gboolean +GtkFormGroup *group, GtkFormField *field + + +gtk_form_group_clear +gboolean +GtkFormGroup *group + + +gtk_form_group_set_from_datamodel +gboolean +GtkFormGroup *group, GdaDataModel *dm, gint row + + +gtk_form_group_set_from_hashtable +gboolean +GtkFormGroup *group, GHashTable *hashtable + + TYPE_GTK_FORM_FIELD_BOOLEAN #define TYPE_GTK_FORM_FIELD_BOOLEAN (gtk_form_field_boolean_get_type ()) @@ -1269,6 +1353,16 @@ GtkForm *form gboolean GtkForm *form, GHashTable *hashtable + +gtk_form_add_group +gboolean +GtkForm *form, GtkFormGroup *group + + +gtk_form_get_group_by_name +GtkFormGroup * +GtkForm *form, const gchar *group_name + TYPE_GTK_FORM_WIDGET_COMBO_BOX #define TYPE_GTK_FORM_WIDGET_COMBO_BOX (gtk_form_widget_combo_box_get_type ()) diff --git a/docs/reference/libgtkform-undocumented.txt b/docs/reference/libgtkform-undocumented.txt index a2b03d3..f3d9712 100644 --- a/docs/reference/libgtkform-undocumented.txt +++ b/docs/reference/libgtkform-undocumented.txt @@ -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 diff --git a/docs/reference/libgtkform-unused.txt b/docs/reference/libgtkform-unused.txt index 3cb8dad..54d74f8 100644 --- a/docs/reference/libgtkform-unused.txt +++ b/docs/reference/libgtkform-unused.txt @@ -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 diff --git a/docs/reference/libgtkform.args b/docs/reference/libgtkform.args index 671dc7b..fa1ddc6 100644 --- a/docs/reference/libgtkform.args +++ b/docs/reference/libgtkform.args @@ -168,6 +168,16 @@ "" + +GtkFormWidget::field +GtkFormField* + +rw +GtkFormField +The GtkFormField. + + + GtkFormWidget::form GtkForm* diff --git a/docs/reference/tmpl/widget.sgml b/docs/reference/tmpl/widget.sgml index 7357bec..53f8169 100644 --- a/docs/reference/tmpl/widget.sgml +++ b/docs/reference/tmpl/widget.sgml @@ -73,6 +73,11 @@ FormWidget + + + + + diff --git a/src/Makefile.am b/src/Makefile.am index 6cbeba0..b14a76c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 diff --git a/src/field.c b/src/field.c index bcf07a6..a0d7fe6 100644 --- a/src/field.c +++ b/src/field.c @@ -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: diff --git a/src/form.c b/src/form.c index ef59ed4..d3541ce 100644 --- a/src/form.c +++ b/src/form.c @@ -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, diff --git a/src/form.h b/src/form.h index 24060e7..eedfe48 100644 --- a/src/form.h +++ b/src/form.h @@ -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 index 0000000..a2278f0 --- /dev/null +++ b/src/group.c @@ -0,0 +1,286 @@ +/* + * Copyright (C) 2005-2010 Andrea Zagli + * + * 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 index 0000000..3a58b66 --- /dev/null +++ b/src/group.h @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2005-2010 Andrea Zagli + * + * 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 + +#include + +#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__ */ diff --git a/src/widget.c b/src/widget.c index a2a8067..8ae6807 100644 --- a/src/widget.c +++ b/src/widget.c @@ -30,11 +30,13 @@ #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;