[cairo-commit] roadster/src Makefile.am, 1.25, 1.26 db.c, 1.35, 1.36 db.h, 1.16, 1.17 mainwindow.c, 1.54, 1.55 mainwindow.h, 1.14, 1.15 map_draw_cairo.c, 1.31, 1.32 mapinfowindow.c, 1.2, 1.3 search.c, 1.9, 1.10 search.h, 1.4, 1.5 search_coordinate.c, NONE, 1.1 search_coordinate.h, NONE, 1.1 search_road.c, 1.29, 1.30 searchwindow.c, 1.27, 1.28 searchwindow.h, 1.6, 1.7 util.c, 1.18, 1.19 util.h, 1.18, 1.19

Ian McIntosh commit at pdx.freedesktop.org
Wed Oct 19 23:56:25 PDT 2005


Committed by: ian

Update of /cvs/cairo/roadster/src
In directory gabe:/tmp/cvs-serv7232/src

Modified Files:
	Makefile.am db.c db.h mainwindow.c mainwindow.h 
	map_draw_cairo.c mapinfowindow.c search.c search.h 
	search_road.c searchwindow.c searchwindow.h util.c util.h 
Added Files:
	search_coordinate.c search_coordinate.h 
Log Message:
	* roadster.spec: Added RPM .spec file contributed by Ofer Achler.
	* src/search_coordinate.c: Added file to allow pasting/typing text containing lat and lon coordinates into search box.  (Currently not implemented!)
	* src/search.c: Init and use search_coordinate stuff.
	* src/mainwindow.c: Disable hittesting related to tooltip for preview release.  Make GPS checkboxes insensitive when 'show position on map' is 
off.
	* src/db.c: Add db_city_get_name(id)
	* src/map_draw_cairo.c: Add miter limit.
	* src/mapinfowindow.c: Improve a lot.  May not make it into the preview release though.


Index: Makefile.am
===================================================================
RCS file: /cvs/cairo/roadster/src/Makefile.am,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- Makefile.am	11 Oct 2005 23:28:45 -0000	1.25
+++ Makefile.am	20 Oct 2005 06:56:22 -0000	1.26
@@ -46,6 +46,7 @@
 	search_road.c\
 	search_location.c\
 	search_city.c\
+	search_coordinate.c\
 	search.c\
 	scenemanager.c\
 	glyph.c\

Index: db.c
===================================================================
RCS file: /cvs/cairo/roadster/src/db.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- db.c	18 Oct 2005 03:05:25 -0000	1.35
+++ db.c	20 Oct 2005 06:56:22 -0000	1.36
@@ -401,6 +401,29 @@
 	return FALSE;
 }
 
