]> saetta.ns0.it Git - libgtkform/commitdiff
Added functions GtkForm::set_as_origin and GtkFormField*::set_as_origin.
authorAndrea Zagli <azagli@libero.it>
Fri, 4 Sep 2009 07:36:26 +0000 (09:36 +0200)
committerAndrea Zagli <azagli@libero.it>
Fri, 4 Sep 2009 07:36:26 +0000 (09:36 +0200)
14 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

index 4ed31fbd3f0fe410db898bfb887738f24b0a9b7e..218d2598d7683a87653e78fee3855c5072bfc890 100644 (file)
@@ -266,6 +266,21 @@ gtk_form_field_is_changed (GtkFormField *field)
        return ret;
 }
 
+/**
+ * gtk_form_field_set_as_origin:
+ * @field: a #GtkFormField object.
+ *
+ * Sets the original value of #GtkFormField to the current value.
+ */
+void
+gtk_form_field_set_as_origin (GtkFormField *field)
+{
+       if (IS_GTK_FORM_FIELD (field) && GTK_FORM_FIELD_GET_CLASS (field)->set_as_origin != NULL)
+               {
+                       GTK_FORM_FIELD_GET_CLASS (field)->set_as_origin (field);
+               }
+}
+
 /**
  * gtk_form_field_set_from_datamodel:
  * @field: a #GtkFormField object.
index 370a882a2fde17bdbf073fbdfcc8131ce3cc344e..0a51a13957aa84acac1c56570f38965948971bdf 100644 (file)
@@ -56,6 +56,7 @@ struct _GtkFormFieldClass
                gboolean (*clear) (GtkFormField *field);
                gboolean (*is_empty) (GtkFormField *field);
                gboolean (*is_changed) (GtkFormField *field);
+               void (*set_as_origin) (GtkFormField *field);
                gboolean (*set_from_datamodel) (GtkFormField *field, GdaDataModel *dm, gint row);
        };
 
@@ -76,6 +77,7 @@ gboolean gtk_form_field_clear (GtkFormField *field);
 gboolean gtk_form_field_is_empty (GtkFormField *field);
 
 gboolean gtk_form_field_is_changed (GtkFormField *field);
+void gtk_form_field_set_as_origin (GtkFormField *field);
 
 gboolean gtk_form_field_set_from_datamodel (GtkFormField *field, GdaDataModel *dm, gint row);
 
index 7528beeebb57aa7e6ed34f6150e9f0ea90fea659..6e7653c7f56e8ce0ec315bcf9cb7907bd0673b40 100644 (file)
@@ -68,6 +68,7 @@ gtk_form_field_boolean_class_init (GtkFormFieldBooleanClass *klass)
        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;
 
        g_object_class_install_property (object_class, PROP_DEFAULT,
@@ -237,6 +238,26 @@ gtk_form_filed_boolean_is_changed (GtkFormField *field)
        return ret;
 }
 
+/**
+ * gtk_form_field_boolean_set_as_origin:
+ * @field: a #GtkFormField object.
+ *
+ */
+void
+gtk_form_field_boolean_set_as_origin (GtkFormField *field)
+{
+       GtkFormFieldBooleanPrivate *priv;
+       const gchar *value;
+
+       g_return_if_fail (IS_GTK_FORM_FIELD_BOOLEAN (field));
+
+       priv = GTK_FORM_FIELD_BOOLEAN_GET_PRIVATE (GTK_FORM_FIELD_BOOLEAN (field));
+
+       value = gtk_form_field_boolean_get_value_stringify (field);
+
+       priv->original_value = gtk_form_field_boolean_str_to_boolean (value);
+}
+
 /**
  * gtk_form_field_boolean_set_from_datamodel:
  * @field: a #GtkFormField object.
index 89349db974c6a6e8589ed63f1b414a78a6fba761..856b566084150a0c9a2df36ed09c9c032f840eef 100644 (file)
@@ -61,6 +61,7 @@ gboolean gtk_form_field_boolean_clear (GtkFormField *field);
 gboolean gtk_form_field_boolean_is_empty (GtkFormField *field);
 
 gboolean gtk_form_filed_boolean_is_changed (GtkFormField *field);
+void gtk_form_field_boolean_set_as_origin (GtkFormField *field);
 
 gboolean gtk_form_field_boolean_set_from_datamodel (GtkFormField *field, GdaDataModel *dm, gint row);
 
index 5430671b4a6a47d80f90aafc3185815034d005b6..e63ad500d5b0c3be37150f9d212def2f4873c227 100644 (file)
@@ -74,6 +74,7 @@ gtk_form_field_datetime_class_init (GtkFormFieldDateTimeClass *klass)
        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;
 
        g_object_class_install_property (object_class, PROP_DEFAULT,
@@ -269,7 +270,7 @@ gtk_form_field_datetime_is_empty (GtkFormField *field)
 
 /**
  * gtk_form_field_datetime_is_changed:
- * @field:
+ * @field: a #GtkFormField object.
  *
  */
 gboolean
