From: Andrea Zagli <azagli@libero.it>
Date: Fri, 9 Dec 2016 09:05:00 +0000 (+0100)
Subject: Added function ZakFormGtkForm::get_gobjects_by_name.
X-Git-Tag: v0.1.0~3
X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=5bedd6b3c296ce9f9f1cbf199959f8986404e04f;p=zakform%2Fgtk

Added function ZakFormGtkForm::get_gobjects_by_name.
---

diff --git a/src/form.c b/src/form.c
index fcbdd15..aa73cf3 100644
--- a/src/form.c
+++ b/src/form.c
@@ -194,6 +194,67 @@ zak_form_gtk_form_is_valid (ZakFormGtkForm *form, GtkWidget *parent_window)
 	return ret;
 }
 
+/**
+ * zak_form_gtk_form_get_gobjects_by_name:
+ * @form: a #ZakFormGtkForm object.
+ * @...: a NULL terminated list of objects name (gchar *) to return.
+ *
+ * Returns: an array of #GObject present in the #GtkBuilder object assigned to
+ * the form. Must be free.
+ */
+GObject
+**zak_form_gtk_form_get_gobjects_by_name (ZakFormGtkForm *form, ...)
+{
+	GObject **ret;
+
+	ZakFormGtkFormPrivate *priv;
+
+	va_list vargs;
+	gchar *object_name;
+	guint l;
+
+	GObject *object;
+
+	g_return_val_if_fail (ZAK_FORM_GTK_IS_FORM (form), NULL);
+
+	priv = ZAK_FORM_GTK_FORM_GET_PRIVATE (form);
+
+	g_return_val_if_fail (GTK_IS_BUILDER (priv->builder), NULL);
+
+	ret = NULL;
+	l = 0;
+
+	va_start (vargs, form);
+
+	while ((object_name = va_arg (vargs, gchar *)) != NULL)
+		{
+			l++;
+			if (l == 1)
+				{
+					ret = g_malloc (sizeof (GObject *));
+				}
+			else
+				{
+					ret = g_realloc (ret, l * sizeof (GObject *));
+				}
+
+			object = gtk_builder_get_object (priv->builder, object_name);
+			if (G_IS_OBJECT (object))
+				{
+					ret[l - 1] = object;
+				}
+			else
+				{
+					ret[l - 1] = NULL;
+					g_warning ("Object «%s» not found.", object_name);
+				}
+		}
+
+	va_end (vargs);
+
+	return ret;
+}
+
 /* PRIVATE */
 static void
 zak_form_gtk_form_set_property (GObject *object,
diff --git a/src/form.h b/src/form.h
index 381251b..688e398 100644
--- a/src/form.h
+++ b/src/form.h
@@ -45,6 +45,8 @@ void zak_form_gtk_form_set_gtkbuilder (ZakFormGtkForm *form, GtkBuilder *builder
 
 gboolean zak_form_gtk_form_is_valid (ZakFormGtkForm *form, GtkWidget *parent_window);
 
+GObject **zak_form_gtk_form_get_gobjects_by_name (ZakFormGtkForm *form, ...);
+
 
 G_END_DECLS