]> saetta.ns0.it Git - libgtkform/commitdiff
Now max and min value can be a field name.
authorAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Fri, 15 Nov 2013 12:18:41 +0000 (13:18 +0100)
committerAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Fri, 15 Nov 2013 12:18:41 +0000 (13:18 +0100)
libgtkform/fielddatetime.c
libgtkform/fieldfloat.c
libgtkform/fieldinteger.c
test/main.c

index e3e7d61a46f7b3043d57a3216a4a8afe6c158da5..048a50134e1cd1c3e4ca744e2ce18b46b0ac4403 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005-2012 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2005-2013 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
@@ -27,6 +27,7 @@
 #include <glib/gi18n-lib.h>
 #include <libxml/xpath.h>
 
+#include "form.h"
 #include "widget.h"
 #include "fielddatetime.h"
 
@@ -449,6 +450,30 @@ gtk_form_field_datetime_is_valid (GtkFormField *field)
                                                                }
                                                        g_date_time_unref (gdt_tmp);
                                                }
+                                       else if (min_value[0] == '[' && min_value[strlen (min_value) - 1] == ']')
+                                               {
+                                                       /* is a widget name */
+                                                       GtkFormWidget *fw;
+                                                       GtkForm *form;
+
+                                                       gchar *wname;
+                                                       const gchar *str;
+                                                       gchar *display_format;
+
+                                                       g_object_get (field,
+                                                                     "form-widget", &fw,
+                                                                     NULL);
+
+                                                       g_object_get (fw,
+                                                                     "form", &form,
+                                                                     NULL);
+
+                                                       wname = g_strndup (min_value + 1, strlen (min_value) - 2);
+                                                       str = gtk_form_get_form_widget_value_stringify_by_name (form, (const gchar *)wname);
+                                                       g_free (wname);
+
+                                                       gdt_min_value = gtk_form_field_datetime_get_gdatetime_from_str (str, priv->display_format);
+                                               }
                                        else
                                                {
                                                        gdt_min_value = gtk_form_field_datetime_get_gdatetime_from_str (min_value,
@@ -493,6 +518,29 @@ gtk_form_field_datetime_is_valid (GtkFormField *field)
                                                                }
                                                        g_date_time_unref (gdt_tmp);
                                                }
+                                       else if (max_value[0] == '[' && max_value[strlen (max_value) - 1] == ']')
+                                               {
+                                                       /* is a widget name */
+                                                       GtkFormWidget *fw;
+                                                       GtkForm *form;
+
+                                                       gchar *wname;
+                                                       const gchar *str;
+
+                                                       g_object_get (field,
+                                                                     "form-widget", &fw,
+                                                                     NULL);
+
+                                                       g_object_get (fw,
+                                                                     "form", &form,
+                                                                     NULL);
+
+                                                       wname = g_strndup (max_value + 1, strlen (max_value) - 2);
+                                                       str = gtk_form_get_form_widget_value_stringify_by_name (form, (const gchar *)wname);
+                                                       g_free (wname);
+
+                                                       gdt_max_value = gtk_form_field_datetime_get_gdatetime_from_str (str, priv->display_format);
+                                               }
                                        else
                                                {
                                                        gdt_max_value = gtk_form_field_datetime_get_gdatetime_from_str (max_value,
@@ -1040,9 +1088,9 @@ GDateTime
 
        if (datetime != NULL)
                {
-                       ret = g_date_time_new_local (datetime->tm_mday,
+                       ret = g_date_time_new_local (datetime->tm_year + 1900,
                                                     datetime->tm_mon + 1,
-                                                    datetime->tm_year + 1900,
+                                                    datetime->tm_mday,
                                                     datetime->tm_hour,
                                                     datetime->tm_min,
                                                     (gdouble)datetime->tm_sec);
index 43791049daf4cc0e396880963cf85e59ed5ad5f8..2fb54d5407c58e053dc0290ac9547613e5ec843b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005-2012 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2005-2013 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
@@ -25,6 +25,7 @@
 #include <glib/gi18n-lib.h>
 #include <libxml/xpath.h>
 
+#include "form.h"
 #include "widget.h"
 #include "fieldfloat.h"
 
@@ -418,14 +419,66 @@ gtk_form_field_float_is_valid (GtkFormField *field)
        if (min_value != NULL
            && g_strcmp0 (min_value, "") != 0)
                {
-                       ret = (g_strtod (min_value, NULL) <= value);
+                       if (min_value[0] == '[' && min_value[strlen (min_value) - 1] == ']')
+                               {
+                                       /* is a widget name */
+                                       GtkFormWidget *fw;
+                                       GtkForm *form;
+
+                                       gchar *wname;
+                                       const gchar *str;
+
+                                       g_object_get (field,
+                                                     "form-widget", &fw,
+                                                     NULL);
+
+                                       g_object_get (fw,
+                                                     "form", &form,
+                                                     NULL);
+
+                                       wname = g_strndup (min_value + 1, strlen (min_value) - 2);
+                                       str = gtk_form_get_form_widget_value_stringify_by_name (form, (const gchar *)wname);
+                                       g_free (wname);
+
+                                       ret = (g_strtod (str, NULL) <= value);
+                               }
+                       else
+                               {
+                                       ret = (g_strtod (min_value, NULL) <= value);
+                               }
                }
 
        if (ret
            && max_value != NULL
            && g_strcmp0 (max_value, "") != 0)
                {
-                       ret = (g_strtod (max_value, NULL) >= value);
+                       if (min_value[0] == '[' && min_value[strlen (min_value) - 1] == ']')
+                               {
+                                       /* is a widget name */
+                                       GtkFormWidget *fw;
+                                       GtkForm *form;
+
+                                       gchar *wname;
+                                       const gchar *str;
+
+                                       g_object_get (field,
+                                                     "form-widget", &fw,
+                                                     NULL);
+
+                                       g_object_get (fw,
+                                                     "form", &form,
+                                                     NULL);
+
+                                       wname = g_strndup (min_value + 1, strlen (min_value) - 2);
+                                       str = gtk_form_get_form_widget_value_stringify_by_name (form, (const gchar *)wname);
+                                       g_free (wname);
+
+                                       ret = (g_strtod (str, NULL) >= value);
+                               }
+                       else
+                               {
+                                       ret = (g_strtod (max_value, NULL) >= value);
+                               }
                }
 
        return ret;
index ccd9552169cf9fef477a170b39c5fa847155a18b..46a75707ab47d350dbdc60f7dde2262eda8c0a9b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005-2012 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2005-2013 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
@@ -23,6 +23,7 @@
 #include <glib/gi18n-lib.h>
 #include <libxml/xpath.h>
 
+#include "form.h"
 #include "widget.h"
 #include "widgetspin.h"
 #include "fieldinteger.h"
@@ -320,8 +321,7 @@ gtk_form_field_integer_is_valid (GtkFormField *field)
                                        if (g_strcmp0 (g_strconcat (g_strdup_printf ("%d", value),
                                                                    IS_GTK_FORM_WIDGET_SPIN (fw) ? ",000000" : "", NULL), 
                                                       str_value) != 0)
-                                               {g_message ("%s %s", g_strconcat (g_strdup_printf ("%d", value),
-                                                                   IS_GTK_FORM_WIDGET_SPIN (fw) ? ",000000" : "", NULL), str_value);
+                                               {
                                                        g_free (str_value);
                                                        return FALSE;
                                                }
@@ -340,14 +340,66 @@ gtk_form_field_integer_is_valid (GtkFormField *field)
        if (min_value != NULL
                && g_strcmp0 (min_value, "") != 0)
                {
-                       ret = (strtol (min_value, NULL, 10) <= value);
+                       if (min_value[0] == '[' && min_value[strlen (min_value) - 1] == ']')
+                               {
+                                       /* is a widget name */
+                                       GtkFormWidget *fw;
+                                       GtkForm *form;
+
+                                       gchar *wname;
+                                       const gchar *str;
+
+                                       g_object_get (field,
+                                                     "form-widget", &fw,
+                                                     NULL);
+
+                                       g_object_get (fw,
+                                                     "form", &form,
+                                                     NULL);
+
+                                       wname = g_strndup (min_value + 1, strlen (min_value) - 2);
+                                       str = gtk_form_get_form_widget_value_stringify_by_name (form, (const gchar *)wname);
+                                       g_free (wname);
+
+                                       ret = (strtol (str, NULL, 10) <= value);
+                               }
+                       else
+                               {
+                                       ret = (strtol (min_value, NULL, 10) <= value);
+                               }
                }
 
        if (ret
            && max_value != NULL
            && g_strcmp0 (max_value, "") != 0)
                {
-                       ret = (strtol (max_value, NULL, 10) >= value);
+                       if (max_value[0] == '[' && max_value[strlen (max_value) - 1] == ']')
+                               {
+                                       /* is a widget name */
+                                       GtkFormWidget *fw;
+                                       GtkForm *form;
+
+                                       gchar *wname;
+                                       const gchar *str;
+
+                                       g_object_get (field,
+                                                     "form-widget", &fw,
+                                                     NULL);
+
+                                       g_object_get (fw,
+                                                     "form", &form,
+                                                     NULL);
+
+                                       wname = g_strndup (max_value + 1, strlen (max_value) - 2);
+                                       str = gtk_form_get_form_widget_value_stringify_by_name (form, (const gchar *)wname);
+                                       g_free (wname);
+
+                                       ret = (strtol (str, NULL, 10) >= value);
+                               }
+                       else
+                               {
+                                       ret = (strtol (max_value, NULL, 10) >= value);
+                               }
                }
 
        return ret;
index 670915d724ea6451f599f2c4f0440502a052c0f0..465024889249ae1da3a0031ae2ca2c402b083a8e 100644 (file)
@@ -406,13 +406,7 @@ main (int argc, char **argv)
                      "field", "now",
                      "form-widget", wlabel,
                      "type", GTK_FORM_FIELD_DATETIME_TYPE_DATE,
-                     "default", g_strdup_printf ("%04d-%02d-%02d %02d:%02d:%02d",
-                                                 now->tm_year + 1900,
-                                                 now->tm_mon + 1,
-                                                 now->tm_mday,
-                                                 now->tm_hour,
-                                                 now->tm_min,
-                                                 now->tm_sec),
+                     "default", gtk_form_field_datetime_get_gdatetime_from_tm (now),
                      "display-format", "%d/%m/%Y",
                      NULL);
        gtk_form_add_field (form, fdatetime);