@@ -298,6 +299,27 @@ gtk_form_field_datetime_is_changed (GtkFormField *field)
        return ret;
 }
 
+/**
+ * gtk_form_field_datetime_set_as_origin:
+ * @field: a #GtkFormField object.
+ *
+ */
+void
+gtk_form_field_datetime_set_as_origin (GtkFormField *field)
+{
+       gboolean ret = FALSE;
+       GtkFormFieldDateTimePrivate *priv;
+       struct tm *value;
+
+       g_return_if_fail (IS_GTK_FORM_FIELD_DATETIME (field));
+
+       priv = GTK_FORM_FIELD_DATETIME_GET_PRIVATE (GTK_FORM_FIELD_DATETIME (field));
+
+       value = gtk_form_field_datetime_get_tm_from_str (gtk_form_field_datetime_get_value_stringify (field));
+
+       priv->original_value = g_memdup (value, sizeof (struct tm));
+}
+
 /**
  * gtk_form_field_datetime_set_from_datamodel:
  * @field: a #GtkFormField object.
index d28d867a517342cd7ed051586055d8d08fd82711..b2007da8e80c5354981f584420efda896932c584 100644 (file)
@@ -68,6 +68,7 @@ gboolean gtk_form_field_datetime_clear (GtkFormField *field);
 gboolean gtk_form_field_datetime_is_empty (GtkFormField *field);
 
 gboolean gtk_form_field_datetime_is_changed (GtkFormField *field);
+void gtk_form_field_datetime_set_as_origin (GtkFormField *field);
 
 gboolean gtk_form_field_datetime_set_from_datamodel (GtkFormField *field, GdaDataModel *dm, gint row);
 
index 20b4dd060bcb2d018a44fb590a3deabb10bdb3a3..8695f4d3172615c4914ad4e008e985457ec4d43e 100644 (file)
@@ -68,6 +68,7 @@ gtk_form_field_float_class_init (GtkFormFieldFloatClass *klass)
        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;
 
        g_object_class_install_property (object_class, PROP_DEFAULT,
@@ -248,6 +249,23 @@ gtk_form_field_float_is_changed (GtkFormField *field)
        return ret;
 }
 
+/**
+ * gtk_form_field_float_set_as_origin:
+ * @field: a #GtkFormField object.
+ *
+ */
+void
+gtk_form_field_float_set_as_origin (GtkFormField *field)
+{
+       GtkFormFieldFloatPrivate *priv;
+
+       g_return_if_fail (IS_GTK_FORM_FIELD_FLOAT (field));
+
+       priv = GTK_FORM_FIELD_FLOAT_GET_PRIVATE (GTK_FORM_FIELD_FLOAT (field));
+
+       priv->original_value = g_strtod (gtk_form_field_float_get_value_stringify (field), NULL);
+}
+
 /**
  * gtk_form_field_float_set_from_datamodel:
  * @field: a #GtkFormField object.
index 5f3ae5f720f7f8db5b2dc31949117e54b80f8e3f..60a7e0ef4f50d74a578f37def2b02f88d36731ce 100644 (file)
@@ -61,6 +61,7 @@ gboolean gtk_form_field_float_clear (GtkFormField *field);
 gboolean gtk_form_field_float_is_empty (GtkFormField *field);
 
 gboolean gtk_form_field_float_is_changed (GtkFormField *field);
+void gtk_form_field_float_set_as_origin (GtkFormField *field);
 
 gboolean gtk_form_field_float_set_from_datamodel (GtkFormField *field, GdaDataModel *dm, gint row);
 
index 10e5dae0e5e1f313340e6245eded88922af213c8..934e4a3bea23a82886824dae4d4a0ec19a1d73ae 100644 (file)
@@ -66,6 +66,7 @@ gtk_form_field_integer_class_init (GtkFormFieldIntegerClass *klass)
        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;
 
        g_object_class_install_property (object_class, PROP_DEFAULT,
@@ -245,6 +246,22 @@ gtk_form_field_integer_is_changed (GtkFormField *field)
        return ret;
 }
 
+/**
+ * gtk_form_field_integer_set_as_origin:
+ * @field: a #GtkFormField object.
+ *
+ */
+void
+gtk_form_field_integer_set_as_origin (GtkFormField *field)
+{
+       GtkFormFieldIntegerPrivate *priv;
+
+       g_return_if_fail (IS_GTK_FORM_FIELD_INTEGER (field));
+
+       priv = GTK_FORM_FIELD_INTEGER_GET_PRIVATE (GTK_FORM_FIELD_INTEGER (field));
+
+       priv->original_value = strtol (gtk_form_field_integer_get_value_stringify (field), NULL, 10);
+}
 /**
  * gtk_form_field_integer_set_from_datamodel:
  * @field: a #GtkFormField object.
index 63a43ba356a2a494e3e7a86920f26895dfdb765d..0fe0afebe7af4cf6b2ec18be1863605f9b44a872 100644 (file)
@@ -61,6 +61,7 @@ gboolean gtk_form_field_integer_clear (GtkFormField *field);
 gboolean gtk_form_field_integer_is_empty (GtkFormField *field);
 
 gboolean gtk_form_field_integer_is_changed (GtkFormField *field);
+void gtk_form_field_integer_set_as_origin (GtkFormField *field);
 
 gboolean gtk_form_field_integer_set_from_datamodel (GtkFormField *field, GdaDataModel *dm, gint row);
 
index b765f641005f03ac576448dca6d7f30218cacf5a..d249d878f38be0a4f600ab902c3d42cfd4b30460 100644 (file)
@@ -66,6 +66,7 @@ gtk_form_field_text_class_init (GtkFormFieldTextClass *klass)
        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;
 
        g_object_class_install_property (object_class, PROP_DEFAULT,
@@ -228,6 +229,23 @@ gtk_form_field_text_is_changed (GtkFormField *field)
        return ret;
 }
 
+/**
+ * gtk_form_field_text_set_as_origin:
+ * @field: a #GtkFormField object.
+ *
+ */
+void
+gtk_form_field_text_set_as_origin (GtkFormField *field)
+{
+       GtkFormFieldTextPrivate *priv;
+
+       g_return_if_fail (IS_GTK_FORM_FIELD_TEXT (field));
+
+       priv = GTK_FORM_FIELD_TEXT_GET_PRIVATE (GTK_FORM_FIELD_TEXT (field));
+
+       priv->original_value = (gchar *)gtk_form_field_text_get_value_stringify (field);
+}
+
 /**
  * gtk_form_field_text_set_from_datamodel:
  * @field: a #GtkFormField object.
index a31788995d20ba82579a70b9473cd53b6844ec54..b7ec022b9d40fdbaa4324240e0f5c02cee40f556 100644 (file)
@@ -61,6 +61,7 @@ gboolean gtk_form_field_text_clear (GtkFormField *field);
 gboolean gtk_form_field_text_is_empty (GtkFormField *field);
 
 gboolean gtk_form_field_text_is_changed (GtkFormField *field);
+void gtk_form_field_text_set_as_origin (GtkFormField *field);
 
 gboolean gtk_form_field_text_set_from_datamodel (GtkFormField *field, GdaDataModel *dm, gint row);
 
index 962ef2479c834fc0552e21acbe4a43ba436500dd..9f67e5e1c882bf164cc7ef9f4612faf54f8f5f91 100644 (file)
@@ -402,7 +402,7 @@ GtkForm
                        else
                                {
                                        /* TO DO */
-                                       g_warning ("The file is not a valid gtkform definition file");
+                                       g_warning ("The file is not a valid gtkform definition file.");
                                }
                }
 
@@ -938,6 +938,32 @@ gtk_form_is_changed (GtkForm *form)
        return ret;
 }
 
+/**
+ * gtk_form_set_as_origin:
+ * @form:  a #GtkForm object.
+ *
+ * Sets the original values of every #GtkForm #GtkFormField's to the currents
+ * values.
+ */
+void
+gtk_form_set_as_origin (GtkForm *form)
+{
+       GtkFormPrivate *priv;
+       GSList *fields;
+
+       g_return_if_fail (IS_GTK_FORM (form));
+
+       priv = GTK_FORM_GET_PRIVATE (form);
+
+       fields = priv->fields;
+       while (fields != NULL)
+               {
+                       gtk_form_field_set_as_origin ((GtkFormField *)fields->data);
+
+                       fields = g_slist_next (fields);
+               }
+}
+
 /**
  * gtk_form_set_sensitive:
  * @form: a #GtkForm object.
@@ -947,13 +973,16 @@ gtk_form_is_changed (GtkForm *form)
 void
 gtk_form_set_sensitive (GtkForm *form, gboolean sensitive)
 {
+       GtkFormPrivate *priv;
+       GSList *fields;
        GtkFormWidget *fwidget;
-       GtkFormPrivate *priv = GTK_FORM_GET_PRIVATE (form);
        GtkWidget *widget;
 
        g_return_if_fail (IS_GTK_FORM (form));
 
-       GSList *fields = priv->fields;
+       priv = GTK_FORM_GET_PRIVATE (form);
+
+       fields = priv->fields;
        while (fields != NULL)
                {
                        fwidget = gtk_form_field_get_form_widget ((GtkFormField *)fields->data);
@@ -1016,11 +1045,14 @@ void
 gtk_form_set_editable (GtkForm *form, gboolean editable)
 {
        GtkFormWidget *fwidget;
-       GtkFormPrivate *priv = GTK_FORM_GET_PRIVATE (form);
+       GtkFormPrivate *priv;
+       GSList *fields;
 
        g_return_if_fail (IS_GTK_FORM (form));
 
-       GSList *fields = priv->fields;
+       priv = GTK_FORM_GET_PRIVATE (form);
+
+       fields = priv->fields;
        while (fields != NULL)
                {
                        fwidget = gtk_form_field_get_form_widget ((GtkFormField *)fields->data);
@@ -1041,6 +1073,8 @@ gtk_form_set_editable (GtkForm *form, gboolean editable)
 gchar
 *gtk_form_get_sql (GtkForm *form, GtkFormSqlType type)
 {
+       GtkFormPrivate *priv;
+       GSList *fields;
        GtkFormField *field;
        gchar *sql = "";
        gchar *fields_names = "";
@@ -1051,9 +1085,9 @@ gchar
 
        g_return_val_if_fail (IS_GTK_FORM (form), NULL);
 
-       GtkFormPrivate *priv = GTK_FORM_GET_PRIVATE (form);
+       priv = GTK_FORM_GET_PRIVATE (form);
 
-       GSList *fields = priv->fields;
+       fields = priv->fields;
 
        while (fields != NULL)
                {
@@ -1146,15 +1180,17 @@ gchar
 gboolean
 gtk_form_fill_from_datamodel (GtkForm *form, GdaDataModel *dm, gint row)
 {
+       GtkFormPrivate *priv;
+       GSList *fields;
        gboolean ret = TRUE;
        GtkFormField *field;
        gchar *field_name;
 
        g_return_val_if_fail (IS_GTK_FORM (form), FALSE);
 
-       GtkFormPrivate *priv = GTK_FORM_GET_PRIVATE (form);
+       priv = GTK_FORM_GET_PRIVATE (form);
 
-       GSList *fields = priv->fields;
+       fields = priv->fields;
 
        while (fields != NULL)
                {
index 31d63e306a958e8dfbdad14168f486875dabcaf8..bdc2300350143521db64fe93aaa84ff8b9e41b44 100644 (file)
@@ -85,6 +85,7 @@ gboolean gtk_form_check (GtkForm *form, gboolean with_key,
                          gboolean set_focus);
 
 gboolean gtk_form_is_changed (GtkForm *form);
+void gtk_form_set_as_origin (GtkForm *form);
 
 void gtk_form_set_sensitive (GtkForm *form, gboolean sensitive);
 void gtk_form_set_sensitive_by_name (GtkForm *form, gboolean sensitive, ...);