diff --git a/riscos/gui.c b/riscos/gui.c index ecc8f9665..436ee8de8 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -5,6 +5,7 @@ * Copyright 2003 Phil Mellor * Copyright 2004 James Bursa * Copyright 2003 John M Bell + * Copyright 2004 Richard Wilson */ #include @@ -66,8 +67,8 @@ bool gui_reformat_pending = false; /**< Some windows have been resized, gui_drag_type gui_current_drag_type; wimp_t task_handle; /**< RISC OS wimp task handle. */ static clock_t gui_last_poll; /**< Time of last wimp_poll. */ -osspriteop_area *pointers; /**< Sprite area containing pointer data */ -gui_pointer_shape curr_pointer; /**< Current shape of the pointer */ +osspriteop_area *gui_pointers; /**< Sprite area containing pointer data */ + /** Accepted wimp user messages. */ static wimp_MESSAGE_LIST(27) task_messages = { { message_DATA_SAVE, @@ -160,13 +161,13 @@ void gui_init(int argc, char** argv) messages_load(".Resources.LangNames"); error = xwimp_initialise(wimp_VERSION_RO38, "NetSurf", - (const wimp_message_list *) &task_messages, 0, - &task_handle); - if (error) { - LOG(("xwimp_initialise failed: 0x%x: %s", + (const wimp_message_list *) &task_messages, 0, + &task_handle); + if (error) { + LOG(("xwimp_initialise failed: 0x%x: %s", error->errnum, error->errmess)); - exit(EXIT_FAILURE); - } + die(error->errmess); + } ro_gui_check_fonts(); @@ -209,100 +210,6 @@ void gui_init(int argc, char** argv) } -/** - * Clones a browser window's options. - * - * \param new_bw the new browser window - * \param old_bw the browser window to clone from, or NULL for default - */ -void gui_window_clone_options(struct browser_window *new_bw, struct browser_window *old_bw) { - gui_window *old_gui = NULL; - gui_window *new_gui; - - /* Abort on bad input - */ - if (new_bw == NULL) return; - - /* Get our GUIs - */ - new_gui = new_bw->window; - - /* Abort on bad input - */ - if (!new_gui) return; - if (old_bw) old_gui = old_bw->window; - - /* Clone the basic options - */ - if (!old_gui) { - new_gui->scale = ((float)option_scale) / 100; - new_gui->option_dither_sprites = option_dither_sprites; - new_gui->option_filter_sprites = option_filter_sprites; - new_gui->option_animate_images = option_animate_images; - } else { - new_gui->scale = old_gui->scale; - new_gui->option_dither_sprites = old_gui->option_dither_sprites; - new_gui->option_filter_sprites = old_gui->option_filter_sprites; - new_gui->option_animate_images = old_gui->option_animate_images; - } - - /* Set up the toolbar - */ - if (new_gui->data.browser.toolbar) { - if ((old_gui) && (old_gui->data.browser.toolbar)) { - new_gui->data.browser.toolbar->status_width = old_gui->data.browser.toolbar->status_width; - new_gui->data.browser.toolbar->status_window = old_gui->data.browser.toolbar->status_window; - new_gui->data.browser.toolbar->standard_buttons = old_gui->data.browser.toolbar->standard_buttons; - new_gui->data.browser.toolbar->url_bar = old_gui->data.browser.toolbar->url_bar; - new_gui->data.browser.toolbar->throbber = old_gui->data.browser.toolbar->throbber; - } else { - new_gui->data.browser.toolbar->status_width = option_toolbar_status_width; - new_gui->data.browser.toolbar->status_window = option_toolbar_show_status; - new_gui->data.browser.toolbar->standard_buttons = option_toolbar_show_buttons; - new_gui->data.browser.toolbar->url_bar = option_toolbar_show_address; - new_gui->data.browser.toolbar->throbber = option_toolbar_show_throbber; - } - ro_theme_update_toolbar(new_gui); - } -} - - -/** - * Makes a browser window's options the default. - * - * \param bw the browser window to read options from - */ -void gui_window_default_options(struct browser_window *bw) { - gui_window *gui; - - /* Abort on bad input - */ - if (bw == NULL) return; - - /* Get our GUI - */ - gui = bw->window; - if (!gui) return; - - /* Save the basic options - */ - option_scale = gui->scale * 100; - option_dither_sprites = gui->option_dither_sprites; - option_filter_sprites = gui->option_filter_sprites; - option_animate_images = gui->option_animate_images; - - /* Set up the toolbar - */ - if (gui->data.browser.toolbar) { - option_toolbar_status_width = gui->data.browser.toolbar->status_width; - option_toolbar_show_status = gui->data.browser.toolbar->status_window; - option_toolbar_show_buttons = gui->data.browser.toolbar->standard_buttons; - option_toolbar_show_address = gui->data.browser.toolbar->url_bar; - option_toolbar_show_throbber = gui->data.browser.toolbar->throbber; - } -} - - /** * Determine the language to use. * @@ -411,17 +318,17 @@ void ro_gui_pointers_init(void) if (obj_type != fileswitch_IS_FILE) die(".Resources.Pointers missing."); - pointers = malloc(len + 4); - if (!pointers) + gui_pointers = malloc(len + 4); + if (!gui_pointers) die("NoMemory"); - pointers->size = len+4; - pointers->sprite_count = 0; - pointers->first = 16; - pointers->used = 16; + gui_pointers->size = len+4; + gui_pointers->sprite_count = 0; + gui_pointers->first = 16; + gui_pointers->used = 16; e = xosspriteop_load_sprite_file(osspriteop_USER_AREA, - pointers, ".Resources.Pointers"); + gui_pointers, ".Resources.Pointers"); if (e) { LOG(("xosspriteop_load_sprite_file: 0x%x: %s", e->errnum, e->errmess)); @@ -464,7 +371,7 @@ void ro_gui_check_resolvers(void) void gui_quit(void) { ro_gui_history_quit(); - free(pointers); + free(gui_pointers); wimp_close_down(task_handle); xhourglass_off(); } @@ -677,59 +584,6 @@ void ro_gui_null_reason_code(void) } } -/** - * Change mouse pointer shape - */ -void gui_window_set_pointer(gui_pointer_shape shape) -{ - if (shape == curr_pointer) return; - - switch (shape) { - case GUI_POINTER_DEFAULT: - xwimpspriteop_set_pointer_shape("ptr_default", - 1, 0, 0, 0, 0); - break; - case GUI_POINTER_POINT: - xosspriteop_set_pointer_shape(0x100, pointers, - (osspriteop_id)"ptr_point", 1, 6, 0, 0, 0); - break; - case GUI_POINTER_CARET: - xosspriteop_set_pointer_shape(0x100, pointers, - (osspriteop_id)"ptr_caret", 1, 5, 0, 0, 0); - break; - case GUI_POINTER_MENU: - xosspriteop_set_pointer_shape(0x100, pointers, - (osspriteop_id)"ptr_menu", 1, 6, 4, 0, 0); - break; - case GUI_POINTER_UD: - xosspriteop_set_pointer_shape(0x100, pointers, - (osspriteop_id)"ptr_ud", 1, 6, 0, 0, 0); - break; - case GUI_POINTER_LR: - xosspriteop_set_pointer_shape(0x100, pointers, - (osspriteop_id)"ptr_lr", 1, 0, 6, 0, 0); - break; - case GUI_POINTER_LD: - xosspriteop_set_pointer_shape(0x100, pointers, - (osspriteop_id)"ptr_ld", 1, 13, 0, 0, 0); - break; - case GUI_POINTER_RD: - xosspriteop_set_pointer_shape(0x100, pointers, - (osspriteop_id)"ptr_rd", 1, 0, 0, 0, 0); - break; - case GUI_POINTER_CROSS: - xosspriteop_set_pointer_shape(0x100, pointers, - (osspriteop_id)"ptr_cross", 1, 8, 0, 0, 0); - break; - case GUI_POINTER_MOVE: - xosspriteop_set_pointer_shape(0x100, pointers, - (osspriteop_id)"ptr_move", 1, 8, 0, 0, 0); - break; - } - - curr_pointer = shape; -} - void gui_launch_url(char *url) { /* Try ant broadcast first */ if (!ro_url_broadcast(url)) diff --git a/riscos/gui.h b/riscos/gui.h index 9ca0c37d6..de23ac3d1 100644 --- a/riscos/gui.h +++ b/riscos/gui.h @@ -10,6 +10,7 @@ #define _NETSURF_RISCOS_GUI_H_ #include +#include "oslib/osspriteop.h" #include "oslib/wimp.h" #include "netsurf/utils/config.h" #include "netsurf/desktop/browser.h" @@ -31,6 +32,7 @@ extern gui_window *window_list; extern bool gui_reformat_pending; extern bool gui_redraw_debug; extern gui_window *current_gui; +extern osspriteop_area *gui_pointers; typedef enum { GUI_BROWSER_WINDOW, GUI_DOWNLOAD_WINDOW } gui_window_type; typedef enum { GUI_SAVE_SOURCE, GUI_SAVE_DRAW, GUI_SAVE_TEXT, diff --git a/riscos/window.c b/riscos/window.c index 0bc4109b4..261d81095 100644 --- a/riscos/window.c +++ b/riscos/window.c @@ -5,6 +5,7 @@ * Copyright 2003 Phil Mellor * Copyright 2004 James Bursa * Copyright 2003 John M Bell + * Copyright 2004 Richard Wilson */ /** \file @@ -1053,3 +1054,167 @@ bool ro_gui_window_dataload(gui_window *g, wimp_message *message) return true; } + + +/** + * Clones a browser window's options. + * + * \param new_bw the new browser window + * \param old_bw the browser window to clone from, or NULL for default + */ + +void gui_window_clone_options(struct browser_window *new_bw, + struct browser_window *old_bw) { + gui_window *old_gui = NULL; + gui_window *new_gui; + + /* Abort on bad input + */ + if (new_bw == NULL) return; + + /* Get our GUIs + */ + new_gui = new_bw->window; + + /* Abort on bad input + */ + if (!new_gui) return; + if (old_bw) old_gui = old_bw->window; + + /* Clone the basic options + */ + if (!old_gui) { + new_gui->scale = ((float)option_scale) / 100; + new_gui->option_dither_sprites = option_dither_sprites; + new_gui->option_filter_sprites = option_filter_sprites; + new_gui->option_animate_images = option_animate_images; + } else { + new_gui->scale = old_gui->scale; + new_gui->option_dither_sprites = old_gui->option_dither_sprites; + new_gui->option_filter_sprites = old_gui->option_filter_sprites; + new_gui->option_animate_images = old_gui->option_animate_images; + } + + /* Set up the toolbar + */ + if (new_gui->data.browser.toolbar) { + if ((old_gui) && (old_gui->data.browser.toolbar)) { + new_gui->data.browser.toolbar->status_width = old_gui->data.browser.toolbar->status_width; + new_gui->data.browser.toolbar->status_window = old_gui->data.browser.toolbar->status_window; + new_gui->data.browser.toolbar->standard_buttons = old_gui->data.browser.toolbar->standard_buttons; + new_gui->data.browser.toolbar->url_bar = old_gui->data.browser.toolbar->url_bar; + new_gui->data.browser.toolbar->throbber = old_gui->data.browser.toolbar->throbber; + } else { + new_gui->data.browser.toolbar->status_width = option_toolbar_status_width; + new_gui->data.browser.toolbar->status_window = option_toolbar_show_status; + new_gui->data.browser.toolbar->standard_buttons = option_toolbar_show_buttons; + new_gui->data.browser.toolbar->url_bar = option_toolbar_show_address; + new_gui->data.browser.toolbar->throbber = option_toolbar_show_throbber; + } + ro_theme_update_toolbar(new_gui); + } +} + + +/** + * Makes a browser window's options the default. + * + * \param bw the browser window to read options from + */ + +void gui_window_default_options(struct browser_window *bw) { + gui_window *gui; + + /* Abort on bad input + */ + if (bw == NULL) return; + + /* Get our GUI + */ + gui = bw->window; + if (!gui) return; + + /* Save the basic options + */ + option_scale = gui->scale * 100; + option_dither_sprites = gui->option_dither_sprites; + option_filter_sprites = gui->option_filter_sprites; + option_animate_images = gui->option_animate_images; + + /* Set up the toolbar + */ + if (gui->data.browser.toolbar) { + option_toolbar_status_width = gui->data.browser.toolbar->status_width; + option_toolbar_show_status = gui->data.browser.toolbar->status_window; + option_toolbar_show_buttons = gui->data.browser.toolbar->standard_buttons; + option_toolbar_show_address = gui->data.browser.toolbar->url_bar; + option_toolbar_show_throbber = gui->data.browser.toolbar->throbber; + } +} + + +/** An entry in ro_gui_pointer_table. */ +struct ro_gui_pointer_entry { + bool wimp_area; /** The pointer is in the Wimp's sprite area. */ + char sprite_name[12]; + int xactive; + int yactive; +}; + +/** Map from gui_pointer_shape to pointer sprite data. Must be ordered as + * enum gui_pointer_shape. */ +struct ro_gui_pointer_entry ro_gui_pointer_table[] = { + { true, "ptr_default", 0, 0 }, + { false, "ptr_point", 6, 0 }, + { false, "ptr_caret", 4, 9 }, + { false, "ptr_menu", 6, 4 }, + { false, "ptr_ud", 6, 7 }, + { false, "ptr_lr", 7, 6 }, + { false, "ptr_ld", 7, 7 }, + { false, "ptr_rd", 7, 7 }, + { false, "ptr_cross", 7, 7 }, + { false, "ptr_move", 8, 0 }, +}; + +/** + * Change mouse pointer shape + */ + +void gui_window_set_pointer(gui_pointer_shape shape) +{ + static gui_pointer_shape curr_pointer = GUI_POINTER_DEFAULT; + struct ro_gui_pointer_entry *entry; + os_error *error; + + if (shape == curr_pointer) + return; + + assert(shape < sizeof ro_gui_pointer_table / + sizeof ro_gui_pointer_table[0]); + + entry = &ro_gui_pointer_table[shape]; + + if (entry->wimp_area) { + /* pointer in the Wimp's sprite area */ + error = xwimpspriteop_set_pointer_shape(entry->sprite_name, + 1, entry->xactive, entry->yactive, 0, 0); + if (error) { + LOG(("xwimpspriteop_set_pointer_shape: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + } + } else { + /* pointer in our own sprite area */ + error = xosspriteop_set_pointer_shape(osspriteop_USER_AREA, + gui_pointers, + (osspriteop_id) entry->sprite_name, + 1, entry->xactive, entry->yactive, 0, 0); + if (error) { + LOG(("xosspriteop_set_pointer_shape: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + } + } + + curr_pointer = shape; +}