]> saetta.ns0.it Git - libgtkform/commitdiff
Added check on validity of float and integer fields.
authorAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Fri, 30 Sep 2011 07:57:13 +0000 (09:57 +0200)
committerAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Fri, 30 Sep 2011 07:57:13 +0000 (09:57 +0200)
Setted default decimals to 2 for float fields.

libgtkform/fieldfloat.c
libgtkform/fieldinteger.c

index 19379efeef4f9eff961e925887dbe1a88c3e066c..3f0ec297129b382158ebdad4aa355f7980633249 100644 (file)
@@ -96,7 +96,7 @@ gtk_form_field_float_class_init (GtkFormFieldFloatClass *klass)
                                         g_param_spec_uint ("decimals",
                                                            "Decimals",
                                                            "Number of decimals to show",
-                                                           0, G_MAXUINT, 0,
+                                                           0, G_MAXUINT, 2,
                                                            G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 
        g_type_class_add_private (object_class, sizeof (GtkFormFieldFloatPrivate));
@@ -340,6 +340,7 @@ gtk_form_field_float_is_valid (GtkFormField *field)
        gboolean ret;
 
        GtkFormFieldFloatPrivate *priv;
+       GtkFormWidget *fw;
 
        gdouble value;
 
@@ -354,6 +355,38 @@ gtk_form_field_float_is_valid (GtkFormField *field)
 
        value = g_strtod (gtk_form_field_float_get_value_stringify (field), NULL);
 
+       g_object_get (field,
+                     "form-widget", &fw,
+                     NULL);
+
+       if (IS_GTK_FORM_WIDGET (fw))
+               {
+                       gdouble dbl_value;
+                       gchar *str_value;
+                       gchar *str_comma;
+                       gchar *str_format;
+
+                       str_value = gtk_form_widget_get_value_stringify (fw);
+                       dbl_value = g_strtod (str_value, NULL);
+                       str_comma = g_strstr_len (str_value, -1, ",");
+
+                       if (str_value != NULL && g_strcmp0 (g_strstrip (str_value), "") != 0)
+                               {
+                                       str_format = g_strdup_printf ("%%0%dd", 6 - (str_comma != NULL ? strlen (str_comma) - 1 : 0));
+                                       if (g_strcmp0 (g_strdup_printf ("%f", dbl_value), g_strdup_printf (g_strconcat ("%s", (str_comma == NULL ? "," : ""), str_format, NULL), str_value, 0)) != 0)
+                                               {
+                                                       g_free (str_value);
+                                                       g_free (str_comma);
+                                                       g_free (str_format);
+                                                       return FALSE;
+                                               }
+
+                                       g_free (str_value);
+                                       g_free (str_comma);
+                                       g_free (str_format);
+                               }
+               }
+
        min_value = NULL;
        max_value = NULL;
 
index 00c12601f7b2adc8f03612b3f7902324f7b5b21e..0d3519a5c036733e56db90ead232eff563a565b1 100644 (file)
@@ -287,6 +287,7 @@ gtk_form_field_integer_is_valid (GtkFormField *field)
        gboolean ret;
 
        GtkFormFieldIntegerPrivate *priv;
+       GtkFormWidget *fw;
 
        gint value;
 
@@ -301,6 +302,27 @@ gtk_form_field_integer_is_valid (GtkFormField *field)
 
        value = strtol (gtk_form_field_integer_get_value_stringify (field), NULL, 10);
 
+       g_object_get (field,
+                     "form-widget", &fw,
+                     NULL);
+
+       if (IS_GTK_FORM_WIDGET (fw))
+               {
+                       gchar *str_value;
+
+                       str_value = gtk_form_widget_get_value_stringify (fw);
+
+                       if (str_value != NULL && g_strcmp0 (g_strstrip (str_value), "") != 0)
+                               {
+                                       if (g_strcmp0 (g_strdup_printf ("%d", value), str_value) != 0)
+                                               {
+                                                       g_free (str_value);
+                                                       return FALSE;
+                                               }
+                                       g_free (str_value);
+                               }
+               }
+
        min_value = NULL;
        max_value = NULL;