From fc81a1cf1c4d17ff8bce4aea09e609856bd71ff3 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Fri, 1 Aug 2008 15:36:14 +0300 Subject: [PATCH] MapWidget: Path handling changes. - Add gtk_map_toggle_current_track() - Add gtk_map_toggle_current_route() - Add boolean argument to path add to set a current track --- libs/libgtkmap/gtkmap.c | 77 ++++++++++++++++++++++++++++++++++++++--- libs/libgtkmap/gtkmap.h | 4 +-- 2 files changed, 75 insertions(+), 6 deletions(-) diff --git a/libs/libgtkmap/gtkmap.c b/libs/libgtkmap/gtkmap.c index 4e8253e..c7318a5 100644 --- a/libs/libgtkmap/gtkmap.c +++ b/libs/libgtkmap/gtkmap.c @@ -1191,11 +1191,12 @@ for (iter=priv->paths; iter!=NULL; iter=iter->next) { /** * gtk_map_add_path: * @path: A path object to add to the map + * @current: Is this the current track ? * * Adds a new path to the map. */ gboolean -gtk_map_add_path(GtkWidget *widget, Path *path) +gtk_map_add_path(GtkWidget *widget, Path *path, gboolean current) { GtkMap *map; GtkMapPriv *priv; @@ -1207,10 +1208,67 @@ map=GTK_MAP(widget); priv=GTK_MAP_GET_PRIVATE(map); /* Don't allow duplicates */ -if (g_slist_find(priv->paths, path)!=NULL) +if (g_slist_find(priv->paths, path)!=NULL) { + g_debug("Tried to add duplicate path!"); return FALSE; +} g_object_ref(path); priv->paths=g_slist_append(priv->paths, path); +if (current==TRUE) + priv->current_track=path; +gtk_map_refresh(widget); +return TRUE; +} + +/** + * gtk_map_set_current_track: + * @path: + * + * Toggle if given path is current track + */ +gboolean +gtk_map_toggle_current_track(GtkWidget *widget, Path *path, gboolean current) +{ +GtkMap *map; +GtkMapPriv *priv; + +g_return_val_if_fail(GTK_IS_MAP(widget), FALSE); +g_return_val_if_fail(path, FALSE); + +map=GTK_MAP(widget); +priv=GTK_MAP_GET_PRIVATE(map); + +if (g_slist_find(priv->paths, path)==NULL) + return FALSE; + +priv->current_track=current==TRUE ? path : NULL; + +return TRUE; +} + +/** + * gtk_map_set_current_route: + * @path: + * + * Toggle if given path is current route + */ +gboolean +gtk_map_toggle_current_route(GtkWidget *widget, Path *path, gboolean current) +{ +GtkMap *map; +GtkMapPriv *priv; + +g_return_val_if_fail(GTK_IS_MAP(widget), FALSE); +g_return_val_if_fail(path, FALSE); + +map=GTK_MAP(widget); +priv=GTK_MAP_GET_PRIVATE(map); + +if (g_slist_find(priv->paths, path)==NULL) + return FALSE; + +priv->current_route=current==TRUE ? path : NULL; + return TRUE; } @@ -1232,10 +1290,21 @@ g_return_val_if_fail(path, FALSE); map=GTK_MAP(widget); priv=GTK_MAP_GET_PRIVATE(map); -if (g_slist_find(priv->paths, path)==NULL) +if (g_slist_find(priv->paths, path)==NULL) { + g_debug("Path is not on map"); return FALSE; +} + priv->paths=g_slist_remove(priv->paths, path); + +if (priv->current_track==path) + priv->current_track=NULL; + +if (priv->current_route==path) + priv->current_route=NULL; + g_object_unref(path); +gtk_map_refresh(widget); return TRUE; } @@ -1892,7 +1961,7 @@ priv=GTK_MAP_GET_PRIVATE(map); omode=priv->center_mode; /* If we have a track, then we can center on it */ -if (priv->current_track) { +if (priv->current_track && mode!=CENTER_MANUAL) { priv->center_mode=mode; if (omode!=mode) g_signal_emit(widget, gtk_map_signals[MAP_CENTER_MODE_CHANGED], 0, NULL); diff --git a/libs/libgtkmap/gtkmap.h b/libs/libgtkmap/gtkmap.h index 5ac2f39..999e5c9 100644 --- a/libs/libgtkmap/gtkmap.h +++ b/libs/libgtkmap/gtkmap.h @@ -130,9 +130,9 @@ gboolean gtk_map_markers_add(GtkWidget *map, GtkMapMarkerType type, GtkListStore gboolean gtk_map_markers_remove(GtkWidget *map, GtkMapMarkerType type, GtkListStore *store); /* Paths */ -gboolean gtk_map_add_path(GtkWidget *map, Path *path); +gboolean gtk_map_add_path(GtkWidget *map, Path *path, gboolean current); gboolean gtk_map_remove_path(GtkWidget *map, Path *path); -gboolean gtk_map_remove_path_by_id(GtkWidget *map, gint path_id); +gboolean gtk_map_toggle_current_track(GtkWidget *widget, Path *path, gboolean current); void gtk_map_set_path_display(GtkWidget *widget, gint path_mask); /* Get copy of map back buffer */ -- 2.39.5