]> saetta.ns0.it Git - libgtkform/commitdiff
Added functions GtkForm::reset and GtkForm::get_original_values_as_hashtable,
authorAndrea Zagli <azagli@libero.it>
Sat, 9 Oct 2010 18:59:50 +0000 (20:59 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 9 Oct 2010 18:59:50 +0000 (20:59 +0200)
GtkFormField::get_original_value and GtkFormField::set_value
and each corresponding functions in every fields type.

16 files changed:
src/field.c
src/field.h
src/fieldboolean.c
src/fieldboolean.h
src/fielddatetime.c
src/fielddatetime.h
src/fieldfloat.c
src/fieldfloat.h
src/fieldinteger.c
src/fieldinteger.h
src/fieldtext.c
src/fieldtext.h
src/form.c
src/form.h
test/from_xml_with_db.c
test/test_db.gui

index 449bdfdc6765077542d476001c94e67647391d38..4500e24dd38798dca28e11f3b49975545ad58e40 100644 (file)
@@ -261,6 +261,30 @@ gchar
        return ret;
 }
 
+/**
+ * gtk_form_field_get_origin_value:
+ * @field: a #GtkFormField object.
+ *
+ */
+GValue
+*gtk_form_field_get_original_value (GtkFormField *field)
+{
+       GValue *ret;
+
+       ret = NULL;
+
+       if (IS_GTK_FORM_FIELD (field) && GTK_FORM_FIELD_GET_CLASS (field)->get_original_value != NULL)
+               {
+                       ret = GTK_FORM_FIELD_GET_CLASS (field)->get_original_value (field);
+                       if (G_VALUE_HOLDS_STRING (ret))
+                               {
+                                       g_value_set_string (ret, g_strstrip (g_strdup (g_value_get_string (ret))));
+                               }
+               }
+
+       return ret;
+}
+
 /**
  * gtk_form_field_clear:
  * @field: a #GtkFormField object.
@@ -434,6 +458,27 @@ gtk_form_field_set_from_hashtable (GtkFormField *field, GHashTable *hashtable)
        return ret;
 }
 
+/**
+ * gtk_form_field_set_value:
+ * @field: a #GtkFormField object.
+ * @gvalue: a #GValue.
+ *
+ */
+gboolean
+gtk_form_field_set_value (GtkFormField *field, GValue *gvalue)
+{
+       gboolean ret = FALSE;
+
+       GtkFormFieldPrivate *priv = GTK_FORM_FIELD_GET_PRIVATE (field);
+
+       if (IS_GTK_FORM_FIELD (field) && GTK_FORM_FIELD_GET_CLASS (field)->set_value != NULL)
+               {
+                       ret = GTK_FORM_FIELD_GET_CLASS (field)->set_value (field, gvalue);
+               }
+
+       return ret;
+}
+
 /* PRIVATE */
 static void
 gtk_form_field_set_property (GObject *object,
index 6c129bf6f6bcdc84b2b75bb53aad6a9d999070bf..2b7bf991d0ec7419dd847c3d86f1496b57367251 100644 (file)
@@ -52,6 +52,7 @@ struct _GtkFormFieldClass
                gchar *(*get_value_stringify) (GtkFormField *field);
                GValue *(*get_value) (GtkFormField *field);
                gchar *(*get_value_sql) (GtkFormField *field);
+               GValue *(*get_original_value) (GtkFormField *field);
 
                gboolean (*clear) (GtkFormField *field);
                gboolean (*is_empty) (GtkFormField *field);
@@ -59,6 +60,7 @@ struct _GtkFormFieldClass
                void (*set_as_origin) (GtkFormField *field);
                gboolean (*set_from_datamodel) (GtkFormField *field, GdaDataModel *dm, gint row);
                gboolean (*set_from_hashtable) (GtkFormField *field, GHashTable *hashtable);
+               gboolean (*set_value) (GtkFormField *field, GValue *gvalue);
        };
 
 GType gtk_form_field_get_type (void) G_GNUC_CONST;
@@ -72,6 +74,7 @@ GtkFormWidget *gtk_form_field_get_form_widget (GtkFormField *field);
 gchar *gtk_form_field_get_value_stringify (GtkFormField *field);
 GValue *gtk_form_field_get_value (GtkFormField *field);
 gchar *gtk_form_field_get_value_sql (GtkFormField *field);
