]> git.street.me.uk Git - andy/viking.git/blobdiff - src/vikwindow.c
[QA] Move file related function into file.c and rename for general reuse
[andy/viking.git] / src / vikwindow.c
index a4ae5a8c55eeaff9e080d0d277e4a31bb087fd31..15ecdbeaa96c35860298ac7f40ad5b886088e8c3 100644 (file)
@@ -34,6 +34,7 @@
 #include "mapcache.h"
 #include "print.h"
 #include "preferences.h"
+#include "viklayer_defaults.h"
 #include "icons/icons.h"
 #include "vikexttools.h"
 #include "garminsymbols.h"
@@ -62,6 +63,7 @@
 //   why not be allowed to open a thousand more...
 #define MAX_WINDOWS 1024
 static guint window_count = 0;
+static GSList *window_list = NULL;
 
 #define VIKING_WINDOW_WIDTH      1000
 #define VIKING_WINDOW_HEIGHT     800
@@ -157,8 +159,6 @@ struct _VikWindow {
 
   GtkToolbar *toolbar;
 
-  GtkItemFactory *item_factory;
-
   /* tool management state */
   guint current_tool;
   toolbox_tools_t *vt;
@@ -357,6 +357,8 @@ static void window_finalize ( GObject *gob )
 
   a_background_remove_window ( vw );
 
+  window_list = g_slist_remove ( window_list, vw );
+
   G_OBJECT_CLASS(parent_class)->finalize(gob);
 }
 
@@ -384,7 +386,7 @@ static void zoom_changed (GtkMenuShell *menushell,
   VikWindow *vw = VIK_WINDOW (user_data);
 
   GtkWidget *aw = gtk_menu_get_active ( GTK_MENU (menushell) );
-  gint active = GPOINTER_TO_INT(gtk_object_get_data ( GTK_OBJECT (aw), "position" ));
+  gint active = GPOINTER_TO_INT(g_object_get_data ( G_OBJECT (aw), "position" ));
 
   gdouble zoom_request = pow (2, active-2 );
 
@@ -408,7 +410,7 @@ static GtkWidget * create_zoom_menu_all_levels ()
       GtkWidget *item = gtk_menu_item_new_with_label (itemLabels[i]);
       gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
       gtk_widget_show (item);
-      gtk_object_set_data (GTK_OBJECT (item), "position", GINT_TO_POINTER(i));
+      g_object_set_data (G_OBJECT (item), "position", GINT_TO_POINTER(i));
     }
 
   return menu;
@@ -479,7 +481,6 @@ static void vik_window_init ( VikWindow *vw )
   gtk_action_activate ( gtk_action_group_get_action ( vw->action_group, "Pan" ) );
 
   vw->filename = NULL;
-  vw->item_factory = NULL;
 
   vw->modified = FALSE;
   vw->only_updating_coord_mode_ui = FALSE;
@@ -498,8 +499,6 @@ static void vik_window_init ( VikWindow *vw )
   gtk_toolbar_set_icon_size (vw->toolbar, GTK_ICON_SIZE_SMALL_TOOLBAR);
   gtk_toolbar_set_style (vw->toolbar, GTK_TOOLBAR_ICONS);
 
-  vik_ext_tools_add_menu_items ( vw, vw->uim );
-
   GtkWidget * zoom_levels = gtk_ui_manager_get_widget (vw->uim, "/MainMenu/View/SetZoom");
   GtkWidget * zoom_levels_menu = create_zoom_menu_all_levels ();
   gtk_menu_item_set_submenu (GTK_MENU_ITEM (zoom_levels), zoom_levels_menu);
@@ -533,6 +532,8 @@ static void vik_window_init ( VikWindow *vw )
 
   a_background_add_window ( vw );
 
+  window_list = g_slist_prepend ( window_list, vw);
+
   vw->open_dia = NULL;
   vw->save_dia = NULL;
   vw->save_img_dia = NULL;
