diff options
Diffstat (limited to 'riscos')
92 files changed, 3774 insertions, 2737 deletions
diff --git a/riscos/401login.c b/riscos/401login.c index 6740f54e5..76e28adee 100644 --- a/riscos/401login.c +++ b/riscos/401login.c @@ -22,20 +22,20 @@ #include <stdbool.h> #include <string.h> #include <oslib/wimp.h> -#include "utils/config.h" + #include "content/content.h" #include "content/hlcache.h" #include "content/urldb.h" #include "desktop/browser.h" -#include "desktop/401login.h" #include "desktop/gui.h" -#include "riscos/dialog.h" -#include "riscos/wimp_event.h" #include "utils/log.h" #include "utils/messages.h" -#include "utils/url.h" #include "utils/utils.h" +#include "riscos/gui.h" +#include "riscos/dialog.h" +#include "riscos/wimp_event.h" + #define ICON_401LOGIN_LOGIN 0 #define ICON_401LOGIN_CANCEL 1 #define ICON_401LOGIN_HOST 2 diff --git a/riscos/Makefile.defaults b/riscos/Makefile.defaults index f48024f5a..f719ee3de 100644 --- a/riscos/Makefile.defaults +++ b/riscos/Makefile.defaults @@ -2,30 +2,32 @@ # RISC OS-specific options # ---------------------------------------------------------------------------- - # Enable NetSurf's use of libsvgtiny for displaying SVGs - # Valid options: YES, NO - NETSURF_USE_NSSVG := YES +# Enable NetSurf's use of libsvgtiny for displaying SVGs +# Valid options: YES, NO +NETSURF_USE_NSSVG := YES - # Enable NetSurf's support for displaying RISC OS Draw files - # Valid options: YES, NO - NETSURF_USE_DRAW := YES +# Enable NetSurf's support for displaying RISC OS Draw files +# Valid options: YES, NO +NETSURF_USE_DRAW := YES - # Enable NetSurf's support for displaying RISC OS Sprites - # Valid options: YES, NO - NETSURF_USE_SPRITE := YES +# Enable NetSurf's support for displaying RISC OS Sprites +# Valid options: YES, NO +NETSURF_USE_SPRITE := YES - # Enable NetSurf's use of AWRender for displaying ArtWorks files - # Valid options: YES, NO - NETSURF_USE_ARTWORKS := YES +# Enable NetSurf's use of AWRender for displaying ArtWorks files +# Valid options: YES, NO +NETSURF_USE_ARTWORKS := YES - # Enable NetSurf's support for the Acorn plugin protocol - # Valid options: YES, NO - NETSURF_USE_PLUGINS := NO +# Enable NetSurf's support for the Acorn plugin protocol +# Valid options: YES, NO +NETSURF_USE_PLUGINS := NO - # Enable NetSurf's use of pencil for Drawfile export - # Valid options: YES, NO - NETSURF_USE_DRAW_EXPORT := YES +# Enable NetSurf's use of pencil for Drawfile export +# Valid options: YES, NO +NETSURF_USE_DRAW_EXPORT := YES - # Optimisation levels - CFLAGS += -O2 +# Enable building the source object cache filesystem based backing store. +NETSURF_FS_BACKING_STORE := YES +# Optimisation levels +CFLAGS += -O2 diff --git a/riscos/Makefile.target b/riscos/Makefile.target index 3d64e24f9..46ca34116 100644 --- a/riscos/Makefile.target +++ b/riscos/Makefile.target @@ -42,10 +42,10 @@ TPD_RISCOS = $(foreach TPL,$(notdir $(TPL_RISCOS)), \ RESOURCES = $(TPD_RISCOS) split-messages -CFLAGS += $(WARNFLAGS) -Driscos -std=c99 -D_BSD_SOURCE -D_POSIX_C_SOURCE \ +CFLAGS += -Driscos -std=c99 -D_BSD_SOURCE -D_POSIX_C_SOURCE \ -mpoke-function-name -fno-strict-aliasing -CFLAGS += -I$(GCCSDK_INSTALL_ENV)/include -I$(GCCSDK_INSTALL_ENV)/include/libmng +CFLAGS += -I$(GCCSDK_INSTALL_ENV)/include ifeq ($(HOST),riscos) CFLAGS += -I<OSLib$$Dir> -mthrowback endif diff --git a/riscos/buffer.c b/riscos/buffer.c index 56c245882..a8cb7fdf5 100644 --- a/riscos/buffer.c +++ b/riscos/buffer.c @@ -19,19 +19,22 @@ #include <stdbool.h> #include <stdlib.h> #include <string.h> -#include "swis.h" -#include "oslib/colourtrans.h" -#include "oslib/os.h" -#include "oslib/osspriteop.h" -#include "oslib/wimp.h" -#include "oslib/wimpreadsysinfo.h" +#include <swis.h> +#include <oslib/colourtrans.h> +#include <oslib/os.h> +#include <oslib/osspriteop.h> +#include <oslib/wimp.h> +#include <oslib/wimpreadsysinfo.h> + +#include "utils/nsoption.h" +#include "utils/log.h" + #include "riscos/buffer.h" #include "riscos/gui.h" -#include "utils/nsoption.h" #include "riscos/tinct.h" #include "riscos/wimp.h" #include "riscos/wimputils.h" -#include "utils/log.h" + #define BUFFER_EXCLUSIVE_USER_REDRAW "Only support pure user redraw (faster)" //#define BUFFER_EMULATE_32BPP "Redirect to a 32bpp sprite and plot with Tinct" @@ -246,7 +249,7 @@ void ro_gui_buffer_open(wimp_draw *redraw) */ if ((error = xos_set_ecf_origin(-ro_plot_origin_x, -ro_plot_origin_y)) != NULL) { - LOG(("Invalid ECF origin")); + LOG(("Invalid ECF origin: '%s'", error->errmess)); } } diff --git a/riscos/configure.c b/riscos/configure.c index 0f5ee322b..68aa3c0c6 100644 --- a/riscos/configure.c +++ b/riscos/configure.c @@ -25,18 +25,21 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include "oslib/os.h" -#include "oslib/osbyte.h" -#include "oslib/territory.h" -#include "oslib/wimp.h" +#include <oslib/os.h> +#include <oslib/osbyte.h> +#include <oslib/territory.h> +#include <oslib/wimp.h> + +#include "utils/log.h" +#include "utils/utils.h" +#include "utils/messages.h" + +#include "riscos/gui.h" #include "riscos/dialog.h" #include "riscos/configure.h" #include "riscos/wimp.h" #include "riscos/wimp_event.h" #include "riscos/configure/configure.h" -#include "utils/log.h" -#include "utils/utils.h" -#include "utils/messages.h" #define CONFIGURE_ICON_PADDING_H 32 #define CONFIGURE_ICON_PADDING_V 32 @@ -177,9 +180,8 @@ void ro_gui_configure_open_window(wimp_open *open) int screen_width, screen_height; int height, width; int icons_per_line, icon_lines; - int max_icons_per_line, max_height; + int max_height; os_box extent = { 0, 0, 0, 0 }; - int x, y, l; struct configure_tool *tool; if (!ro_gui_configure_translate()) { @@ -195,6 +197,7 @@ void ro_gui_configure_open_window(wimp_open *open) /* move our icons */ if (icons_per_line != configure_icons_per_line) { + int x, y, l; configure_icons_per_line = icons_per_line; x = CONFIGURE_ICON_PADDING_H / 2; y = -configure_icon_height + (CONFIGURE_ICON_PADDING_V / 2); @@ -238,6 +241,7 @@ void ro_gui_configure_open_window(wimp_open *open) /* set the extent */ if ((configure_height != height) || (configure_width != width)) { + int max_icons_per_line; ro_gui_screen_size(&screen_width, &screen_height); max_icons_per_line = screen_width / configure_icon_width; if (max_icons_per_line > configure_icons) diff --git a/riscos/configure/con_cache.c b/riscos/configure/con_cache.c index 6e402fe81..adaaa82b7 100644 --- a/riscos/configure/con_cache.c +++ b/riscos/configure/con_cache.c @@ -17,25 +17,33 @@ */ #include <stdbool.h> -#include "oslib/hourglass.h" +#include <oslib/hourglass.h> + #include "utils/nsoption.h" -#include "riscos/dialog.h" +#include "utils/filename.h" +#include "utils/messages.h" +#include "utils/utils.h" + #include "riscos/gui.h" #include "riscos/wimp.h" #include "riscos/wimp_event.h" #include "riscos/configure.h" #include "riscos/configure/configure.h" -#include "utils/filename.h" -#include "utils/messages.h" -#include "utils/utils.h" +#include "riscos/dialog.h" #define CACHE_MEMORY_SIZE 3 #define CACHE_MEMORY_DEC 4 #define CACHE_MEMORY_INC 5 -#define CACHE_DEFAULT_BUTTON 7 -#define CACHE_CANCEL_BUTTON 8 -#define CACHE_OK_BUTTON 9 +#define CACHE_DISC_SIZE 10 +#define CACHE_DISC_DEC 11 +#define CACHE_DISC_INC 12 +#define CACHE_DISC_EXPIRE 15 +#define CACHE_DISC_EXPIRE_DEC 16 +#define CACHE_DISC_EXPIRE_INC 17 +#define CACHE_DEFAULT_BUTTON 19 +#define CACHE_CANCEL_BUTTON 20 +#define CACHE_OK_BUTTON 21 static bool ro_gui_options_cache_click(wimp_pointer *pointer); static bool ro_gui_options_cache_ok(wimp_w w); @@ -45,10 +53,19 @@ bool ro_gui_options_cache_initialise(wimp_w w) /* set the current values */ ro_gui_set_icon_decimal(w, CACHE_MEMORY_SIZE, (nsoption_int(memory_cache_size) * 10) >> 20, 1); + ro_gui_set_icon_decimal(w, CACHE_DISC_SIZE, + (int) ((nsoption_uint(disc_cache_size)) >> 20), 0); + ro_gui_set_icon_decimal(w, CACHE_DISC_EXPIRE, + (nsoption_int(disc_cache_age)), 0); /* initialise all functions for a newly created window */ ro_gui_wimp_event_register_numeric_field(w, CACHE_MEMORY_SIZE, CACHE_MEMORY_INC, CACHE_MEMORY_DEC, 0, 640, 1, 1); + ro_gui_wimp_event_register_numeric_field(w, CACHE_DISC_SIZE, + CACHE_DISC_INC, CACHE_DISC_DEC, 0, 4095, 1, 0); + ro_gui_wimp_event_register_numeric_field(w, CACHE_DISC_EXPIRE, + CACHE_DISC_EXPIRE_INC, CACHE_DISC_EXPIRE_DEC, 1, 3650, + 1, 0); ro_gui_wimp_event_register_mouse_click(w, ro_gui_options_cache_click); ro_gui_wimp_event_register_cancel(w, CACHE_CANCEL_BUTTON); ro_gui_wimp_event_register_ok(w, CACHE_OK_BUTTON, @@ -65,7 +82,11 @@ bool ro_gui_options_cache_click(wimp_pointer *pointer) case CACHE_DEFAULT_BUTTON: /* set the default values */ ro_gui_set_icon_decimal(pointer->w, CACHE_MEMORY_SIZE, - 20, 1); + 120, 1); + ro_gui_set_icon_decimal(pointer->w, CACHE_DISC_SIZE, + 1024, 0); + ro_gui_set_icon_decimal(pointer->w, CACHE_DISC_EXPIRE, + 28, 0); return true; } return false; @@ -76,6 +97,11 @@ bool ro_gui_options_cache_ok(wimp_w w) nsoption_set_int(memory_cache_size, (((ro_gui_get_icon_decimal(w, CACHE_MEMORY_SIZE, 1) + 1) << 20) - 1) / 10); + nsoption_set_uint(disc_cache_size, + (uint) (ro_gui_get_icon_decimal(w, + CACHE_DISC_SIZE, 0) << 20)); + nsoption_set_int(disc_cache_age, + ro_gui_get_icon_decimal(w, CACHE_DISC_EXPIRE, 0)); ro_gui_save_options(); return true; diff --git a/riscos/configure/con_content.c b/riscos/configure/con_content.c index d4f3e46bb..a1d27375f 100644 --- a/riscos/configure/con_content.c +++ b/riscos/configure/con_content.c @@ -17,16 +17,17 @@ */ #include <stdbool.h> + #include "utils/nsoption.h" -#include "riscos/dialog.h" +#include "utils/messages.h" +#include "utils/utils.h" + #include "riscos/gui.h" #include "riscos/wimp.h" #include "riscos/wimp_event.h" #include "riscos/configure.h" #include "riscos/configure/configure.h" -#include "utils/messages.h" -#include "utils/utils.h" - +#include "riscos/dialog.h" #define CONTENT_BLOCK_ADVERTISEMENTS 2 #define CONTENT_BLOCK_POPUPS 3 diff --git a/riscos/configure/con_fonts.c b/riscos/configure/con_fonts.c index 626115523..1fe427c24 100644 --- a/riscos/configure/con_fonts.c +++ b/riscos/configure/con_fonts.c @@ -17,18 +17,21 @@ */ #include <stdbool.h> -#include "css/css.h" + #include "utils/nsoption.h" +#include "utils/messages.h" +#include "utils/utils.h" #include "desktop/plot_style.h" -#include "riscos/dialog.h" +#include "css/css.h" + #include "riscos/gui.h" +#include "riscos/font.h" #include "riscos/menus.h" #include "riscos/wimp.h" #include "riscos/wimp_event.h" #include "riscos/configure.h" #include "riscos/configure/configure.h" -#include "utils/messages.h" -#include "utils/utils.h" +#include "riscos/dialog.h" #define FONT_SANS_FIELD 3 diff --git a/riscos/configure/con_home.c b/riscos/configure/con_home.c index 6f7d01043..4dec6ad61 100644 --- a/riscos/configure/con_home.c +++ b/riscos/configure/con_home.c @@ -17,8 +17,11 @@ */ #include <stdbool.h> + +#include "utils/messages.h" +#include "utils/utils.h" #include "utils/nsoption.h" -#include "riscos/dialog.h" + #include "riscos/gui.h" #include "riscos/menus.h" #include "riscos/url_suggest.h" @@ -26,8 +29,7 @@ #include "riscos/wimp_event.h" #include "riscos/configure.h" #include "riscos/configure/configure.h" -#include "utils/messages.h" -#include "utils/utils.h" +#include "riscos/dialog.h" #define HOME_URL_FIELD 3 #define HOME_URL_GRIGHT 4 diff --git a/riscos/configure/con_image.c b/riscos/configure/con_image.c index 4982423a3..ee4281856 100644 --- a/riscos/configure/con_image.c +++ b/riscos/configure/con_image.c @@ -17,18 +17,21 @@ */ #include <stdbool.h> -#include "swis.h" -#include "oslib/osspriteop.h" -#include "oslib/wimp.h" +#include <swis.h> +#include <oslib/osspriteop.h> +#include <oslib/wimp.h> + #include "utils/nsoption.h" +#include "utils/log.h" +#include "utils/utils.h" + +#include "riscos/gui.h" #include "riscos/configure/configure.h" #include "riscos/dialog.h" #include "riscos/menus.h" #include "riscos/tinct.h" #include "riscos/wimp.h" #include "riscos/wimp_event.h" -#include "utils/log.h" -#include "utils/utils.h" #define IMAGE_FOREGROUND_FIELD 3 @@ -62,11 +65,11 @@ unsigned int tinct_options[] = {tinct_USE_OS_SPRITE_OP, 0, tinct_DITHER, bool ro_gui_options_image_initialise(wimp_w w) { - char pathname[256]; int i; /* load the sprite file */ if (example_users == 0) { + char pathname[256]; snprintf(pathname, 256, "%s.Resources.Image", NETSURF_DIR); pathname[255] = '\0'; example_images = ro_gui_load_sprite_file(pathname); @@ -138,7 +141,6 @@ bool ro_gui_options_image_update(wimp_w w, wimp_i i, wimp_menu *m, void ro_gui_options_image_redraw(wimp_draw *redraw) { osbool more; - int origin_x, origin_y; os_error *error; wimp_icon_state icon_state; osspriteop_header *bg = NULL, *fg = NULL; @@ -168,6 +170,7 @@ void ro_gui_options_image_redraw(wimp_draw *redraw) /* perform the redraw */ more = wimp_redraw_window(redraw); while (more) { + int origin_x, origin_y; origin_x = redraw->box.x0 - redraw->xscroll + icon_state.icon.extent.x0 + 2; origin_y = redraw->box.y1 - redraw->yscroll + diff --git a/riscos/configure/con_inter.c b/riscos/configure/con_inter.c index 2af5e3aa5..7ab912c54 100644 --- a/riscos/configure/con_inter.c +++ b/riscos/configure/con_inter.c @@ -17,14 +17,15 @@ */ #include <stdbool.h> -#include "riscos/dialog.h" -#include "riscos/gui.h" + #include "utils/nsoption.h" + +#include "riscos/gui.h" #include "riscos/wimp.h" #include "riscos/wimp_event.h" #include "riscos/configure.h" #include "riscos/configure/configure.h" - +#include "riscos/dialog.h" #define INTERFACE_STRIP_EXTNS_OPTION 2 #define INTERFACE_CONFIRM_OVWR_OPTION 3 diff --git a/riscos/configure/con_language.c b/riscos/configure/con_language.c index 7e483b5af..ace7a6fdf 100644 --- a/riscos/configure/con_language.c +++ b/riscos/configure/con_language.c @@ -18,17 +18,19 @@ */ #include <stdbool.h> + #include "utils/nsoption.h" -#include "riscos/dialog.h" +#include "utils/log.h" +#include "utils/messages.h" +#include "utils/utils.h" + #include "riscos/gui.h" #include "riscos/menus.h" #include "riscos/wimp.h" #include "riscos/wimp_event.h" #include "riscos/configure.h" #include "riscos/configure/configure.h" -#include "utils/log.h" -#include "utils/messages.h" -#include "utils/utils.h" +#include "riscos/dialog.h" #define LANGUAGE_INTERFACE_FIELD 3 diff --git a/riscos/configure/con_secure.c b/riscos/configure/con_secure.c index 75e2bc705..2e3c31484 100644 --- a/riscos/configure/con_secure.c +++ b/riscos/configure/con_secure.c @@ -17,16 +17,17 @@ */ #include <stdbool.h> + #include "utils/nsoption.h" -#include "riscos/dialog.h" +#include "utils/messages.h" +#include "utils/utils.h" + #include "riscos/gui.h" #include "riscos/wimp.h" #include "riscos/wimp_event.h" #include "riscos/configure.h" #include "riscos/configure/configure.h" -#include "utils/messages.h" -#include "utils/utils.h" - +#include "riscos/dialog.h" #define SECURITY_REFERRER 2 #define SECURITY_DURATION_FIELD 6 diff --git a/riscos/configure/con_theme.c b/riscos/configure/con_theme.c index c4d605c88..13ba3165c 100644 --- a/riscos/configure/con_theme.c +++ b/riscos/configure/con_theme.c @@ -172,10 +172,9 @@ bool ro_gui_options_theme_initialise(wimp_w w) void ro_gui_options_theme_finalise(wimp_w w) { - os_error *error; - ro_gui_options_theme_free(); if (theme_pane) { + os_error *error; ro_gui_wimp_event_finalise(theme_pane); error = xwimp_delete_window(theme_pane); if (error) { @@ -249,7 +248,6 @@ void ro_gui_options_theme_load(void) wimp_icon_create new_icon; wimp_window_state state; int parent_width, nested_y, min_extent, base_extent; - int item_height; int *radio_icons, *radio_set; int theme_count; @@ -315,7 +313,7 @@ void ro_gui_options_theme_load(void) (wimp_COLOUR_VERY_LIGHT_GREY << wimp_ICON_BG_COLOUR_SHIFT); while (link) { /* update the toolbar */ - item_height = 44 + 44 + 16; + int item_height = 44 + 44 + 16; if (link->next) item_height += 16; ro_toolbar_process(link->toolbar, parent_width, false); extent.y0 = nested_y - diff --git a/riscos/content-handlers/artworks.h b/riscos/content-handlers/artworks.h index 20f6168b7..67832cc54 100644 --- a/riscos/content-handlers/artworks.h +++ b/riscos/content-handlers/artworks.h @@ -32,7 +32,10 @@ nserror artworks_init(void); #else -#define artworks_init() NSERROR_OK +static inline nserror artworks_init(void) +{ + return NSERROR_OK; +} #endif diff --git a/riscos/content-handlers/draw.h b/riscos/content-handlers/draw.h index 76fcbc8dc..9f5baf6dc 100644 --- a/riscos/content-handlers/draw.h +++ b/riscos/content-handlers/draw.h @@ -32,7 +32,10 @@ nserror draw_init(void); #else -#define draw_init() NSERROR_OK +static inline nserror draw_init(void) +{ + return NSERROR_OK; +} #endif /* WITH_DRAW */ diff --git a/riscos/content-handlers/sprite.h b/riscos/content-handlers/sprite.h index 2219e0679..ab6d312a5 100644 --- a/riscos/content-handlers/sprite.h +++ b/riscos/content-handlers/sprite.h @@ -32,7 +32,10 @@ nserror sprite_init(void); #else -#define sprite_init() NSERROR_OK +static inline nserror sprite_init(void) +{ + return NSERROR_OK; +} #endif diff --git a/riscos/cookies.c b/riscos/cookies.c index 0a1529737..b5e97f778 100644 --- a/riscos/cookies.c +++ b/riscos/cookies.c @@ -43,7 +43,6 @@ #include "riscos/wimp_event.h" #include "utils/messages.h" #include "utils/log.h" -#include "utils/url.h" #include "utils/utils.h" static void ro_gui_cookies_toolbar_update_buttons(void); diff --git a/riscos/dialog.c b/riscos/dialog.c index 147dce9f8..fd854b857 100644 --- a/riscos/dialog.c +++ b/riscos/dialog.c @@ -5,6 +5,7 @@ * Copyright 2005 Richard Wilson <info@tinct.net> * Copyright 2004 Andrew Timmins <atimmins@blueyonder.co.uk> * Copyright 2005 Adrian Lees <adrianl@users.sourceforge.net> + * Copyright 2014 Stephen Fryatt <stevef@netsurf-browser.org> * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -21,19 +22,28 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include "utils/config.h" + #include <assert.h> #include <stddef.h> #include <stdlib.h> #include <string.h> -#include "oslib/colourtrans.h" -#include "oslib/osfile.h" -#include "oslib/osgbpb.h" -#include "oslib/osspriteop.h" -#include "oslib/wimp.h" -#include "rufl.h" -#include "utils/config.h" +#include <oslib/colourtrans.h> +#include <oslib/osfile.h> +#include <oslib/osgbpb.h> +#include <oslib/osspriteop.h> +#include <oslib/wimp.h> + +#include "utils/nsoption.h" +#include "utils/log.h" +#include "utils/messages.h" +#include "utils/nsurl.h" +#include "utils/url.h" +#include "utils/utils.h" #include "desktop/netsurf.h" +#include "desktop/browser.h" #include "render/font.h" + #include "riscos/configure.h" #include "riscos/cookies.h" #include "riscos/dialog.h" @@ -41,7 +51,6 @@ #include "riscos/gui.h" #include "riscos/hotlist.h" #include "riscos/menus.h" -#include "utils/nsoption.h" #include "riscos/save.h" #include "riscos/sslcert.h" #include "riscos/toolbar.h" @@ -50,10 +59,6 @@ #include "riscos/wimp.h" #include "riscos/wimp_event.h" #include "riscos/wimputils.h" -#include "utils/log.h" -#include "utils/messages.h" -#include "utils/url.h" -#include "utils/utils.h" #define ICON_ZOOM_VALUE 1 #define ICON_ZOOM_DEC 2 @@ -85,6 +90,7 @@ static struct { } persistent_dialog[MAX_PERSISTENT]; +static bool ro_gui_dialog_open_url_init(void); static bool ro_gui_dialog_openurl_apply(wimp_w w); static bool ro_gui_dialog_open_url_menu_prepare(wimp_w w, wimp_i i, wimp_menu *menu, wimp_pointer *pointer); @@ -161,15 +167,7 @@ void ro_gui_dialog_init(void) ro_gui_wimp_event_set_help_prefix(dialog_url_complete, "HelpAutoURL"); /* open URL */ - dialog_openurl = ro_gui_dialog_create("open_url"); - ro_gui_wimp_event_register_menu_gright(dialog_openurl, ICON_OPENURL_URL, - ICON_OPENURL_MENU, ro_gui_url_suggest_menu); - ro_gui_wimp_event_register_cancel(dialog_openurl, ICON_OPENURL_CANCEL); - ro_gui_wimp_event_register_ok(dialog_openurl, ICON_OPENURL_OPEN, - ro_gui_dialog_openurl_apply); - ro_gui_wimp_event_register_menu_prepare(dialog_openurl, - ro_gui_dialog_open_url_menu_prepare); - ro_gui_wimp_event_set_help_prefix(dialog_openurl, "HelpOpenURL"); + ro_gui_dialog_open_url_init(); /* scale view */ dialog_zoom = ro_gui_dialog_create("zoom"); @@ -413,8 +411,6 @@ bool ro_gui_dialog_open_top(wimp_w w, struct toolbar *toolbar, os_error *error; int screen_width, screen_height; wimp_window_state state; - int dimension; - int scroll_width; bool open; state.w = w; @@ -428,6 +424,8 @@ bool ro_gui_dialog_open_top(wimp_w w, struct toolbar *toolbar, * open in the centre of the screen. */ open = state.flags & wimp_WINDOW_OPEN; if (!open) { + int dimension; + int scroll_width; /* cancel any editing */ if (ro_toolbar_get_editing(toolbar)) ro_toolbar_toggle_edit(toolbar); @@ -702,6 +700,70 @@ void ro_gui_dialog_update_zoom(struct gui_window *g) { } +/** + * Create the Open URL dialogue, allocating storage for the URL field icon + * as we go. + * + * \return true on success; false on failure (although errors with + * the templates or memory allocation will exit via die()). + */ + +static bool ro_gui_dialog_open_url_init(void) +{ + wimp_window *definition; + char *buffer; + os_error *error; + + definition = ro_gui_dialog_load_template("open_url"); + + /* _load_template() should die on any error, so we trust its data. */ + + assert(definition != NULL); + + /* Create the dialogue, with modifications. */ + + if ((definition->icons[ICON_OPENURL_URL].flags & wimp_ICON_INDIRECTED) + == 0) { + LOG(("open_url URL icon not indirected")); + xwimp_close_template(); + die("Template"); + } + + buffer = malloc(RO_GUI_MAX_URL_SIZE); + if (buffer == NULL) { + xwimp_close_template(); + die("NoMemory"); + } + + definition->icons[ICON_OPENURL_URL].data.indirected_text.text = buffer; + definition->icons[ICON_OPENURL_URL].data.indirected_text.size = + RO_GUI_MAX_URL_SIZE; + definition->sprite_area = gui_sprites; + + error = xwimp_create_window(definition, &dialog_openurl); + if (error != NULL) { + LOG(("xwimp_create_window: 0x%x: %s", + error->errnum, error->errmess)); + xwimp_close_template(); + die(error->errmess); + } + + free(definition); + + ro_gui_wimp_event_register_menu_gright(dialog_openurl, ICON_OPENURL_URL, + ICON_OPENURL_MENU, ro_gui_url_suggest_menu); + ro_gui_wimp_event_register_cancel(dialog_openurl, ICON_OPENURL_CANCEL); + ro_gui_wimp_event_register_ok(dialog_openurl, ICON_OPENURL_OPEN, + ro_gui_dialog_openurl_apply); + ro_gui_wimp_event_register_menu_prepare(dialog_openurl, + ro_gui_dialog_open_url_menu_prepare); + ro_gui_wimp_event_set_help_prefix(dialog_openurl, "HelpOpenURL"); + + return true; +} + + + bool ro_gui_dialog_openurl_apply(wimp_w w) { const char *urltxt; char *url2; @@ -717,8 +779,7 @@ bool ro_gui_dialog_openurl_apply(wimp_w w) { error = nsurl_create(url2, &url); free(url2); if (error == NSERROR_OK) { - error = browser_window_create(BROWSER_WINDOW_VERIFIABLE | - BROWSER_WINDOW_HISTORY, + error = browser_window_create(BW_CREATE_HISTORY, url, NULL, NULL, diff --git a/riscos/dialog.h b/riscos/dialog.h index 5758ad366..463048436 100644 --- a/riscos/dialog.h +++ b/riscos/dialog.h @@ -19,11 +19,8 @@ #ifndef _NETSURF_RISCOS_DIALOG_H_ #define _NETSURF_RISCOS_DIALOG_H_ -#include <stdbool.h> -#include <stdlib.h> -#include "oslib/wimp.h" -#include "riscos/toolbar.h" -#include "riscos/gui.h" +struct toolbar; +struct gui_window; void ro_gui_dialog_init(void); wimp_w ro_gui_dialog_create(const char *template_name); diff --git a/riscos/distribution/!Boot/Resources/!Cache/!Boot,feb b/riscos/distribution/!Boot/Resources/!Cache/!Boot,feb new file mode 100644 index 000000000..f126ba27a --- /dev/null +++ b/riscos/distribution/!Boot/Resources/!Cache/!Boot,feb @@ -0,0 +1,3 @@ +Set Cache$FromBoot True +If "<Cache$Dir>" = "" Then Run <Obey$Dir>.!Run +Unset Cache$FromBoot
\ No newline at end of file diff --git a/riscos/distribution/!Boot/Resources/!Cache/!Help,feb b/riscos/distribution/!Boot/Resources/!Cache/!Help,feb new file mode 100644 index 000000000..35eeeb31b --- /dev/null +++ b/riscos/distribution/!Boot/Resources/!Cache/!Help,feb @@ -0,0 +1,2 @@ +If "<CacheAppRes$Path>" = "" Then Run <Cache$AppDir>.Resources.ResFind CacheApp +Filer_Run CacheAppRes:Help
\ No newline at end of file diff --git a/riscos/distribution/!Boot/Resources/!Cache/!Run,feb b/riscos/distribution/!Boot/Resources/!Cache/!Run,feb new file mode 100644 index 000000000..a920e39ab --- /dev/null +++ b/riscos/distribution/!Boot/Resources/!Cache/!Run,feb @@ -0,0 +1,10 @@ +Set Cache$AppDir <Obey$Dir> +IconSprites <Cache$AppDir>.!Sprites + +Run <Cache$AppDir>.Resources.ResFind CacheApp +Set Cache$Meta CacheAppRes:!Meta + +RMEnsure SysLog 0.17 IfThere <SysLog$Dir>.!Run Then Run <SysLog$Dir>.!Run +RMEnsure SysLog 0.17 Set Cache$SysLogMissing "True" + +Run <Cache$AppDir>.!RunImage
\ No newline at end of file diff --git a/riscos/distribution/!Boot/Resources/!Cache/!RunImage,ffb b/riscos/distribution/!Boot/Resources/!Cache/!RunImage,ffb Binary files differnew file mode 100644 index 000000000..61752af99 --- /dev/null +++ b/riscos/distribution/!Boot/Resources/!Cache/!RunImage,ffb diff --git a/riscos/distribution/!Boot/Resources/!Cache/!Sprites,ff9 b/riscos/distribution/!Boot/Resources/!Cache/!Sprites,ff9 Binary files differnew file mode 100644 index 000000000..b71a51cf3 --- /dev/null +++ b/riscos/distribution/!Boot/Resources/!Cache/!Sprites,ff9 diff --git a/riscos/distribution/!Boot/Resources/!Cache/!Sprites22,ff9 b/riscos/distribution/!Boot/Resources/!Cache/!Sprites22,ff9 Binary files differnew file mode 100644 index 000000000..e43f88c89 --- /dev/null +++ b/riscos/distribution/!Boot/Resources/!Cache/!Sprites22,ff9 diff --git a/riscos/distribution/!Boot/Resources/!Cache/Caches/Blank b/riscos/distribution/!Boot/Resources/!Cache/Caches/Blank new file mode 100644 index 000000000..898dc5872 --- /dev/null +++ b/riscos/distribution/!Boot/Resources/!Cache/Caches/Blank @@ -0,0 +1 @@ +This is here just to stop the directory structure getting lost when unzipping.
\ No newline at end of file diff --git a/riscos/distribution/!Boot/Resources/!Cache/Resources/MultiError,ffb b/riscos/distribution/!Boot/Resources/!Cache/Resources/MultiError,ffb Binary files differnew file mode 100644 index 000000000..ec348b0e9 --- /dev/null +++ b/riscos/distribution/!Boot/Resources/!Cache/Resources/MultiError,ffb diff --git a/riscos/distribution/!Boot/Resources/!Cache/Resources/ResFind,ffb b/riscos/distribution/!Boot/Resources/!Cache/Resources/ResFind,ffb Binary files differnew file mode 100644 index 000000000..7766cc928 --- /dev/null +++ b/riscos/distribution/!Boot/Resources/!Cache/Resources/ResFind,ffb diff --git a/riscos/distribution/!Boot/Resources/!Cache/Resources/UK/!Meta b/riscos/distribution/!Boot/Resources/!Cache/Resources/UK/!Meta new file mode 100644 index 000000000..2de40bd7c --- /dev/null +++ b/riscos/distribution/!Boot/Resources/!Cache/Resources/UK/!Meta @@ -0,0 +1,9 @@ +# Meta file for Cache +Help:<CacheAppRes$Dir>.Help +Version:1.13 +Web:http://www.snowstone.org.uk/riscos/ +Title:Cache +Publisher:Adam Richardson +Description:Cache provides a central location for semi-permanent data on your system. +Email:riscos@snowstone.org.uk + diff --git a/riscos/distribution/!Boot/Resources/!Cache/Resources/UK/Help b/riscos/distribution/!Boot/Resources/!Cache/Resources/UK/Help new file mode 100644 index 000000000..aad9bf0b1 --- /dev/null +++ b/riscos/distribution/!Boot/Resources/!Cache/Resources/UK/Help @@ -0,0 +1,60 @@ +Cache +----- + +Cache provides a shared location for cached data. This location can be +used by application authors to store semi-permanent data. Cache can be +placed anywhere on your computer where it will be "seen" by the Filer +during start up. (For instance, the "Resources" directory inside !Boot.) + +Once "seen" it will set up a cache location, which can be shown by +double-clicking on !Cache. + + +Application Authors +----------- ------- + +Use Cache in a similar way to using Scrap. You *must not* assume that +Cache is present on the user's system however, as Cache is not an +official part of the system (like Scrap). + +To use Cache you should: + * Check for the presence of "<Cache$Dir>" before proceeding + * Read from and write data to "<Cache$Dir>.APPNAME" where APPNAME has + been allocated to you by the allocations service. See: + http://www.riscosopen.com/content/allocate + * If the APPNAME directory does not exist, you should create it. + +This version of Cache is published by Adam Richardson who can be +contacted at riscos@snowstone.org.uk. + +The website for Cache is: http://www.snowstone.org.uk/riscos/ + + +Credits +------- + +Cache is (c) Adam Richardson, 2007. +Thanks to Rob Kendrick for the initial idea and input. + + +License +------- + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/riscos/distribution/!Boot/Resources/!Cache/Resources/UK/Messages b/riscos/distribution/!Boot/Resources/!Cache/Resources/UK/Messages new file mode 100644 index 000000000..366122292 --- /dev/null +++ b/riscos/distribution/!Boot/Resources/!Cache/Resources/UK/Messages @@ -0,0 +1,8 @@ +# Messages for Cache + +multiuser:Multi-user system present. +singleuser:No multi-user system present. +location:Cache directory set to: +opendir:Opening cache location... +fatalerror:Cache has suffered a fatal error and has quit. + diff --git a/riscos/distribution/!Boot/Resources/!Cache/Resources/UK/Templates,fec b/riscos/distribution/!Boot/Resources/!Cache/Resources/UK/Templates,fec Binary files differnew file mode 100644 index 000000000..22f910ad9 --- /dev/null +++ b/riscos/distribution/!Boot/Resources/!Cache/Resources/UK/Templates,fec diff --git a/riscos/download.c b/riscos/download.c index ebd981dca..a03ff474b 100644 --- a/riscos/download.c +++ b/riscos/download.c @@ -33,6 +33,8 @@ #include <sys/time.h> #include <time.h> #include <curl/curl.h> +#include <libwapcaplet/libwapcaplet.h> + #include "oslib/mimemap.h" #include "oslib/osargs.h" #include "oslib/osfile.h" @@ -41,21 +43,27 @@ #include "oslib/osgbpb.h" #include "oslib/wimp.h" #include "oslib/wimpspriteop.h" + #include "desktop/gui.h" #include "desktop/netsurf.h" -#include "riscos/dialog.h" +#include "desktop/download.h" #include "utils/nsoption.h" +#include "utils/log.h" +#include "utils/messages.h" +#include "utils/nsurl.h" +#include "utils/utf8.h" +#include "utils/utils.h" +#include "utils/corestrings.h" + +#include "riscos/gui.h" +#include "riscos/dialog.h" #include "riscos/mouse.h" #include "riscos/save.h" #include "riscos/query.h" #include "riscos/wimp.h" #include "riscos/wimp_event.h" -#include "utils/log.h" -#include "utils/messages.h" -#include "utils/schedule.h" -#include "utils/url.h" -#include "utils/utf8.h" -#include "utils/utils.h" +#include "riscos/ucstables.h" +#include "riscos/filetype.h" #define ICON_DOWNLOAD_ICON 0 #define ICON_DOWNLOAD_URL 1 @@ -206,6 +214,60 @@ const char *ro_gui_download_temp_name(struct gui_download_window *dw) return temp_name; } +/** + * Try and find the correct RISC OS filetype from a download context. + */ +static nserror download_ro_filetype(download_context *ctx, bits *ftype_out) +{ + nsurl *url = download_context_get_url(ctx); + bits ftype = 0; + lwc_string *scheme; + + /* If the file is local try and read its filetype */ + scheme = nsurl_get_component(url, NSURL_SCHEME); + if (scheme != NULL) { + bool filescheme; + if (lwc_string_isequal(scheme, + corestring_lwc_file, + &filescheme) != lwc_error_ok) { + filescheme = false; + } + + if (filescheme) { + lwc_string *path = nsurl_get_component(url, NSURL_PATH); + if (path != NULL && lwc_string_length(path) != 0) { + char *raw_path; + raw_path = curl_unescape(lwc_string_data(path), + lwc_string_length(path)); + if (raw_path != NULL) { + ftype = ro_filetype_from_unix_path(raw_path); + curl_free(raw_path); + } + } + } + } + + /* If we still don't have a filetype (i.e. failed reading local + * one or fetching a remote object), then use the MIME type. + */ + if (ftype == 0) { + /* convert MIME type to RISC OS file type */ + os_error *error; + const char *mime_type; + + mime_type = download_context_get_mime_type(ctx); + error = xmimemaptranslate_mime_type_to_filetype(mime_type, &ftype); + if (error) { + LOG(("xmimemaptranslate_mime_type_to_filetype: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("MiscError", error->errmess); + ftype = 0xffd; + } + } + + *ftype_out = ftype; + return NSERROR_OK; +} /** * Create and open a download progress window. @@ -215,20 +277,17 @@ const char *ro_gui_download_temp_name(struct gui_download_window *dw) * reported */ -struct gui_download_window *gui_download_window_create(download_context *ctx, - struct gui_window *gui) +static struct gui_download_window * +gui_download_window_create(download_context *ctx, struct gui_window *gui) { - const char *url = download_context_get_url(ctx); - const char *mime_type = download_context_get_mime_type(ctx); + nsurl *url = download_context_get_url(ctx); const char *temp_name; - char *scheme = NULL; char *filename = NULL; struct gui_download_window *dw; bool space_warning = false; os_error *error; - url_func_result res; char *local_path; - utf8_convert_ret err; + nserror err; size_t i, last_dot; dw = malloc(sizeof *dw); @@ -244,8 +303,13 @@ struct gui_download_window *gui_download_window_create(download_context *ctx, dw->query = QUERY_INVALID; dw->received = 0; dw->total_size = download_context_get_total_length(ctx); - strncpy(dw->url, url, sizeof dw->url); + + /** @todo change this to take a reference to the nsurl and use + * that value directly rather than using a fixed buffer. + */ + strncpy(dw->url, nsurl_access(url), sizeof dw->url); dw->url[sizeof dw->url - 1] = 0; + dw->status[0] = 0; gettimeofday(&dw->start_time, 0); dw->last_time = dw->start_time; @@ -254,55 +318,12 @@ struct gui_download_window *gui_download_window_create(download_context *ctx, dw->average_rate = 0; dw->average_points = 0; - /* Get scheme from URL */ - res = url_scheme(url, &scheme); - if (res == URL_FUNC_NOMEM) { - warn_user("NoMemory", 0); + /* get filetype */ + err = download_ro_filetype(ctx, &dw->file_type); + if (err != NSERROR_OK) { + warn_user(messages_get_errorcode(err), 0); free(dw); return 0; - } else if (res == URL_FUNC_OK) { - /* If we have a scheme and it's "file", then - * attempt to use the local filetype directly */ - if (strcasecmp(scheme, "file") == 0) { - char *path = NULL; - res = url_path(url, &path); - if (res == URL_FUNC_NOMEM) { - warn_user("NoMemory", 0); - free(scheme); - free(dw); - return 0; - } else if (res == URL_FUNC_OK) { - char *raw_path = curl_unescape(path, - strlen(path)); - if (raw_path == NULL) { - warn_user("NoMemory", 0); - free(path); - free(scheme); - free(dw); - return 0; - } - dw->file_type = - ro_filetype_from_unix_path(raw_path); - curl_free(raw_path); - free(path); - } - } - - free(scheme); - } - - /* If we still don't have a filetype (i.e. failed reading local - * one or fetching a remote object), then use the MIME type */ - if (dw->file_type == 0) { - /* convert MIME type to RISC OS file type */ - error = xmimemaptranslate_mime_type_to_filetype(mime_type, - &(dw->file_type)); - if (error) { - LOG(("xmimemaptranslate_mime_type_to_filetype: 0x%x: %s", - error->errnum, error->errmess)); - warn_user("MiscError", error->errmess); - dw->file_type = 0xffd; - } } /* open temporary output file */ @@ -375,10 +396,12 @@ struct gui_download_window *gui_download_window_create(download_context *ctx, snprintf(dw->path, RO_DOWNLOAD_MAX_PATH_LEN, "%s", filename); + free(filename); + err = utf8_to_local_encoding(dw->path, 0, &local_path); - if (err != UTF8_CONVERT_OK) { + if (err != NSERROR_OK) { /* badenc should never happen */ - assert(err != UTF8_CONVERT_BADENC); + assert(err !=NSERROR_BAD_ENCODING); LOG(("utf8_to_local_encoding failed")); warn_user("NoMemory", 0); free(dw); @@ -435,6 +458,57 @@ struct gui_download_window *gui_download_window_create(download_context *ctx, return dw; } +/** + * Handle failed downloads. + * + * \param dw download window + * \param error_msg error message + */ + +static void gui_download_window_error(struct gui_download_window *dw, + const char *error_msg) +{ + os_error *error; + + if (dw->ctx != NULL) + download_context_destroy(dw->ctx); + dw->ctx = NULL; + dw->error = true; + + riscos_schedule(-1, ro_gui_download_update_status_wrapper, dw); + + /* place error message in status icon in red */ + strncpy(dw->status, error_msg, sizeof dw->status); + error = xwimp_set_icon_state(dw->window, + ICON_DOWNLOAD_STATUS, + wimp_COLOUR_RED << wimp_ICON_FG_COLOUR_SHIFT, + wimp_ICON_FG_COLOUR); + if (error) { + LOG(("xwimp_set_icon_state: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + } + + /* grey out pathname icon */ + error = xwimp_set_icon_state(dw->window, ICON_DOWNLOAD_PATH, + wimp_ICON_SHADED, 0); + if (error) { + LOG(("xwimp_set_icon_state: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + } + + /* grey out file icon */ + error = xwimp_set_icon_state(dw->window, ICON_DOWNLOAD_ICON, + wimp_ICON_SHADED, wimp_ICON_SHADED); + if (error) { + LOG(("xwimp_set_icon_state: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + } + + ro_gui_download_window_hide_caret(dw); +} /** * Handle received download data. @@ -445,7 +519,7 @@ struct gui_download_window *gui_download_window_create(download_context *ctx, * \return NSERROR_OK on success, appropriate error otherwise */ -nserror gui_download_window_data(struct gui_download_window *dw, +static nserror gui_download_window_data(struct gui_download_window *dw, const char *data, unsigned int size) { while (true) { @@ -526,7 +600,6 @@ nserror gui_download_window_data(struct gui_download_window *dw, void ro_gui_download_update_status(struct gui_download_window *dw) { - char *received; char *total_size; char *speed; char time[20] = "?"; @@ -537,7 +610,7 @@ void ro_gui_download_update_status(struct gui_download_window *dw) os_error *error; int width; char *local_status; - utf8_convert_ret err; + nserror err; gettimeofday(&t, 0); dt = (t.tv_sec + 0.000001 * t.tv_usec) - (dw->last_time.tv_sec + @@ -548,6 +621,7 @@ void ro_gui_download_update_status(struct gui_download_window *dw) total_size = human_friendly_bytesize(max(dw->received, dw->total_size)); if (dw->ctx) { + char *received; rate = (dw->received - dw->last_received) / dt; received = human_friendly_bytesize(dw->received); /* A simple 'modified moving average' download rate calculation @@ -571,9 +645,9 @@ void ro_gui_download_update_status(struct gui_download_window *dw) /* convert to local encoding */ err = utf8_to_local_encoding( messages_get("Download"), 0, &local_status); - if (err != UTF8_CONVERT_OK) { + if (err != NSERROR_OK) { /* badenc should never happen */ - assert(err != UTF8_CONVERT_BADENC); + assert(err != NSERROR_BAD_ENCODING); /* hide nomem error */ snprintf(dw->status, sizeof dw->status, messages_get("Download"), @@ -594,9 +668,9 @@ void ro_gui_download_update_status(struct gui_download_window *dw) err = utf8_to_local_encoding( messages_get("DownloadU"), 0, &local_status); - if (err != UTF8_CONVERT_OK) { + if (err != NSERROR_OK) { /* badenc should never happen */ - assert(err != UTF8_CONVERT_BADENC); + assert(err != NSERROR_BAD_ENCODING); /* hide nomem error */ snprintf(dw->status, sizeof dw->status, messages_get("DownloadU"), @@ -622,9 +696,9 @@ void ro_gui_download_update_status(struct gui_download_window *dw) err = utf8_to_local_encoding(messages_get("Downloaded"), 0, &local_status); - if (err != UTF8_CONVERT_OK) { + if (err != NSERROR_OK) { /* badenc should never happen */ - assert(err != UTF8_CONVERT_BADENC); + assert(err != NSERROR_BAD_ENCODING); /* hide nomem error */ snprintf(dw->status, sizeof dw->status, messages_get("Downloaded"), @@ -661,15 +735,16 @@ void ro_gui_download_update_status(struct gui_download_window *dw) warn_user("WimpError", error->errmess); } - if (dw->ctx) - schedule(100, ro_gui_download_update_status_wrapper, dw); - else - schedule_remove(ro_gui_download_update_status_wrapper, dw); + if (dw->ctx) { + riscos_schedule(1000, ro_gui_download_update_status_wrapper, dw); + } else { + riscos_schedule(-1, ro_gui_download_update_status_wrapper, dw); + } } /** - * Wrapper for ro_gui_download_update_status(), suitable for schedule(). + * Wrapper for ro_gui_download_update_status(), suitable for riscos_schedule(). */ void ro_gui_download_update_status_wrapper(void *p) @@ -707,57 +782,6 @@ void ro_gui_download_window_hide_caret(struct gui_download_window *dw) } -/** - * Handle failed downloads. - * - * \param dw download window - * \param error_msg error message - */ - -void gui_download_window_error(struct gui_download_window *dw, - const char *error_msg) -{ - os_error *error; - - if (dw->ctx != NULL) - download_context_destroy(dw->ctx); - dw->ctx = NULL; - dw->error = true; - - schedule_remove(ro_gui_download_update_status_wrapper, dw); - - /* place error message in status icon in red */ - strncpy(dw->status, error_msg, sizeof dw->status); - error = xwimp_set_icon_state(dw->window, - ICON_DOWNLOAD_STATUS, - wimp_COLOUR_RED << wimp_ICON_FG_COLOUR_SHIFT, - wimp_ICON_FG_COLOUR); - if (error) { - LOG(("xwimp_set_icon_state: 0x%x: %s", - error->errnum, error->errmess)); - warn_user("WimpError", error->errmess); - } - - /* grey out pathname icon */ - error = xwimp_set_icon_state(dw->window, ICON_DOWNLOAD_PATH, - wimp_ICON_SHADED, 0); - if (error) { - LOG(("xwimp_set_icon_state: 0x%x: %s", - error->errnum, error->errmess)); - warn_user("WimpError", error->errmess); - } - - /* grey out file icon */ - error = xwimp_set_icon_state(dw->window, ICON_DOWNLOAD_ICON, - wimp_ICON_SHADED, wimp_ICON_SHADED); - if (error) { - LOG(("xwimp_set_icon_state: 0x%x: %s", - error->errnum, error->errmess)); - warn_user("WimpError", error->errmess); - } - - ro_gui_download_window_hide_caret(dw); -} /** @@ -766,7 +790,7 @@ void gui_download_window_error(struct gui_download_window *dw, * \param dw download window */ -void gui_download_window_done(struct gui_download_window *dw) +static void gui_download_window_done(struct gui_download_window *dw) { os_error *error; @@ -792,10 +816,11 @@ void gui_download_window_done(struct gui_download_window *dw) warn_user("SaveError", error->errmess); } - if (dw->send_dataload) + if (dw->send_dataload) { ro_gui_download_send_dataload(dw); + } - schedule(200, ro_gui_download_window_destroy_wrapper, dw); + riscos_schedule(2000, ro_gui_download_window_destroy_wrapper, dw); } } @@ -810,9 +835,6 @@ void gui_download_window_done(struct gui_download_window *dw) bool ro_gui_download_click(wimp_pointer *pointer) { struct gui_download_window *dw; - char command[256] = "Filer_OpenDir "; - char *dot; - os_error *error; dw = (struct gui_download_window *)ro_gui_wimp_event_get_user_data(pointer->w); if ((pointer->buttons & (wimp_DRAG_SELECT | wimp_DRAG_ADJUST)) && @@ -836,10 +858,14 @@ bool ro_gui_download_click(wimp_pointer *pointer) ro_gui_drag_icon(x, y, sprite); } else if (pointer->i == ICON_DOWNLOAD_DESTINATION) { + char command[256] = "Filer_OpenDir "; + char *dot; + strncpy(command + 14, dw->path, 242); command[255] = 0; dot = strrchr(command, '.'); if (dot) { + os_error *error; *dot = 0; error = xos_cli(command); if (error) { @@ -886,7 +912,7 @@ bool ro_gui_download_keypress(wimp_key *key) !nsoption_bool(confirm_overwrite)) && !dw->ctx) { /* finished already */ - schedule(200, ro_gui_download_window_destroy_wrapper, dw); + riscos_schedule(2000, ro_gui_download_window_destroy_wrapper, dw); } return true; } @@ -982,7 +1008,7 @@ void ro_gui_download_datasave_ack(wimp_message *message) ro_gui_download_send_dataload(dw); - schedule(200, ro_gui_download_window_destroy_wrapper, dw); + riscos_schedule(2000, ro_gui_download_window_destroy_wrapper, dw); } } @@ -1414,7 +1440,7 @@ void ro_gui_download_send_dataload(struct gui_download_window *dw) warn_user("WimpError", error->errmess); } - schedule(200, ro_gui_download_window_destroy_wrapper, dw); + riscos_schedule(2000, ro_gui_download_window_destroy_wrapper, dw); } @@ -1477,8 +1503,8 @@ bool ro_gui_download_window_destroy(struct gui_download_window *dw, bool quit) return false; } - schedule_remove(ro_gui_download_update_status_wrapper, dw); - schedule_remove(ro_gui_download_window_destroy_wrapper, dw); + riscos_schedule(-1, ro_gui_download_update_status_wrapper, dw); + riscos_schedule(-1, ro_gui_download_window_destroy_wrapper, dw); /* remove from list */ if (dw->prev) @@ -1531,7 +1557,7 @@ bool ro_gui_download_window_destroy(struct gui_download_window *dw, bool quit) /** - * Wrapper for ro_gui_download_window_destroy(), suitable for schedule(). + * Wrapper for ro_gui_download_window_destroy(), suitable for riscos_schedule(). */ void ro_gui_download_window_destroy_wrapper(void *p) @@ -1610,7 +1636,7 @@ void ro_gui_download_overwrite_confirmed(query_id id, enum query_response res, v ro_gui_download_send_dataload(dw); - schedule(200, ro_gui_download_window_destroy_wrapper, dw); + riscos_schedule(2000, ro_gui_download_window_destroy_wrapper, dw); } } @@ -1631,3 +1657,12 @@ bool ro_gui_download_prequit(void) } return true; } + +static struct gui_download_table download_table = { + .create = gui_download_window_create, + .data = gui_download_window_data, + .error = gui_download_window_error, + .done = gui_download_window_done, +}; + +struct gui_download_table *riscos_download_table = &download_table; diff --git a/riscos/filetype.c b/riscos/filetype.c index 86aafa85a..0a546d833 100644 --- a/riscos/filetype.c +++ b/riscos/filetype.c @@ -24,7 +24,7 @@ #include "content/content.h" #include "content/fetch.h" #include "content/hlcache.h" -#include "riscos/gui.h" +#include "riscos/filetype.h" #include "utils/config.h" #include "utils/log.h" #include "utils/utils.h" @@ -60,19 +60,13 @@ static char type_buf[BUF_SIZE]; static int cmp_type(const void *x, const void *y); -/** - * Determine the MIME type of a local file. - * - * \param unix_path Unix style path to file on disk - * \return Pointer to MIME type string (should not be freed) - invalidated - * on next call to fetch_filetype. - */ +/* exported interface documented in riscos/filetype.h */ const char *fetch_filetype(const char *unix_path) { struct type_entry *t; unsigned int len = strlen(unix_path) + 100; char *path = calloc(len, 1); - char *r, *slash; + char *r; os_error *error; bits file_type, temp; int objtype; @@ -110,7 +104,7 @@ const char *fetch_filetype(const char *unix_path) /* If filetype is text or data, and the file has an extension, try to * map the extension to a filetype via the MimeMap file. */ if (file_type == osfile_TYPE_TEXT || file_type == osfile_TYPE_DATA) { - slash = strrchr(path, '/'); + char *slash = strrchr(path, '/'); if (slash) { error = xmimemaptranslate_extension_to_filetype( slash+1, &temp); @@ -154,12 +148,7 @@ const char *fetch_filetype(const char *unix_path) } -/** - * Find a MIME type for a local file - * - * \param ro_path RISC OS style path to file on disk - * \return MIME type string (on heap, caller should free), or NULL - */ +/* exported interface documented in riscos/filetype.h */ char *fetch_mimetype(const char *ro_path) { os_error *e; @@ -246,12 +235,7 @@ int cmp_type(const void *x, const void *y) return *p < q->file_type ? -1 : (*p == q->file_type ? 0 : +1); } -/** - * Determine the RISC OS filetype for a content. - * - * \param content The content to examine. - * \return The RISC OS filetype corresponding to the content - */ +/* exported interface documented in riscos/filetype.h */ int ro_content_filetype(hlcache_handle *c) { lwc_string *mime_type; @@ -270,25 +254,21 @@ int ro_content_filetype(hlcache_handle *c) return file_type; } -/** - * Determine the native RISC OS filetype to export a content as - * - * \param c The content to examine - * \return Native RISC OS filetype for export - */ + +/* exported interface documented in riscos/filetype.h */ int ro_content_native_type(hlcache_handle *c) { switch (ro_content_filetype(c)) { - case 0xc85: /* jpeg */ - case 0xf78: /* jng */ - case 0xf83: /* mng */ - case 0x695: /* gif */ - case 0x69c: /* bmp */ - case 0x132: /* ico */ - case 0xb60: /* png */ + case FILETYPE_JPEG: /* jpeg */ + case FILETYPE_JNG: /* jng */ + case FILETYPE_MNG: /* mng */ + case FILETYPE_GIF: /* gif */ + case FILETYPE_BMP: /* bmp */ + case FILETYPE_ICO: /* ico */ + case FILETYPE_PNG: /* png */ case 0xff9: /* sprite */ return osfile_TYPE_SPRITE; - case 0xaad: /* svg */ + case FILETYPE_SVG: /* svg */ case 0xaff: /* draw */ return osfile_TYPE_DRAW; default: @@ -298,12 +278,8 @@ int ro_content_native_type(hlcache_handle *c) return osfile_TYPE_DATA; } -/** - * Determine the RISC OS filetype for a MIME type - * - * \param mime_type MIME type to consider - * \return Corresponding RISC OS filetype - */ + +/* exported interface documented in riscos/filetype.h */ int ro_content_filetype_from_mime_type(lwc_string *mime_type) { int file_type, index; @@ -329,15 +305,11 @@ int ro_content_filetype_from_mime_type(lwc_string *mime_type) return file_type; } -/** - * Determine the RISC OS filetype from a content type. - * - * \param type The content type to examine. - * \return The RISC OS filetype corresponding to the content, or 0 for unknown - */ + +/* exported interface documented in riscos/filetype.h */ int ro_content_filetype_from_type(content_type type) { switch (type) { - case CONTENT_HTML: return 0xfaf; + case CONTENT_HTML: return FILETYPE_HTML; case CONTENT_TEXTPLAIN: return 0xfff; case CONTENT_CSS: return 0xf79; default: break; @@ -345,12 +317,8 @@ int ro_content_filetype_from_type(content_type type) { return 0; } -/** - * Determine the type of a local file. - * - * \param unix_path Unix style path to file on disk - * \return File type - */ + +/* exported interface documented in riscos/filetype.h */ bits ro_filetype_from_unix_path(const char *unix_path) { unsigned int len = strlen(unix_path) + 100; diff --git a/riscos/filetype.h b/riscos/filetype.h new file mode 100644 index 000000000..20dfb6cbc --- /dev/null +++ b/riscos/filetype.h @@ -0,0 +1,128 @@ +/* + * Copyright 2014 Vincent Sanders <vince@netsurf-browser.org> + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** \file riscos/filetype.h + * RISC OS filetpe interface. + */ + +#ifndef _NETSURF_RISCOS_FILETYPE_H_ +#define _NETSURF_RISCOS_FILETYPE_H_ + +#include "content/content_type.h" + +#ifndef FILETYPE_ACORN_URI +#define FILETYPE_ACORN_URI 0xf91 +#endif +#ifndef FILETYPE_ANT_URL +#define FILETYPE_ANT_URL 0xb28 +#endif +#ifndef FILETYPE_IEURL +#define FILETYPE_IEURL 0x1ba +#endif +#ifndef FILETYPE_HTML +#define FILETYPE_HTML 0xfaf +#endif +#ifndef FILETYPE_JNG +#define FILETYPE_JNG 0xf78 +#endif +#ifndef FILETYPE_CSS +#define FILETYPE_CSS 0xf79 +#endif +#ifndef FILETYPE_MNG +#define FILETYPE_MNG 0xf83 +#endif +#ifndef FILETYPE_GIF +#define FILETYPE_GIF 0x695 +#endif +#ifndef FILETYPE_BMP +#define FILETYPE_BMP 0x69c +#endif +#ifndef FILETYPE_ICO +#define FILETYPE_ICO 0x132 +#endif +#ifndef FILETYPE_PNG +#define FILETYPE_PNG 0xb60 +#endif +#ifndef FILETYPE_JPEG +#define FILETYPE_JPEG 0xc85 +#endif +#ifndef FILETYPE_ARTWORKS +#define FILETYPE_ARTWORKS 0xd94 +#endif +#ifndef FILETYPE_SVG +#define FILETYPE_SVG 0xaad +#endif + +/** + * Determine the MIME type of a local file. + * + * \param unix_path Unix style path to file on disk + * \return Pointer to MIME type string (should not be freed) - invalidated + * on next call to fetch_filetype. + */ +const char *fetch_filetype(const char *unix_path); + +/** + * Find a MIME type for a local file + * + * \param ro_path RISC OS style path to file on disk + * \return MIME type string (on heap, caller should free), or NULL + */ +char *fetch_mimetype(const char *ro_path); + +/** + * Determine the RISC OS filetype for a content. + * + * \param content The content to examine. + * \return The RISC OS filetype corresponding to the content + */ +int ro_content_filetype(struct hlcache_handle *c); + +/** + * Determine the native RISC OS filetype to export a content as + * + * \param c The content to examine + * \return Native RISC OS filetype for export + */ +int ro_content_native_type(struct hlcache_handle *c); + +/** + * Determine the RISC OS filetype for a MIME type + * + * \param mime_type MIME type to consider + * \return Corresponding RISC OS filetype + */ +int ro_content_filetype_from_mime_type(lwc_string *mime_type); + +/** + * Determine the RISC OS filetype from a content type. + * + * \param type The content type to examine. + * \return The RISC OS filetype corresponding to the content, or 0 for unknown + */ +int ro_content_filetype_from_type(content_type type); + +/** + * Determine the type of a local file. + * + * \param unix_path Unix style path to file on disk + * \return File type + */ +bits ro_filetype_from_unix_path(const char *unix_path); + +#endif diff --git a/riscos/font.c b/riscos/font.c index ddbe8536d..7e6c80fe5 100644 --- a/riscos/font.c +++ b/riscos/font.c @@ -17,25 +17,29 @@ */ /** \file - * Font handling (RISC OS implementation). + * RISC OS implementation of Font handling. * - * The RUfl is used handle and render fonts. + * The RUfl is used to handle and render fonts. */ +#include "utils/config.h" + #include <assert.h> #include <string.h> -#include "oslib/wimp.h" -#include "oslib/wimpreadsysinfo.h" -#include "rufl.h" +#include <oslib/wimp.h> +#include <oslib/wimpreadsysinfo.h> + #include "css/css.h" #include "css/utils.h" #include "render/font.h" -#include "riscos/gui.h" #include "utils/nsoption.h" #include "utils/log.h" #include "utils/messages.h" #include "utils/utils.h" +#include "riscos/gui.h" +#include "riscos/font.h" + static void nsfont_check_option(char **option, const char *family, const char *fallback); static int nsfont_list_cmp(const void *keyval, const void *datum); diff --git a/riscos/font.h b/riscos/font.h new file mode 100644 index 000000000..4a1fe4c6b --- /dev/null +++ b/riscos/font.h @@ -0,0 +1,43 @@ +/* + * Copyright 2014 Vincent Sanders <vince@netsurf-browser.org> + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** \file riscos/font.h + * RISC OS font interface. + */ + +#ifndef _NETSURF_RISCOS_FONT_H_ +#define _NETSURF_RISCOS_FONT_H_ + +#include <rufl.h> + +/** desktop font, size and style being used */ +extern char ro_gui_desktop_font_family[]; +extern int ro_gui_desktop_font_size; +extern rufl_style ro_gui_desktop_font_style; + +void nsfont_init(void); +bool nsfont_exists(const char *font_family); +const char *nsfont_fallback_font(void); +bool nsfont_paint(const plot_font_style_t *fstyle, const char *string, + size_t length, int x, int y); +void nsfont_read_style(const plot_font_style_t *fstyle, + const char **font_family, unsigned int *font_size, + rufl_style *font_style); +void ro_gui_wimp_get_desktop_font(void); + +#endif diff --git a/riscos/global_history.c b/riscos/global_history.c index 840271f93..9d1810503 100644 --- a/riscos/global_history.c +++ b/riscos/global_history.c @@ -32,6 +32,7 @@ #include "content/urldb.h" #include "desktop/global_history.h" #include "desktop/tree.h" +#include "desktop/gui.h" #include "riscos/dialog.h" #include "riscos/global_history.h" #include "riscos/gui.h" @@ -44,7 +45,6 @@ #include "riscos/wimp_event.h" #include "utils/messages.h" #include "utils/log.h" -#include "utils/url.h" #include "utils/utils.h" static void ro_gui_global_history_toolbar_update_buttons(void); diff --git a/riscos/gui.c b/riscos/gui.c index bb1a318de..2e337e5a2 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -21,127 +21,69 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include <stdbool.h> +#include <string.h> #include <assert.h> #include <errno.h> -#include <fpu_control.h> #include <signal.h> -#include <stdbool.h> -#include <stddef.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> -#include <features.h> #include <unixlib/local.h> -#include <curl/curl.h> -#include "oslib/font.h" -#include "oslib/help.h" -#include "oslib/hourglass.h" -#include "oslib/inetsuite.h" -#include "oslib/os.h" -#include "oslib/osbyte.h" -#include "oslib/osfile.h" -#include "oslib/osfscontrol.h" -#include "oslib/osgbpb.h" -#include "oslib/osmodule.h" -#include "oslib/osspriteop.h" -#include "oslib/pdriver.h" -#include "oslib/plugin.h" -#include "oslib/wimp.h" -#include "oslib/wimpspriteop.h" -#include "oslib/uri.h" -#include "rufl.h" -#include "utils/config.h" -#include "content/content.h" -#include "content/hlcache.h" -#include "content/urldb.h" -#include "content/fetchers/resource.h" -#include "desktop/gui.h" -#include "desktop/netsurf.h" +#include <fpu_control.h> +#include <oslib/help.h> +#include <oslib/uri.h> +#include <oslib/inetsuite.h> +#include <oslib/pdriver.h> +#include <oslib/osfile.h> +#include <oslib/hourglass.h> +#include <oslib/osgbpb.h> +#include <oslib/osbyte.h> +#include <oslib/osmodule.h> +#include <oslib/osfscontrol.h> + +#include "utils/utils.h" #include "utils/nsoption.h" +#include "utils/log.h" +#include "utils/messages.h" +#include "utils/file.h" +#include "utils/filename.h" +#include "utils/url.h" +#include "utils/corestrings.h" +#include "desktop/gui.h" #include "desktop/save_complete.h" #include "desktop/treeview.h" -#include "render/font.h" -#include "riscos/content-handlers/artworks.h" -#include "riscos/bitmap.h" -#include "riscos/buffer.h" -#include "riscos/cookies.h" -#include "riscos/dialog.h" -#include "riscos/content-handlers/draw.h" -#include "riscos/global_history.h" +#include "desktop/netsurf.h" +#include "desktop/browser.h" +#include "content/urldb.h" +#include "content/hlcache.h" +#include "content/backing_store.h" + #include "riscos/gui.h" -#include "riscos/gui/url_bar.h" -#include "riscos/help.h" +#include "riscos/wimputils.h" #include "riscos/hotlist.h" -#include "riscos/iconbar.h" -#include "riscos/menus.h" -#include "riscos/message.h" -#include "riscos/mouse.h" +#include "riscos/buffer.h" +#include "riscos/textselection.h" #include "riscos/print.h" -#include "riscos/query.h" #include "riscos/save.h" +#include "riscos/dialog.h" +#include "riscos/wimp.h" +#include "riscos/message.h" +#include "riscos/help.h" +#include "riscos/query.h" +#include "riscos/window.h" +#include "riscos/iconbar.h" #include "riscos/sslcert.h" -#include "riscos/content-handlers/sprite.h" -#include "riscos/textselection.h" -#include "riscos/theme.h" -#include "riscos/toolbar.h" -#include "riscos/treeview.h" +#include "riscos/global_history.h" +#include "riscos/cookies.h" +#include "riscos/wimp_event.h" #include "riscos/uri.h" #include "riscos/url_protocol.h" -#include "riscos/url_complete.h" -#include "riscos/wimp.h" -#include "riscos/wimp_event.h" -#include "riscos/wimputils.h" -#include "riscos/window.h" -#include "utils/filename.h" -#include "utils/log.h" -#include "utils/messages.h" -#include "utils/url.h" -#include "utils/utils.h" - - - -#ifndef FILETYPE_ACORN_URI -#define FILETYPE_ACORN_URI 0xf91 -#endif -#ifndef FILETYPE_ANT_URL -#define FILETYPE_ANT_URL 0xb28 -#endif -#ifndef FILETYPE_IEURL -#define FILETYPE_IEURL 0x1ba -#endif -#ifndef FILETYPE_HTML -#define FILETYPE_HTML 0xfaf -#endif -#ifndef FILETYPE_JNG -#define FILETYPE_JNG 0xf78 -#endif -#ifndef FILETYPE_CSS -#define FILETYPE_CSS 0xf79 -#endif -#ifndef FILETYPE_MNG -#define FILETYPE_MNG 0xf83 -#endif -#ifndef FILETYPE_GIF -#define FILETYPE_GIF 0x695 -#endif -#ifndef FILETYPE_BMP -#define FILETYPE_BMP 0x69c -#endif -#ifndef FILETYPE_ICO -#define FILETYPE_ICO 0x132 -#endif -#ifndef FILETYPE_PNG -#define FILETYPE_PNG 0xb60 -#endif -#ifndef FILETYPE_JPEG -#define FILETYPE_JPEG 0xc85 -#endif -#ifndef FILETYPE_ARTWORKS -#define FILETYPE_ARTWORKS 0xd94 -#endif -#ifndef FILETYPE_SVG -#define FILETYPE_SVG 0xaad -#endif +#include "riscos/mouse.h" +#include "riscos/ucstables.h" +#include "riscos/filetype.h" +#include "riscos/font.h" +#include "riscos/toolbar.h" +#include "riscos/content-handlers/artworks.h" +#include "riscos/content-handlers/draw.h" +#include "riscos/content-handlers/sprite.h" extern bool ro_plot_patterned_lines; @@ -163,11 +105,15 @@ static const char *task_name = "NetSurf"; #define CHOICES_PREFIX "<Choices$Write>.WWW.NetSurf." ro_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 *gui_sprites; /**< Sprite area containing pointer and hotlist sprites */ +wimp_t task_handle; /**< RISC OS wimp task handle. */ +static clock_t gui_last_poll; /**< Time of last wimp_poll. */ +osspriteop_area *gui_sprites; /**< Sprite area containing pointer and hotlist sprites */ + +#define DIR_SEP ('.') -/** Accepted wimp user messages. */ +/** + * Accepted wimp user messages. + */ static ns_wimp_message_list task_messages = { message_HELP_REQUEST, { @@ -221,38 +167,26 @@ static ns_wimp_message_list task_messages = { } }; + static struct { - int width; /* in OS units */ - int height; + int width; /* in OS units */ + int height; } screen_info; -static void ro_gui_create_dirs(void); -static void ro_gui_create_dir(char *path); -static void ro_gui_choose_language(void); -static void ro_gui_signal(int sig); -static void ro_gui_cleanup(void); -static void ro_gui_handle_event(wimp_event_no event, wimp_block *block); -static void ro_gui_close_window_request(wimp_close *close); -static void ro_gui_check_resolvers(void); -static void ro_gui_keypress(wimp_key *key); -static void ro_gui_user_message(wimp_event_no event, wimp_message *message); -static void ro_msg_dataload(wimp_message *block); -static char *ro_gui_uri_file_parse(const char *file_name, char **uri_title); -static bool ro_gui_uri_file_parse_line(FILE *fp, char *b); -static char *ro_gui_url_file_parse(const char *file_name); -static char *ro_gui_ieurl_file_parse(const char *file_name); -static void ro_msg_terminate_filename(wimp_full_message_data_xfer *message); -static void ro_msg_datasave(wimp_message *message); -static void ro_msg_datasave_ack(wimp_message *message); -static void ro_msg_dataopen(wimp_message *message); -static void ro_gui_get_screen_properties(void); -static void ro_msg_prequit(wimp_message *message); -static void ro_msg_save_desktop(wimp_message *message); -static void ro_msg_window_info(wimp_message *message); -static void ro_gui_view_source_bounce(wimp_message *message); - -nsurl *gui_get_resource_url(const char *path) + +/** + * Callback to translate resource to full url for RISC OS. + * + * Transforms a resource: path into a full URL. The returned URL is + * used as the target for a redirect. The caller takes ownership of + * the returned nsurl including unrefing it when finished with it. + * + * \param path The path of the resource to locate. + * \return A string containing the full URL of the target object or + * NULL if no suitable resource can be found. + */ +static nsurl *gui_get_resource_url(const char *path) { static const char base_url[] = "file:///NetSurf:/Resources/"; size_t path_len, length; @@ -313,14 +247,21 @@ nsurl *gui_get_resource_url(const char *path) return url; } + /** - * set option from wimp + * Set colour option from wimp. + * + * \param opts The netsurf options. + * \param wimp wimp colour value + * \param option the netsurf option enum. + * \param def_colour The default colour value to use. + * \return NSERROR_OK on success or error code. */ static nserror set_colour_from_wimp(struct nsoption_s *opts, - wimp_colour wimp, - enum nsoption_e option, - colour def_colour) + wimp_colour wimp, + enum nsoption_e option, + colour def_colour) { os_error *error; os_PALETTE(20) palette; @@ -339,17 +280,16 @@ set_colour_from_wimp(struct nsoption_s *opts, return NSERROR_OK; } + /** * Set option defaults for riscos frontend * * @param defaults The option table to update. * @return error status. * - * @TODO -- The wimp_COLOUR_... values here map the colour definitions - * to parts of the RISC OS desktop palette. In places this - * is fairly arbitrary, and could probably do with - * re-checking. - * + * @todo The wimp_COLOUR_... values here map the colour definitions to + * parts of the RISC OS desktop palette. In places this is fairly + * arbitrary, and could probably do with re-checking. */ static nserror set_defaults(struct nsoption_s *defaults) { @@ -398,11 +338,755 @@ static nserror set_defaults(struct nsoption_s *defaults) return NSERROR_OK; } + + + +/** + * Create intermediate directories for Choices and User Data files + */ +static void ro_gui_create_dirs(void) +{ + char buf[256]; + char *path; + + /* Choices */ + path = getenv("NetSurf$ChoicesSave"); + if (!path) + die("Failed to find NetSurf Choices save path"); + + snprintf(buf, sizeof(buf), "%s", path); + netsurf_mkdir_all(buf); + + /* URL */ + snprintf(buf, sizeof(buf), "%s", nsoption_charp(url_save)); + netsurf_mkdir_all(buf); + + /* Hotlist */ + snprintf(buf, sizeof(buf), "%s", nsoption_charp(hotlist_save)); + netsurf_mkdir_all(buf); + + /* Recent */ + snprintf(buf, sizeof(buf), "%s", nsoption_charp(recent_save)); + netsurf_mkdir_all(buf); + + /* Theme */ + snprintf(buf, sizeof(buf), "%s", nsoption_charp(theme_save)); + netsurf_mkdir_all(buf); + /* and the final directory part (as theme_save is a directory) */ + xosfile_create_dir(buf, 0); +} + + +/** + * Ensures the gui exits cleanly. + */ +static void ro_gui_cleanup(void) +{ + ro_gui_buffer_close(); + xhourglass_off(); + /* Uninstall NetSurf-specific fonts */ + xos_cli("FontRemove NetSurf:Resources.Fonts."); +} + + +/** + * Handles a signal + */ +static void ro_gui_signal(int sig) +{ + static const os_error error = { 1, "NetSurf has detected a serious " + "error and must exit. Please submit a bug report, " + "attaching the browser log file." }; + os_colour old_sand, old_glass; + + ro_gui_cleanup(); + + xhourglass_on(); + xhourglass_colours(0x0000ffff, 0x000000ff, &old_sand, &old_glass); + nsoption_dump(stderr, NULL); + /*rufl_dump_state();*/ + +#ifndef __ELF__ + /* save WimpSlot and DA to files if NetSurf$CoreDump exists */ + int used; + xos_read_var_val_size("NetSurf$CoreDump", 0, 0, &used, 0, 0); + if (used) { + int curr_slot; + xwimp_slot_size(-1, -1, &curr_slot, 0, 0); + LOG(("saving WimpSlot, size 0x%x", curr_slot)); + xosfile_save("$.NetSurf_Slot", 0x8000, 0, + (byte *) 0x8000, + (byte *) 0x8000 + curr_slot); + + if (__dynamic_num != -1) { + int size; + byte *base_address; + xosdynamicarea_read(__dynamic_num, &size, + &base_address, 0, 0, 0, 0, 0); + LOG(("saving DA %i, base %p, size 0x%x", + __dynamic_num, + base_address, size)); + xosfile_save("$.NetSurf_DA", + (bits) base_address, 0, + base_address, + base_address + size); + } + } +#else + /* Save WimpSlot and UnixLib managed DAs when UnixEnv$coredump + * defines a coredump directory. */ + _kernel_oserror *err = __unixlib_write_coredump (NULL); + if (err != NULL) + LOG(("Coredump failed: %s", err->errmess)); +#endif + + xhourglass_colours(old_sand, old_glass, 0, 0); + xhourglass_off(); + + __write_backtrace(sig); + + xwimp_report_error_by_category(&error, + wimp_ERROR_BOX_GIVEN_CATEGORY | + wimp_ERROR_BOX_CATEGORY_ERROR << + wimp_ERROR_BOX_CATEGORY_SHIFT, + "NetSurf", "!netsurf", + (osspriteop_area *) 1, "Quit", 0); + xos_cli("Filer_Run <Wimp$ScrapDir>.WWW.NetSurf.Log"); + + _Exit(sig); +} + + +/** + * Read a "line" from an Acorn URI file. + * + * \param fp file pointer to read from + * \param b buffer for line, size 400 bytes + * \return true on success, false on EOF + */ +static bool ro_gui_uri_file_parse_line(FILE *fp, char *b) +{ + int c; + unsigned int i = 0; + + c = getc(fp); + if (c == EOF) + return false; + + /* skip comment lines */ + while (c == '#') { + do { c = getc(fp); } while (c != EOF && 32 <= c); + if (c == EOF) + return false; + do { c = getc(fp); } while (c != EOF && c < 32); + if (c == EOF) + return false; + } + + /* read "line" */ + do { + if (i == 399) + return false; + b[i++] = c; + c = getc(fp); + } while (c != EOF && 32 <= c); + + /* skip line ending control characters */ + while (c != EOF && c < 32) + c = getc(fp); + + if (c != EOF) + ungetc(c, fp); + + b[i] = 0; + return true; +} + + +/** + * Parse an Acorn URI file. + * + * \param file_name file to read + * \param uri_title pointer to receive title data, or NULL for no data + * \return URL from file, or 0 on error and error reported + */ +static char *ro_gui_uri_file_parse(const char *file_name, char **uri_title) +{ + /* See the "Acorn URI Handler Functional Specification" for the + * definition of the URI file format. */ + char line[400]; + char *url = NULL; + FILE *fp; + + *uri_title = NULL; + fp = fopen(file_name, "rb"); + if (!fp) { + LOG(("fopen(\"%s\", \"rb\"): %i: %s", + file_name, errno, strerror(errno))); + warn_user("LoadError", strerror(errno)); + return 0; + } + + /* "URI" */ + if (!ro_gui_uri_file_parse_line(fp, line) || strcmp(line, "URI") != 0) + goto uri_syntax_error; + + /* version */ + if (!ro_gui_uri_file_parse_line(fp, line) || + strspn(line, "0123456789") != strlen(line)) + goto uri_syntax_error; + + /* URI */ + if (!ro_gui_uri_file_parse_line(fp, line)) + goto uri_syntax_error; + + url = strdup(line); + if (!url) { + warn_user("NoMemory", 0); + fclose(fp); + return 0; + } + + /* title */ + if (!ro_gui_uri_file_parse_line(fp, line)) + goto uri_free; + if (uri_title && line[0] && ((line[0] != '*') || line[1])) { + *uri_title = strdup(line); + if (!*uri_title) /* non-fatal */ + warn_user("NoMemory", 0); + } + fclose(fp); + + return url; + +uri_free: + free(url); + +uri_syntax_error: + fclose(fp); + warn_user("URIError", 0); + return 0; +} + + +/** + * Parse an ANT URL file. + * + * \param file_name file to read + * \return URL from file, or 0 on error and error reported + */ +static char *ro_gui_url_file_parse(const char *file_name) +{ + char line[400]; + char *url; + FILE *fp; + + fp = fopen(file_name, "r"); + if (!fp) { + LOG(("fopen(\"%s\", \"r\"): %i: %s", + file_name, errno, strerror(errno))); + warn_user("LoadError", strerror(errno)); + return 0; + } + + if (!fgets(line, sizeof line, fp)) { + if (ferror(fp)) { + LOG(("fgets: %i: %s", + errno, strerror(errno))); + warn_user("LoadError", strerror(errno)); + } else + warn_user("LoadError", messages_get("EmptyError")); + fclose(fp); + return 0; + } + + fclose(fp); + + if (line[strlen(line) - 1] == '\n') + line[strlen(line) - 1] = '\0'; + + url = strdup(line); + if (!url) { + warn_user("NoMemory", 0); + return 0; + } + + return url; +} + + +/** + * Parse an IEURL file. + * + * \param file_name file to read + * \return URL from file, or 0 on error and error reported + */ +static char *ro_gui_ieurl_file_parse(const char *file_name) +{ + char line[400]; + char *url = 0; + FILE *fp; + + fp = fopen(file_name, "r"); + if (!fp) { + LOG(("fopen(\"%s\", \"r\"): %i: %s", + file_name, errno, strerror(errno))); + warn_user("LoadError", strerror(errno)); + return 0; + } + + while (fgets(line, sizeof line, fp)) { + if (strncmp(line, "URL=", 4) == 0) { + if (line[strlen(line) - 1] == '\n') + line[strlen(line) - 1] = '\0'; + url = strdup(line + 4); + if (!url) { + fclose(fp); + warn_user("NoMemory", 0); + return 0; + } + break; + } + } + if (ferror(fp)) { + LOG(("fgets: %i: %s", + errno, strerror(errno))); + warn_user("LoadError", strerror(errno)); + fclose(fp); + return 0; + } + + fclose(fp); + + if (!url) + warn_user("URIError", 0); + + return url; +} + + +/** + * Handle Message_DataOpen (double-click on file in the Filer). + * + * \param message The wimp message to open. + */ +static void ro_msg_dataopen(wimp_message *message) +{ + int file_type = message->data.data_xfer.file_type; + char *url = 0; + os_error *oserror; + nsurl *urlns; + nserror error; + size_t len; + + switch (file_type) { + case 0xb28: /* ANT URL file */ + url = ro_gui_url_file_parse(message->data.data_xfer.file_name); + error = nsurl_create(url, &urlns); + free(url); + break; + + case 0xfaf: /* HTML file */ + error = netsurf_path_to_nsurl(message->data.data_xfer.file_name, + &urlns); + break; + + case 0x1ba: /* IEURL file */ + url = ro_gui_ieurl_file_parse(message-> + data.data_xfer.file_name); + error = nsurl_create(url, &urlns); + free(url); + break; + + case 0x2000: /* application */ + len = strlen(message->data.data_xfer.file_name); + if (len < 9 || strcmp(".!NetSurf", + message->data.data_xfer.file_name + len - 9)) + return; + + if (nsoption_charp(homepage_url) && + nsoption_charp(homepage_url)[0]) { + error = nsurl_create(nsoption_charp(homepage_url), + &urlns); + } else { + error = nsurl_create(NETSURF_HOMEPAGE, &urlns); + } + break; + + default: + return; + } + + /* send DataLoadAck */ + message->action = message_DATA_LOAD_ACK; + message->your_ref = message->my_ref; + oserror = xwimp_send_message(wimp_USER_MESSAGE, message, message->sender); + if (oserror) { + LOG(("xwimp_send_message: 0x%x: %s", + oserror->errnum, oserror->errmess)); + warn_user("WimpError", oserror->errmess); + return; + } + + if (error != NSERROR_OK) { + warn_user(messages_get_errorcode(error), 0); + return; + } + + /* create a new window with the file */ + error = browser_window_create(BW_CREATE_HISTORY, + urlns, + NULL, + NULL, + NULL); + nsurl_unref(urlns); + if (error != NSERROR_OK) { + warn_user(messages_get_errorcode(error), 0); + } +} + + +/** + * Handle Message_DataLoad (file dragged in). + */ +static void ro_msg_dataload(wimp_message *message) +{ + int file_type = message->data.data_xfer.file_type; + char *urltxt = NULL; + char *title = NULL; + struct gui_window *g; + os_error *oserror; + nsurl *url; + nserror error; + + g = ro_gui_window_lookup(message->data.data_xfer.w); + if (g) { + if (ro_gui_window_dataload(g, message)) + return; + } + else { + g = ro_gui_toolbar_lookup(message->data.data_xfer.w); + if (g && ro_gui_toolbar_dataload(g, message)) + return; + } + + switch (file_type) { + case FILETYPE_ACORN_URI: + urltxt = ro_gui_uri_file_parse(message->data.data_xfer.file_name, + &title); + error = nsurl_create(urltxt, &url); + free(urltxt); + break; + + case FILETYPE_ANT_URL: + urltxt = ro_gui_url_file_parse(message->data.data_xfer.file_name); + error = nsurl_create(urltxt, &url); + free(urltxt); + break; + + case FILETYPE_IEURL: + urltxt = ro_gui_ieurl_file_parse(message->data.data_xfer.file_name); + error = nsurl_create(urltxt, &url); + free(urltxt); + break; + + case FILETYPE_HTML: + case FILETYPE_JNG: + case FILETYPE_CSS: + case FILETYPE_MNG: + case FILETYPE_GIF: + case FILETYPE_BMP: + case FILETYPE_ICO: + case osfile_TYPE_DRAW: + case FILETYPE_PNG: + case FILETYPE_JPEG: + case osfile_TYPE_SPRITE: + case osfile_TYPE_TEXT: + case FILETYPE_ARTWORKS: + case FILETYPE_SVG: + /* display the actual file */ + error = netsurf_path_to_nsurl(message->data.data_xfer.file_name, &url); + break; + + default: + return; + } + + /* report error to user */ + if (error != NSERROR_OK) { + warn_user(messages_get_errorcode(error), 0); + return; + } + + + if (g) { + error = browser_window_navigate(g->bw, + url, + NULL, + BW_NAVIGATE_HISTORY, + NULL, + NULL, + NULL); + } else { + error = browser_window_create(BW_CREATE_HISTORY, + url, + NULL, + NULL, + NULL); + } + nsurl_unref(url); + if (error != NSERROR_OK) { + warn_user(messages_get_errorcode(error), 0); + } + + + /* send DataLoadAck */ + message->action = message_DATA_LOAD_ACK; + message->your_ref = message->my_ref; + oserror = xwimp_send_message(wimp_USER_MESSAGE, message, + message->sender); + if (oserror) { + LOG(("xwimp_send_message: 0x%x: %s", + oserror->errnum, oserror->errmess)); + warn_user("WimpError", oserror->errmess); + return; + } + +} + + +/** + * Ensure that the filename in a data transfer message is NULL terminated + * (some applications, especially BASIC programs use CR) + * + * \param message message to be corrected + */ +static void ro_msg_terminate_filename(wimp_full_message_data_xfer *message) +{ + const char *ep = (char*)message + message->size; + char *p = message->file_name; + + if ((size_t)message->size >= sizeof(*message)) + ep = (char*)message + sizeof(*message) - 1; + + while (p < ep && *p >= ' ') p++; + *p = '\0'; +} + + +/** + * Handle Message_DataSave + */ +static void ro_msg_datasave(wimp_message *message) +{ + wimp_full_message_data_xfer *dataxfer = (wimp_full_message_data_xfer*)message; + + /* remove ghost caret if drag-and-drop protocol was used */ +// ro_gui_selection_drag_reset(); + + ro_msg_terminate_filename(dataxfer); + + if (ro_gui_selection_prepare_paste_datasave(dataxfer)) + return; + + switch (dataxfer->file_type) { + case FILETYPE_ACORN_URI: + case FILETYPE_ANT_URL: + case FILETYPE_IEURL: + case FILETYPE_HTML: + case FILETYPE_JNG: + case FILETYPE_CSS: + case FILETYPE_MNG: + case FILETYPE_GIF: + case FILETYPE_BMP: + case FILETYPE_ICO: + case osfile_TYPE_DRAW: + case FILETYPE_PNG: + case FILETYPE_JPEG: + case osfile_TYPE_SPRITE: + case osfile_TYPE_TEXT: + case FILETYPE_ARTWORKS: + case FILETYPE_SVG: { + os_error *error; + + dataxfer->your_ref = dataxfer->my_ref; + dataxfer->size = offsetof(wimp_full_message_data_xfer, file_name) + 16; + dataxfer->action = message_DATA_SAVE_ACK; + dataxfer->est_size = -1; + memcpy(dataxfer->file_name, "<Wimp$Scrap>", 13); + + error = xwimp_send_message(wimp_USER_MESSAGE, (wimp_message*)dataxfer, message->sender); + if (error) { + LOG(("xwimp_send_message: 0x%x: %s", error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + } + } + break; + } +} + + +/** + * Handle Message_DataSaveAck. + */ +static void ro_msg_datasave_ack(wimp_message *message) +{ + ro_msg_terminate_filename((wimp_full_message_data_xfer*)message); + + if (ro_print_ack(message)) + return; + + switch (gui_current_drag_type) { + case GUI_DRAG_DOWNLOAD_SAVE: + ro_gui_download_datasave_ack(message); + break; + + case GUI_DRAG_SAVE: + ro_gui_save_datasave_ack(message); + gui_current_drag_type = GUI_DRAG_NONE; + break; + + default: + break; + } + + gui_current_drag_type = GUI_DRAG_NONE; +} + + +/** + * Handle PreQuit message + * + * \param message PreQuit message from Wimp + */ +static void ro_msg_prequit(wimp_message *message) +{ + if (!ro_gui_prequit()) { + os_error *error; + + /* we're objecting to the close down */ + message->your_ref = message->my_ref; + error = xwimp_send_message(wimp_USER_MESSAGE_ACKNOWLEDGE, + message, message->sender); + if (error) { + LOG(("xwimp_send_message: 0x%x:%s", error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + } + } +} + + +/** + * Handle SaveDesktop message. + * + * \param message SaveDesktop message from Wimp. + */ +static void ro_msg_save_desktop(wimp_message *message) +{ + os_error *error; + + error = xosgbpb_writew(message->data.save_desktopw.file, + (const byte*)"Run ", 4, NULL); + if (!error) { + error = xosgbpb_writew(message->data.save_desktopw.file, + (const byte*)NETSURF_DIR, strlen(NETSURF_DIR), NULL); + if (!error) + error = xos_bputw('\n', message->data.save_desktopw.file); + } + + if (error) { + LOG(("xosgbpb_writew/xos_bputw: 0x%x:%s", error->errnum, error->errmess)); + warn_user("SaveError", error->errmess); + + /* we must cancel the save by acknowledging the message */ + message->your_ref = message->my_ref; + error = xwimp_send_message(wimp_USER_MESSAGE_ACKNOWLEDGE, + message, message->sender); + if (error) { + LOG(("xwimp_send_message: 0x%x:%s", error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + } + } +} + + /** - * Initialise the gui (RISC OS specific part). + * Handle WindowInfo message (part of the iconising protocol) + * + * \param message WindowInfo message from the Iconiser */ +static void ro_msg_window_info(wimp_message *message) +{ + wimp_full_message_window_info *wi; + struct gui_window *g; -static void gui_init(int argc, char** argv) + /* allow the user to turn off thumbnail icons */ + if (!nsoption_bool(thumbnail_iconise)) + return; + + wi = (wimp_full_message_window_info*)message; + g = ro_gui_window_lookup(wi->w); + + /* ic_<task name> will suffice for our other windows */ + if (g) { + ro_gui_window_iconise(g, wi); + ro_gui_dialog_close_persistent(wi->w); + } +} + + +/** + * Get screen properties following a mode change. + */ +static void ro_gui_get_screen_properties(void) +{ + static const ns_os_vdu_var_list vars = { + os_MODEVAR_XWIND_LIMIT, + { + os_MODEVAR_YWIND_LIMIT, + os_MODEVAR_XEIG_FACTOR, + os_MODEVAR_YEIG_FACTOR, + os_VDUVAR_END_LIST + } + }; + os_error *error; + int vals[4]; + + error = xos_read_vdu_variables(PTR_OS_VDU_VAR_LIST(&vars), vals); + if (error) { + LOG(("xos_read_vdu_variables: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("MiscError", error->errmess); + return; + } + screen_info.width = (vals[0] + 1) << vals[2]; + screen_info.height = (vals[1] + 1) << vals[3]; +} + + +/** + * Warn the user if Inet$Resolvers is not set. + */ +static void ro_gui_check_resolvers(void) +{ + char *resolvers; + resolvers = getenv("Inet$Resolvers"); + if (resolvers && resolvers[0]) { + LOG(("Inet$Resolvers '%s'", resolvers)); + } else { + LOG(("Inet$Resolvers not set or empty")); + warn_user("Resolvers", 0); + } +} + + +/** + * Initialise the RISC OS specific GUI. + * + * \param argc The number of command line arguments. + * \param argv The string vector of command line arguments. + */ +static nserror gui_init(int argc, char** argv) { struct { void (*sigabrt)(int); @@ -417,7 +1101,9 @@ static void gui_init(int argc, char** argv) int length; char *nsdir_temp; byte *base; - nserror err; + nsurl *url; + nserror ret; + bool open_window; /* re-enable all FPU exceptions/traps except inexact operations, * which we're not interested in, and underflow which is incorrectly @@ -540,27 +1226,35 @@ static void gui_init(int argc, char** argv) die(error->errmess); } - err = treeview_init(12); - if (err != NSERROR_OK) { + ret = treeview_init(12); + if (ret != NSERROR_OK) { die("Failed to initialise treeview"); } /* Initialise themes before dialogs */ ro_gui_theme_initialise(); + /* Initialise dialog windows (must be after UI sprites are loaded) */ ro_gui_dialog_init(); + /* Initialise download window */ ro_gui_download_init(); + /* Initialise menus */ ro_gui_menu_init(); + /* Initialise query windows */ ro_gui_query_init(); + /* Initialise the history subsystem */ ro_gui_history_init(); + /* Initialise toolbars */ ro_toolbar_init(); + /* Initialise url bar module */ ro_gui_url_bar_init(); + /* Initialise browser windows */ ro_gui_window_initialise(); @@ -572,89 +1266,84 @@ static void gui_init(int argc, char** argv) /* Finally, check Inet$Resolvers for sanity */ ro_gui_check_resolvers(); -} -/** - * Create intermediate directories for Choices and User Data files - */ -void ro_gui_create_dirs(void) -{ - char buf[256]; - char *path; - - /* Choices */ - path = getenv("NetSurf$ChoicesSave"); - if (!path) - die("Failed to find NetSurf Choices save path"); - - snprintf(buf, sizeof(buf), "%s", path); - ro_gui_create_dir(buf); - - /* URL */ - snprintf(buf, sizeof(buf), "%s", nsoption_charp(url_save)); - ro_gui_create_dir(buf); + /* certificate verification window */ + ro_gui_cert_postinitialise(); - /* Hotlist */ - snprintf(buf, sizeof(buf), "%s", nsoption_charp(hotlist_save)); - ro_gui_create_dir(buf); + /* hotlist window */ + ro_gui_hotlist_postinitialise(); - /* Recent */ - snprintf(buf, sizeof(buf), "%s", nsoption_charp(recent_save)); - ro_gui_create_dir(buf); + /* global history window */ + ro_gui_global_history_postinitialise(); - /* Theme */ - snprintf(buf, sizeof(buf), "%s", nsoption_charp(theme_save)); - ro_gui_create_dir(buf); - /* and the final directory part (as theme_save is a directory) */ - xosfile_create_dir(buf, 0); -} + /* cookies window */ + ro_gui_cookies_postinitialise(); + open_window = nsoption_bool(open_browser_at_startup); -/** - * Create directory structure for a path - * - * Given a path of x.y.z directories x and x.y will be created - * - * \param path the directory path to create - */ -void ro_gui_create_dir(char *path) -{ - char *cur = path; - while ((cur = strchr(cur, '.'))) { - *cur = '\0'; - xosfile_create_dir(path, 0); - *cur++ = '.'; + /* parse command-line arguments */ + if (argc == 2) { + LOG(("parameters: '%s'", argv[1])); + /* this is needed for launching URI files */ + if (strcasecmp(argv[1], "-nowin") == 0) { + return NSERROR_OK; + } + ret = nsurl_create(NETSURF_HOMEPAGE, &url); } -} - + else if (argc == 3) { + LOG(("parameters: '%s' '%s'", argv[1], argv[2])); + open_window = true; -/** - * Choose the language to use. - */ + /* HTML files */ + if (strcasecmp(argv[1], "-html") == 0) { + ret = netsurf_path_to_nsurl(argv[2], &url); + } + /* URL files */ + else if (strcasecmp(argv[1], "-urlf") == 0) { + char *urlf = ro_gui_url_file_parse(argv[2]); + if (!urlf) { + LOG(("allocation failed")); + die("Insufficient memory for URL"); + } + ret = nsurl_create(urlf, &url); + free(urlf); + } + /* ANT URL Load */ + else if (strcasecmp(argv[1], "-url") == 0) { + ret = nsurl_create(argv[2], &url); + } + /* Unknown => exit here. */ + else { + LOG(("Unknown parameters: '%s' '%s'", + argv[1], argv[2])); + return NSERROR_BAD_PARAMETER; + } + } + /* get user's homepage (if configured) */ + else if (nsoption_charp(homepage_url) && + nsoption_charp(homepage_url)[0]) { + ret = nsurl_create(nsoption_charp(homepage_url), &url); + } + /* default homepage */ + else { + ret = nsurl_create(NETSURF_HOMEPAGE, &url); + } -void ro_gui_choose_language(void) -{ - char path[40]; + /* check for url creation error */ + if (ret != NSERROR_OK) { + return ret; + } - /* if option_language exists and is valid, use that */ - if (nsoption_charp(language)) { - if (2 < strlen(nsoption_charp(language))) - nsoption_charp(language)[2] = 0; - sprintf(path, "NetSurf:Resources.%s", nsoption_charp(language)); - if (is_dir(path)) { - nsoption_setnull_charp(accept_language, - strdup(nsoption_charp(language))); - return; - } - nsoption_set_charp(language, NULL); + if (open_window) { + ret = browser_window_create(BW_CREATE_HISTORY, + url, + NULL, + NULL, + NULL); } + nsurl_unref(url); - nsoption_set_charp(language, strdup(ro_gui_default_language())); - if (nsoption_charp(language) == NULL) - die("Out of memory"); - nsoption_set_charp(accept_language, strdup(nsoption_charp(language))); - if (nsoption_charp(accept_language) == NULL) - die("Out of memory"); + return ret; } @@ -664,7 +1353,6 @@ void ro_gui_choose_language(void) * RISC OS has no standard way of determining which language the user prefers. * We have to guess from the 'Country' setting. */ - const char *ro_gui_default_language(void) { char path[40]; @@ -704,222 +1392,173 @@ const char *ro_gui_default_language(void) /** - * Warn the user if Inet$Resolvers is not set. - */ - -void ro_gui_check_resolvers(void) -{ - char *resolvers; - resolvers = getenv("Inet$Resolvers"); - if (resolvers && resolvers[0]) { - LOG(("Inet$Resolvers '%s'", resolvers)); - } else { - LOG(("Inet$Resolvers not set or empty")); - warn_user("Resolvers", 0); - } -} - - -/** - * Last-minute gui init, after all other modules have initialised. + * Create a nsurl from a RISC OS pathname. + * + * Perform the necessary operations on a path to generate a nsurl. + * + * @param[in] path The RISC OS pathname to convert. + * @param[out] url pointer to recive the nsurl, The returned url must be + * unreferenced by the caller. + * @return NSERROR_OK and the url is placed in \a url or error code on faliure. */ - -static void gui_init2(int argc, char** argv) +static nserror ro_path_to_nsurl(const char *path, struct nsurl **url_out) { - char *url = 0; - bool open_window = nsoption_bool(open_browser_at_startup); - - /* Complete initialisation of the treeview modules. */ - - /* certificate verification window */ - ro_gui_cert_postinitialise(); + int spare; + char *canonical_path; /* canonicalised RISC OS path */ + char *unix_path; /* unix path */ + char *escurl; + os_error *error; + nserror ret; + int urllen; + char *url; /* resulting url */ - /* hotlist window */ - ro_gui_hotlist_postinitialise(); + /* calculate the canonical risc os path */ + error = xosfscontrol_canonicalise_path(path, 0, 0, 0, 0, &spare); + if (error) { + LOG(("xosfscontrol_canonicalise_path failed: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("PathToURL", error->errmess); + return NSERROR_NOT_FOUND; + } - /* global history window */ - ro_gui_global_history_postinitialise(); + canonical_path = malloc(1 - spare); + if (canonical_path == NULL) { + free(canonical_path); + return NSERROR_NOMEM; + } - /* cookies window */ - ro_gui_cookies_postinitialise(); + error = xosfscontrol_canonicalise_path(path, canonical_path, 0, 0, 1 - spare, 0); + if (error) { + LOG(("xosfscontrol_canonicalise_path failed: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("PathToURL", error->errmess); + free(canonical_path); + return NSERROR_NOT_FOUND; + } + /* create a unix path from teh cananocal risc os one */ + unix_path = __unixify(canonical_path, __RISCOSIFY_NO_REVERSE_SUFFIX, NULL, 0, 0); - /* parse command-line arguments */ - if (argc == 2) { - LOG(("parameters: '%s'", argv[1])); - /* this is needed for launching URI files */ - if (strcasecmp(argv[1], "-nowin") == 0) - open_window = false; + if (unix_path == NULL) { + LOG(("__unixify failed: %s", canonical_path)); + free(canonical_path); + return NSERROR_BAD_PARAMETER; } - else if (argc == 3) { - LOG(("parameters: '%s' '%s'", argv[1], argv[2])); - open_window = true; + free(canonical_path); - /* HTML files */ - if (strcasecmp(argv[1], "-html") == 0) { - url = path_to_url(argv[2]); - if (!url) { - LOG(("malloc failed")); - die("Insufficient memory for URL"); - } - } - /* URL files */ - else if (strcasecmp(argv[1], "-urlf") == 0) { - url = ro_gui_url_file_parse(argv[2]); - if (!url) { - LOG(("malloc failed")); - die("Insufficient memory for URL"); - } - } - /* ANT URL Load */ - else if (strcasecmp(argv[1], "-url") == 0) { - url = strdup(argv[2]); - if (!url) { - LOG(("malloc failed")); - die("Insufficient memory for URL"); - } - } - /* Unknown => exit here. */ - else { - LOG(("Unknown parameters: '%s' '%s'", - argv[1], argv[2])); - return; - } - } - /* get user's homepage (if configured) */ - else if (nsoption_charp(homepage_url) && nsoption_charp(homepage_url)[0]) { - url = calloc(strlen(nsoption_charp(homepage_url)) + 5, sizeof(char)); - if (!url) { - LOG(("malloc failed")); - die("Insufficient memory for URL"); - } - sprintf(url, "%s", nsoption_charp(homepage_url)); - } - /* default homepage */ - else { - url = strdup(NETSURF_HOMEPAGE); - if (!url) { - LOG(("malloc failed")); - die("Insufficient memory for URL"); - } + /* convert the unix path into a url */ + urllen = strlen(unix_path) + FILE_SCHEME_PREFIX_LEN + 1; + url = malloc(urllen); + if (url == NULL) { + LOG(("Unable to allocate url")); + free(unix_path); + return NSERROR_NOMEM; } - if (open_window) { - nsurl *urlns; - nserror errorns; - - errorns = nsurl_create(url, &urlns); - if (errorns == NSERROR_OK) { - errorns = browser_window_create(BROWSER_WINDOW_VERIFIABLE | - BROWSER_WINDOW_HISTORY, - urlns, - NULL, - NULL, - NULL); - nsurl_unref(urlns); - } - if (errorns != NSERROR_OK) { - warn_user(messages_get_errorcode(errorns), 0); - } + if (*unix_path == '/') { + snprintf(url, urllen, "%s%s", FILE_SCHEME_PREFIX, unix_path + 1); + } else { + snprintf(url, urllen, "%s%s", FILE_SCHEME_PREFIX, unix_path); } + free(unix_path); + /* We don't want '/' to be escaped. */ + ret = url_escape(url, FILE_SCHEME_PREFIX_LEN, false, "/", &escurl); free(url); -} + if (ret != NSERROR_OK) { + return ret; + } -/** - * Ensures output logging stream is correctly configured - */ -static bool nslog_stream_configure(FILE *fptr) -{ - /* set log stream to be non-buffering */ - setbuf(fptr, NULL); + ret = nsurl_create(escurl, url_out); + free(escurl); - return true; + return ret; } -/** Normal entry point from OS */ -int main(int argc, char** argv) + +/** + * Create a path from a nsurl using posix file handling. + * + * @parm[in] url The url to encode. + * @param[out] path_out A string containing the result path which should + * be freed by the caller. + * @return NSERROR_OK and the path is written to \a path or error code + * on faliure. + */ +static nserror ro_nsurl_to_path(struct nsurl *url, char **path_out) { - char path[40]; - int length; - char logging_env[2]; - os_var_type type; - int used = -1; /* slightly better with older OSLib versions */ - os_error *error; - nserror ret; + lwc_string *urlpath; + char *unpath; + char *path; + bool match; + lwc_string *scheme; + nserror res; + char *r; - /* Consult NetSurf$Logging environment variable to decide if logging - * is required. */ - error = xos_read_var_val_size("NetSurf$Logging", 0, os_VARTYPE_STRING, - &used, NULL, &type); - if (error != NULL || type != os_VARTYPE_STRING || used != -2) { - verbose_log = true; - } else { - error = xos_read_var_val("NetSurf$Logging", logging_env, - sizeof(logging_env), 0, os_VARTYPE_STRING, - &used, NULL, &type); - if (error != NULL || logging_env[0] != '0') { - verbose_log = true; - } else { - verbose_log = false; - } + if ((url == NULL) || (path_out == NULL)) { + return NSERROR_BAD_PARAMETER; } - /* initialise logging. Not fatal if it fails but not much we - * can do about it either. - */ - nslog_init(nslog_stream_configure, &argc, argv); + scheme = nsurl_get_component(url, NSURL_SCHEME); - /* user options setup */ - ret = nsoption_init(set_defaults, &nsoptions, &nsoptions_default); - if (ret != NSERROR_OK) { - die("Options failed to initialise"); + if (lwc_string_caseless_isequal(scheme, corestring_lwc_file, + &match) != lwc_error_ok) + { + return NSERROR_BAD_PARAMETER; + } + lwc_string_unref(scheme); + if (match == false) { + return NSERROR_BAD_PARAMETER; } - nsoption_read("NetSurf:Choices", NULL); - nsoption_commandline(&argc, argv, NULL); - - /* Choose the interface language to use */ - ro_gui_choose_language(); - /* select language-specific Messages */ - if (((length = snprintf(path, - sizeof(path), - "NetSurf:Resources.%s.Messages", - nsoption_charp(language))) < 0) || - (length >= (int)sizeof(path))) { - die("Failed to locate Messages resource."); + urlpath = nsurl_get_component(url, NSURL_PATH); + if (urlpath == NULL) { + return NSERROR_BAD_PARAMETER; } - /* common initialisation */ - ret = netsurf_init(path); - if (ret != NSERROR_OK) { - die("NetSurf failed to initialise"); + res = url_unescape(lwc_string_data(urlpath), &unpath); + lwc_string_unref(urlpath); + if (res != NSERROR_OK) { + return res; } - artworks_init(); - draw_init(); - sprite_init(); + /* RISC OS path should not be more than 100 characters longer */ + path = malloc(strlen(unpath) + 100); + if (path == NULL) { + free(unpath); + return NSERROR_NOMEM; + } - /* Load some extra RISC OS specific Messages */ - messages_load("NetSurf:Resources.LangNames"); + r = __riscosify(unpath, 0, __RISCOSIFY_NO_SUFFIX, + path, strlen(unpath) + 100, 0); + free(unpath); + if (r == NULL) { + free(path); + return NSERROR_NOMEM; + } - gui_init(argc, argv); + *path_out = path; - gui_init2(argc, argv); + return NSERROR_OK; +} - netsurf_main_loop(); - netsurf_exit(); +/** + * Ensures output logging stream is correctly configured. + */ +static bool nslog_stream_configure(FILE *fptr) +{ + /* set log stream to be non-buffering */ + setbuf(fptr, NULL); - return 0; + return true; } /** * Close down the gui (RISC OS). */ - -void gui_quit(void) +static void gui_quit(void) { urldb_save_cookies(nsoption_charp(cookie_jar)); urldb_save(nsoption_charp(url_save)); @@ -937,237 +1576,9 @@ void gui_quit(void) /** - * Handles a signal - */ - -void ro_gui_signal(int sig) -{ - static const os_error error = { 1, "NetSurf has detected a serious " - "error and must exit. Please submit a bug report, " - "attaching the browser log file." }; - os_colour old_sand, old_glass; - - ro_gui_cleanup(); - - xhourglass_on(); - xhourglass_colours(0x0000ffff, 0x000000ff, &old_sand, &old_glass); - nsoption_dump(stderr, NULL); - /*rufl_dump_state();*/ - -#ifndef __ELF__ - /* save WimpSlot and DA to files if NetSurf$CoreDump exists */ - int used; - xos_read_var_val_size("NetSurf$CoreDump", 0, 0, &used, 0, 0); - if (used) { - int curr_slot; - xwimp_slot_size(-1, -1, &curr_slot, 0, 0); - LOG(("saving WimpSlot, size 0x%x", curr_slot)); - xosfile_save("$.NetSurf_Slot", 0x8000, 0, - (byte *) 0x8000, - (byte *) 0x8000 + curr_slot); - - if (__dynamic_num != -1) { - int size; - byte *base_address; - xosdynamicarea_read(__dynamic_num, &size, - &base_address, 0, 0, 0, 0, 0); - LOG(("saving DA %i, base %p, size 0x%x", - __dynamic_num, - base_address, size)); - xosfile_save("$.NetSurf_DA", - (bits) base_address, 0, - base_address, - base_address + size); - } - } -#else - /* Save WimpSlot and UnixLib managed DAs when UnixEnv$coredump - * defines a coredump directory. */ - _kernel_oserror *err = __unixlib_write_coredump (NULL); - if (err != NULL) - LOG(("Coredump failed: %s", err->errmess)); -#endif - - xhourglass_colours(old_sand, old_glass, 0, 0); - xhourglass_off(); - - __write_backtrace(sig); - - xwimp_report_error_by_category(&error, - wimp_ERROR_BOX_GIVEN_CATEGORY | - wimp_ERROR_BOX_CATEGORY_ERROR << - wimp_ERROR_BOX_CATEGORY_SHIFT, - "NetSurf", "!netsurf", - (osspriteop_area *) 1, "Quit", 0); - xos_cli("Filer_Run <Wimp$ScrapDir>.WWW.NetSurf.Log"); - - _Exit(sig); -} - - -/** - * Ensures the gui exits cleanly. - */ - -void ro_gui_cleanup(void) -{ - ro_gui_buffer_close(); - xhourglass_off(); - /* Uninstall NetSurf-specific fonts */ - xos_cli("FontRemove NetSurf:Resources.Fonts."); -} - - -/** - * Poll the OS for events (RISC OS). - * - * \param active return as soon as possible - */ - -void gui_poll(bool active) -{ - wimp_event_no event; - wimp_block block; - const wimp_poll_flags mask = wimp_MASK_LOSE | wimp_MASK_GAIN | - wimp_SAVE_FP; - os_t track_poll_offset; - - /* Poll wimp. */ - xhourglass_off(); - track_poll_offset = ro_mouse_poll_interval(); - if (active) { - event = wimp_poll(mask, &block, 0); - } else if (sched_active || (track_poll_offset > 0) || - browser_reformat_pending) { - os_t t = os_read_monotonic_time(); - - if (track_poll_offset > 0) - t += track_poll_offset; - else - t += 10; - - if (sched_active && (sched_time - t) < 0) - t = sched_time; - - event = wimp_poll_idle(mask, &block, t, 0); - } else { - event = wimp_poll(wimp_MASK_NULL | mask, &block, 0); - } - - xhourglass_on(); - gui_last_poll = clock(); - ro_gui_handle_event(event, &block); - - /* Only run scheduled callbacks on a null poll - * We cannot do this in the null event handler, as that may be called - * from gui_multitask(). Scheduled callbacks must only be run from the - * top-level. - */ - if (event == wimp_NULL_REASON_CODE) - schedule_run(); - - ro_gui_window_update_boxes(); - - if (browser_reformat_pending && event == wimp_NULL_REASON_CODE) - ro_gui_window_process_reformats(); -} - - -/** - * Process a Wimp_Poll event. - * - * \param event wimp event number - * \param block parameter block - */ - -void ro_gui_handle_event(wimp_event_no event, wimp_block *block) -{ - switch (event) { - case wimp_NULL_REASON_CODE: - ro_gui_throb(); - ro_mouse_poll(); - break; - - case wimp_REDRAW_WINDOW_REQUEST: - ro_gui_wimp_event_redraw_window(&block->redraw); - break; - - case wimp_OPEN_WINDOW_REQUEST: - ro_gui_open_window_request(&block->open); - break; - - case wimp_CLOSE_WINDOW_REQUEST: - ro_gui_close_window_request(&block->close); - break; - - case wimp_POINTER_LEAVING_WINDOW: - ro_mouse_pointer_leaving_window(&block->leaving); - break; - - case wimp_POINTER_ENTERING_WINDOW: - ro_gui_wimp_event_pointer_entering_window(&block->entering); - break; - - case wimp_MOUSE_CLICK: - ro_gui_wimp_event_mouse_click(&block->pointer); - break; - - case wimp_USER_DRAG_BOX: - ro_mouse_drag_end(&block->dragged); - break; - - case wimp_KEY_PRESSED: - ro_gui_keypress(&(block->key)); - break; - - case wimp_MENU_SELECTION: - ro_gui_menu_selection(&(block->selection)); - break; - - /* Scroll requests fall back to a generic handler because we - * might get these events for any window from a scroll-wheel. - */ - - case wimp_SCROLL_REQUEST: - if (!ro_gui_wimp_event_scroll_window(&(block->scroll))) - ro_gui_scroll(&(block->scroll)); - break; - - case wimp_USER_MESSAGE: - case wimp_USER_MESSAGE_RECORDED: - case wimp_USER_MESSAGE_ACKNOWLEDGE: - ro_gui_user_message(event, &(block->message)); - break; - } -} - - -/** - * Handle Open_Window_Request events. - */ - -void ro_gui_open_window_request(wimp_open *open) -{ - os_error *error; - - if (ro_gui_wimp_event_open_window(open)) - return; - - error = xwimp_open_window(open); - if (error) { - LOG(("xwimp_open_window: 0x%x: %s", - error->errnum, error->errmess)); - warn_user("WimpError", error->errmess); - return; - } -} - - -/** * Handle Close_Window_Request events. */ - -void ro_gui_close_window_request(wimp_close *close) +static void ro_gui_close_window_request(wimp_close *close) { if (ro_gui_alt_pressed()) ro_gui_window_close_all(); @@ -1180,9 +1591,8 @@ void ro_gui_close_window_request(wimp_close *close) /** - * Handle Key_Pressed events. + * Handle key press paste callback. */ - static void ro_gui_keypress_cb(void *pw) { wimp_key *key = (wimp_key *) pw; @@ -1199,14 +1609,20 @@ static void ro_gui_keypress_cb(void *pw) free(key); } -void ro_gui_keypress(wimp_key *key) + +/** + * Handle gui keypress. + */ +static void ro_gui_keypress(wimp_key *key) { if (key->c == wimp_KEY_ESCAPE && (gui_current_drag_type == GUI_DRAG_SAVE || gui_current_drag_type == GUI_DRAG_DOWNLOAD_SAVE)) { - /* Allow Escape key to be used for cancelling a drag save - (easier than finding somewhere safe to abort the drag) */ + /* Allow Escape key to be used for cancelling a drag + * save (easier than finding somewhere safe to abort + * the drag) + */ ro_gui_drag_box_cancel(); gui_current_drag_type = GUI_DRAG_NONE; } else if (key->c == 22 /* Ctrl-V */) { @@ -1233,7 +1649,7 @@ void ro_gui_keypress(wimp_key *key) /** * Handle the three User_Message events. */ -void ro_gui_user_message(wimp_event_no event, wimp_message *message) +static void ro_gui_user_message(wimp_event_no event, wimp_message *message) { /* attempt automatic routing */ if (ro_message_handle_message(event, message)) @@ -1263,7 +1679,8 @@ void ro_gui_user_message(wimp_event_no event, wimp_message *message) break; case message_MENUS_DELETED: - ro_gui_menu_closed(); + ro_gui_menu_message_deleted((wimp_message_menus_deleted *) + &message->data); break; case message_CLAIM_ENTITY: @@ -1367,769 +1784,169 @@ void ro_gui_user_message(wimp_event_no event, wimp_message *message) /** - * Ensure that the filename in a data transfer message is NUL terminated - * (some applications, especially BASIC programs use CR) + * Process a Wimp_Poll event. * - * \param message message to be corrected - */ - -void ro_msg_terminate_filename(wimp_full_message_data_xfer *message) -{ - const char *ep = (char*)message + message->size; - char *p = message->file_name; - - if ((size_t)message->size >= sizeof(*message)) - ep = (char*)message + sizeof(*message) - 1; - - while (p < ep && *p >= ' ') p++; - *p = '\0'; -} - - -/** - * Handle Message_DataLoad (file dragged in). + * \param event wimp event number + * \param block parameter block */ - -void ro_msg_dataload(wimp_message *message) +static void ro_gui_handle_event(wimp_event_no event, wimp_block *block) { - int file_type = message->data.data_xfer.file_type; - int tree_file_type = file_type; - char *urltxt = NULL; - char *title = NULL; - struct gui_window *g; - os_error *oserror; - nsurl *url; - nserror error; - - g = ro_gui_window_lookup(message->data.data_xfer.w); - if (g) { - if (ro_gui_window_dataload(g, message)) - return; - } - else { - g = ro_gui_toolbar_lookup(message->data.data_xfer.w); - if (g && ro_gui_toolbar_dataload(g, message)) - return; - } - - switch (file_type) { - case FILETYPE_ACORN_URI: - urltxt = ro_gui_uri_file_parse(message->data.data_xfer.file_name, - &title); - tree_file_type = 0xfaf; - break; - case FILETYPE_ANT_URL: - urltxt = ro_gui_url_file_parse(message->data.data_xfer.file_name); - tree_file_type = 0xfaf; - break; - case FILETYPE_IEURL: - urltxt = ro_gui_ieurl_file_parse(message->data.data_xfer.file_name); - tree_file_type = 0xfaf; + switch (event) { + case wimp_NULL_REASON_CODE: + ro_gui_throb(); + ro_mouse_poll(); break; - case FILETYPE_HTML: - case FILETYPE_JNG: - case FILETYPE_CSS: - case FILETYPE_MNG: - case FILETYPE_GIF: - case FILETYPE_BMP: - case FILETYPE_ICO: - case osfile_TYPE_DRAW: - case FILETYPE_PNG: - case FILETYPE_JPEG: - case osfile_TYPE_SPRITE: - case osfile_TYPE_TEXT: - case FILETYPE_ARTWORKS: - case FILETYPE_SVG: - /* display the actual file */ - urltxt = path_to_url(message->data.data_xfer.file_name); + case wimp_REDRAW_WINDOW_REQUEST: + ro_gui_wimp_event_redraw_window(&block->redraw); break; - default: - return; - } - - if (!urltxt) - /* error has already been reported by one of the - * functions called above */ - return; - - - error = nsurl_create(urltxt, &url); - if (error == NSERROR_OK) { - if (g) { - error = browser_window_navigate(g->bw, - url, - NULL, - BROWSER_WINDOW_HISTORY | - BROWSER_WINDOW_VERIFIABLE, - NULL, - NULL, - NULL); - -#ifdef DROPURLHOTLIST /** @todo This was commented out should it be removed? */ - } else if (ro_gui_hotlist_check_window( - message->data.data_xfer.w)) { - /* Drop URL into hotlist */ - ro_gui_hotlist_url_drop(message, urltxt); -#endif - } else { - error = browser_window_create( - BROWSER_WINDOW_VERIFIABLE | - BROWSER_WINDOW_HISTORY, - url, - NULL, - NULL, - NULL); - } - nsurl_unref(url); - } - if (error != NSERROR_OK) { - warn_user(messages_get_errorcode(error), 0); - } - - free(urltxt); - - /* send DataLoadAck */ - message->action = message_DATA_LOAD_ACK; - message->your_ref = message->my_ref; - oserror = xwimp_send_message(wimp_USER_MESSAGE, message, - message->sender); - if (oserror) { - LOG(("xwimp_send_message: 0x%x: %s", - oserror->errnum, oserror->errmess)); - warn_user("WimpError", oserror->errmess); - return; - } - -} - - -/** - * Parse an Acorn URI file. - * - * \param file_name file to read - * \param uri_title pointer to receive title data, or NULL for no data - * \return URL from file, or 0 on error and error reported - */ - -char *ro_gui_uri_file_parse(const char *file_name, char **uri_title) -{ - /* See the "Acorn URI Handler Functional Specification" for the - * definition of the URI file format. */ - char line[400]; - char *url = NULL; - FILE *fp; - - *uri_title = NULL; - fp = fopen(file_name, "rb"); - if (!fp) { - LOG(("fopen(\"%s\", \"rb\"): %i: %s", - file_name, errno, strerror(errno))); - warn_user("LoadError", strerror(errno)); - return 0; - } - - /* "URI" */ - if (!ro_gui_uri_file_parse_line(fp, line) || strcmp(line, "URI") != 0) - goto uri_syntax_error; - - /* version */ - if (!ro_gui_uri_file_parse_line(fp, line) || - strspn(line, "0123456789") != strlen(line)) - goto uri_syntax_error; - - /* URI */ - if (!ro_gui_uri_file_parse_line(fp, line)) - goto uri_syntax_error; - url = strdup(line); - if (!url) { - warn_user("NoMemory", 0); - fclose(fp); - return 0; - } - - /* title */ - if (!ro_gui_uri_file_parse_line(fp, line)) - goto uri_syntax_error; - if (uri_title && line[0] && ((line[0] != '*') || line[1])) { - *uri_title = strdup(line); - if (!*uri_title) /* non-fatal */ - warn_user("NoMemory", 0); - } - fclose(fp); - - return url; - -uri_syntax_error: - fclose(fp); - warn_user("URIError", 0); - return 0; -} - - -/** - * Read a "line" from an Acorn URI file. - * - * \param fp file pointer to read from - * \param b buffer for line, size 400 bytes - * \return true on success, false on EOF - */ - -bool ro_gui_uri_file_parse_line(FILE *fp, char *b) -{ - int c; - unsigned int i = 0; - - c = getc(fp); - if (c == EOF) - return false; - - /* skip comment lines */ - while (c == '#') { - do { c = getc(fp); } while (c != EOF && 32 <= c); - if (c == EOF) - return false; - do { c = getc(fp); } while (c != EOF && c < 32); - if (c == EOF) - return false; - } - - /* read "line" */ - do { - if (i == 399) - return false; - b[i++] = c; - c = getc(fp); - } while (c != EOF && 32 <= c); - - /* skip line ending control characters */ - while (c != EOF && c < 32) - c = getc(fp); - - if (c != EOF) - ungetc(c, fp); - - b[i] = 0; - return true; -} - - -/** - * Parse an ANT URL file. - * - * \param file_name file to read - * \return URL from file, or 0 on error and error reported - */ - -char *ro_gui_url_file_parse(const char *file_name) -{ - char line[400]; - char *url; - FILE *fp; - - fp = fopen(file_name, "r"); - if (!fp) { - LOG(("fopen(\"%s\", \"r\"): %i: %s", - file_name, errno, strerror(errno))); - warn_user("LoadError", strerror(errno)); - return 0; - } - - if (!fgets(line, sizeof line, fp)) { - if (ferror(fp)) { - LOG(("fgets: %i: %s", - errno, strerror(errno))); - warn_user("LoadError", strerror(errno)); - } else - warn_user("LoadError", messages_get("EmptyError")); - fclose(fp); - return 0; - } - - fclose(fp); - - if (line[strlen(line) - 1] == '\n') - line[strlen(line) - 1] = '\0'; - - url = strdup(line); - if (!url) { - warn_user("NoMemory", 0); - return 0; - } - - return url; -} - - -/** - * Parse an IEURL file. - * - * \param file_name file to read - * \return URL from file, or 0 on error and error reported - */ - -char *ro_gui_ieurl_file_parse(const char *file_name) -{ - char line[400]; - char *url = 0; - FILE *fp; - - fp = fopen(file_name, "r"); - if (!fp) { - LOG(("fopen(\"%s\", \"r\"): %i: %s", - file_name, errno, strerror(errno))); - warn_user("LoadError", strerror(errno)); - return 0; - } - - while (fgets(line, sizeof line, fp)) { - if (strncmp(line, "URL=", 4) == 0) { - if (line[strlen(line) - 1] == '\n') - line[strlen(line) - 1] = '\0'; - url = strdup(line + 4); - if (!url) { - fclose(fp); - warn_user("NoMemory", 0); - return 0; - } + case wimp_OPEN_WINDOW_REQUEST: + ro_gui_open_window_request(&block->open); break; - } - } - if (ferror(fp)) { - LOG(("fgets: %i: %s", - errno, strerror(errno))); - warn_user("LoadError", strerror(errno)); - fclose(fp); - return 0; - } - - fclose(fp); - - if (!url) - warn_user("URIError", 0); - - return url; -} - - -/** - * Handle Message_DataSave - */ - -void ro_msg_datasave(wimp_message *message) -{ - wimp_full_message_data_xfer *dataxfer = (wimp_full_message_data_xfer*)message; - - /* remove ghost caret if drag-and-drop protocol was used */ -// ro_gui_selection_drag_reset(); - - ro_msg_terminate_filename(dataxfer); - if (ro_gui_selection_prepare_paste_datasave(dataxfer)) - return; - - switch (dataxfer->file_type) { - case FILETYPE_ACORN_URI: - case FILETYPE_ANT_URL: - case FILETYPE_IEURL: - case FILETYPE_HTML: - case FILETYPE_JNG: - case FILETYPE_CSS: - case FILETYPE_MNG: - case FILETYPE_GIF: - case FILETYPE_BMP: - case FILETYPE_ICO: - case osfile_TYPE_DRAW: - case FILETYPE_PNG: - case FILETYPE_JPEG: - case osfile_TYPE_SPRITE: - case osfile_TYPE_TEXT: - case FILETYPE_ARTWORKS: - case FILETYPE_SVG: { - os_error *error; - - dataxfer->your_ref = dataxfer->my_ref; - dataxfer->size = offsetof(wimp_full_message_data_xfer, file_name) + 16; - dataxfer->action = message_DATA_SAVE_ACK; - dataxfer->est_size = -1; - memcpy(dataxfer->file_name, "<Wimp$Scrap>", 13); + case wimp_CLOSE_WINDOW_REQUEST: + ro_gui_close_window_request(&block->close); + break; - error = xwimp_send_message(wimp_USER_MESSAGE, (wimp_message*)dataxfer, message->sender); - if (error) { - LOG(("xwimp_send_message: 0x%x: %s", error->errnum, error->errmess)); - warn_user("WimpError", error->errmess); - } - } - break; - } -} + case wimp_POINTER_LEAVING_WINDOW: + ro_mouse_pointer_leaving_window(&block->leaving); + break; + case wimp_POINTER_ENTERING_WINDOW: + ro_gui_wimp_event_pointer_entering_window(&block->entering); + break; -/** - * Handle Message_DataSaveAck. - */ + case wimp_MOUSE_CLICK: + ro_gui_wimp_event_mouse_click(&block->pointer); + break; -void ro_msg_datasave_ack(wimp_message *message) -{ - ro_msg_terminate_filename((wimp_full_message_data_xfer*)message); + case wimp_USER_DRAG_BOX: + ro_mouse_drag_end(&block->dragged); + break; - if (ro_print_ack(message)) - return; + case wimp_KEY_PRESSED: + ro_gui_keypress(&(block->key)); + break; - switch (gui_current_drag_type) { - case GUI_DRAG_DOWNLOAD_SAVE: - ro_gui_download_datasave_ack(message); + case wimp_MENU_SELECTION: + ro_gui_menu_selection(&(block->selection)); break; - case GUI_DRAG_SAVE: - ro_gui_save_datasave_ack(message); - gui_current_drag_type = GUI_DRAG_NONE; + /* Scroll requests fall back to a generic handler because we + * might get these events for any window from a scroll-wheel. + */ + + case wimp_SCROLL_REQUEST: + if (!ro_gui_wimp_event_scroll_window(&(block->scroll))) + ro_gui_scroll(&(block->scroll)); break; - default: + case wimp_USER_MESSAGE: + case wimp_USER_MESSAGE_RECORDED: + case wimp_USER_MESSAGE_ACKNOWLEDGE: + ro_gui_user_message(event, &(block->message)); break; } - - gui_current_drag_type = GUI_DRAG_NONE; } /** - * Handle Message_DataOpen (double-click on file in the Filer). + * Poll the RISC OS wimp for events. */ - -void ro_msg_dataopen(wimp_message *message) +static void riscos_poll(bool active) { - int file_type = message->data.data_xfer.file_type; - char *url = 0; - size_t len; - os_error *oserror; - nsurl *urlns; - nserror error; + wimp_event_no event; + wimp_block block; + const wimp_poll_flags mask = wimp_MASK_LOSE | wimp_MASK_GAIN | wimp_SAVE_FP; + os_t track_poll_offset; - if (file_type == 0xb28) /* ANT URL file */ - url = ro_gui_url_file_parse(message->data.data_xfer.file_name); - else if (file_type == 0xfaf) /* HTML file */ - url = path_to_url(message->data.data_xfer.file_name); - else if (file_type == 0x1ba) /* IEURL file */ - url = ro_gui_ieurl_file_parse(message-> - data.data_xfer.file_name); - else if (file_type == 0x2000) { /* application */ - len = strlen(message->data.data_xfer.file_name); - if (len < 9 || strcmp(".!NetSurf", - message->data.data_xfer.file_name + len - 9)) - return; - if (nsoption_charp(homepage_url) && - nsoption_charp(homepage_url)[0]) { - url = strdup(nsoption_charp(homepage_url)); + /* Poll wimp. */ + xhourglass_off(); + track_poll_offset = ro_mouse_poll_interval(); + if (sched_active || (track_poll_offset > 0)) { + os_t t = os_read_monotonic_time(); + + if (track_poll_offset > 0) { + t += track_poll_offset; } else { - url = strdup(NETSURF_HOMEPAGE); + t += 10; } - if (!url) - warn_user("NoMemory", 0); - } else - return; - - /* send DataLoadAck */ - message->action = message_DATA_LOAD_ACK; - message->your_ref = message->my_ref; - oserror = xwimp_send_message(wimp_USER_MESSAGE, message, message->sender); - if (oserror) { - LOG(("xwimp_send_message: 0x%x: %s", - oserror->errnum, oserror->errmess)); - warn_user("WimpError", oserror->errmess); - return; - } - - if (!url) - /* error has already been reported by one of the - * functions called above */ - return; - - error = nsurl_create(url, &urlns); - free(url); - if (error == NSERROR_OK) { - /* create a new window with the file */ - error = browser_window_create(BROWSER_WINDOW_VERIFIABLE | - BROWSER_WINDOW_HISTORY, - urlns, - NULL, - NULL, - NULL); - nsurl_unref(urlns); - } - if (error != NSERROR_OK) { - warn_user(messages_get_errorcode(error), 0); - } -} - -/** - * Handle PreQuit message - * - * \param message PreQuit message from Wimp - */ - -void ro_msg_prequit(wimp_message *message) -{ - if (!ro_gui_prequit()) { - os_error *error; - - /* we're objecting to the close down */ - message->your_ref = message->my_ref; - error = xwimp_send_message(wimp_USER_MESSAGE_ACKNOWLEDGE, - message, message->sender); - if (error) { - LOG(("xwimp_send_message: 0x%x:%s", error->errnum, error->errmess)); - warn_user("WimpError", error->errmess); + if (sched_active && (sched_time - t) < 0) { + t = sched_time; } - } -} - - -/** - * Handle SaveDesktop message - * - * \param message SaveDesktop message from Wimp - */ -void ro_msg_save_desktop(wimp_message *message) -{ - os_error *error; - - error = xosgbpb_writew(message->data.save_desktopw.file, - (const byte*)"Run ", 4, NULL); - if (!error) { - error = xosgbpb_writew(message->data.save_desktopw.file, - (const byte*)NETSURF_DIR, strlen(NETSURF_DIR), NULL); - if (!error) - error = xos_bputw('\n', message->data.save_desktopw.file); + event = wimp_poll_idle(mask, &block, t, 0); + } else { + event = wimp_poll(wimp_MASK_NULL | mask, &block, 0); } - if (error) { - LOG(("xosgbpb_writew/xos_bputw: 0x%x:%s", error->errnum, error->errmess)); - warn_user("SaveError", error->errmess); + xhourglass_on(); + gui_last_poll = clock(); + ro_gui_handle_event(event, &block); - /* we must cancel the save by acknowledging the message */ - message->your_ref = message->my_ref; - error = xwimp_send_message(wimp_USER_MESSAGE_ACKNOWLEDGE, - message, message->sender); - if (error) { - LOG(("xwimp_send_message: 0x%x:%s", error->errnum, error->errmess)); - warn_user("WimpError", error->errmess); - } + /* Only run scheduled callbacks on a null poll + * We cannot do this in the null event handler, as that may be called + * from gui_multitask(). Scheduled callbacks must only be run from the + * top-level. + */ + if (event == wimp_NULL_REASON_CODE) { + schedule_run(); } -} - -/** - * Handle WindowInfo message (part of the iconising protocol) - * - * \param message WindowInfo message from the Iconiser - */ - -void ro_msg_window_info(wimp_message *message) -{ - wimp_full_message_window_info *wi; - struct gui_window *g; - - /* allow the user to turn off thumbnail icons */ - if (!nsoption_bool(thumbnail_iconise)) - return; - - wi = (wimp_full_message_window_info*)message; - g = ro_gui_window_lookup(wi->w); - - /* ic_<task name> will suffice for our other windows */ - if (g) { - ro_gui_window_iconise(g, wi); - ro_gui_dialog_close_persistent(wi->w); - } + ro_gui_window_update_boxes(); } /** - * Convert a RISC OS pathname to a file: URL. - * - * \param path RISC OS pathname - * \return URL, allocated on heap, or 0 on failure + * Handle Open_Window_Request events. */ - -char *path_to_url(const char *path) +void ro_gui_open_window_request(wimp_open *open) { - int spare; - char *canonical_path; /* canonicalised RISC OS path */ - char *unix_path; /* unix path */ - char *escurl; os_error *error; - url_func_result url_err; - int urllen; - char *url; /* resulting url */ - /* calculate the canonical risc os path */ - error = xosfscontrol_canonicalise_path(path, 0, 0, 0, 0, &spare); - if (error) { - LOG(("xosfscontrol_canonicalise_path failed: 0x%x: %s", - error->errnum, error->errmess)); - warn_user("PathToURL", error->errmess); - return NULL; - } - - canonical_path = malloc(1 - spare); - if (canonical_path == NULL) { - LOG(("malloc failed")); - warn_user("NoMemory", 0); - free(canonical_path); - return NULL; - } + if (ro_gui_wimp_event_open_window(open)) + return; - error = xosfscontrol_canonicalise_path(path, canonical_path, 0, 0, 1 - spare, 0); + error = xwimp_open_window(open); if (error) { - LOG(("xosfscontrol_canonicalise_path failed: 0x%x: %s", + LOG(("xwimp_open_window: 0x%x: %s", error->errnum, error->errmess)); - warn_user("PathToURL", error->errmess); - free(canonical_path); - return NULL; - } - - /* create a unix path from teh cananocal risc os one */ - unix_path = __unixify(canonical_path, __RISCOSIFY_NO_REVERSE_SUFFIX, NULL, 0, 0); - - if (unix_path == NULL) { - LOG(("__unixify failed: %s", canonical_path)); - free(canonical_path); - return NULL; - } - free(canonical_path); - - /* convert the unix path into a url */ - urllen = strlen(unix_path) + FILE_SCHEME_PREFIX_LEN + 1; - url = malloc(urllen); - if (url == NULL) { - LOG(("Unable to allocate url")); - free(unix_path); - return NULL; - } - - if (*unix_path == '/') { - snprintf(url, urllen, "%s%s", FILE_SCHEME_PREFIX, unix_path + 1); - } else { - snprintf(url, urllen, "%s%s", FILE_SCHEME_PREFIX, unix_path); - } - free(unix_path); - - /* We don't want '/' to be escaped. */ - url_err = url_escape(url, FILE_SCHEME_PREFIX_LEN, false, "/", &escurl); - free(url); url = NULL; - if (url_err != URL_FUNC_OK) { - LOG(("url_escape failed: %s", url)); - return NULL; + warn_user("WimpError", error->errmess); + return; } - - return escurl; } /** - * Convert a file: URL to a RISC OS pathname. - * - * \param url a file: URL - * \return RISC OS pathname, allocated on heap, or 0 on failure + * source bounce callback. */ - -char *url_to_path(const char *url) +static void ro_gui_view_source_bounce(wimp_message *message) { - char *path; char *filename; - char *respath; - url_func_result res; /* result from url routines */ - char *r; - - res = url_path(url, &path); - if (res != URL_FUNC_OK) { - warn_user("NoMemory", 0); - return NULL; - } - - res = url_unescape(path, &respath); - free(path); - if (res != URL_FUNC_OK) { - return NULL; - } - - /* RISC OS path should not be more than 100 characters longer */ - filename = malloc(strlen(respath) + 100); - if (!filename) { - free(respath); - warn_user("NoMemory", 0); - return NULL; - } - - r = __riscosify(respath, 0, __RISCOSIFY_NO_SUFFIX, - filename, strlen(respath) + 100, 0); - - free(respath); - if (r == 0) { - free(filename); - LOG(("__riscosify failed")); - return NULL; - } - - return filename; -} - - -/** - * Get screen properties following a mode change. - */ - -void ro_gui_get_screen_properties(void) -{ - static const ns_os_vdu_var_list vars = { - os_MODEVAR_XWIND_LIMIT, - { - os_MODEVAR_YWIND_LIMIT, - os_MODEVAR_XEIG_FACTOR, - os_MODEVAR_YEIG_FACTOR, - os_VDUVAR_END_LIST - } - }; os_error *error; - int vals[4]; + char command[256]; - error = xos_read_vdu_variables(PTR_OS_VDU_VAR_LIST(&vars), vals); + /* run the file as text */ + filename = ((wimp_full_message_data_xfer *)message)->file_name; + sprintf(command, "@RunType_FFF %s", filename); + error = xwimp_start_task(command, 0); if (error) { - LOG(("xos_read_vdu_variables: 0x%x: %s", - error->errnum, error->errmess)); - warn_user("MiscError", error->errmess); - return; + LOG(("xwimp_start_task failed: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); } - screen_info.width = (vals[0] + 1) << vals[2]; - screen_info.height = (vals[1] + 1) << vals[3]; -} - - -/** - * Find screen size in OS units. - */ - -void ro_gui_screen_size(int *width, int *height) -{ - *width = screen_info.width; - *height = screen_info.height; } /** * Send the source of a content to a text editor. */ - void ro_gui_view_source(hlcache_handle *c) { os_error *error; - char full_name[256]; - char *temp_name, *r; + char *temp_name; wimp_full_message_data_xfer message; int objtype; bool done = false; @@ -2150,8 +1967,7 @@ void ro_gui_view_source(hlcache_handle *c) } /* try to load local files directly. */ - temp_name = url_to_path(nsurl_access(hlcache_handle_get_url(c))); - if (temp_name) { + if (netsurf_nsurl_to_path(hlcache_handle_get_url(c), &temp_name) == NSERROR_OK) { error = xosfile_read_no_path(temp_name, &objtype, 0, 0, 0, 0); if ((!error) && (objtype == osfile_IS_FILE)) { snprintf(message.file_name, 212, "%s", temp_name); @@ -2167,11 +1983,14 @@ void ro_gui_view_source(hlcache_handle *c) * allow it to be re-used next time NetSurf is started. The * memory overhead from doing this is under 1 byte per * filename. */ + char *r; + char full_name[256]; const char *filename = filename_request(); if (!filename) { warn_user("NoMemory", 0); return; } + snprintf(full_name, 256, "%s/%s", TEMP_FILENAME_PREFIX, filename); full_name[255] = '\0'; @@ -2182,6 +2001,7 @@ void ro_gui_view_source(hlcache_handle *c) return; } message.file_name[211] = '\0'; + error = xosfile_save_stamped(message.file_name, ro_content_filetype(c), (byte *) source_data, @@ -2210,63 +2030,43 @@ void ro_gui_view_source(hlcache_handle *c) } -void ro_gui_view_source_bounce(wimp_message *message) +/** + * Broadcast an URL that we can't handle. + */ +static nserror gui_launch_url(struct nsurl *url) { - char *filename; - os_error *error; - char command[256]; - - /* run the file as text */ - filename = ((wimp_full_message_data_xfer *)message)->file_name; - sprintf(command, "@RunType_FFF %s", filename); - error = xwimp_start_task(command, 0); - if (error) { - LOG(("xwimp_start_task failed: 0x%x: %s", - error->errnum, error->errmess)); - warn_user("WimpError", error->errmess); - } + /* Try ant broadcast */ + ro_url_broadcast(nsurl_access(url)); + return NSERROR_OK; } /** - * Send the debug dump of a content to a text editor. + * Choose the language to use. */ - -void ro_gui_dump_browser_window(struct browser_window *bw) +static void ro_gui_choose_language(void) { - os_error *error; - - /* open file for dump */ - FILE *stream = fopen("<Wimp$ScrapDir>.WWW.NetSurf.dump", "w"); - if (!stream) { - LOG(("fopen: errno %i", errno)); - warn_user("SaveError", strerror(errno)); - return; - } - - browser_window_debug_dump(bw, stream); - - fclose(stream); + /* if option_language exists and is valid, use that */ + if (nsoption_charp(language)) { + char path[40]; + if (2 < strlen(nsoption_charp(language))) + nsoption_charp(language)[2] = 0; + sprintf(path, "NetSurf:Resources.%s", nsoption_charp(language)); - /* launch file in editor */ - error = xwimp_start_task("Filer_Run <Wimp$ScrapDir>.WWW.NetSurf.dump", - 0); - if (error) { - LOG(("xwimp_start_task failed: 0x%x: %s", - error->errnum, error->errmess)); - warn_user("WimpError", error->errmess); + if (is_dir(path)) { + nsoption_setnull_charp(accept_language, + strdup(nsoption_charp(language))); + return; + } + nsoption_set_charp(language, NULL); } -} - -/** - * Broadcast an URL that we can't handle. - */ - -void gui_launch_url(const char *url) -{ - /* Try ant broadcast first */ - ro_url_broadcast(url); + nsoption_set_charp(language, strdup(ro_gui_default_language())); + if (nsoption_charp(language) == NULL) + die("Out of memory"); + nsoption_set_charp(accept_language, strdup(nsoption_charp(language))); + if (nsoption_charp(accept_language) == NULL) + die("Out of memory"); } @@ -2276,7 +2076,6 @@ void gui_launch_url(const char *url) * \param warning message key for warning message * \param detail additional message, or 0 */ - void warn_user(const char *warning, const char *detail) { LOG(("%s %s", warning, detail)); @@ -2318,7 +2117,6 @@ void warn_user(const char *warning, const char *detail) * * Should only be used during initialisation. */ - void die(const char * const error) { os_error warn_error; @@ -2345,81 +2143,390 @@ void die(const char * const error) * * \return true iff it's okay to shutdown immediately */ - bool ro_gui_prequit(void) { return ro_gui_download_prequit(); } + void PDF_Password(char **owner_pass, char **user_pass, char *path) { - /*TODO:this waits to be written, until then no PDF encryption*/ + /** @todo this waits to be written, until then no PDF encryption */ *owner_pass = NULL; } + /** - * Return the filename part of a full path + * Generate a riscos path from one or more component elemnts. + * + * Constructs a complete path element from passed components. The + * second (and subsequent) components have a slash substituted for all + * riscos directory separators. * - * \param path full path and filename - * \return filename (will be freed with free()) + * If a string is allocated it must be freed by the caller. + * + * @param[in,out] str pointer to string pointer if this is NULL enough + * storage will be allocated for the complete path. + * @param[in,out] size The size of the space available if \a str not + * NULL on input and if not NULL set to the total + * output length on output. + * @param[in] nemb The number of elements. + * @param[in] ap The elements of the path as string pointers. + * @return NSERROR_OK and the complete path is written to str + * or error code on faliure. */ +static nserror riscos_mkpath(char **str, size_t *size, size_t nelm, va_list ap) +{ + const char *elm[16]; + size_t elm_len[16]; + size_t elm_idx; + char *fname; + size_t fname_len = 0; + char *curp; + size_t idx; + + /* check the parameters are all sensible */ + if ((nelm == 0) || (nelm > 16)) { + return NSERROR_BAD_PARAMETER; + } + if ((*str != NULL) && (size == NULL)) { + /* if the caller is providing the buffer they must say + * how much space is available. + */ + return NSERROR_BAD_PARAMETER; + } + + /* calculate how much storage we need for the complete path + * with all the elements. + */ + for (elm_idx = 0; elm_idx < nelm; elm_idx++) { + elm[elm_idx] = va_arg(ap, const char *); + /* check the argument is not NULL */ + if (elm[elm_idx] == NULL) { + return NSERROR_BAD_PARAMETER; + } + elm_len[elm_idx] = strlen(elm[elm_idx]); + fname_len += elm_len[elm_idx]; + } + fname_len += nelm; /* allow for separators and terminator */ + + /* ensure there is enough space */ + fname = *str; + if (fname != NULL) { + if (fname_len > *size) { + return NSERROR_NOSPACE; + } + } else { + fname = malloc(fname_len); + if (fname == NULL) { + return NSERROR_NOMEM; + } + } + + /* copy the elements in with directory separator */ + curp = fname; -char *filename_from_path(char *path) + /* first element is not altered */ + memmove(curp, elm[0], elm_len[0]); + curp += elm_len[0]; + /* ensure there is a delimiter */ + if (curp[-1] != DIR_SEP) { + *curp = DIR_SEP; + curp++; + } + + /* subsequent elemnts have slashes substituted with directory + * separators. + */ + for (elm_idx = 1; elm_idx < nelm; elm_idx++) { + for (idx = 0; idx < elm_len[elm_idx]; idx++) { + if (elm[elm_idx][idx] == DIR_SEP) { + *curp = '/'; + } else { + *curp = elm[elm_idx][idx]; + } + curp++; + } + *curp = DIR_SEP; + curp++; + } + curp[-1] = 0; /* NULL terminate */ + + assert((curp - fname) <= (int)fname_len); + + *str = fname; + if (size != NULL) { + *size = fname_len; + } + + return NSERROR_OK; + +} + + +/** + * Get the basename of a file using posix path handling. + * + * This gets the last element of a path and returns it. The returned + * element has all forward slashes translated into riscos directory + * separators. + * + * @param[in] path The path to extract the name from. + * @param[in,out] str Pointer to string pointer if this is NULL enough + * storage will be allocated for the path element. + * @param[in,out] size The size of the space available if \a + * str not NULL on input and set to the total + * output length on output. + * @return NSERROR_OK and the complete path is written to str + * or error code on faliure. + */ +static nserror riscos_basename(const char *path, char **str, size_t *size) { - char *leafname; + const char *leafname; + char *fname; char *temp; - int leaflen; - - temp = strrchr(path, '.'); - if (!temp) - temp = path; /* already leafname */ - else - temp += 1; - leaflen = strlen(temp); + if (path == NULL) { + return NSERROR_BAD_PARAMETER; + } - leafname = malloc(leaflen + 1); + leafname = strrchr(path, DIR_SEP); if (!leafname) { - LOG(("malloc failed")); - return NULL; + leafname = path; + } else { + leafname += 1; + } + + fname = strdup(leafname); + if (fname == NULL) { + return NSERROR_NOMEM; } - memcpy(leafname, temp, leaflen + 1); + /** @todo check this leafname translation is actually required */ /* and s/\//\./g */ - for (temp = leafname; *temp; temp++) - if (*temp == '/') - *temp = '.'; + for (temp = fname; *temp != 0; temp++) { + if (*temp == '/') { + *temp = DIR_SEP; + } + } - return leafname; + *str = fname; + if (size != NULL) { + *size = strlen(fname); + } + return NSERROR_OK; } + /** - * Add a path component/filename to an existing path + * Ensure that all directory elements needed to store a filename exist. + * + * Given a path of x.y.z directories x and x.y will be created. * - * \param path buffer containing platform-native format path + free space - * \param length length of buffer "path" - * \param newpart string containing unix-format path component to add to path - * \return true on success + * @param fname The filename to ensure the path to exists. + * @return NSERROR_OK on success or error code on failure. */ +static nserror riscos_mkdir_all(const char *fname) +{ + char *dname; + char *cur; + + dname = strdup(fname); -bool path_add_part(char *path, int length, const char *newpart) + cur = dname; + while ((cur = strchr(cur, '.'))) { + *cur = '\0'; + xosfile_create_dir(dname, 0); + *cur++ = '.'; + } + + free(dname); + + return NSERROR_OK; +} + +/** + * Find screen size in OS units. + */ +void ro_gui_screen_size(int *width, int *height) { - size_t path_len = strlen(path); + *width = screen_info.width; + *height = screen_info.height; +} - /* Append directory separator, if there isn't one */ - if (path[path_len - 1] != '.') { - strncat(path, ".", length); - path_len += 1; + +/** + * Send the debug dump of a content to a text editor. + */ +void ro_gui_dump_browser_window(struct browser_window *bw) +{ + os_error *error; + + /* open file for dump */ + FILE *stream = fopen("<Wimp$ScrapDir>.WWW.NetSurf.dump", "w"); + if (!stream) { + LOG(("fopen: errno %i", errno)); + warn_user("SaveError", strerror(errno)); + return; } - strncat(path, newpart, length); + browser_window_debug_dump(bw, stream, CONTENT_DEBUG_RENDER); + + fclose(stream); - /* Newpart is either a directory name, or a file leafname - * Either way, we must replace all dots with forward slashes */ - for (path = path + path_len; *path; path++) { - if (*path == '.') - *path = '/'; + /* launch file in editor */ + error = xwimp_start_task("Filer_Run <Wimp$ScrapDir>.WWW.NetSurf.dump", + 0); + if (error) { + LOG(("xwimp_start_task failed: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); } +} - return true; + +static struct gui_file_table riscos_file_table = { + .mkpath = riscos_mkpath, + .basename = riscos_basename, + .nsurl_to_path = ro_nsurl_to_path, + .path_to_nsurl = ro_path_to_nsurl, + .mkdir_all = riscos_mkdir_all, +}; + +static struct gui_fetch_table riscos_fetch_table = { + .filetype = fetch_filetype, + + .get_resource_url = gui_get_resource_url, + .mimetype = fetch_mimetype, +}; + +static struct gui_browser_table riscos_browser_table = { + .poll = riscos_poll, + .schedule = riscos_schedule, + + .quit = gui_quit, + .launch_url = gui_launch_url, + .create_form_select_menu = gui_create_form_select_menu, + .cert_verify = gui_cert_verify, + .login = gui_401login_open, +}; + + +static char *get_cachepath(void) +{ + char *cachedir; + char *cachepath = NULL; + nserror ret; + + cachedir = getenv("Cache$Dir"); + if ((cachedir == NULL) || (cachedir[0] == 0)) { + LOG(("cachedir was null")); + return NULL; + } + ret = netsurf_mkpath(&cachepath, NULL, 2, cachedir, "NetSurf"); + if (ret != NSERROR_OK) { + return NULL; + } + return cachepath; +} + +/** + * Normal entry point from RISC OS. + */ +int main(int argc, char** argv) +{ + char *cachepath; + char path[40]; + int length; + os_var_type type; + int used = -1; /* slightly better with older OSLib versions */ + os_error *error; + nserror ret; + struct netsurf_table riscos_table = { + .browser = &riscos_browser_table, + .window = riscos_window_table, + .clipboard = riscos_clipboard_table, + .download = riscos_download_table, + .fetch = &riscos_fetch_table, + .file = &riscos_file_table, + .utf8 = riscos_utf8_table, + .search = riscos_search_table, + .llcache = filesystem_llcache_table, + }; + + ret = netsurf_register(&riscos_table); + if (ret != NSERROR_OK) { + die("NetSurf operation table failed registration"); + } + + /* Consult NetSurf$Logging environment variable to decide if logging + * is required. */ + error = xos_read_var_val_size("NetSurf$Logging", 0, os_VARTYPE_STRING, + &used, NULL, &type); + if (error != NULL || type != os_VARTYPE_STRING || used != -2) { + verbose_log = true; + } else { + char logging_env[2]; + error = xos_read_var_val("NetSurf$Logging", logging_env, + sizeof(logging_env), 0, os_VARTYPE_STRING, + &used, NULL, &type); + if (error != NULL || logging_env[0] != '0') { + verbose_log = true; + } else { + verbose_log = false; + } + } + + /* initialise logging. Not fatal if it fails but not much we + * can do about it either. + */ + nslog_init(nslog_stream_configure, &argc, argv); + + /* user options setup */ + ret = nsoption_init(set_defaults, &nsoptions, &nsoptions_default); + if (ret != NSERROR_OK) { + die("Options failed to initialise"); + } + nsoption_read("NetSurf:Choices", NULL); + nsoption_commandline(&argc, argv, NULL); + + /* Choose the interface language to use */ + ro_gui_choose_language(); + + /* select language-specific Messages */ + if (((length = snprintf(path, + sizeof(path), + "NetSurf:Resources.%s.Messages", + nsoption_charp(language))) < 0) || + (length >= (int)sizeof(path))) { + die("Failed to locate Messages resource."); + } + + /* obtain cache path */ + cachepath = get_cachepath(); + + /* common initialisation */ + ret = netsurf_init(path, cachepath); + free(cachepath); + if (ret != NSERROR_OK) { + die("NetSurf failed to initialise core"); + } + + artworks_init(); + draw_init(); + sprite_init(); + + /* Load some extra RISC OS specific Messages */ + messages_load("NetSurf:Resources.LangNames"); + + ret = gui_init(argc, argv); + if (ret != NSERROR_OK) { + warn_user(messages_get_errorcode(ret), 0); + } + + netsurf_main_loop(); + + netsurf_exit(); + + return 0; } diff --git a/riscos/gui.h b/riscos/gui.h index 827af8108..3403f551e 100644 --- a/riscos/gui.h +++ b/riscos/gui.h @@ -21,20 +21,17 @@ #ifndef _NETSURF_RISCOS_GUI_H_ #define _NETSURF_RISCOS_GUI_H_ -#include <stdbool.h> -#include <stdlib.h> -#include "oslib/osspriteop.h" -#include "oslib/wimp.h" -#include "rufl.h" -#include "desktop/browser.h" -#include "content/content_type.h" -#include "utils/config.h" +#include <oslib/wimp.h> #define RISCOS5 0xAA #define THUMBNAIL_WIDTH 100 #define THUMBNAIL_HEIGHT 86 +/* The maximum size for user-editable URLs in the RISC OS GUI. */ + +#define RO_GUI_MAX_URL_SIZE 2048 + extern int os_version; extern const char * NETSURF_DIR; @@ -47,6 +44,11 @@ struct tree; struct node; struct history; struct css_style; +struct ssl_cert_info; +struct nsurl; +struct hlcache_handle; + +enum gui_pointer_shape; extern wimp_t task_handle; /**< RISC OS wimp task handle. */ @@ -70,12 +72,6 @@ typedef enum { GUI_DRAG_NONE, GUI_DRAG_DOWNLOAD_SAVE, GUI_DRAG_SAVE } extern ro_gui_drag_type gui_current_drag_type; -/** desktop font, size and style being used */ -extern char ro_gui_desktop_font_family[]; -extern int ro_gui_desktop_font_size; -extern rufl_style ro_gui_desktop_font_style; - - /** RISC OS data for a browser window. */ struct gui_window { /** Associated platform-independent browser window data. */ @@ -123,9 +119,12 @@ const char *ro_gui_default_language(void); void ro_gui_download_init(void); void ro_gui_download_datasave_ack(wimp_message *message); bool ro_gui_download_prequit(void); +extern struct gui_download_table *riscos_download_table; /* in 401login.c */ void ro_gui_401login_init(void); +void gui_401login_open(struct nsurl *url, const char *realm, + nserror (*cb)(bool proceed, void *pw), void *cbpw); /* in window.c */ bool ro_gui_window_dataload(struct gui_window *g, wimp_message *message); @@ -135,7 +134,6 @@ void ro_gui_window_iconise(struct gui_window *g, bool ro_gui_toolbar_dataload(struct gui_window *g, wimp_message *message); void ro_gui_window_redraw_all(void); void ro_gui_window_update_boxes(void); -void ro_gui_window_process_reformats(void); void ro_gui_window_quit(void); /* void ro_gui_window_close_all(void); */ #define ro_gui_window_close_all ro_gui_window_quit /* no need for a separate fn */ @@ -147,50 +145,50 @@ bool ro_gui_window_to_window_pos(struct gui_window *g, int x, int y, os_coord *pos); bool ro_gui_window_to_screen_pos(struct gui_window *g, int x, int y, os_coord *pos); -browser_mouse_state ro_gui_mouse_click_state(wimp_mouse_state buttons, +enum browser_mouse_state ro_gui_mouse_click_state(wimp_mouse_state buttons, wimp_icon_flags type); -browser_mouse_state ro_gui_mouse_drag_state(wimp_mouse_state buttons, +enum browser_mouse_state ro_gui_mouse_drag_state(wimp_mouse_state buttons, wimp_icon_flags type); bool ro_gui_shift_pressed(void); bool ro_gui_ctrl_pressed(void); bool ro_gui_alt_pressed(void); +void gui_window_set_pointer(struct gui_window *g, enum gui_pointer_shape shape); +void gui_create_form_select_menu(struct browser_window *bw, struct form_control *control); /* in history.c */ void ro_gui_history_init(void); -void ro_gui_history_open(struct browser_window *bw, struct history *history, - bool pointer); - -/* in filetype.c */ -int ro_content_filetype(struct hlcache_handle *c); -int ro_content_native_type(struct hlcache_handle *c); -int ro_content_filetype_from_mime_type(lwc_string *mime_type); -int ro_content_filetype_from_type(content_type type); -bits ro_filetype_from_unix_path(const char *unix_path); +void ro_gui_history_open(struct gui_window *g, bool pointer); /* in schedule.c */ extern bool sched_active; extern os_t sched_time; + +/** + * Process events up to current time. + */ bool schedule_run(void); +/** + * Schedule a callback. + * + * \param t interval before the callback should be made in ms + * \param callback callback function + * \param p user parameter, passed to callback function + * + * The callback function will be called as soon as possible after t ms have + * passed. + */ +nserror riscos_schedule(int t, void (*callback)(void *p), void *p); + /* in search.c */ void ro_gui_search_init(void); void ro_gui_search_prepare(struct browser_window *g); +struct gui_search_table *riscos_search_table; /* in print.c */ void ro_gui_print_init(void); void ro_gui_print_prepare(struct gui_window *g); -/* in font.c */ -void nsfont_init(void); -bool nsfont_exists(const char *font_family); -const char *nsfont_fallback_font(void); -bool nsfont_paint(const plot_font_style_t *fstyle, const char *string, - size_t length, int x, int y); -void nsfont_read_style(const plot_font_style_t *fstyle, - const char **font_family, unsigned int *font_size, - rufl_style *font_style); -void ro_gui_wimp_get_desktop_font(void); - /* in plotters.c */ extern const struct plotter_table ro_plotters; extern int ro_plot_origin_x; @@ -199,6 +197,11 @@ extern int ro_plot_origin_y; /* in theme_install.c */ bool ro_gui_theme_install_apply(wimp_w w); +/* in sslcert.c */ +void gui_cert_verify(struct nsurl *url, + const struct ssl_cert_info *certs, unsigned long num, + nserror (*cb)(bool proceed, void *pw), void *cbpw); + /* icon numbers */ #define ICON_STATUS_RESIZE 0 #define ICON_STATUS_TEXT 1 diff --git a/riscos/gui/button_bar.c b/riscos/gui/button_bar.c index 7ca67f165..d92433d0b 100644 --- a/riscos/gui/button_bar.c +++ b/riscos/gui/button_bar.c @@ -26,18 +26,20 @@ #include <stdbool.h> #include <stdlib.h> #include <string.h> -#include "oslib/dragasprite.h" -#include "oslib/os.h" -#include "oslib/osspriteop.h" -#include "oslib/wimp.h" -#include "oslib/wimpspriteop.h" +#include <oslib/dragasprite.h> +#include <oslib/os.h> +#include <oslib/osspriteop.h> +#include <oslib/wimp.h> +#include <oslib/wimpspriteop.h> + +#include "utils/log.h" +#include "utils/utils.h" + #include "riscos/gui/button_bar.h" #include "riscos/gui.h" #include "riscos/mouse.h" #include "riscos/theme.h" #include "riscos/wimp.h" -#include "utils/log.h" -#include "utils/utils.h" #define BUTTONBAR_SPRITE_NAME_LENGTH 12 #define BUTTONBAR_VALIDATION_LENGTH 40 @@ -131,7 +133,6 @@ struct button_bar *ro_gui_button_bar_create(struct theme_descriptor *theme, { struct button_bar *button_bar; struct button_bar_button *icon, *new_icon; - bool failed; int def; /* Allocate memory. */ @@ -170,12 +171,10 @@ struct button_bar *ro_gui_button_bar_create(struct theme_descriptor *theme, /* Process the button icon definitions */ icon = NULL; - failed = false; for (def = 0; buttons[def].icon != NULL; def++) { new_icon = malloc(sizeof(struct button_bar_button)); if (new_icon == NULL) { - failed = true; break; } @@ -248,7 +247,6 @@ bool ro_gui_button_bar_rebuild(struct button_bar *button_bar, wimp_w window, bool edit) { struct button_bar_button *button; - os_error *error; int height; @@ -276,7 +274,6 @@ bool ro_gui_button_bar_rebuild(struct button_bar *button_bar, button_bar->separators = (height == 0) ? false : true; button = button_bar->buttons; - error = NULL; while (button != NULL) { button->x_size = 0; @@ -488,7 +485,6 @@ bool ro_gui_button_bar_icon_update(struct button_bar *button_bar) wimp_icon_create icon; struct button_bar_button *button, *b; os_error *error; - bool on_bar; if (button_bar == NULL || button_bar->window == NULL) @@ -497,7 +493,7 @@ bool ro_gui_button_bar_icon_update(struct button_bar *button_bar) button = button_bar->buttons; while (button != NULL) { - on_bar = false; + bool on_bar = false; /* Check if the icon is currently on the bar. */ @@ -725,8 +721,6 @@ bool ro_gui_button_bar_click(struct button_bar *button_bar, struct button_bar_button *button; os_coord pos; os_box box; - os_error *error; - char *sprite; if (button_bar == NULL || button_bar->hidden) return false; @@ -751,6 +745,8 @@ bool ro_gui_button_bar_click(struct button_bar *button_bar, if (button != NULL && (!button->shaded || drag_separator || button_bar->edit_source != NULL)) { + char *sprite; + os_error *error; drag_start = button_bar; drag_opt = button->opt_key; @@ -1191,7 +1187,6 @@ struct button_bar_button *ro_gui_button_bar_find_coords( bool *separator, bool *right) { struct button_bar_button *button; - int x0, y0, x1, y1; if (button_bar == NULL) return NULL; @@ -1200,6 +1195,7 @@ struct button_bar_button *ro_gui_button_bar_find_coords( while (button != NULL) { /* Match button extents. */ + int x0, y0, x1, y1; x0 = button_bar->extent.x0 + button->x_pos; y0 = button_bar->extent.y0 + button->y_pos; diff --git a/riscos/gui/progress_bar.c b/riscos/gui/progress_bar.c index 445797611..09b3edb45 100644 --- a/riscos/gui/progress_bar.c +++ b/riscos/gui/progress_bar.c @@ -29,10 +29,11 @@ #include "oslib/osspriteop.h" #include "oslib/wimp.h" #include "oslib/wimpspriteop.h" + #include "desktop/plotters.h" #include "utils/log.h" -#include "utils/schedule.h" #include "utils/utils.h" + #include "riscos/gui.h" #include "riscos/tinct.h" #include "riscos/wimp_event.h" @@ -159,8 +160,9 @@ void ro_gui_progress_bar_destroy(struct progress_bar *pb) os_error *error; assert(pb); - if (pb->animating) - schedule_remove(ro_gui_progress_bar_animate, pb); + if (pb->animating) { + riscos_schedule(-1, ro_gui_progress_bar_animate, pb); + } ro_gui_wimp_event_finalise(pb->w); error = xwimp_delete_window(pb->w); if (error) { @@ -292,12 +294,14 @@ void ro_gui_progress_bar_update(struct progress_bar *pb, int width, int height) /* update the animation state */ if ((pb->value == 0) || (pb->value == pb->range)) { - if (pb->animating) - schedule_remove(ro_gui_progress_bar_animate, pb); + if (pb->animating) { + riscos_schedule(-1, ro_gui_progress_bar_animate, pb); + } pb->animating = false; } else { - if (!pb->animating) - schedule(20, ro_gui_progress_bar_animate, pb); + if (!pb->animating) { + riscos_schedule(200, ro_gui_progress_bar_animate, pb); + } pb->animating = true; } @@ -324,6 +328,11 @@ void ro_gui_progress_bar_update(struct progress_bar *pb, int width, int height) redraw.box = pb->visible; redraw.box.x0 = cur.x1; error = xwimp_update_window(&redraw, &more); + if (error) { + LOG(("Error getting update window: 0x%x: %s", + error->errnum, error->errmess)); + return; + } if (more) ro_gui_progress_bar_redraw_window(&redraw, pb); } @@ -372,12 +381,17 @@ void ro_gui_progress_bar_animate(void *p) if (pb->offset < 0) pb->offset += progress_width * 2; - if (pb->animating) - schedule(20, ro_gui_progress_bar_animate, pb); + if (pb->animating) { + riscos_schedule(200, ro_gui_progress_bar_animate, pb); + } redraw.w = pb->w; redraw.box = pb->visible; error = xwimp_update_window(&redraw, &more); + if (error != NULL) { + LOG(("Error getting update window: '%s'", error->errmess)); + return; + } if (more) ro_gui_progress_bar_redraw_window(&redraw, pb); } @@ -394,9 +408,8 @@ void ro_gui_progress_bar_animate(void *p) void ro_gui_progress_bar_calculate(struct progress_bar *pb, int width, int height) { - os_error *error; int icon_width, icon_height; - int icon_x0 = 0, icon_y0 = 0, progress_x0, progress_x1, progress_ymid = 0; + int icon_x0 = 0, icon_y0 = 0, progress_x0, progress_x1; osspriteop_header *icon = NULL; bool icon_redraw = false; @@ -417,14 +430,17 @@ void ro_gui_progress_bar_calculate(struct progress_bar *pb, int width, /* get the icon information */ if (progress_bar_definition.sprite_area != wimpspriteop_AREA) { - progress_ymid = height / 2; + int progress_ymid = height / 2; + os_error *error; error = xosspriteop_read_sprite_info(osspriteop_USER_AREA, progress_bar_definition.sprite_area, (osspriteop_id)pb->icon, &icon_width, &icon_height, 0, 0); - error = xosspriteop_select_sprite(osspriteop_USER_AREA, - progress_bar_definition.sprite_area, - (osspriteop_id)pb->icon, &icon); + if (!error) { + error = xosspriteop_select_sprite(osspriteop_USER_AREA, + progress_bar_definition.sprite_area, + (osspriteop_id)pb->icon, &icon); + } if (!error) { progress_x0 += 32 + MARGIN; width -= 32 + MARGIN; @@ -467,7 +483,6 @@ void ro_gui_progress_bar_calculate(struct progress_bar *pb, int width, void ro_gui_progress_bar_redraw_window(wimp_draw *redraw, struct progress_bar *pb) { - os_error *error; osbool more = true; struct rect clip; int progress_ymid; @@ -484,6 +499,7 @@ void ro_gui_progress_bar_redraw_window(wimp_draw *redraw, /* redraw the window */ while (more) { + os_error *error; if (pb->icon) _swix(Tinct_PlotAlpha, _IN(2) | _IN(3) | _IN(4) | _IN(7), pb->icon_img, diff --git a/riscos/gui/status_bar.c b/riscos/gui/status_bar.c index 899fe99b6..57a32ae7f 100644 --- a/riscos/gui/status_bar.c +++ b/riscos/gui/status_bar.c @@ -30,12 +30,13 @@ #include "oslib/wimpspriteop.h" #include "desktop/plotters.h" #include "utils/log.h" -#include "utils/schedule.h" #include "utils/utils.h" + #include "riscos/gui.h" #include "riscos/wimp.h" #include "riscos/wimp_event.h" #include "riscos/wimputils.h" +#include "riscos/font.h" #include "riscos/gui/progress_bar.h" #include "riscos/gui/status_bar.h" @@ -171,7 +172,7 @@ void ro_gui_status_bar_destroy(struct status_bar *sb) ro_gui_progress_bar_destroy(sb->pb); /* Remove any scheduled redraw callbacks */ - schedule_remove(ro_gui_status_bar_redraw_callback, (void *) sb); + riscos_schedule(-1, ro_gui_status_bar_redraw_callback, (void *) sb); free(sb); } @@ -213,15 +214,13 @@ unsigned int ro_gui_status_bar_get_width(struct status_bar *sb) */ void ro_gui_status_bar_set_visible(struct status_bar *sb, bool visible) { - os_error *error; - assert(sb); sb->visible = visible; if (visible) { ro_gui_status_bar_resize(sb); } else { - error = xwimp_close_window(sb->w); + os_error *error = xwimp_close_window(sb->w); if (error) { LOG(("xwimp_close_window: 0x%x:%s", error->errnum, error->errmess)); @@ -271,7 +270,6 @@ void ro_gui_status_bar_set_progress_range(struct status_bar *sb, unsigned int range) { unsigned int old_range; - os_error *error; assert(sb); @@ -282,7 +280,7 @@ void ro_gui_status_bar_set_progress_range(struct status_bar *sb, if ((old_range == 0) && (range != 0)) { ro_gui_status_position_progress_bar(sb); } else if ((old_range != 0) && (range == 0)) { - error = xwimp_close_window( + os_error *error = xwimp_close_window( ro_gui_progress_bar_get_window(sb->pb)); if (error) { LOG(("xwimp_close_window: 0x%x:%s", @@ -331,7 +329,7 @@ void ro_gui_status_bar_set_text(struct status_bar *sb, const char *text) * { callback, handle } pair is registered at once. */ if (sb->visible && text != NULL) { - schedule(1, ro_gui_status_bar_redraw_callback, (void *) sb); + riscos_schedule(10, ro_gui_status_bar_redraw_callback, sb); } } @@ -344,9 +342,8 @@ void ro_gui_status_bar_set_text(struct status_bar *sb, const char *text) */ void ro_gui_status_bar_resize(struct status_bar *sb) { - int window_width, window_height; + int window_width; int status_width, status_height; - int redraw_left, redraw_right; wimp_window_state state; os_error *error; os_box extent; @@ -363,7 +360,6 @@ void ro_gui_status_bar_resize(struct status_bar *sb) return; } window_width = state.visible.x1 - state.visible.x0; - window_height = state.visible.y1 - state.visible.y0; /* recalculate the scaled width */ @@ -375,6 +371,8 @@ void ro_gui_status_bar_resize(struct status_bar *sb) /* resize the status/resize icons */ if (status_width != sb->width) { /* update the window extent */ + int redraw_left, redraw_right; + extent.x0 = 0; extent.y0 = 0; extent.x1 = status_width; diff --git a/riscos/gui/throbber.c b/riscos/gui/throbber.c index 05860a923..5e2c87678 100644 --- a/riscos/gui/throbber.c +++ b/riscos/gui/throbber.c @@ -285,12 +285,12 @@ bool ro_gui_throbber_icon_update(struct throbber *throbber) bool ro_gui_throbber_icon_resize(struct throbber *throbber) { - os_error *error; if (throbber->window == NULL) return false; if (throbber->icon != -1) { + os_error *error; error = xwimp_resize_icon(throbber->window, throbber->icon, throbber->extent.x0, throbber->extent.y0, throbber->extent.x1, throbber->extent.y1); diff --git a/riscos/gui/url_bar.c b/riscos/gui/url_bar.c index 845f8b3e8..d89004856 100644 --- a/riscos/gui/url_bar.c +++ b/riscos/gui/url_bar.c @@ -1,6 +1,6 @@ /* * Copyright 2004, 2005 Richard Wilson <info@tinct.net> - * Copyright 2011 Stephen Fryatt <stevef@netsurf-browser.org> + * Copyright 2011-2014 Stephen Fryatt <stevef@netsurf-browser.org> * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -30,15 +30,25 @@ #include "oslib/os.h" #include "oslib/osspriteop.h" #include "oslib/wimp.h" + +#include "utils/log.h" +#include "utils/messages.h" +#include "utils/utf8.h" +#include "utils/utils.h" +#include "content/hlcache.h" +#include "content/content.h" +#include "desktop/browser.h" + +#include "riscos/gui.h" #include "riscos/hotlist.h" #include "riscos/gui/url_bar.h" #include "riscos/theme.h" #include "riscos/url_suggest.h" #include "riscos/wimp.h" #include "riscos/wimp_event.h" -#include "utils/log.h" -#include "utils/messages.h" -#include "utils/utils.h" +#include "riscos/window.h" +#include "riscos/ucstables.h" +#include "riscos/filetype.h" #define URLBAR_HEIGHT 52 #define URLBAR_FAVICON_SIZE 16 @@ -48,8 +58,6 @@ #define URLBAR_MIN_WIDTH 52 #define URLBAR_GRIGHT_GUTTER 8 #define URLBAR_FAVICON_NAME_LENGTH 12 -#define URLBAR_INITIAL_LENGTH 256 -#define URLBAR_EXTEND_LENGTH 128 struct url_bar { /** The applied theme (or NULL to use the default) */ @@ -166,7 +174,7 @@ struct url_bar *ro_gui_url_bar_create(struct theme_descriptor *theme) url_bar->hotlist.extent.x1 = 0; url_bar->hotlist.extent.y1 = 0; - url_bar->text_size = URLBAR_INITIAL_LENGTH; + url_bar->text_size = RO_GUI_MAX_URL_SIZE; url_bar->text_buffer = malloc(url_bar->text_size); strncpy(url_bar->text_buffer, "", url_bar->text_size); @@ -851,8 +859,7 @@ bool ro_gui_url_bar_menu_select(struct url_bar *url_bar, wimp_i i, browser_window_navigate(g->bw, url, NULL, - BROWSER_WINDOW_HISTORY | - BROWSER_WINDOW_VERIFIABLE, + BW_NAVIGATE_HISTORY, NULL, NULL, NULL); @@ -941,24 +948,68 @@ void ro_gui_url_bar_set_url(struct url_bar *url_bar, const char *url, { wimp_caret caret; os_error *error; - const char *set_url; + char *local_text = NULL; + const char *local_url; nsurl *n; - if (url_bar == NULL || url_bar->text_buffer == NULL) + if (url_bar == NULL || url_bar->text_buffer == NULL || url == NULL) return; - if (nsurl_create(url, &n) == NSERROR_OK) { + /* Before we do anything with the URL, get it into local encoding so + * that behaviour is consistant with the rest of the URL Bar module + * (which will act on the icon's text buffer, which is always in local + * encoding). + */ + + if (is_utf8) { + nserror err; + + err = utf8_to_local_encoding(url, 0, &local_text); + if (err != NSERROR_OK) { + /* A bad encoding should never happen, so assert this */ + assert(err != NSERROR_BAD_ENCODING); + LOG(("utf8_to_enc failed")); + /* Paranoia */ + local_text = NULL; + } + local_url = (local_text != NULL) ? local_text : url; + } else { + local_url = url; + } + + /* Copy the text into the icon buffer. If the text is too long, blank + * the buffer and warn the user. + */ + + if (strlen(local_url) >= url_bar->text_size) { + strncpy(url_bar->text_buffer, "", url_bar->text_size - 1); + url_bar->text_buffer[url_bar->text_size - 1] = '\0'; + warn_user("LongURL", NULL); + LOG(("Long URL (%d chars): %s", strlen(url), url)); + } else { + strncpy(url_bar->text_buffer, local_url, + url_bar->text_size - 1); + url_bar->text_buffer[url_bar->text_size - 1] = '\0'; + } + + if (local_text != NULL) + free(local_text); + + /* Set the hotlist flag. */ + + if (nsurl_create(url_bar->text_buffer, &n) == NSERROR_OK) { ro_gui_url_bar_set_hotlist(url_bar, ro_gui_hotlist_has_page(n)); nsurl_unref(n); } - if (url_bar->text_icon == -1) { - strncpy(url_bar->text_buffer, url, url_bar->text_size); + /* If there's no icon, then there's nothing else to do... */ + + if (url_bar->text_icon == -1) return; - } - ro_gui_set_icon_string(url_bar->window, url_bar->text_icon, - url, is_utf8); + /* ...if there is, redraw the icon and fix the caret's position. */ + + ro_gui_redraw_icon(url_bar->window, url_bar->text_icon); error = xwimp_get_caret_position(&caret); if (error) { @@ -970,7 +1021,7 @@ void ro_gui_url_bar_set_url(struct url_bar *url_bar, const char *url, if (set_caret || (caret.w == url_bar->window && caret.i == url_bar->text_icon)) { - set_url = ro_gui_get_icon_string(url_bar->window, + const char *set_url = ro_gui_get_icon_string(url_bar->window, url_bar->text_icon); error = xwimp_set_caret_position(url_bar->window, @@ -1013,9 +1064,9 @@ static void ro_gui_url_bar_set_hotlist(struct url_bar *url_bar, bool set) { if (url_bar == NULL || set == url_bar->hotlist.set) return; - + url_bar->hotlist.set = set; - + if (!url_bar->hidden) { xwimp_force_redraw(url_bar->window, url_bar->hotlist.extent.x0, @@ -1097,7 +1148,7 @@ bool ro_gui_url_bar_test_for_text_field_keypress(struct url_bar *url_bar, return false; /* Update hotlist indicator */ - + url = (const char *) url_bar->text_buffer; if (url != NULL && nsurl_create(url, &n) == NSERROR_OK) { ro_gui_url_bar_set_hotlist(url_bar, ro_gui_hotlist_has_page(n)); @@ -1278,4 +1329,3 @@ void ro_gui_url_bar_fini(void) hlcache_handle_release(url_bar_res[i].c); } } - diff --git a/riscos/gui/url_bar.h b/riscos/gui/url_bar.h index 034f74df6..0f41a4b01 100644 --- a/riscos/gui/url_bar.h +++ b/riscos/gui/url_bar.h @@ -39,6 +39,7 @@ typedef enum { } url_bar_action; struct url_bar; +struct hlcache_handle; /** * Initialise the url bar module. diff --git a/riscos/help.c b/riscos/help.c index 14d34af15..fe5725071 100644 --- a/riscos/help.c +++ b/riscos/help.c @@ -20,31 +20,26 @@ * Interactive help (implementation). */ -#include <assert.h> -#include <stdbool.h> -#include <stdio.h> -#include "oslib/help.h" -#include "oslib/os.h" -#include "oslib/taskmanager.h" -#include "oslib/wimp.h" -#include "desktop/tree.h" -#include "riscos/cookies.h" -#include "riscos/global_history.h" -#include "riscos/gui.h" -#include "riscos/hotlist.h" -#include "riscos/help.h" -#include "riscos/iconbar.h" -#include "riscos/menus.h" +#include <oslib/wimp.h> +#include <oslib/taskmanager.h> + #include "utils/nsoption.h" -#include "riscos/treeview.h" -#include "riscos/wimp.h" -#include "riscos/wimp_event.h" -#include "riscos/window.h" -#include "utils/messages.h" #include "utils/log.h" -#include "utils/utf8.h" #include "utils/utils.h" +#include "utils/messages.h" +#include "utils/utf8.h" +#include "riscos/treeview.h" +#include "riscos/help.h" +#include "riscos/wimp_event.h" +#include "riscos/hotlist.h" +#include "riscos/global_history.h" +#include "riscos/cookies.h" +#include "riscos/wimp.h" +#include "riscos/iconbar.h" +#include "riscos/window.h" +#include "riscos/ucstables.h" +#include "riscos/gui.h" /* Recognised help keys ==================== @@ -102,7 +97,7 @@ void ro_gui_interactive_help_request(wimp_message *message) bool greyed = false; wimp_menu *test_menu; os_error *error; - const char *auto_text, *auto_suffix; + const char *auto_text; int i; /* check we aren't turned off */ @@ -125,8 +120,9 @@ void ro_gui_interactive_help_request(wimp_message *message) /* do the basic window checks */ auto_text = ro_gui_wimp_event_get_help_prefix(window); if (auto_text != NULL) { - auto_suffix = ro_gui_wimp_event_get_help_suffix(window, icon, - &message_data->pos, message_data->buttons); + const char *auto_suffix = ro_gui_wimp_event_get_help_suffix( + window, icon, &message_data->pos, + message_data->buttons); if (auto_suffix == NULL) sprintf(message_token, "%s%i", auto_text, (int)icon); @@ -222,10 +218,8 @@ static void ro_gui_interactive_help_broadcast(wimp_message *message, { const char *translated_token; help_full_message_reply *reply; - char *base_token; char *local_token; os_error *error; - utf8_convert_ret err; /* start off with an empty reply */ reply = (help_full_message_reply *)message; @@ -237,7 +231,7 @@ static void ro_gui_interactive_help_broadcast(wimp_message *message, /* no default help for 'g' suffix */ if (token[strlen(token) - 1] != 'g') { /* find the base key from the token */ - base_token = token; + char *base_token = token; while (base_token[0] != 0x00) { if ((base_token[0] == '-') || ((base_token[0] >= '0') && @@ -253,11 +247,11 @@ static void ro_gui_interactive_help_broadcast(wimp_message *message, /* copy our message string */ if (translated_token != token) { /* convert to local encoding */ - err = utf8_to_local_encoding(translated_token, 0, + nserror err = utf8_to_local_encoding(translated_token, 0, &local_token); - if (err != UTF8_CONVERT_OK) { + if (err != NSERROR_OK) { /* badenc should never happen */ - assert(err != UTF8_CONVERT_BADENC); + assert(err != NSERROR_BAD_ENCODING); /* simply use UTF-8 string */ strncpy(reply->reply, translated_token, 235); } @@ -292,7 +286,6 @@ bool ro_gui_interactive_help_available(void) taskmanager_task task; int context = 0; os_t time; - os_error *error; /* generic test: any help request within the last 100cs */ xos_read_monotonic_time(&time); @@ -301,6 +294,7 @@ bool ro_gui_interactive_help_available(void) /* special cases: check known application names */ do { + os_error *error; error = xtaskmanager_enumerate_tasks(context, &task, sizeof(taskmanager_task), &context, 0); if (error) { diff --git a/riscos/history.c b/riscos/history.c index a4aedc6b5..3b8b63ae1 100644 --- a/riscos/history.c +++ b/riscos/history.c @@ -27,10 +27,9 @@ #include <stdlib.h> #include <string.h> #include "oslib/wimp.h" -#include "desktop/local_history.h" +#include "desktop/browser_history.h" #include "desktop/plotters.h" #include "riscos/dialog.h" -#include "desktop/browser_private.h" #include "utils/nsoption.h" #include "riscos/gui.h" #include "riscos/mouse.h" @@ -38,12 +37,10 @@ #include "riscos/wimp_event.h" #include "riscos/wimputils.h" #include "utils/log.h" -#include "utils/url.h" #include "utils/utils.h" static struct browser_window *history_bw; -static struct history *history_current = 0; /* Last position of mouse in window. */ static int mouse_x = 0; /* Last position of mouse in window. */ @@ -77,25 +74,24 @@ void ro_gui_history_init(void) /** * Open history window. * - * \param bw browser window to open history for - * \param history history to open - * \param at_pointer open the window at the pointer + * \param g The riscos window to open history for. + * \param at_pointer open the window at the pointer. */ -void ro_gui_history_open(struct browser_window *bw, - struct history *history, bool at_pointer) +void ro_gui_history_open(struct gui_window *g, bool at_pointer) { + struct browser_window *bw; int width, height; os_box box = {0, 0, 0, 0}; wimp_window_state state; os_error *error; - assert(history); - - history_current = history; + assert(g != NULL); + assert(g->bw != NULL); + bw = g->bw; history_bw = bw; - history_size(history, &width, &height); + browser_window_history_size(bw, &width, &height); width *= 2; height *= 2; @@ -132,8 +128,7 @@ void ro_gui_history_open(struct browser_window *bw, return; } - ro_gui_dialog_open_persistent(bw->window->window, history_window, - at_pointer); + ro_gui_dialog_open_persistent(g->window, history_window, at_pointer); } @@ -161,7 +156,7 @@ void ro_gui_history_redraw(wimp_draw *redraw) while (more) { ro_plot_origin_x = redraw->box.x0 - redraw->xscroll; ro_plot_origin_y = redraw->box.y1 - redraw->yscroll; - history_redraw(history_current, &ctx); + browser_window_history_redraw(history_bw, &ctx); error = xwimp_get_rectangle(redraw, &more); if (error) { LOG(("xwimp_get_rectangle: 0x%x: %s", @@ -237,7 +232,7 @@ void ro_gui_history_mouse_at(wimp_pointer *pointer, void *data) x = (pointer->pos.x - (state.visible.x0 - state.xscroll)) / 2; y = -(pointer->pos.y - (state.visible.y1 - state.yscroll)) / 2; - url = history_position_url(history_current, x, y); + url = browser_window_history_position_url(history_bw, x, y); if (!url) { /* not over a tree entry => close tooltip window. */ error = xwimp_close_window(dialog_tooltip); @@ -348,7 +343,7 @@ bool ro_gui_history_click(wimp_pointer *pointer) x = (pointer->pos.x - (state.visible.x0 - state.xscroll)) / 2; y = -(pointer->pos.y - (state.visible.y1 - state.yscroll)) / 2; - history_click(history_bw, history_current, x, y, + browser_window_history_click(history_bw, x, y, pointer->buttons == wimp_CLICK_ADJUST); return true; diff --git a/riscos/hotlist.c b/riscos/hotlist.c index f47d05e9c..82ad3b0f2 100644 --- a/riscos/hotlist.c +++ b/riscos/hotlist.c @@ -1,6 +1,6 @@ /* * Copyright 2004, 2005 Richard Wilson <info@tinct.net> - * Copyright 2010 Stephen Fryatt <stevef@netsurf-browser.org> + * Copyright 2010, 2013 Stephen Fryatt <stevef@netsurf-browser.org> * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -30,26 +30,29 @@ #include "oslib/osfile.h" #include "oslib/osmodule.h" #include "oslib/wimp.h" + #include "content/content.h" #include "content/hlcache.h" #include "content/urldb.h" #include "desktop/hotlist.h" #include "desktop/tree.h" +#include "desktop/gui.h" +#include "utils/log.h" +#include "utils/messages.h" +#include "utils/utils.h" +#include "utils/nsoption.h" + +#include "riscos/gui.h" #include "riscos/dialog.h" #include "riscos/hotlist.h" #include "riscos/menus.h" #include "riscos/message.h" -#include "utils/nsoption.h" #include "riscos/save.h" #include "riscos/toolbar.h" #include "riscos/treeview.h" #include "riscos/wimp.h" #include "riscos/wimp_event.h" -#include "utils/log.h" -#include "utils/messages.h" -#include "utils/schedule.h" -#include "utils/utils.h" -#include "utils/url.h" +#include "riscos/query.h" static void ro_gui_hotlist_toolbar_update_buttons(void); static void ro_gui_hotlist_toolbar_save_buttons(char *config); @@ -217,12 +220,12 @@ void ro_gui_hotlist_destroy(void) void ro_gui_hotlist_open(void) { - os_error *error; - char command[2048]; + if (nsoption_bool(external_hotlists) && + nsoption_charp(external_hotlist_app) != NULL && + *nsoption_charp(external_hotlist_app) != '\0') { + char command[2048]; + os_error *error; - if (nsoption_bool(external_hotlists) && - nsoption_charp(external_hotlist_app) != NULL && - *nsoption_charp(external_hotlist_app) != '\0') { snprintf(command, sizeof(command), "Filer_Run %s", nsoption_charp(external_hotlist_app)); error = xos_cli(command); @@ -542,7 +545,7 @@ void ro_gui_hotlist_add_page(nsurl *url) * message didn't bounce. */ - schedule(0, ro_gui_hotlist_scheduled_callback, NULL); + riscos_schedule(0, ro_gui_hotlist_scheduled_callback, NULL); } @@ -568,7 +571,7 @@ static void ro_gui_hotlist_addurl_bounce(wimp_message *message) /* There's no longer any need to listen for the next Null poll. */ - schedule_remove(ro_gui_hotlist_scheduled_callback, NULL); + riscos_schedule(-1, ro_gui_hotlist_scheduled_callback, NULL); } @@ -732,4 +735,3 @@ void ro_gui_hotlist_url_drop(wimp_message *message, const char *url) nsurl_unref(nsurl); } #endif - diff --git a/riscos/hotlist.h b/riscos/hotlist.h index 4cb5a1ff3..0b87a2e96 100644 --- a/riscos/hotlist.h +++ b/riscos/hotlist.h @@ -1,6 +1,6 @@ /* * Copyright 2006 Richard Wilson <info@tinct.net> - * Copyright 2010 Stephen Fryatt <stevef@netsurf-browser.org> + * Copyright 2010, 2013 Stephen Fryatt <stevef@netsurf-browser.org> * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -45,10 +45,9 @@ void ro_gui_hotlist_open(void); void ro_gui_hotlist_save(void); bool ro_gui_hotlist_check_window(wimp_w window); bool ro_gui_hotlist_check_menu(wimp_menu *menu); -void ro_gui_hotlist_add_page(nsurl *url); +void ro_gui_hotlist_add_page(struct nsurl *url); void ro_gui_hotlist_add_cleanup(void); -void ro_gui_hotlist_remove_page(nsurl *url); -bool ro_gui_hotlist_has_page(nsurl *url); +void ro_gui_hotlist_remove_page(struct nsurl *url); +bool ro_gui_hotlist_has_page(struct nsurl *url); #endif - diff --git a/riscos/iconbar.c b/riscos/iconbar.c index f6c094291..f29b019a2 100644 --- a/riscos/iconbar.c +++ b/riscos/iconbar.c @@ -28,21 +28,26 @@ #include <string.h> #include <time.h> #include <features.h> -#include "oslib/os.h" -#include "oslib/osbyte.h" -#include "oslib/wimp.h" +#include <oslib/os.h> +#include <oslib/osbyte.h> +#include <oslib/wimp.h> + +#include "utils/nsoption.h" +#include "utils/log.h" +#include "utils/messages.h" +#include "utils/utils.h" +#include "utils/nsurl.h" +#include "desktop/netsurf.h" +#include "desktop/browser.h" + +#include "riscos/gui.h" #include "riscos/configure.h" #include "riscos/cookies.h" #include "riscos/dialog.h" #include "riscos/global_history.h" #include "riscos/hotlist.h" #include "riscos/iconbar.h" -#include "desktop/browser.h" -#include "utils/nsoption.h" #include "riscos/wimp_event.h" -#include "utils/log.h" -#include "utils/messages.h" -#include "utils/utils.h" static bool ro_gui_iconbar_click(wimp_pointer *pointer); @@ -133,8 +138,7 @@ bool ro_gui_iconbar_click(wimp_pointer *pointer) /* create an initial browser window */ if (error == NSERROR_OK) { - error = browser_window_create(BROWSER_WINDOW_VERIFIABLE | - BROWSER_WINDOW_HISTORY, + error = browser_window_create(BW_CREATE_HISTORY, url, NULL, NULL, @@ -204,9 +208,7 @@ bool ro_gui_iconbar_menu_select(wimp_w w, wimp_i i, wimp_menu *menu, case HELP_OPEN_CONTENTS: error = nsurl_create("http://www.netsurf-browser.org/documentation/", &url); if (error == NSERROR_OK) { - error = browser_window_create( - BROWSER_WINDOW_VERIFIABLE | - BROWSER_WINDOW_HISTORY, + error = browser_window_create(BW_CREATE_HISTORY, url, NULL, NULL, diff --git a/riscos/image.c b/riscos/image.c index 56feb2b96..07baecd60 100644 --- a/riscos/image.c +++ b/riscos/image.c @@ -17,16 +17,17 @@ */ #include <stdbool.h> -#include "swis.h" -#include "oslib/colourtrans.h" -#include "oslib/osspriteop.h" -#include "riscos/image.h" -#include "riscos/gui.h" +#include <swis.h> +#include <oslib/colourtrans.h> +#include <oslib/osspriteop.h> + #include "utils/nsoption.h" -#include "riscos/tinct.h" #include "utils/log.h" #include "utils/utils.h" +#include "riscos/image.h" +#include "riscos/gui.h" +#include "riscos/tinct.h" static bool image_redraw_tinct(osspriteop_id header, int x, int y, int req_width, int req_height, int width, int height, diff --git a/riscos/menus.c b/riscos/menus.c index e51fc34c5..4158d23af 100644 --- a/riscos/menus.c +++ b/riscos/menus.c @@ -31,15 +31,20 @@ #include "oslib/osgbpb.h" #include "oslib/territory.h" #include "oslib/wimp.h" + +#include "utils/log.h" +#include "utils/messages.h" +#include "utils/utils.h" +#include "utils/utf8.h" #include "content/content.h" #include "content/hlcache.h" #include "content/urldb.h" #include "desktop/cookie_manager.h" #include "desktop/browser.h" #include "desktop/gui.h" -#include "desktop/local_history.h" #include "desktop/netsurf.h" #include "desktop/textinput.h" + #include "riscos/dialog.h" #include "riscos/configure.h" #include "riscos/cookies.h" @@ -56,11 +61,7 @@ #include "riscos/url_suggest.h" #include "riscos/wimp.h" #include "riscos/wimp_event.h" -#include "utils/log.h" -#include "utils/messages.h" -#include "utils/url.h" -#include "utils/utils.h" -#include "utils/utf8.h" +#include "riscos/ucstables.h" struct menu_definition_entry { menu_action action; /**< menu action */ @@ -77,7 +78,7 @@ struct menu_definition { struct menu_definition *next; /**< next menu */ }; - +static void ro_gui_menu_closed(void); static void ro_gui_menu_define_menu_add(struct menu_definition *definition, const struct ns_menu *menu, int depth, wimp_menu_entry *parent_entry, @@ -118,6 +119,7 @@ wimp_menu *image_quality_menu, *proxy_type_menu, *languages_menu; /** * Create menu structures. */ + void ro_gui_menu_init(void) { /* image quality menu */ @@ -212,6 +214,7 @@ void ro_gui_menu_init(void) * \param y The y position. * \param w The window that the menu belongs to. */ + void ro_gui_menu_create(wimp_menu *menu, int x, int y, wimp_w w) { os_error *error; @@ -251,6 +254,7 @@ void ro_gui_menu_create(wimp_menu *menu, int x, int y, wimp_w w) * \param w window handle * \param i icon handle */ + void ro_gui_popup_menu(wimp_menu *menu, wimp_w w, wimp_i i) { wimp_window_state state; @@ -285,29 +289,24 @@ void ro_gui_popup_menu(wimp_menu *menu, wimp_w w, wimp_i i) /** - * Clean up after a menu has been closed, or forcible close an open menu. - */ -void ro_gui_menu_closed(void) + * Forcibly close any menu or transient dialogue box that is currently open. + */ + +void ro_gui_menu_destroy(void) { os_error *error; - if (current_menu) { - 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); - } - - ro_gui_wimp_event_menus_closed(current_menu_window, - current_menu_icon, current_menu); + if (current_menu == NULL) + return; - current_menu = NULL; + 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); } - current_menu_window = NULL; - current_menu_icon = 0; - current_menu_open = false; + ro_gui_menu_closed(); } @@ -439,6 +438,38 @@ void ro_gui_menu_warning(wimp_message_menu_warning *warning) } } + +/** + * Handle Message_MenusDeleted, removing our current record of an open menu + * if it matches the deleted menu handle. + * + * \param *deleted The message block. + */ + +void ro_gui_menu_message_deleted(wimp_message_menus_deleted *deleted) +{ + if (deleted != NULL && deleted->menu == current_menu) + ro_gui_menu_closed(); +} + + +/** + * Clean up after a menu has been closed, or forcibly close an open menu. + */ + +static void ro_gui_menu_closed(void) +{ + if (current_menu != NULL) + ro_gui_wimp_event_menus_closed(current_menu_window, + current_menu_icon, current_menu); + + current_menu = NULL; + current_menu_window = NULL; + current_menu_icon = 0; + current_menu_open = false; +} + + /** * Update the current menu by sending it a Menu Prepare event through wimp_event * and then reopening it if the contents has changed. @@ -451,7 +482,6 @@ void ro_gui_menu_warning(wimp_message_menu_warning *warning) void ro_gui_menu_refresh(wimp_menu *menu) { int checksum = 0; - os_error *error; if (!current_menu_open) return; @@ -465,6 +495,7 @@ void ro_gui_menu_refresh(wimp_menu *menu) /* \TODO -- Call the menu's event handler here. */ if (checksum != ro_gui_menu_get_checksum()) { + os_error *error; error = xwimp_create_menu(current_menu, 0, 0); if (error) { LOG(("xwimp_create_menu: 0x%x: %s", @@ -535,17 +566,17 @@ void ro_gui_menu_define_menu_add(struct menu_definition *definition, wimp_menu_entry *parent_entry, int first, int last, const char *prefix, int prefix_length) { - int entry, id, cur_depth; + int entry; int entries = 0; int matches[last - first + 1]; - const char *match; const char *text, *menu_text; 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; + const char *match; + int cur_depth = 0; match = menu->entries[entry].text; /* skip specials at start of string */ @@ -595,7 +626,7 @@ void ro_gui_menu_define_menu_add(struct menu_definition *definition, /* and then create the entries */ for (entry = 0; entry < entries; entry++) { /* add the entry */ - id = matches[entry]; + int id = matches[entry]; text = menu->entries[id].text; @@ -875,8 +906,7 @@ bool ro_gui_menu_translate(struct menu_definition *menu) int alphabet; struct menu_definition_entry *entry; char *translated; - utf8_convert_ret err; - + nserror err; /* read current alphabet */ error = xosbyte1(osbyte_ALPHABET_NUMBER, 127, 0, &alphabet); @@ -895,8 +925,8 @@ bool ro_gui_menu_translate(struct menu_definition *menu) free(menu->menu->title_data.indirected_text.text); err = utf8_to_local_encoding(messages_get(menu->title_key), 0, &translated); - if (err != UTF8_CONVERT_OK) { - assert(err != UTF8_CONVERT_BADENC); + if (err != NSERROR_OK) { + assert(err != NSERROR_BAD_ENCODING); LOG(("utf8_to_enc failed")); return false; } @@ -912,8 +942,8 @@ bool ro_gui_menu_translate(struct menu_definition *menu) free(entry->menu_entry->data.indirected_text.text); err = utf8_to_local_encoding(messages_get(entry->entry_key), 0, &translated); - if (err != UTF8_CONVERT_OK) { - assert(err != UTF8_CONVERT_BADENC); + if (err != NSERROR_OK) { + assert(err != NSERROR_BAD_ENCODING); LOG(("utf8_to_enc failed")); return false; } diff --git a/riscos/menus.h b/riscos/menus.h index 033b01117..7faa87ed6 100644 --- a/riscos/menus.h +++ b/riscos/menus.h @@ -19,10 +19,6 @@ #ifndef _NETSURF_RISCOS_MENUS_H_ #define _NETSURF_RISCOS_MENUS_H_ -#include <stdbool.h> -#include "oslib/wimp.h" -#include "riscos/gui.h" - extern wimp_menu *image_quality_menu, *proxy_type_menu, *languages_menu; extern wimp_menu *current_menu; @@ -168,11 +164,12 @@ struct ns_menu { void ro_gui_menu_init(void); void ro_gui_menu_create(wimp_menu* menu, int x, int y, wimp_w w); -void ro_gui_menu_closed(void); +void ro_gui_menu_destroy(void); void ro_gui_popup_menu(wimp_menu *menu, wimp_w w, wimp_i i); void ro_gui_menu_window_changed(wimp_w from, wimp_w to); void ro_gui_menu_selection(wimp_selection* selection); void ro_gui_menu_warning(wimp_message_menu_warning *warning); +void ro_gui_menu_message_deleted(wimp_message_menus_deleted *deleted); void ro_gui_menu_refresh(wimp_menu *menu); void ro_gui_menu_init_structure(wimp_menu *menu, int entries); const char *ro_gui_menu_find_menu_entry_key(wimp_menu *menu, diff --git a/riscos/message.c b/riscos/message.c index 5a9bb15fa..bfb33a8c9 100644 --- a/riscos/message.c +++ b/riscos/message.c @@ -188,14 +188,14 @@ struct active_message *ro_message_add(unsigned int message_code, bool ro_message_handle_message(wimp_event_no event, wimp_message *message) { struct active_message *test; - bool handled = false; - int ref; assert(message); if (event == wimp_USER_MESSAGE_ACKNOWLEDGE) { /* handle message acknowledgement */ - ref = message->my_ref; + bool handled = false; + int ref = message->my_ref; + if (ref == 0) return false; diff --git a/riscos/mouse.c b/riscos/mouse.c index a20965e31..e934c1cf4 100644 --- a/riscos/mouse.c +++ b/riscos/mouse.c @@ -163,9 +163,11 @@ void ro_mouse_drag_end(wimp_dragged *dragged) * Start tracking the mouse in a window, providing a function to be called on * null polls and optionally one to be called when it leaves the window. * - * \param *drag_end Callback for when the pointer leaves the window, or - * NULL for none. - * \param *drag_track Callback for mouse tracking while the pointer remains + * \param *poll_end Callback for when the pointer leaves the window, or + * NULL for none. Claimants can receive *leaving==NULL if + * a new tracker is started before a PointerLeaving event + * is received. + * \param *poll_track Callback for mouse tracking while the pointer remains * in the window, or NULL for none. * \param *data Data to be passed to the callback functions, or NULL. */ @@ -175,12 +177,31 @@ void ro_mouse_track_start(void (*poll_end)(wimp_leaving *leaving, void *data), void *data) { /* It should never be possible for the mouse to be in two windows - * at the same time! + * at the same time! However, some third-party extensions to RISC OS + * appear to make this possible (MouseAxess being one), so in the + * event that there's still a claimant we tidy them up first and then + * log the fact in case there are any unexpected consequences. + * + * NB: The Poll End callback will get called with *leaving == NULL in + * this situation, as there's no PointerLeaving event to pass on. */ - assert(ro_mouse_poll_end_callback == NULL && - ro_mouse_poll_track_callback == NULL && - ro_mouse_poll_data == NULL); + if (ro_mouse_poll_end_callback != NULL || + ro_mouse_poll_track_callback != NULL || + ro_mouse_poll_data != NULL) { + if (ro_mouse_poll_end_callback != NULL && + ro_mouse_ignore_leaving_event == false) + ro_mouse_poll_end_callback(NULL, ro_mouse_poll_data); + + LOG(("Unexpected mouse track termination.")); + + ro_mouse_ignore_leaving_event = false; + ro_mouse_poll_end_callback = NULL; + ro_mouse_poll_track_callback = NULL; + ro_mouse_poll_data = NULL; + } + + /* Now record details of the new claimant. */ ro_mouse_poll_end_callback = poll_end; ro_mouse_poll_track_callback = poll_track; diff --git a/riscos/mouse.h b/riscos/mouse.h index bcb3b50bd..8a7405a2f 100644 --- a/riscos/mouse.h +++ b/riscos/mouse.h @@ -65,9 +65,11 @@ void ro_mouse_drag_end(wimp_dragged *dragged); * Start tracking the mouse in a window, providing a function to be called on * null polls and optionally one to be called when it leaves the window. * - * \param *drag_end Callback for when the pointer leaves the window, or - * NULL for none. - * \param *drag_track Callback for mouse tracking while the pointer remains + * \param *poll_end Callback for when the pointer leaves the window, or + * NULL for none. Claimants can receive *leaving==NULL if + * a new tracker is started before a PointerLeaving event + * is received. + * \param *poll_track Callback for mouse tracking while the pointer remains * in the window, or NULL for none. * \param *data Data to be passed to the callback functions, or NULL. */ diff --git a/riscos/plotters.c b/riscos/plotters.c index 966b6cb68..6e49c2278 100644 --- a/riscos/plotters.c +++ b/riscos/plotters.c @@ -25,13 +25,16 @@ #include "oslib/colourtrans.h" #include "oslib/draw.h" #include "oslib/os.h" + +#include "utils/log.h" #include "desktop/plotters.h" #include "render/font.h" + #include "riscos/bitmap.h" #include "riscos/image.h" #include "riscos/gui.h" +#include "riscos/font.h" #include "riscos/oslib_pre7.h" -#include "utils/log.h" static bool ro_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style); @@ -77,9 +80,8 @@ bool ro_plot_patterned_lines = true; bool ro_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style) { - os_error *error; - - if (style->fill_type != PLOT_OP_TYPE_NONE) { + if (style->fill_type != PLOT_OP_TYPE_NONE) { + os_error *error; error = xcolourtrans_set_gcol(style->fill_colour << 8, colourtrans_USE_ECFS_GCOL, os_ACTION_OVERWRITE, 0, 0); @@ -145,17 +147,17 @@ bool ro_plot_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style bool ro_plot_line(int x0, int y0, int x1, int y1, const plot_style_t *style) { - const int path[] = { draw_MOVE_TO, - (ro_plot_origin_x + x0 * 2) * 256, - (ro_plot_origin_y - y0 * 2 - 1) * 256, - draw_LINE_TO, - (ro_plot_origin_x + x1 * 2) * 256, - (ro_plot_origin_y - y1 * 2 - 1) * 256, - draw_END_PATH }; - bool dotted = false; - bool dashed = false; - if (style->stroke_type != PLOT_OP_TYPE_NONE) { + const int path[] = { draw_MOVE_TO, + (ro_plot_origin_x + x0 * 2) * 256, + (ro_plot_origin_y - y0 * 2 - 1) * 256, + draw_LINE_TO, + (ro_plot_origin_x + x1 * 2) * 256, + (ro_plot_origin_y - y1 * 2 - 1) * 256, + draw_END_PATH }; + bool dotted = false; + bool dashed = false; + if (style->stroke_type == PLOT_OP_TYPE_DOT) dotted = true; diff --git a/riscos/print.c b/riscos/print.c index 0df77ef6b..1d9ed3e43 100644 --- a/riscos/print.c +++ b/riscos/print.c @@ -21,28 +21,33 @@ #include <assert.h> #include <string.h> -#include "swis.h" -#include "oslib/font.h" -#include "oslib/hourglass.h" -#include "oslib/osfile.h" -#include "oslib/osfind.h" -#include "oslib/pdriver.h" -#include "oslib/wimp.h" -#include "rufl.h" +#include <swis.h> +#include <oslib/font.h> +#include <oslib/hourglass.h> +#include <oslib/osfile.h> +#include <oslib/osfind.h> +#include <oslib/pdriver.h> +#include <oslib/wimp.h> +#include <rufl.h> + #include "utils/config.h" +#include "utils/log.h" +#include "utils/messages.h" +#include "utils/utils.h" +#include "utils/nsoption.h" #include "content/content.h" #include "content/hlcache.h" -#include "desktop/browser_private.h" -#include "utils/nsoption.h" +#include "desktop/browser.h" #include "desktop/plotters.h" + +#include "riscos/gui.h" #include "riscos/dialog.h" #include "riscos/menus.h" #include "riscos/print.h" #include "riscos/wimp.h" #include "riscos/wimp_event.h" -#include "utils/log.h" -#include "utils/messages.h" -#include "utils/utils.h" +#include "riscos/filetype.h" +#include "riscos/font.h" #define ICON_PRINT_TO_BOTTOM 1 @@ -90,6 +95,7 @@ static unsigned int print_fonts_count; /** Error in print_fonts_plot_text() or print_fonts_callback(). */ static const char *print_fonts_error; +void gui_window_redraw_window(struct gui_window *g); static bool ro_gui_print_click(wimp_pointer *pointer); static bool ro_gui_print_apply(wimp_w w); @@ -276,7 +282,8 @@ bool ro_gui_print_apply(wimp_w w) print_bg_images = ro_gui_get_icon_selected_state(dialog_print, ICON_PRINT_BG_IMAGES); - print_send_printsave(ro_print_current_window->bw->current_content); + print_send_printsave(browser_window_get_content( + ro_print_current_window->bw)); return true; } @@ -524,7 +531,7 @@ void ro_print_cleanup(void) print_text_black = false; print_prev_message = 0; print_max_sheets = -1; - ro_gui_menu_closed(); + ro_gui_menu_destroy(); ro_gui_dialog_close(dialog_print); } @@ -542,7 +549,7 @@ bool print_document(struct gui_window *g, const char *filename) int left, right, top, bottom, width, height; int saved_width, saved_height; int yscroll = 0, sheets = print_max_sheets; - hlcache_handle *h = g->bw->current_content; + hlcache_handle *h = browser_window_get_content(g->bw); const char *error_message; pdriver_features features; os_fw fhandle, old_job = 0; diff --git a/riscos/print.h b/riscos/print.h index 446ad2449..d997dce99 100644 --- a/riscos/print.h +++ b/riscos/print.h @@ -19,11 +19,6 @@ #ifndef _NETSURF_RISCOS_PRINT_H_ #define _NETSURF_RISCOS_PRINT_H_ -#include "utils/config.h" - -#include <stdbool.h> -#include "oslib/wimp.h" - struct gui_window; extern struct gui_window *ro_print_current_window; diff --git a/riscos/query.c b/riscos/query.c index 6401ad2b8..aa7492196 100644 --- a/riscos/query.c +++ b/riscos/query.c @@ -18,18 +18,20 @@ #include <stdlib.h> #include <string.h> - #include <stdbool.h> -#include "riscos/dialog.h" -#include "riscos/query.h" -#include "riscos/wimp.h" -#include "riscos/wimp_event.h" #include "utils/log.h" #include "utils/messages.h" #include "utils/utf8.h" #include "utils/utils.h" +#include "riscos/gui.h" +#include "riscos/query.h" +#include "riscos/wimp.h" +#include "riscos/wimp_event.h" +#include "riscos/ucstables.h" +#include "riscos/dialog.h" + #define ICON_QUERY_MESSAGE 0 #define ICON_QUERY_YES 1 #define ICON_QUERY_NO 2 @@ -150,7 +152,7 @@ query_id query_user_xy(const char *query, const char *detail, int len; int tx; char *local_text = NULL; - utf8_convert_ret err; + nserror err; qw = malloc(sizeof(struct gui_query_window)); if (!qw) { @@ -171,8 +173,8 @@ query_id query_user_xy(const char *query, const char *detail, /* set the text of the 'Yes' button and size accordingly */ err = utf8_to_local_encoding(yes, 0, &local_text); - if (err != UTF8_CONVERT_OK) { - assert(err != UTF8_CONVERT_BADENC); + if (err != NSERROR_OK) { + assert(err != NSERROR_BAD_ENCODING); LOG(("utf8_to_local_encoding_failed")); local_text = NULL; } @@ -201,8 +203,8 @@ query_id query_user_xy(const char *query, const char *detail, /* set the text of the 'No' button and size accordingly */ err = utf8_to_local_encoding(no, 0, &local_text); - if (err != UTF8_CONVERT_OK) { - assert(err != UTF8_CONVERT_BADENC); + if (err != NSERROR_OK) { + assert(err != NSERROR_BAD_ENCODING); LOG(("utf8_to_local_encoding_failed")); local_text = NULL; } diff --git a/riscos/query.h b/riscos/query.h index 92e3e292e..857cce063 100644 --- a/riscos/query.h +++ b/riscos/query.h @@ -23,10 +23,32 @@ #include "oslib/wimp.h" #include "utils/utils.h" +enum query_response { + QUERY_CONTINUE, + QUERY_YES, + QUERY_NO, + QUERY_ESCAPE +}; + +typedef int query_id; + +#define QUERY_INVALID ((query_id)-1) + +typedef struct +{ + void (*confirm)(query_id id, enum query_response res, void *pw); + void (*cancel)(query_id, enum query_response res, void *pw); +} query_callback; + + query_id query_user_xy(const char *query, const char *detail, const query_callback *cb, void *pw, const char *yes, const char *no, int x, int y); void ro_gui_query_init(void); void ro_gui_query_window_bring_to_front(query_id id); +query_id query_user(const char *query, const char *detail, + const query_callback *cb, void *pw, const char *yes, const char *no); +void query_close(query_id); + #endif diff --git a/riscos/save.c b/riscos/save.c index 4d1740397..cc8612bb5 100644 --- a/riscos/save.c +++ b/riscos/save.c @@ -35,6 +35,13 @@ #include "oslib/osspriteop.h" #include "oslib/wimp.h" #include "oslib/wimpspriteop.h" + +#include "utils/config.h" +#include "utils/log.h" +#include "utils/messages.h" +#include "utils/url.h" +#include "utils/utf8.h" +#include "utils/utils.h" #include "content/content.h" #include "content/hlcache.h" #include "desktop/hotlist.h" @@ -43,8 +50,10 @@ #include "desktop/save_complete.h" #include "desktop/save_text.h" #include "desktop/thumbnail.h" +#include "desktop/gui.h" #include "image/bitmap.h" #include "render/form.h" + #include "riscos/bitmap.h" #include "riscos/dialog.h" #include "riscos/gui.h" @@ -60,12 +69,8 @@ #include "riscos/thumbnail.h" #include "riscos/wimp.h" #include "riscos/wimp_event.h" -#include "utils/config.h" -#include "utils/log.h" -#include "utils/messages.h" -#include "utils/url.h" -#include "utils/utf8.h" -#include "utils/utils.h" +#include "riscos/ucstables.h" +#include "riscos/filetype.h" //typedef enum //{ @@ -357,8 +362,8 @@ bool ro_gui_save_ok(wimp_w w) * \param g gui window */ -void gui_drag_save_object(gui_save_type save_type, hlcache_handle *c, - struct gui_window *g) +void gui_drag_save_object(struct gui_window *g, hlcache_handle *c, + gui_save_type save_type) { wimp_pointer pointer; char icon_buf[20]; @@ -614,7 +619,6 @@ static void ro_gui_save_drag_end(wimp_dragged *drag, void *data) os_error *error; char *dp, *ep; char *local_name = NULL; - utf8_convert_ret err; if (dragbox_active) ro_gui_drag_box_cancel(); @@ -650,10 +654,11 @@ static void ro_gui_save_drag_end(wimp_dragged *drag, void *data) if (!saving_from_dialog) { /* saving directly from browser window, choose a * name based upon the URL */ + nserror err; err = utf8_to_local_encoding(save_leafname, 0, &local_name); - if (err != UTF8_CONVERT_OK) { + if (err != NSERROR_OK) { /* badenc should never happen */ - assert(err != UTF8_CONVERT_BADENC); + assert(err != NSERROR_BAD_ENCODING); local_name = NULL; } name = local_name ? local_name : save_leafname; @@ -1216,9 +1221,8 @@ void ro_gui_save_set_state(hlcache_handle *h, gui_save_type save_type, const char *name = gui_save_table[save_type].name; bool done = false; char *nice = NULL; - utf8_convert_ret err; + nserror err; char *local_name; - size_t i; assert(icon_len >= 13); @@ -1247,7 +1251,8 @@ void ro_gui_save_set_state(hlcache_handle *h, gui_save_type save_type, /* leafname */ if (url && url_nice(url, &nice, nsoption_bool(strip_extensions)) == - URL_FUNC_OK) { + NSERROR_OK) { + size_t i; for (i = 0; nice[i]; i++) { if (nice[i] == '.') nice[i] = '/'; @@ -1270,13 +1275,14 @@ void ro_gui_save_set_state(hlcache_handle *h, gui_save_type save_type, leaf_buf[leaf_len - 1] = 0; err = utf8_to_local_encoding(name, 0, &local_name); - if (err != UTF8_CONVERT_OK) { + if (err != NSERROR_OK) { /* badenc should never happen */ - assert(err != UTF8_CONVERT_BADENC); + assert(err != NSERROR_BAD_ENCODING); local_name = NULL; } - name = local_name ? local_name : name; + if (local_name != NULL) + name = local_name; /* sprite name used for icon and dragging */ if (save_type == GUI_SAVE_COMPLETE) { diff --git a/riscos/save.h b/riscos/save.h index 34a4a6ba9..d3ca5c214 100644 --- a/riscos/save.h +++ b/riscos/save.h @@ -25,19 +25,23 @@ #include <stdbool.h> #include "oslib/wimp.h" -#include "desktop/gui.h" + +enum gui_save_type; + +void gui_drag_save_object(struct gui_window *g, struct hlcache_handle *c, enum gui_save_type save_type); +void gui_drag_save_selection(struct gui_window *g, const char *selection); wimp_w ro_gui_saveas_create(const char *template_name); void ro_gui_saveas_quit(void); -void ro_gui_save_prepare(gui_save_type save_type, struct hlcache_handle *h, +void ro_gui_save_prepare(enum gui_save_type save_type, struct hlcache_handle *h, char *s, const char *url, const char *title); void ro_gui_save_start_drag(wimp_pointer *pointer); -void ro_gui_drag_save_link(gui_save_type save_type, const char *url, +void ro_gui_drag_save_link(enum gui_save_type save_type, const char *url, const char *title, struct gui_window *g); void ro_gui_drag_icon(int x, int y, const char *sprite); void ro_gui_drag_box_cancel(void); -void ro_gui_send_datasave(gui_save_type save_type, wimp_full_message_data_xfer *message, wimp_t to); +void ro_gui_send_datasave(enum gui_save_type save_type, wimp_full_message_data_xfer *message, wimp_t to); void ro_gui_save_datasave_ack(wimp_message *message); bool ro_gui_save_ok(wimp_w w); void ro_gui_convert_save_path(char *dp, size_t len, const char *p); diff --git a/riscos/save_draw.c b/riscos/save_draw.c index e0823323b..e8b7faae6 100644 --- a/riscos/save_draw.c +++ b/riscos/save_draw.c @@ -26,18 +26,21 @@ #include <assert.h> #include <limits.h> -#include "oslib/draw.h" -#include "oslib/osfile.h" -#include "pencil.h" +#include <oslib/draw.h> +#include <oslib/osfile.h> +#include <pencil.h> + +#include "utils/log.h" +#include "utils/types.h" +#include "utils/utils.h" #include "content/content.h" #include "content/hlcache.h" #include "desktop/plotters.h" + #include "riscos/bitmap.h" #include "riscos/gui.h" #include "riscos/save_draw.h" -#include "utils/log.h" -#include "utils/types.h" -#include "utils/utils.h" +#include "riscos/font.h" static bool ro_save_draw_rectangle(int x0, int y0, int x1, int y1, const plot_style_t *style); static bool ro_save_draw_line(int x0, int y0, int x1, int y1, const plot_style_t *style); diff --git a/riscos/schedule.c b/riscos/schedule.c index 257f2e72f..59cb97d9b 100644 --- a/riscos/schedule.c +++ b/riscos/schedule.c @@ -24,10 +24,11 @@ #include <stdbool.h> #include <stdlib.h> + #include "oslib/os.h" -#include "riscos/gui.h" #include "utils/log.h" -#include "utils/schedule.h" + +#include "riscos/gui.h" /** Entry in the queue of scheduled callbacks. */ @@ -50,32 +51,65 @@ bool sched_active = false; /** Time of soonest scheduled event (valid only if sched_active is true). */ os_t sched_time; - /** - * Schedule a callback. + * Unschedule a callback. * - * \param t interval before the callback should be made / cs * \param callback callback function * \param p user parameter, passed to callback function * - * The callback function will be called as soon as possible after t cs have - * passed. + * All scheduled callbacks matching both callback and p are removed. */ -void schedule(int t, void (*callback)(void *p), void *p) +static nserror schedule_remove(void (*callback)(void *p), void *p) +{ + struct sched_entry *entry, *prev; + + prev = &sched_queue; + + for (entry = prev->next; entry; entry = prev->next) { + if (entry->callback != callback || entry->p != p) { + prev = entry; + continue; + } + + prev->next = entry->next; + free(entry); + + /* There can only ever be one match, and we've found it */ + break; + } + + if (sched_queue.next) { + sched_active = true; + sched_time = sched_queue.next->time; + } else { + sched_active = false; + } + + return NSERROR_OK; +} + +/* exported function documented in riscos/gui.h */ +nserror riscos_schedule(int t, void (*callback)(void *p), void *p) { struct sched_entry *entry; struct sched_entry *queue; os_t time; + nserror ret; - schedule_remove(callback, p); + ret = schedule_remove(callback, p); + if ((t < 0) || (ret != NSERROR_OK)) { + return ret; + } + + t = t / 10; /* convert to centiseconds */ time = os_read_monotonic_time() + t; entry = malloc(sizeof *entry); if (!entry) { LOG(("malloc failed")); - return; + return NSERROR_NOMEM; } entry->time = time; @@ -91,61 +125,31 @@ void schedule(int t, void (*callback)(void *p), void *p) sched_active = true; sched_time = sched_queue.next->time; -} - -/** - * Unschedule a callback. - * - * \param callback callback function - * \param p user parameter, passed to callback function - * - * All scheduled callbacks matching both callback and p are removed. - */ - -void schedule_remove(void (*callback)(void *p), void *p) -{ - struct sched_entry *entry, *next; - - for (entry = &sched_queue; entry->next; entry = entry->next) { - if (entry->next->callback != callback || entry->next->p != p) - continue; - next = entry->next; - entry->next = entry->next->next; - free(next); - if (!entry->next) - break; - } - - if (sched_queue.next) { - sched_active = true; - sched_time = sched_queue.next->time; - } else - sched_active = false; + return NSERROR_OK; } -/** - * Process events up to current time. - */ - +/* exported function documented in riscos/gui.h */ bool schedule_run(void) { struct sched_entry *entry; - void (*callback)(void *p); - void *p; os_t now; now = os_read_monotonic_time(); while (sched_queue.next && sched_queue.next->time <= now) { + void (*callback)(void *p); + void *p; + entry = sched_queue.next; callback = entry->callback; p = entry->p; sched_queue.next = entry->next; free(entry); - /* The callback may call schedule() or schedule_remove(), so - * leave the queue in a safe state. */ + /* The callback may call riscos_schedule(), so leave + * the queue in a safe state. + */ callback(p); } diff --git a/riscos/search.c b/riscos/search.c index 3d3b7ba4a..e5e3d987d 100644 --- a/riscos/search.c +++ b/riscos/search.c @@ -27,20 +27,22 @@ #include <string.h> #include "oslib/hourglass.h" #include "oslib/wimp.h" -#include "utils/config.h" + #include "content/content.h" #include "content/hlcache.h" #include "desktop/browser.h" #include "desktop/gui.h" -#include "desktop/browser_private.h" +#include "desktop/browser.h" #include "desktop/search.h" +#include "utils/log.h" +#include "utils/messages.h" +#include "utils/utils.h" + +#include "riscos/gui.h" #include "riscos/dialog.h" #include "riscos/menus.h" #include "riscos/wimp.h" #include "riscos/wimp_event.h" -#include "utils/log.h" -#include "utils/messages.h" -#include "utils/utils.h" #define RECENT_SEARCHES 8 @@ -48,12 +50,10 @@ struct search_static_data { char *recent_searches[RECENT_SEARCHES]; bool search_insert; struct browser_window *search_window; - search_flags_t flags; - char *string; }; static struct search_static_data search_data = - {{NULL}, false, NULL, 0, NULL}; + { { NULL }, false, NULL }; static wimp_MENU(RECENT_SEARCHES) menu_recent; wimp_menu *recent_search_menu = (wimp_menu *)&menu_recent; @@ -76,14 +76,16 @@ static void ro_gui_search_set_status(bool found, void *p); static void ro_gui_search_set_hourglass(bool active, void *p); static void ro_gui_search_add_recent(const char *string, void *p); -static struct gui_search_callbacks ro_gui_search_callbacks = { - ro_gui_search_set_forward_state, - ro_gui_search_set_back_state, +static struct gui_search_table search_table = { ro_gui_search_set_status, ro_gui_search_set_hourglass, - ro_gui_search_add_recent + ro_gui_search_add_recent, + ro_gui_search_set_forward_state, + ro_gui_search_set_back_state, }; +struct gui_search_table *riscos_search_table = &search_table; + void ro_gui_search_init(void) { dialog_search = ro_gui_dialog_create("search"); @@ -122,8 +124,7 @@ bool ro_gui_search_next(wimp_w w) search_data.search_insert = true; search_flags_t flags = SEARCH_FLAG_FORWARDS | ro_gui_search_update_flags(); - browser_window_search(search_data.search_window, - &ro_gui_search_callbacks, NULL, flags, + browser_window_search(search_data.search_window, NULL, flags, ro_gui_get_icon_string(dialog_search, ICON_SEARCH_TEXT)); return false; @@ -163,8 +164,7 @@ bool ro_gui_search_click(wimp_pointer *pointer) search_data.search_insert = true; flags = ~SEARCH_FLAG_FORWARDS & ro_gui_search_update_flags(); - browser_window_search(search_data.search_window, - &ro_gui_search_callbacks, NULL, + browser_window_search(search_data.search_window, NULL, flags, ro_gui_get_icon_string(dialog_search, ICON_SEARCH_TEXT)); @@ -172,8 +172,7 @@ bool ro_gui_search_click(wimp_pointer *pointer) case ICON_SEARCH_CASE_SENSITIVE: flags = SEARCH_FLAG_FORWARDS | ro_gui_search_update_flags(); - browser_window_search(search_data.search_window, - &ro_gui_search_callbacks, NULL, + browser_window_search(search_data.search_window, NULL, flags, ro_gui_get_icon_string(dialog_search, ICON_SEARCH_TEXT)); @@ -182,8 +181,7 @@ bool ro_gui_search_click(wimp_pointer *pointer) flags = ro_gui_get_icon_selected_state( pointer->w, pointer->i) ? SEARCH_FLAG_SHOWALL : SEARCH_FLAG_NONE; - browser_window_search(search_data.search_window, - &ro_gui_search_callbacks, NULL, + browser_window_search(search_data.search_window, NULL, flags, ro_gui_get_icon_string(dialog_search, ICON_SEARCH_TEXT)); @@ -262,21 +260,37 @@ bool ro_gui_search_prepare_menu(void) } /** - * Open the search dialog + * Determine of the browser window is searchable. * - * \param bw the browser window to search + * \param bw The browser window to check. */ -void ro_gui_search_prepare(struct browser_window *bw) +static bool ro_gui_search_bw_searchable(struct browser_window *bw) { hlcache_handle *h; assert(bw != NULL); - h = bw->current_content; + h = browser_window_get_content(bw); /* only handle html/textplain contents */ + /** \todo Should have content_is_searchable() api */ if ((!h) || (content_get_type(h) != CONTENT_HTML && content_get_type(h) != CONTENT_TEXTPLAIN)) + return false; + + return true; +} + + +/** + * Open the search dialog + * + * \param bw the browser window to search + */ +void ro_gui_search_prepare(struct browser_window *bw) +{ + /* only handle searchable contents */ + if (!ro_gui_search_bw_searchable(bw)) return; /* if the search dialogue is reopened over a new window, we may @@ -313,8 +327,7 @@ bool ro_gui_search_keypress(wimp_key *key) case 1: { flags = ro_gui_search_update_flags() ^ SEARCH_FLAG_SHOWALL; - browser_window_search(search_data.search_window, - &ro_gui_search_callbacks, NULL, + browser_window_search(search_data.search_window, NULL, flags, ro_gui_get_icon_string(dialog_search, ICON_SEARCH_TEXT)); @@ -327,8 +340,7 @@ bool ro_gui_search_keypress(wimp_key *key) ICON_SEARCH_CASE_SENSITIVE, !state); flags = SEARCH_FLAG_FORWARDS | ro_gui_search_update_flags(); - browser_window_search(search_data.search_window, - &ro_gui_search_callbacks, NULL, + browser_window_search(search_data.search_window, NULL, flags, ro_gui_get_icon_string(dialog_search, ICON_SEARCH_TEXT)); @@ -337,8 +349,7 @@ bool ro_gui_search_keypress(wimp_key *key) search_data.search_insert = true; flags = ~SEARCH_FLAG_FORWARDS & ro_gui_search_update_flags(); - browser_window_search(search_data.search_window, - &ro_gui_search_callbacks, NULL, + browser_window_search(search_data.search_window, NULL, flags, ro_gui_get_icon_string(dialog_search, ICON_SEARCH_TEXT)); @@ -347,8 +358,7 @@ bool ro_gui_search_keypress(wimp_key *key) search_data.search_insert = true; flags = SEARCH_FLAG_FORWARDS | ro_gui_search_update_flags(); - browser_window_search(search_data.search_window, - &ro_gui_search_callbacks, NULL, + browser_window_search(search_data.search_window, NULL, flags, ro_gui_get_icon_string(dialog_search, ICON_SEARCH_TEXT)); @@ -360,10 +370,6 @@ bool ro_gui_search_keypress(wimp_key *key) * a new search */ browser_window_search_clear( search_data.search_window); - ro_gui_search_set_forward_state(true, - search_data.search_window); - ro_gui_search_set_back_state(true, - search_data.search_window); search_data.search_insert = true; } if (key->c == 8 || /* backspace */ @@ -376,7 +382,7 @@ bool ro_gui_search_keypress(wimp_key *key) ro_gui_search_set_back_state(true, search_data.search_window); browser_window_search(search_data.search_window, - &ro_gui_search_callbacks, NULL, + NULL, flags, ro_gui_get_icon_string( dialog_search, @@ -396,8 +402,6 @@ bool ro_gui_search_keypress(wimp_key *key) void ro_gui_search_end(wimp_w w) { browser_window_search_clear(search_data.search_window); - ro_gui_search_set_forward_state(true, search_data.search_window); - ro_gui_search_set_back_state(true, search_data.search_window); } /** diff --git a/riscos/sslcert.c b/riscos/sslcert.c index 1395d274e..a9c79687c 100644 --- a/riscos/sslcert.c +++ b/riscos/sslcert.c @@ -27,6 +27,7 @@ #include <stdbool.h> #include <stdio.h> #include <string.h> + #include "oslib/wimp.h" #include "content/content.h" #include "content/hlcache.h" @@ -36,6 +37,9 @@ #include "desktop/sslcert_viewer.h" #include "desktop/gui.h" #include "desktop/tree.h" +#include "utils/log.h" +#include "utils/utils.h" + #include "riscos/dialog.h" #include "riscos/sslcert.h" #include "riscos/textarea.h" @@ -43,8 +47,7 @@ #include "riscos/wimp.h" #include "riscos/wimp_event.h" #include "riscos/wimputils.h" -#include "utils/log.h" -#include "utils/utils.h" +#include "riscos/gui.h" #define ICON_SSL_PANE 1 #define ICON_SSL_REJECT 3 diff --git a/riscos/sslcert.h b/riscos/sslcert.h index 7fba9d3f2..17fce5552 100644 --- a/riscos/sslcert.h +++ b/riscos/sslcert.h @@ -24,6 +24,8 @@ #ifndef _NETSURF_RISCOS_SSLCERT_H_ #define _NETSURF_RISCOS_SSLCERT_H_ +struct node; + void ro_gui_cert_preinitialise(void); void ro_gui_cert_postinitialise(void); void ro_gui_cert_open(struct tree *tree, struct node *node); diff --git a/riscos/templates/de b/riscos/templates/de index 905d57ec0..c840caa4b 100644 --- a/riscos/templates/de +++ b/riscos/templates/de @@ -28,7 +28,7 @@ wimp_window { wimp_window { template_name:"con_cache" - visible:500,860,1088,1100 + visible:500,672,1088,1100 xscroll:0 yscroll:0 next:wimp_TOP @@ -41,7 +41,7 @@ wimp_window { scroll_inner:wimp_COLOUR_VERY_LIGHT_GREY highlight_bg:wimp_COLOUR_CREAM extra_flags: - extent:0,-240,588,0 + extent:0,-428,588,0 title_flags:wimp_ICON_TEXT | wimp_ICON_BORDER | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_FILLED work_flags: sprite_area:&1 @@ -69,7 +69,7 @@ wimp_window { text_and_sprite.validation:"" } wimp_icon { - extent:80,-100,200,-56 + extent:44,-100,164,-56 icon_flags:wimp_ICON_TEXT | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED | wimp_ICON_RJUSTIFIED icon_esg:0 icon_fg:wimp_COLOUR_BLACK @@ -79,7 +79,7 @@ wimp_window { text.validation:"" } wimp_icon { - extent:204,-104,372,-52 + extent:168,-104,336,-52 icon_flags:wimp_ICON_TEXT | wimp_ICON_BORDER | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_FILLED | wimp_ICON_INDIRECTED | wimp_BUTTON_WRITABLE icon_esg:0 icon_fg:wimp_COLOUR_BLACK @@ -89,7 +89,7 @@ wimp_window { text.validation:"Pptr_write;Kta" } wimp_icon { - extent:388,-96,420,-64 + extent:352,-96,384,-64 icon_flags:wimp_ICON_TEXT | wimp_ICON_SPRITE | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED | wimp_BUTTON_REPEAT icon_esg:0 icon_fg:wimp_COLOUR_BLACK @@ -99,7 +99,7 @@ wimp_window { text_and_sprite.validation:"r5;sdown,pdown" } wimp_icon { - extent:420,-96,452,-64 + extent:384,-96,416,-64 icon_flags:wimp_ICON_TEXT | wimp_ICON_SPRITE | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED | wimp_BUTTON_REPEAT icon_esg:0 icon_fg:wimp_COLOUR_BLACK @@ -109,7 +109,7 @@ wimp_window { text_and_sprite.validation:"r5;sup,pup" } wimp_icon { - extent:460,-100,516,-56 + extent:424,-100,480,-56 icon_flags:wimp_ICON_TEXT | wimp_ICON_VCENTRED | wimp_ICON_RJUSTIFIED icon_esg:0 icon_fg:wimp_COLOUR_BLACK @@ -117,7 +117,123 @@ wimp_window { text_only:"MB" } wimp_icon { - extent:24,-208,188,-156 + extent:16,-312,568,-152 + icon_flags:wimp_ICON_TEXT | wimp_ICON_BORDER | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text.text:"" + text.size:* + text.validation:"R4" + } + wimp_icon { + extent:32,-180,268,-136 + icon_flags:wimp_ICON_TEXT | wimp_ICON_SPRITE | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text_and_sprite.text:" Disc cache " + text_and_sprite.size:* + text_and_sprite.validation:"" + } + wimp_icon { + extent:44,-232,164,-188 + icon_flags:wimp_ICON_TEXT | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED | wimp_ICON_RJUSTIFIED + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text.text:"Größe" + text.size:13 + text.validation:"" + } + wimp_icon { + extent:168,-236,336,-184 + icon_flags:wimp_ICON_TEXT | wimp_ICON_BORDER | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_FILLED | wimp_ICON_INDIRECTED | wimp_BUTTON_WRITABLE + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_WHITE + text.text:"512" + text.size:10 + text.validation:"Pptr_write;Kta;A0-9" + } + wimp_icon { + extent:352,-228,384,-196 + icon_flags:wimp_ICON_TEXT | wimp_ICON_SPRITE | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED | wimp_BUTTON_REPEAT + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text_and_sprite.text:"" + text_and_sprite.size:* + text_and_sprite.validation:"r5;sdown,pdown" + } + wimp_icon { + extent:384,-228,416,-196 + icon_flags:wimp_ICON_TEXT | wimp_ICON_SPRITE | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED | wimp_BUTTON_REPEAT + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text_and_sprite.text:"" + text_and_sprite.size:* + text_and_sprite.validation:"r5;sup,pup" + } + wimp_icon { + extent:424,-232,480,-192 + icon_flags:wimp_ICON_TEXT | wimp_ICON_VCENTRED | wimp_ICON_RJUSTIFIED + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text_only:"MB" + } + wimp_icon { + extent:44,-292,164,-248 + icon_flags:wimp_ICON_TEXT | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED | wimp_ICON_RJUSTIFIED + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text.text:"Expiry" + text.size:13 + text.validation:"" + } + wimp_icon { + extent:168,-296,336,-244 + icon_flags:wimp_ICON_TEXT | wimp_ICON_BORDER | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_FILLED | wimp_ICON_INDIRECTED | wimp_BUTTON_WRITABLE + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_WHITE + text.text:"512" + text.size:10 + text.validation:"Pptr_write;Kta;A0-9" + } + wimp_icon { + extent:352,-288,384,-256 + icon_flags:wimp_ICON_TEXT | wimp_ICON_SPRITE | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED | wimp_BUTTON_REPEAT + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text_and_sprite.text:"" + text_and_sprite.size:* + text_and_sprite.validation:"r5;sdown,pdown" + } + wimp_icon { + extent:384,-288,416,-256 + icon_flags:wimp_ICON_TEXT | wimp_ICON_SPRITE | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED | wimp_BUTTON_REPEAT + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text_and_sprite.text:"" + text_and_sprite.size:* + text_and_sprite.validation:"r5;sup,pup" + } + wimp_icon { + extent:424,-292,500,-252 + icon_flags:wimp_ICON_TEXT | wimp_ICON_VCENTRED | wimp_ICON_RJUSTIFIED + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text_only:"days" + } + wimp_icon { + extent:24,-396,188,-344 icon_flags:wimp_ICON_TEXT | wimp_ICON_BORDER | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_FILLED | wimp_ICON_INDIRECTED | wimp_BUTTON_CLICK icon_esg:0 icon_fg:wimp_COLOUR_BLACK @@ -127,7 +243,7 @@ wimp_window { text.validation:"R5,3" } wimp_icon { - extent:204,-208,368,-156 + extent:204,-396,368,-344 icon_flags:wimp_ICON_TEXT | wimp_ICON_BORDER | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_FILLED | wimp_ICON_INDIRECTED | wimp_BUTTON_CLICK icon_esg:0 icon_fg:wimp_COLOUR_BLACK @@ -137,7 +253,7 @@ wimp_window { text.validation:"R5,3" } wimp_icon { - extent:384,-216,568,-148 + extent:384,-404,568,-336 icon_flags:wimp_ICON_TEXT | wimp_ICON_BORDER | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_FILLED | wimp_ICON_INDIRECTED | wimp_BUTTON_CLICK icon_esg:0 icon_fg:wimp_COLOUR_BLACK @@ -1683,7 +1799,7 @@ wimp_window { icon_fg:wimp_COLOUR_BLACK icon_bg:wimp_COLOUR_WHITE text.text:"" - text.size:128 + text.size:1 text.validation:"Pptr_write;Kta" } wimp_icon { diff --git a/riscos/templates/en b/riscos/templates/en index a943b1e91..fbad63abf 100644 --- a/riscos/templates/en +++ b/riscos/templates/en @@ -28,7 +28,7 @@ wimp_window { wimp_window { template_name:"con_cache" - visible:184,870,772,1110 + visible:184,682,772,1110 xscroll:0 yscroll:0 next:wimp_TOP @@ -41,7 +41,7 @@ wimp_window { scroll_inner:wimp_COLOUR_VERY_LIGHT_GREY highlight_bg:wimp_COLOUR_CREAM extra_flags: - extent:0,-240,588,0 + extent:0,-428,588,0 title_flags:wimp_ICON_TEXT | wimp_ICON_BORDER | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_FILLED work_flags: sprite_area:&1 @@ -117,7 +117,123 @@ wimp_window { text_only:"MB" } wimp_icon { - extent:24,-208,188,-156 + extent:16,-312,568,-152 + icon_flags:wimp_ICON_TEXT | wimp_ICON_BORDER | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text.text:"" + text.size:* + text.validation:"R4" + } + wimp_icon { + extent:32,-180,268,-136 + icon_flags:wimp_ICON_TEXT | wimp_ICON_SPRITE | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text_and_sprite.text:" Disc cache " + text_and_sprite.size:* + text_and_sprite.validation:"" + } + wimp_icon { + extent:44,-232,164,-188 + icon_flags:wimp_ICON_TEXT | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED | wimp_ICON_RJUSTIFIED + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text.text:"Size" + text.size:13 + text.validation:"" + } + wimp_icon { + extent:168,-236,336,-184 + icon_flags:wimp_ICON_TEXT | wimp_ICON_BORDER | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_FILLED | wimp_ICON_INDIRECTED | wimp_BUTTON_WRITABLE + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_WHITE + text.text:"512" + text.size:10 + text.validation:"Pptr_write;Kta;A0-9" + } + wimp_icon { + extent:352,-228,384,-196 + icon_flags:wimp_ICON_TEXT | wimp_ICON_SPRITE | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED | wimp_BUTTON_REPEAT + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text_and_sprite.text:"" + text_and_sprite.size:* + text_and_sprite.validation:"r5;sdown,pdown" + } + wimp_icon { + extent:384,-228,416,-196 + icon_flags:wimp_ICON_TEXT | wimp_ICON_SPRITE | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED | wimp_BUTTON_REPEAT + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text_and_sprite.text:"" + text_and_sprite.size:* + text_and_sprite.validation:"r5;sup,pup" + } + wimp_icon { + extent:424,-232,480,-192 + icon_flags:wimp_ICON_TEXT | wimp_ICON_VCENTRED | wimp_ICON_RJUSTIFIED + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text_only:"MB" + } + wimp_icon { + extent:44,-292,164,-248 + icon_flags:wimp_ICON_TEXT | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED | wimp_ICON_RJUSTIFIED + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text.text:"Expiry" + text.size:13 + text.validation:"" + } + wimp_icon { + extent:168,-296,336,-244 + icon_flags:wimp_ICON_TEXT | wimp_ICON_BORDER | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_FILLED | wimp_ICON_INDIRECTED | wimp_BUTTON_WRITABLE + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_WHITE + text.text:"512" + text.size:10 + text.validation:"Pptr_write;Kta;A0-9" + } + wimp_icon { + extent:352,-288,384,-256 + icon_flags:wimp_ICON_TEXT | wimp_ICON_SPRITE | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED | wimp_BUTTON_REPEAT + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text_and_sprite.text:"" + text_and_sprite.size:* + text_and_sprite.validation:"r5;sdown,pdown" + } + wimp_icon { + extent:384,-288,416,-256 + icon_flags:wimp_ICON_TEXT | wimp_ICON_SPRITE | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED | wimp_BUTTON_REPEAT + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text_and_sprite.text:"" + text_and_sprite.size:* + text_and_sprite.validation:"r5;sup,pup" + } + wimp_icon { + extent:424,-292,500,-252 + icon_flags:wimp_ICON_TEXT | wimp_ICON_VCENTRED | wimp_ICON_RJUSTIFIED + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text_only:"days" + } + wimp_icon { + extent:24,-396,188,-344 icon_flags:wimp_ICON_TEXT | wimp_ICON_BORDER | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_FILLED | wimp_ICON_INDIRECTED | wimp_BUTTON_CLICK icon_esg:0 icon_fg:wimp_COLOUR_BLACK @@ -127,7 +243,7 @@ wimp_window { text.validation:"R5,3" } wimp_icon { - extent:204,-208,368,-156 + extent:204,-396,368,-344 icon_flags:wimp_ICON_TEXT | wimp_ICON_BORDER | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_FILLED | wimp_ICON_INDIRECTED | wimp_BUTTON_CLICK icon_esg:0 icon_fg:wimp_COLOUR_BLACK @@ -137,7 +253,7 @@ wimp_window { text.validation:"R5,3" } wimp_icon { - extent:384,-216,568,-148 + extent:384,-404,568,-336 icon_flags:wimp_ICON_TEXT | wimp_ICON_BORDER | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_FILLED | wimp_ICON_INDIRECTED | wimp_BUTTON_CLICK icon_esg:0 icon_fg:wimp_COLOUR_BLACK @@ -1891,7 +2007,7 @@ wimp_window { icon_fg:wimp_COLOUR_BLACK icon_bg:wimp_COLOUR_WHITE text.text:"" - text.size:128 + text.size:1 text.validation:"Pptr_write;Kta" } wimp_icon { diff --git a/riscos/templates/fr b/riscos/templates/fr index 30bcbfaf5..11612dd5c 100644 --- a/riscos/templates/fr +++ b/riscos/templates/fr @@ -28,7 +28,7 @@ wimp_window { wimp_window { template_name:"con_cache" - visible:564,724,1152,964 + visible:564,536,1152,964 xscroll:0 yscroll:0 next:wimp_TOP @@ -41,7 +41,7 @@ wimp_window { scroll_inner:wimp_COLOUR_VERY_LIGHT_GREY highlight_bg:wimp_COLOUR_CREAM extra_flags: - extent:0,-240,588,0 + extent:0,-428,588,0 title_flags:wimp_ICON_TEXT | wimp_ICON_BORDER | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_FILLED work_flags: sprite_area:&1 @@ -117,7 +117,123 @@ wimp_window { text_only:"MB" } wimp_icon { - extent:24,-208,188,-156 + extent:16,-312,568,-152 + icon_flags:wimp_ICON_TEXT | wimp_ICON_BORDER | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text.text:"" + text.size:* + text.validation:"R4" + } + wimp_icon { + extent:32,-180,268,-136 + icon_flags:wimp_ICON_TEXT | wimp_ICON_SPRITE | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text_and_sprite.text:" Disc cache " + text_and_sprite.size:* + text_and_sprite.validation:"" + } + wimp_icon { + extent:44,-232,164,-188 + icon_flags:wimp_ICON_TEXT | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED | wimp_ICON_RJUSTIFIED + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text.text:"Taille" + text.size:13 + text.validation:"" + } + wimp_icon { + extent:168,-236,336,-184 + icon_flags:wimp_ICON_TEXT | wimp_ICON_BORDER | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_FILLED | wimp_ICON_INDIRECTED | wimp_BUTTON_WRITABLE + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_WHITE + text.text:"512" + text.size:10 + text.validation:"Pptr_write;Kta;A0-9" + } + wimp_icon { + extent:352,-228,384,-196 + icon_flags:wimp_ICON_TEXT | wimp_ICON_SPRITE | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED | wimp_BUTTON_REPEAT + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text_and_sprite.text:"" + text_and_sprite.size:* + text_and_sprite.validation:"r5;sdown,pdown" + } + wimp_icon { + extent:384,-228,416,-196 + icon_flags:wimp_ICON_TEXT | wimp_ICON_SPRITE | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED | wimp_BUTTON_REPEAT + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text_and_sprite.text:"" + text_and_sprite.size:* + text_and_sprite.validation:"r5;sup,pup" + } + wimp_icon { + extent:424,-232,480,-192 + icon_flags:wimp_ICON_TEXT | wimp_ICON_VCENTRED | wimp_ICON_RJUSTIFIED + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text_only:"MB" + } + wimp_icon { + extent:44,-292,164,-248 + icon_flags:wimp_ICON_TEXT | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED | wimp_ICON_RJUSTIFIED + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text.text:"Expiry" + text.size:13 + text.validation:"" + } + wimp_icon { + extent:168,-296,336,-244 + icon_flags:wimp_ICON_TEXT | wimp_ICON_BORDER | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_FILLED | wimp_ICON_INDIRECTED | wimp_BUTTON_WRITABLE + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_WHITE + text.text:"512" + text.size:10 + text.validation:"Pptr_write;Kta;A0-9" + } + wimp_icon { + extent:352,-288,384,-256 + icon_flags:wimp_ICON_TEXT | wimp_ICON_SPRITE | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED | wimp_BUTTON_REPEAT + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text_and_sprite.text:"" + text_and_sprite.size:* + text_and_sprite.validation:"r5;sdown,pdown" + } + wimp_icon { + extent:384,-288,416,-256 + icon_flags:wimp_ICON_TEXT | wimp_ICON_SPRITE | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED | wimp_BUTTON_REPEAT + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text_and_sprite.text:"" + text_and_sprite.size:* + text_and_sprite.validation:"r5;sup,pup" + } + wimp_icon { + extent:424,-292,500,-252 + icon_flags:wimp_ICON_TEXT | wimp_ICON_VCENTRED | wimp_ICON_RJUSTIFIED + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text_only:"days" + } + wimp_icon { + extent:24,-396,188,-344 icon_flags:wimp_ICON_TEXT | wimp_ICON_BORDER | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_FILLED | wimp_ICON_INDIRECTED | wimp_BUTTON_CLICK icon_esg:0 icon_fg:wimp_COLOUR_BLACK @@ -127,7 +243,7 @@ wimp_window { text.validation:"R5,3" } wimp_icon { - extent:204,-208,368,-156 + extent:204,-396,368,-344 icon_flags:wimp_ICON_TEXT | wimp_ICON_BORDER | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_FILLED | wimp_ICON_INDIRECTED | wimp_BUTTON_CLICK icon_esg:0 icon_fg:wimp_COLOUR_BLACK @@ -137,7 +253,7 @@ wimp_window { text.validation:"R5,3" } wimp_icon { - extent:384,-216,568,-148 + extent:384,-404,568,-336 icon_flags:wimp_ICON_TEXT | wimp_ICON_BORDER | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_FILLED | wimp_ICON_INDIRECTED | wimp_BUTTON_CLICK icon_esg:0 icon_fg:wimp_COLOUR_BLACK @@ -1695,7 +1811,7 @@ wimp_window { icon_fg:wimp_COLOUR_BLACK icon_bg:wimp_COLOUR_WHITE text.text:"" - text.size:128 + text.size:1 text.validation:"Pptr_write;Kta" } wimp_icon { diff --git a/riscos/templates/nl b/riscos/templates/nl index dcc8af5f4..adef82198 100644 --- a/riscos/templates/nl +++ b/riscos/templates/nl @@ -28,7 +28,7 @@ wimp_window { wimp_window { template_name:"con_cache" - visible:184,870,772,1110 + visible:184,682,772,1110 xscroll:0 yscroll:0 next:wimp_TOP @@ -41,7 +41,7 @@ wimp_window { scroll_inner:wimp_COLOUR_VERY_LIGHT_GREY highlight_bg:wimp_COLOUR_CREAM extra_flags: - extent:0,-240,588,0 + extent:0,-428,588,0 title_flags:wimp_ICON_TEXT | wimp_ICON_BORDER | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_FILLED work_flags: sprite_area:&1 @@ -69,7 +69,7 @@ wimp_window { text_and_sprite.validation:"" } wimp_icon { - extent:44,-104,164,-60 + extent:40,-104,164,-60 icon_flags:wimp_ICON_TEXT | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED | wimp_ICON_RJUSTIFIED icon_esg:0 icon_fg:wimp_COLOUR_BLACK @@ -117,7 +117,123 @@ wimp_window { text_only:"MB" } wimp_icon { - extent:24,-208,188,-156 + extent:16,-312,568,-152 + icon_flags:wimp_ICON_TEXT | wimp_ICON_BORDER | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text.text:"" + text.size:* + text.validation:"R4" + } + wimp_icon { + extent:32,-180,268,-136 + icon_flags:wimp_ICON_TEXT | wimp_ICON_SPRITE | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text_and_sprite.text:" Disc cache " + text_and_sprite.size:* + text_and_sprite.validation:"" + } + wimp_icon { + extent:40,-232,164,-188 + icon_flags:wimp_ICON_TEXT | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED | wimp_ICON_RJUSTIFIED + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text.text:"Omvang" + text.size:13 + text.validation:"" + } + wimp_icon { + extent:168,-236,336,-184 + icon_flags:wimp_ICON_TEXT | wimp_ICON_BORDER | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_FILLED | wimp_ICON_INDIRECTED | wimp_BUTTON_WRITABLE + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_WHITE + text.text:"512" + text.size:10 + text.validation:"Pptr_write;Kta;A0-9" + } + wimp_icon { + extent:352,-228,384,-196 + icon_flags:wimp_ICON_TEXT | wimp_ICON_SPRITE | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED | wimp_BUTTON_REPEAT + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text_and_sprite.text:"" + text_and_sprite.size:* + text_and_sprite.validation:"r5;sdown,pdown" + } + wimp_icon { + extent:384,-228,416,-196 + icon_flags:wimp_ICON_TEXT | wimp_ICON_SPRITE | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED | wimp_BUTTON_REPEAT + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text_and_sprite.text:"" + text_and_sprite.size:* + text_and_sprite.validation:"r5;sup,pup" + } + wimp_icon { + extent:424,-232,480,-192 + icon_flags:wimp_ICON_TEXT | wimp_ICON_VCENTRED | wimp_ICON_RJUSTIFIED + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text_only:"MB" + } + wimp_icon { + extent:44,-292,164,-248 + icon_flags:wimp_ICON_TEXT | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED | wimp_ICON_RJUSTIFIED + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text.text:"Expiry" + text.size:13 + text.validation:"" + } + wimp_icon { + extent:168,-296,336,-244 + icon_flags:wimp_ICON_TEXT | wimp_ICON_BORDER | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_FILLED | wimp_ICON_INDIRECTED | wimp_BUTTON_WRITABLE + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_WHITE + text.text:"512" + text.size:10 + text.validation:"Pptr_write;Kta;A0-9" + } + wimp_icon { + extent:352,-288,384,-256 + icon_flags:wimp_ICON_TEXT | wimp_ICON_SPRITE | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED | wimp_BUTTON_REPEAT + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text_and_sprite.text:"" + text_and_sprite.size:* + text_and_sprite.validation:"r5;sdown,pdown" + } + wimp_icon { + extent:384,-288,416,-256 + icon_flags:wimp_ICON_TEXT | wimp_ICON_SPRITE | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_INDIRECTED | wimp_BUTTON_REPEAT + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text_and_sprite.text:"" + text_and_sprite.size:* + text_and_sprite.validation:"r5;sup,pup" + } + wimp_icon { + extent:424,-292,500,-252 + icon_flags:wimp_ICON_TEXT | wimp_ICON_VCENTRED | wimp_ICON_RJUSTIFIED + icon_esg:0 + icon_fg:wimp_COLOUR_BLACK + icon_bg:wimp_COLOUR_VERY_LIGHT_GREY + text_only:"days" + } + wimp_icon { + extent:24,-396,188,-344 icon_flags:wimp_ICON_TEXT | wimp_ICON_BORDER | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_FILLED | wimp_ICON_INDIRECTED | wimp_BUTTON_CLICK icon_esg:0 icon_fg:wimp_COLOUR_BLACK @@ -127,7 +243,7 @@ wimp_window { text.validation:"R5,3" } wimp_icon { - extent:204,-208,368,-156 + extent:204,-396,368,-344 icon_flags:wimp_ICON_TEXT | wimp_ICON_BORDER | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_FILLED | wimp_ICON_INDIRECTED | wimp_BUTTON_CLICK icon_esg:0 icon_fg:wimp_COLOUR_BLACK @@ -137,7 +253,7 @@ wimp_window { text.validation:"R5,3" } wimp_icon { - extent:384,-216,568,-148 + extent:384,-404,568,-336 icon_flags:wimp_ICON_TEXT | wimp_ICON_BORDER | wimp_ICON_HCENTRED | wimp_ICON_VCENTRED | wimp_ICON_FILLED | wimp_ICON_INDIRECTED | wimp_BUTTON_CLICK icon_esg:0 icon_fg:wimp_COLOUR_BLACK @@ -1895,7 +2011,7 @@ wimp_window { icon_fg:wimp_COLOUR_BLACK icon_bg:wimp_COLOUR_WHITE text.text:"" - text.size:128 + text.size:1 text.validation:"Pptr_write;Kta" } wimp_icon { diff --git a/riscos/textarea.c b/riscos/textarea.c index 86774fad4..303b7e771 100644 --- a/riscos/textarea.c +++ b/riscos/textarea.c @@ -24,13 +24,17 @@ #include <stdbool.h> #include <stdint.h> #include <string.h> -#include "swis.h" -#include "oslib/colourtrans.h" -#include "oslib/osbyte.h" -#include "oslib/serviceinternational.h" -#include "oslib/wimp.h" -#include "oslib/wimpspriteop.h" -#include "rufl.h" +#include <swis.h> +#include <oslib/colourtrans.h> +#include <oslib/osbyte.h> +#include <oslib/serviceinternational.h> +#include <oslib/wimp.h> +#include <oslib/wimpspriteop.h> + +#include "utils/log.h" +#include "utils/utf8.h" +#include "desktop/browser.h" + #include "riscos/gui.h" #include "riscos/oslib_pre7.h" #include "riscos/textarea.h" @@ -38,8 +42,6 @@ #include "riscos/wimp.h" #include "riscos/wimp_event.h" #include "riscos/wimputils.h" -#include "utils/log.h" -#include "utils/utf8.h" #define MARGIN_LEFT 8 #define MARGIN_RIGHT 8 @@ -909,11 +911,8 @@ bool ro_textarea_key_press(wimp_key *key) uint32_t c = (uint32_t) key->c; wimp_key keypress; struct text_area *ta; - char utf8[7]; - size_t utf8_len; bool redraw = false; unsigned int c_pos; - os_error *error; ta = (struct text_area *)ro_gui_wimp_event_get_user_data(key->w); @@ -923,6 +922,9 @@ bool ro_textarea_key_press(wimp_key *key) if (!(c & IS_WIMP_KEY || (c <= 0x001f || (0x007f <= c && c <= 0x009f)))) { /* normal character - insert */ + char utf8[7]; + size_t utf8_len; + utf8_len = utf8_from_ucs4(c, utf8); utf8[utf8_len] = '\0'; @@ -932,6 +934,7 @@ bool ro_textarea_key_press(wimp_key *key) redraw = true; } else { + os_error *error; /** \todo handle command keys */ switch (c & ~IS_WIMP_KEY) { case 8: /* Backspace */ @@ -1065,8 +1068,7 @@ void ro_textarea_redraw(wimp_draw *redraw) void ro_textarea_redraw_internal(wimp_draw *redraw, bool update) { struct text_area *ta; - int clip_x0, clip_y0, clip_x1, clip_y1; - int line0, line1, line; + int line; osbool more; rufl_code code; os_error *error; @@ -1084,9 +1086,9 @@ void ro_textarea_redraw_internal(wimp_draw *redraw, bool update) } while (more) { - clip_x0 = redraw->clip.x0 - (redraw->box.x0-redraw->xscroll); + int line0, line1; + int clip_y0, clip_y1; clip_y0 = (redraw->box.y1-redraw->yscroll) - redraw->clip.y1; - clip_x1 = redraw->clip.x1 - (redraw->box.x0-redraw->xscroll); clip_y1 = (redraw->box.y1-redraw->yscroll) - redraw->clip.y0; error = xcolourtrans_set_gcol( diff --git a/riscos/textselection.c b/riscos/textselection.c index ab8ea5c3a..f002e0773 100644 --- a/riscos/textselection.c +++ b/riscos/textselection.c @@ -25,25 +25,29 @@ #include <string.h> #include "oslib/osfile.h" #include "oslib/wimp.h" + +#include "utils/log.h" +#include "utils/utf8.h" +#include "utils/utils.h" #include "content/hlcache.h" #include "desktop/gui.h" #include "desktop/textinput.h" +#include "desktop/browser.h" + #include "riscos/gui.h" #include "riscos/menus.h" #include "riscos/message.h" #include "riscos/mouse.h" #include "riscos/save.h" #include "riscos/textselection.h" -#include "utils/log.h" -#include "utils/utf8.h" -#include "utils/utils.h" +#include "riscos/ucstables.h" + #ifndef wimp_DRAG_CLAIM_SUPPRESS_DRAGBOX #define wimp_DRAG_CLAIM_SUPPRESS_DRAGBOX ((wimp_drag_claim_flags) 0x2u) #endif - /** Receive of Dragging message has claimed it */ static bool dragging_claimed = false; static wimp_t dragging_claimant; @@ -186,20 +190,6 @@ static void ro_gui_selection_drag_end(wimp_dragged *drag, void *data) browser_window_mouse_track(g->bw, 0, pos.x, pos.y); } - -/** - * Perform tasks after a selection has been cleared. - * - * \param g gui window - */ - -void gui_clear_selection(struct gui_window *g) -{ - /* Refresh any open menu, in case it's the browser window menu. */ - ro_gui_menu_refresh(0); -} - - /** * Core tells front end to put given text in clipboard * @@ -208,7 +198,7 @@ void gui_clear_selection(struct gui_window *g) * \param styles Array of styles given to text runs, owned by core, or NULL * \param n_styles Number of text run styles in array */ -void gui_set_clipboard(const char *buffer, size_t length, +static void gui_set_clipboard(const char *buffer, size_t length, nsclipboard_styles styles[], int n_styles) { char *new_cb; @@ -259,7 +249,7 @@ void gui_set_clipboard(const char *buffer, size_t length, * \param buffer UTF-8 text, allocated by front end, ownership yielded to core * \param length Byte length of UTF-8 text in buffer */ -void gui_get_clipboard(char **buffer, size_t *length) +static void gui_get_clipboard(char **buffer, size_t *length) { *buffer = NULL; *length = 0; @@ -403,9 +393,6 @@ bool ro_gui_selection_prepare_paste_dataload( wimp_full_message_data_xfer *dataxfer) { FILE *fp; - long size; - char *local_cb; - utf8_convert_ret ret; /* Ignore messages that aren't for us */ if (dataxfer->your_ref == 0 || dataxfer->your_ref != paste_prev_message) @@ -413,18 +400,20 @@ bool ro_gui_selection_prepare_paste_dataload( fp = fopen(dataxfer->file_name, "r"); if (fp != NULL) { + long size; fseek(fp, 0, SEEK_END); size = ftell(fp); fseek(fp, 0, SEEK_SET); if (size > 0) { - local_cb = malloc(size); + char *local_cb = malloc(size); if (local_cb != NULL) { + nserror ret; fread(local_cb, 1, size, fp); ret = utf8_from_local_encoding(local_cb, size, &clipboard); - if (ret == UTF8_CONVERT_OK) { + if (ret == NSERROR_OK) { clip_length = strlen(clipboard); } @@ -523,13 +512,13 @@ void ro_gui_selection_data_request(wimp_full_message_data_request *req) bool ro_gui_save_clipboard(const char *path) { char *local_cb; - utf8_convert_ret ret; + nserror ret; os_error *error; assert(clip_length > 0 && clipboard); ret = utf8_to_local_encoding(clipboard, clip_length, &local_cb); - if (ret != UTF8_CONVERT_OK) { + if (ret != NSERROR_OK) { warn_user("SaveError", "Could not convert"); return false; } @@ -666,3 +655,10 @@ void ro_gui_dragging_bounced(wimp_message *message) { dragging_claimed = false; } + +static struct gui_clipboard_table clipboard_table = { + .get = gui_get_clipboard, + .set = gui_set_clipboard, +}; + +struct gui_clipboard_table *riscos_clipboard_table = &clipboard_table; diff --git a/riscos/textselection.h b/riscos/textselection.h index c6f96f0e9..400e3dd26 100644 --- a/riscos/textselection.h +++ b/riscos/textselection.h @@ -24,7 +24,10 @@ #define _NETSURF_RISCOS_TEXTSELECTION_H_ #include "oslib/wimp.h" -#include "desktop/gui.h" + +struct gui_clipboard_table *riscos_clipboard_table; + +void gui_start_selection(struct gui_window *g); typedef void (*ro_gui_selection_prepare_paste_cb)(void *pw); diff --git a/riscos/theme.c b/riscos/theme.c index f1b7ae249..a12ed926d 100644 --- a/riscos/theme.c +++ b/riscos/theme.c @@ -176,11 +176,10 @@ static void ro_gui_theme_get_available_in_dir(const char *directory) int context = 0; int read_count; osgbpb_INFO(100) info; - os_error *error; while (context != -1) { /* read some directory info */ - error = xosgbpb_dir_entries_info(directory, + os_error *error = xosgbpb_dir_entries_info(directory, (osgbpb_info_list *) &info, 1, context, sizeof(info), 0, &read_count, &context); if (error) { diff --git a/riscos/theme_install.c b/riscos/theme_install.c index 0d436dce8..f29596c88 100644 --- a/riscos/theme_install.c +++ b/riscos/theme_install.c @@ -22,20 +22,22 @@ #include <assert.h> #include <stdbool.h> -#include "oslib/osfile.h" +#include <oslib/osfile.h> +#include <oslib/wimp.h> + +#include "utils/nsoption.h" +#include "utils/log.h" +#include "utils/messages.h" +#include "utils/utils.h" #include "content/content.h" #include "content/hlcache.h" #include "desktop/browser.h" + #include "riscos/dialog.h" #include "riscos/gui.h" -#include "utils/nsoption.h" #include "riscos/theme.h" #include "riscos/wimp.h" #include "riscos/wimp_event.h" -#include "utils/log.h" -#include "utils/messages.h" -#include "utils/url.h" -#include "utils/utils.h" static hlcache_handle *theme_install_content = NULL; @@ -85,17 +87,14 @@ void theme_install_start(hlcache_handle *c) nserror theme_install_callback(hlcache_handle *handle, const hlcache_event *event, void *pw) { - char buffer[256]; - int author_indent = 0; - switch (event->type) { - case CONTENT_MSG_READY: - break; case CONTENT_MSG_DONE: { const char *source_data; unsigned long source_size; + int author_indent = 0; + char buffer[256]; theme_install_content = handle; @@ -129,11 +128,7 @@ nserror theme_install_callback(hlcache_handle *handle, warn_user(event->data.error, 0); break; - case CONTENT_MSG_STATUS: - break; - default: - assert(0); break; } diff --git a/riscos/thumbnail.c b/riscos/thumbnail.c index 66864554b..2bdd37251 100644 --- a/riscos/thumbnail.c +++ b/riscos/thumbnail.c @@ -85,7 +85,6 @@ bool thumbnail_create(hlcache_handle *content, struct bitmap *bitmap, struct thumbnail_save_area *save_area; osspriteop_area *sprite_area = NULL; osspriteop_header *sprite_header = NULL; - _kernel_oserror *error; struct redraw_context ctx = { .interactive = false, .background_images = true, @@ -137,6 +136,8 @@ bool thumbnail_create(hlcache_handle *content, struct bitmap *bitmap, /* if we changed to 8bpp then go back to 32bpp */ if (thumbnail_32bpp_available != 1) { const uint8_t *pixbufp = bitmap_get_buffer(bitmap); + _kernel_oserror *error; + if (!pixbufp || !bitmap->sprite_area) { free(sprite_area); return false; diff --git a/riscos/toolbar.c b/riscos/toolbar.c index 93c4438c3..bd76e23de 100644 --- a/riscos/toolbar.c +++ b/riscos/toolbar.c @@ -593,8 +593,6 @@ bool ro_toolbar_process(struct toolbar *toolbar, int width, bool reformat) wimp_window_state state; os_box extent; int old_height, old_width; - int xeig, yeig; - os_coord pixel = {1, 1}; if (!toolbar) return false; @@ -602,12 +600,6 @@ bool ro_toolbar_process(struct toolbar *toolbar, int width, bool reformat) old_height = toolbar->current_height; old_width = toolbar->current_width; - /* calculate 1px in OS units */ - - ro_convert_pixels_to_os_units(&pixel, (os_mode)-1); - xeig = pixel.x; - yeig = pixel.y; - /* Measure the parent window width if the caller has asked us to * calculate the clip width ourselves. Otherwise, if a clip width * has been specified, set the clip to that. @@ -847,8 +839,8 @@ void ro_toolbar_refresh_widget_dimensions(struct toolbar *toolbar) toolbar->full_height = 0; } toolbar->full_width = 2 * TOOLBAR_WIDGET_GUTTER + - (row_width > toolbar->editor_size.x) ? - row_width : toolbar->editor_size.x; + ((row_width > toolbar->editor_size.x) ? + row_width : toolbar->editor_size.x); } @@ -1579,7 +1571,7 @@ bool ro_toolbar_set_button_order(struct toolbar *toolbar, char order[]) void ro_toolbar_set_button_shaded_state(struct toolbar *toolbar, button_bar_action action, bool shaded) { - if (toolbar == NULL && toolbar->buttons == NULL) + if (toolbar == NULL || toolbar->buttons == NULL) return; ro_gui_button_bar_shade_button(toolbar->buttons, action, shaded); @@ -1686,7 +1678,7 @@ void ro_toolbar_set_content_favicon(struct toolbar *toolbar, void ro_toolbar_update_urlsuggest(struct toolbar *toolbar) { - if (toolbar != NULL && toolbar->url != NULL) + if (toolbar == NULL || toolbar->url == NULL) return; ro_gui_url_bar_update_urlsuggest(toolbar->url); @@ -1774,8 +1766,6 @@ bool ro_toolbar_get_editing(struct toolbar *toolbar) bool ro_toolbar_toggle_edit(struct toolbar *toolbar) { - char *new_buttons; - if (toolbar == NULL || toolbar->editor == NULL) return false; @@ -1799,6 +1789,7 @@ bool ro_toolbar_toggle_edit(struct toolbar *toolbar) if (!toolbar->editing && toolbar->buttons != NULL && toolbar->callbacks != NULL && toolbar->callbacks->save_buttons != NULL) { + char *new_buttons; new_buttons = ro_gui_button_bar_get_config(toolbar->buttons); toolbar->callbacks->save_buttons(toolbar->client_data, new_buttons); diff --git a/riscos/treeview.c b/riscos/treeview.c index 4cf3d425e..d33704c8d 100644 --- a/riscos/treeview.c +++ b/riscos/treeview.c @@ -427,7 +427,6 @@ void ro_treeview_scroll(wimp_scroll *scroll) void ro_treeview_redraw_loop(wimp_draw *redraw, ro_treeview *tv, osbool more) { - os_error *error; struct redraw_context ctx = { .interactive = true, .background_images = true, @@ -435,14 +434,16 @@ void ro_treeview_redraw_loop(wimp_draw *redraw, ro_treeview *tv, osbool more) }; while (more) { - ro_plot_origin_x = redraw->box.x0 + tv->origin.x - - redraw->xscroll; - ro_plot_origin_y = redraw->box.y1 + tv->origin.y - - redraw->yscroll; + os_error *error; if (tv != NULL && tv->tree != NULL) { struct rect clip; + ro_plot_origin_x = redraw->box.x0 + tv->origin.x - + redraw->xscroll; + ro_plot_origin_y = redraw->box.y1 + tv->origin.y - + redraw->yscroll; + clip.x0 = (redraw->clip.x0 - ro_plot_origin_x) / 2; clip.y0 = (ro_plot_origin_y - redraw->clip.y1) / 2; @@ -610,7 +611,6 @@ void ro_treeview_set_window_extent(ro_treeview *tv, int width, int height) wimp_window_state state; int new_x, new_y; int visible_x, visible_y; - int new_x_scroll, new_y_scroll; /* Calculate the new window extents, in RISC OS units. */ @@ -657,8 +657,8 @@ void ro_treeview_set_window_extent(ro_treeview *tv, int width, int height) if ((state.flags & wimp_WINDOW_OPEN) && (visible_x > new_x || visible_y < new_y)) { - new_x_scroll = state.xscroll; - new_y_scroll = state.yscroll; + int new_x_scroll = state.xscroll; + int new_y_scroll = state.yscroll; if (visible_x > new_x) new_x_scroll = new_x - (state.visible.x1 diff --git a/riscos/ucstables.c b/riscos/ucstables.c index 970caf122..f9b6b3648 100644 --- a/riscos/ucstables.c +++ b/riscos/ucstables.c @@ -27,10 +27,13 @@ #include <oslib/territory.h> #include "utils/config.h" -#include "riscos/ucstables.h" +#include "utils/errors.h" #include "utils/log.h" #include "utils/utf8.h" #include "utils/utils.h" +#include "desktop/gui.h" + +#include "riscos/ucstables.h" /* Common values (ASCII) */ #define common \ @@ -446,17 +449,16 @@ static const struct special { * \param string The string to convert * \param len The length (in bytes) of the string, or 0 * \param result Pointer to location in which to store result - * \return The appropriate utf8_convert_ret value + * \return An nserror code */ -utf8_convert_ret utf8_to_local_encoding(const char *string, size_t len, - char **result) +nserror utf8_to_local_encoding(const char *string, size_t len, char **result) { os_error *error; int alphabet, i; size_t off, prev_off; char *temp, *cur_pos; const char *enc; - utf8_convert_ret err; + nserror err; assert(string); assert(result); @@ -473,19 +475,19 @@ utf8_convert_ret utf8_to_local_encoding(const char *string, size_t len, /* UTF-8 -> simply copy string */ if (alphabet == 111 /* UTF-8 */) { *result = strndup(string, len); - return UTF8_CONVERT_OK; + return NSERROR_OK; } /* get encoding name */ enc = (alphabet <= CONT_ENC_END ? localencodings[alphabet - 100] : (alphabet == 120 ? - localencodings[CONT_ENC_END + 1] + localencodings[CONT_ENC_END - 100 + 1] : localencodings[0])); /* create output buffer */ *(result) = malloc(len + 1); if (!(*result)) - return UTF8_CONVERT_NOMEM; + return NSERROR_NOMEM; *(*result) = '\0'; prev_off = 0; @@ -508,10 +510,10 @@ utf8_convert_ret utf8_to_local_encoding(const char *string, size_t len, if (off - prev_off > 0) { err = utf8_to_enc(string + prev_off, enc, off - prev_off, &temp); - if (err != UTF8_CONVERT_OK) { - assert(err != UTF8_CONVERT_BADENC); + if (err != NSERROR_OK) { + assert(err != NSERROR_BAD_ENCODING); free(*result); - return UTF8_CONVERT_NOMEM; + return NSERROR_NOMEM; } strcat(cur_pos, temp); @@ -533,10 +535,10 @@ utf8_convert_ret utf8_to_local_encoding(const char *string, size_t len, if (prev_off < len) { err = utf8_to_enc(string + prev_off, enc, len - prev_off, &temp); - if (err != UTF8_CONVERT_OK) { - assert(err != UTF8_CONVERT_BADENC); + if (err != NSERROR_OK) { + assert(err != NSERROR_BAD_ENCODING); free(*result); - return UTF8_CONVERT_NOMEM; + return NSERROR_NOMEM; } strcat(cur_pos, temp); @@ -544,7 +546,7 @@ utf8_convert_ret utf8_to_local_encoding(const char *string, size_t len, free(temp); } - return UTF8_CONVERT_OK; + return NSERROR_OK; } /** @@ -553,10 +555,9 @@ utf8_convert_ret utf8_to_local_encoding(const char *string, size_t len, * \param string The string to convert * \param len The length (in bytes) of the string, or 0 * \param result Pointer to location in which to store result - * \return The appropriate utf8_convert_ret value + * \return An nserror code */ -utf8_convert_ret utf8_from_local_encoding(const char *string, size_t len, - char **result) +nserror utf8_from_local_encoding(const char *string, size_t len, char **result) { os_error *error; int alphabet, i, num_specials = 0, result_alloc; @@ -564,7 +565,7 @@ utf8_convert_ret utf8_from_local_encoding(const char *string, size_t len, size_t off, prev_off, cur_off; char *temp; const char *enc; - utf8_convert_ret err; + nserror err; assert(string && result); @@ -581,16 +582,16 @@ utf8_convert_ret utf8_from_local_encoding(const char *string, size_t len, if (alphabet == 111 /* UTF-8 */) { temp = strndup(string, len); if (!temp) - return UTF8_CONVERT_NOMEM; + return NSERROR_NOMEM; *result = temp; - return UTF8_CONVERT_OK; + return NSERROR_OK; } /* get encoding name */ enc = (alphabet <= CONT_ENC_END ? localencodings[alphabet - 100] : (alphabet == 120 ? - localencodings[CONT_ENC_END + 1] + localencodings[CONT_ENC_END - 100 + 1] : localencodings[0])); /* create output buffer (oversized) */ @@ -598,7 +599,7 @@ utf8_convert_ret utf8_from_local_encoding(const char *string, size_t len, *(result) = malloc(result_alloc); if (!(*result)) - return UTF8_CONVERT_NOMEM; + return NSERROR_NOMEM; *(*result) = '\0'; prev_off = 0; @@ -619,11 +620,11 @@ utf8_convert_ret utf8_from_local_encoding(const char *string, size_t len, if (off - prev_off > 0) { err = utf8_from_enc(string + prev_off, enc, off - prev_off, &temp, NULL); - if (err != UTF8_CONVERT_OK) { - assert(err != UTF8_CONVERT_BADENC); + if (err != NSERROR_OK) { + assert(err != NSERROR_BAD_ENCODING); LOG(("utf8_from_enc failed")); free(*result); - return UTF8_CONVERT_NOMEM; + return NSERROR_NOMEM; } strcat((*result) + cur_off, temp); @@ -647,7 +648,7 @@ utf8_convert_ret utf8_from_local_encoding(const char *string, size_t len, (3 * SPECIAL_CHUNK_SIZE)); if (!temp) { free(*result); - return UTF8_CONVERT_NOMEM; + return NSERROR_NOMEM; } *result = temp; @@ -661,11 +662,11 @@ utf8_convert_ret utf8_from_local_encoding(const char *string, size_t len, if (prev_off < len) { err = utf8_from_enc(string + prev_off, enc, len - prev_off, &temp, NULL); - if (err != UTF8_CONVERT_OK) { - assert(err != UTF8_CONVERT_BADENC); + if (err != NSERROR_OK) { + assert(err != NSERROR_BAD_ENCODING); LOG(("utf8_from_enc failed")); free(*result); - return UTF8_CONVERT_NOMEM; + return NSERROR_NOMEM; } strcat((*result) + cur_off, temp); @@ -680,9 +681,16 @@ utf8_convert_ret utf8_from_local_encoding(const char *string, size_t len, if (!temp) { LOG(("realloc failed")); free(*result); - return UTF8_CONVERT_NOMEM; + return NSERROR_NOMEM; } *result = temp; - return UTF8_CONVERT_OK; + return NSERROR_OK; } + +static struct gui_utf8_table utf8_table = { + .utf8_to_local = utf8_to_local_encoding, + .local_to_utf8 = utf8_from_local_encoding, +}; + +struct gui_utf8_table *riscos_utf8_table = &utf8_table; diff --git a/riscos/ucstables.h b/riscos/ucstables.h index 0be065897..e5d838249 100644 --- a/riscos/ucstables.h +++ b/riscos/ucstables.h @@ -21,4 +21,9 @@ * This is only used if nothing claims Service_International,8 */ +struct gui_utf8_table *riscos_utf8_table; + +nserror utf8_to_local_encoding(const char *string, size_t len, char **result); +nserror utf8_from_local_encoding(const char *string, size_t len, char **result); + const int *ucstable_from_alphabet(int alphabet); diff --git a/riscos/uri.c b/riscos/uri.c index 70f75bc09..bf789ee17 100644 --- a/riscos/uri.c +++ b/riscos/uri.c @@ -74,8 +74,7 @@ void ro_uri_message_received(wimp_message *msg) error = nsurl_create(uri_requested, &url); free(uri_requested); if (error == NSERROR_OK) { - error = browser_window_create(BROWSER_WINDOW_VERIFIABLE | - BROWSER_WINDOW_HISTORY, + error = browser_window_create(BW_CREATE_HISTORY, url, NULL, NULL, diff --git a/riscos/url_complete.c b/riscos/url_complete.c index 01774f62f..6881de7ea 100644 --- a/riscos/url_complete.c +++ b/riscos/url_complete.c @@ -25,19 +25,23 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include "oslib/wimp.h" -#include "content/urldb.h" +#include <oslib/wimp.h> + #include "utils/log.h" +#include "utils/nsoption.h" +#include "utils/utils.h" +#include "content/urldb.h" +#include "desktop/browser.h" + #include "riscos/global_history.h" #include "riscos/gui.h" #include "riscos/mouse.h" -#include "utils/nsoption.h" #include "riscos/toolbar.h" #include "riscos/url_complete.h" #include "riscos/wimp.h" #include "riscos/wimp_event.h" #include "riscos/wimputils.h" -#include "utils/utils.h" +#include "riscos/filetype.h" #define MAXIMUM_VISIBLE_LINES 7 @@ -96,7 +100,6 @@ bool ro_gui_url_complete_keypress(struct toolbar *toolbar, uint32_t key) wimp_window_state state; char *match_url; const char *url; - int i, lines; int old_selection; int height; os_error *error; @@ -144,7 +147,8 @@ bool ro_gui_url_complete_keypress(struct toolbar *toolbar, uint32_t key) (strcmp(match_url, url_complete_matched_string))) { /* memorize the current matches */ - lines = MAXIMUM_VISIBLE_LINES; + int i; + int lines = MAXIMUM_VISIBLE_LINES; if (lines > url_complete_matches_available) lines = url_complete_matches_available; if (url_complete_matches) { @@ -528,8 +532,7 @@ void ro_gui_url_complete_redraw(wimp_draw *redraw) { osbool more; os_error *error; - int clip_y0, clip_y1, origin_y; - int first_line, last_line, line; + int line; const struct url_data *data; int type; @@ -564,9 +567,10 @@ void ro_gui_url_complete_redraw(wimp_draw *redraw) /* redraw */ more = wimp_redraw_window(redraw); while (more) { - origin_y = redraw->box.y1 - redraw->yscroll; - clip_y0 = redraw->clip.y0 - origin_y; - clip_y1 = redraw->clip.y1 - origin_y; + int first_line, last_line; + int origin_y = redraw->box.y1 - redraw->yscroll; + int clip_y0 = redraw->clip.y0 - origin_y; + int clip_y1 = redraw->clip.y1 - origin_y; first_line = (-clip_y1) / 44; last_line = (-clip_y0 + 43) / 44; @@ -656,9 +660,8 @@ bool ro_gui_url_complete_click(wimp_pointer *pointer) { wimp_window_state state; os_error *error; - int selection, old_selection; + int selection; struct gui_window *g; - const char *url; if ((mouse_x == pointer->pos.x) && (mouse_y == pointer->pos.y) && (!pointer->buttons)) @@ -678,7 +681,11 @@ bool ro_gui_url_complete_click(wimp_pointer *pointer) selection = (state.visible.y1 - pointer->pos.y - state.yscroll) / 44; if (selection != url_complete_matches_selection) { + int old_selection; + if (url_complete_matches_selection == -1) { + const char *url; + g = ro_gui_window_lookup(url_complete_parent); if (!g) return false; @@ -734,8 +741,7 @@ bool ro_gui_url_complete_click(wimp_pointer *pointer) browser_window_navigate(g->bw, url_complete_matches[url_complete_matches_selection], NULL, - BROWSER_WINDOW_HISTORY | - BROWSER_WINDOW_VERIFIABLE, + BW_NAVIGATE_HISTORY, NULL, NULL, NULL); diff --git a/riscos/url_protocol.c b/riscos/url_protocol.c index 171b6205f..76d403147 100644 --- a/riscos/url_protocol.c +++ b/riscos/url_protocol.c @@ -126,8 +126,7 @@ void ro_url_message_received(wimp_message *message) } /* create new browser window */ - errorns = browser_window_create(BROWSER_WINDOW_VERIFIABLE | - BROWSER_WINDOW_HISTORY, + errorns = browser_window_create(BW_CREATE_HISTORY, nsurl, NULL, NULL, diff --git a/riscos/url_suggest.c b/riscos/url_suggest.c index 32e772cca..78cde5cfb 100644 --- a/riscos/url_suggest.c +++ b/riscos/url_suggest.c @@ -21,9 +21,13 @@ */ #include <assert.h> +#include <string.h> +#include <stdlib.h> + #include "oslib/wimp.h" #include "content/content_type.h" #include "content/urldb.h" + #include "riscos/menus.h" #include "riscos/url_suggest.h" #include "utils/messages.h" @@ -89,7 +93,6 @@ bool ro_gui_url_suggest_get_menu_available(void) bool ro_gui_url_suggest_prepare_menu(void) { - int i; struct url_suggest_item *list, *next; /* Fetch the URLs we want to include from URLdb. */ @@ -108,7 +111,7 @@ bool ro_gui_url_suggest_prepare_menu(void) assert(suggest_entries <= URL_SUGGEST_MAX_URLS); if (suggest_entries > 0) { - i = suggest_entries; + int i = suggest_entries; list = suggest_list; suggest_list = NULL; @@ -156,11 +159,11 @@ bool ro_gui_url_suggest_callback(nsurl *url, const struct url_data *data) { int count; unsigned int weight; - struct url_suggest_item **list, *new, *old; + struct url_suggest_item **list, *new; /* Ignore unvisited URLs, and those that don't apply to HTML or Text. */ - if (data->visits <= 0 || (data->type != CONTENT_HTML && + if (data->visits == 0 || (data->type != CONTENT_HTML && data->type != CONTENT_TEXTPLAIN)) return true; @@ -206,7 +209,7 @@ bool ro_gui_url_suggest_callback(nsurl *url, const struct url_data *data) */ while (suggest_list != NULL && suggest_entries > URL_SUGGEST_MAX_URLS) { - old = suggest_list; + struct url_suggest_item *old = suggest_list; suggest_list = suggest_list->next; free(old); diff --git a/riscos/wimp.c b/riscos/wimp.c index 87860ad35..f59fa675a 100644 --- a/riscos/wimp.c +++ b/riscos/wimp.c @@ -40,6 +40,7 @@ #include "utils/log.h" #include "utils/utf8.h" #include "utils/utils.h" +#include "riscos/ucstables.h" static void ro_gui_wimp_cache_furniture_sizes(wimp_w w); @@ -273,12 +274,12 @@ void ro_gui_set_icon_string(wimp_w w, wimp_i i, const char *text, bool is_utf8) unsigned int button_type; if (is_utf8) { - utf8_convert_ret err; + nserror err; /* convert text to local encoding */ err = utf8_to_local_encoding(text, 0, &local_text); - if (err != UTF8_CONVERT_OK) { + if (err != NSERROR_OK) { /* A bad encoding should never happen, so assert this */ - assert(err != UTF8_CONVERT_BADENC); + assert(err != NSERROR_BAD_ENCODING); LOG(("utf8_to_enc failed")); /* Paranoia */ local_text = NULL; @@ -677,7 +678,7 @@ void ro_gui_set_window_title(wimp_w w, const char *text) wimp_window_info_base window; os_error *error; char *title_local_enc; - utf8_convert_ret err; + nserror err; /* Get the window details */ @@ -692,10 +693,10 @@ void ro_gui_set_window_title(wimp_w w, const char *text) /* convert text to local encoding */ err = utf8_to_local_encoding(text, 0, &title_local_enc); - if (err != UTF8_CONVERT_OK) { + if (err != NSERROR_OK) { /* A bad encoding should never happen, * so assert this */ - assert(err != UTF8_CONVERT_BADENC); + assert(err != NSERROR_BAD_ENCODING); LOG(("utf8_to_enc failed")); return; } diff --git a/riscos/wimp_event.c b/riscos/wimp_event.c index e87962039..d42d2b08a 100644 --- a/riscos/wimp_event.c +++ b/riscos/wimp_event.c @@ -32,6 +32,7 @@ #include "oslib/serviceinternational.h" #include "oslib/wimp.h" #include "desktop/gui.h" +#include "riscos/gui.h" #include "riscos/dialog.h" #include "riscos/menus.h" #include "riscos/ucstables.h" @@ -633,7 +634,6 @@ bool ro_gui_wimp_event_mouse_click(wimp_pointer *pointer) int current, step, stepping, min, max, decimal_places; wimp_window_state open; wimp_caret caret; - os_error *error; bool prepared; w = pointer->w; @@ -701,6 +701,7 @@ bool ro_gui_wimp_event_mouse_click(wimp_pointer *pointer) * button, then close the menu (which closes us) and then finally * re-open ourselves. ugh! */ if (current_menu != NULL) { + os_error *error; open.w = pointer->w; error = xwimp_get_window_state(&open); if (error) { @@ -718,8 +719,7 @@ bool ro_gui_wimp_event_mouse_click(wimp_pointer *pointer) } ro_gui_dialog_add_persistent(current_menu_window, pointer->w); - ro_gui_menu_closed(); - gui_poll(true); + ro_gui_menu_destroy(); error = xwimp_open_window(PTR_WIMP_OPEN(&open)); if (error) { LOG(("xwimp_open_window: 0x%x: %s", @@ -768,7 +768,7 @@ bool ro_gui_wimp_event_mouse_click(wimp_pointer *pointer) if (pointer->buttons & wimp_CLICK_SELECT) { ro_gui_dialog_close(pointer->w); ro_gui_wimp_event_close_window(pointer->w); - ro_gui_menu_closed(); + ro_gui_menu_destroy(); } else { ro_gui_wimp_event_restore(pointer->w); } @@ -850,7 +850,7 @@ void ro_gui_wimp_event_ok_click(struct event_window *window, if (state & wimp_CLICK_SELECT) { ro_gui_dialog_close(window->w); ro_gui_wimp_event_close_window(window->w); - ro_gui_menu_closed(); + ro_gui_menu_destroy(); } else { ro_gui_wimp_event_memorise(window->w); } @@ -1045,7 +1045,7 @@ bool ro_gui_wimp_event_keypress(wimp_key *key) return false; ro_gui_dialog_close(key->w); ro_gui_wimp_event_close_window(key->w); - ro_gui_menu_closed(); + ro_gui_menu_destroy(); return true; /* Return performs the OK action */ case wimp_KEY_RETURN: @@ -1163,25 +1163,25 @@ bool ro_gui_wimp_event_pointer_entering_window(wimp_entering *entering) bool ro_gui_wimp_event_process_window_menu_click(wimp_pointer *pointer) { struct event_window *window; - int xpos, ypos, line_height, gap_height, entry; window = ro_gui_wimp_event_find_window(pointer->w); if ((window) && (window->window_menu) && (pointer->buttons == wimp_CLICK_MENU)) { + int xpos, ypos; + if (window->menu_prepare) if (!window->menu_prepare(window->w, wimp_ICON_WINDOW, window->window_menu, pointer)) return false; if (window->window_menu_iconbar) { - xpos = pointer->pos.x; - ypos = 96; - - line_height = window->window_menu->height + + int entry = 0; + int line_height = window->window_menu->height + window->window_menu->gap; - gap_height = 24; /* The fixed dotted line height */ + int gap_height = 24; /* The fixed dotted line height */ - entry = 0; + xpos = pointer->pos.x; + ypos = 96; do { ypos += line_height; if ((window->window_menu-> @@ -1340,7 +1340,6 @@ bool ro_gui_wimp_event_register_checkbox(wimp_w w, wimp_i i) bool ro_gui_wimp_event_register_radio(wimp_w w, wimp_i *i) { struct event_window *window; - struct icon_event *event; window = ro_gui_wimp_event_get_window(w); if (!window) @@ -1348,7 +1347,8 @@ bool ro_gui_wimp_event_register_radio(wimp_w w, wimp_i *i) window->max_radio_group++; while (*i != -1) { - event = ro_gui_wimp_event_get_event(w, *i, EVENT_RADIO); + struct icon_event *event = ro_gui_wimp_event_get_event(w, *i, + EVENT_RADIO); if (!event) return false; event->data.radio_group = window->max_radio_group; @@ -1772,7 +1772,7 @@ bool ro_gui_wimp_event_submenu_warning(wimp_w w, wimp_i i, wimp_menu *menu, } /** - * Handle menus being closed. This is called from ro_gui_menu_closed(), in + * Handle menus being closed. This is called from the menus modules, in * every scenario when one of our own menus is open. * * \param w the window to owning the menu diff --git a/riscos/window.c b/riscos/window.c index f6b274a20..1b9ed3330 100644 --- a/riscos/window.c +++ b/riscos/window.c @@ -5,7 +5,7 @@ * Copyright 2004 Andrew Timmins <atimmins@blueyonder.co.uk> * Copyright 2005 Richard Wilson <info@tinct.net> * Copyright 2005 Adrian Lees <adrianl@users.sourceforge.net> - * Copyright 2010, 2011 Stephen Fryatt <stevef@netsurf-browser.org> + * Copyright 2010-2014 Stephen Fryatt <stevef@netsurf-browser.org> * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -40,16 +40,25 @@ #include "oslib/osspriteop.h" #include "oslib/wimp.h" #include "oslib/wimpspriteop.h" + #include "utils/config.h" +#include "utils/nsoption.h" +#include "utils/log.h" +#include "utils/talloc.h" +#include "utils/url.h" +#include "utils/file.h" +#include "utils/utf8.h" +#include "utils/utils.h" +#include "utils/messages.h" #include "content/content.h" #include "content/hlcache.h" #include "content/urldb.h" #include "css/css.h" +#include "desktop/browser_history.h" #include "desktop/browser_private.h" #include "desktop/cookie_manager.h" #include "desktop/scrollbar.h" #include "desktop/frames.h" -#include "desktop/local_history.h" #include "desktop/mouse.h" #include "desktop/plotters.h" #include "desktop/textinput.h" @@ -58,6 +67,7 @@ #include "desktop/gui.h" #include "render/form.h" #include "render/html.h" + #include "riscos/bitmap.h" #include "riscos/buffer.h" #include "riscos/cookies.h" @@ -69,7 +79,6 @@ #include "riscos/hotlist.h" #include "riscos/menus.h" #include "riscos/mouse.h" -#include "utils/nsoption.h" #include "riscos/oslib_pre7.h" #include "riscos/save.h" #include "riscos/content-handlers/sprite.h" @@ -82,13 +91,10 @@ #include "riscos/wimp_event.h" #include "riscos/wimputils.h" #include "riscos/window.h" -#include "utils/log.h" -#include "utils/talloc.h" -#include "utils/url.h" -#include "utils/utf8.h" -#include "utils/utils.h" -#include "utils/messages.h" +#include "riscos/ucstables.h" +#include "riscos/filetype.h" +void gui_window_redraw_window(struct gui_window *g); static void gui_window_set_extent(struct gui_window *g, int width, int height); @@ -131,8 +137,6 @@ static bool ro_gui_window_navigate_up(struct gui_window *g, const char *url); static void ro_gui_window_action_home(struct gui_window *g); static void ro_gui_window_action_new_window(struct gui_window *g); static void ro_gui_window_action_local_history(struct gui_window *g); -static void ro_gui_window_action_navigate_back_new(struct gui_window *g); -static void ro_gui_window_action_navigate_forward_new(struct gui_window *g); static void ro_gui_window_action_save(struct gui_window *g, gui_save_type save_type); static void ro_gui_window_action_search(struct gui_window *g); @@ -150,8 +154,9 @@ static void ro_gui_window_update_theme(void *data, bool ok); static bool ro_gui_window_import_text(struct gui_window *g, const char *filename); -static void ro_gui_window_clone_options(struct browser_window *new_bw, - struct browser_window *old_bw); +static void ro_gui_window_clone_options( + struct gui_window *new_gui, + struct gui_window *old_gui); static bool ro_gui_window_prepare_form_select_menu(struct browser_window *bw, struct form_control *control); @@ -372,24 +377,49 @@ void ro_gui_window_initialise(void) */ /** + * Place the caret in a browser window. + * + * \param g window with caret + * \param x coordinates of caret + * \param y coordinates of caret + * \param height height of caret + * \param clip clip rectangle, or NULL if none + */ + +static void gui_window_place_caret(struct gui_window *g, int x, int y, int height, + const struct rect *clip) +{ + os_error *error; + + error = xwimp_set_caret_position(g->window, -1, + x * 2, -(y + height) * 2, height * 2, -1); + if (error) { + LOG(("xwimp_set_caret_position: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("WimpError", error->errmess); + } +} + +/** * Create and open a new browser window. * - * \param bw browser_window structure to update - * \param clone the browser window to clone options from, or NULL for default - * \return gui_window, or 0 on error and error reported + * \param bw bw to create gui_window for + * \param existing an existing gui_window, may be NULL + * \param flags flags for gui window creation + * \return gui window, or NULL on error */ -struct gui_window *gui_create_browser_window(struct browser_window *bw, - struct browser_window *clone, bool new_tab) +static struct gui_window *gui_window_create(struct browser_window *bw, + struct gui_window *existing, + gui_window_create_flags flags) { - int screen_width, screen_height, win_width, win_height, scroll_width; + int screen_width, screen_height; static int window_count = 2; wimp_window window; wimp_window_state state; os_error *error; bool open_centred = true; struct gui_window *g; - struct browser_window *top; g = malloc(sizeof *g); if (!g) { @@ -406,9 +436,10 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw, g->iconise_icon = -1; /* Set the window position */ - if (clone && clone->window && nsoption_bool(window_size_clone)) { - for (top = clone; top->parent; top = top->parent); - state.w = top->window->window; + if (existing != NULL && + flags & GW_CREATE_CLONE && + nsoption_bool(window_size_clone)) { + state.w = existing->window; error = xwimp_get_window_state(&state); if (error) { LOG(("xwimp_get_window_state: 0x%x: %s", @@ -421,19 +452,24 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw, window.visible.y1 = state.visible.y1 - 48; open_centred = false; } else { + int win_width, win_height; ro_gui_screen_size(&screen_width, &screen_height); /* Check if we have a preferred position */ if ((nsoption_int(window_screen_width) != 0) && (nsoption_int(window_screen_height) != 0)) { - win_width = (nsoption_int(window_width) * screen_width) / - nsoption_int(window_screen_width); - win_height = (nsoption_int(window_height) * screen_height) / - nsoption_int(window_screen_height); - window.visible.x0 = (nsoption_int(window_x) * screen_width) / - nsoption_int(window_screen_width); - window.visible.y0 = (nsoption_int(window_y) * screen_height) / - nsoption_int(window_screen_height); + win_width = (nsoption_int(window_width) * + screen_width) / + nsoption_int(window_screen_width); + win_height = (nsoption_int(window_height) * + screen_height) / + nsoption_int(window_screen_height); + window.visible.x0 = (nsoption_int(window_x) * + screen_width) / + nsoption_int(window_screen_width); + window.visible.y0 = (nsoption_int(window_y) * + screen_height) / + nsoption_int(window_screen_height); if (nsoption_bool(window_stagger)) { window.visible.y0 += 96 - (48 * (window_count % 5)); @@ -505,7 +541,7 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw, wimp_WINDOW_TOGGLE_ICON; if (open_centred) { - scroll_width = ro_get_vscroll_width(NULL); + int scroll_width = ro_get_vscroll_width(NULL); window.visible.x0 -= scroll_width; } @@ -566,8 +602,7 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw, ro_gui_window_menu_close); /* Set the window options */ - bw->window = g; - ro_gui_window_clone_options(bw, clone); + ro_gui_window_clone_options(g, existing); ro_gui_window_update_toolbar_buttons(g); /* Open the window at the top of the stack */ @@ -600,7 +635,7 @@ struct gui_window *gui_create_browser_window(struct browser_window *bw, * \param g gui_window to destroy */ -void gui_window_destroy(struct gui_window *g) +static void gui_window_destroy(struct gui_window *g) { os_error *error; wimp_w w; @@ -628,7 +663,7 @@ void gui_window_destroy(struct gui_window *g) ro_gui_url_complete_close(); ro_gui_dialog_close_persistent(w); if (current_menu_window == w) - ro_gui_menu_closed(); + ro_gui_menu_destroy(); ro_gui_window_remove_update_boxes(g); /* delete window */ @@ -651,15 +686,14 @@ void gui_window_destroy(struct gui_window *g) * \param title new window title, copied */ -void gui_window_set_title(struct gui_window *g, const char *title) +static void gui_window_set_title(struct gui_window *g, const char *title) { - int scale_disp; - assert(g); assert(title); if (g->bw->scale != 1.0) { - scale_disp = g->bw->scale * 100; + int scale_disp = g->bw->scale * 100; + if (ABS((float)scale_disp - g->bw->scale * 100) >= 0.05) snprintf(g->title, sizeof g->title, "%s (%.1f%%)", title, g->bw->scale * 100); @@ -706,11 +740,11 @@ void gui_window_redraw_window(struct gui_window *g) /** * Redraw an area of a window. * - * \param g gui_window - * \param data content_msg_data union with filled in redraw data + * \param g The window to update + * \param rect The area of the window to update. */ -void gui_window_update_box(struct gui_window *g, const struct rect *rect) +static void gui_window_update_box(struct gui_window *g, const struct rect *rect) { bool use_buffer; int x0, y0, x1, y1; @@ -765,7 +799,7 @@ void gui_window_update_box(struct gui_window *g, const struct rect *rect) * \return true iff successful */ -bool gui_window_get_scroll(struct gui_window *g, int *sx, int *sy) +static bool gui_window_get_scroll(struct gui_window *g, int *sx, int *sy) { wimp_window_state state; os_error *error; @@ -798,7 +832,7 @@ bool gui_window_get_scroll(struct gui_window *g, int *sx, int *sy) * \param sy point to place at top-left of window */ -void gui_window_set_scroll(struct gui_window *g, int sx, int sy) +static void gui_window_set_scroll(struct gui_window *g, int sx, int sy) { wimp_window_state state; os_error *error; @@ -831,7 +865,7 @@ void gui_window_set_scroll(struct gui_window *g, int sx, int sy) * \param x1 right point to ensure visible * \param y1 top point to ensure visible */ -void gui_window_scroll_visible(struct gui_window *g, int x0, int y0, int x1, int y1) +static void gui_window_scroll_visible(struct gui_window *g, int x0, int y0, int x1, int y1) { wimp_window_state state; os_error *error; @@ -915,7 +949,7 @@ void gui_window_scroll_visible(struct gui_window *g, int x0, int y0, int x1, int * \param scaled whether to return scaled values */ -void gui_window_get_dimensions(struct gui_window *g, int *width, int *height, bool scaled) +static void gui_window_get_dimensions(struct gui_window *g, int *width, int *height, bool scaled) { /* use the cached window sizes */ *width = g->old_width / 2; @@ -934,14 +968,10 @@ void gui_window_get_dimensions(struct gui_window *g, int *width, int *height, bo * \param g gui_window to update the extent of */ -void gui_window_update_extent(struct gui_window *g) +static void gui_window_update_extent(struct gui_window *g) { os_error *error; wimp_window_info info; - wimp_window_state state; - bool update; - unsigned int flags; - int scroll = 0; assert(g); @@ -956,26 +986,13 @@ void gui_window_update_extent(struct gui_window *g) /* scroll on toolbar height change */ if (g->toolbar) { - scroll = ro_toolbar_height(g->toolbar) - info.extent.y1; + int scroll = ro_toolbar_height(g->toolbar) - info.extent.y1; info.yscroll += scroll; } - /* only allow a further reformat if we've gained/lost scrollbars */ - flags = info.flags & (wimp_WINDOW_HSCROLL | wimp_WINDOW_VSCROLL); - update = g->bw->reformat_pending; + /* Handle change of extents */ g->update_extent = true; ro_gui_window_open(PTR_WIMP_OPEN(&info)); - - state.w = g->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); - return; - } - if (flags == (state.flags & (wimp_WINDOW_HSCROLL | wimp_WINDOW_VSCROLL))) - g->bw->reformat_pending = update; } @@ -986,7 +1003,7 @@ void gui_window_update_extent(struct gui_window *g) * \param text new status text */ -void gui_window_set_status(struct gui_window *g, const char *text) +static void gui_window_set_status(struct gui_window *g, const char *text) { if (g->status_bar) ro_gui_status_bar_set_text(g->status_bar, text); @@ -1037,30 +1054,7 @@ void gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape) } -/** - * Remove the mouse pointer from the screen - */ - -void gui_window_hide_pointer(struct gui_window *g) -{ - os_error *error; - - error = xwimpspriteop_set_pointer_shape(NULL, 0x30, 0, 0, 0, 0); - if (error) { - LOG(("xwimpspriteop_set_pointer_shape: 0x%x: %s", - error->errnum, error->errmess)); - warn_user("WimpError", error->errmess); - } -} - - -/** - * Set the contents of a window's address bar. - * - * \param g gui_window to update - * \param url new url for address bar - */ - +/* exported function documented in riscos/window.h */ void gui_window_set_url(struct gui_window *g, const char *url) { if (!g->toolbar) @@ -1077,7 +1071,7 @@ void gui_window_set_url(struct gui_window *g, const char *url) * \param g window with start of load */ -void gui_window_start_throbber(struct gui_window *g) +static void gui_window_start_throbber(struct gui_window *g) { ro_gui_window_update_toolbar_buttons(g); ro_gui_menu_refresh(ro_gui_browser_window_menu); @@ -1093,7 +1087,7 @@ void gui_window_start_throbber(struct gui_window *g) * \param g window with start of load */ -void gui_window_stop_throbber(struct gui_window *g) +static void gui_window_stop_throbber(struct gui_window *g) { ro_gui_window_update_toolbar_buttons(g); ro_gui_menu_refresh(ro_gui_browser_window_menu); @@ -1105,7 +1099,7 @@ void gui_window_stop_throbber(struct gui_window *g) * set favicon */ -void gui_window_set_icon(struct gui_window *g, hlcache_handle *icon) +static void gui_window_set_icon(struct gui_window *g, hlcache_handle *icon) { if (g == NULL || g->toolbar == NULL) return; @@ -1113,38 +1107,6 @@ void gui_window_set_icon(struct gui_window *g, hlcache_handle *icon) ro_toolbar_set_site_favicon(g->toolbar, icon); } -/** -* set gui display of a retrieved favicon representing the search provider -* \param ico may be NULL for local calls; then access current cache from -* search_web_ico() -*/ -void gui_window_set_search_ico(hlcache_handle *ico) -{ -} - -/** - * Place the caret in a browser window. - * - * \param g window with caret - * \param x coordinates of caret - * \param y coordinates of caret - * \param height height of caret - * \param clip clip rectangle, or NULL if none - */ - -void gui_window_place_caret(struct gui_window *g, int x, int y, int height, - const struct rect *clip) -{ - os_error *error; - - error = xwimp_set_caret_position(g->window, -1, - x * 2, -(y + height) * 2, height * 2, -1); - if (error) { - LOG(("xwimp_set_caret_position: 0x%x: %s", - error->errnum, error->errmess)); - warn_user("WimpError", error->errmess); - } -} /** @@ -1153,7 +1115,7 @@ void gui_window_place_caret(struct gui_window *g, int x, int y, int height, * \param g window with caret */ -void gui_window_remove_caret(struct gui_window *g) +static void gui_window_remove_caret(struct gui_window *g) { wimp_caret caret; os_error *error; @@ -1181,7 +1143,7 @@ void gui_window_remove_caret(struct gui_window *g) * \param g the gui_window that has new content */ -void gui_window_new_content(struct gui_window *g) +static void gui_window_new_content(struct gui_window *g) { ro_gui_menu_refresh(ro_gui_browser_window_menu); ro_gui_window_update_toolbar_buttons(g); @@ -1193,10 +1155,10 @@ void gui_window_new_content(struct gui_window *g) /** * Starts drag scrolling of a browser window * - * \param gw gui window + * \param g the window to scroll */ -bool gui_window_scroll_start(struct gui_window *g) +static bool gui_window_scroll_start(struct gui_window *g) { wimp_window_info_base info; wimp_pointer pointer; @@ -1260,17 +1222,16 @@ bool gui_window_scroll_start(struct gui_window *g) * \return true iff succesful */ -bool gui_window_drag_start(struct gui_window *g, gui_drag_type type, +static bool gui_window_drag_start(struct gui_window *g, gui_drag_type type, const struct rect *rect) { wimp_pointer pointer; - os_error *error; wimp_drag drag; if (rect != NULL) { /* We have a box to constrain the pointer to, for the drag * duration */ - error = xwimp_get_pointer_info(&pointer); + os_error *error = xwimp_get_pointer_info(&pointer); if (error) { LOG(("xwimp_get_pointer_info 0x%x : %s", error->errnum, error->errmess)); @@ -1316,10 +1277,11 @@ bool gui_window_drag_start(struct gui_window *g, gui_drag_type type, /** * Save the specified content as a link. * - * \param g gui_window containing the content - * \param c the content to save + * \param g The window containing the content + * \param url The url of the link + * \param title The title of the link */ -void gui_window_save_link(struct gui_window *g, const char *url, +static void gui_window_save_link(struct gui_window *g, const char *url, const char *title) { ro_gui_save_prepare(GUI_SAVE_LINK_URL, NULL, NULL, url, title); @@ -1339,11 +1301,9 @@ void gui_window_set_extent(struct gui_window *g, int width, int height) { int screen_width; int toolbar_height = 0; - hlcache_handle *h; wimp_window_state state; os_error *error; - h = g->bw->current_content; if (g->toolbar) toolbar_height = ro_toolbar_full_height(g->toolbar); @@ -1375,9 +1335,11 @@ void gui_window_set_extent(struct gui_window *g, int width, int height) height -= ro_get_hscroll_height(g->window); height -= ro_get_title_height(g->window); } - if (h) { - width = max(width, content_get_width(h) * 2 * g->bw->scale); - height = max(height, content_get_height(h) * 2 * g->bw->scale); + if (browser_window_has_content(g->bw)) { + int w, h; + browser_window_get_extents(g->bw, true, &w, &h); + width = max(width, w * 2); + height = max(height, h * 2); } os_box extent = { 0, -height, width, toolbar_height }; error = xwimp_set_extent(g->window, &extent); @@ -1417,7 +1379,7 @@ 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(); + ro_gui_menu_destroy(); return; } @@ -1522,8 +1484,7 @@ void ro_gui_window_open(wimp_open *open) struct gui_window *g = (struct gui_window *)ro_gui_wimp_event_get_user_data(open->w); int width = open->visible.x1 - open->visible.x0; int height = open->visible.y1 - open->visible.y0; - int size, fheight, fwidth, toolbar_height = 0; - bool no_vscroll, no_hscroll; + int toolbar_height = 0; float new_scale = 0; hlcache_handle *h; wimp_window_state state; @@ -1563,24 +1524,22 @@ void ro_gui_window_open(wimp_open *open) /* handle 'auto' scroll bars' and non-fitting scrollbar removal */ if ((g->bw->scrolling == SCROLLING_AUTO) || (g->bw->scrolling == SCROLLING_YES)) { + int size; + /* windows lose scrollbars when containing a frameset */ - no_hscroll = false; - no_vscroll = g->bw->children; + bool no_hscroll = false; + bool no_vscroll = g->bw->children; /* hscroll */ size = ro_get_hscroll_height(NULL); if (g->bw->border) size -= 2; - fheight = height; - if (state.flags & wimp_WINDOW_HSCROLL) - fheight += size; if (!no_hscroll) { if (!(state.flags & wimp_WINDOW_HSCROLL)) { height -= size; state.visible.y0 += size; if (h) { - g->bw->reformat_pending = true; - browser_reformat_pending = true; + browser_window_schedule_reformat(g->bw); } } state.flags |= wimp_WINDOW_HSCROLL; @@ -1589,8 +1548,7 @@ void ro_gui_window_open(wimp_open *open) height += size; state.visible.y0 -= size; if (h) { - g->bw->reformat_pending = true; - browser_reformat_pending = true; + browser_window_schedule_reformat(g->bw); } } state.flags &= ~wimp_WINDOW_HSCROLL; @@ -1600,16 +1558,12 @@ void ro_gui_window_open(wimp_open *open) size = ro_get_vscroll_width(NULL); if (g->bw->border) size -= 2; - fwidth = width; - if (state.flags & wimp_WINDOW_VSCROLL) - fwidth += size; if (!no_vscroll) { if (!(state.flags & wimp_WINDOW_VSCROLL)) { width -= size; state.visible.x1 -= size; if (h) { - g->bw->reformat_pending = true; - browser_reformat_pending = true; + browser_window_schedule_reformat(g->bw); } } state.flags |= wimp_WINDOW_VSCROLL; @@ -1618,8 +1572,7 @@ void ro_gui_window_open(wimp_open *open) width += size; state.visible.x1 += size; if (h) { - g->bw->reformat_pending = true; - browser_reformat_pending = true; + browser_window_schedule_reformat(g->bw); } } state.flags &= ~wimp_WINDOW_VSCROLL; @@ -1632,8 +1585,7 @@ void ro_gui_window_open(wimp_open *open) if ((g->old_width > 0) && (g->old_width != width) && (ro_gui_ctrl_pressed())) new_scale = (g->bw->scale * width) / g->old_width; - g->bw->reformat_pending = true; - browser_reformat_pending = true; + browser_window_schedule_reformat(g->bw); } if (g->update_extent || g->old_width != width || g->old_height != height) { @@ -1690,8 +1642,8 @@ void ro_gui_window_close(wimp_w w) struct gui_window *g = (struct gui_window *)ro_gui_wimp_event_get_user_data(w); wimp_pointer pointer; os_error *error; - char *temp_name, *r; - char *filename; + char *temp_name; + char *filename = NULL; hlcache_handle *h = NULL; bool destroy; @@ -1706,12 +1658,15 @@ void ro_gui_window_close(wimp_w w) h = g->bw->current_content; if (pointer.buttons & wimp_CLICK_ADJUST) { destroy = !ro_gui_shift_pressed(); - filename = (h && hlcache_handle_get_url(h)) ? - url_to_path(nsurl_access(hlcache_handle_get_url(h))) : - NULL; - if (filename) { + + if (h && hlcache_handle_get_url(h)) { + netsurf_nsurl_to_path(hlcache_handle_get_url(h), + &filename); + } + if (filename != NULL) { temp_name = malloc(strlen(filename) + 32); if (temp_name) { + char *r; sprintf(temp_name, "Filer_OpenDir %s", filename); r = temp_name + strlen(temp_name); @@ -1798,25 +1753,12 @@ bool ro_gui_window_click(wimp_pointer *pointer) bool ro_gui_window_keypress(wimp_key *key) { struct gui_window *g; - hlcache_handle *h; - os_error *error; - wimp_pointer pointer; uint32_t c = (uint32_t) key->c; g = (struct gui_window *) ro_gui_wimp_event_get_user_data(key->w); if (g == NULL) return false; - h = g->bw->current_content; - - error = xwimp_get_pointer_info(&pointer); - if (error) { - LOG(("xwimp_get_pointer_info: 0x%x: %s\n", - error->errnum, error->errmess)); - warn_user("WimpError", error->errmess); - return false; - } - /* First send the key to the browser window, eg. form fields. */ if ((unsigned)c < 0x20 || (0x7f <= c && c <= 0x9f) || @@ -1893,7 +1835,7 @@ bool ro_gui_window_keypress(wimp_key *key) bool ro_gui_window_toolbar_keypress(void *data, wimp_key *key) { - struct gui_window *g = (struct gui_window *) data; + struct gui_window *g = (struct gui_window *) data; if (g != NULL) return ro_gui_window_handle_local_keypress(g, key, true); @@ -1917,27 +1859,44 @@ bool ro_gui_window_toolbar_keypress(void *data, wimp_key *key) bool ro_gui_window_handle_local_keypress(struct gui_window *g, wimp_key *key, bool is_toolbar) { - hlcache_handle *h; - const char *toolbar_url; - float scale; - uint32_t c = (uint32_t) key->c; - wimp_scroll_direction xscroll = wimp_SCROLL_NONE; - wimp_scroll_direction yscroll = wimp_SCROLL_NONE; - nsurl *url; - nserror error; + hlcache_handle *h; + struct contextual_content cont; + os_error *ro_error; + wimp_pointer pointer; + os_coord pos; + float scale; + uint32_t c = (uint32_t) key->c; + wimp_scroll_direction xscroll = wimp_SCROLL_NONE; + wimp_scroll_direction yscroll = wimp_SCROLL_NONE; + nsurl *url; if (g == NULL) return false; + ro_error = xwimp_get_pointer_info(&pointer); + if (ro_error) { + LOG(("xwimp_get_pointer_info: 0x%x: %s\n", + ro_error->errnum, ro_error->errmess)); + warn_user("WimpError", ro_error->errmess); + return false; + } + + if (!ro_gui_window_to_window_pos(g, pointer.pos.x, pointer.pos.y, &pos)) + return false; + + h = g->bw->current_content; + browser_window_get_contextual_content(g->bw, pos.x, pos.y, &cont); + switch (c) { case IS_WIMP_KEY + wimp_KEY_F1: /* Help. */ { - error = nsurl_create("http://www.netsurf-browser.org/documentation/", &url); + nserror error = nsurl_create( + "http://www.netsurf-browser.org/documentation/", + &url); if (error == NSERROR_OK) { - error = browser_window_create(BROWSER_WINDOW_VERIFIABLE | - BROWSER_WINDOW_HISTORY, + error = browser_window_create(BW_CREATE_HISTORY, url, NULL, NULL, @@ -2015,7 +1974,7 @@ bool ro_gui_window_handle_local_keypress(struct gui_window *g, wimp_key *key, return true; case IS_WIMP_KEY + wimp_KEY_F8: /* View source */ - ro_gui_view_source(h); + ro_gui_view_source((cont.main != NULL) ? cont.main : h); return true; case IS_WIMP_KEY + wimp_KEY_F9: @@ -2043,6 +2002,7 @@ bool ro_gui_window_handle_local_keypress(struct gui_window *g, wimp_key *key, case wimp_KEY_RETURN: if (is_toolbar) { + const char *toolbar_url; toolbar_url = ro_toolbar_get_url(g->toolbar); if (toolbar_url != NULL) ro_gui_window_launch_url(g, toolbar_url); @@ -2418,9 +2378,9 @@ bool ro_gui_window_menu_prepare(wimp_w w, wimp_i i, wimp_menu *menu, ro_gui_menu_set_entry_shaded(menu, HOTLIST_ADD_URL, h == NULL); ro_gui_menu_set_entry_shaded(menu, HISTORY_SHOW_LOCAL, - (bw == NULL || (bw->history == NULL) || - !(h != NULL || history_back_available(bw->history) || - history_forward_available(bw->history)))); + (bw == NULL || + !(h != NULL || browser_window_back_available(bw) || + browser_window_forward_available(bw)))); /* Help Submenu */ @@ -2447,7 +2407,6 @@ void ro_gui_window_menu_warning(wimp_w w, wimp_i i, wimp_menu *menu, wimp_selection *selection, menu_action action) { struct gui_window *g; - struct browser_window *bw; hlcache_handle *h; struct toolbar *toolbar; bool export; @@ -2457,8 +2416,7 @@ void ro_gui_window_menu_warning(wimp_w w, wimp_i i, wimp_menu *menu, g = (struct gui_window *) ro_gui_wimp_event_get_user_data(w); toolbar = g->toolbar; - bw = g->bw; - h = bw->current_content; + h = g->bw->current_content; switch (action) { case BROWSER_PAGE_INFO: @@ -2495,9 +2453,9 @@ void ro_gui_window_menu_warning(wimp_w w, wimp_i i, wimp_menu *menu, break; case BROWSER_SELECTION_SAVE: - if (browser_window_get_editor_flags(bw) & BW_EDITOR_CAN_COPY) + if (browser_window_get_editor_flags(g->bw) & BW_EDITOR_CAN_COPY) ro_gui_save_prepare(GUI_SAVE_TEXT_SELECTION, NULL, - browser_window_get_selection(bw), + browser_window_get_selection(g->bw), NULL, NULL); break; @@ -2686,8 +2644,7 @@ bool ro_gui_window_menu_select(wimp_w w, wimp_i i, wimp_menu *menu, case HELP_OPEN_CONTENTS: error = nsurl_create("http://www.netsurf-browser.org/documentation/", &url); if (error == NSERROR_OK) { - error = browser_window_create(BROWSER_WINDOW_VERIFIABLE | - BROWSER_WINDOW_HISTORY, + error = browser_window_create(BW_CREATE_HISTORY, url, NULL, NULL, @@ -2699,8 +2656,7 @@ bool ro_gui_window_menu_select(wimp_w w, wimp_i i, wimp_menu *menu, case HELP_OPEN_GUIDE: error = nsurl_create("http://www.netsurf-browser.org/documentation/guide", &url); if (error == NSERROR_OK) { - error = browser_window_create(BROWSER_WINDOW_VERIFIABLE | - BROWSER_WINDOW_HISTORY, + error = browser_window_create(BW_CREATE_HISTORY, url, NULL, NULL, @@ -2712,8 +2668,7 @@ bool ro_gui_window_menu_select(wimp_w w, wimp_i i, wimp_menu *menu, case HELP_OPEN_INFORMATION: error = nsurl_create("http://www.netsurf-browser.org/documentation/info", &url); if (error == NSERROR_OK) { - error = browser_window_create(BROWSER_WINDOW_VERIFIABLE | - BROWSER_WINDOW_HISTORY, + error = browser_window_create(BW_CREATE_HISTORY, url, NULL, NULL, @@ -2725,8 +2680,7 @@ bool ro_gui_window_menu_select(wimp_w w, wimp_i i, wimp_menu *menu, case HELP_OPEN_CREDITS: error = nsurl_create("about:credits", &url); if (error == NSERROR_OK) { - error = browser_window_create(BROWSER_WINDOW_VERIFIABLE | - BROWSER_WINDOW_HISTORY, + error = browser_window_create(BW_CREATE_HISTORY, url, NULL, NULL, @@ -2738,8 +2692,7 @@ bool ro_gui_window_menu_select(wimp_w w, wimp_i i, wimp_menu *menu, case HELP_OPEN_LICENCE: error = nsurl_create("about:licence", &url); if (error == NSERROR_OK) { - error = browser_window_create(BROWSER_WINDOW_VERIFIABLE | - BROWSER_WINDOW_HISTORY, + error = browser_window_create(BW_CREATE_HISTORY, url, NULL, NULL, @@ -2848,10 +2801,9 @@ bool ro_gui_window_menu_select(wimp_w w, wimp_i i, wimp_menu *menu, error = nsurl_create(current_menu_url, &url); if (error == NSERROR_OK) { error = browser_window_navigate(bw, - url, - hlcache_handle_get_url(h), - BROWSER_WINDOW_DOWNLOAD | - BROWSER_WINDOW_VERIFIABLE, + url, + hlcache_handle_get_url(h), + BW_NAVIGATE_DOWNLOAD, NULL, NULL, NULL); @@ -2864,8 +2816,9 @@ bool ro_gui_window_menu_select(wimp_w w, wimp_i i, wimp_menu *menu, if (current_menu_url != NULL) { error = nsurl_create(current_menu_url, &url); if (error == NSERROR_OK) { - error = browser_window_create(BROWSER_WINDOW_VERIFIABLE | - BROWSER_WINDOW_HISTORY, + error = browser_window_create( + BW_CREATE_HISTORY | + BW_CREATE_CLONE, url, hlcache_handle_get_url(h), bw, @@ -2957,12 +2910,12 @@ bool ro_gui_window_menu_select(wimp_w w, wimp_i i, wimp_menu *menu, ro_gui_window_action_home(g); break; case BROWSER_NAVIGATE_BACK: - if (bw != NULL && bw->history != NULL) - history_back(bw, bw->history); + if (bw != NULL) + browser_window_history_back(bw, false); break; case BROWSER_NAVIGATE_FORWARD: - if (bw != NULL && bw->history != NULL) - history_forward(bw, bw->history); + if (bw != NULL) + browser_window_history_forward(bw, false); break; case BROWSER_NAVIGATE_UP: if (bw != NULL && h != NULL) @@ -3035,12 +2988,12 @@ bool ro_gui_window_menu_select(wimp_w w, wimp_i i, wimp_menu *menu, } break; case BROWSER_WINDOW_STAGGER: - nsoption_set_bool(window_stagger, + nsoption_set_bool(window_stagger, !nsoption_bool(window_stagger)); ro_gui_save_options(); break; case BROWSER_WINDOW_COPY: - nsoption_set_bool(window_size_clone, + nsoption_set_bool(window_size_clone, !nsoption_bool(window_size_clone)); ro_gui_save_options(); break; @@ -3122,7 +3075,7 @@ void ro_gui_window_scroll(wimp_scroll *scroll) inc = 0.02; /* RO5 sends the msg 5 times; * don't ask me why * - * \TODO -- this is liable to break if + * @todo this is liable to break if * HID is configured optimally for * frame scrolling. *5 appears to be * an artifact of non-HID mode scrolling. @@ -3606,7 +3559,6 @@ void ro_gui_window_toolbar_click(void *data, { struct gui_window *g = data; struct browser_window *new_bw; - gui_save_type save_type; if (g == NULL) return; @@ -3615,6 +3567,9 @@ void ro_gui_window_toolbar_click(void *data, if (action_type == TOOLBAR_ACTION_URL) { switch (action.url) { case TOOLBAR_URL_DRAG_URL: + { + gui_save_type save_type; + if (g->bw->current_content == NULL) break; @@ -3628,6 +3583,7 @@ void ro_gui_window_toolbar_click(void *data, ro_gui_drag_save_link(save_type, nsurl_access(hlcache_handle_get_url(h)), content_get_title(h), g); + } break; case TOOLBAR_URL_SELECT_HOTLIST: @@ -3637,7 +3593,7 @@ void ro_gui_window_toolbar_click(void *data, case TOOLBAR_URL_ADJUST_HOTLIST: ro_gui_window_action_remove_bookmark(g); break; - + default: break; } @@ -3655,21 +3611,23 @@ void ro_gui_window_toolbar_click(void *data, switch (action.button) { case TOOLBAR_BUTTON_BACK: - if (g->bw != NULL && g->bw->history != NULL) - history_back(g->bw, g->bw->history); + if (g->bw != NULL) + browser_window_history_back(g->bw, false); break; case TOOLBAR_BUTTON_BACK_NEW: - ro_gui_window_action_navigate_back_new(g); + if (g->bw != NULL) + browser_window_history_back(g->bw, true); break; case TOOLBAR_BUTTON_FORWARD: - if (g->bw != NULL && g->bw->history != NULL) - history_forward(g->bw, g->bw->history); + if (g->bw != NULL) + browser_window_history_forward(g->bw, false); break; case TOOLBAR_BUTTON_FORWARD_NEW: - ro_gui_window_action_navigate_forward_new(g); + if (g->bw != NULL) + browser_window_history_forward(g->bw, true); break; case TOOLBAR_BUTTON_STOP: @@ -3739,7 +3697,8 @@ void ro_gui_window_toolbar_click(void *data, hlcache_handle *h = g->bw->current_content; nserror error; - error = browser_window_create(BROWSER_WINDOW_VERIFIABLE, + error = browser_window_create( + BW_CREATE_HISTORY | BW_CREATE_CLONE, NULL, NULL, g->bw, @@ -3749,7 +3708,7 @@ void ro_gui_window_toolbar_click(void *data, warn_user(messages_get_errorcode(error), 0); } else { /* do it without loading the content - * into the new window + * into the new window */ ro_gui_window_navigate_up(new_bw->window, nsurl_access(hlcache_handle_get_url(h))); @@ -3768,8 +3727,8 @@ void ro_gui_window_toolbar_click(void *data, /** * Handle Message_DataLoad (file dragged in) for a toolbar * - * \TODO -- This belongs in the toolbar module, and should be moved there - * once the module is able to usefully handle its own events. + * @todo This belongs in the toolbar module, and should be moved there + * once the module is able to usefully handle its own events. * * \param g window * \param message Message_DataLoad block @@ -3820,13 +3779,13 @@ bool ro_gui_window_check_menu(wimp_menu *menu) * Return boolean flags to show what RISC OS types we can sensibly convert * the given object into. * - * \TODO -- This should probably be somewhere else but in window.c, and - * should probably even be done in content_(). + * \todo This should probably be somewhere else but in window.c, and + * should probably even be done in content_(). * - * \param *h The object to test. - * \param *export_draw true on exit if a drawfile would be possible. - * \param *export_sprite true on exit if a sprite would be possible. - * \return true if valid data is returned; else false. + * \param h The object to test. + * \param export_draw true on exit if a drawfile would be possible. + * \param export_sprite true on exit if a sprite would be possible. + * \return true if valid data is returned; else false. */ bool ro_gui_window_content_export_types(hlcache_handle *h, @@ -3865,20 +3824,19 @@ bool ro_gui_window_content_export_types(hlcache_handle *h, /** * Return true if a browser window can navigate upwards. * - * \TODO -- This should probably be somewhere else but in window.c. + * \todo This should probably be somewhere else but in window.c. * - * \param *bw the browser window to test. - * \return true if navigation up is possible; else false. + * \param bw the browser window to test. + * \return true if navigation up is possible otherwise false. */ bool ro_gui_window_up_available(struct browser_window *bw) { bool result = false; nsurl *parent; - nserror err; if (bw != NULL && bw->current_content != NULL) { - err = nsurl_parent(hlcache_handle_get_url( + nserror err = nsurl_parent(hlcache_handle_get_url( bw->current_content), &parent); if (err == NSERROR_OK) { result = nsurl_compare(hlcache_handle_get_url( @@ -3903,7 +3861,6 @@ void ro_gui_window_prepare_pageinfo(struct gui_window *g) hlcache_handle *h = g->bw->current_content; char icon_buf[20] = "file_xxx"; char enc_buf[40]; - char enc_token[10] = "Encoding0"; const char *icon = icon_buf; const char *title, *url; lwc_string *mime; @@ -3925,6 +3882,7 @@ void ro_gui_window_prepare_pageinfo(struct gui_window *g) if (content_get_type(h) == CONTENT_HTML) { if (html_get_encoding(h)) { + char enc_token[10] = "Encoding0"; enc_token[8] = '0' + html_get_encoding_source(h); snprintf(enc_buf, sizeof enc_buf, "%s (%s)", html_get_encoding(h), @@ -3997,39 +3955,29 @@ void ro_gui_window_prepare_objectinfo(hlcache_handle *object, const char *href) /** * Launch a new url in the given window. * - * \param g gui_window to update - * \param url url to be launched + * \param g gui_window to update + * \param url1 url to be launched */ void ro_gui_window_launch_url(struct gui_window *g, const char *url1) { - char *url2; /** @todo The risc os maintainer needs to examine why the url is copied here */ - nsurl *url; nserror error; + nsurl *url; - ro_gui_url_complete_close(); - - url2 = strdup(url1); - if (url2 != NULL) { - - gui_window_set_url(g, url2); + if (url1 == NULL) + return; - error = nsurl_create(url2, &url); - if (error != NSERROR_OK) { - warn_user(messages_get_errorcode(error), 0); - } else { - browser_window_navigate(g->bw, - url, - NULL, - BROWSER_WINDOW_HISTORY | - BROWSER_WINDOW_VERIFIABLE, - NULL, - NULL, - NULL); - nsurl_unref(url); - } + ro_gui_url_complete_close(); + gui_window_set_url(g, url1); - free(url2); + error = nsurl_create(url1, &url); + if (error != NSERROR_OK) { + warn_user(messages_get_errorcode(error), 0); + } else { + browser_window_navigate(g->bw, url, + NULL, BW_NAVIGATE_HISTORY, + NULL, NULL, NULL); + nsurl_unref(url); } } @@ -4062,8 +4010,7 @@ bool ro_gui_window_navigate_up(struct gui_window *g, const char *url) browser_window_navigate(g->bw, parent, NULL, - BROWSER_WINDOW_HISTORY | - BROWSER_WINDOW_VERIFIABLE, + BW_NAVIGATE_HISTORY, NULL, NULL, NULL); @@ -4099,8 +4046,7 @@ void ro_gui_window_action_home(struct gui_window *g) error = browser_window_navigate(g->bw, url, NULL, - BROWSER_WINDOW_HISTORY | - BROWSER_WINDOW_VERIFIABLE, + BW_NAVIGATE_HISTORY, NULL, NULL, NULL); @@ -4113,62 +4059,6 @@ void ro_gui_window_action_home(struct gui_window *g) /** - * Navigate back from a browser window into a new window. - * - * \param *g The browser window to act on. - */ - -void ro_gui_window_action_navigate_back_new(struct gui_window *g) -{ - struct browser_window *new_bw; - nserror error; - - if (g == NULL || g->bw == NULL) - return; - - error = browser_window_create(BROWSER_WINDOW_VERIFIABLE, - NULL, - NULL, - g->bw, - &new_bw); - - if (error != NSERROR_OK) { - warn_user(messages_get_errorcode(error), 0); - } else { - history_back(new_bw, new_bw->history); - } -} - - -/** - * Navigate forward from a browser window into a new window. - * - * \param *g The browser window to act on. - */ - -void ro_gui_window_action_navigate_forward_new(struct gui_window *g) -{ - struct browser_window *new_bw; - nserror error; - - if (g == NULL || g->bw == NULL) - return; - - error = browser_window_create(BROWSER_WINDOW_VERIFIABLE, - NULL, - NULL, - g->bw, - &new_bw); - - if (error != NSERROR_OK) { - warn_user(messages_get_errorcode(error), 0); - } else { - history_forward(new_bw, new_bw->history); - } -} - - -/** * Open a new browser window. * * \param *g The browser window to act on. @@ -4181,7 +4071,7 @@ void ro_gui_window_action_new_window(struct gui_window *g) if (g == NULL || g->bw == NULL || g->bw->current_content == NULL) return; - error = browser_window_create(BROWSER_WINDOW_VERIFIABLE, + error = browser_window_create(BW_CREATE_CLONE, hlcache_handle_get_url(g->bw->current_content), NULL, g->bw, @@ -4202,7 +4092,7 @@ void ro_gui_window_action_new_window(struct gui_window *g) void ro_gui_window_action_local_history(struct gui_window *g) { if (g != NULL && g->bw != NULL && g->bw->history != NULL) - ro_gui_history_open(g->bw, g->bw->history, true); + ro_gui_history_open(g, true); } @@ -4455,35 +4345,25 @@ void ro_gui_window_update_boxes(void) /** - * Process pending reformats + * callback from core to reformat a window. */ - -void ro_gui_window_process_reformats(void) +static void riscos_window_reformat(struct gui_window *gw) { - struct gui_window *g; - - browser_reformat_pending = false; - for (g = window_list; g; g = g->next) { - if (!g->bw->reformat_pending) - continue; - g->bw->reformat_pending = false; - browser_window_reformat(g->bw, false, - g->old_width / 2, - g->old_height / 2); + if (gw != NULL) { + browser_window_reformat(gw->bw, false, + gw->old_width / 2, + gw->old_height / 2); } } - /** * Destroy all browser windows. */ void ro_gui_window_quit(void) { - struct gui_window *cur; - while (window_list) { - cur = window_list; + struct gui_window *cur = window_list; window_list = window_list->next; browser_window_destroy(cur->bw); @@ -4623,11 +4503,10 @@ void ro_gui_window_update_theme(void *data, bool ok) */ /** - * Import text file into window or its toolbar + * Import text file into window * * \param g gui window containing textarea * \param filename pathname of file to be imported - * \param toolbar true iff imported to toolbar rather than main window * \return true iff successful */ @@ -4637,7 +4516,7 @@ bool ro_gui_window_import_text(struct gui_window *g, const char *filename) os_error *error; char *buf, *utf8_buf, *sp; int size; - utf8_convert_ret ret; + nserror ret; const char *ep; char *p; @@ -4672,9 +4551,9 @@ bool ro_gui_window_import_text(struct gui_window *g, const char *filename) } ret = utf8_from_local_encoding(buf, size, &utf8_buf); - if (ret != UTF8_CONVERT_OK) { + if (ret != NSERROR_OK) { /* bad encoding shouldn't happen */ - assert(ret != UTF8_CONVERT_BADENC); + assert(ret != NSERROR_BAD_ENCODING); LOG(("utf8_from_local_encoding failed")); free(buf); warn_user("NoMemory", NULL); @@ -4705,29 +4584,19 @@ bool ro_gui_window_import_text(struct gui_window *g, const char *filename) /** * 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 + * \param new_gui the new gui window + * \param old_gui the gui window to clone from, or NULL for default */ -void ro_gui_window_clone_options(struct browser_window *new_bw, - struct browser_window *old_bw) +void ro_gui_window_clone_options( + struct gui_window *new_gui, + struct gui_window *old_gui) { - struct gui_window *old_gui = NULL; - struct gui_window *new_gui; - - assert(new_bw); - - /* Get our GUIs - */ - new_gui = new_bw->window; - - if (old_bw) - old_gui = old_bw->window; + assert(new_gui); /* Clone the basic options */ if (!old_gui) { - new_bw->scale = ((float)nsoption_int(scale)) / 100; new_gui->option.buffer_animations = nsoption_bool(buffer_animations); new_gui->option.buffer_everything = nsoption_bool(buffer_everything); } else { @@ -4818,7 +4687,7 @@ bool ro_gui_window_prepare_form_select_menu(struct browser_window *bw, char *text_convert, *temp; struct form_option *option; bool reopen = true; - utf8_convert_ret err; + nserror err; assert(control); @@ -4826,7 +4695,7 @@ bool ro_gui_window_prepare_form_select_menu(struct browser_window *bw, option = option->next) entries++; if (entries == 0) { - ro_gui_menu_closed(); + ro_gui_menu_destroy(); return false; } @@ -4850,17 +4719,17 @@ bool ro_gui_window_prepare_form_select_menu(struct browser_window *bw, gui_form_select_menu = malloc(wimp_SIZEOF_MENU(entries)); if (!gui_form_select_menu) { warn_user("NoMemory", 0); - ro_gui_menu_closed(); + ro_gui_menu_destroy(); return false; } err = utf8_to_local_encoding(messages_get("SelectMenu"), 0, &text_convert); - if (err != UTF8_CONVERT_OK) { + if (err != NSERROR_OK) { /* badenc should never happen */ - assert(err != UTF8_CONVERT_BADENC); + assert(err != NSERROR_BAD_ENCODING); LOG(("utf8_to_local_encoding failed")); warn_user("NoMemory", 0); - ro_gui_menu_closed(); + ro_gui_menu_destroy(); return false; } gui_form_select_menu->title_data.indirected_text.text = @@ -4885,19 +4754,19 @@ bool ro_gui_window_prepare_form_select_menu(struct browser_window *bw, if (!temp) { LOG(("cnv_space2nbsp failed")); warn_user("NoMemory", 0); - ro_gui_menu_closed(); + ro_gui_menu_destroy(); return false; } err = utf8_to_local_encoding(temp, 0, &text_convert); - if (err != UTF8_CONVERT_OK) { + if (err != NSERROR_OK) { /* A bad encoding should never happen, * so assert this */ - assert(err != UTF8_CONVERT_BADENC); + assert(err != NSERROR_BAD_ENCODING); LOG(("utf8_to_enc failed")); warn_user("NoMemory", 0); - ro_gui_menu_closed(); + ro_gui_menu_destroy(); return false; } @@ -4931,9 +4800,7 @@ void ro_gui_window_process_form_select_menu(struct gui_window *g, assert(g != NULL); if (selection->items[0] >= 0) - form_select_process_selection( - ro_gui_select_menu_bw->current_content, - gui_form_select_control, + form_select_process_selection(gui_form_select_control, selection->items[0]); } @@ -4945,8 +4812,8 @@ void ro_gui_window_process_form_select_menu(struct gui_window *g, /** * Convert a RISC OS window handle to a gui_window. * - * \param w RISC OS window handle - * \return pointer to a structure if found, 0 otherwise + * \param window RISC OS window handle. + * \return A pointer to a riscos gui window if found or NULL. */ struct gui_window *ro_gui_window_lookup(wimp_w window) @@ -4955,15 +4822,15 @@ struct gui_window *ro_gui_window_lookup(wimp_w window) for (g = window_list; g; g = g->next) if (g->window == window) return g; - return 0; + return NULL; } /** * Convert a toolbar RISC OS window handle to a gui_window. * - * \param w RISC OS window handle of a toolbar - * \return pointer to a structure if found, 0 otherwise + * \param window RISC OS window handle of a toolbar + * \return pointer to a structure if found, NULL otherwise */ struct gui_window *ro_gui_toolbar_lookup(wimp_w window) @@ -5256,3 +5123,38 @@ bool ro_gui_alt_pressed(void) return (alt == 0xff); } +static struct gui_window_table window_table = { + .create = gui_window_create, + .destroy = gui_window_destroy, + .redraw = gui_window_redraw_window, + .update = gui_window_update_box, + .get_scroll = gui_window_get_scroll, + .set_scroll = gui_window_set_scroll, + .get_dimensions = gui_window_get_dimensions, + .update_extent = gui_window_update_extent, + .reformat = riscos_window_reformat, + + .set_title = gui_window_set_title, + .set_url = gui_window_set_url, + .set_icon = gui_window_set_icon, + .set_status = gui_window_set_status, + .set_pointer = gui_window_set_pointer, + .place_caret = gui_window_place_caret, + .remove_caret = gui_window_remove_caret, + .save_link = gui_window_save_link, + .drag_start = gui_window_drag_start, + .scroll_visible = gui_window_scroll_visible, + .scroll_start = gui_window_scroll_start, + .new_content = gui_window_new_content, + .start_throbber = gui_window_start_throbber, + .stop_throbber = gui_window_stop_throbber, + + /* from save */ + .drag_save_object = gui_drag_save_object, + .drag_save_selection =gui_drag_save_selection, + + /* from textselection */ + .start_selection = gui_start_selection, +}; + +struct gui_window_table *riscos_window_table = &window_table; diff --git a/riscos/window.h b/riscos/window.h index adbd999f9..c4daf8bb8 100644 --- a/riscos/window.h +++ b/riscos/window.h @@ -25,9 +25,21 @@ #ifndef _NETSURF_RISCOS_WINDOW_H_ #define _NETSURF_RISCOS_WINDOW_H_ +struct gui_window; + +extern struct gui_window_table *riscos_window_table; + void ro_gui_window_initialise(void); bool ro_gui_window_check_menu(wimp_menu *menu); +/** + * Set the contents of a window's address bar. + * + * \param g gui_window to update + * \param url new url for address bar + */ +void gui_window_set_url(struct gui_window *g, const char *url); + #endif |