From 3529ead319289f4effe798c9bee0da3f48d5c5b5 Mon Sep 17 00:00:00 2001 From: Steve Fryatt Date: Sun, 24 Oct 2010 23:17:21 +0000 Subject: Restore toolbar menus in RO treeview windows. svn path=/trunk/netsurf/; revision=10908 --- riscos/cookies.c | 39 +++++++++++++++++---------------------- riscos/cookies.h | 8 ++++++++ riscos/global_history.c | 47 ++++++++++++++++++++--------------------------- riscos/global_history.h | 8 ++++++++ riscos/gui.c | 13 +++++++------ riscos/hotlist.c | 47 +++++++++++++++++++++-------------------------- riscos/hotlist.h | 7 +++++++ riscos/menus.c | 18 +++++++++++++----- riscos/menus.h | 2 +- riscos/theme.c | 15 +++++++++++++++ riscos/wimp_event.c | 3 ++- riscos/window.c | 8 ++++---- 12 files changed, 123 insertions(+), 92 deletions(-) diff --git a/riscos/cookies.c b/riscos/cookies.c index d73e8b5fe..51b1f5f25 100644 --- a/riscos/cookies.c +++ b/riscos/cookies.c @@ -45,12 +45,6 @@ #include "utils/url.h" #include "utils/utils.h" -static void ro_gui_cookies_menu_prepare(wimp_w window, wimp_menu *menu); -static bool ro_gui_cookies_menu_select(wimp_w window, wimp_menu *menu, - wimp_selection *selection, menu_action action); -static void ro_gui_cookies_menu_warning(wimp_w window, wimp_menu *menu, - wimp_selection *selection, menu_action action); - /* The RISC OS cookie window, toolbar and treeview data. */ static struct ro_cookies_window { @@ -160,6 +154,9 @@ void ro_gui_cookies_open(void) bool ro_gui_cookies_toolbar_click(wimp_pointer *pointer) { + if (pointer->buttons == wimp_CLICK_MENU) + return ro_gui_wimp_event_process_window_menu_click(pointer); + if (cookies_window.toolbar->editor != NULL) { ro_gui_theme_toolbar_editor_click(cookies_window.toolbar, pointer); @@ -193,13 +190,6 @@ bool ro_gui_cookies_toolbar_click(wimp_pointer *pointer) break; } - /* \todo -- We assume that the owning module will have attached a window menu - * to our parent window. If it hasn't, this call will quietly fail. - */ - - if (pointer->buttons == wimp_CLICK_MENU) - return ro_gui_wimp_event_process_window_menu_click(pointer); - return false; } @@ -214,24 +204,29 @@ void ro_gui_cookies_menu_prepare(wimp_w window, wimp_menu *menu) { bool selection; - selection = ro_treeview_has_selection(cookies_window.tv); + if (menu != cookies_window.menu && menu != tree_toolbar_menu) + return; - ro_gui_menu_set_entry_shaded(cookies_window.menu, TREE_SELECTION, - !selection); - ro_gui_menu_set_entry_shaded(cookies_window.menu, TREE_CLEAR_SELECTION, - !selection); + if (menu == cookies_window.menu) { + selection = ro_treeview_has_selection(cookies_window.tv); + + ro_gui_menu_set_entry_shaded(cookies_window.menu, TREE_SELECTION, + !selection); + ro_gui_menu_set_entry_shaded(cookies_window.menu, TREE_CLEAR_SELECTION, + !selection); + } - ro_gui_menu_set_entry_shaded(cookies_window.menu, TOOLBAR_BUTTONS, + ro_gui_menu_set_entry_shaded(menu, TOOLBAR_BUTTONS, (cookies_window.toolbar == NULL || cookies_window.toolbar->editor)); - ro_gui_menu_set_entry_ticked(cookies_window.menu, TOOLBAR_BUTTONS, + ro_gui_menu_set_entry_ticked(menu, TOOLBAR_BUTTONS, (cookies_window.toolbar != NULL && (cookies_window.toolbar->display_buttons || (cookies_window.toolbar->editor)))); - ro_gui_menu_set_entry_shaded(cookies_window.menu, TOOLBAR_EDIT, + ro_gui_menu_set_entry_shaded(menu, TOOLBAR_EDIT, cookies_window.toolbar == NULL); - ro_gui_menu_set_entry_ticked(cookies_window.menu, TOOLBAR_EDIT, + ro_gui_menu_set_entry_ticked(menu, TOOLBAR_EDIT, (cookies_window.toolbar != NULL && cookies_window.toolbar->editor)); } diff --git a/riscos/cookies.h b/riscos/cookies.h index 3ab1a3bad..8f46147c4 100644 --- a/riscos/cookies.h +++ b/riscos/cookies.h @@ -24,12 +24,20 @@ #ifndef _NETSURF_RISCOS_COOKIES_H_ #define _NETSURF_RISCOS_COOKIES_H_ +#include "riscos/menus.h" + void ro_gui_cookies_preinitialise(void); void ro_gui_cookies_postinitialise(void); bool ro_gui_cookies_check_window(wimp_w window); bool ro_gui_cookies_check_menu(wimp_menu *menu); bool ro_gui_cookies_toolbar_click(wimp_pointer *pointer); +void ro_gui_cookies_menu_prepare(wimp_w window, wimp_menu *menu); +bool ro_gui_cookies_menu_select(wimp_w window, wimp_menu *menu, + wimp_selection *selection, menu_action action); +void ro_gui_cookies_menu_warning(wimp_w window, wimp_menu *menu, + wimp_selection *selection, menu_action action); + void ro_gui_cookies_open(void); void ro_gui_cookies_update_theme(bool full_update); diff --git a/riscos/global_history.c b/riscos/global_history.c index 4b2352289..2f4f8a1b5 100644 --- a/riscos/global_history.c +++ b/riscos/global_history.c @@ -47,12 +47,6 @@ #include "utils/url.h" #include "utils/utils.h" -static void ro_gui_global_history_menu_prepare(wimp_w window, wimp_menu *menu); -static bool ro_gui_global_history_menu_select(wimp_w window, wimp_menu *menu, - wimp_selection *selection, menu_action action); -static void ro_gui_global_history_menu_warning(wimp_w window, wimp_menu *menu, - wimp_selection *selection, menu_action action); - /* The RISC OS global history window, toolbar and treeview data */ static struct ro_global_history_window { @@ -167,6 +161,9 @@ void ro_gui_global_history_open(void) bool ro_gui_global_history_toolbar_click(wimp_pointer *pointer) { + if (pointer->buttons == wimp_CLICK_MENU) + return ro_gui_wimp_event_process_window_menu_click(pointer); + if (global_history_window.toolbar->editor != NULL) { ro_gui_theme_toolbar_editor_click(global_history_window.toolbar, pointer); @@ -206,13 +203,6 @@ bool ro_gui_global_history_toolbar_click(wimp_pointer *pointer) break; } - /* \todo -- We assume that the owning module will have attached a window menu - * to our parent window. If it hasn't, this call will quietly fail. - */ - - if (pointer->buttons == wimp_CLICK_MENU) - return ro_gui_wimp_event_process_window_menu_click(pointer); - return true; } @@ -228,31 +218,34 @@ void ro_gui_global_history_menu_prepare(wimp_w window, wimp_menu *menu) { bool selection; - selection = ro_treeview_has_selection(global_history_window.tv); + if (menu != global_history_window.menu && menu != tree_toolbar_menu) + return; + + if (menu == global_history_window.menu) { + selection = ro_treeview_has_selection(global_history_window.tv); - ro_gui_menu_set_entry_shaded(global_history_window.menu, - TREE_SELECTION, !selection); - ro_gui_menu_set_entry_shaded(global_history_window.menu, - TREE_CLEAR_SELECTION, !selection); + ro_gui_menu_set_entry_shaded(global_history_window.menu, + TREE_SELECTION, !selection); + ro_gui_menu_set_entry_shaded(global_history_window.menu, + TREE_CLEAR_SELECTION, !selection); - ro_gui_menu_set_entry_shaded(global_history_window.menu, - TOOLBAR_BUTTONS, + ro_gui_save_prepare(GUI_SAVE_HISTORY_EXPORT_HTML, + NULL, NULL, NULL, NULL); + } + + ro_gui_menu_set_entry_shaded(menu, TOOLBAR_BUTTONS, (global_history_window.toolbar == NULL || global_history_window.toolbar->editor)); - ro_gui_menu_set_entry_ticked(global_history_window.menu, - TOOLBAR_BUTTONS, + ro_gui_menu_set_entry_ticked(menu, TOOLBAR_BUTTONS, (global_history_window.toolbar != NULL && (global_history_window.toolbar->display_buttons || (global_history_window.toolbar->editor)))); - ro_gui_menu_set_entry_shaded(global_history_window.menu, TOOLBAR_EDIT, + ro_gui_menu_set_entry_shaded(menu, TOOLBAR_EDIT, global_history_window.toolbar == NULL); - ro_gui_menu_set_entry_ticked(global_history_window.menu, TOOLBAR_EDIT, + ro_gui_menu_set_entry_ticked(menu, TOOLBAR_EDIT, (global_history_window.toolbar != NULL && global_history_window.toolbar->editor)); - - ro_gui_save_prepare(GUI_SAVE_HISTORY_EXPORT_HTML, - NULL, NULL, NULL, NULL); } /** diff --git a/riscos/global_history.h b/riscos/global_history.h index 7618aa438..ff06d574b 100644 --- a/riscos/global_history.h +++ b/riscos/global_history.h @@ -24,6 +24,8 @@ #ifndef _NETSURF_RISCOS_GLOBALHISTORY_H_ #define _NETSURF_RISCOS_GLOBALHISTORY_H_ +#include "riscos/menus.h" + void ro_gui_global_history_preinitialise(void); void ro_gui_global_history_postinitialise(void); void ro_gui_global_history_open(void); @@ -33,5 +35,11 @@ bool ro_gui_global_history_check_window(wimp_w window); bool ro_gui_global_history_check_menu(wimp_menu *menu); bool ro_gui_global_history_toolbar_click(wimp_pointer *pointer); +void ro_gui_global_history_menu_prepare(wimp_w window, wimp_menu *menu); +bool ro_gui_global_history_menu_select(wimp_w window, wimp_menu *menu, + wimp_selection *selection, menu_action action); +void ro_gui_global_history_menu_warning(wimp_w window, wimp_menu *menu, + wimp_selection *selection, menu_action action); + #endif diff --git a/riscos/gui.c b/riscos/gui.c index 6968bb04f..1b5bd3d8d 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -987,9 +987,9 @@ void gui_poll(bool active) gui_last_poll = clock(); ro_gui_handle_event(event, &block); - /* Only run scheduled callbacks on a null poll - * We cannot do this in the null event handler, as that may be called - * from gui_multitask(). Scheduled callbacks must only be run from the + /* Only run scheduled callbacks on a null poll + * We cannot do this in the null event handler, as that may be called + * from gui_multitask(). Scheduled callbacks must only be run from the * top-level. */ if (event == wimp_NULL_REASON_CODE) @@ -1248,7 +1248,8 @@ bool ro_gui_icon_bar_click(wimp_pointer *pointer) if (pointer->buttons == wimp_CLICK_MENU) { ro_gui_menu_create(iconbar_menu, pointer->pos.x, - 96 + iconbar_menu_height, wimp_ICON_BAR); + 96 + iconbar_menu_height, wimp_ICON_BAR, + true); } else if (pointer->buttons == wimp_CLICK_SELECT) { if (option_homepage_url && option_homepage_url[0]) { @@ -2070,7 +2071,7 @@ char *path_to_url(const char *path) /* create a unix path from teh cananocal risc os one */ unix_path = __unixify(canonical_path, __RISCOSIFY_NO_REVERSE_SUFFIX, NULL, 0, 0); - + if (unix_path == NULL) { LOG(("__unixify failed: %s", canonical_path)); free(canonical_path); @@ -2092,7 +2093,7 @@ char *path_to_url(const char *path) } else { snprintf(url, urllen, "%s%s", FILE_SCHEME_PREFIX, unix_path); } - free(unix_path); + free(unix_path); /* We don't want '/' to be escaped. */ url_err = url_escape(url, FILE_SCHEME_PREFIX_LEN, false, "/", &escurl); diff --git a/riscos/hotlist.c b/riscos/hotlist.c index 61202eaa2..4c2c084d2 100644 --- a/riscos/hotlist.c +++ b/riscos/hotlist.c @@ -48,12 +48,6 @@ #include "utils/utils.h" #include "utils/url.h" -static void ro_gui_hotlist_menu_prepare(wimp_w window, wimp_menu *menu); -static bool ro_gui_hotlist_menu_select(wimp_w window, wimp_menu *menu, - wimp_selection *selection, menu_action action); -static void ro_gui_hotlist_menu_warning(wimp_w window, wimp_menu *menu, - wimp_selection *selection, menu_action action); - /* The RISC OS hotlist window, toolbar and treeview data. */ static struct ro_hotlist { @@ -181,6 +175,9 @@ void ro_gui_hotlist_open(void) bool ro_gui_hotlist_toolbar_click(wimp_pointer *pointer) { + if (pointer->buttons == wimp_CLICK_MENU) + return ro_gui_wimp_event_process_window_menu_click(pointer); + if (hotlist_window.toolbar->editor != NULL) { ro_gui_theme_toolbar_editor_click(hotlist_window.toolbar, pointer); @@ -226,14 +223,6 @@ bool ro_gui_hotlist_toolbar_click(wimp_pointer *pointer) break; } - - /* \todo -- We assume that the owning module will have attached a window menu - * to our parent window. If it hasn't, this call will quietly fail. - */ - - if (pointer->buttons == wimp_CLICK_MENU) - return ro_gui_wimp_event_process_window_menu_click(pointer); - return true; } @@ -249,31 +238,37 @@ void ro_gui_hotlist_menu_prepare(wimp_w window, wimp_menu *menu) { bool selection; - selection = ro_treeview_has_selection(hotlist_window.tv); + if (menu != hotlist_window.menu && menu != tree_toolbar_menu) + return; + + if (menu == hotlist_window.menu) { + selection = ro_treeview_has_selection(hotlist_window.tv); - ro_gui_menu_set_entry_shaded(hotlist_window.menu, TREE_SELECTION, - !selection); - ro_gui_menu_set_entry_shaded(hotlist_window.menu, TREE_CLEAR_SELECTION, - !selection); + ro_gui_menu_set_entry_shaded(hotlist_window.menu, + TREE_SELECTION, !selection); + ro_gui_menu_set_entry_shaded(hotlist_window.menu, + TREE_CLEAR_SELECTION, !selection); - ro_gui_menu_set_entry_shaded(hotlist_window.menu, TOOLBAR_BUTTONS, + ro_gui_save_prepare(GUI_SAVE_HOTLIST_EXPORT_HTML, + NULL, NULL, NULL, NULL); + } + + ro_gui_menu_set_entry_shaded(menu, TOOLBAR_BUTTONS, (hotlist_window.toolbar == NULL || hotlist_window.toolbar->editor != NULL)); - ro_gui_menu_set_entry_ticked(hotlist_window.menu, TOOLBAR_BUTTONS, + ro_gui_menu_set_entry_ticked(menu, TOOLBAR_BUTTONS, (hotlist_window.toolbar != NULL && (hotlist_window.toolbar->display_buttons || (hotlist_window.toolbar->editor != NULL)))); - ro_gui_menu_set_entry_shaded(hotlist_window.menu, TOOLBAR_EDIT, + ro_gui_menu_set_entry_shaded(menu, TOOLBAR_EDIT, hotlist_window.toolbar == NULL); - ro_gui_menu_set_entry_ticked(hotlist_window.menu, TOOLBAR_EDIT, + ro_gui_menu_set_entry_ticked(menu, TOOLBAR_EDIT, (hotlist_window.toolbar != NULL && hotlist_window.toolbar->editor != NULL)); - - ro_gui_save_prepare(GUI_SAVE_HOTLIST_EXPORT_HTML, - NULL, NULL, NULL, NULL); } + /** * Handle submenu warnings for the hotlist menu * diff --git a/riscos/hotlist.h b/riscos/hotlist.h index 84fcca9c2..d6126bbd5 100644 --- a/riscos/hotlist.h +++ b/riscos/hotlist.h @@ -24,6 +24,8 @@ #ifndef _NETSURF_RISCOS_HOTLIST_H_ #define _NETSURF_RISCOS_HOTLIST_H_ +#include "riscos/menus.h" + void ro_gui_hotlist_preinitialise(void); void ro_gui_hotlist_postinitialise(void); void ro_gui_hotlist_open(void); @@ -32,6 +34,11 @@ void ro_gui_hotlist_update_theme(bool full_update); bool ro_gui_hotlist_check_window(wimp_w window); bool ro_gui_hotlist_check_menu(wimp_menu *menu); bool ro_gui_hotlist_toolbar_click(wimp_pointer *pointer); +void ro_gui_hotlist_menu_prepare(wimp_w window, wimp_menu *menu); +bool ro_gui_hotlist_menu_select(wimp_w window, wimp_menu *menu, + wimp_selection *selection, menu_action action); +void ro_gui_hotlist_menu_warning(wimp_w window, wimp_menu *menu, + wimp_selection *selection, menu_action action); #endif diff --git a/riscos/menus.c b/riscos/menus.c index 9bffbd582..af16127bc 100644 --- a/riscos/menus.c +++ b/riscos/menus.c @@ -301,6 +301,7 @@ void ro_gui_menu_init(void) }; tree_toolbar_menu = ro_gui_menu_define_menu(&tree_toolbar_definition); + /* proxy menu */ static const struct ns_menu proxy_type_definition = { "ProxyType", { @@ -375,8 +376,15 @@ void ro_gui_menu_init(void) /** * Display a menu. + * + * \param *menu Pointer to the menu to be displayed. + * \param x The x position. + * \param y The y position. + * \param w The window that the menu belongs to. + * \param prepare true if the menu is to be prepared; otherwise + * false (mainly for use by wimp_event module). */ -void ro_gui_menu_create(wimp_menu *menu, int x, int y, wimp_w w) +void ro_gui_menu_create(wimp_menu *menu, int x, int y, wimp_w w, bool prepare) { struct gui_window *g; os_error *error; @@ -442,7 +450,7 @@ void ro_gui_menu_create(wimp_menu *menu, int x, int y, wimp_w w) } else if (menu == recent_search_menu) { if (!ro_gui_search_prepare_menu()) return; - } else { + } else if (prepare) { i = 0; do { action = ro_gui_menu_find_action(menu, @@ -499,7 +507,7 @@ void ro_gui_popup_menu(wimp_menu *menu, wimp_w w, wimp_i i) ro_gui_menu_create(menu, state.visible.x0 + icon_state.icon.extent.x1 + 64, state.visible.y1 + icon_state.icon.extent.y1 - - state.yscroll, w); + state.yscroll, w, true); current_menu_icon = i; } @@ -679,7 +687,7 @@ void ro_gui_menu_selection(wimp_selection *selection) assert(g); /* Keep scan-build happy */ gui_create_form_select_menu(g->bw, gui_form_select_control); } else - ro_gui_menu_create(current_menu, 0, 0, current_menu_window); + ro_gui_menu_create(current_menu, 0, 0, current_menu_window, true); current_menu_icon = previous_menu_icon; } @@ -989,7 +997,7 @@ void gui_create_form_select_menu(struct browser_window *bw, gui_form_select_control = control; ro_gui_menu_create(gui_form_select_menu, - pointer.pos.x, pointer.pos.y, bw->window->window); + pointer.pos.x, pointer.pos.y, bw->window->window, true); } diff --git a/riscos/menus.h b/riscos/menus.h index 7cb6a4c3f..197aee9d1 100644 --- a/riscos/menus.h +++ b/riscos/menus.h @@ -170,7 +170,7 @@ struct ns_menu { void ro_gui_menu_init(void); -void ro_gui_menu_create(wimp_menu* menu, int x, int y, wimp_w w); +void ro_gui_menu_create(wimp_menu* menu, int x, int y, wimp_w w, bool prepare); bool ro_gui_menu_handle_action(wimp_w owner, menu_action action, bool windows_at_pointer); void ro_gui_menu_prepare_action(wimp_w owner, menu_action action, diff --git a/riscos/theme.c b/riscos/theme.c index a2b893266..015cf10eb 100644 --- a/riscos/theme.c +++ b/riscos/theme.c @@ -951,16 +951,31 @@ bool ro_gui_theme_update_toolbar(struct theme_descriptor *descriptor, case THEME_HOTLIST_EDIT_TOOLBAR: ro_gui_wimp_event_register_mouse_click(toolbar->toolbar_handle, ro_gui_hotlist_toolbar_click); + ro_gui_wimp_event_register_window_menu(toolbar->toolbar_handle, + tree_toolbar_menu, + ro_gui_hotlist_menu_prepare, + ro_gui_hotlist_menu_select, NULL, + ro_gui_hotlist_menu_warning, false); break; case THEME_HISTORY_TOOLBAR: case THEME_HISTORY_EDIT_TOOLBAR: ro_gui_wimp_event_register_mouse_click(toolbar->toolbar_handle, ro_gui_global_history_toolbar_click); + ro_gui_wimp_event_register_window_menu(toolbar->toolbar_handle, + tree_toolbar_menu, + ro_gui_global_history_menu_prepare, + ro_gui_global_history_menu_select, NULL, + ro_gui_global_history_menu_warning, false); break; case THEME_COOKIES_TOOLBAR: case THEME_COOKIES_EDIT_TOOLBAR: ro_gui_wimp_event_register_mouse_click(toolbar->toolbar_handle, ro_gui_cookies_toolbar_click); + ro_gui_wimp_event_register_window_menu(toolbar->toolbar_handle, + tree_toolbar_menu, + ro_gui_cookies_menu_prepare, + ro_gui_cookies_menu_select, NULL, + ro_gui_cookies_menu_warning, false); break; default: break; diff --git a/riscos/wimp_event.c b/riscos/wimp_event.c index 5d1f725f4..43011a0e6 100644 --- a/riscos/wimp_event.c +++ b/riscos/wimp_event.c @@ -985,7 +985,8 @@ bool ro_gui_wimp_event_process_window_menu_click(wimp_pointer *pointer) window->window_menu); ro_gui_menu_create(window->window_menu, - pointer->pos.x, pointer->pos.y, window->w); + pointer->pos.x, pointer->pos.y, + window->w, false); return true; } return false; diff --git a/riscos/window.c b/riscos/window.c index 55bdb11d6..d8eb2fa51 100644 --- a/riscos/window.c +++ b/riscos/window.c @@ -593,7 +593,7 @@ void gui_window_update_box(struct gui_window *g, y0 = -ceilf((data->redraw.y + data->redraw.height) * 2 * g->bw->scale); x1 = ceilf((data->redraw.x + data->redraw.width) * 2 * g->bw->scale) + 1; y1 = -floorf(data->redraw.y * 2 * g->bw->scale) + 1; - use_buffer = + use_buffer = (g->option.buffer_everything || g->option.buffer_animations); /* try to optimise buffered redraws */ @@ -1398,7 +1398,7 @@ bool gui_window_frame_resize_start(struct gui_window *g) * \param g gui_window containing the content * \param c the content to save */ -void gui_window_save_link(struct gui_window *g, const char *url, +void gui_window_save_link(struct gui_window *g, const char *url, const char *title) { ro_gui_save_prepare(GUI_SAVE_LINK_URL, NULL, NULL, url, title); @@ -2148,7 +2148,7 @@ bool ro_gui_toolbar_click(wimp_pointer *pointer) /* Handle Menu clicks */ if (pointer->buttons == wimp_CLICK_MENU) { ro_gui_menu_create(browser_toolbar_menu, pointer->pos.x, - pointer->pos.y, g->window); + pointer->pos.y, g->window, true); return true; } @@ -2317,7 +2317,7 @@ bool ro_gui_window_click(wimp_pointer *pointer) gui_window_place_caret(g, -100, -100, 0); if (pointer->buttons == wimp_CLICK_MENU) { - ro_gui_menu_create(browser_menu, pointer->pos.x, pointer->pos.y, pointer->w); + ro_gui_menu_create(browser_menu, pointer->pos.x, pointer->pos.y, pointer->w, true); } else { if (ro_gui_window_to_window_pos(g, pointer->pos.x, pointer->pos.y, &pos)) browser_window_mouse_click(g->bw, -- cgit v1.2.3