]> git.street.me.uk Git - andy/viking.git/blobdiff - src/viktrwlayer_propwin.c
Enable control of create_label_vbox spacing and padding.
[andy/viking.git] / src / viktrwlayer_propwin.c
index 000f49e06d9d98dd6fae58b5cf3f20b14ebf091c..73807d531e4f03698600ff42323071c9652a52ce 100644 (file)
 #ifdef HAVE_STRING_H
 #include <string.h>
 #endif
-#include "coords.h"
-#include "vikcoord.h"
-#include "viktrack.h"
 #include "viktrwlayer.h"
 #include "viktrwlayer_propwin.h"
-#include "vikwaypoint.h"
-#include "dialog.h"
-#include "globals.h"
 #include "dems.h"
-
+#include "viking.h"
 #include "vikviewport.h" /* ugh */
-#include "viktreeview.h" /* ugh */
 #include <gdk-pixbuf/gdk-pixdata.h>
-#include "viklayer.h" /* ugh */
-#include "vikaggregatelayer.h"
-#include "viklayerspanel.h" /* ugh */
-
-#define PROPWIN_PROFILE_WIDTH 600
-#define PROPWIN_PROFILE_HEIGHT 300
 
 typedef enum {
   PROPWIN_GRAPH_TYPE_ELEVATION_DISTANCE,
@@ -76,7 +63,10 @@ static const gdouble chunksa[] = {2.0, 5.0, 10.0, 15.0, 20.0,
 static const gdouble chunksg[] = {1.0, 2.0, 3.0, 4.0, 5.0, 8.0, 10.0,
                                  12.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0, 45.0, 50.0, 75.0,
                                  100.0, 150.0, 200.0, 250.0, 375.0, 500.0,
-                                 750.0, 1000.0, 10000.0};
+                                 750.0, 1000.0, 10000.0, 100000.0};
+// Normally gradients should range up to couple hundred precent at most,
+//  however there are possibilities of having points with no altitude after a point with a big altitude
+//  (such as places with invalid DEM values in otherwise mountainous regions) - thus giving huge negative gradients.
 
 /* (Hopefully!) Human friendly grid sizes - note no fixed 'ratio' just numbers that look nice...*/
 /* As need to cover walking speeds - have many low numbers (but also may go up to airplane speeds!) */
@@ -244,113 +234,52 @@ static void minmax_array(const gdouble *array, gdouble *min, gdouble *max, gbool
 #define MARGIN 70
 #define LINES 5
 /**
+ * get_new_min_and_chunk_index:
  * Returns via pointers:
- *   the new minimum value to be used for the altitude graph
- *   the index in to the altitudes chunk sizes array (ci = Chunk Index)
+ *   the new minimum value to be used for the graph
+ *   the index in to the chunk sizes array (ci = Chunk Index)
  */
-static void get_new_min_and_chunk_index_altitude (gdouble mina, gdouble maxa, gdouble *new_min, gint *ci)
+static void get_new_min_and_chunk_index (gdouble mina, gdouble maxa, const gdouble *chunks, size_t chunky, gdouble *new_min, gint *ci)
 {
   /* Get unitized chunk */
   /* Find suitable chunk index */
   *ci = 0;
-  gdouble diffa_chunk = (maxa - mina)/LINES;
+  gdouble diff_chunk = (maxa - mina)/LINES;
 
   /* Loop through to find best match */
-  while (diffa_chunk > chunksa[*ci]) {
+  while (diff_chunk > chunks[*ci]) {
     (*ci)++;
     /* Last Resort Check */
-    if ( *ci == sizeof(chunksa)/sizeof(chunksa[0]) )
+    if ( *ci == chunky ) {
+      // Use previous value and exit loop
+      (*ci)--;
       break;
-  }
-
-  /* Ensure adjusted minimum .. maximum covers mina->maxa */
-
-  // Now work out adjusted minimum point to the nearest lowest chunk divisor value
-  // When negative ensure logic uses lowest value
-  if ( mina < 0 )
-    *new_min = (gdouble) ( ( (gint)(mina - chunksa[*ci]) / (gint)chunksa[*ci] ) * (gint)chunksa[*ci] );
-  else
-    *new_min = (gdouble) ( ( (gint)mina / (gint)chunksa[*ci] ) * (gint)chunksa[*ci] );
-
-  // Range not big enough - as new minimum has lowered
-  if ((*new_min + (chunksa[*ci] * LINES) < maxa)) {
-    // Next chunk should cover it
-    if ( *ci < sizeof(chunksa)/sizeof(chunksa[0]) ) {
-      (*ci)++;
-      // Remember to adjust the minimum too...
-      if ( mina < 0 )
-       *new_min = (gdouble) ( ( (gint)(mina - chunksa[*ci]) / (gint)chunksa[*ci] ) * (gint)chunksa[*ci] );
-      else
-       *new_min = (gdouble) ( ( (gint)mina / (gint)chunksa[*ci] ) * (gint)chunksa[*ci] );
     }
   }
-}
-
-/**
- * Returns via pointers:
- *   the new minimum value to be used for the altitude graph
- *   the index in to the altitudes chunk sizes array (ci = Chunk Index)
- */
-static void get_new_min_and_chunk_index_gradient (gdouble mina, gdouble maxa, gdouble *new_min, gint *ci)
-{
-  /* Get unitized chunk */
-  /* Find suitable chunk index */
-  *ci = 0;
-  gdouble diffa_chunk = (maxa - mina)/LINES;
-
-  /* Loop through to find best match */
-  while (diffa_chunk > chunksg[*ci]) {
-    (*ci)++;
-    /* Last Resort Check */
-    if ( *ci == sizeof(chunksg)/sizeof(chunksg[0]) )
-      break;
-  }
 
   /* Ensure adjusted minimum .. maximum covers mina->maxa */
 
   // Now work out adjusted minimum point to the nearest lowest chunk divisor value
   // When negative ensure logic uses lowest value
   if ( mina < 0 )
-    *new_min = (gdouble) ( ( (gint)(mina - chunksg[*ci]) / (gint)chunksg[*ci] ) * (gint)chunksg[*ci] );
+    *new_min = (gdouble) ( (gint)((mina - chunks[*ci]) / chunks[*ci]) * chunks[*ci] );
   else
-    *new_min = (gdouble) ( ( (gint)mina / (gint)chunksg[*ci] ) * (gint)chunksg[*ci] );
+    *new_min = (gdouble) ( (gint)(mina / chunks[*ci]) * chunks[*ci] );
 
   // Range not big enough - as new minimum has lowered
-  if ((*new_min + (chunksg[*ci] * LINES) < maxa)) {
+  if ((*new_min + (chunks[*ci] * LINES) < maxa)) {
     // Next chunk should cover it
-    if ( *ci < sizeof(chunksg)/sizeof(chunksg[0]) ) {
+    if ( *ci < chunky-1 ) {
       (*ci)++;
       // Remember to adjust the minimum too...
       if ( mina < 0 )
-       *new_min = (gdouble) ( ( (gint)(mina - chunksg[*ci]) / (gint)chunksg[*ci] ) * (gint)chunksg[*ci] );
+        *new_min = (gdouble) ( (gint)((mina - chunks[*ci]) / chunks[*ci]) * chunks[*ci] );
       else
-       *new_min = (gdouble) ( ( (gint)mina / (gint)chunksg[*ci] ) * (gint)chunksg[*ci] );
+        *new_min = (gdouble) ( (gint)(mina / chunks[*ci]) * chunks[*ci] );
     }
   }
 }
 
-/**
- * Returns via pointers:
- *   the new minimum value to be used for the appropriate graph
- *   the index in to that array (ci = Chunk Index)
- */
-static void get_new_min_and_chunk_index (gdouble mins, gdouble maxs, const gdouble *chunks, size_t chunky, gdouble *new_min, gint *ci)
-{
-  *ci = 0;
-  gdouble diff_chunk = (maxs - mins)/LINES;
-
-  /* Loop through to find best match */
-  while (diff_chunk > chunks[*ci]) {
-    (*ci)++;
-    /* Last Resort Check */
-    if ( *ci == chunky )
-      break;
-  }
-  *new_min = (gdouble) ( (gint)((mins / chunks[*ci] ) * chunks[*ci]) );
-
-  // Speeds are never negative so don't need to worry about a negative new minimum
-}
-
 static VikTrackpoint *set_center_at_graph_position(gdouble event_x,
                                                   gint img_width,
                                                   VikTrwLayer *vtl,
@@ -556,7 +485,7 @@ static void track_graph_click( GtkWidget *event_box, GdkEventButton *event, Prop
        gdouble marker_x = (pc * widgets->profile_width) + MARGIN;
        save_image_and_draw_graph_marks(image,
                                        marker_x,
-                                       window->style->black_gc,
+                                       gtk_widget_get_style(window)->black_gc,
                                        -1, // Don't draw blob on clicks
                                        0,
                                        graph_saved_img,
@@ -764,7 +693,7 @@ void track_profile_move( GtkWidget *event_box, GdkEventMotion *event, PropWidget
 
   save_image_and_draw_graph_marks (image,
                                   marker_x,
-                                  window->style->black_gc,
+                                  gtk_widget_get_style(window)->black_gc,
                                   MARGIN+x,
                                   y_blob,
                                   &widgets->elev_graph_saved_img,
@@ -841,7 +770,7 @@ void track_gradient_move( GtkWidget *event_box, GdkEventMotion *event, PropWidge
 
   save_image_and_draw_graph_marks (image,
                                   marker_x,
-                                  window->style->black_gc,
+                                  gtk_widget_get_style(window)->black_gc,
                                   MARGIN+x,
                                   y_blob,
                                   &widgets->gradient_graph_saved_img,
@@ -932,7 +861,7 @@ void track_vt_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *wi
 
   save_image_and_draw_graph_marks (image,
                                   marker_x,
-                                  window->style->black_gc,
+                                  gtk_widget_get_style(window)->black_gc,
                                   MARGIN+x,
                                   y_blob,
                                   &widgets->speed_graph_saved_img,
@@ -1011,7 +940,7 @@ void track_dt_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *wi
 
   save_image_and_draw_graph_marks (image,
                                   marker_x,
-                                  window->style->black_gc,
+                                  gtk_widget_get_style(window)->black_gc,
                                   MARGIN+x,
                                   y_blob,
                                   &widgets->dist_graph_saved_img,
@@ -1090,7 +1019,7 @@ void track_et_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *wi
 
   save_image_and_draw_graph_marks (image,
                                   marker_x,
-                                  window->style->black_gc,
+                                  gtk_widget_get_style(window)->black_gc,
                                   MARGIN+x,
                                   y_blob,
                                   &widgets->elev_time_graph_saved_img,
@@ -1186,7 +1115,7 @@ void track_sd_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *wi
 
   save_image_and_draw_graph_marks (image,
                                   marker_x,
-                                  window->style->black_gc,
+                                  gtk_widget_get_style(window)->black_gc,
                                   MARGIN+x,
                                   y_blob,
                                   &widgets->speed_dist_graph_saved_img,
@@ -1254,6 +1183,35 @@ static void draw_dem_alt_speed_dist(VikTrack *tr,
   }
 }
 
+/**
+ * draw_grid:
+ *
+ * A common way to draw the grid with y axis labels
+ *
+ */
+static void draw_grid ( GtkWidget *window, GtkWidget *image, PropWidgets *widgets, GdkPixmap *pix, gchar *ss, gint i )
+{
+  PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
+
+  pango_layout_set_alignment (pl, PANGO_ALIGN_RIGHT);
+  pango_layout_set_font_description (pl, gtk_widget_get_style(window)->font_desc);
+
+  gchar *label_markup = g_strdup_printf ( "<span size=\"small\">%s</span>", ss );
+  pango_layout_set_markup ( pl, label_markup, -1 );
+  g_free ( label_markup );
+
+  int w, h;
+  pango_layout_get_pixel_size ( pl, &w, &h );
+
+  gdk_draw_layout ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->fg_gc[0], MARGIN-w-3,
+                    CLAMP((int)i*widgets->profile_height/LINES - h/2, 0, widgets->profile_height-h), pl );
+
+  gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[0],
+                  MARGIN, widgets->profile_height/LINES * i, MARGIN + widgets->profile_width, widgets->profile_height/LINES * i );
+  g_object_unref ( G_OBJECT ( pl ) );
+  pl = NULL;
+}
+
 /**
  * Draw just the height profile image
  */
@@ -1288,7 +1246,7 @@ static void draw_elevations (GtkWidget *image, VikTrack *tr, PropWidgets *widget
 
   minmax_array(widgets->altitudes, &widgets->min_altitude, &widgets->max_altitude, TRUE, widgets->profile_width);
 
-  get_new_min_and_chunk_index_altitude (widgets->min_altitude, widgets->max_altitude, &widgets->draw_min_altitude, &widgets->cia);
+  get_new_min_and_chunk_index (widgets->min_altitude, widgets->max_altitude, chunksa, G_N_ELEMENTS(chunksa), &widgets->draw_min_altitude, &widgets->cia);
 
   // Assign locally
   mina = widgets->draw_min_altitude;
@@ -1296,28 +1254,23 @@ static void draw_elevations (GtkWidget *image, VikTrack *tr, PropWidgets *widget
 
   window = gtk_widget_get_toplevel (widgets->elev_box);
 
-  pix = gdk_pixmap_new( window->window, widgets->profile_width + MARGIN, widgets->profile_height, -1 );
+  pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
 
   gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
 
-  no_alt_info = gdk_gc_new ( window->window );
+  no_alt_info = gdk_gc_new ( gtk_widget_get_window(window) );
   gdk_color_parse ( "yellow", &color );
   gdk_gc_set_rgb_fg_color ( no_alt_info, &color);
 
   /* clear the image */
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->bg_gc[0], 
+  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->bg_gc[0],
                     TRUE, 0, 0, MARGIN, widgets->profile_height);
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->mid_gc[0], 
+  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->mid_gc[0],
                     TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
   
   /* draw grid */
   for (i=0; i<=LINES; i++) {
-    PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
     gchar s[32];
-    int w, h;
-
-    pango_layout_set_alignment (pl, PANGO_ALIGN_RIGHT);
-    pango_layout_set_font_description (pl, window->style->font_desc);
 
     switch (height_units) {
     case VIK_UNITS_HEIGHT_METRES:
@@ -1331,15 +1284,8 @@ static void draw_elevations (GtkWidget *image, VikTrack *tr, PropWidgets *widget
       sprintf(s, "--");
       g_critical("Houston, we've had a problem. height=%d", height_units);
     }
-    pango_layout_set_text(pl, s, -1);
-    pango_layout_get_pixel_size (pl, &w, &h);
-    gdk_draw_layout(GDK_DRAWABLE(pix), window->style->fg_gc[0], MARGIN-w-3, 
-                   CLAMP((int)i*widgets->profile_height/LINES - h/2, 0, widgets->profile_height-h), pl);
 
-    gdk_draw_line (GDK_DRAWABLE(pix), window->style->dark_gc[0], 
-                  MARGIN, widgets->profile_height/LINES * i, MARGIN + widgets->profile_width, widgets->profile_height/LINES * i);
-    g_object_unref ( G_OBJECT ( pl ) );
-    pl = NULL;
+    draw_grid ( window, image, widgets, pix, s, i );
   }
 
   /* draw elevations */
@@ -1348,14 +1294,14 @@ static void draw_elevations (GtkWidget *image, VikTrack *tr, PropWidgets *widget
       gdk_draw_line ( GDK_DRAWABLE(pix), no_alt_info, 
                      i + MARGIN, 0, i + MARGIN, widgets->profile_height );
     else 
-      gdk_draw_line ( GDK_DRAWABLE(pix), window->style->dark_gc[3], 
+      gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
                      i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->altitudes[i]-mina)/(chunksa[widgets->cia]*LINES) );
 
   if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_dem)) ||
        gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_alt_gps_speed)) ) {
 
-    GdkGC *dem_alt_gc = gdk_gc_new ( window->window );
-    GdkGC *gps_speed_gc = gdk_gc_new ( window->window );
+    GdkGC *dem_alt_gc = gdk_gc_new ( gtk_widget_get_window(window) );
+    GdkGC *gps_speed_gc = gdk_gc_new ( gtk_widget_get_window(window) );
 
     gdk_color_parse ( "green", &color );
     gdk_gc_set_rgb_fg_color ( dem_alt_gc, &color);
@@ -1386,7 +1332,7 @@ static void draw_elevations (GtkWidget *image, VikTrack *tr, PropWidgets *widget
   }
 
   /* draw border */
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
+  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
 
   g_object_unref ( G_OBJECT(pix) );
   g_object_unref ( G_OBJECT(no_alt_info) );
@@ -1452,51 +1398,39 @@ static void draw_gradients (GtkWidget *image, VikTrack *tr, PropWidgets *widgets
 
   minmax_array(widgets->gradients, &widgets->min_gradient, &widgets->max_gradient, TRUE, widgets->profile_width);
 
-  get_new_min_and_chunk_index_gradient (widgets->min_gradient, widgets->max_gradient, &widgets->draw_min_gradient, &widgets->cig);
+  get_new_min_and_chunk_index (widgets->min_gradient, widgets->max_gradient, chunksg, G_N_ELEMENTS(chunksg), &widgets->draw_min_gradient, &widgets->cig);
 
   // Assign locally
   mina = widgets->draw_min_gradient;
 
   window = gtk_widget_get_toplevel (widgets->gradient_box);
 
-  pix = gdk_pixmap_new( window->window, widgets->profile_width + MARGIN, widgets->profile_height, -1 );
+  pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
 
   gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
 
   /* clear the image */
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->bg_gc[0], 
+  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->bg_gc[0],
                     TRUE, 0, 0, MARGIN, widgets->profile_height);
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->mid_gc[0], 
+  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->mid_gc[0],
                     TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
   
   /* draw grid */
   for (i=0; i<=LINES; i++) {
-    PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
     gchar s[32];
-    int w, h;
-
-    pango_layout_set_alignment (pl, PANGO_ALIGN_RIGHT);
-    pango_layout_set_font_description (pl, window->style->font_desc);
 
     sprintf(s, "%8d%%", (int)(mina + (LINES-i)*chunksg[widgets->cig]));
-    pango_layout_set_text(pl, s, -1);
-    pango_layout_get_pixel_size (pl, &w, &h);
-    gdk_draw_layout(GDK_DRAWABLE(pix), window->style->fg_gc[0], MARGIN-w-3, 
-                   CLAMP((int)i*widgets->profile_height/LINES - h/2, 0, widgets->profile_height-h), pl);
 
-    gdk_draw_line (GDK_DRAWABLE(pix), window->style->dark_gc[0], 
-                  MARGIN, widgets->profile_height/LINES * i, MARGIN + widgets->profile_width, widgets->profile_height/LINES * i);
-    g_object_unref ( G_OBJECT ( pl ) );
-    pl = NULL;
+    draw_grid ( window, image, widgets, pix, s, i );
   }
 
   /* draw gradients */
   for ( i = 0; i < widgets->profile_width; i++ )
-      gdk_draw_line ( GDK_DRAWABLE(pix), window->style->dark_gc[3], 
+    gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
                      i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->gradients[i]-mina)/(chunksg[widgets->cig]*LINES) );
 
   if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_gradient_gps_speed)) ) {
-    GdkGC *gps_speed_gc = gdk_gc_new ( window->window );
+    GdkGC *gps_speed_gc = gdk_gc_new ( gtk_widget_get_window(window) );
 
     gdk_color_parse ( "red", &color );
     gdk_gc_set_rgb_fg_color ( gps_speed_gc, &color);
@@ -1518,7 +1452,7 @@ static void draw_gradients (GtkWidget *image, VikTrack *tr, PropWidgets *widgets
   }
 
   /* draw border */
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
+  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
 
   g_object_unref ( G_OBJECT(pix) );
 }
@@ -1567,7 +1501,7 @@ static void draw_vt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
 
   window = gtk_widget_get_toplevel (widgets->speed_box);
 
-  pix = gdk_pixmap_new( window->window, widgets->profile_width + MARGIN, widgets->profile_height, -1 );
+  pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
 
   gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
 
@@ -1576,25 +1510,20 @@ static void draw_vt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
     widgets->min_speed = 0; /* splines sometimes give negative speeds */
 
   /* Find suitable chunk index */
-  get_new_min_and_chunk_index (widgets->min_speed, widgets->max_speed, chunkss, sizeof(chunkss)/sizeof(chunkss[0]), &widgets->draw_min_speed, &widgets->cis);
+  get_new_min_and_chunk_index (widgets->min_speed, widgets->max_speed, chunkss, G_N_ELEMENTS(chunkss), &widgets->draw_min_speed, &widgets->cis);
 
   // Assign locally
   mins = widgets->draw_min_speed;
   
   /* clear the image */
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->bg_gc[0], 
+  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->bg_gc[0],
                     TRUE, 0, 0, MARGIN, widgets->profile_height);
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->mid_gc[0], 
+  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->mid_gc[0],
                     TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
 
   /* draw grid */
   for (i=0; i<=LINES; i++) {
-    PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
     gchar s[32];
-    int w, h;
-
-    pango_layout_set_alignment (pl, PANGO_ALIGN_RIGHT);
-    pango_layout_set_font_description (pl, window->style->font_desc);
 
     // NB: No need to convert here anymore as numbers are in the appropriate units
     switch (speed_units) {
@@ -1615,27 +1544,19 @@ static void draw_vt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
       g_critical("Houston, we've had a problem. speed=%d", speed_units);
     }
 
-    pango_layout_set_text(pl, s, -1);
-    pango_layout_get_pixel_size (pl, &w, &h);
-    gdk_draw_layout(GDK_DRAWABLE(pix), window->style->fg_gc[0], MARGIN-w-3, 
-                   CLAMP((int)i*widgets->profile_height/LINES - h/2, 0, widgets->profile_height-h), pl);
-
-    gdk_draw_line (GDK_DRAWABLE(pix), window->style->dark_gc[0], 
-                  MARGIN, widgets->profile_height/LINES * i, MARGIN + widgets->profile_width, widgets->profile_height/LINES * i);
-    g_object_unref ( G_OBJECT ( pl ) );
-    pl = NULL;
+    draw_grid ( window, image, widgets, pix, s, i );
   }
   
 
   /* draw speeds */
   for ( i = 0; i < widgets->profile_width; i++ )
-      gdk_draw_line ( GDK_DRAWABLE(pix), window->style->dark_gc[3], 
+    gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
                      i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->speeds[i]-mins)/(chunkss[widgets->cis]*LINES) );
 
 
   if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->w_show_gps_speed)) ) {
 
-    GdkGC *gps_speed_gc = gdk_gc_new ( window->window );
+    GdkGC *gps_speed_gc = gdk_gc_new ( gtk_widget_get_window(window) );
     GdkColor color;
     gdk_color_parse ( "red", &color );
     gdk_gc_set_rgb_fg_color ( gps_speed_gc, &color);
@@ -1671,7 +1592,7 @@ static void draw_vt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
   }
 
   /* draw border */
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
+  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
 
   g_object_unref ( G_OBJECT(pix) );
 }
@@ -1710,7 +1631,7 @@ static void draw_dt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
 
   window = gtk_widget_get_toplevel (widgets->dist_box);
 
-  pix = gdk_pixmap_new( window->window, widgets->profile_width + MARGIN, widgets->profile_height, -1 );
+  pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
 
   gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
 
@@ -1724,47 +1645,34 @@ static void draw_dt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
 
   /* Find suitable chunk index */
   gdouble dummy = 0.0; // expect this to remain the same! (not that it's used)
-  get_new_min_and_chunk_index (0, maxd, chunksd, sizeof(chunksd)/sizeof(chunksd[0]), &dummy, &widgets->cid);
+  get_new_min_and_chunk_index (0, maxd, chunksd, G_N_ELEMENTS(chunksd), &dummy, &widgets->cid);
 
   /* clear the image */
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->bg_gc[0],
+  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->bg_gc[0],
                     TRUE, 0, 0, MARGIN, widgets->profile_height);
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->mid_gc[0],
+  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->mid_gc[0],
                     TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
 
   /* draw grid */
   for (i=0; i<=LINES; i++) {
-    PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
     gchar s[32];
-    int w, h;
-
-    pango_layout_set_alignment (pl, PANGO_ALIGN_RIGHT);
-    pango_layout_set_font_description (pl, window->style->font_desc);
 
     if ( dist_units == VIK_UNITS_DISTANCE_MILES )
       sprintf(s, _("%.1f miles"), ((LINES-i)*chunksd[widgets->cid]));
     else
       sprintf(s, _("%.1f km"), ((LINES-i)*chunksd[widgets->cid]));
 
-    pango_layout_set_text(pl, s, -1);
-    pango_layout_get_pixel_size (pl, &w, &h);
-    gdk_draw_layout(GDK_DRAWABLE(pix), window->style->fg_gc[0], MARGIN-w-3,
-                   CLAMP((int)i*widgets->profile_height/LINES - h/2, 0, widgets->profile_height-h), pl);
-
-    gdk_draw_line (GDK_DRAWABLE(pix), window->style->dark_gc[0],
-                  MARGIN, widgets->profile_height/LINES * i, MARGIN + widgets->profile_width, widgets->profile_height/LINES * i);
-    g_object_unref ( G_OBJECT ( pl ) );
-    pl = NULL;
+    draw_grid ( window, image, widgets, pix, s, i );
   }
   
   /* draw distance */
   for ( i = 0; i < widgets->profile_width; i++ )
-      gdk_draw_line ( GDK_DRAWABLE(pix), window->style->dark_gc[3],
+    gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
                      i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->distances[i])/(chunksd[widgets->cid]*LINES) );
 
   // Show speed indicator
   if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->w_show_dist_speed)) ) {
-    GdkGC *dist_speed_gc = gdk_gc_new ( window->window );
+    GdkGC *dist_speed_gc = gdk_gc_new ( gtk_widget_get_window(window) );
     GdkColor color;
     gdk_color_parse ( "red", &color );
     gdk_gc_set_rgb_fg_color ( dist_speed_gc, &color);
@@ -1782,7 +1690,7 @@ static void draw_dt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
   }
 
   /* draw border */
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
+  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
 
   g_object_unref ( G_OBJECT(pix) );
 
