Remove deprecated objects GtkAction and GtkUIManager
[pspp] / src / ui / gui / psppire-window-base.c
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2012  Free Software Foundation
3
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.
8
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.
13
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/>. */
16
17 /*
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.
21
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.
24 */
25
26
27 #include <config.h>
28
29 #include "psppire-window-base.h"
30 #include "psppire-conf.h"
31 #include <string.h>
32
33 #include <gtk/gtk.h>
34
35 static void psppire_window_base_class_init    (PsppireWindowBaseClass *class);
36 static void psppire_window_base_init          (PsppireWindowBase      *window);
37
38 G_DEFINE_ABSTRACT_TYPE (PsppireWindowBase, psppire_window_base, GTK_TYPE_APPLICATION_WINDOW);
39
40
41 /* Obtain a string identifying this window.
42
43    If the window has a name, we use that.
44    Otherwise we fall back on the class name.
45  */
46 static const char *
47 get_window_id (GtkWidget *wb)
48 {
49   const gchar *name = gtk_widget_get_name (wb);
50   if (NULL == name || 0 == strcmp ("", name))
51     name = G_OBJECT_TYPE_NAME (wb);
52
53   return name;
54 }
55
56 /*
57   On realization, we read the desired geometry from the config, and set the
58   window accordingly.
59  */
60 static void
61 realize (GtkWidget *wb)
62 {
63   PsppireConf *conf = psppire_conf_new ();
64
65   psppire_conf_set_window_geometry (conf, get_window_id (wb), GTK_WINDOW (wb));
66
67   if (GTK_WIDGET_CLASS (psppire_window_base_parent_class)->realize)
68     return GTK_WIDGET_CLASS (psppire_window_base_parent_class)->realize (wb) ;
69 }
70
71
72 /*
73   When the window is resized/repositioned, write the new geometry to the config.
74 */
75 static gboolean
76 configure_event (GtkWidget *wb, GdkEventConfigure *event)
77 {
78   if (gtk_widget_get_mapped (wb))
79     {
80       PsppireConf *conf = psppire_conf_new ();
81
82       psppire_conf_save_window_geometry (conf, get_window_id (wb), GTK_WINDOW (wb));
83     }
84
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) ;
87
88   return FALSE;
89 }
90
91 static void 
92 psppire_window_base_class_init    (PsppireWindowBaseClass *class)
93 {
94   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
95   widget_class->configure_event = configure_event;
96   widget_class->realize = realize;
97 }
98
99 static void 
100 psppire_window_base_init          (PsppireWindowBase      *window)
101 {
102 }
103