From 7897a98a4c7475e116f406ab173139c959d6dfb6 Mon Sep 17 00:00:00 2001 From: James Bursa Date: Wed, 25 Feb 2004 15:12:58 +0000 Subject: [project @ 2004-02-25 15:12:57 by bursa] Implement scaling; rewrite desktop/browser; add riscos/thumbnail; rewrite history. svn path=/import/netsurf/; revision=566 --- !NetSurf/Resources/en/Messages | 4 + !NetSurf/Resources/en/Templates,fec | Bin 4528 -> 5126 bytes content/content.c | 17 +- content/content.h | 5 +- debug/netsurfd.c | 3 +- desktop/browser.c | 1542 ++++++++++++++++++----------------- desktop/browser.h | 104 +-- desktop/gui.h | 13 +- makefile | 2 +- render/html.h | 3 +- riscos/401login.c | 4 +- riscos/dialog.c | 69 +- riscos/draw.c | 3 +- riscos/draw.h | 3 +- riscos/frames.c | 1 - riscos/gif.c | 3 +- riscos/gif.h | 3 +- riscos/gui.c | 100 +-- riscos/gui.h | 33 +- riscos/history.c | 304 +++++-- riscos/htmlredraw.c | 80 +- riscos/jpeg.c | 3 +- riscos/jpeg.h | 3 +- riscos/menus.c | 31 +- riscos/mouseactions.c | 4 +- riscos/plugin.c | 14 +- riscos/png.c | 3 +- riscos/png.h | 3 +- riscos/sprite.c | 3 +- riscos/sprite.h | 3 +- riscos/textselection.c | 4 +- riscos/thumbnail.c | 68 ++ riscos/thumbnail.h | 15 + riscos/uri.c | 15 +- riscos/url.c | 17 +- riscos/window.c | 113 +-- utils/utils.c | 1 + 37 files changed, 1445 insertions(+), 1151 deletions(-) create mode 100644 riscos/thumbnail.c create mode 100644 riscos/thumbnail.h diff --git a/!NetSurf/Resources/en/Messages b/!NetSurf/Resources/en/Messages index ed835d170..c865404ba 100644 --- a/!NetSurf/Resources/en/Messages +++ b/!NetSurf/Resources/en/Messages @@ -23,6 +23,8 @@ Home:Home page Back:Back one page Forward:Forward one page Reload:Reload this page +View:View +ScaleView:Scale view Themes:Themes @@ -42,3 +44,5 @@ cookiejar:.WWW.NetSurf.Cookies ErrorPage:Page error

Sorry, NetSurf was unable to display this page

%s

