]> git.street.me.uk Git - andy/viking.git/blobdiff - src/vikwindow.c
Adjusted v-t drawing
[andy/viking.git] / src / vikwindow.c
index d5c57a823151d1fb183a0cc8936a110da0f06af2..3e9824c1cea2422952ecede94360ff6f966bbfcc 100644 (file)
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include "viking.h"
 #include "background.h"
-
-#define VIKING_TITLE " - Viking " VIKING_VERSION " " VIKING_VERSION_NAME " " VIKING_URL
+#include "acquire.h"
+#include "datasources.h"
+#include "googlesearch.h"
+#include "dems.h"
+#include "print.h"
+#include "preferences.h"
 
 #include <stdlib.h>
 #include <math.h>
 #include <string.h>
 #include <ctype.h>
-
+#include <glib/gprintf.h>
+#include <glib/gi18n.h>
 #ifdef WINDOWS
 /* TODO IMPORTANT: mkdir for windows header? is it called 'mkdir' */
 #define make_dir(dir) mkdir(dir)
@@ -37,6 +47,8 @@
 #define make_dir(dir) mkdir(dir,0777)
 #endif
 
+#define VIKING_WINDOW_WIDTH      1000
+#define VIKING_WINDOW_HEIGHT     800
 #define DRAW_IMAGE_DEFAULT_WIDTH 1280
 #define DRAW_IMAGE_DEFAULT_HEIGHT 1024
 #define DRAW_IMAGE_DEFAULT_SAVE_AS_PNG TRUE
@@ -46,6 +58,7 @@ static GObjectClass *parent_class;
 
 static void window_init ( VikWindow *vw );
 static void window_class_init ( VikWindowClass *klass );
+static void window_set_filename ( VikWindow *vw, const gchar *filename );
 
 static void draw_update ( VikWindow *vw );
 
@@ -55,9 +68,12 @@ static void newwindow_cb ( GtkAction *a, VikWindow *vw );
 
 static gboolean delete_event( VikWindow *vw );
 
+static gboolean key_press_event( VikWindow *vw, GdkEventKey *event, gpointer data );
+
+static void window_configure_event ( VikWindow *vw );
 static void draw_sync ( VikWindow *vw );
 static void draw_redraw ( VikWindow *vw );
-static void draw_scroll  ( VikWindow *vw, GdkEvent *event );
+static void draw_scroll  ( VikWindow *vw, GdkEventScroll *event );
 static void draw_click  ( VikWindow *vw, GdkEventButton *event );
 static void draw_release ( VikWindow *vw, GdkEventButton *event );
 static void draw_mouse_motion ( VikWindow *vw, GdkEventMotion *event );
@@ -71,16 +87,42 @@ static void draw_status ();
 static void menu_addlayer_cb ( GtkAction *a, VikWindow *vw );
 static void menu_properties_cb ( GtkAction *a, VikWindow *vw );
 static void menu_delete_layer_cb ( GtkAction *a, VikWindow *vw );
+
+/* tool management */
+typedef struct {
+  VikToolInterface ti;
+  gpointer state;
+  gint layer_type;
+} toolbox_tool_t;
+#define TOOL_LAYER_TYPE_NONE -1
+
+typedef struct {
+  int                  active_tool;
+  int                  n_tools;
+  toolbox_tool_t       *tools;
+  VikWindow *vw;
+} toolbox_tools_t;
+
 static void menu_tool_cb ( GtkAction *old, GtkAction *a, VikWindow *vw );
+static toolbox_tools_t* toolbox_create(VikWindow *vw);
+static void toolbox_add_tool(toolbox_tools_t *vt, VikToolInterface *vti, gint layer_type );
+static int toolbox_get_tool(toolbox_tools_t *vt, const gchar *tool_name);
+static void toolbox_activate(toolbox_tools_t *vt, const gchar *tool_name);
+static void toolbox_click (toolbox_tools_t *vt, GdkEventButton *event);
+static void toolbox_move (toolbox_tools_t *vt, GdkEventButton *event);
+static void toolbox_release (toolbox_tools_t *vt, GdkEventButton *event);
+
 
+/* ui creation */
 static void window_create_ui( VikWindow *window );
+static void register_vik_icons (GtkIconFactory *icon_factory);
 
+/* i/o */
 static void load_file ( GtkAction *a, VikWindow *vw );
 static gboolean save_file_as ( GtkAction *a, VikWindow *vw );
 static gboolean save_file ( GtkAction *a, VikWindow *vw );
+static gboolean save_file_and_exit ( GtkAction *a, VikWindow *vw );
 static gboolean window_save ( VikWindow *vw );
-static void register_vik_icons (GtkIconFactory *icon_factory);
-
 
 struct _VikWindow {
   GtkWindow gtkwindow;
@@ -92,16 +134,14 @@ struct _VikWindow {
 
   GtkItemFactory *item_factory;
 
-  /* ruler variables */
-  VikCoord oldcoord;
-  gboolean has_oldcoord;
-  
-
+  /* tool management state */
   guint current_tool;
-
+  toolbox_tools_t *vt;
   guint16 tool_layer_id;
   guint16 tool_tool_id;
 
+  GtkActionGroup *action_group;
+
   gint pan_x, pan_y;
 
   guint draw_image_width, draw_image_height;
@@ -111,9 +151,14 @@ struct _VikWindow {
   gboolean modified;
 
   GtkWidget *open_dia, *save_dia;
+  GtkWidget *save_img_dia, *save_img_dir_dia;
 
   gboolean only_updating_coord_mode_ui; /* hack for a bug in GTK */
   GtkUIManager *uim;
+
+  /* half-drawn update */
+  VikLayer *trigger;
+  VikCoord trigger_center;
 };
 
 enum {
@@ -131,7 +176,10 @@ enum {
 
 static guint window_signals[VW_LAST_SIGNAL] = { 0 };
 
-static gchar *tool_names[NUMBER_OF_TOOLS] = { "Zoom", "Ruler", "Pan" };
+static gchar *tool_names[NUMBER_OF_TOOLS] = { N_("Zoom"), N_("Ruler"), N_("Pan") };
+
+GdkCursor *vw_cursor_zoom = NULL;
+GdkCursor *vw_cursor_ruler = NULL;
 
 GType vik_window_get_type (void)
 {
@@ -157,6 +205,31 @@ GType vik_window_get_type (void)
   return vw_type;
 }
 
+VikViewport * vik_window_viewport(VikWindow *vw)
+{
+  return(vw->viking_vvp);
+}
+
+void vik_window_selected_layer(VikWindow *vw, VikLayer *vl)
+{
+  int i, j, tool_count;
+  VikLayerInterface *layer_interface;
+
+  if (!vw->action_group) return;
+
+  for (i=0; i<VIK_LAYER_NUM_TYPES; i++) {
+    GtkAction *action;
+    layer_interface = vik_layer_get_interface(i);
+    tool_count = layer_interface->tools_count;
+
+    for (j = 0; j < tool_count; j++) {
+      action = gtk_action_group_get_action(vw->action_group,
+           layer_interface->tools[j].name);
+      g_object_set(action, "sensitive", i == vl->type, NULL);
+    }
+  }
+}
+
 static void window_finalize ( GObject *gob )
 {
   VikWindow *vw = VIK_WINDOW(gob);
@@ -167,6 +240,7 @@ static void window_finalize ( GObject *gob )
   G_OBJECT_CLASS(parent_class)->finalize(gob);
 }
 
+
 static void window_class_init ( VikWindowClass *klass )
 {
   /* destructor */
@@ -188,21 +262,25 @@ static void window_init ( VikWindow *vw )
   GtkWidget *main_vbox;
   GtkWidget *hpaned;
 
-  window_create_ui(vw);
-  gtk_window_set_title ( GTK_WINDOW(vw), "Untitled" VIKING_TITLE );
+  vw->action_group = NULL;
 
   vw->viking_vvp = vik_viewport_new();
   vw->viking_vlp = vik_layers_panel_new();
   vik_layers_panel_set_viewport ( vw->viking_vlp, vw->viking_vvp );
   vw->viking_vs = vik_statusbar_new();
 
+  vw->vt = toolbox_create(vw);
+  window_create_ui(vw);
+  window_set_filename (vw, NULL);
+  
+  toolbox_activate(vw->vt, "Zoom");
+
   vw->filename = NULL;
   vw->item_factory = NULL;
 
-  vw->has_oldcoord = FALSE;
   vw->modified = FALSE;
   vw->only_updating_coord_mode_ui = FALSE;
-
+  
   vw->pan_x = vw->pan_y = -1;
   vw->draw_image_width = DRAW_IMAGE_DEFAULT_WIDTH;
   vw->draw_image_height = DRAW_IMAGE_DEFAULT_HEIGHT;
@@ -216,18 +294,21 @@ static void window_init ( VikWindow *vw )
   gtk_toolbar_set_icon_size(GTK_TOOLBAR(gtk_ui_manager_get_widget (vw->uim, "/MainToolbar")), GTK_ICON_SIZE_SMALL_TOOLBAR);
   gtk_toolbar_set_style (GTK_TOOLBAR(gtk_ui_manager_get_widget (vw->uim, "/MainToolbar")), GTK_TOOLBAR_ICONS);
 
+
   g_signal_connect (G_OBJECT (vw), "delete_event", G_CALLBACK (delete_event), NULL);
 
   g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "expose_event", G_CALLBACK(draw_sync), vw);
-  g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "configure_event", G_CALLBACK(draw_redraw), vw);
-  gtk_widget_add_events ( GTK_WIDGET(vw->viking_vvp), GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK );
+  g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "configure_event", G_CALLBACK(window_configure_event), vw);
+  gtk_widget_add_events ( GTK_WIDGET(vw->viking_vvp), GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK );
   g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "scroll_event", G_CALLBACK(draw_scroll), vw);
   g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "button_press_event", G_CALLBACK(draw_click), vw);
   g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "button_release_event", G_CALLBACK(draw_release), vw);
   g_signal_connect_swapped (G_OBJECT(vw->viking_vvp), "motion_notify_event", G_CALLBACK(draw_mouse_motion), vw);
   g_signal_connect_swapped (G_OBJECT(vw->viking_vlp), "update", G_CALLBACK(draw_update), vw);
 
-  gtk_window_set_default_size ( GTK_WINDOW(vw), 1000, 800);
+  g_signal_connect_swapped (G_OBJECT (vw->viking_vvp), "key_press_event", G_CALLBACK (key_press_event), vw);
+
+  gtk_window_set_default_size ( GTK_WINDOW(vw), VIKING_WINDOW_WIDTH, VIKING_WINDOW_HEIGHT);
 
   hpaned = gtk_hpaned_new ();
   gtk_paned_add1 ( GTK_PANED(hpaned), GTK_WIDGET (vw->viking_vlp) );
@@ -242,6 +323,8 @@ static void window_init ( VikWindow *vw )
 
   vw->open_dia = NULL;
   vw->save_dia = NULL;
+  vw->save_img_dia = NULL;
+  vw->save_img_dir_dia = NULL;
 }
 
 VikWindow *vik_window_new ()
@@ -249,15 +332,32 @@ VikWindow *vik_window_new ()
   return VIK_WINDOW ( g_object_new ( VIK_WINDOW_TYPE, NULL ) );
 }
 
