]> saetta.ns0.it Git - zakform/gtk/commitdiff
ZakFormGtkFormElement: added the way to store label name.
authorAndrea Zagli <azagli@libero.it>
Thu, 28 May 2020 07:41:09 +0000 (09:41 +0200)
committerAndrea Zagli <azagli@libero.it>
Thu, 28 May 2020 07:41:09 +0000 (09:41 +0200)
src/formelement.c
src/formelement.h

index 0306f87d8bf690abd0cc293e64c94c4c2d4a3fff..a93fed8913f4bf66e289baecb54397f5f6306469 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015-2017 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2015-2020 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
@@ -66,6 +66,7 @@ struct _ZakFormGtkFormElementPrivate
                gchar *name;
 
                GtkWidget *label;
+               gchar *label_name;
        };
 
 G_DEFINE_ABSTRACT_TYPE (ZakFormGtkFormElement, zak_form_gtk_form_element, ZAK_FORM_TYPE_ELEMENT)
@@ -91,18 +92,18 @@ zak_form_gtk_form_element_class_init (ZakFormGtkFormElementClass *class)
        g_type_class_add_private (object_class, sizeof (ZakFormGtkFormElementPrivate));
 
        g_object_class_install_property (object_class, PROP_GTKBUILDER,
-                                                                        g_param_spec_object ("gtkbuilder",
-                                                                                                                 "GtkBuilder",
-                                                                                                                 "GtkBuilder",
-                                                                                                                 G_TYPE_OBJECT,
-                                                                                                                 G_PARAM_READWRITE));
+                                        g_param_spec_object ("gtkbuilder",
+                                                             "GtkBuilder",
+                                                             "GtkBuilder",
+                                                             G_TYPE_OBJECT,
+                                                             G_PARAM_READWRITE));
 
        g_object_class_install_property (object_class, PROP_WIDGET,
-                                                                        g_param_spec_object ("widget",
-                                                                                                                 "Widget",
-                                                                                                                 "Widget",
-                                                                                                                 GTK_TYPE_WIDGET,
-                                                                                                                 G_PARAM_READABLE));
+                                        g_param_spec_object ("widget",
+                                                             "Widget",
+                                                             "Widget",
+                                                             GTK_TYPE_WIDGET,
+                                                             G_PARAM_READABLE));
 
        g_object_class_install_property (object_class, PROP_NAME,
                                         g_param_spec_string ("name",
@@ -112,11 +113,11 @@ zak_form_gtk_form_element_class_init (ZakFormGtkFormElementClass *class)
                                                              G_PARAM_READABLE));
 
        g_object_class_install_property (object_class, PROP_LABEL,
-                                                                        g_param_spec_object ("label",
-                                                                                                                 "Label",
-                                                                                                                 "Label",
-                                                                                                                 GTK_TYPE_WIDGET,
-                                                                                                                 G_PARAM_READWRITE));
+                                        g_param_spec_object ("label",
+                                                             "Label",
+                                                             "Label",
+                                                             GTK_TYPE_WIDGET,
+                                                             G_PARAM_READWRITE));
 }
 
 static void
@@ -170,8 +171,8 @@ GtkBuilder
  */
 gboolean
 zak_form_gtk_form_element_set_widget_from_gtkbuilder (ZakFormGtkFormElement *element,
-                                                                                                         GtkBuilder *gtkbuilder,
-                                                                                                         const gchar *widget_name)
+                                                      GtkBuilder *gtkbuilder,
+                                                      const gchar *widget_name)
 {
        ZakFormGtkFormElementPrivate *priv;
 
@@ -269,6 +270,21 @@ GtkWidget
        return priv->label;
 }
 
