]> git.street.me.uk Git - andy/viking.git/blobdiff - src/viktrwlayer_propwin.c
SF Bugs#100: Fix Crash on viewing Track Properties with extreme gradients.
[andy/viking.git] / src / viktrwlayer_propwin.c
index e14d912663de6c86c57973368a31dcbf0e334c17..952b956db41eda09109ad3df94bb202d333e2e74 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
-
-#define PROPWIN_LABEL_FONT "Sans 7"
 
 typedef enum {
   PROPWIN_GRAPH_TYPE_ELEVATION_DISTANCE,
@@ -78,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!) */
@@ -102,6 +90,9 @@ typedef struct _propwidgets {
   gboolean  configure_dialog;
   VikTrwLayer *vtl;
   VikTrack *tr;
+  gpointer  trk_id;
+  VikViewport *vvp;
+  VikLayersPanel *vlp;
   gint      profile_width;
   gint      profile_height;
   gint      profile_width_old;
@@ -110,6 +101,7 @@ typedef struct _propwidgets {
   gint      profile_height_offset;
   GtkWidget *dialog;
   GtkWidget *w_comment;
+  GtkWidget *w_description;
   GtkWidget *w_track_length;
   GtkWidget *w_tp_count;
   GtkWidget *w_segment_count;
@@ -123,6 +115,7 @@ typedef struct _propwidgets {
   GtkWidget *w_time_start;
   GtkWidget *w_time_end;
   GtkWidget *w_time_dur;
+  GtkWidget *w_color;
   GtkWidget *w_cur_dist; /*< Current distance */
   GtkWidget *w_cur_elevation;
   GtkWidget *w_cur_gradient_dist; /*< Current distance on gradient graph */
@@ -241,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,
@@ -379,7 +311,7 @@ static VikTrackpoint *set_center_at_graph_position(gdouble event_x,
       /* since vlp not set, vvp should be valid instead! */
       if ( vvp )
        vik_viewport_set_center_coord ( vvp, &coord );
-      vik_layer_emit_update ( VIK_LAYER(vtl), FALSE );
+      vik_layer_emit_update ( VIK_LAYER(vtl) );
     }
   }
   return trackpoint;
@@ -474,19 +406,14 @@ static gdouble tp_percentage_by_distance ( VikTrack *tr, VikTrackpoint *trackpoi
   return pc;
 }
 
-static void track_graph_click( GtkWidget *event_box, GdkEventButton *event, gpointer *pass_along, VikPropWinGraphType_t graph_type )
+static void track_graph_click( GtkWidget *event_box, GdkEventButton *event, PropWidgets *widgets, VikPropWinGraphType_t graph_type )
 {
-  VikTrack *tr = pass_along[0];
-  VikLayersPanel *vlp = pass_along[1];
-  VikViewport *vvp = pass_along[2];
-  PropWidgets *widgets = pass_along[3];
-
   gboolean is_time_graph =
     ( graph_type == PROPWIN_GRAPH_TYPE_SPEED_TIME ||
       graph_type == PROPWIN_GRAPH_TYPE_DISTANCE_TIME ||
       graph_type == PROPWIN_GRAPH_TYPE_ELEVATION_TIME );
 
-  VikTrackpoint *trackpoint = set_center_at_graph_position(event->x, event_box->allocation.width, widgets->vtl, vlp, vvp, tr, is_time_graph, widgets->profile_width);
+  VikTrackpoint *trackpoint = set_center_at_graph_position(event->x, event_box->allocation.width, widgets->vtl, widgets->vlp, widgets->vvp, widgets->tr, is_time_graph, widgets->profile_width);
   // Unable to get the point so give up
   if ( trackpoint == NULL ) {
     gtk_dialog_set_response_sensitive(GTK_DIALOG(widgets->dialog), VIK_TRW_LAYER_PROPWIN_SPLIT_MARKER, FALSE);
@@ -550,15 +477,15 @@ static void track_graph_click( GtkWidget *event_box, GdkEventButton *event, gpoi
       image = GTK_WIDGET(child->data);
 
       if (is_time_graph)
-       pc = tp_percentage_by_time ( tr, trackpoint );
+       pc = tp_percentage_by_time ( widgets->tr, trackpoint );
       else
-       pc = tp_percentage_by_distance ( tr, trackpoint, widgets->track_length_inc_gaps );
+       pc = tp_percentage_by_distance ( widgets->tr, trackpoint, widgets->track_length_inc_gaps );
 
       if (!isnan(pc)) {
        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,
@@ -574,39 +501,39 @@ static void track_graph_click( GtkWidget *event_box, GdkEventButton *event, gpoi
   gtk_dialog_set_response_sensitive(GTK_DIALOG(widgets->dialog), VIK_TRW_LAYER_PROPWIN_SPLIT_MARKER, widgets->is_marker_drawn);
 }
 
-static gboolean track_profile_click( GtkWidget *event_box, GdkEventButton *event, gpointer *pass_along )
+static gboolean track_profile_click( GtkWidget *event_box, GdkEventButton *event, gpointer ptr )
 {
-  track_graph_click(event_box, event, pass_along, PROPWIN_GRAPH_TYPE_ELEVATION_DISTANCE);
+  track_graph_click(event_box, event, ptr, PROPWIN_GRAPH_TYPE_ELEVATION_DISTANCE);
   return TRUE;  /* don't call other (further) callbacks */
 }
 
-static gboolean track_gradient_click( GtkWidget *event_box, GdkEventButton *event, gpointer *pass_along )
+static gboolean track_gradient_click( GtkWidget *event_box, GdkEventButton *event, gpointer ptr )
 {
-  track_graph_click(event_box, event, pass_along, PROPWIN_GRAPH_TYPE_GRADIENT_DISTANCE);
+  track_graph_click(event_box, event, ptr, PROPWIN_GRAPH_TYPE_GRADIENT_DISTANCE);
   return TRUE;  /* don't call other (further) callbacks */
 }
 
-static gboolean track_vt_click( GtkWidget *event_box, GdkEventButton *event, gpointer *pass_along )
+static gboolean track_vt_click( GtkWidget *event_box, GdkEventButton *event, gpointer ptr )
 {
-  track_graph_click(event_box, event, pass_along, PROPWIN_GRAPH_TYPE_SPEED_TIME);
+  track_graph_click(event_box, event, ptr, PROPWIN_GRAPH_TYPE_SPEED_TIME);
   return TRUE;  /* don't call other (further) callbacks */
 }
 
-static gboolean track_dt_click( GtkWidget *event_box, GdkEventButton *event, gpointer *pass_along )
+static gboolean track_dt_click( GtkWidget *event_box, GdkEventButton *event, gpointer ptr )
 {
-  track_graph_click(event_box, event, pass_along, PROPWIN_GRAPH_TYPE_DISTANCE_TIME);
+  track_graph_click(event_box, event, ptr, PROPWIN_GRAPH_TYPE_DISTANCE_TIME);
   return TRUE;  /* don't call other (further) callbacks */
 }
 
-static gboolean track_et_click( GtkWidget *event_box, GdkEventButton *event, gpointer *pass_along )
+static gboolean track_et_click( GtkWidget *event_box, GdkEventButton *event, gpointer ptr )
 {
-  track_graph_click(event_box, event, pass_along, PROPWIN_GRAPH_TYPE_ELEVATION_TIME);
+  track_graph_click(event_box, event, ptr, PROPWIN_GRAPH_TYPE_ELEVATION_TIME);
   return TRUE;  /* don't call other (further) callbacks */
 }
 
-static gboolean track_sd_click( GtkWidget *event_box, GdkEventButton *event, gpointer *pass_along )
+static gboolean track_sd_click( GtkWidget *event_box, GdkEventButton *event, gpointer ptr )
 {
-  track_graph_click(event_box, event, pass_along, PROPWIN_GRAPH_TYPE_SPEED_DISTANCE);
+  track_graph_click(event_box, event, ptr, PROPWIN_GRAPH_TYPE_SPEED_DISTANCE);
   return TRUE;  /* don't call other (further) callbacks */
 }
 
@@ -701,10 +628,8 @@ static gint blobby_speed_dist ( gdouble x_blob, PropWidgets *widgets )
 }
 
 
-void track_profile_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *pass_along )
+void track_profile_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *widgets )
 {
-  VikTrack *tr = pass_along[0];
-  PropWidgets *widgets = pass_along[3];
   int mouse_x, mouse_y;
   GdkModifierType state;
 
@@ -720,7 +645,7 @@ void track_profile_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *
     x = widgets->profile_width;
 
   gdouble meters_from_start;
-  VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_dist ( tr, (gdouble) x / widgets->profile_width, &meters_from_start );
+  VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_dist ( widgets->tr, (gdouble) x / widgets->profile_width, &meters_from_start );
   if (trackpoint && widgets->w_cur_dist) {
     static gchar tmp_buf[20];
     vik_units_distance_t dist_units = a_vik_get_units_distance ();
@@ -760,7 +685,7 @@ void track_profile_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *
 
   gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
   if (widgets->is_marker_drawn) {
-    gdouble pc = tp_percentage_by_distance ( tr, widgets->marker_tp, widgets->track_length_inc_gaps );
+    gdouble pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
     if (!isnan(pc)) {
       marker_x = (pc * widgets->profile_width) + MARGIN;
     }
@@ -768,7 +693,7 @@ void track_profile_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *
 
   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,
@@ -780,10 +705,8 @@ void track_profile_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *
   g_list_free(child);
 }
 
-void track_gradient_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *pass_along )
+void track_gradient_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *widgets )
 {
-  VikTrack *tr = pass_along[0];
-  PropWidgets *widgets = pass_along[3];
   int mouse_x, mouse_y;
   GdkModifierType state;
 
@@ -799,7 +722,7 @@ void track_gradient_move( GtkWidget *event_box, GdkEventMotion *event, gpointer
     x = widgets->profile_width;
 
   gdouble meters_from_start;
-  VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_dist ( tr, (gdouble) x / widgets->profile_width, &meters_from_start );
+  VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_dist ( widgets->tr, (gdouble) x / widgets->profile_width, &meters_from_start );
   if (trackpoint && widgets->w_cur_gradient_dist) {
     static gchar tmp_buf[20];
     vik_units_distance_t dist_units = a_vik_get_units_distance ();
@@ -839,7 +762,7 @@ void track_gradient_move( GtkWidget *event_box, GdkEventMotion *event, gpointer
 
   gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
   if (widgets->is_marker_drawn) {
-    gdouble pc = tp_percentage_by_distance ( tr, widgets->marker_tp, widgets->track_length_inc_gaps );
+    gdouble pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
     if (!isnan(pc)) {
       marker_x = (pc * widgets->profile_width) + MARGIN;
     }
@@ -847,7 +770,7 @@ void track_gradient_move( GtkWidget *event_box, GdkEventMotion *event, gpointer
 
   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,
@@ -859,10 +782,8 @@ void track_gradient_move( GtkWidget *event_box, GdkEventMotion *event, gpointer
   g_list_free(child);
 }
 
-void track_vt_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *pass_along )
+void track_vt_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *widgets )
 {
-  VikTrack *tr = pass_along[0];
-  PropWidgets *widgets = pass_along[3];
   int mouse_x, mouse_y;
   GdkModifierType state;
 
@@ -878,7 +799,7 @@ void track_vt_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *pass_
     x = widgets->profile_width;
 
   time_t seconds_from_start;
-  VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_time ( tr, (gdouble) x / widgets->profile_width, &seconds_from_start );
+  VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_time ( widgets->tr, (gdouble) x / widgets->profile_width, &seconds_from_start );
   if (trackpoint && widgets->w_cur_time) {
     static gchar tmp_buf[20];
     guint h, m, s;
@@ -932,7 +853,7 @@ void track_vt_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *pass_
 
   gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
   if (widgets->is_marker_drawn) {
-    gdouble pc = tp_percentage_by_time ( tr, widgets->marker_tp );
+    gdouble pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
     if (!isnan(pc)) {
       marker_x = (pc * widgets->profile_width) + MARGIN;
     }
@@ -940,7 +861,7 @@ void track_vt_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *pass_
 
   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,
@@ -955,10 +876,8 @@ void track_vt_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *pass_
 /**
  * Update labels and blob marker on mouse moves in the distance/time graph
  */
-void track_dt_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *pass_along )
+void track_dt_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *widgets )
 {
-  VikTrack *tr = pass_along[0];
-  PropWidgets *widgets = pass_along[3];
   int mouse_x, mouse_y;
   GdkModifierType state;
 
@@ -974,7 +893,7 @@ void track_dt_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *pass_
     x = widgets->profile_width;
 
   time_t seconds_from_start;
-  VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_time ( tr, (gdouble) x / widgets->profile_width, &seconds_from_start );
+  VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_time ( widgets->tr, (gdouble) x / widgets->profile_width, &seconds_from_start );
   if (trackpoint && widgets->w_cur_dist_time) {
     static gchar tmp_buf[20];
     guint h, m, s;
@@ -1013,7 +932,7 @@ void track_dt_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *pass_
 
   gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
   if (widgets->is_marker_drawn) {
-    gdouble pc = tp_percentage_by_time ( tr, widgets->marker_tp );
+    gdouble pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
     if (!isnan(pc)) {
       marker_x = (pc * widgets->profile_width) + MARGIN;
     }
@@ -1021,7 +940,7 @@ void track_dt_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *pass_
 
   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,
@@ -1036,10 +955,8 @@ void track_dt_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *pass_
 /**
  * Update labels and blob marker on mouse moves in the elevation/time graph
  */
-void track_et_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *pass_along )
+void track_et_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *widgets )
 {
-  VikTrack *tr = pass_along[0];
-  PropWidgets *widgets = pass_along[3];
   int mouse_x, mouse_y;
   GdkModifierType state;
 
@@ -1055,7 +972,7 @@ void track_et_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *pass_
     x = widgets->profile_width;
 
   time_t seconds_from_start;
-  VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_time ( tr, (gdouble) x / widgets->profile_width, &seconds_from_start );
+  VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_time ( widgets->tr, (gdouble) x / widgets->profile_width, &seconds_from_start );
   if (trackpoint && widgets->w_cur_elev_time) {
     static gchar tmp_buf[20];
     guint h, m, s;
@@ -1094,7 +1011,7 @@ void track_et_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *pass_
 
   gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
   if (widgets->is_marker_drawn) {
-    gdouble pc = tp_percentage_by_time ( tr, widgets->marker_tp );
+    gdouble pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
     if (!isnan(pc)) {
       marker_x = (pc * widgets->profile_width) + MARGIN;
     }
@@ -1102,7 +1019,7 @@ void track_et_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *pass_
 
   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,
@@ -1114,10 +1031,8 @@ void track_et_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *pass_
   g_list_free(child);
 }
 
-void track_sd_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *pass_along )
+void track_sd_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *widgets )
 {
-  VikTrack *tr = pass_along[0];
-  PropWidgets *widgets = pass_along[3];
   int mouse_x, mouse_y;
   GdkModifierType state;
 
@@ -1133,7 +1048,7 @@ void track_sd_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *pass_
     x = widgets->profile_width;
 
   gdouble meters_from_start;
-  VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_dist ( tr, (gdouble) x / widgets->profile_width, &meters_from_start );
+  VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_dist ( widgets->tr, (gdouble) x / widgets->profile_width, &meters_from_start );
   if (trackpoint && widgets->w_cur_speed_dist) {
     static gchar tmp_buf[20];
     vik_units_distance_t dist_units = a_vik_get_units_distance ();
@@ -1192,7 +1107,7 @@ void track_sd_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *pass_
 
   gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
   if (widgets->is_marker_drawn) {
-    gdouble pc = tp_percentage_by_distance ( tr, widgets->marker_tp, widgets->track_length_inc_gaps );
+    gdouble pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
     if (!isnan(pc)) {
       marker_x = (pc * widgets->profile_width) + MARGIN;
     }
@@ -1200,7 +1115,7 @@ void track_sd_move( GtkWidget *event_box, GdkEventMotion *event, gpointer *pass_
 
   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,
@@ -1302,7 +1217,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;
@@ -1310,31 +1225,29 @@ 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++) {
-    PangoFontDescription *pfd;
     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);
-    pfd = pango_font_description_from_string (PROPWIN_LABEL_FONT);
-    pango_layout_set_font_description (pl, pfd);
-    pango_font_description_free (pfd);
+    pango_layout_set_font_description (pl, gtk_widget_get_style(window)->font_desc);
+
     switch (height_units) {
     case VIK_UNITS_HEIGHT_METRES:
       sprintf(s, "%8dm", (int)(mina + (LINES-i)*chunksa[widgets->cia]));
@@ -1349,10 +1262,10 @@ static void draw_elevations (GtkWidget *image, VikTrack *tr, PropWidgets *widget
     }
     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, 
+    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), window->style->dark_gc[0], 
+    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;
@@ -1364,14 +1277,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);
@@ -1402,7 +1315,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) );
@@ -1468,41 +1381,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++) {
-    PangoFontDescription *pfd;
     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);
-    pfd = pango_font_description_from_string (PROPWIN_LABEL_FONT);
-    pango_layout_set_font_description (pl, pfd);
-    pango_font_description_free (pfd);
+    pango_layout_set_font_description (pl, gtk_widget_get_style(window)->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, 
+    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), window->style->dark_gc[0], 
+    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;
@@ -1510,11 +1421,11 @@ static void draw_gradients (GtkWidget *image, VikTrack *tr, PropWidgets *widgets
 
   /* 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);
@@ -1536,7 +1447,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) );
 }
@@ -1585,7 +1496,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 );
 
@@ -1594,28 +1505,26 @@ 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++) {
-    PangoFontDescription *pfd;
     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);
-    pfd = pango_font_description_from_string (PROPWIN_LABEL_FONT);
-    pango_layout_set_font_description (pl, pfd);
-    pango_font_description_free (pfd);
+    pango_layout_set_font_description (pl, gtk_widget_get_style(window)->font_desc);
+
     // NB: No need to convert here anymore as numbers are in the appropriate units
     switch (speed_units) {
     case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
@@ -1637,10 +1546,10 @@ static void draw_vt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
 
     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, 
+    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), window->style->dark_gc[0], 
+    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;
@@ -1649,13 +1558,13 @@ static void draw_vt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
 
   /* 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);
@@ -1691,7 +1600,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) );
 }
@@ -1730,7 +1639,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 );
 
@@ -1744,25 +1653,23 @@ 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++) {
-    PangoFontDescription *pfd;
     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);
-    pfd = pango_font_description_from_string (PROPWIN_LABEL_FONT);
-    pango_layout_set_font_description (pl, pfd);
-    pango_font_description_free (pfd);
+    pango_layout_set_font_description (pl, gtk_widget_get_style(window)->font_desc);
+
     if ( dist_units == VIK_UNITS_DISTANCE_MILES )
       sprintf(s, _("%.1f miles"), ((LINES-i)*chunksd[widgets->cid]));
     else
@@ -1770,10 +1677,10 @@ static void draw_dt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
 
     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,
+    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), window->style->dark_gc[0],
+    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;
@@ -1781,12 +1688,12 @@ static void draw_dt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
   
   /* 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);
@@ -1804,7 +1711,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) );
 
@@ -1841,34 +1748,32 @@ 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++) {
-    PangoFontDescription *pfd;
     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);
-    pfd = pango_font_description_from_string (PROPWIN_LABEL_FONT);
-    pango_layout_set_font_description (pl, pfd);
-    pango_font_description_free (pfd);
+    pango_layout_set_font_description (pl, gtk_widget_get_style(window)->font_desc);
+
     switch (height_units) {
     case VIK_UNITS_HEIGHT_METRES:
       sprintf(s, "%8dm", (int)(mina + (LINES-i)*chunksa[widgets->ciat]));
@@ -1883,10 +1788,10 @@ static void draw_et ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
     }
     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,
+    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), window->style->dark_gc[0],
+    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;
@@ -1894,12 +1799,12 @@ static void draw_et ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
 
   /* 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);
@@ -1917,7 +1822,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) );
 
@@ -1967,7 +1872,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 );
 
@@ -1977,28 +1882,26 @@ 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++) {
-    PangoFontDescription *pfd;
     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);
-    pfd = pango_font_description_from_string (PROPWIN_LABEL_FONT);
-    pango_layout_set_font_description (pl, pfd);
-    pango_font_description_free (pfd);
+    pango_layout_set_font_description (pl, gtk_widget_get_style(window)->font_desc);
+
     // NB: No need to convert here anymore as numbers are in the appropriate units
     switch (speed_units) {
     case VIK_UNITS_SPEED_KILOMETRES_PER_HOUR:
@@ -2020,10 +1923,10 @@ static void draw_sd ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
 
     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,
+    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), window->style->dark_gc[0],
+    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;
@@ -2032,13 +1935,13 @@ static void draw_sd ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
 
   /* 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);
@@ -2075,7 +1978,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) );
 }
@@ -2084,11 +1987,8 @@ static void draw_sd ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
 /**
  * Draw all graphs
  */
-static void draw_all_graphs ( GtkWidget *widget, gpointer *pass_along, gboolean resized )
+static void draw_all_graphs ( GtkWidget *widget, PropWidgets *widgets, gboolean resized )
 {
-  VikTrack *tr = pass_along[0];
-  PropWidgets *widgets = pass_along[3];
-
   // Draw graphs even if they are not visible
 
   GList *child = NULL;
@@ -2108,7 +2008,7 @@ static void draw_all_graphs ( GtkWidget *widget, gpointer *pass_along, gboolean
     }
 
     child = gtk_container_get_children(GTK_CONTAINER(widgets->elev_box));
-    draw_elevations (GTK_WIDGET(child->data), tr, widgets );
+    draw_elevations (GTK_WIDGET(child->data), widgets->tr, widgets );
 
     image = GTK_WIDGET(child->data);
     g_list_free(child);
@@ -2116,11 +2016,11 @@ static void draw_all_graphs ( GtkWidget *widget, gpointer *pass_along, gboolean
     // Ensure marker or blob are redrawn if necessary
     if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
 
-      pc = tp_percentage_by_distance ( tr, widgets->marker_tp, widgets->track_length_inc_gaps );
+      pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
       gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
       gint y_blob = 0;
       if (widgets->is_blob_drawn) {
-       pc_blob = tp_percentage_by_distance ( tr, widgets->blob_tp, widgets->track_length_inc_gaps );
+       pc_blob = tp_percentage_by_distance ( widgets->tr, widgets->blob_tp, widgets->track_length_inc_gaps );
        if (!isnan(pc_blob)) {
          x_blob = (pc_blob * widgets->profile_width);
        }
@@ -2134,7 +2034,7 @@ static void draw_all_graphs ( GtkWidget *widget, gpointer *pass_along, 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,
@@ -2156,7 +2056,7 @@ static void draw_all_graphs ( GtkWidget *widget, gpointer *pass_along, gboolean
     }
 
     child = gtk_container_get_children(GTK_CONTAINER(widgets->gradient_box));
-    draw_gradients (GTK_WIDGET(child->data), tr, widgets );
+    draw_gradients (GTK_WIDGET(child->data), widgets->tr, widgets );
 
     image = GTK_WIDGET(child->data);
     g_list_free(child);
@@ -2164,11 +2064,11 @@ static void draw_all_graphs ( GtkWidget *widget, gpointer *pass_along, gboolean
     // Ensure marker or blob are redrawn if necessary
     if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
 
-      pc = tp_percentage_by_distance ( tr, widgets->marker_tp, widgets->track_length_inc_gaps );
+      pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
       gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
       gint y_blob = 0;
       if (widgets->is_blob_drawn) {
-       pc_blob = tp_percentage_by_distance ( tr, widgets->blob_tp, widgets->track_length_inc_gaps );
+       pc_blob = tp_percentage_by_distance ( widgets->tr, widgets->blob_tp, widgets->track_length_inc_gaps );
        if (!isnan(pc_blob)) {
          x_blob = (pc_blob * widgets->profile_width);
        }
@@ -2182,7 +2082,7 @@ static void draw_all_graphs ( GtkWidget *widget, gpointer *pass_along, 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,
@@ -2204,7 +2104,7 @@ static void draw_all_graphs ( GtkWidget *widget, gpointer *pass_along, gboolean
     }
 
     child = gtk_container_get_children(GTK_CONTAINER(widgets->speed_box));
-    draw_vt (GTK_WIDGET(child->data), tr, widgets );
+    draw_vt (GTK_WIDGET(child->data), widgets->tr, widgets );
 
     image = GTK_WIDGET(child->data);
     g_list_free(child);
@@ -2212,12 +2112,12 @@ static void draw_all_graphs ( GtkWidget *widget, gpointer *pass_along, gboolean
     // Ensure marker or blob are redrawn if necessary
     if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
 
-      pc = tp_percentage_by_time ( tr, widgets->marker_tp );
+      pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
 
       gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
       gint    y_blob = 0;
       if (widgets->is_blob_drawn) {
-       pc_blob = tp_percentage_by_time ( tr, widgets->blob_tp );
+       pc_blob = tp_percentage_by_time ( widgets->tr, widgets->blob_tp );
        if (!isnan(pc_blob)) {
          x_blob = (pc_blob * widgets->profile_width);
        }
@@ -2232,7 +2132,7 @@ static void draw_all_graphs ( GtkWidget *widget, gpointer *pass_along, 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,
@@ -2254,7 +2154,7 @@ static void draw_all_graphs ( GtkWidget *widget, gpointer *pass_along, gboolean
     }
 
     child = gtk_container_get_children(GTK_CONTAINER(widgets->dist_box));
-    draw_dt (GTK_WIDGET(child->data), tr, widgets );
+    draw_dt (GTK_WIDGET(child->data), widgets->tr, widgets );
 
     image = GTK_WIDGET(child->data);
     g_list_free(child);
@@ -2262,12 +2162,12 @@ static void draw_all_graphs ( GtkWidget *widget, gpointer *pass_along, gboolean
     // Ensure marker or blob are redrawn if necessary
     if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
 
-      pc = tp_percentage_by_time ( tr, widgets->marker_tp );
+      pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
 
       gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
       gint    y_blob = 0;
       if (widgets->is_blob_drawn) {
-       pc_blob = tp_percentage_by_time ( tr, widgets->blob_tp );
+       pc_blob = tp_percentage_by_time ( widgets->tr, widgets->blob_tp );
        if (!isnan(pc_blob)) {
          x_blob = (pc_blob * widgets->profile_width);
        }
@@ -2282,7 +2182,7 @@ static void draw_all_graphs ( GtkWidget *widget, gpointer *pass_along, 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,
@@ -2304,7 +2204,7 @@ static void draw_all_graphs ( GtkWidget *widget, gpointer *pass_along, gboolean
     }
 
     child = gtk_container_get_children(GTK_CONTAINER(widgets->elev_time_box));
-    draw_et (GTK_WIDGET(child->data), tr, widgets );
+    draw_et (GTK_WIDGET(child->data), widgets->tr, widgets );
 
     image = GTK_WIDGET(child->data);
     g_list_free(child);
@@ -2312,12 +2212,12 @@ static void draw_all_graphs ( GtkWidget *widget, gpointer *pass_along, gboolean
     // Ensure marker or blob are redrawn if necessary
     if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
 
-      pc = tp_percentage_by_time ( tr, widgets->marker_tp );
+      pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
 
       gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
       gint    y_blob = 0;
       if (widgets->is_blob_drawn) {
-       pc_blob = tp_percentage_by_time ( tr, widgets->blob_tp );
+       pc_blob = tp_percentage_by_time ( widgets->tr, widgets->blob_tp );
        if (!isnan(pc_blob)) {
          x_blob = (pc_blob * widgets->profile_width);
        }
@@ -2331,7 +2231,7 @@ static void draw_all_graphs ( GtkWidget *widget, gpointer *pass_along, 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,
@@ -2353,7 +2253,7 @@ static void draw_all_graphs ( GtkWidget *widget, gpointer *pass_along, gboolean
     }
 
     child = gtk_container_get_children(GTK_CONTAINER(widgets->speed_dist_box));
-    draw_sd (GTK_WIDGET(child->data), tr, widgets );
+    draw_sd (GTK_WIDGET(child->data), widgets->tr, widgets );
 
     image = GTK_WIDGET(child->data);
     g_list_free(child);
@@ -2361,11 +2261,11 @@ static void draw_all_graphs ( GtkWidget *widget, gpointer *pass_along, gboolean
     // Ensure marker or blob are redrawn if necessary
     if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
 
-      pc = tp_percentage_by_distance ( tr, widgets->marker_tp, widgets->track_length_inc_gaps );
+      pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
       gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
       gint y_blob = 0;
       if (widgets->is_blob_drawn) {
-       pc_blob = tp_percentage_by_distance ( tr, widgets->blob_tp, widgets->track_length_inc_gaps );
+       pc_blob = tp_percentage_by_distance ( widgets->tr, widgets->blob_tp, widgets->track_length_inc_gaps );
        if (!isnan(pc_blob)) {
          x_blob = (pc_blob * widgets->profile_width);
        }
@@ -2379,7 +2279,7 @@ static void draw_all_graphs ( GtkWidget *widget, gpointer *pass_along, 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,
@@ -2395,10 +2295,8 @@ static void draw_all_graphs ( GtkWidget *widget, gpointer *pass_along, gboolean
 /**
  * Configure/Resize the profile & speed/time images
  */
-static gboolean configure_event ( GtkWidget *widget, GdkEventConfigure *event, gpointer *pass_along )
+static gboolean configure_event ( GtkWidget *widget, GdkEventConfigure *event, PropWidgets *widgets )
 {
-  PropWidgets *widgets = pass_along[3];
-
   if (widgets->configure_dialog) {
     // Determine size offsets between dialog size and size for images
     // Only on the initialisation of the dialog
@@ -2407,8 +2305,11 @@ static gboolean configure_event ( GtkWidget *widget, GdkEventConfigure *event, g
     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;
@@ -2425,7 +2326,7 @@ static gboolean configure_event ( GtkWidget *widget, GdkEventConfigure *event, g
     return FALSE;
 
   // Draw stuff
-  draw_all_graphs ( widget, pass_along, TRUE );
+  draw_all_graphs ( widget, widgets, TRUE );
 
   return FALSE;
 }
@@ -2433,15 +2334,14 @@ static gboolean configure_event ( GtkWidget *widget, GdkEventConfigure *event, g
 /**
  * Create height profile widgets including the image and callbacks
  */
-GtkWidget *vik_trw_layer_create_profile ( GtkWidget *window, VikTrack *tr, gpointer vlp, VikViewport *vvp, PropWidgets *widgets, gdouble *min_alt, gdouble *max_alt)
+GtkWidget *vik_trw_layer_create_profile ( GtkWidget *window, PropWidgets *widgets, gdouble *min_alt, gdouble *max_alt)
 {
   GdkPixmap *pix;
   GtkWidget *image;
   GtkWidget *eventbox;
-  gpointer *pass_along;
 
   // First allocation
-  widgets->altitudes = vik_track_make_elevation_map ( tr, widgets->profile_width );
+  widgets->altitudes = vik_track_make_elevation_map ( widgets->tr, widgets->profile_width );
 
   if ( widgets->altitudes == NULL ) {
     *min_alt = *max_alt = VIK_DEFAULT_ALTITUDE;
@@ -2450,21 +2350,14 @@ GtkWidget *vik_trw_layer_create_profile ( GtkWidget *window, VikTrack *tr, gpoin
 
   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) );
 
-  pass_along = g_malloc ( sizeof(gpointer) * 4 ); /* FIXME: mem leak -- never be freed */
-  pass_along[0] = tr;
-  pass_along[1] = vlp;
-  pass_along[2] = vvp;
-  pass_along[3] = widgets;
-
   eventbox = gtk_event_box_new ();
-  g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_profile_click), pass_along );
-  g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_profile_move), pass_along );
-  g_signal_connect_swapped ( G_OBJECT(eventbox), "destroy", G_CALLBACK(g_free), pass_along );
+  g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_profile_click), widgets );
+  g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_profile_move), widgets );
   gtk_container_add ( GTK_CONTAINER(eventbox), image );
   gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_STRUCTURE_MASK);
 
@@ -2474,35 +2367,27 @@ GtkWidget *vik_trw_layer_create_profile ( GtkWidget *window, VikTrack *tr, gpoin
 /**
  * Create height profile widgets including the image and callbacks
  */
-GtkWidget *vik_trw_layer_create_gradient ( GtkWidget *window, VikTrack *tr, gpointer vlp, VikViewport *vvp, PropWidgets *widgets)
+GtkWidget *vik_trw_layer_create_gradient ( GtkWidget *window, PropWidgets *widgets)
 {
   GdkPixmap *pix;
   GtkWidget *image;
   GtkWidget *eventbox;
-  gpointer *pass_along;
 
   // First allocation
-  widgets->gradients = vik_track_make_gradient_map ( tr, widgets->profile_width );
+  widgets->gradients = vik_track_make_gradient_map ( widgets->tr, widgets->profile_width );
 
   if ( widgets->gradients == 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) );
 
-  pass_along = g_malloc ( sizeof(gpointer) * 4 ); /* FIXME: mem leak -- never be freed */
-  pass_along[0] = tr;
-  pass_along[1] = vlp;
-  pass_along[2] = vvp;
-  pass_along[3] = widgets;
-
   eventbox = gtk_event_box_new ();
-  g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_gradient_click), pass_along );
-  g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_gradient_move), pass_along );
-  g_signal_connect_swapped ( G_OBJECT(eventbox), "destroy", G_CALLBACK(g_free), pass_along );
+  g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_gradient_click), widgets );
+  g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_gradient_move), widgets );
   gtk_container_add ( GTK_CONTAINER(eventbox), image );
   gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_STRUCTURE_MASK);
 
@@ -2512,44 +2397,37 @@ GtkWidget *vik_trw_layer_create_gradient ( GtkWidget *window, VikTrack *tr, gpoi
 /**
  * Create speed/time widgets including the image and callbacks
  */
-GtkWidget *vik_trw_layer_create_vtdiag ( GtkWidget *window, VikTrack *tr, gpointer vlp, VikViewport *vvp, PropWidgets *widgets)
+GtkWidget *vik_trw_layer_create_vtdiag ( GtkWidget *window, PropWidgets *widgets)
 {
   GdkPixmap *pix;
   GtkWidget *image;
   GtkWidget *eventbox;
-  gpointer *pass_along;
 
   // First allocation
-  widgets->speeds = vik_track_make_speed_map ( tr, widgets->profile_width );
+  widgets->speeds = vik_track_make_speed_map ( widgets->tr, widgets->profile_width );
   if ( widgets->speeds == NULL )
     return NULL;
 
-  pass_along = g_malloc ( sizeof(gpointer) * 4 ); /* FIXME: mem leak -- never be freed */
-  pass_along[0] = tr;
-  pass_along[1] = vlp;
-  pass_along[2] = vvp;
-  pass_along[3] = widgets;
-
-  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);
       }
     }
@@ -2559,9 +2437,8 @@ GtkWidget *vik_trw_layer_create_vtdiag ( GtkWidget *window, VikTrack *tr, gpoint
   g_object_unref ( G_OBJECT(pix) );
 
   eventbox = gtk_event_box_new ();
-  g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_vt_click), pass_along );
-  g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_vt_move), pass_along );
-  g_signal_connect_swapped ( G_OBJECT(eventbox), "destroy", G_CALLBACK(g_free), pass_along );
+  g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_vt_click), widgets );
+  g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_vt_move), widgets );
   gtk_container_add ( GTK_CONTAINER(eventbox), image );
   gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
 
@@ -2571,33 +2448,26 @@ GtkWidget *vik_trw_layer_create_vtdiag ( GtkWidget *window, VikTrack *tr, gpoint
 /**
  * Create distance / time widgets including the image and callbacks
  */
-GtkWidget *vik_trw_layer_create_dtdiag ( GtkWidget *window, VikTrack *tr, gpointer vlp, VikViewport *vvp, PropWidgets *widgets)
+GtkWidget *vik_trw_layer_create_dtdiag ( GtkWidget *window, PropWidgets *widgets)
 {
   GdkPixmap *pix;
   GtkWidget *image;
   GtkWidget *eventbox;
-  gpointer *pass_along;
 
   // First allocation
-  widgets->distances = vik_track_make_distance_map ( tr, widgets->profile_width );
+  widgets->distances = vik_track_make_distance_map ( widgets->tr, widgets->profile_width );
   if ( widgets->distances == NULL )
     return NULL;
 
-  pass_along = g_malloc ( sizeof(gpointer) * 4 ); /* FIXME: mem leak -- never be freed */
-  pass_along[0] = tr;
-  pass_along[1] = vlp;
-  pass_along[2] = vvp;
-  pass_along[3] = widgets;
-
-  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) );
 
   eventbox = gtk_event_box_new ();
-  g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_dt_click), pass_along );
-  g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_dt_move), pass_along );
-  g_signal_connect_swapped ( G_OBJECT(eventbox), "destroy", G_CALLBACK(g_free), pass_along );
+  g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_dt_click), widgets );
+  g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_dt_move), widgets );
+  //g_signal_connect_swapped ( G_OBJECT(eventbox), "destroy", G_CALLBACK(g_free), widgets );
   gtk_container_add ( GTK_CONTAINER(eventbox), image );
   gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
 
@@ -2607,33 +2477,25 @@ GtkWidget *vik_trw_layer_create_dtdiag ( GtkWidget *window, VikTrack *tr, gpoint
 /**
  * Create elevation / time widgets including the image and callbacks
  */
-GtkWidget *vik_trw_layer_create_etdiag ( GtkWidget *window, VikTrack *tr, gpointer vlp, VikViewport *vvp, PropWidgets *widgets)
+GtkWidget *vik_trw_layer_create_etdiag ( GtkWidget *window, PropWidgets *widgets)
 {
   GdkPixmap *pix;
   GtkWidget *image;
   GtkWidget *eventbox;
-  gpointer *pass_along;
 
   // First allocation
-  widgets->ats = vik_track_make_elevation_time_map ( tr, widgets->profile_width );
+  widgets->ats = vik_track_make_elevation_time_map ( widgets->tr, widgets->profile_width );
   if ( widgets->ats == NULL )
     return NULL;
 
-  pass_along = g_malloc ( sizeof(gpointer) * 4 ); /* FIXME: mem leak -- never be freed */
-  pass_along[0] = tr;
-  pass_along[1] = vlp;
-  pass_along[2] = vvp;
-  pass_along[3] = widgets;
-
-  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) );
 
   eventbox = gtk_event_box_new ();
-  g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_et_click), pass_along );
-  g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_et_move), pass_along );
-  g_signal_connect_swapped ( G_OBJECT(eventbox), "destroy", G_CALLBACK(g_free), pass_along );
+  g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_et_click), widgets );
+  g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_et_move), widgets );
   gtk_container_add ( GTK_CONTAINER(eventbox), image );
   gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
 