@@ -1819,31 +1727,26 @@ static void draw_et ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
 
   minmax_array(widgets->ats, &widgets->min_altitude, &widgets->max_altitude, TRUE, widgets->profile_width);
 
-  get_new_min_and_chunk_index_altitude (widgets->min_altitude, widgets->max_altitude, &widgets->draw_min_altitude_time, &widgets->ciat);
+  get_new_min_and_chunk_index (widgets->min_altitude, widgets->max_altitude, chunksa, G_N_ELEMENTS(chunksa), &widgets->draw_min_altitude_time, &widgets->ciat);
 
   // Assign locally
   mina = widgets->draw_min_altitude_time;
 
   window = gtk_widget_get_toplevel (widgets->elev_time_box);
 
-  pix = gdk_pixmap_new( window->window, widgets->profile_width + MARGIN, widgets->profile_height, -1 );
+  pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
 
   gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
 
   /* clear the image */
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->bg_gc[0],
+  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->bg_gc[0],
                     TRUE, 0, 0, MARGIN, widgets->profile_height);
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->mid_gc[0],
+  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->mid_gc[0],
                     TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
 
   /* draw grid */
   for (i=0; i<=LINES; i++) {
-    PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
     gchar s[32];
-    int w, h;
-
-    pango_layout_set_alignment (pl, PANGO_ALIGN_RIGHT);
-    pango_layout_set_font_description (pl, window->style->font_desc);
 
     switch (height_units) {
     case VIK_UNITS_HEIGHT_METRES:
@@ -1857,25 +1760,18 @@ static void draw_et ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
       sprintf(s, "--");
       g_critical("Houston, we've had a problem. height=%d", height_units);
     }
-    pango_layout_set_text(pl, s, -1);
-    pango_layout_get_pixel_size (pl, &w, &h);
-    gdk_draw_layout(GDK_DRAWABLE(pix), window->style->fg_gc[0], MARGIN-w-3,
-                   CLAMP((int)i*widgets->profile_height/LINES - h/2, 0, widgets->profile_height-h), pl);
 
-    gdk_draw_line (GDK_DRAWABLE(pix), window->style->dark_gc[0],
-                  MARGIN, widgets->profile_height/LINES * i, MARGIN + widgets->profile_width, widgets->profile_height/LINES * i);
-    g_object_unref ( G_OBJECT ( pl ) );
-    pl = NULL;
+    draw_grid ( window, image, widgets, pix, s, i );
   }
 
   /* draw elevations */
   for ( i = 0; i < widgets->profile_width; i++ )
