--- trunk/src/main.c 2009/07/16 18:43:30 29 +++ trunk/src/main.c 2009/07/24 19:24:42 30 @@ -1525,106 +1525,129 @@ } #ifdef USE_STACKABLE_WINDOW -static GtkWidget *export_menu_create(appdata_t *appdata) { - GtkWidget *button; - HildonAppMenu *menu = HILDON_APP_MENU(hildon_app_menu_new()); - - button = hildon_button_new_with_text( - HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH, - HILDON_BUTTON_ARRANGEMENT_VERTICAL, - _("Export to Maemo Mapper"), - _("Save a Maemo Mapper POI file")); - g_signal_connect_after(button, "clicked", - G_CALLBACK(cb_menu_export_mmpoi), appdata); - hildon_app_menu_append(menu, GTK_BUTTON(button)); +typedef struct { + char *label, *desc; + GtkSignalFunc activate_cb; +} menu_entry_t; - button = hildon_button_new_with_text( - HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH, - HILDON_BUTTON_ARRANGEMENT_VERTICAL, - _("Export Field Notes"), - _("Save a Garmin Field Notes file")); - g_signal_connect_after(button, "clicked", - G_CALLBACK(cb_menu_export_log), appdata); - hildon_app_menu_append(menu, GTK_BUTTON(button)); +typedef struct { + const char *title; + const menu_entry_t *menu; + int len; +} submenu_t; + +#define COLUMNS 1 + +void on_submenu_entry_clicked(GtkButton *button, GtkWidget *menu) { + + /* force closing of submenu dialog */ + gtk_dialog_response(GTK_DIALOG(menu), GTK_RESPONSE_NONE); + gtk_widget_hide(menu); + + /* let gtk clean up */ + while(gtk_events_pending()) + gtk_main_iteration(); +} + +static GtkWidget *app_submenu_create(appdata_t *appdata, + const submenu_t *submenu) { + + /* create a oridinary dialog box */ + GtkWidget *dialog = gtk_dialog_new(); + gtk_window_set_title(GTK_WINDOW(dialog), _(submenu->title)); + gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); + gtk_window_set_transient_for(GTK_WINDOW(dialog), + GTK_WINDOW(appdata->window)); + gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); + + GtkWidget *table = gtk_table_new(submenu->len/COLUMNS, COLUMNS, TRUE); + int x = 0, y = 0; + + const menu_entry_t *menu_entries = submenu->menu; + while(menu_entries->label) { + GtkWidget *button = NULL; - button = hildon_button_new_with_text( + button = hildon_button_new_with_text( HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH, HILDON_BUTTON_ARRANGEMENT_VERTICAL, - _("Export Garmin GPX"), - _("Save modified waypoints in GPX file")); - g_signal_connect_after(button, "clicked", - G_CALLBACK(cb_menu_export_garmin), appdata); - hildon_app_menu_append(menu, GTK_BUTTON(button)); + _(menu_entries->label), _(menu_entries->desc)); - gtk_widget_show_all(GTK_WIDGET(menu)); + g_signal_connect(button, "clicked", + G_CALLBACK(on_submenu_entry_clicked), dialog); - return GTK_WIDGET(menu); -} + g_signal_connect(button, "clicked", + menu_entries->activate_cb, appdata); -/* the export submenu */ -void on_export_clicked(GtkButton *button, appdata_t *appdata) { - if(!appdata->export_menu) - appdata->export_menu = export_menu_create(appdata); + gtk_table_attach_defaults(GTK_TABLE(table), button, x, x+1, y, y+1); + + x++; + if(x == COLUMNS) { x = 0; y++; } - /* draw a popup menu */ - hildon_app_menu_popup(HILDON_APP_MENU(appdata->export_menu), - GTK_WINDOW(hildon_window_stack_peek( - hildon_window_stack_get_default()))); -} + menu_entries++; + } -static GtkWidget *tools_menu_create(appdata_t *appdata) { - GtkWidget *button; - HildonAppMenu *menu = HILDON_APP_MENU(hildon_app_menu_new()); + gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), table); - /* the following doesn't have an effect */ - // gtk_window_set_title(GTK_WINDOW(menu), "Tools"); + return dialog; +} - button = hildon_button_new_with_text( - HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH, - HILDON_BUTTON_ARRANGEMENT_VERTICAL, - _("Geomath"), - _("Geocoordinate calculation")); - g_signal_connect_after(button, "clicked", - G_CALLBACK(cb_menu_geomath), appdata); - hildon_app_menu_append(menu, GTK_BUTTON(button)); +/* popup the dialog shaped submenu */ +static void submenu_popup(GtkWidget *menu) { + gtk_widget_show_all(menu); + gtk_dialog_run(GTK_DIALOG(menu)); + gtk_widget_hide(menu); +} +static void submenu_cleanup(GtkWidget *menu) { + gtk_widget_destroy(menu); +} - button = hildon_button_new_with_text( - HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH, - HILDON_BUTTON_ARRANGEMENT_VERTICAL, - _("Geotext"), - _("Text analysis")); - g_signal_connect_after(button, "clicked", - G_CALLBACK(cb_menu_geotext), appdata); - hildon_app_menu_append(menu, GTK_BUTTON(button)); - +static const menu_entry_t submenu_export_entries[] = { + { "Export to Maemo Mapper" , "Save a Maemo Mapper POI file", + G_CALLBACK(cb_menu_export_mmpoi) }, + { "Export Field Notes", "Save a Garmin Field Notes file", + G_CALLBACK(cb_menu_export_log) }, + { "Export Garmin GPX", "Save modified waypoints in GPX file", + G_CALLBACK(cb_menu_export_garmin) }, + { NULL, NULL, NULL } +}; - button = hildon_button_new_with_text( - HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH, - HILDON_BUTTON_ARRANGEMENT_VERTICAL, - _("Precise Position"), - _("Calculate a precise GPS position")); - g_signal_connect_after(button, "clicked", - G_CALLBACK(cb_menu_precpos), appdata); - hildon_app_menu_append(menu, GTK_BUTTON(button)); +static const submenu_t submenu_export = { + "Export", submenu_export_entries, + sizeof(submenu_export_entries)/sizeof(menu_entry_t)-1 +}; - gtk_widget_show_all(GTK_WIDGET(menu)); +/* the export submenu */ +void on_export_clicked(GtkButton *button, appdata_t *appdata) { + if(!appdata->export_menu) + appdata->export_menu = app_submenu_create(appdata, &submenu_export); - return GTK_WIDGET(menu); + submenu_popup(appdata->export_menu); } +static const menu_entry_t submenu_tools_entries[] = { + { "Geomath", "Geocoordinate calculation", + G_CALLBACK(cb_menu_geomath) }, + { "Geotext", "Text analysis", + G_CALLBACK(cb_menu_geotext) }, + { "Precise Position", "Calculate a precise GPS position", + G_CALLBACK(cb_menu_precpos) }, + { NULL, NULL, NULL } +}; + +static const submenu_t submenu_tools = { + "Tools", submenu_tools_entries, + sizeof(submenu_tools_entries)/sizeof(menu_entry_t)-1 +}; + /* the tools submenu */ void on_tools_clicked(GtkButton *button, appdata_t *appdata) { if(!appdata->tools_menu) - appdata->tools_menu = tools_menu_create(appdata); + appdata->tools_menu = app_submenu_create(appdata, &submenu_tools); - /* draw a popup menu */ - hildon_app_menu_popup(HILDON_APP_MENU(appdata->tools_menu), - GTK_WINDOW(hildon_window_stack_peek( - hildon_window_stack_get_default()))); + submenu_popup(appdata->tools_menu); } - HildonAppMenu *menu_create(appdata_t *appdata, int mode) { GtkWidget *button; HildonAppMenu *menu = HILDON_APP_MENU(hildon_app_menu_new()); @@ -1845,6 +1868,11 @@ if(appdata->image_path) free(appdata->image_path); if(appdata->search_str) free(appdata->search_str); +#ifdef USE_STACKABLE_WINDOW + if(appdata->export_menu) submenu_cleanup(appdata->export_menu); + if(appdata->tools_menu) submenu_cleanup(appdata->tools_menu); +#endif + gnome_vfs_shutdown(); icons_free(); gps_release(appdata); @@ -2216,7 +2244,6 @@ appdata.vbox = gtk_vbox_new(FALSE, 2); gtk_container_add(GTK_CONTAINER(appdata.window), appdata.vbox); - #ifndef USE_STACKABLE_WINDOW menu_create(&appdata); #else