+GValue *gtk_form_field_get_original_value (GtkFormField *field);
 
 gboolean gtk_form_field_clear (GtkFormField *field);
 
@@ -87,6 +90,7 @@ void gtk_form_field_set_as_origin (GtkFormField *field);
 
 gboolean gtk_form_field_set_from_datamodel (GtkFormField *field, GdaDataModel *dm, gint row);
 gboolean gtk_form_field_set_from_hashtable (GtkFormField *field, GHashTable *hashtable);
+gboolean gtk_form_field_set_value (GtkFormField *field, GValue *gvalue);
 
 
 G_END_DECLS
index 47a23aee558d38e185b679c22281cc562a3ff0da..d38d706b49436be40bcdc097ab009c315e320d7f 100644 (file)
@@ -71,12 +71,14 @@ gtk_form_field_boolean_class_init (GtkFormFieldBooleanClass *klass)
        field_class->get_value_stringify = gtk_form_field_boolean_get_value_stringify;
        field_class->get_value = gtk_form_field_boolean_get_value;
        field_class->get_value_sql = gtk_form_field_boolean_get_value_sql;
+       field_class->get_original_value = gtk_form_field_boolean_get_original_value;
        field_class->clear = gtk_form_field_boolean_clear;
        field_class->is_empty = gtk_form_field_boolean_is_empty;
        field_class->is_changed = gtk_form_filed_boolean_is_changed;
        field_class->set_as_origin = gtk_form_field_boolean_set_as_origin;
        field_class->set_from_datamodel = gtk_form_field_boolean_set_from_datamodel;
        field_class->set_from_hashtable = gtk_form_field_boolean_set_from_hashtable;