+/**
+ * zak_form_gtk_form_element_get_label_name:
+ * @element:
+ *
+ */
+gchar
+*zak_form_gtk_form_element_get_label_name (ZakFormGtkFormElement *element)
+{
+       ZakFormGtkFormElementPrivate *priv;
+
+       priv = ZAK_FORM_GTK_FORM_ELEMENT_GET_PRIVATE (element);
+
+       return g_strdup (priv->label_name);
+}
+
 /**
  * zak_form_gtk_form_element_set_label:
  * @element:
@@ -289,7 +305,46 @@ zak_form_gtk_form_element_set_label (ZakFormGtkFormElement *element, GtkWidget *
        priv->label = g_object_ref (label);
 
        zak_form_element_set_long_name (ZAK_FORM_ELEMENT (element),
-                                                                       gtk_label_get_text (GTK_LABEL (priv->label)));
+                                       gtk_label_get_text (GTK_LABEL (priv->label)));
+}
+
+/**
+ * zak_form_gtk_form_element_set_label_from_gtkbuilder:
+ * @element:
+ * @gtkbuilder:
+ * @widget_name:
+ *
+ */
+gboolean
+zak_form_gtk_form_element_set_label_from_gtkbuilder (ZakFormGtkFormElement *element,
+                                                     GtkBuilder *gtkbuilder,
+                                                     const gchar *widget_name)
+{
+       ZakFormGtkFormElementPrivate *priv;
+
+       GtkWidget *w;
+
+       g_return_val_if_fail (GTK_IS_BUILDER (gtkbuilder), FALSE);
+       g_return_val_if_fail (widget_name != NULL, FALSE);
+       g_return_val_if_fail (g_strcmp0 (widget_name, "") != 0, FALSE);
+
+       priv = ZAK_FORM_GTK_FORM_ELEMENT_GET_PRIVATE (element);
+
+       priv->builder = gtkbuilder;
+
+       w = GTK_WIDGET (gtk_builder_get_object (gtkbuilder, widget_name));
+       if (w != NULL
+               && GTK_IS_WIDGET (w))
+               {
+                       zak_form_gtk_form_element_set_label (element, w);
+                       priv->label_name = g_strdup (widget_name);
+               }
+       else
+               {
+                       g_warning (_("Widget «%s» not found."), widget_name);
+               }
+
+       return TRUE;
 }
 
 /* PRIVATE */
@@ -416,12 +471,15 @@ zak_form_gtk_form_element_xml_parsing (ZakFormElement *element, xmlNode *xmlnode
                {
                        if (xmlStrcmp (cur->name, (const xmlChar *)"widget") == 0)
                                {
-                                       zak_form_gtk_form_element_set_widget_from_gtkbuilder (ZAK_FORM_GTK_FORM_ELEMENT (element), priv->builder, (gchar *)xmlNodeGetContent (cur));
+                                       zak_form_gtk_form_element_set_widget_from_gtkbuilder (ZAK_FORM_GTK_FORM_ELEMENT (element),
+                                                                                             priv->builder,
+                                                                                             (gchar *)xmlNodeGetContent (cur));
                                }
                        else if (xmlStrcmp (cur->name, (const xmlChar *)"label") == 0)
                                {
-                                       zak_form_gtk_form_element_set_label (ZAK_FORM_GTK_FORM_ELEMENT (element),
-                                                                                                                GTK_WIDGET (gtk_builder_get_object (priv->builder, (gchar *)xmlNodeGetContent (cur))));
+                                       zak_form_gtk_form_element_set_label_from_gtkbuilder (ZAK_FORM_GTK_FORM_ELEMENT (element),
+                                                                                            priv->builder,
+                                                                                            (gchar *)xmlNodeGetContent (cur));
                                }
 
                        cur = cur->next;
index 4440288a6b359200f9fc28e9513328b2d9c8a99a..54b79ed25b950e2b379b5886b3db3171d0d21828 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015-2017 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2015-2020 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
@@ -47,8 +47,8 @@ void zak_form_gtk_form_element_set_gtkbuilder (ZakFormGtkFormElement *element, G
 GtkBuilder *zak_form_gtk_form_element_get_gtkbuilder (ZakFormGtkFormElement *element);
 
 gboolean zak_form_gtk_form_element_set_widget_from_gtkbuilder (ZakFormGtkFormElement *element,
-                                                                                                                          GtkBuilder *gtkbuilder,
-                                                                                                                          const gchar *widget_name);
+                                                               GtkBuilder *gtkbuilder,
+                                                               const gchar *widget_name);
 
 GtkWidget *zak_form_gtk_form_element_get_widget (ZakFormGtkFormElement *element);
 void zak_form_gtk_form_element_set_widget (ZakFormGtkFormElement *element, GtkWidget *widget, const gchar *widget_name);
@@ -58,6 +58,12 @@ gchar *zak_form_gtk_form_element_get_widget_name (ZakFormGtkFormElement *element
 GtkWidget *zak_gtk_form_element_get_label (ZakFormGtkFormElement *element);
 void zak_form_gtk_form_element_set_label (ZakFormGtkFormElement *element, GtkWidget *label);
 
+gboolean zak_form_gtk_form_element_set_label_from_gtkbuilder (ZakFormGtkFormElement *element,
+                                                              GtkBuilder *gtkbuilder,
+                                                              const gchar *widget_name);
+
+gchar *zak_form_gtk_form_element_get_label_name (ZakFormGtkFormElement *element);
+
 
 G_END_DECLS