From a5afbddc5156864a23e028d1619af222b2f8c199 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Thu, 26 Nov 2015 20:57:53 +0100 Subject: [PATCH] Starting test. --- src/Makefile.am | 17 +++ src/form.c | 34 +++++- src/form.h | 4 + src/formelement.c | 13 +- src/formelement.h | 2 +- tests/Makefile.am | 9 +- tests/test.c | 50 ++++++++ tests/test.ui | 294 ++++++++++++++++++++++++++++++++++++++++++++++ tests/test.xml | 57 +++++++++ 9 files changed, 472 insertions(+), 8 deletions(-) create mode 100644 tests/test.c create mode 100644 tests/test.ui create mode 100644 tests/test.xml diff --git a/src/Makefile.am b/src/Makefile.am index f6a23b2..5acf7be 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,3 +1,13 @@ +if PLATFORM_WIN32 +libmodulesext = -0.dll +libmodulesdir = $(bindir) +else +libmodulesext = .so +libmodulesdir = $(libdir) +endif + +libzakformmodulesdir = `pkg-config --variable=modulesdir libzakform` + LIBS = $(ZAKFORMGTK_LIBS) AM_CPPFLAGS = $(ZAKFORMGTK_CFLAGS) \ @@ -30,3 +40,10 @@ libzakformgtk_include_HEADERS = \ formelementtextview.h libzakformgtk_includedir = $(includedir)/libzakformgtk + +install-exec-hook: + cd $(libzakformmodulesdir) && \ + ln -s -f $(libmodulesdir)/libzakformgtk$(libmodulesext) . + +uninstall-hook: + rm -f $(libzakformmodulesdir)/libzakformgtk$(libmodulesext) diff --git a/src/form.c b/src/form.c index ddd0578..6449682 100644 --- a/src/form.c +++ b/src/form.c @@ -23,6 +23,7 @@ #include #include "form.h" +#include "formelement.h" static void zak_form_gtk_form_class_init (ZakFormGtkFormClass *class); static void zak_form_gtk_form_init (ZakFormGtkForm *zak_form_gtk_form); @@ -39,12 +40,14 @@ static void zak_form_gtk_form_get_property (GObject *object, static void zak_form_gtk_form_dispose (GObject *gobject); static void zak_form_gtk_form_finalize (GObject *gobject); +static void zak_form_gtk_form_element_added (ZakFormGtkForm *form, ZakFormGtkFormElement *element); + #define ZAK_FORM_GTK_FORM_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_FORM_GTK_TYPE_FORM, ZakFormGtkFormPrivate)) typedef struct _ZakFormGtkFormPrivate ZakFormGtkFormPrivate; struct _ZakFormGtkFormPrivate { - gpointer nothing; + GtkBuilder *builder;; }; G_DEFINE_TYPE (ZakFormGtkForm, zak_form_gtk_form, ZAK_FORM_TYPE_FORM) @@ -53,12 +56,15 @@ static void zak_form_gtk_form_class_init (ZakFormGtkFormClass *class) { GObjectClass *object_class = G_OBJECT_CLASS (class); + ZakFormFormClass *parent_class = ZAK_FORM_FORM_CLASS (class); object_class->set_property = zak_form_gtk_form_set_property; object_class->get_property = zak_form_gtk_form_get_property; object_class->dispose = zak_form_gtk_form_dispose; object_class->finalize = zak_form_gtk_form_finalize; + parent_class->element_added = zak_form_gtk_form_element_added; + g_type_class_add_private (object_class, sizeof (ZakFormGtkFormPrivate)); } @@ -66,6 +72,8 @@ static void zak_form_gtk_form_init (ZakFormGtkForm *zak_form_gtk_form) { ZakFormGtkFormPrivate *priv = ZAK_FORM_GTK_FORM_GET_PRIVATE (zak_form_gtk_form); + + priv->builder = NULL; } /** @@ -86,6 +94,22 @@ ZakFormGtkForm return zak_form_gtk_form; } +/** + * zak_form_gtk_form_set_gtkbuilder: + * @form: + * @builder: + * + */ +void +zak_form_gtk_form_set_gtkbuilder (ZakFormGtkForm *form, GtkBuilder *builder) +{ + ZakFormGtkFormPrivate *priv; + + priv = ZAK_FORM_GTK_FORM_GET_PRIVATE (form); + + priv->builder = builder; +} + /* PRIVATE */ static void zak_form_gtk_form_set_property (GObject *object, @@ -142,3 +166,11 @@ zak_form_gtk_form_finalize (GObject *gobject) GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject)); parent_class->finalize (gobject); } + +static void +zak_form_gtk_form_element_added (ZakFormGtkForm *form, ZakFormGtkFormElement *element) +{ + ZakFormGtkFormPrivate *priv = ZAK_FORM_GTK_FORM_GET_PRIVATE (form); + + zak_form_gtk_form_element_set_gtkbuilder (element, priv->builder); +} diff --git a/src/form.h b/src/form.h index 73d3d93..56ee14d 100644 --- a/src/form.h +++ b/src/form.h @@ -22,6 +22,8 @@ #include +#include + #include @@ -39,6 +41,8 @@ struct _ZakFormGtkFormClass ZakFormGtkForm *zak_form_gtk_form_new (void); +void zak_form_gtk_form_set_gtkbuilder (ZakFormGtkForm *form, GtkBuilder *builder); + G_END_DECLS diff --git a/src/formelement.c b/src/formelement.c index 88a26a3..57281d8 100644 --- a/src/formelement.c +++ b/src/formelement.c @@ -114,7 +114,7 @@ zak_form_gtk_form_element_class_init (ZakFormGtkFormElementClass *class) "Label", "Label", GTK_TYPE_WIDGET, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); + G_PARAM_READWRITE)); } static void @@ -160,14 +160,14 @@ GtkBuilder } /** - * zak_form_gtk_form_element_widget_set_from_gtkbuilder: + * zak_form_gtk_form_element_set_widget_from_gtkbuilder: * @element: * @gtkbuilder: * @widget_name: * */ gboolean -zak_form_gtk_form_element_widget_set_from_gtkbuilder (ZakFormGtkFormElement *element, +zak_form_gtk_form_element_set_widget_from_gtkbuilder (ZakFormGtkFormElement *element, GtkBuilder *gtkbuilder, const gchar *widget_name) { @@ -411,7 +411,12 @@ zak_form_gtk_form_element_xml_parsing (ZakFormElement *element, xmlNode *xmlnode { if (xmlStrcmp (cur->name, (const xmlChar *)"widget") == 0) { - zak_form_gtk_form_element_widget_set_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)))); } cur = cur->next; diff --git a/src/formelement.h b/src/formelement.h index a9c88c0..91a71cb 100644 --- a/src/formelement.h +++ b/src/formelement.h @@ -47,7 +47,7 @@ struct _ZakFormGtkFormElementClass void zak_form_gtk_form_element_set_gtkbuilder (ZakFormGtkFormElement *element, GtkBuilder *gtkbuilder); GtkBuilder *zak_form_gtk_form_element_get_gtkbuilder (ZakFormGtkFormElement *element); -gboolean zak_form_gtk_form_element_widget_set_from_gtkbuilder (ZakFormGtkFormElement *element, +gboolean zak_form_gtk_form_element_set_widget_from_gtkbuilder (ZakFormGtkFormElement *element, GtkBuilder *gtkbuilder, const gchar *widget_name); diff --git a/tests/Makefile.am b/tests/Makefile.am index 6fa87f6..af3533e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,11 +1,16 @@ AM_CPPFLAGS = $(WARN_CFLAGS) \ $(DISABLE_DEPRECATED_CFLAGS) \ $(ZAKFORMGTK_CFLAGS) \ - -I$(top_srcdir)/src + -I$(top_srcdir)/src \ + -DGUIDIR="\"@abs_builddir@\"" LIBS = $(ZAKFORMGTK_LIBS) \ -export-dynamic LDADD = $(top_builddir)/src/libzakformgtk.la -noinst_PROGRAMS = +noinst_PROGRAMS = \ + test + +EXTRA_DIST = \ + test.xml diff --git a/tests/test.c b/tests/test.c new file mode 100644 index 0000000..ca979c7 --- /dev/null +++ b/tests/test.c @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2015 Andrea Zagli + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include + +#include "form.h" + +int +main (int argc, char *argv[]) +{ + GtkBuilder *builder; + GtkWidget *w; + + ZakFormGtkForm *form; + + gtk_init (&argc, &argv); + + builder = gtk_builder_new (); + gtk_builder_add_objects_from_file (builder, GUIDIR "/test.ui", g_strsplit ("w_main", "|", -1), NULL); + + w = GTK_WIDGET (gtk_builder_get_object (builder, "w_main")); + + g_signal_connect (w, "delete-event", + gtk_main_quit, NULL); + + form = zak_form_gtk_form_new (); + zak_form_gtk_form_set_gtkbuilder (form, builder); + zak_form_form_load_from_file (ZAK_FORM_FORM (form), GUIDIR "/test.xml"); + + gtk_widget_show_all (w); + + gtk_main (); + + return 0; +} diff --git a/tests/test.ui b/tests/test.ui new file mode 100644 index 0000000..505bfe3 --- /dev/null +++ b/tests/test.ui @@ -0,0 +1,294 @@ + + + + + + False + + + True + False + 5 + 5 + 5 + 5 + vertical + 5 + + + True + False + True + 5 + 5 + + + True + False + ID + 0 + + + 0 + 0 + + + + + True + False + True + 0 + + + 1 + 0 + + + + + True + False + Name + 0 + + + 0 + 1 + + + + + True + True + 200 + False + False + + + 1 + 1 + + + + + True + False + Age + 0 + + + 0 + 2 + + + + + True + True + 1 + False + False + adjustment2 + 1 + 1 + + + 1 + 2 + + + + + True + False + Married + 0 + + + 0 + 3 + + + + + True + True + False + True + 0 + True + + + 1 + 3 + + + + + True + False + Description + 0 + 0 + + + 0 + 4 + + + + + True + True + True + + + True + True + + + + + 1 + 4 + + + + + True + False + Birthday + 0 + + + 0 + 5 + + + + + True + True + 10 + • + False + False + + + 1 + 5 + + + + + True + False + Sex + 0 + + + 0 + 6 + + + + + True + False + + + None + True + True + False + 0 + True + True + + + True + True + 0 + + + + + Male + True + True + False + 0 + True + rbtnNone + + + True + True + 1 + + + + + Female + True + True + False + 0 + True + rbtnNone + + + True + True + 2 + + + + + 1 + 6 + + + + + True + False + Income + 0 + + + 0 + 7 + + + + + True + True + • + False + False + + + 1 + 7 + + + + + False + True + 0 + + + + + + + + + + + + diff --git a/tests/test.xml b/tests/test.xml new file mode 100644 index 0000000..c7a8584 --- /dev/null +++ b/tests/test.xml @@ -0,0 +1,57 @@ + + + + + lbl_id + + + + + + -- 2.49.0