-      gdk_draw_line ( GDK_DRAWABLE(pix), window->style->dark_gc[3],
+    gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
                      i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->ats[i]-mina)/(chunksa[widgets->ciat]*LINES) );
 
   // Show speed indicator
   if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->w_show_elev_speed)) ) {
-    GdkGC *elev_speed_gc = gdk_gc_new ( window->window );
+    GdkGC *elev_speed_gc = gdk_gc_new ( gtk_widget_get_window(window) );
     GdkColor color;
     gdk_color_parse ( "red", &color );
     gdk_gc_set_rgb_fg_color ( elev_speed_gc, &color);
@@ -1893,7 +1789,7 @@ static void draw_et ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
   }
 
   /* draw border */
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
+  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
 
   g_object_unref ( G_OBJECT(pix) );
 
@@ -1943,7 +1839,7 @@ static void draw_sd ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
 
   window = gtk_widget_get_toplevel (widgets->speed_dist_box);
 
-  pix = gdk_pixmap_new( window->window, widgets->profile_width + MARGIN, widgets->profile_height, -1 );
+  pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
 
   gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
 
@@ -1953,25 +1849,20 @@ static void draw_sd ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
     widgets->min_speed = 0; /* splines sometimes give negative speeds */
 
   /* Find suitable chunk index */