+gboolean db_city_get_name(gint nCityID, gchar** ppszReturnName)
+{
+	g_assert(ppszReturnName != NULL);
+
+	// create SQL
+	gchar* pszSQL = g_strdup_printf("SELECT City.Name FROM City WHERE ID='%d';", nCityID);
+
+	// try query
+	db_resultset_t* pResultSet = NULL;
+	db_row_t aRow;
+	db_query(pszSQL, &pResultSet);
+	g_free(pszSQL);
+	// get result?
+	if(pResultSet) {
+		if((aRow = db_fetch_row(pResultSet)) != NULL) {
+			*ppszReturnName = g_strdup(aRow[0]);
+		}
+		db_free_result(pResultSet);
+		return TRUE;
+	}
+	return FALSE;
+}
+
 gboolean db_insert_city(const gchar* pszName, gint nStateID, gint* pnReturnCityID)
 {
 	gint nCityID = 0;

Index: db.h
===================================================================
RCS file: /cvs/cairo/roadster/src/db.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- db.h	18 Oct 2005 03:05:25 -0000	1.16
+++ db.h	20 Oct 2005 06:56:22 -0000	1.17
@@ -89,6 +89,8 @@
 gboolean db_city_get_id(const gchar* pszName, gint nStateID, gint* pnReturnID);
 gboolean db_state_get_id(const gchar* pszName, gint* pnReturnID);
 
+gboolean db_city_get_name(gint nCityID, gchar** ppszReturnName);
+
 void db_lock(void);
 void db_unlock(void);
 

Index: mainwindow.c
===================================================================
RCS file: /cvs/cairo/roadster/src/mainwindow.c,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -d -r1.54 -r1.55
--- mainwindow.c	18 Oct 2005 06:40:19 -0000	1.54
+++ mainwindow.c	20 Oct 2005 06:56:22 -0000	1.55
@@ -58,6 +58,8 @@
 #define PROGRAM_DESCRIPTION		"Mapping for everyone!"
 #define WEBSITE_URL				"http://linuxadvocate.org/projects/roadster"
 
+//#define ENABLE_MAP_TOOLTIP
+
 #define MAP_STYLE_FILENAME 		("layers.xml")
 
 // how long after stopping various movements should we redraw in high-quality mode
@@ -557,10 +559,11 @@
 
 	// Fill locationset list with live data
 	const GPtrArray* pLocationSetArray = locationset_get_array();
-	gint i;
+	g_debug("%d locationsets", pLocationSetArray->len);
 
 	gtk_list_store_clear(g_MainWindow.pLocationSetsListStore);
 
+	gint i;
 	for(i=0 ; i<pLocationSetArray->len ; i++) {
 		locationset_t* pLocationSet = g_ptr_array_index(pLocationSetArray, i);
 
@@ -627,8 +630,9 @@
 	g_MainWindow.nDrawPrettyTimeoutID = g_timeout_add(nTimeoutInMilliseconds, mainwindow_on_draw_pretty_timeout, NULL);
 	g_assert(g_MainWindow.nDrawPrettyTimeoutID != 0);
 }
+
 //
-// the "scroll" timeout
+// the scroll timeout
 //
 void mainwindow_scroll_direction(EDirection eScrollDirection, gint nPixels)
 {
@@ -1159,6 +1163,7 @@
 			g_MainWindow.bMouseDragMovement = FALSE;
 			g_MainWindow.ptClickLocation.nX = nX;
 			g_MainWindow.ptClickLocation.nY = nY;
+			tooltip_hide(g_MainWindow.pTooltip);
 		}
 		else if(event->type == GDK_BUTTON_RELEASE) {
 			if(g_MainWindow.bMouseDragging == TRUE) {
@@ -1251,6 +1256,7 @@
 		EDirection eScrollDirection = util_match_border(nX, nY, nWidth, nHeight, BORDER_SCROLL_CLICK_TARGET_SIZE);
 
 		if(eScrollDirection == DIRECTION_NONE) {
+#ifdef ENABLE_MAP_TOOLTIP
 			// get mouse position on screen
 			screenpoint_t screenpoint;
 			screenpoint.nX = nX;
@@ -1307,6 +1313,7 @@
 				// no hit. hide the tooltip
 				tooltip_hide(g_MainWindow.pTooltip);
 			}
+#endif
 		}
 		else {
 			nCursor = g_aDirectionCursors[eScrollDirection].nCursor;
@@ -1503,20 +1510,22 @@
 	return TRUE;
 }
 
-static gboolean mainwindow_on_expose_event(GtkWidget *pDrawingArea, GdkEventExpose *event, gpointer data)
+static gboolean mainwindow_on_expose_event(GtkWidget *_unused, GdkEventExpose *pEvent, gpointer __unused)
 {
-	GdkPixmap* pMapPixmap = map_get_pixmap(g_MainWindow.pMap);
+    if(pEvent->count > 0) return FALSE;
 
-	// Copy relevant portion of off-screen bitmap to window
-	gdk_draw_drawable(GTK_WIDGET(g_MainWindow.pDrawingArea)->window,
-                      GTK_WIDGET(g_MainWindow.pDrawingArea)->style->fg_gc[GTK_WIDGET_STATE(g_MainWindow.pDrawingArea)],
-                      pMapPixmap,
-                      event->area.x, event->area.y,
-                      event->area.x, event->area.y,
-                      event->area.width, event->area.height);
+    GdkPixmap* pMapPixmap = map_get_pixmap(g_MainWindow.pMap);
 
-	map_release_pixmap(g_MainWindow.pMap);
-	return FALSE;
+    // Copy relevant portion of off-screen bitmap to window
+    gdk_draw_drawable(GTK_WIDGET(g_MainWindow.pDrawingArea)->window,
+			   GTK_WIDGET(g_MainWindow.pDrawingArea)->style->fg_gc[GTK_WIDGET_STATE(g_MainWindow.pDrawingArea)],
+			   pMapPixmap,
+			   pEvent->area.x, pEvent->area.y,
+			   pEvent->area.x, pEvent->area.y,
+			   pEvent->area.width, pEvent->area.height);
+
+    map_release_pixmap(g_MainWindow.pMap);
+    return FALSE;
 }
 
 /*
@@ -1524,7 +1533,10 @@
 */
 void mainwindow_on_gps_show_position_toggled(GtkWidget* _unused, gpointer* __unused)
 {
-
+	gboolean bShowPosition = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g_MainWindow.GPS.pShowPositionCheckButton));
+	gtk_widget_set_sensitive(GTK_WIDGET(g_MainWindow.GPS.pKeepPositionCenteredCheckButton), bShowPosition == TRUE);
+	gtk_widget_set_sensitive(GTK_WIDGET(g_MainWindow.GPS.pShowTrailCheckButton), bShowPosition == TRUE);
+	gtk_widget_set_sensitive(GTK_WIDGET(g_MainWindow.GPS.pStickToRoadsCheckButton), FALSE);	// XXX: for now.
 }
 
 void mainwindow_on_gps_keep_position_centered_toggled(GtkWidget* _unused, gpointer* __unused)