InvalidURL:The address %s could not be understood. + +NoMemory:NetSurf is running out of memory. Please free some memory and try again. diff --git a/!NetSurf/Resources/en/Templates,fec b/!NetSurf/Resources/en/Templates,fec index e3e27896c..fa80450e4 100644 Binary files a/!NetSurf/Resources/en/Templates,fec and b/!NetSurf/Resources/en/Templates,fec differ diff --git a/content/content.c b/content/content.c index 4b4e19bff..9a53869ed 100644 --- a/content/content.c +++ b/content/content.c @@ -2,7 +2,7 @@ * This file is part of NetSurf, http://netsurf.sourceforge.net/ * Licensed under the GNU General Public License, * http://www.opensource.org/licenses/gpl-license - * Copyright 2003 James Bursa + * Copyright 2004 James Bursa */ /** \file @@ -90,7 +90,8 @@ struct handler_entry { void (*destroy)(struct content *c); void (*redraw)(struct content *c, long x, long y, unsigned long width, unsigned long height, - long clip_x0, long clip_y0, long clip_x1, long clip_y1); + long clip_x0, long clip_y0, long clip_x1, long clip_y1, + float scale); void (*add_instance)(struct content *c, struct browser_window *bw, struct content *page, struct box *box, struct object_params *params, void **state); @@ -256,7 +257,7 @@ void content_process_data(struct content *c, char *data, unsigned long size) * (eg. loading images), the content gets status CONTENT_STATUS_READY, and a * CONTENT_MSG_READY is sent to all users. * - If the conversion succeeds and is complete, the content gets status - * CONTENT_STATUS_DONE, and CONTENT_MSG_DONE is sent. + * CONTENT_STATUS_DONE, and CONTENT_MSG_READY then CONTENT_MSG_DONE are sent. * - If the conversion fails, CONTENT_MSG_ERROR is sent. The content is then * destroyed and must no longer be used. */ @@ -278,9 +279,8 @@ void content_convert(struct content *c, unsigned long width, unsigned long heigh } assert(c->status == CONTENT_STATUS_READY || c->status == CONTENT_STATUS_DONE); - if (c->status == CONTENT_STATUS_READY) - content_broadcast(c, CONTENT_MSG_READY, 0); - else + content_broadcast(c, CONTENT_MSG_READY, 0); + if (c->status == CONTENT_STATUS_DONE) content_broadcast(c, CONTENT_MSG_DONE, 0); } @@ -379,12 +379,13 @@ void content_reset(struct content *c) void content_redraw(struct content *c, long x, long y, unsigned long width, unsigned long height, - long clip_x0, long clip_y0, long clip_x1, long clip_y1) + long clip_x0, long clip_y0, long clip_x1, long clip_y1, + float scale) { assert(c != 0); if (handler_map[c->type].redraw != 0) handler_map[c->type].redraw(c, x, y, width, height, - clip_x0, clip_y0, clip_x1, clip_y1); + clip_x0, clip_y0, clip_x1, clip_y1, scale); } diff --git a/content/content.h b/content/content.h index 737942187..2d2e498fe 100644 --- a/content/content.h +++ b/content/content.h @@ -2,7 +2,7 @@ * This file is part of NetSurf, http://netsurf.sourceforge.net/ * Licensed under the GNU General Public License, * http://www.opensource.org/licenses/gpl-license - * Copyright 2003 James Bursa + * Copyright 2004 James Bursa * Copyright 2003 Philip Pemberton */ @@ -161,7 +161,8 @@ void content_destroy(struct content *c); void content_reset(struct content *c); void content_redraw(struct content *c, long x, long y, unsigned long width, unsigned long height, - long clip_x0, long clip_y0, long clip_x1, long clip_y1); + long clip_x0, long clip_y0, long clip_x1, long clip_y1, + float scale); void content_add_user(struct content *c, void (*callback)(content_msg msg, struct content *c, void *p1, void *p2, const char *error), diff --git a/debug/netsurfd.c b/debug/netsurfd.c index d0e62ebda..a9fe710e4 100644 --- a/debug/netsurfd.c +++ b/debug/netsurfd.c @@ -103,7 +103,8 @@ void plugin_decode(void *a, void *b, void *c, void *d) void html_redraw(struct content *c, long x, long y, unsigned long width, unsigned long height, - long x0, long y0, long x1, long y1) + long x0, long y0, long x1, long y1, + float scale) { } diff --git a/desktop/browser.c b/desktop/browser.c index ef29aa80b..f6c157697 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -3,7 +3,11 @@ * Licensed under the GNU General Public License, * http://www.opensource.org/licenses/gpl-license * Copyright 2003 Phil Mellor - * Copyright 2003 James Bursa + * Copyright 2004 James Bursa + */ + +/** \file + * Browser window creation and manipulation (implementation). */ #include @@ -13,10 +17,7 @@ #include #include #include -#include "curl/curl.h" -#include "libxml/debugXML.h" #include "netsurf/utils/config.h" -#include "netsurf/content/cache.h" #include "netsurf/content/fetchcache.h" #include "netsurf/css/css.h" #ifdef WITH_AUTH @@ -31,7 +32,20 @@ #include "netsurf/utils/messages.h" #include "netsurf/utils/utils.h" -static void browser_window_start_throbber(struct browser_window* bw); + +static void browser_window_callback(content_msg msg, struct content *c, + void *p1, void *p2, const char *error); +static void browser_window_convert_to_download(struct browser_window *bw, + content_msg msg); +static void browser_window_start_throbber(struct browser_window *bw); +static void browser_window_stop_throbber(struct browser_window *bw); +static void browser_window_update(struct browser_window *bw, + bool scroll_to_top); +static void browser_window_set_status(struct browser_window *bw, + const char *text); +static void download_window_callback(content_msg msg, struct content *c, + void *p1, void *p2, const char *error); + static void browser_window_text_selection(struct browser_window* bw, unsigned long click_x, unsigned long click_y, int click_type); static void browser_window_clear_text_selection(struct browser_window* bw); @@ -42,17 +56,6 @@ static int redraw_box_list(struct browser_window* bw, struct box* current, static void browser_window_redraw_boxes(struct browser_window* bw, struct box_position* start, struct box_position* end); static void browser_window_follow_link(struct browser_window* bw, unsigned long click_x, unsigned long click_y, int click_type); -static void browser_window_open_location_post(struct browser_window* bw, - const char* url0 -#ifdef WITH_POST - , char *post_urlenc, - struct form_successful_control *post_multipart -#endif - ); -static void browser_window_callback(content_msg msg, struct content *c, - void *p1, void *p2, const char *error); -static void download_window_callback(content_msg msg, struct content *c, - void *p1, void *p2, const char *error); static void clear_radio_gadgets(struct browser_window* bw, struct box* box, struct form_control* group); static void gui_redraw_gadget2(struct browser_window* bw, struct box* box, struct form_control* g, unsigned long x, unsigned long y); @@ -74,366 +77,367 @@ static void browser_window_place_caret(struct browser_window *bw, int x, int y, int height, void (*callback)(struct browser_window *bw, char key, void *p), void *p); -void browser_window_start_throbber(struct browser_window* bw) -{ - bw->throbbing = 1; - gui_window_start_throbber(bw->window); - return; -} +/** + * Create and open a new browser window with the given page. + * + * \param url URL to start fetching in the new window (copied) + */ -void browser_window_stop_throbber(struct browser_window* bw) +void browser_window_create(const char *url) { - bw->throbbing = 0; - gui_window_stop_throbber(bw->window); -} + struct browser_window *bw; + bw = malloc(sizeof *bw); + if (!bw) { + warn_user("NoMemory"); + return; + } -void browser_window_reformat(struct browser_window* bw, int scroll_to_top) -{ - LOG(("bw = %p", bw)); - - assert(bw != 0); - if (bw->current_content == NULL) - return; - - if (bw->current_content->title == 0) - gui_window_set_title(bw->window, bw->url); - else - gui_window_set_title(bw->window, bw->current_content->title); - gui_window_set_extent(bw->window, bw->current_content->width, bw->current_content->height); - if (scroll_to_top) - gui_window_set_scroll(bw->window, 0, 0); - gui_window_redraw_window(bw->window); - - LOG(("done")); + bw->current_content = 0; + bw->loading_content = 0; + bw->history = history_create(); + bw->throbbing = false; + bw->caret_callback = 0; + bw->window = gui_create_browser_window(bw); + if (!bw->window) { + free(bw); + return; + } + + browser_window_go(bw, url); } -void browser_window_back(struct browser_window* bw) + +/** + * Start fetching a page in a browser window. + * + * \param bw browser window + * \param url URL to start fetching (copied) + * + * Any existing fetches in the window are aborted. + */ + +void browser_window_go(struct browser_window *bw, const char *url) { + browser_window_go_post(bw, url, 0, 0, true); } -void browser_window_forward(struct browser_window* bw) + +/** + * Start fetching a page in a browser window, POSTing form data. + * + * \param bw browser window + * \param url URL to start fetching (copied) + * \param post_urlenc url encoded post data, or 0 if none + * \param post_multipart multipart post data, or 0 if none + * \param history_add add to window history + * + * Any existing fetches in the window are aborted. + * + * If post_urlenc and post_multipart are 0 the url is fetched using GET. + * + * The page is not added to the window history if add_history is false. This + * should be used when returning to a page in the window history. + */ + +void browser_window_go_post(struct browser_window *bw, const char *url, + char *post_urlenc, + struct form_successful_control *post_multipart, + bool history_add) { + struct content *c; + + browser_window_stop(bw); + + browser_window_set_status(bw, "Opening page..."); + bw->history_add = history_add; + bw->time0 = clock(); + c = fetchcache(url, 0, + browser_window_callback, bw, 0, + gui_window_get_width(bw->window), 0, + false, + post_urlenc, post_multipart, + true); + if (!c) { + browser_window_set_status(bw, "Unable to fetch document"); + return; + } + bw->loading_content = c; + browser_window_start_throbber(bw); + + if (c->status == CONTENT_STATUS_READY) { + browser_window_callback(CONTENT_MSG_READY, c, bw, 0, 0); + + } else if (c->status == CONTENT_STATUS_DONE) { + browser_window_callback(CONTENT_MSG_READY, c, bw, 0, 0); + if (c->type == CONTENT_OTHER) + download_window_callback(CONTENT_MSG_DONE, c, bw, 0, 0); + else + browser_window_callback(CONTENT_MSG_DONE, c, bw, 0, 0); + } } -struct browser_window* create_browser_window(int flags, int width, int height -#ifdef WITH_FRAMES -, struct browser_window *parent -#endif -) +/** + * Callback for fetchcache() for browser window fetches. + */ + +void browser_window_callback(content_msg msg, struct content *c, + void *p1, void *p2, const char *error) { - struct browser_window* bw; - bw = (struct browser_window*) xcalloc(1, sizeof(struct browser_window)); + struct browser_window *bw = p1; + char status[40]; - bw->flags = flags; - bw->throbbing = 0; - bw->format_width = width; - bw->format_height = height; + if (c->type == CONTENT_OTHER) { + browser_window_convert_to_download(bw, msg); + return; + } - bw->scale.mult = 1; - bw->scale.div = 1; + switch (msg) { + case CONTENT_MSG_LOADING: + break; - bw->current_content = NULL; - bw->loading_content = NULL; - bw->history_entry = 0; + case CONTENT_MSG_READY: + assert(bw->loading_content == c); + + if (bw->current_content) { + if (bw->current_content->status == + CONTENT_STATUS_DONE) + content_remove_instance( + bw->current_content, + bw, 0, 0, + 0, + &bw->current_content_state); + content_remove_user(bw->current_content, + browser_window_callback, + bw, 0); + } + bw->current_content = c; + bw->loading_content = 0; + bw->caret_callback = 0; + gui_window_set_url(bw->window, c->url); + browser_window_update(bw, true); + browser_window_set_status(bw, c->status_message); + if (bw->history_add) + history_add(bw->history, c); + break; - bw->url = NULL; - bw->caret_callback = 0; + case CONTENT_MSG_DONE: + assert(bw->current_content == c); + + content_add_instance(c, bw, 0, 0, 0, + &bw->current_content_state); + browser_window_update(bw, false); + content_reshape_instance(c, bw, 0, 0, 0, + &bw->current_content_state); + sprintf(status, "Page complete (%gs)", + ((float) (clock() - bw->time0)) / + CLOCKS_PER_SEC); + browser_window_set_status(bw, status); + browser_window_stop_throbber(bw); + history_update(bw->history, c); + break; -#ifdef WITH_FRAMES - bw->parent = parent; + case CONTENT_MSG_ERROR: + browser_window_set_status(bw, error); + if (c == bw->loading_content) + bw->loading_content = 0; + else if (c == bw->current_content) + bw->current_content = 0; + browser_window_stop_throbber(bw); + break; - if (bw->parent != NULL) { - bw->parent->children = xrealloc(bw->parent->children, - (bw->parent->no_children+1) * - sizeof(struct browser_window)); - bw->parent->children[bw->parent->no_children] = bw; - bw->parent->no_children++; + case CONTENT_MSG_STATUS: + browser_window_set_status(bw, c->status_message); + break; - bw->window = NULL; /* This is filled in by frame_add_instance */ - } - else { -#endif + case CONTENT_MSG_REDIRECT: + bw->loading_content = 0; + browser_window_set_status(bw, "Redirecting"); + /* error actually holds the new URL */ + browser_window_go(bw, error); + break; - bw->window = gui_create_browser_window(bw); + case CONTENT_MSG_REFORMAT: + browser_window_update(bw, false); + break; -#ifdef WITH_FRAMES - } +#ifdef WITH_AUTH + case CONTENT_MSG_AUTH: + gui_401login_open(bw, c, error); + if (c == bw->loading_content) + bw->loading_content = 0; + else if (c == bw->current_content) + bw->current_content = 0; + browser_window_stop_throbber(bw); + break; #endif - return bw; + default: + assert(0); + } } -void browser_window_set_status(struct browser_window* bw, const char* text) + +/** + * Transfer the loading_content to a new download window. + */ + +void browser_window_convert_to_download(struct browser_window *bw, + content_msg msg) { - if (bw->window != NULL) - gui_window_set_status(bw->window, text); + gui_window *download_window; + struct content *c = bw->loading_content; + assert(c); + + /* create download window and add content to it */ + download_window = gui_create_download_window(c); + content_add_user(c, download_window_callback, download_window, 0); + + if (msg == CONTENT_MSG_DONE) + download_window_callback(CONTENT_MSG_DONE, c, download_window, + 0, 0); + + /* remove content from browser window */ + bw->loading_content = 0; + content_remove_user(c, browser_window_callback, bw, 0); + browser_window_stop_throbber(bw); } -void browser_window_destroy(struct browser_window* bw -#ifdef WITH_FRAMES -, bool self -#endif -) + +/** + * Start the busy indicator. + * + * \param bw browser window + */ + +void browser_window_start_throbber(struct browser_window *bw) { - /*unsigned int i;*/ - LOG(("bw = %p", bw)); - assert(bw != 0); - -#ifdef WITH_FRAMES - if (bw->no_children == 0 && bw->parent != NULL) { /* leaf node -> delete */ - if (bw->current_content != NULL) { - if (bw->current_content->status == CONTENT_STATUS_DONE) - content_remove_instance(bw->current_content, bw, 0, 0, 0, &bw->current_content_state); -#ifdef WITH_AUTH - login_list_remove(bw->current_content->url); -#endif - } - xfree(bw->url); - xfree(bw); + bw->throbbing = true; + gui_window_start_throbber(bw->window); +} - return; - } - for (i=0; i!=bw->no_children; i++) { /* non-leaf node -> kill children */ - browser_window_destroy(bw->children[i], true); - } +/** + * Stop the busy indicator. + * + * \param bw browser window + */ - /* all children killed -> remove this node */ - if (self || bw->parent != NULL) { -#endif +void browser_window_stop_throbber(struct browser_window *bw) +{ + bw->throbbing = false; + gui_window_stop_throbber(bw->window); +} - if (bw->current_content != NULL) { - if (bw->current_content->status == CONTENT_STATUS_DONE) - content_remove_instance(bw->current_content, bw, 0, 0, 0, &bw->current_content_state); - content_remove_user(bw->current_content, browser_window_callback, bw, 0); -#ifdef WITH_AUTH - login_list_remove(bw->current_content->url); -#endif - } - if (bw->loading_content != NULL) { - content_remove_user(bw->loading_content, browser_window_callback, bw, 0); - } - xfree(bw->url); - gui_window_destroy(bw->window); +/** + * Redraw browser window, set extent to content, and update title. + * + * \param bw browser_window + * \param scroll_to_top move view to top of page + */ -#ifdef WITH_FRAMES - xfree(bw->children); -#endif +void browser_window_update(struct browser_window *bw, + bool scroll_to_top) +{ + if (!bw->current_content) + return; - xfree(bw); + if (bw->current_content->title) + gui_window_set_title(bw->window, bw->current_content->title); + else + gui_window_set_title(bw->window, bw->current_content->url); -#ifdef WITH_FRAMES - } - else { - bw->no_children = 0; - xfree(bw->children); - } -#endif + gui_window_set_extent(bw->window, bw->current_content->width, + bw->current_content->height); - LOG(("end")); + if (scroll_to_top) + gui_window_set_scroll(bw->window, 0, 0); + + gui_window_redraw_window(bw->window); } -void browser_window_open_location_historical(struct browser_window* bw, - const char* url -#ifdef WITH_POST - , char *post_urlenc, - struct form_successful_control *post_multipart -#endif - ) -{ -#ifdef WITH_AUTH - struct login *li; -#endif - LOG(("bw = %p, url = %s", bw, url)); - assert(bw != 0 && url != 0); +/** + * Stop all fetching activity in a browser window. + * + * \param bw browser window + */ - /* Check window still exists, if not, don't bother going any further */ - if (!gui_window_in_list(bw->window)) return; +void browser_window_stop(struct browser_window *bw) +{ + if (bw->loading_content) { + content_remove_user(bw->loading_content, + browser_window_callback, bw, 0); + bw->loading_content = 0; + } -#ifdef WITH_FRAMES - if (bw->url != NULL) - browser_window_destroy(bw, false); -#endif + if (bw->current_content && + bw->current_content->status != CONTENT_STATUS_DONE) { + assert(bw->current_content->status == CONTENT_STATUS_READY); + /** \todo implement content_stop */ + } -#ifdef WITH_AUTH - if ((li = login_list_get(url)) == NULL) { + browser_window_stop_throbber(bw); +} - if (bw->current_content != NULL) { - login_list_remove(bw->current_content->url); - } - } -#endif - browser_window_set_status(bw, "Opening page..."); - browser_window_start_throbber(bw); - bw->time0 = clock(); - bw->history_add = false; - bw->loading_content = fetchcache(url, 0, browser_window_callback, bw, 0, - gui_window_get_width(bw->window), 0, false -#ifdef WITH_POST - ,post_urlenc, post_multipart -#endif -#ifdef WITH_COOKIES - , true -#endif - ); - if (bw->loading_content == 0) { - browser_window_set_status(bw, "Unable to fetch document"); - return; - } - if (bw->loading_content->status == CONTENT_STATUS_READY) - browser_window_callback(CONTENT_MSG_READY, bw->loading_content, bw, 0, 0); - else if (bw->loading_content->status == CONTENT_STATUS_DONE) - browser_window_callback(CONTENT_MSG_DONE, bw->loading_content, bw, 0, 0); - - LOG(("end")); +/** + * Change the status bar of a browser window. + * + * \param bw browser window + * \param text new status text (copied) + */ + +void browser_window_set_status(struct browser_window *bw, const char *text) +{ + gui_window_set_status(bw->window, text); } -void browser_window_open_location(struct browser_window* bw, const char* url0) + +/** + * Close and destroy a browser window. + * + * \param bw browser window + */ + +void browser_window_destroy(struct browser_window *bw) { - browser_window_open_location_post(bw, url0 -#ifdef WITH_POST - , 0, 0 -#endif - ); + if (bw->loading_content) { + content_remove_user(bw->loading_content, + browser_window_callback, bw, 0); + bw->loading_content = 0; + } + + if (bw->current_content) { + if (bw->current_content->status == CONTENT_STATUS_DONE) + content_remove_instance(bw->current_content, bw, 0, + 0, 0, &bw->current_content_state); + content_remove_user(bw->current_content, + browser_window_callback, bw, 0); + } + + history_destroy(bw->history); + gui_window_destroy(bw->window); + + free(bw); } -void browser_window_open_location_post(struct browser_window* bw, - const char* url -#ifdef WITH_POST - , char *post_urlenc, - struct form_successful_control *post_multipart -#endif - ) + + +void browser_window_back(struct browser_window* bw) { - char *url1; - LOG(("bw = %p, url = %s", bw, url)); - assert(bw != 0 && url != 0); - url1 = url_join(url, 0); - if (!url1) - return; - browser_window_open_location_historical(bw, url1 -#ifdef WITH_POST - , post_urlenc, post_multipart -#endif - ); - bw->history_add = true; - free(url1); - LOG(("end")); } -void browser_window_callback(content_msg msg, struct content *c, - void *p1, void *p2, const char *error) +void browser_window_forward(struct browser_window* bw) { - struct browser_window* bw = p1; - gui_safety previous_safety; - char status[40]; - - switch (msg) - { - case CONTENT_MSG_LOADING: - case CONTENT_MSG_READY: - case CONTENT_MSG_DONE: - if (c->type == CONTENT_OTHER) { - gui_window *download_window; - assert(bw->loading_content == c); - - /* create download window and add content to it */ - download_window = gui_create_download_window(c); - content_add_user(c, download_window_callback, download_window, 0); - if (msg == CONTENT_MSG_DONE) - download_window_callback(CONTENT_MSG_DONE, c, download_window, 0, 0); - - /* remove content from browser window */ - bw->loading_content = 0; - content_remove_user(c, browser_window_callback, bw, 0); - browser_window_stop_throbber(bw); - - break; - } - - if (msg == CONTENT_MSG_LOADING) - break; - - previous_safety = gui_window_set_redraw_safety(bw->window, UNSAFE); - if (bw->loading_content == c) { - if (bw->url != 0) - xfree(bw->url); - bw->url = xstrdup(c->url); - - gui_window_set_url(bw->window, bw->url); - - if (bw->current_content != NULL) - { - if (bw->current_content->status == CONTENT_STATUS_DONE) - content_remove_instance(bw->current_content, bw, 0, 0, 0, &bw->current_content_state); - content_remove_user(bw->current_content, browser_window_callback, bw, 0); - } - bw->current_content = c; - bw->loading_content = 0; - bw->caret_callback = 0; - if (bw->history_add) - bw->history_entry = history_add(bw->history_entry, bw->url, - bw->current_content->title); - bw->history_add = false; - } - gui_window_set_redraw_safety(bw->window, previous_safety); - if (bw->current_content->status == CONTENT_STATUS_DONE) { - content_add_instance(bw->current_content, bw, 0, 0, 0, &bw->current_content_state); - browser_window_reformat(bw, 0); - content_reshape_instance(bw->current_content, bw, 0, 0, 0, &bw->current_content_state); - sprintf(status, "Page complete (%gs)", ((float) (clock() - bw->time0)) / CLOCKS_PER_SEC); - browser_window_set_status(bw, status); - browser_window_stop_throbber(bw); - } else { - browser_window_reformat(bw, 1); - browser_window_set_status(bw, c->status_message); - } - break; - - case CONTENT_MSG_ERROR: - browser_window_set_status(bw, error); - if (c == bw->loading_content) - bw->loading_content = 0; - else if (c == bw->current_content) - bw->current_content = 0; - browser_window_stop_throbber(bw); - break; - - case CONTENT_MSG_STATUS: - browser_window_set_status(bw, c->status_message); - break; - - case CONTENT_MSG_REDIRECT: - bw->loading_content = 0; - browser_window_set_status(bw, "Redirecting"); - /* error actually holds the new URL */ - browser_window_open_location(bw, error); - break; - - case CONTENT_MSG_REFORMAT: - browser_window_reformat(bw, 0); - break; +} -#ifdef WITH_AUTH - case CONTENT_MSG_AUTH: - gui_401login_open(bw, c, error); - if (c == bw->loading_content) - bw->loading_content = 0; - else if (c == bw->current_content) - bw->current_content = 0; - browser_window_stop_throbber(bw); - break; -#endif - default: - assert(0); - } -} +/** + * Callback for fetchcache() for download window fetches. + */ void download_window_callback(content_msg msg, struct content *c, void *p1, void *p2, const char *error) @@ -454,13 +458,12 @@ void download_window_callback(content_msg msg, struct content *c, break; case CONTENT_MSG_READY: - /* not possible for CONTENT_OTHER */ - assert(0); break; case CONTENT_MSG_LOADING: case CONTENT_MSG_REDIRECT: - /* not possible at this point, handled above */ + /* not possible at this point, handled in + browser_window_callback() */ assert(0); break; @@ -474,49 +477,53 @@ void download_window_callback(content_msg msg, struct content *c, } } -void clear_radio_gadgets(struct browser_window* bw, struct box* box, struct form_control* group) +void clear_radio_gadgets(struct browser_window *bw, struct box *box, + struct form_control *group) { - struct box* c; + struct box *c; if (box == NULL) return; - if (box->gadget != 0) - { - if (box->gadget->type == GADGET_RADIO && box->gadget->name != 0 && box->gadget != group) - { - if (strcmp(box->gadget->name, group->name) == 0) - { - if (box->gadget->data.radio.selected) - { - box->gadget->data.radio.selected = 0; + if (box->gadget != 0) { + if (box->gadget->type == GADGET_RADIO + && box->gadget->name != 0 && box->gadget != group) { + if (strcmp(box->gadget->name, group->name) == 0) { + if (box->gadget->data.radio.selected) { + box->gadget->data.radio.selected = + 0; gui_redraw_gadget(bw, box->gadget); } } } } - for (c = box->children; c != 0; c = c->next) - if (c->type != BOX_FLOAT_LEFT && c->type != BOX_FLOAT_RIGHT) - clear_radio_gadgets(bw, c, group); + for (c = box->children; c != 0; c = c->next) + if (c->type != BOX_FLOAT_LEFT + && c->type != BOX_FLOAT_RIGHT) + clear_radio_gadgets(bw, c, group); - for (c = box->float_children; c != 0; c = c->next_float) - clear_radio_gadgets(bw, c, group); + for (c = box->float_children; c != 0; c = c->next_float) + clear_radio_gadgets(bw, c, group); } -void gui_redraw_gadget2(struct browser_window* bw, struct box* box, struct form_control* g, - unsigned long x, unsigned long y) +void gui_redraw_gadget2(struct browser_window *bw, struct box *box, + struct form_control *g, unsigned long x, + unsigned long y) { - struct box* c; + struct box *c; - if (box->gadget == g) - { - gui_window_redraw(bw->window, x + box->x, y + box->y, x + box->x + box->width, y+box->y + box->height); + if (box->gadget == g) { + gui_window_redraw(bw->window, x + box->x, y + box->y, + x + box->x + box->width, + y + box->y + box->height); } - for (c = box->children; c != 0; c = c->next) - if (c->type != BOX_FLOAT_LEFT && c->type != BOX_FLOAT_RIGHT) - gui_redraw_gadget2(bw, c, g, box->x + x, box->y + y); + for (c = box->children; c != 0; c = c->next) + if (c->type != BOX_FLOAT_LEFT + && c->type != BOX_FLOAT_RIGHT) + gui_redraw_gadget2(bw, c, g, box->x + x, + box->y + y); - for (c = box->float_children; c != 0; c = c->next_float) - gui_redraw_gadget2(bw, c, g, box->x + x, box->y + y); + for (c = box->float_children; c != 0; c = c->next_float) + gui_redraw_gadget2(bw, c, g, box->x + x, box->y + y); } void gui_redraw_gadget(struct browser_window* bw, struct form_control* g) @@ -1209,378 +1216,422 @@ bool browser_window_key_press(struct browser_window *bw, char key) } -int browser_window_action(struct browser_window* bw, struct browser_action* act) +int browser_window_action(struct browser_window *bw, + struct browser_action *act) { - switch (act->type) - { - case act_MOUSE_AT: - browser_window_follow_link(bw, act->data.mouse.x, act->data.mouse.y, 0); - break; - case act_MOUSE_CLICK: - return browser_window_gadget_click(bw, act->data.mouse.x, act->data.mouse.y); - break; - case act_CLEAR_SELECTION: - browser_window_text_selection(bw, act->data.mouse.x, act->data.mouse.y, 0); - break; - case act_START_NEW_SELECTION: - browser_window_text_selection(bw, act->data.mouse.x, act->data.mouse.y, 1); - break; - case act_ALTER_SELECTION: - browser_window_text_selection(bw, act->data.mouse.x, act->data.mouse.y, 2); - break; - case act_FOLLOW_LINK: - browser_window_follow_link(bw, act->data.mouse.x, act->data.mouse.y, 1); - break; - case act_FOLLOW_LINK_NEW_WINDOW: - browser_window_follow_link(bw, act->data.mouse.x, act->data.mouse.y, 2); - break; - case act_GADGET_SELECT: - browser_window_gadget_select(bw, act->data.gadget_select.g, act->data.gadget_select.item); - default: - break; - } - return 0; + switch (act->type) { + case act_MOUSE_AT: + browser_window_follow_link(bw, act->data.mouse.x, + act->data.mouse.y, 0); + break; + case act_MOUSE_CLICK: + return browser_window_gadget_click(bw, act->data.mouse.x, + act->data.mouse.y); + break; + case act_CLEAR_SELECTION: + browser_window_text_selection(bw, act->data.mouse.x, + act->data.mouse.y, 0); + break; + case act_START_NEW_SELECTION: + browser_window_text_selection(bw, act->data.mouse.x, + act->data.mouse.y, 1); + break; + case act_ALTER_SELECTION: + browser_window_text_selection(bw, act->data.mouse.x, + act->data.mouse.y, 2); + break; + case act_FOLLOW_LINK: + browser_window_follow_link(bw, act->data.mouse.x, + act->data.mouse.y, 1); + break; + case act_FOLLOW_LINK_NEW_WINDOW: + browser_window_follow_link(bw, act->data.mouse.x, + act->data.mouse.y, 2); + break; + case act_GADGET_SELECT: + browser_window_gadget_select(bw, act->data.gadget_select.g, + act->data.gadget_select.item); + default: + break; + } + return 0; } -void box_under_area(struct box* box, unsigned long x, unsigned long y, unsigned long ox, unsigned long oy, - struct box_selection** found, int* count, int* plot_index) +void box_under_area(struct box *box, unsigned long x, unsigned long y, + unsigned long ox, unsigned long oy, + struct box_selection **found, int *count, + int *plot_index) { - struct box* c; - - if (box == NULL) - return; + struct box *c; - *plot_index = *plot_index + 1; + if (box == NULL) + return; - if (x >= box->x + ox && x <= box->x + ox + box->width && - y >= box->y + oy && y <= box->y + oy + box->height) - { - *found = xrealloc(*found, sizeof(struct box_selection) * (*count + 1)); - (*found)[*count].box = box; - (*found)[*count].actual_x = box->x + ox; - (*found)[*count].actual_y = box->y + oy; - (*found)[*count].plot_index = *plot_index; - *count = *count + 1; - } + *plot_index = *plot_index + 1; + + if (x >= box->x + ox && x <= box->x + ox + box->width && + y >= box->y + oy && y <= box->y + oy + box->height) { + *found = + xrealloc(*found, + sizeof(struct box_selection) * (*count + 1)); + (*found)[*count].box = box; + (*found)[*count].actual_x = box->x + ox; + (*found)[*count].actual_y = box->y + oy; + (*found)[*count].plot_index = *plot_index; + *count = *count + 1; + } - for (c = box->children; c != 0; c = c->next) - if (c->type != BOX_FLOAT_LEFT && c->type != BOX_FLOAT_RIGHT) - box_under_area(c, x, y, box->x + ox, box->y + oy, found, count, plot_index); + for (c = box->children; c != 0; c = c->next) + if (c->type != BOX_FLOAT_LEFT + && c->type != BOX_FLOAT_RIGHT) + box_under_area(c, x, y, box->x + ox, box->y + oy, + found, count, plot_index); - for (c = box->float_children; c != 0; c = c->next_float) - box_under_area(c, x, y, box->x + ox, box->y + oy, found, count, plot_index); + for (c = box->float_children; c != 0; c = c->next_float) + box_under_area(c, x, y, box->x + ox, box->y + oy, found, + count, plot_index); - return; + return; } -void browser_window_follow_link(struct browser_window* bw, - unsigned long click_x, unsigned long click_y, int click_type) +void browser_window_follow_link(struct browser_window *bw, + unsigned long click_x, + unsigned long click_y, int click_type) { - struct box_selection* click_boxes; - int found, plot_index; - int i; - int done = 0; - - found = 0; - click_boxes = NULL; - plot_index = 0; - - if (bw->current_content->type != CONTENT_HTML) - return; - - box_under_area(bw->current_content->data.html.layout->children, - click_x, click_y, 0, 0, &click_boxes, &found, &plot_index); - - if (found == 0) - return; - - for (i = found - 1; i >= 0; i--) - { - if (click_boxes[i].box->style->visibility == CSS_VISIBILITY_HIDDEN) - continue; - if (click_boxes[i].box->href != NULL) - { - char *url = url_join((char*) click_boxes[i].box->href, - bw->current_content->data.html.base_url); - if (!url) - continue; - - if (click_type == 1) { - browser_window_open_location(bw, url); - } - else if (click_type == 2) - { - struct browser_window* bw_new; - bw_new = create_browser_window(browser_TITLE | browser_TOOLBAR - | browser_SCROLL_X_ALWAYS | browser_SCROLL_Y_ALWAYS, 640, 480 -#ifdef WITH_FRAMES - , NULL -#endif - ); - gui_window_show(bw_new->window); - browser_window_open_location(bw_new, url); - } - else if (click_type == 0) - { - browser_window_set_status(bw, url); - done = 1; - } - free(url); - break; - } - if (click_type == 0 && click_boxes[i].box->title != NULL) - { - browser_window_set_status(bw, click_boxes[i].box->title); - done = 1; - break; - } - } - - if (click_type == 0 && done == 0) { - if (bw->loading_content != 0) - browser_window_set_status(bw, bw->loading_content->status_message); - else - browser_window_set_status(bw, bw->current_content->status_message); - } - - free(click_boxes); - - return; + struct box_selection *click_boxes; + int found, plot_index; + int i; + int done = 0; + + found = 0; + click_boxes = NULL; + plot_index = 0; + + if (bw->current_content->type != CONTENT_HTML) + return; + + box_under_area(bw->current_content->data.html.layout->children, + click_x, click_y, 0, 0, &click_boxes, &found, + &plot_index); + + if (found == 0) + return; + + for (i = found - 1; i >= 0; i--) { + if (click_boxes[i].box->style->visibility == + CSS_VISIBILITY_HIDDEN) + continue; + if (click_boxes[i].box->href != NULL) { + char *url = + url_join((char *) click_boxes[i].box->href, + bw->current_content->data.html. + base_url); + if (!url) + continue; + + if (click_type == 1) { + browser_window_go(bw, url); + } else if (click_type == 2) { + browser_window_create(url); + } else if (click_type == 0) { + browser_window_set_status(bw, url); + done = 1; + } + free(url); + break; + } + if (click_type == 0 && click_boxes[i].box->title != NULL) { + browser_window_set_status(bw, + click_boxes[i].box-> + title); + done = 1; + break; + } + } + + if (click_type == 0 && done == 0) { + if (bw->loading_content != 0) + browser_window_set_status(bw, + bw->loading_content-> + status_message); + else + browser_window_set_status(bw, + bw->current_content-> + status_message); + } + + free(click_boxes); + + return; } -void browser_window_text_selection(struct browser_window* bw, - unsigned long click_x, unsigned long click_y, int click_type) +void browser_window_text_selection(struct browser_window *bw, + unsigned long click_x, + unsigned long click_y, int click_type) { - struct box_selection* click_boxes; - int found, plot_index; - int i; - - if (click_type == 0 /* click_CLEAR_SELECTION */ ) - { - browser_window_clear_text_selection(bw); - return; - } - - found = 0; - click_boxes = NULL; - plot_index = 0; - - assert(bw->current_content->type == CONTENT_HTML); - box_under_area(bw->current_content->data.html.layout->children, - click_x, click_y, 0, 0, &click_boxes, &found, &plot_index); - - if (found == 0) - return; - - for (i = found - 1; i >= 0; i--) - { - if (click_boxes[i].box->type == BOX_INLINE) - { - struct box_position new_pos; - struct box_position* start; - struct box_position* end; - int click_char_offset, click_pixel_offset; - - /* shortcuts */ - start = &(bw->current_content->data.html.text_selection.start); - end = &(bw->current_content->data.html.text_selection.end); - - if (click_boxes[i].box->text && click_boxes[i].box->font) - { - font_position_in_string(click_boxes[i].box->text, - click_boxes[i].box->font, click_boxes[i].box->length, - click_x - click_boxes[i].actual_x, - &click_char_offset, &click_pixel_offset); - } - else - { - click_char_offset = 0; - click_pixel_offset = 0; - } - - new_pos.box = click_boxes[i].box; - new_pos.actual_box_x = click_boxes[i].actual_x; - new_pos.actual_box_y = click_boxes[i].actual_y; - new_pos.plot_index = click_boxes[i].plot_index; - new_pos.char_offset = click_char_offset; - new_pos.pixel_offset = click_pixel_offset; - - if (click_type == 1 /* click_START_SELECTION */ ) - { - /* update both start and end */ - browser_window_clear_text_selection(bw); - bw->current_content->data.html.text_selection.altering = alter_UNKNOWN; - bw->current_content->data.html.text_selection.selected = 1; - memcpy(start, &new_pos, sizeof(struct box_position)); - memcpy(end, &new_pos, sizeof(struct box_position)); - i = -1; - } - else if (bw->current_content->data.html.text_selection.selected == 1 && - click_type == 2 /* click_ALTER_SELECTION */) - { - /* alter selection */ - - if (bw->current_content->data.html.text_selection.altering - != alter_UNKNOWN) - { - if (bw->current_content->data.html.text_selection.altering - == alter_START) - { - if (box_position_gt(&new_pos,end)) - { - bw->current_content->data.html.text_selection.altering - = alter_END; - browser_window_change_text_selection(bw, end, &new_pos); - } - else - browser_window_change_text_selection(bw, &new_pos, end); - } - else - { - if (box_position_lt(&new_pos,start)) - { - bw->current_content->data.html.text_selection.altering - = alter_START; - browser_window_change_text_selection(bw, &new_pos, start); - } - else - browser_window_change_text_selection(bw, start, &new_pos); - } - i = -1; - } - else - { - /* work out whether the start or end is being dragged */ - - int click_start_distance = 0; - int click_end_distance = 0; - - int inside_block = 0; - int before_start = 0; - int after_end = 0; - - if (box_position_lt(&new_pos, start)) - before_start = 1; - - if (box_position_gt(&new_pos, end)) - after_end = 1; - - if (!box_position_lt(&new_pos, start) - && !box_position_gt(&new_pos, end)) - inside_block = 1; - - if (inside_block == 1) - { - click_start_distance = box_position_distance(start, &new_pos); - click_end_distance = box_position_distance(end, &new_pos); - } - - if (before_start == 1 - || (after_end == 0 && inside_block == 1 - && click_start_distance < click_end_distance)) - { - /* alter the start position */ - bw->current_content->data.html.text_selection.altering - = alter_START; - browser_window_change_text_selection(bw, &new_pos, end); - i = -1; - } - else if (after_end == 1 - || (before_start == 0 && inside_block == 1 - && click_start_distance >= click_end_distance)) - { - /* alter the end position */ - bw->current_content->data.html.text_selection.altering = alter_END; - browser_window_change_text_selection(bw, start, &new_pos); - i = -1; - } - } - } - } - } + struct box_selection *click_boxes; + int found, plot_index; + int i; - free(click_boxes); + if (click_type == 0 /* click_CLEAR_SELECTION */ ) { + browser_window_clear_text_selection(bw); + return; + } - return; + found = 0; + click_boxes = NULL; + plot_index = 0; + + assert(bw->current_content->type == CONTENT_HTML); + box_under_area(bw->current_content->data.html.layout->children, + click_x, click_y, 0, 0, &click_boxes, &found, + &plot_index); + + if (found == 0) + return; + + for (i = found - 1; i >= 0; i--) { + if (click_boxes[i].box->type == BOX_INLINE) { + struct box_position new_pos; + struct box_position *start; + struct box_position *end; + int click_char_offset, click_pixel_offset; + + /* shortcuts */ + start = + &(bw->current_content->data.html. + text_selection.start); + end = + &(bw->current_content->data.html. + text_selection.end); + + if (click_boxes[i].box->text + && click_boxes[i].box->font) { + font_position_in_string(click_boxes[i]. + box->text, + click_boxes[i]. + box->font, + click_boxes[i]. + box->length, + click_x - + click_boxes[i]. + actual_x, + &click_char_offset, + &click_pixel_offset); + } else { + click_char_offset = 0; + click_pixel_offset = 0; + } + + new_pos.box = click_boxes[i].box; + new_pos.actual_box_x = click_boxes[i].actual_x; + new_pos.actual_box_y = click_boxes[i].actual_y; + new_pos.plot_index = click_boxes[i].plot_index; + new_pos.char_offset = click_char_offset; + new_pos.pixel_offset = click_pixel_offset; + + if (click_type == 1 /* click_START_SELECTION */ ) { + /* update both start and end */ + browser_window_clear_text_selection(bw); + bw->current_content->data.html. + text_selection.altering = + alter_UNKNOWN; + bw->current_content->data.html. + text_selection.selected = 1; + memcpy(start, &new_pos, + sizeof(struct box_position)); + memcpy(end, &new_pos, + sizeof(struct box_position)); + i = -1; + } else if (bw->current_content->data.html. + text_selection.selected == 1 + && click_type == + 2 /* click_ALTER_SELECTION */ ) { + /* alter selection */ + + if (bw->current_content->data.html. + text_selection.altering != + alter_UNKNOWN) { + if (bw->current_content->data.html. + text_selection.altering == + alter_START) { + if (box_position_gt + (&new_pos, end)) { + bw->current_content->data.html.text_selection.altering = alter_END; + browser_window_change_text_selection + (bw, end, + &new_pos); + } else + browser_window_change_text_selection + (bw, &new_pos, + end); + } else { + if (box_position_lt + (&new_pos, start)) { + bw->current_content->data.html.text_selection.altering = alter_START; + browser_window_change_text_selection + (bw, &new_pos, + start); + } else + browser_window_change_text_selection + (bw, start, + &new_pos); + } + i = -1; + } else { + /* work out whether the start or end is being dragged */ + + int click_start_distance = 0; + int click_end_distance = 0; + + int inside_block = 0; + int before_start = 0; + int after_end = 0; + + if (box_position_lt + (&new_pos, start)) + before_start = 1; + + if (box_position_gt(&new_pos, end)) + after_end = 1; + + if (!box_position_lt + (&new_pos, start) + && !box_position_gt(&new_pos, + end)) + inside_block = 1; + + if (inside_block == 1) { + click_start_distance = + box_position_distance + (start, &new_pos); + click_end_distance = + box_position_distance + (end, &new_pos); + } + + if (before_start == 1 + || (after_end == 0 + && inside_block == 1 + && click_start_distance < + click_end_distance)) { + /* alter the start position */ + bw->current_content->data. + html.text_selection. + altering = alter_START; + browser_window_change_text_selection + (bw, &new_pos, end); + i = -1; + } else if (after_end == 1 + || (before_start == 0 + && inside_block == 1 + && + click_start_distance + >= + click_end_distance)) + { + /* alter the end position */ + bw->current_content->data. + html.text_selection. + altering = alter_END; + browser_window_change_text_selection + (bw, start, &new_pos); + i = -1; + } + } + } + } + } + + free(click_boxes); + + return; } -void browser_window_clear_text_selection(struct browser_window* bw) +void browser_window_clear_text_selection(struct browser_window *bw) { - struct box_position* old_start; - struct box_position* old_end; + struct box_position *old_start; + struct box_position *old_end; - assert(bw->current_content->type == CONTENT_HTML); - old_start = &(bw->current_content->data.html.text_selection.start); - old_end = &(bw->current_content->data.html.text_selection.end); + assert(bw->current_content->type == CONTENT_HTML); + old_start = &(bw->current_content->data.html.text_selection.start); + old_end = &(bw->current_content->data.html.text_selection.end); - if (bw->current_content->data.html.text_selection.selected == 1) - { - bw->current_content->data.html.text_selection.selected = 0; - browser_window_redraw_boxes(bw, old_start, old_end); - } + if (bw->current_content->data.html.text_selection.selected == 1) { + bw->current_content->data.html.text_selection.selected = 0; + browser_window_redraw_boxes(bw, old_start, old_end); + } - bw->current_content->data.html.text_selection.altering = alter_UNKNOWN; + bw->current_content->data.html.text_selection.altering = + alter_UNKNOWN; } -void browser_window_change_text_selection(struct browser_window* bw, - struct box_position* new_start, struct box_position* new_end) +void browser_window_change_text_selection(struct browser_window *bw, + struct box_position *new_start, + struct box_position *new_end) { - struct box_position start; - struct box_position end; - - assert(bw->current_content->type == CONTENT_HTML); - memcpy(&start, &(bw->current_content->data.html.text_selection.start), sizeof(struct box_position)); - memcpy(&end, &(bw->current_content->data.html.text_selection.end), sizeof(struct box_position)); - - if (!box_position_eq(new_start, &start)) - { - if (box_position_lt(new_start, &start)) - browser_window_redraw_boxes(bw, new_start, &start); - else - browser_window_redraw_boxes(bw, &start, new_start); - memcpy(&start, new_start, sizeof(struct box_position)); - } - - if (!box_position_eq(new_end, &end)) - { - if (box_position_lt(new_end, &end)) - browser_window_redraw_boxes(bw, new_end, &end); - else - browser_window_redraw_boxes(bw, &end, new_end); - memcpy(&end, new_end, sizeof(struct box_position)); - } - - memcpy(&(bw->current_content->data.html.text_selection.start), &start, sizeof(struct box_position)); - memcpy(&(bw->current_content->data.html.text_selection.end), &end, sizeof(struct box_position)); - - bw->current_content->data.html.text_selection.selected = 1; + struct box_position start; + struct box_position end; + + assert(bw->current_content->type == CONTENT_HTML); + memcpy(&start, + &(bw->current_content->data.html.text_selection.start), + sizeof(struct box_position)); + memcpy(&end, &(bw->current_content->data.html.text_selection.end), + sizeof(struct box_position)); + + if (!box_position_eq(new_start, &start)) { + if (box_position_lt(new_start, &start)) + browser_window_redraw_boxes(bw, new_start, &start); + else + browser_window_redraw_boxes(bw, &start, new_start); + memcpy(&start, new_start, sizeof(struct box_position)); + } + + if (!box_position_eq(new_end, &end)) { + if (box_position_lt(new_end, &end)) + browser_window_redraw_boxes(bw, new_end, &end); + else + browser_window_redraw_boxes(bw, &end, new_end); + memcpy(&end, new_end, sizeof(struct box_position)); + } + + memcpy(&(bw->current_content->data.html.text_selection.start), + &start, sizeof(struct box_position)); + memcpy(&(bw->current_content->data.html.text_selection.end), &end, + sizeof(struct box_position)); + + bw->current_content->data.html.text_selection.selected = 1; } -int box_position_lt(struct box_position* x, struct box_position* y) +int box_position_lt(struct box_position *x, struct box_position *y) { - return (x->plot_index < y->plot_index || - (x->plot_index == y->plot_index && x->char_offset < y->char_offset)); + return (x->plot_index < y->plot_index || + (x->plot_index == y->plot_index + && x->char_offset < y->char_offset)); } -int box_position_gt(struct box_position* x, struct box_position* y) +int box_position_gt(struct box_position *x, struct box_position *y) { - return (x->plot_index > y->plot_index || - (x->plot_index == y->plot_index && x->char_offset > y->char_offset)); + return (x->plot_index > y->plot_index || + (x->plot_index == y->plot_index + && x->char_offset > y->char_offset)); } -int box_position_eq(struct box_position* x, struct box_position* y) +int box_position_eq(struct box_position *x, struct box_position *y) { - return (x->plot_index == y->plot_index && x->char_offset == y->char_offset); + return (x->plot_index == y->plot_index + && x->char_offset == y->char_offset); } -int box_position_distance(struct box_position* x, struct box_position* y) +int box_position_distance(struct box_position *x, struct box_position *y) { - int dx = (y->actual_box_x + y->pixel_offset) - - (x->actual_box_x + x->pixel_offset); - int dy = (y->actual_box_y + y->box->height / 2) - - (x->actual_box_y + x->box->height / 2); - return dx*dx + dy*dy; + int dx = (y->actual_box_x + y->pixel_offset) + - (x->actual_box_x + x->pixel_offset); + int dy = (y->actual_box_y + y->box->height / 2) + - (x->actual_box_y + x->box->height / 2); + return dx * dx + dy * dy; } unsigned long redraw_min_x = LONG_MAX; @@ -1588,74 +1639,77 @@ unsigned long redraw_min_y = LONG_MAX; unsigned long redraw_max_x = 0; unsigned long redraw_max_y = 0; -int redraw_box_list(struct browser_window* bw, struct box* current, - unsigned long x, unsigned long y, struct box_position* start, - struct box_position* end, int* plot) +int redraw_box_list(struct browser_window *bw, struct box *current, + unsigned long x, unsigned long y, + struct box_position *start, struct box_position *end, + int *plot) { - struct box* c; - - if (current == start->box) - *plot = 1; - - if (*plot >= 1 && current->type == BOX_INLINE) - { - unsigned long minx = x + current->x; - unsigned long miny = y + current->y; - unsigned long maxx = x + current->x + current->width; - unsigned long maxy = y + current->y + current->height; - - if (minx < redraw_min_x) - redraw_min_x = minx; - if (miny < redraw_min_y) - redraw_min_y = miny; - if (maxx > redraw_max_x) - redraw_max_x = maxx; - if (maxy > redraw_max_y) - redraw_max_y = maxy; - - *plot = 2; - } - - if (current == end->box) - return 1; - - for (c = current->children; c != 0; c = c->next) - if (c->type != BOX_FLOAT_LEFT && c->type != BOX_FLOAT_RIGHT) - if (redraw_box_list(bw, c, x + current->x, y + current->y, - start, end, plot) == 1) - return 1; - - for (c = current->float_children; c != 0; c = c->next_float) - if (redraw_box_list(bw, c, x + current->x, y + current->y, - start, end, plot) == 1) - return 1; - - return 0; + struct box *c; + + if (current == start->box) + *plot = 1; + + if (*plot >= 1 && current->type == BOX_INLINE) { + unsigned long minx = x + current->x; + unsigned long miny = y + current->y; + unsigned long maxx = x + current->x + current->width; + unsigned long maxy = y + current->y + current->height; + + if (minx < redraw_min_x) + redraw_min_x = minx; + if (miny < redraw_min_y) + redraw_min_y = miny; + if (maxx > redraw_max_x) + redraw_max_x = maxx; + if (maxy > redraw_max_y) + redraw_max_y = maxy; + + *plot = 2; + } + + if (current == end->box) + return 1; + + for (c = current->children; c != 0; c = c->next) + if (c->type != BOX_FLOAT_LEFT + && c->type != BOX_FLOAT_RIGHT) + if (redraw_box_list + (bw, c, x + current->x, y + current->y, start, + end, plot) == 1) + return 1; + + for (c = current->float_children; c != 0; c = c->next_float) + if (redraw_box_list(bw, c, x + current->x, y + current->y, + start, end, plot) == 1) + return 1; + + return 0; } -void browser_window_redraw_boxes(struct browser_window* bw, struct box_position* start, struct box_position* end) +void browser_window_redraw_boxes(struct browser_window *bw, + struct box_position *start, + struct box_position *end) { - int plot = 0; + int plot = 0; - assert(bw->current_content->type == CONTENT_HTML); - if (box_position_eq(start, end)) - return; + assert(bw->current_content->type == CONTENT_HTML); + if (box_position_eq(start, end)) + return; - redraw_min_x = LONG_MAX; - redraw_min_y = LONG_MAX; - redraw_max_x = 0; - redraw_max_y = 0; + redraw_min_x = LONG_MAX; + redraw_min_y = LONG_MAX; + redraw_max_x = 0; + redraw_max_y = 0; - redraw_box_list(bw, bw->current_content->data.html.layout, - 0,0, start, end, &plot); + redraw_box_list(bw, bw->current_content->data.html.layout, + 0, 0, start, end, &plot); - if (plot == 2) - gui_window_redraw(bw->window, redraw_min_x, redraw_min_y, - redraw_max_x, redraw_max_y); + if (plot == 2) + gui_window_redraw(bw->window, redraw_min_x, redraw_min_y, + redraw_max_x, redraw_max_y); } - /** * Collect controls and submit a form. */ @@ -1685,26 +1739,22 @@ void browser_form_submit(struct browser_window *bw, struct form *form, url1 = url_join(url, base); if (!url1) break; - browser_window_open_location(bw, url1); + browser_window_go(bw, url1); break; -#ifdef WITH_POST + case method_POST_URLENC: data = form_url_encode(success); url = url_join(form->action, base); if (!url) break; - browser_window_open_location_post(bw, url, data, 0); + browser_window_go_post(bw, url, data, 0, true); break; case method_POST_MULTIPART: url = url_join(form->action, base); - browser_window_open_location_post(bw, url, 0, success); + browser_window_go_post(bw, url, 0, success, true); break; -#else - case method_POST_URLENC: - case method_POST_MULTIPART: - break; -#endif + default: assert(0); } diff --git a/desktop/browser.h b/desktop/browser.h index ead88eb82..3f2bae61a 100644 --- a/desktop/browser.h +++ b/desktop/browser.h @@ -3,7 +3,11 @@ * Licensed under the GNU General Public License, * http://www.opensource.org/licenses/gpl-license * Copyright 2003 Phil Mellor - * Copyright 2003 James Bursa + * Copyright 2004 James Bursa + */ + +/** \file + * Browser window creation and manipulation (interface). */ #ifndef _NETSURF_DESKTOP_BROWSER_H_ @@ -14,47 +18,39 @@ #include "netsurf/utils/config.h" #include "netsurf/content/content.h" #include "netsurf/desktop/gui.h" -#include "netsurf/render/box.h" - -typedef int browser_window_flags; -#define browser_TOOLBAR ((browser_window_flags) 1) -#define browser_TITLE ((browser_window_flags) 2) -#define browser_SCROLL_X_NONE ((browser_window_flags) 4) -#define browser_SCROLL_X_AUTO ((browser_window_flags) 8) -#define browser_SCROLL_X_ALWAYS ((browser_window_flags) 16) -#define browser_SCROLL_Y_NONE ((browser_window_flags) 32) -#define browser_SCROLL_Y_AUTO ((browser_window_flags) 64) -#define browser_SCROLL_Y_ALWAYS ((browser_window_flags) 128) - -typedef int action_buttons; -#define act_BUTTON_NORMAL ((action_buttons) 4) -#define act_BUTTON_ALTERNATIVE ((action_buttons) 1) -#define act_BUTTON_CONTEXT_MENU ((action_buttons) 2) -struct history_entry; +struct box; +struct history; +/** Browser window data. */ struct browser_window { - unsigned long format_width; - unsigned long format_height; - struct { int mult; int div; } scale; + /** Page currently displayed, or 0. Must have status READY or DONE. */ + struct content *current_content; + /** Instance state pointer for current_content. */ + void *current_content_state; + /** Page being loaded, or 0. */ + struct content *loading_content; - struct content* current_content; - void *current_content_state; - struct content* loading_content; - struct history_entry *history_entry; - bool history_add; - clock_t time0; + /** Window history structure. */ + struct history *history; - char* url; + /** Handler for keyboard input, or 0. */ + void (*caret_callback)(struct browser_window *bw, char key, void *p); + /** User parameter for caret_callback. */ + void *caret_p; - browser_window_flags flags; - gui_window* window; + /** Platform specific window handle. */ + gui_window *window; + + /** Busy indicator is active. */ + bool throbbing; + /** Add loading_content to the window history when it loads. */ + bool history_add; + /** Start time of fetching loading_content. */ + clock_t time0; - int throbbing; - void (*caret_callback)(struct browser_window *bw, char key, void *p); - void *caret_p; #ifdef WITH_FRAMES struct browser_window *parent; unsigned int no_children; @@ -75,7 +71,6 @@ struct browser_action struct { unsigned long x; unsigned long y; - action_buttons buttons; } mouse; struct { struct form_control* g; @@ -92,32 +87,21 @@ struct box_selection int plot_index; }; -/* public functions */ -struct browser_window* create_browser_window(int flags, int width, int height -#ifdef WITH_FRAMES -, struct browser_window *parent -#endif -); -void browser_window_destroy(struct browser_window* bw -#ifdef WITH_FRAMES -, bool self -#endif -); -void browser_window_open_location(struct browser_window* bw, const char* url); -void browser_window_open_location_historical(struct browser_window* bw, - const char* url -#ifdef WITH_POST - , char *post_urlenc, - struct form_successful_control *post_multipart -#endif - ); -int browser_window_action(struct browser_window* bw, struct browser_action* act); -void browser_window_set_status(struct browser_window* bw, const char* text); +void browser_window_create(const char *url); +void browser_window_go(struct browser_window *bw, const char *url); +void browser_window_go_post(struct browser_window *bw, const char *url, + char *post_urlenc, + struct form_successful_control *post_multipart, + bool history_add); +void browser_window_stop(struct browser_window *bw); +void browser_window_destroy(struct browser_window *bw); void browser_window_back(struct browser_window* bw); void browser_window_forward(struct browser_window* bw); +int browser_window_action(struct browser_window* bw, struct browser_action* act); + void box_under_area(struct box* box, unsigned long x, unsigned long y, unsigned long ox, unsigned long oy, struct box_selection** found, int* count, int* plot_index); @@ -128,12 +112,12 @@ int box_position_distance(struct box_position* x, struct box_position* y); void gui_redraw_gadget(struct browser_window* bw, struct form_control* g); -void browser_window_stop_throbber(struct browser_window* bw); -void browser_window_reformat(struct browser_window* bw, int scroll_to_top); - bool browser_window_key_press(struct browser_window *bw, char key); -struct history_entry * history_add(struct history_entry *current, - char *url, char *title); +/* In platform specific history.c. */ +struct history *history_create(void); +void history_add(struct history *history, struct content *content); +void history_update(struct history *history, struct content *content); +void history_destroy(struct history *history); #endif diff --git a/desktop/gui.h b/desktop/gui.h index 61b3088b5..3554a87ee 100644 --- a/desktop/gui.h +++ b/desktop/gui.h @@ -3,15 +3,16 @@ * Licensed under the GNU General Public License, * http://www.opensource.org/licenses/gpl-license * Copyright 2003 Phil Mellor - * Copyright 2003 James Bursa + * Copyright 2004 James Bursa + */ + +/** \file + * Interface to platform-specific gui functions. */ #ifndef _NETSURF_DESKTOP_GUI_H_ #define _NETSURF_DESKTOP_GUI_H_ -typedef enum { GUI_BROWSER_WINDOW, GUI_DOWNLOAD_WINDOW } gui_window_type; -typedef enum { SAFE, UNSAFE } gui_safety; - struct gui_window; typedef struct gui_window gui_window; @@ -43,8 +44,6 @@ void gui_multitask(void); void gui_poll(bool active); void gui_quit(void); -gui_safety gui_window_set_redraw_safety(gui_window* g, gui_safety s); - void gui_window_start_throbber(gui_window* g); void gui_window_stop_throbber(gui_window* g); @@ -52,4 +51,6 @@ void gui_gadget_combo(struct browser_window* bw, struct form_control* g, unsigne void gui_window_place_caret(gui_window *g, int x, int y, int height); +void warn_user(const char *warning); + #endif diff --git a/makefile b/makefile index ae0f239d6..05f151d4f 100644 --- a/makefile +++ b/makefile @@ -18,7 +18,7 @@ OBJECTS = $(OBJECTS_COMMON) \ textselection.o theme.o window.o \ draw.o gif.o jpeg.o plugin.o png.o sprite.o \ about.o filetype.o font.o uri.o url.o history.o \ - version.o save_draw.o save_complete.o + version.o save_draw.o save_complete.o thumbnail.o OBJECTS_DEBUG = $(OBJECTS_COMMON) \ netsurfd.o \ options.o filetyped.o fontd.o diff --git a/render/html.h b/render/html.h index 52f175cb0..6eaa651df 100644 --- a/render/html.h +++ b/render/html.h @@ -102,6 +102,7 @@ void html_remove_instance(struct content *c, struct browser_window *bw, /* in riscos/htmlredraw.c */ void html_redraw(struct content *c, long x, long y, unsigned long width, unsigned long height, - long clip_x0, long clip_y0, long clip_x1, long clip_y1); + long clip_x0, long clip_y0, long clip_x1, long clip_y1, + float scale); #endif diff --git a/riscos/401login.c b/riscos/401login.c index ab59f0f45..b46d115d0 100644 --- a/riscos/401login.c +++ b/riscos/401login.c @@ -117,7 +117,7 @@ bool ro_gui_401login_keypress(wimp_key *key) { case wimp_KEY_RETURN: get_unamepwd(); ro_gui_dialog_close(dialog_401li); - browser_window_open_location(bwin, url); + browser_window_go(bwin, url); return true; case wimp_KEY_ESCAPE: ro_gui_dialog_close(dialog_401li); @@ -139,7 +139,7 @@ void ro_gui_401login_click(wimp_pointer *pointer) { case ICON_401LOGIN_LOGIN: get_unamepwd(); ro_gui_dialog_close(dialog_401li); - browser_window_open_location(bwin, url); + browser_window_go(bwin, url); break; case ICON_401LOGIN_CANCEL: ro_gui_dialog_close(dialog_401li); diff --git a/riscos/dialog.c b/riscos/dialog.c index a5ab66311..c9797168f 100644 --- a/riscos/dialog.c +++ b/riscos/dialog.c @@ -25,10 +25,11 @@ #include "netsurf/utils/utils.h" wimp_w dialog_info, dialog_saveas, dialog_config, dialog_config_br, - dialog_config_prox, dialog_config_th, download_template + dialog_config_prox, dialog_config_th, download_template, #ifdef WITH_AUTH - ,dialog_401li + dialog_401li, #endif + dialog_zoom; ; wimp_menu* theme_menu = NULL; @@ -41,6 +42,7 @@ static void ro_gui_dialog_click_config_br(wimp_pointer *pointer); static void ro_gui_dialog_update_config_br(void); static void ro_gui_dialog_click_config_prox(wimp_pointer *pointer); static void ro_gui_dialog_click_config_th(wimp_pointer *pointer); +static void ro_gui_dialog_click_zoom(wimp_pointer *pointer); static void set_browser_choices(void); static void get_browser_choices(void); static void set_proxy_choices(void); @@ -73,6 +75,7 @@ void ro_gui_dialog_init(void) dialog_config_br = ro_gui_dialog_create("config_br"); dialog_config_prox = ro_gui_dialog_create("config_prox"); dialog_config_th = ro_gui_dialog_create("config_th"); + dialog_zoom = ro_gui_dialog_create("zoom"); set_browser_choices(); set_proxy_choices(); @@ -176,6 +179,8 @@ void ro_gui_dialog_click(wimp_pointer *pointer) else if (pointer->w == dialog_401li) ro_gui_401login_click(pointer); #endif + else if (pointer->w == dialog_zoom) + ro_gui_dialog_click_zoom(pointer); } @@ -243,14 +248,7 @@ void ro_gui_dialog_click_config_br(wimp_pointer *pointer) set_browser_choices(); break; case ICON_CONFIG_BR_EXPLAIN: - bw = create_browser_window(browser_TITLE | browser_TOOLBAR | - browser_SCROLL_X_ALWAYS | browser_SCROLL_Y_ALWAYS, 320, 256 -#ifdef WITH_FRAMES - , NULL -#endif - ); - gui_window_show(bw->window); - browser_window_open_location(bw, GESTURES_URL); + browser_window_create(GESTURES_URL); break; case ICON_CONFIG_BR_FONTSIZE_DEC: if (font_size == 50) @@ -295,8 +293,6 @@ void ro_gui_dialog_update_config_br(void) set_icon_string(dialog_config_br, ICON_CONFIG_BR_FONTSIZE, s); sprintf(s, "%i.%ipt", font_min_size / 10, font_min_size % 10); set_icon_string(dialog_config_br, ICON_CONFIG_BR_MINSIZE, s); - wimp_set_icon_state(dialog_config_br, ICON_CONFIG_BR_FONTSIZE, 0, 0); - wimp_set_icon_state(dialog_config_br, ICON_CONFIG_BR_MINSIZE, 0, 0); } @@ -348,19 +344,49 @@ void ro_gui_dialog_click_config_th(wimp_pointer *pointer) os_cli("Filer_OpenDir " THEMES_DIR); break; case ICON_CONFIG_TH_GET: - bw = create_browser_window(browser_TITLE | browser_TOOLBAR | - browser_SCROLL_X_ALWAYS | browser_SCROLL_Y_ALWAYS, 480, 320 -#ifdef WITH_FRAMES - , NULL -#endif - ); - gui_window_show(bw->window); - browser_window_open_location(bw, THEMES_URL); + browser_window_create(THEMES_URL); break; } } +/** + * Handle clicks in the Scale view dialog. + */ + +void ro_gui_dialog_click_zoom(wimp_pointer *pointer) +{ + unsigned int scale; + scale = atoi(get_icon_string(dialog_zoom, ICON_ZOOM_VALUE)); + + switch (pointer->i) { + case ICON_ZOOM_DEC: scale -= 10; break; + case ICON_ZOOM_INC: scale += 10; break; + case ICON_ZOOM_50: scale = 50; break; + case ICON_ZOOM_80: scale = 80; break; + case ICON_ZOOM_100: scale = 100; break; + case ICON_ZOOM_120: scale = 120; break; + } + + if (scale < 10) + scale = 10; + else if (500 < scale) + scale = 500; + set_icon_string_i(dialog_zoom, ICON_ZOOM_VALUE, scale); + + if (pointer->i == ICON_ZOOM_OK) { + current_gui->scale = scale * 0.01; + current_gui->data.browser.reformat_pending = true; + gui_reformat_pending = true; + } + + if (pointer->buttons == wimp_CLICK_SELECT && + (pointer->i == ICON_ZOOM_CANCEL || + pointer->i == ICON_ZOOM_OK)) + wimp_create_menu(wimp_CLOSE_MENU, 0, 0); +} + + /** * Close a dialog box. */ @@ -637,9 +663,7 @@ void ro_gui_theme_menu_selection(char *theme) { set_icon_string(dialog_config_th, ICON_CONFIG_TH_NAME, theme); load_theme_preview(theme); - wimp_set_icon_state(dialog_config_th, ICON_CONFIG_TH_NAME, 0, 0); wimp_set_icon_state(dialog_config_th, ICON_CONFIG_TH_PREVIEW, 0, 0); - } int file_exists(const char* base, const char* dir, const char* leaf, bits ftype) @@ -695,6 +719,7 @@ void set_icon_string(wimp_w w, wimp_i i, const char *text) wimp_get_icon_state(&ic); strncpy(ic.icon.data.indirected_text.text, text, (unsigned int)ic.icon.data.indirected_text.size); + wimp_set_icon_state(w, i, 0, 0); } char* get_icon_string(wimp_w w, wimp_i i) diff --git a/riscos/draw.c b/riscos/draw.c index 3eaf63087..fbaf1be85 100644 --- a/riscos/draw.c +++ b/riscos/draw.c @@ -92,7 +92,8 @@ void draw_destroy(struct content *c) void draw_redraw(struct content *c, long x, long y, unsigned long width, unsigned long height, - long clip_x0, long clip_y0, long clip_x1, long clip_y1) + long clip_x0, long clip_y0, long clip_x1, long clip_y1, + float scale) { os_trfm *matrix = xcalloc(1, sizeof(os_trfm)); diff --git a/riscos/draw.h b/riscos/draw.h index 6fdf0a3c1..fbf9cfc4b 100644 --- a/riscos/draw.h +++ b/riscos/draw.h @@ -25,5 +25,6 @@ void draw_reformat(struct content *c, unsigned int width, unsigned int height); void draw_destroy(struct content *c); void draw_redraw(struct content *c, long x, long y, unsigned long width, unsigned long height, - long clip_x0, long clip_y0, long clip_x1, long clip_y1); + long clip_x0, long clip_y0, long clip_x1, long clip_y1, + float scale); #endif diff --git a/riscos/frames.c b/riscos/frames.c index 1c49382ef..dc23102e5 100644 --- a/riscos/frames.c +++ b/riscos/frames.c @@ -76,7 +76,6 @@ void frame_add_instance(struct content *c, struct browser_window *parent, g->type = GUI_BROWSER_WINDOW; g->data.browser.bw = bw; g->data.browser.toolbar = 0; - g->redraw_safety = SAFE; g->data.browser.reformat_pending = false; g->data.browser.old_width = 0; diff --git a/riscos/gif.c b/riscos/gif.c index c827f19c7..faf54e655 100644 --- a/riscos/gif.c +++ b/riscos/gif.c @@ -133,7 +133,8 @@ void nsgif_reformat(struct content *c, unsigned int width, unsigned int height) void nsgif_redraw(struct content *c, long x, long y, unsigned long width, unsigned long height, - long clip_x0, long clip_y0, long clip_x1, long clip_y1) + long clip_x0, long clip_y0, long clip_x1, long clip_y1, + float scale) { unsigned int size; osspriteop_trans_tab *table; diff --git a/riscos/gif.h b/riscos/gif.h index f0b2bad43..e520481f7 100644 --- a/riscos/gif.h +++ b/riscos/gif.h @@ -29,5 +29,6 @@ void nsgif_reformat(struct content *c, unsigned int width, unsigned int height); void nsgif_destroy(struct content *c); void nsgif_redraw(struct content *c, long x, long y, unsigned long width, unsigned long height, - long clip_x0, long clip_y0, long clip_x1, long clip_y1); + long clip_x0, long clip_y0, long clip_x1, long clip_y1, + float scale); #endif diff --git a/riscos/gui.c b/riscos/gui.c index 864e35464..99a3bb45e 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -245,7 +245,8 @@ void gui_poll(bool active) for (g = window_list; g; g = g->next) { if (g->type == GUI_BROWSER_WINDOW && g->data.browser.reformat_pending) { content_reformat(g->data.browser.bw->current_content, - browser_x_units(g->data.browser.old_width), 1000); + g->data.browser.old_width / 2 / g->scale, + 1000); g->data.browser.reformat_pending = false; } } @@ -475,14 +476,9 @@ void ro_gui_mouse_click(wimp_pointer *pointer) ro_gui_icon_bar_click(pointer); else if (pointer->w == history_window) ro_gui_history_click(pointer); + else if (g && g->type == GUI_BROWSER_WINDOW && g->window == pointer->w) + ro_gui_window_click(g, pointer); else if (g && g->type == GUI_BROWSER_WINDOW && - g->window == pointer->w) { - if (g->redraw_safety == SAFE) - ro_gui_window_click(g, pointer); - else - ro_gui_poll_queue(wimp_MOUSE_CLICK, - (wimp_block *) pointer); - } else if (g && g->type == GUI_BROWSER_WINDOW && g->data.browser.toolbar == pointer->w) ro_gui_toolbar_click(g, pointer); else if (g && g->type == GUI_DOWNLOAD_WINDOW) @@ -502,21 +498,7 @@ void ro_gui_icon_bar_click(wimp_pointer *pointer) ro_gui_create_menu(iconbar_menu, pointer->pos.x - 64, 96 + iconbar_menu_height, NULL); } else if (pointer->buttons == wimp_CLICK_SELECT) { - struct browser_window *bw; - bw = create_browser_window(browser_TITLE | browser_TOOLBAR - | browser_SCROLL_X_ALWAYS | - browser_SCROLL_Y_ALWAYS, 640, - 480 -#ifdef WITH_FRAMES - , NULL -#endif - ); - gui_window_show(bw->window); - browser_window_open_location(bw, HOME_URL); - wimp_set_caret_position(bw->window->data.browser.toolbar, - ICON_TOOLBAR_URL, - 0, 0, -1, - (int) strlen(bw->window->url)); + browser_window_create(HOME_URL); } } @@ -690,8 +672,8 @@ void ro_msg_datasave(wimp_message* block) state.w = data->w; wimp_get_window_state(&state); - x = browser_x_units(window_x_units(data->pos.x, &state)); - y = browser_y_units(window_y_units(data->pos.y, &state)); + x = window_x_units(data->pos.x, &state) / 2; + y = -window_y_units(data->pos.y, &state) / 2; found = 0; click_boxes = NULL; @@ -745,8 +727,8 @@ void ro_msg_dataload(wimp_message* block) state.w = data->w; wimp_get_window_state(&state); - x = browser_x_units(window_x_units(data->pos.x, &state)); - y = browser_y_units(window_y_units(data->pos.y, &state)); + x = window_x_units(data->pos.x, &state) / 2; + y = -window_y_units(data->pos.y, &state) / 2; found = 0; click_boxes = NULL; @@ -832,7 +814,6 @@ int ro_save_data(void *data, unsigned long length, char *file_name, bits file_ty void ro_msg_dataopen(wimp_message *message) { char *url; - struct browser_window *bw; if (message->data.data_xfer.file_type != 0xfaf) /* ignore all but HTML */ @@ -844,15 +825,8 @@ void ro_msg_dataopen(wimp_message *message) wimp_send_message(wimp_USER_MESSAGE, message, message->sender); /* create a new window with the file */ - bw = create_browser_window(browser_TITLE | browser_TOOLBAR | - browser_SCROLL_X_ALWAYS | browser_SCROLL_Y_ALWAYS, 640, 480 -#ifdef WITH_FRAMES - , NULL -#endif - ); - gui_window_show(bw->window); url = ro_path_to_url(message->data.data_xfer.file_name); - browser_window_open_location(bw, url); + browser_window_create(url); free(url); } @@ -888,21 +862,9 @@ void ro_gui_screen_size(int *width, int *height) } -void ro_gui_open_help_page (void) +void ro_gui_open_help_page(void) { - struct browser_window *bw; - bw = create_browser_window(browser_TITLE | browser_TOOLBAR | - browser_SCROLL_X_ALWAYS | - browser_SCROLL_Y_ALWAYS, 640, 480 -#ifdef WITH_FRAMES - , NULL -#endif - ); - gui_window_show(bw->window); - browser_window_open_location(bw, HELP_URL); - wimp_set_caret_position(bw->window->data.browser.toolbar, - ICON_TOOLBAR_URL, - 0,0,-1, (int) strlen(bw->window->url)); + browser_window_create(HELP_URL); } @@ -985,32 +947,24 @@ void ro_gui_drag_box_start(wimp_pointer *pointer) } -int ro_x_units(unsigned long browser_units) -{ - return (browser_units << 1); -} - -int ro_y_units(unsigned long browser_units) -{ - return -(browser_units << 1); -} -unsigned long browser_x_units(int ro_units) -{ - return (ro_units >> 1); -} +static os_error warn_error = { 1, "" }; -unsigned long browser_y_units(int ro_units) -{ - return -(ro_units >> 1); -} -int window_x_units(int scr_units, wimp_window_state* win) -{ - return scr_units - (win->visible.x0 - win->xscroll); -} +/** + * Display a warning for a serious problem (eg memory exhaustion). + * + * \param warning message key for warning message + */ -int window_y_units(int scr_units, wimp_window_state* win) +void warn_user(const char *warning) { - return scr_units - (win->visible.y1 - win->yscroll); + strncpy(warn_error.errmess, messages_get(warning), 252); + /** \todo get rid of cancel button, appears for unknown reason */ + xwimp_report_error_by_category(&warn_error, + wimp_ERROR_BOX_OK_ICON | + wimp_ERROR_BOX_GIVEN_CATEGORY | + wimp_ERROR_BOX_CATEGORY_PROGRAM, + "NetSurf", "!netsurf", + (osspriteop_area *) 1, 0, 0); } diff --git a/riscos/gui.h b/riscos/gui.h index c90e08e09..afcee9829 100644 --- a/riscos/gui.h +++ b/riscos/gui.h @@ -20,15 +20,17 @@ #define THEMES_DIR ".Themes" extern wimp_w dialog_info, dialog_saveas, dialog_config, dialog_config_br, - dialog_config_prox, dialog_config_th; + dialog_config_prox, dialog_config_th, dialog_zoom; extern wimp_w history_window; -extern wimp_menu *current_menu, *iconbar_menu, *browser_menu, - *combo_menu, *theme_menu; -extern int current_menu_x, current_menu_y, iconbar_menu_height; +extern wimp_menu *iconbar_menu, *browser_menu, *combo_menu, *theme_menu; +extern int iconbar_menu_height; extern struct form_control *current_gadget; extern gui_window *window_list; extern bool gui_reformat_pending; extern bool gui_redraw_debug; +extern gui_window *current_gui; + +typedef enum { GUI_BROWSER_WINDOW, GUI_DOWNLOAD_WINDOW } gui_window_type; struct gui_window { @@ -67,8 +69,9 @@ struct gui_window char throb_buf[12]; float throbtime; - gui_safety redraw_safety; enum { drag_NONE, drag_UNKNOWN, drag_BROWSER_TEXT_SELECTION } drag_status; + + float scale; }; struct ro_gui_drag_info @@ -89,12 +92,6 @@ struct ro_gui_drag_info }; /* in gui.c */ -int ro_x_units(unsigned long browser_units); -int ro_y_units(unsigned long browser_units); -unsigned long browser_x_units(int ro_units); -unsigned long browser_y_units(int ro_units); -int window_x_units(int scr_units, wimp_window_state* win); -int window_y_units(int scr_units, wimp_window_state* win); void ro_gui_copy_selection(gui_window* g); void ro_gui_open_help_page(void); void ro_gui_screen_size(int *width, int *height); @@ -152,12 +149,14 @@ gui_window* ro_lookup_gui_toolbar_from_w(wimp_w window); gui_window *ro_gui_window_lookup(wimp_w w); bool ro_gui_window_keypress(gui_window *g, int key, bool toolbar); void ro_gui_scroll_request(wimp_scroll *scroll); +int window_x_units(int x, wimp_window_state *state); +int window_y_units(int y, wimp_window_state *state); /* in history.c */ void ro_gui_history_init(void); void ro_gui_history_quit(void); void ro_gui_history_open(struct browser_window *bw, - struct history_entry *entry, int wx, int wy); + struct history *history, int wx, int wy); void ro_gui_history_redraw(wimp_draw *redraw); void ro_gui_history_click(wimp_pointer *pointer); @@ -223,4 +222,14 @@ void ro_gui_history_click(wimp_pointer *pointer); #define ICON_401LOGIN_USERNAME 4 #define ICON_401LOGIN_PASSWORD 5 +#define ICON_ZOOM_VALUE 1 +#define ICON_ZOOM_DEC 2 +#define ICON_ZOOM_INC 3 +#define ICON_ZOOM_50 5 +#define ICON_ZOOM_80 6 +#define ICON_ZOOM_100 7 +#define ICON_ZOOM_120 8 +#define ICON_ZOOM_CANCEL 9 +#define ICON_ZOOM_OK 10 + #endif diff --git a/riscos/history.c b/riscos/history.c index 49fbf956f..9166f04d3 100644 --- a/riscos/history.c +++ b/riscos/history.c @@ -2,88 +2,231 @@ * This file is part of NetSurf, http://netsurf.sourceforge.net/ * Licensed under the GNU General Public License, * http://www.opensource.org/licenses/gpl-license - * Copyright 2003 James Bursa + * Copyright 2004 James Bursa + */ + +/** \file + * Browser history tree and window (implementation). */ #include #include +#include #include "oslib/colourtrans.h" #include "oslib/font.h" #include "oslib/wimp.h" -#include "netsurf/utils/config.h" #include "netsurf/riscos/gui.h" +#include "netsurf/riscos/thumbnail.h" #include "netsurf/utils/log.h" #include "netsurf/utils/utils.h" #define SIZE 10 -#define WIDTH 300 -#define HEIGHT 100 +#define WIDTH 200 +#define HEIGHT 150 #define MARGIN 32 +#define FULL_WIDTH (WIDTH + MARGIN + MARGIN) +#define FULL_HEIGHT (HEIGHT + MARGIN + MARGIN) +#define SPRITE_SIZE (16 + 44 + ((WIDTH / 2 + 3) & ~3) * HEIGHT / 2) /** A node in the history tree. */ struct history_entry { - char *url; /**< Page URL. */ - char *title; /**< Page title. */ - struct history_entry *back; - struct history_entry *forward, *forward_pref, *forward_last; - struct history_entry *prev, *next; - unsigned int children; + char *url; /**< Page URL. */ + char *title; /**< Page title. */ + struct history_entry *back; /**< Parent. */ + struct history_entry *next; /**< Next sibling. */ + struct history_entry *forward; /**< First child. */ + struct history_entry *forward_pref; /**< Child in direction of + current entry. */ + struct history_entry *forward_last; /**< Last child. */ + unsigned int children; /**< Number of children. */ int x, y, width; + osspriteop_area *sprite_area; /**< Thumbnail sprite area, or 0. */ +}; + +/** History tree for a window. */ +struct history { + /** First page in tree (page that window opened with). */ + struct history_entry *start; + /** Current position in tree. */ + struct history_entry *current; }; static struct browser_window *history_bw; -static struct history_entry *history_start; -static struct history_entry *history_current; +static struct history *history_current; wimp_w history_window; font_f history_font; +static void history_free_entry(struct history_entry *entry); static void ro_gui_history_redraw_tree(struct history_entry *he, int x0, int y0); static struct history_entry * ro_gui_history_click_find(struct history_entry *he, int x, int y); +/** + * Create a new history tree for a window. + * + * \return pointer to an opaque history structure, 0 on failure. + */ + +struct history *history_create(void) +{ + struct history *history; + + history = malloc(sizeof *history); + if (!history) { + warn_user("NoMemory"); + return 0; + } + + history->start = 0; + history->current = 0; + + return history; +} + + /** * Insert a url into the history tree. * - * Takes a copy of the url and title and inserts an entry into the tree forward - * from current, returning the new entry. current may be 0 to start a new tree. + * \param history opaque history structure, as returned by history_create() + * \param content content to add to history + * + * The page is added after the current entry and becomes current. */ -struct history_entry * history_add(struct history_entry *current, - char *url, char *title) +void history_add(struct history *history, struct content *content) { - struct history_entry *entry = xcalloc(1, sizeof(*entry)); + struct history_entry *entry; + char *url; + char *title; char *split; int width; + osspriteop_area *area; + os_error *error; + + if (!history) + return; + + /* allocate space */ + entry = malloc(sizeof *entry); + url = strdup(content->url); + title = strdup(content->title ? content->title : url); + if (!entry || !url || !title) { + warn_user("NoMemory"); + free(entry); + free(url); + free(title); + return; + } + /* truncate title to available width */ font_scan_string(history_font, title, font_GIVEN_FONT | font_KERN, - (WIDTH - MARGIN - MARGIN) * 400, 0x7fffffff, + WIDTH * 400, 0x7fffffff, 0, 0, 0, &split, &width, 0, 0); - - entry->url = xstrdup(url); - entry->title = xstrdup(title); - if (entry->title[split - title]) { - entry->title[split - title - 2] = 0x8c; /* ellipsis */ - entry->title[split - title - 1] = 0; + if (title[split - title]) { + title[split - title - 2] = 0x8c; /* ellipsis */ + title[split - title - 1] = 0; } - entry->back = current; - entry->forward = entry->forward_pref = entry->forward_last = 0; + + entry->url = url; + entry->title = title; + entry->back = history->current; entry->next = 0; + entry->forward = entry->forward_pref = entry->forward_last = 0; entry->children = 0; entry->width = width / 400; - if (current) { - entry->prev = current->forward_last; - if (current->forward_last) - current->forward_last->next = entry; + entry->sprite_area = 0; + if (history->current) { + if (history->current->forward_last) + history->current->forward_last->next = entry; else - current->forward = entry; - current->forward_pref = current->forward_last = entry; - current->children++; + history->current->forward = entry; + history->current->forward_pref = entry; + history->current->forward_last = entry; + history->current->children++; } else { - entry->prev = 0; + history->start = entry; + } + history->current = entry; + + area = malloc(SPRITE_SIZE); + if (!area) { + LOG(("malloc failed")); + return; } - return entry; + + area->size = SPRITE_SIZE; + area->sprite_count = 0; + area->first = 16; + area->used = 16; + + error = xosspriteop_create_sprite(osspriteop_NAME, + area, "thumbnail", false, + WIDTH / 2, HEIGHT / 2, os_MODE8BPP90X90); + if (error) { + LOG(("0x%x: %s", error->errnum, error->errmess)); + return; + } + + thumbnail_create(content, area, + (osspriteop_header *) ((char *) area + 16), + WIDTH / 2, HEIGHT / 2); +/* xosspriteop_save_sprite_file(osspriteop_NAME, + area, "thumbnail");*/ + + entry->sprite_area = area; +} + + +/** + * Update the thumbnail for the current entry. + * + * \param history opaque history structure, as returned by history_create() + * \param content content for current entry + */ + +void history_update(struct history *history, struct content *content) +{ + if (!history || !history->current->sprite_area) + return; + + thumbnail_create(content, history->current->sprite_area, + (osspriteop_header *) + ((char *) history->current->sprite_area + 16), + WIDTH / 2, HEIGHT / 2); +} + + +/** + * Free a history structure. + * + * \param history opaque history structure, as returned by history_create() + */ + +void history_destroy(struct history *history) +{ + if (!history) + return; + history_free_entry(history->start); + free(history); +} + + +/** + * Free an entry in the tree recursively. + */ + +void history_free_entry(struct history_entry *entry) +{ + if (!entry) + return; + history_free_entry(entry->forward); + history_free_entry(entry->next); + free(entry->url); + free(entry->title); + free(entry->sprite_area); + free(entry); } @@ -109,11 +252,11 @@ void ro_gui_history_quit(void) /** - * Open history window at a specified entry. + * Open history window. */ void ro_gui_history_open(struct browser_window *bw, - struct history_entry *entry, int wx, int wy) + struct history *history, int wx, int wy) { bool done = false; unsigned int i, j, max_y = 0; @@ -123,18 +266,14 @@ void ro_gui_history_open(struct browser_window *bw, os_box box = {0, 0, 0, 0}; history_bw = bw; - history_current = entry; - for (history_start = entry; - history_start->back; - history_start = history_start->back) - ; + history_current = history; /* calculate layout */ for (i = 0; i != SIZE; i++) row[i] = row2[i] = 0; - row[0] = history_start; - history_start->x = 0; - history_start->y = 0; + row[0] = history->start; + history->start->x = 0; + history->start->y = 0; for (x = 1; !done; x++) { for (i = 0; i != SIZE; i++) { if (row[i]) { @@ -171,8 +310,8 @@ void ro_gui_history_open(struct browser_window *bw, } } - box.x1 = WIDTH * (x - 1); - box.y0 = -(HEIGHT * (max_y + 1)); + box.x1 = FULL_WIDTH * (x - 1); + box.y0 = -(FULL_HEIGHT * (max_y + 1)); wimp_set_extent(history_window, &box); wimp_create_menu((wimp_menu *) history_window, wx, wy); } @@ -190,7 +329,7 @@ void ro_gui_history_redraw(wimp_draw *redraw) colourtrans_set_gcol(os_COLOUR_WHITE, 0, os_ACTION_OVERWRITE, 0); while (more) { - ro_gui_history_redraw_tree(history_start, + ro_gui_history_redraw_tree(history_current->start, redraw->box.x0 - redraw->xscroll, redraw->box.y1 - redraw->yscroll); more = wimp_get_rectangle(redraw); @@ -207,30 +346,62 @@ void ro_gui_history_redraw_tree(struct history_entry *he, { struct history_entry *c; - os_plot(os_MOVE_TO, x0 + he->x * WIDTH + MARGIN, - y0 - he->y * HEIGHT - MARGIN); - os_plot(os_PLOT_RECTANGLE | os_PLOT_BY, WIDTH - MARGIN - MARGIN, - -(HEIGHT - MARGIN - MARGIN)); + os_plot(os_MOVE_TO, x0 + he->x * FULL_WIDTH + MARGIN, + y0 - he->y * FULL_HEIGHT - MARGIN); + os_plot(os_PLOT_RECTANGLE | os_PLOT_BY, WIDTH, -HEIGHT); + + if (he->sprite_area) { + unsigned int size; + osspriteop_area *area = he->sprite_area; + osspriteop_trans_tab *table; + os_factors factors; + + xcolourtrans_generate_table_for_sprite( + area, + (char *) area + 16, + colourtrans_CURRENT_MODE, colourtrans_CURRENT_PALETTE, + 0, colourtrans_GIVEN_SPRITE, 0, 0, &size); + table = xcalloc(size, 1); + xcolourtrans_generate_table_for_sprite( + area, + (char *) area + 16, + colourtrans_CURRENT_MODE, colourtrans_CURRENT_PALETTE, + table, colourtrans_GIVEN_SPRITE, 0, 0, 0); + + factors.xmul = 1; + factors.ymul = 1; + factors.xdiv = 1; + factors.ydiv = 1; + + xosspriteop_put_sprite_scaled(osspriteop_PTR, + area, + (char *) area + 16, + x0 + he->x * FULL_WIDTH + MARGIN, + y0 - he->y * FULL_HEIGHT - FULL_HEIGHT + MARGIN, + osspriteop_USE_MASK | osspriteop_USE_PALETTE, &factors, table); + + xfree(table); + } - if (he == history_current) + if (he == history_current->current) wimp_set_font_colours(wimp_COLOUR_WHITE, wimp_COLOUR_RED); else wimp_set_font_colours(wimp_COLOUR_WHITE, wimp_COLOUR_BLACK); font_paint(history_font, he->title, font_OS_UNITS | font_GIVEN_FONT | font_KERN, - x0 + he->x * WIDTH + (WIDTH - he->width) / 2, - y0 - he->y * HEIGHT - MARGIN - 24, + x0 + he->x * FULL_WIDTH + (FULL_WIDTH - he->width) / 2, + y0 - he->y * FULL_HEIGHT - MARGIN - 24, 0, 0, 0); for (c = he->forward; c; c = c->next) { if (c->x == -1) continue; - os_plot(os_MOVE_TO, x0 + c->x * WIDTH - MARGIN, - y0 - he->y * HEIGHT - HEIGHT / 2); + os_plot(os_MOVE_TO, x0 + c->x * FULL_WIDTH - MARGIN, + y0 - he->y * FULL_HEIGHT - FULL_HEIGHT / 2); os_plot(os_PLOT_SOLID | os_PLOT_TO, - x0 + c->x * WIDTH + MARGIN, - y0 - c->y * HEIGHT - HEIGHT / 2); + x0 + c->x * FULL_WIDTH + MARGIN, + y0 - c->y * FULL_HEIGHT - FULL_HEIGHT / 2); ro_gui_history_redraw_tree(c, x0, y0); } } @@ -249,19 +420,14 @@ void ro_gui_history_click(wimp_pointer *pointer) state.w = history_window; wimp_get_window_state(&state); - x = (pointer->pos.x - (state.visible.x0 - state.xscroll)) / WIDTH; - y = -(pointer->pos.y - (state.visible.y1 - state.yscroll)) / HEIGHT; + x = (pointer->pos.x - (state.visible.x0 - state.xscroll)) / FULL_WIDTH; + y = -(pointer->pos.y - (state.visible.y1 - state.yscroll)) / FULL_HEIGHT; LOG(("x = %i, y = %i", x, y)); - he = ro_gui_history_click_find(history_start, x, y); + he = ro_gui_history_click_find(history_current->start, x, y); if (he) { - history_bw->history_entry = he; + history_current->current = he; wimp_create_menu(wimp_CLOSE_MENU, 0, 0); - browser_window_open_location_historical(history_bw, - he->url -#ifdef WITH_POST - , 0, 0 -#endif - ); + browser_window_go_post(history_bw, he->url, 0, 0, false); } } diff --git a/riscos/htmlredraw.c b/riscos/htmlredraw.c index 825c5c793..d4e2f0e16 100644 --- a/riscos/htmlredraw.c +++ b/riscos/htmlredraw.c @@ -3,7 +3,7 @@ * Licensed under the GNU General Public License, * http://www.opensource.org/licenses/gpl-license * Copyright 2003 Phil Mellor - * Copyright 2003 James Bursa + * Copyright 2004 James Bursa */ #include @@ -25,7 +25,8 @@ static void html_redraw_box(struct content *content, struct box * box, unsigned long current_background_color, signed long gadget_subtract_x, signed long gadget_subtract_y, bool *select_on, - long clip_x0, long clip_y0, long clip_x1, long clip_y1); + long clip_x0, long clip_y0, long clip_x1, long clip_y1, + float scale); static void html_redraw_clip(long clip_x0, long clip_y0, long clip_x1, long clip_y1); void html_redraw_rectangle(int x0, int y0, int width, int height, @@ -33,10 +34,16 @@ void html_redraw_rectangle(int x0, int y0, int width, int height, bool gui_redraw_debug = false; +static os_trfm trfm = { { + { 65536, 0 }, + { 0, 65536 }, + { 0, 0 } } }; + void html_redraw(struct content *c, long x, long y, unsigned long width, unsigned long height, - long clip_x0, long clip_y0, long clip_x1, long clip_y1) + long clip_x0, long clip_y0, long clip_x1, long clip_y1, + float scale) { bool select_on = false; unsigned long background_colour = 0xffffff; @@ -55,8 +62,10 @@ void html_redraw(struct content *c, long x, long y, background_colour = c->data.html.background_colour; } + trfm.entries[0][0] = trfm.entries[1][1] = 65536 * scale; + html_redraw_box(c, box, x, y, background_colour, x, y, - &select_on, clip_x0, clip_y0, clip_x1, clip_y1); + &select_on, clip_x0, clip_y0, clip_x1, clip_y1, scale); } @@ -71,15 +80,16 @@ void html_redraw_box(struct content *content, struct box * box, unsigned long current_background_color, signed long gadget_subtract_x, signed long gadget_subtract_y, bool *select_on, - long clip_x0, long clip_y0, long clip_x1, long clip_y1) + long clip_x0, long clip_y0, long clip_x1, long clip_y1, + float scale) { struct box *c; int width, height, x0, y0, x1, y1, colour; - x += box->x * 2; - y -= box->y * 2; - width = (box->padding[LEFT] + box->width + box->padding[RIGHT]) * 2; - height = (box->padding[TOP] + box->height + box->padding[BOTTOM]) * 2; + x += box->x * 2 * scale; + y -= box->y * 2 * scale; + width = (box->padding[LEFT] + box->width + box->padding[RIGHT]) * 2 * scale; + height = (box->padding[TOP] + box->height + box->padding[BOTTOM]) * 2 * scale; x0 = x; y1 = y - 1; @@ -91,14 +101,15 @@ void html_redraw_box(struct content *content, struct box * box, for (c = box->children; c; c = c->next) html_redraw_box(content, c, x, y, current_background_color, gadget_subtract_x, gadget_subtract_y, select_on, - x0, y0, x1, y1); + x0, y0, x1, y1, scale); return; } if (gui_redraw_debug) { html_redraw_rectangle(x, y, width, height, os_COLOUR_MAGENTA); html_redraw_rectangle(x + box->padding[LEFT] * 2, y - box->padding[TOP] * 2, - box->width * 2, box->height * 2, os_COLOUR_CYAN); + box->width * 2 * scale, box->height * 2 * scale, + os_COLOUR_CYAN); html_redraw_rectangle(x - (box->border[LEFT] + box->margin[LEFT]) * 2, y + (box->border[TOP] + box->margin[TOP]) * 2, width + (box->border[LEFT] + box->margin[LEFT] + @@ -143,7 +154,7 @@ void html_redraw_box(struct content *content, struct box * box, if (box->object) { content_redraw(box->object, x, y, (unsigned int)width, - (unsigned int)height, x0, y0, x1, y1); + (unsigned int)height, x0, y0, x1, y1, scale); } else if (box->gadget && (box->gadget->type == GADGET_CHECKBOX || @@ -249,40 +260,49 @@ void html_redraw_box(struct content *content, struct box * box, os_ACTION_OVERWRITE, 0); if (box->style->text_decoration & CSS_TEXT_DECORATION_UNDERLINE) { - os_plot(os_MOVE_TO, x, y - (int) (box->height * 1.8)); - os_plot(os_PLOT_SOLID_EX_END | os_PLOT_BY, box->width * 2, 0); + os_plot(os_MOVE_TO, x, y - (int) (box->height * 1.8 * scale)); + os_plot(os_PLOT_SOLID_EX_END | os_PLOT_BY, box->width * 2 * scale, 0); } if (box->parent->parent->style->text_decoration & CSS_TEXT_DECORATION_UNDERLINE && box->parent->parent->type == BOX_BLOCK) { colourtrans_set_gcol((unsigned int)box->parent->parent->style->color << 8, colourtrans_USE_ECFS, os_ACTION_OVERWRITE, 0); - os_plot(os_MOVE_TO, x, y - (int) (box->height * 1.8)); - os_plot(os_PLOT_SOLID_EX_END | os_PLOT_BY, box->width * 2, 0); + os_plot(os_MOVE_TO, x, y - (int) (box->height * 1.8 * scale)); + os_plot(os_PLOT_SOLID_EX_END | os_PLOT_BY, box->width * 2 * scale, 0); colourtrans_set_gcol((unsigned int)box->style->color << 8, colourtrans_USE_ECFS, os_ACTION_OVERWRITE, 0); } if (box->style->text_decoration & CSS_TEXT_DECORATION_OVERLINE) { - os_plot(os_MOVE_TO, x, y - (int) (box->height * 0.2)); - os_plot(os_PLOT_SOLID_EX_END | os_PLOT_BY, box->width * 2, 0); + os_plot(os_MOVE_TO, x, y - (int) (box->height * 0.2 * scale)); + os_plot(os_PLOT_SOLID_EX_END | os_PLOT_BY, box->width * 2 * scale, 0); } if (box->parent->parent->style->text_decoration & CSS_TEXT_DECORATION_OVERLINE && box->parent->parent->type == BOX_BLOCK) { colourtrans_set_gcol((unsigned int)box->parent->parent->style->color << 8, colourtrans_USE_ECFS, os_ACTION_OVERWRITE, 0); - os_plot(os_MOVE_TO, x, y - (int) (box->height * 0.2)); - os_plot(os_PLOT_SOLID_EX_END | os_PLOT_BY, box->width * 2, 0); + os_plot(os_MOVE_TO, x, y - (int) (box->height * 0.2 * scale)); + os_plot(os_PLOT_SOLID_EX_END | os_PLOT_BY, box->width * 2 * scale, 0); colourtrans_set_gcol((unsigned int)box->style->color << 8, colourtrans_USE_ECFS, os_ACTION_OVERWRITE, 0); } if (box->style->text_decoration & CSS_TEXT_DECORATION_LINE_THROUGH) { - os_plot(os_MOVE_TO, x, y - (int) (box->height * 1.0)); - os_plot(os_PLOT_SOLID_EX_END | os_PLOT_BY, box->width * 2, 0); + os_plot(os_MOVE_TO, x, y - (int) (box->height * 1.0 * scale)); + os_plot(os_PLOT_SOLID_EX_END | os_PLOT_BY, box->width * 2 * scale, 0); } if (box->parent->parent->style->text_decoration & CSS_TEXT_DECORATION_LINE_THROUGH && box->parent->parent->type == BOX_BLOCK) { colourtrans_set_gcol((unsigned int)box->parent->parent->style->color << 8, colourtrans_USE_ECFS, os_ACTION_OVERWRITE, 0); - os_plot(os_MOVE_TO, x, y - (int) (box->height * 1.0)); - os_plot(os_PLOT_SOLID_EX_END | os_PLOT_BY, box->width * 2, 0); + os_plot(os_MOVE_TO, x, y - (int) (box->height * 1.0 * scale)); + os_plot(os_PLOT_SOLID_EX_END | os_PLOT_BY, box->width * 2 * scale, 0); colourtrans_set_gcol((unsigned int)box->style->color << 8, colourtrans_USE_ECFS, os_ACTION_OVERWRITE, 0); } - font_paint(box->font->handle, box->text, - font_OS_UNITS | font_GIVEN_FONT | font_KERN | font_GIVEN_LENGTH, - x, y - (int) (box->height * 1.5), - NULL, NULL, (int) box->length); + if (scale == 1) + font_paint(box->font->handle, box->text, + font_OS_UNITS | font_GIVEN_FONT | + font_KERN | font_GIVEN_LENGTH, + x, y - (int) (box->height * 1.5), + 0, 0, (int) box->length); + else + font_paint(box->font->handle, box->text, + font_OS_UNITS | font_GIVEN_FONT | + font_KERN | font_GIVEN_LENGTH | + font_GIVEN_TRFM, + x, y - (int) (box->height * 1.5 * scale), + 0, &trfm, (int) box->length); } else { @@ -291,13 +311,13 @@ void html_redraw_box(struct content *content, struct box * box, html_redraw_box(content, c, x, y, current_background_color, gadget_subtract_x, gadget_subtract_y, select_on, - x0, y0, x1, y1); + x0, y0, x1, y1, scale); for (c = box->float_children; c != 0; c = c->next_float) html_redraw_box(content, c, x, y, current_background_color, gadget_subtract_x, gadget_subtract_y, select_on, - x0, y0, x1, y1); + x0, y0, x1, y1, scale); } if (box->type == BOX_BLOCK || box->type == BOX_INLINE_BLOCK || diff --git a/riscos/jpeg.c b/riscos/jpeg.c index 0da212682..3d72e7acb 100644 --- a/riscos/jpeg.c +++ b/riscos/jpeg.c @@ -329,7 +329,8 @@ void nsjpeg_destroy(struct content *c) void nsjpeg_redraw(struct content *c, long x, long y, unsigned long width, unsigned long height, - long clip_x0, long clip_y0, long clip_x1, long clip_y1) + long clip_x0, long clip_y0, long clip_x1, long clip_y1, + float scale) { unsigned int size; osspriteop_trans_tab *table; diff --git a/riscos/jpeg.h b/riscos/jpeg.h index 40e449b22..d3439fd93 100644 --- a/riscos/jpeg.h +++ b/riscos/jpeg.h @@ -30,6 +30,7 @@ void nsjpeg_reformat(struct content *c, unsigned int width, unsigned int height) void nsjpeg_destroy(struct content *c); void nsjpeg_redraw(struct content *c, long x, long y, unsigned long width, unsigned long height, - long clip_x0, long clip_y0, long clip_x1, long clip_y1); + long clip_x0, long clip_y0, long clip_x1, long clip_y1, + float scale); #endif diff --git a/riscos/menus.c b/riscos/menus.c index 78ec67db0..444996623 100644 --- a/riscos/menus.c +++ b/riscos/menus.c @@ -3,10 +3,14 @@ * Licensed under the GNU General Public License, * http://www.opensource.org/licenses/gpl-license * Copyright 2003 Phil Mellor - * Copyright 2003 James Bursa + * Copyright 2004 James Bursa * Copyright 2003 John M Bell */ +/** \file + * Menu creation and handling (implementation). + */ + #include #include #include "oslib/wimp.h" @@ -21,8 +25,8 @@ static void translate_menu(wimp_menu *menu); -wimp_menu *current_menu; -int current_menu_x, current_menu_y; +static wimp_menu *current_menu; +static int current_menu_x, current_menu_y; gui_window *current_gui; @@ -44,7 +48,6 @@ wimp_menu *iconbar_menu = (wimp_menu *) & (wimp_MENU(4)) { int iconbar_menu_height = 4 * 44; /* browser window menu structure - based on Style Guide */ -/*wimp_menu *browser_page_menu = (wimp_menu *) & (wimp_MENU(4)) {*/ static wimp_MENU(4) page_menu = { { "Page" }, 7,2,7,0, 200, 44, 0, { @@ -78,12 +81,21 @@ static wimp_MENU(5) navigate_menu = { }; static wimp_menu *browser_navigate_menu = (wimp_menu *) &navigate_menu; -wimp_menu *browser_menu = (wimp_menu *) & (wimp_MENU(3)) { +static wimp_MENU(1) view_menu = { + { "View" }, 7,2,7,0, 300, 44, 0, + { + { wimp_MENU_LAST, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "ScaleView" } } + } +}; +static wimp_menu *browser_view_menu = (wimp_menu *) &view_menu; + +wimp_menu *browser_menu = (wimp_menu *) & (wimp_MENU(4)) { { "NetSurf" }, 7,2,7,0, 200, 44, 0, { { 0, (wimp_menu *) &page_menu, DEFAULT_FLAGS, { "Page" } }, { 0, (wimp_menu *) &selection_menu, DEFAULT_FLAGS, { "Selection" } }, - { wimp_MENU_LAST, (wimp_menu *) &navigate_menu, DEFAULT_FLAGS, { "Navigate" } } + { 0, (wimp_menu *) &navigate_menu, DEFAULT_FLAGS, { "Navigate" } }, + { wimp_MENU_LAST, (wimp_menu *) &view_menu, DEFAULT_FLAGS, { "View" } } } }; @@ -99,9 +111,11 @@ void ro_gui_menus_init(void) translate_menu(browser_page_menu); translate_menu(browser_selection_menu); translate_menu(browser_navigate_menu); + translate_menu(browser_view_menu); iconbar_menu->entries[0].sub_menu = (wimp_menu *) dialog_info; browser_page_menu->entries[1].sub_menu = (wimp_menu *) dialog_saveas; + browser_view_menu->entries[0].sub_menu = (wimp_menu *) dialog_zoom; } @@ -126,7 +140,7 @@ void translate_menu(wimp_menu *menu) menu->entries[i].data.indirected_text.size = strlen(menu->entries[i].data.indirected_text.text) + 1; i++; - } while ((menu->entries[i].menu_flags & wimp_MENU_LAST) == 0); + } while ((menu->entries[i - 1].menu_flags & wimp_MENU_LAST) == 0); } @@ -228,7 +242,8 @@ void ro_gui_menu_selection(wimp_selection *selection) case 0: /* Open URL... */ break; case 1: /* Home */ - browser_window_open_location(current_gui->data.browser.bw, HOME_URL); + browser_window_go(current_gui->data.browser.bw, + HOME_URL); break; case 2: /* Back */ browser_window_back(current_gui->data.browser.bw); diff --git a/riscos/mouseactions.c b/riscos/mouseactions.c index 2fa00d946..6b9d2c483 100644 --- a/riscos/mouseactions.c +++ b/riscos/mouseactions.c @@ -56,12 +56,12 @@ void ro_gui_mouse_action(gui_window *g) { break; case mouseaction_RELOAD: - browser_window_open_location_historical(g->data.browser.bw, +/* browser_window_open_location_historical(g->data.browser.bw, g->data.browser.bw->url #ifdef WITH_POST , 0, 0 #endif - ); + );*/ break; default: break; diff --git a/riscos/plugin.c b/riscos/plugin.c index 0ec741f93..01926fd50 100644 --- a/riscos/plugin.c +++ b/riscos/plugin.c @@ -1287,20 +1287,10 @@ void plugin_url_access(wimp_message *message) { strcasecmp(window, "_parent") == 0 || strcasecmp(window, "_top") == 0 || strcasecmp(window, "") == 0) { - browser_window_open_location(npl->bw, url); + browser_window_go(npl->bw, url); } else if (strcasecmp(window, "_blank") == 0) { - struct browser_window *bwnew; - bwnew = create_browser_window(browser_TITLE - | browser_TOOLBAR | browser_SCROLL_X_ALWAYS - | browser_SCROLL_Y_ALWAYS, 640, 480 -#ifdef WITH_FRAMES - , NULL -#endif - ); - gui_window_show(bwnew->window); - bwnew->url = xstrdup(url); - browser_window_open_location(bwnew, url); + browser_window_create(url); } } else { /* POST request */ diff --git a/riscos/png.c b/riscos/png.c index 20597fa57..f2947133d 100644 --- a/riscos/png.c +++ b/riscos/png.c @@ -376,7 +376,8 @@ void nspng_destroy(struct content *c) void nspng_redraw(struct content *c, long x, long y, unsigned long width, unsigned long height, - long clip_x0, long clip_y0, long clip_x1, long clip_y1) + long clip_x0, long clip_y0, long clip_x1, long clip_y1, + float scale) { int size; osspriteop_trans_tab *table; diff --git a/riscos/png.h b/riscos/png.h index f52514b73..8d91ef7ee 100644 --- a/riscos/png.h +++ b/riscos/png.h @@ -35,5 +35,6 @@ void nspng_reformat(struct content *c, unsigned int width, unsigned int height); void nspng_destroy(struct content *c); void nspng_redraw(struct content *c, long x, long y, unsigned long width, unsigned long height, - long clip_x0, long clip_y0, long clip_x1, long clip_y1); + long clip_x0, long clip_y0, long clip_x1, long clip_y1, + float scale); #endif diff --git a/riscos/sprite.c b/riscos/sprite.c index 44bd39c9a..2c9abb31d 100644 --- a/riscos/sprite.c +++ b/riscos/sprite.c @@ -82,7 +82,8 @@ void sprite_destroy(struct content *c) void sprite_redraw(struct content *c, long x, long y, unsigned long width, unsigned long height, - long clip_x0, long clip_y0, long clip_x1, long clip_y1) + long clip_x0, long clip_y0, long clip_x1, long clip_y1, + float scale) { unsigned int size; osspriteop_area *area = (osspriteop_area*)c->data.sprite.data; diff --git a/riscos/sprite.h b/riscos/sprite.h index 5096081f7..183a5494f 100644 --- a/riscos/sprite.h +++ b/riscos/sprite.h @@ -26,5 +26,6 @@ void sprite_reformat(struct content *c, unsigned int width, unsigned int height) void sprite_destroy(struct content *c); void sprite_redraw(struct content *c, long x, long y, unsigned long width, unsigned long height, - long clip_x0, long clip_y0, long clip_x1, long clip_y1); + long clip_x0, long clip_y0, long clip_x1, long clip_y1, + float scale); #endif diff --git a/riscos/textselection.c b/riscos/textselection.c index fec3bbc69..9dbf397dd 100644 --- a/riscos/textselection.c +++ b/riscos/textselection.c @@ -59,8 +59,8 @@ void ro_gui_drag_end(wimp_dragged* drag) state.w = current_drag.data.selection.gui->window; wimp_get_window_state(&state); - final_x0 = browser_x_units(window_x_units(drag->final.x0, &state)); - final_y0 = browser_y_units(window_y_units(drag->final.y0, &state)); + final_x0 = window_x_units(drag->final.x0, &state) / 2; + final_y0 = window_y_units(drag->final.y0, &state) / 2; msg.data.mouse.x = final_x0; msg.data.mouse.y = final_y0; diff --git a/riscos/thumbnail.c b/riscos/thumbnail.c new file mode 100644 index 000000000..2f5b8d868 --- /dev/null +++ b/riscos/thumbnail.c @@ -0,0 +1,68 @@ +/* + * This file is part of NetSurf, http://netsurf.sourceforge.net/ + * Licensed under the GNU General Public License, + * http://www.opensource.org/licenses/gpl-license + * Copyright 2004 James Bursa + */ + +/** \file + * Page thumbnail creation (implementation). + * + * Thumbnails are created by redirecting output to a sprite and rendering the + * page at a small scale. + */ + +#include "oslib/colourtrans.h" +#include "oslib/osspriteop.h" +#include "netsurf/content/content.h" +#include "netsurf/riscos/thumbnail.h" +#include "netsurf/utils/log.h" + + +/** + * Create a thumbnail of a page. + * + * \param content content structure to thumbnail + * \param area sprite area containing thumbnail sprite + * \param sprite pointer to sprite + * \param width sprite width / pixels + * \param height sprite height / pixels + * + * The thumbnail is rendered in the given sprite. + */ + +void thumbnail_create(struct content *content, osspriteop_area *area, + osspriteop_header *sprite, int width, int height) +{ + float scale; + os_error *error; + + scale = (float) width / (float) content->width; + + /* switch output to sprite */ + error = xosspriteop_switch_output_to_sprite(osspriteop_PTR, area, + (osspriteop_id) sprite, 0, 0, 0, 0, 0); + if (error) { + LOG(("xosspriteop_switch_output_to_sprite failed: %s", + error->errmess)); + return; + } + + /* clear background to white */ + colourtrans_set_gcol(os_COLOUR_WHITE, colourtrans_SET_BG, + os_ACTION_OVERWRITE, 0); + os_clg(); + + /* render content */ + content_redraw(content, 0, height * 2, width * 2, height * 2, + 0, 0, width * 2, height * 2, scale); + + /* switch output back to screen */ + error = xosspriteop_switch_output_to_sprite(osspriteop_PTR, area, + 0, 0, 0, 0, 0, 0); + if (error) { + LOG(("xosspriteop_switch_output_to_sprite failed: %s", + error->errmess)); + return; + } +} diff --git a/riscos/thumbnail.h b/riscos/thumbnail.h new file mode 100644 index 000000000..7482b3c39 --- /dev/null +++ b/riscos/thumbnail.h @@ -0,0 +1,15 @@ +/* + * This file is part of NetSurf, http://netsurf.sourceforge.net/ + * Licensed under the GNU General Public License, + * http://www.opensource.org/licenses/gpl-license + * Copyright 2004 James Bursa + */ + +/** \file + * Page thumbnail creation (interface). + */ + +#include "oslib/osspriteop.h" + +void thumbnail_create(struct content *content, osspriteop_area *area, + osspriteop_header *sprite, int width, int height); diff --git a/riscos/uri.c b/riscos/uri.c index aac943f2a..ae13ba0ea 100644 --- a/riscos/uri.c +++ b/riscos/uri.c @@ -57,20 +57,7 @@ void ro_uri_message_received(uri_full_message_process* uri_message) xuri_request_uri(0, uri_requested, uri_length, uri_handle, NULL); - bw = create_browser_window(browser_TITLE | browser_TOOLBAR - | browser_SCROLL_X_ALWAYS | browser_SCROLL_Y_ALWAYS, 640, 480 -#ifdef WITH_FRAMES - , NULL -#endif - ); - - gui_window_show(bw->window); - browser_window_open_location(bw, uri_requested); - - wimp_set_caret_position(bw->window->data.browser.toolbar, - ICON_TOOLBAR_URL, - 0,0,-1, (int) strlen(bw->window->url) - 1); - + browser_window_create(uri_requested); xfree(uri_requested); } diff --git a/riscos/url.c b/riscos/url.c index 4b01280c8..e1ee94d47 100644 --- a/riscos/url.c +++ b/riscos/url.c @@ -99,29 +99,16 @@ void ro_url_message_received(wimp_message* message) message->sender); /* create new browser window */ - bw = create_browser_window(browser_TITLE | browser_TOOLBAR - | browser_SCROLL_X_ALWAYS | browser_SCROLL_Y_ALWAYS, 640, 480 -#ifdef WITH_FRAMES - , NULL -#endif - ); - - gui_window_show(bw->window); + browser_window_create(uri_requested); -#ifdef ALLOW_POST +#if 0 if (post) { /* TODO - create urlencoded data from file contents. * Delete the file when finished with it. */ browser_window_open_location_historical(bw, uri_requested, /*data*/0, 0); } - else #endif - browser_window_open_location(bw, uri_requested); - - wimp_set_caret_position(bw->window->data.browser.toolbar, - ICON_TOOLBAR_URL, - 0,0,-1, (int) strlen(bw->window->url)); #ifdef ALLOW_POST xfree(filename); diff --git a/riscos/window.c b/riscos/window.c index efbc03c92..4c305d5bf 100644 --- a/riscos/window.c +++ b/riscos/window.c @@ -3,7 +3,7 @@ * Licensed under the GNU General Public License, * http://www.opensource.org/licenses/gpl-license * Copyright 2003 Phil Mellor - * Copyright 2003 James Bursa + * Copyright 2004 James Bursa * Copyright 2003 John M Bell */ @@ -14,15 +14,18 @@ #include #include #include +#include "oslib/osspriteop.h" #include "oslib/wimp.h" #include "oslib/wimpspriteop.h" #include "netsurf/css/css.h" #include "netsurf/utils/config.h" #include "netsurf/riscos/constdata.h" #include "netsurf/riscos/gui.h" +#include "netsurf/riscos/options.h" #include "netsurf/riscos/save_complete.h" #include "netsurf/riscos/save_draw.h" #include "netsurf/riscos/theme.h" +#include "netsurf/riscos/thumbnail.h" #include "netsurf/utils/log.h" #include "netsurf/utils/utils.h" @@ -62,7 +65,7 @@ gui_window *gui_create_browser_window(struct browser_window *bw) ro_gui_screen_size(&screen_width, &screen_height); - if (bw->flags & browser_TOOLBAR) + if (option_show_toolbar) toolbar_height = ro_theme_toolbar_height(); win_width = screen_width * 3 / 4; @@ -109,7 +112,7 @@ gui_window *gui_create_browser_window(struct browser_window *bw) strcpy(g->title, "NetSurf"); g->data.browser.toolbar = 0; - if ((bw->flags & browser_TOOLBAR) != 0) + if (option_show_toolbar) { g->data.browser.toolbar = ro_theme_create_toolbar(g->url, g->status, g->throb_buf); @@ -117,9 +120,9 @@ gui_window *gui_create_browser_window(struct browser_window *bw) sprintf(g->throb_buf, "throbber0"); } - g->redraw_safety = SAFE; g->data.browser.reformat_pending = false; g->data.browser.old_width = 0; + g->scale = 1; g->next = window_list; window_list = g; @@ -199,8 +202,7 @@ void gui_window_redraw(gui_window* g, unsigned long x0, unsigned long y0, if (g == NULL) return; - wimp_force_redraw(g->window, - ro_x_units(x0), ro_y_units(y1), ro_x_units(x1), ro_y_units(y0)); + wimp_force_redraw(g->window, x0 * 2, -y1 * 2, x1 * 2, -y0 * 2); } void gui_window_redraw_window(gui_window* g) @@ -213,26 +215,13 @@ void gui_window_redraw_window(gui_window* g) wimp_force_redraw(g->window, info.extent.x0, info.extent.y0, info.extent.x1, info.extent.y1); } -gui_safety gui_window_set_redraw_safety(gui_window* g, gui_safety s) -{ - gui_safety old; - - if (g == NULL) - return SAFE; - - old = g->redraw_safety; - g->redraw_safety = s; - - return old; -} - void ro_gui_window_redraw(gui_window* g, wimp_draw* redraw) { osbool more; struct content *c = g->data.browser.bw->current_content; - if (g->redraw_safety == SAFE && g->type == GUI_BROWSER_WINDOW && c != NULL) + if (g->type == GUI_BROWSER_WINDOW && c != NULL) { more = wimp_redraw_window(redraw); wimp_set_font_colours(wimp_COLOUR_WHITE, wimp_COLOUR_BLACK); @@ -244,7 +233,8 @@ void ro_gui_window_redraw(gui_window* g, wimp_draw* redraw) (int) redraw->box.y1 - (int) redraw->yscroll, c->width * 2, c->height * 2, redraw->clip.x0, redraw->clip.y0, - redraw->clip.x1 - 1, redraw->clip.y1 - 1); + redraw->clip.x1 - 1, redraw->clip.y1 - 1, + g->scale); more = wimp_get_rectangle(redraw); } } @@ -263,9 +253,9 @@ void gui_window_set_scroll(gui_window* g, unsigned long sx, unsigned long sy) return; state.w = g->window; wimp_get_window_state(&state); - state.xscroll = ro_x_units(sx); - state.yscroll = ro_y_units(sy); - if ((g->data.browser.bw->flags & browser_TOOLBAR) != 0) + state.xscroll = sx * 2; + state.yscroll = -sy * 2; + if (option_show_toolbar) state.yscroll += ro_theme_toolbar_height(); ro_gui_window_open(g, (wimp_open*)&state); } @@ -275,7 +265,7 @@ unsigned long gui_window_get_width(gui_window* g) wimp_window_state state; state.w = g->window; wimp_get_window_state(&state); - return browser_x_units(state.visible.x1 - state.visible.x0); + return (state.visible.x1 - state.visible.x0) / 2; } @@ -286,14 +276,14 @@ void gui_window_set_extent(gui_window *g, unsigned long width, wimp_window_state state; int toolbar_height = 0; - width *= 2; - height *= 2; + width *= 2 * g->scale; + height *= 2 * g->scale; state.w = g->window; wimp_get_window_state(&state); /* account for toolbar height, if present */ - if (g->data.browser.bw->flags & browser_TOOLBAR) + if (option_show_toolbar) toolbar_height = ro_theme_toolbar_height(); if (width < (unsigned int)(state.visible.x1 - state.visible.x0)) @@ -372,7 +362,7 @@ void ro_gui_window_open(gui_window *g, wimp_open *open) } /* account for toolbar height, if present */ - if (g->data.browser.bw->flags & browser_TOOLBAR) { + if (option_show_toolbar) { toolbar_height = ro_theme_toolbar_height(); height -= toolbar_height; } @@ -443,7 +433,7 @@ void ro_gui_throb(void) { if (g->type == GUI_BROWSER_WINDOW) { - if ((g->data.browser.bw->flags & browser_TOOLBAR) != 0) + if (option_show_toolbar) { if (g->data.browser.bw->throbbing != 0) { @@ -517,7 +507,7 @@ gui_window *ro_gui_window_lookup(wimp_w w) void ro_gui_window_mouse_at(wimp_pointer* pointer) { - int x,y; + int x, y; wimp_window_state state; gui_window* g; @@ -526,17 +516,11 @@ void ro_gui_window_mouse_at(wimp_pointer* pointer) if (g == NULL) return; - if (g->redraw_safety != SAFE) - { - fprintf(stderr, "mouse at UNSAFE\n"); - return; - } - state.w = pointer->w; wimp_get_window_state(&state); - x = browser_x_units(window_x_units(pointer->pos.x, &state)); - y = browser_y_units(window_y_units(pointer->pos.y, &state)); + x = window_x_units(pointer->pos.x, &state) / 2 / g->scale; + y = -window_y_units(pointer->pos.y, &state) / 2 / g->scale; if (g->drag_status == drag_BROWSER_TEXT_SELECTION) { @@ -565,17 +549,17 @@ void ro_gui_toolbar_click(gui_window* g, wimp_pointer* pointer) switch (pointer->i) { case ICON_TOOLBAR_HISTORY: ro_gui_history_open(g->data.browser.bw, - g->data.browser.bw->history_entry, + g->data.browser.bw->history, pointer->pos.x - 200, pointer->pos.y + 100); break; case ICON_TOOLBAR_RELOAD: - browser_window_open_location_historical(g->data.browser.bw, +/* browser_window_open_location_historical(g->data.browser.bw, g->data.browser.bw->url #ifdef WITH_POST , 0, 0 #endif - ); + );*/ break; } } @@ -587,19 +571,13 @@ void ro_gui_window_click(gui_window* g, wimp_pointer* pointer) int x,y; wimp_window_state state; - if (g->redraw_safety != SAFE) - { - fprintf(stderr, "gui_window_click UNSAFE\n"); - return; - } - state.w = pointer->w; wimp_get_window_state(&state); if (g->type == GUI_BROWSER_WINDOW) { - x = browser_x_units(window_x_units(pointer->pos.x, &state)); - y = browser_y_units(window_y_units(pointer->pos.y, &state)); + x = window_x_units(pointer->pos.x, &state) / 2 / g->scale; + y = -window_y_units(pointer->pos.y, &state) / 2 / g->scale; if (pointer->buttons == wimp_CLICK_MENU) { @@ -615,7 +593,6 @@ void ro_gui_window_click(gui_window* g, wimp_pointer* pointer) msg.type = act_MOUSE_CLICK; msg.data.mouse.x = x; msg.data.mouse.y = y; - msg.data.mouse.buttons = act_BUTTON_NORMAL; if (browser_window_action(g->data.browser.bw, &msg) == 1) return; msg.type = act_UNKNOWN; @@ -770,7 +747,7 @@ bool ro_gui_window_keypress(gui_window *g, int key, bool toolbar) free(url); if (url2) { gui_window_set_url(g, url2); - browser_window_open_location(g->data.browser.bw, url2); + browser_window_go(g->data.browser.bw, url2); free(url2); } } @@ -791,7 +768,7 @@ bool ro_gui_window_keypress(gui_window *g, int key, bool toolbar) state.w = g->window; wimp_get_window_state(&state); y = state.visible.y1 - state.visible.y0 - 32; - if (g->data.browser.bw->flags & browser_TOOLBAR) + if (option_show_toolbar) y -= ro_theme_toolbar_height(); switch (key) { @@ -833,7 +810,7 @@ void ro_gui_scroll_request(wimp_scroll *scroll) x = scroll->visible.x1 - scroll->visible.x0 - 32; y = scroll->visible.y1 - scroll->visible.y0 - 32; - if (g->data.browser.bw->flags & browser_TOOLBAR) + if (option_show_toolbar) y -= ro_theme_toolbar_height(); switch (scroll->xmin) { @@ -872,3 +849,31 @@ void ro_gui_scroll_request(wimp_scroll *scroll) wimp_open_window((wimp_open *) scroll); } + + +/** + * Convert x from screen to window coordinates. + * + * \param x x coordinate / os units + * \param state window state + * \return x coordinate in window / os units + */ + +int window_x_units(int x, wimp_window_state *state) +{ + return x - (state->visible.x0 - state->xscroll); +} + + +/** + * Convert y from screen to window coordinates. + * + * \param y y coordinate / os units + * \param state window state + * \return y coordinate in window / os units + */ + +int window_y_units(int y, wimp_window_state *state) +{ + return y - (state->visible.y1 - state->yscroll); +} diff --git a/utils/utils.c b/utils/utils.c index 04cfa81fc..4e04af353 100644 --- a/utils/utils.c +++ b/utils/utils.c @@ -23,6 +23,7 @@ #include "netsurf/riscos/about.h" #include "netsurf/riscos/constdata.h" #endif +#define NDEBUG #include "netsurf/utils/log.h" #include "netsurf/utils/messages.h" #include "netsurf/utils/utils.h" -- cgit v1.2.3