Much better scoping of the window code. Minor rename of functions and update header appropriately.
#include "modules.h"
-#define MAX_WINDOWS 1024
-
/* FIXME LOCALEDIR must be configured by ./configure --localedir */
/* But something does not work actually. */
/* So, we need to redefine this variable on windows. */
#define LOCALEDIR "locale"
#endif
-static guint window_count = 0;
-
-static VikWindow *new_window ();
-static void open_window ( VikWindow *vw, GSList *files );
-static void statusbar_update ( VikWindow *vw, const gchar *message );
-static void destroy( GtkWidget *widget,
- gpointer data );
-
#if GLIB_CHECK_VERSION (2, 32, 0)
/* Callback to log message */
static void log_debug(const gchar *log_domain,
}
#endif
-/* Another callback */
-static void destroy( GtkWidget *widget,
- gpointer data )
-{
- if ( ! --window_count )
- gtk_main_quit ();
-}
-
-// Only here because other signal handlers are!
-// TODO: why can't we just move all these into VikWindow and be done with it?!
-static void statusbar_update ( VikWindow *vw, const gchar *message )
-{
- vik_window_statusbar_update ( vw, message );
-}
-
-static VikWindow *new_window ()
-{
- if ( window_count < MAX_WINDOWS )
- {
- VikWindow *vw = vik_window_new ();
-
- g_signal_connect (G_OBJECT (vw), "destroy",
- G_CALLBACK (destroy), NULL);
- g_signal_connect (G_OBJECT (vw), "newwindow",
- G_CALLBACK (new_window), NULL);
- g_signal_connect (G_OBJECT (vw), "openwindow",
- G_CALLBACK (open_window), NULL);
- g_signal_connect (G_OBJECT (vw), "statusbarupdate",
- G_CALLBACK (statusbar_update), NULL);
-
- gtk_widget_show_all ( GTK_WIDGET(vw) );
-
- window_count++;
-
- return vw;
- }
- return NULL;
-}
-
-static void open_window ( VikWindow *vw, GSList *files )
-{
- gboolean change_fn = (g_slist_length(files) == 1); /* only change fn if one file */
- GSList *cur_file = files;
- while ( cur_file ) {
- // Only open a new window if a viking file
- gchar *file_name = cur_file->data;
- if (vw != NULL && check_file_magic_vik ( file_name ) ) {
- VikWindow *newvw = new_window();
- if (newvw)
- vik_window_open_file ( newvw, file_name, change_fn );
- }
- else {
- vik_window_open_file ( vw, file_name, change_fn );
- }
- g_free (file_name);
- cur_file = g_slist_next (cur_file);
- }
- g_slist_free (files);
-}
-
/* Options */
static GOptionEntry entries[] =
{
gtk_window_set_default_icon(main_icon);
/* Create the first window */
- first_window = new_window();
+ first_window = vik_window_new_window();
gdk_threads_enter ();
while ( ++i < argc ) {
#include <gio/gio.h>
#include <gdk/gdkkeysyms.h>
+// This seems rather arbitary, quite large and pointless
+// I mean, if you have a thousand windows open;
+// why not be allowed to open a thousand more...
+#define MAX_WINDOWS 1024
+static guint window_count = 0;
+
#define VIKING_WINDOW_WIDTH 1000
#define VIKING_WINDOW_HEIGHT 800
#define DRAW_IMAGE_DEFAULT_WIDTH 1280
static void window_class_init ( VikWindowClass *klass );
static void window_set_filename ( VikWindow *vw, const gchar *filename );
+static VikWindow *window_new ();
+
static void draw_update ( VikWindow *vw );
static void newwindow_cb ( GtkAction *a, VikWindow *vw );
+// Signals
+static void open_window ( VikWindow *vw, GSList *files );
+static void statusbar_update ( VikWindow *vw, const gchar *message );
+static void destroy_window ( GtkWidget *widget,
+ gpointer data );
+
/* Drawing & stuff */
static gboolean delete_event( VikWindow *vw );
g_idle_add ( (GSourceFunc) statusbar_idle_update, data );
}
+// Actual signal handlers
+static void destroy_window ( GtkWidget *widget,
+ gpointer data )
+{
+ if ( ! --window_count )
+ gtk_main_quit ();
+}
+
+static void statusbar_update ( VikWindow *vw, const gchar *message )
+{
+ vik_window_statusbar_update ( vw, message );
+}
+
+VikWindow *vik_window_new_window ()
+{
+ if ( window_count < MAX_WINDOWS )
+ {
+ VikWindow *vw = window_new ();
+
+ g_signal_connect (G_OBJECT (vw), "destroy",
+ G_CALLBACK (destroy_window), NULL);
+ g_signal_connect (G_OBJECT (vw), "newwindow",
+ G_CALLBACK (vik_window_new_window), NULL);
+ g_signal_connect (G_OBJECT (vw), "openwindow",
+ G_CALLBACK (open_window), NULL);
+ g_signal_connect (G_OBJECT (vw), "statusbarupdate",
+ G_CALLBACK (statusbar_update), NULL);
+
+ gtk_widget_show_all ( GTK_WIDGET(vw) );
+
+ window_count++;
+
+ return vw;
+ }
+ return NULL;
+}
+
+static void open_window ( VikWindow *vw, GSList *files )
+{
+ gboolean change_fn = (g_slist_length(files) == 1); /* only change fn if one file */
+ GSList *cur_file = files;
+ while ( cur_file ) {
+ // Only open a new window if a viking file
+ gchar *file_name = cur_file->data;
+ if (vw != NULL && check_file_magic_vik ( file_name ) ) {
+ VikWindow *newvw = vik_window_new_window ();
+ if (newvw)
+ vik_window_open_file ( newvw, file_name, change_fn );
+ }
+ else {
+ vik_window_open_file ( vw, file_name, change_fn );
+ }
+ g_free (file_name);
+ cur_file = g_slist_next (cur_file);
+ }
+ g_slist_free (files);
+}
+// End signals
+
void vik_window_selected_layer(VikWindow *vw, VikLayer *vl)
{
int i, j, tool_count;
vw->save_img_dir_dia = NULL;
}
-VikWindow *vik_window_new ()
+static VikWindow *window_new ()
{
return VIK_WINDOW ( g_object_new ( VIK_WINDOW_TYPE, NULL ) );
}
GType vik_window_get_type ();
-VikWindow *vik_window_new ();
+// To call from main to start things off:
+VikWindow *vik_window_new_window ();
+
GtkWidget *vik_window_get_drawmode_button ( VikWindow *vw, VikViewportDrawMode mode );
gboolean vik_window_get_pan_move ( VikWindow *vw );
void vik_window_open_file ( VikWindow *vw, const gchar *filename, gboolean changefilename );
struct _VikStatusbar * vik_window_get_statusbar(VikWindow *vw);
// Only for use from background.c:
void vik_window_signal_statusbar_update (VikWindow *vw, const gchar* message );
-// This one only from main.c:
-void vik_window_statusbar_update (VikWindow *vw, const gchar* message );
void vik_window_set_redraw_trigger(struct _VikLayer *vl);