@@ -1032,7 +1033,7 @@ static void draw_ruler(VikViewport *vvp, GdkDrawable *d, GdkGC *gc, gint x1, gin
     gint wb, hb, xb, yb;
 
     pl = gtk_widget_create_pango_layout (GTK_WIDGET(vvp), NULL);
-    pango_layout_set_font_description (pl, GTK_WIDGET(vvp)->style->font_desc);
+    pango_layout_set_font_description (pl, gtk_widget_get_style(GTK_WIDGET(vvp))->font_desc);
     pango_layout_set_text(pl, "N", -1);
     gdk_draw_layout(d, gc, x1-5, y1-CR-3*CW-8, pl);
 
@@ -1198,13 +1199,13 @@ static VikLayerToolFuncStatus ruler_move (VikLayer *vl, GdkEventMotion *event, r
     vik_coord_to_latlon ( &coord, &ll );
     vik_viewport_coord_to_screen ( vvp, &s->oldcoord, &oldx, &oldy );
 
-    gdk_draw_drawable (buf, GTK_WIDGET(vvp)->style->black_gc, 
+    gdk_draw_drawable (buf, gtk_widget_get_style(GTK_WIDGET(vvp))->black_gc,
                       vik_viewport_get_pixmap(vvp), 0, 0, 0, 0, -1, -1);
-    draw_ruler(vvp, buf, GTK_WIDGET(vvp)->style->black_gc, oldx, oldy, event->x, event->y, vik_coord_diff( &coord, &(s->oldcoord)) );
+    draw_ruler(vvp, buf, gtk_widget_get_style(GTK_WIDGET(vvp))->black_gc, oldx, oldy, event->x, event->y, vik_coord_diff( &coord, &(s->oldcoord)) );
     if (draw_buf_done) {
       static gpointer pass_along[3];
       pass_along[0] = GTK_WIDGET(vvp)->window;
-      pass_along[1] = GTK_WIDGET(vvp)->style->black_gc;
+      pass_along[1] = gtk_widget_get_style(GTK_WIDGET(vvp))->black_gc;
       pass_along[2] = buf;
       g_idle_add_full (G_PRIORITY_HIGH_IDLE + 10, draw_buf, pass_along, NULL);
       draw_buf_done = FALSE;
@@ -1390,7 +1391,7 @@ static VikLayerToolFuncStatus zoomtool_move (VikLayer *vl, GdkEventMotion *event
 
     // Blank out currently drawn area
     gdk_draw_drawable ( zts->pixmap,
-                        GTK_WIDGET(zts->vw->viking_vvp)->style->black_gc,
+                        gtk_widget_get_style(GTK_WIDGET(zts->vw->viking_vvp))->black_gc,
                         vik_viewport_get_pixmap(zts->vw->viking_vvp),
                         0, 0, 0, 0, -1, -1);
 
@@ -1414,13 +1415,13 @@ static VikLayerToolFuncStatus zoomtool_move (VikLayer *vl, GdkEventMotion *event
     }
 
     // Draw the box
-    gdk_draw_rectangle (zts->pixmap, GTK_WIDGET(zts->vw->viking_vvp)->style->black_gc, FALSE, xx, yy, width, height);
+    gdk_draw_rectangle (zts->pixmap, gtk_widget_get_style(GTK_WIDGET(zts->vw->viking_vvp))->black_gc, FALSE, xx, yy, width, height);
 
     // Only actually draw when there's time to do so
     if (draw_buf_done) {
       static gpointer pass_along[3];
       pass_along[0] = GTK_WIDGET(zts->vw->viking_vvp)->window;
-      pass_along[1] = GTK_WIDGET(zts->vw->viking_vvp)->style->black_gc;
+      pass_along[1] = gtk_widget_get_style(GTK_WIDGET(zts->vw->viking_vvp))->black_gc;
       pass_along[2] = zts->pixmap;
       g_idle_add_full (G_PRIORITY_HIGH_IDLE + 10, draw_buf, pass_along, NULL);
       draw_buf_done = FALSE;
@@ -2520,17 +2521,52 @@ static void mapcache_flush_cb ( GtkAction *a, VikWindow *vw )
   a_mapcache_flush();
 }
 
+static void layer_defaults_cb ( GtkAction *a, VikWindow *vw )
+{
+  gchar **texts = g_strsplit ( gtk_action_get_name(a), "Layer", 0 );
+
+  if ( !texts[1] )
+    return; // Internally broken :(
+
+  if ( ! a_layer_defaults_show_window ( GTK_WINDOW(vw), texts[1] ) )
+    a_dialog_info_msg ( GTK_WINDOW(vw), _("This layer has no configurable properties.") );
+  // NB no update needed
+
+  g_strfreev ( texts );
+}
+
+static void preferences_change_update ( VikWindow *vw, gpointer data )
+{
+  // Want to update all TrackWaypoint layers
+  GList *layers = vik_layers_panel_get_all_layers_of_type ( vw->viking_vlp, VIK_LAYER_TRW, TRUE );
+
+  GList *iter = g_list_first ( layers );
+  while ( iter ) {
+    // Reset the individual waypoints themselves due to the preferences change
+    VikTrwLayer *vtl = VIK_TRW_LAYER(VIK_LAYER(layers->data));
+    vik_trw_layer_reset_waypoints ( vtl );
+       iter = g_list_next ( iter );
+  }
+
+  g_list_free ( layers );
+
+  draw_update ( vw );
+}
+
 static void preferences_cb ( GtkAction *a, VikWindow *vw )
 {
   gboolean wp_icon_size = a_vik_get_use_large_waypoint_icons();
 
   a_preferences_show_window ( GTK_WINDOW(vw) );
 
-  // Delete icon indexing 'cache' and so automatically regenerates with the new setting when changed
-  if (wp_icon_size != a_vik_get_use_large_waypoint_icons())
+  // Has the waypoint size setting changed?
+  if (wp_icon_size != a_vik_get_use_large_waypoint_icons()) {
+    // Delete icon indexing 'cache' and so automatically regenerates with the new setting when changed
     clear_garmin_icon_syms ();
 
-  draw_update ( vw );
+    // Update all windows
+    g_slist_foreach ( window_list, (GFunc) preferences_change_update, NULL );
+  }
 }
 
 static void default_location_cb ( GtkAction *a, VikWindow *vw )
@@ -2538,7 +2574,8 @@ static void default_location_cb ( GtkAction *a, VikWindow *vw )
   /* Simplistic repeat of preference setting
      Only the name & type are important for setting the preference via this 'external' way */
   VikLayerParam pref_lat[] = {
-    { VIKING_PREFERENCES_NAMESPACE "default_latitude",
+    { VIK_LAYER_NUM_TYPES,
+      VIKING_PREFERENCES_NAMESPACE "default_latitude",
       VIK_LAYER_PARAM_DOUBLE,
       VIK_LOCATION_LAT,
       NULL,
@@ -2548,7 +2585,8 @@ static void default_location_cb ( GtkAction *a, VikWindow *vw )
       NULL },
   };
   VikLayerParam pref_lon[] = {
-    { VIKING_PREFERENCES_NAMESPACE "default_longitude",
+    { VIK_LAYER_NUM_TYPES,
+      VIKING_PREFERENCES_NAMESPACE "default_longitude",
       VIK_LAYER_PARAM_DOUBLE,
       VIK_LOCATION_LONG,
       NULL,
@@ -3202,6 +3240,7 @@ static GtkActionEntry entries[] = {
   { "MapCacheFlush",NULL,                N_("_Flush Map Cache"),              NULL,         NULL,                                           (GCallback)mapcache_flush_cb     },
   { "SetDefaultLocation", GTK_STOCK_GO_FORWARD, N_("_Set the Default Location"), NULL, N_("Set the Default Location to the current position"),(GCallback)default_location_cb },
   { "Preferences",GTK_STOCK_PREFERENCES, N_("_Preferences"),                  NULL,         NULL,                                           (GCallback)preferences_cb              },
+  { "LayerDefaults",GTK_STOCK_PROPERTIES, N_("_Layer Defaults"),             NULL,         NULL,                                           NULL },
   { "Properties",GTK_STOCK_PROPERTIES,   N_("_Properties"),                   NULL,         NULL,                                           (GCallback)menu_properties_cb    },
 
   { "HelpEntry", GTK_STOCK_HELP,         N_("_Help"),                         "F1",         NULL,                                           (GCallback)help_help_cb     },
@@ -3322,6 +3361,22 @@ static void window_create_ui( VikWindow *window )
       // Overwrite with actual number to use
       radio->value = ntools;
     }
+
+    GtkActionEntry action_dl;
+    gtk_ui_manager_add_ui(uim, mid,  "/ui/MainMenu/Edit/LayerDefaults",
+                         vik_layer_get_interface(i)->name,
+                         g_strdup_printf("Layer%s", vik_layer_get_interface(i)->fixed_layer_name),
+                         GTK_UI_MANAGER_MENUITEM, FALSE);
+
+    // For default layers use action names of the form 'Layer<LayerName>'
+    // This is to avoid clashing with just the layer name used above for the tool actions
+    action_dl.name = g_strconcat("Layer", vik_layer_get_interface(i)->fixed_layer_name, NULL);
+    action_dl.stock_id = NULL;
+    action_dl.label = g_strconcat("_", vik_layer_get_interface(i)->name, "...", NULL); // Prepend marker for keyboard accelerator
+    action_dl.accelerator = NULL;
+    action_dl.tooltip = NULL;
+    action_dl.callback = (GCallback)layer_defaults_cb;
+    gtk_action_group_add_actions(action_group, &action_dl, 1, window);
   }
   g_object_unref (icon_factory);
 
@@ -3337,6 +3392,10 @@ static void window_create_ui( VikWindow *window )
       g_object_set(action, "sensitive", FALSE, NULL);
     }
   }
+
+  // This is done last so we don't need to track the value of mid anymore
+  vik_ext_tools_add_action_items ( window, window->uim, action_group, mid );
+
   window->action_group = action_group;
 
   accel_group = gtk_ui_manager_get_accel_group (uim);