Convenience functions for setting/retrieving window geometry.
authorJohn Darrington <john@darrington.wattle.id.au>
Wed, 4 Mar 2009 00:22:46 +0000 (09:22 +0900)
committerJohn Darrington <john@darrington.wattle.id.au>
Wed, 4 Mar 2009 00:22:46 +0000 (09:22 +0900)
Created a pair of convenience functions in psppire-conf.c to
perform saving and loading of window geometry.  Updated
psppire-window.c to use them.

src/ui/gui/psppire-conf.c
src/ui/gui/psppire-conf.h
src/ui/gui/psppire-window.c

index c7d7cbe3bbe7f1d49a98c87f688eff5585e03f47..36ef97f44fe9de1dcdea27c0cbbda34ec821c318 100644 (file)
@@ -185,3 +185,49 @@ psppire_conf_set_int (PsppireConf *conf,
   conf_write (conf);
 }
 
+
+
+/*
+  A convenience function to set the geometry of a
+  window from from a saved config
+*/
+void
+psppire_conf_set_window_geometry (PsppireConf *conf,
+                                 const gchar *base,
+                                 GtkWindow *window)
+{
+  gint height, width;
+  gint x, y;
+
+  if (psppire_conf_get_int (conf, base, "height", &height)
+      &&
+      psppire_conf_get_int (conf, base, "width", &width) )
+    {
+      gtk_window_set_default_size (window, width, height);
+    }
+
+  if ( psppire_conf_get_int (conf, base, "x", &x)
+       &&
+       psppire_conf_get_int (conf, base, "y", &y) )
+    {
+      gtk_window_move (window, x, y);
+    }
+}
+
+
+/*
+   A convenience function to save the window geometry.
+   This should typically be called from a window's
+   "configure-event" signal handler
+ */
+void
+psppire_conf_save_window_geometry (PsppireConf *conf,
+                                  const gchar *base,
+                                  GdkEventConfigure *event)
+{
+  psppire_conf_set_int (conf, base, "height", event->height);
+  psppire_conf_set_int (conf, base, "width", event->width);
+
+  psppire_conf_set_int (conf, base, "x", event->x);
+  psppire_conf_set_int (conf, base, "y", event->y);
+}
index f98c25a095689e132962a96ca23dda2f8d8bcacd..b98c1e65ffd7e0607a8970e060e7162eef951ae9 100644 (file)
@@ -18,6 +18,8 @@
 #include <glib-object.h>
 #include <glib.h>
 
+#include <gtk/gtkwindow.h>
+
 #ifndef __PSPPIRE_CONF_H__
 #define __PSPPIRE_CONF_H__
 
@@ -80,6 +82,14 @@ void psppire_conf_set_int (PsppireConf *conf,
                           const gchar *base, const gchar *name,
                           gint value);
 
+void psppire_conf_set_window_geometry (PsppireConf *conf,
+                                      const gchar *base,
+                                      GtkWindow *window);
+
+void psppire_conf_save_window_geometry (PsppireConf *,
+                                       const gchar *,
+                                       GdkEventConfigure *);
+
 
 G_END_DECLS
 
index 5de6afd84a8e416ea23275d7c04a5cc151917670..628ed45cb2ec56426820edda1525600d6b1e9df9 100644 (file)
@@ -194,42 +194,22 @@ psppire_window_get_property (GObject         *object,
 static void
 on_realize (GtkWindow *window, gpointer data)
 {
-  gint height, width;
-  gint x, y;
-
   PsppireConf *conf = psppire_conf_new ();
 
   const gchar *base = G_OBJECT_TYPE_NAME (window);
 
-  if (psppire_conf_get_int (conf, base, "height", &height)
-      &&
-      psppire_conf_get_int (conf, base, "width", &width) )
-    {
-      gtk_window_set_default_size (window, width, height);
-    }
-
-
-  if ( psppire_conf_get_int (conf, base, "x", &x)
-       &&
-       psppire_conf_get_int (conf, base, "x", &y) )
-    {
-      gtk_window_move (window, x, y);
-    }
-
+  psppire_conf_set_window_geometry (conf, base, window);
 }
 
 
 static gboolean
-on_configure (GtkWidget *w, GdkEventConfigure *event, gpointer data)
+on_configure (GtkWidget *window, GdkEventConfigure *event, gpointer data)
 {
-  const gchar *base = G_OBJECT_TYPE_NAME (w);
+  const gchar *base = G_OBJECT_TYPE_NAME (window);
 
   PsppireConf *conf = psppire_conf_new ();
 
-  psppire_conf_set_int (conf, base, "height", event->height);
-  psppire_conf_set_int (conf, base, "width", event->width);
-  psppire_conf_set_int (conf, base, "x", event->x);
-  psppire_conf_set_int (conf, base, "y", event->y);
+  psppire_conf_save_window_geometry (conf, base, event);
 
   return FALSE;
 }