Index: mainwindow.h
===================================================================
RCS file: /cvs/cairo/roadster/src/mainwindow.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- mainwindow.h	18 Oct 2005 03:05:25 -0000	1.14
+++ mainwindow.h	20 Oct 2005 06:56:22 -0000	1.15
@@ -80,8 +80,9 @@
 void mainwindow_scroll_direction(EDirection eScrollDirection, gint nPixels);
 
 #define SIDEBAR_TAB_LOCATIONSETS	0
-//#define SIDEBAR_TAB_TRACKS			1
-#define SIDEBAR_TAB_SEARCH_RESULTS	1
+#define SIDEBAR_TAB_TRACKS		1
+//#define SIDEBAR_TAB_GPS			2
+#define SIDEBAR_TAB_SEARCH_RESULTS	2
 
 void mainwindow_sidebar_set_tab(gint nTab);
 

Index: map_draw_cairo.c
===================================================================
RCS file: /cvs/cairo/roadster/src/map_draw_cairo.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- map_draw_cairo.c	18 Oct 2005 06:40:20 -0000	1.31
+++ map_draw_cairo.c	20 Oct 2005 06:56:22 -0000	1.32
@@ -66,7 +66,6 @@
 static void map_draw_cairo_layer_polygon_labels(map_t* pMap, cairo_t* pCairo, rendermetrics_t* pRenderMetrics, GPtrArray* pRoadsArray, maplayerstyle_t* pLayerStyle);
 
 // Draw a single line/polygon/point
-static void map_draw_cairo_background(map_t* pMap, cairo_t *pCairo);
 static void map_draw_cairo_layer_points(map_t* pMap, cairo_t* pCairo, rendermetrics_t* pRenderMetrics, GPtrArray* pLocationsArray);
 //static void map_draw_cairo_locationset(map_t* pMap, cairo_t *pCairo, rendermetrics_t* pRenderMetrics, locationset_t* pLocationSet, GPtrArray* pLocationsArray);
 //static void map_draw_cairo_locationselection(map_t* pMap, cairo_t *pCairo, rendermetrics_t* pRenderMetrics, GPtrArray* pLocationSelectionArray);
@@ -121,6 +120,7 @@
 	gdk_drawable_get_size (pPixmap, &width, &height);
 	cairo_surface_t *pSurface = cairo_xlib_surface_create (dpy, drawable, visual, width, height);
 	cairo_t* pCairo = cairo_create (pSurface);
+	cairo_set_miter_limit(pCairo, 10);
 
 //    cairo_set_antialias(pCairo, CAIRO_ANTIALIAS_GRAY);	// CAIRO_ANTIALIAS_DEFAULT, CAIRO_ANTIALIAS_NONE, CAIRO_ANTIALIAS_GRAY, CAIRO_ANTIALIAS_SUBPIXEL
 

Index: mapinfowindow.c
===================================================================
RCS file: /cvs/cairo/roadster/src/mapinfowindow.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- mapinfowindow.c	18 Oct 2005 03:05:25 -0000	1.2
+++ mapinfowindow.c	20 Oct 2005 06:56:22 -0000	1.3
@@ -32,6 +32,13 @@
 #include "util.h"
 #include "db.h"
 
+#define MSG_NO_COUNTRY 	("<i>Select Country</i>")
+#define MSG_NO_STATE	("<i>Select State</i>")
+#define MSG_NO_CITY		("<i>Select City</i>")
+#define MSG_COUNTRY 	("<b>%s</b>")
+#define MSG_STATE		("<b>%s</b>")
+#define MSG_CITY		("<b>%s</b>")
+
 #ifdef HAVE_CONFIG_H
 #  include <config.h>
 #endif
@@ -54,35 +61,23 @@
 	gint nCurrentCityID;
 } g_MapInfoWindow = {0};
 
-static void mapinfowindow_load_cities(gint nStateID);
-static void mapinfowindow_load_states(gint nCountryID);
-
-static void mapinfowindow_on_country_button_clicked(GtkWidget* _unused, gpointer __unused)
-{
-	if(g_MapInfoWindow.nCurrentCountryID != 0) {
-		g_debug("recentering on countryID %d", g_MapInfoWindow.nCurrentCountryID);
-	}
-}
+static void mapinfowindow_on_country_chosen(GtkMenuItem* pMenuItem, gint nCountryID);
+static void mapinfowindow_on_state_chosen(GtkMenuItem* pMenuItem, gint nStateID);
+static void mapinfowindow_on_city_chosen(GtkMenuItem* pMenuItem, gint nCityID);
 
