From: John Darrington Date: Sat, 4 Feb 2012 07:44:05 +0000 (+0100) Subject: New abstract base class: PsppireWindowBase X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fbuilds%2F20120204030502%2Fpspp;p=pspp New abstract base class: PsppireWindowBase Created a new abstract base class for windows/dialogs and moved the psppire_conf manipulation to there. Should fix problems reported by bojo42 where the window geometry wasn't always correctly saved. --- diff --git a/src/ui/gui/automake.mk b/src/ui/gui/automake.mk index 770a5a9a01..560d44af83 100644 --- a/src/ui/gui/automake.mk +++ b/src/ui/gui/automake.mk @@ -252,6 +252,8 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/psppire-vbuttonbox.h \ src/ui/gui/psppire-window.c \ src/ui/gui/psppire-window.h \ + src/ui/gui/psppire-window-base.c \ + src/ui/gui/psppire-window-base.h \ src/ui/gui/psppire-window-register.c \ src/ui/gui/psppire-window-register.h \ src/ui/gui/rank-dialog.c \ diff --git a/src/ui/gui/psppire-dialog.c b/src/ui/gui/psppire-dialog.c index c365ab4b8e..1e4216175b 100644 --- a/src/ui/gui/psppire-dialog.c +++ b/src/ui/gui/psppire-dialog.c @@ -21,11 +21,12 @@ #include "psppire-dialog.h" #include "psppire-buttonbox.h" #include "psppire-selector.h" -#include "psppire-conf.h" #include #include "builder-wrapper.h" #include "help-menu.h" +#include "psppire-window-base.h" + static void psppire_dialog_class_init (PsppireDialogClass *); static void psppire_dialog_init (PsppireDialog *); @@ -69,7 +70,7 @@ psppire_dialog_get_type (void) NULL }; - dialog_type = g_type_register_static (GTK_TYPE_WINDOW, + dialog_type = g_type_register_static (PSPPIRE_TYPE_WINDOW_BASE, "PsppireDialog", &dialog_info, 0); g_type_add_interface_static (dialog_type, @@ -314,37 +315,6 @@ delete_event_callback (GtkWidget *w, GdkEvent *e, gpointer data) } -static gboolean -configure_event_callback (GtkDialog *dialog, - GdkEvent *event, gpointer data) -{ - const gchar *base; - - PsppireConf *conf = psppire_conf_new (); - - if ( ! gtk_widget_get_mapped (GTK_WIDGET (dialog))) - return FALSE; - - base = gtk_buildable_get_name (GTK_BUILDABLE (dialog)); - - psppire_conf_save_window_geometry (conf, base, GTK_WINDOW (dialog)); - - return FALSE; -} - - -static void -on_realize (GtkWindow *dialog, gpointer data) -{ - PsppireConf *conf = psppire_conf_new (); - - const gchar *base = gtk_buildable_get_name (GTK_BUILDABLE (dialog)); - - psppire_conf_set_window_geometry (conf, base, dialog); -} - - - static void psppire_dialog_init (PsppireDialog *dialog) { @@ -366,15 +336,6 @@ psppire_dialog_init (PsppireDialog *dialog) G_CALLBACK (delete_event_callback), dialog); - g_signal_connect (dialog, "configure-event", - G_CALLBACK (configure_event_callback), - dialog); - - g_signal_connect (dialog, "realize", - G_CALLBACK (on_realize), - dialog); - - gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_DIALOG); diff --git a/src/ui/gui/psppire-window-base.c b/src/ui/gui/psppire-window-base.c new file mode 100644 index 0000000000..29c0fd7a58 --- /dev/null +++ b/src/ui/gui/psppire-window-base.c @@ -0,0 +1,106 @@ +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 2012 Free Software Foundation + + 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 3 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, see . */ + +/* + This is an abstract base class upon which all (well almost all) windows in + psppire are based. The exceptions are transient windows such as the + splash screen and popups. + + It currently provides the feature where the window's geometry "persists" + so that she gets the windows appearing in her favourite size/shape/position. +*/ + + +#include + +#include "psppire-window-base.h" +#include "psppire-conf.h" +#include + +#include + +static void psppire_window_base_class_init (PsppireWindowBaseClass *class); +static void psppire_window_base_init (PsppireWindowBase *window); + +G_DEFINE_ABSTRACT_TYPE (PsppireWindowBase, psppire_window_base, GTK_TYPE_WINDOW); + + +/* Obtain a string identifying this window. + + If the window has a name, we use that. + Otherwise we fall back on the class name. + */ +static const char * +get_window_id (GtkWidget *wb) +{ + const gchar *name = NULL; + + g_object_get (wb, "name", &name, NULL); + + if (NULL == name || 0 == strcmp ("", name)) + name = G_OBJECT_TYPE_NAME (wb); + + return name; +} + +/* + On realization, we read the desired geometry from the config, and set the + window accordingly. + */ +static void +realize (GtkWidget *wb) +{ + PsppireConf *conf = psppire_conf_new (); + + psppire_conf_set_window_geometry (conf, get_window_id (wb), GTK_WINDOW (wb)); + + if (GTK_WIDGET_CLASS (psppire_window_base_parent_class)->realize) + return GTK_WIDGET_CLASS (psppire_window_base_parent_class)->realize (wb) ; +} + + +/* + When the window is resized/repositioned, write the new geometry to the config. +*/ +static gboolean +configure_event (GtkWidget *wb, GdkEventConfigure *event) +{ + if (gtk_widget_get_mapped (wb)) + { + PsppireConf *conf = psppire_conf_new (); + + psppire_conf_save_window_geometry (conf, get_window_id (wb), GTK_WINDOW (wb)); + } + + if (GTK_WIDGET_CLASS (psppire_window_base_parent_class)->configure_event) + return GTK_WIDGET_CLASS (psppire_window_base_parent_class)->configure_event (wb, event) ; + + return FALSE; +} + +static void +psppire_window_base_class_init (PsppireWindowBaseClass *class) +{ + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class); + widget_class->configure_event = configure_event; + widget_class->realize = realize; +} + +static void +psppire_window_base_init (PsppireWindowBase *window) +{ +} + diff --git a/src/ui/gui/psppire-window-base.h b/src/ui/gui/psppire-window-base.h new file mode 100644 index 0000000000..5453bb78f8 --- /dev/null +++ b/src/ui/gui/psppire-window-base.h @@ -0,0 +1,73 @@ +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 2012 Free Software Foundation + + 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 3 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, see . */ + +/* + This is an abstract base class upon which all (well almost all) windows in + psppire are based. The exceptions are transient windows such as the + splash screen and popups. +*/ + +#ifndef __PSPPIRE_WINDOW_BASE_H__ +#define __PSPPIRE_WINDOW_BASE_H__ + + +#include +#include +#include + +G_BEGIN_DECLS + + +#define PSPPIRE_TYPE_WINDOW_BASE (psppire_window_base_get_type ()) + +#define PSPPIRE_WINDOW_BASE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + PSPPIRE_TYPE_WINDOW_BASE, PsppireWindowBase)) + +#define PSPPIRE_WINDOW_BASE_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), \ + PSPPIRE_TYPE_WINDOW_BASE, PsppireWindowBaseClass)) + +#define PSPPIRE_IS_WINDOW_BASE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ + PSPPIRE_TYPE_WINDOW_BASE)) + +#define PSPPIRE_IS_WINDOW_BASE_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), \ + PSPPIRE_TYPE_WINDOW_BASE)) + + +typedef struct _PsppireWindowBase PsppireWindowBase; +typedef struct _PsppireWindowBaseClass PsppireWindowBaseClass; + + +struct _PsppireWindowBase +{ + GtkWindow parent; + + /* */ +}; + + +struct _PsppireWindowBaseClass +{ + GtkWindowClass parent_class; +}; + + + +GType psppire_window_base_get_type (void); +GType psppire_window_base_model_get_type (void); + +G_END_DECLS + +#endif /* __PSPPIRE_WINDOW_BASE_H__ */ diff --git a/src/ui/gui/psppire-window.c b/src/ui/gui/psppire-window.c index 4eb274b528..4c7fcf57dc 100644 --- a/src/ui/gui/psppire-window.c +++ b/src/ui/gui/psppire-window.c @@ -17,6 +17,7 @@ #include #include "psppire-window.h" +#include "psppire-window-base.h" #include @@ -32,7 +33,6 @@ #include "data/dataset.h" #include "helper.h" -#include "psppire-conf.h" #include "psppire-data-window.h" #include "psppire-encoding-selector.h" #include "psppire-syntax-window.h" @@ -67,7 +67,7 @@ psppire_window_get_type (void) }; psppire_window_type = - g_type_register_static (GTK_TYPE_WINDOW, "PsppireWindow", + g_type_register_static (PSPPIRE_TYPE_WINDOW_BASE, "PsppireWindow", &psppire_window_info, G_TYPE_FLAG_ABSTRACT); } @@ -229,17 +229,6 @@ psppire_window_get_property (GObject *object, } -static void -on_realize (GtkWindow *window, gpointer data) -{ - PsppireConf *conf = psppire_conf_new (); - - const gchar *base = G_OBJECT_TYPE_NAME (window); - - psppire_conf_set_window_geometry (conf, base, window); -} - - static void psppire_window_finalize (GObject *object) { @@ -423,13 +412,6 @@ on_delete (PsppireWindow *w, GdkEvent *event, gpointer user_data) { PsppireWindowRegister *reg = psppire_window_register_new (); - const gchar *base = G_OBJECT_TYPE_NAME (w); - - PsppireConf *conf = psppire_conf_new (); - - psppire_conf_save_window_geometry (conf, base, GTK_WINDOW (w)); - - if ( w->dirty ) { gint response = psppire_window_query_save (w); @@ -490,9 +472,6 @@ psppire_window_init (PsppireWindow *window) g_signal_connect_swapped (window, "delete-event", G_CALLBACK (on_delete), window); g_object_set (window, "icon-name", "pspp", NULL); - - g_signal_connect (window, "realize", - G_CALLBACK (on_realize), window); } /*