-  get_new_min_and_chunk_index (widgets->min_speed, widgets->max_speed_dist, chunkss, sizeof(chunkss)/sizeof(chunkss[0]), &widgets->draw_min_speed, &widgets->cisd);
+  get_new_min_and_chunk_index (widgets->min_speed, widgets->max_speed_dist, chunkss, G_N_ELEMENTS(chunkss), &widgets->draw_min_speed, &widgets->cisd);
 
   // Assign locally
   mins = widgets->draw_min_speed;
   
   /* clear the image */
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->bg_gc[0],
+  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->bg_gc[0],
                     TRUE, 0, 0, MARGIN, widgets->profile_height);
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->mid_gc[0],
+  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->mid_gc[0],
                     TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
 
   /* draw grid */
   for (i=0; i<=LINES; i++) {
-    PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
     gchar s[32];
-    int w, h;
-
-    pango_layout_set_alignment (pl, PANGO_ALIGN_RIGHT);
-    pango_layout_set_font_description (pl, window->style->font_desc);
 
     // NB: No need to convert here anymore as numbers are in the appropriate units
     switch (speed_units) {
@@ -1992,27 +1883,18 @@ static void draw_sd ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
       g_critical("Houston, we've had a problem. speed=%d", speed_units);
     }
 
-    pango_layout_set_text(pl, s, -1);
-    pango_layout_get_pixel_size (pl, &w, &h);
-    gdk_draw_layout(GDK_DRAWABLE(pix), window->style->fg_gc[0], MARGIN-w-3,
-                   CLAMP((int)i*widgets->profile_height/LINES - h/2, 0, widgets->profile_height-h), pl);
-
-    gdk_draw_line (GDK_DRAWABLE(pix), window->style->dark_gc[0],
-                  MARGIN, widgets->profile_height/LINES * i, MARGIN + widgets->profile_width, widgets->profile_height/LINES * i);
-    g_object_unref ( G_OBJECT ( pl ) );
-    pl = NULL;
+    draw_grid ( window, image, widgets, pix, s, i );
   }