@@ -2643,33 +2505,25 @@ GtkWidget *vik_trw_layer_create_etdiag ( GtkWidget *window, VikTrack *tr, gpoint
 /**
  * Create speed/distance widgets including the image and callbacks
  */
-GtkWidget *vik_trw_layer_create_sddiag ( GtkWidget *window, VikTrack *tr, gpointer vlp, VikViewport *vvp, PropWidgets *widgets)
+GtkWidget *vik_trw_layer_create_sddiag ( GtkWidget *window, PropWidgets *widgets)
 {
   GdkPixmap *pix;
   GtkWidget *image;
   GtkWidget *eventbox;
-  gpointer *pass_along;
 
   // First allocation
-  widgets->speeds_dist = vik_track_make_speed_dist_map ( tr, widgets->profile_width );
+  widgets->speeds_dist = vik_track_make_speed_dist_map ( widgets->tr, widgets->profile_width );
   if ( widgets->speeds_dist == NULL )
     return NULL;
 
-  pass_along = g_malloc ( sizeof(gpointer) * 4 ); /* FIXME: mem leak -- never be freed */
-  pass_along[0] = tr;
-  pass_along[1] = vlp;
-  pass_along[2] = vvp;
-  pass_along[3] = widgets;
-
-  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) );
 
   eventbox = gtk_event_box_new ();
