From a836591435736b1d72eced1e6f643341422a7d82 Mon Sep 17 00:00:00 2001 From: Richard Wilson Date: Thu, 13 Jul 2006 12:46:02 +0000 Subject: Add basic cookie viewer, make trees use textarea components for UTF8 editing, trim headers, fix tree redraw issues. svn path=/trunk/netsurf/; revision=2739 --- riscos/cookies.c | 201 ++++++++++++++++++++++++++++++++++++++++++++++++ riscos/cookies.h | 19 +++++ riscos/debugwin.c | 1 + riscos/dialog.c | 4 + riscos/download.c | 1 + riscos/global_history.c | 2 +- riscos/gui.c | 6 +- riscos/gui.h | 14 ++-- riscos/help.c | 26 +++++-- riscos/history.c | 4 +- riscos/menus.c | 79 ++++++++++++++++--- riscos/menus.h | 5 +- riscos/options.h | 3 + riscos/save.c | 1 + riscos/theme.c | 39 +++++++++- riscos/theme.h | 22 +++--- riscos/treeview.c | 88 +++++++++++---------- riscos/url_complete.h | 4 +- riscos/window.c | 1 + 19 files changed, 439 insertions(+), 81 deletions(-) create mode 100644 riscos/cookies.c create mode 100644 riscos/cookies.h (limited to 'riscos') diff --git a/riscos/cookies.c b/riscos/cookies.c new file mode 100644 index 000000000..b1cf8873f --- /dev/null +++ b/riscos/cookies.c @@ -0,0 +1,201 @@ +/* + * This file is part of NetSurf, http://netsurf.sourceforge.net/ + * Licensed under the GNU General Public License, + * http://www.opensource.org/licenses/gpl-license + * Copyright 2006 Richard Wilson + */ + +/** \file + * Cookies (implementation). + */ + +#include +#include +#include +#include +#include +#include +#include "oslib/wimp.h" +#include "oslib/wimpspriteop.h" +#include "netsurf/content/urldb.h" +#include "netsurf/desktop/cookies.h" +#include "netsurf/desktop/tree.h" +#include "netsurf/riscos/cookies.h" +#include "netsurf/riscos/dialog.h" +#include "netsurf/riscos/menus.h" +#include "netsurf/riscos/options.h" +#include "netsurf/riscos/theme.h" +#include "netsurf/riscos/treeview.h" +#include "netsurf/riscos/wimp.h" +#include "netsurf/riscos/wimp_event.h" +#include "netsurf/utils/messages.h" +#include "netsurf/utils/log.h" +#include "netsurf/utils/url.h" +#include "netsurf/utils/utils.h" + +static bool ro_gui_cookies_click(wimp_pointer *pointer); +static struct node *ro_gui_cookies_find(const char *url); + +/* The history window, toolbar and plot origins */ +static wimp_w cookies_window; +struct tree *cookies_tree; +static bool cookies_init; + +/** + * Initialise cookies tree + */ +void ro_gui_cookies_initialise(void) +{ + /* create our window */ + cookies_window = ro_gui_dialog_create("tree"); + ro_gui_set_window_title(cookies_window, + messages_get("Cookies")); + ro_gui_wimp_event_register_redraw_window(cookies_window, + ro_gui_tree_redraw); + ro_gui_wimp_event_register_open_window(cookies_window, + ro_gui_tree_open); + ro_gui_wimp_event_register_mouse_click(cookies_window, + ro_gui_cookies_click); + + /* Create an empty tree */ + cookies_tree = calloc(sizeof(struct tree), 1); + if (!cookies_tree) { + warn_user("NoMemory", 0); + return; + } + cookies_tree->root = tree_create_folder_node(NULL, "Root"); + if (!cookies_tree->root) { + warn_user("NoMemory", 0); + free(cookies_tree); + cookies_tree = NULL; + } + cookies_tree->root->expanded = true; + cookies_tree->handle = (int)cookies_window; + cookies_tree->movable = false; + ro_gui_wimp_event_set_user_data(cookies_window, + cookies_tree); + ro_gui_wimp_event_register_keypress(cookies_window, + ro_gui_tree_keypress); + + /* Create our toolbar */ + cookies_tree->toolbar = ro_gui_theme_create_toolbar(NULL, + THEME_COOKIES_TOOLBAR); + if (cookies_tree->toolbar) + ro_gui_theme_attach_toolbar(cookies_tree->toolbar, + cookies_window); + + cookies_init = true; + urldb_iterate_cookies(cookies_update); + cookies_init = false; + tree_initialise(cookies_tree); +} + + +/** + * Respond to a mouse click + * + * \param pointer the pointer state + * \return true to indicate click handled + */ +bool ro_gui_cookies_click(wimp_pointer *pointer) +{ + ro_gui_tree_click(pointer, cookies_tree); + if (pointer->buttons == wimp_CLICK_MENU) + ro_gui_menu_create(cookies_menu, pointer->pos.x, + pointer->pos.y, pointer->w); + else + ro_gui_menu_prepare_action(pointer->w, TREE_SELECTION, false); + return true; +} + + +/** + * Attempts to process an interactive help message request + * + * \param x the x co-ordinate to give help for + * \param y the x co-ordinate to give help for + * \return the message code index + */ +int ro_gui_cookies_help(int x, int y) +{ + return -1; +} + + +/** + * Perform cookie addition + * + * \param data Cookie data for a domain + * \return true (for urldb_iterate_entries) + */ +bool cookies_update(const struct cookie_data *data) +{ + struct node *parent; + struct node *node = NULL; + struct node *child; + const struct cookie_data *cookie; + + assert(data); + + /* check if we're a domain, and add get the first cookie */ + for (cookie = data; cookie->prev; cookie = cookie->prev); + + if (!cookies_init) { + node = ro_gui_cookies_find(data->domain); + if (node) { + /* mark as deleted so we don't remove the cookies */ + for (child = node->child; child; child = child->next) + child->deleted = true; + if (node->child) + tree_delete_node(cookies_tree, node->child, + true); + } + } + + if (!node) { + for (parent = cookies_tree->root->child; parent; + parent = parent->next) { + if (strcmp(cookie->domain, parent->data.text) < 0) + break; + } + if (!parent) { + node = tree_create_folder_node(cookies_tree->root, + cookie->domain); + } else { + node = tree_create_folder_node(NULL, data->domain); + if (node) + tree_link_node(parent, node, true); + } + } + if (!node) + return true; + node->editable = false; + + for (; cookie; cookie = cookie->next) + tree_create_cookie_node(node, cookie); + if (!cookies_init) { + tree_handle_node_changed(cookies_tree, node, + true, false); + tree_redraw_area(cookies_tree, + node->box.x - NODE_INSTEP, + 0, NODE_INSTEP, 16384); + } + return true; +} + +/** + * Find an entry in the cookie tree + * + * \param url The URL to find + * \return Pointer to node, or NULL if not found + */ +struct node *ro_gui_cookies_find(const char *url) +{ + struct node *node; + + for (node = cookies_tree->root->child; node; node = node->next) { + if (!strcmp(url, node->data.text)) + return node; + } + return NULL; +} diff --git a/riscos/cookies.h b/riscos/cookies.h new file mode 100644 index 000000000..283a91ca8 --- /dev/null +++ b/riscos/cookies.h @@ -0,0 +1,19 @@ +/* + * This file is part of NetSurf, http://netsurf.sourceforge.net/ + * Licensed under the GNU General Public License, + * http://www.opensource.org/licenses/gpl-license + * Copyright 2006 Richard Wilson + */ + +/** \file + * Cookies (interface). + */ + +#ifndef _NETSURF_RISCOS_COOKIES_H_ +#define _NETSURF_RISCOS_COOKIES_H_ + +void ro_gui_cookies_initialise(void); +int ro_gui_cookies_help(int x, int y); + + +#endif diff --git a/riscos/debugwin.c b/riscos/debugwin.c index d271eb890..a38f2e442 100644 --- a/riscos/debugwin.c +++ b/riscos/debugwin.c @@ -12,6 +12,7 @@ #include #include #include "oslib/wimp.h" +#include "netsurf/content/content.h" #include "netsurf/riscos/dialog.h" #include "netsurf/riscos/wimp_event.h" #include "netsurf/utils/log.h" diff --git a/riscos/dialog.c b/riscos/dialog.c index aa46f19b2..706ee5701 100644 --- a/riscos/dialog.c +++ b/riscos/dialog.c @@ -24,6 +24,7 @@ #include "netsurf/desktop/netsurf.h" #include "netsurf/render/font.h" #include "netsurf/riscos/configure.h" +#include "netsurf/riscos/cookies.h" #include "netsurf/riscos/dialog.h" #include "netsurf/riscos/global_history.h" #include "netsurf/riscos/gui.h" @@ -102,6 +103,9 @@ void ro_gui_dialog_init(void) /* global history window */ ro_gui_global_history_initialise(); + /* cookies window */ + ro_gui_cookies_initialise(); + /* theme installation */ dialog_theme_install = ro_gui_dialog_create("theme_inst"); ro_gui_wimp_event_register_cancel(dialog_theme_install, diff --git a/riscos/download.c b/riscos/download.c index 171b7ffcc..fb4ddc045 100644 --- a/riscos/download.c +++ b/riscos/download.c @@ -32,6 +32,7 @@ #include "oslib/wimpspriteop.h" #include "netsurf/content/fetch.h" #include "netsurf/desktop/gui.h" +#include "netsurf/desktop/netsurf.h" #include "netsurf/riscos/dialog.h" #include "netsurf/riscos/options.h" #include "netsurf/riscos/save.h" diff --git a/riscos/global_history.c b/riscos/global_history.c index 93cb34be7..c16eea498 100644 --- a/riscos/global_history.c +++ b/riscos/global_history.c @@ -90,7 +90,6 @@ void ro_gui_global_history_initialise(void) } global_history_tree->root->expanded = true; ro_gui_global_history_initialise_nodes(); - tree_initialise(global_history_tree); global_history_tree->handle = (int)global_history_window; global_history_tree->movable = false; ro_gui_wimp_event_set_user_data(global_history_window, @@ -122,6 +121,7 @@ void ro_gui_global_history_initialise(void) global_history_init = true; urldb_iterate_entries(global_history_add_internal); global_history_init = false; + tree_initialise(global_history_tree); } /** diff --git a/riscos/gui.c b/riscos/gui.c index 3e8efca12..a2206d759 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -321,9 +321,11 @@ void gui_init(int argc, char** argv) if (!option_toolbar_browser) option_toolbar_browser = strdup("0123|58|9"); if (!option_toolbar_hotlist) - option_toolbar_hotlist = strdup("401|23"); + option_toolbar_hotlist = strdup("40|12|3"); if (!option_toolbar_history) - option_toolbar_history = strdup("01|23"); + option_toolbar_history = strdup("0|12|3"); + if (!option_toolbar_cookies) + option_toolbar_cookies = strdup("0|12"); if (!option_ca_bundle) option_ca_bundle = strdup("NetSurf:Resources.ca-bundle"); if (!option_cookie_file) diff --git a/riscos/gui.h b/riscos/gui.h index b5665dcda..743e701ea 100644 --- a/riscos/gui.h +++ b/riscos/gui.h @@ -15,12 +15,9 @@ #include #include #include -#include "netsurf/utils/config.h" #include "netsurf/desktop/browser.h" -#include "netsurf/desktop/netsurf.h" -#include "netsurf/desktop/gui.h" -#include "netsurf/desktop/options.h" -#include "netsurf/desktop/tree.h" +#include "netsurf/content/content_type.h" +#include "netsurf/utils/config.h" #define RISCOS5 0xAA @@ -33,6 +30,11 @@ extern const char * NETSURF_DIR; struct toolbar; struct plotter_table; +struct gui_window; +struct tree; +struct node; +struct history; +struct css_style; extern wimp_t task_handle; /**< RISC OS wimp task handle. */ @@ -51,7 +53,7 @@ extern bool gui_redraw_debug; extern osspriteop_area *gui_sprites; extern bool dialog_folder_add, dialog_entry_add, hotlist_insert; extern bool print_active, print_text_black; -extern struct tree *hotlist_tree, *global_history_tree; +extern struct tree *hotlist_tree, *global_history_tree, *cookies_tree; typedef enum { GUI_DRAG_NONE, GUI_DRAG_SELECTION, GUI_DRAG_DOWNLOAD_SAVE, GUI_DRAG_SAVE, GUI_DRAG_SCROLL, GUI_DRAG_STATUS_RESIZE, diff --git a/riscos/help.c b/riscos/help.c index de42f8f30..f189ce48a 100644 --- a/riscos/help.c +++ b/riscos/help.c @@ -17,6 +17,7 @@ #include "oslib/taskmanager.h" #include "oslib/wimp.h" #include "netsurf/desktop/tree.h" +#include "netsurf/riscos/cookies.h" #include "netsurf/riscos/global_history.h" #include "netsurf/riscos/gui.h" #include "netsurf/riscos/help.h" @@ -35,15 +36,17 @@ Help keys should be registered using the wimp_event system to be recognised. The only special case help values are: - HelpIconbar Iconbar (no icon suffix is used) - HelpHotlist Hotlist window [*] - HelpGHistory Global history window [*] - HelpBrowser Browser window [*] + HelpIconbar Iconbar (no icon suffix is used) + HelpBrowser Browser window [*] + HelpHotlist Hotlist window [*] + HelpGHistory Global history window [*] + HelpCookies Cookies window [*] - HelpIconMenu Iconbar menu - HelpBrowserMenu Browser window menu - HelpHotlistMenu Hotlist window menu - HelpGHistoryMenu Global history window menu + HelpIconMenu Iconbar menu + HelpBrowserMenu Browser window menu + HelpHotlistMenu Hotlist window menu + HelpGHistoryMenu Global history window menu + HelpCookiesMenu Cookie window menu The prefixes are followed by either the icon number (eg 'HelpToolbar7'), or a series of numbers representing the menu structure (eg @@ -114,6 +117,11 @@ void ro_gui_interactive_help_request(wimp_message *message) { sprintf(message_token, "HelpGHistory%i", ro_gui_global_history_help(message_data->pos.x, message_data->pos.y)); + else if ((cookies_tree) && + (window == (wimp_w)cookies_tree->handle)) + sprintf(message_token, "HelpGHistory%i", + ro_gui_cookies_help(message_data->pos.x, + message_data->pos.y)); else if ((g = ro_gui_window_lookup(window)) != NULL) sprintf(message_token, "HelpBrowser%i", (int)icon); @@ -153,6 +161,8 @@ void ro_gui_interactive_help_request(wimp_message *message) { sprintf(message_token, "HelpHotlistMenu"); else if (current_menu == global_history_menu) sprintf(message_token, "HelpGHistoryMenu"); + else if (current_menu == cookies_menu) + sprintf(message_token, "HelpCookiesMenu"); else return; diff --git a/riscos/history.c b/riscos/history.c index ce8d5a75d..89d7d4bfc 100644 --- a/riscos/history.c +++ b/riscos/history.c @@ -71,6 +71,8 @@ void ro_gui_history_open(struct browser_window *bw, os_box box = {0, 0, 0, 0}; wimp_window_state state; os_error *error; + + assert(history); history_current = history; history_bw = bw; @@ -164,7 +166,7 @@ void ro_gui_history_mouse_at(wimp_pointer *pointer) wimp_icon_state ic; os_box box = {0, 0, 0, 0}; os_error *error; - + /* If the mouse hasn't moved, or if we don't want tooltips, exit */ if ((mouse_x == pointer->pos.x && mouse_y == pointer->pos.y) || !option_history_tooltip) diff --git a/riscos/menus.c b/riscos/menus.c index bef46b201..0d71b6f3b 100644 --- a/riscos/menus.c +++ b/riscos/menus.c @@ -23,10 +23,12 @@ #include "netsurf/content/urldb.h" #include "netsurf/desktop/gui.h" #include "netsurf/desktop/history_core.h" +#include "netsurf/desktop/netsurf.h" #include "netsurf/render/box.h" #include "netsurf/riscos/dialog.h" #include "netsurf/render/form.h" #include "netsurf/riscos/configure.h" +#include "netsurf/riscos/cookies.h" #include "netsurf/riscos/gui.h" #include "netsurf/riscos/global_history.h" #include "netsurf/riscos/help.h" @@ -129,7 +131,7 @@ static wimp_i current_menu_icon; /** The height of the iconbar menu */ int iconbar_menu_height = 5 * 44; /** The available menus */ -wimp_menu *iconbar_menu, *browser_menu, *hotlist_menu, *global_history_menu, +wimp_menu *iconbar_menu, *browser_menu, *hotlist_menu, *global_history_menu, *cookies_menu, *image_quality_menu, *browser_toolbar_menu, *tree_toolbar_menu, *proxy_type_menu, *languages_menu; /** URL suggestion menu */ @@ -148,7 +150,7 @@ wimp_menu *url_suggest_menu = (wimp_menu *)&url_suggest; void ro_gui_menu_init(void) { /* iconbar menu */ - NS_MENU(9) iconbar_definition = { + NS_MENU(10) iconbar_definition = { "NetSurf", { { "Info", NO_ACTION, dialog_info }, { "AppHelp", HELP_OPEN_CONTENTS, 0 }, @@ -156,6 +158,7 @@ void ro_gui_menu_init(void) { "Open.OpenURL", BROWSER_NAVIGATE_URL, dialog_openurl }, { "Open.HotlistShow", HOTLIST_SHOW, 0 }, { "Open.HistGlobal", HISTORY_SHOW_GLOBAL, 0 }, + { "Open.ShowCookies", COOKIES_SHOW, 0 }, { "Choices", CHOICES_SHOW, 0 }, { "Quit", APPLICATION_QUIT, 0 }, {NULL, 0, 0} @@ -165,7 +168,7 @@ void ro_gui_menu_init(void) (struct ns_menu *)&iconbar_definition); /* browser menu */ - NS_MENU(66) browser_definition = { + NS_MENU(68) browser_definition = { "NetSurf", { { "Page", BROWSER_PAGE, 0 }, { "Page.PageInfo",BROWSER_PAGE_INFO, dialog_pageinfo }, @@ -220,6 +223,8 @@ void ro_gui_menu_init(void) { "Utilities.History", HISTORY_SHOW_GLOBAL, 0 }, { "Utilities.History.HistLocal", HISTORY_SHOW_LOCAL, 0 }, { "Utilities.History.HistGlobal", HISTORY_SHOW_GLOBAL, 0 }, + { "Utilities.Cookies", COOKIES_SHOW, 0 }, + { "Utilities.Cookies.ShowCookies", COOKIES_SHOW, 0 }, { "Utilities.FindText", BROWSER_FIND_TEXT, dialog_search }, { "Utilities.Window", NO_ACTION, 0 }, { "Utilities.Window.WindowSave", BROWSER_WINDOW_DEFAULT, 0 }, @@ -296,6 +301,30 @@ void ro_gui_menu_init(void) global_history_menu = ro_gui_menu_define_menu( (struct ns_menu *)&global_history_definition); + /* history menu */ + NS_MENU(17) 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_menu = ro_gui_menu_define_menu( + (struct ns_menu *)&cookies_definition); /* image quality menu */ NS_MENU(5) images_definition = { "Display", { @@ -1321,14 +1350,20 @@ menu_action ro_gui_menu_find_action(wimp_menu *menu, wimp_menu_entry *menu_entry */ void ro_gui_menu_set_entry_shaded(wimp_menu *menu, menu_action action, bool shaded) { - struct menu_definition_entry *entry = - ro_gui_menu_find_entry(menu, action); - if (entry) { - if (shaded) - entry->menu_entry->icon_flags |= wimp_ICON_SHADED; - else - entry->menu_entry->icon_flags &= ~wimp_ICON_SHADED; - } + struct menu_definition_entry *entry; + struct menu_definition *definition = ro_gui_menu_find_menu(menu); + + if (!definition) + return; + + /* we can't use find_entry as multiple actions may appear in one menu */ + for (entry = definition->entries; entry; entry = entry->next) + if (entry->action == action) { + if (shaded) + entry->menu_entry->icon_flags |= wimp_ICON_SHADED; + else + entry->menu_entry->icon_flags &= ~wimp_ICON_SHADED; + } } @@ -1430,6 +1465,11 @@ bool ro_gui_menu_handle_action(wimp_w owner, menu_action action, ro_gui_tree_show(hotlist_tree); return true; + /* cookies actions */ + case COOKIES_SHOW: + ro_gui_tree_show(cookies_tree); + return true; + /* page actions */ case BROWSER_PAGE_INFO: if (!c) @@ -1787,6 +1827,12 @@ void ro_gui_menu_prepare_action(wimp_w owner, menu_action action, !hotlist_tree); break; + /* cookies actions */ + case COOKIES_SHOW: + ro_gui_menu_set_entry_shaded(current_menu, action, + !cookies_tree); + break; + /* page actions */ case BROWSER_PAGE_INFO: ro_gui_menu_set_entry_shaded(current_menu, @@ -2072,6 +2118,15 @@ void ro_gui_menu_prepare_action(wimp_w owner, menu_action action, if ((tree) && (tree->root)) ro_gui_menu_set_entry_shaded(current_menu, action, !tree->root->child); + if ((t) && (!t->editor) && + (t->type != THEME_BROWSER_TOOLBAR)) { + ro_gui_set_icon_shaded_state( + t->toolbar_handle, + ICON_TOOLBAR_EXPAND, !tree->root->child); + ro_gui_set_icon_shaded_state( + t->toolbar_handle, + ICON_TOOLBAR_OPEN, !tree->root->child); + } break; case TREE_SELECTION: if ((!tree) || (!tree->root)) @@ -2196,6 +2251,8 @@ void ro_gui_menu_get_window_details(wimp_w w, struct gui_window **g, else if ((global_history_tree) && (w == (wimp_w)global_history_tree->handle)) *tree = global_history_tree; + else if ((cookies_tree) && (w == (wimp_w)cookies_tree->handle)) + *tree = cookies_tree; else *tree = NULL; if (*tree) diff --git a/riscos/menus.h b/riscos/menus.h index 9ac7fcaf4..9b68fcf8a 100644 --- a/riscos/menus.h +++ b/riscos/menus.h @@ -12,7 +12,7 @@ #include "oslib/wimp.h" #include "netsurf/riscos/gui.h" -extern wimp_menu *iconbar_menu, *browser_menu, *hotlist_menu, +extern wimp_menu *iconbar_menu, *browser_menu, *hotlist_menu, *cookies_menu, *global_history_menu, *image_quality_menu, *browser_toolbar_menu, *tree_toolbar_menu, *proxy_type_menu; extern wimp_menu *languages_menu, *url_suggest_menu; @@ -40,6 +40,9 @@ typedef enum { HOTLIST_ADD_URL, HOTLIST_SHOW, + /* cookie actions */ + COOKIES_SHOW, + /* page actions */ BROWSER_PAGE, BROWSER_PAGE_INFO, diff --git a/riscos/options.h b/riscos/options.h index 176924b8f..6f6dec4b5 100644 --- a/riscos/options.h +++ b/riscos/options.h @@ -32,6 +32,7 @@ extern bool option_toolbar_show_throbber; extern char *option_toolbar_browser; extern char *option_toolbar_hotlist; extern char *option_toolbar_history; +extern char *option_toolbar_cookies; extern int option_window_x; extern int option_window_y; extern int option_window_width; @@ -78,6 +79,7 @@ bool option_toolbar_show_throbber = true; \ char *option_toolbar_browser = 0; \ char *option_toolbar_hotlist = 0; \ char *option_toolbar_history = 0; \ +char *option_toolbar_cookies = 0; \ int option_window_x = 0; \ int option_window_y = 0; \ int option_window_width = 0; \ @@ -124,6 +126,7 @@ bool option_thumbnail_iconise = true; { "toolbar_browser", OPTION_STRING, &option_toolbar_browser }, \ { "toolbar_hotlist", OPTION_STRING, &option_toolbar_hotlist }, \ { "toolbar_history", OPTION_STRING, &option_toolbar_history }, \ +{ "toolbar_cookies", OPTION_STRING, &option_toolbar_cookies }, \ { "window_x", OPTION_INTEGER, &option_window_x }, \ { "window_y", OPTION_INTEGER, &option_window_y }, \ { "window_width", OPTION_INTEGER, &option_window_width }, \ diff --git a/riscos/save.c b/riscos/save.c index 1039f0440..3ca898c29 100644 --- a/riscos/save.c +++ b/riscos/save.c @@ -24,6 +24,7 @@ #include "oslib/osspriteop.h" #include "oslib/wimp.h" #include "oslib/wimpspriteop.h" +#include "netsurf/desktop/netsurf.h" #include "netsurf/desktop/save_text.h" #include "netsurf/desktop/selection.h" #include "netsurf/image/bitmap.h" diff --git a/riscos/theme.c b/riscos/theme.c index 5016e7e75..2c7f44f2b 100644 --- a/riscos/theme.c +++ b/riscos/theme.c @@ -25,6 +25,7 @@ #include "oslib/wimp.h" #include "oslib/wimpextend.h" #include "oslib/wimpspriteop.h" +#include "netsurf/desktop/gui.h" #include "netsurf/riscos/dialog.h" #include "netsurf/riscos/gui.h" #include "netsurf/riscos/menus.h" @@ -54,6 +55,8 @@ static const char * theme_hotlist_icons[] = {"delete", "expand", "open", "launch", "create", NULL}; static const char * theme_history_icons[] = {"delete", "expand", "open", "launch", NULL}; +static const char * theme_cookies_icons[] = {"delete", "expand", "open", + NULL}; static bool ro_gui_theme_add_descriptor(const char *folder, const char *leafname); static void ro_gui_theme_redraw(wimp_draw *redraw); @@ -779,6 +782,11 @@ struct toolbar *ro_gui_theme_create_toolbar(struct theme_descriptor *descriptor, theme_history_icons, option_toolbar_history); break; + case THEME_COOKIES_TOOLBAR: + ro_gui_theme_add_toolbar_icons(toolbar, + theme_cookies_icons, + option_toolbar_cookies); + break; case THEME_BROWSER_EDIT_TOOLBAR: ro_gui_theme_add_toolbar_icons(toolbar, theme_browser_icons, @@ -794,6 +802,11 @@ struct toolbar *ro_gui_theme_create_toolbar(struct theme_descriptor *descriptor, theme_history_icons, "0123|"); break; + case THEME_COOKIES_EDIT_TOOLBAR: + ro_gui_theme_add_toolbar_icons(toolbar, + theme_cookies_icons, + "012|"); + break; } /* Claim the memory for our Wimp indirection @@ -877,7 +890,8 @@ bool ro_gui_theme_update_toolbar(struct theme_descriptor *descriptor, if ((toolbar->editor) || (toolbar->type == THEME_HOTLIST_EDIT_TOOLBAR) || (toolbar->type == THEME_HISTORY_EDIT_TOOLBAR) || - (toolbar->type == THEME_BROWSER_EDIT_TOOLBAR)) + (toolbar->type == THEME_BROWSER_EDIT_TOOLBAR) || + (toolbar->type == THEME_COOKIES_EDIT_TOOLBAR)) theme_toolbar_window.work_flags |= (wimp_BUTTON_CLICK_DRAG << wimp_ICON_BUTTON_TYPE_SHIFT); theme_toolbar_window.flags &= ~wimp_WINDOW_AUTO_REDRAW; @@ -916,6 +930,8 @@ bool ro_gui_theme_update_toolbar(struct theme_descriptor *descriptor, case THEME_HOTLIST_EDIT_TOOLBAR: case THEME_HISTORY_TOOLBAR: case THEME_HISTORY_EDIT_TOOLBAR: + case THEME_COOKIES_TOOLBAR: + case THEME_COOKIES_EDIT_TOOLBAR: ro_gui_wimp_event_register_mouse_click(toolbar->toolbar_handle, ro_gui_tree_toolbar_click); break; @@ -929,6 +945,9 @@ bool ro_gui_theme_update_toolbar(struct theme_descriptor *descriptor, else if ((toolbar->type == THEME_HISTORY_TOOLBAR) || (toolbar->type == THEME_HISTORY_EDIT_TOOLBAR)) max_icon = ICON_TOOLBAR_HISTORY_LAST; + else if ((toolbar->type == THEME_COOKIES_TOOLBAR) || + (toolbar->type == THEME_COOKIES_EDIT_TOOLBAR)) + max_icon = ICON_TOOLBAR_COOKIES_LAST; else max_icon = ICON_TOOLBAR_LAST; new_icon.w = toolbar->toolbar_handle; @@ -939,6 +958,7 @@ bool ro_gui_theme_update_toolbar(struct theme_descriptor *descriptor, if ((toolbar->editor) || (toolbar->type == THEME_HOTLIST_EDIT_TOOLBAR) || (toolbar->type == THEME_HISTORY_EDIT_TOOLBAR) || + (toolbar->type == THEME_COOKIES_EDIT_TOOLBAR) || (toolbar->type == THEME_BROWSER_EDIT_TOOLBAR)) new_icon.icon.flags |= (wimp_BUTTON_CLICK_DRAG << wimp_ICON_BUTTON_TYPE_SHIFT); @@ -1174,8 +1194,11 @@ bool ro_gui_theme_update_toolbar(struct theme_descriptor *descriptor, break; case THEME_HOTLIST_TOOLBAR: case THEME_HISTORY_TOOLBAR: + case THEME_COOKIES_TOOLBAR: ro_gui_menu_prepare_action(toolbar->parent_handle, TREE_SELECTION, false); + ro_gui_menu_prepare_action(toolbar->parent_handle, + TREE_EXPAND_ALL, false); break; default: break; @@ -1822,6 +1845,10 @@ void ro_gui_theme_toggle_edit(struct toolbar *toolbar) { free(option_toolbar_history); option_toolbar_history = option; break; + case THEME_COOKIES_TOOLBAR: + free(option_toolbar_cookies); + option_toolbar_cookies = option; + break; default: break; } @@ -1862,6 +1889,11 @@ void ro_gui_theme_toggle_edit(struct toolbar *toolbar) { toolbar->descriptor, THEME_HISTORY_EDIT_TOOLBAR); break; + case THEME_COOKIES_TOOLBAR: + toolbar->editor = ro_gui_theme_create_toolbar( + toolbar->descriptor, + THEME_COOKIES_EDIT_TOOLBAR); + break; default: return; } @@ -2385,9 +2417,14 @@ void ro_gui_theme_set_help_prefix(struct toolbar *toolbar) { ro_gui_wimp_event_set_help_prefix(toolbar->toolbar_handle, "HelpGHistToolbar"); break; + case THEME_COOKIES_TOOLBAR: + ro_gui_wimp_event_set_help_prefix(toolbar->toolbar_handle, + "HelpCookiesToolbar"); + break; case THEME_BROWSER_EDIT_TOOLBAR: case THEME_HOTLIST_EDIT_TOOLBAR: case THEME_HISTORY_EDIT_TOOLBAR: + case THEME_COOKIES_EDIT_TOOLBAR: ro_gui_wimp_event_set_help_prefix(toolbar->toolbar_handle, "HelpEditToolbar"); break; diff --git a/riscos/theme.h b/riscos/theme.h index d5ba81956..7b7d209b7 100644 --- a/riscos/theme.h +++ b/riscos/theme.h @@ -1,7 +1,7 @@ /* * This file is part of NetSurf, http://netsurf.sourceforge.net/ * Licensed under the GNU General Public License, - * http://www.opensource.org/licenses/gpl-license + * http://www.opensource.org/licenses/gpl-license * Copyright 2005 Richard Wilson */ @@ -38,6 +38,7 @@ #define ICON_TOOLBAR_DELETE 0 #define ICON_TOOLBAR_EXPAND 1 #define ICON_TOOLBAR_OPEN 2 +#define ICON_TOOLBAR_COOKIES_LAST 4 #define ICON_TOOLBAR_LAUNCH 3 #define ICON_TOOLBAR_HISTORY_LAST 4 #define ICON_TOOLBAR_CREATE 4 // must be after last history icon @@ -47,14 +48,17 @@ #define ICON_TOOLBAR_SEPARATOR_BROWSER 11 #define ICON_TOOLBAR_SEPARATOR_HOTLIST 5 #define ICON_TOOLBAR_SEPARATOR_HISTORY 4 +#define ICON_TOOLBAR_SEPARATOR_COOKIES 3 typedef enum { - THEME_BROWSER_TOOLBAR, - THEME_HOTLIST_TOOLBAR, - THEME_HISTORY_TOOLBAR, - THEME_BROWSER_EDIT_TOOLBAR, - THEME_HOTLIST_EDIT_TOOLBAR, - THEME_HISTORY_EDIT_TOOLBAR + THEME_BROWSER_TOOLBAR, + THEME_HOTLIST_TOOLBAR, + THEME_HISTORY_TOOLBAR, + THEME_COOKIES_TOOLBAR, + THEME_BROWSER_EDIT_TOOLBAR, + THEME_HOTLIST_EDIT_TOOLBAR, + THEME_HISTORY_EDIT_TOOLBAR, + THEME_COOKIES_EDIT_TOOLBAR } toolbar_type; struct theme_file_header { @@ -113,13 +117,13 @@ struct toolbar { char *status_buffer; /**< buffer for status text (read only) */ struct toolbar_icon *icon; /**< first toolbar icon (read only) */ struct toolbar_icon *suggest; /**< suggestion toolbar icon (read only) */ - struct theme_descriptor *descriptor; /**< theme descriptor (read only) */ + struct theme_descriptor *descriptor; /**< theme descriptor (read only) */ toolbar_type type; /**< toolbar type (read only) */ struct toolbar *editor; /**< toolbar editor */ }; struct theme_descriptor { - char *leafname; /**< theme leafname */ + char *leafname; /**< theme leafname */ char *filename; /**< theme filename */ char name[32]; /**< theme name */ char author[64]; /**< theme author */ diff --git a/riscos/treeview.c b/riscos/treeview.c index 7a8b9788f..f6f7903d3 100644 --- a/riscos/treeview.c +++ b/riscos/treeview.c @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -31,6 +32,7 @@ #include "netsurf/riscos/menus.h" #include "netsurf/riscos/theme.h" #include "netsurf/riscos/tinct.h" +#include "netsurf/riscos/textarea.h" #include "netsurf/riscos/treeview.h" #include "netsurf/riscos/wimp.h" #include "netsurf/riscos/wimp_event.h" @@ -561,14 +563,12 @@ void tree_update_URL_node(struct node *node, element = tree_find_element(node, TREE_ELEMENT_LAST_VISIT); if (element) { - if (data->last_visit > 0) { - snprintf(buffer, 256, messages_get("TreeLast"), - ctime((time_t *)&data->last_visit)); - buffer[strlen(buffer) - 1] = '\0'; - } else { - snprintf(buffer, 256, messages_get("TreeLast"), + snprintf(buffer, 256, messages_get("TreeLast"), + (data->last_visit > 0) ? + ctime((time_t *)&data->last_visit) : messages_get("TreeUnknown")); - } + if (data->last_visit > 0) + buffer[strlen(buffer) - 1] = '\0'; free(element->text); element->text = strdup(buffer); } @@ -916,6 +916,7 @@ void ro_gui_tree_menu_closed(struct tree *tree) { tree_handle_node_element_changed(tree, &tree->temp_selection->data); tree->temp_selection = NULL; ro_gui_menu_prepare_action((wimp_w)tree->handle, TREE_SELECTION, false); + ro_gui_menu_prepare_action((wimp_w)tree->handle, TREE_EXPAND_ALL, false); } } @@ -990,10 +991,8 @@ bool ro_gui_tree_toolbar_click(wimp_pointer* pointer) { void ro_gui_tree_start_edit(struct tree *tree, struct node_element *element, wimp_pointer *pointer) { os_error *error; - wimp_window_state state; struct node *parent; int toolbar_height = 0; - int caret_x, caret_height, caret_index; assert(tree); assert(element); @@ -1014,8 +1013,6 @@ void ro_gui_tree_start_edit(struct tree *tree, struct node_element *element, } tree->editing = element; - snprintf(tree->edit_buffer, 256, element->text); - tree->edit_buffer[255] = '\0'; ro_gui_tree_edit_icon.w = (wimp_w)tree->handle; ro_gui_tree_edit_icon.icon.extent.x0 = tree->offset_x + element->box.x - 2; ro_gui_tree_edit_icon.icon.extent.x1 = tree->offset_x + @@ -1026,32 +1023,26 @@ void ro_gui_tree_start_edit(struct tree *tree, struct node_element *element, element->box.y - element->box.height; if (element->type == NODE_ELEMENT_TEXT_PLUS_SPRITE) ro_gui_tree_edit_icon.icon.extent.x0 += NODE_INSTEP; - ro_gui_tree_edit_icon.icon.data.indirected_text.text = tree->edit_buffer; + ro_gui_tree_edit_icon.icon.data.indirected_text.text = element->text; error = xwimp_create_icon(&ro_gui_tree_edit_icon, (wimp_i *)&tree->edit_handle); if (error) LOG(("xwimp_create_icon: 0x%x: %s", error->errnum, error->errmess)); - if (pointer) { - state.w = (wimp_w)tree->handle; - error = xwimp_get_window_state(&state); - if (error) - LOG(("xwimp_get_window_state: 0x%x: %s", - error->errnum, error->errmess)); - caret_x = pointer->pos.x - state.visible.x0; - caret_height = element->box.height; - caret_index = -1; - } else { - caret_x = 0; - caret_height = -1; - caret_index = strlen(tree->edit_buffer); + + tree->textarea_handle = textarea_create((wimp_w)tree->handle, + (wimp_i)tree->edit_handle, 0, "Homerton", 192); + if (!tree->textarea_handle) { + ro_gui_tree_stop_edit(tree); + return; } - error = xwimp_set_caret_position((wimp_w)tree->handle, - (wimp_i)tree->edit_handle, - caret_x, 0, caret_height, caret_index); - if (error) - LOG(("xwimp_set_caret_position: 0x%x: %s", - error->errnum, error->errmess)); + textarea_set_text(tree->textarea_handle, element->text); + if (pointer) + textarea_set_caret_xy(tree->textarea_handle, + pointer->pos.x, pointer->pos.y); + else + textarea_set_caret(tree->textarea_handle, strlen(element->text)); + tree_handle_node_element_changed(tree, element); ro_gui_tree_scroll_visible(tree, element); } @@ -1069,6 +1060,10 @@ void ro_gui_tree_stop_edit(struct tree *tree) { if (!tree->editing) return; + if (tree->textarea_handle) { + textarea_destroy(tree->textarea_handle); + tree->textarea_handle = 0; + } error = xwimp_delete_icon((wimp_w)tree->handle, (wimp_i)tree->edit_handle); if (error) LOG(("xwimp_delete_icon: 0x%x: %s", @@ -1200,6 +1195,7 @@ void ro_gui_tree_open(wimp_open *open) { if (tree->toolbar) ro_gui_theme_process_toolbar(tree->toolbar, -1); ro_gui_menu_prepare_action((wimp_w)tree->handle, TREE_SELECTION, false); + ro_gui_menu_prepare_action((wimp_w)tree->handle, TREE_EXPAND_ALL, false); } @@ -1213,6 +1209,7 @@ void ro_gui_tree_open(wimp_open *open) { bool ro_gui_tree_keypress(wimp_key *key) { char *new_string; struct tree *tree; + int strlen; tree = (struct tree *)ro_gui_wimp_event_get_user_data(key->w); if (!tree) @@ -1234,15 +1231,24 @@ bool ro_gui_tree_keypress(wimp_key *key) { TREE_CLEAR_SELECTION, false); return true; case wimp_KEY_RETURN: - if (tree->editing) { - new_string = strdup(tree->edit_buffer); - if (new_string) { - if (tree->editing->text) { - free(tree->editing->text); - tree->editing->text = NULL; - } - tree->editing->text = new_string; - } + if ((tree->editing) && (tree->textarea_handle)) { + strlen = textarea_get_text(tree->textarea_handle, + NULL, 0); + if (strlen == -1) { + ro_gui_tree_stop_edit(tree); + return true; + } + new_string = malloc(strlen); + if (!new_string) { + ro_gui_tree_stop_edit(tree); + LOG(("No memory for malloc()")); + warn_user("NoMemory", 0); + return true; + } + textarea_get_text(tree->textarea_handle, + new_string, strlen); + free(tree->editing->text); + tree->editing->text = new_string; ro_gui_tree_stop_edit(tree); tree_recalculate_size(tree); } else { @@ -1304,6 +1310,8 @@ void ro_gui_tree_selection_drag_end(wimp_dragged *drag) { (ro_gui_tree_current_drag_buttons == (wimp_CLICK_ADJUST << 4))); ro_gui_menu_prepare_action((wimp_w)ro_gui_tree_current_drag_tree->handle, TREE_SELECTION, false); + ro_gui_menu_prepare_action((wimp_w)ro_gui_tree_current_drag_tree->handle, + TREE_EXPAND_ALL, false); } diff --git a/riscos/url_complete.h b/riscos/url_complete.h index 8c5233919..03d101bca 100644 --- a/riscos/url_complete.h +++ b/riscos/url_complete.h @@ -13,7 +13,9 @@ #define _NETSURF_RISCOS_URLCOMPLETE_H_ #include -#include "netsurf/riscos/gui.h" +#include "oslib/wimp.h" + +struct gui_window; void ro_gui_url_complete_start(struct gui_window *g); bool ro_gui_url_complete_keypress(struct gui_window *g, int key); diff --git a/riscos/window.c b/riscos/window.c index 121c43766..78532da91 100644 --- a/riscos/window.c +++ b/riscos/window.c @@ -36,6 +36,7 @@ #include "netsurf/desktop/knockout.h" #include "netsurf/desktop/plotters.h" #include "netsurf/desktop/textinput.h" +#include "netsurf/desktop/tree.h" #include "netsurf/desktop/gui.h" #include "netsurf/render/box.h" #include "netsurf/render/form.h" -- cgit v1.2.3