summaryrefslogtreecommitdiff
path: root/frontends/riscos
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2016-12-28 16:14:19 +0000
committerVincent Sanders <vince@kyllikki.org>2016-12-28 16:14:19 +0000
commit96e073a29777bbe927f0bc7187f7032d3f51e68b (patch)
treea74404287ae531793095126a3499f2d4d34c98fe /frontends/riscos
parent770c277ccc182f504be0a316390d59c05a59e041 (diff)
parentaf6139bcb5845d4cdbc852b113ac8fabcee29097 (diff)
downloadnetsurf-96e073a29777bbe927f0bc7187f7032d3f51e68b.tar.gz
netsurf-96e073a29777bbe927f0bc7187f7032d3f51e68b.tar.bz2
Merge branch 'vince/ro-corewindow'
Conflicts: frontends/riscos/sslcert.h
Diffstat (limited to 'frontends/riscos')
-rw-r--r--frontends/riscos/Makefile15
-rw-r--r--frontends/riscos/cookies.c517
-rw-r--r--frontends/riscos/cookies.h49
-rw-r--r--frontends/riscos/corewindow.c932
-rw-r--r--frontends/riscos/corewindow.h139
-rw-r--r--frontends/riscos/dialog.c8
-rw-r--r--frontends/riscos/global_history.c534
-rw-r--r--frontends/riscos/global_history.h40
-rw-r--r--frontends/riscos/gui.c18
-rw-r--r--frontends/riscos/gui.h5
-rw-r--r--frontends/riscos/gui/button_bar.h24
-rw-r--r--frontends/riscos/gui/url_bar.h1
-rw-r--r--frontends/riscos/help.c8
-rw-r--r--frontends/riscos/hotlist.c861
-rw-r--r--frontends/riscos/hotlist.h59
-rw-r--r--frontends/riscos/iconbar.c11
-rw-r--r--frontends/riscos/menus.c1
-rw-r--r--frontends/riscos/sslcert.c496
-rw-r--r--frontends/riscos/sslcert.h26
-rw-r--r--frontends/riscos/theme.c2
-rw-r--r--frontends/riscos/toolbar.c1
-rw-r--r--frontends/riscos/treeview.c1277
-rw-r--r--frontends/riscos/treeview.h55
-rw-r--r--frontends/riscos/window.c14
24 files changed, 2649 insertions, 2444 deletions
diff --git a/frontends/riscos/Makefile b/frontends/riscos/Makefile
index 6ed076800..b457f02da 100644
--- a/frontends/riscos/Makefile
+++ b/frontends/riscos/Makefile
@@ -46,15 +46,14 @@ endif
# ----------------------------------------------------------------------------
# S_RISCOS are sources purely for the RISC OS build
-S_FRONTEND := 401login.c assert.c bitmap.c buffer.c cookies.c configure.c \
- dialog.c download.c filetype.c font.c \
- global_history.c gui.c help.c history.c hotlist.c iconbar.c \
- image.c menus.c message.c mouse.c palettes.c plotters.c \
+S_FRONTEND := 401login.c assert.c bitmap.c buffer.c configure.c gui.c \
+ dialog.c download.c filetype.c font.c help.c history.c image.c \
+ iconbar.c menus.c message.c mouse.c palettes.c plotters.c \
print.c query.c save.c save_draw.c save_pdf.c schedule.c \
- search.c searchweb.c sslcert.c textarea.c \
- textselection.c theme.c theme_install.c toolbar.c \
- treeview.c ucstables.c uri.c url_complete.c url_protocol.c \
- url_suggest.c wimp.c wimp_event.c window.c \
+ search.c searchweb.c textarea.c textselection.c theme.c \
+ theme_install.c toolbar.c url_suggest.c wimp.c wimp_event.c \
+ ucstables.c uri.c url_complete.c url_protocol.c window.c \
+ corewindow.c cookies.c sslcert.c global_history.c hotlist.c \
$(addprefix content-handlers/,artworks.c awrender.s draw.c \
sprite.c) \
$(addprefix gui/,button_bar.c progress_bar.c status_bar.c \
diff --git a/frontends/riscos/cookies.c b/frontends/riscos/cookies.c
index 26374a567..38963ab3a 100644
--- a/frontends/riscos/cookies.c
+++ b/frontends/riscos/cookies.c
@@ -1,6 +1,5 @@
/*
- * Copyright 2006 Richard Wilson <info@tinct.net>
- * Copyright 2010 Stephen Fryatt <stevef@netsurf-browser.org>
+ * Copyright 2016 Vincent Sanders <vince@netsurf-browser.org>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
@@ -17,176 +16,120 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-/** \file
- * Cookies (implementation).
+/**
+ * \file
+ * Implementation of RISC OS cookie manager.
*/
-#include <assert.h>
-#include <stdbool.h>
-#include <stdio.h>
+#include <stdint.h>
#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include "oslib/wimp.h"
-#include "oslib/wimpspriteop.h"
+#include <oslib/wimp.h>
+#include "utils/log.h"
#include "utils/nsoption.h"
#include "utils/messages.h"
-#include "utils/log.h"
+#include "netsurf/plotters.h"
#include "netsurf/keypress.h"
#include "desktop/cookie_manager.h"
-#include "desktop/tree.h"
-#include "riscos/cookies.h"
-#include "riscos/dialog.h"
-#include "riscos/menus.h"
-#include "riscos/toolbar.h"
-#include "riscos/treeview.h"
+#include "riscos/gui.h"
#include "riscos/wimp.h"
#include "riscos/wimp_event.h"
+#include "riscos/dialog.h"
+#include "riscos/toolbar.h"
+#include "riscos/corewindow.h"
+#include "riscos/cookies.h"
-static void ro_gui_cookies_toolbar_update_buttons(void);
-static void ro_gui_cookies_toolbar_save_buttons(char *config);
-static bool ro_gui_cookies_menu_prepare(wimp_w w, wimp_i i, wimp_menu *menu,
- wimp_pointer *pointer);
-static void ro_gui_cookies_menu_warning(wimp_w w, wimp_i i, wimp_menu *menu,
- wimp_selection *selection, menu_action action);
-static bool ro_gui_cookies_menu_select(wimp_w w, wimp_i i, wimp_menu *menu,
- wimp_selection *selection, menu_action action);
-static void ro_gui_cookies_toolbar_click(button_bar_action action);
-
-struct ro_treeview_callbacks ro_cookies_treeview_callbacks = {
- ro_gui_cookies_toolbar_click,
- ro_gui_cookies_toolbar_update_buttons,
- ro_gui_cookies_toolbar_save_buttons
+struct ro_cookie_window {
+ struct ro_corewindow core;
+ wimp_menu *menu;
};
-/* The RISC OS cookie window, toolbar and treeview data. */
+/** cookie window is a singleton */
+static struct ro_cookie_window *cookie_window = NULL;
-static struct ro_cookies_window {
- wimp_w window;
- struct toolbar *toolbar;
- ro_treeview *tv;
- wimp_menu *menu;
-} cookies_window;
+/** riscos template for cookie window */
+static wimp_window *dialog_cookie_template;
-/**
- * Pre-Initialise the cookies tree. This is called for things that
- * need to be done at the gui_init() stage, such as loading templates.
- */
-
-void ro_gui_cookies_preinitialise(void)
-{
- /* Create our window. */
-
- cookies_window.window = ro_gui_dialog_create("tree");
- ro_gui_set_window_title(cookies_window.window,
- messages_get("Cookies"));
-}
/**
- * Initialise cookies tree, at the gui_init2() stage.
+ * callback to draw on drawable area of ro cookie window
+ *
+ * \param ro_cw The riscos core window structure.
+ * \param r The rectangle of the window that needs updating.
+ * \param originx The risc os plotter x origin.
+ * \param originy The risc os plotter y origin.
+ * \return NSERROR_OK on success otherwise apropriate error code
*/
-
-void ro_gui_cookies_postinitialise(void)
+static nserror
+cookie_draw(struct ro_corewindow *ro_cw,
+ int originx,
+ int originy,
+ struct rect *r)
{
- /* Create our toolbar. */
-
- cookies_window.toolbar = ro_toolbar_create(NULL, cookies_window.window,
- THEME_STYLE_COOKIES_TOOLBAR, TOOLBAR_FLAGS_NONE,
- ro_treeview_get_toolbar_callbacks(), NULL,
- "HelpCookiesToolbar");
- if (cookies_window.toolbar != NULL) {
- ro_toolbar_add_buttons(cookies_window.toolbar,
- cookies_toolbar_buttons,
- nsoption_charp(toolbar_cookies));
- ro_toolbar_rebuild(cookies_window.toolbar);
- }
-
- /* Create the treeview with the window and toolbar. */
-
- cookies_window.tv = ro_treeview_create(cookies_window.window,
- cookies_window.toolbar, &ro_cookies_treeview_callbacks,
- TREE_COOKIES);
- if (cookies_window.tv == NULL) {
- LOG("Failed to allocate treeview");
- return;
- }
-
- ro_toolbar_update_client_data(cookies_window.toolbar,
- cookies_window.tv);
+ struct redraw_context ctx = {
+ .interactive = true,
+ .background_images = true,
+ .plot = &ro_plotters
+ };
- /* Build the cookies window menu. */
+ ro_plot_origin_x = originx;
+ ro_plot_origin_y = originy;
+ no_font_blending = true;
+ cookie_manager_redraw(0, 0, r, &ctx);
+ no_font_blending = false;
- static const struct ns_menu cookies_definition = {
- "Cookies", {
- { "Cookies", NO_ACTION, 0 },
- { "Cookies.Expand", TREE_EXPAND_ALL, 0 },
- { "Cookies.Expand.All", TREE_EXPAND_ALL, 0 },
- { "Cookies.Expand.Folders", TREE_EXPAND_FOLDERS, 0 },
- { "Cookies.Expand.Links", TREE_EXPAND_LINKS, 0 },
- { "Cookies.Collapse", TREE_COLLAPSE_ALL, 0 },
- { "Cookies.Collapse.All", TREE_COLLAPSE_ALL, 0 },
- { "Cookies.Collapse.Folders", TREE_COLLAPSE_FOLDERS, 0 },
- { "Cookies.Collapse.Links", TREE_COLLAPSE_LINKS, 0 },
- { "Cookies.Toolbars", NO_ACTION, 0 },
- { "_Cookies.Toolbars.ToolButtons", TOOLBAR_BUTTONS, 0 },
- { "Cookies.Toolbars.EditToolbar",TOOLBAR_EDIT, 0 },
- { "Selection", TREE_SELECTION, 0 },
- { "Selection.Delete", TREE_SELECTION_DELETE, 0 },
- { "SelectAll", TREE_SELECT_ALL, 0 },
- { "Clear", TREE_CLEAR_SELECTION, 0 },
- {NULL, 0, 0}
- }
- };
- cookies_window.menu = ro_gui_menu_define_menu(&cookies_definition);
-
- ro_gui_wimp_event_register_menu(cookies_window.window,
- cookies_window.menu, false, false);
- ro_gui_wimp_event_register_menu_prepare(cookies_window.window,
- ro_gui_cookies_menu_prepare);
- ro_gui_wimp_event_register_menu_selection(cookies_window.window,
- ro_gui_cookies_menu_select);
- ro_gui_wimp_event_register_menu_warning(cookies_window.window,
- ro_gui_cookies_menu_warning);
+ return NSERROR_OK;
}
+
/**
- * Destroy the cookies window.
+ * callback for keypress on ro cookie window
+ *
+ * \param ro_cw The ro core window structure.
+ * \param nskey The netsurf key code.
+ * \return NSERROR_OK if key processed,
+ * NSERROR_NOT_IMPLEMENTED if key not processed
+ * otherwise apropriate error code
*/
-
-void ro_gui_cookies_destroy(void)
+static nserror cookie_key(struct ro_corewindow *ro_cw, uint32_t nskey)
{
- if (cookies_window.tv == NULL)
- return;
-
- ro_treeview_destroy(cookies_window.tv);
+ if (cookie_manager_keypress(nskey)) {
+ return NSERROR_OK;
+ }
+ return NSERROR_NOT_IMPLEMENTED;
}
+
/**
- * Open the cookies window.
+ * callback for mouse event on ro cookie window
*
+ * \param ro_cw The ro core window structure.
+ * \param mouse_state mouse state
+ * \param x location of event
+ * \param y location of event
+ * \return NSERROR_OK on sucess otherwise apropriate error code.
*/
-
-void ro_gui_cookies_open(void)
+static nserror
+cookie_mouse(struct ro_corewindow *ro_cw,
+ browser_mouse_state mouse_state,
+ int x, int y)
{
- ro_gui_cookies_toolbar_update_buttons();
+ cookie_manager_mouse_action(mouse_state, x, y);
- if (!ro_gui_dialog_open_top(cookies_window.window,
- cookies_window.toolbar, 600, 800)) {
- ro_treeview_set_origin(cookies_window.tv, 0,
- -(ro_toolbar_height(cookies_window.toolbar)));
- }
+ return NSERROR_OK;
}
/**
- * Handle toolbar button clicks.
+ * handle clicks in ro core window toolbar.
*
- * \param action The action to handle
+ * \param ro_cw The ro core window structure.
+ * \param action The button bar action.
+ * \return NSERROR_OK if config saved, otherwise apropriate error code
*/
-
-void ro_gui_cookies_toolbar_click(button_bar_action action)
+static nserror
+cookie_toolbar_click(struct ro_corewindow *ro_cw, button_bar_action action)
{
switch (action) {
case TOOLBAR_BUTTON_DELETE:
@@ -212,139 +155,178 @@ void ro_gui_cookies_toolbar_click(button_bar_action action)
default:
break;
}
+
+ return NSERROR_OK;
}
/**
- * Update the button state in the cookies toolbar.
+ * Handle updating state of buttons in ro core window toolbar.
+ *
+ * \param ro_cw The ro core window structure.
+ * \return NSERROR_OK if config saved, otherwise apropriate error code
*/
-
-void ro_gui_cookies_toolbar_update_buttons(void)
+static nserror cookie_toolbar_update(struct ro_corewindow *ro_cw)
{
- ro_toolbar_set_button_shaded_state(cookies_window.toolbar,
+ ro_toolbar_set_button_shaded_state(ro_cw->toolbar,
TOOLBAR_BUTTON_DELETE,
!cookie_manager_has_selection());
+ return NSERROR_OK;
}
/**
- * Save a new button arrangement in the cookies toolbar.
+ * callback for saving of toolbar state in ro cookie window
*
- * \param *config The new button configuration string.
+ * \param ro_cw The ro core window structure.
+ * \param config The new toolbar configuration.
+ * \return NSERROR_OK if config saved, otherwise apropriate error code
*/
-
-void ro_gui_cookies_toolbar_save_buttons(char *config)
+static nserror cookie_toolbar_save(struct ro_corewindow *ro_cw, char *config)
{
nsoption_set_charp(toolbar_cookies, config);
ro_gui_save_options();
+
+ return NSERROR_OK;
}
/**
- * Prepare the cookies menu for opening
+ * Prepare the cookie meu for display
*
- * \param w The window owning the menu.
- * \param i The icon owning the menu.
- * \param *menu The menu about to be opened.
- * \param *pointer Pointer to the relevant wimp event block, or
- * NULL for an Adjust click.
- * \return true if the event was handled; else false.
+ * \param w The window owning the menu.
+ * \param i The icon owning the menu.
+ * \param menu The menu from which the selection was made.
+ * \param pointer The pointer shape
+ * \return true if action accepted; else false.
*/
-
-bool ro_gui_cookies_menu_prepare(wimp_w w, wimp_i i, wimp_menu *menu,
- wimp_pointer *pointer)
+static bool
+cookie_menu_prepare(wimp_w w,
+ wimp_i i,
+ wimp_menu *menu,
+ wimp_pointer *pointer)
{
bool selection;
+ struct ro_cookie_window *cookiew;
- if (menu != cookies_window.menu)
+ cookiew = (struct ro_cookie_window *)ro_gui_wimp_event_get_user_data(w);
+
+ if ((cookiew == NULL) ||
+ (menu != cookiew->menu)) {
return false;
+ }
selection = cookie_manager_has_selection();
- ro_gui_menu_set_entry_shaded(cookies_window.menu,
- TREE_SELECTION, !selection);
- ro_gui_menu_set_entry_shaded(cookies_window.menu,
- TREE_CLEAR_SELECTION, !selection);
+ ro_gui_menu_set_entry_shaded(menu, TREE_SELECTION, !selection);
+ ro_gui_menu_set_entry_shaded(menu, TREE_CLEAR_SELECTION, !selection);
ro_gui_menu_set_entry_shaded(menu, TOOLBAR_BUTTONS,
- ro_toolbar_menu_option_shade(cookies_window.toolbar));
+ ro_toolbar_menu_option_shade(cookiew->core.toolbar));
ro_gui_menu_set_entry_ticked(menu, TOOLBAR_BUTTONS,
- ro_toolbar_menu_buttons_tick(cookies_window.toolbar));
+ ro_toolbar_menu_buttons_tick(cookiew->core.toolbar));
ro_gui_menu_set_entry_shaded(menu, TOOLBAR_EDIT,
- ro_toolbar_menu_edit_shade(cookies_window.toolbar));
+ ro_toolbar_menu_edit_shade(cookiew->core.toolbar));
ro_gui_menu_set_entry_ticked(menu, TOOLBAR_EDIT,
- ro_toolbar_menu_edit_tick(cookies_window.toolbar));
+ ro_toolbar_menu_edit_tick(cookiew->core.toolbar));
return true;
}
+
/**
* Handle submenu warnings for the cookies menu
*
- * \param w The window owning the menu.
- * \param i The icon owning the menu.
- * \param *menu The menu to which the warning applies.
- * \param *selection The wimp menu selection data.
- * \param action The selected menu action.
+ * \param w The window owning the menu.
+ * \param i The icon owning the menu.
+ * \param menu The menu to which the warning applies.
+ * \param selection The wimp menu selection data.
+ * \param action The selected menu action.
*/
-
-void ro_gui_cookies_menu_warning(wimp_w w, wimp_i i, wimp_menu *menu,
- wimp_selection *selection, menu_action action)
+static void
+cookie_menu_warning(wimp_w w,
+ wimp_i i,
+ wimp_menu *menu,
+ wimp_selection *selection,
+ menu_action action)
{
/* Do nothing */
}
+
/**
* Handle selections from the cookies menu
*
- * \param w The window owning the menu.
- * \param i The icon owning the menu.
- * \param *menu The menu from which the selection was made.
- * \param *selection The wimp menu selection data.
- * \param action The selected menu action.
- * \return true if action accepted; else false.
+ * \param w The window owning the menu.
+ * \param i The icon owning the menu.
+ * \param menu The menu from which the selection was made.
+ * \param selection The wimp menu selection data.
+ * \param action The selected menu action.
+ * \return true if action accepted; else false.
*/
-
-bool ro_gui_cookies_menu_select(wimp_w w, wimp_i i, wimp_menu *menu,
- wimp_selection *selection, menu_action action)
+static bool
+cookie_menu_select(wimp_w w,
+ wimp_i i,
+ wimp_menu *menu,
+ wimp_selection *selection,
+ menu_action action)
{
+ struct ro_cookie_window *cookiew;
+
+ cookiew = (struct ro_cookie_window *)ro_gui_wimp_event_get_user_data(w);
+
+ if ((cookiew == NULL) ||
+ (menu != cookiew->menu)) {
+ return false;
+ }
+
switch (action) {
case TREE_EXPAND_ALL:
cookie_manager_expand(false);
return true;
+
case TREE_EXPAND_FOLDERS:
cookie_manager_expand(true);
return true;
+
case TREE_EXPAND_LINKS:
cookie_manager_expand(false);
return true;
+
case TREE_COLLAPSE_ALL:
cookie_manager_contract(true);
return true;
+
case TREE_COLLAPSE_FOLDERS:
cookie_manager_contract(true);
return true;
+
case TREE_COLLAPSE_LINKS:
cookie_manager_contract(false);
return true;
+
case TREE_SELECTION_DELETE:
cookie_manager_keypress(NS_KEY_DELETE_LEFT);
return true;
+
case TREE_SELECT_ALL:
cookie_manager_keypress(NS_KEY_SELECT_ALL);
return true;
+
case TREE_CLEAR_SELECTION:
cookie_manager_keypress(NS_KEY_CLEAR_SELECTION);
return true;
+
case TOOLBAR_BUTTONS:
- ro_toolbar_set_display_buttons(cookies_window.toolbar,
- !ro_toolbar_get_display_buttons(
- cookies_window.toolbar));
+ ro_toolbar_set_display_buttons(cookiew->core.toolbar,
+ !ro_toolbar_get_display_buttons(cookiew->core.toolbar));
return true;
+
case TOOLBAR_EDIT:
- ro_toolbar_toggle_edit(cookies_window.toolbar);
+ ro_toolbar_toggle_edit(cookiew->core.toolbar);
return true;
+
default:
return false;
}
@@ -352,33 +334,174 @@ bool ro_gui_cookies_menu_select(wimp_w w, wimp_i i, wimp_menu *menu,
return false;
}
+
/**
- * Check if a particular window handle is the cookies window
+ * Creates the window for the cookie tree.
*
- * \param window the window in question
- * \return true if this window is the cookies
+ * \return NSERROR_OK on success else appropriate error code on faliure.
*/
+static nserror ro_cookie_init(void)
+{
+ struct ro_cookie_window *ncwin;
+ nserror res;
+ static const struct ns_menu cookie_menu_def = {
+ "Cookies", {
+ { "Cookies", NO_ACTION, 0 },
+ { "Cookies.Expand", TREE_EXPAND_ALL, 0 },
+ { "Cookies.Expand.All", TREE_EXPAND_ALL, 0 },
+ { "Cookies.Expand.Folders", TREE_EXPAND_FOLDERS, 0 },
+ { "Cookies.Expand.Links", TREE_EXPAND_LINKS, 0 },
+ { "Cookies.Collapse", TREE_COLLAPSE_ALL, 0 },
+ { "Cookies.Collapse.All", TREE_COLLAPSE_ALL, 0 },
+ { "Cookies.Collapse.Folders", TREE_COLLAPSE_FOLDERS, 0 },
+ { "Cookies.Collapse.Links", TREE_COLLAPSE_LINKS, 0 },
+ { "Cookies.Toolbars", NO_ACTION, 0 },
+ { "_Cookies.Toolbars.ToolButtons", TOOLBAR_BUTTONS, 0 },
+ { "Cookies.Toolbars.EditToolbar",TOOLBAR_EDIT, 0 },
+ { "Selection", TREE_SELECTION, 0 },
+ { "Selection.Delete", TREE_SELECTION_DELETE, 0 },
+ { "SelectAll", TREE_SELECT_ALL, 0 },
+ { "Clear", TREE_CLEAR_SELECTION, 0 },
+ { NULL, 0, 0}
+ }
+ };
-bool ro_gui_cookies_check_window(wimp_w window)
+ static const struct button_bar_buttons cookies_toolbar_buttons[] = {
+ { "delete", TOOLBAR_BUTTON_DELETE, TOOLBAR_BUTTON_NONE, '0', "0"},
+ { "expand", TOOLBAR_BUTTON_EXPAND, TOOLBAR_BUTTON_COLLAPSE, '1', "1"},
+ { "open", TOOLBAR_BUTTON_OPEN, TOOLBAR_BUTTON_CLOSE, '2', "2"},
+ { NULL, TOOLBAR_BUTTON_NONE, TOOLBAR_BUTTON_NONE, '\0', ""}
+ };
+
+ if (cookie_window != NULL) {
+ return NSERROR_OK;
+ }
+
+ ncwin = malloc(sizeof(struct ro_cookie_window));
+ if (ncwin == NULL) {
+ return NSERROR_NOMEM;
+ }
+
+ /* create window from template */
+ ncwin->core.wh = wimp_create_window(dialog_cookie_template);
+
+ ro_gui_set_window_title(ncwin->core.wh, messages_get("Cookies"));
+
+ ncwin->core.draw = cookie_draw;
+ ncwin->core.key = cookie_key;
+ ncwin->core.mouse = cookie_mouse;
+ ncwin->core.toolbar_click = cookie_toolbar_click;
+ ncwin->core.toolbar_save = cookie_toolbar_save;
+ /* update is not valid untill cookie manager is initialised */
+ ncwin->core.toolbar_update = NULL;
+
+ /* initialise core window */
+ res = ro_corewindow_init(&ncwin->core,
+ cookies_toolbar_buttons,
+ nsoption_charp(toolbar_cookies),
+ THEME_STYLE_COOKIES_TOOLBAR,
+ "HelpCookiesToolbar");
+ if (res != NSERROR_OK) {
+ free(ncwin);
+ return res;
+ }
+
+ res = cookie_manager_init(ncwin->core.cb_table,
+ (struct core_window *)ncwin);
+ if (res != NSERROR_OK) {
+ free(ncwin);
+ return res;
+ }
+
+ /* setup toolbar update post cookie manager initialisation */
+ ncwin->core.toolbar_update = cookie_toolbar_update;
+ cookie_toolbar_update(&ncwin->core);
+
+ /* Build the cookies window menu. */
+ ncwin->menu = ro_gui_menu_define_menu(&cookie_menu_def);
+
+ ro_gui_wimp_event_register_menu(ncwin->core.wh,
+ ncwin->menu, false, false);
+ ro_gui_wimp_event_register_menu_prepare(ncwin->core.wh,
+ cookie_menu_prepare);
+ ro_gui_wimp_event_register_menu_selection(ncwin->core.wh,
+ cookie_menu_select);
+ ro_gui_wimp_event_register_menu_warning(ncwin->core.wh,
+ cookie_menu_warning);
+
+ /* memoise window so it can be represented when necessary
+ * instead of recreating every time.
+ */
+ cookie_window = ncwin;
+
+ return NSERROR_OK;
+}
+
+
+/* exported interface documented in riscos/cookies.h */
+nserror ro_gui_cookies_present(void)
+{
+ nserror res;
+
+ res = ro_cookie_init();
+ if (res == NSERROR_OK) {
+ LOG("Presenting");
+ ro_gui_dialog_open_top(cookie_window->core.wh,
+ cookie_window->core.toolbar,
+ 600, 800);
+ } else {
+ LOG("Failed presenting code %d", res);
+ }
+
+ return res;
+}
+
+
+/* exported interface documented in riscos/cookies.h */
+void ro_gui_cookies_initialise(void)
+{
+ dialog_cookie_template = ro_gui_dialog_load_template("tree");
+}
+
+
+/* exported interface documented in riscos/cookies.h */
+nserror ro_gui_cookies_finalise(void)
+{
+ nserror res;
+
+ if (cookie_window == NULL) {
+ return NSERROR_OK;
+ }
+
+ res = cookie_manager_fini();
+ if (res == NSERROR_OK) {
+ res = ro_corewindow_fini(&cookie_window->core);
+
+ free(cookie_window);
+ cookie_window = NULL;
+ }
+
+ return res;
+}
+
+
+/* exported interface documented in riscos/cookies.h */
+bool ro_gui_cookies_check_window(wimp_w wh)
{
- if (cookies_window.window == window)
+ if ((cookie_window != NULL) &&
+ (cookie_window->core.wh == wh)) {
return true;
- else
- return false;
+ }
+ return false;
}
-/**
- * Check if a particular menu handle is the cookies menu
- *
- * \param *menu The menu in question.
- * \return true if this menu is the cookies menu
- */
+/* exported interface documented in riscos/cookies.h */
bool ro_gui_cookies_check_menu(wimp_menu *menu)
{
- if (cookies_window.menu == menu)
+ if ((cookie_window != NULL) &&
+ (cookie_window->menu == menu)) {
return true;
- else
- return false;
+ }
+ return false;
}
-
diff --git a/frontends/riscos/cookies.h b/frontends/riscos/cookies.h
index b7313393e..1b07d2122 100644
--- a/frontends/riscos/cookies.h
+++ b/frontends/riscos/cookies.h
@@ -17,22 +17,47 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-/** \file
- * Cookies (interface).
+/**
+ * \file
+ * Interface to riscos cookie viewing using riscos core window.
+ *
+ * The interface assumes there is only a single cookie window which is
+ * presented (shown) when asked for and hidden by usual toolkit
+ * mechanics.
+ *
+ * The destructor is called once during browser shutdown
*/
-#ifndef _NETSURF_RISCOS_COOKIES_H_
-#define _NETSURF_RISCOS_COOKIES_H_
+#ifndef NETSURF_RISCOS_COOKIES_H
+#define NETSURF_RISCOS_COOKIES_H
-#include "riscos/menus.h"
+/**
+ * initialise the cookies window template ready for subsequent use.
+ */
+void ro_gui_cookies_initialise(void);
-void ro_gui_cookies_preinitialise(void);
-void ro_gui_cookies_postinitialise(void);
-void ro_gui_cookies_destroy(void);
-bool ro_gui_cookies_check_window(wimp_w window);
-bool ro_gui_cookies_check_menu(wimp_menu *menu);
+/**
+ * make the cookie window visible.
+ *
+ * \return NSERROR_OK on success else appropriate error code on faliure.
+ */
+nserror ro_gui_cookies_present(void);
-void ro_gui_cookies_open(void);
+/**
+ * Free any resources allocated for the cookie window.
+ *
+ * \return NSERROR_OK on success else appropriate error code on faliure.
+ */
+nserror ro_gui_cookies_finalise(void);
-#endif
+/**
+ * check if window handle is for the cookies window
+ */
+bool ro_gui_cookies_check_window(wimp_w window);
+
+/**
+ * check if menu handle is for the cookies menu
+ */
+bool ro_gui_cookies_check_menu(wimp_menu *menu);
+#endif /* NETSURF_RISCOS_COOKIES_H */
diff --git a/frontends/riscos/corewindow.c b/frontends/riscos/corewindow.c
new file mode 100644
index 000000000..5c0b3e630
--- /dev/null
+++ b/frontends/riscos/corewindow.c
@@ -0,0 +1,932 @@
+/*
+ * Copyright 2016 Vincent Sanders <vince@netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * \file
+ * RISC OS generic core window implementation.
+ *
+ * Provides interface for core renderers to a risc os drawing area.
+ *
+ * This module is an object that must be encapsulated. Client users
+ * should embed a struct ro_corewindow at the beginning of their
+ * context for this display surface, fill in relevant data and then
+ * call ro_corewindow_init()
+ *
+ * The ro core window structure requires the callback for draw, key
+ * and mouse operations.
+ */
+
+#include <stdint.h>
+#include <oslib/wimp.h>
+
+#include "utils/utils.h"
+#include "utils/log.h"
+#include "netsurf/mouse.h"
+#include "netsurf/keypress.h"
+
+#include "riscos/wimp_event.h"
+#include "riscos/dialog.h"
+#include "riscos/gui.h"
+#include "riscos/toolbar.h"
+#include "riscos/mouse.h"
+#include "riscos/corewindow.h"
+
+#ifndef wimp_KEY_END
+#define wimp_KEY_END wimp_KEY_COPY
+#endif
+
+/**
+ * Update a windows scrollbars.
+ *
+ * in the wimp this is done by setting the extent and calling window open
+ */
+static void update_scrollbars(struct ro_corewindow *ro_cw, wimp_open *open)
+{
+ os_error *error;
+ int extent_width;
+ int extent_height;
+ os_box extent;
+
+ LOG("RO corewindow context %p", ro_cw);
+
+ /* extent of content in not smaller than window so start there */
+ extent_width = open->visible.x1 - open->visible.x0;
+ extent_height = open->visible.y0 - open->visible.y1;
+ LOG("extent w:%d h:%d content w:%d h:%d origin h:%d",
+ extent_width, extent_height,
+ ro_cw->content_width, ro_cw->content_height, ro_cw->origin_y);
+ if (ro_cw->content_width > extent_width) {
+ extent_width = ro_cw->content_width;
+ }
+ if (extent_height > (ro_cw->origin_y + ro_cw->content_height)) {
+ extent_height = ro_cw->origin_y + ro_cw->content_height;
+ }
+ LOG("extent w:%d h:%d",
+ extent_width, extent_height);
+ extent.x0 = 0;
+ extent.y0 = extent_height;
+ extent.x1 = extent_width;
+ extent.y1 = 0;
+
+ error = xwimp_set_extent(ro_cw->wh, &extent);
+ if (error) {
+ LOG("xwimp_set_extent: 0x%x: %s",
+ error->errnum, error->errmess);
+ return;
+ }
+
+ error = xwimp_open_window(open);
+ if (error) {
+ LOG("xwimp_open_window: 0x%x: %s",
+ error->errnum, error->errmess);
+ }
+}
+
+
+/**
+ * wimp callback on redraw event
+ */
+static void ro_cw_redraw(wimp_draw *redraw)
+{
+ struct ro_corewindow *ro_cw;
+ osbool more;
+ os_error *error;
+ struct rect r;
+ int origin_x;
+ int origin_y;
+
+ ro_cw = (struct ro_corewindow *)ro_gui_wimp_event_get_user_data(redraw->w);
+
+ error = xwimp_redraw_window(redraw, &more);
+ while ((error == NULL) && (more)) {
+ /* compute rectangle to redraw */
+ origin_x = redraw->box.x0 - redraw->xscroll;
+ origin_y = redraw->box.y1 + ro_cw->origin_y - redraw->yscroll;
+
+ r.x0 = (redraw->clip.x0 - origin_x) / 2;
+ r.y0 = (origin_y - redraw->clip.y1) / 2;
+ r.x1 = r.x0 + ((redraw->clip.x1 - redraw->clip.x0) / 2);
+ r.y1 = r.y0 + ((redraw->clip.y1 - redraw->clip.y0) / 2);
+
+ /* call the draw callback */
+ ro_cw->draw(ro_cw, origin_x, origin_y, &r);
+
+ error = xwimp_get_rectangle(redraw, &more);
+ }
+ if (error != NULL) {
+ LOG("xwimp_redraw_window: 0x%x: %s",
+ error->errnum, error->errmess);
+ }
+
+}
+
+static void ro_cw_scroll(wimp_scroll *scroll)
+{
+ os_error *error;
+ int page_x;
+ int page_y;
+ struct ro_corewindow *ro_cw;
+ wimp_open open;
+
+ ro_cw = (struct ro_corewindow *)ro_gui_wimp_event_get_user_data(scroll->w);
+ LOG("RO corewindow context %p", ro_cw);
+
+ page_x = scroll->visible.x1 - scroll->visible.x0 - 32;
+ page_y = scroll->visible.y1 - scroll->visible.y0 - 32;
+
+ page_y += ro_cw->origin_y;
+
+ open.w = scroll->w;
+ open.visible = scroll->visible;
+ open.next = scroll->next;
+
+ switch (scroll->xmin) {
+ case wimp_SCROLL_PAGE_LEFT:
+ open.xscroll = scroll->xscroll - page_x;
+ break;
+
+ case wimp_SCROLL_COLUMN_LEFT:
+ open.xscroll = scroll->xscroll - 32;
+ break;
+
+ case wimp_SCROLL_COLUMN_RIGHT:
+ open.xscroll = scroll->xscroll + 32;
+ break;
+
+ case wimp_SCROLL_PAGE_RIGHT:
+ open.xscroll = scroll->xscroll + page_x;
+ break;
+
+ default:
+ open.xscroll = scroll->xscroll + ((page_x * (scroll->xmin>>2)) >> 2);
+ break;
+ }
+
+ switch (scroll->ymin) {
+ case wimp_SCROLL_PAGE_UP:
+ open.yscroll = scroll->yscroll + page_y;
+ break;
+
+ case wimp_SCROLL_LINE_UP:
+ open.yscroll = scroll->yscroll + 32;
+ break;
+
+ case wimp_SCROLL_LINE_DOWN:
+ open.yscroll = scroll->yscroll - 32;
+ break;
+
+ case wimp_SCROLL_PAGE_DOWN:
+ open.yscroll = scroll->yscroll - page_y;
+ break;
+
+ default:
+ open.yscroll = scroll->yscroll + ((page_y * (scroll->ymin>>2)) >> 2);
+ break;
+ }
+
+ error = xwimp_open_window(&open);
+ if (error) {
+ LOG("xwimp_open_window: 0x%x: %s",
+ error->errnum, error->errmess);
+ }
+
+}
+
+
+
+/**
+ * Track the mouse under Null Polls from the wimp, to support dragging.
+ *
+ * \param pointer Pointer to a Wimp Pointer block.
+ * \param data NULL to allow use as a ro_mouse callback.
+ */
+static void ro_cw_mouse_at(wimp_pointer *pointer, void *data)
+{
+ os_error *error;
+ struct ro_corewindow *ro_cw;
+ wimp_window_state state;
+ int xpos, ypos;
+ browser_mouse_state mouse;
+
+ /* ignore menu clicks */
+ if (pointer->buttons & (wimp_CLICK_MENU)) {
+ return;
+ }
+
+ ro_cw = (struct ro_corewindow *)ro_gui_wimp_event_get_user_data(pointer->w);
+ if (ro_cw == NULL) {
+ LOG("no corewindow conext for window: 0x%x",
+ (unsigned int)pointer->w);
+ return;
+ }
+ LOG("RO corewindow context %p", ro_cw);
+
+ /* no futher processing required if no drag in progress */
+ if (ro_cw->drag_status == CORE_WINDOW_DRAG_NONE) {
+ return;
+ }
+
+ /* Not a Menu click and a drag is in progress. */
+ state.w = pointer->w;
+ error = xwimp_get_window_state(&state);
+ if (error) {
+ LOG("xwimp_get_window_state: 0x%x: %s",
+ error->errnum, error->errmess);
+ return;
+ }
+
+ /* Convert the returned mouse coordinates into NetSurf's internal
+ * units.
+ */
+ xpos = ((pointer->pos.x - state.visible.x0) + state.xscroll) / 2;
+ ypos = ((state.visible.y1 - pointer->pos.y) -
+ state.yscroll + ro_cw->origin_y) / 2;
+
+ /* Start to process the mouse click. */
+ mouse = ro_gui_mouse_drag_state(pointer->buttons,
+ wimp_BUTTON_DOUBLE_CLICK_DRAG);
+
+ ro_cw->mouse(ro_cw, mouse, xpos, ypos);
+
+ if (!(mouse & BROWSER_MOUSE_DRAG_ON)) {
+ ro_cw->mouse(ro_cw, BROWSER_MOUSE_HOVER, xpos, ypos);
+ ro_cw->drag_status = CORE_WINDOW_DRAG_NONE;
+ }
+
+ ro_cw->toolbar_update(ro_cw);
+}
+
+/**
+ * Process RISC OS User Drag Box events which relate to us: in effect, drags
+ * started by ro_cw_drag_start().
+ *
+ * \param drag Pointer to the User Drag Box Event block.
+ * \param data NULL to allow use as a ro_mouse callback.
+ */
+static void ro_cw_drag_end(wimp_dragged *drag, void *data)
+{
+ os_error *error;
+
+ error = xwimp_drag_box((wimp_drag *) -1);
+ if (error) {
+ LOG("xwimp_drag_box: 0x%x: %s", error->errnum, error->errmess);
+ ro_warn_user("WimpError", error->errmess);
+ }
+
+ error = xwimp_auto_scroll(0, NULL, NULL);
+ if (error) {
+ LOG("xwimp_auto_scroll: 0x%x: %s",
+ error->errnum, error->errmess);
+ ro_warn_user("WimpError", error->errmess);
+ }
+}
+
+
+/**
+ * Start a RISC OS drag event to reflect on screen what is happening
+ * during the core tree drag.
+ *
+ * \param ro_cw The RO corewindow to which the drag is attached.
+ * \param pointer The RO pointer event data block starting the drag.
+ * \param state The RO window state block for the treeview window.
+ */
+static void
+ro_cw_drag_start(struct ro_corewindow *ro_cw,
+ wimp_pointer *pointer,
+ wimp_window_state *state)
+{
+ os_error *error;
+ wimp_drag drag;
+ wimp_auto_scroll_info auto_scroll;
+
+ drag.w = ro_cw->wh;
+ drag.bbox.x0 = state->visible.x0;
+ drag.bbox.y0 = state->visible.y0;
+ drag.bbox.x1 = state->visible.x1;
+ drag.bbox.y1 = state->visible.y1 - ro_toolbar_height(ro_cw->toolbar) - 2;
+
+ switch (ro_cw->drag_status) {
+ case CORE_WINDOW_DRAG_SELECTION:
+ drag.type = wimp_DRAG_USER_RUBBER;
+
+ drag.initial.x0 = pointer->pos.x;
+ drag.initial.y0 = pointer->pos.y;
+ drag.initial.x1 = pointer->pos.x;
+ drag.initial.y1 = pointer->pos.y;
+ break;
+
+ case CORE_WINDOW_DRAG_MOVE:
+ drag.type = wimp_DRAG_USER_POINT;
+
+ drag.initial.x0 = pointer->pos.x - 4;
+ drag.initial.y0 = pointer->pos.y - 48;
+ drag.initial.x1 = pointer->pos.x + 48;
+ drag.initial.y1 = pointer->pos.y + 4;
+ break;
+
+ default:
+ /* No other drag types are supported. */
+ break;
+ }
+
+ LOG("Drag start...");
+
+ error = xwimp_drag_box_with_flags(&drag,
+ wimp_DRAG_BOX_KEEP_IN_LINE | wimp_DRAG_BOX_CLIP);
+ if (error) {
+ LOG("xwimp_drag_box: 0x%x: %s", error->errnum, error->errmess);
+ ro_warn_user("WimpError", error->errmess);
+ } else {
+ auto_scroll.w = ro_cw->wh;
+ auto_scroll.pause_zone_sizes.x0 = 80;
+ auto_scroll.pause_zone_sizes.y0 = 80;
+ auto_scroll.pause_zone_sizes.x1 = 80;
+ auto_scroll.pause_zone_sizes.y1 = 80 + ro_toolbar_height(ro_cw->toolbar);
+ auto_scroll.pause_duration = 0;
+ auto_scroll.state_change = (void *) 1;
+
+ error = xwimp_auto_scroll(wimp_AUTO_SCROLL_ENABLE_VERTICAL,
+ &auto_scroll, NULL);
+ if (error) {
+ LOG("xwimp_auto_scroll: 0x%x: %s", error->errnum, error->errmess);
+ ro_warn_user("WimpError", error->errmess);
+ }
+
+ ro_mouse_drag_start(ro_cw_drag_end, ro_cw_mouse_at, NULL, NULL);
+ }
+}
+
+
+/**
+ * Wimp callback on pointer entering window.
+ *
+ * The wimp has issued an event to the window because the pointer has
+ * entered it.
+ *
+ * \param open The open event to be processed
+ */
+static void ro_cw_pointer_entering(wimp_entering *entering)
+{
+ ro_mouse_track_start(NULL, ro_cw_mouse_at, NULL);
+}
+
+
+/**
+ * Wimp callback on window open event.
+ *
+ * The wimp has issued an event to the window because an attempt has
+ * been made to open or resize it. This requires the new dimensions to
+ * be calculated and set within the wimp.
+ *
+ * \param open The open event to be processed
+ */
+static void ro_cw_open(wimp_open *open)
+{
+ struct ro_corewindow *ro_cw;
+
+ ro_cw = (struct ro_corewindow *)ro_gui_wimp_event_get_user_data(open->w);
+
+ update_scrollbars(ro_cw, open);
+}
+
+static bool ro_cw_mouse_click(wimp_pointer *pointer)
+{
+ os_error *error;
+ wimp_window_state state;
+ int xpos, ypos;
+ browser_mouse_state mouse;
+ bool handled = false;
+ struct ro_corewindow *ro_cw;
+
+ ro_cw = (struct ro_corewindow *)ro_gui_wimp_event_get_user_data(pointer->w);
+ LOG("RO corewindow context %p", ro_cw);
+
+
+ state.w = ro_cw->wh;
+ error = xwimp_get_window_state(&state);
+ if (error) {
+ LOG("xwimp_get_window_state: 0x%x: %s",
+ error->errnum, error->errmess);
+ return false;
+ }
+
+ /* Convert the returned mouse coordinates into NetSurf's internal
+ * units.
+ */
+ xpos = ((pointer->pos.x - state.visible.x0) + state.xscroll) / 2;
+ ypos = ((state.visible.y1 - pointer->pos.y) -
+ state.yscroll + ro_cw->origin_y) / 2;
+
+ if (pointer->buttons != wimp_CLICK_MENU) {
+ mouse = ro_gui_mouse_click_state(pointer->buttons,
+ wimp_BUTTON_DOUBLE_CLICK_DRAG);
+
+ /* Give the window input focus on Select-clicks. This wouldn't
+ * be necessary if the core used the RISC OS caret.
+ */
+ if (mouse & BROWSER_MOUSE_CLICK_1) {
+ xwimp_set_caret_position(ro_cw->wh,
+ -1, -100, -100, 32, -1);
+ }
+ }
+
+ /* call the mouse callback */
+ if (mouse != 0) {
+ ro_cw->mouse(ro_cw, mouse, xpos, ypos);
+
+ /* If it's a visible drag, start the RO side of the visible
+ * effects.
+ */
+ if ((ro_cw->drag_status == CORE_WINDOW_DRAG_SELECTION) ||
+ (ro_cw->drag_status == CORE_WINDOW_DRAG_MOVE)) {
+ ro_cw_drag_start(ro_cw, pointer, &state);
+ }
+
+ ro_cw->toolbar_update(ro_cw);
+ }
+
+ /* Special actions for some mouse buttons. Adjust closes the dialog;
+ * Menu opens a menu. For the latter, we assume that the owning module
+ * will have attached a window menu to our parent window with the auto
+ * flag unset (so that we can fudge the selection above). If it hasn't,
+ * the call will quietly fail.
+ *
+ * \TODO -- Adjust-click close isn't a perfect copy of what the RO
+ * version did: adjust clicks anywhere close the tree, and
+ * selections persist.
+ */
+ switch(pointer->buttons) {
+ case wimp_CLICK_ADJUST:
+ if (handled) {
+ ro_gui_dialog_close(ro_cw->wh);
+ }
+ break;
+
+ case wimp_CLICK_MENU:
+ ro_gui_wimp_event_process_window_menu_click(pointer);
+ break;
+ }
+
+ return true;
+}
+
+static bool ro_cw_keypress(wimp_key *key)
+{
+ uint32_t c;
+ struct ro_corewindow *ro_cw;
+ nserror res;
+
+ ro_cw = (struct ro_corewindow *)ro_gui_wimp_event_get_user_data(key->w);
+ LOG("RO corewindow context %p", ro_cw);
+
+ c = (uint32_t) key->c;
+
+ if ((unsigned)c < 0x20 ||
+ (0x7f <= c && c <= 0x9f) ||
+ (c & IS_WIMP_KEY)) {
+ /* Munge control keys into unused control chars */
+ /* We can't map onto 1->26 (reserved for ctrl+<qwerty>
+ That leaves 27->31 and 128->159 */
+ switch (c & ~IS_WIMP_KEY) {
+ case wimp_KEY_TAB:
+ c = 9;
+ break;
+
+ case wimp_KEY_SHIFT | wimp_KEY_TAB:
+ c = 11;
+ break;
+
+ /* cursor movement keys */
+ case wimp_KEY_HOME:
+ case wimp_KEY_CONTROL | wimp_KEY_LEFT:
+ c = NS_KEY_LINE_START;
+ break;
+
+ case wimp_KEY_END:
+ if (os_version >= RISCOS5)
+ c = NS_KEY_LINE_END;
+ else
+ c = NS_KEY_DELETE_RIGHT;
+ break;
+
+ case wimp_KEY_CONTROL | wimp_KEY_RIGHT:
+ c = NS_KEY_LINE_END;
+ break;
+
+ case wimp_KEY_CONTROL | wimp_KEY_UP:
+ c = NS_KEY_TEXT_START;
+ break;
+
+ case wimp_KEY_CONTROL | wimp_KEY_DOWN:
+ c = NS_KEY_TEXT_END;
+ break;
+
+ case wimp_KEY_SHIFT | wimp_KEY_LEFT:
+ c = NS_KEY_WORD_LEFT;
+ break;
+
+ case wimp_KEY_SHIFT | wimp_KEY_RIGHT:
+ c = NS_KEY_WORD_RIGHT;
+ break;
+
+ case wimp_KEY_SHIFT | wimp_KEY_UP:
+ c = NS_KEY_PAGE_UP;
+ break;
+
+ case wimp_KEY_SHIFT | wimp_KEY_DOWN:
+ c = NS_KEY_PAGE_DOWN;
+ break;
+
+ case wimp_KEY_LEFT:
+ c = NS_KEY_LEFT;
+ break;
+
+ case wimp_KEY_RIGHT:
+ c = NS_KEY_RIGHT;
+ break;
+
+ case wimp_KEY_UP:
+ c = NS_KEY_UP;
+ break;
+
+ case wimp_KEY_DOWN:
+ c = NS_KEY_DOWN;
+ break;
+
+ /* editing */
+ case wimp_KEY_CONTROL | wimp_KEY_END:
+ c = NS_KEY_DELETE_LINE_END;
+ break;
+
+ case wimp_KEY_DELETE:
+ if (ro_gui_ctrl_pressed())
+ c = NS_KEY_DELETE_LINE_START;
+ else if (os_version < RISCOS5)
+ c = NS_KEY_DELETE_LEFT;
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ if (!(c & IS_WIMP_KEY)) {
+ res = ro_cw->key(ro_cw, c);
+ if (res == NSERROR_OK) {
+ ro_cw->toolbar_update(ro_cw);
+ return true;
+ }
+ }
+
+ return false;
+}
+
+
+/**
+ * Update a corewindow toolbar to a new size.
+ *
+ * \param ctx Context as passed to toolbar creation.
+ */
+static void cw_tb_size(void *ctx)
+{
+ struct ro_corewindow *ro_cw;
+ wimp_window_state state;
+ os_error *error;
+
+ ro_cw = (struct ro_corewindow *)ctx;
+
+ ro_cw->origin_y = -(ro_toolbar_height(ro_cw->toolbar));
+
+ state.w = ro_cw->wh;
+ error = xwimp_get_window_state(&state);
+ if (error) {
+ LOG("xwimp_get_window_state: 0x%x: %s",
+ error->errnum, error->errmess);
+ return;
+ }
+
+ error = xwimp_force_redraw(ro_cw->wh,
+ 0, state.visible.y0 - state.visible.y1,
+ state.visible.x1 - state.visible.x0, 0);
+ if (error) {
+ LOG("xwimp_force_redraw: 0x%x: %s",
+ error->errnum, error->errmess);
+ return;
+ }
+}
+
+
+/**
+ * Update a corewindow toolbar to use a new theme.
+ *
+ * \param ctx Context as passed to toolbar creation.
+ * \param exists true if the bar still exists; else false.
+ */
+static void cw_tb_theme(void *ctx, bool exists)
+{
+ if (exists) {
+ cw_tb_size(ctx);
+ }
+}
+
+
+/**
+ * Allow a corewindow toolbar button state to be updated.
+ *
+ * \param ctx Context as passed to toolbar creation.
+ */
+static void cw_tb_update(void *ctx)
+{
+ struct ro_corewindow *ro_cw;
+
+ ro_cw = (struct ro_corewindow *)ctx;
+
+ ro_cw->toolbar_update(ro_cw);
+}
+
+
+/**
+ * Respond to user actions (click) in a corewindow.
+ *
+ * \param ctx Context as passed to toolbar creation.
+ */
+static void
+cw_tb_click(void *ctx,
+ toolbar_action_type action_type,
+ union toolbar_action action)
+{
+ struct ro_corewindow *ro_cw;
+
+ ro_cw = (struct ro_corewindow *)ctx;
+
+ if (action_type == TOOLBAR_ACTION_BUTTON) {
+ ro_cw->toolbar_click(ro_cw, action.button);
+ ro_cw->toolbar_update(ro_cw);
+ }
+}
+
+
+/**
+ * Save positions of core window toolbar buttons.
+ *
+ * \param ctx Context as passed to toolbar creation.
+ * \param config The new button config string.
+ */
+static void cw_tb_save(void *ctx, char *config)
+{
+ struct ro_corewindow *ro_cw;
+
+ ro_cw = (struct ro_corewindow *)ctx;
+
+ ro_cw->toolbar_save(ro_cw, config);
+}
+
+
+
+/** core window toolbar callbacks */
+static const struct toolbar_callbacks corewindow_toolbar_callbacks = {
+ .theme_update = cw_tb_theme,
+ .change_size = cw_tb_size,
+ .update_buttons = cw_tb_update,
+ .user_action = cw_tb_click,
+ .save_buttons = cw_tb_save,
+};
+
+/**
+ * callback from core to request a redraw.
+ */
+static void
+ro_cw_redraw_request(struct core_window *cw, const struct rect *r)
+{
+ struct ro_corewindow *ro_cw = (struct ro_corewindow *)cw;
+ os_error *error;
+
+ error = xwimp_force_redraw(ro_cw->wh,
+ (2 * r->x0),
+ (-2 * (r->y0 + (r->y1 - r->y0))) + ro_cw->origin_y,
+ (2 * (r->x0 + (r->x1 - r->x0))),
+ (-2 * r->y0) + ro_cw->origin_y);
+ if (error) {
+ LOG("xwimp_force_redraw: 0x%x: %s",
+ error->errnum, error->errmess);
+ }
+}
+
+
+/**
+ * Callback from the core to update the content area size.
+ */
+static void
+ro_cw_update_size(struct core_window *cw, int width, int height)
+{
+ struct ro_corewindow *ro_cw = (struct ro_corewindow *)cw;
+ wimp_open open;
+ wimp_window_state state;
+ os_error *error;
+
+ LOG("content resize from w:%d h:%d to w:%d h:%d",
+ ro_cw->content_width, ro_cw->content_height, width, height);
+
+ ro_cw->content_width = width;
+ ro_cw->content_height = -(2 * height);
+
+ state.w = ro_cw->wh;
+ error = xwimp_get_window_state(&state);
+ if (error) {
+ LOG("xwimp_get_window_state: 0x%x: %s",
+ error->errnum, error->errmess);
+ return;
+ }
+
+ open.w = ro_cw->wh;
+ open.visible = state.visible;
+ open.xscroll = state.xscroll;
+ open.yscroll = state.yscroll;
+ open.next = state.next;
+
+ update_scrollbars(ro_cw, &open);
+}
+
+
+/**
+ * Callback from the core to scroll the visible content.
+ */
+static void
+ro_cw_scroll_visible(struct core_window *cw, const struct rect *r)
+{
+ //struct ro_corewindow *ro_cw = (struct ro_corewindow *)cw;
+}
+
+
+/**
+ * Callback from the core to obtain the window viewport dimensions
+ *
+ * \param[in] cw the core window object
+ * \param[out] width to be set to viewport width in px
+ * \param[out] height to be set to viewport height in px
+ */
+static void
+ro_cw_get_window_dimensions(struct core_window *cw, int *width, int *height)
+{
+ struct ro_corewindow *ro_cw = (struct ro_corewindow *)cw;
+ os_error *error;
+ wimp_window_state state;
+
+ state.w = ro_cw->wh;
+ error = xwimp_get_window_state(&state);
+ if (error) {
+ LOG("xwimp_get_window_state: 0x%x: %s",
+ error->errnum, error->errmess);
+ return;
+ }
+
+ *width = (state.visible.x1 - state.visible.x0) / 2;
+ *height = (state.visible.y1 - state.visible.y0) / 2;
+}
+
+
+/**
+ * Callback from the core to update the drag status.
+ */
+static void
+ro_cw_drag_status(struct core_window *cw, core_window_drag_status ds)
+{
+ struct ro_corewindow *ro_cw = (struct ro_corewindow *)cw;
+ ro_cw->drag_status = ds;
+}
+
+
+struct core_window_callback_table ro_cw_cb_table = {
+ .redraw_request = ro_cw_redraw_request,
+ .update_size = ro_cw_update_size,
+ .scroll_visible = ro_cw_scroll_visible,
+ .get_window_dimensions = ro_cw_get_window_dimensions,
+ .drag_status = ro_cw_drag_status
+};
+
+/**
+ * dummy toolbar click callback
+ *
+ */
+static nserror dummy_toolbar_click(struct ro_corewindow *ro_cw, button_bar_action action)
+{
+ return NSERROR_OK;
+}
+
+/**
+ * dummy toolbar update callback
+ */
+static nserror dummy_toolbar_update(struct ro_corewindow *ro_cw)
+{
+ return NSERROR_OK;
+}
+
+/**
+ * dummy toolbar save callback
+ */
+static nserror dummy_toolbar_save(struct ro_corewindow *ro_cw, char *config)
+{
+ return NSERROR_OK;
+}
+
+/* exported function documented ro/corewindow.h */
+nserror
+ro_corewindow_init(struct ro_corewindow *ro_cw,
+ const struct button_bar_buttons *tb_buttons,
+ char *tb_order,
+ theme_style tb_style,
+ const char *tb_help)
+{
+ /* setup the core window callback table */
+ ro_cw->cb_table = &ro_cw_cb_table;
+
+ /* start with the content area being as small as possible */
+ ro_cw->content_width = -1;
+ ro_cw->content_height = -1;
+ ro_cw->origin_y = 0; /* no offset */
+ ro_cw->drag_status = CORE_WINDOW_DRAG_NONE; /* no drag */
+
+ /* Create toolbar. */
+ if (tb_buttons != NULL) {
+ /* ensure toolbar callbacks are always valid so calls
+ * do not have to be conditional
+ */
+ if (ro_cw->toolbar_click == NULL) {
+ ro_cw->toolbar_click = dummy_toolbar_click;
+ }
+ if (ro_cw->toolbar_save == NULL) {
+ ro_cw->toolbar_save = dummy_toolbar_save;
+ }
+ if (ro_cw->toolbar_update == NULL) {
+ ro_cw->toolbar_update = dummy_toolbar_update;
+ }
+
+ ro_cw->toolbar = ro_toolbar_create(NULL,
+ ro_cw->wh,
+ tb_style,
+ TOOLBAR_FLAGS_NONE,
+ &corewindow_toolbar_callbacks,
+ ro_cw,
+ tb_help);
+ if (ro_cw->toolbar == NULL) {
+ return NSERROR_INIT_FAILED;
+ }
+
+ ro_toolbar_add_buttons(ro_cw->toolbar, tb_buttons, tb_order);
+ ro_toolbar_rebuild(ro_cw->toolbar);
+ ro_cw->origin_y = -(ro_toolbar_height(ro_cw->toolbar));
+ } else {
+ ro_cw->toolbar = NULL; /* no toolbar */
+
+ /* ensure callback functions are set to defaults when
+ * no toolbar
+ */
+ ro_cw->toolbar_click = dummy_toolbar_click;
+ ro_cw->toolbar_save = dummy_toolbar_save;
+ ro_cw->toolbar_update = dummy_toolbar_update;
+ }
+
+ /* setup context for event handlers */
+ ro_gui_wimp_event_set_user_data(ro_cw->wh, ro_cw);
+
+ /* register wimp events. */
+ ro_gui_wimp_event_register_redraw_window(ro_cw->wh,
+ ro_cw_redraw);
+ ro_gui_wimp_event_register_scroll_window(ro_cw->wh,
+ ro_cw_scroll);
+ ro_gui_wimp_event_register_pointer_entering_window(ro_cw->wh,
+ ro_cw_pointer_entering);
+ ro_gui_wimp_event_register_open_window(ro_cw->wh,
+ ro_cw_open);
+ ro_gui_wimp_event_register_mouse_click(ro_cw->wh,
+ ro_cw_mouse_click);
+ ro_gui_wimp_event_register_keypress(ro_cw->wh,
+ ro_cw_keypress);
+
+ return NSERROR_OK;
+}
+
+/* exported interface documented in ro/corewindow.h */
+nserror ro_corewindow_fini(struct ro_corewindow *ro_cw)
+{
+ ro_gui_wimp_event_finalise(ro_cw->wh);
+
+ /** \todo need to consider freeing of toolbar */
+
+ return NSERROR_OK;
+}
diff --git a/frontends/riscos/corewindow.h b/frontends/riscos/corewindow.h
new file mode 100644
index 000000000..b340bde35
--- /dev/null
+++ b/frontends/riscos/corewindow.h
@@ -0,0 +1,139 @@
+/*
+ * Copyright 2016 Vincent Sanders <vince@netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * \file
+ * RISC OS core window interface
+ *
+ * This module is an object that must be encapsulated. Client users
+ * should embed a struct ro_corewindow at the beginning of their
+ * context for this display surface, fill in relevant data and then
+ * call ro_corewindow_init()
+ */
+
+#ifndef NETSURF_RISCOS_COREWINDOW_H
+#define NETSURF_RISCOS_COREWINDOW_H
+
+#include "netsurf/core_window.h"
+
+/**
+ * ro core window state
+ */
+struct ro_corewindow {
+ /** window handle */
+ wimp_w wh;
+
+ /** toolbar */
+ struct toolbar *toolbar;
+
+ /** content plot origin y relative to window */
+ int origin_y;
+
+ /** content width */
+ int content_width;
+
+ /** content height */
+ int content_height;
+
+ /** drag status set by core */
+ core_window_drag_status drag_status;
+
+ /** table of callbacks for core window operations */
+ struct core_window_callback_table *cb_table;
+
+ /**
+ * callback to draw on drawable area of ro core window
+ *
+ * \param ro_cw The riscos core window structure.
+ * \param originx The risc os plotter x origin.
+ * \param originy The risc os plotter y origin.
+ * \param r The rectangle of the window that needs updating.
+ * \return NSERROR_OK on success otherwise apropriate error code
+ */
+ nserror (*draw)(struct ro_corewindow *ro_cw, int originx, int originy, struct rect *r);
+
+ /**
+ * callback for keypress on ro core window
+ *
+ * \param ro_cw The ro core window structure.
+ * \param nskey The netsurf key code.
+ * \return NSERROR_OK if key processed,
+ * NSERROR_NOT_IMPLEMENTED if key not processed
+ * otherwise apropriate error code
+ */
+ nserror (*key)(struct ro_corewindow *ro_cw, uint32_t nskey);
+
+ /**
+ * callback for mouse event on ro core window
+ *
+ * \param ro_cw The ro core window structure.
+ * \param mouse_state mouse state
+ * \param x location of event
+ * \param y location of event
+ * \return NSERROR_OK on sucess otherwise apropriate error code.
+ */
+ nserror (*mouse)(struct ro_corewindow *ro_cw, browser_mouse_state mouse_state, int x, int y);
+
+ /**
+ * callback for clicks in ro core window toolbar.
+ *
+ * \param ro_cw The ro core window structure.
+ * \param action The button bar action.
+ * \return NSERROR_OK if config saved, otherwise apropriate error code
+ */
+ nserror (*toolbar_click)(struct ro_corewindow *ro_cw, button_bar_action action);
+
+ /**
+ * callback for updating state of buttons in ro core window toolbar.
+ *
+ * \param ro_cw The ro core window structure.
+ * \return NSERROR_OK if config saved, otherwise apropriate error code
+ */
+ nserror (*toolbar_update)(struct ro_corewindow *ro_cw);
+
+ /**
+ * callback for saving ro core window toolbar state.
+ *
+ * \param ro_cw The ro core window structure.
+ * \param config The new toolbar configuration.
+ * \return NSERROR_OK if config saved, otherwise apropriate error code
+ */
+ nserror (*toolbar_save)(struct ro_corewindow *ro_cw, char *config);
+
+};
+
+/**
+ * initialise elements of riscos core window.
+ *
+ * As a pre-requisite the draw, key and mouse callbacks must be defined
+ *
+ * \param ro_cw A riscos core window structure to initialise
+ * \return NSERROR_OK on successful initialisation otherwise error code.
+ */
+nserror ro_corewindow_init(struct ro_corewindow *ro_cw, const struct button_bar_buttons *tb_buttons, char *tb_order, theme_style tb_style, const char *tb_help);
+
+/**
+ * finalise elements of ro core window.
+ *
+ * \param ro_cw A riscos core window structure to initialise
+ * \return NSERROR_OK on successful finalisation otherwise error code.
+ */
+nserror ro_corewindow_fini(struct ro_corewindow *ro_cw);
+
+
+#endif
diff --git a/frontends/riscos/dialog.c b/frontends/riscos/dialog.c
index 2b258bbca..94c62354b 100644
--- a/frontends/riscos/dialog.c
+++ b/frontends/riscos/dialog.c
@@ -181,16 +181,16 @@ void ro_gui_dialog_init(void)
*/
/* certificate verification window */
- ro_gui_cert_preinitialise();
+ ro_gui_cert_initialise();
/* hotlist window */
- ro_gui_hotlist_preinitialise();
+ ro_gui_hotlist_initialise();
/* global history window */
- ro_gui_global_history_preinitialise();
+ ro_gui_global_history_initialise();
/* cookies window */
- ro_gui_cookies_preinitialise();
+ ro_gui_cookies_initialise();
}
diff --git a/frontends/riscos/global_history.c b/frontends/riscos/global_history.c
index e893630d1..94e1d4a03 100644
--- a/frontends/riscos/global_history.c
+++ b/frontends/riscos/global_history.c
@@ -1,6 +1,6 @@
/*
- * Copyright 2005 Richard Wilson <info@tinct.net>
* Copyright 2010 Stephen Fryatt <stevef@netsurf-browser.org>
+ * Copyright 2016 Vincent Sanders <vince@netsurf-browser.org>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
@@ -19,183 +19,122 @@
/**
* \file
- * Global history implementation for RISC OS.
+ * Implementation of RISC OS global history.
*/
-#include <assert.h>
-#include <stdbool.h>
-#include <stdio.h>
+#include <stdint.h>
#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include "oslib/wimp.h"
-#include "oslib/wimpspriteop.h"
+#include <oslib/wimp.h>
#include "utils/nsoption.h"
#include "utils/messages.h"
#include "utils/log.h"
#include "netsurf/window.h"
+#include "netsurf/plotters.h"
#include "netsurf/keypress.h"
#include "desktop/global_history.h"
-#include "desktop/tree.h"
#include "riscos/dialog.h"
-#include "riscos/global_history.h"
#include "riscos/gui.h"
#include "riscos/menus.h"
#include "riscos/save.h"
#include "riscos/toolbar.h"
-#include "riscos/treeview.h"
#include "riscos/wimp.h"
#include "riscos/wimp_event.h"
+#include "riscos/corewindow.h"
+#include "riscos/global_history.h"
-static void ro_gui_global_history_toolbar_update_buttons(void);
-static void ro_gui_global_history_toolbar_save_buttons(char *config);
-static bool ro_gui_global_history_menu_prepare(wimp_w w, wimp_i i,
- wimp_menu *menu, wimp_pointer *pointer);
-static void ro_gui_global_history_menu_warning(wimp_w w, wimp_i i,
- wimp_menu *menu, wimp_selection *selection, menu_action action);
-static bool ro_gui_global_history_menu_select(wimp_w w, wimp_i i,
- wimp_menu *menu, wimp_selection *selection, menu_action action);
-static void ro_gui_global_history_toolbar_click(button_bar_action action);
-
-struct ro_treeview_callbacks ro_global_history_treeview_callbacks = {
- ro_gui_global_history_toolbar_click,
- ro_gui_global_history_toolbar_update_buttons,
- ro_gui_global_history_toolbar_save_buttons
+struct ro_global_history_window {
+ struct ro_corewindow core;
+ wimp_menu *menu;
};
-/* The RISC OS global history window, toolbar and treeview data */
-
-static struct ro_global_history_window {
- wimp_w window;
- struct toolbar *toolbar;
- ro_treeview *tv;
- wimp_menu *menu;
-} global_history_window;
-
-/**
- * Pre-Initialise the global history tree. This is called for things that
- * need to be done at the gui_init() stage, such as loading templates.
- */
+/** global_history window is a singleton */
+static struct ro_global_history_window *global_history_window = NULL;
-void ro_gui_global_history_preinitialise(void)
-{
- /* Create our window. */
+/** riscos template for global_history window */
+static wimp_window *dialog_global_history_template;
- global_history_window.window = ro_gui_dialog_create("tree");
- ro_gui_set_window_title(global_history_window.window,
- messages_get("GlobalHistory"));
-}
/**
- * Initialise global history tree, at the gui_init2() stage.
+ * callback to draw on drawable area of ro global_history window
+ *
+ * \param ro_cw The riscos core window structure.
+ * \param r The rectangle of the window that needs updating.
+ * \param originx The risc os plotter x origin.
+ * \param originy The risc os plotter y origin.
+ * \return NSERROR_OK on success otherwise apropriate error code
*/
-
-void ro_gui_global_history_postinitialise(void)
+static nserror
+global_history_draw(struct ro_corewindow *ro_cw,
+ int originx,
+ int originy,
+ struct rect *r)
{
- /* Create our toolbar. */
-
- global_history_window.toolbar = ro_toolbar_create(NULL,
- global_history_window.window,
- THEME_STYLE_GLOBAL_HISTORY_TOOLBAR, TOOLBAR_FLAGS_NONE,
- ro_treeview_get_toolbar_callbacks(), NULL,
- "HelpGHistoryToolbar");
- if (global_history_window.toolbar != NULL) {
- ro_toolbar_add_buttons(global_history_window.toolbar,
- global_history_toolbar_buttons,
- nsoption_charp(toolbar_history));
- ro_toolbar_rebuild(global_history_window.toolbar);
- }
-
- /* Create the treeview with the window and toolbar. */
-
- global_history_window.tv =
- ro_treeview_create(global_history_window.window,
- global_history_window.toolbar,
- &ro_global_history_treeview_callbacks,
- TREE_HISTORY);
- if (global_history_window.tv == NULL) {
- LOG("Failed to allocate treeview");
- return;
- }
-
- ro_toolbar_update_client_data(global_history_window.toolbar,
- global_history_window.tv);
+ struct redraw_context ctx = {
+ .interactive = true,
+ .background_images = true,
+ .plot = &ro_plotters
+ };
- /* Build the global history window menu. */
+ ro_plot_origin_x = originx;
+ ro_plot_origin_y = originy;
+ no_font_blending = true;
+ global_history_redraw(0, 0, r, &ctx);
+ no_font_blending = false;
- static const struct ns_menu global_history_definition = {
- "History", {
- { "History", NO_ACTION, 0 },
- { "_History.Export", HISTORY_EXPORT, &dialog_saveas },
- { "History.Expand", TREE_EXPAND_ALL, 0 },
- { "History.Expand.All", TREE_EXPAND_ALL, 0 },
- { "History.Expand.Folders", TREE_EXPAND_FOLDERS, 0 },
- { "History.Expand.Links", TREE_EXPAND_LINKS, 0 },
- { "History.Collapse", TREE_COLLAPSE_ALL, 0 },
- { "History.Collapse.All", TREE_COLLAPSE_ALL, 0 },
- { "History.Collapse.Folders", TREE_COLLAPSE_FOLDERS, 0 },
- { "History.Collapse.Links", TREE_COLLAPSE_LINKS, 0 },
- { "History.Toolbars", NO_ACTION, 0 },
- { "_History.Toolbars.ToolButtons", TOOLBAR_BUTTONS, 0 },
- { "History.Toolbars.EditToolbar",TOOLBAR_EDIT, 0 },
- { "Selection", TREE_SELECTION, 0 },
- { "Selection.Launch", TREE_SELECTION_LAUNCH, 0 },
- { "Selection.Delete", TREE_SELECTION_DELETE, 0 },
- { "SelectAll", TREE_SELECT_ALL, 0 },
- { "Clear", TREE_CLEAR_SELECTION, 0 },
- {NULL, 0, 0}
- }
- };
- global_history_window.menu = ro_gui_menu_define_menu(
- &global_history_definition);
-
- ro_gui_wimp_event_register_menu(global_history_window.window,
- global_history_window.menu, false, false);
- ro_gui_wimp_event_register_menu_prepare(global_history_window.window,
- ro_gui_global_history_menu_prepare);
- ro_gui_wimp_event_register_menu_selection(global_history_window.window,
- ro_gui_global_history_menu_select);
- ro_gui_wimp_event_register_menu_warning(global_history_window.window,
- ro_gui_global_history_menu_warning);
+ return NSERROR_OK;
}
+
/**
- * Destroy the global history window.
+ * callback for keypress on ro coookie window
+ *
+ * \param ro_cw The ro core window structure.
+ * \param nskey The netsurf key code.
+ * \return NSERROR_OK if key processed,
+ * NSERROR_NOT_IMPLEMENTED if key not processed
+ * otherwise apropriate error code
*/
-
-void ro_gui_global_history_destroy(void)
+static nserror global_history_key(struct ro_corewindow *ro_cw, uint32_t nskey)
{
- if (global_history_window.tv == NULL)
- return;
-
- ro_treeview_destroy(global_history_window.tv);
+ if (global_history_keypress(nskey)) {
+ return NSERROR_OK;
+ }
+ return NSERROR_NOT_IMPLEMENTED;
}
+
/**
- * Open the global history window.
+ * callback for mouse event on ro global_history window
+ *
+ * \param ro_cw The ro core window structure.
+ * \param mouse_state mouse state
+ * \param x location of event
+ * \param y location of event
+ * \return NSERROR_OK on sucess otherwise apropriate error code.
*/
-
-void ro_gui_global_history_open(void)
+static nserror
+global_history_mouse(struct ro_corewindow *ro_cw,
+ browser_mouse_state mouse_state,
+ int x, int y)
{
- ro_gui_global_history_toolbar_update_buttons();
+ global_history_mouse_action(mouse_state, x, y);
- if (!ro_gui_dialog_open_top(global_history_window.window,
- global_history_window.toolbar, 600, 800)) {
- ro_treeview_set_origin(global_history_window.tv, 0,
- -(ro_toolbar_height(
- global_history_window.toolbar)));
- }
+ return NSERROR_OK;
}
+
/**
- * Handle toolbar button clicks.
+ * handle clicks in ro core window toolbar.
*
- * \param action The action to handle
+ * \param ro_cw The ro core window structure.
+ * \param action The button bar action.
+ * \return NSERROR_OK if config saved, otherwise apropriate error code
*/
-
-void ro_gui_global_history_toolbar_click(button_bar_action action)
+static nserror
+global_history_toolbar_click(struct ro_corewindow *ro_cw,
+ button_bar_action action)
{
switch (action) {
case TOOLBAR_BUTTON_DELETE:
@@ -225,156 +164,194 @@ void ro_gui_global_history_toolbar_click(button_bar_action action)
default:
break;
}
+
+ return NSERROR_OK;
}
/**
- * Update the button state in the global history toolbar.
+ * Handle updating state of buttons in ro core window toolbar.
+ *
+ * \param ro_cw The ro core window structure.
+ * \return NSERROR_OK if config saved, otherwise apropriate error code
*/
-
-void ro_gui_global_history_toolbar_update_buttons(void)
+static nserror global_history_toolbar_update(struct ro_corewindow *ro_cw)
{
- ro_toolbar_set_button_shaded_state(global_history_window.toolbar,
+ ro_toolbar_set_button_shaded_state(ro_cw->toolbar,
TOOLBAR_BUTTON_DELETE,
!global_history_has_selection());
- ro_toolbar_set_button_shaded_state(global_history_window.toolbar,
+ ro_toolbar_set_button_shaded_state(ro_cw->toolbar,
TOOLBAR_BUTTON_LAUNCH,
!global_history_has_selection());
+ return NSERROR_OK;
}
/**
- * Save a new button arrangement in the global history toolbar.
+ * callback for saving of toolbar state in ro global history window
*
- * \param *config The new button configuration string.
+ * \param ro_cw The ro core window structure.
+ * \param config The new toolbar configuration.
+ * \return NSERROR_OK if config saved, otherwise apropriate error code
*/
-
-void ro_gui_global_history_toolbar_save_buttons(char *config)
+static nserror
+global_history_toolbar_save(struct ro_corewindow *ro_cw, char *config)
{
nsoption_set_charp(toolbar_history, config);
ro_gui_save_options();
+
+ return NSERROR_OK;
}
/**
- * Prepare the global history menu for opening
+ * Prepare the global_history menu for display
*
- * \param w The window owning the menu.
- * \param i The icon owning the menu.
- * \param *menu The menu about to be opened.
- * \param *pointer Pointer to the relevant wimp event block, or
- * NULL for an Adjust click.
- * \return true if the event was handled; else false.
+ * \param w The window owning the menu.
+ * \param i The icon owning the menu.
+ * \param menu The menu from which the selection was made.
+ * \param pointer The pointer shape
+ * \return true if action accepted; else false.
*/
-
-bool ro_gui_global_history_menu_prepare(wimp_w w, wimp_i i, wimp_menu *menu,
- wimp_pointer *pointer)
+static bool
+global_history_menu_prepare(wimp_w w,
+ wimp_i i,
+ wimp_menu *menu,
+ wimp_pointer *pointer)
{
bool selection;
+ struct ro_global_history_window *global_historyw;
- if (menu != global_history_window.menu)
+ global_historyw = (struct ro_global_history_window *)ro_gui_wimp_event_get_user_data(w);
+
+ if ((global_historyw == NULL) ||
+ (menu != global_historyw->menu)) {
return false;
+ }
selection = global_history_has_selection();
- ro_gui_menu_set_entry_shaded(global_history_window.menu,
- TREE_SELECTION, !selection);
- ro_gui_menu_set_entry_shaded(global_history_window.menu,
- TREE_CLEAR_SELECTION, !selection);
+ ro_gui_menu_set_entry_shaded(menu, TREE_SELECTION, !selection);
+ ro_gui_menu_set_entry_shaded(menu, TREE_CLEAR_SELECTION, !selection);
ro_gui_save_prepare(GUI_SAVE_HISTORY_EXPORT_HTML,
- NULL, NULL, NULL, NULL);
+ NULL, NULL, NULL, NULL);
ro_gui_menu_set_entry_shaded(menu, TOOLBAR_BUTTONS,
- ro_toolbar_menu_option_shade(
- global_history_window.toolbar));
+ ro_toolbar_menu_option_shade(global_historyw->core.toolbar));
ro_gui_menu_set_entry_ticked(menu, TOOLBAR_BUTTONS,
- ro_toolbar_menu_buttons_tick(
- global_history_window.toolbar));
+ ro_toolbar_menu_buttons_tick(global_historyw->core.toolbar));
ro_gui_menu_set_entry_shaded(menu, TOOLBAR_EDIT,
- ro_toolbar_menu_edit_shade(
- global_history_window.toolbar));
+ ro_toolbar_menu_edit_shade(global_historyw->core.toolbar));
ro_gui_menu_set_entry_ticked(menu, TOOLBAR_EDIT,
- ro_toolbar_menu_edit_tick(
- global_history_window.toolbar));
+ ro_toolbar_menu_edit_tick(global_historyw->core.toolbar));
return true;
}
+
/**
- * Handle submenu warnings for the global_hostory menu
+ * Handle submenu warnings for the global_history menu
*
- * \param w The window owning the menu.
- * \param i The icon owning the menu.
- * \param *menu The menu to which the warning applies.
- * \param *selection The wimp menu selection data.
- * \param action The selected menu action.
+ * \param w The window owning the menu.
+ * \param i The icon owning the menu.
+ * \param menu The menu to which the warning applies.
+ * \param selection The wimp menu selection data.
+ * \param action The selected menu action.
*/
-
-void ro_gui_global_history_menu_warning(wimp_w w, wimp_i i, wimp_menu *menu,
- wimp_selection *selection, menu_action action)
+static void
+global_history_menu_warning(wimp_w w,
+ wimp_i i,
+ wimp_menu *menu,
+ wimp_selection *selection,
+ menu_action action)
{
/* Do nothing */
}
+
/**
- * Handle selections from the global history menu
+ * Handle selections from the global_history menu
*
- * \param w The window owning the menu.
- * \param i The icon owning the menu.
- * \param *menu The menu from which the selection was made.
- * \param *selection The wimp menu selection data.
- * \param action The selected menu action.
- * \return true if action accepted; else false.
+ * \param w The window owning the menu.
+ * \param i The icon owning the menu.
+ * \param menu The menu from which the selection was made.
+ * \param selection The wimp menu selection data.
+ * \param action The selected menu action.
+ * \return true if action accepted; else false.
*/
-
-bool ro_gui_global_history_menu_select(wimp_w w, wimp_i i, wimp_menu *menu,
- wimp_selection *selection, menu_action action)
+static bool
+global_history_menu_select(wimp_w w,
+ wimp_i i,
+ wimp_menu *menu,
+ wimp_selection *selection,
+ menu_action action)
{
+ struct ro_global_history_window *global_historyw;
+
+ global_historyw = (struct ro_global_history_window *)ro_gui_wimp_event_get_user_data(w);
+
+ if ((global_historyw == NULL) ||
+ (menu != global_historyw->menu)) {
+ return false;
+ }
+
switch (action) {
case HISTORY_EXPORT:
ro_gui_dialog_open_persistent(w, dialog_saveas, true);
return true;
+
case TREE_EXPAND_ALL:
global_history_expand(false);
return true;
+
case TREE_EXPAND_FOLDERS:
global_history_expand(true);
return true;
+
case TREE_EXPAND_LINKS:
global_history_expand(false);
return true;
+
case TREE_COLLAPSE_ALL:
global_history_contract(true);
return true;
+
case TREE_COLLAPSE_FOLDERS:
global_history_contract(true);
return true;
+
case TREE_COLLAPSE_LINKS:
global_history_contract(false);
return true;
+
case TREE_SELECTION_LAUNCH:
global_history_keypress(NS_KEY_CR);
return true;
+
case TREE_SELECTION_DELETE:
global_history_keypress(NS_KEY_DELETE_LEFT);
return true;
+
case TREE_SELECT_ALL:
global_history_keypress(NS_KEY_SELECT_ALL);
return true;
+
case TREE_CLEAR_SELECTION:
global_history_keypress(NS_KEY_CLEAR_SELECTION);
return true;
+
case TOOLBAR_BUTTONS:
- ro_toolbar_set_display_buttons(global_history_window.toolbar,
- !ro_toolbar_get_display_buttons(
- global_history_window.toolbar));
+ ro_toolbar_set_display_buttons(global_historyw->core.toolbar,
+ !ro_toolbar_get_display_buttons(global_historyw->core.toolbar));
return true;
+
case TOOLBAR_EDIT:
- ro_toolbar_toggle_edit(global_history_window.toolbar);
+ ro_toolbar_toggle_edit(global_historyw->core.toolbar);
return true;
+
default:
return false;
}
@@ -382,33 +359,178 @@ bool ro_gui_global_history_menu_select(wimp_w w, wimp_i i, wimp_menu *menu,
return false;
}
+
/**
- * Check if a particular window handle is the global history window
+ * Creates the window for the global_history tree.
*
- * \param window the window in question
- * \return true if this window is the global history
+ * \return NSERROR_OK on success else appropriate error code on faliure.
*/
+static nserror ro_global_history_init(void)
+{
+ struct ro_global_history_window *ncwin;
+ nserror res;
+ static const struct ns_menu global_history_menu_def = {
+ "History", {
+ { "History", NO_ACTION, 0 },
+ { "_History.Export", HISTORY_EXPORT, &dialog_saveas },
+ { "History.Expand", TREE_EXPAND_ALL, 0 },
+ { "History.Expand.All", TREE_EXPAND_ALL, 0 },
+ { "History.Expand.Folders", TREE_EXPAND_FOLDERS, 0 },
+ { "History.Expand.Links", TREE_EXPAND_LINKS, 0 },
+ { "History.Collapse", TREE_COLLAPSE_ALL, 0 },
+ { "History.Collapse.All", TREE_COLLAPSE_ALL, 0 },
+ { "History.Collapse.Folders", TREE_COLLAPSE_FOLDERS, 0 },
+ { "History.Collapse.Links", TREE_COLLAPSE_LINKS, 0 },
+ { "History.Toolbars", NO_ACTION, 0 },
+ { "_History.Toolbars.ToolButtons", TOOLBAR_BUTTONS, 0 },
+ { "History.Toolbars.EditToolbar",TOOLBAR_EDIT, 0 },
+ { "Selection", TREE_SELECTION, 0 },
+ { "Selection.Launch", TREE_SELECTION_LAUNCH, 0 },
+ { "Selection.Delete", TREE_SELECTION_DELETE, 0 },
+ { "SelectAll", TREE_SELECT_ALL, 0 },
+ { "Clear", TREE_CLEAR_SELECTION, 0 },
+ { NULL, 0, 0}
+ }
+ };
+
+ static const struct button_bar_buttons global_history_toolbar_buttons[] = {
+ { "delete", TOOLBAR_BUTTON_DELETE, TOOLBAR_BUTTON_NONE, '0', "0"},
+ { "expand", TOOLBAR_BUTTON_EXPAND, TOOLBAR_BUTTON_COLLAPSE, '1', "1"},
+ { "open", TOOLBAR_BUTTON_OPEN, TOOLBAR_BUTTON_CLOSE, '2', "2"},
+ { "launch", TOOLBAR_BUTTON_LAUNCH, TOOLBAR_BUTTON_NONE, '3', "3"},
+ { NULL, TOOLBAR_BUTTON_NONE, TOOLBAR_BUTTON_NONE, '\0', ""}
+ };
+
+ if (global_history_window != NULL) {
+ return NSERROR_OK;
+ }
+
+ ncwin = malloc(sizeof(struct ro_global_history_window));
+ if (ncwin == NULL) {
+ return NSERROR_NOMEM;
+ }
+
+ /* create window from template */
+ ncwin->core.wh = wimp_create_window(dialog_global_history_template);
+
+ ro_gui_set_window_title(ncwin->core.wh, messages_get("GlobalHistory"));
+
+ /* initialise callbacks */
+ ncwin->core.draw = global_history_draw;
+ ncwin->core.key = global_history_key;
+ ncwin->core.mouse = global_history_mouse;
+ ncwin->core.toolbar_click = global_history_toolbar_click;
+ ncwin->core.toolbar_save = global_history_toolbar_save;
+ /* update is not valid untill global history is initialised */
+ ncwin->core.toolbar_update = NULL;
+
+ /* initialise core window */
+ res = ro_corewindow_init(&ncwin->core,
+ global_history_toolbar_buttons,
+ nsoption_charp(toolbar_history),
+ THEME_STYLE_GLOBAL_HISTORY_TOOLBAR,
+ "HelpGHistoryToolbar");
+ if (res != NSERROR_OK) {
+ free(ncwin);
+ return res;
+ }
+
+ res = global_history_init(ncwin->core.cb_table,
+ (struct core_window *)ncwin);
+ if (res != NSERROR_OK) {
+ free(ncwin);
+ return res;
+ }
-bool ro_gui_global_history_check_window(wimp_w window)
+ /* setup toolbar update post global_history manager initialisation */
+ ncwin->core.toolbar_update = global_history_toolbar_update;
+ global_history_toolbar_update(&ncwin->core);
+
+ /* Build the global_history window menu. */
+ ncwin->menu = ro_gui_menu_define_menu(&global_history_menu_def);
+
+ ro_gui_wimp_event_register_menu(ncwin->core.wh,
+ ncwin->menu, false, false);
+ ro_gui_wimp_event_register_menu_prepare(ncwin->core.wh,
+ global_history_menu_prepare);
+ ro_gui_wimp_event_register_menu_selection(ncwin->core.wh,
+ global_history_menu_select);
+ ro_gui_wimp_event_register_menu_warning(ncwin->core.wh,
+ global_history_menu_warning);
+
+ /* memoise window so it can be represented when necessary
+ * instead of recreating every time.
+ */
+ global_history_window = ncwin;
+
+ return NSERROR_OK;
+}
+
+
+/* exported interface documented in riscos/global_history.h */
+nserror ro_gui_global_history_present(void)
{
- if (global_history_window.window == window)
+ nserror res;
+
+ res = ro_global_history_init();
+ if (res == NSERROR_OK) {
+ LOG("Presenting");
+ ro_gui_dialog_open_top(global_history_window->core.wh,
+ global_history_window->core.toolbar,
+ 600, 800);
+ } else {
+ LOG("Failed presenting code %d", res);
+ }
+
+ return res;
+}
+
+
+/* exported interface documented in riscos/global_history.h */
+void ro_gui_global_history_initialise(void)
+{
+ dialog_global_history_template = ro_gui_dialog_load_template("tree");
+}
+
+
+/* exported interface documented in riscos/global_history.h */
+nserror ro_gui_global_history_finalise(void)
+{
+ nserror res;
+
+ if (global_history_window == NULL) {
+ return NSERROR_OK;
+ }
+
+ res = global_history_fini();
+ if (res == NSERROR_OK) {
+ res = ro_corewindow_fini(&global_history_window->core);
+
+ free(global_history_window);
+ global_history_window = NULL;
+ }
+
+ return res;
+}
+
+
+/* exported interface documented in riscos/global_history.h */
+bool ro_gui_global_history_check_window(wimp_w wh)
+{
+ if ((global_history_window != NULL) &&
+ (global_history_window->core.wh == wh)) {
return true;
- else
- return false;
+ }
+ return false;
}
-/**
- * Check if a particular menu handle is the global history menu
- *
- * \param *menu The menu in question.
- * \return true if this menu is the global history menu
- */
+/* exported interface documented in riscos/global_history.h */
bool ro_gui_global_history_check_menu(wimp_menu *menu)
{
- if (global_history_window.menu == menu)
+ if ((global_history_window != NULL) &&
+ (global_history_window->menu == menu)) {
return true;
- else
- return false;
+ }
+ return false;
}
-
diff --git a/frontends/riscos/global_history.h b/frontends/riscos/global_history.h
index 6f5ba11eb..0d368c3da 100644
--- a/frontends/riscos/global_history.h
+++ b/frontends/riscos/global_history.h
@@ -17,21 +17,41 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-/** \file
- * Global history (interface).
+/**
+ * \file
+ * RISc OS global history interface.
*/
-#ifndef _NETSURF_RISCOS_GLOBALHISTORY_H_
-#define _NETSURF_RISCOS_GLOBALHISTORY_H_
+#ifndef RISCOS_GLOBALHISTORY_H
+#define RISCOS_GLOBALHISTORY_H
-#include "riscos/menus.h"
+/**
+ * initialise the global history window template ready for subsequent use.
+ */
+void ro_gui_global_history_initialise(void);
+
+/**
+ * make the global history window visible.
+ *
+ * \return NSERROR_OK on success else appropriate error code on faliure.
+ */
+nserror ro_gui_global_history_present(void);
+
+/**
+ * Free any resources allocated for the global history window.
+ *
+ * \return NSERROR_OK on success else appropriate error code on faliure.
+ */
+nserror ro_gui_global_history_finalise(void);
-void ro_gui_global_history_preinitialise(void);
-void ro_gui_global_history_postinitialise(void);
-void ro_gui_global_history_destroy(void);
-void ro_gui_global_history_open(void);
-void ro_gui_global_history_save(void);
+/**
+ * check if window handle is for the global history window
+ */
bool ro_gui_global_history_check_window(wimp_w window);
+
+/**
+ * check if menu handle is for the global history menu
+ */
bool ro_gui_global_history_check_menu(wimp_menu *menu);
#endif
diff --git a/frontends/riscos/gui.c b/frontends/riscos/gui.c
index 92268e3b8..3ac9d4aa9 100644
--- a/frontends/riscos/gui.c
+++ b/frontends/riscos/gui.c
@@ -1268,18 +1268,6 @@ static nserror gui_init(int argc, char** argv)
/* Finally, check Inet$Resolvers for sanity */
ro_gui_check_resolvers();
- /* certificate verification window */
- ro_gui_cert_postinitialise();
-
- /* hotlist window */
- ro_gui_hotlist_postinitialise();
-
- /* global history window */
- ro_gui_global_history_postinitialise();
-
- /* cookies window */
- ro_gui_cookies_postinitialise();
-
open_window = nsoption_bool(open_browser_at_startup);
/* parse command-line arguments */
@@ -1567,9 +1555,9 @@ static void gui_quit(void)
urldb_save_cookies(nsoption_charp(cookie_jar));
urldb_save(nsoption_charp(url_save));
ro_gui_window_quit();
- ro_gui_global_history_destroy();
- ro_gui_hotlist_destroy();
- ro_gui_cookies_destroy();
+ ro_gui_global_history_finalise();
+ ro_gui_hotlist_finalise();
+ ro_gui_cookies_finalise();
ro_gui_saveas_quit();
ro_gui_url_bar_fini();
rufl_quit();
diff --git a/frontends/riscos/gui.h b/frontends/riscos/gui.h
index 505e8e755..1f5070012 100644
--- a/frontends/riscos/gui.h
+++ b/frontends/riscos/gui.h
@@ -211,11 +211,6 @@ extern int ro_plot_origin_y;
/* in theme_install.c */
bool ro_gui_theme_install_apply(wimp_w w);
-/* in sslcert.c */
-nserror gui_cert_verify(struct nsurl *url,
- const struct ssl_cert_info *certs, unsigned long num,
- nserror (*cb)(bool proceed, void *pw), void *cbpw);
-
/* icon numbers */
#define ICON_STATUS_RESIZE 0
#define ICON_STATUS_TEXT 1
diff --git a/frontends/riscos/gui/button_bar.h b/frontends/riscos/gui/button_bar.h
index a1f7e8b9f..5cde986ee 100644
--- a/frontends/riscos/gui/button_bar.h
+++ b/frontends/riscos/gui/button_bar.h
@@ -95,30 +95,6 @@ static const struct button_bar_buttons brower_toolbar_buttons[] = {
{NULL, TOOLBAR_BUTTON_NONE, TOOLBAR_BUTTON_NONE, '\0', ""}
};
-static const struct button_bar_buttons cookies_toolbar_buttons[] = {
- {"delete", TOOLBAR_BUTTON_DELETE, TOOLBAR_BUTTON_NONE, '0', "0"},
- {"expand", TOOLBAR_BUTTON_EXPAND, TOOLBAR_BUTTON_COLLAPSE, '1', "1"},
- {"open", TOOLBAR_BUTTON_OPEN, TOOLBAR_BUTTON_CLOSE, '2', "2"},
- {NULL, TOOLBAR_BUTTON_NONE, TOOLBAR_BUTTON_NONE, '\0', ""}
-};
-
-static const struct button_bar_buttons global_history_toolbar_buttons[] = {
- {"delete", TOOLBAR_BUTTON_DELETE, TOOLBAR_BUTTON_NONE, '0', "0"},
- {"expand", TOOLBAR_BUTTON_EXPAND, TOOLBAR_BUTTON_COLLAPSE, '1', "1"},
- {"open", TOOLBAR_BUTTON_OPEN, TOOLBAR_BUTTON_CLOSE, '2', "2"},
- {"launch", TOOLBAR_BUTTON_LAUNCH, TOOLBAR_BUTTON_NONE, '3', "3"},
- {NULL, TOOLBAR_BUTTON_NONE, TOOLBAR_BUTTON_NONE, '\0', ""}
-};
-
-static const struct button_bar_buttons hotlist_toolbar_buttons[] = {
- {"delete", TOOLBAR_BUTTON_DELETE, TOOLBAR_BUTTON_NONE, '0', "0"},
- {"expand", TOOLBAR_BUTTON_EXPAND, TOOLBAR_BUTTON_COLLAPSE, '1', "1"},
- {"open", TOOLBAR_BUTTON_OPEN, TOOLBAR_BUTTON_CLOSE, '2', "2"},
- {"launch", TOOLBAR_BUTTON_LAUNCH, TOOLBAR_BUTTON_NONE, '3', "3"},
- {"create", TOOLBAR_BUTTON_CREATE, TOOLBAR_BUTTON_NONE, '4', "4"},
- {NULL, TOOLBAR_BUTTON_NONE, TOOLBAR_BUTTON_NONE, '\0', ""}
-};
-
struct button_bar;
diff --git a/frontends/riscos/gui/url_bar.h b/frontends/riscos/gui/url_bar.h
index 981afb35f..9486e214d 100644
--- a/frontends/riscos/gui/url_bar.h
+++ b/frontends/riscos/gui/url_bar.h
@@ -40,6 +40,7 @@ typedef enum {
struct url_bar;
struct hlcache_handle;
+struct gui_window;
/**
* Initialise the url bar module.
diff --git a/frontends/riscos/help.c b/frontends/riscos/help.c
index 64d4a2f8e..b6871c5eb 100644
--- a/frontends/riscos/help.c
+++ b/frontends/riscos/help.c
@@ -21,6 +21,7 @@
*/
#include <oslib/wimp.h>
+#include <oslib/help.h>
#include <oslib/taskmanager.h>
#include "utils/nsoption.h"
@@ -30,7 +31,6 @@
#include "netsurf/mouse.h"
#include "netsurf/window.h"
-#include "riscos/treeview.h"
#include "riscos/help.h"
#include "riscos/wimp_event.h"
#include "riscos/hotlist.h"
@@ -132,16 +132,16 @@ void ro_gui_interactive_help_request(wimp_message *message)
} else if (window == wimp_ICON_BAR)
sprintf(message_token, "HelpIconbar");
else if (ro_gui_hotlist_check_window(message->data.data_xfer.w)) {
- i = ro_treeview_get_help(message_data);
+ i = -1;
sprintf(message_token,
(i >= 0) ? "HelpTree%i" :"HelpHotlist%i", i);
} else if (ro_gui_global_history_check_window(
message->data.data_xfer.w)) {
- i = ro_treeview_get_help(message_data);
+ i = -1;
sprintf(message_token,
(i >= 0) ? "HelpTree%i" :"HelpGHistory%i", i);
} else if (ro_gui_cookies_check_window(message->data.data_xfer.w)) {
- i = ro_treeview_get_help(message_data);
+ i = -1;
sprintf(message_token,
(i >= 0) ? "HelpTree%i" :"HelpCookies%i", i);
} else if (ro_gui_window_lookup(window) != NULL)
diff --git a/frontends/riscos/hotlist.c b/frontends/riscos/hotlist.c
index d47702082..24ced69b5 100644
--- a/frontends/riscos/hotlist.c
+++ b/frontends/riscos/hotlist.c
@@ -1,6 +1,6 @@
/*
- * Copyright 2004, 2005 Richard Wilson <info@tinct.net>
* Copyright 2010, 2013 Stephen Fryatt <stevef@netsurf-browser.org>
+ * Copyright 2016 Vincent Sanders <vince@netsurf-browser.org>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
@@ -19,16 +19,11 @@
/**
* \file
- * Hotlist implementation for RISC OS.
+ * Implementation of RISC OS hotlist manager.
*/
-#include <ctype.h>
-#include <string.h>
-#include <stdbool.h>
-#include <stdio.h>
+#include <stdint.h>
#include <stdlib.h>
-#include <time.h>
-#include <oslib/osfile.h>
#include <oslib/osmodule.h>
#include <oslib/wimp.h>
@@ -38,222 +33,145 @@
#include "utils/nsurl.h"
#include "netsurf/url_db.h"
#include "netsurf/window.h"
+#include "netsurf/plotters.h"
#include "netsurf/keypress.h"
#include "desktop/hotlist.h"
-#include "desktop/tree.h"
#include "riscos/gui.h"
#include "riscos/dialog.h"
-#include "riscos/hotlist.h"
-#include "riscos/menus.h"
#include "riscos/message.h"
#include "riscos/save.h"
#include "riscos/toolbar.h"
-#include "riscos/treeview.h"
#include "riscos/wimp.h"
#include "riscos/wimp_event.h"
#include "riscos/query.h"
+#include "riscos/menus.h"
+#include "riscos/corewindow.h"
+#include "riscos/hotlist.h"
-static void ro_gui_hotlist_toolbar_update_buttons(void);
-static void ro_gui_hotlist_toolbar_save_buttons(char *config);
-static bool ro_gui_hotlist_menu_prepare(wimp_w w, wimp_i i, wimp_menu *menu,
- wimp_pointer *pointer);
-static void ro_gui_hotlist_menu_warning(wimp_w w, wimp_i i, wimp_menu *menu,
- wimp_selection *selection, menu_action action);
-static bool ro_gui_hotlist_menu_select(wimp_w w, wimp_i i, wimp_menu *menu,
- wimp_selection *selection, menu_action action);
-static void ro_gui_hotlist_toolbar_click(button_bar_action action);
-static void ro_gui_hotlist_addurl_bounce(wimp_message *message);
-static void ro_gui_hotlist_scheduled_callback(void *p);
-static void ro_gui_hotlist_remove_confirmed(query_id id,
- enum query_response res, void *p);
-static void ro_gui_hotlist_remove_cancelled(query_id id,
- enum query_response res, void *p);
-
-static const query_callback remove_funcs = {
- ro_gui_hotlist_remove_confirmed,
- ro_gui_hotlist_remove_cancelled
-};
-
-struct ro_treeview_callbacks ro_hotlist_treeview_callbacks = {
- ro_gui_hotlist_toolbar_click,
- ro_gui_hotlist_toolbar_update_buttons,
- ro_gui_hotlist_toolbar_save_buttons
-};
-
-/* Hotlist Protocol Message Blocks, which are currently not in OSLib. */
-
-struct ro_hotlist_message_hotlist_addurl {
- wimp_MESSAGE_HEADER_MEMBERS /**< The standard message header. */
- char *url; /**< Pointer to the URL in RMA. */
- char *title; /**< Pointer to the title in RMA. */
- char appname[32]; /**< The application name. */
+/**
+ * Hotlist window container for RISC OS.
+ */
+struct ro_hotlist_window {
+ struct ro_corewindow core;
+ wimp_menu *menu;
};
-struct ro_hotlist_message_hotlist_changed {
- wimp_MESSAGE_HEADER_MEMBERS /**< The standard message header. */
-};
+/** hotlist window singleton */
+static struct ro_hotlist_window *hotlist_window = NULL;
-static char *hotlist_url = NULL; /**< URL area claimed from RMA. */
-static char *hotlist_title = NULL; /**< Title area claimed from RMA. */
+/** riscos template for hotlist window */
+static wimp_window *dialog_hotlist_template;
/** Hotlist Query Handler. */
-
static query_id hotlist_query = QUERY_INVALID;
-static nsurl *hotlist_delete_url = NULL;
-
-/* The RISC OS hotlist window, toolbar and treeview data. */
+static nsurl *hotlist_delete_url = NULL;
-static struct ro_hotlist {
- wimp_w window; /**< The hotlist RO window handle. */
- struct toolbar *toolbar; /**< The hotlist toolbar handle. */
- ro_treeview *tv; /**< The hotlist treeview handle. */
- wimp_menu *menu; /**< The hotlist window menu. */
-} hotlist_window;
+/**
+ * URL adding hotlist protocol message block.
+ *
+ * Message block is not currently in OSLib.
+ */
+struct ro_hotlist_message_hotlist_addurl {
+ wimp_MESSAGE_HEADER_MEMBERS /**< The standard message header. */
+ char *url; /**< Pointer to the URL in RMA. */
+ char *title; /**< Pointer to the title in RMA. */
+ char appname[32]; /**< The application name. */
+};
/**
- * Pre-Initialise the hotlist tree. This is called for things that need to
- * be done at the gui_init() stage, such as loading templates.
+ * change hotlist protocol message block.
+ *
+ * Message block is not currently in OSLib.
*/
+struct ro_hotlist_message_hotlist_changed {
+ wimp_MESSAGE_HEADER_MEMBERS /**< The standard message header. */
+};
-void ro_gui_hotlist_preinitialise(void)
-{
- /* Create our window. */
+/** URL area claimed from RMA. */
+static char *hotlist_url = NULL;
+/** Title area claimed from RMA. */
+static char *hotlist_title = NULL;
- hotlist_window.window = ro_gui_dialog_create("tree");
- ro_gui_set_window_title(hotlist_window.window,
- messages_get("Hotlist"));
-}
/**
- * Initialise the hotlist tree, at the gui_init2() stage.
+ * callback to draw on drawable area of ro hotlist window
+ *
+ * \param ro_cw The riscos core window structure.
+ * \param r The rectangle of the window that needs updating.
+ * \param originx The risc os plotter x origin.
+ * \param originy The risc os plotter y origin.
+ * \return NSERROR_OK on success otherwise apropriate error code
*/
-
-void ro_gui_hotlist_postinitialise(void)
+static nserror
+hotlist_draw(struct ro_corewindow *ro_cw,
+ int originx,
+ int originy,
+ struct rect *r)
{
- /* Create our toolbar. */
-
- hotlist_window.toolbar = ro_toolbar_create(NULL, hotlist_window.window,
- THEME_STYLE_HOTLIST_TOOLBAR, TOOLBAR_FLAGS_NONE,
- ro_treeview_get_toolbar_callbacks(), NULL,
- "HelpHotToolbar");
- if (hotlist_window.toolbar != NULL) {
- ro_toolbar_add_buttons(hotlist_window.toolbar,
- hotlist_toolbar_buttons,
- nsoption_charp(toolbar_hotlist));
- ro_toolbar_rebuild(hotlist_window.toolbar);
- }
-
- /* Create the treeview with the window and toolbar. */
- tree_hotlist_path = nsoption_charp(hotlist_path);
- hotlist_window.tv = ro_treeview_create(hotlist_window.window,
- hotlist_window.toolbar, &ro_hotlist_treeview_callbacks,
- TREE_HOTLIST);
- if (hotlist_window.tv == NULL) {
- LOG("Failed to allocate treeview");
- return;
- }
-
- ro_toolbar_update_client_data(hotlist_window.toolbar,
- hotlist_window.tv);
-
- /* Build the hotlist window menu. */
-
- static const struct ns_menu hotlist_definition = {
- "Hotlist", {
- { "Hotlist", NO_ACTION, 0 },
- { "Hotlist.New", NO_ACTION, 0 },
- { "Hotlist.New.Folder", TREE_NEW_FOLDER, 0 },
- { "Hotlist.New.Link", TREE_NEW_LINK, 0 },
- { "_Hotlist.Export", HOTLIST_EXPORT, &dialog_saveas },
- { "Hotlist.Expand", TREE_EXPAND_ALL, 0 },
- { "Hotlist.Expand.All", TREE_EXPAND_ALL, 0 },
- { "Hotlist.Expand.Folders", TREE_EXPAND_FOLDERS, 0 },
- { "Hotlist.Expand.Links", TREE_EXPAND_LINKS, 0 },
- { "Hotlist.Collapse", TREE_COLLAPSE_ALL, 0 },
- { "Hotlist.Collapse.All", TREE_COLLAPSE_ALL, 0 },
- { "Hotlist.Collapse.Folders", TREE_COLLAPSE_FOLDERS, 0 },
- { "Hotlist.Collapse.Links", TREE_COLLAPSE_LINKS, 0 },
- { "Hotlist.Toolbars", NO_ACTION, 0 },
- { "_Hotlist.Toolbars.ToolButtons", TOOLBAR_BUTTONS, 0 },
- { "Hotlist.Toolbars.EditToolbar", TOOLBAR_EDIT, 0 },
- { "Selection", TREE_SELECTION, 0 },
- { "Selection.Edit", TREE_SELECTION_EDIT, 0 },
- { "Selection.Launch", TREE_SELECTION_LAUNCH, 0 },
- { "Selection.Delete", TREE_SELECTION_DELETE, 0 },
- { "SelectAll", TREE_SELECT_ALL, 0 },
- { "Clear", TREE_CLEAR_SELECTION, 0 },
- {NULL, 0, 0}
- }
+ struct redraw_context ctx = {
+ .interactive = true,
+ .background_images = true,
+ .plot = &ro_plotters
};
- hotlist_window.menu = ro_gui_menu_define_menu(&hotlist_definition);
+ ro_plot_origin_x = originx;
+ ro_plot_origin_y = originy;
+ no_font_blending = true;
+ hotlist_redraw(0, 0, r, &ctx);
+ no_font_blending = false;
- ro_gui_wimp_event_register_menu(hotlist_window.window,
- hotlist_window.menu, false, false);
- ro_gui_wimp_event_register_menu_prepare(hotlist_window.window,
- ro_gui_hotlist_menu_prepare);
- ro_gui_wimp_event_register_menu_selection(hotlist_window.window,
- ro_gui_hotlist_menu_select);
- ro_gui_wimp_event_register_menu_warning(hotlist_window.window,
- ro_gui_hotlist_menu_warning);
+ return NSERROR_OK;
}
+
/**
- * Destroy the hotlist window.
+ * callback for keypress on ro hotlist window
+ *
+ * \param ro_cw The ro core window structure.
+ * \param nskey The netsurf key code.
+ * \return NSERROR_OK if key processed,
+ * NSERROR_NOT_IMPLEMENTED if key not processed
+ * otherwise apropriate error code
*/
-
-void ro_gui_hotlist_destroy(void)
+static nserror hotlist_key(struct ro_corewindow *ro_cw, uint32_t nskey)
{
- if (hotlist_window.tv == NULL)
- return;
-
- tree_hotlist_path = nsoption_charp(hotlist_save);
- ro_treeview_destroy(hotlist_window.tv);
+ if (hotlist_keypress(nskey)) {
+ return NSERROR_OK;
+ }
+ return NSERROR_NOT_IMPLEMENTED;
}
/**
- * Open the hotlist window.
+ * callback for mouse event on ro hotlist window
*
+ * \param ro_cw The ro core window structure.
+ * \param mouse_state mouse state
+ * \param x location of event
+ * \param y location of event
+ * \return NSERROR_OK on sucess otherwise apropriate error code.
*/
-
-void ro_gui_hotlist_open(void)
+static nserror
+hotlist_mouse(struct ro_corewindow *ro_cw,
+ browser_mouse_state mouse_state,
+ int x, int y)
{
- if (nsoption_bool(external_hotlists) &&
- nsoption_charp(external_hotlist_app) != NULL &&
- *nsoption_charp(external_hotlist_app) != '\0') {
- char command[2048];
- os_error *error;
-
- snprintf(command, sizeof(command), "Filer_Run %s",
- nsoption_charp(external_hotlist_app));
- error = xos_cli(command);
-
- if (error == NULL)
- return;
-
- LOG("xos_cli: 0x%x: %s", error->errnum, error->errmess);
- ro_warn_user("Failed to launch external hotlist: %s",
- error->errmess);
- }
-
- ro_gui_hotlist_toolbar_update_buttons();
+ hotlist_mouse_action(mouse_state, x, y);
- if (!ro_gui_dialog_open_top(hotlist_window.window,
- hotlist_window.toolbar, 600, 800)) {
- ro_treeview_set_origin(hotlist_window.tv, 0,
- -(ro_toolbar_height(hotlist_window.toolbar)));
- }
+ return NSERROR_OK;
}
+
/**
- * Handle toolbar button clicks.
+ * handle clicks in ro hotlist window toolbar.
*
- * \param action The action to handle
+ * \param ro_cw The ro core window structure.
+ * \param action The button bar action.
+ * \return NSERROR_OK if config saved, otherwise apropriate error code
*/
-
-void ro_gui_hotlist_toolbar_click(button_bar_action action)
+static nserror
+hotlist_toolbar_click(struct ro_corewindow *ro_cw, button_bar_action action)
{
switch (action) {
case TOOLBAR_BUTTON_DELETE:
@@ -288,76 +206,90 @@ void ro_gui_hotlist_toolbar_click(button_bar_action action)
default:
break;
}
+
+ return NSERROR_OK;
}
/**
- * Update the button state in the hotlist toolbar.
+ * Handle updating state of buttons in ro core window toolbar.
+ *
+ * \param ro_cw The ro core window structure.
+ * \return NSERROR_OK if config saved, otherwise apropriate error code
*/
-
-void ro_gui_hotlist_toolbar_update_buttons(void)
+static nserror hotlist_toolbar_update(struct ro_corewindow *ro_cw)
{
- ro_toolbar_set_button_shaded_state(hotlist_window.toolbar,
- TOOLBAR_BUTTON_DELETE,
- !hotlist_has_selection());
+ bool has_selection;
+
+ has_selection = hotlist_has_selection();
+
+ ro_toolbar_set_button_shaded_state(ro_cw->toolbar,
+ TOOLBAR_BUTTON_DELETE,
+ !has_selection);
- ro_toolbar_set_button_shaded_state(hotlist_window.toolbar,
- TOOLBAR_BUTTON_LAUNCH,
- !hotlist_has_selection());
+ ro_toolbar_set_button_shaded_state(ro_cw->toolbar,
+ TOOLBAR_BUTTON_LAUNCH,
+ !has_selection);
+
+ return NSERROR_OK;
}
/**
- * Save a new button arrangement in the hotlist toolbar.
+ * callback for saving of toolbar state in ro hotlist window
*
- * \param *config The new button configuration string.
+ * \param ro_cw The ro core window structure.
+ * \param config The new toolbar configuration.
+ * \return NSERROR_OK if config saved, otherwise apropriate error code
*/
-
-void ro_gui_hotlist_toolbar_save_buttons(char *config)
+static nserror hotlist_toolbar_save(struct ro_corewindow *ro_cw, char *config)
{
nsoption_set_charp(toolbar_hotlist, config);
ro_gui_save_options();
+
+ return NSERROR_OK;
}
/**
- * Prepare the hotlist menu for opening
+ * Prepare the hotlist menu for display
*
- * \param w The window owning the menu.
- * \param i A wimp icon
- * \param menu The menu about to be opened.
- * \param pointer Pointer to the relevant wimp event block, or
- * NULL for an Adjust click.
- * \return true if the event was handled; else false.
+ * \param w The window owning the menu.
+ * \param i The icon owning the menu.
+ * \param menu The menu from which the selection was made.
+ * \param pointer The pointer shape
+ * \return true if action accepted; else false.
*/
-
-bool ro_gui_hotlist_menu_prepare(wimp_w w, wimp_i i, wimp_menu *menu,
- wimp_pointer *pointer)
+static bool
+hotlist_menu_prepare(wimp_w w, wimp_i i, wimp_menu *menu, wimp_pointer *pointer)
{
bool selection;
+ struct ro_hotlist_window *hotlistw;
+
+ hotlistw = (struct ro_hotlist_window *)ro_gui_wimp_event_get_user_data(w);
- if (menu != hotlist_window.menu)
+ if ((hotlistw == NULL) ||
+ (menu != hotlistw->menu)) {
return false;
+ }
selection = hotlist_has_selection();
- ro_gui_menu_set_entry_shaded(hotlist_window.menu,
- TREE_SELECTION, !selection);
- ro_gui_menu_set_entry_shaded(hotlist_window.menu,
- TREE_CLEAR_SELECTION, !selection);
+ ro_gui_menu_set_entry_shaded(menu, TREE_SELECTION, !selection);
+ ro_gui_menu_set_entry_shaded(menu, TREE_CLEAR_SELECTION, !selection);
ro_gui_save_prepare(GUI_SAVE_HOTLIST_EXPORT_HTML,
- NULL, NULL, NULL, NULL);
+ NULL, NULL, NULL, NULL);
ro_gui_menu_set_entry_shaded(menu, TOOLBAR_BUTTONS,
- ro_toolbar_menu_option_shade(hotlist_window.toolbar));
+ ro_toolbar_menu_option_shade(hotlistw->core.toolbar));
ro_gui_menu_set_entry_ticked(menu, TOOLBAR_BUTTONS,
- ro_toolbar_menu_buttons_tick(hotlist_window.toolbar));
+ ro_toolbar_menu_buttons_tick(hotlistw->core.toolbar));
ro_gui_menu_set_entry_shaded(menu, TOOLBAR_EDIT,
- ro_toolbar_menu_edit_shade(hotlist_window.toolbar));
+ ro_toolbar_menu_edit_shade(hotlistw->core.toolbar));
ro_gui_menu_set_entry_ticked(menu, TOOLBAR_EDIT,
- ro_toolbar_menu_edit_tick(hotlist_window.toolbar));
+ ro_toolbar_menu_edit_tick(hotlistw->core.toolbar));
return true;
}
@@ -366,85 +298,116 @@ bool ro_gui_hotlist_menu_prepare(wimp_w w, wimp_i i, wimp_menu *menu,
/**
* Handle submenu warnings for the hotlist menu
*
- * \param w The window owning the menu.
- * \param i The icon owning the menu.
- * \param *menu The menu to which the warning applies.
- * \param *selection The wimp menu selection data.
- * \param action The selected menu action.
+ * \param w The window owning the menu.
+ * \param i The icon owning the menu.
+ * \param menu The menu to which the warning applies.
+ * \param selection The wimp menu selection data.
+ * \param action The selected menu action.
*/
-
-void ro_gui_hotlist_menu_warning(wimp_w w, wimp_i i, wimp_menu *menu,
- wimp_selection *selection, menu_action action)
+static void
+hotlist_menu_warning(wimp_w w,
+ wimp_i i,
+ wimp_menu *menu,
+ wimp_selection *selection,
+ menu_action action)
{
/* Do nothing */
}
+
/**
* Handle selections from the hotlist menu
*
- * \param w The window owning the menu.
- * \param i The icon owning the menu.
- * \param *menu The menu from which the selection was made.
- * \param *selection The wimp menu selection data.
- * \param action The selected menu action.
- * \return true if action accepted; else false.
+ * \param w The window owning the menu.
+ * \param i The icon owning the menu.
+ * \param menu The menu from which the selection was made.
+ * \param selection The wimp menu selection data.
+ * \param action The selected menu action.
+ * \return true if action accepted; else false.
*/
-
-bool ro_gui_hotlist_menu_select(wimp_w w, wimp_i i, wimp_menu *menu,
- wimp_selection *selection, menu_action action)
+static bool
+hotlist_menu_select(wimp_w w,
+ wimp_i i,
+ wimp_menu *menu,
+ wimp_selection *selection,
+ menu_action action)
{
+ struct ro_hotlist_window *hotlistw;
+
+ hotlistw = (struct ro_hotlist_window *)ro_gui_wimp_event_get_user_data(w);
+
+ if ((hotlistw == NULL) ||
+ (menu != hotlistw->menu)) {
+ return false;
+ }
+
switch (action) {
case HOTLIST_EXPORT:
ro_gui_dialog_open_persistent(w, dialog_saveas, true);
return true;
+
case TREE_NEW_FOLDER:
hotlist_add_folder(NULL, false, 0);
return true;
+
case TREE_NEW_LINK:
hotlist_add_entry(NULL, NULL, false, 0);
return true;
+
case TREE_EXPAND_ALL:
hotlist_expand(false);
return true;
+
case TREE_EXPAND_FOLDERS:
hotlist_expand(true);
return true;
+
case TREE_EXPAND_LINKS:
hotlist_expand(false);
return true;
+
case TREE_COLLAPSE_ALL:
hotlist_contract(true);
return true;
+
case TREE_COLLAPSE_FOLDERS:
hotlist_contract(true);
return true;
+
case TREE_COLLAPSE_LINKS:
hotlist_contract(false);
return true;
+
case TREE_SELECTION_EDIT:
hotlist_edit_selection();
return true;
+
case TREE_SELECTION_LAUNCH:
hotlist_keypress(NS_KEY_CR);
return true;
+
case TREE_SELECTION_DELETE:
hotlist_keypress(NS_KEY_DELETE_LEFT);
ro_toolbar_update_all_hotlists();
return true;
+
case TREE_SELECT_ALL:
hotlist_keypress(NS_KEY_SELECT_ALL);
return true;
+
case TREE_CLEAR_SELECTION:
hotlist_keypress(NS_KEY_CLEAR_SELECTION);
return true;
+
case TOOLBAR_BUTTONS:
- ro_toolbar_set_display_buttons(hotlist_window.toolbar,
- !ro_toolbar_get_display_buttons(
- hotlist_window.toolbar));
+ ro_toolbar_set_display_buttons(hotlistw->core.toolbar,
+ !ro_toolbar_get_display_buttons(hotlistw->core.toolbar));
return true;
+
case TOOLBAR_EDIT:
- ro_toolbar_toggle_edit(hotlist_window.toolbar);
+ ro_toolbar_toggle_edit(hotlistw->core.toolbar);
return true;
+
default:
return false;
}
@@ -452,58 +415,262 @@ bool ro_gui_hotlist_menu_select(wimp_w w, wimp_i i, wimp_menu *menu,
return false;
}
+
/**
- * Check if a particular window handle is the hotlist window
+ * Creates the window for the hotlist tree.
*
- * \param window The window in question
- * \return true if this window is the hotlist
+ * \return NSERROR_OK on success else appropriate error code on faliure.
*/
-bool ro_gui_hotlist_check_window(wimp_w window)
+static nserror ro_hotlist_init(void)
+{
+ struct ro_hotlist_window *ncwin;
+ nserror res;
+ static const struct ns_menu hotlist_menu_def = {
+ "Hotlist", {
+ { "Hotlist", NO_ACTION, 0 },
+ { "Hotlist.New", NO_ACTION, 0 },
+ { "Hotlist.New.Folder", TREE_NEW_FOLDER, 0 },
+ { "Hotlist.New.Link", TREE_NEW_LINK, 0 },
+ { "_Hotlist.Export", HOTLIST_EXPORT, &dialog_saveas },
+ { "Hotlist.Expand", TREE_EXPAND_ALL, 0 },
+ { "Hotlist.Expand.All", TREE_EXPAND_ALL, 0 },
+ { "Hotlist.Expand.Folders", TREE_EXPAND_FOLDERS, 0 },
+ { "Hotlist.Expand.Links", TREE_EXPAND_LINKS, 0 },
+ { "Hotlist.Collapse", TREE_COLLAPSE_ALL, 0 },
+ { "Hotlist.Collapse.All", TREE_COLLAPSE_ALL, 0 },
+ { "Hotlist.Collapse.Folders", TREE_COLLAPSE_FOLDERS, 0 },
+ { "Hotlist.Collapse.Links", TREE_COLLAPSE_LINKS, 0 },
+ { "Hotlist.Toolbars", NO_ACTION, 0 },
+ { "_Hotlist.Toolbars.ToolButtons", TOOLBAR_BUTTONS, 0 },
+ { "Hotlist.Toolbars.EditToolbar", TOOLBAR_EDIT, 0 },
+ { "Selection", TREE_SELECTION, 0 },
+ { "Selection.Edit", TREE_SELECTION_EDIT, 0 },
+ { "Selection.Launch", TREE_SELECTION_LAUNCH, 0 },
+ { "Selection.Delete", TREE_SELECTION_DELETE, 0 },
+ { "SelectAll", TREE_SELECT_ALL, 0 },
+ { "Clear", TREE_CLEAR_SELECTION, 0 },
+ { NULL, 0, 0}
+ }
+ };
+
+ static const struct button_bar_buttons hotlist_toolbar_buttons[] = {
+ { "delete", TOOLBAR_BUTTON_DELETE, TOOLBAR_BUTTON_NONE, '0', "0" },
+ { "expand", TOOLBAR_BUTTON_EXPAND, TOOLBAR_BUTTON_COLLAPSE, '1', "1" },
+ { "open", TOOLBAR_BUTTON_OPEN, TOOLBAR_BUTTON_CLOSE, '2', "2" },
+ { "launch", TOOLBAR_BUTTON_LAUNCH, TOOLBAR_BUTTON_NONE, '3', "3" },
+ { "create", TOOLBAR_BUTTON_CREATE, TOOLBAR_BUTTON_NONE, '4', "4" },
+ { NULL, TOOLBAR_BUTTON_NONE, TOOLBAR_BUTTON_NONE, '\0', "" }
+ };
+
+ if (hotlist_window != NULL) {
+ return NSERROR_OK;
+ }
+
+ ncwin = malloc(sizeof(struct ro_hotlist_window));
+ if (ncwin == NULL) {
+ return NSERROR_NOMEM;
+ }
+
+ /* create window from template */
+ ncwin->core.wh = wimp_create_window(dialog_hotlist_template);
+
+ ro_gui_set_window_title(ncwin->core.wh, messages_get("Hotlist"));
+
+ /* Set up callback handlers */
+ ncwin->core.draw = hotlist_draw;
+ ncwin->core.key = hotlist_key;
+ ncwin->core.mouse = hotlist_mouse;
+ ncwin->core.toolbar_click = hotlist_toolbar_click;
+ ncwin->core.toolbar_save = hotlist_toolbar_save;
+ /* update is not valid untill hotlist manager is initialised */
+ ncwin->core.toolbar_update = NULL;
+
+ /* initialise core window */
+ res = ro_corewindow_init(&ncwin->core,
+ hotlist_toolbar_buttons,
+ nsoption_charp(toolbar_hotlist),
+ THEME_STYLE_HOTLIST_TOOLBAR,
+ "HelpHotToolbar");
+ if (res != NSERROR_OK) {
+ free(ncwin);
+ return res;
+ }
+
+ res = hotlist_init(ncwin->core.cb_table,
+ (struct core_window *)ncwin,
+ nsoption_charp(hotlist_path));
+ if (res != NSERROR_OK) {
+ free(ncwin);
+ return res;
+ }
+
+ /* setup toolbar update post hotlist manager initialisation */
+ ncwin->core.toolbar_update = hotlist_toolbar_update;
+ hotlist_toolbar_update(&ncwin->core);
+
+ /* Build the hotlist window menu. */
+ ncwin->menu = ro_gui_menu_define_menu(&hotlist_menu_def);
+
+ ro_gui_wimp_event_register_menu(ncwin->core.wh,
+ ncwin->menu, false, false);
+ ro_gui_wimp_event_register_menu_prepare(ncwin->core.wh,
+ hotlist_menu_prepare);
+ ro_gui_wimp_event_register_menu_selection(ncwin->core.wh,
+ hotlist_menu_select);
+ ro_gui_wimp_event_register_menu_warning(ncwin->core.wh,
+ hotlist_menu_warning);
+
+ /* memoise window so it can be re-presented when necessary
+ * instead of recreating every time.
+ */
+ hotlist_window = ncwin;
+
+ return NSERROR_OK;
+}
+
+
+/* exported interface documented in riscos/hotlist.h */
+nserror ro_gui_hotlist_present(void)
{
- if (hotlist_window.window == window)
+ nserror res;
+
+ /* deal with external hotlist handler */
+ if (nsoption_bool(external_hotlists) &&
+ (nsoption_charp(external_hotlist_app) != NULL) &&
+ (*nsoption_charp(external_hotlist_app) != '\0')) {
+ char command[2048];
+ os_error *error;
+
+ snprintf(command, sizeof(command), "Filer_Run %s",
+ nsoption_charp(external_hotlist_app));
+ error = xos_cli(command);
+
+ if (error == NULL) {
+ return NSERROR_OK;
+ }
+
+ LOG("xos_cli: 0x%x: %s", error->errnum, error->errmess);
+ ro_warn_user("Failed to launch external hotlist: %s",
+ error->errmess);
+ }
+
+ res = ro_hotlist_init();
+ if (res == NSERROR_OK) {
+ LOG("Presenting");
+ ro_gui_dialog_open_top(hotlist_window->core.wh,
+ hotlist_window->core.toolbar,
+ 600, 800);
+ } else {
+ LOG("Failed presenting code %d", res);
+ }
+
+ return res;
+}
+
+
+/* exported interface documented in riscos/hotlist.h */
+void ro_gui_hotlist_initialise(void)
+{
+ dialog_hotlist_template = ro_gui_dialog_load_template("tree");
+}
+
+
+/* exported interface documented in riscos/hotlist.h */
+nserror ro_gui_hotlist_finalise(void)
+{
+ nserror res;
+
+ if (hotlist_window == NULL) {
+ return NSERROR_OK;
+ }
+
+ res = hotlist_fini(nsoption_charp(hotlist_path));
+ if (res == NSERROR_OK) {
+ res = ro_corewindow_fini(&hotlist_window->core);
+
+ free(hotlist_window);
+ hotlist_window = NULL;
+ }
+
+ return res;
+}
+
+
+/* exported interface documented in riscos/hotlist.h */
+bool ro_gui_hotlist_check_window(wimp_w wh)
+{
+ if ((hotlist_window != NULL) &&
+ (hotlist_window->core.wh == wh)) {
return true;
- else
- return false;
+ }
+ return false;
}
-/**
- * Check if a particular menu handle is the hotlist menu
- *
- * \param *menu The menu in question.
- * \return true if this menu is the hotlist menu
- */
+/* exported interface documented in riscos/hotlist.h */
bool ro_gui_hotlist_check_menu(wimp_menu *menu)
{
- if (hotlist_window.menu == menu)
+ if ((hotlist_window != NULL) &&
+ (hotlist_window->menu == menu)) {
return true;
- else
- return false;
+ }
+ return false;
+}
+
+
+/**
+ * Callback to schedule for the next available Null poll, by which point
+ * a hotlist client will have claimed the Message_HotlistAddURL and any
+ * details in RMA can safely be discarded.
+ *
+ * \param p Unused data pointer.
+ */
+static void ro_gui_hotlist_scheduled_callback(void *p)
+{
+ ro_gui_hotlist_add_cleanup();
}
/**
- * Add a URL to the hotlist. This will be passed on to the core hotlist, then
- * Message_HotlistAddURL will broadcast to any bookmark applications via the
- * Hotlist Protocol.
+ * Handle bounced Message_HotlistAddURL, so that RMA storage can be freed.
*
- * \param *url The URL to be added.
+ * \param message The bounced message content.
*/
+static void ro_gui_hotlist_addurl_bounce(wimp_message *message)
+{
+ if (hotlist_url != NULL) {
+ nsurl *nsurl;
+
+ if (nsurl_create(hotlist_url, &nsurl) != NSERROR_OK)
+ return;
+
+ hotlist_add_url(nsurl);
+ nsurl_unref(nsurl);
+ }
+ ro_gui_hotlist_add_cleanup();
+
+ /* There's no longer any need to listen for the next Null poll. */
+
+ riscos_schedule(-1, ro_gui_hotlist_scheduled_callback, NULL);
+}
+
+
+/* exported interface documented in riscos/hotlist.h */
void ro_gui_hotlist_add_page(nsurl *url)
{
- const struct url_data *data;
- wimp_message message;
- struct ro_hotlist_message_hotlist_addurl *add_url =
- (struct ro_hotlist_message_hotlist_addurl *) &message;
+ const struct url_data *data;
+ wimp_message message;
+ struct ro_hotlist_message_hotlist_addurl *add_url =
+ (struct ro_hotlist_message_hotlist_addurl *) &message;
- if (url == NULL)
+ if (url == NULL) {
return;
+ }
/* If we're not using external hotlists, add the page to NetSurf's
* own hotlist and return...
*/
-
if (!nsoption_bool(external_hotlists)) {
hotlist_add_url(url);
return;
@@ -538,91 +705,89 @@ void ro_gui_hotlist_add_page(nsurl *url)
add_url->title = hotlist_title;
strcpy(add_url->appname, "NetSurf");
- if (!ro_message_send_message(wimp_USER_MESSAGE_RECORDED, &message, 0,
- ro_gui_hotlist_addurl_bounce))
+ if (!ro_message_send_message(wimp_USER_MESSAGE_RECORDED,
+ &message,
+ 0,
+ ro_gui_hotlist_addurl_bounce)) {
ro_gui_hotlist_add_cleanup();
+ }
/* Listen for the next Null poll, as an indication that the
* message didn't bounce.
*/
-
riscos_schedule(0, ro_gui_hotlist_scheduled_callback, NULL);
}
-/**
- * Handle bounced Message_HotlistAddURL, so that RMA storage can be freed.
- *
- * \param *message The bounced message content.
- */
-
-static void ro_gui_hotlist_addurl_bounce(wimp_message *message)
+/* exported interface documented in riscos/hotlist.h */
+void ro_gui_hotlist_add_cleanup(void)
{
if (hotlist_url != NULL) {
- nsurl *nsurl;
-
- if (nsurl_create(hotlist_url, &nsurl) != NSERROR_OK)
- return;
-
- hotlist_add_url(nsurl);
- nsurl_unref(nsurl);
+ osmodule_free(hotlist_url);
+ hotlist_url = NULL;
}
- ro_gui_hotlist_add_cleanup();
-
- /* There's no longer any need to listen for the next Null poll. */
-
- riscos_schedule(-1, ro_gui_hotlist_scheduled_callback, NULL);
+ if (hotlist_title != NULL) {
+ osmodule_free(hotlist_title);
+ hotlist_title = NULL;
+ }
}
/**
- * Callback to schedule for the next available Null poll, by which point
- * a hotlist client will have claimed the Message_HotlistAddURL and any
- * details in RMA can safely be discarded.
+ * Callback confirming a URL delete query.
*
- * \param *p Unused data pointer.
+ * \param id The ID of the query calling us.
+ * \param res The user's response to the query.
+ * \param p Callback data (always NULL).
*/
-
-static void ro_gui_hotlist_scheduled_callback(void *p)
+static void
+ro_gui_hotlist_remove_confirmed(query_id id, enum query_response res, void *p)
{
- ro_gui_hotlist_add_cleanup();
+ hotlist_remove_url(hotlist_delete_url);
+ ro_toolbar_update_all_hotlists();
+
+ nsurl_unref(hotlist_delete_url);
+ hotlist_delete_url = NULL;
+ hotlist_query = QUERY_INVALID;
}
/**
- * Clean up RMA storage used by the Message_HotlistAddURL protocol.
+ * Callback cancelling a URL delete query.
+ *
+ * \param id The ID of the query calling us.
+ * \param res The user's response to the query.
+ * \param p Callback data (always NULL).
*/
-
-void ro_gui_hotlist_add_cleanup(void)
+static void
+ro_gui_hotlist_remove_cancelled(query_id id, enum query_response res, void *p)
{
- if (hotlist_url != NULL) {
- osmodule_free(hotlist_url);
- hotlist_url = NULL;
- }
-
- if (hotlist_title != NULL) {
- osmodule_free(hotlist_title);
- hotlist_title = NULL;
- }
+ nsurl_unref(hotlist_delete_url);
+ hotlist_delete_url = NULL;
+ hotlist_query = QUERY_INVALID;
}
/**
- * Remove a URL from the hotlist. This will be passed on to the core hotlist,
- * unless we're configured to use external hotlists in which case we ignore it.
- *
- * \param *url The URL to be removed.
+ * removal query dialog callbacks.
*/
+static const query_callback remove_funcs = {
+ ro_gui_hotlist_remove_confirmed,
+ ro_gui_hotlist_remove_cancelled
+};
+
+/* exported interface documented in riscos/hotlist.h */
void ro_gui_hotlist_remove_page(nsurl *url)
{
- if (url == NULL || nsoption_bool(external_hotlists) ||
- !hotlist_has_url(url))
+ if ((url == NULL) ||
+ nsoption_bool(external_hotlists) ||
+ !hotlist_has_url(url)) {
return;
+ }
/* Clean up any existing delete attempts before continuing. */
-
if (hotlist_query != QUERY_INVALID) {
query_close(hotlist_query);
hotlist_query = QUERY_INVALID;
@@ -636,12 +801,11 @@ void ro_gui_hotlist_remove_page(nsurl *url)
/* Check with the user before removing the URL, unless they don't
* want us to be careful in which case just do it.
*/
-
if (nsoption_bool(confirm_hotlist_remove)) {
hotlist_query = query_user("RemoveHotlist", NULL,
- &remove_funcs, NULL,
- messages_get("Remove"),
- messages_get("DontRemove"));
+ &remove_funcs, NULL,
+ messages_get("Remove"),
+ messages_get("DontRemove"));
hotlist_delete_url = nsurl_ref(url);
} else {
@@ -651,88 +815,13 @@ void ro_gui_hotlist_remove_page(nsurl *url)
}
-/**
- * Callback confirming a URL delete query.
- *
- * \param id The ID of the query calling us.
- * \param res The user's response to the query.
- * \param *p Callback data (always NULL).
- */
-
-static void ro_gui_hotlist_remove_confirmed(query_id id,
- enum query_response res, void *p)
-{
- hotlist_remove_url(hotlist_delete_url);
- ro_toolbar_update_all_hotlists();
-
- nsurl_unref(hotlist_delete_url);
- hotlist_delete_url = NULL;
- hotlist_query = QUERY_INVALID;
-}
-
-
-/**
- * Callback cancelling a URL delete query.
- *
- * \param id The ID of the query calling us.
- * \param res The user's response to the query.
- * \param *p Callback data (always NULL).
- */
-
-static void ro_gui_hotlist_remove_cancelled(query_id id,
- enum query_response res, void *p)
-{
- nsurl_unref(hotlist_delete_url);
- hotlist_delete_url = NULL;
- hotlist_query = QUERY_INVALID;
-}
-
-
-/**
- * Report whether the hotlist contains a given URL. This will be passed on to
- * the core hotlist, unless we're configured to use an external hotlist in which
- * case we always report false.
- *
- * \param *url The URL to be tested.
- * \return true if the hotlist contains the URL; else false.
- */
-
+/* exported interface documented in riscos/hotlist.h */
bool ro_gui_hotlist_has_page(nsurl *url)
{
- if (url == NULL || nsoption_bool(external_hotlists))
+ if ((url == NULL) ||
+ nsoption_bool(external_hotlists)) {
return false;
+ }
return hotlist_has_url(url);
}
-
-
-#if 0
-/**
- * Handle URL dropped on hotlist
- *
- * \param message the wimp message we're acting on
- * \param url the URL to add
- */
-void ro_gui_hotlist_url_drop(wimp_message *message, const char *url)
-{
- int x, y;
- nsurl *nsurl;
-
- if (hotlist_window.window != message->data.data_xfer.w)
- return;
-
- if (url == NULL)
- return;
-
- if (nsurl_create(url, &nsurl) != NSERROR_OK)
- return;
-
- ro_gui_tree_get_tree_coordinates(hotlist_window.tree,
- message->data.data_xfer.pos.x,
- message->data.data_xfer.pos.y,
- &x, &y);
-
- hotlist_add_entry(nsurl, NULL, true, y);
- nsurl_unref(nsurl);
-}
-#endif
diff --git a/frontends/riscos/hotlist.h b/frontends/riscos/hotlist.h
index 0b87a2e96..14a661e88 100644
--- a/frontends/riscos/hotlist.h
+++ b/frontends/riscos/hotlist.h
@@ -34,20 +34,65 @@
#define message_HOTLIST_CHANGED 0x4af82
#endif
-#include "riscos/menus.h"
-
struct nsurl;
-void ro_gui_hotlist_preinitialise(void);
-void ro_gui_hotlist_postinitialise(void);
-void ro_gui_hotlist_destroy(void);
-void ro_gui_hotlist_open(void);
-void ro_gui_hotlist_save(void);
+/**
+ * initialise the hotlist window template ready for subsequent use.
+ */
+void ro_gui_hotlist_initialise(void);
+
+/**
+ * make the cookie window visible.
+ *
+ * \return NSERROR_OK on success else appropriate error code on faliure.
+ */
+nserror ro_gui_hotlist_present(void);
+
+/**
+ * Free any resources allocated for the cookie window.
+ *
+ * \return NSERROR_OK on success else appropriate error code on faliure.
+ */
+nserror ro_gui_hotlist_finalise(void);
+
bool ro_gui_hotlist_check_window(wimp_w window);
bool ro_gui_hotlist_check_menu(wimp_menu *menu);
+
+/**
+ * Add a URL to the hotlist.
+ *
+ * This will be passed on to the core hotlist, then
+ * Message_HotlistAddURL will broadcast to any bookmark applications
+ * via the Hotlist Protocol.
+ *
+ * \param *url The URL to be added.
+ */
void ro_gui_hotlist_add_page(struct nsurl *url);
+
+/**
+ * Clean up RMA storage used by the Message_HotlistAddURL protocol.
+ */
void ro_gui_hotlist_add_cleanup(void);
+
+/**
+ * Remove a URL from the hotlist.
+ *
+ * This will be passed on to the core hotlist, unless we're configured
+ * to use external hotlists in which case we ignore it.
+ *
+ * \param *url The URL to be removed.
+ */
void ro_gui_hotlist_remove_page(struct nsurl *url);
+
+/**
+ * Report whether the hotlist contains a given URL.
+ *
+ * This will be passed on to the core hotlist, unless we're configured
+ * to use an external hotlist in which case we always report false.
+ *
+ * \param url The URL to be tested.
+ * \return true if the hotlist contains the URL; else false.
+ */
bool ro_gui_hotlist_has_page(struct nsurl *url);
#endif
diff --git a/frontends/riscos/iconbar.c b/frontends/riscos/iconbar.c
index 8582a4539..3430ed2f0 100644
--- a/frontends/riscos/iconbar.c
+++ b/frontends/riscos/iconbar.c
@@ -150,8 +150,9 @@ bool ro_gui_iconbar_click(wimp_pointer *pointer)
case wimp_CLICK_ADJUST:
xosbyte1(osbyte_SCAN_KEYBOARD, 0 ^ 0x80, 0, &key_down);
- if (key_down == 0)
- ro_gui_hotlist_open();
+ if (key_down == 0) {
+ ro_gui_hotlist_present();
+ }
break;
}
@@ -224,13 +225,13 @@ bool ro_gui_iconbar_menu_select(wimp_w w, wimp_i i, wimp_menu *menu,
ro_gui_dialog_open_persistent(NULL, dialog_openurl, true);
return true;
case HOTLIST_SHOW:
- ro_gui_hotlist_open();
+ ro_gui_hotlist_present();
return true;
case HISTORY_SHOW_GLOBAL:
- ro_gui_global_history_open();
+ ro_gui_global_history_present();
return true;
case COOKIES_SHOW:
- ro_gui_cookies_open();
+ ro_gui_cookies_present();
return true;
case CHOICES_SHOW:
ro_gui_configure_show();
diff --git a/frontends/riscos/menus.c b/frontends/riscos/menus.c
index c123a0fce..d46afa28e 100644
--- a/frontends/riscos/menus.c
+++ b/frontends/riscos/menus.c
@@ -51,7 +51,6 @@
#include "riscos/save.h"
#include "riscos/tinct.h"
#include "riscos/toolbar.h"
-#include "riscos/treeview.h"
#include "riscos/url_suggest.h"
#include "riscos/wimp.h"
#include "riscos/wimp_event.h"
diff --git a/frontends/riscos/sslcert.c b/frontends/riscos/sslcert.c
index 8a8ddfb5b..85b84456e 100644
--- a/frontends/riscos/sslcert.c
+++ b/frontends/riscos/sslcert.c
@@ -1,6 +1,6 @@
/*
* Copyright 2006 John M Bell <jmb202@ecs.soton.ac.uk>
- * Copyright 2010 Stephen Fryatt <stevef@netsurf-browser.org>
+ * Copyright 2016 Vincent Sanders <vince@netsurf-browser.org>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
@@ -17,329 +17,399 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-/** \file
- * SSL Certificate verification UI (implementation)
+/**
+ * \file
+ * Implementation of RISC OS certificate verification UI.
*/
-#include "utils/config.h"
-
-#include <assert.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <string.h>
-#include "oslib/wimp.h"
+#include <oslib/wimp.h>
#include "utils/log.h"
+#include "netsurf/plotters.h"
#include "desktop/sslcert_viewer.h"
-#include "desktop/tree.h"
#include "riscos/dialog.h"
-#include "riscos/sslcert.h"
-#include "riscos/textarea.h"
-#include "riscos/treeview.h"
#include "riscos/wimp.h"
#include "riscos/wimp_event.h"
#include "riscos/wimputils.h"
#include "riscos/gui.h"
+#include "riscos/toolbar.h"
+#include "riscos/corewindow.h"
+#include "riscos/sslcert.h"
+/* widget ID */
#define ICON_SSL_PANE 1
#define ICON_SSL_REJECT 3
#define ICON_SSL_ACCEPT 4
-static wimp_window *ro_gui_cert_dialog_template;
-static wimp_window *ro_gui_cert_tree_template;
+/**
+ * RISC OS certificate viewer context.
+ */
+struct ro_cert_window {
+ struct ro_corewindow core;
+
+ /** certificate view window handle */
+ wimp_w wh;
+
+ /** SSL certificate viewer context data */
+ struct sslcert_session_data *ssl_data;
-struct ro_sslcert
-{
- wimp_w window;
- wimp_w pane;
- ro_treeview *tv;
- struct sslcert_session_data *data;
};
-static void ro_gui_cert_accept(wimp_pointer *pointer);
-static void ro_gui_cert_reject(wimp_pointer *pointer);
-static void ro_gui_cert_close_window(wimp_w w);
-static void ro_gui_cert_release_window(struct ro_sslcert *s);
+/** riscos dialog template for certificate viewer window. */
+static wimp_window *dialog_cert_template;
+
+/** riscos template for certificate tree pane. */
+static wimp_window *cert_tree_template;
+
/**
- * Load and initialise the certificate window template
+ * Handle closing of the RISC OS certificate verification dialog
+ *
+ * Deleting wimp windows, freeing up the core window and ssl data block.
+ *
+ * \param certw The context associated with the dialogue.
*/
-
-void ro_gui_cert_preinitialise(void)
+static void ro_gui_cert_release_window(struct ro_cert_window *certw)
{
- /* Load templates for the SSL windows and adjust the tree window
- * flags to suit.
- */
+ os_error *error;
+
+ ro_gui_wimp_event_finalise(certw->wh);
+
+ sslcert_viewer_fini(certw->ssl_data);
- ro_gui_cert_dialog_template = ro_gui_dialog_load_template("sslcert");
- ro_gui_cert_tree_template = ro_gui_dialog_load_template("tree");
+ ro_corewindow_fini(&certw->core);
+
+ error = xwimp_delete_window(certw->wh);
+ if (error) {
+ LOG("xwimp_delete_window: 0x%x:%s",
+ error->errnum, error->errmess);
+ }
- ro_gui_cert_tree_template->flags &= ~(wimp_WINDOW_MOVEABLE |
- wimp_WINDOW_BACK_ICON |
- wimp_WINDOW_CLOSE_ICON |
- wimp_WINDOW_TITLE_ICON |
- wimp_WINDOW_SIZE_ICON |
- wimp_WINDOW_TOGGLE_ICON);
+ error = xwimp_delete_window(certw->core.wh);
+ if (error) {
+ LOG("xwimp_delete_window: 0x%x:%s",
+ error->errnum, error->errmess);
+ }
+
+ free(certw);
}
/**
- * Load and initialise the certificate window template
+ * Handle acceptance of certificate via event callback.
+ *
+ * \param pointer The wimp pointer event.
*/
-
-void ro_gui_cert_postinitialise(void)
+static void ro_gui_cert_accept(wimp_pointer *pointer)
{
- /* Initialise the SSL module. */
+ struct ro_cert_window *certw;
+ certw = (struct ro_cert_window *)ro_gui_wimp_event_get_user_data(pointer->w);
+
+ sslcert_viewer_accept(certw->ssl_data);
+ ro_gui_dialog_close(certw->wh);
+ ro_gui_cert_release_window(certw);
}
+
/**
- * Prompt the user to verify a certificate with issuse.
+ * Handle rejection of certificate via event callback.
*
- * \param url The URL being verified.
- * \param certs The certificate to be verified
- * \param num The number of certificates to be verified.
- * \param cb Callback upon user decision.
- * \param cbpw Context pointer passed to cb
+ * \param pointer The wimp pointer block.
*/
-nserror gui_cert_verify(nsurl *url,
- const struct ssl_cert_info *certs, unsigned long num,
- nserror (*cb)(bool proceed, void *pw), void *cbpw)
+static void ro_gui_cert_reject(wimp_pointer *pointer)
{
- struct ro_sslcert *sslcert_window;
- wimp_window_state state;
- wimp_icon_state istate;
- wimp_window_info info;
- os_error *error;
- bool set_extent;
-
- assert(certs);
-
- sslcert_window = malloc(sizeof(struct ro_sslcert));
- if (sslcert_window == NULL) {
- LOG("Failed to allocate memory for SSL Cert Dialog");
- return NSERROR_NOMEM;
- }
+ struct ro_cert_window *certw;
+ certw = (struct ro_cert_window *)ro_gui_wimp_event_get_user_data(pointer->w);
- /* Create the SSL window and its pane. */
+ sslcert_viewer_reject(certw->ssl_data);
+ ro_gui_dialog_close(certw->wh);
+ ro_gui_cert_release_window(certw);
+}
- error = xwimp_create_window(ro_gui_cert_dialog_template,
- &(sslcert_window->window));
- if (error) {
- LOG("xwimp_create_window: 0x%x: %s", error->errnum, error->errmess);
- free(sslcert_window);
- return NSERROR_INIT_FAILED;
- }
- error = xwimp_create_window(ro_gui_cert_tree_template,
- &(sslcert_window->pane));
- if (error) {
- LOG("xwimp_create_window: 0x%x: %s", error->errnum, error->errmess);
- free(sslcert_window);
- return NSERROR_INIT_FAILED;
- }
+/**
+ * Callback to handle the closure of the SSL dialogue by other means.
+ *
+ * \param w The window handle being closed.
+ */
+static void ro_gui_cert_close_window(wimp_w w)
+{
+ struct ro_cert_window *certw;
+ certw = (struct ro_cert_window *)ro_gui_wimp_event_get_user_data(w);
- /* Create the SSL data and build a tree from it. */
- sslcert_viewer_create_session_data(num, url,
- cb, cbpw, certs, &sslcert_window->data);
- ssl_current_session = sslcert_window->data;
+ ro_gui_cert_release_window(certw);
+}
- sslcert_window->tv = ro_treeview_create(sslcert_window->pane,
- NULL, NULL, TREE_SSLCERT);
- if (sslcert_window->tv == NULL) {
- LOG("Failed to allocate treeview");
- free(sslcert_window);
- return NSERROR_NOMEM;
- }
- /* Set up the certificate window event handling.
- *
- * (The action buttons are registered as button events, not OK and
- * Cancel, as both need to carry out actions.)
- */
-
- ro_gui_wimp_event_set_user_data(sslcert_window->window, sslcert_window);
- ro_gui_wimp_event_register_close_window(sslcert_window->window,
- ro_gui_cert_close_window);
- ro_gui_wimp_event_register_button(sslcert_window->window,
- ICON_SSL_REJECT, ro_gui_cert_reject);
- ro_gui_wimp_event_register_button(sslcert_window->window,
- ICON_SSL_ACCEPT, ro_gui_cert_accept);
-
- ro_gui_dialog_open_persistent(NULL, sslcert_window->window, false);
-
- /* Nest the tree window inside the pane window. To do this, we:
- * - Get the current pane extent,
- * - Get the parent window position and the location of the pane-
- * locating icon inside it,
- * - Set the visible area of the pane to suit,
- * - Check that the pane extents are OK for this visible area, and
- * increase them if necessary,
- * - Before finally opening the pane as a nested part of the parent.
- */
+/**
+ * Attach tree window as a pane to ssl window.
+ *
+ * Nest the tree window inside the pane window. To do this, we:
+ * - Get the current pane extent,
+ * - Get the parent window position and the location of the pane-
+ * locating icon inside it,
+ * - Set the visible area of the pane to suit,
+ * - Check that the pane extents are OK for this visible area, and
+ * increase them if necessary,
+ * - Before finally opening the pane as a nested part of the parent.
+ *
+ */
+static nserror cert_attach_pane(wimp_w parent, wimp_w pane)
+{
+ os_error *error;
+ wimp_window_state wstate;
+ wimp_window_info winfo;
+ wimp_icon_state istate;
+ bool set_extent;
- info.w = sslcert_window->pane;
- error = xwimp_get_window_info_header_only(&info);
+ winfo.w = pane;
+ error = xwimp_get_window_info_header_only(&winfo);
if (error) {
- ro_gui_cert_release_window(sslcert_window);
- LOG("xwimp_get_window_info: 0x%x: %s", error->errnum, error->errmess);
+ LOG("xwimp_get_window_info: 0x%x: %s",
+ error->errnum, error->errmess);
return NSERROR_INIT_FAILED;
}
- state.w = sslcert_window->window;
- error = xwimp_get_window_state(&state);
+ wstate.w = parent;
+ error = xwimp_get_window_state(&wstate);
if (error) {
- ro_gui_cert_release_window(sslcert_window);
- LOG("xwimp_get_window_state: 0x%x: %s", error->errnum, error->errmess);
+ LOG("xwimp_get_window_state: 0x%x: %s",
+ error->errnum, error->errmess);
return NSERROR_INIT_FAILED;
}
- istate.w = sslcert_window->window;
+ istate.w = parent;
istate.i = ICON_SSL_PANE;
error = xwimp_get_icon_state(&istate);
if (error) {
- ro_gui_cert_release_window(sslcert_window);
- LOG("xwimp_get_icon_state: 0x%x: %s", error->errnum, error->errmess);
+ LOG("xwimp_get_icon_state: 0x%x: %s",
+ error->errnum, error->errmess);
return NSERROR_INIT_FAILED;
}
- state.w = sslcert_window->pane;
- state.visible.x1 = state.visible.x0 + istate.icon.extent.x1 - 20 -
- ro_get_vscroll_width(sslcert_window->pane);
- state.visible.x0 += istate.icon.extent.x0 + 20;
- state.visible.y0 = state.visible.y1 + istate.icon.extent.y0 + 20 +
- ro_get_hscroll_height(sslcert_window->pane);
- state.visible.y1 += istate.icon.extent.y1 - 32;
+ wstate.w = pane;
+ wstate.visible.x1 = wstate.visible.x0 + istate.icon.extent.x1 - 20 - ro_get_vscroll_width(pane);
+ wstate.visible.x0 += istate.icon.extent.x0 + 20;
+ wstate.visible.y0 = wstate.visible.y1 + istate.icon.extent.y0 + 20 + ro_get_hscroll_height(pane);
+ wstate.visible.y1 += istate.icon.extent.y1 - 32;
set_extent = false;
- if ((info.extent.x1 - info.extent.x0) <
- (state.visible.x1 - state.visible.x0)) {
- info.extent.x0 = 0;
- info.extent.x1 = state.visible.x1 - state.visible.x0;
+ if ((winfo.extent.x1 - winfo.extent.x0) <
+ (wstate.visible.x1 - wstate.visible.x0)) {
+ winfo.extent.x0 = 0;
+ winfo.extent.x1 = wstate.visible.x1 - wstate.visible.x0;
set_extent = true;
}
- if ((info.extent.y1 - info.extent.y0) <
- (state.visible.y1 - state.visible.y0)) {
- info.extent.y1 = 0;
- info.extent.x1 = state.visible.y0 - state.visible.y1;
+ if ((winfo.extent.y1 - winfo.extent.y0) <
+ (wstate.visible.y1 - wstate.visible.y0)) {
+ winfo.extent.y1 = 0;
+ winfo.extent.x1 = wstate.visible.y0 - wstate.visible.y1;
set_extent = true;
}
if (set_extent) {
- error = xwimp_set_extent(sslcert_window->pane, &(info.extent));
+ error = xwimp_set_extent(pane, &(winfo.extent));
if (error) {
- ro_gui_cert_release_window(sslcert_window);
- LOG("xwimp_set_extent: 0x%x: %s", error->errnum, error->errmess);
+ LOG("xwimp_set_extent: 0x%x: %s",
+ error->errnum, error->errmess);
return NSERROR_INIT_FAILED;
}
}
- error = xwimp_open_window_nested(PTR_WIMP_OPEN(&state),
- sslcert_window->window,
- wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT
- << wimp_CHILD_XORIGIN_SHIFT |
- wimp_CHILD_LINKS_PARENT_VISIBLE_TOP_OR_RIGHT
- << wimp_CHILD_YORIGIN_SHIFT |
- wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT
- << wimp_CHILD_LS_EDGE_SHIFT |
- wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT
- << wimp_CHILD_RS_EDGE_SHIFT);
+ error = xwimp_open_window_nested(
+ PTR_WIMP_OPEN(&wstate),
+ parent,
+ wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT << wimp_CHILD_XORIGIN_SHIFT |
+ wimp_CHILD_LINKS_PARENT_VISIBLE_TOP_OR_RIGHT << wimp_CHILD_YORIGIN_SHIFT |
+ wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT << wimp_CHILD_LS_EDGE_SHIFT |
+ wimp_CHILD_LINKS_PARENT_VISIBLE_BOTTOM_OR_LEFT << wimp_CHILD_RS_EDGE_SHIFT);
if (error) {
- ro_gui_cert_release_window(sslcert_window);
- LOG("xwimp_open_window_nested: 0x%x: %s", error->errnum, error->errmess);
- ro_gui_cert_release_window(sslcert_window);
+ LOG("xwimp_open_window_nested: 0x%x: %s",
+ error->errnum, error->errmess);
return NSERROR_INIT_FAILED;
}
- ro_treeview_set_origin(sslcert_window->tv, 0, 0);
-
return NSERROR_OK;
}
+
/**
- * Handle acceptance of certificate via event callback.
+ * Callback to draw on drawable area of ro certificate viewer window.
*
- * \param *pointer The wimp pointer block.
+ * \param ro_cw The riscos core window structure.
+ * \param originx The risc os plotter x origin.
+ * \param originy The risc os plotter y origin.
+ * \param r The rectangle of the window that needs updating.
+ * \return NSERROR_OK on success otherwise apropriate error code
*/
-
-void ro_gui_cert_accept(wimp_pointer *pointer)
+static nserror
+cert_draw(struct ro_corewindow *ro_cw, int originx, int originy, struct rect *r)
{
- struct ro_sslcert *s;
+ struct ro_cert_window *certw;
+ struct redraw_context ctx = {
+ .interactive = true,
+ .background_images = true,
+ .plot = &ro_plotters
+ };
- s = (struct ro_sslcert *) ro_gui_wimp_event_get_user_data(pointer->w);
+ certw = (struct ro_cert_window *)ro_cw;
- if (s != NULL) {
- sslcert_viewer_accept(s->data);
- ro_gui_dialog_close(s->window);
- ro_gui_cert_release_window(s);
- }
+ ro_plot_origin_x = originx;
+ ro_plot_origin_y = originy;
+ no_font_blending = true;
+ sslcert_viewer_redraw(certw->ssl_data, 0, 0, r, &ctx);
+ no_font_blending = false;
+
+ return NSERROR_OK;
}
+
/**
- * Handle rejection of certificate via event callback.
+ * callback for keypress on ro certificate viewer window
*
- * \param pointer The wimp pointer block.
+ * \param ro_cw The ro core window structure.
+ * \param nskey The netsurf key code.
+ * \return NSERROR_OK if key processed,
+ * NSERROR_NOT_IMPLEMENTED if key not processed
+ * otherwise apropriate error code
*/
-
-void ro_gui_cert_reject(wimp_pointer *pointer)
+static nserror cert_key(struct ro_corewindow *ro_cw, uint32_t nskey)
{
- struct ro_sslcert *s;
+ struct ro_cert_window *certw;
+ certw = (struct ro_cert_window *)ro_cw;
- s = (struct ro_sslcert *) ro_gui_wimp_event_get_user_data(pointer->w);
-
- if (s != NULL) {
- sslcert_viewer_reject(s->data);
- ro_gui_dialog_close(s->window);
- ro_gui_cert_release_window(s);
+ if (sslcert_viewer_keypress(certw->ssl_data, nskey)) {
+ return NSERROR_OK;
}
+ return NSERROR_NOT_IMPLEMENTED;
}
+
/**
- * Callback to handle the closure of the SSL dialogue by other means.
+ * callback for mouse event on ro certificate viewer window
*
- * \param w The window being closed.
+ * \param ro_cw The ro core window structure.
+ * \param mouse_state mouse state
+ * \param x location of event
+ * \param y location of event
+ * \return NSERROR_OK on sucess otherwise apropriate error code.
*/
-
-static void ro_gui_cert_close_window(wimp_w w)
+static nserror
+cert_mouse(struct ro_corewindow *ro_cw,
+ browser_mouse_state mouse_state,
+ int x, int y)
{
- struct ro_sslcert *s;
+ struct ro_cert_window *certw;
+ certw = (struct ro_cert_window *)ro_cw;
- s = (struct ro_sslcert *) ro_gui_wimp_event_get_user_data(w);
+ sslcert_viewer_mouse_action(certw->ssl_data, mouse_state, x, y);
- if (s != NULL)
- ro_gui_cert_release_window(s);
+ return NSERROR_OK;
}
-/**
- * Handle closing of the RISC OS certificate verification dialog, deleting
- * the windows and freeing up the treeview and data block.
- *
- * \param *s The data block associated with the dialogue.
- */
-
-void ro_gui_cert_release_window(struct ro_sslcert *s)
+/* exported interface documented in riscos/sslcert.h */
+nserror
+gui_cert_verify(nsurl *url,
+ const struct ssl_cert_info *certs,
+ unsigned long num,
+ nserror (*cb)(bool proceed, void *pw),
+ void *cbpw)
{
os_error *error;
+ struct ro_cert_window *ncwin; /* new certificate window */
+ nserror res;
- if (s == NULL)
- return;
-
- LOG("Releasing SSL data: 0x%x", (unsigned)s);
+ ncwin = malloc(sizeof(struct ro_cert_window));
+ if (ncwin == NULL) {
+ return NSERROR_NOMEM;
+ }
- ro_gui_wimp_event_finalise(s->window);
- ro_treeview_destroy(s->tv);
+ /* initialise certificate viewing interface */
+ res = sslcert_viewer_create_session_data(num, url, cb, cbpw, certs,
+ &ncwin->ssl_data);
+ if (res != NSERROR_OK) {
+ free(ncwin);
+ return res;
+ }
- error = xwimp_delete_window(s->window);
+ /* Create the SSL window */
+ error = xwimp_create_window(dialog_cert_template, &ncwin->wh);
if (error) {
- LOG("xwimp_delete_window: 0x%x:%s", error->errnum, error->errmess);
- ro_warn_user("WimpError", error->errmess);
+ LOG("xwimp_create_window: 0x%x: %s",
+ error->errnum, error->errmess);
+ free(ncwin);
+ return NSERROR_INIT_FAILED;
}
- error = xwimp_delete_window(s->pane);
+
+ /* create ssl viewer pane window */
+ error = xwimp_create_window(cert_tree_template, &ncwin->core.wh);
if (error) {
- LOG("xwimp_delete_window: 0x%x:%s", error->errnum, error->errmess);
- ro_warn_user("WimpError", error->errmess);
+ LOG("xwimp_create_window: 0x%x: %s",
+ error->errnum, error->errmess);
+ free(ncwin);
+ return NSERROR_INIT_FAILED;
+ }
+
+ /* setup callbacks */
+ ncwin->core.draw = cert_draw;
+ ncwin->core.key = cert_key;
+ ncwin->core.mouse = cert_mouse;
+
+ /* initialise core window */
+ res = ro_corewindow_init(&ncwin->core, NULL, NULL, 0, NULL);
+ if (res != NSERROR_OK) {
+ free(ncwin);
+ return res;
+ }
+
+ res = sslcert_viewer_init(ncwin->core.cb_table,
+ (struct core_window *)ncwin,
+ ncwin->ssl_data);
+ if (res != NSERROR_OK) {
+ free(ncwin);
+ return res;
}
- free(s);
+ /* Set up the certificate window event handling.
+ *
+ * (The action buttons are registered as button events, not OK and
+ * Cancel, as both need to carry out actions.)
+ */
+ ro_gui_wimp_event_set_user_data(ncwin->wh, ncwin);
+ ro_gui_wimp_event_register_close_window(ncwin->wh,
+ ro_gui_cert_close_window);
+ ro_gui_wimp_event_register_button(ncwin->wh,
+ ICON_SSL_REJECT,
+ ro_gui_cert_reject);
+ ro_gui_wimp_event_register_button(ncwin->wh,
+ ICON_SSL_ACCEPT,
+ ro_gui_cert_accept);
+
+ ro_gui_dialog_open_persistent(NULL, ncwin->wh, false);
+
+ res = cert_attach_pane(ncwin->wh, ncwin->core.wh);
+ if (res != NSERROR_OK) {
+ ro_gui_cert_release_window(ncwin);
+ }
+
+ return res;
}
+
+/* exported interface documented in riscos/sslcert.h */
+void ro_gui_cert_initialise(void)
+{
+ /* Load template for the SSL certificate window */
+ dialog_cert_template = ro_gui_dialog_load_template("sslcert");
+
+ /* load template for ssl treeview pane and adjust the window flags. */
+ cert_tree_template = ro_gui_dialog_load_template("tree");
+
+ cert_tree_template->flags &= ~(wimp_WINDOW_MOVEABLE |
+ wimp_WINDOW_BACK_ICON |
+ wimp_WINDOW_CLOSE_ICON |
+ wimp_WINDOW_TITLE_ICON |
+ wimp_WINDOW_SIZE_ICON |
+ wimp_WINDOW_TOGGLE_ICON);
+}
diff --git a/frontends/riscos/sslcert.h b/frontends/riscos/sslcert.h
index 514b5190c..09607f04c 100644
--- a/frontends/riscos/sslcert.h
+++ b/frontends/riscos/sslcert.h
@@ -17,17 +17,31 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-/** \file
- * SSL certificate viewer (interface).
+/**
+ * \file
+ * RISC OS SSL certificate viewer interface.
*/
-#ifndef _NETSURF_RISCOS_SSLCERT_H_
-#define _NETSURF_RISCOS_SSLCERT_H_
+#ifndef NETSURF_RISCOS_SSLCERT_H
+#define NETSURF_RISCOS_SSLCERT_H
struct node;
-void ro_gui_cert_preinitialise(void);
-void ro_gui_cert_postinitialise(void);
+/**
+ * Load and initialise the certificate window template.
+ */
+void ro_gui_cert_initialise(void);
+
+/**
+ * Prompt the user to verify a certificate with issuse.
+ *
+ * \param url The URL being verified.
+ * \param certs The certificate to be verified
+ * \param num The number of certificates to be verified.
+ * \param cb Callback upon user decision.
+ * \param cbpw Context pointer passed to cb
+ */
+nserror gui_cert_verify(struct nsurl *url, const struct ssl_cert_info *certs, unsigned long num, nserror (*cb)(bool proceed, void *pw), void *cbpw);
#endif
diff --git a/frontends/riscos/theme.c b/frontends/riscos/theme.c
index 6e56fbca0..b0b4ab879 100644
--- a/frontends/riscos/theme.c
+++ b/frontends/riscos/theme.c
@@ -47,7 +47,7 @@
#include "riscos/hotlist.h"
#include "riscos/menus.h"
#include "riscos/theme.h"
-#include "riscos/treeview.h"
+#include "riscos/toolbar.h"
#include "riscos/wimp.h"
#include "riscos/wimp_event.h"
#include "riscos/wimputils.h"
diff --git a/frontends/riscos/toolbar.c b/frontends/riscos/toolbar.c
index 23f64ad66..2b5cb3415 100644
--- a/frontends/riscos/toolbar.c
+++ b/frontends/riscos/toolbar.c
@@ -53,7 +53,6 @@
#include "riscos/save.h"
#include "riscos/theme.h"
#include "riscos/toolbar.h"
-#include "riscos/treeview.h"
#include "riscos/url_complete.h"
#include "riscos/wimp.h"
#include "riscos/wimp_event.h"
diff --git a/frontends/riscos/treeview.c b/frontends/riscos/treeview.c
deleted file mode 100644
index 17981466f..000000000
--- a/frontends/riscos/treeview.c
+++ /dev/null
@@ -1,1277 +0,0 @@
-/*
- * Copyright 2005 Richard Wilson <info@tinct.net>
- * Copyright 2010 Stephen Fryatt <stevef@netsurf-browser.org>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * NetSurf is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/** \file
- * Generic tree handling (implementation).
- */
-
-#include <oslib/os.h>
-
-#include <assert.h>
-#include <stdbool.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include <swis.h>
-#include <time.h>
-#include "oslib/colourtrans.h"
-#include "oslib/dragasprite.h"
-#include "oslib/osbyte.h"
-#include "oslib/osspriteop.h"
-#include "oslib/wimp.h"
-
-#include "utils/log.h"
-#include "utils/messages.h"
-#include "utils/utils.h"
-#include "netsurf/plotters.h"
-#include "netsurf/keypress.h"
-#include "desktop/tree.h"
-
-#include "riscos/bitmap.h"
-#include "riscos/dialog.h"
-#include "riscos/gui.h"
-#include "riscos/image.h"
-#include "riscos/menus.h"
-#include "riscos/mouse.h"
-#include "riscos/toolbar.h"
-#include "riscos/tinct.h"
-#include "riscos/textarea.h"
-#include "riscos/treeview.h"
-#include "riscos/wimp.h"
-#include "riscos/wimp_event.h"
-#include "riscos/wimputils.h"
-
-#ifndef wimp_KEY_END
-#define wimp_KEY_END wimp_KEY_COPY
-#endif
-
-struct ro_treeview
-{
- struct tree *tree; /*< Pointer to treeview tree block. */
- wimp_w w; /*< RO Window Handle for tree window. */
- struct toolbar *tb; /*< Pointer to toolbar block. */
- struct {
- int x; /*< X origin of tree, to RO work area. */
- int y; /*< Y origin of tree, to RO work area. */
- } origin;
- struct {
- int x; /*< X dimension of the tree, in RO units. */
- int y; /*< Y dimension of the tree, in RO units. */
- } size; /* (Dimensions are 0 until set correctly). */
- struct {
- int x; /*< X extent of the window, in RO units. */
- int y; /*< Y extent of the window, in RO units. */
- } extent; /* (Extents are 0 until set correctly). */
- struct {
- int x; /*< X coordinate of drag start */
- int y; /*< Y coordinate of drag start */
- } drag_start;
- tree_drag_type drag; /*< The current drag type for the tree */
- struct ro_treeview_callbacks *callbacks; /*< Callback handlers */
-};
-
-static void ro_treeview_redraw_request(int x, int y, int width, int height,
- void *pw);
-static void ro_treeview_resized(struct tree *tree, int width, int height,
- void *pw);
-static void ro_treeview_scroll_visible(int y, int height, void *pw);
-static void ro_treeview_get_window_dimensions(int *width, int *height,
- void *pw);
-
-static void ro_treeview_redraw(wimp_draw *redraw);
-static void ro_treeview_scroll(wimp_scroll *scroll);
-static void ro_treeview_redraw_loop(wimp_draw *redraw, ro_treeview *tv,
- osbool more);
-static void ro_treeview_open(wimp_open *open);
-static bool ro_treeview_mouse_click(wimp_pointer *pointer);
-static void ro_treeview_pointer_entering(wimp_entering *entering);
-static void ro_treeview_drag_start(ro_treeview *tv, wimp_pointer *pointer,
- wimp_window_state *state);
-static void ro_treeview_drag_end(wimp_dragged *drag, void *data);
-static bool ro_treeview_keypress(wimp_key *key);
-
-static void ro_treeview_set_window_extent(ro_treeview *tv,
- int width, int height);
-
-static void ro_treeview_update_theme(void *data, bool ok);
-static void ro_treeview_update_toolbar(void *data);
-static void ro_treeview_button_update(void *data);
-static void ro_treeview_save_toolbar_buttons(void *data, char *config);
-static void ro_treeview_button_click(void *data,
- toolbar_action_type action_type, union toolbar_action action);
-
-static const struct treeview_table ro_tree_callbacks = {
- ro_treeview_redraw_request,
- ro_treeview_resized,
- ro_treeview_scroll_visible,
- ro_treeview_get_window_dimensions
-};
-
-static const struct toolbar_callbacks ro_treeview_toolbar_callbacks = {
- ro_treeview_update_theme,
- ro_treeview_update_toolbar,
- ro_treeview_button_update,
- ro_treeview_button_click,
- NULL, /* No toolbar keypress handler */
- ro_treeview_save_toolbar_buttons
-};
-
-
-/**
- * Create a RISC OS GUI implementation of a treeview tree.
- *
- * \param window The window to create the tree in.
- * \param *toolbar A toolbar to attach to the window.
- * \param *callbacks Callbacks to service the treeview.
- * \param flags The treeview flags.
- *
- * \return The RISC OS treeview pointer.
- */
-
-ro_treeview *ro_treeview_create(wimp_w window, struct toolbar *toolbar,
- struct ro_treeview_callbacks *callbacks, unsigned int flags)
-{
- ro_treeview *tv;
-
- /* Claim memory for the treeview block, and create a tree. */
-
- tv = malloc(sizeof(ro_treeview));
- if (tv == NULL)
- return NULL;
-
- tv->w = window;
- tv->tb = toolbar;
-
- /* Set the tree redraw origin at a default 0,0 RO units. */
-
- tv->origin.x = 0;
- tv->origin.y = 0;
-
- /* Set the tree size as 0,0 to indicate that we don't know. */
-
- tv->size.x = 0;
- tv->size.y = 0;
-
- /* Set the tree window extent to 0,0, to indicate that we
- * don't know. */
-
- tv->extent.x = 0;
- tv->extent.y = 0;
-
- /* Set that there is no drag opperation at the moment */
-
- tv->drag = TREE_NO_DRAG;
-
- tv->tree = tree_create(flags, &ro_tree_callbacks, tv);
- if (tv->tree == NULL) {
- free(tv);
- return NULL;
- }
-
- /* Record the callback info. */
-
- tv->callbacks = callbacks;
-
- /* Register wimp events to handle the supplied window. */
-
- ro_gui_wimp_event_register_redraw_window(tv->w, ro_treeview_redraw);
- ro_gui_wimp_event_register_scroll_window(tv->w, ro_treeview_scroll);
- ro_gui_wimp_event_register_pointer_entering_window(tv->w,
- ro_treeview_pointer_entering);
- ro_gui_wimp_event_register_open_window(tv->w, ro_treeview_open);
- ro_gui_wimp_event_register_mouse_click(tv->w, ro_treeview_mouse_click);
- ro_gui_wimp_event_register_keypress(tv->w, ro_treeview_keypress);
- ro_gui_wimp_event_set_user_data(tv->w, tv);
-
- return tv;
-}
-
-/**
- * Delete a RISC OS GUI implementation of a treeview tree. The window is
- * *not* destroyed -- this must be done by the caller.
- *
- * \param tv The RISC OS treeview to delete.
- */
-
-void ro_treeview_destroy(ro_treeview *tv)
-{
- ro_gui_wimp_event_finalise(tv->w);
-
- tree_delete(tv->tree);
-
- free(tv);
-}
-
-/**
- * Return a pointer to a toolbar callbacks structure with the handlers to be
- * used by any treeview window toolbars.
- *
- * \return A pointer to the callback structure.
- */
-
-const struct toolbar_callbacks *ro_treeview_get_toolbar_callbacks(void)
-{
- return &ro_treeview_toolbar_callbacks;
-}
-
-/**
- * Change the redraw origin of a treeview tree in RISC OS graphics units.
- *
- * \param *tv The ro_treeview object to update.
- * \param x The X position, in terms of the RO window work area.
- * \param y The Y position, in terms of the RO window work area.
- *
- * \todo -- this probably needs a rework.
- */
-
-void ro_treeview_set_origin(ro_treeview *tv, int x, int y)
-{
- if (tv != NULL) {
- tv->origin.x = x;
- tv->origin.y = y;
-
- /* Assuming that we know how big the tree currently is, then
- * adjust the window work area extent to match. If we don't,
- * then presumably the tree isn't in an open window yet and
- * a subsequent Open Window Event should pick it up.
- */
-
- if (tv->size.x != 0 && tv->size.y != 0)
- ro_treeview_set_window_extent(tv,
- tv->origin.x + tv->size.x,
- tv->origin.y + tv->size.y);
- }
-}
-
-/**
- * Return details of the tree block associated with an ro_treeview object.
- *
- * \param *tv The ro_treeview object of interest.
- * \return A pointer to the associated tree block.
- */
-
-struct tree *ro_treeview_get_tree(ro_treeview *tv)
-{
- return (tv != NULL) ? (tv->tree) : (NULL);
-}
-
-/**
- * Return details of the RISC OS window handle associated with an
- * ro_treeview object.
- *
- * \param *tv The ro_treeview object of interest.
- * \return The associated RISC OS window handle.
- */
-
-wimp_w ro_treeview_get_window(ro_treeview *tv)
-{
- return (tv != NULL) ? (tv->w) : (NULL);
-}
-
-/**
- * Callback to force a redraw of part of the treeview window.
- *
- * \param x Min X Coordinate of area to be redrawn.
- * \param y Min Y Coordinate of area to be redrawn.
- * \param width Width of area to be redrawn.
- * \param height Height of area to be redrawn.
- * \param pw The treeview object to be redrawn.
- */
-
-void ro_treeview_redraw_request(int x, int y, int width, int height,
- void *pw)
-{
- if (pw != NULL) {
- ro_treeview *tv = (ro_treeview *) pw;
- os_error *error;
- wimp_draw update;
- osbool more;
-
- update.w = tv->w;
- update.box.x0 = (2 * x) + tv->origin.x;
- update.box.y0 = (-2 * (y + height)) + tv->origin.y;
- update.box.x1 = (2 * (x + width)) + tv->origin.x;
- update.box.y1 = (-2 * y) + tv->origin.y;
-
- error = xwimp_update_window(&update, &more);
- if (error) {
- LOG("xwimp_update_window: 0x%x: %s", error->errnum, error->errmess);
- ro_warn_user("WimpError", error->errmess);
- return;
- }
- ro_treeview_redraw_loop(&update, tv, more);
- }
-}
-
-/**
- * Pass RISC OS redraw events on to the treeview widget.
- *
- * \param *redraw Pointer to Redraw Event block.
- */
-
-void ro_treeview_redraw(wimp_draw *redraw)
-{
- osbool more;
- os_error *error;
- ro_treeview *tv;
-
- tv = (ro_treeview *) ro_gui_wimp_event_get_user_data(redraw->w);
- if (tv == NULL) {
- LOG("NULL treeview block for window: 0x%x", (unsigned int)redraw->w);
- /* Don't return, as not servicing redraw events isn't a good
- * idea. The following code must handle (tv == NULL)
- * gracefully while clearing the redraw queue.
- */
- }
-
- error = xwimp_redraw_window(redraw, &more);
- if (error) {
- LOG("xwimp_redraw_window: 0x%x: %s", error->errnum, error->errmess);
- ro_warn_user("WimpError", error->errmess);
- return;
- }
-
- ro_treeview_redraw_loop(redraw, tv, more);
-}
-
-/**
- * Handle scroll events in treeview windows.
- *
- * \param *scroll Pointer to Scroll Event block.
- */
-
-void ro_treeview_scroll(wimp_scroll *scroll)
-{
- os_error *error;
- int x = scroll->visible.x1 - scroll->visible.x0 - 32;
- int y = scroll->visible.y1 - scroll->visible.y0 - 32;
- ro_treeview *tv;
-
- tv = (ro_treeview *) ro_gui_wimp_event_get_user_data(scroll->w);
- if (tv == NULL)
- return;
-
- if (tv->tb != NULL)
- y -= ro_toolbar_full_height(tv->tb);
-
- switch (scroll->xmin) {
- case wimp_SCROLL_PAGE_LEFT:
- scroll->xscroll -= x;
- break;
- case wimp_SCROLL_COLUMN_LEFT:
- scroll->xscroll -= 32;
- break;
- case wimp_SCROLL_COLUMN_RIGHT:
- scroll->xscroll += 32;
- break;
- case wimp_SCROLL_PAGE_RIGHT:
- scroll->xscroll += x;
- break;
- default:
- scroll->xscroll += (x * (scroll->xmin>>2)) >> 2;
- break;
- }
-
- switch (scroll->ymin) {
- case wimp_SCROLL_PAGE_UP:
- scroll->yscroll += y;
- break;
- case wimp_SCROLL_LINE_UP:
- scroll->yscroll += 32;
- break;
- case wimp_SCROLL_LINE_DOWN:
- scroll->yscroll -= 32;
- break;
- case wimp_SCROLL_PAGE_DOWN:
- scroll->yscroll -= y;
- break;
- default:
- scroll->yscroll += (y * (scroll->ymin>>2)) >> 2;
- break;
- }
-
- error = xwimp_open_window((wimp_open *) scroll);
- if (error) {
- LOG("xwimp_open_window: 0x%x: %s", error->errnum, error->errmess);
- }
-}
-
-
-/**
- * Redraw a treeview window, once the initial readraw block has been collected.
- *
- * /param *redraw Pointer to redraw block.
- * /param *tv The treeview object being redrawn.
- * /param more Flag to show if more actions are required.
- */
-
-void ro_treeview_redraw_loop(wimp_draw *redraw, ro_treeview *tv, osbool more)
-{
- struct redraw_context ctx = {
- .interactive = true,
- .background_images = true,
- .plot = &ro_plotters
- };
-
- while (more) {
- os_error *error;
-
- if (tv != NULL && tv->tree != NULL) {
- struct rect clip;
-
- ro_plot_origin_x = redraw->box.x0 + tv->origin.x -
- redraw->xscroll;
- ro_plot_origin_y = redraw->box.y1 + tv->origin.y -
- redraw->yscroll;
-
- clip.x0 = (redraw->clip.x0 - ro_plot_origin_x) / 2;
- clip.y0 = (ro_plot_origin_y - redraw->clip.y1) / 2;
-
- /* Treeview text alwyas has flat background colour,
- * so disable unnecessary background blending */
- no_font_blending = true;
- tree_draw(tv->tree, 0, 0,
- clip.x0, clip.y0,
- (redraw->clip.x1 - redraw->clip.x0)/2,
- (redraw->clip.y1 - redraw->clip.y0)/2,
- &ctx);
- no_font_blending = false;
- }
-
- error = xwimp_get_rectangle(redraw, &more);
- if (error) {
- LOG("xwimp_redraw_window: 0x%x: %s", error->errnum, error->errmess);
- ro_warn_user("WimpError", error->errmess);
- return;
- }
- }
-}
-
-/**
- * Callback to notify us of a new overall tree size.
- *
- * \param tree The tree being resized.
- * \param width The new width of the window.
- * \param height The new height of the window.
- * \param *pw The treeview object to be resized.
- */
-
-void ro_treeview_resized(struct tree *tree, int width, int height,
- void *pw)
-{
- if (pw != NULL) {
- ro_treeview *tv = (ro_treeview *) pw;
-
- /* Store the width and height in terms of RISC OS work area. */
-
- tv->size.x = width * 2;
- tv->size.y = -(height * 2);
-
- /* Resize the window. */
-
- ro_treeview_set_window_extent(tv, tv->size.x, tv->size.y);
- }
-}
-
-/**
- * Callback to request that a section of the tree is scrolled into view.
- *
- * \param y The Y coordinate of top of the area in NS units.
- * \param height The height of the area in NS units.
- * \param *pw The treeview object affected.
- */
-
-void ro_treeview_scroll_visible(int y, int height, void *pw)
-{
- if (pw != NULL) {
- ro_treeview *tv = (ro_treeview *) pw;
- os_error *error;
- wimp_window_state state;
- int visible_t, visible_b;
- int request_t, request_b;
-
- state.w = tv->w;
- error = xwimp_get_window_state(&state);
- if (error) {
- LOG("xwimp_get_window_state: 0x%x: %s", error->errnum, error->errmess);
- ro_warn_user("WimpError", error->errmess);
- return;
- }
-
- /* Work out top and bottom of both the currently visible and
- * the required areas, in terms of the RO work area.
- */
-
- visible_t = state.yscroll;
- visible_b = state.yscroll
- - (state.visible.y1 - state.visible.y0);
-
- request_t = -(2 * y);// - tv->origin.y;
- request_b = -(2 * (y + height));// - tv->origin.y;
-
- /* If the area is outside the visible window, then scroll it
- * in to view.
- */
-
- if (request_t > visible_t || request_b < visible_b) {
- if (request_t > visible_t) {
- state.yscroll = request_t;
- } else if (request_b < visible_b) {
- state.yscroll = request_b + tv->origin.y
- + (state.visible.y1 - state.visible.y0);
-
- /* If the required area is bigger than the
- * visible extent, then align to the top and
- * let the bottom disappear out of view.
- */
-
- if (state.yscroll < request_t)
- state.yscroll = request_t;
- }
-
- error = xwimp_open_window((wimp_open *) &state);
- if (error) {
- LOG("xwimp_open_window: 0x%x: %s", error->errnum, error->errmess);
- ro_warn_user("WimpError", error->errmess);
- return;
- }
- }
- }
-}
-
-/**
- * Callback to return the tree window dimensions to the treeview system.
- *
- * \param *width Return the window width.
- * \param *height Return the window height.
- * \param *pw The treeview object to use.
- */
-
-void ro_treeview_get_window_dimensions(int *width, int *height,
- void *pw)
-{
- if (pw != NULL && (width != NULL || height != NULL)) {
- ro_treeview *tv = (ro_treeview *) pw;
- os_error *error;
- wimp_window_state state;
-
- state.w = tv->w;
- error = xwimp_get_window_state(&state);
- if (error) {
- LOG("xwimp_get_window_state: 0x%x: %s", error->errnum, error->errmess);
- ro_warn_user("WimpError", error->errmess);
- return;
- }
-
- if (width != NULL)
- *width = (state.visible.x1 - state.visible.x0) / 2;
-
- if (height != NULL)
- *height = (state.visible.y1 - state.visible.y0) / 2;
- }
-}
-
-/**
- * Resize the RISC OS window extent of a treeview.
- *
- * \param *tv The RISC OS treeview object to resize.
- * \param width The new width of the work area, in RO units.
- * \param height The new height of the work area, in RO units.
- */
-
-void ro_treeview_set_window_extent(ro_treeview *tv, int width, int height)
-{
- if (tv != NULL) {
- os_error *error;
- os_box extent;
- wimp_window_state state;
- int new_x, new_y;
- int visible_x, visible_y;
-
- /* Calculate the new window extents, in RISC OS units. */
-
- new_x = width + tv->origin.x;
- new_y = height + tv->origin.y;
-
- /* Get details of the existing window, and start to sanity
- * check the new extents.
- */
-
- state.w = tv->w;
- error = xwimp_get_window_state(&state);
- if (error) {
- LOG("xwimp_get_window_state: 0x%x: %s", error->errnum, error->errmess);
- ro_warn_user("WimpError", error->errmess);
- return;
- }
-
- /* If the extent is smaller than the current visible area,
- * then extend it so that it matches the visible area.
- */
-
- if (new_x < (state.visible.x1 - state.visible.x0))
- new_x = state.visible.x1 - state.visible.x0;
-
- if (new_y > (state.visible.y0 - state.visible.y1))
- new_y = state.visible.y0 - state.visible.y1;
-
- /* Calculate the maximum visible coordinates of the existing
- * window.
- */
-
- visible_x = state.xscroll +
- (state.visible.x1 - state.visible.x0);
- visible_y = state.yscroll +
- (state.visible.y0 - state.visible.y1);
-
- /* If the window is currently open, and the exising visible
- * area is bigger than the new extent, then we need to reopen
- * the window in an appropriare position before setting the
- * new extent.
- */
-
- if ((state.flags & wimp_WINDOW_OPEN) &&
- (visible_x > new_x || visible_y < new_y)) {
- int new_x_scroll = state.xscroll;
- int new_y_scroll = state.yscroll;
-
- if (visible_x > new_x)
- new_x_scroll = new_x - (state.visible.x1
- - state.visible.x0);
-
- if (visible_y < new_y)
- new_y_scroll = new_y - (state.visible.y0
- - state.visible.y1);
-
- if (new_x_scroll < 0) {
- state.visible.x1 -= new_x_scroll;
- state.xscroll = 0;
- } else {
- state.xscroll = new_x_scroll;
- }
-
- if (new_y_scroll > 0) {
- state.visible.y0 += new_y_scroll;
- state.yscroll = 0;
- } else {
- state.yscroll = new_y_scroll;
- }
-
- error = xwimp_open_window((wimp_open *) &state);
- if (error) {
- LOG("xwimp_get_window_state: 0x%x: %s", error->errnum, error->errmess);
- ro_warn_user("WimpError", error->errmess);
- return;
- }
-
- /* \todo -- Not sure if we need to reattach the
- * toolbar here: the nested wimp seems to take care
- * of it for us?
- */
- }
-
- /* Now that the new extent fits into the visible window, we
- * can resize the work area. If we succeed, the values are
- * recorded to save having to ask the Wimp for them
- * each time.
- */
-
- extent.x0 = 0;
- extent.y0 = new_y;
- extent.x1 = new_x;
- extent.y1 = 0;
-
- error = xwimp_set_extent(tv->w, &extent);
- if (error) {
- LOG("xwimp_set_extent: 0x%x: %s", error->errnum, error->errmess);
- ro_warn_user("WimpError", error->errmess);
- return;
- }
-
- tv->extent.x = new_x;
- tv->extent.y = new_y;
- }
-}
-
-/**
- * Handle RISC OS Window Open events for a treeview window.
- *
- * \param *open Pointer to the Window Open Event block.
- */
-
-static void ro_treeview_open(wimp_open *open)
-{
- ro_treeview *tv;
- os_error *error;
- os_box extent;
- int width, height;
-
- tv = (ro_treeview *) ro_gui_wimp_event_get_user_data(open->w);
- if (tv == NULL) {
- LOG("NULL treeview block for window: ox%x", (unsigned int)open->w);
- return;
- }
-
- /* Calculate the window work area. It must be at least the same as
- * the current visible area of the window, and needs to contain the
- * tree as defined by size.x + offset.x and size.y + offset.y (note
- * that the offset.y should be set to cover any toolbar, so we can
- * ignore the size of that).
- */
-
- width = open->visible.x1 - open->visible.x0;
- height = open->visible.y0 - open->visible.y1;
-
- if (tv->size.x != 0 && width < (tv->origin.x + tv->size.x))
- width = (tv->origin.x + tv->size.x);
-
- if (tv->size.y != 0 && height > (tv->size.y + tv->origin.y))
- height = (tv->size.y + tv->origin.y);
-
- if (width != tv->extent.x || height != tv->extent.y) {
- extent.x0 = 0;
- extent.y0 = height;
- extent.x1 = width;
- extent.y1 = 0;
-
- error = xwimp_set_extent(tv->w, &extent);
- if (error) {
- LOG("xwimp_set_extent: 0x%x: %s", error->errnum, error->errmess);
- ro_warn_user("WimpError", error->errmess);
- return;
- }
-
- tv->extent.x = width;
- tv->extent.y = height;
- }
-
- /* \todo -- Might need to add vertical scrollbar hiding back in here? */
-
- error = xwimp_open_window(open);
- if (error) {
- LOG("xwimp_open_window: 0x%x: %s", error->errnum, error->errmess);
- ro_warn_user("WimpError", error->errmess);
- }
-
- if (tv->tb)
- ro_toolbar_process(tv->tb, -1, false);
-}
-
-
-/**
- * Pass RISC OS Mouse Click events on to the treeview widget.
- *
- * \param *pointer Pointer to the Mouse Click Event block.
- * \return Return true if click handled; else false.
- */
-
-static bool ro_treeview_mouse_click(wimp_pointer *pointer)
-{
- os_error *error;
- ro_treeview *tv;
- wimp_window_state state;
- int xpos, ypos;
- browser_mouse_state mouse;
- bool handled = false;
-
- tv = (ro_treeview *) ro_gui_wimp_event_get_user_data(pointer->w);
- if (tv == NULL) {
- LOG("NULL treeview block for window: 0x%x", (unsigned int)pointer->w);
- return false;
- }
-
- state.w = tv->w;
- error = xwimp_get_window_state(&state);
- if (error) {
- LOG("xwimp_get_window_state: 0x%x: %s", error->errnum, error->errmess);
- ro_warn_user("WimpError", error->errmess);
- return false;
- }
-
- /* Convert the returned mouse coordinates into NetSurf's internal
- * units.
- */
-
- xpos = ((pointer->pos.x - state.visible.x0) +
- state.xscroll - tv->origin.x) / 2;
- ypos = ((state.visible.y1 - pointer->pos.y) -
- state.yscroll + tv->origin.y) / 2;
-
- /* Start to process the mouse click.
- *
- * Select and Adjust are processed normally. To get filer-like operation
- * with selections, Menu clicks are passed to the treeview first as
- * Select if there are no selected nodes in the tree.
- */
-
- mouse = 0;
-
- if (pointer->buttons == wimp_CLICK_MENU) {
- /* TODO: test for no selection, and pass click to select node */
- /* mouse |= BROWSER_MOUSE_CLICK_1; */
- } else {
- mouse = ro_gui_mouse_click_state(pointer->buttons,
- wimp_BUTTON_DOUBLE_CLICK_DRAG);
-
- /* Give the window input focus on Select-clicks. This wouldn't
- * be necessary if the core used the RISC OS caret.
- */
-
- if (mouse & BROWSER_MOUSE_CLICK_1)
- xwimp_set_caret_position(tv->w, -1, -100, -100, 32, -1);
- }
-
- if (mouse != 0) {
- handled = tree_mouse_action(tv->tree, mouse, xpos, ypos);
-
- tv->drag = tree_drag_status(tv->tree);
- if (tv->drag != TREE_NO_DRAG) {
- tv->drag_start.x = xpos;
- tv->drag_start.y = ypos;
- }
-
- /* If it's a visible drag, start the RO side of the visible
- * effects.
- */
-
- if (tv->drag == TREE_SELECT_DRAG ||
- tv->drag == TREE_MOVE_DRAG)
- ro_treeview_drag_start(tv, pointer, &state);
-
-
- if (tv->callbacks != NULL &&
- tv->callbacks->toolbar_button_update != NULL)
- tv->callbacks->toolbar_button_update();
- }
-
- /* Special actions for some mouse buttons. Adjust closes the dialog;
- * Menu opens a menu. For the latter, we assume that the owning module
- * will have attached a window menu to our parent window with the auto
- * flag unset (so that we can fudge the selection above). If it hasn't,
- * the call will quietly fail.
- *
- * \TODO -- Adjust-click close isn't a perfect copy of what the RO
- * version did: adjust clicks anywhere close the tree, and
- * selections persist.
- */
-
- switch(pointer->buttons) {
- case wimp_CLICK_ADJUST:
- if (handled)
- ro_gui_dialog_close(tv->w);
- break;
-
- case wimp_CLICK_MENU:
- ro_gui_wimp_event_process_window_menu_click(pointer);
- break;
- }
-
- return true;
-}
-
-
-/**
- * Handle Pointer Entering Window events for treeview windows.
- *
- * \param *entering The Wimp_PointerEnteringWindow block.
- */
-
-void ro_treeview_pointer_entering(wimp_entering *entering)
-{
- ro_treeview *tv;
-
- tv = (ro_treeview *) ro_gui_wimp_event_get_user_data(entering->w);
- if (tv == NULL)
- return;
-
- ro_mouse_track_start(NULL, ro_treeview_mouse_at, NULL);
-}
-
-/**
- * Track the mouse under Null Polls from the wimp, to support dragging.
- *
- * \param *pointer Pointer to a Wimp Pointer block.
- * \param *data NULL to allow use as a ro_mouse callback.
- */
-
-void ro_treeview_mouse_at(wimp_pointer *pointer, void *data)
-{
- os_error *error;
- ro_treeview *tv;
- wimp_window_state state;
- int xpos, ypos;
- browser_mouse_state mouse;
-
- if (pointer->buttons & (wimp_CLICK_MENU))
- return;
-
- tv = (ro_treeview *) ro_gui_wimp_event_get_user_data(pointer->w);
- if (tv == NULL) {
- LOG("NULL treeview block for window: 0x%x", (unsigned int)pointer->w);
- return;
- }
-
- if (tv->drag == TREE_NO_DRAG)
- return;
-
- /* We know now that it's not a Menu click and the treeview thinks
- * that a drag is in progress.
- */
-
- state.w = tv->w;
- error = xwimp_get_window_state(&state);
- if (error) {
- LOG("xwimp_get_window_state: 0x%x: %s", error->errnum, error->errmess);
- ro_warn_user("WimpError", error->errmess);
- return;
- }
-
- /* Convert the returned mouse coordinates into NetSurf's internal
- * units.
- */
-
- xpos = ((pointer->pos.x - state.visible.x0) +
- state.xscroll - tv->origin.x) / 2;
- ypos = ((state.visible.y1 - pointer->pos.y) -
- state.yscroll + tv->origin.y) / 2;
-
- /* Start to process the mouse click. */
-
- mouse = ro_gui_mouse_drag_state(pointer->buttons,
- wimp_BUTTON_DOUBLE_CLICK_DRAG);
-
- tree_mouse_action(tv->tree, mouse, xpos, ypos);
-
- if (!(mouse & BROWSER_MOUSE_DRAG_ON)) {
- tree_drag_end(tv->tree, mouse, tv->drag_start.x,
- tv->drag_start.y, xpos, ypos);
- tv->drag = TREE_NO_DRAG;
- }
-
- if (tv->callbacks != NULL &&
- tv->callbacks->toolbar_button_update != NULL)
- tv->callbacks->toolbar_button_update();
-}
-
-
-/**
- * Start a RISC OS drag event to reflect on screen what is happening
- * during the core tree drag.
- *
- * \param *tv The RO treeview to which the drag is attached.
- * \param *pointer The RO pointer event data block starting the drag.
- * \param *state The RO window state block for the treeview window.
- */
-
-static void ro_treeview_drag_start(ro_treeview *tv, wimp_pointer *pointer,
- wimp_window_state *state)
-{
- os_error *error;
- wimp_drag drag;
- wimp_auto_scroll_info auto_scroll;
-
- drag.w = tv->w;
- drag.bbox.x0 = state->visible.x0;
- drag.bbox.y0 = state->visible.y0;
- drag.bbox.x1 = state->visible.x1;
- drag.bbox.y1 = state->visible.y1 - ro_toolbar_height(tv->tb) - 2;
-
- switch (tv->drag) {
- case TREE_SELECT_DRAG:
- drag.type = wimp_DRAG_USER_RUBBER;
-
- drag.initial.x0 = pointer->pos.x;
- drag.initial.y0 = pointer->pos.y;
- drag.initial.x1 = pointer->pos.x;
- drag.initial.y1 = pointer->pos.y;
- break;
-
- case TREE_MOVE_DRAG:
- drag.type = wimp_DRAG_USER_POINT;
-
- drag.initial.x0 = pointer->pos.x - 4;
- drag.initial.y0 = pointer->pos.y - 48;
- drag.initial.x1 = pointer->pos.x + 48;
- drag.initial.y1 = pointer->pos.y + 4;
- break;
-
- default:
- /* No other drag types are supported. */
- break;
- }
-
- LOG("Drag start...");
-
- error = xwimp_drag_box_with_flags(&drag,
- wimp_DRAG_BOX_KEEP_IN_LINE | wimp_DRAG_BOX_CLIP);
- if (error) {
- LOG("xwimp_drag_box: 0x%x: %s", error->errnum, error->errmess);
- ro_warn_user("WimpError", error->errmess);
- } else {
- auto_scroll.w = tv->w;
- auto_scroll.pause_zone_sizes.x0 = 80;
- auto_scroll.pause_zone_sizes.y0 = 80;
- auto_scroll.pause_zone_sizes.x1 = 80;
- auto_scroll.pause_zone_sizes.y1 = 80 +
- ro_toolbar_height(tv->tb);
- auto_scroll.pause_duration = 0;
- auto_scroll.state_change = (void *) 1;
-
- error = xwimp_auto_scroll(wimp_AUTO_SCROLL_ENABLE_VERTICAL,
- &auto_scroll, NULL);
- if (error) {
- LOG("xwimp_auto_scroll: 0x%x: %s", error->errnum, error->errmess);
- ro_warn_user("WimpError", error->errmess);
- }
-
- ro_mouse_drag_start(ro_treeview_drag_end, ro_treeview_mouse_at,
- NULL, NULL);
- }
-}
-
-
-/**
- * Process RISC OS User Drag Box events which relate to us: in effect, drags
- * started by ro_treeview_drag_start().
- *
- * \param *drag Pointer to the User Drag Box Event block.
- * \param *data NULL to allow use as a ro_mouse callback.
- */
-
-static void ro_treeview_drag_end(wimp_dragged *drag, void *data)
-{
- os_error *error;
-
- error = xwimp_drag_box((wimp_drag *) -1);
- if (error) {
- LOG("xwimp_drag_box: 0x%x: %s", error->errnum, error->errmess);
- ro_warn_user("WimpError", error->errmess);
- }
-
- error = xwimp_auto_scroll(0, NULL, NULL);
- if (error) {
- LOG("xwimp_auto_scroll: 0x%x: %s", error->errnum, error->errmess);
- ro_warn_user("WimpError", error->errmess);
- }
-}
-
-
-/**
- * Pass RISC OS keypress events on to the treeview widget.
- *
- * \param *key Pointer to the Key Pressed Event block.
- * \return Return true if keypress handled; else false.
- */
-
-static bool ro_treeview_keypress(wimp_key *key)
-{
- ro_treeview *tv;
- uint32_t c;
-
- tv = (ro_treeview *) ro_gui_wimp_event_get_user_data(key->w);
- if (tv == NULL) {
- LOG("NULL treeview block for window: 0x%x", (unsigned int)key->w);
- return false;
- }
-
- c = (uint32_t) key->c;
-
- if ((unsigned)c < 0x20 || (0x7f <= c && c <= 0x9f) ||
- (c & IS_WIMP_KEY)) {
- /* Munge control keys into unused control chars */
- /* We can't map onto 1->26 (reserved for ctrl+<qwerty>
- That leaves 27->31 and 128->159 */
- switch (c & ~IS_WIMP_KEY) {
- case wimp_KEY_TAB: c = 9; break;
- case wimp_KEY_SHIFT | wimp_KEY_TAB: c = 11; break;
-
- /* cursor movement keys */
- case wimp_KEY_HOME:
- case wimp_KEY_CONTROL | wimp_KEY_LEFT:
- c = NS_KEY_LINE_START;
- break;
- case wimp_KEY_END:
- if (os_version >= RISCOS5)
- c = NS_KEY_LINE_END;
- else
- c = NS_KEY_DELETE_RIGHT;
- break;
- case wimp_KEY_CONTROL | wimp_KEY_RIGHT: c = NS_KEY_LINE_END; break;
- case wimp_KEY_CONTROL | wimp_KEY_UP: c = NS_KEY_TEXT_START; break;
- case wimp_KEY_CONTROL | wimp_KEY_DOWN: c = NS_KEY_TEXT_END; break;
- case wimp_KEY_SHIFT | wimp_KEY_LEFT: c = NS_KEY_WORD_LEFT ; break;
- case wimp_KEY_SHIFT | wimp_KEY_RIGHT: c = NS_KEY_WORD_RIGHT; break;
- case wimp_KEY_SHIFT | wimp_KEY_UP: c = NS_KEY_PAGE_UP; break;
- case wimp_KEY_SHIFT | wimp_KEY_DOWN: c = NS_KEY_PAGE_DOWN; break;
- case wimp_KEY_LEFT: c = NS_KEY_LEFT; break;
- case wimp_KEY_RIGHT: c = NS_KEY_RIGHT; break;
- case wimp_KEY_UP: c = NS_KEY_UP; break;
- case wimp_KEY_DOWN: c = NS_KEY_DOWN; break;
-
- /* editing */
- case wimp_KEY_CONTROL | wimp_KEY_END:
- c = NS_KEY_DELETE_LINE_END;
- break;
- case wimp_KEY_DELETE:
- if (ro_gui_ctrl_pressed())
- c = NS_KEY_DELETE_LINE_START;
- else if (os_version < RISCOS5)
- c = NS_KEY_DELETE_LEFT;
- break;
-
- default:
- break;
- }
- }
-
- if (!(c & IS_WIMP_KEY)) {
- if (tree_keypress(tv->tree, c)) {
- if (tv->callbacks &&
- tv->callbacks->toolbar_button_update
- != NULL)
- tv->callbacks->toolbar_button_update();
-
- return true;
- }
- }
-
- return false;
-}
-
-
-/**
- * Update a treeview to use a new theme.
- *
- * \param *data Pointer to the treeview to update.
- * \param ok true if the bar still exists; else false.
- */
-
-void ro_treeview_update_theme(void *data, bool ok)
-{
- ro_treeview *tv = (ro_treeview *) data;
-
- if (tv != NULL && tv->tb != NULL){
- if (ok) {
- ro_treeview_update_toolbar(tv);
- } else {
- tv->tb = NULL;
- }
- }
-}
-
-
-/**
- * Change the size of a treeview's toolbar and redraw the window.
- *
- * \param *data The treeview to update.
- */
-
-void ro_treeview_update_toolbar(void *data)
-{
- ro_treeview *tv = (ro_treeview *) data;
-
- if (tv != NULL && tv->tb != NULL) {
- ro_treeview_set_origin(tv, 0,
- -(ro_toolbar_height(tv->tb)));
-
- xwimp_force_redraw(tv->w, 0, tv->extent.y, tv->extent.x, 0);
- }
-}
-
-
-/**
- * Update the toolbar icons in a treeview window's toolbar. As we're just
- * an intermediate widget, we pass the details on down the chain.
- *
- * \param *data The treeview owning the toolbar.
- */
-
-void ro_treeview_button_update(void *data)
-{
- ro_treeview *tv = (ro_treeview *) data;
-
- if (tv == NULL || tv->callbacks == NULL)
- return;
-
- if (tv->callbacks->toolbar_button_update != NULL)
- tv->callbacks->toolbar_button_update();
-}
-
-
-/**
- * Save a new button configuration from a treeview window's toolbar. As
- * we're just an intermediate widget, we pass the details on.
- *
- * \param *data The treeview owning the toolbar.
- * \param *config The new button config string.
- */
-
-void ro_treeview_save_toolbar_buttons(void *data, char *config)
-{
- ro_treeview *tv = (ro_treeview *) data;
-
- if (tv == NULL || tv->callbacks == NULL)
- return;
-
- if (tv->callbacks->toolbar_button_save != NULL)
- tv->callbacks->toolbar_button_save(config);
-}
-
-
-/**
- * Process clicks on buttons in a treeview window's toolbar. As we're just
- * an intermediate widget, we just pass the details on down the chain.
- *
- * \param *data The treeview owning the click.
- * \param action_type The action type to be handled.
- * \param action The action to handle.
- */
-
-void ro_treeview_button_click(void *data,
- toolbar_action_type action_type, union toolbar_action action)
-{
- ro_treeview *tv = (ro_treeview *) data;
-
- if (tv == NULL || tv->callbacks == NULL ||
- action_type != TOOLBAR_ACTION_BUTTON)
- return;
-
- if (tv->callbacks->toolbar_button_click != NULL)
- tv->callbacks->toolbar_button_click(action.button);
-
- if (tv->callbacks->toolbar_button_update != NULL)
- tv->callbacks->toolbar_button_update();
-}
-
-
-/**
- * Return a token identifying the interactive help message for a given cursor
- * position.
- *
- * Currently this is inimplemented.
- *
- * \param *message_data Pointer to the Wimp's help message block.
- * \return Token value (-1 indicates no help available).
- */
-
-int ro_treeview_get_help(help_full_message_request *message_data)
-{
- return -1;
-}
-
diff --git a/frontends/riscos/treeview.h b/frontends/riscos/treeview.h
deleted file mode 100644
index 80ff7660f..000000000
--- a/frontends/riscos/treeview.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright 2004 Richard Wilson <not_ginger_matt@users.sourceforge.net>
- * Copyright 2010 Stephen Fryatt <stevef@netsurf-browser.org>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * NetSurf is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/** \file
- * Generic tree handling (interface).
- */
-
-#ifndef _NETSURF_RISCOS_TREEVIEW_H_
-#define _NETSURF_RISCOS_TREEVIEW_H_
-
-#include <stdbool.h>
-#include <oslib/help.h>
-#include <oslib/wimp.h>
-
-#include "desktop/tree.h"
-#include "riscos/toolbar.h"
-
-typedef struct ro_treeview ro_treeview;
-
-struct ro_treeview_callbacks {
- void (*toolbar_button_click)(button_bar_action action);
- void (*toolbar_button_update)(void);
- void (*toolbar_button_save)(char *);
-};
-
-ro_treeview *ro_treeview_create(wimp_w window, struct toolbar *toolbar,
- struct ro_treeview_callbacks *callbacks, unsigned int flags);
-void ro_treeview_destroy(ro_treeview *tv);
-const struct toolbar_callbacks *ro_treeview_get_toolbar_callbacks(void);
-
-struct tree *ro_treeview_get_tree(ro_treeview *tv);
-wimp_w ro_treeview_get_window(ro_treeview *tv);
-
-void ro_treeview_set_origin(ro_treeview *tv, int x, int y);
-void ro_treeview_mouse_at(wimp_pointer *pointer, void *data);
-int ro_treeview_get_help(help_full_message_request *message_data);
-
-#endif
-
diff --git a/frontends/riscos/window.c b/frontends/riscos/window.c
index 58cd86e49..3e84846a3 100644
--- a/frontends/riscos/window.c
+++ b/frontends/riscos/window.c
@@ -1944,7 +1944,7 @@ bool ro_gui_window_handle_local_keypress(struct gui_window *g, wimp_key *key,
return true;
case IS_WIMP_KEY + wimp_KEY_F6: /* Hotlist */
- ro_gui_hotlist_open();
+ ro_gui_hotlist_present();
return true;
case IS_WIMP_KEY + wimp_KEY_F7: /* Show local history */
@@ -1953,7 +1953,7 @@ bool ro_gui_window_handle_local_keypress(struct gui_window *g, wimp_key *key,
case IS_WIMP_KEY + wimp_KEY_CONTROL + wimp_KEY_F7:
/* Show global history */
- ro_gui_global_history_open();
+ ro_gui_global_history_present();
return true;
case IS_WIMP_KEY + wimp_KEY_F8: /* View source */
@@ -2696,7 +2696,7 @@ bool ro_gui_window_menu_select(wimp_w w, wimp_i i, wimp_menu *menu,
ro_gui_window_action_local_history(g);
break;
case HISTORY_SHOW_GLOBAL:
- ro_gui_global_history_open();
+ ro_gui_global_history_present();
break;
/* hotlist actions */
@@ -2704,12 +2704,12 @@ bool ro_gui_window_menu_select(wimp_w w, wimp_i i, wimp_menu *menu,
ro_gui_window_action_add_bookmark(g);
break;
case HOTLIST_SHOW:
- ro_gui_hotlist_open();
+ ro_gui_hotlist_present();
break;
/* cookies actions */
case COOKIES_SHOW:
- ro_gui_cookies_open();
+ ro_gui_cookies_present();
break;
case COOKIES_DELETE:
@@ -3607,7 +3607,7 @@ void ro_gui_window_toolbar_click(void *data,
break;
case TOOLBAR_BUTTON_HISTORY_GLOBAL:
- ro_gui_global_history_open();
+ ro_gui_global_history_present();
break;
case TOOLBAR_BUTTON_HOME:
@@ -3623,7 +3623,7 @@ void ro_gui_window_toolbar_click(void *data,
break;
case TOOLBAR_BUTTON_BOOKMARK_OPEN:
- ro_gui_hotlist_open();
+ ro_gui_hotlist_present();
break;
case TOOLBAR_BUTTON_BOOKMARK_ADD: