Fix:gui/gtk:Make the roadbook a toggle button
authortinloaf <tinloaf@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Tue, 28 Oct 2008 13:48:40 +0000 (13:48 +0000)
committertinloaf <tinloaf@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Tue, 28 Oct 2008 13:48:40 +0000 (13:48 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@1586 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/navit/gui/gtk/datawindow.c
navit/navit/gui/gtk/gui_gtk.h
navit/navit/gui/gtk/gui_gtk_action.c
navit/navit/navit.c

index 4815aeb..a18b845 100644 (file)
@@ -32,17 +32,13 @@ struct datawindow_priv {
        GtkWidget *window;
        GtkWidget *scrolled_window;
        GtkWidget *treeview;
+       GtkWidget *button;
        GtkListStore *liststore;
        GtkTreeModel *sortmodel;
        struct callback *click, *close;
+       struct gui_priv *gui;
 };
 
-static void
-gui_gtk_datawindow_destroy(struct datawindow_priv *win)
-{
-       return;
-}
-
 static GValue value;
 static void
 select_row(GtkTreeView *tree, GtkTreePath *path, GtkTreeViewColumn *column, struct datawindow_priv *win)
@@ -139,9 +135,33 @@ gui_gtk_datawindow_delete(GtkWidget *widget, GdkEvent *event, struct datawindow_
 {
        callback_call_0(win->close);
 
+       if (win->button) {
+               gtk_toggle_action_set_active (GTK_TOGGLE_ACTION(win->button), FALSE);
+       }
+
        return FALSE;
 }
 
+void
+gui_gtk_datawindow_destroy(struct datawindow_priv *win)
+{
+       if ((!win->gui) || (!win->gui->datawindow)) {
+               return;
+       }
+
+       gui_gtk_datawindow_delete(NULL, NULL, win);
+       gtk_widget_destroy(win->window);
+       win->gui->datawindow = NULL;
+
+       return;
+}
+
+void
+gui_gtk_datawindow_set_button(struct datawindow_priv *this_, GtkWidget *btn)
+{
+       this_->button = btn;
+}
+
 static gboolean
 keypress(GtkWidget *widget, GdkEventKey *event, struct datawindow_priv *win)
 {
@@ -185,7 +205,9 @@ gui_gtk_datawindow_new(struct gui_priv *gui, char *name, struct callback *click,
                gtk_window_set_transient_for(GTK_WINDOW((GtkWidget *)(win->window)), GTK_WINDOW(gui->win));
        g_signal_connect(G_OBJECT(win->window), "delete-event", G_CALLBACK(gui_gtk_datawindow_delete), win);
        gtk_widget_show_all(win->window);
+
+       win->gui = gui;
+       gui->datawindow = win;
        return win;
-       return NULL;
 }
 
index 45d144e..9a6eca3 100644 (file)
@@ -48,6 +48,7 @@ struct gui_priv {
        int toolbar_enable;
        int statusbar_enable;
        int dyn_counter;
+       struct datawindow_priv *datawindow;
 };
 
 void gui_gtk_ui_init(struct gui_priv *this);
index a03881c..bad3ba4 100644 (file)
@@ -66,10 +66,23 @@ refresh_action(GtkWidget *w, struct gui_priv *gui, void *dummy)
        navit_draw(gui->nav);
 }
 
+// Forward declarations, these should not be visible outside the GUI, so 
+// they are not in the header files, but here
+void gui_gtk_datawindow_set_button(struct datawindow_priv *this_, GtkWidget *btn);
+void gui_gtk_datawindow_destroy(struct datawindow_priv *win);
+
 static void
 roadbook_action(GtkWidget *w, struct gui_priv *gui, void *dummy)
 {
-       navit_window_roadbook_new(gui->nav);
+
+       if (! gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(w))) {
+               gui_gtk_datawindow_destroy(gui->datawindow);
+       } else {
+               navit_window_roadbook_new(gui->nav);
+               if (gui->datawindow) {
+                       gui_gtk_datawindow_set_button(gui->datawindow, w);
+               }
+       }
 }
 
 static void
@@ -176,7 +189,6 @@ static GtkActionEntry entries[] =
        { "ZoomOutAction", GTK_STOCK_ZOOM_OUT, _n("ZoomOut"), NULL, NULL, G_CALLBACK(zoom_out_action) },
        { "ZoomInAction", GTK_STOCK_ZOOM_IN, _n("ZoomIn"), NULL, NULL, G_CALLBACK(zoom_in_action) },
        { "RefreshAction", GTK_STOCK_REFRESH, _n("Recalculate"), NULL, NULL, G_CALLBACK(refresh_action) },
-       { "RoadbookAction", GTK_STOCK_JUSTIFY_FILL, _n("Roadbook"), NULL, NULL, G_CALLBACK(roadbook_action) },
 #ifdef GTK_STOCK_INFO
        { "InfoAction", GTK_STOCK_INFO, _n("Info"), NULL, NULL, G_CALLBACK(info_action) },
 #else
@@ -195,6 +207,7 @@ static GtkToggleActionEntry toggleentries[] =
        { "CursorAction", "cursor_icon",_n("Cursor"), NULL, NULL, G_CALLBACK(cursor_action),TRUE },
        { "TrackingAction", NULL ,_n("Lock on Road"), NULL, NULL, G_CALLBACK(tracking_action),TRUE },
        { "OrientationAction", "orientation_icon", _n("Northing"), NULL, NULL, G_CALLBACK(orient_north_action),FALSE },
+       { "RoadbookAction", GTK_STOCK_JUSTIFY_FILL, _n("Roadbook"), NULL, NULL, G_CALLBACK(roadbook_action), FALSE },
 #ifdef GTK_STOCK_FULLSCREEN
        { "FullscreenAction",GTK_STOCK_FULLSCREEN, _n("Fullscreen"), NULL, NULL, G_CALLBACK(window_fullscreen_action), FALSE }
 #else
@@ -546,6 +559,8 @@ gui_gtk_ui_init(struct gui_priv *this)
                toggle_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(this->base_group, "TrackingAction"));
                gtk_toggle_action_set_active(toggle_action, attr.u.num);
        }
+       toggle_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(this->base_group, "RoadbookAction"));
+       gtk_toggle_action_set_active(toggle_action, 0);
 }
 
 static struct menu_priv *
index 053dad5..d719eeb 100644 (file)
@@ -1007,6 +1007,10 @@ navit_window_roadbook_destroy(struct navit *this_)
 void
 navit_window_roadbook_new(struct navit *this_)
 {
+       if (this_->roadbook_callback || this_->roadbook_window) {
+               return;
+       }
+
        this_->roadbook_callback=callback_new_1(callback_cast(navit_window_roadbook_update), this_);
        navigation_register_callback(this_->navigation, attr_navigation_long, this_->roadbook_callback);
        this_->roadbook_window=gui_datawindow_new(this_->gui, _("Roadbook"), NULL, callback_new_1(callback_cast(navit_window_roadbook_destroy), this_));