]> saetta.ns0.it Git - zakform/libzakform/commitdiff
Added some member functions to ZakFormElement.
authorAndrea Zagli <azagli@libero.it>
Mon, 12 Jun 2017 18:10:41 +0000 (20:10 +0200)
committerAndrea Zagli <azagli@libero.it>
Mon, 12 Jun 2017 18:10:41 +0000 (20:10 +0200)
set_as_original_value, is_changed, clear and is_valid.

src/formelement.c
src/formelement.h

index 75691c81cd8f1efc67d37202a103afa1e7c7ce13..dccfe91188dc6cbf8c00d3e6f7eff82c9d2bc920 100644 (file)
@@ -1020,7 +1020,14 @@ zak_form_element_set_original_value (ZakFormElement *element, const gchar *value
 void
 zak_form_element_set_as_original_value (ZakFormElement *element)
 {
-       zak_form_element_set_original_value_gvalue (element, zak_form_element_get_value_gvalue (element));
+       if (ZAK_FORM_ELEMENT_GET_CLASS (element)->set_as_original_value != NULL)
+               {
+                       ZAK_FORM_ELEMENT_GET_CLASS (element)->set_as_original_value (element);
+               }
+       else
+               {
+                       zak_form_element_set_original_value_gvalue (element, zak_form_element_get_value_gvalue (element));
+               }
 }
 
 /**
@@ -1031,7 +1038,14 @@ zak_form_element_set_as_original_value (ZakFormElement *element)
 gboolean
 zak_form_element_is_changed (ZakFormElement *element)
 {
-       return (g_strcmp0 (zak_form_element_get_original_value (element), zak_form_element_get_value (element)) != 0);
+       if (ZAK_FORM_ELEMENT_GET_CLASS (element)->is_changed != NULL)
+               {
+                       return ZAK_FORM_ELEMENT_GET_CLASS (element)->is_changed (element);
+               }
+       else
+               {
+                       return (g_strcmp0 (zak_form_element_get_original_value (element), zak_form_element_get_value (element)) != 0);
+               }
 }
 
 /**
@@ -1244,7 +1258,14 @@ zak_form_element_clear (ZakFormElement *element)
 
        priv = zak_form_element_get_instance_private (element);
 
-       zak_form_element_set_value_gvalue (element, priv->default_value);
+       if (ZAK_FORM_ELEMENT_GET_CLASS (element)->clear != NULL)
+               {
+                       ZAK_FORM_ELEMENT_GET_CLASS (element)->clear (element);
+               }
+       else
+               {
+                       zak_form_element_set_value_gvalue (element, priv->default_value);
+               }
 }
 
 /**
@@ -1332,16 +1353,23 @@ zak_form_element_is_valid (ZakFormElement *element)
                        ret = FALSE;
                }
 
-       value = zak_form_element_get_value (element);
-
-       for (i = 0; i < priv->pa_validators->len; i++)
+       if (ZAK_FORM_ELEMENT_GET_CLASS (element)->is_valid != NULL)
+               {
+                       ret = ZAK_FORM_ELEMENT_GET_CLASS (element)->is_valid (element);
+               }
+       else
                {
-                       ZakFormElementValidator *validator = (ZakFormElementValidator *)g_ptr_array_index (priv->pa_validators, i);
-                       if (!zak_form_element_validator_validate (validator, value))
+                       value = zak_form_element_get_value (element);
+
+                       for (i = 0; i < priv->pa_validators->len; i++)
                                {
-                                       g_ptr_array_add (priv->pa_messages, (gpointer)g_strdup (zak_form_element_validator_get_message (validator)));
+                                       ZakFormElementValidator *validator = (ZakFormElementValidator *)g_ptr_array_index (priv->pa_validators, i);
+                                       if (!zak_form_element_validator_validate (validator, value))
+                                               {
+                                                       g_ptr_array_add (priv->pa_messages, (gpointer)g_strdup (zak_form_element_validator_get_message (validator)));
 
-                                       ret = FALSE;
+                                                       ret = FALSE;
+                                               }
                                }
                }
 
index 2eb03e8a5aba107a99a8fd7458850eb228bfaa6e..9fb99eb66cd4c898cdec9c0418559573b30397ba 100644 (file)
@@ -43,12 +43,19 @@ struct _ZakFormElementClass
                gboolean (*set_value) (ZakFormElement *element, GValue *value);
                GValue *(*get_value) (ZakFormElement *element);
 
+               void (*set_as_original_value) (ZakFormElement *element);
+               gboolean (*is_changed) (ZakFormElement *element);
+
                void (*set_visible) (ZakFormElement *element, gboolean visible);
                gboolean (*get_visible) (ZakFormElement *element);
 
                void (*set_editable) (ZakFormElement *element, gboolean editable);
                gboolean (*get_editable) (ZakFormElement *element);
 
+               void (*clear) (ZakFormElement *element);
+
+               gboolean (*is_valid) (ZakFormElement *element);
+
                guint before_validating_signal_id;
                guint after_validating_signal_id;
        };