From c1f796a012aa172cf44ed3cf386b0222fa12ab35 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Sat, 3 Jan 2009 21:20:28 +0900 Subject: [PATCH] Added infrastructure for GtkBuilder and change oneway-dialog to use it. --- configure.ac | 3 --- src/ui/gui/automake.mk | 12 +++++++--- src/ui/gui/helper.c | 31 +++++++++++++++++++++---- src/ui/gui/helper.h | 11 ++++----- src/ui/gui/oneway-anova-dialog.c | 40 ++++++++++++++++---------------- src/ui/gui/psppire-dialog.c | 39 +++++++++++++++++++++++++++++++ 6 files changed, 99 insertions(+), 37 deletions(-) diff --git a/configure.ac b/configure.ac index 1abc8043..7a67e600 100644 --- a/configure.ac +++ b/configure.ac @@ -46,9 +46,6 @@ AC_ARG_WITH( [AS_HELP_STRING([--without-gui], [don't build the PSPPIRE gui])]) required_gtk_version=2.12 -if test x"$enable_anachronistic_dependencies" = x"yes" ; then - required_gtk_version=2.8.20 -fi if test x"$with_gui" != x"no" ; then PKG_CHECK_MODULES(GTK, gtk+-2.0 >= $required_gtk_version,, diff --git a/src/ui/gui/automake.mk b/src/ui/gui/automake.mk index 57d9163c..3f5d3076 100644 --- a/src/ui/gui/automake.mk +++ b/src/ui/gui/automake.mk @@ -64,6 +64,12 @@ src_ui_gui_psppire_LDADD = \ src_ui_gui_psppiredir = $(pkgdatadir) +nodist_src_ui_gui_psppire_DATA = \ + $(top_srcdir)/src/ui/gui/oneway.ui + +EXTRA_DIST += \ + $(top_srcdir)/src/ui/gui/oneway.glade + dist_src_ui_gui_psppire_DATA = \ $(top_srcdir)/src/ui/gui/data-editor.glade \ $(top_srcdir)/src/ui/gui/descriptives-dialog.glade \ @@ -71,7 +77,6 @@ dist_src_ui_gui_psppire_DATA = \ $(top_srcdir)/src/ui/gui/crosstabs.glade \ $(top_srcdir)/src/ui/gui/frequencies.glade \ $(top_srcdir)/src/ui/gui/message-dialog.glade \ - $(top_srcdir)/src/ui/gui/oneway.glade \ $(top_srcdir)/src/ui/gui/output-viewer.glade \ $(top_srcdir)/src/ui/gui/psppire.glade \ $(top_srcdir)/src/ui/gui/rank.glade \ @@ -207,8 +212,6 @@ nodist_src_ui_gui_psppire_SOURCES = \ src/ui/gui/psppire-marshal.h - - yelp-check: @if ! yelp --version > /dev/null 2>&1 ; then \ echo ; \ @@ -228,6 +231,9 @@ src/ui/gui/psppire-marshal.c: src/ui/gui/marshaller-list src/ui/gui/psppire-marshal.h: src/ui/gui/marshaller-list glib-genmarshal --header --prefix=psppire_marshal $< > $@ +.glade.ui: + gtk-builder-convert $< $@ + EXTRA_DIST += src/ui/gui/OChangeLog\ src/ui/gui/marshaller-list diff --git a/src/ui/gui/helper.c b/src/ui/gui/helper.c index bae608af..fc9105d7 100644 --- a/src/ui/gui/helper.c +++ b/src/ui/gui/helper.c @@ -32,6 +32,7 @@ #include #include +#include #include #include @@ -100,14 +101,35 @@ text_to_value (const gchar *text, union value *v, } +GtkBuilder * +builder_new_real (const gchar *name) +{ + GtkBuilder *builder = gtk_builder_new (); + + GError *err = NULL; + if ( ! gtk_builder_add_from_file (builder, name, &err)) + { + g_critical ("Couldnt open user interface file %s: %s", name, err->message); + g_clear_error (&err); + } + + return builder; +} + + + GtkWidget * -get_widget_assert (GladeXML *xml, const gchar *name) +get_widget_assert (gpointer x, const gchar *name) { - GtkWidget *w; - g_assert (xml); + GObject *obj = G_OBJECT (x); + GtkWidget *w = NULL; g_assert (name); - w = glade_xml_get_widget (xml, name); + if (GTK_IS_BUILDER (obj)) + w = GTK_WIDGET (gtk_builder_get_object (GTK_BUILDER (obj), name)); + + if (GLADE_IS_XML (obj)) + w = glade_xml_get_widget (GLADE_XML (obj), name); if ( !w ) g_critical ("Widget \"%s\" could not be found\n", name); @@ -297,3 +319,4 @@ clone_list_store (const GtkListStore *src) } + diff --git a/src/ui/gui/helper.h b/src/ui/gui/helper.h index 1a620908..d08a1752 100644 --- a/src/ui/gui/helper.h +++ b/src/ui/gui/helper.h @@ -43,7 +43,7 @@ gchar * value_to_text (union value v, struct fmt_spec format); gboolean text_to_value (const gchar *text, union value *v, struct fmt_spec format); -GtkWidget * get_widget_assert (GladeXML *xml, const gchar *name); +GtkWidget * get_widget_assert (gpointer x, const gchar *name); /* Converts a string in the pspp locale to utf-8 */ char * pspp_locale_to_utf8 (const gchar *text, gssize len, GError **err); @@ -60,12 +60,9 @@ gboolean execute_syntax (struct getl_interface *sss); glade_xml_new (relocate(PKGDATADIR "/" FILE), NULL, NULL) -void marshaller_VOID__INT_INT_INT (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data); +#define builder_new(NAME) builder_new_real (relocate (PKGDATADIR "/" NAME)) + +GtkBuilder *builder_new_real (const gchar *name); /* Create a deep copy of SRC */ diff --git a/src/ui/gui/oneway-anova-dialog.c b/src/ui/gui/oneway-anova-dialog.c index 13f36210..59b65b4a 100644 --- a/src/ui/gui/oneway-anova-dialog.c +++ b/src/ui/gui/oneway-anova-dialog.c @@ -17,7 +17,6 @@ #include -#include #include #include "oneway-anova-dialog.h" #include "psppire-dict.h" @@ -121,6 +120,7 @@ refresh (struct oneway_anova_dialog *ow) } + /* Pops up the dialog box */ void oneway_anova_dialog (GObject *o, gpointer data) @@ -130,43 +130,43 @@ oneway_anova_dialog (GObject *o, gpointer data) PsppireVarStore *vs = NULL; - GladeXML *xml = XML_NEW ("oneway.glade"); - struct oneway_anova_dialog ow; + GtkBuilder *builder = builder_new ("oneway.ui"); + GtkWidget *dict_view = - get_widget_assert (xml, "oneway-anova-treeview1"); + get_widget_assert (builder, "oneway-anova-treeview1"); GtkWidget *selector2 = - get_widget_assert (xml, "oneway-anova-selector2"); + get_widget_assert (builder, "oneway-anova-selector2"); GtkWidget *selector1 = - get_widget_assert (xml, "oneway-anova-selector1"); + get_widget_assert (builder, "oneway-anova-selector1"); GtkWidget *contrasts_button = - get_widget_assert (xml, "contrasts-button"); + get_widget_assert (builder, "contrasts-button"); g_signal_connect_swapped (contrasts_button, "clicked", G_CALLBACK (run_contrasts_dialog), &ow); - ow.factor_entry = get_widget_assert (xml, "oneway-anova-entry"); + ow.factor_entry = get_widget_assert (builder, "oneway-anova-entry"); ow.vars_treeview = - get_widget_assert (xml, "oneway-anova-treeview2"); + get_widget_assert (builder, "oneway-anova-treeview2"); ow.descriptives = - GTK_TOGGLE_BUTTON (get_widget_assert (xml, "checkbutton1")); + GTK_TOGGLE_BUTTON (get_widget_assert (builder, "checkbutton1")); ow.homogeneity = - GTK_TOGGLE_BUTTON (get_widget_assert (xml, "checkbutton2")); + GTK_TOGGLE_BUTTON (get_widget_assert (builder, "checkbutton2")); g_object_get (de->data_editor, "var-store", &vs, NULL); ow.dict = vs->dict; ow.dialog = - GTK_WINDOW (get_widget_assert (xml, "oneway-anova-dialog")); + GTK_WINDOW (get_widget_assert (builder, "oneway-anova-dialog")); gtk_window_set_transient_for (ow.dialog, de->parent.window); @@ -202,16 +202,16 @@ oneway_anova_dialog (GObject *o, gpointer data) { struct contrasts_subdialog *cd = &ow.contrasts; - GtkEntry *entry = GTK_ENTRY (get_widget_assert (xml, "entry1")); + GtkEntry *entry = GTK_ENTRY (get_widget_assert (builder, "entry1")); - cd->acr = PSPPIRE_ACR (get_widget_assert (xml, "psppire-acr1")); - cd->contrasts_dialog = get_widget_assert (xml, "contrasts-dialog"); + cd->acr = PSPPIRE_ACR (get_widget_assert (builder, "psppire-acr1")); + cd->contrasts_dialog = get_widget_assert (builder, "contrasts-dialog"); - cd->next = get_widget_assert (xml, "next-button"); - cd->prev = get_widget_assert (xml, "prev-button"); - cd->ctotal = get_widget_assert (xml, "entry2"); + cd->next = get_widget_assert (builder, "next-button"); + cd->prev = get_widget_assert (builder, "prev-button"); + cd->ctotal = get_widget_assert (builder, "entry2"); - cd->stack_label = get_widget_assert (xml, "contrast-stack-label"); + cd->stack_label = get_widget_assert (builder, "contrast-stack-label"); /* Contrasts */ ow.contrasts_array = g_array_new (FALSE, FALSE, sizeof (GtkListStore *)); @@ -256,7 +256,7 @@ oneway_anova_dialog (GObject *o, gpointer data) g_array_free (ow.contrasts_array, FALSE); - g_object_unref (xml); + g_object_unref (builder); } diff --git a/src/ui/gui/psppire-dialog.c b/src/ui/gui/psppire-dialog.c index 24d90896..99e0ad7c 100644 --- a/src/ui/gui/psppire-dialog.c +++ b/src/ui/gui/psppire-dialog.c @@ -19,6 +19,7 @@ #include #include +#include #include "psppire-dialog.h" #include "psppire-buttonbox.h" #include "psppire-selector.h" @@ -34,6 +35,9 @@ enum {DIALOG_REFRESH, static guint signals [n_SIGNALS]; +static void psppire_dialog_buildable_init (GtkBuildableIface *iface); + + GType psppire_dialog_get_type (void) { @@ -54,8 +58,20 @@ psppire_dialog_get_type (void) (GInstanceInitFunc) psppire_dialog_init, }; + static const GInterfaceInfo buildable_info = + { + (GInterfaceInitFunc) psppire_dialog_buildable_init, + NULL, + NULL + }; + dialog_type = g_type_register_static (GTK_TYPE_WINDOW, "PsppireDialog", &dialog_info, 0); + + g_type_add_interface_static (dialog_type, + GTK_TYPE_BUILDABLE, + &buildable_info); + } return dialog_type; @@ -475,3 +491,26 @@ psppire_dialog_set_valid_predicate (PsppireDialog *dialog, } + + + +static GObject * +get_internal_child (GtkBuildable *buildable, + GtkBuilder *builder, + const gchar *childname) +{ + PsppireDialog *dialog = PSPPIRE_DIALOG (buildable); + + if ( 0 == strcmp(childname, "hbox")) + return G_OBJECT (dialog->box); + + return NULL; +} + + + +static void +psppire_dialog_buildable_init (GtkBuildableIface *iface) +{ + iface->get_internal_child = get_internal_child; +} -- 2.30.2