-  
 
   /* draw speeds */
   for ( i = 0; i < widgets->profile_width; i++ )
-      gdk_draw_line ( GDK_DRAWABLE(pix), window->style->dark_gc[3],
+    gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
                      i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->speeds_dist[i]-mins)/(chunkss[widgets->cisd]*LINES) );
 
 
   if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->w_show_sd_gps_speed)) ) {
 
-    GdkGC *gps_speed_gc = gdk_gc_new ( window->window );
+    GdkGC *gps_speed_gc = gdk_gc_new ( gtk_widget_get_window(window) );
     GdkColor color;
     gdk_color_parse ( "red", &color );
     gdk_gc_set_rgb_fg_color ( gps_speed_gc, &color);
@@ -2049,7 +1931,7 @@ static void draw_sd ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
   }
 
   /* draw border */
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
+  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
 
   g_object_unref ( G_OBJECT(pix) );
 }
@@ -2105,7 +1987,7 @@ static void draw_all_graphs ( GtkWidget *widget, PropWidgets *widgets, gboolean
 
       save_image_and_draw_graph_marks (image,
                                       marker_x,
-                                      window->style->black_gc,
+                                      gtk_widget_get_style(window)->black_gc,
                                       x_blob+MARGIN,
                                       y_blob,
                                       &widgets->elev_graph_saved_img,
@@ -2153,7 +2035,7 @@ static void draw_all_graphs ( GtkWidget *widget, PropWidgets *widgets, gboolean
 
       save_image_and_draw_graph_marks (image,
                                       marker_x,
-                                      window->style->black_gc,
+                                      gtk_widget_get_style(window)->black_gc,
                                       x_blob+MARGIN,
                                       y_blob,
                                       &widgets->gradient_graph_saved_img,
@@ -2203,7 +2085,7 @@ static void draw_all_graphs ( GtkWidget *widget, PropWidgets *widgets, gboolean
 
       save_image_and_draw_graph_marks (image,
                                       marker_x,
-                                      window->style->black_gc,
+                                      gtk_widget_get_style(window)->black_gc,
                                       x_blob+MARGIN,
                                       y_blob,
                                       &widgets->speed_graph_saved_img,
@@ -2253,7 +2135,7 @@ static void draw_all_graphs ( GtkWidget *widget, PropWidgets *widgets, gboolean
 
       save_image_and_draw_graph_marks (image,
                                       marker_x,
-                                      window->style->black_gc,
+                                      gtk_widget_get_style(window)->black_gc,
                                       x_blob+MARGIN,
                                       y_blob,
                                       &widgets->dist_graph_saved_img,
@@ -2302,7 +2184,7 @@ static void draw_all_graphs ( GtkWidget *widget, PropWidgets *widgets, gboolean
 
       save_image_and_draw_graph_marks (image,
                                       marker_x,
-                                      window->style->black_gc,
+                                      gtk_widget_get_style(window)->black_gc,
                                       x_blob+MARGIN,
                                       y_blob,
                                       &widgets->elev_time_graph_saved_img,
@@ -2350,7 +2232,7 @@ static void draw_all_graphs ( GtkWidget *widget, PropWidgets *widgets, gboolean
 
       save_image_and_draw_graph_marks (image,
                                       marker_x,
-                                      window->style->black_gc,
+                                      gtk_widget_get_style(window)->black_gc,
                                       x_blob+MARGIN,
                                       y_blob,
                                       &widgets->speed_dist_graph_saved_img,
@@ -2376,8 +2258,11 @@ static gboolean configure_event ( GtkWidget *widget, GdkEventConfigure *event, P
     widgets->configure_dialog = FALSE;
 
     // Without this the settting, the dialog will only grow in vertical size - one can not then make it smaller!
-    gtk_widget_set_size_request ( widget, widgets->profile_width+widgets->profile_width_offset, widgets->profile_height );
-    // In fact this allows one to compress it a bit more vertically as I don't add on the height offset
+    gtk_widget_set_size_request ( widget, widgets->profile_width+widgets->profile_width_offset, widgets->profile_height+widgets->profile_height_offset );
+
+    // Allow resizing back down to a minimal size (especially useful if the initial size has been made bigger after restoring from the saved settings)
+    GdkGeometry geom = { 600+widgets->profile_width_offset, 300+widgets->profile_height_offset, 0, 0, 0, 0, 0, 0, 0, 0, GDK_GRAVITY_STATIC };
+    gdk_window_set_geometry_hints ( gtk_widget_get_window(widget), &geom, GDK_HINT_MIN_SIZE );
   }
   else {
     widgets->profile_width_old = widgets->profile_width;
@@ -2418,7 +2303,7 @@ GtkWidget *vik_trw_layer_create_profile ( GtkWidget *window, PropWidgets *widget
 
   minmax_array(widgets->altitudes, min_alt, max_alt, TRUE, widgets->profile_width);
   
-  pix = gdk_pixmap_new( window->window, widgets->profile_width + MARGIN, widgets->profile_height, -1 );
+  pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
   image = gtk_image_new_from_pixmap ( pix, NULL );
 
   g_object_unref ( G_OBJECT(pix) );
@@ -2448,7 +2333,7 @@ GtkWidget *vik_trw_layer_create_gradient ( GtkWidget *window, PropWidgets *widge
     return NULL;
   }
 
-  pix = gdk_pixmap_new( window->window, widgets->profile_width + MARGIN, widgets->profile_height, -1 );
+  pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
   image = gtk_image_new_from_pixmap ( pix, NULL );
 
   g_object_unref ( G_OBJECT(pix) );
@@ -2476,26 +2361,26 @@ GtkWidget *vik_trw_layer_create_vtdiag ( GtkWidget *window, PropWidgets *widgets
   if ( widgets->speeds == NULL )
     return NULL;
 
-  pix = gdk_pixmap_new( window->window, widgets->profile_width + MARGIN, widgets->profile_height, -1 );
+  pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
   image = gtk_image_new_from_pixmap ( pix, NULL );
 
 #if 0
   /* XXX this can go out, it's just a helpful dev tool */
   {
     int j;
-    GdkGC **colors[8] = { window->style->bg_gc,
-                         window->style->fg_gc,
-                         window->style->light_gc,
-                         window->style->dark_gc,
-                         window->style->mid_gc,
-                         window->style->text_gc,
-                         window->style->base_gc,
-                         window->style->text_aa_gc };
+    GdkGC **colors[8] = { gtk_widget_get_style(window)->bg_gc,
+                         gtk_widget_get_style(window)->fg_gc,
+                         gtk_widget_get_style(window)->light_gc,
+                         gtk_widget_get_style(window)->dark_gc,
+                         gtk_widget_get_style(window)->mid_gc,
+                         gtk_widget_get_style(window)->text_gc,
+                         gtk_widget_get_style(window)->base_gc,
+                         gtk_widget_get_style(window)->text_aa_gc };
     for (i=0; i<5; i++) {
       for (j=0; j<8; j++) {
        gdk_draw_rectangle(GDK_DRAWABLE(pix), colors[j][i],
                           TRUE, i*20, j*20, 20, 20);
-       gdk_draw_rectangle(GDK_DRAWABLE(pix), window->style->black_gc,
+       gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc,
                           FALSE, i*20, j*20, 20, 20);
       }
     }
@@ -2527,7 +2412,7 @@ GtkWidget *vik_trw_layer_create_dtdiag ( GtkWidget *window, PropWidgets *widgets
   if ( widgets->distances == NULL )
     return NULL;
 
-  pix = gdk_pixmap_new( window->window, widgets->profile_width + MARGIN, widgets->profile_height, -1 );
+  pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
   image = gtk_image_new_from_pixmap ( pix, NULL );
 
   g_object_unref ( G_OBJECT(pix) );
@@ -2556,7 +2441,7 @@ GtkWidget *vik_trw_layer_create_etdiag ( GtkWidget *window, PropWidgets *widgets
   if ( widgets->ats == NULL )
     return NULL;
 
-  pix = gdk_pixmap_new( window->window, widgets->profile_width + MARGIN, widgets->profile_height, -1 );
+  pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
   image = gtk_image_new_from_pixmap ( pix, NULL );
 
   g_object_unref ( G_OBJECT(pix) );
@@ -2584,7 +2469,7 @@ GtkWidget *vik_trw_layer_create_sddiag ( GtkWidget *window, PropWidgets *widgets
   if ( widgets->speeds_dist == NULL )
     return NULL;
 
-  pix = gdk_pixmap_new( window->window, widgets->profile_width + MARGIN, widgets->profile_height, -1 );
+  pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
   image = gtk_image_new_from_pixmap ( pix, NULL );
 
   g_object_unref ( G_OBJECT(pix) );
@@ -2599,8 +2484,18 @@ GtkWidget *vik_trw_layer_create_sddiag ( GtkWidget *window, PropWidgets *widgets
 }
 #undef MARGIN
 
+#define VIK_SETTINGS_TRACK_PROFILE_WIDTH "track_profile_display_width"
+#define VIK_SETTINGS_TRACK_PROFILE_HEIGHT "track_profile_display_height"
+
+static void save_values ( PropWidgets *widgets )
+{
+  a_settings_set_integer ( VIK_SETTINGS_TRACK_PROFILE_WIDTH, widgets->profile_width );
+  a_settings_set_integer ( VIK_SETTINGS_TRACK_PROFILE_HEIGHT, widgets->profile_height );
+}
+
 static void destroy_cb ( GtkDialog *dialog, PropWidgets *widgets )
 {
+  save_values(widgets);
   prop_widgets_free(widgets);
 }
 
@@ -2774,8 +2669,19 @@ void vik_trw_layer_propwin_run ( GtkWindow *parent,
   widgets->vlp = vlp;
   widgets->tr = tr;
   widgets->trk_id = trk_id;
-  widgets->profile_width  = PROPWIN_PROFILE_WIDTH;
-  widgets->profile_height = PROPWIN_PROFILE_HEIGHT;
+
+  gint profile_size_value;
+  // Ensure minimum values
+  widgets->profile_width = 600;
+  if ( a_settings_get_integer ( VIK_SETTINGS_TRACK_PROFILE_WIDTH, &profile_size_value ) )
+    if ( profile_size_value > widgets->profile_width )
+      widgets->profile_width = profile_size_value;
+
+  widgets->profile_height = 300;
+  if ( a_settings_get_integer ( VIK_SETTINGS_TRACK_PROFILE_HEIGHT, &profile_size_value ) )
+    if ( profile_size_value > widgets->profile_height )
+      widgets->profile_height = profile_size_value;
+
   gchar *title = g_strdup_printf(_("%s - Track Properties"), tr->name);
   GtkWidget *dialog = gtk_dialog_new_with_buttons (title,
                          parent,
@@ -3018,14 +2924,10 @@ void vik_trw_layer_propwin_run ( GtkWindow *parent,
     t1 = VIK_TRACKPOINT(tr->trackpoints->data)->timestamp;
     t2 = VIK_TRACKPOINT(g_list_last(tr->trackpoints)->data)->timestamp;
 
-    strncpy(tmp_buf, ctime(&t1), sizeof(tmp_buf));
-    tmp_buf[sizeof(tmp_buf)-1] = 0;
-    g_strchomp(tmp_buf);
+    strftime (tmp_buf, sizeof(tmp_buf), "%c", localtime(&(t1)));
     widgets->w_time_start = content[cnt++] = gtk_label_new(tmp_buf);
 
-    strncpy(tmp_buf, ctime(&t2), sizeof(tmp_buf));
-    tmp_buf[sizeof(tmp_buf)-1] = 0;
-    g_strchomp(tmp_buf);
+    strftime (tmp_buf, sizeof(tmp_buf), "%c", localtime(&(t2)));
     widgets->w_time_end = content[cnt++] = gtk_label_new(tmp_buf);
 
     g_snprintf(tmp_buf, sizeof(tmp_buf), _("%d minutes"), (int)(t2-t1)/60);
@@ -3143,7 +3045,7 @@ void vik_trw_layer_propwin_run ( GtkWindow *parent,
     gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Speed-distance")));
   }
 
-  gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), graphs, FALSE, FALSE, 0);
+  gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), graphs, FALSE, FALSE, 0);
 
   gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), VIK_TRW_LAYER_PROPWIN_SPLIT_MARKER, FALSE);
   if (seg_count <= 1)
@@ -3151,7 +3053,7 @@ void vik_trw_layer_propwin_run ( GtkWindow *parent,
   if (vik_track_get_dup_point_count(tr) <= 0)
     gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), VIK_TRW_LAYER_PROPWIN_DEL_DUP, FALSE);
 
-  // On dialog realization configure_event casues the graphs to be initially drawn
+  // On dialog realization configure_event causes the graphs to be initially drawn
   widgets->configure_dialog = TRUE;
   g_signal_connect ( G_OBJECT(dialog), "configure-event", G_CALLBACK (configure_event), widgets );