/*
- * 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
gchar *name;
GtkWidget *label;
+ gchar *label_name;
};
G_DEFINE_ABSTRACT_TYPE (ZakFormGtkFormElement, zak_form_gtk_form_element, ZAK_FORM_TYPE_ELEMENT)
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",
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
*/
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;
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:
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 */
{
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;
/*
- * 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
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);
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