]> saetta.ns0.it Git - zakform/gtk/commitdiff
Added function ZakFormGtkForm::get_gobjects_by_name.
authorAndrea Zagli <azagli@libero.it>
Fri, 9 Dec 2016 09:05:00 +0000 (10:05 +0100)
committerAndrea Zagli <azagli@libero.it>
Fri, 9 Dec 2016 09:05:00 +0000 (10:05 +0100)
src/form.c
src/form.h

index fcbdd15a070ec4bbe303064a08161a60e5538e69..aa73cf3765b0f9c5db098abac74597c9a4cbd61a 100644 (file)
@@ -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,
index 381251b9a3d1d1e6b389fcf16058ff2906451dbb..688e398c6576954603a9c7b590043da71470c193 100644 (file)
@@ -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