1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2012 Free Software Foundation
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 This is an abstract base class upon which all (well almost all) windows in
19 psppire are based. The exceptions are transient windows such as the
20 splash screen and popups.
22 It currently provides the feature where the window's geometry "persists"
23 so that she gets the windows appearing in her favourite size/shape/position.
29 #include "psppire-window-base.h"
30 #include "psppire-conf.h"
35 static void psppire_window_base_class_init (PsppireWindowBaseClass *class);
36 static void psppire_window_base_init (PsppireWindowBase *window);
38 G_DEFINE_ABSTRACT_TYPE (PsppireWindowBase, psppire_window_base, GTK_TYPE_APPLICATION_WINDOW);
41 /* Obtain a string identifying this window.
43 If the window has a name, we use that.
44 Otherwise we fall back on the class name.
47 get_window_id (GtkWidget *wb)
49 const gchar *name = gtk_widget_get_name (wb);
50 if (NULL == name || 0 == strcmp ("", name))
51 name = G_OBJECT_TYPE_NAME (wb);
57 On realization, we read the desired geometry from the config, and set the
61 realize (GtkWidget *wb)
63 PsppireConf *conf = psppire_conf_new ();
65 psppire_conf_set_window_geometry (conf, get_window_id (wb), GTK_WINDOW (wb));
67 if (GTK_WIDGET_CLASS (psppire_window_base_parent_class)->realize)
68 return GTK_WIDGET_CLASS (psppire_window_base_parent_class)->realize (wb) ;
73 When the window is resized/repositioned, write the new geometry to the config.
76 configure_event (GtkWidget *wb, GdkEventConfigure *event)
78 if (gtk_widget_get_mapped (wb))
80 PsppireConf *conf = psppire_conf_new ();
82 psppire_conf_save_window_geometry (conf, get_window_id (wb), GTK_WINDOW (wb));
85 if (GTK_WIDGET_CLASS (psppire_window_base_parent_class)->configure_event)
86 return GTK_WIDGET_CLASS (psppire_window_base_parent_class)->configure_event (wb, event) ;
92 psppire_window_base_class_init (PsppireWindowBaseClass *class)
94 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
95 widget_class->configure_event = configure_event;
96 widget_class->realize = realize;
100 psppire_window_base_init (PsppireWindowBase *window)