From ceefe542595b31e1ffdbf0b57030670e51723d69 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Fri, 23 May 2008 16:53:06 +0300 Subject: [PATCH] WidgetTester: Use a normal Window. Add code to test upcoming threading --- libs/libgtkmap/map-widget-test.c | 40 +++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/libs/libgtkmap/map-widget-test.c b/libs/libgtkmap/map-widget-test.c index 5be15f8..6eb241f 100644 --- a/libs/libgtkmap/map-widget-test.c +++ b/libs/libgtkmap/map-widget-test.c @@ -6,6 +6,8 @@ #define TESTREPO "/home/milang/MyDocs/.documents/Maps/OpenStreet" +#define WITH_THREADS 1 + GtkWidget *map; static gboolean @@ -62,27 +64,37 @@ return TRUE; int main (int argc, char **args) { -GtkDialog *dialog; +GtkWidget *window, *wvbox; GtkWidget *hbox, *zoomer, *btn_left, *btn_right, *btn_up, *btn_down, *vbox; GtkWidget *rotate; RepoData *rd; -gtk_init (&argc, &args); +#if WITH_THREADS +if (!g_thread_supported ()) { + g_thread_init(NULL); +} +gdk_threads_init(); +gdk_threads_enter(); +#endif + +gtk_init(&argc, &args); + +window=gtk_window_new(GTK_WINDOW_TOPLEVEL); +gtk_window_set_title(GTK_WINDOW(window), "MapWidget Test"); +gtk_window_resize(GTK_WINDOW(window), 800, 600); +wvbox=gtk_vbox_new(FALSE, 3); +gtk_container_add(GTK_CONTAINER(window), wvbox); rd=map_tile_repo_new(); rd->view_zoom_steps=1; rd->cache_dir=TESTREPO; -dialog=GTK_DIALOG(gtk_dialog_new ()); -gtk_window_set_title(GTK_WINDOW(dialog), "Map test"); -gtk_window_resize(GTK_WINDOW(dialog), 800, 600); -gtk_dialog_add_button (dialog, "Close", GTK_RESPONSE_CLOSE); - hbox=gtk_hbox_new(FALSE, 3); vbox=gtk_vbox_new(FALSE, 3); map=gtk_map_new(); gtk_map_set_tile_repository(map, rd); + gtk_box_pack_start(GTK_BOX(hbox), map, TRUE, TRUE, 0); zoomer=gtk_vscale_new_with_range(0,17,1); @@ -101,8 +113,8 @@ gtk_box_pack_start(GTK_BOX(vbox), btn_up, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), btn_down, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); -gtk_box_pack_start(GTK_BOX(dialog->vbox), hbox, TRUE, TRUE, 0); -gtk_box_pack_start(GTK_BOX(dialog->vbox), rotate, FALSE, FALSE, 0); +gtk_box_pack_start(GTK_BOX(wvbox), hbox, TRUE, TRUE, 0); +gtk_box_pack_start(GTK_BOX(wvbox), rotate, FALSE, FALSE, 0); g_signal_connect(G_OBJECT(zoomer), "value-changed", G_CALLBACK(map_zoom), NULL); g_signal_connect(G_OBJECT(rotate), "value-changed", G_CALLBACK(map_rotate), NULL); @@ -113,12 +125,18 @@ g_signal_connect(G_OBJECT(btn_down), "clicked", G_CALLBACK(map_pan_down), NULL); g_signal_connect(G_OBJECT(btn_left), "clicked", G_CALLBACK(map_pan_left), NULL); g_signal_connect(G_OBJECT(btn_right), "clicked", G_CALLBACK(map_pan_right), NULL); -gtk_widget_show_all(GTK_WIDGET(dialog)); +g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL); + +gtk_widget_show_all(GTK_WIDGET(window)); gtk_map_set_center_latlon(map, 60.45, 22.25); gtk_map_set_zoom(map, 8); -gtk_dialog_run(dialog); +gtk_main(); + +#ifdef WITH_THREADS +gdk_threads_leave(); +#endif return 0; } -- 2.39.5