-static void mapinfowindow_on_state_button_clicked(GtkWidget* _unused, gpointer __unused)
-{
-	if(g_MapInfoWindow.nCurrentStateID != 0) {
-		g_debug("recentering on StateID %d", g_MapInfoWindow.nCurrentStateID);
-	}
-}
+static void mapinfowindow_on_state_button_clicked(GtkWidget* _unused, gpointer __unused);
+static void mapinfowindow_on_city_button_clicked(GtkWidget* _unused, gpointer __unused);
+static void mapinfowindow_on_country_button_clicked(GtkWidget* _unused, gpointer __unused);
 
-static void mapinfowindow_on_city_button_clicked(GtkWidget* _unused, gpointer __unused)
-{
-	if(g_MapInfoWindow.nCurrentCityID != 0) {
-		g_debug("recentering on cityID %d", g_MapInfoWindow.nCurrentCityID);
-	}
-}
+static void mapinfowindow_load_countries();
+static void mapinfowindow_load_cities(gint nStateID);
+static void mapinfowindow_load_states(gint nCountryID);
 
 void mapinfowindow_init(GladeXML* pGladeXML)
 {
 	GLADE_LINK_WIDGET(pGladeXML, g_MapInfoWindow.pCountryButton, GTK_MENU_TOOL_BUTTON, "countrybutton");
 	GLADE_LINK_WIDGET(pGladeXML, g_MapInfoWindow.pStateButton, GTK_MENU_TOOL_BUTTON, "statebutton");
-    GLADE_LINK_WIDGET(pGladeXML, g_MapInfoWindow.pCityButton, GTK_MENU_TOOL_BUTTON, "citybutton");
+	GLADE_LINK_WIDGET(pGladeXML, g_MapInfoWindow.pCityButton, GTK_MENU_TOOL_BUTTON, "citybutton");
 
 	g_MapInfoWindow.pCountryLabel = GTK_LABEL(gtk_label_new(""));	gtk_widget_show(GTK_WIDGET(g_MapInfoWindow.pCountryLabel));
 	g_MapInfoWindow.pStateLabel = GTK_LABEL(gtk_label_new(""));	gtk_widget_show(GTK_WIDGET(g_MapInfoWindow.pStateLabel));
@@ -99,6 +94,8 @@
 	g_MapInfoWindow.nCurrentCountryID = -1;	//
 	g_MapInfoWindow.nCurrentStateID = -1;
 	g_MapInfoWindow.nCurrentCityID = -1;
+
+	mapinfowindow_load_countries();
 }
 
 void mapinfowindow_update(const map_t* pMap)
@@ -108,7 +105,7 @@
 	gint nNewStateID = 0;
 	gint nNewCityID = 0;
 
-	gint nZoomScale = map_get_scale(pMap);
+//	gint nZoomScale = map_get_scale(pMap);
 
 	// Step 2. Set button text and drop-down menus
 
