+/********************************************************************************
+ ** Select tool code
+ ********************************************************************************/
+static gpointer selecttool_create (VikWindow *vw, VikViewport *vvp)
+{
+ tool_ed_t *t = g_new(tool_ed_t, 1);
+ t->vw = vw;
+ t->vvp = vvp;
+ t->vtl = NULL;
+ t->is_waypoint = FALSE;
+ return t;
+}
+
+static void selecttool_destroy (tool_ed_t *t)
+{
+ g_free(t);
+}
+
+typedef struct {
+ gboolean cont;
+ VikViewport *vvp;
+ GdkEventButton *event;
+ tool_ed_t *tool_edit;
+} clicker;
+
+static void click_layer_selected (VikLayer *vl, clicker *ck)
+{
+ /* Do nothing when function call returns true; */
+ /* i.e. stop on first found item */
+ if ( ck->cont )
+ if ( vl->visible )
+ if ( vik_layer_get_interface(vl->type)->select_click )
+ ck->cont = !vik_layer_get_interface(vl->type)->select_click ( vl, ck->event, ck->vvp, ck->tool_edit );
+}
+
+static VikLayerToolFuncStatus selecttool_click (VikLayer *vl, GdkEventButton *event, tool_ed_t *t)
+{
+ /* Only allow selection on primary button */
+ if ( event->button == 1 ) {
+ /* Enable click to apply callback to potentially all track/waypoint layers */
+ /* Useful as we can find things that aren't necessarily in the currently selected layer */
+ GList* gl = vik_layers_panel_get_all_layers_of_type ( t->vw->viking_vlp, VIK_LAYER_TRW, FALSE ); // Don't get invisible layers
+ clicker ck;
+ ck.cont = TRUE;
+ ck.vvp = t->vw->viking_vvp;
+ ck.event = event;
+ ck.tool_edit = t;
+ g_list_foreach ( gl, (GFunc) click_layer_selected, &ck );
+ g_list_free ( gl );
+
+ // If nothing found then deselect & redraw screen if necessary to remove the highlight
+ if ( ck.cont ) {
+ GtkTreeIter iter;
+ VikTreeview *vtv = vik_layers_panel_get_treeview ( t->vw->viking_vlp );
+
+ if ( vik_treeview_get_selected_iter ( vtv, &iter ) ) {
+ // Only clear if selected thing is a TrackWaypoint layer or a sublayer
+ gint type = vik_treeview_item_get_type ( vtv, &iter );
+ if ( type == VIK_TREEVIEW_TYPE_SUBLAYER ||
+ VIK_LAYER(vik_treeview_item_get_pointer ( vtv, &iter ))->type == VIK_LAYER_TRW ) {
+
+ vik_treeview_item_unselect ( vtv, &iter );
+ if ( vik_window_clear_highlight ( t->vw ) )
+ draw_update ( t->vw );
+ }
+ }
+ }
+ }
+ else if ( ( event->button == 3 ) && ( vl && ( vl->type == VIK_LAYER_TRW ) ) ) {
+ if ( vl->visible )
+ /* Act on currently selected item to show menu */
+ if ( ( t->vw->selected_track || t->vw->selected_waypoint ) && t->vw->selected_name )
+ if ( vik_layer_get_interface(vl->type)->show_viewport_menu )
+ vik_layer_get_interface(vl->type)->show_viewport_menu ( vl, event, t->vw->viking_vvp );
+ }
+
+ return VIK_LAYER_TOOL_ACK;
+}
+
+static VikLayerToolFuncStatus selecttool_move (VikLayer *vl, GdkEventButton *event, tool_ed_t *t)
+{
+ /* Only allow selection on primary button */
+ if ( event->button == 1 ) {
+ // Don't care about vl here
+ if ( t->vtl )
+ if ( vik_layer_get_interface(VIK_LAYER_TRW)->select_move )
+ vik_layer_get_interface(VIK_LAYER_TRW)->select_move ( vl, event, t->vvp, t );
+ }
+ return VIK_LAYER_TOOL_ACK;
+}
+
+static VikLayerToolFuncStatus selecttool_release (VikLayer *vl, GdkEventButton *event, tool_ed_t *t)
+{
+ /* Only allow selection on primary button */
+ if ( event->button == 1 ) {
+ // Don't care about vl here
+ if ( t->vtl )
+ if ( vik_layer_get_interface(VIK_LAYER_TRW)->select_release )
+ vik_layer_get_interface(VIK_LAYER_TRW)->select_release ( (VikLayer*)t->vtl, event, t->vvp, t );
+ }
+ return VIK_LAYER_TOOL_ACK;
+}
+
+static VikToolInterface select_tool =
+ { { "Select", "vik-icon-select", N_("_Select"), "<control><shift>S", N_("Select Tool"), 3 },
+ (VikToolConstructorFunc) selecttool_create,
+ (VikToolDestructorFunc) selecttool_destroy,
+ (VikToolActivationFunc) NULL,
+ (VikToolActivationFunc) NULL,
+ (VikToolMouseFunc) selecttool_click,
+ (VikToolMouseMoveFunc) selecttool_move,
+ (VikToolMouseFunc) selecttool_release,
+ (VikToolKeyFunc) NULL,
+ GDK_LEFT_PTR,
+ NULL,
+ NULL };
+/*** end select tool code ********************************************************/
+