+static gboolean key_press_event( VikWindow *vw, GdkEventKey *event, gpointer data )
+{
+  VikLayer *vl = vik_layers_panel_get_selected ( vw->viking_vlp );
+  if (vl && vw->vt->active_tool != -1 && vw->vt->tools[vw->vt->active_tool].ti.key_press ) {
+    gint ltype = vw->vt->tools[vw->vt->active_tool].layer_type;
+    if ( vl && ltype == vl->type )
+      return vw->vt->tools[vw->vt->active_tool].ti.key_press(vl, event, vw->vt->tools[vw->vt->active_tool].state);
+  }
+  return FALSE; /* don't handle the keypress */
+}
+
 static gboolean delete_event( VikWindow *vw )
 {
+#ifdef VIKING_PROMPT_IF_MODIFIED
   if ( vw->modified )
+#else
+  if (0)
+#endif
   {
     GtkDialog *dia;
     dia = GTK_DIALOG ( gtk_message_dialog_new ( GTK_WINDOW(vw), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
-      "Do you want to save the changes you made to the document \"%s\"?\n\nYour changes will be lost if you don't save them.",
-      vw->filename ? a_file_basename ( vw->filename ) : "Untitled" ) );
-    gtk_dialog_add_buttons ( dia, "Don't Save", GTK_RESPONSE_NO, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_YES, NULL );
+      _("Do you want to save the changes you made to the document \"%s\"?\n"
+       "\n"
+       "Your changes will be lost if you don't save them."),
+      vw->filename ? a_file_basename ( vw->filename ) : _("Untitled") ) );
+    gtk_dialog_add_buttons ( dia, _("Don't Save"), GTK_RESPONSE_NO, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_SAVE, GTK_RESPONSE_YES, NULL );
     switch ( gtk_dialog_run ( dia ) )
     {
       case GTK_RESPONSE_NO: gtk_widget_destroy ( GTK_WIDGET(dia) ); return FALSE;
@@ -290,22 +390,189 @@ static void draw_sync ( VikWindow *vw )
 static void draw_status ( VikWindow *vw )
 {
   static gchar zoom_level[22];
-  g_snprintf ( zoom_level, 22, "%.3f/%.3f %s", vik_viewport_get_xmpp (vw->viking_vvp), vik_viewport_get_ympp(vw->viking_vvp), vik_viewport_get_coord_mode(vw->viking_vvp) == VIK_COORD_UTM ? "mpp" : "pixelfact" );
+  g_snprintf ( zoom_level, 22, "%.3f/%.3f %s", vik_viewport_get_xmpp (vw->viking_vvp), vik_viewport_get_ympp(vw->viking_vvp), vik_viewport_get_coord_mode(vw->viking_vvp) == VIK_COORD_UTM ? _("mpp") : _("pixelfact") );
   if ( vw->current_tool == TOOL_LAYER )
     vik_statusbar_set_message ( vw->viking_vs, 0, vik_layer_get_interface(vw->tool_layer_id)->tools[vw->tool_tool_id].name );
   else
-    vik_statusbar_set_message ( vw->viking_vs, 0, tool_names[vw->current_tool] );
+    vik_statusbar_set_message ( vw->viking_vs, 0, _(tool_names[vw->current_tool]) );
 
   vik_statusbar_set_message ( vw->viking_vs, 2, zoom_level );
 }
 
+void vik_window_set_redraw_trigger(VikLayer *vl)
+{
+  VikWindow *vw = VIK_WINDOW(VIK_GTK_WINDOW_FROM_LAYER(vl));
+  vw->trigger = vl;
+}
+
+static void window_configure_event ( VikWindow *vw )
+{
+  draw_redraw ( vw );
+  gdk_window_set_cursor ( GTK_WIDGET(vw->viking_vvp)->window, vw_cursor_zoom );
+}
+
 static void draw_redraw ( VikWindow *vw )
 {
+  VikCoord old_center = vw->trigger_center;
+  vw->trigger_center = *(vik_viewport_get_center(vw->viking_vvp));
+  VikLayer *new_trigger = vw->trigger;
+  vw->trigger = NULL;
+  VikLayer *old_trigger = VIK_LAYER(vik_viewport_get_trigger(vw->viking_vvp));
+
+  if ( ! new_trigger )
+    ; /* do nothing -- have to redraw everything. */
+  else if ( (old_trigger != new_trigger) || !vik_coord_equals(&old_center, &vw->trigger_center) )
+    vik_viewport_set_trigger ( vw->viking_vvp, new_trigger ); /* todo: set to half_drawn mode if new trigger is above old */
+  else
+    vik_viewport_set_half_drawn ( vw->viking_vvp, TRUE );
+
+  /* actually draw */
   vik_viewport_clear ( vw->viking_vvp);
   vik_layers_panel_draw_all ( vw->viking_vlp );
   vik_viewport_draw_scale ( vw->viking_vvp );
+  vik_viewport_draw_centermark ( vw->viking_vvp );
+
+  vik_viewport_set_half_drawn ( vw->viking_vvp, FALSE ); /* just in case. */
+}
+
+gboolean draw_buf_done = TRUE;
+
+static gboolean draw_buf(gpointer data)
+{
+  gpointer *pass_along = data;
+  gdk_threads_enter();
+  gdk_draw_drawable (pass_along[0], pass_along[1],
+                    pass_along[2], 0, 0, 0, 0, -1, -1);
+  draw_buf_done = TRUE;
+  gdk_threads_leave();
+  return FALSE;
+}
+
+
+/* Mouse event handlers ************************************************************************/
+
+static void draw_click (VikWindow *vw, GdkEventButton *event)
+{
+  gtk_widget_grab_focus ( GTK_WIDGET(vw->viking_vvp) );
+
+  /* middle button pressed.  we reserve all middle button and scroll events
+   * for panning and zooming; tools only get left/right/movement 
+   */
+  if ( event->button == 2) {
+    /* set panning origin */
+    vw->pan_x = (gint) event->x;
+    vw->pan_y = (gint) event->y;
+  } 
+  else {
+    toolbox_click(vw->vt, event);
+  }
+}
+
+static void draw_mouse_motion (VikWindow *vw, GdkEventMotion *event)
+{
+  static VikCoord coord;
+  static struct UTM utm;
+  static struct LatLon ll;
+  static char pointer_buf[36];
+  gint16 alt;
+  gdouble zoom;
+  VikDemInterpol interpol_method;
+
+  toolbox_move(vw->vt, (GdkEventButton *)event);
+
+  vik_viewport_screen_to_coord ( vw->viking_vvp, event->x, event->y, &coord );
+  vik_coord_to_utm ( &coord, &utm );
+  a_coords_utm_to_latlon ( &utm, &ll );
+  /* Change interpolate method according to scale */
+  zoom = vik_viewport_get_zoom(vw->viking_vvp);
+  if (zoom > 2.0)
+    interpol_method = VIK_DEM_INTERPOL_NONE;
+  else if (zoom >= 1.0)
+    interpol_method = VIK_DEM_INTERPOL_SIMPLE;
+  else
+    interpol_method = VIK_DEM_INTERPOL_BEST;
+  if ((alt = a_dems_get_elev_by_coord(&coord, interpol_method)) != VIK_DEM_INVALID_ELEVATION)
+    g_snprintf ( pointer_buf, 36, _("Cursor: %f %f %dm"), ll.lat, ll.lon, alt );
+  else
+    g_snprintf ( pointer_buf, 36, _("Cursor: %f %f"), ll.lat, ll.lon );
+  vik_statusbar_set_message ( vw->viking_vs, 4, pointer_buf );
+
+  if ( vw->pan_x != -1 ) {
+    vik_viewport_pan_sync ( vw->viking_vvp, event->x - vw->pan_x, event->y - vw->pan_y );
+  }
+}
+
+static void draw_release ( VikWindow *vw, GdkEventButton *event )
+{
+  gtk_widget_grab_focus ( GTK_WIDGET(vw->viking_vvp) );
+
+  if ( event->button == 2 ) {  /* move / pan */
+    if ( ABS(vw->pan_x - event->x) <= 1 && ABS(vw->pan_y - event->y) <= 1 )
+        vik_viewport_set_center_screen ( vw->viking_vvp, vw->pan_x, vw->pan_y );
+      else
+         vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/2 - event->x + vw->pan_x,
+                                         vik_viewport_get_height(vw->viking_vvp)/2 - event->y + vw->pan_y );
+      draw_update ( vw );
+      vw->pan_x = vw->pan_y = -1;
+  }
+  else {
+    toolbox_release(vw->vt, event);
+  }
 }
 
