+static void zoom_changed (GtkMenuShell *menushell,
+ gpointer user_data)
+{
+ VikWindow *vw = VIK_WINDOW (user_data);
+
+ GtkWidget *aw = gtk_menu_get_active ( GTK_MENU (menushell) );
+ gint active = GPOINTER_TO_INT(g_object_get_data ( G_OBJECT (aw), "position" ));
+
+ gdouble zoom_request = pow (2, active-2 );
+
+ // But has it really changed?
+ gdouble current_zoom = vik_viewport_get_zoom ( vw->viking_vvp );
+ if ( current_zoom != 0.0 && zoom_request != current_zoom ) {
+ vik_viewport_set_zoom ( vw->viking_vvp, zoom_request );
+ // Force drawing update
+ draw_update ( vw );
+ }
+}
+
+/**
+ * @mpp: The initial zoom level
+ */
+static GtkWidget *create_zoom_menu_all_levels ( gdouble mpp )
+{
+ GtkWidget *menu = gtk_menu_new ();
+ char *itemLabels[] = { "0.25", "0.5", "1", "2", "4", "8", "16", "32", "64", "128", "256", "512", "1024", "2048", "4096", "8192", "16384", "32768" };
+
+ int i;
+ for (i = 0 ; i < G_N_ELEMENTS(itemLabels) ; i++)
+ {
+ GtkWidget *item = gtk_menu_item_new_with_label (itemLabels[i]);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ gtk_widget_show (item);
+ g_object_set_data (G_OBJECT (item), "position", GINT_TO_POINTER(i));
+ }
+
+ gint active = 2 + round ( log (mpp) / log (2) );
+ // Ensure value derived from mpp is in bounds of the menu
+ if ( active >= G_N_ELEMENTS(itemLabels) )
+ active = G_N_ELEMENTS(itemLabels) - 1;
+ if ( active < 0 )
+ active = 0;
+ gtk_menu_set_active ( GTK_MENU(menu), active );
+
+ return menu;
+}
+
+static GtkWidget *create_zoom_combo_all_levels ()
+{
+ GtkWidget *combo = vik_combo_box_text_new();
+ vik_combo_box_text_append ( combo, "0.25");
+ vik_combo_box_text_append ( combo, "0.5");
+ vik_combo_box_text_append ( combo, "1");
+ vik_combo_box_text_append ( combo, "2");
+ vik_combo_box_text_append ( combo, "4");
+ vik_combo_box_text_append ( combo, "8");
+ vik_combo_box_text_append ( combo, "16");
+ vik_combo_box_text_append ( combo, "32");
+ vik_combo_box_text_append ( combo, "64");
+ vik_combo_box_text_append ( combo, "128");
+ vik_combo_box_text_append ( combo, "256");
+ vik_combo_box_text_append ( combo, "512");
+ vik_combo_box_text_append ( combo, "1024");
+ vik_combo_box_text_append ( combo, "2048");
+ vik_combo_box_text_append ( combo, "4096");
+ vik_combo_box_text_append ( combo, "8192");
+ vik_combo_box_text_append ( combo, "16384");
+ vik_combo_box_text_append ( combo, "32768");
+ /* Create tooltip */
+ gtk_widget_set_tooltip_text (combo, _("Select zoom level"));
+ return combo;
+}
+
+static gint zoom_popup_handler (GtkWidget *widget)
+{
+ GtkMenu *menu;
+
+ g_return_val_if_fail (widget != NULL, FALSE);
+ g_return_val_if_fail (GTK_IS_MENU (widget), FALSE);
+
+ /* The "widget" is the menu that was supplied when
+ * g_signal_connect_swapped() was called.
+ */
+ menu = GTK_MENU (widget);
+
+ gtk_menu_popup (menu, NULL, NULL, NULL, NULL,
+ 1, gtk_get_current_event_time());
+ return TRUE;
+}
+
+enum {
+ TARGET_URIS,
+};
+
+static void drag_data_received_cb ( GtkWidget *widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ GtkSelectionData *selection_data,
+ guint target_type,
+ guint time,
+ gpointer data )
+{
+ gboolean success = FALSE;
+
+ if ( (selection_data != NULL) && (gtk_selection_data_get_length(selection_data) > 0) ) {
+ switch (target_type) {
+ case TARGET_URIS: {
+ gchar *str = (gchar*)gtk_selection_data_get_data(selection_data);
+ g_debug ("drag received string:%s \n", str);
+
+ // Convert string into GSList of individual entries for use with our open signal
+ gchar **entries = g_strsplit(str, "\r\n", 0);
+ GSList *filenames = NULL;
+ gint entry_runner = 0;
+ gchar *entry = entries[entry_runner];
+ while (entry) {
+ if ( g_strcmp0 ( entry, "" ) )
+ filenames = g_slist_append ( filenames, entry );
+ entry_runner++;
+ entry = entries[entry_runner];
+ }
+
+ if ( filenames )
+ g_signal_emit ( G_OBJECT(VIK_WINDOW_FROM_WIDGET(widget)), window_signals[VW_OPENWINDOW_SIGNAL], 0, filenames );
+ // NB: GSList & contents are freed by main.open_window
+
+ success = TRUE;
+ break;
+ }
+ default: break;
+ }
+ }
+
+ gtk_drag_finish ( context, success, FALSE, time );
+}
+
+#define VIK_SETTINGS_WIN_MAX "window_maximized"
+#define VIK_SETTINGS_WIN_FULLSCREEN "window_fullscreen"
+#define VIK_SETTINGS_WIN_WIDTH "window_width"
+#define VIK_SETTINGS_WIN_HEIGHT "window_height"
+#define VIK_SETTINGS_WIN_SAVE_IMAGE_WIDTH "window_save_image_width"
+#define VIK_SETTINGS_WIN_SAVE_IMAGE_HEIGHT "window_save_image_height"
+#define VIK_SETTINGS_WIN_SAVE_IMAGE_PNG "window_save_image_as_png"
+
+static void vik_window_init ( VikWindow *vw )