From 9805610091b0ffe0795db0430226d846d7493587 Mon Sep 17 00:00:00 2001 From: James Bursa Date: Thu, 11 Dec 2003 01:23:57 +0000 Subject: [project @ 2003-12-11 01:23:57 by bursa] Clean up key handling and implement scrolling using cursor keys. svn path=/import/netsurf/; revision=425 --- desktop/browser.c | 46 ++++++++++++++--------- desktop/browser.h | 2 +- riscos/gui.c | 110 +++++++++++++++++++++--------------------------------- riscos/gui.h | 3 ++ riscos/window.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 171 insertions(+), 87 deletions(-) diff --git a/desktop/browser.c b/desktop/browser.c index b05a3da25..dfd16d32f 100644 --- a/desktop/browser.c +++ b/desktop/browser.c @@ -205,16 +205,16 @@ void browser_window_open_location(struct browser_window* bw, const char* url0) } void browser_window_open_location_post(struct browser_window* bw, - const char* url0, char *post_urlenc, + const char* url, char *post_urlenc, struct form_successful_control *post_multipart) { - char *url; - LOG(("bw = %p, url0 = %s", bw, url0)); - assert(bw != 0 && url0 != 0); - url = url_join(url0, bw->url); - browser_window_open_location_historical(bw, url, post_urlenc, post_multipart); + char *url1; + LOG(("bw = %p, url = %s", bw, url)); + assert(bw != 0 && url != 0); + url1 = url_join(url, 0); + browser_window_open_location_historical(bw, url1, post_urlenc, post_multipart); bw->history_add = true; - xfree(url); + free(url1); LOG(("end")); } @@ -1073,11 +1073,12 @@ void browser_window_place_caret(struct browser_window *bw, int x, int y, * Handle key presses in a browser window. */ -void browser_window_key_press(struct browser_window *bw, char key) +bool browser_window_key_press(struct browser_window *bw, char key) { if (!bw->caret_callback) - return; + return false; bw->caret_callback(bw, key, bw->caret_p); + return true; } @@ -1172,17 +1173,20 @@ void browser_window_follow_link(struct browser_window* bw, continue; if (click_boxes[i].box->href != NULL) { - if (click_type == 1) - browser_window_open_location(bw, (char*) click_boxes[i].box->href); + if (click_type == 1) { + char *url = url_join((char*) click_boxes[i].box->href, bw->url); + browser_window_open_location(bw, url); + free(url); + } else if (click_type == 2) { + char *url = url_join((char*) click_boxes[i].box->href, bw->url); struct browser_window* bw_new; bw_new = create_browser_window(browser_TITLE | browser_TOOLBAR | browser_SCROLL_X_ALWAYS | browser_SCROLL_Y_ALWAYS, 640, 480); gui_window_show(bw_new->window); - if (bw->url != NULL) - bw_new->url = xstrdup(bw->url); - browser_window_open_location(bw_new, (char*) click_boxes[i].box->href); + browser_window_open_location(bw_new, url); + free(url); } else if (click_type == 0) { @@ -1526,7 +1530,7 @@ void browser_window_redraw_boxes(struct browser_window* bw, struct box_position* void browser_form_submit(struct browser_window *bw, struct form *form, struct form_control *submit_button) { - char *data, *url; + char *data, *url, *url1; struct form_successful_control *success; success = form_successful_controls(form, submit_button); @@ -1536,19 +1540,25 @@ void browser_form_submit(struct browser_window *bw, struct form *form, data = form_url_encode(success); url = xcalloc(1, strlen(form->action) + strlen(data) + 2); sprintf(url, "%s?%s", form->action, data); + url1 = url_join(url, bw->url); free(data); - browser_window_open_location(bw, url); free(url); + browser_window_open_location(bw, url1); + free(url1); break; case method_POST_URLENC: data = form_url_encode(success); - browser_window_open_location_post(bw, form->action, data, 0); + url = url_join(form->action, bw->url); + browser_window_open_location_post(bw, url, data, 0); + free(url); free(data); break; case method_POST_MULTIPART: - browser_window_open_location_post(bw, form->action, 0, success); + url = url_join(form->action, bw->url); + browser_window_open_location_post(bw, url, 0, success); + free(url); break; default: diff --git a/desktop/browser.h b/desktop/browser.h index ae59c2876..e507b5826 100644 --- a/desktop/browser.h +++ b/desktop/browser.h @@ -113,7 +113,7 @@ 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); -void browser_window_key_press(struct browser_window *bw, char key); +bool browser_window_key_press(struct browser_window *bw, char key); struct history_entry * history_add(struct history_entry *current, char *url, char *title); diff --git a/riscos/gui.c b/riscos/gui.c index f2b2af6a9..cc8668249 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -576,79 +576,35 @@ void ro_gui_icon_bar_click(wimp_pointer* pointer) } } -void ro_gui_keypress(wimp_key* key) + +/** + * Handle Key_Pressed events. + */ +void ro_gui_keypress(wimp_key *key) { - gui_window* g; + bool handled = false; + gui_window *g = ro_gui_window_lookup(key->w); - if (key->i == -1 && (key->c < 256 || (key->c >= 396 && key->c <= 399))) { - g = ro_lookup_gui_from_w(key->w); - if (g) { - /* Munge cursor keys into unused control chars */ - if (key->c == 396) key->c = 29; /* Left */ - else if (key->c == 397) key->c = 28; /* Right */ - else if (key->c == 398) key->c = 31; /* Down */ - else if (key->c == 399) key->c = 30; /* Up */ - browser_window_key_press(g->data.browser.bw, (char) key->c); - return; - } - } + if (!g) { + wimp_process_key(key->c); + return; + } - g = ro_lookup_gui_toolbar_from_w(key->w); - if (g != NULL) - { - if (key->c == wimp_KEY_RETURN) - { - if (g->data.browser.bw->url != NULL) - { - xfree(g->data.browser.bw->url); - g->data.browser.bw->url = NULL; - } - if (strcasecmp(g->url, "about:") == 0) { - about_create(); - browser_window_open_location(g->data.browser.bw, - "file:///%3CWimp$ScrapDir%3E/WWW/NetSurf/About"); - } - else { - browser_window_open_location(g->data.browser.bw, g->url); - } - return; - } - else if (key->c == wimp_KEY_F8) - { - /* TODO: use some protocol so it's type as HTML not Text. */ - if(g->data.browser.bw->current_content->type == CONTENT_HTML || - g->data.browser.bw->current_content->type == CONTENT_TEXTPLAIN) - xosfile_save_stamped("Pipe:$.Source", osfile_TYPE_TEXT, - g->data.browser.bw->current_content->data.html.source, - (g->data.browser.bw->current_content->data.html.source + - g->data.browser.bw->current_content->data.html.length)); - xosfile_set_type("Pipe:$.Source", osfile_TYPE_TEXT); - xos_cli("Filer_Run Pipe:$.Source"); - } - else if (key->c == wimp_KEY_F9) - { - switch (g->data.browser.bw->current_content->type) { - case CONTENT_HTML: - box_dump(g->data.browser.bw->current_content->data.html.layout->children, 0); - break; - case CONTENT_CSS: - css_dump_stylesheet(g->data.browser.bw->current_content->data.css.css); - break; - } - } - else if (key->c == wimp_KEY_F10) - { - cache_dump(); - } - else if (key->c == (wimp_KEY_CONTROL + wimp_KEY_F2)) - { - browser_window_destroy(g->data.browser.bw); - } - } - wimp_process_key(key->c); - return; + switch (g->type) { + case GUI_BROWSER_WINDOW: + handled = ro_gui_window_keypress(g, key->c, + (bool) (g->data.browser.toolbar == key->w)); + break; + + case GUI_DOWNLOAD_WINDOW: + break; + } + + if (!handled) + wimp_process_key(key->c); } + void gui_gadget_combo(struct browser_window* bw, struct form_control* g, unsigned long mx, unsigned long my) { int count = 0; @@ -930,6 +886,24 @@ void ro_gui_open_help_page (void) 0,0,-1, (int) strlen(bw->window->url) - 1); } + +/** + * Send the source of a content to a text editor. + */ +void ro_gui_view_source(struct content *content) +{ + if (content->type != CONTENT_HTML) + return; + + xosfile_save_stamped("", 0xfff, + content->data.html.source, + (content->data.html.source + + content->data.html.length)); + xos_cli("Filer_Run "); + xosfile_set_type("", 0xfaf); +} + + void ro_gui_drag_box_start(wimp_pointer *pointer) { wimp_drag *drag_box; diff --git a/riscos/gui.h b/riscos/gui.h index 1883e53b4..6d92ff2bf 100644 --- a/riscos/gui.h +++ b/riscos/gui.h @@ -96,6 +96,7 @@ 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); +void ro_gui_view_source(struct content *content); /* in menus.c */ void ro_gui_menus_init(void); @@ -140,6 +141,8 @@ void ro_gui_toolbar_click(gui_window* g, wimp_pointer* pointer); void ro_gui_throb(void); gui_window* ro_lookup_gui_from_w(wimp_w window); 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); /* in history.c */ void ro_gui_history_init(void); diff --git a/riscos/window.c b/riscos/window.c index e5b7bd4ed..72e815ad7 100644 --- a/riscos/window.c +++ b/riscos/window.c @@ -413,6 +413,25 @@ gui_window* ro_lookup_gui_toolbar_from_w(wimp_w window) return NULL; } + +/** + * Convert a wimp window handle to the owning gui_window structure. + */ +gui_window *ro_gui_window_lookup(wimp_w w) +{ + gui_window *g; + + for (g = window_list; g; g = g->next) { + if (g->window == w) + return g; + else if (g->type == GUI_BROWSER_WINDOW && + g->data.browser.toolbar == w) + return g; + } + return 0; +} + + void ro_gui_window_mouse_at(wimp_pointer* pointer) { int x,y; @@ -573,3 +592,81 @@ void gui_window_place_caret(gui_window *g, int x, int y, int height) wimp_set_caret_position(g->window, -1, x * 2, -(y + height) * 2, height * 2, -1); } + + +/** + * Process Key_Pressed events in a browser window. + */ +bool ro_gui_window_keypress(gui_window *g, int key, bool toolbar) +{ + struct content *content = g->data.browser.bw->current_content; + wimp_window_state state; + + assert(g->type == GUI_BROWSER_WINDOW); + + /* First send the key to the browser window, eg. form fields. */ + if (!toolbar) { + int c = key; + /* Munge cursor keys into unused control chars */ + if (c == 396) c = 29; /* Left */ + else if (c == 397) c = 28; /* Right */ + else if (c == 398) c = 31; /* Down */ + else if (c == 399) c = 30; /* Up */ + if (c < 256) + if (browser_window_key_press(g->data.browser.bw, + (char) c)) + return true; + } + + switch (key) { + case wimp_KEY_F8: /* View source. */ + ro_gui_view_source(content); + return true; + + case wimp_KEY_F9: /* Dump content for debugging. */ + switch (content->type) { + case CONTENT_HTML: + box_dump(content->data.html.layout->children, 0); + break; + case CONTENT_CSS: + css_dump_stylesheet(content->data.css.css); + break; + default: + break; + } + return true; + + case wimp_KEY_F10: /* Dump cache for debugging. */ + cache_dump(); + return true; + + case wimp_KEY_CONTROL + wimp_KEY_F2: /* Close window. */ + browser_window_destroy(g->data.browser.bw); + return true; + + case wimp_KEY_RETURN: + if (!toolbar) + break; + if (strcasecmp(g->url, "about:") == 0) { + about_create(); + browser_window_open_location(g->data.browser.bw, + "file:///%3CWimp$ScrapDir%3E/WWW/NetSurf/About"); + } else { + browser_window_open_location(g->data.browser.bw, g->url); + } + return true; + + case wimp_KEY_UP: + case wimp_KEY_DOWN: + state.w = g->window; + wimp_get_window_state(&state); + state.yscroll += key == wimp_KEY_UP ? 32 : -32; + wimp_open_window((wimp_open *) &state); + return true; + + default: + break; + } + + return false; +} -- cgit v1.2.3