diff options
Diffstat (limited to 'riscos')
-rw-r--r-- | riscos/dialog.c | 110 | ||||
-rw-r--r-- | riscos/global_history.c | 307 | ||||
-rw-r--r-- | riscos/global_history.h | 2 | ||||
-rw-r--r-- | riscos/gui.c | 27 | ||||
-rw-r--r-- | riscos/gui.h | 44 | ||||
-rw-r--r-- | riscos/help.c | 330 | ||||
-rw-r--r-- | riscos/help.h | 6 | ||||
-rw-r--r-- | riscos/hotlist.c | 147 | ||||
-rw-r--r-- | riscos/menus.c | 3528 | ||||
-rw-r--r-- | riscos/menus.h | 139 | ||||
-rw-r--r-- | riscos/mouseactions.c | 3 | ||||
-rw-r--r-- | riscos/print.c | 25 | ||||
-rw-r--r-- | riscos/save.c | 29 | ||||
-rw-r--r-- | riscos/search.c | 23 | ||||
-rw-r--r-- | riscos/textselection.c | 7 | ||||
-rw-r--r-- | riscos/theme.c | 6 | ||||
-rw-r--r-- | riscos/treeview.c | 39 | ||||
-rw-r--r-- | riscos/wimp.c | 372 | ||||
-rw-r--r-- | riscos/wimp.h | 9 | ||||
-rw-r--r-- | riscos/window.c | 238 |
20 files changed, 2686 insertions, 2705 deletions
diff --git a/riscos/dialog.c b/riscos/dialog.c index 1ffae34cc..039246c65 100644 --- a/riscos/dialog.c +++ b/riscos/dialog.c @@ -5,7 +5,7 @@ * Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net> * Copyright 2005 James Bursa <bursa@users.sourceforge.net> * Copyright 2003 John M Bell <jmb202@ecs.soton.ac.uk> - * Copyright 2004 Richard Wilson <not_ginger_matt@users.sourceforge.net> + * Copyright 2005 Richard Wilson <not_ginger_matt@users.sourceforge.net> * Copyright 2004 Andrew Timmins <atimmins@blueyonder.co.uk> */ @@ -23,11 +23,13 @@ #include "netsurf/desktop/netsurf.h" #include "netsurf/render/font.h" #include "netsurf/riscos/gui.h" +#include "netsurf/riscos/menus.h" #include "netsurf/riscos/options.h" #include "netsurf/riscos/theme.h" #include "netsurf/riscos/wimp.h" #include "netsurf/utils/log.h" #include "netsurf/utils/messages.h" +#include "netsurf/utils/url.h" #include "netsurf/utils/utils.h" /* The maximum number of persistant dialogues @@ -44,7 +46,8 @@ wimp_w dialog_info, dialog_saveas, dialog_config, dialog_config_br, dialog_zoom, dialog_pageinfo, dialog_objinfo, dialog_tooltip, dialog_warning, dialog_config_th_pane, dialog_debug, dialog_folder, dialog_entry, dialog_search, dialog_print, - dialog_config_font, dialog_config_image, dialog_url_complete; + dialog_config_font, dialog_config_image, dialog_url_complete, + dialog_openurl; static int ro_gui_choices_font_size; static int ro_gui_choices_font_min_size; @@ -59,6 +62,8 @@ static unsigned int ro_gui_choices_fg_plot_style = 0; static unsigned int ro_gui_choices_bg_plot_style = 0; +struct gui_window *ro_gui_current_zoom_gui; + struct toolbar_display { struct toolbar *toolbar; struct theme_descriptor *descriptor; @@ -104,7 +109,7 @@ static void ro_gui_dialog_click_config_th_pane(wimp_pointer *pointer); static void ro_gui_dialog_update_config_font(void); static void ro_gui_dialog_click_config_font(wimp_pointer *pointer); static void ro_gui_dialog_click_zoom(wimp_pointer *pointer); -static void ro_gui_dialog_reset_zoom(void); +static void ro_gui_dialog_click_open_url(wimp_pointer *pointer); static void ro_gui_dialog_click_warning(wimp_pointer *pointer); static const char *language_name(const char *code); @@ -142,6 +147,7 @@ void ro_gui_dialog_init(void) dialog_config_image = ro_gui_dialog_create("config_img"); dialog_theme_install = ro_gui_dialog_create("theme_inst"); dialog_url_complete = ro_gui_dialog_create("url_suggest"); + dialog_openurl = ro_gui_dialog_create("open_url"); } @@ -334,8 +340,13 @@ void ro_gui_dialog_open_persistant(wimp_w parent, wimp_w w, bool pointer) { ro_gui_open_window_centre(parent, w); } - /* Set the caret position + /* Set the caret position and window furniture */ + if ((w == dialog_pageinfo) || (w == dialog_objinfo)) + ro_gui_wimp_update_window_furniture(w, wimp_WINDOW_CLOSE_ICON, + wimp_WINDOW_CLOSE_ICON); + ro_gui_wimp_update_window_furniture(w, wimp_WINDOW_BACK_ICON, + wimp_WINDOW_BACK_ICON); ro_gui_set_caret_first(w); /* Add a mapping @@ -460,6 +471,8 @@ void ro_gui_dialog_click(wimp_pointer *pointer) ro_gui_dialog_click_config_font(pointer); else if (pointer->w == dialog_theme_install) ro_gui_theme_install_click(pointer); + else if (pointer->w == dialog_openurl) + ro_gui_dialog_click_open_url(pointer); } @@ -757,7 +770,8 @@ void ro_gui_dialog_click_config(wimp_pointer *pointer) state.visible.x1 -= 12; state.visible.y0 += 128; state.visible.y1 -= 12; - xwimp_open_window_nested((wimp_open *) &state, dialog_config_th, + xwimp_open_window_nested((wimp_open *) &state, + dialog_config_th, wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT << wimp_CHILD_XORIGIN_SHIFT | wimp_CHILD_LINKS_PARENT_VISIBLE_TOP_OR_RIGHT @@ -814,7 +828,8 @@ void ro_gui_dialog_click_config_br(wimp_pointer *pointer) /* drop through */ case ICON_CONFIG_BR_ALANG_PICK: config_br_icon = pointer->i; - ro_gui_popup_menu(languages_menu, dialog_config_br, pointer->i); + ro_gui_popup_menu(languages_menu, dialog_config_br, + pointer->i); break; } } @@ -850,9 +865,6 @@ void ro_gui_dialog_languages_menu_selection(char *lang) lang); break; } - - /* invalidate icon number and update window */ - config_br_icon = -1; } @@ -868,7 +880,7 @@ void ro_gui_dialog_click_config_prox(wimp_pointer *pointer) ro_gui_dialog_config_proxy_update(); break; case ICON_CONFIG_PROX_AUTHTYPE_PICK: - ro_gui_popup_menu(proxyauth_menu, dialog_config_prox, + ro_gui_popup_menu(proxy_auth_menu, dialog_config_prox, ICON_CONFIG_PROX_AUTHTYPE_PICK); break; } @@ -895,7 +907,7 @@ void ro_gui_dialog_click_config_image(wimp_pointer *pointer) } else { ro_gui_choices_fg_plot_style &= ~tinct_BILINEAR_FILTER; } - break; + break; case ICON_CONFIG_IMG_BG_MENU: ro_gui_choices_image_edit_type = 2; ro_gui_menu_prepare_image_quality(ro_gui_choices_bg_plot_style); @@ -909,7 +921,7 @@ void ro_gui_dialog_click_config_image(wimp_pointer *pointer) } else { ro_gui_choices_bg_plot_style &= ~tinct_BILINEAR_FILTER; } - break; + break; } } @@ -1174,27 +1186,75 @@ void ro_gui_dialog_click_zoom(wimp_pointer *pointer) if (pointer->buttons == wimp_CLICK_ADJUST && pointer->i == ICON_ZOOM_CANCEL) - ro_gui_dialog_reset_zoom(); + ro_gui_dialog_prepare_zoom(ro_gui_current_zoom_gui); if (pointer->buttons == wimp_CLICK_SELECT && (pointer->i == ICON_ZOOM_CANCEL || pointer->i == ICON_ZOOM_OK)) { ro_gui_dialog_close(dialog_zoom); - wimp_create_menu(wimp_CLOSE_MENU, 0, 0); + ro_gui_menu_closed(); } } /** - * Resets the Scale view dialog. + * Prepares the Scale view dialog. */ -void ro_gui_dialog_reset_zoom(void) +void ro_gui_dialog_prepare_zoom(struct gui_window *g) { char scale_buffer[8]; - sprintf(scale_buffer, "%.0f", - ro_gui_current_zoom_gui->option.scale * 100); + sprintf(scale_buffer, "%.0f", g->option.scale * 100); ro_gui_set_icon_string(dialog_zoom, ICON_ZOOM_VALUE, scale_buffer); + + ro_gui_current_zoom_gui = g; +} + + +/** + * Handle clicks in the Open URL dialog. + */ + +void ro_gui_dialog_click_open_url(wimp_pointer *pointer) +{ + url_func_result res; + const char *url; + char *url2; + + if ((pointer->i != ICON_OPENURL_OPEN) && + (pointer->i != ICON_OPENURL_CANCEL)) + return; + + if (pointer->i == ICON_OPENURL_OPEN) { + url = ro_gui_get_icon_string(dialog_openurl, + ICON_OPENURL_URL); + res = url_normalize(url, &url2); + if (res == URL_FUNC_OK) { + browser_window_create(url2, 0, 0); + global_history_add_recent(url2); + free(url2); + } + } + + if (pointer->buttons == wimp_CLICK_ADJUST && + pointer->i == ICON_OPENURL_CANCEL) + ro_gui_dialog_prepare_open_url(); + + if (pointer->buttons == wimp_CLICK_SELECT) { + ro_gui_dialog_close(dialog_openurl); + ro_gui_menu_closed(); + } + +} + + +/** + * Prepares the Open URL dialog. + */ + +void ro_gui_dialog_prepare_open_url(void) +{ + ro_gui_set_icon_string(dialog_openurl, ICON_OPENURL_URL, "www."); } @@ -1220,7 +1280,7 @@ void ro_gui_dialog_close(wimp_w close) os_error *error; /* Give the caret back to the parent window. This code relies on - the fact that only hotlist windows and browser windows open + the fact that only tree windows and browser windows open persistant dialogues, as the caret gets placed to no icon. */ error = xwimp_get_caret_position(&caret); @@ -1306,7 +1366,8 @@ void ro_gui_dialog_load_themes(void) while (descriptor) { /* Try to create a toolbar */ - toolbar = ro_gui_theme_create_toolbar(descriptor, THEME_BROWSER_TOOLBAR); + toolbar = ro_gui_theme_create_toolbar(descriptor, + THEME_BROWSER_TOOLBAR); if (toolbar) { toolbar_display = calloc(sizeof(struct toolbar_display), 1); if (!toolbar_display) { @@ -1411,7 +1472,8 @@ void ro_gui_dialog_load_themes(void) state.yscroll = 0; state.visible.y1 = nested_y + base_extent; state.visible.y0 = state.visible.y1 - link->toolbar->height + 2; - xwimp_open_window_nested((wimp_open *)&state, dialog_config_th_pane, + xwimp_open_window_nested((wimp_open *)&state, + dialog_config_th_pane, wimp_CHILD_LINKS_PARENT_WORK_AREA << wimp_CHILD_BS_EDGE_SHIFT | wimp_CHILD_LINKS_PARENT_WORK_AREA @@ -1428,7 +1490,8 @@ void ro_gui_dialog_load_themes(void) link = toolbars; while (link) { ro_gui_set_icon_selected_state(dialog_config_th_pane, - link->icon_number, (link->descriptor == theme_choice)); + link->icon_number, + (link->descriptor == theme_choice)); link = link->next; } xwimp_force_redraw(dialog_config_th_pane, 0, -16384, 16384, 16384); @@ -1451,7 +1514,8 @@ void ro_gui_dialog_free_themes(void) xwimp_delete_icon(dialog_config_th_pane, toolbar->icon_number); xwimp_delete_icon(dialog_config_th_pane, toolbar->icon_number + 1); if (toolbar->next) - xwimp_delete_icon(dialog_config_th_pane, toolbar->icon_number + 2); + xwimp_delete_icon(dialog_config_th_pane, + toolbar->icon_number + 2); ro_gui_theme_destroy_toolbar(toolbar->toolbar); next_toolbar = toolbar->next; free(toolbar); diff --git a/riscos/global_history.c b/riscos/global_history.c index 2dbd9410d..ac04a8141 100644 --- a/riscos/global_history.c +++ b/riscos/global_history.c @@ -21,6 +21,7 @@ #include "netsurf/desktop/tree.h" #include "netsurf/riscos/global_history.h" #include "netsurf/riscos/gui.h" +#include "netsurf/riscos/menus.h" #include "netsurf/riscos/theme.h" #include "netsurf/riscos/treeview.h" #include "netsurf/utils/messages.h" @@ -45,9 +46,10 @@ static char *global_history_recent_url[GLOBAL_HISTORY_RECENT_URLS]; static int global_history_recent_count = 0; static void ro_gui_global_history_initialise_nodes(void); -static void ro_gui_global_history_initialise_node(const char *title, time_t base, - int days_back); -static void ro_gui_global_history_add(char *title, char *url, int visit_date, int filetype); +static void ro_gui_global_history_initialise_node(const char *title, + time_t base, int days_back); +static void ro_gui_global_history_add(char *title, char *url, int visit_date, + int filetype); static void ro_gui_global_history_save_node(struct node *node, FILE *fp); /* A basic window for the history @@ -91,7 +93,7 @@ struct tree *global_history_tree; void ro_gui_global_history_initialise(void) { char s[MAXIMUM_URL_LENGTH]; FILE *fp; - const char *title; + const char *title; os_error *error; char *node_title; char *node_url; @@ -101,29 +103,32 @@ void ro_gui_global_history_initialise(void) { /* Create our window */ title = messages_get("GlobalHistory"); - history_window_definition.title_data.indirected_text.text = strdup(title); + history_window_definition.title_data.indirected_text.text = + strdup(title); history_window_definition.title_data.indirected_text.validation = (char *) -1; - history_window_definition.title_data.indirected_text.size = strlen(title); - error = xwimp_create_window(&history_window_definition, &global_history_window); + history_window_definition.title_data.indirected_text.size = + strlen(title); + error = xwimp_create_window(&history_window_definition, + &global_history_window); if (error) { LOG(("xwimp_create_window: 0x%x: %s", error->errnum, error->errmess)); die(error->errmess); } - + /* Create an empty tree */ global_history_tree = calloc(sizeof(struct tree), 1); if (!global_history_tree) { - warn_user("NoMemory", 0); + warn_user("NoMemory", 0); return; } global_history_tree->root = tree_create_folder_node(NULL, "Root"); if (!global_history_tree->root) { - warn_user("NoMemory", 0); - free(global_history_tree); - global_history_tree = NULL; + warn_user("NoMemory", 0); + free(global_history_tree); + global_history_tree = NULL; } global_history_tree->root->expanded = true; ro_gui_global_history_initialise_nodes(); @@ -138,66 +143,66 @@ void ro_gui_global_history_initialise(void) { if (global_history_tree->toolbar) ro_gui_theme_attach_toolbar(global_history_tree->toolbar, global_history_window); - - /* load recent URLs */ + + /* load recent URLs */ fp = fopen(GLOBAL_HISTORY_RECENT_READ, "r"); if (!fp) LOG(("Failed to open file '%s' for reading", GLOBAL_HISTORY_RECENT_READ)); else { while (fgets(s, MAXIMUM_URL_LENGTH, fp)) { - if (s[strlen(s) - 1] == '\n') - s[strlen(s) - 1] = '\0'; + if (s[strlen(s) - 1] == '\n') + s[strlen(s) - 1] = '\0'; global_history_add_recent(s); } fclose(fp); } - /* load global history */ + /* load global history */ fp = fopen(GLOBAL_HISTORY_READ, "r"); if (!fp) LOG(("Failed to open file '%s' for reading", GLOBAL_HISTORY_READ)); else { while (fgets(s, MAXIMUM_URL_LENGTH, fp)) { - if (s[strlen(s) - 1] == '\n') - s[strlen(s) - 1] = '\0'; - node_title = strdup(s); + if (s[strlen(s) - 1] == '\n') + s[strlen(s) - 1] = '\0'; + node_title = strdup(s); if (!fgets(s, MAXIMUM_URL_LENGTH, fp)) { - LOG(("Error reading global history")); - warn_user("HistoryCorrupt", 0); - fclose(fp); - return; + LOG(("Error reading global history")); + warn_user("HistoryCorrupt", 0); + fclose(fp); + return; } - if (s[strlen(s) - 1] == '\n') - s[strlen(s) - 1] = '\0'; + if (s[strlen(s) - 1] == '\n') + s[strlen(s) - 1] = '\0'; node_url = strdup(s); - if ((!node_title) || (!node_url)) { - LOG(("No memory to read global history node")); - warn_user("NoMemory", 0); - fclose(fp); - return; - } + if ((!node_title) || (!node_url)) { + LOG(("No memory to read global history node")); + warn_user("NoMemory", 0); + fclose(fp); + return; + } if (!fgets(s, MAXIMUM_URL_LENGTH, fp)) { - LOG(("Error reading global history")); - warn_user("HistoryCorrupt", 0); - fclose(fp); - return; + LOG(("Error reading global history")); + warn_user("HistoryCorrupt", 0); + fclose(fp); + return; } node_filetype = atoi(s); if (!fgets(s, MAXIMUM_URL_LENGTH, fp)) { - LOG(("Error reading global history")); - warn_user("HistoryCorrupt", 0); - fclose(fp); - return; + LOG(("Error reading global history")); + warn_user("HistoryCorrupt", 0); + fclose(fp); + return; } node_visited = atoi(s); - ro_gui_global_history_add(node_title, node_url, node_visited, - node_filetype); - free(node_title); - node_title = NULL; - free(node_url); - node_url = NULL; + ro_gui_global_history_add(node_title, node_url, + node_visited, node_filetype); + free(node_title); + node_title = NULL; + free(node_url); + node_url = NULL; } fclose(fp); } @@ -212,12 +217,12 @@ static void ro_gui_global_history_initialise_nodes(void) { time_t t; int weekday; int i; - + /* get the current time */ t = time(NULL); if (t == -1) return; - + /* get the time at the start of today */ full_time = localtime(&t); weekday = full_time->tm_wday; @@ -227,11 +232,11 @@ static void ro_gui_global_history_initialise_nodes(void) { t = mktime(full_time); if (t == -1) return; - + ro_gui_global_history_initialise_node(messages_get("DateToday"), t, 0); if (weekday > 0) - ro_gui_global_history_initialise_node(messages_get("DateYesterday"), - t, -1); + ro_gui_global_history_initialise_node( + messages_get("DateYesterday"), t, -1); for (i = 2; i <= weekday; i++) ro_gui_global_history_initialise_node(NULL, t, -i); ro_gui_global_history_initialise_node(messages_get("Date1Week"), @@ -242,12 +247,12 @@ static void ro_gui_global_history_initialise_nodes(void) { t, -weekday - 21); } -static void ro_gui_global_history_initialise_node(const char *title, time_t base, - int days_back) { +static void ro_gui_global_history_initialise_node(const char *title, + time_t base, int days_back) { struct tm *full_time; char buffer[64]; struct node *node; - + base += days_back * 60 * 60 * 24; if (!title) { full_time = localtime(&base); @@ -282,8 +287,10 @@ void ro_gui_global_history_save(void) { GLOBAL_HISTORY_RECENT_WRITE)); else { for (i = global_history_recent_count - 1; i >= 0; i--) - if (strlen(global_history_recent_url[i]) < MAXIMUM_URL_LENGTH) - fprintf(fp, "%s\n", global_history_recent_url[i]); + if (strlen(global_history_recent_url[i]) < + MAXIMUM_URL_LENGTH) + fprintf(fp, "%s\n", + global_history_recent_url[i]); fclose(fp); } @@ -304,17 +311,19 @@ void ro_gui_global_history_save(void) { */ void ro_gui_global_history_save_node(struct node *node, FILE *fp) { struct node_element *element; - + for (; node; node = node->next) { if (node->folder) { - ro_gui_global_history_save_node(node->child, fp); + ro_gui_global_history_save_node(node->child, fp); } else { element = tree_find_element(node, TREE_ELEMENT_URL); if (element) { fprintf(fp, "%s\n%s\n%i\n", node->data.text, - element->text, element->user_data); - - element = tree_find_element(node, TREE_ELEMENT_VISITED); + element->text, + element->user_data); + + element = tree_find_element(node, + TREE_ELEMENT_VISITED); if (element) fprintf(fp, "%i\n", element->user_data); else @@ -324,14 +333,6 @@ void ro_gui_global_history_save_node(struct node *node, FILE *fp) { } } -/** - * Shows the history window. - */ -void ro_gui_global_history_show(void) { - ro_gui_tree_show(global_history_tree); - ro_gui_menu_prepare_global_history(); -} - /** * Respond to a mouse click @@ -341,32 +342,10 @@ void ro_gui_global_history_show(void) { void ro_gui_global_history_click(wimp_pointer *pointer) { ro_gui_tree_click(pointer, global_history_tree); if (pointer->buttons == wimp_CLICK_MENU) - ro_gui_create_menu(global_history_menu, pointer->pos.x, - pointer->pos.y, NULL); + ro_gui_menu_create(global_history_menu, pointer->pos.x, + pointer->pos.y, pointer->w); else - ro_gui_menu_prepare_global_history(); -} - - -/** - * Respond to a keypress - * - * \param key the key pressed - */ -bool ro_gui_global_history_keypress(int key) { - bool result = ro_gui_tree_keypress(key, global_history_tree); - ro_gui_menu_prepare_global_history(); - return result; -} - - -/** - * Handles a menu closed event - */ -void ro_gui_global_history_menu_closed(void) { - ro_gui_tree_menu_closed(global_history_tree); - current_menu = NULL; - ro_gui_menu_prepare_global_history(); + ro_gui_menu_prepare_action(pointer->w, TREE_SELECTION, false); } @@ -389,74 +368,84 @@ int ro_gui_global_history_help(int x, int y) { */ void global_history_add(struct gui_window *g) { assert(g); - - if ((!g->bw->current_content) || (!global_history_tree)) - return; - - ro_gui_global_history_add(g->bw->current_content->title, g->bw->current_content->url, time(NULL), - ro_content_filetype(g->bw->current_content)); + + if ((!g->bw->current_content) || (!global_history_tree)) + return; + + ro_gui_global_history_add(g->bw->current_content->title, + g->bw->current_content->url, time(NULL), + ro_content_filetype(g->bw->current_content)); } /** * Adds to the global history * - * \param title the page title - * \param url the page URL + * \param title the page title + * \param url the page URL * \param visit_date the visit date */ -void ro_gui_global_history_add(char *title, char *url, int visit_date, int filetype) { - int i, j; - struct node *parent = NULL; - struct node *link; - struct node *node; - struct node_element *element; - bool before = false; - - /* Find/create the node to link into - */ - for (i = 0; i < global_history_base_node_count; i++) { - if (global_history_base_node_time[i] <= visit_date) { - parent = global_history_base_node[i]; - if (parent->deleted) { - link = global_history_tree->root; - for (j = 0; j < i; j++) { - if (!global_history_base_node[j]->deleted) { - link = global_history_base_node[j]; - before = true; - break; - } - } - tree_link_node(link, parent, before); - tree_recalculate_node_positions(global_history_tree->root); - tree_redraw_area(global_history_tree, 0, 0, 16384, 16384); } - break; - } - } - - if (parent) { - /* Add the node at the bottom - */ - node = tree_create_URL_node_brief(parent, title, url, filetype, visit_date); +void ro_gui_global_history_add(char *title, char *url, int visit_date, + int filetype) { + int i, j; + struct node *parent = NULL; + struct node *link; + struct node *node; + struct node_element *element; + bool before = false; + + /* Find/create the node to link into + */ + for (i = 0; i < global_history_base_node_count; i++) { + if (global_history_base_node_time[i] <= visit_date) { + parent = global_history_base_node[i]; + if (!parent->deleted) + break; + link = global_history_tree->root; + for (j = 0; j < i; j++) { + if (!global_history_base_node[j]->deleted) { + link = global_history_base_node[j]; + before = true; + break; + } + } + tree_link_node(link, parent, before); + tree_recalculate_node_positions( + global_history_tree->root); + tree_redraw_area(global_history_tree, + 0, 0, 16384, 16384); + break; + } + } + + if (parent) { + /* Add the node at the bottom + */ + node = tree_create_URL_node_brief(parent, title, url, filetype, + visit_date); if (node) { - tree_redraw_area(global_history_tree, node->box.x - NODE_INSTEP, + tree_redraw_area(global_history_tree, + node->box.x - NODE_INSTEP, 0, NODE_INSTEP, 16384); - tree_handle_node_changed(global_history_tree, node, false, - true); + tree_handle_node_changed(global_history_tree, node, + false, true); } - /* Remove any duplicate URL from within the parent node. This must be done after - the duplicate has been created as deleting all children of a child automatically - collapses the display. - */ - for (node = parent->child; node && (node->next); node = node->next) { - element = tree_find_element(node, TREE_ELEMENT_URL); - if ((element) && (!strcmp(url, element->text))) { - tree_delete_node(global_history_tree, node, false); - break; - } - } - } + /* Remove any duplicate URL from within the parent node. + * This must be done after the duplicate has been created as + * deleting all children of a child automatically collapses + * the display. + */ + for (node = parent->child; node && (node->next); + node = node->next) { + element = tree_find_element(node, TREE_ELEMENT_URL); + if ((element) && (!strcmp(url, element->text))) { + tree_delete_node(global_history_tree, node, + false); + break; + } + } + } } @@ -470,31 +459,33 @@ void global_history_add_recent(const char *url) { int i; int j = -1; char *current; - - /* by using the url_store, we get a central char* of the string that isn't - * going anywhere unless we tell it to */ + + /* by using the url_store, we get a central char* of the string that + * isn't going anywhere unless we tell it to */ data = url_store_find(url); if (!data) return; - + /* try to find a string already there */ for (i = 0; i < global_history_recent_count; i++) if (global_history_recent_url[i] == data->url) j = i; - + /* already at head of list */ if (j == 0) return; - + /* add to head of list */ if (j < 0) { memmove(&global_history_recent_url[1], &global_history_recent_url[0], - (GLOBAL_HISTORY_RECENT_URLS - 1) * sizeof(char *)); + (GLOBAL_HISTORY_RECENT_URLS - 1) * + sizeof(char *)); global_history_recent_url[0] = data->url; global_history_recent_count++; if (global_history_recent_count > GLOBAL_HISTORY_RECENT_URLS) - global_history_recent_count = GLOBAL_HISTORY_RECENT_URLS; + global_history_recent_count = + GLOBAL_HISTORY_RECENT_URLS; if (global_history_recent_count == 1) ro_gui_window_prepare_navigate_all(); } else { diff --git a/riscos/global_history.h b/riscos/global_history.h index a1824679a..120f73e8f 100644 --- a/riscos/global_history.h +++ b/riscos/global_history.h @@ -21,9 +21,7 @@ void ro_gui_global_history_initialise(void); void ro_gui_global_history_save(void); -void ro_gui_global_history_show(void); void ro_gui_global_history_click(wimp_pointer *pointer); -bool ro_gui_global_history_keypress(int key); void ro_gui_global_history_dialog_click(wimp_pointer *pointer); void ro_gui_global_history_menu_closed(void); int ro_gui_global_history_help(int x, int y); diff --git a/riscos/gui.c b/riscos/gui.c index c67a91474..f773105a7 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -48,6 +48,7 @@ #include "netsurf/riscos/global_history.h" #include "netsurf/riscos/gui.h" #include "netsurf/riscos/help.h" +#include "netsurf/riscos/menus.h" #include "netsurf/riscos/options.h" #ifdef WITH_PLUGIN #include "netsurf/riscos/plugin.h" @@ -319,7 +320,7 @@ void gui_init(int argc, char** argv) } ro_gui_dialog_init(); ro_gui_download_init(); - ro_gui_menus_init(); + ro_gui_menu_init(); #ifdef WITH_AUTH ro_gui_401login_init(); #endif @@ -1024,8 +1025,8 @@ void ro_gui_icon_bar_click(wimp_pointer *pointer) int key_down = 0; if (pointer->buttons == wimp_CLICK_MENU) { - ro_gui_create_menu(iconbar_menu, pointer->pos.x, - 96 + iconbar_menu_height, NULL); + ro_gui_menu_create(iconbar_menu, pointer->pos.x, + 96 + iconbar_menu_height, wimp_ICON_BAR); } else if (pointer->buttons == wimp_CLICK_SELECT) { if (option_homepage_url && option_homepage_url[0]) { @@ -1039,11 +1040,11 @@ void ro_gui_icon_bar_click(wimp_pointer *pointer) } else if (pointer->buttons == wimp_CLICK_ADJUST) { xosbyte1(osbyte_SCAN_KEYBOARD, 0 ^ 0x80, 0, &key_down); - if (key_down == 0) { - ro_gui_hotlist_show(); - } else { + if (key_down == 0) + ro_gui_menu_handle_action(pointer->w, HOTLIST_SHOW, + false); + else ro_gui_debugwin_open(); - } } } @@ -1096,9 +1097,9 @@ void ro_gui_keypress(wimp_key *key) os_error *error; if ((hotlist_tree) && (key->w == (wimp_w)hotlist_tree->handle)) - handled = ro_gui_hotlist_keypress(key->c); + handled = ro_gui_tree_keypress(key->c, hotlist_tree); else if ((global_history_tree) && (key->w == (wimp_w)global_history_tree->handle)) - handled = ro_gui_global_history_keypress(key->c); + handled = ro_gui_tree_keypress(key->c, global_history_tree); else if ((g = ro_gui_window_lookup(key->w)) != NULL) handled = ro_gui_window_keypress(g, key->c, false); else if ((g = ro_gui_toolbar_lookup(key->w)) != NULL) @@ -1163,13 +1164,7 @@ void ro_gui_user_message(wimp_event_no event, wimp_message *message) &message->data); break; case message_MENUS_DELETED: - if ((current_menu == hotlist_menu) && (hotlist_tree)) - ro_gui_hotlist_menu_closed(); - else if ((current_menu == global_history_menu) && - (global_history_tree)) - ro_gui_global_history_menu_closed(); - current_menu = NULL; - current_gui = NULL; + ro_gui_menu_closed(); break; case message_MODE_CHANGE: ro_gui_history_mode_change(); diff --git a/riscos/gui.h b/riscos/gui.h index d32a7f55c..4a392e6d9 100644 --- a/riscos/gui.h +++ b/riscos/gui.h @@ -28,20 +28,15 @@ struct plotter_table; extern wimp_w dialog_info, dialog_saveas, dialog_config, dialog_config_br, dialog_config_prox, dialog_config_th, dialog_zoom, dialog_pageinfo, - dialog_objinfo, dialog_tooltip, dialog_warning, + dialog_objinfo, dialog_tooltip, dialog_warning, dialog_openurl, dialog_config_th_pane, dialog_debug, dialog_folder, dialog_entry, dialog_search, dialog_print, dialog_config_font, dialog_theme_install, dialog_url_complete; +extern wimp_menu *font_menu; /* font.c */ extern wimp_w history_window; -extern wimp_menu *iconbar_menu, *browser_menu, *combo_menu, *hotlist_menu, - *proxyauth_menu, *languages_menu, *toolbar_menu, - *image_quality_menu, *global_history_menu, *url_suggest_menu, - *font_menu; -extern int iconbar_menu_height; extern struct form_control *current_gadget; extern bool gui_reformat_pending; extern bool gui_redraw_debug; -extern wimp_menu *current_menu; extern osspriteop_area *gui_sprites; extern bool dialog_folder_add, dialog_entry_add, hotlist_insert; extern bool print_active, print_text_black; @@ -101,10 +96,7 @@ struct gui_window { }; -extern struct toolbar *current_toolbar; -extern struct gui_window *current_gui; extern struct gui_window *ro_gui_current_redraw_gui; -extern struct gui_window *ro_gui_current_zoom_gui; /* in gui.c */ @@ -114,21 +106,6 @@ void ro_gui_screen_size(int *width, int *height); void ro_gui_view_source(struct content *content); void ro_gui_drag_box_start(wimp_pointer *pointer); -/* in menus.c */ -void ro_gui_menus_init(void); -bool ro_gui_menu_prepare_url_suggest(void); -void ro_gui_create_menu(wimp_menu* menu, int x, int y, struct gui_window *g); -void ro_gui_popup_menu(wimp_menu *menu, wimp_w w, wimp_i i); -void ro_gui_menu_selection(wimp_selection* selection); -void ro_gui_menu_warning(wimp_message_menu_warning *warning); -void ro_gui_prepare_navigate(struct gui_window *gui); -void ro_gui_menu_prepare_image_quality(unsigned int tinct_options); -void ro_gui_menu_prepare_scale(void); -void ro_gui_menu_prepare_pageinfo(void); -void ro_gui_menu_prepare_hotlist(void); -void ro_gui_menu_prepare_global_history(void); -void ro_gui_display_font_menu(const char *tick, wimp_w w, wimp_i i); - /* in dialog.c */ void ro_gui_dialog_init(void); wimp_w ro_gui_dialog_create(const char *template_name); @@ -137,6 +114,8 @@ void ro_gui_dialog_open(wimp_w w); void ro_gui_dialog_open_persistant(wimp_w parent, wimp_w w, bool pointer); void ro_gui_dialog_close_persistant(wimp_w parent); void ro_gui_dialog_click(wimp_pointer *pointer); +void ro_gui_dialog_prepare_zoom(struct gui_window *g); +void ro_gui_dialog_prepare_open_url(void); void ro_gui_save_options(void); bool ro_gui_dialog_keypress(wimp_key *key); void ro_gui_dialog_close(wimp_w close); @@ -211,19 +190,14 @@ void ro_gui_history_mouse_at(wimp_pointer *pointer); /* in hotlist.c */ void ro_gui_hotlist_initialise(void); void ro_gui_hotlist_save(void); -void ro_gui_hotlist_show(void); void ro_gui_hotlist_click(wimp_pointer *pointer); -bool ro_gui_hotlist_keypress(int key); -void ro_gui_hotlist_toolbar_click(wimp_pointer* pointer); void ro_gui_hotlist_prepare_folder_dialog(struct node *node); void ro_gui_hotlist_prepare_entry_dialog(struct node *node); void ro_gui_hotlist_dialog_click(wimp_pointer *pointer); -void ro_gui_hotlist_menu_closed(void); int ro_gui_hotlist_help(int x, int y); /* in save.c */ -void ro_gui_save_open(gui_save_type save_type, struct content *c, - bool sub_menu, int x, int y, wimp_w parent, bool keypress); +void ro_gui_save_prepare(gui_save_type save_type, struct content *c); void ro_gui_save_click(wimp_pointer *pointer); void ro_gui_drag_icon(wimp_pointer *pointer); void ro_gui_save_drag_end(wimp_dragged *drag); @@ -242,12 +216,12 @@ void ro_gui_debugwin_close(void); void ro_gui_debugwin_redraw(wimp_draw *redraw); /* in search.c */ -void ro_gui_search_open(struct gui_window *g, int x, int y, bool sub_menu, bool keypress); +void ro_gui_search_prepare(struct gui_window *g); void ro_gui_search_click(wimp_pointer *pointer); bool ro_gui_search_keypress(wimp_key *key); /* in print.c */ -void ro_gui_print_open(struct gui_window *g, int x, int y, bool sub_menu, bool keypress); +void ro_gui_print_prepare(struct gui_window *g); void ro_gui_print_click(wimp_pointer *pointer); bool ro_gui_print_keypress(wimp_key *key); @@ -434,4 +408,8 @@ void ro_gui_theme_install_click(wimp_pointer *pointer); #define ICON_THEME_INSTALL_INSTALL 1 #define ICON_THEME_INSTALL_CANCEL 2 +#define ICON_OPENURL_URL 1 +#define ICON_OPENURL_CANCEL 2 +#define ICON_OPENURL_OPEN 3 + #endif diff --git a/riscos/help.c b/riscos/help.c index 1ee8ca8d7..bc5494c45 100644 --- a/riscos/help.c +++ b/riscos/help.c @@ -9,20 +9,22 @@ * Interactive help (implementation). */ -#include <assert.h> +#include <stdbool.h> #include <stdio.h> -#include <string.h> #include "oslib/help.h" #include "oslib/os.h" #include "oslib/taskmanager.h" #include "oslib/wimp.h" +#include "netsurf/desktop/tree.h" #include "netsurf/riscos/global_history.h" #include "netsurf/riscos/gui.h" #include "netsurf/riscos/help.h" +#include "netsurf/riscos/menus.h" #include "netsurf/riscos/theme.h" #include "netsurf/riscos/wimp.h" #include "netsurf/utils/messages.h" #include "netsurf/utils/log.h" +#include "netsurf/utils/utils.h" /* Recognised help keys @@ -44,29 +46,36 @@ HelpHotEntry Hotlist entry window HelpHotFolder Hotlist entry window HelpGHistory Global history window [*] - HelpGHistoryToolbar Global history window toolbar + HelpGHistToolbar Global history window toolbar + HelpEditToolbar Toolbars in edit mode HelpIconMenu Iconbar menu - HelpBrowserMenu Browser window menu - HelpHotlistMenu Hotlist window menu - - The prefixes are followed by either the icon number (eg 'HelpToolbar7'), or a series - of numbers representing the menu structure (eg 'HelpBrowserMenu3-1-2'). - If '<key><identifier>' is not available, then simply '<key>' is then used. For example - if 'HelpToolbar7' is not available then 'HelpToolbar' is then tried. - - If an item is greyed out then a suffix of 'g' is added (eg 'HelpToolbar7g'). For this to - work, windows must have bit 4 of the window flag byte set and the user must be running - RISC OS 5.03 or greater. - - For items marked with an asterisk [*] a call must be made to determine the required - help text as the window does not contain any icons. An example of this is the hotlist - window where ro_gui_hotlist_help() is called. + HelpBrowserMenu Browser window menu + HelpHotlistMenu Hotlist window menu + HelpGHistoryMenu Global history window menu + + The prefixes are followed by either the icon number (eg 'HelpToolbar7'), + or a series of numbers representing the menu structure (eg + 'HelpBrowserMenu3-1-2'). + If '<key><identifier>' is not available, then simply '<key>' is then + used. For example if 'HelpToolbar7' is not available then 'HelpToolbar' + is then tried. + If an item is greyed out then a suffix of 'g' is added (eg + 'HelpToolbar7g'). For this to work, windows must have bit 4 of the + window flag byte set and the user must be running RISC OS 5.03 or + greater. + For items marked with an asterisk [*] a call must be made to determine + the required help text as the window does not contain any icons. An + example of this is the hotlist window where ro_gui_hotlist_help() is + called. */ -static void ro_gui_interactive_help_broadcast(wimp_message *message, char *token); + +static void ro_gui_interactive_help_broadcast(wimp_message *message, + char *token); static os_t help_time = 0; + /** * Attempts to process an interactive help message request * @@ -80,135 +89,136 @@ void ro_gui_interactive_help_request(wimp_message *message) { wimp_w window; wimp_i icon; struct gui_window *g; + struct toolbar *toolbar = NULL; unsigned int index; bool greyed = false; wimp_menu *test_menu; + os_error *error; - /* Ensure we have a help request - */ - if ((!message) || (message->action != message_HELP_REQUEST)) return; + /* only accept help requests */ + if ((!message) || (message->action != message_HELP_REQUEST)) + return; - /* Remember the time of the request - */ + /* remember the time of the request so we can track them */ xos_read_monotonic_time(&help_time); - /* Initialise the basic token to a null byte - */ + /* set up our state */ message_token[0] = 0x00; - - /* Get the message data - */ message_data = (help_full_message_request *)message; window = message_data->w; icon = message_data->i; - /* Do the basic window checks - */ - if (window == (wimp_w)-2) { + /* do the basic window checks */ + if (window == wimp_ICON_BAR) sprintf(message_token, "HelpIconbar"); - } else if (window == dialog_info) { + else if (window == dialog_info) sprintf(message_token, "HelpAppInfo%i", (int)icon); - } else if (window == history_window) { + else if (window == history_window) sprintf(message_token, "HelpHistory%i", (int)icon); - } else if (window == dialog_objinfo) { + else if (window == dialog_objinfo) sprintf(message_token, "HelpObjInfo%i", (int)icon); - } else if (window == dialog_pageinfo) { + else if (window == dialog_pageinfo) sprintf(message_token, "HelpPageInfo%i", (int)icon); - } else if (window == dialog_saveas) { + else if (window == dialog_saveas) sprintf(message_token, "HelpSaveAs%i", (int)icon); - } else if (window == dialog_zoom) { + else if (window == dialog_zoom) sprintf(message_token, "HelpScaleView%i", (int)icon); - } else if (window == dialog_folder) { + else if (window == dialog_folder) sprintf(message_token, "HelpHotFolder%i", (int)icon); - } else if (window == dialog_entry) { + else if (window == dialog_entry) sprintf(message_token, "HelpHotEntry%i", (int)icon); - } else if ((hotlist_tree) && (window == (wimp_w)hotlist_tree->handle)) { + else if ((hotlist_tree) && (window == (wimp_w)hotlist_tree->handle)) sprintf(message_token, "HelpHotlist%i", ro_gui_hotlist_help(message_data->pos.x, message_data->pos.y)); - } else if ((hotlist_tree) && (hotlist_tree->toolbar) && - (window == hotlist_tree->toolbar->toolbar_handle)) { - sprintf(message_token, "HelpHotToolbar%i", (int)icon); - } else if ((global_history_tree) && (window == (wimp_w)global_history_tree->handle)) { + else if ((global_history_tree) && + (window == (wimp_w)global_history_tree->handle)) sprintf(message_token, "HelpGHistory%i", ro_gui_global_history_help(message_data->pos.x, message_data->pos.y)); + else if ((hotlist_tree) && (hotlist_tree->toolbar) && + ((window == hotlist_tree->toolbar->toolbar_handle) || + ((hotlist_tree->toolbar->editor) && + (window == hotlist_tree->toolbar-> + editor->toolbar_handle)))) { + toolbar = hotlist_tree->toolbar; + sprintf(message_token, "HelpHotToolbar%i", (int)icon); } else if ((global_history_tree) && (global_history_tree->toolbar) && - (window == global_history_tree->toolbar->toolbar_handle)) { - sprintf(message_token, "HelpGHistoryToolbar%i", (int)icon); - } else if ((g = ro_gui_window_lookup(window)) != NULL) { + ((window == global_history_tree->toolbar-> + toolbar_handle) || + ((global_history_tree->toolbar->editor) && + (window == global_history_tree->toolbar-> + editor->toolbar_handle)))) { + toolbar = global_history_tree->toolbar; + sprintf(message_token, "HelpGHistToolbar%i", (int)icon); + } else if ((g = ro_gui_window_lookup(window)) != NULL) sprintf(message_token, "HelpBrowser%i", (int)icon); - } else if ((g = ro_gui_toolbar_lookup(window)) != NULL) { + else if ((g = ro_gui_toolbar_lookup(window)) != NULL) { + toolbar = g->toolbar; sprintf(message_token, "HelpToolbar%i", (int)icon); - } else if ((g = ro_gui_status_lookup(window)) != NULL) { + } else if ((g = ro_gui_status_lookup(window)) != NULL) sprintf(message_token, "HelpStatus%i", (int)icon); + + /* change toolbars to editors where appropriate */ + if ((toolbar) && (toolbar->editor)) + sprintf(message_token, "HelpEditToolbar%i", (int)icon); + + /* if we've managed to find something so far then we broadcast it */ + if (message_token[0]) { + if ((icon >= 0) && + (ro_gui_get_icon_shaded_state(window, icon))) + strcat(message_token, "g"); + ro_gui_interactive_help_broadcast(message, + (char *)message_token); + return; } - /* If we've managed to find something so far then we broadcast it - */ - if (message_token[0] != 0x00) { - /* Check to see if we are greyed out - */ - if ((icon >= 0) && (ro_gui_get_icon_shaded_state(window, icon))) { - strcat(message_token, "g"); - } + /* if we are not on an icon, we can't be in a menu (which stops + * separators giving help for their parent) so we abort */ + if (icon == wimp_ICON_WINDOW) + return; - /* Broadcast out message - */ - ro_gui_interactive_help_broadcast(message, &message_token[0]); + /* get the current menu tree */ + error = xwimp_get_menu_state(wimp_GIVEN_WINDOW_AND_ICON, + &menu_tree, window, icon); + if (error) { + LOG(("xwimp_get_menu_state: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); return; } + if (menu_tree.items[0] == -1) + return; - /* If we are not on an icon, we can't be in a menu (which stops separators - giving help for their parent) so we abort. You don't even want to think - about the awful hack I was considering before I realised this... - */ - if (icon == (wimp_i)-1) return; - - /* As a last resort, check for menu help. - */ - if (xwimp_get_menu_state((wimp_menu_state_flags)1, - &menu_tree, - window, icon)) return; - if (menu_tree.items[0] == -1) return; - - /* Set the prefix - */ - if (current_menu == iconbar_menu) { + /* get the menu prefix */ + if (current_menu == iconbar_menu) sprintf(message_token, "HelpIconMenu"); - } else if (current_menu == browser_menu) { + else if (current_menu == browser_menu) sprintf(message_token, "HelpBrowserMenu"); - } else if (current_menu == hotlist_menu) { + else if (current_menu == hotlist_menu) sprintf(message_token, "HelpHotlistMenu"); - } else { + else if (current_menu == global_history_menu) + sprintf(message_token, "HelpGHistoryMenu"); + else return; - } - /* Decode the menu - */ + /* decode the menu */ index = 0; test_menu = current_menu; while (menu_tree.items[index] != -1) { - /* Check if we're greyed out - */ - greyed |= test_menu->entries[menu_tree.items[index]].icon_flags & wimp_ICON_SHADED; + greyed |= test_menu->entries[menu_tree.items[index]].icon_flags + & wimp_ICON_SHADED; test_menu = test_menu->entries[menu_tree.items[index]].sub_menu; - - /* Continue adding the entries - */ - if (index == 0) { + if (index == 0) sprintf(menu_buffer, "%i", menu_tree.items[index]); - } else { + else sprintf(menu_buffer, "-%i", menu_tree.items[index]); - } strcat(message_token, menu_buffer); index++; } - if (greyed) strcat(message_token, "g"); - - /* Finally, broadcast the menu help - */ - ro_gui_interactive_help_broadcast(message, &message_token[0]); + if (greyed) + strcat(message_token, "g"); + ro_gui_interactive_help_broadcast(message, (char *)message_token); } @@ -218,55 +228,53 @@ void ro_gui_interactive_help_request(wimp_message *message) { * \param message the original request message * \param token the token to look up */ -static void ro_gui_interactive_help_broadcast(wimp_message *message, char *token) { +static void ro_gui_interactive_help_broadcast(wimp_message *message, + char *token) { const char *translated_token; help_full_message_reply *reply; char *base_token; + os_error *error; - /* Start off with an empty reply - */ + /* start off with an empty reply */ reply = (help_full_message_reply *)message; reply->reply[0] = '\0'; - /* Check if the message exists - */ + /* check if the message exists */ translated_token = messages_get(token); if (translated_token == token) { - /* We must never provide default help for a 'g' suffix. - */ + /* no default help for 'g' suffix */ if (token[strlen(token) - 1] != 'g') { - /* Find the key from the token. - */ + /* find the base key from the token */ base_token = token; while (base_token[0] != 0x00) { if ((base_token[0] == '-') || - ((base_token[0] >= '0') && (base_token[0] <= '9'))) { + ((base_token[0] >= '0') && + (base_token[0] <= '9'))) base_token[0] = 0x00; - } else { + else ++base_token; - } } - - /* Check if the base key exists and use an empty string if not - */ translated_token = messages_get(token); } } - - /* Copy our message string - */ + /* copy our message string */ if (translated_token != token) { reply->reply[235] = 0; strncpy(reply->reply, translated_token, 235); } - /* Broadcast the help reply - */ + /* broadcast the help reply */ reply->size = 256; reply->action = message_HELP_REPLY; reply->your_ref = reply->my_ref; - wimp_send_message(wimp_USER_MESSAGE, (wimp_message *)reply, reply->sender); + error = xwimp_send_message(wimp_USER_MESSAGE, (wimp_message *)reply, + reply->sender); + if (error) { + LOG(("xwimp_send_message: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + } } @@ -275,34 +283,80 @@ static void ro_gui_interactive_help_broadcast(wimp_message *message, char *token * * \return non-zero if interactive help is available, or 0 if not available */ -int ro_gui_interactive_help_available() { +bool ro_gui_interactive_help_available(void) { taskmanager_task task; int context = 0; - char *end; os_t time; + os_error *error; - /* Check if we've received a help request in the last 1.0s to test for generic - interactive help applications - */ + /* generic test: any help request within the last 100cs */ xos_read_monotonic_time(&time); - if ((help_time + 100) > time) return true; + if ((help_time + 100) > time) + return true; - /* Attempt to find the task 'Help' - */ + /* special cases: check known application names */ do { - if (xtaskmanager_enumerate_tasks(context, &task, sizeof(taskmanager_task), - &context, &end)) return 0; - - /* We can't just use strcmp due to string termination issues. - */ - if (strncmp(task.name, "Help", 4) == 0) { - if (task.name[4] < 32) return true; - } else if (strncmp(task.name, "Floating Help", 13) == 0) { - if (task.name[13] < 32) return true; + error = xtaskmanager_enumerate_tasks(context, &task, + sizeof(taskmanager_task), &context, 0); + if (error) { + LOG(("xtaskmanager_enumerate_tasks: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("MiscError", error->errmess); } + + /* we can't just use strcmp due to string termination issues */ + if (!strncmp(task.name, "Help", 4) && + (task.name[4] < 32)) + return true; + else if (!strncmp(task.name, "Bubble Help", 11) && + (task.name[11] < 32)) + return true; + else if (!strncmp(task.name, "Floating Help", 13) && + (task.name[13] < 32)) + return true; } while (context >= 0); + return false; +} + - /* Return failure - */ - return 0; +/** + * Launches interactive help. + */ +void ro_gui_interactive_help_start(void) { + char *help_start; + wimp_t task = 0; + os_error *error; + + /* launch <Help$Start> */ + help_start = getenv("Help$Start"); + if ((help_start) && (help_start[0])) { + error = xwimp_start_task("<Help$Start>", &task); + if (error) { + LOG(("xwimp_start_tast: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + return; + } + } + + /* first attempt failed, launch !Help */ + if (!task) { + error = xwimp_start_task("Resources:$.Apps.!Help", &task); + if (error) { + LOG(("xwimp_start_tast: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + return; + } + } + + /* pretend we got a help request straight away */ + if (task) { + error = xos_read_monotonic_time(&help_time); + if (error) { + LOG(("xwimp_read_monotonic_time: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + } + } } diff --git a/riscos/help.h b/riscos/help.h index 444dec7c8..544931707 100644 --- a/riscos/help.h +++ b/riscos/help.h @@ -2,7 +2,7 @@ * This file is part of NetSurf, http://netsurf.sourceforge.net/ * Licensed under the GNU General Public License, * http://www.opensource.org/licenses/gpl-license - * Copyright 2004 Richard Wilson <not_ginger_matt@users.sourceforge.net> + * Copyright 2004, 2005 Richard Wilson <info@tinct.net> */ /** \file @@ -12,9 +12,11 @@ #ifndef _NETSURF_RISCOS_HELP_H_ #define _NETSURF_RISCOS_HELP_H_ +#include <stdbool.h> #include "oslib/wimp.h" void ro_gui_interactive_help_request(wimp_message *message); -int ro_gui_interactive_help_available(void); +bool ro_gui_interactive_help_available(void); +void ro_gui_interactive_help_start(void); #endif diff --git a/riscos/hotlist.c b/riscos/hotlist.c index 7cccd635c..61b3d0ea0 100644 --- a/riscos/hotlist.c +++ b/riscos/hotlist.c @@ -25,6 +25,7 @@ #include "netsurf/content/content.h" #include "netsurf/desktop/tree.h" #include "netsurf/riscos/gui.h" +#include "netsurf/riscos/menus.h" #include "netsurf/riscos/theme.h" #include "netsurf/riscos/tinct.h" #include "netsurf/riscos/treeview.h" @@ -85,38 +86,41 @@ struct node *dialog_entry_node; void ro_gui_hotlist_initialise(void) { FILE *fp; - const char *title; + const char *title; os_error *error; struct node *node; /* Create our window */ title = messages_get("Hotlist"); - hotlist_window_definition.title_data.indirected_text.text = strdup(title); + hotlist_window_definition.title_data.indirected_text.text = + strdup(title); hotlist_window_definition.title_data.indirected_text.validation = (char *) -1; - hotlist_window_definition.title_data.indirected_text.size = strlen(title); - error = xwimp_create_window(&hotlist_window_definition, &hotlist_window); + hotlist_window_definition.title_data.indirected_text.size = + strlen(title); + error = xwimp_create_window(&hotlist_window_definition, + &hotlist_window); if (error) { LOG(("xwimp_create_window: 0x%x: %s", error->errnum, error->errmess)); die(error->errmess); } - + /* Either load or create a hotlist */ fp = fopen("Choices:WWW.NetSurf.Hotlist", "r"); if (!fp) { hotlist_tree = calloc(sizeof(struct tree), 1); if (!hotlist_tree) { - warn_user("NoMemory", 0); + warn_user("NoMemory", 0); return; } hotlist_tree->root = tree_create_folder_node(NULL, "Root"); if (!hotlist_tree->root) { - warn_user("NoMemory", 0); - free(hotlist_tree); - hotlist_tree = NULL; + warn_user("NoMemory", 0); + free(hotlist_tree); + hotlist_tree = NULL; } hotlist_tree->root->expanded = true; node = tree_create_folder_node(hotlist_tree->root, "NetSurf"); @@ -127,7 +131,7 @@ void ro_gui_hotlist_initialise(void) { time(NULL), -1, 0); tree_initialise(hotlist_tree); } else { - fclose(fp); + fclose(fp); hotlist_tree = options_load_tree("Choices:WWW.NetSurf.Hotlist"); } if (!hotlist_tree) return; @@ -136,9 +140,11 @@ void ro_gui_hotlist_initialise(void) { /* Create our toolbar */ - hotlist_tree->toolbar = ro_gui_theme_create_toolbar(NULL, THEME_HOTLIST_TOOLBAR); + hotlist_tree->toolbar = ro_gui_theme_create_toolbar(NULL, + THEME_HOTLIST_TOOLBAR); if (hotlist_tree->toolbar) - ro_gui_theme_attach_toolbar(hotlist_tree->toolbar, hotlist_window); + ro_gui_theme_attach_toolbar(hotlist_tree->toolbar, + hotlist_window); } @@ -146,8 +152,8 @@ void ro_gui_hotlist_initialise(void) { * Perform a save to the default file */ void ro_gui_hotlist_save(void) { - os_error *error; - + os_error *error; + if (!hotlist_tree) return; /* Save to our file @@ -162,15 +168,6 @@ void ro_gui_hotlist_save(void) { /** - * Shows the hotlist window. - */ -void ro_gui_hotlist_show(void) { - ro_gui_tree_show(hotlist_tree); - ro_gui_menu_prepare_hotlist(); -} - - -/** * Respond to a mouse click * * \param pointer the pointer state @@ -178,32 +175,10 @@ void ro_gui_hotlist_show(void) { void ro_gui_hotlist_click(wimp_pointer *pointer) { ro_gui_tree_click(pointer, hotlist_tree); if (pointer->buttons == wimp_CLICK_MENU) - ro_gui_create_menu(hotlist_menu, pointer->pos.x, - pointer->pos.y, NULL); + ro_gui_menu_create(hotlist_menu, pointer->pos.x, + pointer->pos.y, pointer->w); else - ro_gui_menu_prepare_hotlist(); -} - - -/** - * Respond to a keypress - * - * \param key the key pressed - */ -bool ro_gui_hotlist_keypress(int key) { - bool result = ro_gui_tree_keypress(key, hotlist_tree); - ro_gui_menu_prepare_hotlist(); - return result; -} - - -/** - * Handles a menu closed event - */ -void ro_gui_hotlist_menu_closed(void) { - ro_gui_tree_menu_closed(hotlist_tree); - current_menu = NULL; - ro_gui_menu_prepare_hotlist(); + ro_gui_menu_prepare_action(pointer->w, TREE_SELECTION, false); } @@ -223,28 +198,31 @@ void hotlist_visited(struct content *content) { * Informs the hotlist that some content has been visited * * \param content the content visited - * \param tree the tree to find the URL data from - * \param node the node to update siblings and children of + * \param tree the tree to find the URL data from + * \param node the node to update siblings and children of */ void ro_gui_hotlist_visited(struct content *content, struct tree *tree, struct node *node) { struct node_element *element; - + for (; node; node = node->next) { if (!node->folder) { element = tree_find_element(node, TREE_ELEMENT_URL); - if ((element) && (!strcmp(element->text, content->url))) { - element->user_data = ro_content_filetype(content); + if ((element) && (!strcmp(element->text, + content->url))) { + element->user_data = + ro_content_filetype(content); element = tree_find_element(node, - TREE_ELEMENT_VISITS); + TREE_ELEMENT_VISITS); if (element) element->user_data += 1; element = tree_find_element(node, TREE_ELEMENT_LAST_VISIT); if (element) element->user_data = time(NULL); - tree_update_URL_node(node); - tree_handle_node_changed(tree, node, true, false); + tree_update_URL_node(node); + tree_handle_node_changed(tree, node, true, + false); } } if (node->child) @@ -256,16 +234,19 @@ void ro_gui_hotlist_visited(struct content *content, struct tree *tree, /** * Prepares the folder dialog contents for a node * - * \param node the node to prepare the dialogue for, or NULL + * \param node the node to prepare the dialogue for, or NULL */ void ro_gui_hotlist_prepare_folder_dialog(struct node *node) { dialog_folder_node = node; if (node) { - ro_gui_set_window_title(dialog_folder, messages_get("EditFolder")); + ro_gui_set_window_title(dialog_folder, + messages_get("EditFolder")); ro_gui_set_icon_string(dialog_folder, 1, node->data.text); } else { - ro_gui_set_window_title(dialog_folder, messages_get("NewFolder")); - ro_gui_set_icon_string(dialog_folder, 1, messages_get("Folder")); + ro_gui_set_window_title(dialog_folder, + messages_get("NewFolder")); + ro_gui_set_icon_string(dialog_folder, 1, + messages_get("Folder")); } } @@ -273,16 +254,16 @@ void ro_gui_hotlist_prepare_folder_dialog(struct node *node) { /** * Prepares the entry dialog contents for a node * - * \param node the node to prepare the dialogue for, or NULL + * \param node the node to prepare the dialogue for, or NULL */ void ro_gui_hotlist_prepare_entry_dialog(struct node *node) { - struct node_element *element; + struct node_element *element; dialog_entry_node = node; if (node) { ro_gui_set_window_title(dialog_entry, messages_get("EditLink")); ro_gui_set_icon_string(dialog_entry, 1, node->data.text); - element = tree_find_element(node, TREE_ELEMENT_URL); + element = tree_find_element(node, TREE_ELEMENT_URL); if (element) ro_gui_set_icon_string(dialog_entry, 3, element->text); else @@ -301,8 +282,8 @@ void ro_gui_hotlist_prepare_entry_dialog(struct node *node) { * \param pointer the pointer state */ void ro_gui_hotlist_dialog_click(wimp_pointer *pointer) { - struct node_element *element; - struct node *node; + struct node_element *element; + struct node *node; char *title = NULL; char *url = NULL; char *old_value; @@ -326,12 +307,14 @@ void ro_gui_hotlist_dialog_click(wimp_pointer *pointer) { if (icon == close_icon) { if (pointer->buttons == wimp_CLICK_SELECT) { ro_gui_dialog_close(pointer->w); - xwimp_create_menu((wimp_menu *)-1, 0, 0); + xwimp_create_menu((wimp_menu *)-1, 0, 0); } else { if (pointer->w == dialog_folder) - ro_gui_hotlist_prepare_folder_dialog(dialog_folder_node); + ro_gui_hotlist_prepare_folder_dialog( + dialog_folder_node); else - ro_gui_hotlist_prepare_entry_dialog(dialog_entry_node); + ro_gui_hotlist_prepare_entry_dialog( + dialog_entry_node); } return; } @@ -353,23 +336,25 @@ void ro_gui_hotlist_dialog_click(wimp_pointer *pointer) { /* Update/insert our data */ if (!node) { - if (pointer->w == dialog_folder) { - dialog_folder_node = tree_create_folder_node(hotlist_tree->root, - title); - node = dialog_folder_node; - } else { - dialog_entry_node = tree_create_URL_node(hotlist_tree->root, - title, url, 0xfaf, time(NULL), -1, 0); - node = dialog_entry_node; - } + if (pointer->w == dialog_folder) { + dialog_folder_node = tree_create_folder_node( + hotlist_tree->root, + title); + node = dialog_folder_node; + } else { + dialog_entry_node = tree_create_URL_node( + hotlist_tree->root, + title, url, 0xfaf, time(NULL), -1, 0); + node = dialog_entry_node; + } tree_handle_node_changed(hotlist_tree, node, true, false); - ro_gui_tree_scroll_visible(hotlist_tree, &node->data); + ro_gui_tree_scroll_visible(hotlist_tree, &node->data); tree_redraw_area(hotlist_tree, node->box.x - NODE_INSTEP, 0, NODE_INSTEP, 16384); } else { if (url) { - element = tree_find_element(node, TREE_ELEMENT_URL); - if (element) { + element = tree_find_element(node, TREE_ELEMENT_URL); + if (element) { old_value = element->text; res = url_normalize(url, &element->text); if (res != URL_FUNC_OK) { @@ -394,8 +379,8 @@ void ro_gui_hotlist_dialog_click(wimp_pointer *pointer) { } if (pointer->buttons == wimp_CLICK_SELECT) { - xwimp_create_menu((wimp_menu *)-1, 0, 0); ro_gui_dialog_close(pointer->w); + ro_gui_menu_closed(); return; } if (pointer->w == dialog_folder) diff --git a/riscos/menus.c b/riscos/menus.c index e354ee8cc..01191b03f 100644 --- a/riscos/menus.c +++ b/riscos/menus.c @@ -14,18 +14,16 @@ #include <stdlib.h> #include <string.h> -#include "oslib/font.h" #include "oslib/os.h" #include "oslib/osgbpb.h" #include "oslib/wimp.h" -#include "oslib/wimpspriteop.h" -#include "netsurf/content/url_store.h" #include "netsurf/desktop/gui.h" #include "netsurf/render/box.h" #include "netsurf/render/form.h" #include "netsurf/riscos/gui.h" #include "netsurf/riscos/global_history.h" #include "netsurf/riscos/help.h" +#include "netsurf/riscos/menus.h" #include "netsurf/riscos/options.h" #include "netsurf/riscos/tinct.h" #include "netsurf/riscos/theme.h" @@ -33,627 +31,362 @@ #include "netsurf/riscos/wimp.h" #include "netsurf/utils/log.h" #include "netsurf/utils/messages.h" -#include "netsurf/utils/url.h" #include "netsurf/utils/utils.h" -/* Menu index definitions used by menu decoding code so that entries can - be quickly commented out. Use -ve numbers below -1 to hide an entry. -*/ -#define MENU_PAGE 0 -#define MENU_OBJECT 1 -#define MENU_SELECTION -2 -#define MENU_NAVIGATE 2 -#define MENU_VIEW 3 -#define MENU_UTILITIES 4 -#define MENU_HELP 5 - -static void translate_menu(wimp_menu *menu); -static void build_languages_menu(void); -static void ro_gui_menu_toolbar_submenu_selection(int index); -static void ro_gui_menu_prepare_images(void); -static void ro_gui_menu_prepare_window(void); -static void ro_gui_menu_prepare_toolbars(struct toolbar *toolbar); -static void ro_gui_menu_prepare_render(void); -static void ro_gui_menu_prepare_help(int forced); -static void ro_gui_menu_prepare_view(void); -static void ro_gui_menu_objectinfo(wimp_message_menu_warning *warning); -static void ro_gui_menu_object_reload(void); -static void ro_gui_menu_browser_warning(wimp_message_menu_warning *warning); -static void ro_gui_menu_hotlist_warning(wimp_message_menu_warning *warning); -static void ro_gui_menu_global_history_warning(wimp_message_menu_warning *warning); - -struct gui_window *current_gui; -wimp_menu *current_menu; -static int current_menu_x, current_menu_y; -static char select_null_text_string[] = "\0"; - -/** Box for object under menu, or 0 if no object. */ -static struct box *gui_menu_object_box = 0; - -/** Menu of options for form select controls. */ -static wimp_menu *gui_form_select_menu = 0; -/** Form control which gui_form_select_menu is for. */ -static struct form_control *gui_form_select_control; - - -/* Default menu item flags -*/ -#define DEFAULT_FLAGS (wimp_ICON_TEXT | wimp_ICON_FILLED | \ - (wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT) | \ - (wimp_COLOUR_WHITE << wimp_ICON_BG_COLOUR_SHIFT)) - - -/* Iconbar menu -*/ -static wimp_MENU(4) ibar_menu = { - { "NetSurf" }, 7,2,7,0, 200, 44, 0, - { - { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Info" } }, - { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "AppHelp" } }, - { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Choices" } }, - { wimp_MENU_LAST, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Quit" } } - } -}; -int iconbar_menu_height = 4 * 44; -wimp_menu *iconbar_menu = (wimp_menu *)&ibar_menu; - - -/* Export submenu -*/ -static wimp_MENU(2) export_menu = { - { "ExportAs" }, 7,2,7,0, 200, 44, 0, - { - { wimp_MENU_GIVE_WARNING, (wimp_menu *)1, DEFAULT_FLAGS, { "Draw" } }, - { wimp_MENU_LAST | wimp_MENU_GIVE_WARNING, (wimp_menu *)1, DEFAULT_FLAGS, { "Text" } } - } -}; - -static wimp_MENU(3) link_menu = { - { "SaveLink" }, 7,2,7,0, 200, 44, 0, - { - { wimp_MENU_GIVE_WARNING, (wimp_menu*)1, DEFAULT_FLAGS, { "URI" } }, - { wimp_MENU_GIVE_WARNING, (wimp_menu*)1, DEFAULT_FLAGS, { "URL" } }, - { wimp_MENU_LAST | wimp_MENU_GIVE_WARNING, (wimp_menu*)1, DEFAULT_FLAGS, { "LinkText" } } - } -}; - - -/* Page submenu -*/ -static wimp_MENU(8) page_menu = { - { "Page" }, 7,2,7,0, 200, 44, 0, - { - { wimp_MENU_GIVE_WARNING, (wimp_menu *)1, DEFAULT_FLAGS, { "PageInfo" } }, - { wimp_MENU_GIVE_WARNING, (wimp_menu *)1, DEFAULT_FLAGS, { "Save" } }, - { wimp_MENU_GIVE_WARNING, (wimp_menu *)1, DEFAULT_FLAGS, { "SaveComp" } }, - { 0, (wimp_menu *)&export_menu, DEFAULT_FLAGS, { "Export" } }, - { 0, (wimp_menu *)&link_menu, DEFAULT_FLAGS, { "SaveURL" } }, - { wimp_MENU_GIVE_WARNING | wimp_MENU_SEPARATE, (wimp_menu *)1, DEFAULT_FLAGS, { "Print" } }, - { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "NewWindow" } }, - { wimp_MENU_LAST, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "ViewSrc" } } - } -}; - - -/* Object export submenu -*/ -static wimp_MENU(2) object_export_menu = { - { "ExportAs" }, 7,2,7,0, 200, 44, 0, - { - { wimp_MENU_LAST | wimp_MENU_GIVE_WARNING, (wimp_menu *)1, DEFAULT_FLAGS, { "Sprite" } } - } -}; - - -/* Object submenu -*/ -static wimp_MENU(5) object_menu = { - { "Object" }, 7,2,7,0, 300, 44, 0, - { - { wimp_MENU_GIVE_WARNING, (wimp_menu *)1, DEFAULT_FLAGS, { "ObjInfo" } }, - { wimp_MENU_GIVE_WARNING, (wimp_menu *)1, DEFAULT_FLAGS, { "ObjSave" } }, - { 0, (wimp_menu *)&object_export_menu, DEFAULT_FLAGS, { "Export" } }, - { wimp_MENU_SEPARATE, (wimp_menu *)&link_menu, DEFAULT_FLAGS, { "SaveURL" } }, - { wimp_MENU_LAST, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "ObjReload" } } - } -}; - - -/* Selection submenu -*/ -static wimp_MENU(3) selection_menu = { - { "Selection" }, 7,2,7,0, 300, 44, 0, - { - { wimp_MENU_SEPARATE, wimp_NO_SUB_MENU, DEFAULT_FLAGS | wimp_ICON_SHADED, { "Copy" } }, - { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS | wimp_ICON_SHADED, { "SelectAll" } }, - { wimp_MENU_LAST, wimp_NO_SUB_MENU, DEFAULT_FLAGS | wimp_ICON_SHADED, { "Clear" } } - } -}; - - -/* Navigate submenu -*/ -static wimp_MENU(5) navigate_menu = { - { "Navigate" }, 7,2,7,0, 300, 44, 0, - { - { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Home" } }, - { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Back" } }, - { wimp_MENU_SEPARATE, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Forward" } }, - { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Reload" } }, - { wimp_MENU_LAST, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Stop" } } - } -}; - - -/* Image submenu -*/ -static wimp_MENU(3) image_menu = { - { "Images" }, 7,2,7,0, 300, 44, 0, - { - { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS | wimp_ICON_SHADED, { "ForeImg" } }, - { wimp_MENU_LAST, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "BackImg" } }, - } -}; - - -/* Toolbar submenu -*/ -static wimp_MENU(4) show_toolbar_menu = { - { "Toolbars" }, 7,2,7,0, 300, 44, 0, - { - { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "ToolButtons" } }, - { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "ToolAddress" } }, - { wimp_MENU_SEPARATE, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "ToolThrob" } }, - { wimp_MENU_LAST, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "ToolStatus" } } - } -}; - - -/* Render submenu -*/ -static wimp_MENU(3) render_menu = { - { "Render" }, 7,2,7,0, 300, 44, 0, - { - { wimp_MENU_SEPARATE, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "RenderText" } }, - { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "RenderAnims" } }, - { wimp_MENU_LAST, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "RenderAll" } } - } -}; - - -/* Window submenu -*/ -static wimp_MENU(4) window_menu = { - { "Window" }, 7,2,7,0, 300, 44, 0, - { - { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "WindowSave" } }, - { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "WindowStagr" } }, - { wimp_MENU_SEPARATE, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "WindowSize" } }, - { wimp_MENU_LAST, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "WindowReset" } } - } -}; - - -/* View submenu -*/ -static wimp_MENU(5) view_menu = { - { "View" }, 7,2,7,0, 300, 44, 0, - { - { wimp_MENU_GIVE_WARNING, (wimp_menu *)1, DEFAULT_FLAGS, { "ScaleView" } }, - { wimp_MENU_GIVE_WARNING, (wimp_menu *)&image_menu, DEFAULT_FLAGS, { "Images" } }, - { wimp_MENU_GIVE_WARNING, (wimp_menu *)&show_toolbar_menu, DEFAULT_FLAGS, { "Toolbars" } }, - { wimp_MENU_GIVE_WARNING | wimp_MENU_SEPARATE, (wimp_menu *)&render_menu, DEFAULT_FLAGS, { "Render" } }, - { wimp_MENU_LAST, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "OptDefault" } } - } -}; - - -/* Hotlist submenu -*/ -static wimp_MENU(2) hotlist_util_menu = { - { "Hotlist" }, 7,2,7,0, 300, 44, 0, - { - { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "HotlistAdd" } }, - { wimp_MENU_LAST, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "HotlistShow" } } - } -}; - - -/* History submenu -*/ -static wimp_MENU(2) history_util_menu = { - { "History" }, 7,2,7,0, 300, 44, 0, - { - { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "HistLocal" } }, - { wimp_MENU_LAST, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "HistGlobal" } } - } -}; - - -/* Utilities submenu -*/ -static wimp_MENU(4) utilities_menu = { - { "Utilities" }, 7,2,7,0, 300, 44, 0, - { - { 0, (wimp_menu *)&hotlist_util_menu, DEFAULT_FLAGS, { "Hotlist" } }, - { 0, (wimp_menu *)&history_util_menu, DEFAULT_FLAGS, { "History" } }, - { wimp_MENU_GIVE_WARNING, (wimp_menu *)1, DEFAULT_FLAGS, { "FindText" } }, - { wimp_MENU_GIVE_WARNING | wimp_MENU_LAST, (wimp_menu *)&window_menu, DEFAULT_FLAGS, { "Window" } }, - } -}; - - -/* Help submenu -*/ -static wimp_MENU(5) help_menu = { - { "Help" }, 7,2,7,0, 300, 44, 0, - { - { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "HelpContent" } }, - { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "HelpGuide" } }, - { wimp_MENU_SEPARATE, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "HelpInfo" } }, - { wimp_MENU_SEPARATE, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "HelpAbout" } }, - { wimp_MENU_LAST, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "HelpInter" } } - } -}; - - -/* Main browser menu -*/ -static wimp_MENU(6) menu = { - { "NetSurf" }, 7,2,7,0, 200, 44, 0, - { - { 0, (wimp_menu *)&page_menu, DEFAULT_FLAGS, { "Page" } }, - { 0, (wimp_menu *)&object_menu, DEFAULT_FLAGS, { "Object" } }, -// { 0, (wimp_menu *)&selection_menu, DEFAULT_FLAGS, { "Selection" } }, - { wimp_MENU_GIVE_WARNING, (wimp_menu *)&navigate_menu, DEFAULT_FLAGS, { "Navigate" } }, - { wimp_MENU_GIVE_WARNING, (wimp_menu *)&view_menu, DEFAULT_FLAGS, { "View" } }, - { 0, (wimp_menu *)&utilities_menu, DEFAULT_FLAGS, { "Utilities" } }, - { wimp_MENU_LAST | wimp_MENU_GIVE_WARNING, (wimp_menu *)&help_menu, DEFAULT_FLAGS, { "Help" } } - } -}; -wimp_menu *browser_menu = (wimp_menu *) &menu; - - - -/* Hotlist new submenu -*/ -static wimp_MENU(2) hotlist_new = { - { "New" }, 7,2,7,0, 300, 44, 0, - { - { wimp_MENU_GIVE_WARNING, (wimp_menu *)1, DEFAULT_FLAGS, { "Folder" } }, - { wimp_MENU_LAST | wimp_MENU_GIVE_WARNING, (wimp_menu *)1, DEFAULT_FLAGS, { "Link" } }, - } -}; - - -/* Hotlist expand submenu -*/ -static wimp_MENU(3) hotlist_expand = { - { "Expand" }, 7,2,7,0, 300, 44, 0, - { - { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "All" } }, - { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Folders" } }, - { wimp_MENU_LAST, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Links" } } - } -}; - -/* Hotlist collapse submenu -*/ -static wimp_MENU(3) hotlist_collapse = { - { "Collapse" }, 7,2,7,0, 300, 44, 0, - { - { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "All" } }, - { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Folders" } }, - { wimp_MENU_LAST, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Links" } } - } +struct ns_menu_entry { + const char *text; /**< menu text (from messages) */ + menu_action action; /**< associated action */ + wimp_w sub_window; /**< sub-window if any */ }; -/* Hotlist file submenu -*/ -static wimp_MENU(5) hotlist_file = { - { "Hotlist" }, 7,2,7,0, 300, 44, 0, - { - { 0, (wimp_menu *)&hotlist_new, DEFAULT_FLAGS, { "New" } }, - { wimp_MENU_GIVE_WARNING | wimp_MENU_SEPARATE, (wimp_menu *)1, DEFAULT_FLAGS, { "Export" } }, - { 0, (wimp_menu *)&hotlist_expand, DEFAULT_FLAGS, { "Expand" } }, - { 0, (wimp_menu *)&hotlist_collapse, DEFAULT_FLAGS, { "Collapse" } }, - { wimp_MENU_LAST | wimp_MENU_GIVE_WARNING, (wimp_menu *)&show_toolbar_menu, DEFAULT_FLAGS, { "Toolbars" } } - } +struct ns_menu { + const char *title; + struct ns_menu_entry entries[1]; }; -/* History file submenu -*/ -static wimp_MENU(4) history_file = { - { "History" }, 7,2,7,0, 300, 44, 0, - { - { wimp_MENU_GIVE_WARNING | wimp_MENU_SEPARATE, (wimp_menu *)1, DEFAULT_FLAGS, { "Export" } }, - { 0, (wimp_menu *)&hotlist_expand, DEFAULT_FLAGS, { "Expand" } }, - { 0, (wimp_menu *)&hotlist_collapse, DEFAULT_FLAGS, { "Collapse" } }, - { wimp_MENU_LAST | wimp_MENU_GIVE_WARNING, (wimp_menu *)&show_toolbar_menu, DEFAULT_FLAGS, { "Toolbars" } } - } -}; - -/* Hotlist file submenu -*/ -static wimp_MENU(4) hotlist_select = { - { "Selection" }, 7,2,7,0, 300, 44, 0, - { - { wimp_MENU_GIVE_WARNING, (wimp_menu *)1, DEFAULT_FLAGS, { "Edit" } }, - { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Launch" } }, - { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Delete" } }, - { wimp_MENU_LAST, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "ResetUsage" } } - } -}; - -/* History file submenu -*/ -static wimp_MENU(4) history_select = { - { "Selection" }, 7,2,7,0, 300, 44, 0, - { - { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Launch" } }, - { wimp_MENU_LAST, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Delete" } }, - } -}; +#define NS_MENU(N) \ + struct { \ + const char *title; \ + struct ns_menu_entry entries[N]; \ + } -/* Hotlist menu -*/ -static wimp_MENU(4) hotlist_root = { - { "Hotlist" }, 7,2,7,0, 200, 44, 0, - { - { 0, (wimp_menu *)&hotlist_file, DEFAULT_FLAGS, { "Hotlist" } }, - { wimp_MENU_GIVE_WARNING, (wimp_menu *)&hotlist_select, DEFAULT_FLAGS, { "Selection" } }, - { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "SelectAll" } }, - { wimp_MENU_LAST, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Clear" } } - } -}; -wimp_menu *hotlist_menu = (wimp_menu *)&hotlist_root; - -/* History menu -*/ -static wimp_MENU(4) history_root = { - { "History" }, 7,2,7,0, 200, 44, 0, - { - { 0, (wimp_menu *)&history_file, DEFAULT_FLAGS, { "History" } }, - { wimp_MENU_GIVE_WARNING, (wimp_menu *)&history_select, DEFAULT_FLAGS, { "Selection" } }, - { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "SelectAll" } }, - { wimp_MENU_LAST, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Clear" } } - } -}; -wimp_menu *global_history_menu = (wimp_menu *)&history_root; - - -/* Proxy auth popup menu (used in proxy Choices dialog) -*/ -static wimp_MENU(3) proxy_menu = { - { "ProxyAuth" }, 7,2,7,0, 200, 44, 0, - { - { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "ProxyNone" } }, - { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "ProxyBasic" } }, - { wimp_MENU_LAST, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "ProxyNTLM" } } - } +struct menu_definition_entry { + menu_action action; /**< menu action */ + wimp_menu_entry *menu_entry; /**< corresponding menu entry */ + struct menu_definition_entry *next; /**< next menu entry */ }; -wimp_menu *proxyauth_menu = (wimp_menu *) &proxy_menu; - - -/* Image display quality popup menu (used in image Choices dialog) -*/ -static wimp_MENU(4) imageq_menu = { - { "Display" }, 7,2,7,0, 200, 44, 0, - { - { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "ImgStyle0" } }, - { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "ImgStyle1" } }, - { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "ImgStyle2" } }, - { wimp_MENU_LAST, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "ImgStyle3" } } - } -}; -wimp_menu *image_quality_menu = (wimp_menu *) &imageq_menu; - -/* Toolbar icon menu -*/ -static wimp_MENU(5) toolbar = { - { "Toolbar" }, 7,2,7,0, 200, 44, 0, - { - { 0, (wimp_menu *)&show_toolbar_menu, DEFAULT_FLAGS, { "Toolbars" } }, - { wimp_MENU_LAST, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "EditToolbar" } } - } +struct menu_definition { + wimp_menu *menu; /**< corresponding menu */ + struct menu_definition_entry *entries; /**< menu entries */ + struct menu_definition *next; /**< next menu */ }; -wimp_menu *toolbar_menu = (wimp_menu *)&toolbar; - -/* Current toolbar -*/ -struct toolbar *current_toolbar; -/* Languages popup menu (used in browser choices dialog) -*/ -wimp_menu *languages_menu = NULL; +static wimp_menu *ro_gui_menu_define_menu(struct ns_menu *menu); +static void ro_gui_menu_define_menu_add(struct menu_definition *definition, + struct ns_menu *menu, int depth, wimp_menu_entry *link, + int first, int last, const char *prefix, int prefix_length); +static struct menu_definition *ro_gui_menu_find_menu(wimp_menu *menu); +static struct menu_definition_entry *ro_gui_menu_find_entry(wimp_menu *menu, + menu_action action); +static menu_action ro_gui_menu_find_action(wimp_menu *menu, + wimp_menu_entry *menu_entry); +static void ro_gui_menu_set_entry_shaded(wimp_menu *menu, menu_action action, + bool shaded); +static void ro_gui_menu_set_entry_ticked(wimp_menu *menu, menu_action action, + bool ticked); +static void ro_gui_menu_get_window_details(wimp_w w, struct gui_window **g, + struct browser_window **bw, struct content **content, + struct toolbar **toolbar, struct tree **tree); +static int ro_gui_menu_get_checksum(void); +static bool ro_gui_menu_prepare_url_suggest(void); +static void ro_gui_menu_prepare_pageinfo(struct gui_window *g); +static void ro_gui_menu_prepare_objectinfo(struct box *box); +static void ro_gui_menu_refresh_toolbar(struct toolbar *toolbar); + + +/* default menu item flags */ +#define DEFAULT_FLAGS (wimp_ICON_TEXT | wimp_ICON_FILLED | \ + (wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT) | \ + (wimp_COLOUR_WHITE << wimp_ICON_BG_COLOUR_SHIFT)) -/* Toolbar menu -*/ -wimp_menu *toolbar_icon_menu = NULL; -/* URL suggestion menu -*/ +/** The currently defined menus to perform actions for */ +static struct menu_definition *ro_gui_menu_definitions; +/** The current menu being worked with (may not be open) */ +wimp_menu *current_menu; +/** Whether a menu is currently open */ +static bool current_menu_open = false; +/** Box for object under menu, or 0 if no object. */ +static struct box *current_menu_object_box = 0; +/** Menu of options for form select controls. */ +static wimp_menu *gui_form_select_menu = 0; +/** Form control which gui_form_select_menu is for. */ +static struct form_control *gui_form_select_control; +/** Window that owns the current menu */ +static wimp_w current_menu_window; +/** The height of the iconbar menu */ +int iconbar_menu_height = 5 * 44; +/** The available menus */ +wimp_menu *iconbar_menu, *browser_menu, *hotlist_menu, *global_history_menu, + *image_quality_menu, *browser_toolbar_menu, + *tree_toolbar_menu, *proxy_auth_menu, *languages_menu; +/** URL suggestion menu */ static wimp_MENU(GLOBAL_HISTORY_RECENT_URLS) url_suggest; wimp_menu *url_suggest_menu = (wimp_menu *)&url_suggest; -static wimp_menu *browser_page_menu = (wimp_menu *)&page_menu; -static wimp_menu *browser_export_menu = (wimp_menu *)&export_menu; -static wimp_menu *browser_object_menu = (wimp_menu *)&object_menu; -static wimp_menu *browser_link_menu = (wimp_menu *)&link_menu; -static wimp_menu *browser_object_export_menu = (wimp_menu *)&object_export_menu; -static wimp_menu *browser_selection_menu = (wimp_menu *)&selection_menu; -static wimp_menu *browser_navigate_menu = (wimp_menu *)&navigate_menu; -static wimp_menu *browser_view_menu = (wimp_menu *)&view_menu; -static wimp_menu *browser_image_menu = (wimp_menu *)&image_menu; -static wimp_menu *browser_toolbar_menu = (wimp_menu *)&show_toolbar_menu; -static wimp_menu *browser_render_menu = (wimp_menu *)&render_menu; -static wimp_menu *browser_window_menu = (wimp_menu *)&window_menu; -static wimp_menu *browser_utilities_menu = (wimp_menu *)&utilities_menu; -static wimp_menu *browser_hotlist_menu = (wimp_menu *)&hotlist_util_menu; -static wimp_menu *browser_history_menu = (wimp_menu *)&history_util_menu; -static wimp_menu *browser_help_menu = (wimp_menu *)&help_menu; - -static wimp_menu *hotlist_new_menu = (wimp_menu *)&hotlist_new; -static wimp_menu *hotlist_expand_menu = (wimp_menu *)&hotlist_expand; -static wimp_menu *hotlist_collapse_menu = (wimp_menu *)&hotlist_collapse; -static wimp_menu *hotlist_file_menu = (wimp_menu *)&hotlist_file; -static wimp_menu *hotlist_select_menu = (wimp_menu *)&hotlist_select; - -static wimp_menu *history_file_menu = (wimp_menu *)&history_file; -static wimp_menu *history_select_menu = (wimp_menu *)&history_select; - /** * Create menu structures. */ - -void ro_gui_menus_init(void) -{ - translate_menu(iconbar_menu); - - translate_menu(browser_menu); - translate_menu(browser_page_menu); - translate_menu(browser_export_menu); - translate_menu(browser_object_menu); - translate_menu(browser_link_menu); - translate_menu(browser_object_export_menu); - translate_menu(browser_selection_menu); - translate_menu(browser_navigate_menu); - translate_menu(browser_view_menu); - translate_menu(browser_image_menu); - translate_menu(browser_toolbar_menu); - translate_menu(browser_render_menu); - translate_menu(browser_window_menu); - translate_menu(browser_utilities_menu); - translate_menu(browser_hotlist_menu); - translate_menu(browser_history_menu); - translate_menu(browser_help_menu); - - translate_menu(hotlist_menu); - translate_menu(hotlist_new_menu); - translate_menu(hotlist_expand_menu); - translate_menu(hotlist_collapse_menu); - translate_menu(hotlist_file_menu); - translate_menu(hotlist_select_menu); - - translate_menu(global_history_menu); - translate_menu(history_file_menu); - translate_menu(history_select_menu); - - - translate_menu(toolbar_menu); - - translate_menu(proxyauth_menu); - - translate_menu(image_quality_menu); - - build_languages_menu(); - - url_suggest_menu->title_data.indirected_text.text = strdup(messages_get("URLSuggest")); - - iconbar_menu->entries[0].sub_menu = (wimp_menu *) dialog_info; - browser_page_menu->entries[0].sub_menu = (wimp_menu*) dialog_pageinfo; - browser_object_menu->entries[0].sub_menu = (wimp_menu*) dialog_objinfo; -// browser_page_menu->entries[1].sub_menu = (wimp_menu *) dialog_saveas; -// browser_page_menu->entries[2].sub_menu = (wimp_menu *) dialog_saveas; -// browser_export_menu->entries[0].sub_menu = (wimp_menu *) dialog_saveas; -// browser_export_menu->entries[1].sub_menu = (wimp_menu *) dialog_saveas; -// browser_view_menu->entries[0].sub_menu = (wimp_menu *) dialog_zoom; -} - - -/** - * Replace text in a menu with message values. - */ - -void translate_menu(wimp_menu *menu) -{ - unsigned int i = 0; - const char *indirected_text; - - /* We can't just blindly set something as indirected as if we use - the fallback messages text (ie the pointer we gave), we overwrite - this data when setting the pointer to the indirected text we - already had. - */ - indirected_text = messages_get(menu->title_data.text); - if (indirected_text != menu->title_data.text) { - menu->title_data.indirected_text.text = strdup(indirected_text); - menu->entries[0].menu_flags |= wimp_MENU_TITLE_INDIRECTED; - - } - - /* items */ - do { - indirected_text = messages_get(menu->entries[i].data.text); - if (indirected_text != menu->entries[i].data.text) { - menu->entries[i].icon_flags |= wimp_ICON_INDIRECTED; - menu->entries[i].data.indirected_text.text = strdup(indirected_text); - menu->entries[i].data.indirected_text.validation = select_null_text_string; - menu->entries[i].data.indirected_text.size = strlen(indirected_text) + 1; - } - i++; - } while ((menu->entries[i - 1].menu_flags & wimp_MENU_LAST) == 0); -} - -/** - * Builds the languages menu based on available translations - */ -void build_languages_menu(void) -{ +void ro_gui_menu_init(void) { int context = 0, read_count, entries = 0; - os_error *e; + os_error *error; osgbpb_INFO(100) info; char lang[8] = {0}; char *lang_name; void *temp; + /* iconbar menu */ + NS_MENU(9) iconbar_definition = { + "NetSurf", { + { "Info", NO_ACTION, dialog_info }, + { "AppHelp", HELP_OPEN_CONTENTS, 0 }, + { "Open", NO_ACTION, 0 }, + { "Open.OpenURL", BROWSER_NAVIGATE_URL, dialog_openurl }, + { "Open.HotlistShow", HOTLIST_SHOW, 0 }, + { "Open.HistGlobal", HISTORY_SHOW_GLOBAL, 0 }, + { "Choices", CHOICES_SHOW, 0 }, + { "Quit", APPLICATION_QUIT, 0 }, + {NULL, 0, 0} + } + }; + iconbar_menu = ro_gui_menu_define_menu( + (struct ns_menu *)&iconbar_definition); + + /* browser menu */ + NS_MENU(66) browser_definition = { + "NetSurf", { + { "Page", BROWSER_PAGE, 0 }, + { "Page.PageInfo",BROWSER_PAGE_INFO, dialog_pageinfo }, + { "Page.Save", BROWSER_SAVE, dialog_saveas }, + { "Page.SaveComp", BROWSER_SAVE_COMPLETE, dialog_saveas }, + { "Page.Export", NO_ACTION, 0 }, + { "Page.Export.Draw", BROWSER_EXPORT_DRAW, dialog_saveas }, + { "Page.Export.Text", BROWSER_EXPORT_TEXT, dialog_saveas }, + { "Page.SaveURL", NO_ACTION, 0 }, + { "Page.SaveURL.URI", BROWSER_SAVE_URL_URI, dialog_saveas }, + { "Page.SaveURL.URL", BROWSER_SAVE_URL_URL, dialog_saveas }, + { "Page.SaveURL.LinkText", BROWSER_SAVE_URL_TEXT, dialog_saveas }, + { "Page.Print_", BROWSER_PRINT, dialog_print }, + { "Page.NewWindow", BROWSER_NEW_WINDOW, 0 }, + { "Page.ViewSrc", BROWSER_VIEW_SOURCE, 0 }, + { "Object", BROWSER_OBJECT, 0 }, + { "Object.ObjInfo", BROWSER_OBJECT_INFO, dialog_objinfo }, + { "Object.ObjSave", BROWSER_OBJECT_SAVE, dialog_saveas }, + { "Object.Export", NO_ACTION, 0 }, + { "Object.Export.Sprite", BROWSER_OBJECT_EXPORT_SPRITE, dialog_saveas }, + { "Object.SaveURL_", NO_ACTION, 0 }, + { "Object.SaveURL.URI", BROWSER_OBJECT_SAVE_URL_URI, dialog_saveas }, + { "Object.SaveURL.URL", BROWSER_OBJECT_SAVE_URL_URL, dialog_saveas }, + { "Object.SaveURL.LinkText", BROWSER_OBJECT_SAVE_URL_TEXT, dialog_saveas }, + { "Object.ObjReload", BROWSER_OBJECT_RELOAD, 0 }, + { "Navigate", NO_ACTION, 0 }, + { "Navigate.Home", BROWSER_NAVIGATE_HOME, 0 }, + { "Navigate.Back", BROWSER_NAVIGATE_BACK, 0 }, + { "Navigate.Forward_", BROWSER_NAVIGATE_FORWARD, 0 }, + { "Navigate.Reload", BROWSER_NAVIGATE_RELOAD_ALL, 0 }, + { "Navigate.Stop", BROWSER_NAVIGATE_STOP, 0 }, + { "View", NO_ACTION, 0 }, + { "View.ScaleView", BROWSER_SCALE_VIEW, dialog_zoom }, + { "View.Images", NO_ACTION, 0 }, + { "View.Images.ForeImg", BROWSER_IMAGES_FOREGROUND, 0 }, + { "View.Images.BackImg", BROWSER_IMAGES_BACKGROUND, 0 }, + { "View.Toolbars", NO_ACTION, 0 }, + { "View.Toolbars.ToolButtons", TOOLBAR_BUTTONS, 0 }, + { "View.Toolbars.ToolAddress", TOOLBAR_ADDRESS_BAR, 0 }, + { "View.Toolbars.ToolThrob", TOOLBAR_THROBBER, 0 }, + { "View.Toolbars.ToolStatus_", TOOLBAR_STATUS_BAR, 0 }, + { "View.Toolbars.EditToolbar", TOOLBAR_EDIT, 0 }, + { "View.Render_", NO_ACTION, 0 }, + { "View.Render.RenderText_", BROWSER_BLEND_TEXT, 0 }, + { "View.Render.RenderAnims", BROWSER_BUFFER_ANIMS, 0 }, + { "View.Render.RenderAll", BROWSER_BUFFER_ALL, 0 }, + { "View.OptDefault", BROWSER_SAVE_VIEW, 0 }, + { "Utilities", NO_ACTION, 0 }, + { "Utilities.Hotlist", HOTLIST_SHOW, 0 }, + { "Utilities.Hotlist.HotlistAdd", HOTLIST_ADD_URL, 0 }, + { "Utilities.Hotlist.HotlistShow", HOTLIST_SHOW, 0 }, + { "Utilities.History", HISTORY_SHOW_GLOBAL, 0 }, + { "Utilities.History.HistLocal", HISTORY_SHOW_LOCAL, 0 }, + { "Utilities.History.HistGlobal", HISTORY_SHOW_GLOBAL, 0 }, + { "Utilities.FindText", BROWSER_FIND_TEXT, dialog_search }, + { "Utilities.Window", NO_ACTION, 0 }, + { "Utilities.Window.WindowSave", BROWSER_WINDOW_DEFAULT, 0 }, + { "Utilities.Window.WindowStagr", BROWSER_WINDOW_STAGGER, 0 }, + { "Utilities.Window.WindowSize_", BROWSER_WINDOW_COPY, 0 }, + { "Utilities.Window.WindowReset", BROWSER_WINDOW_RESET, 0 }, + { "Help", HELP_OPEN_CONTENTS, 0 }, + { "Help.HelpContent", HELP_OPEN_CONTENTS, 0 }, + { "Help.HelpGuide", HELP_OPEN_GUIDE, 0 }, + { "Help.HelpInfo_", HELP_OPEN_INFORMATION, 0 }, + { "Help.HelpAbout_", HELP_OPEN_ABOUT, 0 }, + { "Help.HelpInter", HELP_LAUNCH_INTERACTIVE, 0 }, + {NULL, 0, 0} + } + }; + browser_menu = ro_gui_menu_define_menu( + (struct ns_menu *)&browser_definition); + + /* hotlist menu */ + NS_MENU(24) hotlist_definition = { + "Hotlist", { + { "Hotlist", NO_ACTION, 0 }, + { "Hotlist.New", NO_ACTION, 0 }, + { "Hotlist.New.Folder", TREE_NEW_FOLDER, dialog_folder }, + { "Hotlist.New.Link", TREE_NEW_LINK, dialog_entry }, + { "Hotlist.Export_", HOTLIST_EXPORT, dialog_saveas }, + { "Hotlist.Expand", TREE_EXPAND_ALL, 0 }, + { "Hotlist.Expand.All", TREE_EXPAND_ALL, 0 }, + { "Hotlist.Expand.Folders", TREE_EXPAND_FOLDERS, 0 }, + { "Hotlist.Expand.Links", TREE_EXPAND_LINKS, 0 }, + { "Hotlist.Collapse", TREE_COLLAPSE_ALL, 0 }, + { "Hotlist.Collapse.All", TREE_COLLAPSE_ALL, 0 }, + { "Hotlist.Collapse.Folders", TREE_COLLAPSE_FOLDERS, 0 }, + { "Hotlist.Collapse.Links", TREE_COLLAPSE_LINKS, 0 }, + { "Hotlist.Toolbars", NO_ACTION, 0 }, + { "Hotlist.Toolbars.ToolButtons_", TOOLBAR_BUTTONS, 0 }, + { "Hotlist.Toolbars.EditToolbar", TOOLBAR_EDIT, 0 }, + { "Selection", TREE_SELECTION, 0 }, + { "Selection.Edit", TREE_SELECTION_EDIT, (wimp_w)1 }, + { "Selection.Launch", TREE_SELECTION_LAUNCH, 0 }, + { "Selection.Delete", TREE_SELECTION_DELETE, 0 }, + { "Selection.ResetUsage", TREE_SELECTION_RESET, 0 }, + { "SelectAll", TREE_SELECT_ALL, 0 }, + { "Clear", TREE_CLEAR_SELECTION, 0 }, + {NULL, 0, 0} + } + }; + hotlist_menu = ro_gui_menu_define_menu( + (struct ns_menu *)&hotlist_definition); + + /* history menu */ + NS_MENU(19) global_history_definition = { + "History", { + { "History", NO_ACTION, 0 }, + { "History.Export_", HISTORY_EXPORT, dialog_saveas }, + { "History.Expand", TREE_EXPAND_ALL, 0 }, + { "History.Expand.All", TREE_EXPAND_ALL, 0 }, + { "History.Expand.Folders", TREE_EXPAND_FOLDERS, 0 }, + { "History.Expand.Links", TREE_EXPAND_LINKS, 0 }, + { "History.Collapse", TREE_COLLAPSE_ALL, 0 }, + { "History.Collapse.All", TREE_COLLAPSE_ALL, 0 }, + { "History.Collapse.Folders", TREE_COLLAPSE_FOLDERS, 0 }, + { "History.Collapse.Links", TREE_COLLAPSE_LINKS, 0 }, + { "History.Toolbars", NO_ACTION, 0 }, + { "History.Toolbars.ToolButtons_", TOOLBAR_BUTTONS, 0 }, + { "History.Toolbars.EditToolbar",TOOLBAR_EDIT, 0 }, + { "Selection", TREE_SELECTION, 0 }, + { "Selection.Launch", TREE_SELECTION_LAUNCH, 0 }, + { "Selection.Delete", TREE_SELECTION_DELETE, 0 }, + { "SelectAll", TREE_SELECT_ALL, 0 }, + { "Clear", TREE_CLEAR_SELECTION, 0 }, + {NULL, 0, 0} + } + }; + global_history_menu = ro_gui_menu_define_menu( + (struct ns_menu *)&global_history_definition); + + /* image quality menu */ + NS_MENU(5) images_definition = { + "Display", { + { "ImgStyle0", NO_ACTION, 0 }, + { "ImgStyle1", NO_ACTION, 0 }, + { "ImgStyle2", NO_ACTION, 0 }, + { "ImgStyle3", NO_ACTION, 0 }, + {NULL, 0, 0} + } + }; + image_quality_menu = ro_gui_menu_define_menu( + (struct ns_menu *)&images_definition); + + /* browser toolbar menu */ + NS_MENU(7) browser_toolbar_definition = { + "Toolbar", { + { "Toolbars", NO_ACTION, 0 }, + { "Toolbars.ToolButtons", TOOLBAR_BUTTONS, 0 }, + { "Toolbars.ToolAddress", TOOLBAR_ADDRESS_BAR, 0 }, + { "Toolbars.ToolThrob", TOOLBAR_THROBBER, 0 }, + { "Toolbars.ToolStatus", TOOLBAR_STATUS_BAR, 0 }, + { "EditToolbar", TOOLBAR_EDIT, 0 }, + {NULL, 0, 0} + } + }; + browser_toolbar_menu = ro_gui_menu_define_menu( + (struct ns_menu *)&browser_toolbar_definition); + + /* tree toolbar menu */ + NS_MENU(4) tree_toolbar_definition = { + "Toolbar", { + { "Toolbars", NO_ACTION, 0 }, + { "Toolbars.ToolButtons", TOOLBAR_BUTTONS, 0 }, + { "EditToolbar", TOOLBAR_EDIT, 0 }, + {NULL, 0, 0} + } + }; + tree_toolbar_menu = ro_gui_menu_define_menu( + (struct ns_menu *)&tree_toolbar_definition); + + /* proxy menu */ + NS_MENU(4) proxy_auth_definition = { + "ProxyAuth", { + { "ProxyNone", NO_ACTION, 0 }, + { "ProxyBasic", NO_ACTION, 0 }, + { "ProxyNTLM", NO_ACTION, 0 }, + {NULL, 0, 0} + } + }; + proxy_auth_menu = ro_gui_menu_define_menu( + (struct ns_menu *)&proxy_auth_definition); + + /* special case menus */ + url_suggest_menu->title_data.indirected_text.text = + messages_get("URLSuggest"); + url_suggest_menu->title_fg = wimp_COLOUR_BLACK; + url_suggest_menu->title_bg = wimp_COLOUR_LIGHT_GREY; + url_suggest_menu->work_fg = wimp_COLOUR_BLACK; + url_suggest_menu->work_bg = wimp_COLOUR_WHITE; + url_suggest_menu->width = 200; + url_suggest_menu->height = wimp_MENU_ITEM_HEIGHT; + url_suggest_menu->gap = wimp_MENU_ITEM_GAP; + + /* language menu */ languages_menu = calloc(1, wimp_SIZEOF_MENU(1)); - if (!languages_menu) { - LOG(("No memory for languages menu")); - die("Insufficient memory for languages menu"); - } - languages_menu->title_data.indirected_text.text = strdup(messages_get("Languages")); + if (!languages_menu) + die("Insufficient memory for languages menu."); + languages_menu->title_data.indirected_text.text = + messages_get("Languages"); languages_menu->title_fg = wimp_COLOUR_BLACK; languages_menu->title_bg = wimp_COLOUR_LIGHT_GREY; languages_menu->work_fg = wimp_COLOUR_BLACK; languages_menu->work_bg = wimp_COLOUR_WHITE; - languages_menu->width = 300; - languages_menu->height = 44; - languages_menu->gap = 0; + languages_menu->width = 200; + languages_menu->height = wimp_MENU_ITEM_HEIGHT; + languages_menu->gap = wimp_MENU_ITEM_GAP; while (context != -1) { - e = xosgbpb_dir_entries_info("<NetSurf$Dir>.Resources", (osgbpb_info_list*)&info, 1, - context, sizeof(info), 0, &read_count, &context); - if (e) - die(e->errmess); - - if (read_count == 0) - continue; - - if (info.obj_type != fileswitch_IS_DIR) + error = xosgbpb_dir_entries_info("<NetSurf$Dir>.Resources", + (osgbpb_info_list*)&info, 1, context, + sizeof(info), 0, &read_count, &context); + if (error) + die(error->errmess); + if ((read_count == 0) || (info.obj_type != fileswitch_IS_DIR)) continue; snprintf(lang, sizeof lang, "lang_%2s", info.name); - if ((lang_name = strdup(messages_get(lang))) == NULL || - strlen(info.name) != 2) + /* we can't duplicate the string returned from our messages as + * it causes value->key lookups to fail */ + lang_name = messages_get(lang); + if ((lang_name == lang) || (strlen(info.name) != 2)) continue; - temp = realloc(languages_menu, wimp_SIZEOF_MENU(entries+1)); + temp = realloc(languages_menu, wimp_SIZEOF_MENU(entries + 1)); if (!temp) die("Insufficient memory for languages menu"); languages_menu = temp; languages_menu->entries[entries].menu_flags = 0; languages_menu->entries[entries].sub_menu = wimp_NO_SUB_MENU; - languages_menu->entries[entries].icon_flags = DEFAULT_FLAGS | wimp_ICON_INDIRECTED; - languages_menu->entries[entries].data.indirected_text.text = lang_name; - languages_menu->entries[entries].data.indirected_text.validation = (char *)-1; - languages_menu->entries[entries].data.indirected_text.size = strlen(lang_name) + 1; - + languages_menu->entries[entries].icon_flags = DEFAULT_FLAGS | + wimp_ICON_INDIRECTED; + languages_menu->entries[entries].data.indirected_text.text = + lang_name; + languages_menu->entries[entries].data.indirected_text. + validation = (char *)-1; + languages_menu->entries[entries].data.indirected_text.size = + strlen(lang_name) + 1; entries++; } @@ -663,55 +396,19 @@ void build_languages_menu(void) /** - * Builds the URL suggestion menu - */ -bool ro_gui_menu_prepare_url_suggest(void) { - char **suggest_text; - int suggestions; - int i; - - suggest_text = global_history_get_recent(&suggestions); - if (suggestions < 1) - return false; - - url_suggest_menu->title_fg = wimp_COLOUR_BLACK; - url_suggest_menu->title_bg = wimp_COLOUR_LIGHT_GREY; - url_suggest_menu->work_fg = wimp_COLOUR_BLACK; - url_suggest_menu->work_bg = wimp_COLOUR_WHITE; - url_suggest_menu->width = 300; - url_suggest_menu->height = 44; - url_suggest_menu->gap = 0; - - for (i = 0; i < suggestions; i++) { - url_suggest_menu->entries[i].menu_flags = 0; - url_suggest_menu->entries[i].sub_menu = wimp_NO_SUB_MENU; - url_suggest_menu->entries[i].icon_flags = DEFAULT_FLAGS | wimp_ICON_INDIRECTED; - url_suggest_menu->entries[i].data.indirected_text.text = suggest_text[i]; - url_suggest_menu->entries[i].data.indirected_text.validation = (char *)-1; - url_suggest_menu->entries[i].data.indirected_text.size = strlen(suggest_text[i]) + 1; - } - - url_suggest_menu->entries[0].menu_flags |= wimp_MENU_TITLE_INDIRECTED; - url_suggest_menu->entries[suggestions - 1].menu_flags |= wimp_MENU_LAST; - return true; -} - - -/** * Display a menu. */ -void ro_gui_create_menu(wimp_menu *menu, int x, int y, struct gui_window *g) -{ +void ro_gui_menu_create(wimp_menu *menu, int x, int y, wimp_w w) { int doc_x, doc_y; wimp_window_state state; + struct gui_window *g; os_error *error; + int i; + menu_action action; - current_gui = g; - - if (menu == browser_menu) { - assert(g); - - state.w = g->window; + /* read the object under the pointer for a new gui_window menu */ + if ((!current_menu) && (menu == browser_menu)) { + state.w = w; error = xwimp_get_window_state(&state); if (error) { LOG(("xwimp_get_window_state: 0x%x: %s", @@ -720,55 +417,45 @@ void ro_gui_create_menu(wimp_menu *menu, int x, int y, struct gui_window *g) return; } + g = ro_gui_window_lookup(w); + assert(g); + doc_x = window_x_units(x, &state) / 2 / g->option.scale; doc_y = -window_y_units(y, &state) / 2 / g->option.scale; - gui_menu_object_box = 0; + current_menu_object_box = NULL; if (g->bw->current_content && - g->bw->current_content->type == CONTENT_HTML) { - gui_menu_object_box = box_object_at_point( + g->bw->current_content->type == CONTENT_HTML) + current_menu_object_box = box_object_at_point( g->bw->current_content, doc_x, doc_y); - } + } - if (!hotlist_tree) - browser_utilities_menu->entries[0].icon_flags |= - wimp_ICON_SHADED; - if (gui_menu_object_box) - menu->entries[1].icon_flags &= ~wimp_ICON_SHADED; - else - menu->entries[1].icon_flags |= wimp_ICON_SHADED; - if ((current_gui->bw) && (current_gui->bw->current_content)) { - menu->entries[0].icon_flags &= ~wimp_ICON_SHADED; - } else { - menu->entries[0].icon_flags |= wimp_ICON_SHADED; - } - current_toolbar = g->toolbar; - - } else if (menu == toolbar_menu) { - ro_gui_menu_prepare_toolbars(current_toolbar); - toolbar_menu->entries[1].menu_flags &= ~wimp_MENU_TICKED; - if (current_toolbar->editor) - toolbar_menu->entries[1].menu_flags |= wimp_MENU_TICKED; - } else if (menu == hotlist_menu) { - ro_gui_menu_prepare_hotlist(); - current_toolbar = hotlist_tree->toolbar; - } else if (menu == global_history_menu) { - ro_gui_menu_prepare_global_history(); - current_toolbar = global_history_tree->toolbar; - } else if (menu == url_suggest_menu) { + /* store the menu characteristics */ + current_menu = menu; + current_menu_window = w; + + /* prepare the menu state */ + if (menu == url_suggest_menu) { if (!ro_gui_menu_prepare_url_suggest()) return; + } else { + i = 0; + do { + action = ro_gui_menu_find_action(menu, + &menu->entries[i]); + if (action != NO_ACTION) + ro_gui_menu_prepare_action(w, action, false); + } while (!(menu->entries[i++].menu_flags & wimp_MENU_LAST)); } + /* create the menu */ + current_menu_open = true; error = xwimp_create_menu(menu, x - 64, y); if (error) { LOG(("xwimp_create_menu: 0x%x: %s", error->errnum, error->errmess)); warn_user("MenuError", error->errmess); - } else { - current_menu = menu; - current_menu_x = x; - current_menu_y = y; + ro_gui_menu_closed(); } } @@ -777,12 +464,10 @@ void ro_gui_create_menu(wimp_menu *menu, int x, int y, struct gui_window *g) * Display a pop-up menu next to the specified icon. * * \param menu menu to open - * \param w window handle - * \param i icon handle + * \param w window handle + * \param i icon handle */ - -void ro_gui_popup_menu(wimp_menu *menu, wimp_w w, wimp_i i) -{ +void ro_gui_popup_menu(wimp_menu *menu, wimp_w w, wimp_i i) { wimp_window_state state; wimp_icon_state icon_state; os_error *error; @@ -806,798 +491,203 @@ void ro_gui_popup_menu(wimp_menu *menu, wimp_w w, wimp_i i) return; } - ro_gui_create_menu(menu, + ro_gui_menu_create(menu, state.visible.x0 + icon_state.icon.extent.x1 + 64, state.visible.y1 + icon_state.icon.extent.y1 - - state.yscroll, current_gui); + state.yscroll, w); } /** - * Handle menu selection. + * Clean up after a menu has been closed, or forcible close an open menu. */ - -void ro_gui_menu_selection(wimp_selection *selection) -{ - struct node *node; - char url[80]; - wimp_pointer pointer; - wimp_window_state state; +void ro_gui_menu_closed(void) { + struct gui_window *g; + struct browser_window *bw; + struct content *c; + struct toolbar *t; + struct tree *tree; os_error *error; - wimp_get_pointer_info(&pointer); - - if (current_menu == gui_form_select_menu && 0 <= selection->items[0]) { - browser_window_form_select(current_gui->bw, - gui_form_select_control, - selection->items[0]); - - } else if (current_menu == iconbar_menu) { - switch (selection->items[0]) { - case 0: /* Info */ - ro_gui_create_menu((wimp_menu *) dialog_info, - pointer.pos.x, pointer.pos.y, 0); - break; - case 1: /* Help */ - ro_gui_open_help_page("docs"); - break; - case 2: /* Choices */ - ro_gui_dialog_open_config(); - break; - case 3: /* Quit */ - netsurf_quit = true; - break; - } - - } else if (current_menu == url_suggest_menu) { - if (!current_gui) - LOG(("No current GUI")); - else if (selection->items[0] >= 0) { - browser_window_go(current_gui->bw, - url_suggest_menu->entries[selection->items[0]].data.indirected_text.text, 0); - global_history_add_recent(url_suggest_menu->entries[selection->items[0]].data.indirected_text.text); - } - } else if (current_menu == toolbar_menu) { - switch (selection->items[0]) { - case 0: /* Toolbars-> */ - ro_gui_menu_toolbar_submenu_selection(selection->items[1]); - break; - case 1: /* Edit toolbar */ - ro_gui_theme_toggle_edit(current_toolbar); - ro_gui_menu_prepare_toolbars(current_toolbar); - break; - } - } else if (current_menu == hotlist_menu) { - switch (selection->items[0]) { - case 0: /* Hotlist-> */ - switch (selection->items[1]) { - case 0: /* New */ - break; - case 1: /* Export */ - break; - case 2: /* Expand */ - tree_handle_expansion(hotlist_tree, hotlist_tree->root, true, - (selection->items[2] != 2), (selection->items[2] != 1)); - break; - case 3: /* Collapse */ - tree_handle_expansion(hotlist_tree, hotlist_tree->root, false, - (selection->items[2] != 2), (selection->items[2] != 1)); - break; - case 4: /* Toolbars-> */ - ro_gui_menu_toolbar_submenu_selection(selection->items[2]); - break; - } - break; - case 1: /* Selection-> */ - switch (selection->items[1]) { - case 0: /* Edit-> */ - break; - case 1: /* Launch */ - ro_gui_tree_launch_selected(hotlist_tree); - break; - case 2: /* Delete */ - tree_delete_selected_nodes(hotlist_tree, hotlist_tree->root); - break; - case 3: /* Reset usage */ - tree_reset_URL_nodes(hotlist_tree, hotlist_tree->root, true); - break; - } - break; - case 2: /* Select all */ - ro_gui_tree_keypress(1, hotlist_tree); - ro_gui_menu_prepare_hotlist(); - break; - case 3: /* Clear */ - ro_gui_tree_keypress(26, hotlist_tree); - ro_gui_menu_prepare_hotlist(); - break; - } - } else if (current_menu == global_history_menu) { - switch (selection->items[0]) { - case 0: /* Hotlist-> */ - switch (selection->items[1]) { - case 0: /* Export */ - break; - case 1: /* Expand */ - tree_handle_expansion(global_history_tree, global_history_tree->root, true, - (selection->items[2] != 2), (selection->items[2] != 1)); - break; - case 2: /* Collapse */ - tree_handle_expansion(global_history_tree, global_history_tree->root, false, - (selection->items[2] != 2), (selection->items[2] != 1)); - break; - case 3: /* Toolbars-> */ - ro_gui_menu_toolbar_submenu_selection(selection->items[2]); - break; - } - break; - case 1: /* Selection-> */ - switch (selection->items[1]) { - case 0: /* Launch */ - ro_gui_tree_launch_selected(global_history_tree); - break; - case 1: /* Delete */ - tree_delete_selected_nodes(global_history_tree, global_history_tree->root); - break; - } - break; - case 2: /* Select all */ - ro_gui_tree_keypress(1, global_history_tree); - ro_gui_menu_prepare_global_history(); - break; - case 3: /* Clear */ - ro_gui_tree_keypress(26, global_history_tree); - ro_gui_menu_prepare_global_history(); - break; - } - } else if (current_menu == browser_menu) { - struct content *c = current_gui->bw->current_content; - switch (selection->items[0]) { - case MENU_PAGE: - switch (selection->items[1]) { - case 0: /* Info */ - break; - case 1: /* Save */ - break; - case 2: /* Full save */ - break; - case 3: /* Export */ - break; - case 4: /* Save location */ - switch (selection->items[2]) { - case 0: /* URI */ - break; - case 1: /* URL */ - break; - case 2: /* Text */ - break; - } - break; - case 5: /* Print */ - break; - case 6: /* New window */ - browser_window_create(current_gui->bw->current_content->url, - current_gui->bw, 0); - break; - case 7: /* Page source */ - ro_gui_view_source(c); - break; - } - break; - case MENU_OBJECT: - if (!gui_menu_object_box) - break; - switch (selection->items[1]) { - case 0: /* Info */ - break; - case 1: /* Save */ - break; - case 2: /* Export */ - break; - case 3: /* Save Link */ - switch (selection->items[2]) { - case 0: /* URI */ - break; - case 1: /* URL */ - break; - case 2: /* Text */ - break; - } - break; - case 4: /* Reload */ - ro_gui_menu_object_reload(); - break; - } - break; - case MENU_SELECTION: - switch (selection->items[1]) { - case 0: /* Copy to clipboard */ - ro_gui_copy_selection(current_gui); - break; - case 1: /* Select all */ - break; - case 2: /* Clear */ - break; - } - break; - case MENU_NAVIGATE: - switch (selection->items[1]) { - case 0: /* Home */ - if (option_homepage_url && option_homepage_url[0]) { - browser_window_go(current_gui->bw, option_homepage_url, 0); - } else { - snprintf(url, sizeof url, - "file:/<NetSurf$Dir>/Docs/intro_%s", - option_language); - browser_window_go(current_gui->bw, url, 0); - } - break; - case 1: /* Back */ - history_back(current_gui->bw, - current_gui->bw->history); - ro_gui_prepare_navigate(current_gui); - break; - case 2: /* Forward */ - history_forward(current_gui->bw, - current_gui->bw->history); - ro_gui_prepare_navigate(current_gui); - break; - case 3: /* Reload */ - browser_window_reload(current_gui->bw, false); - break; - case 4: /* Stop */ - browser_window_stop(current_gui->bw); - break; - } - break; - case MENU_VIEW: - switch (selection->items[1]) { - case 0: /* Scale view */ - ro_gui_menu_prepare_scale(); - ro_gui_dialog_open_persistant(current_gui->window, dialog_zoom, false); - break; - case 1: /* Images -> */ - switch (selection->items[2]) { - case 0: - break; - case 1: - current_gui->option.background_images = - !current_gui->option.background_images; - break; - } - ro_gui_menu_prepare_images(); - gui_window_redraw_window(current_gui); - break; - case 2: /* Toolbars-> */ - ro_gui_menu_toolbar_submenu_selection(selection->items[2]); - break; - case 3: /* Render -> */ - switch (selection->items[2]) { - case 0: - current_gui->option.background_blending = - !current_gui->option.background_blending; - gui_window_redraw_window(current_gui); - break; - case 1: - current_gui->option.buffer_animations = - !current_gui->option.buffer_animations; - break; - case 2: - current_gui->option.buffer_everything = - !current_gui->option.buffer_everything; - break; - } - ro_gui_menu_prepare_render(); - break; - case 4: /* Make default */ - ro_gui_window_default_options(current_gui->bw); - ro_gui_save_options(); - break; - } - break; - case MENU_UTILITIES: - switch (selection->items[1]) { - case 0: /* Hotlist -> */ - switch (selection->items[2]) { - case 0: /* Add to hotlist */ - node = tree_create_URL_node(hotlist_tree->root, - messages_get(current_gui->title), - current_gui->bw->current_content->url, - ro_content_filetype(current_gui->bw->current_content), - time(NULL), -1, 0); - tree_redraw_area(hotlist_tree, node->box.x - NODE_INSTEP, 0, - NODE_INSTEP, 16384); - tree_handle_node_changed(hotlist_tree, node, false, true); - ro_gui_tree_scroll_visible(hotlist_tree, &node->data); - break; - case -1: - case 1: /* Show hotlist */ - ro_gui_hotlist_show(); - break; - } - break; - case 1: /* History -> */ - switch (selection->items[2]) { - case -1: - case 0: /* Local history */ - ro_gui_history_open(current_gui->bw, - current_gui->bw->history, false); - break; - case 1: /* Global history */ - ro_gui_global_history_show(); - break; - } - break; - case 2: /* Find Text -> */ -#ifdef WITH_SEARCH - ro_gui_search_open(current_gui, 0, 0, false, true); -#endif - break; - case 3: /* Window -> */ - switch (selection->items[2]) { - case 0: - ro_gui_screen_size(&option_window_screen_width, - &option_window_screen_height); - state.w = current_gui->window; - error = xwimp_get_window_state(&state); - if (error) { - LOG(("xwimp_get_window_state: 0x%x: %s", - error->errnum, error->errmess)); - warn_user("WimpError", error->errmess); - } - option_window_x = state.visible.x0; - option_window_y = state.visible.y0; - option_window_width = state.visible.x1 - state.visible.x0; - option_window_height = state.visible.y1 - state.visible.y0; - break; - case 1: - option_window_stagger = !option_window_stagger; - break; - case 2: - option_window_size_clone = !option_window_size_clone; - break; - case 3: - option_window_screen_width = 0; - option_window_screen_height = 0; - break; - } - if (selection->items[2] >= 0) - ro_gui_save_options(); - ro_gui_menu_prepare_window(); - break; - } - break; - case MENU_HELP: - switch (selection->items[1]) { - case -1: /* No sub-item */ - case 0: /* Contents */ - ro_gui_open_help_page("docs"); - break; - case 1: /* User guide -> */ - ro_gui_open_help_page("guide"); - break; - case 2: /* User information */ - ro_gui_open_help_page("info"); - break; - case 3: /* About NetSurf */ - browser_window_create("file:/" - "<NetSurf$Dir>/Docs/about", 0, 0); - break; - case 4: /* Interactive help */ - xos_cli("Filer_Run Resources:$.Apps.!Help"); - ro_gui_menu_prepare_help(true); - break; - } - break; - } - } else if (current_menu == proxyauth_menu) { - ro_gui_dialog_proxyauth_menu_selection(selection->items[0]); - } else if (current_menu == image_quality_menu) { - ro_gui_dialog_image_menu_selection(selection->items[0]); - } else if (current_menu == languages_menu) { - ro_gui_dialog_languages_menu_selection(languages_menu-> - entries[selection->items[0]]. - data.indirected_text.text); - } else if (current_menu == font_menu) { - ro_gui_dialog_font_menu_selection(selection->items[0]); + error = xwimp_create_menu(wimp_CLOSE_MENU, 0, 0); + if (error) { + LOG(("xwimp_create_menu: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("MenuError", error->errmess); } - if (pointer.buttons == wimp_CLICK_ADJUST) { - if (current_menu == gui_form_select_menu) - gui_create_form_select_menu(current_gui->bw, - gui_form_select_control); - else - ro_gui_create_menu(current_menu, - current_menu_x, current_menu_y, - current_gui); - } else { - if (current_menu == hotlist_menu) - ro_gui_hotlist_menu_closed(); - else if (current_menu == global_history_menu) - ro_gui_global_history_menu_closed(); - current_menu = NULL; - current_gui = NULL; - } -} + if (!current_menu) + return; + ro_gui_menu_get_window_details(current_menu_window, &g, &bw, &c, &t, &tree); -/** - * Handle a selection for a toolbar submenu - */ -void ro_gui_menu_toolbar_submenu_selection(int index) { - int height; + current_menu = NULL; + current_menu_window = NULL; + current_menu_open = false; - if ((index < 0) || (!current_toolbar)) - return; - switch (index) { - case 0: - current_toolbar->display_buttons = !current_toolbar->display_buttons; - break; - case 1: - current_toolbar->display_url = !current_toolbar->display_url; - break; - case 2: - current_toolbar->display_throbber = !current_toolbar->display_throbber; - break; - case 3: - current_toolbar->display_status = !current_toolbar->display_status; - break; - } - ro_gui_menu_prepare_toolbars(current_toolbar); - current_toolbar->reformat_buttons = true; - height = current_toolbar->height; - ro_gui_theme_process_toolbar(current_toolbar, -1); - if ((index == 1) && (current_toolbar->display_url)) - ro_gui_set_caret_first(current_toolbar->toolbar_handle); - if (current_toolbar->type == THEME_BROWSER_TOOLBAR) { - if ((height != current_toolbar->height) && (current_gui)) - ro_gui_window_update_dimensions(current_gui, - height - current_toolbar->height); - } else if (current_toolbar->type == THEME_HOTLIST_TOOLBAR) { - tree_resized(hotlist_tree); - xwimp_force_redraw((wimp_w)hotlist_tree->handle, 0,-16384, 16384, 16384); - } else if (current_toolbar->type == THEME_HISTORY_TOOLBAR) { - tree_resized(global_history_tree); - xwimp_force_redraw((wimp_w)global_history_tree->handle, 0,-16384, 16384, 16384); - } + if (tree) + ro_gui_tree_menu_closed(tree); + } - /** - * Handle Message_MenuWarning. + * The content has changed, reset object references */ - -void ro_gui_menu_warning(wimp_message_menu_warning *warning) -{ - if (current_menu == browser_menu) - ro_gui_menu_browser_warning(warning); - else if (current_menu == hotlist_menu) - ro_gui_menu_hotlist_warning(warning); - else if (current_menu == global_history_menu) - ro_gui_menu_global_history_warning(warning); +void ro_gui_menu_objects_moved(void) { + gui_form_select_control = NULL; + current_menu_object_box = NULL; + + ro_gui_menu_prepare_action(0, BROWSER_OBJECT, false); + if (current_menu == gui_form_select_menu) + ro_gui_menu_closed(); } /** - * Handle Message_MenuWarning for the browser menu. + * Handle menu selection. */ +void ro_gui_menu_selection(wimp_selection *selection) { + int i, j; + wimp_menu_entry *menu_entry; + menu_action action; + wimp_pointer pointer; + struct gui_window *g = NULL; + wimp_menu *menu; + os_error *error; -void ro_gui_menu_browser_warning(wimp_message_menu_warning *warning) -{ - struct content *c; - struct box *box; - os_error *error = 0; - - c = current_gui->bw->current_content; - - switch (warning->selection.items[0]) { - case MENU_PAGE: /* Page -> */ - switch (warning->selection.items[1]) { - case 0: /* Page info */ - ro_gui_menu_prepare_pageinfo(); - error = xwimp_create_sub_menu( - (wimp_menu *) dialog_pageinfo, - warning->pos.x, warning->pos.y); - break; - - case 1: /* Save */ - ro_gui_save_open(GUI_SAVE_SOURCE, c, true, - warning->pos.x, warning->pos.y, 0, false); - break; - - case 2: /* Save complete */ - ro_gui_save_open(GUI_SAVE_COMPLETE, c, true, - warning->pos.x, warning->pos.y, 0, false); - break; - - case 3: /* Export as -> */ - switch (warning->selection.items[2]) { - case 0: /* Draw */ - ro_gui_save_open(GUI_SAVE_DRAW, c, true, - warning->pos.x, warning->pos.y, - 0, false); - break; - - case 1: /* Text */ - ro_gui_save_open(GUI_SAVE_TEXT, c, true, - warning->pos.x, warning->pos.y, - 0, false); - break; - } - break; - - case 4: /* Save Link */ - switch (warning->selection.items[2]) { - case 0: /* URI */ - ro_gui_save_open(GUI_SAVE_LINK_URI, c, true, - warning->pos.x, warning->pos.y, - 0, false); - break; - - case 1: /* URL */ - ro_gui_save_open(GUI_SAVE_LINK_URL, c, true, - warning->pos.x, warning->pos.y, - 0, false); - break; - - case 2: /* Text */ - ro_gui_save_open(GUI_SAVE_LINK_TEXT, c, true, - warning->pos.x, warning->pos.y, - 0, false); - break; - } - break; - - case 5: /* Print -> */ -#ifdef WITH_PRINT - ro_gui_print_open(current_gui, warning->pos.x, - warning->pos.y, true, false); -#endif - break; - } - break; - - case MENU_OBJECT: /* Object -> */ - /** \todo this is really dumb, the object should be the one - * that the user clicked menu over, not the one that happens to - * be under the menu now */ - box = gui_menu_object_box; - if (!box) - break; - - switch (warning->selection.items[1]) { - case 0: /* Object info */ - ro_gui_menu_objectinfo(warning); - return; - - case 1: /* Save */ - ro_gui_save_open(GUI_SAVE_OBJECT_ORIG, box->object, - true, - warning->pos.x, warning->pos.y, 0, false); - break; - - case 2: /* Export */ - switch (warning->selection.items[2]) { - case 0: /* Sprite */ - ro_gui_save_open(GUI_SAVE_OBJECT_NATIVE, - box->object, true, - warning->pos.x, warning->pos.y, - 0, false); - break; - } - break; - - case 3: /* Save Link */ - switch (warning->selection.items[2]) { - case 0: /* URI */ - ro_gui_save_open(GUI_SAVE_LINK_URI, - box->object, true, - warning->pos.x, warning->pos.y, - 0, false); - break; - - case 1: /* URL */ - ro_gui_save_open(GUI_SAVE_LINK_URL, - box->object, true, - warning->pos.x, warning->pos.y, - 0, false); - break; + assert(current_menu); + assert(current_menu_window); - case 2: /* Text */ - ro_gui_save_open(GUI_SAVE_LINK_TEXT, - box->object, true, - warning->pos.x, warning->pos.y, - 0, false); - break; - } - break; - } - break; - - case MENU_NAVIGATE: /* Navigate -> */ - ro_gui_prepare_navigate(current_gui); - error = xwimp_create_sub_menu(browser_navigate_menu, - warning->pos.x, warning->pos.y); - break; - - case MENU_VIEW: /* View -> */ - switch (warning->selection.items[1]) { - case -1: /* View-> */ - ro_gui_menu_prepare_view(); - if (current_gui->toolbar) - view_menu.entries[2].icon_flags &= ~wimp_ICON_SHADED; - else - view_menu.entries[2].icon_flags |= wimp_ICON_SHADED; - error = xwimp_create_sub_menu((wimp_menu *) browser_view_menu, - warning->pos.x, warning->pos.y); - break; - case 0: /* Scale view -> */ - ro_gui_menu_prepare_scale(); - error = xwimp_create_sub_menu((wimp_menu *) dialog_zoom, - warning->pos.x, warning->pos.y); - break; + /* get the menu entry and associated action */ + menu_entry = ¤t_menu->entries[selection->items[0]]; + for (i = 1; selection->items[i] != -1; i++) + menu_entry = &menu_entry->sub_menu-> + entries[selection->items[i]]; + action = ro_gui_menu_find_action(current_menu, menu_entry); - case 1: /* Images -> */ - ro_gui_menu_prepare_images(); - error = xwimp_create_sub_menu(browser_image_menu, - warning->pos.x, warning->pos.y); - break; - case 2: /* Toolbars -> */ - ro_gui_menu_prepare_toolbars(current_gui->toolbar); - error = xwimp_create_sub_menu(browser_toolbar_menu, - warning->pos.x, warning->pos.y); - break; - case 3: /* Render -> */ - ro_gui_menu_prepare_render(); - error = xwimp_create_sub_menu(browser_render_menu, - warning->pos.x, warning->pos.y); - break; - } - break; + /* perform menu action */ + if (action != NO_ACTION) + ro_gui_menu_handle_action(current_menu_window, action, false); - case MENU_UTILITIES: - switch (warning->selection.items[1]) { - case 0: /* Hotlist -> */ - case 1: /* History -> */ - break; - case 2: /* Find text -> */ -#ifdef WITH_SEARCH - ro_gui_search_open(current_gui, - warning->pos.x, - warning->pos.y, - true, - false); - break; -#endif - case 3: /* Window -> */ - ro_gui_menu_prepare_window(); - error = xwimp_create_sub_menu(browser_window_menu, - warning->pos.x, warning->pos.y); - break; - } - break; - case MENU_HELP: /* Help -> */ - ro_gui_menu_prepare_help(false); - error = xwimp_create_sub_menu(browser_help_menu, - warning->pos.x, warning->pos.y); + /* perform non-automated actions */ + if (current_menu == url_suggest_menu) { + g = ro_gui_toolbar_lookup(current_menu_window); + assert(g); + browser_window_go(g->bw, + url_suggest_menu->entries[selection->items[0]]. + data.indirected_text.text, 0); + global_history_add_recent(url_suggest_menu-> + entries[selection->items[0]]. + data.indirected_text.text); + } else if (current_menu == proxy_auth_menu) { + ro_gui_dialog_proxyauth_menu_selection(selection->items[0]); + } else if (current_menu == image_quality_menu) { + ro_gui_dialog_image_menu_selection(selection->items[0]); + } else if (current_menu == languages_menu) { + ro_gui_dialog_languages_menu_selection(languages_menu-> + entries[selection->items[0]]. + data.indirected_text.text); + } else if (current_menu == font_menu) { + ro_gui_dialog_font_menu_selection(selection->items[0]); + } else if ((current_menu == gui_form_select_menu) && + (selection->items[0] >= 0)) { + g = ro_gui_window_lookup(current_menu_window); + assert(g); + browser_window_form_select(g->bw, + gui_form_select_control, + selection->items[0]); } + /* re-open the menu for Adjust clicks */ + error = xwimp_get_pointer_info(&pointer); if (error) { - LOG(("xwimp_create_sub_menu: 0x%x: %s", + LOG(("xwimp_get_pointer_info: 0x%x: %s", error->errnum, error->errmess)); - warn_user("MenuError", error->errmess); + warn_user("WimpError", error->errmess); + ro_gui_menu_closed(); + return; } -} - - -/** - * Handle Message_MenuWarning for the hotlist menu. - */ -void ro_gui_menu_hotlist_warning(wimp_message_menu_warning *warning) -{ - os_error *error = NULL; - struct node *node; - - switch (warning->selection.items[0]) { - case 0: /* Hotlist-> */ - switch (warning->selection.items[1]) { - case 0: /* New-> */ - switch (warning->selection.items[2]) { - case 0: /* Folder */ - ro_gui_hotlist_prepare_folder_dialog(NULL); - error = xwimp_create_sub_menu( - (wimp_menu *) dialog_folder, - warning->pos.x, warning->pos.y); - break; - case 1: /* Entry */ - ro_gui_hotlist_prepare_entry_dialog(NULL); - error = xwimp_create_sub_menu( - (wimp_menu *) dialog_entry, - warning->pos.x, warning->pos.y); - break; - } - break; - case 1: /* Export-> */ - ro_gui_save_open(GUI_SAVE_HOTLIST_EXPORT_HTML, 0, true, - warning->pos.x, warning->pos.y, 0, false); - break; - case 4: /* Toolbars -> */ - ro_gui_menu_prepare_toolbars(hotlist_tree->toolbar); - error = xwimp_create_sub_menu(browser_toolbar_menu, - warning->pos.x, warning->pos.y); - break; - } - break; - case 1: /* Selection-> */ - switch (warning->selection.items[1]) { - case -1: /* Root */ - ro_gui_menu_prepare_hotlist(); - error = xwimp_create_sub_menu(hotlist_select_menu, - warning->pos.x, warning->pos.y); - break; - case 0: /* Edit-> */ - node = tree_get_selected_node(hotlist_tree->root); - if (!node) - break; - if (node->folder) { - ro_gui_hotlist_prepare_folder_dialog(node); - error = xwimp_create_sub_menu( - (wimp_menu *) dialog_folder, - warning->pos.x, warning->pos.y); - } else { - ro_gui_hotlist_prepare_entry_dialog(node); - error = xwimp_create_sub_menu( - (wimp_menu *) dialog_entry, - warning->pos.x, warning->pos.y); - } - break; - } - break; + if (pointer.buttons != wimp_CLICK_ADJUST) { + ro_gui_menu_closed(); + return; } - if (error) { - LOG(("xwimp_create_sub_menu: 0x%x: %s", - error->errnum, error->errmess)); - warn_user("MenuError", error->errmess); - } + /* re-prepare all the visible enties */ + i = 0; + menu = current_menu; + do { + j = 0; + do { + action = ro_gui_menu_find_action(current_menu, + &menu->entries[j]); + if (action != NO_ACTION) + ro_gui_menu_prepare_action(current_menu_window, + action, false); + } while (!(menu->entries[j++].menu_flags & wimp_MENU_LAST)); + j = selection->items[i++]; + if (j != -1) + menu = menu->entries[j].sub_menu; + } while (j != -1); + + if (current_menu == gui_form_select_menu) + gui_create_form_select_menu(g->bw, + gui_form_select_control); + else + ro_gui_menu_create(current_menu, 0, 0, current_menu_window); } /** - * Handle Message_MenuWarning for the global history menu. + * Handle Message_MenuWarning. */ +void ro_gui_menu_warning(wimp_message_menu_warning *warning) { + int i; + menu_action action; + wimp_menu_entry *menu_entry; + wimp_menu *sub_menu; + os_error *error; + int menu_check; -void ro_gui_menu_global_history_warning(wimp_message_menu_warning *warning) -{ - os_error *error = NULL; - - switch (warning->selection.items[0]) { - case 0: /* History-> */ - switch (warning->selection.items[1]) { - case 0: /* Export-> */ - ro_gui_save_open(GUI_SAVE_HISTORY_EXPORT_HTML, 0, true, - warning->pos.x, warning->pos.y, 0, false); - break; - case 3: /* Toolbars -> */ - ro_gui_menu_prepare_toolbars(hotlist_tree->toolbar); - error = xwimp_create_sub_menu(browser_toolbar_menu, - warning->pos.x, warning->pos.y); - break; - } - break; - case 1: /* Selection-> */ - switch (warning->selection.items[1]) { - case -1: /* Root */ - ro_gui_menu_prepare_global_history(); - error = xwimp_create_sub_menu(history_select_menu, - warning->pos.x, warning->pos.y); - break; - } - break; + assert(current_menu); + assert(current_menu_window); + + /* get the sub-menu of the warning */ + if (warning->selection.items[0] == -1) + return; + menu_entry = ¤t_menu->entries[warning->selection.items[0]]; + for (i = 1; warning->selection.items[i] != -1; i++) + menu_entry = &menu_entry->sub_menu-> + entries[warning->selection.items[i]]; + + /* the values given in PRM 3-157 for how to check menus/windows are + * incorrect so we use a hack of checking if the sub-menu is within + * 256KB of its parent */ + menu_check = abs((int)menu_entry->sub_menu - (int)menu_entry); + if (menu_check < 0x40000) { + sub_menu = menu_entry->sub_menu; + i = 0; + do { + action = ro_gui_menu_find_action(current_menu, + &sub_menu->entries[i]); + if (action != NO_ACTION) + ro_gui_menu_prepare_action(current_menu_window, + action, false); + } while (!(sub_menu->entries[i++].menu_flags & wimp_MENU_LAST)); + } else { + action = ro_gui_menu_find_action(current_menu, menu_entry); + if (action != NO_ACTION) + ro_gui_menu_prepare_action(current_menu_window, + action, true); + /* remove the close icon */ + ro_gui_wimp_update_window_furniture((wimp_w)menu_entry->sub_menu, + wimp_WINDOW_CLOSE_ICON | wimp_WINDOW_BACK_ICON, 0); } + /* open the sub-menu */ + error = xwimp_create_sub_menu(menu_entry->sub_menu, + warning->pos.x, warning->pos.y); if (error) { LOG(("xwimp_create_sub_menu: 0x%x: %s", error->errnum, error->errmess)); @@ -1605,459 +695,120 @@ void ro_gui_menu_global_history_warning(wimp_message_menu_warning *warning) } } -/** - * Update navigate menu status and toolbar icons. - * - * /param gui_window the gui_window to update - */ -void ro_gui_prepare_navigate(struct gui_window *gui) { - struct browser_window *bw; - struct history *h; - struct content *c; - struct toolbar *t; - bool update_menu = ((current_menu == browser_menu) && (current_gui == gui)); - int menu_changed = 0; - unsigned int i; - int suggestions; - wimp_selection selection; - - if (!gui) { - LOG(("Attempt to update a NULL gui_window icon status")); - return; - } - - /* Get the data we need to work with - */ - bw = gui->bw; - h = bw->history; - c = bw->current_content; - t = gui->toolbar; - - /* Get the initial menu state to check for changes - */ - if (update_menu) { - for (i = 0; i < 4; i++) { - if (browser_navigate_menu->entries[i].icon_flags & wimp_ICON_SHADED) { - menu_changed += (1 << i); - } - } - if (menu.entries[0].icon_flags & wimp_ICON_SHADED) menu_changed += (1 << 4); - } - - /* Update the back/forwards icons/buttons - */ - if (update_menu) { - if (history_back_available(h)) { - browser_navigate_menu->entries[1].icon_flags &= ~wimp_ICON_SHADED; - } else { - browser_navigate_menu->entries[1].icon_flags |= wimp_ICON_SHADED; - } - if (history_forward_available(h)) { - browser_navigate_menu->entries[2].icon_flags &= ~wimp_ICON_SHADED; - } else { - browser_navigate_menu->entries[2].icon_flags |= wimp_ICON_SHADED; - } - } - if (t) { - if ((h) && (!t->editor)) { - ro_gui_set_icon_shaded_state(t->toolbar_handle, ICON_TOOLBAR_BACK, - !history_back_available(h)); - ro_gui_set_icon_shaded_state(t->toolbar_handle, ICON_TOOLBAR_FORWARD, - !history_forward_available(h)); - ro_gui_set_icon_shaded_state(t->toolbar_handle, ICON_TOOLBAR_HISTORY, - !(c || history_back_available(h) || history_forward_available(h))); - } else { - ro_gui_set_icon_shaded_state(t->toolbar_handle, ICON_TOOLBAR_BACK, !t->editor); - ro_gui_set_icon_shaded_state(t->toolbar_handle, ICON_TOOLBAR_FORWARD, !t->editor); - ro_gui_set_icon_shaded_state(t->toolbar_handle, ICON_TOOLBAR_HISTORY, !t->editor); - } - ro_gui_set_icon_shaded_state(t->toolbar_handle, ICON_TOOLBAR_BOOKMARK, (!hotlist_tree && !t->editor)); - global_history_get_recent(&suggestions); - ro_gui_set_icon_shaded_state(t->toolbar_handle, ICON_TOOLBAR_SUGGEST, (suggestions <= 0)); - } - - /* Update the stop/refresh icons/buttons - */ - if (bw->current_content && !bw->loading_content) { - if (update_menu) browser_navigate_menu->entries[3].icon_flags &= ~wimp_ICON_SHADED; - if (t) ro_gui_set_icon_shaded_state(t->toolbar_handle, ICON_TOOLBAR_RELOAD, false); - } else { - if (update_menu) browser_navigate_menu->entries[3].icon_flags |= wimp_ICON_SHADED; - if (t) ro_gui_set_icon_shaded_state(t->toolbar_handle, ICON_TOOLBAR_RELOAD, !t->editor); - } - if (bw->loading_content || (bw->current_content && - bw->current_content->status != CONTENT_STATUS_DONE)) { - if (update_menu) browser_navigate_menu->entries[4].icon_flags &= ~wimp_ICON_SHADED; - if (t) ro_gui_set_icon_shaded_state(t->toolbar_handle, ICON_TOOLBAR_STOP, false); - } else { - if (update_menu) browser_navigate_menu->entries[4].icon_flags |= wimp_ICON_SHADED; - if (t) ro_gui_set_icon_shaded_state(t->toolbar_handle, ICON_TOOLBAR_STOP, !t->editor); - } - - /* Set the scale view icon - */ - if (update_menu) { - if (c) - menu.entries[0].icon_flags &= ~wimp_ICON_SHADED; - else - menu.entries[0].icon_flags |= wimp_ICON_SHADED; - } - if (t) { - ro_gui_set_icon_shaded_state(t->toolbar_handle, ICON_TOOLBAR_SEARCH, (!c && !t->editor)); - ro_gui_set_icon_shaded_state(t->toolbar_handle, ICON_TOOLBAR_SCALE, (!c && !t->editor)); - ro_gui_set_icon_shaded_state(t->toolbar_handle, ICON_TOOLBAR_SAVE, (!c && !t->editor)); - ro_gui_set_icon_shaded_state(t->toolbar_handle, ICON_TOOLBAR_PRINT, (!c && !t->editor)); - } - - /* Check if we've changed our menu state - */ - if (update_menu) { - for (i = 0; i < 4; i++) { - if (browser_navigate_menu->entries[i].icon_flags & wimp_ICON_SHADED) { - menu_changed -= (1 << i); - } - } - if (menu.entries[0].icon_flags & wimp_ICON_SHADED) menu_changed -= (1 << 4); - - /* Re-open the submenu - */ - if (menu_changed != 0) { - if (!xwimp_get_menu_state((wimp_menu_state_flags)0, &selection, - (wimp_w)0, (wimp_i)0)) { - if (selection.items[0] == MENU_NAVIGATE) { - ro_gui_create_menu(current_menu, 0, 0, current_gui); - } - - } - } - } -} - /** - * Update image menu status + * Refresh a toolbar after it has been updated + * + * \param toolbar the toolbar to update */ -static void ro_gui_menu_prepare_images(void) { - if (current_menu != browser_menu) return; - - /* Set the options according to the local values - */ - browser_image_menu->entries[1].menu_flags &= ~wimp_MENU_TICKED; - if (current_gui->option.background_images) browser_image_menu->entries[1].menu_flags |= wimp_MENU_TICKED; - browser_image_menu->entries[2].menu_flags &= ~wimp_MENU_TICKED; -} +void ro_gui_menu_refresh_toolbar(struct toolbar *toolbar) { + int height; + assert(toolbar); -/** - * Update render menu status - */ -static void ro_gui_menu_prepare_render(void) { - if (current_menu != browser_menu) return; - - /* Set the options according to the local values - */ - browser_render_menu->entries[1].menu_flags &= ~wimp_MENU_TICKED; - browser_render_menu->entries[1].icon_flags &= ~wimp_ICON_SHADED; - browser_render_menu->entries[2].menu_flags &= ~wimp_MENU_TICKED; - if (current_gui->option.background_blending) { - browser_render_menu->entries[0].menu_flags |= wimp_MENU_TICKED; - } else { - browser_render_menu->entries[0].menu_flags &= ~wimp_MENU_TICKED; - } - if (current_gui->option.buffer_everything) { - browser_render_menu->entries[1].icon_flags |= wimp_ICON_SHADED; - browser_render_menu->entries[1].menu_flags |= wimp_MENU_TICKED; - browser_render_menu->entries[2].menu_flags |= wimp_MENU_TICKED; - } else { - browser_render_menu->entries[1].icon_flags &= ~wimp_ICON_SHADED; - browser_render_menu->entries[2].menu_flags &= ~wimp_MENU_TICKED; - if (current_gui->option.buffer_animations) { - browser_render_menu->entries[1].menu_flags |= wimp_MENU_TICKED; - } else { - browser_render_menu->entries[1].menu_flags &= ~wimp_MENU_TICKED; - } + toolbar->reformat_buttons = true; + height = toolbar->height; + ro_gui_theme_process_toolbar(toolbar, -1); + if (toolbar->type == THEME_BROWSER_TOOLBAR) { + ro_gui_window_update_dimensions( + ro_gui_window_lookup(current_menu_window), + height - toolbar->height); + } else if (toolbar->type == THEME_HOTLIST_TOOLBAR) { + tree_resized(hotlist_tree); + xwimp_force_redraw((wimp_w)hotlist_tree->handle, + 0,-16384, 16384, 16384); + } else if (toolbar->type == THEME_HISTORY_TOOLBAR) { + tree_resized(global_history_tree); + xwimp_force_redraw((wimp_w)global_history_tree->handle, + 0,-16384, 16384, 16384); } } /** - * Update window menu status + * Builds the URL suggestion menu */ -static void ro_gui_menu_prepare_window(void) { - if (current_menu != browser_menu) return; - - /* Check if we can reset - */ - if ((option_window_screen_width != 0) && (option_window_screen_height != 0)) { - browser_window_menu->entries[1].icon_flags &= ~wimp_ICON_SHADED; - browser_window_menu->entries[3].icon_flags &= ~wimp_ICON_SHADED; - - /* Check if we are staggered - */ - if (option_window_stagger) { - browser_window_menu->entries[1].menu_flags |= wimp_MENU_TICKED; - } else { - browser_window_menu->entries[1].menu_flags &= ~wimp_MENU_TICKED; - } - } else { - browser_window_menu->entries[1].menu_flags |= wimp_MENU_TICKED; - browser_window_menu->entries[1].icon_flags |= wimp_ICON_SHADED; - browser_window_menu->entries[3].icon_flags |= wimp_ICON_SHADED; - } - - /* Set if we are cloing the window size - */ - if (option_window_size_clone) { - browser_window_menu->entries[2].menu_flags |= wimp_MENU_TICKED; - } else { - browser_window_menu->entries[2].menu_flags &= ~wimp_MENU_TICKED; - } -} +bool ro_gui_menu_prepare_url_suggest(void) { + char **suggest_text; + int suggestions; + int i; + suggest_text = global_history_get_recent(&suggestions); + if (suggestions < 1) + return false; -/** - * Update toolbar menu status - */ -static void ro_gui_menu_prepare_toolbars(struct toolbar *toolbar) { - int index; - - /* Set our ticks, or shade everything if there's no toolbar - */ - if (toolbar) { - for (index = 0; index < 4; index++) { - browser_toolbar_menu->entries[index].icon_flags &= ~wimp_ICON_SHADED; - browser_toolbar_menu->entries[index].menu_flags &= ~wimp_MENU_TICKED; - } - if (toolbar->editor) { - browser_toolbar_menu->entries[0].icon_flags |= wimp_ICON_SHADED; - browser_toolbar_menu->entries[0].menu_flags |= wimp_MENU_TICKED; - } - if ((toolbar->descriptor) && (toolbar->descriptor->theme)) { - if (toolbar->display_buttons) browser_toolbar_menu->entries[0].menu_flags |= wimp_MENU_TICKED; - if (toolbar->display_throbber) browser_toolbar_menu->entries[2].menu_flags |= wimp_MENU_TICKED; - } else { - for (index = 0; index < 3; index += 2) { - browser_toolbar_menu->entries[index].icon_flags |= wimp_ICON_SHADED; - browser_toolbar_menu->entries[index].menu_flags &= ~wimp_MENU_TICKED; - } - } - if (toolbar->display_url) - browser_toolbar_menu->entries[1].menu_flags |= wimp_MENU_TICKED; - if (toolbar->display_status) - browser_toolbar_menu->entries[3].menu_flags |= wimp_MENU_TICKED; - if (toolbar->type == THEME_BROWSER_TOOLBAR) - browser_toolbar_menu->entries[0].menu_flags &= ~wimp_MENU_LAST; - else - browser_toolbar_menu->entries[0].menu_flags |= wimp_MENU_LAST; - } else { - for (index = 0; index < 4; index++) { - browser_toolbar_menu->entries[index].icon_flags |= wimp_ICON_SHADED; - browser_toolbar_menu->entries[index].menu_flags &= ~wimp_MENU_TICKED; - } - browser_toolbar_menu->entries[0].menu_flags &= ~wimp_MENU_LAST; + for (i = 0; i < suggestions; i++) { + url_suggest_menu->entries[i].menu_flags = 0; + url_suggest_menu->entries[i].sub_menu = wimp_NO_SUB_MENU; + url_suggest_menu->entries[i].icon_flags = + DEFAULT_FLAGS | wimp_ICON_INDIRECTED; + url_suggest_menu->entries[i].data.indirected_text.text = + suggest_text[i]; + url_suggest_menu->entries[i].data.indirected_text.validation = + (char *)-1; + url_suggest_menu->entries[i].data.indirected_text.size = + strlen(suggest_text[i]) + 1; } -} - -/** - * Update scale to current document value - */ -void ro_gui_menu_prepare_scale(void) { - char scale_buffer[8]; - sprintf(scale_buffer, "%.0f", current_gui->option.scale * 100); - ro_gui_set_icon_string(dialog_zoom, ICON_ZOOM_VALUE, scale_buffer); - ro_gui_current_zoom_gui = current_gui; + url_suggest_menu->entries[0].menu_flags |= wimp_MENU_TITLE_INDIRECTED; + url_suggest_menu->entries[suggestions - 1].menu_flags |= wimp_MENU_LAST; + return true; } /** - * Update hotlist menu (all of) + * Update navigate menu status and toolbar icons. + * + * /param gui the gui_window to update */ -void ro_gui_menu_prepare_hotlist(void) { - os_error *error; - bool reopen = false; - bool selection = false; - struct node *single = NULL; - struct toolbar *hotlist_toolbar; - - if (!hotlist_tree) - return; - hotlist_toolbar = hotlist_tree->toolbar; - - if (hotlist_tree->root->child) { - single = tree_get_selected_node(hotlist_tree->root->child); - selection = tree_has_selection(hotlist_tree->root->child); - hotlist_menu->entries[2].icon_flags &= ~wimp_ICON_SHADED; - hotlist_file_menu->entries[2].icon_flags &= ~wimp_ICON_SHADED; - hotlist_file_menu->entries[3].icon_flags &= ~wimp_ICON_SHADED; - } else { - hotlist_menu->entries[2].icon_flags |= wimp_ICON_SHADED; - hotlist_file_menu->entries[2].icon_flags |= wimp_ICON_SHADED; - hotlist_file_menu->entries[3].icon_flags &= wimp_ICON_SHADED; - } - - if (hotlist_toolbar) { - if (hotlist_toolbar->editor) { - ro_gui_set_icon_shaded_state(hotlist_toolbar->toolbar_handle, - ICON_TOOLBAR_OPEN, false); - ro_gui_set_icon_shaded_state(hotlist_toolbar->toolbar_handle, - ICON_TOOLBAR_EXPAND, false); - ro_gui_set_icon_shaded_state(hotlist_toolbar->toolbar_handle, - ICON_TOOLBAR_DELETE, false); - ro_gui_set_icon_shaded_state(hotlist_toolbar->toolbar_handle, - ICON_TOOLBAR_LAUNCH, false); - } else { - ro_gui_set_icon_shaded_state(hotlist_toolbar->toolbar_handle, - ICON_TOOLBAR_OPEN, !hotlist_tree->root->child); - ro_gui_set_icon_shaded_state(hotlist_toolbar->toolbar_handle, - ICON_TOOLBAR_EXPAND, !hotlist_tree->root->child); - ro_gui_set_icon_shaded_state(hotlist_toolbar->toolbar_handle, - ICON_TOOLBAR_DELETE, !selection); - ro_gui_set_icon_shaded_state(hotlist_toolbar->toolbar_handle, - ICON_TOOLBAR_LAUNCH, !selection); - } - } - - if (selection) { - reopen |= (hotlist_menu->entries[1].icon_flags & wimp_ICON_SHADED); - hotlist_menu->entries[1].icon_flags &= ~wimp_ICON_SHADED; - hotlist_menu->entries[3].icon_flags &= ~wimp_ICON_SHADED; - } else { - reopen |= !(hotlist_menu->entries[1].icon_flags & wimp_ICON_SHADED); - hotlist_menu->entries[1].icon_flags |= wimp_ICON_SHADED; - hotlist_menu->entries[3].icon_flags |= wimp_ICON_SHADED; - } - - if (single) { - reopen |= (hotlist_select_menu->entries[0].icon_flags & wimp_ICON_SHADED); - hotlist_select_menu->entries[0].icon_flags &= ~wimp_ICON_SHADED; - } else { - reopen |= !(hotlist_select_menu->entries[0].icon_flags & wimp_ICON_SHADED); - hotlist_select_menu->entries[0].icon_flags |= wimp_ICON_SHADED; - } +void ro_gui_prepare_navigate(struct gui_window *gui) { + int suggestions; - if ((reopen) && (current_menu == hotlist_menu)) { - error = xwimp_create_menu(hotlist_menu, 0, 0); - if (error) { - LOG(("xwimp_create_menu: 0x%x: %s", - error->errnum, error->errmess)); - warn_user("MenuError", error->errmess); - } + ro_gui_menu_prepare_action(gui->window, HOTLIST_SHOW, false); + ro_gui_menu_prepare_action(gui->window, BROWSER_NAVIGATE_STOP, false); + ro_gui_menu_prepare_action(gui->window, BROWSER_NAVIGATE_RELOAD_ALL, false); + ro_gui_menu_prepare_action(gui->window, BROWSER_NAVIGATE_BACK, false); + ro_gui_menu_prepare_action(gui->window, BROWSER_NAVIGATE_FORWARD, false); + ro_gui_menu_prepare_action(gui->window, HOTLIST_SHOW, false); + ro_gui_menu_prepare_action(gui->window, BROWSER_SAVE, false); + ro_gui_menu_prepare_action(gui->window, BROWSER_PRINT, false); + ro_gui_menu_prepare_action(gui->window, BROWSER_SCALE_VIEW, false); + ro_gui_menu_prepare_action(gui->window, BROWSER_FIND_TEXT, false); + + if (gui->toolbar) { + global_history_get_recent(&suggestions); + ro_gui_set_icon_shaded_state(gui->toolbar->toolbar_handle, + ICON_TOOLBAR_SUGGEST, (suggestions <= 0)); } } /** - * Update global history menu (all of) + * Prepare the image quality menu for use + * + * \param tinct_options the options to set the menu status for */ -void ro_gui_menu_prepare_global_history(void) { - os_error *error; - bool reopen = false; - bool selection = false; - struct toolbar *global_history_toolbar; - - if (!global_history_tree) - return; - global_history_toolbar = global_history_tree->toolbar; - - if (global_history_tree->root->child) { - selection = tree_has_selection(global_history_tree->root->child); - global_history_menu->entries[2].icon_flags &= ~wimp_ICON_SHADED; - history_file_menu->entries[1].icon_flags &= ~wimp_ICON_SHADED; - history_file_menu->entries[2].icon_flags &= ~wimp_ICON_SHADED; - } else { - global_history_menu->entries[2].icon_flags |= wimp_ICON_SHADED; - history_file_menu->entries[1].icon_flags |= wimp_ICON_SHADED; - history_file_menu->entries[2].icon_flags |= wimp_ICON_SHADED; - } - - if (global_history_toolbar) { - if (global_history_toolbar->editor) { - ro_gui_set_icon_shaded_state(global_history_toolbar->toolbar_handle, - ICON_TOOLBAR_OPEN, false); - ro_gui_set_icon_shaded_state(global_history_toolbar->toolbar_handle, - ICON_TOOLBAR_EXPAND, false); - ro_gui_set_icon_shaded_state(global_history_toolbar->toolbar_handle, - ICON_TOOLBAR_DELETE, false); - ro_gui_set_icon_shaded_state(global_history_toolbar->toolbar_handle, - ICON_TOOLBAR_LAUNCH, false); - } else { - ro_gui_set_icon_shaded_state(global_history_toolbar->toolbar_handle, - ICON_TOOLBAR_OPEN, !global_history_tree->root->child); - ro_gui_set_icon_shaded_state(global_history_toolbar->toolbar_handle, - ICON_TOOLBAR_EXPAND, !global_history_tree->root->child); - ro_gui_set_icon_shaded_state(global_history_toolbar->toolbar_handle, - ICON_TOOLBAR_DELETE, !selection); - ro_gui_set_icon_shaded_state(global_history_toolbar->toolbar_handle, - ICON_TOOLBAR_LAUNCH, !selection); - } - } - - if (selection) { - reopen |= (global_history_menu->entries[1].icon_flags & wimp_ICON_SHADED); - global_history_menu->entries[1].icon_flags &= ~wimp_ICON_SHADED; - global_history_menu->entries[3].icon_flags &= ~wimp_ICON_SHADED; - } else { - reopen |= !(global_history_menu->entries[1].icon_flags & wimp_ICON_SHADED); - global_history_menu->entries[1].icon_flags |= wimp_ICON_SHADED; - global_history_menu->entries[3].icon_flags |= wimp_ICON_SHADED; - } - - if ((reopen) && (current_menu == global_history_menu)) { - error = xwimp_create_menu(global_history_menu, 0, 0); - if (error) { - LOG(("xwimp_create_menu: 0x%x: %s", - error->errnum, error->errmess)); - warn_user("MenuError", error->errmess); - } - } +void ro_gui_menu_prepare_image_quality(unsigned int tinct_options) { + for (int i = 0; i < 4; i++) + image_quality_menu->entries[i].menu_flags &= ~wimp_MENU_TICKED; + if (tinct_options & tinct_USE_OS_SPRITE_OP) + image_quality_menu->entries[0].menu_flags |= wimp_MENU_TICKED; + else if (tinct_options & tinct_ERROR_DIFFUSE) + image_quality_menu->entries[3].menu_flags |= wimp_MENU_TICKED; + else if (tinct_options & tinct_DITHER) + image_quality_menu->entries[2].menu_flags |= wimp_MENU_TICKED; + else + image_quality_menu->entries[1].menu_flags |= wimp_MENU_TICKED; } /** - * Update the Interactive Help status + * Prepare the page info window for use * - * \parmam force force the status to be disabled + * \param g the gui_window to set the display icons for */ -void ro_gui_menu_prepare_help(int forced) { - if (ro_gui_interactive_help_available() || (forced)) { - browser_help_menu->entries[4].icon_flags |= wimp_ICON_SHADED; - } else { - browser_help_menu->entries[4].icon_flags &= ~wimp_ICON_SHADED; - } -} - -void ro_gui_menu_prepare_view(void) { - if (current_gui->toolbar) { - view_menu.entries[2].icon_flags &= ~wimp_ICON_SHADED; - } else { - view_menu.entries[2].icon_flags |= wimp_ICON_SHADED; - } - if ((current_gui->bw) && (current_gui->bw->current_content)) { - view_menu.entries[0].icon_flags &= ~wimp_ICON_SHADED; - } else { - view_menu.entries[0].icon_flags |= wimp_ICON_SHADED; - } -} - -void ro_gui_menu_prepare_image_quality(unsigned int tinct_options) { - for (int i = 0; i < 4; i++) - image_quality_menu->entries[i].menu_flags &= ~wimp_MENU_TICKED; - if (tinct_options & tinct_USE_OS_SPRITE_OP) { - image_quality_menu->entries[0].menu_flags |= wimp_MENU_TICKED; - } else if (tinct_options & tinct_ERROR_DIFFUSE) { - image_quality_menu->entries[3].menu_flags |= wimp_MENU_TICKED; - } else if (tinct_options & tinct_DITHER) { - image_quality_menu->entries[2].menu_flags |= wimp_MENU_TICKED; - } else { - image_quality_menu->entries[1].menu_flags |= wimp_MENU_TICKED; - } -} - - -void ro_gui_menu_prepare_pageinfo(void) -{ - struct content *c = current_gui->bw->current_content; +void ro_gui_menu_prepare_pageinfo(struct gui_window *g) { + struct content *c = g->bw->current_content; char icon_buf[20] = "file_xxx"; char enc_buf[40]; char enc_token[10] = "Encoding0"; @@ -2067,17 +818,18 @@ void ro_gui_menu_prepare_pageinfo(void) const char *enc = "-"; const char *mime = "-"; - if (c->title != 0) title = c->title; - if (c->url != 0) url = c->url; - if (c->mime_type != 0) mime = c->mime_type; + assert(c); - sprintf(icon_buf, "file_%x", ro_content_filetype(c)); + if (c->title) + title = c->title; + if (c->url) + url = c->url; + if (c->mime_type) + mime = c->mime_type; - /* Ensure the correct icon exists - */ - if (xwimpspriteop_read_sprite_info(icon_buf, 0, 0, 0, 0)) { + sprintf(icon_buf, "file_%x", ro_content_filetype(c)); + if (!ro_gui_wimp_sprite_exists(icon_buf)) sprintf(icon_buf, "file_xxx"); - } if (c->type == CONTENT_HTML) { if (c->data.html.encoding) { @@ -2099,45 +851,33 @@ void ro_gui_menu_prepare_pageinfo(void) } -void ro_gui_menu_objectinfo(wimp_message_menu_warning *warning) -{ +/** + * Prepare the object info window for use + * + * \param box the box to set the display icons for + */ +void ro_gui_menu_prepare_objectinfo(struct box *box) { char icon_buf[20] = "file_xxx"; const char *url = "-"; const char *target = "-"; const char *mime = "-"; - os_error *error; sprintf(icon_buf, "file_%.3x", - ro_content_filetype(gui_menu_object_box->object)); + ro_content_filetype(box->object)); if (!ro_gui_wimp_sprite_exists(icon_buf)) sprintf(icon_buf, "file_xxx"); - if (gui_menu_object_box->object->url) - url = gui_menu_object_box->object->url; - if (gui_menu_object_box->href) - target = gui_menu_object_box->href; - if (gui_menu_object_box->object->mime_type) - mime = gui_menu_object_box->object->mime_type; + if (box->object->url) + url = box->object->url; + if (box->href) + target = box->href; + if (box->object->mime_type) + mime = box->object->mime_type; ro_gui_set_icon_string(dialog_objinfo, ICON_OBJINFO_ICON, icon_buf); ro_gui_set_icon_string(dialog_objinfo, ICON_OBJINFO_URL, url); ro_gui_set_icon_string(dialog_objinfo, ICON_OBJINFO_TARGET, target); ro_gui_set_icon_string(dialog_objinfo, ICON_OBJINFO_TYPE, mime); - - error = xwimp_create_sub_menu((wimp_menu *) dialog_objinfo, - warning->pos.x, warning->pos.y); - if (error) { - LOG(("xwimp_create_sub_menu: 0x%x: %s", - error->errnum, error->errmess)); - warn_user("MenuError", error->errmess); - } -} - - -void ro_gui_menu_object_reload(void) -{ - gui_menu_object_box->object->fresh = false; - browser_window_reload(current_gui->bw, false); } @@ -2147,24 +887,21 @@ void ro_gui_menu_object_reload(void) * \param bw browser window containing form control * \param control form control of type GADGET_SELECT */ - void gui_create_form_select_menu(struct browser_window *bw, - struct form_control *control) -{ + struct form_control *control) { unsigned int i = 0, j; char *text_convert; struct form_option *option; wimp_pointer pointer; os_error *error; + gui_form_select_control = NULL; for (option = control->data.select.items; option; option = option->next) i++; - if (i == 0) return; if (gui_form_select_menu) { - free(gui_form_select_menu->title_data.indirected_text.text); for (j = 0; ; j++) { free(gui_form_select_menu->entries[j].data. indirected_text.text); @@ -2179,11 +916,12 @@ void gui_create_form_select_menu(struct browser_window *bw, gui_form_select_menu = malloc(wimp_SIZEOF_MENU(i)); if (!gui_form_select_menu) { warn_user("NoMemory", 0); + ro_gui_menu_closed(); return; } gui_form_select_menu->title_data.indirected_text.text = - strdup(messages_get("SelectMenu")); + messages_get("SelectMenu"); gui_form_select_menu->title_fg = wimp_COLOUR_BLACK; gui_form_select_menu->title_bg = wimp_COLOUR_LIGHT_GREY; gui_form_select_menu->work_fg = wimp_COLOUR_BLACK; @@ -2208,14 +946,16 @@ void gui_create_form_select_menu(struct browser_window *bw, /* \todo can cnv_str_local_enc() fail? */ gui_form_select_menu->entries[i].data.indirected_text.text = cnv_str_local_enc(option->text); - /* convert spaces to hard spaces to stop things like 'Go Home' being treated - as if 'Home' is a keyboard shortcut and right aligned in the menu. */ - text_convert = gui_form_select_menu->entries[i].data.indirected_text.text - 1; + /* convert spaces to hard spaces to stop things like 'Go Home' + * being treated as if 'Home' is a keyboard shortcut and right + * aligned in the menu. */ + text_convert = gui_form_select_menu->entries[i]. + data.indirected_text.text - 1; while (*++text_convert != '\0') if (*text_convert == 0x20) *text_convert = 0xa0; gui_form_select_menu->entries[i].data.indirected_text. - validation = select_null_text_string; + validation = (char *)-1; gui_form_select_menu->entries[i].data.indirected_text.size = strlen(gui_form_select_menu->entries[i]. data.indirected_text.text) + 1; @@ -2230,10 +970,1050 @@ void gui_create_form_select_menu(struct browser_window *bw, LOG(("xwimp_get_pointer_info: 0x%x: %s", error->errnum, error->errmess)); warn_user("WimpError", error->errmess); + ro_gui_menu_closed(); + return; } - current_gui = bw->window; gui_form_select_control = control; - ro_gui_create_menu(gui_form_select_menu, - pointer.pos.x, pointer.pos.y, bw->window); + ro_gui_menu_create(gui_form_select_menu, + pointer.pos.x, pointer.pos.y, bw->window->window); +} + + +/** + * Creates a wimp_menu and adds it to the list to handle actions for. + * + * \param menu the data to create the menu with + * \return the menu created, or NULL on failure + */ +wimp_menu *ro_gui_menu_define_menu(struct ns_menu *menu) { + struct menu_definition *definition; + int entry; + + definition = calloc(sizeof(struct menu_definition), 1); + if (!definition) + die("No memory to create menu definition."); + + /* link in the menu to our list */ + definition->next = ro_gui_menu_definitions; + ro_gui_menu_definitions = definition; + + /* create our definitions */ + for (entry = 0; menu->entries[entry].text; entry++); + ro_gui_menu_define_menu_add(definition, menu, 0, NULL, + 0, entry, NULL, 0); + return definition->menu; +} + +void ro_gui_menu_define_menu_add(struct menu_definition *definition, + struct ns_menu *menu, int depth, wimp_menu_entry *link, + int first, int last, const char *prefix, int prefix_length) { + int entry, id, cur_depth, new_prefix_length; + int entries = 0; + int matches[last - first + 1]; + const char *match; + char *text, *menu_text, *search; + char *title, *translated; + wimp_menu *new_menu; + struct menu_definition_entry *definition_entry; + + /* step 1: store the matches for depth and subset string */ + for (entry = first; entry < last; entry++) { + cur_depth = 0; + match = menu->entries[entry].text; + if ((prefix) && (strncmp(match, prefix, prefix_length))) + continue; + while (*match) + if (*match++ == '.') + cur_depth++; + if (depth == cur_depth) + matches[entries++] = entry; + } + matches[entries] = last; + + /* step 2: build and link the menu. we must use realloc to stop + * our memory fragmenting so we can test for sub-menus easily */ + if (entries == 0) + return; + new_menu = (wimp_menu *)malloc(wimp_SIZEOF_MENU(entries)); + if (!new_menu) + die("No memory to create menu."); + if (link) { + title = link->data.indirected_text.text; + link->sub_menu = new_menu; + } else { + title = messages_get(menu->title); + if (!title) + die("No memory to translate root menu title"); + definition->menu = new_menu; + } + new_menu->title_data.indirected_text.text = title; + new_menu->title_fg = wimp_COLOUR_BLACK; + new_menu->title_bg = wimp_COLOUR_LIGHT_GREY; + new_menu->work_fg = wimp_COLOUR_BLACK; + new_menu->work_bg = wimp_COLOUR_WHITE; + new_menu->width = 200; + new_menu->height = wimp_MENU_ITEM_HEIGHT; + new_menu->gap = wimp_MENU_ITEM_GAP; + for (entry = 0; entry < entries; entry++) { + /* add the entry */ + id = matches[entry]; + text = strdup(menu->entries[id].text); + if (!text) + die("No memory to examine menu text"); + search = menu_text = text; + while (*search) + if (*search++ == '.') + menu_text = search; + new_menu->entries[entry].menu_flags = 0; + search = menu_text; + while (*search) + if (*search++ == '_') { + new_menu->entries[entry].menu_flags |= + wimp_MENU_SEPARATE; + search[-1] = 0; + break; + } + if (menu->entries[id].sub_window) + new_menu->entries[entry].sub_menu = (wimp_menu *)menu-> + entries[id].sub_window; + else + new_menu->entries[entry].sub_menu = wimp_NO_SUB_MENU; + new_menu->entries[entry].icon_flags = DEFAULT_FLAGS | + wimp_ICON_INDIRECTED; + translated = messages_get(menu_text); + if (translated != menu_text) + free(text); + new_menu->entries[entry].data.indirected_text.text = translated; + new_menu->entries[entry].data.indirected_text.validation = + (char *)-1; + new_menu->entries[entry].data.indirected_text.size = + strlen(translated); + + /* store action */ + if (menu->entries[id].action != NO_ACTION) { + definition_entry = malloc( + sizeof(struct menu_definition_entry)); + if (!definition_entry) + die("Unable to create menu definition entry"); + definition_entry->action = menu->entries[id].action; + definition_entry->menu_entry = + &new_menu->entries[entry]; + definition_entry->next = definition->entries; + definition->entries = definition_entry; + } + + /* recurse */ + if (new_menu->entries[entry].sub_menu == wimp_NO_SUB_MENU) { + new_prefix_length = strlen(menu->entries[id].text); + if (menu->entries[id].text[new_prefix_length - 1] == '_') + new_prefix_length--; + ro_gui_menu_define_menu_add(definition, menu, depth + 1, + &new_menu->entries[entry], + matches[entry], matches[entry + 1], + menu->entries[id].text, + new_prefix_length); + } + + /* give menu warnings */ + if (new_menu->entries[entry].sub_menu != wimp_NO_SUB_MENU) + new_menu->entries[entry].menu_flags |= + wimp_MENU_GIVE_WARNING; + } + new_menu->entries[0].menu_flags |= wimp_MENU_TITLE_INDIRECTED; + new_menu->entries[entries - 1].menu_flags |= wimp_MENU_LAST; +} + + +/** + * Finds the menu_definition corresponding to a wimp_menu. + * + * \param menu the menu to find the definition for + * \return the associated definition, or NULL if one could not be found + */ +struct menu_definition *ro_gui_menu_find_menu(wimp_menu *menu) { + struct menu_definition *definition; + + if (!menu) + return NULL; + + for (definition = ro_gui_menu_definitions; definition; + definition = definition->next) + if (definition->menu == menu) + return definition; + return NULL; +} + + +/** + * Finds the menu_definition_entry corresponding to an action for a wimp_menu. + * + * \param menu the menu to search for an action within + * \param action the action to find + * \return the associated menu entry, or NULL if one could not be found + */ +struct menu_definition_entry *ro_gui_menu_find_entry(wimp_menu *menu, + menu_action action) { + struct menu_definition_entry *entry; + struct menu_definition *definition = ro_gui_menu_find_menu(menu); + + if (!definition) + return NULL; + + for (entry = definition->entries; entry; entry = entry->next) + if (entry->action == action) + return entry; + return NULL; +} + + +/** + * Finds the action corresponding to a wimp_menu_entry for a wimp_menu. + * + * \param menu the menu to search for an action within + * \param menu_entry the menu_entry to find + * \return the associated action, or 0 if one could not be found + */ +menu_action ro_gui_menu_find_action(wimp_menu *menu, wimp_menu_entry *menu_entry) { + struct menu_definition_entry *entry; + struct menu_definition *definition = ro_gui_menu_find_menu(menu); + + if (!definition) + return NO_ACTION; + + for (entry = definition->entries; entry; entry = entry->next) { + if (entry->menu_entry == menu_entry) + return entry->action; + } + return NO_ACTION; +} + + +/** + * Sets an action within a menu as having a specific ticked status. + * + * \param menu the menu containing the action + * \param action the action to tick/untick + * \param ticked whether to set the item as ticked + */ +void ro_gui_menu_set_entry_shaded(wimp_menu *menu, menu_action action, + bool shaded) { + struct menu_definition_entry *entry = + ro_gui_menu_find_entry(menu, action); + if (entry) { + if (shaded) + entry->menu_entry->icon_flags |= wimp_ICON_SHADED; + else + entry->menu_entry->icon_flags &= ~wimp_ICON_SHADED; + } +} + + +/** + * Sets an action within a menu as having a specific ticked status. + * + * \param menu the menu containing the action + * \param action the action to tick/untick + * \param ticked whether to set the item as ticked + */ +void ro_gui_menu_set_entry_ticked(wimp_menu *menu, menu_action action, + bool ticked) { + struct menu_definition_entry *entry = + ro_gui_menu_find_entry(menu, action); + if (entry) { + if (ticked) + entry->menu_entry->menu_flags |= wimp_MENU_TICKED; + else + entry->menu_entry->menu_flags &= ~wimp_MENU_TICKED; + } +} + + +/** + * Handles an action. + * + * \param owner the window to handle the action for + * \param action the action to handle + * \param windows_at_pointer whether to open any windows at the pointer location + */ +bool ro_gui_menu_handle_action(wimp_w owner, menu_action action, + bool windows_at_pointer) { + wimp_window_state state; + struct gui_window *g = NULL; + struct browser_window *bw = NULL; + struct content *c = NULL; + struct toolbar *t = NULL; + struct tree *tree; + struct node *node; + os_error *error; + char url[80]; + + ro_gui_menu_get_window_details(owner, &g, &bw, &c, &t, &tree); + + switch (action) { + + /* help actions */ + case HELP_OPEN_CONTENTS: + ro_gui_open_help_page("docs"); + return true; + case HELP_OPEN_GUIDE: + ro_gui_open_help_page("guide"); + return true; + case HELP_OPEN_INFORMATION: + ro_gui_open_help_page("info"); + return true; + case HELP_OPEN_ABOUT: + browser_window_create("file:/<NetSurf$Dir>/Docs/about", + 0, 0); + return true; + case HELP_LAUNCH_INTERACTIVE: + ro_gui_interactive_help_start(); + return true; + + /* history actions */ + case HISTORY_SHOW_LOCAL: + if ((!bw) || (!bw->history)) + return false; + ro_gui_history_open(bw, bw->history, windows_at_pointer); + return true; + case HISTORY_SHOW_GLOBAL: + ro_gui_tree_show(global_history_tree); + return true; + + /* hotlist actions */ + case HOTLIST_ADD_URL: + if ((!hotlist_tree) || (!c)) + return false; + node = tree_create_URL_node(hotlist_tree->root, + c->title, c->url, ro_content_filetype(c), + time(NULL), -1, 0); + if (node) { + tree_redraw_area(hotlist_tree, + node->box.x - NODE_INSTEP, 0, + NODE_INSTEP, 16384); + tree_handle_node_changed(hotlist_tree, node, + false, true); + ro_gui_tree_scroll_visible(hotlist_tree, + &node->data); + } + return true; + case HOTLIST_SHOW: + ro_gui_tree_show(hotlist_tree); + return true; + + /* page actions */ + case BROWSER_PAGE_INFO: + if (!c) + return false; + ro_gui_menu_prepare_action(owner, action, true); + ro_gui_dialog_open_persistant(g->window, dialog_pageinfo, + windows_at_pointer); + return true; + case BROWSER_PRINT: + if (!c) + return false; + ro_gui_menu_prepare_action(owner, action, true); + ro_gui_dialog_open_persistant(g->window, dialog_print, + windows_at_pointer); + return true; + case BROWSER_NEW_WINDOW: + if (!c) + return false; + browser_window_create(c->url, bw, 0); + return true; + case BROWSER_VIEW_SOURCE: + if (!c) + return false; + ro_gui_view_source(c); + return true; + + /* object actions */ + case BROWSER_OBJECT_INFO: + if (!current_menu_object_box) + return false; + ro_gui_menu_prepare_action(owner, action, true); + ro_gui_dialog_open_persistant(g->window, dialog_objinfo, + windows_at_pointer); + return true; + case BROWSER_OBJECT_RELOAD: + if (!current_menu_object_box) + return false; + current_menu_object_box->object->fresh = false; + browser_window_reload(bw, false); + return true; + + /* save actions */ + case BROWSER_OBJECT_SAVE: + case BROWSER_OBJECT_EXPORT_SPRITE: + case BROWSER_OBJECT_SAVE_URL_URI: + case BROWSER_OBJECT_SAVE_URL_URL: + case BROWSER_OBJECT_SAVE_URL_TEXT: + c = current_menu_object_box ? + current_menu_object_box->object : NULL; + case BROWSER_SAVE: + case BROWSER_SAVE_COMPLETE: + case BROWSER_EXPORT_DRAW: + case BROWSER_EXPORT_TEXT: + case BROWSER_SAVE_URL_URI: + case BROWSER_SAVE_URL_URL: + case BROWSER_SAVE_URL_TEXT: + if (!c) + return false; + case HOTLIST_EXPORT: + case HISTORY_EXPORT: + ro_gui_menu_prepare_action(owner, action, true); + ro_gui_dialog_open_persistant(owner, dialog_saveas, + windows_at_pointer); + return true; + + /* navigation actions */ + case BROWSER_NAVIGATE_HOME: + if (!bw) + return false; + if ((option_homepage_url) && (option_homepage_url[0])) { + browser_window_go(g->bw, option_homepage_url, 0); + } else { + snprintf(url, sizeof url, + "file:/<NetSurf$Dir>/Docs/intro_%s", + option_language); + browser_window_go(g->bw, url, 0); + } + return true; + case BROWSER_NAVIGATE_BACK: + if ((!bw) || (!bw->history)) + return false; + history_back(bw, bw->history); + return true; + case BROWSER_NAVIGATE_FORWARD: + if ((!bw) || (!bw->history)) + return false; + history_forward(bw, bw->history); + return true; + case BROWSER_NAVIGATE_RELOAD: + case BROWSER_NAVIGATE_RELOAD_ALL: + if (!bw) + return false; + browser_window_reload(bw, + (action == BROWSER_NAVIGATE_RELOAD_ALL)); + return true; + case BROWSER_NAVIGATE_STOP: + if (!bw) + return false; + browser_window_stop(bw); + return true; + case BROWSER_NAVIGATE_URL: + ro_gui_menu_prepare_action(owner, action, true); + ro_gui_dialog_open_persistant(NULL, dialog_openurl, + windows_at_pointer); + return true; + + /* browser window/display actions */ + case BROWSER_SCALE_VIEW: + if (!c) + return false; + ro_gui_menu_prepare_action(owner, action, true); + ro_gui_dialog_open_persistant(g->window, dialog_zoom, + windows_at_pointer); + return true; + case BROWSER_FIND_TEXT: + if (!c) + return false; + ro_gui_menu_prepare_action(owner, action, true); + ro_gui_dialog_open_persistant(g->window, dialog_search, + windows_at_pointer); + return true; + case BROWSER_IMAGES_BACKGROUND: + if (!g) + return false; + g->option.background_images = !g->option.background_images; + gui_window_redraw_window(g); + return true; + case BROWSER_BLEND_TEXT: + if (!g) + return false; + g->option.background_blending = !g->option.background_blending; + break; + case BROWSER_BUFFER_ANIMS: + if (!g) + return false; + g->option.buffer_animations = !g->option.buffer_animations; + break; + case BROWSER_BUFFER_ALL: + if (!g) + return false; + g->option.buffer_everything = !g->option.buffer_everything; + break; + case BROWSER_SAVE_VIEW: + if (!bw) + return false; + ro_gui_window_default_options(bw); + ro_gui_save_options(); + return true; + case BROWSER_WINDOW_DEFAULT: + if (!g) + return false; + ro_gui_screen_size(&option_window_screen_width, + &option_window_screen_height); + state.w = current_menu_window; + error = xwimp_get_window_state(&state); + if (error) { + LOG(("xwimp_get_window_state: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + } + option_window_x = state.visible.x0; + option_window_y = state.visible.y0; + option_window_width = state.visible.x1 - state.visible.x0; + option_window_height = state.visible.y1 - state.visible.y0; + return true; + case BROWSER_WINDOW_STAGGER: + option_window_stagger = !option_window_stagger; + ro_gui_save_options(); + return true; + case BROWSER_WINDOW_COPY: + option_window_size_clone = !option_window_size_clone; + ro_gui_save_options(); + return true; + case BROWSER_WINDOW_RESET: + option_window_screen_width = 0; + option_window_screen_height = 0; + ro_gui_save_options(); + return true; + + /* tree actions */ + case TREE_NEW_FOLDER: + ro_gui_menu_prepare_action(owner, action, true); + ro_gui_dialog_open_persistant(g->window, dialog_folder, + windows_at_pointer); + return true; + case TREE_NEW_LINK: + ro_gui_menu_prepare_action(owner, action, true); + ro_gui_dialog_open_persistant(g->window, dialog_entry, + windows_at_pointer); + return true; + case TREE_EXPAND_ALL: + case TREE_EXPAND_FOLDERS: + case TREE_EXPAND_LINKS: + tree_handle_expansion(tree, tree->root, true, + (action != TREE_EXPAND_LINKS), + (action != TREE_EXPAND_FOLDERS)); + return true; + case TREE_COLLAPSE_ALL: + case TREE_COLLAPSE_FOLDERS: + case TREE_COLLAPSE_LINKS: + tree_handle_expansion(tree, tree->root, false, + (action != TREE_COLLAPSE_LINKS), + (action != TREE_COLLAPSE_FOLDERS)); + return true; + case TREE_SELECTION_EDIT: + return true; + case TREE_SELECTION_LAUNCH: + ro_gui_tree_launch_selected(tree); + return true; + case TREE_SELECTION_DELETE: + tree_delete_selected_nodes(tree, tree->root); + return true; + case TREE_SELECTION_RESET: + tree_reset_URL_nodes(tree, tree->root, true); + return true; + case TREE_SELECT_ALL: + ro_gui_tree_keypress(1, tree); /* CTRL-A */ + return true; + case TREE_CLEAR_SELECTION: + ro_gui_tree_keypress(26, tree); /* CTRL-Z */ + return true; + + /* toolbar actions */ + case TOOLBAR_BUTTONS: + assert(t); + t->display_buttons = !t->display_buttons; + ro_gui_menu_refresh_toolbar(t); + return true; + case TOOLBAR_ADDRESS_BAR: + assert(t); + t->display_url = !t->display_url; + ro_gui_menu_refresh_toolbar(t); + if (t->display_url) + ro_gui_set_caret_first(t->toolbar_handle); + return true; + case TOOLBAR_THROBBER: + assert(t); + t->display_throbber = !t->display_throbber; + ro_gui_menu_refresh_toolbar(t); + return true; + case TOOLBAR_STATUS_BAR: + assert(t); + t->display_status = !t->display_status; + ro_gui_menu_refresh_toolbar(t); + return true; + case TOOLBAR_EDIT: + assert(t); + ro_gui_theme_toggle_edit(t); + return true; + + /* misc actions */ + case APPLICATION_QUIT: + netsurf_quit = true; + return true; + case CHOICES_SHOW: + ro_gui_dialog_open_config(); + return true; + + /* unknown action */ + default: + return false; + } + return false; +} + + +/** + * Prepares an action for use. + * + * \param owner the window to prepare the action for + * \param action the action to prepare + * \param windows whether to update sub-windows + */ +void ro_gui_menu_prepare_action(wimp_w owner, menu_action action, bool windows) { + struct menu_definition_entry *entry; + struct gui_window *g; + struct browser_window *bw; + struct content *c; + struct toolbar *t; + struct tree *tree; + struct node *node; + bool result = false; + int checksum = 0; + os_error *error; + + ro_gui_menu_get_window_details(owner, &g, &bw, &c, &t, &tree); + if (current_menu_open) + checksum = ro_gui_menu_get_checksum(); + + switch (action) { + + /* help actions */ + case HELP_LAUNCH_INTERACTIVE: + result = ro_gui_interactive_help_available(); + ro_gui_menu_set_entry_shaded(current_menu, action, result); + ro_gui_menu_set_entry_ticked(current_menu, action, result); + break; + + /* history actions */ + case HISTORY_SHOW_LOCAL: + ro_gui_menu_set_entry_shaded(current_menu, action, + (!bw || (!bw->history) || + !(c || history_back_available(bw->history) || + history_forward_available(bw->history)))); + break; + case HISTORY_SHOW_GLOBAL: + ro_gui_menu_set_entry_shaded(current_menu, action, + !global_history_tree); + break; + + /* hotlist actions */ + case HOTLIST_ADD_URL: + ro_gui_menu_set_entry_shaded(current_menu, action, + (!c || !hotlist_tree)); + break; + case HOTLIST_SHOW: + ro_gui_menu_set_entry_shaded(current_menu, action, + !hotlist_tree); + if ((t) && (!t->editor) && (t->type == THEME_BROWSER_TOOLBAR)) + ro_gui_set_icon_shaded_state(t->toolbar_handle, + ICON_TOOLBAR_BOOKMARK, !hotlist_tree); + break; + + /* page actions */ + case BROWSER_PAGE_INFO: + ro_gui_menu_set_entry_shaded(current_menu, action, !c); + if ((windows) && (c)) + ro_gui_menu_prepare_pageinfo(g); + break; + case BROWSER_PRINT: + ro_gui_menu_set_entry_shaded(current_menu, action, !c); + if ((t) && (t->type == THEME_BROWSER_TOOLBAR)) + ro_gui_set_icon_shaded_state(t->toolbar_handle, + ICON_TOOLBAR_PRINT, !c); + if ((windows) && (c)) + ro_gui_print_prepare(g); + if ((t) && (!t->editor) && (t->type == THEME_BROWSER_TOOLBAR)) + ro_gui_set_icon_shaded_state(t->toolbar_handle, + ICON_TOOLBAR_PRINT, !c); + break; + case BROWSER_PAGE: + case BROWSER_NEW_WINDOW: + case BROWSER_VIEW_SOURCE: + ro_gui_menu_set_entry_shaded(current_menu, action, !c); + break; + + /* object actions */ + case BROWSER_OBJECT: + c = current_menu_object_box ? + current_menu_object_box->object : NULL; + ro_gui_menu_set_entry_shaded(current_menu, action, !c); + break; + case BROWSER_OBJECT_INFO: + if ((windows) && (current_menu_object_box)) + ro_gui_menu_prepare_objectinfo( + current_menu_object_box); + case BROWSER_OBJECT_RELOAD: + ro_gui_menu_set_entry_shaded(current_menu, action, + !current_menu_object_box); + break; + + /* save actions (browser, hotlist, history) */ + case BROWSER_OBJECT_SAVE: + c = current_menu_object_box ? + current_menu_object_box->object : NULL; + ro_gui_menu_set_entry_shaded(current_menu, action, !c); + if ((c) && (windows)) + ro_gui_save_prepare(GUI_SAVE_OBJECT_ORIG, c); + break; + case BROWSER_OBJECT_EXPORT_SPRITE: + c = current_menu_object_box ? + current_menu_object_box->object : NULL; + ro_gui_menu_set_entry_shaded(current_menu, action, !c); + if ((c) && (windows)) + ro_gui_save_prepare(GUI_SAVE_OBJECT_NATIVE, c); + break; + case BROWSER_SAVE: + ro_gui_menu_set_entry_shaded(current_menu, action, !c); + if ((c) && (windows)) + ro_gui_save_prepare(GUI_SAVE_SOURCE, c); + if ((t) && (!t->editor) && (t->type == THEME_BROWSER_TOOLBAR)) + ro_gui_set_icon_shaded_state(t->toolbar_handle, + ICON_TOOLBAR_SAVE, !c); + break; + case BROWSER_SAVE_COMPLETE: + ro_gui_menu_set_entry_shaded(current_menu, action, !c); + if ((c) && (windows)) + ro_gui_save_prepare(GUI_SAVE_COMPLETE, c); + break; + case BROWSER_EXPORT_DRAW: + ro_gui_menu_set_entry_shaded(current_menu, action, !c); + if ((c) && (windows)) + ro_gui_save_prepare(GUI_SAVE_DRAW, c); + break; + case BROWSER_EXPORT_TEXT: + ro_gui_menu_set_entry_shaded(current_menu, action, !c); + if ((c) && (windows)) + ro_gui_save_prepare(GUI_SAVE_TEXT, c); + break; + case BROWSER_OBJECT_SAVE_URL_URI: + c = current_menu_object_box ? + current_menu_object_box->object : NULL; + case BROWSER_SAVE_URL_URI: + ro_gui_menu_set_entry_shaded(current_menu, action, !c); + if ((c) && (windows)) + ro_gui_save_prepare(GUI_SAVE_LINK_URI, c); + break; + case BROWSER_OBJECT_SAVE_URL_URL: + c = current_menu_object_box ? + current_menu_object_box->object : NULL; + case BROWSER_SAVE_URL_URL: + ro_gui_menu_set_entry_shaded(current_menu, action, !c); + if ((c) && (windows)) + ro_gui_save_prepare(GUI_SAVE_LINK_URL, c); + break; + case BROWSER_OBJECT_SAVE_URL_TEXT: + c = current_menu_object_box ? + current_menu_object_box->object : NULL; + case BROWSER_SAVE_URL_TEXT: + ro_gui_menu_set_entry_shaded(current_menu, action, !c); + if ((c) && (windows)) + ro_gui_save_prepare(GUI_SAVE_LINK_TEXT, c); + break; + case HOTLIST_EXPORT: + if ((tree) && (windows)) + ro_gui_save_prepare(GUI_SAVE_HOTLIST_EXPORT_HTML, + NULL); + break; + case HISTORY_EXPORT: + if ((tree) && (windows)) + ro_gui_save_prepare(GUI_SAVE_HISTORY_EXPORT_HTML, + NULL); + break; + + /* navigation actions */ + case BROWSER_NAVIGATE_BACK: + result = (!bw || !bw->history || + !history_back_available(bw->history)); + ro_gui_menu_set_entry_shaded(current_menu, action, result); + if ((t) && (!t->editor) && (t->type == THEME_BROWSER_TOOLBAR)) + ro_gui_set_icon_shaded_state(t->toolbar_handle, + ICON_TOOLBAR_BACK, result); + break; + case BROWSER_NAVIGATE_FORWARD: + result = (!bw || !bw->history || + !history_forward_available(bw->history)); + ro_gui_menu_set_entry_shaded(current_menu, action, result); + if ((t) && (!t->editor) && (t->type == THEME_BROWSER_TOOLBAR)) + ro_gui_set_icon_shaded_state(t->toolbar_handle, + ICON_TOOLBAR_FORWARD, result); + break; + case BROWSER_NAVIGATE_RELOAD: + case BROWSER_NAVIGATE_RELOAD_ALL: + result = (bw->current_content && !bw->loading_content); + ro_gui_menu_set_entry_shaded(current_menu, action, !result); + if ((t) && (!t->editor) && (t->type == THEME_BROWSER_TOOLBAR)) + ro_gui_set_icon_shaded_state(t->toolbar_handle, + ICON_TOOLBAR_RELOAD, !result); + break; + case BROWSER_NAVIGATE_STOP: + result = (bw->loading_content || (bw->current_content && + (bw->current_content->status != + CONTENT_STATUS_DONE))); + ro_gui_menu_set_entry_shaded(current_menu, action, !result); + if ((t) && (!t->editor) && (t->type == THEME_BROWSER_TOOLBAR)) + ro_gui_set_icon_shaded_state(t->toolbar_handle, + ICON_TOOLBAR_STOP, !result); + break; + case BROWSER_NAVIGATE_URL: + if (windows) + ro_gui_dialog_prepare_open_url(); + break; + + /* display actions */ + case BROWSER_SCALE_VIEW: + ro_gui_menu_set_entry_shaded(current_menu, action, !c); + if ((c) && (windows)) + ro_gui_dialog_prepare_zoom(g); + if ((t) && (!t->editor) && (t->type == THEME_BROWSER_TOOLBAR)) + ro_gui_set_icon_shaded_state(t->toolbar_handle, + ICON_TOOLBAR_SCALE, !c); + break; + case BROWSER_FIND_TEXT: + if ((c) && (windows)) + ro_gui_search_prepare(g); + if ((t) && (!t->editor) && (t->type == THEME_BROWSER_TOOLBAR)) + ro_gui_set_icon_shaded_state(t->toolbar_handle, + ICON_TOOLBAR_SEARCH, !c); + break; + case BROWSER_IMAGES_FOREGROUND: + ro_gui_menu_set_entry_shaded(current_menu, action, true); + ro_gui_menu_set_entry_ticked(current_menu, action, true); + break; + case BROWSER_IMAGES_BACKGROUND: + if (g) + ro_gui_menu_set_entry_ticked(current_menu, action, + g->option.background_images); + break; + case BROWSER_BLEND_TEXT: + if (g) + ro_gui_menu_set_entry_ticked(current_menu, action, + g->option.background_blending); + break; + case BROWSER_BUFFER_ANIMS: + if (g) { + ro_gui_menu_set_entry_shaded(current_menu, action, + g->option.buffer_everything); + ro_gui_menu_set_entry_ticked(current_menu, action, + g->option.buffer_animations || + g->option.buffer_everything); + } + break; + case BROWSER_BUFFER_ALL: + if (g) + ro_gui_menu_set_entry_ticked(current_menu, action, + g->option.buffer_everything); + break; + case BROWSER_WINDOW_STAGGER: + ro_gui_menu_set_entry_shaded(current_menu, action, + option_window_screen_width == 0); + ro_gui_menu_set_entry_ticked(current_menu, action, + ((option_window_screen_width == 0) || + option_window_stagger)); + break; + case BROWSER_WINDOW_COPY: + ro_gui_menu_set_entry_ticked(current_menu, action, + option_window_size_clone); + break; + case BROWSER_WINDOW_RESET: + ro_gui_menu_set_entry_shaded(current_menu, action, + option_window_screen_width == 0); + break; + + /* tree actions */ + case TREE_NEW_FOLDER: + ro_gui_hotlist_prepare_folder_dialog(NULL); + break; + case TREE_NEW_LINK: + ro_gui_hotlist_prepare_entry_dialog(NULL); + break; + case TREE_EXPAND_ALL: + case TREE_EXPAND_FOLDERS: + case TREE_EXPAND_LINKS: + case TREE_COLLAPSE_ALL: + case TREE_COLLAPSE_FOLDERS: + case TREE_COLLAPSE_LINKS: + if ((tree) && (tree->root)) + ro_gui_menu_set_entry_shaded(current_menu, action, + !tree->root->child); + break; + case TREE_SELECTION: + if ((!tree) || (!tree->root)) + break; + if (tree->root->child) + result = tree_has_selection(tree->root->child); + ro_gui_menu_set_entry_shaded(current_menu, action, !result); + if ((t) && (!t->editor) && (t->type != THEME_BROWSER_TOOLBAR)) { + ro_gui_set_icon_shaded_state(t->toolbar_handle, + ICON_TOOLBAR_DELETE, !result); + ro_gui_set_icon_shaded_state(t->toolbar_handle, + ICON_TOOLBAR_LAUNCH, !result); + } + break; + case TREE_SELECTION_EDIT: + node = tree_get_selected_node(tree->root); + entry = ro_gui_menu_find_entry(current_menu, action); + if ((!node) || (!entry)) + break; + if (node->folder) { + entry->menu_entry->sub_menu = + (wimp_menu *)dialog_folder; + if (windows) + ro_gui_hotlist_prepare_folder_dialog(node); + } else { + entry->menu_entry->sub_menu = + (wimp_menu *)dialog_entry; + if (windows) + ro_gui_hotlist_prepare_entry_dialog(node); + } + break; + case TREE_SELECTION_LAUNCH: + case TREE_SELECTION_DELETE: + case TREE_SELECTION_RESET: + if ((!tree) || (!tree->root)) + break; + if (tree->root->child) + result = tree_has_selection(tree->root->child); + ro_gui_menu_set_entry_shaded(current_menu, action, !result); + break; + case TREE_SELECT_ALL: + ro_gui_menu_set_entry_shaded(current_menu, action, + !tree->root->child); + break; + case TREE_CLEAR_SELECTION: + if ((!tree) || (!tree->root)) + break; + if (tree->root->child) + result = tree_has_selection(tree->root->child); + ro_gui_menu_set_entry_shaded(current_menu, action, !result); + break; + + /* toolbar actions */ + case TOOLBAR_BUTTONS: + ro_gui_menu_set_entry_shaded(current_menu, action, (!t || + (t->editor))); + ro_gui_menu_set_entry_ticked(current_menu, action, (t && + ((t->display_buttons) || (t->editor)))); + break; + case TOOLBAR_ADDRESS_BAR: + ro_gui_menu_set_entry_shaded(current_menu, action, !t); + ro_gui_menu_set_entry_ticked(current_menu, action, + (t && t->display_url)); + break; + case TOOLBAR_THROBBER: + ro_gui_menu_set_entry_shaded(current_menu, action, !t); + ro_gui_menu_set_entry_ticked(current_menu, action, + (t && t->display_throbber)); + break; + case TOOLBAR_STATUS_BAR: + ro_gui_menu_set_entry_shaded(current_menu, action, !t); + ro_gui_menu_set_entry_ticked(current_menu, action, + (t && t->display_status)); + break; + case TOOLBAR_EDIT: + ro_gui_menu_set_entry_shaded(current_menu, action, !t); + ro_gui_menu_set_entry_ticked(current_menu, action, + (t && t->editor)); + break; + + /* unknown action */ + default: + return; + } + + /* update open menus */ + if ((current_menu_open) && + (checksum != ro_gui_menu_get_checksum())) { + error = xwimp_create_menu(current_menu, 0, 0); + if (error) { + LOG(("xwimp_create_menu: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("MenuError", error->errmess); + } + } +} + + +/** + * Gets various details relating to a window + * + * \param w the window to complete information for + */ +void ro_gui_menu_get_window_details(wimp_w w, struct gui_window **g, + struct browser_window **bw, struct content **content, + struct toolbar **toolbar, struct tree **tree) { + *g = ro_gui_window_lookup(w); + if (*g) { + *bw = (*g)->bw; + *toolbar = (*g)->toolbar; + if (*bw) + *content = (*bw)->current_content; + *tree = NULL; + } else { + *bw = NULL; + *content = NULL; + if ((hotlist_tree) && (w == (wimp_w)hotlist_tree->handle)) + *tree = hotlist_tree; + else if ((global_history_tree) && + (w == (wimp_w)global_history_tree->handle)) + *tree = global_history_tree; + else + *tree = NULL; + if (*tree) + *toolbar = (*tree)->toolbar; + else + *toolbar = NULL; + } +} + + +/** + * Calculates a simple checksum for the current menu state + */ +int ro_gui_menu_get_checksum(void) { + wimp_selection menu_tree; + int i = 0, j, checksum = 0; + os_error *error; + wimp_menu *menu; + + if (!current_menu_open) + return 0; + + error = xwimp_get_menu_state((wimp_menu_state_flags)0, + &menu_tree, 0, 0); + if (error) { + LOG(("xwimp_get_menu_state: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("MenuError", error->errmess); + return 0; + } + + menu = current_menu; + do { + j = 0; + do { + if (menu->entries[j].icon_flags & wimp_ICON_SHADED) + checksum ^= (1 << (i + j * 2)); + if (menu->entries[j].menu_flags & wimp_MENU_TICKED) + checksum ^= (2 << (i + j * 2)); + } while (!(menu->entries[j++].menu_flags & wimp_MENU_LAST)); + j = menu_tree.items[i++]; + if (j != -1) + menu = menu->entries[j].sub_menu; + } while (j != -1); + return checksum; } diff --git a/riscos/menus.h b/riscos/menus.h new file mode 100644 index 000000000..2f3e6f9d4 --- /dev/null +++ b/riscos/menus.h @@ -0,0 +1,139 @@ +/* + * This file is part of NetSurf, http://netsurf.sourceforge.net/ + * Licensed under the GNU General Public License, + * http://www.opensource.org/licenses/gpl-license + * Copyright 2005 Richard Wilson <info@tinct.net> + */ + +#ifndef _NETSURF_RISCOS_MENUS_H_ +#define _NETSURF_RISCOS_MENUS_H_ + +#include <stdbool.h> +#include "oslib/wimp.h" +#include "netsurf/desktop/gui.h" + +extern wimp_menu *iconbar_menu, *browser_menu, *hotlist_menu, + *global_history_menu, *image_quality_menu, + *browser_toolbar_menu, *tree_toolbar_menu, *proxy_auth_menu; +extern wimp_menu *languages_menu, *url_suggest_menu; + +extern wimp_menu *current_menu; +extern int iconbar_menu_height; + +typedef enum { + + /* no/unknown actions */ + NO_ACTION, + + /* help actions */ + HELP_OPEN_CONTENTS, + HELP_OPEN_GUIDE, + HELP_OPEN_INFORMATION, + HELP_OPEN_ABOUT, + HELP_LAUNCH_INTERACTIVE, + + /* history actions */ + HISTORY_SHOW_LOCAL, + HISTORY_SHOW_GLOBAL, + + /* hotlist actions */ + HOTLIST_ADD_URL, + HOTLIST_SHOW, + + /* page actions */ + BROWSER_PAGE, + BROWSER_PAGE_INFO, + BROWSER_PRINT, + BROWSER_NEW_WINDOW, + BROWSER_VIEW_SOURCE, + + /* object actions */ + BROWSER_OBJECT, + BROWSER_OBJECT_INFO, + BROWSER_OBJECT_RELOAD, + + /* save actions */ + BROWSER_OBJECT_SAVE, + BROWSER_OBJECT_EXPORT_SPRITE, + BROWSER_OBJECT_SAVE_URL_URI, + BROWSER_OBJECT_SAVE_URL_URL, + BROWSER_OBJECT_SAVE_URL_TEXT, + BROWSER_SAVE, + BROWSER_SAVE_COMPLETE, + BROWSER_EXPORT_DRAW, + BROWSER_EXPORT_TEXT, + BROWSER_SAVE_URL_URI, + BROWSER_SAVE_URL_URL, + BROWSER_SAVE_URL_TEXT, + HOTLIST_EXPORT, + HISTORY_EXPORT, + + /* navigation actions */ + BROWSER_NAVIGATE_HOME, + BROWSER_NAVIGATE_BACK, + BROWSER_NAVIGATE_FORWARD, + BROWSER_NAVIGATE_RELOAD, + BROWSER_NAVIGATE_RELOAD_ALL, + BROWSER_NAVIGATE_STOP, + BROWSER_NAVIGATE_URL, + + /* browser window/display actions */ + BROWSER_SCALE_VIEW, + BROWSER_FIND_TEXT, + BROWSER_IMAGES_FOREGROUND, + BROWSER_IMAGES_BACKGROUND, + BROWSER_BLEND_TEXT, + BROWSER_BUFFER_ANIMS, + BROWSER_BUFFER_ALL, + BROWSER_SAVE_VIEW, + BROWSER_WINDOW_DEFAULT, + BROWSER_WINDOW_STAGGER, + BROWSER_WINDOW_COPY, + BROWSER_WINDOW_RESET, + + /* tree actions */ + TREE_NEW_FOLDER, + TREE_NEW_LINK, + TREE_EXPAND_ALL, + TREE_EXPAND_FOLDERS, + TREE_EXPAND_LINKS, + TREE_COLLAPSE_ALL, + TREE_COLLAPSE_FOLDERS, + TREE_COLLAPSE_LINKS, + TREE_SELECTION, + TREE_SELECTION_EDIT, + TREE_SELECTION_LAUNCH, + TREE_SELECTION_DELETE, + TREE_SELECTION_RESET, + TREE_SELECT_ALL, + TREE_CLEAR_SELECTION, + + /* toolbar actions */ + TOOLBAR_BUTTONS, + TOOLBAR_ADDRESS_BAR, + TOOLBAR_THROBBER, + TOOLBAR_STATUS_BAR, + TOOLBAR_EDIT, + + /* misc actions */ + CHOICES_SHOW, + APPLICATION_QUIT, +} menu_action; + + +void ro_gui_menu_init(void); +void ro_gui_menu_create(wimp_menu* menu, int x, int y, wimp_w w); +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, + bool windows); +void ro_gui_menu_closed(void); +void ro_gui_menu_objects_moved(void); +void ro_gui_popup_menu(wimp_menu *menu, wimp_w w, wimp_i i); +void ro_gui_menu_selection(wimp_selection* selection); +void ro_gui_menu_warning(wimp_message_menu_warning *warning); +void ro_gui_prepare_navigate(struct gui_window *gui); +void ro_gui_menu_prepare_image_quality(unsigned int tinct_options); +void ro_gui_display_font_menu(const char *tick, wimp_w w, wimp_i i); + +#endif diff --git a/riscos/mouseactions.c b/riscos/mouseactions.c index 1fa7626b8..aa068d00d 100644 --- a/riscos/mouseactions.c +++ b/riscos/mouseactions.c @@ -11,6 +11,7 @@ #include "netsurf/utils/config.h" #include "netsurf/desktop/browser.h" #include "netsurf/riscos/gui.h" +#include "netsurf/riscos/menus.h" #include "netsurf/riscos/options.h" #include "netsurf/utils/log.h" @@ -39,7 +40,7 @@ void ro_gui_mouse_action(struct gui_window *g) { if (ma == mouseaction_NONE) { os_mouse(&x, &y, NULL, NULL); - ro_gui_create_menu(browser_menu, x - 64, y, g); + ro_gui_menu_create(browser_menu, x - 64, y, g->window); } else { diff --git a/riscos/print.c b/riscos/print.c index 5de07182f..0e4eef004 100644 --- a/riscos/print.c +++ b/riscos/print.c @@ -22,6 +22,7 @@ #include "netsurf/render/html.h" #include "netsurf/render/layout.h" #include "netsurf/riscos/gui.h" +#include "netsurf/riscos/menus.h" #include "netsurf/riscos/print.h" #include "netsurf/riscos/wimp.h" #include "netsurf/utils/log.h" @@ -66,16 +67,11 @@ static bool print_find_fonts(struct box *box, struct print_font **print_fonts, int *font_count); /** - * Open the print dialog + * Prepares all aspects of the print dialog prior to opening. * * \param g parent window - * \param x leftmost edge of dialog (only if sub_menu == true) - * \param y topmost edge of dialog (as above) - * \param sub_menu open window as a submenu or as a persistent dialog - * \param keypress whether we were opened by a keypress */ -void ro_gui_print_open(struct gui_window *g, int x, int y, bool sub_menu, bool keypress) -{ +void ro_gui_print_prepare(struct gui_window *g) { char *pdName; bool printers_exists = true; os_error *e; @@ -123,20 +119,9 @@ void ro_gui_print_open(struct gui_window *g, int x, int y, bool sub_menu, bool k ro_gui_set_icon_shaded_state(dialog_print, ICON_PRINT_PRINT, false); ro_gui_set_window_title(dialog_print, pdName); } - - if (sub_menu) { - e = xwimp_create_sub_menu((wimp_menu *) dialog_print, x, y); - if (e) { - LOG(("xwimp_create_sub_menu: 0x%x: %s", - e->errnum, e->errmess)); - warn_user("MenuError", e->errmess); - } - } - else { - ro_gui_dialog_open_persistant(g->window, dialog_print, !keypress); - } } + /** * Handle mouse clicks in print dialog * @@ -468,7 +453,7 @@ void print_cleanup(void) print_text_black = false; print_prev_message = 0; print_max_sheets = -1; - xwimp_create_menu((wimp_menu *)-1, 0, 0); + ro_gui_menu_closed(); ro_gui_dialog_close(dialog_print); } diff --git a/riscos/save.c b/riscos/save.c index fd472384c..666eeec05 100644 --- a/riscos/save.c +++ b/riscos/save.c @@ -22,6 +22,7 @@ #include "netsurf/desktop/save_text.h" #include "netsurf/image/bitmap.h" #include "netsurf/riscos/gui.h" +#include "netsurf/riscos/menus.h" #include "netsurf/riscos/save_complete.h" #include "netsurf/riscos/save_draw.h" #include "netsurf/riscos/thumbnail.h" @@ -79,14 +80,12 @@ struct gui_save_table_entry gui_save_table[] = { * \param parent parent window for persistent box, for sub_menu false only */ -void ro_gui_save_open(gui_save_type save_type, struct content *c, - bool sub_menu, int x, int y, wimp_w parent, bool keypress) +void ro_gui_save_prepare(gui_save_type save_type, struct content *c) { char icon_buf[20]; const char *icon = icon_buf; const char *name = ""; const char *nice; - os_error *error; url_func_result res; assert((save_type == GUI_SAVE_HOTLIST_EXPORT_HTML) || @@ -111,22 +110,8 @@ void ro_gui_save_open(gui_save_type save_type, struct content *c, name = nice; } ro_gui_set_icon_string(dialog_saveas, ICON_SAVE_PATH, name); - - /* open sub menu or persistent dialog */ - if (sub_menu) { - error = xwimp_create_sub_menu((wimp_menu *) dialog_saveas, - x, y); - if (error) { - LOG(("xwimp_create_sub_menu: 0x%x: %s", - error->errnum, error->errmess)); - warn_user("MenuError", error->errmess); - } - } else { - ro_gui_dialog_open_persistant(parent, dialog_saveas, !keypress); - } } - /** * Handle clicks in the save dialog. */ @@ -332,6 +317,7 @@ void ro_gui_save_datasave_ack(wimp_message *message) /* Close the save window */ ro_gui_dialog_close(dialog_saveas); + ro_gui_menu_closed(); /* Ack successful save with message_DATA_LOAD */ message->action = message_DATA_LOAD; @@ -343,15 +329,6 @@ void ro_gui_save_datasave_ack(wimp_message *message) error->errnum, error->errmess)); warn_user("SaveError", error->errmess); } - - error = xwimp_create_menu(wimp_CLOSE_MENU, 0, 0); - if (error) { - LOG(("xwimp_create_menu: 0x%x: %s", - error->errnum, error->errmess)); - warn_user("MenuError", error->errmess); - } - - gui_save_content = 0; } diff --git a/riscos/search.c b/riscos/search.c index 356867d9a..6ece879c7 100644 --- a/riscos/search.c +++ b/riscos/search.c @@ -21,6 +21,7 @@ #include "netsurf/render/box.h" #include "netsurf/render/html.h" #include "netsurf/riscos/gui.h" +#include "netsurf/riscos/menus.h" #include "netsurf/riscos/wimp.h" #include "netsurf/utils/log.h" #include "netsurf/utils/utils.h" @@ -59,15 +60,9 @@ static bool find_occurrences(const char *pattern, int p_len, struct box *cur, bo * Open the search dialog * * \param g the gui window to search - * \param x x position, for sub_menu true only - * \param y y position, for sub_menu true only - * \param sub_menu open as a sub_menu, otherwise persistent - * \param keypress whether opened by a keypress or not */ -void ro_gui_search_open(struct gui_window *g, int x, int y, bool sub_menu, bool keypress) +void ro_gui_search_prepare(struct gui_window *g) { - os_error *e; - assert(g != NULL); search_current_window = g; @@ -81,18 +76,6 @@ void ro_gui_search_open(struct gui_window *g, int x, int y, bool sub_menu, bool false); ro_gui_set_icon_selected_state(dialog_search, ICON_SEARCH_CASE_SENSITIVE, false); - - if (sub_menu) { - e = xwimp_create_sub_menu((wimp_menu *) dialog_search, x, y); - if (e) { - LOG(("xwimp_create_sub_menu: 0x%x: %s", - e->errnum, e->errmess)); - warn_user("MenuError", e->errmess); - } - } - else { - ro_gui_dialog_open_persistant(g->window, dialog_search, !keypress); - } } /** @@ -210,7 +193,7 @@ void end_search(void) search_prev_case_sens = false; /* and close the window */ - xwimp_create_menu((wimp_menu *)-1, 0, 0); + ro_gui_menu_closed(); ro_gui_dialog_close(dialog_search); } diff --git a/riscos/textselection.c b/riscos/textselection.c index b2b69baff..7d6e18090 100644 --- a/riscos/textselection.c +++ b/riscos/textselection.c @@ -15,7 +15,7 @@ void ro_gui_start_selection(wimp_pointer *pointer, wimp_window_state *state, struct gui_window *g) { - wimp_drag drag; +/* wimp_drag drag; gui_current_drag_type = GUI_DRAG_SELECTION; current_gui = g; @@ -30,13 +30,14 @@ void ro_gui_start_selection(wimp_pointer *pointer, wimp_window_state *state, drag.bbox.x1 = state->visible.x1; drag.bbox.y1 = state->visible.y1; wimp_drag_box(&drag); +*/ } void ro_gui_selection_drag_end(wimp_dragged *drag) { /* struct browser_action msg; */ - int final_x0, final_y0; +/* int final_x0, final_y0; wimp_window_state state; state.w = current_gui->window; @@ -44,7 +45,7 @@ void ro_gui_selection_drag_end(wimp_dragged *drag) final_x0 = window_x_units(drag->final.x0, &state) / 2; final_y0 = window_y_units(drag->final.y0, &state) / 2; - +*/ /* msg.data.mouse.x = final_x0; msg.data.mouse.y = final_y0; msg.type = act_ALTER_SELECTION; diff --git a/riscos/theme.c b/riscos/theme.c index fb1f2a60d..9bd32d111 100644 --- a/riscos/theme.c +++ b/riscos/theme.c @@ -27,6 +27,7 @@ #include "oslib/wimpextend.h" #include "oslib/wimpspriteop.h" #include "netsurf/riscos/gui.h" +#include "netsurf/riscos/menus.h" #include "netsurf/riscos/options.h" #include "netsurf/riscos/theme.h" #include "netsurf/riscos/wimp.h" @@ -1020,10 +1021,9 @@ bool ro_gui_theme_update_toolbar(struct theme_descriptor *descriptor, struct too ro_gui_prepare_navigate(g); break; case THEME_HOTLIST_TOOLBAR: - ro_gui_menu_prepare_hotlist(); - break; case THEME_HISTORY_TOOLBAR: - ro_gui_menu_prepare_global_history(); + ro_gui_menu_prepare_action(toolbar->parent_handle, + TREE_SELECTION, false); break; default: break; diff --git a/riscos/treeview.c b/riscos/treeview.c index e570819d0..f28875938 100644 --- a/riscos/treeview.c +++ b/riscos/treeview.c @@ -22,6 +22,7 @@ #include "oslib/wimp.h" #include "netsurf/desktop/tree.h" #include "netsurf/riscos/gui.h" +#include "netsurf/riscos/menus.h" #include "netsurf/riscos/theme.h" #include "netsurf/riscos/tinct.h" #include "netsurf/riscos/treeview.h" @@ -812,6 +813,7 @@ void ro_gui_tree_menu_closed(struct tree *tree) { tree->temp_selection->selected = false; tree_handle_node_element_changed(tree, &tree->temp_selection->data); tree->temp_selection = NULL; + ro_gui_menu_prepare_action((wimp_w)tree->handle, TREE_SELECTION, false); } } @@ -823,18 +825,16 @@ void ro_gui_tree_menu_closed(struct tree *tree) { */ void ro_gui_tree_toolbar_click(wimp_pointer* pointer, struct tree *tree) { struct node *node; - bool refresh = true; - current_toolbar = tree->toolbar; ro_gui_tree_stop_edit(tree); if (pointer->buttons == wimp_CLICK_MENU) { - ro_gui_create_menu(toolbar_menu, pointer->pos.x, - pointer->pos.y, NULL); + ro_gui_menu_create(tree_toolbar_menu, pointer->pos.x, + pointer->pos.y, (wimp_w)tree->handle); return; } - if (current_toolbar->editor) { + if (tree->toolbar->editor) { ro_gui_theme_toolbar_editor_click(tree->toolbar, pointer); return; } @@ -866,16 +866,7 @@ void ro_gui_tree_toolbar_click(wimp_pointer* pointer, struct tree *tree) { ro_gui_tree_launch_selected(tree); break; } - switch (tree->toolbar->type) { - case THEME_HOTLIST_TOOLBAR: - ro_gui_menu_prepare_hotlist(); - break; - case THEME_HISTORY_TOOLBAR: - ro_gui_menu_prepare_global_history(); - break; - default: - break; - } + ro_gui_menu_prepare_action((wimp_w)tree->handle, TREE_SELECTION, false); } @@ -1140,7 +1131,7 @@ void ro_gui_tree_open(wimp_open *open, struct tree *tree) { } if (tree->toolbar) ro_gui_theme_process_toolbar(tree->toolbar, -1); - + ro_gui_menu_prepare_action((wimp_w)tree->handle, TREE_SELECTION, false); } @@ -1164,15 +1155,21 @@ bool ro_gui_tree_keypress(int key, struct tree *tree) { tree->temp_selection = NULL; tree_set_node_selected(tree, tree->root, true); } + ro_gui_menu_prepare_action((wimp_w)tree->handle, + TREE_SELECTION, true); return true; case 24: /* CTRL+X */ ro_gui_tree_stop_edit(tree); tree_delete_selected_nodes(tree, tree->root); + ro_gui_menu_prepare_action((wimp_w)tree->handle, + TREE_SELECTION, true); return true; case 26: /* CTRL+Z */ tree->temp_selection = NULL; ro_gui_tree_stop_edit(tree); tree_set_node_selected(tree, tree->root, false); + ro_gui_menu_prepare_action((wimp_w)tree->handle, + TREE_SELECTION, true); return true; case wimp_KEY_RETURN: if (tree->editing) { @@ -1248,14 +1245,8 @@ void ro_gui_tree_selection_drag_end(wimp_dragged *drag) { tree_handle_selection_area(ro_gui_tree_current_drag_tree, x0, y0, x1 - x0, y1 - y0, (ro_gui_tree_current_drag_buttons == (wimp_CLICK_ADJUST << 4))); - - /* send an empty keypress to stimulate the tree owner to update the GUI. - for this to work, we must always own the caret when this function is - called. */ - error = xwimp_process_key(0); - if (error) - LOG(("xwimp_process_key: 0x%x: %s", - error->errnum, error->errmess)); + ro_gui_menu_prepare_action((wimp_w)ro_gui_tree_current_drag_tree->handle, + TREE_SELECTION, false); } diff --git a/riscos/wimp.c b/riscos/wimp.c index 54a3cf815..36c832247 100644 --- a/riscos/wimp.c +++ b/riscos/wimp.c @@ -1,7 +1,7 @@ /* * This file is part of NetSurf, http://netsurf.sourceforge.net/ * Licensed under the GNU General Public License, - * http://www.opensource.org/licenses/gpl-license + * http://www.opensource.org/licenses/gpl-license * Copyright 2004 Richard Wilson <not_ginger_matt@users.sourceforge.net> */ @@ -27,55 +27,71 @@ #include "netsurf/utils/log.h" #include "netsurf/utils/utils.h" +static bool ro_gui_wimp_cache_furniture_sizes(wimp_w w); +static bool ro_gui_wimp_read_eig_factors(os_mode mode, int *xeig, int *yeig); + /* Wimp_Extend,11 block */ static wimpextend_furniture_sizes furniture_sizes; - +static wimp_w furniture_window = NULL; +static int ro_gui_hscroll_height = -1; +static int ro_gui_vscroll_width = -1; /** * Gets the horzontal scrollbar height + * + * \param w the window to read (or NULL to read a cached value) */ int ro_get_hscroll_height(wimp_w w) { - wimp_version_no version; - - /* Read the hscroll height - */ - if (!w) w = dialog_debug; - furniture_sizes.w = w; - furniture_sizes.border_widths.y0 = 38; - xwimpextend_get_furniture_sizes(&furniture_sizes); - - /* There is a quirk with the returned size as it differs between versions of the - WindowManager module. The incorrect height is returned by the version distributed - with the universal boot sequence (3.98) and presumably any previous version. - */ - if (!xwimpreadsysinfo_version(&version)) { - if ((int)version <= 398) { - return furniture_sizes.border_widths.y0 + 2; - } - } - - /* Return the standard (unhacked) size - */ - return furniture_sizes.border_widths.y0; + if (!w) + w = dialog_debug; + if ((furniture_window != w) && (!ro_gui_wimp_cache_furniture_sizes(w))) + return 38; + return ro_gui_hscroll_height; } /** * Gets the vertical scrollbar width + * + * \param w the window to read (or NULL to read a cached value) */ int ro_get_vscroll_width(wimp_w w) { + if (!w) + w = dialog_debug; + if ((furniture_window != w) && (!ro_gui_wimp_cache_furniture_sizes(w))) + return 38; + return ro_gui_vscroll_width; +} - /* Read the hscroll height - */ - if (!w) w = dialog_debug; - furniture_sizes.w = w; - furniture_sizes.border_widths.x1 = 38; - xwimpextend_get_furniture_sizes(&furniture_sizes); +/** + * Caches window furniture information + * + * \param w the window to cache information from + * \return true on success, false on error + */ +bool ro_gui_wimp_cache_furniture_sizes(wimp_w w) { + wimp_version_no version; + os_error *error; + assert(w); - /* Return the standard (unhacked) size - */ - return furniture_sizes.border_widths.x1; + furniture_sizes.w = w; + error = xwimpextend_get_furniture_sizes(&furniture_sizes); + if (error) { + LOG(("xwimpextend_get_furniture_sizes: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + return false; + } + furniture_window = w; + ro_gui_vscroll_width = furniture_sizes.border_widths.x1; + ro_gui_hscroll_height = furniture_sizes.border_widths.y0; + + /* work around inconsistencies in returned sizes beteen wimp versions */ + if ((!xwimpreadsysinfo_version(&version)) && + ((int)version <= 398)) + ro_gui_hscroll_height += 2; + return true; } @@ -84,12 +100,24 @@ int ro_get_vscroll_width(wimp_w w) { * * \param mode mode to read EIG factors for, or -1 for current */ -struct eig_factors ro_read_eig_factors(os_mode mode) { - bits psr; - struct eig_factors factors; - xos_read_mode_variable(mode, os_MODEVAR_XEIG_FACTOR, &factors.xeig, &psr); - xos_read_mode_variable(mode, os_MODEVAR_YEIG_FACTOR, &factors.yeig, &psr); - return factors; +bool ro_gui_wimp_read_eig_factors(os_mode mode, int *xeig, int *yeig) { + os_error *error; + + error = xos_read_mode_variable(mode, os_MODEVAR_XEIG_FACTOR, xeig, 0); + if (error) { + LOG(("xos_read_mode_variable: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("MiscError", error->errmess); + return false; + } + error = xos_read_mode_variable(mode, os_MODEVAR_YEIG_FACTOR, yeig, 0); + if (error) { + LOG(("xos_read_mode_variable: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("MiscError", error->errmess); + return false; + } + return true; } @@ -97,12 +125,14 @@ struct eig_factors ro_read_eig_factors(os_mode mode) { * Converts the supplied os_coord from OS units to pixels. * * \param os_units values to convert - * \param mode mode to use EIG factors for, or -1 for current + * \param mode mode to use EIG factors for, or -1 for current */ void ro_convert_os_units_to_pixels(os_coord *os_units, os_mode mode) { - struct eig_factors factors = ro_read_eig_factors(mode); - os_units->x = (os_units->x >> factors.xeig); - os_units->y = (os_units->y >> factors.yeig); + int xeig = 2, yeig = 2; + + ro_gui_wimp_read_eig_factors(mode, &xeig, &yeig); + os_units->x = (os_units->x >> xeig); + os_units->y = (os_units->y >> yeig); } @@ -110,12 +140,14 @@ void ro_convert_os_units_to_pixels(os_coord *os_units, os_mode mode) { * Converts the supplied os_coord from pixels to OS units. * * \param pixels values to convert - * \param mode mode to use EIG factors for, or -1 for current + * \param mode mode to use EIG factors for, or -1 for current */ void ro_convert_pixels_to_os_units(os_coord *pixels, os_mode mode) { - struct eig_factors factors = ro_read_eig_factors(mode); - pixels->x = (pixels->x << factors.xeig); - pixels->y = (pixels->y << factors.yeig); + int xeig = 2, yeig = 2; + + ro_gui_wimp_read_eig_factors(mode, &xeig, &yeig); + pixels->x = (pixels->x << xeig); + pixels->y = (pixels->y << yeig); } @@ -168,9 +200,17 @@ void ro_gui_force_redraw_icon(wimp_w w, wimp_i i) { */ char *ro_gui_get_icon_string(wimp_w w, wimp_i i) { wimp_icon_state ic; + os_error *error; + ic.w = w; ic.i = i; - if (xwimp_get_icon_state(&ic)) return NULL; + error = xwimp_get_icon_state(&ic); + if (error) { + LOG(("xwimp_get_icon_state: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + return NULL; + } return ic.icon.data.indirected_text.text; } @@ -178,51 +218,63 @@ char *ro_gui_get_icon_string(wimp_w w, wimp_i i) { /** * Set the contents of an icon to a string. * - * \param w window handle - * \param i icon handle + * \param w window handle + * \param i icon handle * \param text string (copied) */ void ro_gui_set_icon_string(wimp_w w, wimp_i i, const char *text) { wimp_caret caret; wimp_icon_state ic; + os_error *error; int old_len, len; - /* Get the icon data - */ + /* get the icon data */ ic.w = w; ic.i = i; - if (xwimp_get_icon_state(&ic)) + error = xwimp_get_icon_state(&ic); + if (error) { + LOG(("xwimp_get_icon_state: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); return; + } - /* Check that the existing text is not the same as the updated text - to stop flicker - */ - if (ic.icon.data.indirected_text.size - && !strncmp(ic.icon.data.indirected_text.text, text, + /* check that the existing text is not the same as the updated text + * to stop flicker */ + if (ic.icon.data.indirected_text.size && + !strncmp(ic.icon.data.indirected_text.text, text, (unsigned int)ic.icon.data.indirected_text.size - 1)) return; - /* Copy the text across - */ + /* copy the text across */ old_len = strlen(ic.icon.data.indirected_text.text); if (ic.icon.data.indirected_text.size) { strncpy(ic.icon.data.indirected_text.text, text, (unsigned int)ic.icon.data.indirected_text.size - 1); - ic.icon.data.indirected_text.text[ic.icon.data.indirected_text.size - 1] = '\0'; + ic.icon.data.indirected_text.text[ + ic.icon.data.indirected_text.size - 1] = '\0'; } - /* Handle the caret being in the icon - */ - if (!xwimp_get_caret_position(&caret)) { - if ((caret.w == w) && (caret.i == i)) { - len = strlen(text); - if ((caret.index > len) || (caret.index == old_len)) caret.index = len; - xwimp_set_caret_position(w, i, caret.pos.x, caret.pos.y, -1, caret.index); + /* handle the caret being in the icon */ + error = xwimp_get_caret_position(&caret); + if (error) { + LOG(("xwimp_get_caret_position: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + return; + } + if ((caret.w == w) && (caret.i == i)) { + len = strlen(text); + if ((caret.index > len) || (caret.index == old_len)) + caret.index = len; + error = xwimp_set_caret_position(w, i, caret.pos.x, caret.pos.y, + -1, caret.index); + if (error) { + LOG(("xwimp_set_caret_position: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); } } - - /* Redraw the icon - */ ro_gui_redraw_icon(w, i); } @@ -230,8 +282,8 @@ void ro_gui_set_icon_string(wimp_w w, wimp_i i, const char *text) { /** * Set the contents of an icon to a number. * - * \param w window handle - * \param i icon handle + * \param w window handle + * \param i icon handle * \param value value */ void ro_gui_set_icon_integer(wimp_w w, wimp_i i, int value) { @@ -244,8 +296,8 @@ void ro_gui_set_icon_integer(wimp_w w, wimp_i i, int value) { /** * Set the selected state of an icon. * - * \param w window handle - * \param i icon handle + * \param w window handle + * \param i icon handle * \param state selected state */ void ro_gui_set_icon_selected_state(wimp_w w, wimp_i i, bool state) { @@ -263,8 +315,8 @@ void ro_gui_set_icon_selected_state(wimp_w w, wimp_i i, bool state) { /** * Gets the selected state of an icon. * - * \param w window handle - * \param i icon handle + * \param w window handle + * \param i icon handle */ bool ro_gui_get_icon_selected_state(wimp_w w, wimp_i i) { os_error *error; @@ -285,8 +337,8 @@ bool ro_gui_get_icon_selected_state(wimp_w w, wimp_i i) { /** * Set the shaded state of an icon. * - * \param w window handle - * \param i icon handle + * \param w window handle + * \param i icon handle * \param state selected state */ void ro_gui_set_icon_shaded_state(wimp_w w, wimp_i i, bool state) { @@ -305,8 +357,8 @@ void ro_gui_set_icon_shaded_state(wimp_w w, wimp_i i, bool state) { /** * Gets the shaded state of an icon. * - * \param w window handle - * \param i icon handle + * \param w window handle + * \param i icon handle */ bool ro_gui_get_icon_shaded_state(wimp_w w, wimp_i i) { wimp_icon_state ic; @@ -320,8 +372,8 @@ bool ro_gui_get_icon_shaded_state(wimp_w w, wimp_i i) { /** * Set the button type of an icon. * - * \param w window handle - * \param i icon handle + * \param w window handle + * \param i icon handle * \param type button type */ void ro_gui_set_icon_button_type(wimp_w w, wimp_i i, int type) { @@ -332,14 +384,14 @@ void ro_gui_set_icon_button_type(wimp_w w, wimp_i i, int type) { LOG(("xwimp_set_icon_state: 0x%x: %s", error->errnum, error->errmess)); warn_user("WimpError", error->errmess); - } + } } /** * Set a window title (does *not* redraw the title) * - * \param w window handle + * \param w window handle * \param text new title (copied) */ void ro_gui_set_window_title(wimp_w w, const char *text) { @@ -360,8 +412,10 @@ void ro_gui_set_window_title(wimp_w w, const char *text) { /* Set the title string */ strncpy(window.title_data.indirected_text.text, text, - (unsigned int)window.title_data.indirected_text.size - 1); - window.title_data.indirected_text.text[window.title_data.indirected_text.size - 1] = '\0'; + (unsigned int)window.title_data.indirected_text.size + - 1); + window.title_data.indirected_text.text[ + window.title_data.indirected_text.size - 1] = '\0'; /* Redraw accordingly */ @@ -371,7 +425,7 @@ void ro_gui_set_window_title(wimp_w w, const char *text) { error->errnum, error->errmess)); warn_user("WimpError", error->errmess); return; - } + } } @@ -379,14 +433,13 @@ void ro_gui_set_window_title(wimp_w w, const char *text) { * Places the caret in the first available icon */ void ro_gui_set_caret_first(wimp_w w) { - int icon, button; + int icon, b; wimp_window_state win_state; wimp_window_info_base window; wimp_icon_state state; os_error *error; - /* Check the window is open - */ + /* check the window is open */ win_state.w = w; error = xwimp_get_window_state(&win_state); if (error) { @@ -395,10 +448,10 @@ void ro_gui_set_caret_first(wimp_w w) { warn_user("WimpError", error->errmess); return; } - if (!(win_state.flags & wimp_WINDOW_OPEN)) return; - - /* Get the window details - */ + if (!(win_state.flags & wimp_WINDOW_OPEN)) + return; + + /* get the window details for the icon count */ window.w = w; error = xwimp_get_window_info_header_only((wimp_window_info *)&window); if (error) { @@ -408,12 +461,9 @@ void ro_gui_set_caret_first(wimp_w w) { return; } - /* Work through our icons - */ + /* work through all the icons */ state.w = w; for (icon = 0; icon < window.icon_count; icon++) { - /* Get the icon state - */ state.i = icon; error = xwimp_get_icon_state(&state); if (error) { @@ -423,25 +473,23 @@ void ro_gui_set_caret_first(wimp_w w) { return; } - /* Ignore if it's shaded - */ + /* ignore if it's shaded or not writable */ if (state.icon.flags & wimp_ICON_SHADED) continue; + b = (state.icon.flags >> wimp_ICON_BUTTON_TYPE_SHIFT) & 0xf; + if ((b != wimp_BUTTON_WRITE_CLICK_DRAG) && + (b != wimp_BUTTON_WRITABLE)) + continue; - /* Check if it's writable - */ - button = (state.icon.flags >> wimp_ICON_BUTTON_TYPE_SHIFT) & 0xf; - if ((button == wimp_BUTTON_WRITE_CLICK_DRAG) || - (button == wimp_BUTTON_WRITABLE)) { - error = xwimp_set_caret_position(w, icon, 0, 0, -1, - strlen(state.icon.data.indirected_text.text)); - if (error) { - LOG(("xwimp_set_caret_position: 0x%x: %s", - error->errnum, error->errmess)); - warn_user("WimpError", error->errmess); - } - return; + /* move the caret */ + error = xwimp_set_caret_position(w, icon, 0, 0, -1, + strlen(state.icon.data.indirected_text.text)); + if (error) { + LOG(("xwimp_set_caret_position: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); } + return; } } @@ -458,38 +506,36 @@ void ro_gui_open_window_centre(wimp_w parent, wimp_w child) { int mid_x, mid_y; int dimension, scroll_width; - /* Get the parent window state - */ + /* get the parent window state */ if (parent) { state.w = parent; error = xwimp_get_window_state(&state); if (error) { + LOG(("xwimp_get_window_state: 0x%x: %s", + error->errnum, error->errmess)); warn_user("WimpError", error->errmess); return; } scroll_width = ro_get_vscroll_width(parent); - - /* Get the centre of the parent - */ - mid_x = (state.visible.x0 + state.visible.x1 + scroll_width) / 2; - mid_y = (state.visible.y0 + state.visible.y1) / 2; - } else { + mid_x = (state.visible.x0 + state.visible.x1 + scroll_width); + mid_y = (state.visible.y0 + state.visible.y1); + } else { ro_gui_screen_size(&mid_x, &mid_y); - mid_x /= 2; - mid_y /= 2; - } + } + mid_x /= 2; + mid_y /= 2; - /* Get the child window state - */ + /* get the child window state */ state.w = child; error = xwimp_get_window_state(&state); if (error) { + LOG(("xwimp_get_window_state: 0x%x: %s", + error->errnum, error->errmess)); warn_user("WimpError", error->errmess); return; } - /* Move to the centre of the parent at the top of the stack - */ + /* move to the centre of the parent at the top of the stack */ dimension = state.visible.x1 - state.visible.x0; scroll_width = ro_get_vscroll_width(history_window); state.visible.x0 = mid_x - (dimension + scroll_width) / 2; @@ -498,7 +544,13 @@ void ro_gui_open_window_centre(wimp_w parent, wimp_w child) { state.visible.y0 = mid_y - dimension / 2; state.visible.y1 = state.visible.y0 + dimension; state.next = wimp_TOP; - wimp_open_window((wimp_open *) &state); + error = xwimp_open_window((wimp_open *) &state); + if (error) { + LOG(("xwimp_open_window: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + return; + } } @@ -582,7 +634,7 @@ bool ro_gui_wimp_sprite_exists(const char *sprite) * Open a window as a pane in another window. * * \param parent parent window - * \param pane pane to open in parent window + * \param pane pane to open in parent window * \param offset inset of pane from parent */ @@ -632,12 +684,12 @@ void ro_gui_open_pane(wimp_w parent, wimp_w pane, int offset) /** * Performs simple user redraw for a window. * - * \param user_fill whether to fill the redraw area + * \param user_fill whether to fill the redraw area * \param user_colour the colour to use when filling */ -void ro_gui_user_redraw(wimp_draw *redraw, bool user_fill, os_colour user_colour) -{ +void ro_gui_user_redraw(wimp_draw *redraw, bool user_fill, + os_colour user_colour) { os_error *error; osbool more; @@ -649,7 +701,7 @@ void ro_gui_user_redraw(wimp_draw *redraw, bool user_fill, os_colour user_colour return; } while (more) { - if (user_fill) { + if (user_fill) { error = xcolourtrans_set_gcol(user_colour, colourtrans_SET_BG, os_ACTION_OVERWRITE, 0, 0); @@ -659,7 +711,7 @@ void ro_gui_user_redraw(wimp_draw *redraw, bool user_fill, os_colour user_colour warn_user("MiscError", error->errmess); } os_clg(); - } + } error = xwimp_get_rectangle(redraw, &more); if (error) { LOG(("xwimp_get_rectangle: 0x%x: %s", @@ -669,3 +721,51 @@ void ro_gui_user_redraw(wimp_draw *redraw, bool user_fill, os_colour user_colour } } } + + +/** + * Sets whether a piece of window furniture is present for a window. + * + * \param w the window to modify + * \param bic_mask the furniture flags to clear + * \param xor_mask the furniture flags to toggle + */ +void ro_gui_wimp_update_window_furniture(wimp_w w, wimp_window_flags bic_mask, + wimp_window_flags xor_mask) { + wimp_window_state state; + os_error *error; + bool open; + + state.w = w; + error = xwimp_get_window_state(&state); + if (error) { + LOG(("xwimp_get_window_state: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + return; + } + + open = state.flags & wimp_WINDOW_OPEN; + state.flags &= ~(63 << 16); /* clear bits 16-21 */ + state.flags &= ~bic_mask; + state.flags ^= xor_mask; + if (!open) + state.next = wimp_HIDDEN; + error = xwimp_open_window_nested_with_flags(&state, (wimp_w)-1, 0); + if (error) { + LOG(("xwimp_open_window: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + return; + } + + if (!open) { + error = xwimp_close_window(w); + if (error) { + LOG(("xwimp_close_window: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + return; + } + } +} diff --git a/riscos/wimp.h b/riscos/wimp.h index aaf048a0f..6c9ae0cd0 100644 --- a/riscos/wimp.h +++ b/riscos/wimp.h @@ -21,12 +21,6 @@ #include "oslib/os.h" #include "oslib/wimp.h" -struct eig_factors { - int xeig; - int yeig; -}; - - int ro_get_hscroll_height(wimp_w w); int ro_get_vscroll_width(wimp_w w); struct eig_factors ro_read_eig_factors(os_mode mode); @@ -56,4 +50,7 @@ wimp_w ro_gui_set_window_background_colour(wimp_w window, wimp_colour background void ro_gui_set_icon_colours(wimp_w window, wimp_i icon, wimp_colour foreground, wimp_colour background); void ro_gui_user_redraw(wimp_draw *redraw, bool user_fill, os_colour user_colour); +void ro_gui_wimp_update_window_furniture(wimp_w w, wimp_window_flags bic_mask, + wimp_window_flags xor_mask); + #endif diff --git a/riscos/window.c b/riscos/window.c index f17db239c..8cfb254e2 100644 --- a/riscos/window.c +++ b/riscos/window.c @@ -33,6 +33,7 @@ #include "netsurf/riscos/buffer.h" #include "netsurf/riscos/global_history.h" #include "netsurf/riscos/gui.h" +#include "netsurf/riscos/menus.h" #include "netsurf/riscos/options.h" #include "netsurf/riscos/theme.h" #include "netsurf/riscos/thumbnail.h" @@ -49,8 +50,6 @@ static struct gui_window *window_list = 0; /** GUI window which is being redrawn. Valid only during redraw. */ struct gui_window *ro_gui_current_redraw_gui; -/** GUI window which the current zoom window refers to. */ -struct gui_window *ro_gui_current_zoom_gui; static float scale_snap_to[] = {0.10, 0.125, 0.25, 0.333, 0.5, 0.75, 1.0, @@ -212,7 +211,7 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw, window.title_data.indirected_text.size = 255; window.icon_count = 0; if (open_centred) { - scroll_width = ro_get_vscroll_width(g->window); + scroll_width = ro_get_vscroll_width(NULL); window.visible.x0 -= scroll_width; } @@ -1199,12 +1198,6 @@ void ro_gui_window_mouse_at(struct gui_window *g, wimp_pointer *pointer) void ro_gui_toolbar_click(struct gui_window *g, wimp_pointer *pointer) { - struct node *node; - char url[80]; - - /* Store the toolbar - */ - current_toolbar = g->toolbar; /* try to close url-completion */ ro_gui_url_complete_close(g, pointer->i); @@ -1212,8 +1205,8 @@ void ro_gui_toolbar_click(struct gui_window *g, wimp_pointer *pointer) /* Handle Menu clicks */ if (pointer->buttons == wimp_CLICK_MENU) { - ro_gui_create_menu(toolbar_menu, pointer->pos.x, - pointer->pos.y, g); + ro_gui_menu_create(browser_toolbar_menu, pointer->pos.x, + pointer->pos.y, g->window); return; } @@ -1228,98 +1221,79 @@ void ro_gui_toolbar_click(struct gui_window *g, wimp_pointer *pointer) */ switch (pointer->i) { case ICON_TOOLBAR_BACK: - history_back(g->bw, g->bw->history); + ro_gui_menu_handle_action(g->window, + BROWSER_NAVIGATE_BACK, true); break; + case ICON_TOOLBAR_FORWARD: - history_forward(g->bw, g->bw->history); + ro_gui_menu_handle_action(g->window, + BROWSER_NAVIGATE_FORWARD, true); break; case ICON_TOOLBAR_STOP: - browser_window_stop(g->bw); + ro_gui_menu_handle_action(g->window, + BROWSER_NAVIGATE_STOP, true); break; case ICON_TOOLBAR_RELOAD: if (pointer->buttons == wimp_CLICK_SELECT) - browser_window_reload(g->bw, false); + ro_gui_menu_handle_action(g->window, + BROWSER_NAVIGATE_RELOAD, true); else if (pointer->buttons == wimp_CLICK_ADJUST) - browser_window_reload(g->bw, true); + ro_gui_menu_handle_action(g->window, + BROWSER_NAVIGATE_RELOAD_ALL, true); break; case ICON_TOOLBAR_HISTORY: - if (pointer->buttons == wimp_CLICK_SELECT) { - ro_gui_history_open(g->bw, g->bw->history, true); - } else if (global_history_tree) { - ro_gui_global_history_show(); - } + if (pointer->buttons == wimp_CLICK_SELECT) + ro_gui_menu_handle_action(g->window, + HISTORY_SHOW_LOCAL, true); + else + ro_gui_menu_handle_action(g->window, + HISTORY_SHOW_GLOBAL, true); break; case ICON_TOOLBAR_HOME: - if (option_homepage_url && option_homepage_url[0]) { - if (pointer->buttons == wimp_CLICK_SELECT) { - browser_window_go(g->bw, - option_homepage_url, 0); - } else { - browser_window_create(option_homepage_url, NULL, 0); - } - } else { - snprintf(url, sizeof url, - "file:/<NetSurf$Dir>/Docs/intro_%s", - option_language); - if (pointer->buttons == wimp_CLICK_SELECT) { - browser_window_go(g->bw, url, 0); - } else { - browser_window_create(url, NULL, 0); - } - } + ro_gui_menu_handle_action(g->window, + BROWSER_NAVIGATE_HOME, true); break; #ifdef WITH_SEARCH case ICON_TOOLBAR_SEARCH: - ro_gui_search_open(g, 0, 0, false, true); + ro_gui_menu_handle_action(g->window, + BROWSER_FIND_TEXT, true); break; #endif case ICON_TOOLBAR_SCALE: - current_gui = g; - ro_gui_menu_prepare_scale(); - ro_gui_dialog_open_persistant(g->window, dialog_zoom, true); + ro_gui_menu_handle_action(g->window, + BROWSER_SCALE_VIEW, true); break; case ICON_TOOLBAR_BOOKMARK: - if ((pointer->buttons == wimp_CLICK_ADJUST) && (hotlist_tree)) { - node = tree_create_URL_node(hotlist_tree->root, - g->bw->current_content->title, - g->bw->current_content->url, - ro_content_filetype(g->bw->current_content), - time(NULL), -1, 0); - if (node) { - tree_redraw_area(hotlist_tree, - node->box.x - NODE_INSTEP, 0, - NODE_INSTEP, 16384); - tree_handle_node_changed(hotlist_tree, node, false, - true); - ro_gui_tree_scroll_visible(hotlist_tree, &node->data); - } - } else if (hotlist_tree) { - ro_gui_hotlist_show(); - } + if (pointer->buttons == wimp_CLICK_ADJUST) + ro_gui_menu_handle_action(g->window, + HOTLIST_ADD_URL, true); + else + ro_gui_menu_handle_action(g->window, + HOTLIST_SHOW, true); break; case ICON_TOOLBAR_SAVE: - current_gui = g; - if (g->bw->current_content) - ro_gui_save_open(GUI_SAVE_SOURCE, - g->bw->current_content, - false, 0, 0, g->window, false); + if (pointer->buttons == wimp_CLICK_ADJUST) + ro_gui_menu_handle_action(g->window, + BROWSER_SAVE_COMPLETE, true); + else + ro_gui_menu_handle_action(g->window, + BROWSER_SAVE, true); break; case ICON_TOOLBAR_PRINT: - current_gui = g; - ro_gui_print_open(g, 0, 0, false, false); + ro_gui_menu_handle_action(g->window, + BROWSER_PRINT, true); break; case ICON_TOOLBAR_URL: ro_gui_url_complete_start(g); break; case ICON_TOOLBAR_SUGGEST: - current_gui = g; ro_gui_popup_menu(url_suggest_menu, - current_toolbar->toolbar_handle, + g->toolbar->toolbar_handle, ICON_TOOLBAR_SUGGEST); break; } @@ -1403,8 +1377,8 @@ void ro_gui_window_click(struct gui_window *g, wimp_pointer *pointer) } if (pointer->buttons == wimp_CLICK_MENU) - ro_gui_create_menu(browser_menu, pointer->pos.x, - pointer->pos.y, g); + ro_gui_menu_create(browser_menu, pointer->pos.x, + pointer->pos.y, pointer->w); else if (pointer->buttons == wimp_CLICK_SELECT) browser_window_mouse_click(g->bw, (shift == 0xff) ? BROWSER_MOUSE_CLICK_1_MOD @@ -1424,6 +1398,7 @@ void ro_gui_window_click(struct gui_window *g, wimp_pointer *pointer) void gui_window_start_throbber(struct gui_window *g) { + ro_gui_menu_objects_moved(); ro_gui_prepare_navigate(g); xos_read_monotonic_time(&g->throbtime); g->throbber = 0; @@ -1559,14 +1534,12 @@ bool ro_gui_window_keypress(struct gui_window *g, int key, bool toolbar) switch (key) { case wimp_KEY_F1: /* Help. */ - ro_gui_open_help_page("docs"); - return true; + return ro_gui_menu_handle_action(g->window, + HELP_OPEN_CONTENTS, false); case wimp_KEY_CONTROL + wimp_KEY_F1: - current_gui = g; - ro_gui_menu_prepare_pageinfo(); - ro_gui_dialog_open_persistant(g->window, dialog_pageinfo, false); - return true; + return ro_gui_menu_handle_action(g->window, + BROWSER_PAGE_INFO, false); case wimp_KEY_F2: if (!g->toolbar) @@ -1586,59 +1559,49 @@ bool ro_gui_window_keypress(struct gui_window *g, int key, bool toolbar) return true; case wimp_KEY_F3: - current_gui = g; - ro_gui_save_open(GUI_SAVE_SOURCE, content, - false, 0, 0, g->window, true); - return true; + return ro_gui_menu_handle_action(g->window, + BROWSER_SAVE, false); case wimp_KEY_CONTROL + wimp_KEY_F3: - current_gui = g; - ro_gui_save_open(GUI_SAVE_TEXT, content, - false, 0, 0, g->window, true); - return true; + return ro_gui_menu_handle_action(g->window, + BROWSER_EXPORT_TEXT, false); case wimp_KEY_SHIFT + wimp_KEY_F3: - current_gui = g; - ro_gui_save_open(GUI_SAVE_COMPLETE, content, - false, 0, 0, g->window, true); - return true; + return ro_gui_menu_handle_action(g->window, + BROWSER_SAVE_COMPLETE, false); case wimp_KEY_CONTROL + wimp_KEY_SHIFT + wimp_KEY_F3: - current_gui = g; - ro_gui_save_open(GUI_SAVE_DRAW, content, - false, 0, 0, g->window, true); - return true; + return ro_gui_menu_handle_action(g->window, + BROWSER_EXPORT_DRAW, false); #ifdef WITH_SEARCH case wimp_KEY_F4: /* Search */ - ro_gui_search_open(g, 0, 0, false, true); - return true; + return ro_gui_menu_handle_action(g->window, + BROWSER_FIND_TEXT, false); #endif - case wimp_KEY_F5: /* Refresh. */ - browser_window_reload(g->bw, false); - return true; + case wimp_KEY_F5: /* Reload */ + return ro_gui_menu_handle_action(g->window, + BROWSER_NAVIGATE_RELOAD, false); - case wimp_KEY_F6: /* Hotlist. */ - ro_gui_hotlist_show(); - return true; + case wimp_KEY_CONTROL + wimp_KEY_F5: /* Full reload */ + return ro_gui_menu_handle_action(g->window, + BROWSER_NAVIGATE_RELOAD_ALL, false); - case wimp_KEY_F7: /* Show history. */ - current_gui = g; - ro_gui_history_open(current_gui->bw, - current_gui->bw->history, false); - return true; + case wimp_KEY_F6: /* Hotlist */ + return ro_gui_menu_handle_action(g->window, + HOTLIST_SHOW, false); - case wimp_KEY_CONTROL + wimp_KEY_F7: /* Show global history. */ - ro_gui_global_history_show(); - return true; + case wimp_KEY_F7: /* Show local history */ + return ro_gui_menu_handle_action(g->window, + HISTORY_SHOW_LOCAL, false); - case wimp_KEY_F8: /* View source. */ - ro_gui_view_source(content); - return true; + case wimp_KEY_CONTROL + wimp_KEY_F7: /* Show global history */ + return ro_gui_menu_handle_action(g->window, + HISTORY_SHOW_GLOBAL, false); - case wimp_KEY_CONTROL + wimp_KEY_F8: /* Dump url_store. */ - url_store_dump(); + case wimp_KEY_F8: /* View source */ + ro_gui_view_source(content); return true; case wimp_KEY_F9: /* Dump content for debugging. */ @@ -1654,12 +1617,14 @@ bool ro_gui_window_keypress(struct gui_window *g, int key, bool toolbar) } return true; - case wimp_KEY_F11: /* Zoom */ - current_gui = g; - ro_gui_menu_prepare_scale(); - ro_gui_dialog_open_persistant(g->window, dialog_zoom, false); + case wimp_KEY_CONTROL + wimp_KEY_F9: /* Dump url_store. */ + url_store_dump(); return true; + case wimp_KEY_F11: /* Zoom */ + return ro_gui_menu_handle_action(g->window, + BROWSER_SCALE_VIEW, false); + case wimp_KEY_SHIFT + wimp_KEY_F11: /* Toggle display of box outlines. */ html_redraw_debug = !html_redraw_debug; gui_window_redraw_window(g); @@ -1685,52 +1650,46 @@ bool ro_gui_window_keypress(struct gui_window *g, int key, bool toolbar) ro_gui_url_complete_start(g); return true; } - browser_window_stop(g->bw); - return true; + return ro_gui_menu_handle_action(g->window, + BROWSER_NAVIGATE_STOP, false); case 14: /* CTRL+N */ - current_gui = g; - browser_window_create(current_gui->bw->current_content->url, - current_gui->bw, 0); - return true; - case 18: /* CTRL+R */ - browser_window_reload(g->bw, false); - return true; + return ro_gui_menu_handle_action(g->window, + BROWSER_NEW_WINDOW, false); case 17: /* CTRL+Q (Zoom out) */ case 23: /* CTRL+W (Zoom in) */ - current_gui = g; - old_scale = current_gui->option.scale; + old_scale = g->option.scale; if (key == 17) { for (int i = SCALE_SNAP_TO_SIZE - 1; i >= 0; i--) if (scale_snap_to[i] < old_scale) { - current_gui->option.scale = scale_snap_to[i]; + g->option.scale = scale_snap_to[i]; break; } } else { for (unsigned int i = 0; i < SCALE_SNAP_TO_SIZE; i++) if (scale_snap_to[i] > old_scale) { - current_gui->option.scale = scale_snap_to[i]; + g->option.scale = scale_snap_to[i]; break; } } - if (current_gui->option.scale < scale_snap_to[0]) - current_gui->option.scale = scale_snap_to[0]; - if (current_gui->option.scale > scale_snap_to[SCALE_SNAP_TO_SIZE - 1]) - current_gui->option.scale = + if (g->option.scale < scale_snap_to[0]) + g->option.scale = scale_snap_to[0]; + if (g->option.scale > scale_snap_to[SCALE_SNAP_TO_SIZE - 1]) + g->option.scale = scale_snap_to[SCALE_SNAP_TO_SIZE - 1]; - if (old_scale != current_gui->option.scale) { - current_gui->reformat_pending = true; + if (old_scale != g->option.scale) { + g->reformat_pending = true; if ((content) && (content->type != CONTENT_HTML)) - browser_window_update(current_gui->bw, false); + browser_window_update(g->bw, false); gui_reformat_pending = true; } return true; #ifdef WITH_PRINT case wimp_KEY_PRINT: - ro_gui_print_open(g, 0, 0, false, true); - return true; + return ro_gui_menu_handle_action(g->window, + BROWSER_PRINT, false); #endif case wimp_KEY_UP: @@ -2128,6 +2087,7 @@ void gui_window_set_pointer(gui_pointer_shape shape) void gui_window_new_content(struct gui_window *g) { + ro_gui_menu_objects_moved(); ro_gui_prepare_navigate(g); ro_gui_dialog_close_persistant(g->window); } |