From 46b305ad926772f74e612845612e15d99e27f648 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Wed, 25 Nov 2015 21:34:53 +0100 Subject: [PATCH] Added overrideable functions ZakFormElement::set_value, ::get_value, ::set_visible, ::get_visible, ::set_editable and ::get_editable. --- src/formelement.c | 78 +++++++++++++++++++++++++++++++++++++++++++---- src/formelement.h | 15 +++++++-- 2 files changed, 84 insertions(+), 9 deletions(-) diff --git a/src/formelement.c b/src/formelement.c index 10f702d..acf4709 100644 --- a/src/formelement.c +++ b/src/formelement.c @@ -184,11 +184,15 @@ zak_form_element_filter (ZakFormElement *element) * @value: * */ -void +gboolean zak_form_element_set_value (ZakFormElement *element, const gchar *value) { ZakFormElementPrivate *priv; + gboolean ret; + + ret = TRUE; + priv = zak_form_element_get_instance_private (element); if (priv->value != NULL) @@ -197,6 +201,13 @@ zak_form_element_set_value (ZakFormElement *element, const gchar *value) } priv->value = g_strdup (value); + + if (ZAK_FORM_ELEMENT_GET_CLASS (element)->set_value != NULL) + { + ret = ZAK_FORM_ELEMENT_GET_CLASS (element)->set_value (element, priv->value); + } + + return ret; } /** @@ -209,9 +220,20 @@ gchar { ZakFormElementPrivate *priv; + gchar *ret; + priv = zak_form_element_get_instance_private (element); - return g_strdup (priv->value); + if (ZAK_FORM_ELEMENT_GET_CLASS (element)->get_value != NULL) + { + ret = ZAK_FORM_ELEMENT_GET_CLASS (element)->get_value (element); + } + else + { + ret = g_strdup (priv->value); + } + + return ret; } /** @@ -220,11 +242,15 @@ gchar * @value: * */ -void +gboolean zak_form_element_set_default_value (ZakFormElement *element, const gchar *value) { ZakFormElementPrivate *priv; + gboolean ret; + + ret = TRUE; + priv = zak_form_element_get_instance_private (element); if (priv->default_value != NULL) @@ -233,6 +259,8 @@ zak_form_element_set_default_value (ZakFormElement *element, const gchar *value) } priv->default_value = g_strdup (value); + + return ret; } /** @@ -256,11 +284,15 @@ gchar * @value: * */ -void +gboolean zak_form_element_set_original_value (ZakFormElement *element, const gchar *value) { ZakFormElementPrivate *priv; + gboolean ret; + + ret = TRUE; + priv = zak_form_element_get_instance_private (element); if (priv->original_value != NULL) @@ -269,6 +301,8 @@ zak_form_element_set_original_value (ZakFormElement *element, const gchar *value } priv->original_value = g_strdup (value); + + return ret; } /** @@ -322,6 +356,11 @@ zak_form_element_set_visible (ZakFormElement *element, gboolean visible) priv = zak_form_element_get_instance_private (element); priv->visible = visible; + + if (ZAK_FORM_ELEMENT_GET_CLASS (element)->set_visible != NULL) + { + ZAK_FORM_ELEMENT_GET_CLASS (element)->set_visible (element, priv->visible); + } } /** @@ -334,9 +373,20 @@ zak_form_element_get_visible (ZakFormElement *element) { ZakFormElementPrivate *priv; + gboolean ret; + priv = zak_form_element_get_instance_private (element); - return priv->visible; + if (ZAK_FORM_ELEMENT_GET_CLASS (element)->get_visible != NULL) + { + ret = ZAK_FORM_ELEMENT_GET_CLASS (element)->get_visible (element); + } + else + { + ret = priv->visible; + } + + return ret; } /** @@ -353,6 +403,11 @@ zak_form_element_set_editable (ZakFormElement *element, gboolean editable) priv = zak_form_element_get_instance_private (element); priv->editable = editable; + + if (ZAK_FORM_ELEMENT_GET_CLASS (element)->set_editable != NULL) + { + ZAK_FORM_ELEMENT_GET_CLASS (element)->set_editable (element, priv->editable); + } } /** @@ -365,9 +420,20 @@ zak_form_element_get_editable (ZakFormElement *element) { ZakFormElementPrivate *priv; + gboolean ret; + priv = zak_form_element_get_instance_private (element); - return priv->editable; + if (ZAK_FORM_ELEMENT_GET_CLASS (element)->get_editable != NULL) + { + ret = ZAK_FORM_ELEMENT_GET_CLASS (element)->get_editable (element); + } + else + { + ret = priv->editable; + } + + return ret; } /** diff --git a/src/formelement.h b/src/formelement.h index 5c0e5af..4f3dc31 100644 --- a/src/formelement.h +++ b/src/formelement.h @@ -36,17 +36,26 @@ struct _ZakFormElementClass { GObjectClass parent_class; + gboolean (*set_value) (ZakFormElement *element, const gchar *value); + gchar *(*get_value) (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); + GPtrArray *(*get_messages) (ZakFormElement *element); }; -void zak_form_element_set_value (ZakFormElement *element, const gchar *value); +gboolean zak_form_element_set_value (ZakFormElement *element, const gchar *value); gchar *zak_form_element_get_value (ZakFormElement *element); -void zak_form_element_set_default_value (ZakFormElement *element, const gchar *value); +gboolean zak_form_element_set_default_value (ZakFormElement *element, const gchar *value); gchar *zak_form_element_get_default_value (ZakFormElement *element); -void zak_form_element_set_original_value (ZakFormElement *element, const gchar *value); +gboolean zak_form_element_set_original_value (ZakFormElement *element, const gchar *value); gchar *zak_form_element_get_original_value (ZakFormElement *element); void zak_form_element_set_as_original_value (ZakFormElement *element); gboolean zak_form_element_is_changed (ZakFormElement *element); -- 2.49.0