-  g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_sd_click), pass_along );
-  g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_sd_move), pass_along );
-  g_signal_connect_swapped ( G_OBJECT(eventbox), "destroy", G_CALLBACK(g_free), pass_along );
+  g_signal_connect ( G_OBJECT(eventbox), "button_press_event", G_CALLBACK(track_sd_click), widgets );
+  g_signal_connect ( G_OBJECT(eventbox), "motion_notify_event", G_CALLBACK(track_sd_move), widgets );
   gtk_container_add ( GTK_CONTAINER(eventbox), image );
   gtk_widget_set_events (eventbox, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
 
@@ -2677,7 +2531,22 @@ GtkWidget *vik_trw_layer_create_sddiag ( GtkWidget *window, VikTrack *tr, gpoint
 }
 #undef MARGIN
 
-static void propwin_response_cb( GtkDialog *dialog, gint resp, PropWidgets *widgets)
+#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);
+}
+
+static void propwin_response_cb( GtkDialog *dialog, gint resp, PropWidgets *widgets )
 {
   VikTrack *tr = widgets->tr;
   VikTrwLayer *vtl = widgets->vtl;
@@ -2691,16 +2560,23 @@ static void propwin_response_cb( GtkDialog *dialog, gint resp, PropWidgets *widg
       break;
     case GTK_RESPONSE_ACCEPT:
       vik_track_set_comment(tr, gtk_entry_get_text(GTK_ENTRY(widgets->w_comment)));
+      vik_track_set_description(tr, gtk_entry_get_text(GTK_ENTRY(widgets->w_description)));
+      gtk_color_button_get_color ( GTK_COLOR_BUTTON(widgets->w_color), &(tr->color) );
+      trw_layer_update_treeview ( widgets->vtl, widgets->tr, widgets->trk_id );
+      vik_layer_emit_update ( VIK_LAYER(vtl) );
       break;
     case VIK_TRW_LAYER_PROPWIN_REVERSE:
       vik_track_reverse(tr);
-      vik_layer_emit_update ( VIK_LAYER(vtl), FALSE );
+      vik_layer_emit_update ( VIK_LAYER(vtl) );
       break;
     case VIK_TRW_LAYER_PROPWIN_DEL_DUP:
-      vik_track_remove_dup_points(tr);
+      vik_track_remove_dup_points(tr); // NB ignore the returned answer
+      // As we could have seen the nuber of dulplicates that would be deleted in the properties statistics tab,
+      //   choose not to inform the user unnecessarily
+
       /* above operation could have deleted current_tp or last_tp */
       trw_layer_cancel_tps_of_track ( vtl, tr );
-      vik_layer_emit_update ( VIK_LAYER(vtl), FALSE );
+      vik_layer_emit_update ( VIK_LAYER(vtl) );
       break;
     case VIK_TRW_LAYER_PROPWIN_SPLIT:
       {
@@ -2713,8 +2589,13 @@ static void propwin_response_cb( GtkDialog *dialog, gint resp, PropWidgets *widg
         for ( i = 0; i < ntracks; i++ )
         {
           if ( tracks[i] ) {
-           new_tr_name = g_strdup_printf("%s #%d", widgets->tr->name, i+1);
-           vik_trw_layer_add_track ( vtl, new_tr_name, tracks[i] );
+           new_tr_name = trw_layer_new_unique_sublayer_name ( vtl,
+                                                               widgets->tr->is_route ? VIK_TRW_LAYER_SUBLAYER_ROUTE : VIK_TRW_LAYER_SUBLAYER_TRACK,
+                                                               widgets->tr->name);
+            if ( widgets->tr->is_route )
+              vik_trw_layer_add_route ( vtl, new_tr_name, tracks[i] );
+            else
+              vik_trw_layer_add_track ( vtl, new_tr_name, tracks[i] );
          }
         }
         if ( tracks )
@@ -2722,8 +2603,11 @@ static void propwin_response_cb( GtkDialog *dialog, gint resp, PropWidgets *widg
           g_free ( tracks );
           /* Don't let track destroy this dialog */
           vik_track_clear_property_dialog(tr);
-          vik_trw_layer_delete_track ( vtl, tr );
-          vik_layer_emit_update ( VIK_LAYER(vtl), FALSE ); /* chase thru the hoops */
+          if ( widgets->tr->is_route )
+            vik_trw_layer_delete_route ( vtl, tr );
+          else
+            vik_trw_layer_delete_track ( vtl, tr );
+          vik_layer_emit_update ( VIK_LAYER(vtl) ); /* chase thru the hoops */
         }
       }
       break;
@@ -2741,17 +2625,23 @@ static void propwin_response_cb( GtkDialog *dialog, gint resp, PropWidgets *widg
           break;
         }
 
-        gchar *r_name = g_strdup_printf("%s #2", widgets->tr->name);
+        gchar *r_name = trw_layer_new_unique_sublayer_name(vtl,
+                                                           widgets->tr->is_route ? VIK_TRW_LAYER_SUBLAYER_ROUTE : VIK_TRW_LAYER_SUBLAYER_TRACK,
+                                                           widgets->tr->name);
         iter->prev->next = NULL;
         iter->prev = NULL;
         VikTrack *tr_right = vik_track_new();
         if ( tr->comment )
           vik_track_set_comment ( tr_right, tr->comment );
         tr_right->visible = tr->visible;
+        tr_right->is_route = tr->is_route;
         tr_right->trackpoints = iter;
 
-        vik_trw_layer_add_track(vtl, r_name, tr_right);
-        vik_layer_emit_update ( VIK_LAYER(vtl), FALSE );
+        if ( widgets->tr->is_route )
+          vik_trw_layer_add_route(vtl, r_name, tr_right);
+        else
+          vik_trw_layer_add_track(vtl, r_name, tr_right);
+        vik_layer_emit_update ( VIK_LAYER(vtl) );
       }
       break;
     default:
@@ -2761,7 +2651,6 @@ static void propwin_response_cb( GtkDialog *dialog, gint resp, PropWidgets *widg
 
   /* Keep same behaviour for now: destroy dialog if click on any button */
   if (!keep_dialog) {
-    prop_widgets_free(widgets);
     vik_track_clear_property_dialog(tr);
     gtk_widget_destroy ( GTK_WIDGET(dialog) );
   }
@@ -2770,12 +2659,11 @@ static void propwin_response_cb( GtkDialog *dialog, gint resp, PropWidgets *widg
 /**
  * Force a redraw when checkbutton has been toggled to show/hide that information
  */
-static void checkbutton_toggle_cb ( GtkToggleButton *togglebutton, gpointer *pass_along, gpointer dummy)
+static void checkbutton_toggle_cb ( GtkToggleButton *togglebutton, PropWidgets *widgets, gpointer dummy )
 {
-  PropWidgets *widgets = pass_along[3];
   // Even though not resized, we'll pretend it is -
   //  as this invalidates the saved images (since the image may have changed)
-  draw_all_graphs ( widgets->dialog, pass_along, TRUE);
+  draw_all_graphs ( widgets->dialog, widgets, TRUE );
 }
 
 /**
@@ -2815,14 +2703,32 @@ static GtkWidget *create_graph_page ( GtkWidget *graph,
   return vbox;
 }
 
-void vik_trw_layer_propwin_run ( GtkWindow *parent, VikTrwLayer *vtl, VikTrack *tr, gpointer vlp, VikViewport *vvp )
+void vik_trw_layer_propwin_run ( GtkWindow *parent,
+                                 VikTrwLayer *vtl,
+                                 VikTrack *tr,
+                                 gpointer vlp,
+                                 VikViewport *vvp,
+                                 gpointer *trk_id )
 {
-  /* FIXME: free widgets when destroy signal received */
   PropWidgets *widgets = prop_widgets_new();
   widgets->vtl = vtl;
+  widgets->vvp = vvp;
+  widgets->vlp = vlp;
   widgets->tr = tr;
-  widgets->profile_width  = PROPWIN_PROFILE_WIDTH;
-  widgets->profile_height = PROPWIN_PROFILE_HEIGHT;
+  widgets->trk_id = trk_id;
+
+  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,
@@ -2835,26 +2741,44 @@ void vik_trw_layer_propwin_run ( GtkWindow *parent, VikTrwLayer *vtl, VikTrack *
                          GTK_STOCK_OK,     GTK_RESPONSE_ACCEPT,
                          NULL);
   widgets->dialog = dialog;
+  g_signal_connect( G_OBJECT(dialog), "response", G_CALLBACK(propwin_response_cb), widgets);
+
   g_free(title);
-  g_signal_connect(dialog, "response", G_CALLBACK(propwin_response_cb), widgets);
   GtkTable *table;
   gdouble tr_len;
-  guint32 tp_count, seg_count;
+  gulong tp_count;
+  guint seg_count;
 
   gdouble min_alt, max_alt;
-  widgets->elev_box = vik_trw_layer_create_profile(GTK_WIDGET(parent), tr, vlp, vvp, widgets, &min_alt, &max_alt);
-  widgets->gradient_box = vik_trw_layer_create_gradient(GTK_WIDGET(parent), tr, vlp, vvp, widgets);
-  widgets->speed_box = vik_trw_layer_create_vtdiag(GTK_WIDGET(parent), tr, vlp, vvp, widgets);
-  widgets->dist_box = vik_trw_layer_create_dtdiag(GTK_WIDGET(parent), tr, vlp, vvp, widgets);
-  widgets->elev_time_box = vik_trw_layer_create_etdiag(GTK_WIDGET(parent), tr, vlp, vvp, widgets);
-  widgets->speed_dist_box = vik_trw_layer_create_sddiag(GTK_WIDGET(parent), tr, vlp, vvp, widgets);
+  widgets->elev_box = vik_trw_layer_create_profile(GTK_WIDGET(parent), widgets, &min_alt, &max_alt);
+  widgets->gradient_box = vik_trw_layer_create_gradient(GTK_WIDGET(parent), widgets);
+  widgets->speed_box = vik_trw_layer_create_vtdiag(GTK_WIDGET(parent), widgets);
+  widgets->dist_box = vik_trw_layer_create_dtdiag(GTK_WIDGET(parent), widgets);
+  widgets->elev_time_box = vik_trw_layer_create_etdiag(GTK_WIDGET(parent), widgets);
+  widgets->speed_dist_box = vik_trw_layer_create_sddiag(GTK_WIDGET(parent), widgets);
   GtkWidget *graphs = gtk_notebook_new();
 
   GtkWidget *content[20];
   int cnt;
   int i;
 
-  static gchar *label_texts[] = { N_("<b>Comment:</b>"), N_("<b>Track Length:</b>"), N_("<b>Trackpoints:</b>"), N_("<b>Segments:</b>"), N_("<b>Duplicate Points:</b>"), N_("<b>Max Speed:</b>"), N_("<b>Avg. Speed:</b>"), N_("<b>Moving Avg. Speed:</b>"), N_("<b>Avg. Dist. Between TPs:</b>"), N_("<b>Elevation Range:</b>"), N_("<b>Total Elevation Gain/Loss:</b>"), N_("<b>Start:</b>"), N_("<b>End:</b>"), N_("<b>Duration:</b>") };
+  static gchar *label_texts[] = {
+    N_("<b>Comment:</b>"),
+    N_("<b>Description:</b>"),
+    N_("<b>Track Length:</b>"),
+    N_("<b>Trackpoints:</b>"),
+    N_("<b>Segments:</b>"),
+    N_("<b>Duplicate Points:</b>"),
+    N_("<b>Max Speed:</b>"),
+    N_("<b>Avg. Speed:</b>"),
+    N_("<b>Moving Avg. Speed:</b>"),
+    N_("<b>Avg. Dist. Between TPs:</b>"),
+    N_("<b>Elevation Range:</b>"),
+    N_("<b>Total Elevation Gain/Loss:</b>"),
+    N_("<b>Start:</b>"),
+    N_("<b>End:</b>"),
+    N_("<b>Duration:</b>"),
+    N_("<b>Color:</b>") };
   static gchar tmp_buf[50];
   gdouble tmp_speed;
 
@@ -2865,6 +2789,12 @@ void vik_trw_layer_propwin_run ( GtkWindow *parent, VikTrwLayer *vtl, VikTrack *
   g_signal_connect_swapped ( widgets->w_comment, "activate", G_CALLBACK(a_dialog_response_accept), GTK_DIALOG(dialog) );
   content[cnt++] = widgets->w_comment;
 
+  widgets->w_description = gtk_entry_new ();
+  if ( tr->description )
+    gtk_entry_set_text ( GTK_ENTRY(widgets->w_description), tr->description );
+  g_signal_connect_swapped ( widgets->w_description, "activate", G_CALLBACK(a_dialog_response_accept), GTK_DIALOG(dialog) );
+  content[cnt++] = widgets->w_description;
+
   vik_units_distance_t dist_units = a_vik_get_units_distance ();
 
   // NB This value not shown yet - but is used by internal calculations
@@ -2884,7 +2814,7 @@ void vik_trw_layer_propwin_run ( GtkWindow *parent, VikTrwLayer *vtl, VikTrack *
   widgets->w_track_length = content[cnt++] = gtk_label_new ( tmp_buf );
 
   tp_count = vik_track_get_tp_count(tr);
-  g_snprintf(tmp_buf, sizeof(tmp_buf), "%u", tp_count );
+  g_snprintf(tmp_buf, sizeof(tmp_buf), "%lu", tp_count );
   widgets->w_tp_count = content[cnt++] = gtk_label_new ( tmp_buf );
 
   seg_count = vik_track_get_segment_count(tr) ;
@@ -3041,14 +2971,10 @@ void vik_trw_layer_propwin_run ( GtkWindow *parent, VikTrwLayer *vtl, VikTrack *
     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);
@@ -3059,6 +2985,8 @@ void vik_trw_layer_propwin_run ( GtkWindow *parent, VikTrwLayer *vtl, VikTrack *
     widgets->w_time_dur = content[cnt++] = gtk_label_new(_("No Data"));
   }
 
+  widgets->w_color = content[cnt++] = gtk_color_button_new_with_color ( &(tr->color) );
+
   table = GTK_TABLE(gtk_table_new (cnt, 2, FALSE));
   gtk_table_set_col_spacing (table, 0, 10);
   for (i=0; i<cnt; i++) {
@@ -3078,13 +3006,6 @@ void vik_trw_layer_propwin_run ( GtkWindow *parent, VikTrwLayer *vtl, VikTrack *
 
   gtk_notebook_append_page(GTK_NOTEBOOK(graphs), GTK_WIDGET(table), gtk_label_new(_("Statistics")));
 
-  gpointer *pass_along;
-  pass_along = g_malloc ( sizeof(gpointer) * 4 ); /* FIXME: mem leak -- never be freed */
-  pass_along[0] = tr;
-  pass_along[1] = vlp;
-  pass_along[2] = vvp;
-  pass_along[3] = widgets;
-
   if ( widgets->elev_box ) {
     GtkWidget *page = NULL;
     widgets->w_cur_dist = gtk_label_new(_("No Data"));
@@ -3096,8 +3017,8 @@ void vik_trw_layer_propwin_run ( GtkWindow *parent, VikTrwLayer *vtl, VikTrack *
                              _("<b>Track Height:</b>"), widgets->w_cur_elevation,
                              widgets->w_show_dem, TRUE,
                              widgets->w_show_alt_gps_speed, TRUE);
-    g_signal_connect (widgets->w_show_dem, "toggled", G_CALLBACK (checkbutton_toggle_cb), pass_along);
-    g_signal_connect (widgets->w_show_alt_gps_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), pass_along);
+    g_signal_connect (widgets->w_show_dem, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
+    g_signal_connect (widgets->w_show_alt_gps_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
     gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Elevation-distance")));
   }
 
@@ -3111,7 +3032,7 @@ void vik_trw_layer_propwin_run ( GtkWindow *parent, VikTrwLayer *vtl, VikTrack *
                              _("<b>Track Gradient:</b>"), widgets->w_cur_gradient_gradient,
                              widgets->w_show_gradient_gps_speed, TRUE,
                   NULL, FALSE);
-    g_signal_connect (widgets->w_show_gradient_gps_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), pass_along);
+    g_signal_connect (widgets->w_show_gradient_gps_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
     gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Gradient-distance")));
   }
 
@@ -3125,7 +3046,7 @@ void vik_trw_layer_propwin_run ( GtkWindow *parent, VikTrwLayer *vtl, VikTrack *
                              _("<b>Track Speed:</b>"), widgets->w_cur_speed,
                              widgets->w_show_gps_speed, TRUE,
                              NULL, FALSE);
-    g_signal_connect (widgets->w_show_gps_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), pass_along);
+    g_signal_connect (widgets->w_show_gps_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
     gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Speed-time")));
   }
 
@@ -3139,7 +3060,7 @@ void vik_trw_layer_propwin_run ( GtkWindow *parent, VikTrwLayer *vtl, VikTrack *
                              _("<b>Track Time:</b>"), widgets->w_cur_dist_time,
                              widgets->w_show_dist_speed, FALSE,
                              NULL, FALSE);
-    g_signal_connect (widgets->w_show_dist_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), pass_along);
+    g_signal_connect (widgets->w_show_dist_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
     gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Distance-time")));
   }
 
@@ -3153,7 +3074,7 @@ void vik_trw_layer_propwin_run ( GtkWindow *parent, VikTrwLayer *vtl, VikTrack *
                              _("<b>Track Height:</b>"), widgets->w_cur_elev_elev,
                              widgets->w_show_elev_speed, FALSE,
                              NULL, FALSE);
-    g_signal_connect (widgets->w_show_elev_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), pass_along);
+    g_signal_connect (widgets->w_show_elev_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
     gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Elevation-time")));
   }
 
@@ -3167,11 +3088,11 @@ void vik_trw_layer_propwin_run ( GtkWindow *parent, VikTrwLayer *vtl, VikTrack *
                              _("<b>Track Speed:</b>"), widgets->w_cur_speed_speed,
                              widgets->w_show_sd_gps_speed, TRUE,
                              NULL, FALSE);
-    g_signal_connect (widgets->w_show_sd_gps_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), pass_along);
+    g_signal_connect (widgets->w_show_sd_gps_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
     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)
@@ -3179,9 +3100,11 @@ void vik_trw_layer_propwin_run ( GtkWindow *parent, VikTrwLayer *vtl, VikTrack *
   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), pass_along);
+  g_signal_connect ( G_OBJECT(dialog), "configure-event", G_CALLBACK (configure_event), widgets );
+
+  g_signal_connect ( G_OBJECT(dialog), "destroy", G_CALLBACK (destroy_cb), widgets );
 
   vik_track_set_property_dialog(tr, dialog);
   gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );