From: Andrea Zagli Date: Mon, 12 Jun 2017 18:10:41 +0000 (+0200) Subject: Added some member functions to ZakFormElement. X-Git-Tag: v0.1.0~1^2~6^2~4 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=9b256b706846b909720d3085c8af1ee327742264;p=zakform%2Flibzakform Added some member functions to ZakFormElement. set_as_original_value, is_changed, clear and is_valid. --- diff --git a/src/formelement.c b/src/formelement.c index 75691c8..dccfe91 100644 --- a/src/formelement.c +++ b/src/formelement.c @@ -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; + } } } diff --git a/src/formelement.h b/src/formelement.h index 2eb03e8..9fb99eb 100644 --- a/src/formelement.h +++ b/src/formelement.h @@ -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; };