+static void draw_scroll (VikWindow *vw, GdkEventScroll *event)
+{
+  if ( event->state == GDK_CONTROL_MASK ) {
+    /* control == pan up & down */
+    if ( event->direction == GDK_SCROLL_UP )
+      vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/2, vik_viewport_get_height(vw->viking_vvp)/3 );
+    else
+      vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/2, vik_viewport_get_height(vw->viking_vvp)*2/3 );
+  } else if ( event->state == GDK_SHIFT_MASK ) {
+    /* control-shift == pan left & right */
+    if ( event->direction == GDK_SCROLL_UP )
+      vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/3, vik_viewport_get_height(vw->viking_vvp)/2 );
+    else
+      vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)*2/3, vik_viewport_get_height(vw->viking_vvp)/2 );
+  } else if ( event->state == (GDK_CONTROL_MASK | GDK_SHIFT_MASK) ) {
+    if ( event->direction == GDK_SCROLL_UP ) {
+      /* make sure mouse is still over the same point on the map when we zoom */
+      VikCoord coord;
+      gint x, y;
+      gint center_x = vik_viewport_get_width ( vw->viking_vvp ) / 2;
+      gint center_y = vik_viewport_get_height ( vw->viking_vvp ) / 2;
+      vik_viewport_screen_to_coord ( vw->viking_vvp, event->x, event->y, &coord );
+      vik_viewport_zoom_in (vw->viking_vvp);
+      vik_viewport_coord_to_screen ( vw->viking_vvp, &coord, &x, &y );
+      vik_viewport_set_center_screen ( vw->viking_vvp, center_x + (x - event->x),
+                               center_y + (y - event->y) );
+    }
+    else {
+      VikCoord coord;
+      gint x, y;
+      gint center_x = vik_viewport_get_width ( vw->viking_vvp ) / 2;
+      gint center_y = vik_viewport_get_height ( vw->viking_vvp ) / 2;
+      vik_viewport_screen_to_coord ( vw->viking_vvp, event->x, event->y, &coord );
+      vik_viewport_zoom_out(vw->viking_vvp);
+      vik_viewport_coord_to_screen ( vw->viking_vvp, &coord, &x, &y );
+      vik_viewport_set_center_screen ( vw->viking_vvp, center_x + (x - event->x),
+                               center_y + (y - event->y) );
+    }
+  } else {
+    if ( event->direction == GDK_SCROLL_UP )
+      vik_viewport_zoom_in (vw->viking_vvp);
+    else
+      vik_viewport_zoom_out (vw->viking_vvp);
+  }
+
+  draw_update(vw);
+}
+
+
+
+/********************************************************************************
+ ** Ruler tool code
+ ********************************************************************************/
 static void draw_ruler(VikViewport *vvp, GdkDrawable *d, GdkGC *gc, gint x1, gint y1, gint x2, gint y2, gdouble distance)
 {
   PangoFontDescription *pfd;
@@ -320,10 +587,19 @@ static void draw_ruler(VikViewport *vvp, GdkDrawable *d, GdkGC *gc, gint x1, gin
   gdouble c = cos(15.0 * M_PI/180.0);
   gdouble s = sin(15.0 * M_PI/180.0);
   gdouble angle;
+  gdouble baseangle = 0;
   gint i;
 
   /* draw line with arrow ends */
+  {
+    gint tmp_x1=x1, tmp_y1=y1, tmp_x2=x2, tmp_y2=y2;
+    a_viewport_clip_line(&tmp_x1, &tmp_y1, &tmp_x2, &tmp_y2);
+    gdk_draw_line(d, gc, tmp_x1, tmp_y1, tmp_x2, tmp_y2);
+  }
+
+  a_viewport_clip_line(&x1, &y1, &x2, &y2);
   gdk_draw_line(d, gc, x1, y1, x2, y2);
+
   gdk_draw_line(d, gc, x1 - dy, y1 + dx, x1 + dy, y1 - dx);
   gdk_draw_line(d, gc, x2 - dy, y2 + dx, x2 + dy, y2 - dx);
   gdk_draw_line(d, gc, x2, y2, x2 - (dx * c + dy * s), y2 - (dy * c - dx * s));
@@ -334,7 +610,25 @@ static void draw_ruler(VikViewport *vvp, GdkDrawable *d, GdkGC *gc, gint x1, gin
   /* draw compass */
 #define CR 80
 #define CW 4
-  angle = atan2(dy, dx) + M_PI/2;
+  angle = atan2(dy, dx) + M_PI_2;
+
+  if ( vik_viewport_get_drawmode ( vvp ) == VIK_VIEWPORT_DRAWMODE_UTM) {
+    VikCoord test;
+    struct LatLon ll;
+    struct UTM u;
+    gint tx, ty;
+
+    vik_viewport_screen_to_coord ( vvp, x1, y1, &test );
+    vik_coord_to_latlon ( &test, &ll );
+    ll.lat += vik_viewport_get_ympp ( vvp ) * vik_viewport_get_height ( vvp ) / 11000.0; // about 11km per degree latitude
+    a_coords_latlon_to_utm ( &ll, &u );
+    vik_coord_load_from_utm ( &test, VIK_VIEWPORT_DRAWMODE_UTM, &u );
+    vik_viewport_coord_to_screen ( vvp, &test, &tx, &ty );
+
+    baseangle = M_PI - atan2(tx-x1, ty-y1);
+    angle -= baseangle;
+  }
+
   if (angle<0) 
     angle+=2*M_PI;
   if (angle>2*M_PI)
@@ -347,14 +641,14 @@ static void draw_ruler(VikViewport *vvp, GdkDrawable *d, GdkGC *gc, gint x1, gin
     gdk_color_parse("#2255cc", &color);
     gdk_gc_set_rgb_fg_color(thickgc, &color);
   }
-  gdk_draw_arc (d, thickgc, FALSE, x1-CR+CW/2, y1-CR+CW/2, 2*CR-CW, 2*CR-CW, 90*64, -angle*180/M_PI*64);
+  gdk_draw_arc (d, thickgc, FALSE, x1-CR+CW/2, y1-CR+CW/2, 2*CR-CW, 2*CR-CW, (90 - baseangle*180/M_PI)*64, -angle*180/M_PI*64);
 
 
   gdk_gc_copy(thickgc, gc);
   gdk_gc_set_line_attributes(thickgc, 2, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
   for (i=0; i<180; i++) {
-    c = cos(i*M_PI/90.0);
-    s = sin(i*M_PI/90.0);
+    c = cos(i*M_PI/90.0 + baseangle);
+    s = sin(i*M_PI/90.0 + baseangle);
 
     if (i%5) {
       gdk_draw_line (d, gc, x1 + CR*c, y1 + CR*s, x1 + (CR+CW)*c, y1 + (CR+CW)*s);
@@ -367,8 +661,10 @@ static void draw_ruler(VikViewport *vvp, GdkDrawable *d, GdkGC *gc, gint x1, gin
   gdk_draw_arc (d, gc, FALSE, x1-CR, y1-CR, 2*CR, 2*CR, 0, 64*360);
   gdk_draw_arc (d, gc, FALSE, x1-CR-CW, y1-CR-CW, 2*(CR+CW), 2*(CR+CW), 0, 64*360);
   gdk_draw_arc (d, gc, FALSE, x1-CR+CW, y1-CR+CW, 2*(CR-CW), 2*(CR-CW), 0, 64*360);
-  gdk_draw_line (d, gc, x1-CR-CW*2, y1, x1+CR+CW*2, y1);
-  gdk_draw_line (d, gc, x1-1, y1-CR-CW*2, x1-1, y1+CR+CW*2);
+  c = (CR+CW*2)*cos(baseangle);
+  s = (CR+CW*2)*sin(baseangle);
+  gdk_draw_line (d, gc, x1-c, y1-s, x1+c, y1+s);
+  gdk_draw_line (d, gc, x1+s, y1-c, x1-s, y1+c);
 
   /* draw labels */
 #define LABEL(x, y, w, h) { \
@@ -390,11 +686,11 @@ static void draw_ruler(VikViewport *vvp, GdkDrawable *d, GdkGC *gc, gint x1, gin
 
     /* draw label with distance */
     if (distance >= 1000 && distance < 100000) {
-      sprintf(str, "%3.2f km", distance/1000.0);
+      g_sprintf(str, "%3.2f km", distance/1000.0);
     } else if (distance < 1000) {
-      sprintf(str, "%d m", (int)distance);
+      g_sprintf(str, "%d m", (int)distance);
     } else {
-      sprintf(str, "%d km", (int)distance/1000);
+      g_sprintf(str, "%d km", (int)distance/1000);
     }
     pango_layout_set_text(pl, str, -1);
 
@@ -406,15 +702,26 @@ static void draw_ruler(VikViewport *vvp, GdkDrawable *d, GdkGC *gc, gint x1, gin
       xd = (x1+x2)/2 - dy;
       yd = (y1+y2)/2 - hd/2 + dx;
     }
+
+    if ( xd < -5 || yd < -5 || xd > vik_viewport_get_width(vvp)+5 || yd > vik_viewport_get_height(vvp)+5 ) {
+      xd = x2 + 10;
+      yd = y2 - 5;
+    }
+
     LABEL(xd, yd, wd, hd);
 
     /* draw label with bearing */
-    sprintf(str, "%3.1f°", angle*180.0/M_PI);
+    g_sprintf(str, "%3.1f°", angle*180.0/M_PI);
     pango_layout_set_text(pl, str, -1);
     pango_layout_get_pixel_size ( pl, &wb, &hb );
     xb = x1 + CR*cos(angle-M_PI_2);
     yb = y1 + CR*sin(angle-M_PI_2);
 
+    if ( xb < -5 || yb < -5 || xb > vik_viewport_get_width(vvp)+5 || yb > vik_viewport_get_height(vvp)+5 ) {
+      xb = x2 + 10;
+      yb = y2 + 10;
+    }
+
     {
       GdkRectangle r1 = {xd-2, yd-1, wd+4, hd+1}, r2 = {xb-2, yb-1, wb+4, hb+1};
       if (gdk_rectangle_intersect(&r1, &r2, &r2)) {
@@ -425,168 +732,194 @@ static void draw_ruler(VikViewport *vvp, GdkDrawable *d, GdkGC *gc, gint x1, gin
   }
 #undef LABEL
 
+  g_object_unref ( G_OBJECT ( pl ) );
   g_object_unref ( G_OBJECT ( labgc ) );
   g_object_unref ( G_OBJECT ( thickgc ) );
 }
 
-gboolean draw_buf_done = TRUE;
+typedef struct {
+  VikWindow *vw;
+  VikViewport *vvp;
+  gboolean has_oldcoord;
+  VikCoord oldcoord;
+} ruler_tool_state_t;
 
-static gboolean draw_buf(gpointer data)
+static gpointer ruler_create (VikWindow *vw, VikViewport *vvp) 
 {
-  gpointer *pass_along = data;
-  gdk_threads_enter();
-  gdk_draw_drawable (pass_along[0], pass_along[1],
-                    pass_along[2], 0, 0, 0, 0, -1, -1);
-  gdk_threads_leave();
-  draw_buf_done = TRUE;
-  return FALSE;
+  ruler_tool_state_t *s = g_new(ruler_tool_state_t, 1);
+  s->vw = vw;
+  s->vvp = vvp;
+  s->has_oldcoord = FALSE;
+  return s;
 }
 
-static void draw_mouse_motion (VikWindow *vw, GdkEventMotion *event)
+static void ruler_destroy (ruler_tool_state_t *s)
 {
-  VikViewport *vvp = vw->viking_vvp;
-  static VikCoord coord;
-  static struct UTM utm;
-  static struct LatLon ll;
-  static char pointer_buf[36];
+  g_free(s);
+}
 
-  vik_viewport_screen_to_coord ( vw->viking_vvp, event->x, event->y, &coord );
-  vik_coord_to_utm ( &coord, &utm );
-  a_coords_utm_to_latlon ( &utm, &ll );
+static VikLayerToolFuncStatus ruler_click (VikLayer *vl, GdkEventButton *event, ruler_tool_state_t *s)
+{
+  struct LatLon ll;
+  VikCoord coord;
+  gchar *temp;
+  if ( event->button == 1 ) {
+    vik_viewport_screen_to_coord ( s->vvp, (gint) event->x, (gint) event->y, &coord );
+    vik_coord_to_latlon ( &coord, &ll );
+    if ( s->has_oldcoord ) {
+      temp = g_strdup_printf ( "%f %f DIFF %f meters", ll.lat, ll.lon, vik_coord_diff( &coord, &(s->oldcoord) ) );
+      s->has_oldcoord = FALSE;
+    }
+    else {
+      temp = g_strdup_printf ( "%f %f", ll.lat, ll.lon );
+      s->has_oldcoord = TRUE;
+    }
 
-  if ( vw->current_tool == TOOL_RULER )
-  {
-    struct LatLon ll;
-    VikCoord coord;
-    gchar *temp;
-
-    if ( vw->has_oldcoord ) {
-      int oldx, oldy, w1, h1, w2, h2;
-      static GdkPixmap *buf = NULL;
-      w1 = vik_viewport_get_width(vvp); 
-      h1 = vik_viewport_get_height(vvp);
-      if (!buf) {
-       buf = gdk_pixmap_new ( GTK_WIDGET(vvp)->window, w1, h1, -1 );
-      }
-      gdk_drawable_get_size(buf, &w2, &h2);
-      if (w1 != w2 || h1 != h2) {
-       g_object_unref ( G_OBJECT ( buf ) );
-       buf = gdk_pixmap_new ( GTK_WIDGET(vvp)->window, w1, h1, -1 );
-      }
+    vik_statusbar_set_message ( s->vw->viking_vs, 3, temp );
+    g_free ( temp );
 
-      vik_viewport_screen_to_coord ( vvp, (gint) event->x, (gint) event->y, &coord );
-      vik_coord_to_latlon ( &coord, &ll );
-      vik_viewport_coord_to_screen ( vvp, &vw->oldcoord, &oldx, &oldy );
-
-      gdk_draw_drawable (buf, GTK_WIDGET(vvp)->style->black_gc, 
-                        vik_viewport_get_pixmap(vvp), 0, 0, 0, 0, -1, -1);
-      draw_ruler(vvp, buf, GTK_WIDGET(vvp)->style->black_gc, oldx, oldy, event->x, event->y, vik_coord_diff( &coord, &(vw->oldcoord)) );
-      if (draw_buf_done) {
-       static gpointer pass_along[3];
-       pass_along[0] = GTK_WIDGET(vvp)->window;
-       pass_along[1] = GTK_WIDGET(vvp)->style->black_gc;
-       pass_along[2] = buf;
-       g_idle_add (draw_buf, pass_along);
-       draw_buf_done = FALSE;
-      }
+    s->oldcoord = coord;
+  }
+  else {
+    vik_viewport_set_center_screen ( s->vvp, (gint) event->x, (gint) event->y );
+    draw_update ( s->vw );
+  }
+  return VIK_LAYER_TOOL_ACK;
+}
 
-      temp = g_strdup_printf ( "%f %f DIFF %f meters", ll.lat, ll.lon, vik_coord_diff( &coord, &(vw->oldcoord) ) );
-      vik_statusbar_set_message ( vw->viking_vs, 3, temp );
-      g_free ( temp );
+static VikLayerToolFuncStatus ruler_move (VikLayer *vl, GdkEventButton *event, ruler_tool_state_t *s)
+{
+  VikViewport *vvp = s->vvp;
+  VikWindow *vw = s->vw;
+
+  struct LatLon ll;
+  VikCoord coord;
+  gchar *temp;
+
+  if ( s->has_oldcoord ) {
+    int oldx, oldy, w1, h1, w2, h2;
+    static GdkPixmap *buf = NULL;
+    w1 = vik_viewport_get_width(vvp); 
+    h1 = vik_viewport_get_height(vvp);
+    if (!buf) {
+      buf = gdk_pixmap_new ( GTK_WIDGET(vvp)->window, w1, h1, -1 );
+    }
+    gdk_drawable_get_size(buf, &w2, &h2);
+    if (w1 != w2 || h1 != h2) {
+      g_object_unref ( G_OBJECT ( buf ) );
+      buf = gdk_pixmap_new ( GTK_WIDGET(vvp)->window, w1, h1, -1 );
     }
-  }
 
-  g_snprintf ( pointer_buf, 36, "Cursor: %f %f", ll.lat, ll.lon );
+    vik_viewport_screen_to_coord ( vvp, (gint) event->x, (gint) event->y, &coord );
+    vik_coord_to_latlon ( &coord, &ll );
+    vik_viewport_coord_to_screen ( vvp, &s->oldcoord, &oldx, &oldy );
+
+    gdk_draw_drawable (buf, GTK_WIDGET(vvp)->style->black_gc, 
+                      vik_viewport_get_pixmap(vvp), 0, 0, 0, 0, -1, -1);
+    draw_ruler(vvp, buf, GTK_WIDGET(vvp)->style->black_gc, oldx, oldy, event->x, event->y, vik_coord_diff( &coord, &(s->oldcoord)) );
+    if (draw_buf_done) {
+      static gpointer pass_along[3];
+      pass_along[0] = GTK_WIDGET(vvp)->window;
+      pass_along[1] = GTK_WIDGET(vvp)->style->black_gc;
+      pass_along[2] = buf;
+      g_idle_add_full (G_PRIORITY_HIGH_IDLE + 10, draw_buf, pass_along, NULL);
+      draw_buf_done = FALSE;
+    }
 
-  if ( vw->pan_x != -1 ) {
-    vik_viewport_pan_sync ( vw->viking_vvp, event->x - vw->pan_x, event->y - vw->pan_y );
+    temp = g_strdup_printf ( "%f %f DIFF %f meters", ll.lat, ll.lon, vik_coord_diff( &coord, &(s->oldcoord) ) );
+    vik_statusbar_set_message ( vw->viking_vs, 3, temp );
+    g_free ( temp );
   }
+  return VIK_LAYER_TOOL_ACK;
+}
 
-  vik_statusbar_set_message ( vw->viking_vs, 4, pointer_buf );
+static VikLayerToolFuncStatus ruler_release (VikLayer *vl, GdkEventButton *event, ruler_tool_state_t *s)
+{
+  return VIK_LAYER_TOOL_ACK;
 }
 
-static void draw_scroll (VikWindow *vw, GdkEvent *event)
+static void ruler_deactivate (VikLayer *vl, ruler_tool_state_t *s)
 {
-  if ( event->scroll.direction == GDK_SCROLL_UP )
-    vik_viewport_zoom_in (vw->viking_vvp);
-  else
-    vik_viewport_zoom_out(vw->viking_vvp);
-  draw_update(vw);
+  draw_update ( s->vw );
 }
 
-static void draw_release ( VikWindow *vw, GdkEventButton *event )
+static VikToolInterface ruler_tool = 
+  { "Ruler", 
+    (VikToolConstructorFunc) ruler_create,
+    (VikToolDestructorFunc) ruler_destroy,
+    (VikToolActivationFunc) NULL,
+    (VikToolActivationFunc) ruler_deactivate, 
+    (VikToolMouseFunc) ruler_click, 
+    (VikToolMouseFunc) ruler_move, 
+    (VikToolMouseFunc) ruler_release };
+/*** end ruler code ********************************************************/
+
+
+
+/********************************************************************************
+ ** Zoom tool code
+ ********************************************************************************/
+static gpointer zoomtool_create (VikWindow *vw, VikViewport *vvp)
 {
-  if ( event->button == 2 ) { /* move / pan */
-    if ( ABS(vw->pan_x - event->x) <= 1 && ABS(vw->pan_y - event->y) <= 1 )
-        vik_viewport_set_center_screen ( vw->viking_vvp, vw->pan_x, vw->pan_y );
-      else
-         vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/2 - event->x + vw->pan_x,
-                                         vik_viewport_get_height(vw->viking_vvp)/2 - event->y + vw->pan_y );
-      draw_update ( vw );
-      vw->pan_x = vw->pan_y = -1;
-  }
-  if ( vw->current_tool == TOOL_LAYER && ( event->button == 1 || event->button == 3 ) &&
-      vik_layer_get_interface(vw->tool_layer_id)->tools[vw->tool_tool_id].callback_release )
-  {
-    vik_layers_panel_tool ( vw->viking_vlp, vw->tool_layer_id,
-        vik_layer_get_interface(vw->tool_layer_id)->tools[vw->tool_tool_id].callback_release,
-        event, vw->viking_vvp );
-  }
+  return vw;
 }
 
-static void draw_click (VikWindow *vw, GdkEventButton *event)
+static VikLayerToolFuncStatus zoomtool_click (VikLayer *vl, GdkEventButton *event, VikWindow *vw)
 {
-  if ( event->button == 2) {
-    vw->pan_x = (gint) event->x;
-    vw->pan_y = (gint) event->y;
-  } else if ( vw->current_tool == TOOL_ZOOM )
-  {
-    vw->modified = TRUE;
-    vik_viewport_set_center_screen ( vw->viking_vvp, (gint) event->x, (gint) event->y );
-    if ( event->button == 1 )
-      vik_viewport_zoom_in (vw->viking_vvp);
-    else if ( event->button == 3 )
-      vik_viewport_zoom_out (vw->viking_vvp);
-    draw_update ( vw );
-  }
-  else if ( vw->current_tool == TOOL_RULER )
-  {
-    struct LatLon ll;
-    VikCoord coord;
-    gchar *temp;
-    if ( event->button == 1 || event->button == 3 )
-    {
-      vik_viewport_screen_to_coord ( vw->viking_vvp, (gint) event->x, (gint) event->y, &coord );
-      vik_coord_to_latlon ( &coord, &ll );
-      if ( vw->has_oldcoord ) {
-         temp = g_strdup_printf ( "%f %f DIFF %f meters", ll.lat, ll.lon, vik_coord_diff( &coord, &(vw->oldcoord) ) );
-        vw->has_oldcoord = FALSE;
-      }
-      else {
-        temp = g_strdup_printf ( "%f %f", ll.lat, ll.lon );
-       vw->has_oldcoord = TRUE;
-      }
+  vw->modified = TRUE;
+  vik_viewport_set_center_screen ( vw->viking_vvp, (gint) event->x, (gint) event->y );
+  if ( event->button == 1 )
+    vik_viewport_zoom_in (vw->viking_vvp);
+  else if ( event->button == 3 )
+    vik_viewport_zoom_out (vw->viking_vvp);
+  draw_update ( vw );
+  return VIK_LAYER_TOOL_ACK;
+}
 
-      vik_statusbar_set_message ( vw->viking_vs, 3, temp );
-      g_free ( temp );
+static VikLayerToolFuncStatus zoomtool_move (VikLayer *vl, GdkEventButton *event, VikViewport *vvp)
+{
+  return VIK_LAYER_TOOL_ACK;
+}
 
-      vw->oldcoord = coord;
-      /* we don't use anything else so far */
-    }
-    else
-    {
-      vik_viewport_set_center_screen ( vw->viking_vvp, (gint) event->x, (gint) event->y );
-      draw_update ( vw );
-    }
-  }
-  else if ( vw->current_tool == TOOL_LAYER )
-  {
-    vw->modified = TRUE;
-    if ( ! vik_layers_panel_tool ( vw->viking_vlp, vw->tool_layer_id,
-        vik_layer_get_interface(vw->tool_layer_id)->tools[vw->tool_tool_id].callback,
-        event, vw->viking_vvp ) )
-      a_dialog_info_msg_extra ( GTK_WINDOW(vw), "A %s Layer must exist and be either selected or visible before you can use this function.", vik_layer_get_interface ( vw->tool_layer_id )->name );
+static VikLayerToolFuncStatus zoomtool_release (VikLayer *vl, GdkEventButton *event, VikViewport *vvp)
+{
+  return VIK_LAYER_TOOL_ACK;
+}
+
+static VikToolInterface zoom_tool = 
+  { "Zoom", 
+    (VikToolConstructorFunc) zoomtool_create,
+    (VikToolDestructorFunc) NULL,
+    (VikToolActivationFunc) NULL,
+    (VikToolActivationFunc) NULL,
+    (VikToolMouseFunc) zoomtool_click, 
+    (VikToolMouseFunc) zoomtool_move,
+    (VikToolMouseFunc) zoomtool_release };
+/*** end ruler code ********************************************************/
+
+static void draw_pan_cb ( GtkAction *a, VikWindow *vw )
+{
+  if (!strcmp(gtk_action_get_name(a), "PanNorth")) {
+    vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/2, 0 );
+  } else if (!strcmp(gtk_action_get_name(a), "PanEast")) {
+    vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp), vik_viewport_get_height(vw->viking_vvp)/2 );
+  } else if (!strcmp(gtk_action_get_name(a), "PanSouth")) {
+    vik_viewport_set_center_screen ( vw->viking_vvp, vik_viewport_get_width(vw->viking_vvp)/2, vik_viewport_get_height(vw->viking_vvp) );
+  } else if (!strcmp(gtk_action_get_name(a), "PanWest")) {
+    vik_viewport_set_center_screen ( vw->viking_vvp, 0, vik_viewport_get_height(vw->viking_vvp)/2 );
   }
+  draw_update ( vw );
+}
+
+static void full_screen_cb ( GtkAction *a, VikWindow *vw )
+{
+  GtkWidget *check_box = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/FullScreen" );
+  g_assert(check_box);
+  gboolean state = gtk_check_menu_item_get_active ( GTK_CHECK_MENU_ITEM(check_box));
+  if ( state )
+    gtk_window_fullscreen ( GTK_WINDOW(vw) );
+  else
+    gtk_window_unfullscreen ( GTK_WINDOW(vw) );
 }
 
 static void draw_zoom_cb ( GtkAction *a, VikWindow *vw )
@@ -642,7 +975,7 @@ void draw_goto_cb ( GtkAction *a, VikWindow *vw )
      return;
   }
   else {
-    fprintf(stderr, "Houston we have a problem\n");
+    g_critical("Houston we have a problem\n");
     return;
   }
 
@@ -665,12 +998,12 @@ static void menu_addlayer_cb ( GtkAction *a, VikWindow *vw )
 
 static void menu_copy_layer_cb ( GtkAction *a, VikWindow *vw )
 {
-  a_clipboard_copy ( vw->viking_vlp );
+  a_clipboard_copy_selected ( vw->viking_vlp );
 }
 
 static void menu_cut_layer_cb ( GtkAction *a, VikWindow *vw )
 {
-  a_clipboard_copy ( vw->viking_vlp );
+  a_clipboard_copy_selected ( vw->viking_vlp );
   menu_delete_layer_cb ( a, vw );
 }
 
@@ -686,7 +1019,12 @@ static void menu_paste_layer_cb ( GtkAction *a, VikWindow *vw )
 static void menu_properties_cb ( GtkAction *a, VikWindow *vw )
 {
   if ( ! vik_layers_panel_properties ( vw->viking_vlp ) )
-    a_dialog_info_msg ( GTK_WINDOW(vw), "You must select a layer to show its properties." );
+    a_dialog_info_msg ( GTK_WINDOW(vw), _("You must select a layer to show its properties.") );
+}
+
+static void help_about_cb ( GtkAction *a, VikWindow *vw )
+{
+  a_dialog_about(GTK_WINDOW(vw));
 }
 
 static void menu_delete_layer_cb ( GtkAction *a, VikWindow *vw )
@@ -697,27 +1035,141 @@ static void menu_delete_layer_cb ( GtkAction *a, VikWindow *vw )
     vw->modified = TRUE;
   }
   else
-    a_dialog_info_msg ( GTK_WINDOW(vw), "You must select a layer to delete." );
+    a_dialog_info_msg ( GTK_WINDOW(vw), _("You must select a layer to delete.") );
+}
+
+/***************************************
+ ** tool management routines
+ **
+ ***************************************/
+
+static toolbox_tools_t* toolbox_create(VikWindow *vw)
+{
+  toolbox_tools_t *vt = g_new(toolbox_tools_t, 1);
+  vt->tools = NULL;
+  vt->n_tools = 0;
+  vt->active_tool = -1;
+  vt->vw = vw;
+  if (!vw->viking_vvp) {
+    g_critical("no viewport found.");
+    exit(1);
+  }
+  return vt;
+}
+
+static void toolbox_add_tool(toolbox_tools_t *vt, VikToolInterface *vti, gint layer_type )
+{
+  vt->tools = g_renew(toolbox_tool_t, vt->tools, vt->n_tools+1);
+  vt->tools[vt->n_tools].ti = *vti;
+  vt->tools[vt->n_tools].layer_type = layer_type;
+  if (vti->create) {
+    vt->tools[vt->n_tools].state = vti->create(vt->vw, vt->vw->viking_vvp);
+  } 
+  else {
+    vt->tools[vt->n_tools].state = NULL;
+  }
+  vt->n_tools++;
+}
+
+static int toolbox_get_tool(toolbox_tools_t *vt, const gchar *tool_name)
+{
+  int i;
+  for (i=0; i<vt->n_tools; i++) {
+    if (!strcmp(tool_name, vt->tools[i].ti.name)) {
+      break;
+    }
+  }
+  return i;
+}
+
+static void toolbox_activate(toolbox_tools_t *vt, const gchar *tool_name)
+{
+  int tool = toolbox_get_tool(vt, tool_name);
+  toolbox_tool_t *t = &vt->tools[tool];
+  VikLayer *vl = vik_layers_panel_get_selected ( vt->vw->viking_vlp );
+
+  if (tool == vt->n_tools) {
+    g_critical("trying to activate a non-existent tool...");
+    exit(1);
+  }
+  /* is the tool already active? */
+  if (vt->active_tool == tool) {
+    return;
+  }
+
+  if (vt->active_tool != -1) {
+    if (vt->tools[vt->active_tool].ti.deactivate) {
+      vt->tools[vt->active_tool].ti.deactivate(NULL, vt->tools[vt->active_tool].state);
+    }
+  }
+  if (t->ti.activate) {
+    t->ti.activate(vl, t->state);
+  }
+  vt->active_tool = tool;
+}
+
+static void toolbox_click (toolbox_tools_t *vt, GdkEventButton *event)
+{
+  VikLayer *vl = vik_layers_panel_get_selected ( vt->vw->viking_vlp );
+  if (vt->active_tool != -1 && vt->tools[vt->active_tool].ti.click) {
+    gint ltype = vt->tools[vt->active_tool].layer_type;
+    if ( ltype == TOOL_LAYER_TYPE_NONE || (vl && ltype == vl->type) )
+      vt->tools[vt->active_tool].ti.click(vl, event, vt->tools[vt->active_tool].state);
+  }
+}
+
+static void toolbox_move (toolbox_tools_t *vt, GdkEventButton *event)
+{
+  VikLayer *vl = vik_layers_panel_get_selected ( vt->vw->viking_vlp );
+  if (vt->active_tool != -1 && vt->tools[vt->active_tool].ti.move) {
+    gint ltype = vt->tools[vt->active_tool].layer_type;
+    if ( ltype == TOOL_LAYER_TYPE_NONE || (vl && ltype == vl->type) )
+      if ( VIK_LAYER_TOOL_ACK_GRAB_FOCUS == vt->tools[vt->active_tool].ti.move(vl, event, vt->tools[vt->active_tool].state) )
+        gtk_widget_grab_focus ( GTK_WIDGET(vt->vw->viking_vvp) );
+  }
+}
+
+static void toolbox_release (toolbox_tools_t *vt, GdkEventButton *event)
+{
+  VikLayer *vl = vik_layers_panel_get_selected ( vt->vw->viking_vlp );
+  if (vt->active_tool != -1 && vt->tools[vt->active_tool].ti.release ) {
+    gint ltype = vt->tools[vt->active_tool].layer_type;
+    if ( ltype == TOOL_LAYER_TYPE_NONE || (vl && ltype == vl->type) )
+      vt->tools[vt->active_tool].ti.release(vl, event, vt->tools[vt->active_tool].state);
+  }
 }
+/** End tool management ************************************/
 
+void vik_window_enable_layer_tool ( VikWindow *vw, gint layer_id, gint tool_id )
+{
+  gtk_action_activate ( gtk_action_group_get_action ( vw->action_group, vik_layer_get_interface(layer_id)->tools[tool_id].name ) );
+}
+
+/* this function gets called whenever a toolbar tool is clicked */
 static void menu_tool_cb ( GtkAction *old, GtkAction *a, VikWindow *vw )
 {
   /* White Magic, my friends ... White Magic... */
-  int i, j;
+  int layer_id, tool_id;
+
+  toolbox_activate(vw->vt, gtk_action_get_name(a));
 
   if (!strcmp(gtk_action_get_name(a), "Zoom")) {
     vw->current_tool = TOOL_ZOOM;
+    gdk_window_set_cursor ( GTK_WIDGET(vw->viking_vvp)->window, vw_cursor_zoom );
   } 
   else if (!strcmp(gtk_action_get_name(a), "Ruler")) {
     vw->current_tool = TOOL_RULER;
+    gdk_window_set_cursor ( GTK_WIDGET(vw->viking_vvp)->window, vw_cursor_ruler );
   }
   else {
-    for (i=0; i<VIK_LAYER_NUM_TYPES; i++) {
-      for ( j = 0; j < vik_layer_get_interface(i)->tools_count; j++ ) {
-       if (!strcmp(vik_layer_get_interface(i)->tools[j].name, gtk_action_get_name(a))) {
-         vw->current_tool = TOOL_LAYER;
-         vw->tool_layer_id = i;
-         vw->tool_tool_id = j;
+    /* TODO: only enable tools from active layer */
+    for (layer_id=0; layer_id<VIK_LAYER_NUM_TYPES; layer_id++) {
+      for ( tool_id = 0; tool_id < vik_layer_get_interface(layer_id)->tools_count; tool_id++ ) {
+       if (!strcmp(vik_layer_get_interface(layer_id)->tools[tool_id].name, gtk_action_get_name(a))) {
+           vw->current_tool = TOOL_LAYER;
+           vw->tool_layer_id = layer_id;
+           vw->tool_tool_id = tool_id;
+           gdk_window_set_cursor ( GTK_WIDGET(vw->viking_vvp)->window, vik_layer_get_tool_cursor ( layer_id, tool_id ) );
        }
       }
     }
@@ -728,20 +1180,38 @@ static void menu_tool_cb ( GtkAction *old, GtkAction *a, VikWindow *vw )
 static void window_set_filename ( VikWindow *vw, const gchar *filename )
 {
   gchar *title;
+  const gchar *file;
   if ( vw->filename )
     g_free ( vw->filename );
   if ( filename == NULL )
   {
     vw->filename = NULL;
-    gtk_window_set_title ( GTK_WINDOW(vw), "Untitled" VIKING_TITLE );
+    file = _("Untitled");
   }
   else
   {
     vw->filename = g_strdup(filename);
-    title = g_strconcat ( a_file_basename ( filename ), VIKING_TITLE, NULL );
-    gtk_window_set_title ( GTK_WINDOW(vw), title );
-    g_free ( title );
+    file = a_file_basename ( filename );
   }
+  title = g_strdup_printf( "%s - Viking", file );
+  gtk_window_set_title ( GTK_WINDOW(vw), title );
+  g_free ( title );
+}
+
+GtkWidget *vik_window_get_drawmode_button ( VikWindow *vw, VikViewportDrawMode mode )
+{
+  GtkWidget *mode_button;
+  gchar *buttonname;
+  switch ( mode ) {
+    case VIK_VIEWPORT_DRAWMODE_UTM: buttonname = "/ui/MainMenu/View/ModeUTM"; break;
+    case VIK_VIEWPORT_DRAWMODE_EXPEDIA: buttonname = "/ui/MainMenu/View/ModeExpedia"; break;
+    case VIK_VIEWPORT_DRAWMODE_GOOGLE: buttonname = "/ui/MainMenu/View/ModeGoogle"; break;
+    case VIK_VIEWPORT_DRAWMODE_MERCATOR: buttonname = "/ui/MainMenu/View/ModeMercator"; break;
+    default: buttonname = "/ui/MainMenu/View/ModeKH";
+  }
+  mode_button = gtk_ui_manager_get_widget ( vw->uim, buttonname );
+  g_assert ( mode_button );
+  return mode_button;
 }
 
 void vik_window_open_file ( VikWindow *vw, const gchar *filename, gboolean change_filename )
@@ -749,32 +1219,31 @@ void vik_window_open_file ( VikWindow *vw, const gchar *filename, gboolean chang
   switch ( a_file_load ( vik_layers_panel_get_top_layer(vw->viking_vlp), vw->viking_vvp, filename ) )
   {
     case 0:
-      a_dialog_error_msg ( GTK_WINDOW(vw), "The file you requested could not be opened." );
+      a_dialog_error_msg ( GTK_WINDOW(vw), _("The file you requested could not be opened.") );
       break;
     case 1:
     {
       GtkWidget *mode_button;
-      gchar *buttonname;
       if ( change_filename )
         window_set_filename ( vw, filename );
-      switch ( vik_viewport_get_drawmode ( vw->viking_vvp ) ) {
-        case VIK_VIEWPORT_DRAWMODE_UTM: buttonname = "/ui/MainMenu/View/ModeUTM"; break;
-        case VIK_VIEWPORT_DRAWMODE_EXPEDIA: buttonname = "/ui/MainMenu/View/ModeExpedia"; break;
-        case VIK_VIEWPORT_DRAWMODE_GOOGLE: buttonname = "/ui/MainMenu/View/ModeGoogle"; break;
-        default: buttonname = "/ui/MainMenu/View/ModeKH";
-      }
-      mode_button = gtk_ui_manager_get_widget ( vw->uim, buttonname );
-      g_assert ( mode_button );
+      mode_button = vik_window_get_drawmode_button ( vw, vik_viewport_get_drawmode ( vw->viking_vvp ) );
       vw->only_updating_coord_mode_ui = TRUE; /* if we don't set this, it will change the coord to UTM if we click Lat/Lon. I don't know why. */
       gtk_check_menu_item_set_active ( GTK_CHECK_MENU_ITEM(mode_button), TRUE );
       vw->only_updating_coord_mode_ui = FALSE;
 
       vik_layers_panel_change_coord_mode ( vw->viking_vlp, vik_viewport_get_coord_mode ( vw->viking_vvp ) );
+
+      mode_button = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/ShowScale" );
+      g_assert ( mode_button );
+      gtk_check_menu_item_set_active ( GTK_CHECK_MENU_ITEM(mode_button),vik_viewport_get_draw_scale(vw->viking_vvp) );
+
+      mode_button = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/ShowCenterMark" );
+      g_assert ( mode_button );
+      gtk_check_menu_item_set_active ( GTK_CHECK_MENU_ITEM(mode_button),vik_viewport_get_draw_centermark(vw->viking_vvp) );
     }
     default: draw_update ( vw );
   }
 }
-
 static void load_file ( GtkAction *a, VikWindow *vw )
 {
   gboolean newwindow;
@@ -785,13 +1254,13 @@ static void load_file ( GtkAction *a, VikWindow *vw )
     newwindow = FALSE;
   } 
   else {
-    fprintf(stderr, "Houston we got a problem\n");
+    g_critical("Houston we got a problem\n");
     return;
   }
     
   if ( ! vw->open_dia )
   {
-    vw->open_dia = gtk_file_selection_new ("Please select a GPS data file to open. " );
+    vw->open_dia = gtk_file_selection_new ( _("Please select a GPS data file to open. ") );
     gtk_file_selection_set_select_multiple ( GTK_FILE_SELECTION(vw->open_dia), TRUE );
     gtk_window_set_transient_for ( GTK_WINDOW(vw->open_dia), GTK_WINDOW(vw) );
     gtk_window_set_destroy_with_parent ( GTK_WINDOW(vw->open_dia), TRUE );
@@ -799,7 +1268,11 @@ static void load_file ( GtkAction *a, VikWindow *vw )
   if ( gtk_dialog_run ( GTK_DIALOG(vw->open_dia) ) == GTK_RESPONSE_OK )
   {
     gtk_widget_hide ( vw->open_dia );
+#ifdef VIKING_PROMPT_IF_MODIFIED
     if ( (vw->modified || vw->filename) && newwindow )
+#else
+    if ( vw->filename && newwindow )
+#endif
       g_signal_emit ( G_OBJECT(vw), window_signals[VW_OPENWINDOW_SIGNAL], 0, gtk_file_selection_get_selections (GTK_FILE_SELECTION(vw->open_dia) ) );
     else {
       gchar **files = gtk_file_selection_get_selections (GTK_FILE_SELECTION(vw->open_dia) );
@@ -820,7 +1293,7 @@ static gboolean save_file_as ( GtkAction *a, VikWindow *vw )
   const gchar *fn;
   if ( ! vw->save_dia )
   {
-    vw->save_dia = gtk_file_selection_new ("Save as Viking File. " );
+    vw->save_dia = gtk_file_selection_new ( _("Save as Viking File.") );
     gtk_window_set_transient_for ( GTK_WINDOW(vw->save_dia), GTK_WINDOW(vw) );
     gtk_window_set_destroy_with_parent ( GTK_WINDOW(vw->save_dia), TRUE );
   }
@@ -828,7 +1301,7 @@ static gboolean save_file_as ( GtkAction *a, VikWindow *vw )
   while ( gtk_dialog_run ( GTK_DIALOG(vw->save_dia) ) == GTK_RESPONSE_OK )
   {
     fn = gtk_file_selection_get_filename (GTK_FILE_SELECTION(vw->save_dia) );
-    if ( access ( fn, F_OK ) != 0 || a_dialog_overwrite ( GTK_WINDOW(vw->save_dia), "The file \"%s\" exists, do you wish to overwrite it?", a_file_basename ( fn ) ) )
+    if ( access ( fn, F_OK ) != 0 || a_dialog_overwrite ( GTK_WINDOW(vw->save_dia), _("The file \"%s\" exists, do you wish to overwrite it?"), a_file_basename ( fn ) ) )
     {
       window_set_filename ( vw, fn );
       rv = window_save ( vw );
@@ -846,7 +1319,7 @@ static gboolean window_save ( VikWindow *vw )
     return TRUE;
   else
   {
-    a_dialog_error_msg ( GTK_WINDOW(vw), "The filename you requested could not be opened for writing." );
+    a_dialog_error_msg ( GTK_WINDOW(vw), _("The filename you requested could not be opened for writing.") );
     return FALSE;
   }
 }
@@ -862,6 +1335,33 @@ static gboolean save_file ( GtkAction *a, VikWindow *vw )
   }
 }
 
+static void acquire_from_gps ( GtkAction *a, VikWindow *vw )
+{
+  a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_gps_interface );
+}
+
+static void acquire_from_google ( GtkAction *a, VikWindow *vw )
+{
+  a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_google_interface );
+}
+
+#ifdef VIK_CONFIG_GEOCACHES
+static void acquire_from_gc ( GtkAction *a, VikWindow *vw )
+{
+  a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_gc_interface );
+}
+#endif
+
+static void goto_address( GtkAction *a, VikWindow *vw)
+{
+  a_google_search(vw, vw->viking_vlp, vw->viking_vvp);
+}
+
+static void preferences_cb ( GtkAction *a, VikWindow *vw )
+{
+  a_preferences_show_window ( GTK_WINDOW(vw) );
+}
+
 static void clear_cb ( GtkAction *a, VikWindow *vw )
 {
   vik_layers_panel_clear ( vw->viking_vlp );
@@ -875,6 +1375,16 @@ static void window_close ( GtkAction *a, VikWindow *vw )
     gtk_widget_destroy ( GTK_WIDGET(vw) );
 }
 
+static gboolean save_file_and_exit ( GtkAction *a, VikWindow *vw )
+{
+  if (save_file( NULL, vw)) {
+    window_close( NULL, vw);
+    return(TRUE);
+  }
+  else
+    return(FALSE);
+}
+
 static void zoom_to_cb ( GtkAction *a, VikWindow *vw )
 {
   gdouble xmpp = vik_viewport_get_xmpp ( vw->viking_vvp ), ympp = vik_viewport_get_ympp ( vw->viking_vvp );
@@ -909,7 +1419,7 @@ static void save_image_file ( VikWindow *vw, const gchar *fn, guint w, guint h,
   gdk_pixbuf_save ( pixbuf_to_save, fn, save_as_png ? "png" : "jpeg", &error, NULL );
   if (error)
   {
-    fprintf(stderr, "Unable to write to file %s: %s", fn, error->message );
+    g_warning("Unable to write to file %s: %s", fn, error->message );
     g_error_free (error);
   }
   g_object_unref ( G_OBJECT(pixbuf_to_save) );
@@ -952,7 +1462,7 @@ static void save_image_dir ( VikWindow *vw, const gchar *fn, guint w, guint h, g
   {
     for ( x = 1; x <= tiles_w; x++ )
     {
-      g_snprintf ( name_of_file, size, "%s%cy%d-x%d.%s", fn, VIKING_FILE_SEP, y, x, save_as_png ? "png" : "jpg" );
+      g_snprintf ( name_of_file, size, "%s%cy%d-x%d.%s", fn, G_DIR_SEPARATOR, y, x, save_as_png ? "png" : "jpg" );
       utm = utm_orig;
       if ( tiles_w & 0x1 )
         utm.easting += ((gdouble)x - ceil(((gdouble)tiles_w)/2)) * (w*zoom);
@@ -973,7 +1483,7 @@ static void save_image_dir ( VikWindow *vw, const gchar *fn, guint w, guint h, g
       gdk_pixbuf_save ( pixbuf_to_save, name_of_file, save_as_png ? "png" : "jpeg", &error, NULL );
       if (error)
       {
-        fprintf(stderr, "Unable to write to file %s: %s", name_of_file, error->message );
+        g_warning("Unable to write to file %s: %s", name_of_file, error->message );
         g_error_free (error);
       }
 
@@ -1006,7 +1516,7 @@ static void draw_to_image_file_current_window_cb(GtkWidget* widget,GdkEventButto
   height = vik_viewport_get_height ( vw->viking_vvp ) * vik_viewport_get_xmpp ( vw->viking_vvp ) / gtk_spin_button_get_value ( zoom_spin );
 
   if ( width > width_max || width < width_min || height > height_max || height < height_min )
-    a_dialog_info_msg ( GTK_WINDOW(vw), "Viewable region outside allowable pixel size bounds for image. Clipping width/height values." );
+    a_dialog_info_msg ( GTK_WINDOW(vw), _("Viewable region outside allowable pixel size bounds for image. Clipping width/height values.") );
 
   gtk_spin_button_set_value ( width_spin, width );
   gtk_spin_button_set_value ( height_spin, height );
@@ -1025,7 +1535,7 @@ static void draw_to_image_file_total_area_cb (GtkSpinButton *spinbutton, gpointe
     w *= gtk_spin_button_get_value(GTK_SPIN_BUTTON(pass_along[4]));
     h *= gtk_spin_button_get_value(GTK_SPIN_BUTTON(pass_along[5]));
   }
-  label_text = g_strdup_printf ( "Total area: %ldm x %ldm (%.3f sq. km)", (glong)w, (glong)h, (w*h/1000000));
+  label_text = g_strdup_printf ( _("Total area: %ldm x %ldm (%.3f sq. km)"), (glong)w, (glong)h, (w*h/1000000));
   gtk_label_set_text(GTK_LABEL(pass_along[6]), label_text);
   g_free ( label_text );
 }
@@ -1033,13 +1543,13 @@ static void draw_to_image_file_total_area_cb (GtkSpinButton *spinbutton, gpointe
 static void draw_to_image_file ( VikWindow *vw, const gchar *fn, gboolean one_image_only )
 {
   /* todo: default for answers inside VikWindow or static (thruout instance) */
-  GtkWidget *dialog = gtk_dialog_new_with_buttons ( "Save to Image File", GTK_WINDOW(vw),
+  GtkWidget *dialog = gtk_dialog_new_with_buttons ( _("Save to Image File"), GTK_WINDOW(vw),
                                                   GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
                                                   GTK_STOCK_CANCEL,
                                                   GTK_RESPONSE_REJECT,
                                                   GTK_STOCK_OK,
                                                   GTK_RESPONSE_ACCEPT,
-                                                  0 );
+                                                  NULL );
   GtkWidget *width_label, *width_spin, *height_label, *height_spin;
   GtkWidget *png_radio, *jpeg_radio;
   GtkWidget *current_window_button;
@@ -1051,18 +1561,18 @@ static void draw_to_image_file ( VikWindow *vw, const gchar *fn, gboolean one_im
   GtkWidget *tiles_width_spin = NULL, *tiles_height_spin = NULL;
 
 
-  width_label = gtk_label_new ( "Width (pixels):" );
+  width_label = gtk_label_new ( _("Width (pixels):") );
   width_spin = gtk_spin_button_new ( GTK_ADJUSTMENT(gtk_adjustment_new ( vw->draw_image_width, 10, 5000, 10, 100, 0 )), 10, 0 );
-  height_label = gtk_label_new ( "Height (pixels):" );
+  height_label = gtk_label_new ( _("Height (pixels):") );
   height_spin = gtk_spin_button_new ( GTK_ADJUSTMENT(gtk_adjustment_new ( vw->draw_image_height, 10, 5000, 10, 100, 0 )), 10, 0 );
 
-  zoom_label = gtk_label_new ( "Zoom (meters per pixel):" );
+  zoom_label = gtk_label_new ( _("Zoom (meters per pixel):") );
   /* TODO: separate xzoom and yzoom factors */
   zoom_spin = gtk_spin_button_new ( GTK_ADJUSTMENT(gtk_adjustment_new ( vik_viewport_get_xmpp(vw->viking_vvp), VIK_VIEWPORT_MIN_ZOOM, VIK_VIEWPORT_MAX_ZOOM/2.0, 1, 100, 3 )), 16, 3);
 
   total_size_label = gtk_label_new ( NULL );
 
-  current_window_button = gtk_button_new_with_label ( "Area in current viewable window" );
+  current_window_button = gtk_button_new_with_label ( _("Area in current viewable window") );
   current_window_pass_along [0] = vw;
   current_window_pass_along [1] = width_spin;
   current_window_pass_along [2] = height_spin;
@@ -1072,8 +1582,8 @@ static void draw_to_image_file ( VikWindow *vw, const gchar *fn, gboolean one_im
   current_window_pass_along [6] = total_size_label;
   g_signal_connect ( G_OBJECT(current_window_button), "button_press_event", G_CALLBACK(draw_to_image_file_current_window_cb), current_window_pass_along );
 
-  png_radio = gtk_radio_button_new_with_label ( NULL, "Save as PNG" );
-  jpeg_radio = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(png_radio), "Save as JPEG" );
+  png_radio = gtk_radio_button_new_with_label ( NULL, _("Save as PNG") );
+  jpeg_radio = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(png_radio), _("Save as JPEG") );
 
   if ( ! vw->draw_image_save_as_png )
     gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON(jpeg_radio), TRUE );
@@ -1093,9 +1603,9 @@ static void draw_to_image_file ( VikWindow *vw, const gchar *fn, gboolean one_im
     GtkWidget *tiles_width_label, *tiles_height_label;
 
 
-    tiles_width_label = gtk_label_new ( "East-west image tiles:" );
+    tiles_width_label = gtk_label_new ( _("East-west image tiles:") );
     tiles_width_spin = gtk_spin_button_new ( GTK_ADJUSTMENT(gtk_adjustment_new ( 5, 1, 10, 1, 100, 0 )), 1, 0 );
-    tiles_height_label = gtk_label_new ( "North-south image tiles:" );
+    tiles_height_label = gtk_label_new ( _("North-south image tiles:") );
     tiles_height_spin = gtk_spin_button_new ( GTK_ADJUSTMENT(gtk_adjustment_new ( 5, 1, 10, 1, 100, 0 )), 1, 0 );
     gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), tiles_width_label, FALSE, FALSE, 0);
     gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), tiles_width_spin, FALSE, FALSE, 0);
@@ -1135,7 +1645,7 @@ static void draw_to_image_file ( VikWindow *vw, const gchar *fn, gboolean one_im
                        gtk_spin_button_get_value ( GTK_SPIN_BUTTON(tiles_width_spin) ),
                        gtk_spin_button_get_value ( GTK_SPIN_BUTTON(tiles_height_spin) ) );
       else
-        a_dialog_error_msg ( GTK_WINDOW(vw), "You must be in UTM mode to use this feature" );
+        a_dialog_error_msg ( GTK_WINDOW(vw), _("You must be in UTM mode to use this feature") );
     }
   }
   gtk_widget_destroy ( GTK_WIDGET(dialog) );
@@ -1144,43 +1654,54 @@ static void draw_to_image_file ( VikWindow *vw, const gchar *fn, gboolean one_im
 
 static void draw_to_image_file_cb ( GtkAction *a, VikWindow *vw )
 {
-  GtkWidget *file_selector;
   const gchar *fn;
-  file_selector = gtk_file_selection_new ("Save Image");
+  if (!vw->save_img_dia) {
+    vw->save_img_dia = gtk_file_selection_new ( _("Save Image") );
+    gtk_window_set_transient_for ( GTK_WINDOW(vw->save_img_dia), GTK_WINDOW(vw) );
+    gtk_window_set_destroy_with_parent ( GTK_WINDOW(vw->save_img_dia), TRUE );
+  }
 
-  while ( gtk_dialog_run ( GTK_DIALOG(file_selector) ) == GTK_RESPONSE_OK )
+  while ( gtk_dialog_run ( GTK_DIALOG(vw->save_img_dia) ) == GTK_RESPONSE_OK )
   {
-    fn = gtk_file_selection_get_filename (GTK_FILE_SELECTION(file_selector) );
-    if ( access ( fn, F_OK ) != 0 || a_dialog_overwrite ( GTK_WINDOW(file_selector), "The file \"%s\" exists, do you wish to overwrite it?", a_file_basename ( fn ) ) )
+    fn = gtk_file_selection_get_filename (GTK_FILE_SELECTION(vw->save_img_dia) );
+    if ( access ( fn, F_OK ) != 0 || a_dialog_overwrite ( GTK_WINDOW(vw->save_img_dia), _("The file \"%s\" exists, do you wish to overwrite it?"), a_file_basename ( fn ) ) )
     {
-      gtk_widget_hide ( file_selector );
       draw_to_image_file ( vw, fn, TRUE );
       break;
     }
   }
-  gtk_widget_destroy ( file_selector );
+  gtk_widget_hide ( vw->save_img_dia );
 }
 
 static void draw_to_image_dir_cb ( GtkAction *a, VikWindow *vw )
 {
-  GtkWidget *file_selector;
   const gchar *fn;
-  file_selector = gtk_file_selection_new ("Choose a name for a new directory to hold images");
+  if (!vw->save_img_dir_dia) {
+    vw->save_img_dir_dia = gtk_file_selection_new ( _("Choose a name for a new directory to hold images"));
+    gtk_window_set_transient_for ( GTK_WINDOW(vw->save_img_dir_dia), GTK_WINDOW(vw) );
+    gtk_window_set_destroy_with_parent ( GTK_WINDOW(vw->save_img_dir_dia), TRUE );
+  }
 
-  while ( gtk_dialog_run ( GTK_DIALOG(file_selector) ) == GTK_RESPONSE_OK )
+  while ( gtk_dialog_run ( GTK_DIALOG(vw->save_img_dir_dia) ) == GTK_RESPONSE_OK )
   {
-    fn = gtk_file_selection_get_filename (GTK_FILE_SELECTION(file_selector) );
+    fn = gtk_file_selection_get_filename (GTK_FILE_SELECTION(vw->save_img_dir_dia) );
     if ( access ( fn, F_OK ) == 0 )
-      a_dialog_info_msg_extra ( GTK_WINDOW(file_selector), "The file %s exists. Please choose a name for a new directory to hold images in that does not exist.", a_file_basename(fn) );
+      a_dialog_info_msg_extra ( GTK_WINDOW(vw->save_img_dir_dia), _("The file %s exists. Please choose a name for a new directory to hold images in that does not exist."), a_file_basename(fn) );
     else
     {
-      gtk_widget_hide ( file_selector );
       draw_to_image_file ( vw, fn, FALSE );
       break;
     }
   }
-  gtk_widget_destroy ( file_selector );
+  gtk_widget_hide ( vw->save_img_dir_dia );
+}
+
+#if GTK_CHECK_VERSION(2,10,0)
+static void print_cb ( GtkAction *a, VikWindow *vw )
+{
+  a_print(vw, vw->viking_vvp);
 }
+#endif
 
 /* really a misnomer: changes coord mode (actual coordinates) AND/OR draw mode (viewport only) */
 static void window_change_coord_mode_cb ( GtkAction *old_a, GtkAction *a, VikWindow *vw )
@@ -1202,7 +1723,7 @@ static void window_change_coord_mode_cb ( GtkAction *old_a, GtkAction *a, VikWin
     drawmode = VIK_VIEWPORT_DRAWMODE_MERCATOR;
   }
   else {
-    fprintf(stderr, "Houston, we got a problem!\n");
+    g_critical("Houston, we got a problem!\n");
     return;
   }
 
@@ -1225,13 +1746,25 @@ static void window_change_coord_mode_cb ( GtkAction *old_a, GtkAction *a, VikWin
 
 static void set_draw_scale ( GtkAction *a, VikWindow *vw )
 {
-  vik_viewport_set_draw_scale ( vw->viking_vvp, !vik_viewport_get_draw_scale(vw->viking_vvp) );
+  GtkWidget *check_box = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/ShowScale" );
+  g_assert(check_box);
+  gboolean state = gtk_check_menu_item_get_active ( GTK_CHECK_MENU_ITEM(check_box));
+  vik_viewport_set_draw_scale ( vw->viking_vvp, state );
+  draw_update ( vw );
+}
+
+static void set_draw_centermark ( GtkAction *a, VikWindow *vw )
+{
+  GtkWidget *check_box = gtk_ui_manager_get_widget ( vw->uim, "/ui/MainMenu/View/ShowCenterMark" );
+  g_assert(check_box);
+  gboolean state = gtk_check_menu_item_get_active ( GTK_CHECK_MENU_ITEM(check_box));
+  vik_viewport_set_draw_centermark ( vw->viking_vvp, state );
   draw_update ( vw );
 }
 
 static void set_bg_color ( GtkAction *a, VikWindow *vw )
 {
-  GtkWidget *colorsd = gtk_color_selection_dialog_new ("Choose a background color");
+  GtkWidget *colorsd = gtk_color_selection_dialog_new ( _("Choose a background color") );
   GdkColor *color = vik_viewport_get_background_gdkcolor ( vw->viking_vvp );
   gtk_color_selection_set_previous_color ( GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(colorsd)->colorsel), color );
   gtk_color_selection_set_current_color ( GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(colorsd)->colorsel), color );
@@ -1245,64 +1778,95 @@ static void set_bg_color ( GtkAction *a, VikWindow *vw )
   gtk_widget_destroy ( colorsd );
 }
 
+
+
+/***********************************************************************************************
+ ** GUI Creation
+ ***********************************************************************************************/
+
 static GtkActionEntry entries[] = {
-  { "File", NULL, "_File", 0, 0, 0 },
-  { "View", NULL, "_View", 0, 0, 0 },
-  { "SetZoom", NULL, "_Zoom", 0, 0, 0 },
-  { "Layers", NULL, "_Layers", 0, 0, 0 },
-  { "Tools", NULL, "_Tools", 0, 0, 0 },
-
-  { "New",       GTK_STOCK_NEW,          "_New",                          "<control>N", "New file",                                     (GCallback)newwindow_cb          },
-  { "Open",      GTK_STOCK_OPEN,         "_Open",                         "<control>O", "Open a file",                                  (GCallback)load_file             },
-  { "Append",    GTK_STOCK_ADD,          "A_ppend File",                  NULL,         "Append data from a different file",            (GCallback)load_file             },
-  { "Save",      GTK_STOCK_SAVE,         "_Save",                         "<control>S", "Save the file",                                (GCallback)save_file             },
-  { "SaveAs",    GTK_STOCK_SAVE_AS,      "Save _As",                      NULL,         "Save the file under different name",           (GCallback)save_file_as          },
-  { "GenImg",    GTK_STOCK_CLEAR,        "_Generate Image File",          NULL,         "Save a snapshot of the workspace into a file", (GCallback)draw_to_image_file_cb },
-  { "GenImgDir", GTK_STOCK_DND_MULTIPLE, "Generate _Directory of Images", NULL,         "FIXME:IMGDIR",                                 (GCallback)draw_to_image_dir_cb  },
-  { "Exit",      GTK_STOCK_QUIT,         "E_xit",                         "<control>W", "Exit the program",                             (GCallback)window_close          },
-
-  { "GotoLL",    GTK_STOCK_QUIT,         "_Go to Lat\\/Lon...",           NULL,         "Go to arbitrary lat\\/lon coordinate",         (GCallback)draw_goto_cb          },
-  { "GotoUTM",   GTK_STOCK_QUIT,         "Go to UTM...",                  NULL,         "Go to arbitrary UTM coordinate",               (GCallback)draw_goto_cb          },
-  { "SetBGColor",GTK_STOCK_SELECT_COLOR, "Set Background Color...",       NULL,         NULL,                                           (GCallback)set_bg_color          },
-  { "ZoomIn",    GTK_STOCK_ZOOM_IN,      "Zoom _In",                   "<control>plus", NULL,                                           (GCallback)draw_zoom_cb          },
-  { "ZoomOut",   GTK_STOCK_ZOOM_OUT,     "Zoom _Out",                 "<control>minus", NULL,                                           (GCallback)draw_zoom_cb          },
-  { "ZoomTo",    GTK_STOCK_ZOOM_FIT,     "Zoom _To",               "<control><shift>Z", NULL,                                           (GCallback)zoom_to_cb            },
-  { "Zoom0.25",  NULL,                   "0.25",                          NULL,         NULL,                                           (GCallback)draw_zoom_cb          },
-  { "Zoom0.5",   NULL,                   "0.5",                           NULL,         NULL,                                           (GCallback)draw_zoom_cb          },
-  { "Zoom1",     NULL,                   "1",                             NULL,         NULL,                                           (GCallback)draw_zoom_cb          },
-  { "Zoom2",     NULL,                   "2",                             NULL,         NULL,                                           (GCallback)draw_zoom_cb          },
-  { "Zoom4",     NULL,                   "4",                             NULL,         NULL,                                           (GCallback)draw_zoom_cb          },
-  { "Zoom8",     NULL,                   "8",                             NULL,         NULL,                                           (GCallback)draw_zoom_cb          },
-  { "Zoom16",    NULL,                   "16",                            NULL,         NULL,                                           (GCallback)draw_zoom_cb          },
-  { "Zoom32",    NULL,                   "32",                            NULL,         NULL,                                           (GCallback)draw_zoom_cb          },
-  { "Zoom64",    NULL,                   "64",                            NULL,         NULL,                                           (GCallback)draw_zoom_cb          },
-  { "Zoom128",   NULL,                   "128",                           NULL,         NULL,                                           (GCallback)draw_zoom_cb          },
-  { "BGJobs",    GTK_STOCK_EXECUTE,      "Background _Jobs",              NULL,         NULL,                                           (GCallback)a_background_show_window },
-
-  { "Cut",       GTK_STOCK_CUT,          "Cu_t",                          NULL,         NULL,                                           (GCallback)menu_cut_layer_cb     },
-  { "Copy",      GTK_STOCK_COPY,         "_Copy",                         NULL,         NULL,                                           (GCallback)menu_copy_layer_cb    },
-  { "Paste",     GTK_STOCK_PASTE,        "_Paste",                        NULL,         NULL,                                           (GCallback)menu_paste_layer_cb   },
-  { "Delete",    GTK_STOCK_DELETE,       "_Delete",                       NULL,         NULL,                                           (GCallback)menu_delete_layer_cb  },
-  { "DeleteAll", NULL,                   "Delete All",                    NULL,         NULL,                                           (GCallback)clear_cb              },
-  { "Properties",GTK_STOCK_PROPERTIES,   "_Properties",                   NULL,         NULL,                                           (GCallback)menu_properties_cb    },
+  { "File", NULL, N_("_File"), 0, 0, 0 },
+  { "Edit", NULL, N_("_Edit"), 0, 0, 0 },
+  { "View", NULL, N_("_View"), 0, 0, 0 },
+  { "SetZoom", NULL, N_("_Zoom"), 0, 0, 0 },
+  { "SetPan", NULL, N_("_Pan"), 0, 0, 0 },
+  { "Layers", NULL, N_("_Layers"), 0, 0, 0 },
+  { "Tools", NULL, N_("_Tools"), 0, 0, 0 },
+  { "Help", NULL, N_("_Help"), 0, 0, 0 },
+
+  { "New",       GTK_STOCK_NEW,          N_("_New"),                          "<control>N", N_("New file"),                                     (GCallback)newwindow_cb          },
+  { "Open",      GTK_STOCK_OPEN,         N_("_Open"),                         "<control>O", N_("Open a file"),                                  (GCallback)load_file             },
+  { "Append",    GTK_STOCK_ADD,          N_("A_ppend File"),                  NULL,         N_("Append data from a different file"),            (GCallback)load_file             },
+  { "Acquire", NULL, N_("A_cquire"), 0, 0, 0 },
+  { "AcquireGPS",   NULL,                N_("From _GPS"),                NULL,         N_("Transfer data from a GPS device"),              (GCallback)acquire_from_gps      },
+  { "AcquireGoogle",   NULL,             N_("Google _Directions"),       NULL,         N_("Get driving directions from Google"),           (GCallback)acquire_from_google   },
+#ifdef VIK_CONFIG_GEOCACHES
+  { "AcquireGC",   NULL,                 N_("Geo_caches"),               NULL,         N_("Get Geocaches from geocaching.com"),            (GCallback)acquire_from_gc       },
+#endif
+  { "Save",      GTK_STOCK_SAVE,         N_("_Save"),                         "<control>S", N_("Save the file"),                                (GCallback)save_file             },
+  { "SaveAs",    GTK_STOCK_SAVE_AS,      N_("Save _As"),                      NULL,         N_("Save the file under different name"),           (GCallback)save_file_as          },
+  { "GenImg",    GTK_STOCK_CLEAR,        N_("_Generate Image File"),          NULL,         N_("Save a snapshot of the workspace into a file"), (GCallback)draw_to_image_file_cb },
+  { "GenImgDir", GTK_STOCK_DND_MULTIPLE, N_("Generate _Directory of Images"), NULL,         N_("FIXME:IMGDIR"),                                 (GCallback)draw_to_image_dir_cb  },
+
+#if GTK_CHECK_VERSION(2,10,0)
+  { "Print",    GTK_STOCK_PRINT,        N_("_Print..."),          NULL,         N_("Print maps"), (GCallback)print_cb },
+#endif
+
+  { "Exit",      GTK_STOCK_QUIT,         N_("E_xit"),                         "<control>W", N_("Exit the program"),                             (GCallback)window_close          },
+  { "SaveExit",  GTK_STOCK_QUIT,         N_("Save and Exit"),                 NULL, N_("Save and Exit the program"),                             (GCallback)save_file_and_exit          },
+
+  { "GoogleMapsSearch",   GTK_STOCK_GO_FORWARD,                 N_("Go To Google Maps location"),                NULL,         N_("Go to address/place using Google Maps search"),            (GCallback)goto_address       },
+  { "GotoLL",    GTK_STOCK_QUIT,         N_("_Go to Lat\\/Lon..."),           NULL,         N_("Go to arbitrary lat\\/lon coordinate"),         (GCallback)draw_goto_cb          },
+  { "GotoUTM",   GTK_STOCK_QUIT,         N_("Go to UTM..."),                  NULL,         N_("Go to arbitrary UTM coordinate"),               (GCallback)draw_goto_cb          },
+  { "SetBGColor",GTK_STOCK_SELECT_COLOR, N_("Set Background Color..."),       NULL,         NULL,                                           (GCallback)set_bg_color          },
+  { "ZoomIn",    GTK_STOCK_ZOOM_IN,      N_("Zoom _In"),                   "<control>plus", NULL,                                           (GCallback)draw_zoom_cb          },
+  { "ZoomOut",   GTK_STOCK_ZOOM_OUT,     N_("Zoom _Out"),                 "<control>minus", NULL,                                           (GCallback)draw_zoom_cb          },
+  { "ZoomTo",    GTK_STOCK_ZOOM_FIT,     N_("Zoom _To"),               "<control><shift>Z", NULL,                                           (GCallback)zoom_to_cb            },
+  { "Zoom0.25",  NULL,                   N_("0.25"),                          NULL,         NULL,                                           (GCallback)draw_zoom_cb          },
+  { "Zoom0.5",   NULL,                   N_("0.5"),                           NULL,         NULL,                                           (GCallback)draw_zoom_cb          },
+  { "Zoom1",     NULL,                   N_("1"),                             NULL,         NULL,                                           (GCallback)draw_zoom_cb          },
+  { "Zoom2",     NULL,                   N_("2"),                             NULL,         NULL,                                           (GCallback)draw_zoom_cb          },
+  { "Zoom4",     NULL,                   N_("4"),                             NULL,         NULL,                                           (GCallback)draw_zoom_cb          },
+  { "Zoom8",     NULL,                   N_("8"),                             NULL,         NULL,                                           (GCallback)draw_zoom_cb          },
+  { "Zoom16",    NULL,                   N_("16"),                            NULL,         NULL,                                           (GCallback)draw_zoom_cb          },
+  { "Zoom32",    NULL,                   N_("32"),                            NULL,         NULL,                                           (GCallback)draw_zoom_cb          },
+  { "Zoom64",    NULL,                   N_("64"),                            NULL,         NULL,                                           (GCallback)draw_zoom_cb          },
+  { "Zoom128",   NULL,                   N_("128"),                           NULL,         NULL,                                           (GCallback)draw_zoom_cb          },
+  { "PanNorth",  NULL,                   N_("Pan North"),                  "<control>Up", NULL,                                           (GCallback)draw_pan_cb },
+  { "PanEast",  NULL,                    N_("Pan East"),                   "<control>Right", NULL,                                           (GCallback)draw_pan_cb },
+  { "PanSouth",  NULL,                   N_("Pan South"),                  "<control>Down", NULL,                                           (GCallback)draw_pan_cb },
+  { "PanWest",  NULL,                    N_("Pan West"),                   "<control>Left", NULL,                                           (GCallback)draw_pan_cb },
+  { "BGJobs",    GTK_STOCK_EXECUTE,      N_("Background _Jobs"),              NULL,         NULL,                                           (GCallback)a_background_show_window },
+
+  { "Cut",       GTK_STOCK_CUT,          N_("Cu_t"),                          NULL,         NULL,                                           (GCallback)menu_cut_layer_cb     },
+  { "Copy",      GTK_STOCK_COPY,         N_("_Copy"),                         NULL,         NULL,                                           (GCallback)menu_copy_layer_cb    },
+  { "Paste",     GTK_STOCK_PASTE,        N_("_Paste"),                        NULL,         NULL,                                           (GCallback)menu_paste_layer_cb   },
+  { "Delete",    GTK_STOCK_DELETE,       N_("_Delete"),                       NULL,         NULL,                                           (GCallback)menu_delete_layer_cb  },
+  { "DeleteAll", NULL,                   N_("Delete All"),                    NULL,         NULL,                                           (GCallback)clear_cb              },
+  { "Preferences",GTK_STOCK_PREFERENCES, N_("_Preferences..."),                    NULL,         NULL,                                           (GCallback)preferences_cb              },
+  { "Properties",GTK_STOCK_PROPERTIES,   N_("_Properties"),                   NULL,         NULL,                                           (GCallback)menu_properties_cb    },
+
+  { "About",     GTK_STOCK_ABOUT,        N_("_About"),                        NULL,         NULL,                                           (GCallback)help_about_cb    },
 };
 
 /* Radio items */
 static GtkRadioActionEntry mode_entries[] = {
-  { "ModeUTM",         NULL,         "_UTM Mode",               "<control>u", NULL, 0 },
-  { "ModeExpedia",     NULL,         "_Expedia Mode",           "<control>e", NULL, 1 },
-  { "ModeGoogle",      NULL,         "_Google Mode",            "<control>g", NULL, 2 },
-  { "ModeKH",          NULL,         "_KH\\/Flat LatLon Mode",  "<control>k", NULL, 3 },
-  { "ModeMercator",    NULL,         "_Mercator (New Google)",  "<control>m", NULL, 4 }
+  { "ModeUTM",         NULL,         N_("_UTM Mode"),               "<control>u", NULL, 0 },
+  { "ModeExpedia",     NULL,         N_("_Expedia Mode"),           "<control>e", NULL, 1 },
+  { "ModeGoogle",      NULL,         N_("_Old Google Mode"),        "<control>o", NULL, 2 },
+  { "ModeKH",          NULL,         N_("Old _KH Mode"),            "<control>k", NULL, 3 },
+  { "ModeMercator",    NULL,         N_("_Google Mode"),            "<control>g", NULL, 4 }
 };
 
 static GtkRadioActionEntry tool_entries[] = {
-  { "Zoom",      "vik-icon-zoom",        "_Zoom",                         "<control><shift>Z", "Zoom Tool",  0 },
-  { "Ruler",     "vik-icon-ruler",       "_Ruler",                        "<control><shift>R", "Ruler Tool", 1 }
+  { "Zoom",      "vik-icon-zoom",        N_("_Zoom"),                         "<control><shift>Z", N_("Zoom Tool"),  0 },
+  { "Ruler",     "vik-icon-ruler",       N_("_Ruler"),                        "<control><shift>R", N_("Ruler Tool"), 1 }
 };
 
 static GtkToggleActionEntry toggle_entries[] = {
-  { "ShowScale", NULL,                   "Show Scale",                    NULL,         NULL,                                           (GCallback)set_draw_scale, TRUE   },
+  { "ShowScale", NULL,                   N_("Show Scale"),                    NULL,         NULL,                                           (GCallback)set_draw_scale, TRUE   },
+  { "ShowCenterMark", NULL,                   N_("Show Center Mark"),                    NULL,         NULL,                                           (GCallback)set_draw_centermark, TRUE   },
+  { "FullScreen",    NULL,      N_("Full Screen"),                   "F11", NULL,                                           (GCallback)full_screen_cb, FALSE },
 };
 
 #include "menu.xml.h"
@@ -1321,7 +1885,9 @@ static void window_create_ui( VikWindow *window )
   uim = gtk_ui_manager_new ();
   window->uim = uim;
 
-  
+  toolbox_add_tool(window->vt, &ruler_tool, TOOL_LAYER_TYPE_NONE);
+  toolbox_add_tool(window->vt, &zoom_tool, TOOL_LAYER_TYPE_NONE);
+
   error = NULL;
   if (!(mid = gtk_ui_manager_add_ui_from_string (uim, menu_xml, -1, &error))) {
     g_error_free (error);
@@ -1329,11 +1895,13 @@ static void window_create_ui( VikWindow *window )
   }
 
   action_group = gtk_action_group_new ("MenuActions");
+  gtk_action_group_set_translation_domain(action_group, PACKAGE_NAME);
   gtk_action_group_add_actions (action_group, entries, G_N_ELEMENTS (entries), window);
   gtk_action_group_add_toggle_actions (action_group, toggle_entries, G_N_ELEMENTS (toggle_entries), window);
-  gtk_action_group_add_radio_actions (action_group, mode_entries, G_N_ELEMENTS (mode_entries), 0, (GCallback)window_change_coord_mode_cb, window);
+  gtk_action_group_add_radio_actions (action_group, mode_entries, G_N_ELEMENTS (mode_entries), 4, (GCallback)window_change_coord_mode_cb, window);
 
   icon_factory = gtk_icon_factory_new ();
+  gtk_icon_factory_add_default (icon_factory); 
 
   register_vik_icons(icon_factory);
 
@@ -1359,7 +1927,7 @@ static void window_create_ui( VikWindow *window )
 
     action.name = vik_layer_get_interface(i)->name;
     action.stock_id = vik_layer_get_interface(i)->name;
-    action.label = g_strdup_printf("New %s Layer", vik_layer_get_interface(i)->name);
+    action.label = g_strdup_printf( _("New %s Layer"), vik_layer_get_interface(i)->name);
     action.accelerator = NULL;
     action.tooltip = NULL;
     action.callback = (GCallback)menu_addlayer_cb;
@@ -1376,54 +1944,67 @@ static void window_create_ui( VikWindow *window )
       ntools++;
       
       gtk_ui_manager_add_ui(uim, mid,  "/ui/MainMenu/Tools", 
-                           vik_layer_get_interface(i)->tools[j].name,
+                           _(vik_layer_get_interface(i)->tools[j].name),
                            vik_layer_get_interface(i)->tools[j].name,
                            GTK_UI_MANAGER_MENUITEM, FALSE);
       gtk_ui_manager_add_ui(uim, mid,  "/ui/MainToolbar/ToolItems", 
-                           vik_layer_get_interface(i)->tools[j].name,
+                           _(vik_layer_get_interface(i)->tools[j].name),
                            vik_layer_get_interface(i)->tools[j].name,
                            GTK_UI_MANAGER_TOOLITEM, FALSE);
 
+      toolbox_add_tool(window->vt, &(vik_layer_get_interface(i)->tools[j]), i);
+
       radio->name = vik_layer_get_interface(i)->tools[j].name;
       radio->stock_id = vik_layer_get_interface(i)->tools[j].name,
-      radio->label = vik_layer_get_interface(i)->tools[j].name;
+      radio->label = _(vik_layer_get_interface(i)->tools[j].name);
       radio->accelerator = NULL;
-      radio->tooltip = vik_layer_get_interface(i)->tools[j].name;
+      radio->tooltip = _(vik_layer_get_interface(i)->tools[j].name);
       radio->value = ntools;
     }
   }
+  g_object_unref (icon_factory);
 
   gtk_action_group_add_radio_actions(action_group, tools, ntools, 0, (GCallback)menu_tool_cb, window);
   g_free(tools);
 
   gtk_ui_manager_insert_action_group (uim, action_group, 0);
 
+  for (i=0; i<VIK_LAYER_NUM_TYPES; i++) {
+    for ( j = 0; j < vik_layer_get_interface(i)->tools_count; j++ ) {
+      GtkAction *action = gtk_action_group_get_action(action_group,
+                           vik_layer_get_interface(i)->tools[j].name);
+      g_object_set(action, "sensitive", FALSE, NULL);
+    }
+  }
+  window->action_group = action_group;
+
   accel_group = gtk_ui_manager_get_accel_group (uim);
   gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
   gtk_ui_manager_ensure_update (uim);
-  gtk_icon_factory_add_default (icon_factory); 
-  g_object_unref (icon_factory);
 }
 
 
-#include "icons.h"
+
+#include "icons/icons.h"
 static struct { 
   const GdkPixdata *data;
   gchar *stock_id;
 } stock_icons[] = {
   { &addtr_18,         "Create Track"      },
+  { &begintr_18,       "Begin Track"      },
   { &edtr_18,          "Edit Trackpoint"   },
   { &addwp_18,         "Create Waypoint"   },
   { &edwp_18,          "Edit Waypoint"     },
+  { &iscissors_18,     "Magic Scissors"   },
   { &zoom_18,          "vik-icon-zoom"     },
   { &ruler_18,         "vik-icon-ruler"    },
   { &geozoom_18,       "Georef Zoom Tool"  },
   { &geomove_18,       "Georef Move Map"   },
   { &mapdl_18,         "Maps Download"     },
+  { &demdl_18,         "DEM Download/Import"     },
   { &showpic_18,       "Show Picture"      },
 };
  
-
 static gint n_stock_icons = G_N_ELEMENTS (stock_icons);
 
 static void
@@ -1439,3 +2020,25 @@ register_vik_icons (GtkIconFactory *icon_factory)
     gtk_icon_set_unref (icon_set);
   }
 }
+
+void vik_window_cursors_init()
+{
+  GdkPixbuf *cursor_pixbuf;
+  GError *cursor_load_err;
+
+  cursor_pixbuf = gdk_pixbuf_from_pixdata (&cursor_zoom, FALSE, &cursor_load_err);
+  vw_cursor_zoom = gdk_cursor_new_from_pixbuf ( gdk_display_get_default(), cursor_pixbuf, 6, 6 );
+
+  g_object_unref ( G_OBJECT(cursor_pixbuf) );
+
+  cursor_pixbuf = gdk_pixbuf_from_pixdata (&cursor_ruler, FALSE, &cursor_load_err);
+  vw_cursor_ruler = gdk_cursor_new_from_pixbuf ( gdk_display_get_default(), cursor_pixbuf, 6, 6 );
+
+  g_object_unref ( G_OBJECT(cursor_pixbuf) );
+}
+
+void vik_window_cursors_uninit()
+{
+  gdk_cursor_unref ( vw_cursor_zoom );
+  gdk_cursor_unref ( vw_cursor_ruler );
+}