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 --- riscos/gui.c | 110 ++++++++++++++++++++++---------------------------------- riscos/gui.h | 3 ++ riscos/window.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 142 insertions(+), 68 deletions(-) (limited to 'riscos') 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