+       field_class->set_value = gtk_form_field_boolean_set_value;
 
        g_object_class_install_property (object_class, PROP_DEFAULT,
                                         g_param_spec_boolean ("default",
@@ -191,6 +193,30 @@ gchar
        return ret;
 }
 
+/**
+ * gtk_form_field_boolean_get_original_value:
+ * @field: a #GtkFormField object.
+ *
+ */
+GValue
+*gtk_form_field_boolean_get_original_value (GtkFormField *field)
+{
+       GValue *ret;
+
+       g_return_val_if_fail (IS_GTK_FORM_FIELD_BOOLEAN (field), NULL);
+
+       GtkFormFieldBooleanPrivate *priv = GTK_FORM_FIELD_BOOLEAN_GET_PRIVATE (field);
+
+       ret = NULL;
+
+       ret = g_malloc0 (sizeof (GValue));
+       g_value_init (ret, G_TYPE_BOOLEAN);
+       g_value_set_boolean (ret, priv->original_value
+       );
+
+       return ret;
+}
+
 /**
  * gtk_form_field_boolean_clear:
  * @field: a #GtkFormField object.
@@ -376,6 +402,38 @@ gtk_form_field_boolean_set_from_hashtable (GtkFormField *field, GHashTable *hash
        return ret;
 }
 
+/**
+ * gtk_form_field_boolean_set_value:
+ * @field: a #GtkFormField object.
+ * @gvalue: a #GValue.
+ *
+ */
+gboolean
+gtk_form_field_boolean_set_value (GtkFormField *field, GValue *gvalue)
+{
+       gboolean ret = FALSE;
+       GtkFormFieldBooleanPrivate *priv;
+       gchar *value;
+
+       g_return_val_if_fail (IS_GTK_FORM_FIELD_BOOLEAN (field), FALSE);
+       g_return_val_if_fail (G_VALUE_HOLDS_BOOLEAN (gvalue), FALSE);
+
+       priv = GTK_FORM_FIELD_BOOLEAN_GET_PRIVATE (GTK_FORM_FIELD_BOOLEAN (field));
+
+       priv->original_value = g_value_get_boolean (gvalue);
+       if (priv->original_value)
+               {
+                       value = g_strdup_printf ("TRUE");
+               }
+       else
+               {
+                       value = g_strdup_printf ("FALSE");
+               }
+       ret = gtk_form_field_boolean_set_value_stringify (field, value);
+
+       return ret;
+}
+
 /**
  * gtk_form_field_boolean_str_to_boolean:
  * @value:
index 7485d6d79b356c26ac5e3721d22dc169c7b7bd38..303be5b2e4d388b88614d8d2598e3e4f522d67da 100644 (file)
@@ -55,6 +55,7 @@ GtkFormField *gtk_form_field_boolean_new (void);
 gchar *gtk_form_field_boolean_get_value_stringify (GtkFormField *field);
 GValue *gtk_form_field_boolean_get_value (GtkFormField *field);
 gchar *gtk_form_field_boolean_get_value_sql (GtkFormField *field);
+GValue *gtk_form_field_boolean_get_original_value (GtkFormField *field);
 
 gboolean gtk_form_field_boolean_clear (GtkFormField *field);
 
@@ -65,6 +66,7 @@ void gtk_form_field_boolean_set_as_origin (GtkFormField *field);
 
 gboolean gtk_form_field_boolean_set_from_datamodel (GtkFormField *field, GdaDataModel *dm, gint row);
 gboolean gtk_form_field_boolean_set_from_hashtable (GtkFormField *field, GHashTable *hashtable);
+gboolean gtk_form_field_boolean_set_value (GtkFormField *field, GValue *gvalue);
 
 gboolean gtk_form_field_boolean_str_to_boolean (const gchar *value);
 
index 4ce51398a01cb2a43f578af31d914879f56062e0..c7108f1621757562d0265ed874b0389a534318cd 100644 (file)
@@ -87,12 +87,14 @@ gtk_form_field_datetime_class_init (GtkFormFieldDateTimeClass *klass)
        field_class->get_value_stringify = gtk_form_field_datetime_get_value_stringify;
        field_class->get_value = gtk_form_field_datetime_get_value;
        field_class->get_value_sql = gtk_form_field_datetime_get_value_sql;
+       field_class->get_original_value = gtk_form_field_datetime_get_original_value;
        field_class->clear = gtk_form_field_datetime_clear;
        field_class->is_empty = gtk_form_field_datetime_is_empty;
        field_class->is_changed = gtk_form_field_datetime_is_changed;
        field_class->set_as_origin = gtk_form_field_datetime_set_as_origin;
        field_class->set_from_datamodel = gtk_form_field_datetime_set_from_datamodel;
        field_class->set_from_hashtable = gtk_form_field_datetime_set_from_hashtable;
+       field_class->set_value = gtk_form_field_datetime_set_value;
 
        g_object_class_install_property (object_class, PROP_DEFAULT,
                                         g_param_spec_pointer ("default",
@@ -247,6 +249,31 @@ gchar
        return ret;
 }
 
+/**
+ * gtk_form_field_datetime_get_original_value:
+ * @field: a #GtkFormField object.
+ *
+ * Returns: a #GValue of type G_TYPE_POINTER that point to a struct tm.
+ */
+GValue
+*gtk_form_field_datetime_get_original_value (GtkFormField *field)
+{
+       GValue *ret;
+       GtkFormFieldDateTimePrivate *priv;
+
+       g_return_val_if_fail (IS_GTK_FORM_FIELD_DATETIME (field), NULL);
+
+       priv = GTK_FORM_FIELD_DATETIME_GET_PRIVATE (GTK_FORM_FIELD_DATETIME (field));
+
+       ret = NULL;
+
+       ret = g_malloc0 (sizeof (GValue));
+       g_value_init (ret, G_TYPE_POINTER);
+       g_value_set_pointer (ret, g_memdup (priv->original_value, sizeof (struct tm)));
+
+       return ret;
+}
+
 /**
  * gtk_form_field_datetime_clear:
  * @field: a #GtkFormField object.
@@ -461,6 +488,35 @@ gtk_form_field_datetime_set_from_hashtable (GtkFormField *field, GHashTable *has
        return ret;
 }
 
+/**
+ * gtk_form_field_datetime_set_value:
+ * @field: a #GtkFormField object.
+ * @value: a #GValue.
+ *
+ */
+gboolean
+gtk_form_field_datetime_set_value (GtkFormField *field, GValue *gvalue)
+{
+       gboolean ret;
+       GtkFormFieldDateTimePrivate *priv;
+       struct tm *datetime;
+       gchar *value;
+
+       g_return_val_if_fail (IS_GTK_FORM_FIELD_DATETIME (field), FALSE);
+       g_return_val_if_fail (G_VALUE_HOLDS_POINTER (gvalue), FALSE);
+
+       ret = FALSE;
+
+       priv = GTK_FORM_FIELD_DATETIME_GET_PRIVATE (GTK_FORM_FIELD_DATETIME (field));
+
+       datetime = (struct tm *)g_value_get_pointer (gvalue);
+       value = gtk_form_field_datetime_get_str_from_tm (datetime, priv->display_format);
+       ret = gtk_form_field_datetime_set_value_stringify (field, value);
+       priv->original_value = g_memdup (datetime, sizeof (struct tm));
+
+       return ret;
+}
+
 /**
  * gtk_form_field_datetime_get_tm_from_str:
  * @str: the #gchar to be parsed.
index b5acc9acc93c4b0978acdeff27377b969807049a..6acfeacedb0b732b3e30c28ddebca19097a9d621 100644 (file)
@@ -62,6 +62,7 @@ GtkFormField *gtk_form_field_datetime_new (void);
 gchar *gtk_form_field_datetime_get_value_stringify (GtkFormField *field);
 GValue *gtk_form_field_datetime_get_value (GtkFormField *field);
 gchar *gtk_form_field_datetime_get_value_sql (GtkFormField *field);
+GValue *gtk_form_field_datetime_get_original_value (GtkFormField *field);
 
 gboolean gtk_form_field_datetime_clear (GtkFormField *field);
 
@@ -72,6 +73,7 @@ void gtk_form_field_datetime_set_as_origin (GtkFormField *field);
 
 gboolean gtk_form_field_datetime_set_from_datamodel (GtkFormField *field, GdaDataModel *dm, gint row);
 gboolean gtk_form_field_datetime_set_from_hashtable (GtkFormField *field, GHashTable *hashtable);
+gboolean gtk_form_field_datetime_set_value (GtkFormField *field, GValue *gvalue);
 
 struct tm *gtk_form_field_datetime_get_tm_from_str (const gchar *str, const gchar *format);
 gchar *gtk_form_field_datetime_get_str_from_tm (struct tm *datetime, const gchar *format);
index b8e0235cfd7e426b5a0c9ddc69faf336a033032c..59cfb5b069d84810044cba7a8bcdf70308b04ab7 100644 (file)
@@ -71,12 +71,14 @@ gtk_form_field_float_class_init (GtkFormFieldFloatClass *klass)
        field_class->get_value_stringify = gtk_form_field_float_get_value_stringify;
        field_class->get_value = gtk_form_field_float_get_value;
        field_class->get_value_sql = gtk_form_field_float_get_value_sql;
+       field_class->get_original_value = gtk_form_field_float_get_original_value;
        field_class->clear = gtk_form_field_float_clear;
        field_class->is_empty = gtk_form_field_float_is_empty;
        field_class->is_changed = gtk_form_field_float_is_changed;
        field_class->set_as_origin = gtk_form_field_float_set_as_origin;
        field_class->set_from_datamodel = gtk_form_field_float_set_from_datamodel;
        field_class->set_from_hashtable = gtk_form_field_float_set_from_hashtable;
+       field_class->set_value = gtk_form_field_float_set_value;
 
        g_object_class_install_property (object_class, PROP_DEFAULT,
                                         g_param_spec_float ("default",
@@ -200,6 +202,27 @@ gchar
        return ret;
 }
 
+/**
+ * gtk_form_field_float_get_original_value:
+ * @field: a #GtkFormField object.
+ *
+ */
+GValue
+*gtk_form_field_float_get_original_value (GtkFormField *field)
+{
+       GValue *ret;
+
+       ret = NULL;
+
+       GtkFormFieldFloatPrivate *priv = GTK_FORM_FIELD_FLOAT_GET_PRIVATE (field);
+
+       ret = g_malloc0 (sizeof (GValue));
+       g_value_init (ret, G_TYPE_FLOAT);
+       g_value_set_float (ret, priv->original_value);
+
+       return ret;
+}
+
 /**
  * gtk_form_field_float_clear:
  * @field: a #GtkFormField object.
@@ -370,6 +393,30 @@ gtk_form_field_float_set_from_hashtable (GtkFormField *field, GHashTable *hashta
        return ret;
 }
 
+/**
+ * gtk_form_field_float_set_value:
+ * @field: a #GtkFormField object.
+ * @value: a #GValue.
+ *
+ */
+gboolean
+gtk_form_field_float_set_value (GtkFormField *field, GValue *gvalue)
+{
+       gboolean ret = FALSE;
+       GtkFormFieldFloatPrivate *priv;
+
+       g_return_val_if_fail (IS_GTK_FORM_FIELD_FLOAT (field), FALSE);
+       g_return_val_if_fail (G_VALUE_HOLDS_FLOAT (gvalue), FALSE);
+
+       priv = GTK_FORM_FIELD_FLOAT_GET_PRIVATE (GTK_FORM_FIELD_FLOAT (field));
+
+       priv->original_value = g_value_get_float (gvalue);
+       setlocale (LC_NUMERIC, "");
+       ret = gtk_form_field_float_set_value_stringify (field, g_strdup_printf ("%f", priv->original_value));
+
+       return ret;
+}
+
 /* PRIVATE */
 static void
 gtk_form_field_float_set_property (GObject *object,
index b1dc528910348787f82947b9570a7c6a5540181f..6816ffbeae1b71c21575f81febc9469b787b1eaf 100644 (file)
@@ -55,6 +55,7 @@ GtkFormField *gtk_form_field_float_new (void);
 gchar *gtk_form_field_float_get_value_stringify (GtkFormField *field);
 GValue *gtk_form_field_float_get_value (GtkFormField *field);
 gchar *gtk_form_field_float_get_value_sql (GtkFormField *field);
+GValue *gtk_form_field_float_get_original_value (GtkFormField *field);
 
 gboolean gtk_form_field_float_clear (GtkFormField *field);
 
@@ -65,6 +66,7 @@ void gtk_form_field_float_set_as_origin (GtkFormField *field);
 
 gboolean gtk_form_field_float_set_from_datamodel (GtkFormField *field, GdaDataModel *dm, gint row);
 gboolean gtk_form_field_float_set_from_hashtable (GtkFormField *field, GHashTable *hashtable);
+gboolean gtk_form_field_float_set_value (GtkFormField *field, GValue *gvalue);
 
 
 G_END_DECLS
index 611f790a3f3a96c2cd341cc488f045fcff0e73d6..e422e36a9e3af289c089b9a5c8cd068e49395f01 100644 (file)
@@ -69,12 +69,14 @@ gtk_form_field_integer_class_init (GtkFormFieldIntegerClass *klass)
        field_class->get_value_stringify = gtk_form_field_integer_get_value_stringify;
        field_class->get_value = gtk_form_field_integer_get_value;
        field_class->get_value_sql = gtk_form_field_integer_get_value_sql;
+       field_class->get_original_value = gtk_form_field_integer_get_original_value;
        field_class->clear = gtk_form_field_integer_clear;
        field_class->is_empty = gtk_form_field_integer_is_empty;
        field_class->is_changed = gtk_form_field_integer_is_changed;
        field_class->set_as_origin = gtk_form_field_integer_set_as_origin;
        field_class->set_from_datamodel = gtk_form_field_integer_set_from_datamodel;
        field_class->set_from_hashtable = gtk_form_field_integer_set_from_hashtable;
+       field_class->set_value = gtk_form_field_integer_set_value;
 
        g_object_class_install_property (object_class, PROP_DEFAULT,
                                         g_param_spec_int ("default",
@@ -158,7 +160,7 @@ GValue
                {
                        ret = g_malloc0 (sizeof (GValue));
                        g_value_init (ret, G_TYPE_INT);
-                       g_value_set_int (ret, atol (value));
+                       g_value_set_int (ret, strtol (value, NULL, 10));
 
                        g_free (value);
                }
@@ -179,6 +181,29 @@ gchar
        return gtk_form_field_integer_get_value_stringify (field);
 }
 
+/**
+ * gtk_form_field_integer_get_original_value:
+ * @field: a #GtkFormField object.
+ *
+ */
+GValue
+*gtk_form_field_integer_get_original_value (GtkFormField *field)
+{
+       GValue *ret;
+
+       g_return_val_if_fail (IS_GTK_FORM_FIELD_INTEGER (field), NULL);
+
+       GtkFormFieldIntegerPrivate *priv = GTK_FORM_FIELD_INTEGER_GET_PRIVATE (field);
+
+       ret = NULL;
+
+       ret = g_malloc0 (sizeof (GValue));
+       g_value_init (ret, G_TYPE_INT);
+       g_value_set_int (ret, priv->original_value);
+
+       return ret;
+}
+
 /**
  * gtk_form_field_integer_clear:
  * @field: a #GtkFormField object.
@@ -339,6 +364,29 @@ gtk_form_field_integer_set_from_hashtable (GtkFormField *field, GHashTable *hash
        return ret;
 }
 
+/**
+ * gtk_form_field_integer_set_value:
+ * @field: a #GtkFormField object.
+ * @gvalue: a #Gvalue.
+ *
+ */
+gboolean
+gtk_form_field_integer_set_value (GtkFormField *field, GValue *gvalue)
+{
+       gboolean ret = FALSE;
+       GtkFormFieldIntegerPrivate *priv;
+
+       g_return_val_if_fail (IS_GTK_FORM_FIELD_INTEGER (field), FALSE);
+       g_return_val_if_fail (G_VALUE_HOLDS_INT (gvalue), FALSE);
+
+       priv = GTK_FORM_FIELD_INTEGER_GET_PRIVATE (GTK_FORM_FIELD_INTEGER (field));
+
+       priv->original_value = g_value_get_int (gvalue);
+       ret = gtk_form_field_integer_set_value_stringify (field, g_strdup_printf ("%d", priv->original_value));
+
+       return ret;
+}
+
 /* PRIVATE */
 static void
 gtk_form_field_integer_set_property (GObject *object,
index 0d55392e94401557a7fe51481aa4c77b0b6434e4..3caa6de3407789efa762a386fb64931b19d3b226 100644 (file)
@@ -55,6 +55,7 @@ GtkFormField *gtk_form_field_integer_new (void);
 gchar *gtk_form_field_integer_get_value_stringify (GtkFormField *field);
 GValue *gtk_form_field_integer_get_value (GtkFormField *field);
 gchar *gtk_form_field_integer_get_value_sql (GtkFormField *field);
+GValue *gtk_form_field_integer_get_original_value (GtkFormField *field);
 
 gboolean gtk_form_field_integer_clear (GtkFormField *field);
 
@@ -65,6 +66,7 @@ void gtk_form_field_integer_set_as_origin (GtkFormField *field);
 
 gboolean gtk_form_field_integer_set_from_datamodel (GtkFormField *field, GdaDataModel *dm, gint row);
 gboolean gtk_form_field_integer_set_from_hashtable (GtkFormField *field, GHashTable *hashtable);
+gboolean gtk_form_field_integer_set_value (GtkFormField *field, GValue *gvalue);
 
 
 G_END_DECLS
index e6d45178fa54a54f2ec7f787958d097cb01032b2..5b8b5e23228c3860d15a469fd5aff2bd61a4952f 100644 (file)
@@ -69,12 +69,14 @@ gtk_form_field_text_class_init (GtkFormFieldTextClass *klass)
        field_class->get_value_stringify = gtk_form_field_text_get_value_stringify;
        field_class->get_value = gtk_form_field_text_get_value;
        field_class->get_value_sql = gtk_form_field_text_get_value_sql;
+       field_class->get_original_value = gtk_form_field_text_get_original_value;
        field_class->clear = gtk_form_field_text_clear;
        field_class->is_empty = gtk_form_field_text_is_empty;
        field_class->is_changed = gtk_form_field_text_is_changed;
        field_class->set_as_origin = gtk_form_field_text_set_as_origin;
        field_class->set_from_datamodel = gtk_form_field_text_set_from_datamodel;
        field_class->set_from_hashtable = gtk_form_field_text_set_from_hashtable;
+       field_class->set_value = gtk_form_field_text_set_value;
 
        g_object_class_install_property (object_class, PROP_DEFAULT,
                                         g_param_spec_string ("default",
@@ -191,6 +193,27 @@ gchar
        return ret;
 }
 
+/**
+ * gtk_form_field_text_get_original_value:
+ * @field: a #GtkFormField object.
+ *
+ */
+GValue
+*gtk_form_field_text_get_original_value (GtkFormField *field)
+{
+       GValue *ret;
+
+       GtkFormFieldTextPrivate *priv = GTK_FORM_FIELD_TEXT_GET_PRIVATE (field);
+
+       ret = NULL;
+
+       ret = g_malloc0 (sizeof (GValue));
+       g_value_init (ret, G_TYPE_STRING);
+       g_value_set_string (ret, priv->original_value);
+
+       return ret;
+}
+
 /**
  * gtk_form_field_text_clear:
  * @field: a #GtkFormField object.
@@ -357,6 +380,29 @@ gtk_form_field_text_set_from_hashtable (GtkFormField *field, GHashTable *hashtab
        return ret;
 }
 
+/**
+ * gtk_form_field_text_set_value:
+ * @field: a #GtkFormField object.
+ * @gvalue: a #GValue.
+ *
+ */
+gboolean
+gtk_form_field_text_set_value (GtkFormField *field, GValue *gvalue)
+{
+       gboolean ret = FALSE;
+       GtkFormFieldTextPrivate *priv;
+
+       g_return_val_if_fail (IS_GTK_FORM_FIELD_TEXT (field), FALSE);
+       g_return_val_if_fail (G_VALUE_HOLDS_STRING (gvalue), FALSE);
+
+       priv = GTK_FORM_FIELD_TEXT_GET_PRIVATE (GTK_FORM_FIELD_TEXT (field));
+
+       ret = gtk_form_field_text_set_value_stringify (field, g_value_get_string (gvalue));
+       priv->original_value = gtk_form_field_text_get_value_stringify (field);
+
+       return ret;
+}
+
 /* PRIVATE */
 static void
 gtk_form_field_text_set_property (GObject *object,
index c693aa80c4efb7fa79d3144100b32478878e7fe3..885eded6d2f76f5b7eb5da655bf5a87661f4d50f 100644 (file)
@@ -55,6 +55,7 @@ GtkFormField *gtk_form_field_text_new (void);
 gchar *gtk_form_field_text_get_value_stringify (GtkFormField *field);
 GValue *gtk_form_field_text_get_value (GtkFormField *field);
 gchar *gtk_form_field_text_get_value_sql (GtkFormField *field);
+GValue *gtk_form_field_text_get_original_value (GtkFormField *field);
 
 gboolean gtk_form_field_text_clear (GtkFormField *field);
 
@@ -65,6 +66,7 @@ void gtk_form_field_text_set_as_origin (GtkFormField *field);
 
 gboolean gtk_form_field_text_set_from_datamodel (GtkFormField *field, GdaDataModel *dm, gint row);
 gboolean gtk_form_field_text_set_from_hashtable (GtkFormField *field, GHashTable *hashtable);
+gboolean gtk_form_field_text_set_value (GtkFormField *field, GValue *gvalue);
 
 
 G_END_DECLS
index 1249f41d42cc35d6b459682612a806ac3b14afa1..1620f68b62c5a94ee6e3d409b8fe33c82a623d9e 100644 (file)
@@ -1929,6 +1929,40 @@ gtk_form_fill_from_table (GtkForm *form)
        return ret;
 }
 
+/**
+ * gtk_form_reset:
+ * @form:
+ *
+ */
+gboolean
+gtk_form_reset (GtkForm *form)
+{
+       GtkFormPrivate *priv;
+       GSList *fields;
+       gboolean ret = TRUE;
+       GtkFormField *field;
+       GtkFormWidget *widget;
+       GValue *gval;
+
+       g_return_val_if_fail (IS_GTK_FORM (form), FALSE);
+
+       priv = GTK_FORM_GET_PRIVATE (form);
+
+       fields = priv->fields;
+
+       while (fields != NULL)
+               {
+                       field = (GtkFormField *)fields->data;
+
+                       gval = gtk_form_field_get_original_value (field);
+                       gtk_form_field_set_value (field, gval);
+
+                       fields = g_slist_next (fields);
+               }
+
+       return ret;
+}
+
 /**
  * gtk_form_get_values_as_hashtable:
  * @form: a #GtkForm object.
@@ -1974,6 +2008,51 @@ GHashTable
        return ht;
 }
 
+/**
+ * gtk_form_get_original_values_as_hashtable:
+ * @form:
+ *
+ */
+GHashTable
+*gtk_form_get_original_values_as_hashtable (GtkForm *form)
+{
+       GtkFormPrivate *priv;
+       GSList *fields;
+       GtkFormField *field;
+       gchar *field_name;
+       GValue *gval;
+       GHashTable *ht;
+
+       g_return_val_if_fail (IS_GTK_FORM (form), NULL);
+
+       priv = GTK_FORM_GET_PRIVATE (form);
+
+       fields = priv->fields;
+
+       if (fields != NULL)
+               {
+                       ht = g_hash_table_new (g_str_hash, g_str_equal);
+               }
+
+       while (fields != NULL)
+               {
+                       field = (GtkFormField *)fields->data;
+
+                       field_name = gtk_form_field_get_field_name (field);
+
+                       gval = gtk_form_field_get_original_value (field);
+                       if (gval != NULL)
+                               {
+                                       /* TODO check if the field already exists */
+                                       g_hash_table_insert (ht, field_name, gval);
+                               }
+
+                       fields = g_slist_next (fields);
+               }
+
+       return ht;
+}
+
 /**
  * gtk_form_fill_from_hashtable:
  * @form: a #GtkForm object.
index f42ae370b036e2edfa75518c8629bf8ebae85c4b..a7cbf7b808ac0a5e9fa509fe7a236dc48fe990b8 100644 (file)
@@ -124,7 +124,10 @@ gchar *gtk_form_get_sql (GtkForm *form, GtkFormSqlType type);
 gboolean gtk_form_fill_from_datamodel (GtkForm *form, GdaDataModel *dm, gint row);
 gboolean gtk_form_fill_from_table (GtkForm *form);
 
+gboolean gtk_form_reset (GtkForm *form);
+
 GHashTable *gtk_form_get_values_as_hashtable (GtkForm *form);
+GHashTable *gtk_form_get_original_values_as_hashtable (GtkForm *form);
 gboolean gtk_form_fill_from_hashtable (GtkForm *form, GHashTable *hashtable);
 
 gboolean gtk_form_add_group (GtkForm *form, GtkFormGroup *group);
index b08062967eb870578037ef2a3a8d14c48388b0a9..f4ec5363673e40f79eb28d36e4ef6aa3f9908cb4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005-2009 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2005-2010 Andrea Zagli <azagli@libero.it>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -49,6 +49,7 @@ GtkWidget *btn_edit;
 GtkWidget *btn_delete;
 GtkWidget *cb_customers;
 GtkWidget *btn_open;
+GtkWidget *btn_cancel;
 
 GtkListStore *lstore_customers;
 
@@ -157,6 +158,13 @@ on_btn_open_clicked (GtkButton *button,
        current_id = id;
 }
 
+G_MODULE_EXPORT void
+on_btn_cancel_clicked (GtkButton *button,
+                         gpointer user_data)
+{
+       gtk_form_reset (form);
+}
+
 void
 fill_cb_customers (void)
 {
@@ -211,6 +219,7 @@ main (int argc, char **argv)
        btn_delete = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "btn_delete"));
        cb_customers = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "cb_customers"));
        btn_open = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "btn_open"));
+       btn_cancel = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, "btn_cancel"));
 
        lstore_customers = GTK_LIST_STORE (gtk_builder_get_object (gtkbuilder, "lstore_customers"));
 
index 4765b94ee02134e5cab625a509723ad0f458d1ca..dc974ef3ae44617bde1b2fea61b59c674e417836 100644 (file)
                 <property name="position">4</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkButton" id="btn_cancel">
+                <property name="label">gtk-undo</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+                <signal name="clicked" handler="on_btn_cancel_clicked"/>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">5</property>
+              </packing>
+            </child>
           </object>
           <packing>
             <property name="expand">False</property>