@@ -119,14 +116,14 @@
 		// If we are now too high up to have a country selected, we clear the country label and
 		// hide the state list (of course, the state is 0 too, so 
 		if(nNewCountryID == 0) {
-			gtk_label_set_markup(g_MapInfoWindow.pCountryLabel, "<i>Country</i>");
+			gtk_label_set_markup(g_MapInfoWindow.pCountryLabel, MSG_NO_COUNTRY);
 
 			// hide state list
 			gtk_widget_hide(GTK_WIDGET(g_MapInfoWindow.pStateButton));
 		}
 		else {
 			// XXX: Set new country button text
-			gchar* pszLabel = g_strdup_printf("<b>%s</b>", "United States");
+			gchar* pszLabel = g_strdup_printf(MSG_COUNTRY, "United States");
 			gtk_label_set_markup(g_MapInfoWindow.pCountryLabel, pszLabel);
 			g_free(pszLabel);
 	
@@ -141,7 +138,7 @@
 	//
 	if(nNewStateID != g_MapInfoWindow.nCurrentStateID) {
 		if(nNewStateID == 0) {
-			gtk_label_set_markup(g_MapInfoWindow.pStateLabel, "<i>State</i>");
+			gtk_label_set_markup(g_MapInfoWindow.pStateLabel, MSG_NO_STATE);
 
 			// hide city list
 			gtk_widget_hide(GTK_WIDGET(g_MapInfoWindow.pCityButton));
@@ -162,24 +159,70 @@
 	if(nNewCityID != g_MapInfoWindow.nCurrentCityID) {
 		if(nNewCityID == 0) {
 			// XXX: Set new city button text
-			gtk_label_set_markup(g_MapInfoWindow.pCityLabel, "<i>City</i>");
-		}
-		else {
-			// XXX: Set new city button text
-			gtk_label_set_markup(g_MapInfoWindow.pCityLabel, "<b>City</b>");
+			gtk_label_set_markup(g_MapInfoWindow.pCityLabel, MSG_NO_CITY);
 		}
 		g_MapInfoWindow.nCurrentCityID = nNewCityID;
 	}
 }
 
-static void mapinfowindow_on_city_chosen(GtkWidget* _unused, gint nCityID)
+static void mapinfowindow_load_countries()
 {
-	g_debug("centering on CityID %d", nCityID);
+	// New menu
+	if(g_MapInfoWindow.pCountryMenu) {
+		gtk_widget_destroy(GTK_WIDGET(g_MapInfoWindow.pCountryMenu));
+	}
+	g_MapInfoWindow.pCountryMenu = GTK_MENU(gtk_menu_new());
+	
+	// LOAD AND LOOP
+	{
+		gchar* pszCountryName = "United States";
+		gint nID = 1;
+
+		GtkMenuItem* pNewMenuItem = GTK_MENU_ITEM(gtk_menu_item_new_with_mnemonic(pszCountryName));
+		g_signal_connect(G_OBJECT(pNewMenuItem), "activate", (GCallback)mapinfowindow_on_country_chosen, (gpointer)nID);
+
+		gtk_menu_shell_append(GTK_MENU_SHELL(g_MapInfoWindow.pCountryMenu), GTK_WIDGET(pNewMenuItem));
+	}
+
+	// Install new menu
+	gtk_widget_show_all(GTK_WIDGET(g_MapInfoWindow.pCountryMenu));
+	gtk_menu_tool_button_set_menu(g_MapInfoWindow.pCountryButton, GTK_WIDGET(g_MapInfoWindow.pCountryMenu));
 }
 
-static void mapinfowindow_on_state_chosen(GtkWidget* _unused, gint nStateID)
+static void mapinfowindow_load_states(gint nCountryID)
 {
-	g_debug("centering on nStateID %d", nStateID);
+	db_resultset_t* pResultSet = NULL;
+	db_row_t aRow;
+
+	//
+	// Load up all states for this country
+	//
+	gchar* pszSQL = g_strdup_printf("SELECT State.ID, State.Name FROM State WHERE CountryID=%d ORDER BY Name ASC;", nCountryID);
+	db_query(pszSQL, &pResultSet);
+	g_free(pszSQL);
+	g_return_if_fail(pResultSet != NULL);
+
+	// New menu
+	if(g_MapInfoWindow.pStateMenu) {
+		gtk_widget_destroy(GTK_WIDGET(g_MapInfoWindow.pStateMenu));
+	}
+	g_MapInfoWindow.pStateMenu = GTK_MENU(gtk_menu_new());
+
+	// Fill menu
+	while((aRow = db_fetch_row(pResultSet)) != NULL) {
+		gint nID = atoi(aRow[0]);
+		gchar* pszName = aRow[1];
+
+		// Add new menu item
+		GtkMenuItem* pNewMenuItem = GTK_MENU_ITEM(gtk_menu_item_new_with_mnemonic(pszName));
+		g_signal_connect(G_OBJECT(pNewMenuItem), "activate", (GCallback)mapinfowindow_on_state_chosen, (gpointer)nID);
+		gtk_menu_shell_append(GTK_MENU_SHELL(g_MapInfoWindow.pStateMenu), GTK_WIDGET(pNewMenuItem));
+	}
+	db_free_result(pResultSet);
+
+	// Install new menu
+	gtk_widget_show_all(GTK_WIDGET(g_MapInfoWindow.pStateMenu));
+	gtk_menu_tool_button_set_menu(g_MapInfoWindow.pStateButton, GTK_WIDGET(g_MapInfoWindow.pStateMenu));
 }
 
 static void mapinfowindow_load_cities(gint nStateID)
@@ -193,7 +236,7 @@
 	gchar* pszSQL = g_strdup_printf("SELECT City.ID, City.Name FROM City WHERE StateID=%d ORDER BY Name ASC;", nStateID);
 	db_query(pszSQL, &pResultSet);
 	g_free(pszSQL);
-	if(pResultSet == NULL) return;
+	g_return_if_fail(pResultSet != NULL);
 
 	// New menu
 	if(g_MapInfoWindow.pCityMenu) {
@@ -206,9 +249,9 @@
 		gint nCityID = atoi(aRow[0]);
 		gchar* pszName = aRow[1];
 
+		// Add new menu item
 		GtkMenuItem* pNewMenuItem = GTK_MENU_ITEM(gtk_menu_item_new_with_mnemonic(pszName));
 		g_signal_connect(G_OBJECT(pNewMenuItem), "activate", (GCallback)mapinfowindow_on_city_chosen, (gpointer)nCityID);
-
 		gtk_menu_shell_append(GTK_MENU_SHELL(g_MapInfoWindow.pCityMenu), GTK_WIDGET(pNewMenuItem));
 	}
 	db_free_result(pResultSet);
@@ -218,38 +261,88 @@
 	gtk_menu_tool_button_set_menu(g_MapInfoWindow.pCityButton, GTK_WIDGET(g_MapInfoWindow.pCityMenu));
 }
 
-static void mapinfowindow_load_states(gint nCountryID)
+//
+// Country
+//
+void mapinfowindow_select_country(gint nCountryID, const gchar* pszCountryMarkup)
 {
-	db_resultset_t* pResultSet = NULL;
-	db_row_t aRow;
+	g_debug("recentering on countryID %d", nCountryID);
+	g_MapInfoWindow.nCurrentCountryID = nCountryID;
 
-	//
-	// Load up all states for this country
-	//
-	gchar* pszSQL = g_strdup_printf("SELECT State.ID, State.Name FROM State WHERE CountryID=%d ORDER BY Name ASC;", nCountryID);
-	db_query(pszSQL, &pResultSet);
-	g_free(pszSQL);
-	if(pResultSet == NULL) return;
+	g_debug("clearing selection on state list");
+	gtk_label_set_markup(g_MapInfoWindow.pStateLabel, MSG_NO_STATE);
+	g_MapInfoWindow.nCurrentStateID = 0;
 
-	// New menu
-	if(g_MapInfoWindow.pStateMenu) {
-		gtk_widget_destroy(GTK_WIDGET(g_MapInfoWindow.pStateMenu));
+	// Configure state and city buttons
+	mapinfowindow_load_states(nCountryID);
+	util_gtk_widget_set_visible(GTK_WIDGET(g_MapInfoWindow.pCityButton), FALSE);
+}
+
+static void mapinfowindow_on_country_button_clicked(GtkWidget* _unused, gpointer __unused)
+{
+	// re-zoom to the current country
+	mapinfowindow_select_country(g_MapInfoWindow.nCurrentCountryID, gtk_label_get_label(g_MapInfoWindow.pCountryLabel));
+}
+
+static void mapinfowindow_on_country_chosen(GtkMenuItem* pMenuItem, gint nCountryID)
+{
+	// zoom to selected country
+	gchar* pszName = g_strdup_printf(MSG_COUNTRY, util_gtk_menu_item_get_label_text(pMenuItem));
+	mapinfowindow_select_country(nCountryID, pszName);
+	g_free(pszName);
+}
+
+//
+// State
+//
+void mapinfowindow_select_state(gint nStateID, const gchar* pszStateMarkup)
+{
+	g_debug("recentering on StateID %d", g_MapInfoWindow.nCurrentStateID);
+	g_MapInfoWindow.nCurrentStateID = nStateID;
+	gtk_label_set_markup(g_MapInfoWindow.pStateLabel, pszStateMarkup);
+
+	g_debug("clearing selection on city list");
+	gtk_label_set_markup(g_MapInfoWindow.pCityLabel, MSG_NO_CITY);
+	g_MapInfoWindow.nCurrentCityID = 0;
+
+	if(nStateID != 0) {
+		// Show city button with a new list
+		g_debug("loading cities for nStateID %d", nStateID);
+		mapinfowindow_load_cities(nStateID);
+		util_gtk_widget_set_visible(GTK_WIDGET(g_MapInfoWindow.pCityButton), TRUE);
 	}
-	g_MapInfoWindow.pStateMenu = GTK_MENU(gtk_menu_new());
+}
 
-	// Fill menu
-	while((aRow = db_fetch_row(pResultSet)) != NULL) {
-		gint nID = atoi(aRow[0]);
-		gchar* pszName = aRow[1];
+static void mapinfowindow_on_state_button_clicked(GtkWidget* _unused, gpointer __unused)
+{
+	// Just re-set selected state
+	mapinfowindow_select_state(g_MapInfoWindow.nCurrentStateID, gtk_label_get_label(g_MapInfoWindow.pStateLabel));
+}
 
-		GtkMenuItem* pNewMenuItem = GTK_MENU_ITEM(gtk_menu_item_new_with_mnemonic(pszName));
-		g_signal_connect(G_OBJECT(pNewMenuItem), "activate", (GCallback)mapinfowindow_on_state_chosen, (gpointer)nID);
+static void mapinfowindow_on_state_chosen(GtkMenuItem* pMenuItem, gint nStateID)
+{
+	gchar* pszName = g_strdup_printf(MSG_STATE, util_gtk_menu_item_get_label_text(pMenuItem));
+	mapinfowindow_select_state(nStateID, pszName);
+	g_free(pszName);
+}
 
-		gtk_menu_shell_append(GTK_MENU_SHELL(g_MapInfoWindow.pStateMenu), GTK_WIDGET(pNewMenuItem));
+//
+// City
+//
+static void mapinfowindow_on_city_button_clicked(GtkWidget* _unused, gpointer __unused)
+{
+	if(g_MapInfoWindow.nCurrentCityID != 0) {
+		g_debug("recentering on cityID %d", g_MapInfoWindow.nCurrentCityID);
 	}
-	db_free_result(pResultSet);
+}
 
-	// Install new menu
-	gtk_widget_show_all(GTK_WIDGET(g_MapInfoWindow.pStateMenu));
-	gtk_menu_tool_button_set_menu(g_MapInfoWindow.pStateButton, GTK_WIDGET(g_MapInfoWindow.pStateMenu));
+static void mapinfowindow_on_city_chosen(GtkMenuItem* pMenuItem, gint nCityID)
+{
+	// Set new button text
+	gchar* pszName = g_strdup_printf(MSG_CITY, util_gtk_menu_item_get_label_text(pMenuItem));
+	gtk_label_set_markup(g_MapInfoWindow.pCityLabel, pszName);
+	g_free(pszName);
+
+	g_MapInfoWindow.nCurrentCityID = nCityID;
+	g_debug("centering on CityID %d", nCityID);
 }

Index: search.c
===================================================================
RCS file: /cvs/cairo/roadster/src/search.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- search.c	26 Sep 2005 13:57:13 -0000	1.9
+++ search.c	20 Oct 2005 06:56:22 -0000	1.10
@@ -29,6 +29,7 @@
 #include "search_road.h"
 #include "search_location.h"
 #include "search_city.h"
+#include "search_coordinate.h"
 
 // functions
 
@@ -37,6 +38,7 @@
 	search_road_init();
 	search_location_init();
 	search_city_init();
+	search_coordinate_init();
 }
 
 // functions common to all searches
@@ -114,6 +116,7 @@
 	search_city_execute(pszCleanedSentence);
 	search_location_execute(pszCleanedSentence);
 	search_road_execute(pszCleanedSentence);
+	search_coordinate_execute(pszCleanedSentence);
 	
 	TIMER_END(search, "END SearchAll");
 

Index: search.h
===================================================================
RCS file: /cvs/cairo/roadster/src/search.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- search.h	26 Sep 2005 13:57:14 -0000	1.4
+++ search.h	20 Oct 2005 06:56:22 -0000	1.5
@@ -25,7 +25,8 @@
 #define _SEARCH_H
 
 typedef enum {
-	SEARCH_RESULT_TYPE_COUNTRY = 0,		// in order of importance (for search results)
+	SEARCH_RESULT_TYPE_COORDINATE,	// in order of importance (for search results)
+	SEARCH_RESULT_TYPE_COUNTRY,
 	SEARCH_RESULT_TYPE_STATE,
 	SEARCH_RESULT_TYPE_CITY,
 	SEARCH_RESULT_TYPE_LOCATION,

--- NEW FILE: search_coordinate.c ---
/***************************************************************************
 *            search_coordinate.c
 *
 *  Copyright  2005  Ian McIntosh
 *  ian_mcintosh at linuxadvocate.org
 ****************************************************************************/

/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Library General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include <gtk/gtk.h>
#include <math.h>
#include <stdlib.h>

#include "main.h"
#include "map.h"
#include "util.h"
#include "search_coordinate.h"
#include "glyph.h"
#include "searchwindow.h"		// for defines about glyph size

#define COORDINATE_RESULT_SUGGESTED_ZOOMLEVEL		(37)		// no idea what to use for this :)

#define FORMAT_COORDINATE_RESULT 	("<b>Lat:</b> %10.5f\n<b>Lon:</b> %10.5f")

static void search_coordinate_add_result(const mappoint_t* pPoint);

//
// globals
//
static glyph_t* g_SearchResultTypeCoordinateGlyph = NULL;

//
// Public API
//
void search_coordinate_init()
{
	g_SearchResultTypeCoordinateGlyph = glyph_load_at_size("search-result-type-coordinate", SEARCHWINDOW_SEARCH_RESULT_GLYPH_WIDTH, SEARCHWINDOW_SEARCH_RESULT_GLYPH_HEIGHT);
}

void search_coordinate_execute(const gchar* pszSentence)
{
	mappoint_t ptResult = {0};

	// Goals:
	// Make sure never to match something that could likely be a road or POI search!
	// That said, be _as flexible as possible_ with input formats.

	// Here are some examples from the web:
	//  32°	57' N 	 85°	 57' W
	//  37 degrees N 123 degrees W
	//  40 02 40
	//  43° 28' 07" N
	//  49:30.0-123:30.0
	//  49.5000-123.5000
	//  h&lat=32.11611&lon=-110.94109&alt=

	// And our own:
	//  Lat: 1.0, Lon: -1.0

	// And of course, don't match things out of valid range (map.h has constants: MIN_LATITUDE, MAX_LATITUDE, MIN_LONGITUDE, MAX_LONGITUDE)

	// Call only if we have a likely match!
	//search_coordinate_add_result(&ptResult);
}

//
// Private
//
static void search_coordinate_add_result(const mappoint_t* pPoint)
{
	gchar* pszBuffer = g_strdup_printf(FORMAT_COORDINATE_RESULT, pPoint->fLatitude, pPoint->fLongitude);
	searchwindow_add_result(SEARCH_RESULT_TYPE_COORDINATE, pszBuffer, g_SearchResultTypeCoordinateGlyph, pPoint, COORDINATE_RESULT_SUGGESTED_ZOOMLEVEL);
	g_free(pszBuffer);
}

--- NEW FILE: search_coordinate.h ---
/***************************************************************************
 *            search_coordinate.h
 *
 *  Copyright  2005  Ian McIntosh
 *  ian_mcintosh at linuxadvocate.org
 ****************************************************************************/

/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Library General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
 
#ifndef _SEARCH_COORDINATE_H
#define _SEARCH_COORDINATE_H

G_BEGIN_DECLS

void search_coordinate_init();
void search_coordinate_execute(const gchar* pszSentence);

G_END_DECLS

#endif /* _SEARCH_COORDINATE_H */

Index: search_road.c
===================================================================
RCS file: /cvs/cairo/roadster/src/search_road.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- search_road.c	5 Oct 2005 06:09:36 -0000	1.29
+++ search_road.c	20 Oct 2005 06:56:22 -0000	1.30
@@ -52,7 +52,6 @@
 #define SEARCH_RESULT_COUNT_LIMIT		(400)		// how many rows to get from DB
 #define MAX_QUERY 						(4000)
 
-
 static glyph_t* g_SearchResultTypeRoadGlyph = NULL;
 
 void search_road_init()

Index: searchwindow.c
===================================================================
RCS file: /cvs/cairo/roadster/src/searchwindow.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- searchwindow.c	10 Oct 2005 07:07:36 -0000	1.27
+++ searchwindow.c	20 Oct 2005 06:56:22 -0000	1.28
@@ -228,7 +228,7 @@
 }
 
 // add a result row to the list
-void searchwindow_add_result(ESearchResultType eResultType, const gchar* pszText, glyph_t* pGlyph, mappoint_t* pPoint, gint nZoomLevel)
+void searchwindow_add_result(ESearchResultType eResultType, const gchar* pszText, glyph_t* pGlyph, const mappoint_t* pPoint, gint nZoomLevel)
 {
 	GtkTreeIter iter;
 

Index: searchwindow.h
===================================================================
RCS file: /cvs/cairo/roadster/src/searchwindow.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- searchwindow.h	26 Sep 2005 13:57:14 -0000	1.6
+++ searchwindow.h	20 Oct 2005 06:56:22 -0000	1.7
@@ -38,7 +38,7 @@
 
 void searchwindow_init(GladeXML* pGladeXML);
 
-void searchwindow_add_result(ESearchResultType eResultType, const gchar* pszText, glyph_t* pGlyph, mappoint_t* pPoint, gint nZoomLevel);
+void searchwindow_add_result(ESearchResultType eResultType, const gchar* pszText, glyph_t* pGlyph, const mappoint_t* pPoint, gint nZoomLevel);
 
 void searchwindow_clear_results(void);
 

Index: util.c
===================================================================
RCS file: /cvs/cairo/roadster/src/util.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- util.c	18 Oct 2005 03:05:25 -0000	1.18
+++ util.c	20 Oct 2005 06:56:22 -0000	1.19
@@ -242,6 +242,12 @@
 	}
 }
 
+const gchar* util_gtk_menu_item_get_label_text(GtkMenuItem* pMenuItem)
+{
+	GtkLabel* pLabel = GTK_LABEL(GTK_BIN(pMenuItem)->child);
+	return gtk_label_get_text(pLabel);
+}
+
 #if(!GLIB_CHECK_VERSION(2,6,0))
 
 // This one 

Index: util.h
===================================================================
RCS file: /cvs/cairo/roadster/src/util.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- util.h	18 Oct 2005 03:05:25 -0000	1.18
+++ util.h	20 Oct 2005 06:56:22 -0000	1.19
@@ -66,6 +66,7 @@
 gboolean util_gtk_window_set_fullscreen(GtkWindow* pWindow, gboolean bFullscreen);
 
 gboolean util_gtk_range_instant_set_on_value_changing_callback(GtkRange *range, GtkScrollType scroll, gdouble value, gpointer user_data);
+const gchar* util_gtk_menu_item_get_label_text(GtkMenuItem* pMenuItem);
 
 // if glib < 2.6
 #if(!GLIB_CHECK_VERSION(2,6,0))



More information about the cairo-commit mailing list