From dfbe3c84f1541590cf4bea240d0abfaf76d5afb1 Mon Sep 17 00:00:00 2001 From: James Bursa Date: Thu, 21 Aug 2003 21:39:07 +0000 Subject: [project @ 2003-08-21 21:39:07 by bursa] Break out menu related code. svn path=/import/netsurf/; revision=245 --- !NetSurf/Resources/en/Messages | 24 +++++ makefile | 2 +- riscos/gui.c | 225 +++------------------------------------ riscos/gui.h | 19 +++- riscos/menus.c | 233 +++++++++++++++++++++++++++++++++++++++++ riscos/uri.h | 4 +- 6 files changed, 292 insertions(+), 215 deletions(-) create mode 100644 !NetSurf/Resources/en/Messages create mode 100644 riscos/menus.c diff --git a/!NetSurf/Resources/en/Messages b/!NetSurf/Resources/en/Messages new file mode 100644 index 000000000..4c8317661 --- /dev/null +++ b/!NetSurf/Resources/en/Messages @@ -0,0 +1,24 @@ +# English messages for NetSurf + +# Menus +NetSurf:NetSurf +Info:Info +Choices:Choices... +Quit:Quit + +Page:Page +PageInfo:Info... +Save:Save +Export:Export +Print:Print... +Selection:Selection +Copy:Copy to clipboard +SelectAll:Select all +Clear:Clear selection +Navigate:Navigate +OpenURL:Open URL... +Home:Home page +Back:Back one page +Forward:Forward one page +Reload:Reload this page + diff --git a/makefile b/makefile index 0612c5722..2021e23a1 100644 --- a/makefile +++ b/makefile @@ -12,7 +12,7 @@ OBJECTS_COMMON = cache.o content.o fetch.o fetchcache.o other.o \ messages.o utils.o OBJECTS = $(OBJECTS_COMMON) \ browser.o netsurf.o \ - gif.o gui.o jpeg.o png.o theme.o plugin.o \ + gif.o gui.o jpeg.o menus.o png.o theme.o plugin.o \ options.o filetype.o font.o uri.o OBJECTS_DEBUG = $(OBJECTS_COMMON) \ netsurfd.o \ diff --git a/riscos/gui.c b/riscos/gui.c index 4e24c9132..bf1bfe89c 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -38,65 +38,10 @@ static gui_window *window_list = 0; int gadget_subtract_x; int gadget_subtract_y; -#define browser_menu_flags (wimp_ICON_TEXT | wimp_ICON_FILLED | (wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT) | (wimp_COLOUR_WHITE << wimp_ICON_BG_COLOUR_SHIFT)) const char* HOME_URL = "file:///%3CNetSurf$Dir%3E/Resources/intro"; const char* GESTURES_URL = "file:///%3CNetSurf$Dir%3E/Resources/gestures"; const char* THEMES_URL = "http://netsurf.sourceforge.net/themes/"; -wimp_MENU(3) netsurf_iconbar_menu = - { - { "NetSurf" }, 7,2,7,0, 0, 44, 0, - { - { 0, wimp_NO_SUB_MENU, browser_menu_flags, { "MICONBAR1" } }, - { 0, wimp_NO_SUB_MENU, browser_menu_flags, { "MICONBAR2" } }, - { wimp_MENU_LAST, wimp_NO_SUB_MENU, browser_menu_flags, { "MICONBAR3" } } - } - }; -#define ICONBAR_MENU_ENTRIES 3 - -wimp_MENU(3) browser_save_menu = - { - { "Save as" }, 7,2,7,0, 0, 44, 0, - { - { 0, wimp_NO_SUB_MENU, browser_menu_flags, { "MSAVE1" } }, - { 0, wimp_NO_SUB_MENU, browser_menu_flags, { "MSAVE2" } }, - { wimp_MENU_LAST, wimp_NO_SUB_MENU, browser_menu_flags, { "MSAVE3" } } - } - }; - -wimp_MENU(3) browser_selection_menu = - { - { "Selection" }, 7,2,7,0, 0, 44, 0, - { - { 0, wimp_NO_SUB_MENU, browser_menu_flags | wimp_ICON_SHADED, { "MSELECT1" } }, - { 0, wimp_NO_SUB_MENU, browser_menu_flags, { "MSELECT2" } }, - { wimp_MENU_LAST, wimp_NO_SUB_MENU, browser_menu_flags, { "MSELECT3" } } - } - }; - -wimp_MENU(5) browser_navigate_menu = - { - { "Navigate" }, 7,2,7,0, 0, 44, 0, - { - { 0, wimp_NO_SUB_MENU, browser_menu_flags | wimp_ICON_SHADED, { "MNAVIG1" } }, - { 0, wimp_NO_SUB_MENU, browser_menu_flags, { "MNAVIG2" } }, - { 0, wimp_NO_SUB_MENU, browser_menu_flags, { "MNAVIG3" } }, - { 0, wimp_NO_SUB_MENU, browser_menu_flags, { "MNAVIG4" } }, - { wimp_MENU_LAST, wimp_NO_SUB_MENU, browser_menu_flags | wimp_ICON_SHADED, { "MNAVIG5" } } - } - }; - -wimp_MENU(4) browser_menu = - { - { "NetSurf" }, 7,2,7,0, 0, 44, 0, - { - { 0, wimp_NO_SUB_MENU, browser_menu_flags | wimp_ICON_SHADED, { "MBROWSE1" } }, - { 0, (wimp_menu*) &browser_save_menu, browser_menu_flags, { "MBROWSE2" } }, - { 0, (wimp_menu*) &browser_selection_menu, browser_menu_flags, { "MBROWSE3" } }, - { wimp_MENU_LAST, (wimp_menu*) &browser_navigate_menu, browser_menu_flags, { "MBROWSE4" } } - } - }; - wimp_menu* theme_menu = NULL; const char* THEME_DIR = ".Themes"; @@ -154,9 +99,6 @@ static void ro_gui_load_messages(void); static wimp_w ro_gui_load_template(const char* template_name); static void ro_gui_load_templates(void); static wimp_i ro_gui_icon(char* token); -static void ro_gui_transform_menu_entry(wimp_menu_entry* e); -static void ro_gui_transform_menus(void); -static void ro_gui_create_menu(wimp_menu* menu, int x, int y, gui_window* g); static int window_x_units(int scr_units, wimp_window_state* win); static int window_y_units(int scr_units, wimp_window_state* win); static void ro_gui_window_redraw_box(struct content *content, struct box * box, @@ -181,8 +123,6 @@ static int anglesDifferent(double a, double b); static mouseaction ro_gui_try_mouse_action(void); static void ro_gui_poll_queue(wimp_event_no event, wimp_block* block); static void ro_gui_keypress(wimp_key* key); -static void ro_gui_copy_selection(gui_window* g); -static void ro_gui_menu_selection(wimp_selection* selection); static void ro_msg_datasave(wimp_message* block); static void ro_msg_dataload(wimp_message* block); static void gui_set_gadget_extent(struct box* box, int x, int y, os_box* extent, struct gui_gadget* g); @@ -269,72 +209,10 @@ wimp_i ro_gui_icon(char* token) return -1; } -void ro_gui_transform_menu_entry(wimp_menu_entry* e) -{ - char buffer[256]; - char* block; - int size; - - fprintf(stderr, "looking up message %s\n", e->data.text); - messagetrans_lookup(&netsurf_messages_cb, e->data.text, buffer, 256, 0,0,0,0, &size); - fprintf(stderr, "message '%s' uses %d bytes\n", buffer, size + 1); - block = xcalloc((unsigned int) size + 1, 1); - fprintf(stderr, "copying buffer to block\n"); - strncpy(block, buffer, (unsigned int) size); - - fprintf(stderr, "applying flags\n"); - e->icon_flags = e->icon_flags | wimp_ICON_INDIRECTED; - e->data.indirected_text.text = block; - e->data.indirected_text.validation = NULL; - e->data.indirected_text.size = size+1; - - fprintf(stderr, "returning\n"); - - return; -} - -void ro_gui_transform_menus(void) -{ - int i; - - for (i = 0; i < 3; i++) - ro_gui_transform_menu_entry(&netsurf_iconbar_menu.entries[i]); - - for (i = 0; i < 3; i++) - ro_gui_transform_menu_entry(&browser_save_menu.entries[i]); - - for (i = 0; i < 3; i++) - ro_gui_transform_menu_entry(&browser_selection_menu.entries[i]); - - for (i = 0; i < 5; i++) - ro_gui_transform_menu_entry(&browser_navigate_menu.entries[i]); - - for (i = 0; i < 4; i++) - ro_gui_transform_menu_entry(&browser_menu.entries[i]); - - browser_save_menu.entries[0].sub_menu = (wimp_menu*) netsurf_saveas; - browser_save_menu.entries[1].sub_menu = (wimp_menu*) netsurf_saveas; - browser_save_menu.entries[2].sub_menu = (wimp_menu*) netsurf_saveas; - browser_selection_menu.entries[2].sub_menu = (wimp_menu*) netsurf_saveas; - - netsurf_iconbar_menu.entries[0].sub_menu = (wimp_menu*) netsurf_info; -} - -wimp_menu* current_menu; -int current_menu_x, current_menu_y; -gui_window* current_gui; wimp_menu* combo_menu; struct gui_gadget* current_gadget; -void ro_gui_create_menu(wimp_menu* menu, int x, int y, gui_window* g) -{ - current_menu = menu; - current_menu_x = x; - current_menu_y = y; - current_gui = g; - wimp_create_menu(menu, x, y); -} int TOOLBAR_HEIGHT = 128; @@ -1113,7 +991,7 @@ void ro_gui_icon_bar_click(wimp_pointer* pointer) { if (pointer->buttons == wimp_CLICK_MENU) { - ro_gui_create_menu((wimp_menu*)&netsurf_iconbar_menu, pointer->pos.x - 64, 96 + ICONBAR_MENU_ENTRIES*44, NULL); + ro_gui_create_menu(iconbar_menu, pointer->pos.x - 64, 96 + iconbar_menu_height, NULL); } else if (pointer->buttons == wimp_CLICK_SELECT) { @@ -1147,6 +1025,7 @@ void gui_init(int argc, char** argv) fileswitch_object_type *ot; NETSURF_DIR = getenv("NetSurf$Dir"); + messages_load(".Resources.en.Messages"); /* __riscosify_control = __RISCOSIFY_NO_PROCESS; */ @@ -1196,7 +1075,7 @@ void gui_init(int argc, char** argv) ro_gui_load_templates(); ro_gui_load_messages(); - ro_gui_transform_menus(); + ro_gui_menus_init(); } void ro_gui_throb(void) @@ -1769,7 +1648,7 @@ void ro_gui_window_click(gui_window* g, wimp_pointer* pointer) int z; os_mouse(&x, &y, &z, &now); - ro_gui_create_menu((wimp_menu*) &browser_menu, x - 64, y, g); + ro_gui_create_menu(browser_menu, x - 64, y, g); } else { @@ -2091,93 +1970,6 @@ void ro_gui_copy_selection(gui_window* g) } } -void ro_gui_menu_selection(wimp_selection* selection) -{ - struct browser_action msg; - wimp_pointer pointer; - int i; - wimp_get_pointer_info(&pointer); - - fprintf(stderr, "Menu selection: "); - i = 0; while (selection->items[i] != -1) { - fprintf(stderr, "%d ", selection->items[i]); - i++; - } - fprintf(stderr, "\n"); - - if (current_menu == combo_menu && selection->items[0] >= 0) - { - struct browser_action msg; - msg.type = act_GADGET_SELECT; - msg.data.gadget_select.g= current_gadget; - msg.data.gadget_select.item = selection->items[0]; - browser_window_action(current_gui->data.browser.bw, &msg); - } - else if (current_menu == (wimp_menu*) &netsurf_iconbar_menu) - { - if (selection->items[0] == 1) - gui_show_choices(); - if (selection->items[0] == 2) - netsurf_quit = 1; - } - else if (current_menu == (wimp_menu*) &browser_menu) - { - switch (selection->items[0]) - { - case 0: /* Display -> */ - break; - case 1: /* Save -> */ - break; - case 2: /* Selection -> */ - switch (selection->items[1]) - { - case 0: /* Copy to clipboard */ - ro_gui_copy_selection(current_gui); - break; - case 1: /* Clear */ - msg.type = act_CLEAR_SELECTION; - browser_window_action(current_gui->data.browser.bw, &msg); - break; - case 2: /* Save */ - break; - } - break; - case 3: /* Navigate -> */ - switch (selection->items[1]) - { - case 0: /* Open URL... */ - break; - case 1: /* Home */ - browser_window_open_location(current_gui->data.browser.bw, HOME_URL); - break; - case 2: /* Back */ - browser_window_back(current_gui->data.browser.bw); - break; - case 3: /* Forward */ - browser_window_forward(current_gui->data.browser.bw); - break; - } - break; - } - - } - else if (current_menu == theme_menu && theme_menu != NULL) - { - strcpy(theme_choices.name, theme_menu->entries[selection->items[0]].data.indirected_text.text); - set_icon_string(config_th, ro_gui_icon("CONFIG_TH_NAME"), theme_choices.name); - load_theme_preview(theme_choices.name); - wimp_set_icon_state(config_th, ro_gui_icon("CONFIG_TH_NAME"), 0, 0); - wimp_set_icon_state(config_th, ro_gui_icon("CONFIG_TH_PREVIEW"), 0, 0); - } - - if (pointer.buttons == wimp_CLICK_ADJUST) - { - if (current_menu == combo_menu) - gui_gadget_combo(current_gui->data.browser.bw, current_gadget, current_menu_x, current_menu_y); - else - ro_gui_create_menu(current_menu, current_menu_x, current_menu_y, current_gui); - } -} void gui_poll(void) { @@ -3013,4 +2805,13 @@ void ro_gui_redraw_config_th(wimp_draw* redraw) } +void ro_gui_theme_menu_selection(char *theme) +{ + strcpy(theme_choices.name, theme); + set_icon_string(config_th, ro_gui_icon("CONFIG_TH_NAME"), theme_choices.name); + load_theme_preview(theme_choices.name); + wimp_set_icon_state(config_th, ro_gui_icon("CONFIG_TH_NAME"), 0, 0); + wimp_set_icon_state(config_th, ro_gui_icon("CONFIG_TH_PREVIEW"), 0, 0); + +} diff --git a/riscos/gui.h b/riscos/gui.h index 3426c59d3..8f087cdfa 100644 --- a/riscos/gui.h +++ b/riscos/gui.h @@ -8,9 +8,17 @@ #ifndef _NETSURF_RISCOS_GUI_H_ #define _NETSURF_RISCOS_GUI_H_ +#include "oslib/wimp.h" #include "netsurf/desktop/browser.h" +#include "netsurf/desktop/netsurf.h" #include "netsurf/desktop/gui.h" -#include "oslib/wimp.h" + +extern wimp_w netsurf_info, netsurf_saveas; +extern wimp_menu *current_menu, *iconbar_menu, *browser_menu, + *combo_menu, *theme_menu; +extern int current_menu_x, current_menu_y, iconbar_menu_height; +extern struct gui_gadget *current_gadget; +extern const char *HOME_URL; struct ro_gui_window { @@ -38,4 +46,13 @@ struct ro_gui_window int old_width; }; +/* in gui.c */ +void ro_gui_copy_selection(gui_window* g); +void ro_gui_theme_menu_selection(char *theme); + +/* in menus.c */ +void ro_gui_menus_init(void); +void ro_gui_create_menu(wimp_menu* menu, int x, int y, gui_window* g); +void ro_gui_menu_selection(wimp_selection* selection); + #endif diff --git a/riscos/menus.c b/riscos/menus.c new file mode 100644 index 000000000..51b76f0ac --- /dev/null +++ b/riscos/menus.c @@ -0,0 +1,233 @@ +/* + * 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 2003 Phil Mellor + * Copyright 2003 James Bursa + * Copyright 2003 John M Bell + */ + +#include +#include +#include "oslib/wimp.h" +#include "netsurf/desktop/gui.h" +#include "netsurf/riscos/gui.h" +#include "netsurf/riscos/theme.h" +#include "netsurf/utils/log.h" +#include "netsurf/utils/messages.h" +#include "netsurf/utils/utils.h" + + +static void translate_menu(wimp_menu *menu); + +wimp_menu *current_menu; +int current_menu_x, current_menu_y; +gui_window *current_gui; + + +/* 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 */ +wimp_menu *iconbar_menu = (wimp_menu *) & (wimp_MENU(3)) { + { "NetSurf" }, 7,2,7,0, 200, 44, 0, + { + { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Info" } }, + { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Choices" } }, + { wimp_MENU_LAST, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Quit" } } + } +}; +int iconbar_menu_height = 3 * 44; + +/* browser window menu structure - based on Style Guide */ +/*wimp_menu *browser_page_menu = (wimp_menu *) & (wimp_MENU(4)) {*/ +static wimp_MENU(4) page_menu = { + { "Page" }, 7,2,7,0, 200, 44, 0, + { + { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Info" } }, + { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Save" } }, + { 0, (wimp_menu *) 1, DEFAULT_FLAGS | wimp_ICON_SHADED, { "Export" } }, + { wimp_MENU_LAST, wimp_NO_SUB_MENU, DEFAULT_FLAGS | wimp_ICON_SHADED, { "Print" } } + } +}; +static wimp_menu *browser_page_menu = (wimp_menu *) &page_menu; + +static wimp_MENU(3) selection_menu = { + { "Selection" }, 7,2,7,0, 300, 44, 0, + { + { 0, 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" } } + } +}; +static wimp_menu *browser_selection_menu = (wimp_menu *) &selection_menu; + +static wimp_MENU(5) navigate_menu = { + { "Navigate" }, 7,2,7,0, 300, 44, 0, + { + { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS | wimp_ICON_SHADED, { "OpenURL" } }, + { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Home" } }, + { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Back" } }, + { 0, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Forward" } }, + { wimp_MENU_LAST, wimp_NO_SUB_MENU, DEFAULT_FLAGS | wimp_ICON_SHADED, { "Reload" } } + } +}; +static wimp_menu *browser_navigate_menu = (wimp_menu *) &navigate_menu; + +wimp_menu *browser_menu = (wimp_menu *) & (wimp_MENU(3)) { + { "NetSurf" }, 7,2,7,0, 200, 44, 0, + { + { 0, (wimp_menu *) &page_menu, DEFAULT_FLAGS, { "Page" } }, + { 0, (wimp_menu *) &selection_menu, DEFAULT_FLAGS, { "Selection" } }, + { wimp_MENU_LAST, (wimp_menu *) &navigate_menu, DEFAULT_FLAGS, { "Navigate" } } + } +}; + + +/** + * 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_selection_menu); + translate_menu(browser_navigate_menu); + + iconbar_menu->entries[0].sub_menu = (wimp_menu *) netsurf_info; + browser_page_menu->entries[1].sub_menu = (wimp_menu *) netsurf_saveas; +} + + +/** + * Replace text in a menu with message values. + */ + +void translate_menu(wimp_menu *menu) +{ + unsigned int i = 0; + + /* title */ + menu->title_data.indirected_text.text = messages_get(menu->title_data.text); + menu->entries[0].menu_flags |= wimp_MENU_TITLE_INDIRECTED; + + /* items */ + do { + menu->entries[i].icon_flags |= wimp_ICON_INDIRECTED; + menu->entries[i].data.indirected_text.text = + messages_get(menu->entries[i].data.text); + menu->entries[i].data.indirected_text.validation = 0; + menu->entries[i].data.indirected_text.size = + strlen(menu->entries[i].data.indirected_text.text) + 1; + i++; + } while ((menu->entries[i].menu_flags & wimp_MENU_LAST) == 0); +} + + +/** + * Display a menu. + */ + +void ro_gui_create_menu(wimp_menu *menu, int x, int y, gui_window *g) +{ + current_menu = menu; + current_menu_x = x; + current_menu_y = y; + current_gui = g; + wimp_create_menu(menu, x, y); +} + + +/** + * Handle menu selection. + */ + +void ro_gui_menu_selection(wimp_selection *selection) +{ + struct browser_action msg; + wimp_pointer pointer; + + wimp_get_pointer_info(&pointer); + + if (current_menu == combo_menu && selection->items[0] >= 0) { + msg.type = act_GADGET_SELECT; + msg.data.gadget_select.g = current_gadget; + msg.data.gadget_select.item = selection->items[0]; + browser_window_action(current_gui->data.browser.bw, &msg); + + } else if (current_menu == iconbar_menu) { + switch (selection->items[0]) { + case 0: /* Info */ + ro_gui_create_menu((wimp_menu *) netsurf_info, + pointer.pos.x, pointer.pos.y, 0); + break; + case 1: /* Choices */ + gui_show_choices(); + break; + case 2: /* Quit */ + netsurf_quit = 1; + break; + } + + } else if (current_menu == browser_menu) { + switch (selection->items[0]) { + case 0: /* Page -> */ + switch (selection->items[1]) { + case 0: /* Info */ + break; + case 1: /* Save */ + break; + case 2: /* Export */ + break; + case 3: /* Print */ + break; + } + break; + case 1: /* 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 */ + msg.type = act_CLEAR_SELECTION; + browser_window_action(current_gui->data.browser.bw, &msg); + break; + } + break; + case 2: /* Navigate -> */ + switch (selection->items[1]) { + case 0: /* Open URL... */ + break; + case 1: /* Home */ + browser_window_open_location(current_gui->data.browser.bw, HOME_URL); + break; + case 2: /* Back */ + browser_window_back(current_gui->data.browser.bw); + break; + case 3: /* Forward */ + browser_window_forward(current_gui->data.browser.bw); + break; + case 4: /* Reload */ + break; + } + break; + } + + } else if (current_menu == theme_menu && theme_menu != NULL) { + ro_gui_theme_menu_selection(theme_menu->entries[selection->items[0]].data.indirected_text.text); + } + + if (pointer.buttons == wimp_CLICK_ADJUST) { + if (current_menu == combo_menu) + gui_gadget_combo(current_gui->data.browser.bw, current_gadget, current_menu_x, current_menu_y); + else + ro_gui_create_menu(current_menu, current_menu_x, current_menu_y, current_gui); + } +} + diff --git a/riscos/uri.h b/riscos/uri.h index 70564bfa7..a7eb5d198 100644 --- a/riscos/uri.h +++ b/riscos/uri.h @@ -8,6 +8,8 @@ #ifndef _NETSURF_RISCOS_URI_H_ #define _NETSURF_RISCOS_URI_H_ -static void ro_uri_message_received(uri_full_message_process*); +#include "oslib/wimp.h" + +void ro_uri_message_received(wimp_message *message); #endif -- cgit v1.2.3