From 1a2cc4c12750bb1b46c0251356abc91dd969d7fe Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Wed, 19 Dec 2007 13:48:35 +0200 Subject: [PATCH] Move goto lat/lon dialog from cb.c to map.c --- src/cb.c | 77 ++-------------------------------------------------- src/map.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 75 deletions(-) diff --git a/src/cb.c b/src/cb.c index d538ec3..e988bb3 100644 --- a/src/cb.c +++ b/src/cb.c @@ -281,79 +281,7 @@ return TRUE; gboolean menu_cb_goto_latlon(GtkAction * action) { -GtkWidget *dialog; -GtkWidget *table; -GtkWidget *label; -GtkWidget *txt_lat; -GtkWidget *txt_lon; - -dialog = gtk_dialog_new_with_buttons(_("Go to Lat/Lon"), - GTK_WINDOW(_window), - GTK_DIALOG_MODAL, GTK_STOCK_OK, - GTK_RESPONSE_ACCEPT, - GTK_STOCK_CANCEL, - GTK_RESPONSE_REJECT, NULL); - -gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), table = gtk_table_new(2, 3, FALSE), TRUE, TRUE, 0); - -gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(_("Latitude")),0, 1, 0, 1, GTK_FILL, 0, 2, 4); -gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); - -gtk_table_attach(GTK_TABLE(table), txt_lat = gtk_entry_new(), 1, 2, 0, 1, GTK_FILL, 0, 2, 4); -gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f); - -gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(_("Longitude")), 0, 1, 1, 2, GTK_FILL, 0, 2, 4); -gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); - -gtk_table_attach(GTK_TABLE(table), txt_lon = gtk_entry_new(), 1, 2, 1, 2, GTK_FILL, 0, 2, 4); -gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f); - -#if defined (WITH_DEVICE_770) && !defined(WITH_HILDON_NEW) -g_object_set(G_OBJECT(txt_lat), HILDON_INPUT_MODE_HINT, HILDON_INPUT_MODE_HINT_NUMERICSPECIAL, NULL); -g_object_set(G_OBJECT(txt_lon), HILDON_INPUT_MODE_HINT, HILDON_INPUT_MODE_HINT_NUMERICSPECIAL, NULL); -#endif - -/* Initialize with the current center position. */ -{ - gchar buffer[32]; - gdouble lat, lon; - unit2latlon(_center.unitx, _center.unity, lat, lon); - snprintf(buffer, sizeof(buffer), "%.06f", lat); - gtk_label_set_text(GTK_LABEL(txt_lat), buffer); - snprintf(buffer, sizeof(buffer), "%.06f", lon); - gtk_label_set_text(GTK_LABEL(txt_lon), buffer); -} - -gtk_widget_show_all(dialog); - -while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) { - const gchar *text; - gchar *error_check; - gdouble lat, lon; - guint unitx, unity; - - text = gtk_entry_get_text(GTK_ENTRY(txt_lat)); - lat = strtof(text, &error_check); - if (text == error_check || lat < -90.f || lat > 90.f) { - popup_error(dialog, _("Invalid Latitude")); - continue; - } - - text = gtk_entry_get_text(GTK_ENTRY(txt_lon)); - lon = strtof(text, &error_check); - if (text == error_check || lon < -180.f || lon > 180.f) { - popup_error(dialog, _("Invalid Longitude")); - continue; - } - - latlon2unit(lat, lon, unitx, unity); - if (_center_mode > 0) - set_action_activate("autocenter_none", TRUE); - - map_center_unit(unitx, unity); - break; -} -gtk_widget_destroy(dialog); +map_dialog_goto_latlon(); return TRUE; } @@ -660,8 +588,7 @@ switch (event->keyval) { case CUSTOM_ACTION_ZOOM_IN: case CUSTOM_ACTION_ZOOM_OUT: if (!_key_zoom_timeout_sid) { - _key_zoom_new = _zoom + (_action[custom_key] == CUSTOM_ACTION_ZOOM_IN - ? -_curr_repo->view_zoom_steps : _curr_repo->view_zoom_steps); + _key_zoom_new = _zoom + (_action[custom_key] == CUSTOM_ACTION_ZOOM_IN ? -_curr_repo->view_zoom_steps : _curr_repo->view_zoom_steps); /* Remember, _key_zoom_new is unsigned. */ if (_key_zoom_new < MAX_ZOOM) { _key_zoom_timeout_sid = g_timeout_add(400, map_key_zoom_timeout, NULL); diff --git a/src/map.c b/src/map.c index fa1ed9e..6c555f0 100644 --- a/src/map.c +++ b/src/map.c @@ -1285,3 +1285,83 @@ break; /* Return FALSE to avoid context menu (if it hasn't popped up already). */ return FALSE; } + +gboolean +map_dialog_goto_latlon(void) +{ +GtkWidget *dialog; +GtkWidget *table; +GtkWidget *label; +GtkWidget *txt_lat; +GtkWidget *txt_lon; + +dialog = gtk_dialog_new_with_buttons(_("Go to Lat/Lon"), + GTK_WINDOW(_window), + GTK_DIALOG_MODAL, GTK_STOCK_OK, + GTK_RESPONSE_ACCEPT, + GTK_STOCK_CANCEL, + GTK_RESPONSE_REJECT, NULL); + +gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), table = gtk_table_new(2, 3, FALSE), TRUE, TRUE, 0); + +gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(_("Latitude")),0, 1, 0, 1, GTK_FILL, 0, 2, 4); +gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); + +gtk_table_attach(GTK_TABLE(table), txt_lat = gtk_entry_new(), 1, 2, 0, 1, GTK_FILL, 0, 2, 4); +gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f); + +gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(_("Longitude")), 0, 1, 1, 2, GTK_FILL, 0, 2, 4); +gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); + +gtk_table_attach(GTK_TABLE(table), txt_lon = gtk_entry_new(), 1, 2, 1, 2, GTK_FILL, 0, 2, 4); +gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f); + +#if defined (WITH_DEVICE_770) && !defined(WITH_HILDON_NEW) +g_object_set(G_OBJECT(txt_lat), HILDON_INPUT_MODE_HINT, HILDON_INPUT_MODE_HINT_NUMERICSPECIAL, NULL); +g_object_set(G_OBJECT(txt_lon), HILDON_INPUT_MODE_HINT, HILDON_INPUT_MODE_HINT_NUMERICSPECIAL, NULL); +#endif + +/* Initialize with the current center position. */ +{ + gchar buffer[32]; + gdouble lat, lon; + unit2latlon(_center.unitx, _center.unity, lat, lon); + snprintf(buffer, sizeof(buffer), "%.06f", lat); + gtk_label_set_text(GTK_LABEL(txt_lat), buffer); + snprintf(buffer, sizeof(buffer), "%.06f", lon); + gtk_label_set_text(GTK_LABEL(txt_lon), buffer); +} + +gtk_widget_show_all(dialog); + +while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) { + const gchar *text; + gchar *error_check; + gdouble lat, lon; + guint unitx, unity; + + text = gtk_entry_get_text(GTK_ENTRY(txt_lat)); + lat = strtof(text, &error_check); + if (text == error_check || lat < -90.f || lat > 90.f) { + popup_error(dialog, _("Invalid Latitude")); + continue; + } + + text = gtk_entry_get_text(GTK_ENTRY(txt_lon)); + lon = strtof(text, &error_check); + if (text == error_check || lon < -180.f || lon > 180.f) { + popup_error(dialog, _("Invalid Longitude")); + continue; + } + + latlon2unit(lat, lon, unitx, unity); + if (_center_mode > 0) + set_action_activate("autocenter_none", TRUE); + + map_center_unit(unitx, unity); + break; +} +gtk_widget_destroy(dialog); +return TRUE; +} + -- 2.39.5