Add basic cookie viewer, make trees use textarea components for UTF8 editing, trim headers, fix tree redraw issues.

svn path=/trunk/netsurf/; revision=2739
This commit is contained in:
Richard Wilson 2006-07-13 12:46:02 +00:00
parent d4331fa64f
commit a836591435
27 changed files with 716 additions and 140 deletions

View File

@ -82,6 +82,7 @@
#include "netsurf/image/bitmap.h" #include "netsurf/image/bitmap.h"
#include "netsurf/content/urldb.h" #include "netsurf/content/urldb.h"
#include "netsurf/desktop/cookies.h"
#include "netsurf/desktop/options.h" #include "netsurf/desktop/options.h"
#ifdef riscos #ifdef riscos
/** \todo lose this */ /** \todo lose this */
@ -91,7 +92,7 @@
#include "netsurf/utils/url.h" #include "netsurf/utils/url.h"
#include "netsurf/utils/utils.h" #include "netsurf/utils/utils.h"
struct cookie { struct cookie_internal_data {
char *name; /**< Cookie name */ char *name; /**< Cookie name */
char *value; /**< Cookie value */ char *value; /**< Cookie value */
char *comment; /**< Cookie comment */ char *comment; /**< Cookie comment */
@ -102,15 +103,12 @@ struct cookie {
time_t expires; /**< Expiry timestamp, or 1 for session */ time_t expires; /**< Expiry timestamp, or 1 for session */
time_t last_used; /**< Last used time */ time_t last_used; /**< Last used time */
bool secure; /**< Only send for HTTPS requests */ bool secure; /**< Only send for HTTPS requests */
enum { COOKIE_NETSCAPE = 0, cookie_version version; /**< Specification compliance */
COOKIE_RFC2109 = 1,
COOKIE_RFC2965 = 2
} version; /**< Specification compliance */
bool no_destroy; /**< Never destroy this cookie, bool no_destroy; /**< Never destroy this cookie,
* unless it's expired */ * unless it's expired */
struct cookie *prev; /**< Previous in list */ struct cookie_internal_data *prev; /**< Previous in list */
struct cookie *next; /**< Next in list */ struct cookie_internal_data *next; /**< Next in list */
}; };
struct auth_data { struct auth_data {
@ -138,7 +136,7 @@ struct path_data {
struct bitmap *thumb; /**< Thumbnail image of resource */ struct bitmap *thumb; /**< Thumbnail image of resource */
struct url_internal_data urld; /**< URL data for resource */ struct url_internal_data urld; /**< URL data for resource */
struct auth_data auth; /**< Authentication data for resource */ struct auth_data auth; /**< Authentication data for resource */
struct cookie *cookies; /**< Cookies associated with resource */ struct cookie_internal_data *cookies; /**< Cookies associated with resource */
struct path_data *next; /**< Next sibling */ struct path_data *next; /**< Next sibling */
struct path_data *prev; /**< Previous sibling */ struct path_data *prev; /**< Previous sibling */
@ -189,11 +187,11 @@ static bool urldb_iterate_partial_path(const struct path_data *parent,
const char *prefix, bool (*callback)(const char *url, const char *prefix, bool (*callback)(const char *url,
const struct url_data *data)); const struct url_data *data));
static bool urldb_iterate_entries_host(struct search_node *parent, static bool urldb_iterate_entries_host(struct search_node *parent,
bool (*callback)(const char *url, bool (*url_callback)(const char *url, const struct url_data *data),
const struct url_data *data)); bool (*cookie_callback)(const struct cookie_data *data));
static bool urldb_iterate_entries_path(const struct path_data *parent, static bool urldb_iterate_entries_path(const struct path_data *parent,
bool (*callback)(const char *url, bool (*url_callback)(const char *url, const struct url_data *data),
const struct url_data *data)); bool (*cookie_callback)(const struct cookie_data *data));
/* Insertion */ /* Insertion */
static struct host_part *urldb_add_host_node(const char *part, static struct host_part *urldb_add_host_node(const char *part,
@ -239,13 +237,13 @@ static int urldb_search_match_prefix(const struct host_part *a,
const char *b); const char *b);
/* Cookies */ /* Cookies */
static struct cookie *urldb_parse_cookie(const char *url, static struct cookie_internal_data *urldb_parse_cookie(const char *url,
const char **cookie); const char **cookie);
static bool urldb_parse_avpair(struct cookie *c, char *n, char *v); static bool urldb_parse_avpair(struct cookie_internal_data *c, char *n, char *v);
static bool urldb_insert_cookie(struct cookie *c, const char *scheme, static bool urldb_insert_cookie(struct cookie_internal_data *c, const char *scheme,
const char *url); const char *url);
static void urldb_free_cookie(struct cookie *c); static void urldb_free_cookie(struct cookie_internal_data *c);
static bool urldb_concat_cookie(struct cookie *c, int *used, static bool urldb_concat_cookie(struct cookie_internal_data *c, int *used,
int *alloc, char **buf); int *alloc, char **buf);
static void urldb_save_cookie_hosts(FILE *fp, struct host_part *parent); static void urldb_save_cookie_hosts(FILE *fp, struct host_part *parent);
static void urldb_save_cookie_paths(FILE *fp, struct path_data *parent); static void urldb_save_cookie_paths(FILE *fp, struct path_data *parent);
@ -1225,7 +1223,7 @@ bool urldb_iterate_partial_host(struct search_node *root, const char *prefix,
if (root->data->paths.children) { if (root->data->paths.children) {
/* and extract all paths attached to this host */ /* and extract all paths attached to this host */
if (!urldb_iterate_entries_path(&root->data->paths, if (!urldb_iterate_entries_path(&root->data->paths,
callback)) { callback, NULL)) {
return false; return false;
} }
} }
@ -1274,7 +1272,7 @@ bool urldb_iterate_partial_path(const struct path_data *parent,
if (slash == end) { if (slash == end) {
/* we've run out of prefix, so all /* we've run out of prefix, so all
* paths below this one match */ * paths below this one match */
if (!urldb_iterate_entries_path(p, callback)) if (!urldb_iterate_entries_path(p, callback, NULL))
return false; return false;
} else { } else {
/* more prefix to go => recurse */ /* more prefix to go => recurse */
@ -1301,7 +1299,25 @@ void urldb_iterate_entries(bool (*callback)(const char *url,
for (i = 0; i < NUM_SEARCH_TREES; i++) { for (i = 0; i < NUM_SEARCH_TREES; i++) {
if (!urldb_iterate_entries_host(search_trees[i], if (!urldb_iterate_entries_host(search_trees[i],
callback)) callback, NULL))
break;
}
}
/**
* Iterate over all cookies in database
*
* \param callback Function to callback for each entry
*/
void urldb_iterate_cookies(bool (*callback)(const struct cookie_data *data))
{
int i;
assert(callback);
for (i = 0; i < NUM_SEARCH_TREES; i++) {
if (!urldb_iterate_entries_host(search_trees[i],
NULL, callback))
break; break;
} }
} }
@ -1310,28 +1326,29 @@ void urldb_iterate_entries(bool (*callback)(const char *url,
* Host data iterator (internal) * Host data iterator (internal)
* *
* \param parent Root of subtree to iterate over * \param parent Root of subtree to iterate over
* \param callback Callback function * \param url_callback Callback function
* \param cookie_callback Callback function
* \return true to continue, false otherwise * \return true to continue, false otherwise
*/ */
bool urldb_iterate_entries_host(struct search_node *parent, bool urldb_iterate_entries_host(struct search_node *parent,
bool (*callback)(const char *url, bool (*url_callback)(const char *url, const struct url_data *data),
const struct url_data *data)) bool (*cookie_callback)(const struct cookie_data *data))
{ {
if (parent == &empty) if (parent == &empty)
return true; return true;
if (!urldb_iterate_entries_host(parent->left, callback)) if (!urldb_iterate_entries_host(parent->left, url_callback, cookie_callback))
return false; return false;
if (parent->data->paths.children) { if ((parent->data->paths.children) || ((cookie_callback) && (parent->data->paths.cookies))) {
/* We have paths, so iterate them */ /* We have paths (or domain cookies), so iterate them */
if (!urldb_iterate_entries_path(&parent->data->paths, if (!urldb_iterate_entries_path(&parent->data->paths,
callback)) { url_callback, cookie_callback)) {
return false; return false;
} }
} }
if (!urldb_iterate_entries_host(parent->right, callback)) if (!urldb_iterate_entries_host(parent->right, url_callback, cookie_callback))
return false; return false;
return true; return true;
@ -1341,33 +1358,36 @@ bool urldb_iterate_entries_host(struct search_node *parent,
* Path data iterator (internal) * Path data iterator (internal)
* *
* \param parent Root of subtree to iterate over * \param parent Root of subtree to iterate over
* \param callback Callback function to call * \param url_callback Callback function
* \param cookie_callback Callback function
* \return true to continue, false otherwise * \return true to continue, false otherwise
*/ */
bool urldb_iterate_entries_path(const struct path_data *parent, bool urldb_iterate_entries_path(const struct path_data *parent,
bool (*callback)(const char *url, bool (*url_callback)(const char *url, const struct url_data *data),
const struct url_data *data)) bool (*cookie_callback)(const struct cookie_data *data))
{ {
const struct path_data *p; const struct path_data *p;
if (!parent->children) { if (!parent->children) {
/* leaf node */ /* leaf node */
/* All leaf nodes in the path tree should have an URL /* All leaf nodes in the path tree should have an URL or cookies
* attached to them. If this is not the case, it indicates * attached to them. If this is not the case, it indicates
* that there's a bug in the file loader/URL insertion code. * that there's a bug in the file loader/URL insertion code.
* Therefore, assert this here. */ * Therefore, assert this here. */
assert(parent->url); assert(parent->url || parent->cookies);
/** \todo handle fragments? */ /** \todo handle fragments? */
if (url_callback && parent->url && !url_callback(parent->url,
if (!callback(parent->url,
(const struct url_data *) &parent->urld)) (const struct url_data *) &parent->urld))
return false; return false;
if (cookie_callback && parent->cookies && !cookie_callback(
(const struct cookie_data *) parent->cookies))
return false;
} }
for (p = parent->children; p; p = p->next) { for (p = parent->children; p; p = p->next) {
if (!urldb_iterate_entries_path(p, callback)) if (!urldb_iterate_entries_path(p, url_callback, cookie_callback))
return false; return false;
} }
@ -2278,7 +2298,7 @@ char *urldb_get_cookie(const char *url, const char *referer)
{ {
const struct path_data *p, *q; const struct path_data *p, *q;
const struct host_part *h; const struct host_part *h;
struct cookie *c; struct cookie_internal_data *c;
int count = 0, version = COOKIE_RFC2965; int count = 0, version = COOKIE_RFC2965;
int ret_alloc = 4096, ret_used = 1; int ret_alloc = 4096, ret_used = 1;
char *path; char *path;
@ -2519,7 +2539,7 @@ bool urldb_set_cookie(const char *header, const char *url)
end = cur + strlen(cur) - 2 /* Trailing CRLF */; end = cur + strlen(cur) - 2 /* Trailing CRLF */;
do { do {
struct cookie *c; struct cookie_internal_data *c;
char *dot; char *dot;
c = urldb_parse_cookie(url, &cur); c = urldb_parse_cookie(url, &cur);
@ -2595,6 +2615,7 @@ bool urldb_set_cookie(const char *header, const char *url)
/* Now insert into database */ /* Now insert into database */
if (!urldb_insert_cookie(c, scheme, urlt)) if (!urldb_insert_cookie(c, scheme, urlt))
goto error; goto error;
cookies_update((struct cookie_data *)c);
} while (cur < end); } while (cur < end);
free(host); free(host);
@ -2620,9 +2641,9 @@ error:
* \param cookie Pointer to cookie string (updated on exit) * \param cookie Pointer to cookie string (updated on exit)
* \return Pointer to cookie structure (on heap, caller frees) or NULL * \return Pointer to cookie structure (on heap, caller frees) or NULL
*/ */
struct cookie *urldb_parse_cookie(const char *url, const char **cookie) struct cookie_internal_data *urldb_parse_cookie(const char *url, const char **cookie)
{ {
struct cookie *c; struct cookie_internal_data *c;
const char *cur; const char *cur;
char name[1024], value[4096]; char name[1024], value[4096];
char *n = name, *v = value; char *n = name, *v = value;
@ -2632,7 +2653,7 @@ struct cookie *urldb_parse_cookie(const char *url, const char **cookie)
assert(url && cookie && *cookie); assert(url && cookie && *cookie);
c = calloc(1, sizeof(struct cookie)); c = calloc(1, sizeof(struct cookie_internal_data));
if (!c) if (!c)
return NULL; return NULL;
@ -2779,7 +2800,7 @@ struct cookie *urldb_parse_cookie(const char *url, const char **cookie)
* \param v Value component * \param v Value component
* \return true on success, false on memory exhaustion * \return true on success, false on memory exhaustion
*/ */
bool urldb_parse_avpair(struct cookie *c, char *n, char *v) bool urldb_parse_avpair(struct cookie_internal_data *c, char *n, char *v)
{ {
int vlen; int vlen;
@ -2881,10 +2902,10 @@ bool urldb_parse_avpair(struct cookie *c, char *n, char *v)
* \param url URL (sans fragment) associated with cookie * \param url URL (sans fragment) associated with cookie
* \return true on success, false on memory exhaustion (c will be freed) * \return true on success, false on memory exhaustion (c will be freed)
*/ */
bool urldb_insert_cookie(struct cookie *c, const char *scheme, bool urldb_insert_cookie(struct cookie_internal_data *c, const char *scheme,
const char *url) const char *url)
{ {
struct cookie *d; struct cookie_internal_data *d;
const struct host_part *h; const struct host_part *h;
struct path_data *p; struct path_data *p;
@ -2977,7 +2998,7 @@ bool urldb_insert_cookie(struct cookie *c, const char *scheme,
* *
* \param c The cookie to free * \param c The cookie to free
*/ */
void urldb_free_cookie(struct cookie *c) void urldb_free_cookie(struct cookie_internal_data *c)
{ {
assert(c); assert(c);
@ -2998,7 +3019,7 @@ void urldb_free_cookie(struct cookie *c)
* \param buf Pointer to Pointer to buffer (updated) * \param buf Pointer to Pointer to buffer (updated)
* \return true on success, false on memory exhaustion * \return true on success, false on memory exhaustion
*/ */
bool urldb_concat_cookie(struct cookie *c, int *used, int *alloc, char **buf) bool urldb_concat_cookie(struct cookie_internal_data *c, int *used, int *alloc, char **buf)
{ {
int clen; int clen;
@ -3128,7 +3149,7 @@ void urldb_load_cookies(const char *filename)
assert(p <= end); assert(p <= end);
/* Now create cookie */ /* Now create cookie */
struct cookie *c = malloc(sizeof(struct cookie)); struct cookie_internal_data *c = malloc(sizeof(struct cookie_internal_data));
if (!c) if (!c)
break; break;
@ -3228,7 +3249,7 @@ void urldb_save_cookie_paths(FILE *fp, struct path_data *parent)
assert(fp && parent); assert(fp && parent);
if (parent->cookies) { if (parent->cookies) {
for (struct cookie *c = parent->cookies; c; c = c->next) { for (struct cookie_internal_data *c = parent->cookies; c; c = c->next) {
if (c->expires < now) if (c->expires < now)
/* Skip expired cookies */ /* Skip expired cookies */

View File

@ -16,6 +16,12 @@
#include <time.h> #include <time.h>
#include "netsurf/content/content_type.h" #include "netsurf/content/content_type.h"
typedef enum {
COOKIE_NETSCAPE = 0,
COOKIE_RFC2109 = 1,
COOKIE_RFC2965 = 2
} cookie_version;
struct url_data { struct url_data {
const char *title; /**< Resource title */ const char *title; /**< Resource title */
unsigned int visits; /**< Visit count */ unsigned int visits; /**< Visit count */
@ -23,6 +29,25 @@ struct url_data {
content_type type; /**< Type of resource */ content_type type; /**< Type of resource */
}; };
struct cookie_data {
const char *name; /**< Cookie name */
const char *value; /**< Cookie value */
const char *comment; /**< Cookie comment */
const bool domain_from_set; /**< Domain came from Set-Cookie: header */
const char *domain; /**< Domain */
const bool path_from_set; /**< Path came from Set-Cookie: header */
const char *path; /**< Path */
const time_t expires; /**< Expiry timestamp, or 1 for session */
const time_t last_used; /**< Last used time */
const bool secure; /**< Only send for HTTPS requests */
cookie_version version; /**< Specification compliance */
const bool no_destroy; /**< Never destroy this cookie,
* unless it's expired */
const struct cookie_data *prev; /**< Previous in list */
const struct cookie_data *next; /**< Next in list */
};
struct bitmap; struct bitmap;
/* Persistence support */ /* Persistence support */
@ -62,6 +87,7 @@ void urldb_iterate_partial(const char *prefix,
/* Iteration */ /* Iteration */
void urldb_iterate_entries(bool (*callback)(const char *url, void urldb_iterate_entries(bool (*callback)(const char *url,
const struct url_data *data)); const struct url_data *data));
void urldb_iterate_cookies(bool (*callback)(const struct cookie_data *cookie));
/* Debug */ /* Debug */
void urldb_dump(void); void urldb_dump(void);

21
desktop/cookies.h Normal file
View File

@ -0,0 +1,21 @@
/*
* 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 <info@tinct.net>
*/
/** \file
* Cookies (interface).
*/
#ifndef _NETSURF_DESKTOP_COOKIES_H_
#define _NETSURF_DESKTOP_COOKIES_H_
#include <stdbool.h>
struct cookie_data;
bool cookies_update(const struct cookie_data *data);
#endif

View File

@ -24,7 +24,7 @@
#ifndef _NETSURF_DESKTOP_OPTIONS_H_ #ifndef _NETSURF_DESKTOP_OPTIONS_H_
#define _NETSURF_DESKTOP_OPTIONS_H_ #define _NETSURF_DESKTOP_OPTIONS_H_
#include "netsurf/desktop/tree.h" struct tree;
enum { OPTION_HTTP_PROXY_AUTH_NONE = 0, OPTION_HTTP_PROXY_AUTH_BASIC = 1, enum { OPTION_HTTP_PROXY_AUTH_NONE = 0, OPTION_HTTP_PROXY_AUTH_BASIC = 1,
OPTION_HTTP_PROXY_AUTH_NTLM = 2 }; OPTION_HTTP_PROXY_AUTH_NTLM = 2 };

View File

@ -18,6 +18,7 @@
#include "netsurf/desktop/tree.h" #include "netsurf/desktop/tree.h"
#include "netsurf/desktop/options.h" #include "netsurf/desktop/options.h"
#include "netsurf/utils/log.h" #include "netsurf/utils/log.h"
#include "netsurf/utils/messages.h"
#include "netsurf/utils/utils.h" #include "netsurf/utils/utils.h"
static void tree_draw_node(struct tree *tree, struct node *node, int clip_x, static void tree_draw_node(struct tree *tree, struct node *node, int clip_x,
@ -33,6 +34,8 @@ static void tree_selected_to_processing(struct node *node);
void tree_clear_processing(struct node *node); void tree_clear_processing(struct node *node);
struct node *tree_move_processing_node(struct node *node, struct node *link, struct node *tree_move_processing_node(struct node *node, struct node *link,
bool before, bool first); bool before, bool first);
struct node *tree_create_leaf_node(struct node *parent, const char *title);
struct node *tree_create_leaf_node_shared(struct node *parent, const char *title);
static int tree_initialising = 0; static int tree_initialising = 0;
@ -726,6 +729,12 @@ void tree_draw_node(struct tree *tree, struct node *node, int clip_x, int clip_y
tree_draw_line(node->box.x + (NODE_INSTEP / 2), tree_draw_line(node->box.x + (NODE_INSTEP / 2),
node->data.box.y + node->data.box.height, 0, node->data.box.y + node->data.box.height, 0,
(40 / 2)); (40 / 2));
if ((node->parent) && (node->parent != tree->root) &&
(node->parent->child == node))
tree_draw_line(node->parent->box.x + (NODE_INSTEP / 2),
node->parent->data.box.y +
node->parent->data.box.height, 0,
(40 / 2));
tree_draw_line(node->box.x - (NODE_INSTEP / 2), tree_draw_line(node->box.x - (NODE_INSTEP / 2),
node->data.box.y + node->data.box.y +
node->data.box.height - (40 / 2), node->data.box.height - (40 / 2),
@ -895,13 +904,18 @@ void tree_delete_node(struct tree *tree, struct node *node, bool siblings) {
if (e->text) { if (e->text) {
/* we don't free non-editable titles or URLs */ /* we don't free non-editable titles or URLs */
if (node->editable) if ((node->editable) || (node->folder))
free(e->text); free(e->text);
else { else {
if (e->data == TREE_ELEMENT_URL) { if (e->data == TREE_ELEMENT_URL) {
/* reset URL characteristics */ /* reset URL characteristics */
urldb_reset_url_visit_data(e->text); urldb_reset_url_visit_data(e->text);
} }
/* if not already 'deleted' then delete cookie */
if (!node->deleted) {
/* todo: delete cookie data */
}
if (e->data != TREE_ELEMENT_TITLE && if (e->data != TREE_ELEMENT_TITLE &&
e->data != TREE_ELEMENT_URL) e->data != TREE_ELEMENT_URL)
@ -974,6 +988,33 @@ struct node *tree_create_leaf_node(struct node *parent, const char *title) {
node->data.type = NODE_ELEMENT_TEXT; node->data.type = NODE_ELEMENT_TEXT;
node->data.text = squash_whitespace(title); node->data.text = squash_whitespace(title);
node->data.data = TREE_ELEMENT_TITLE; node->data.data = TREE_ELEMENT_TITLE;
node->editable = true;
if (parent)
tree_link_node(parent, node, false);
return node;
}
/**
* Creates a leaf node with the specified title, and links it into the tree.
*
* \param parent the parent node, or NULL not to link
* \param title the node title
* \return the newly created node.
*/
struct node *tree_create_leaf_node_shared(struct node *parent, const char *title) {
struct node *node;
assert(title);
node = calloc(sizeof(struct node), 1);
if (!node) return NULL;
node->folder = false;
node->data.parent = node;
node->data.type = NODE_ELEMENT_TEXT;
node->data.text = title;
node->data.data = TREE_ELEMENT_TITLE;
node->editable = false;
if (parent) if (parent)
tree_link_node(parent, node, false); tree_link_node(parent, node, false);
return node; return node;
@ -1009,7 +1050,6 @@ struct node *tree_create_URL_node(struct node *parent,
node = tree_create_leaf_node(parent, title); node = tree_create_leaf_node(parent, title);
if (!node) if (!node)
return NULL; return NULL;
node->editable = true;
element = tree_create_node_element(node, TREE_ELEMENT_THUMBNAIL); element = tree_create_node_element(node, TREE_ELEMENT_THUMBNAIL);
if (element) if (element)
@ -1050,12 +1090,9 @@ struct node *tree_create_URL_node_shared(struct node *parent,
title = data->title; title = data->title;
else else
title = url; title = url;
node = tree_create_leaf_node(parent, title); node = tree_create_leaf_node_shared(parent, title);
if (!node) if (!node)
return NULL; return NULL;
free(node->data.text);
node->data.text = title;
node->editable = false;
element = tree_create_node_element(node, TREE_ELEMENT_THUMBNAIL); element = tree_create_node_element(node, TREE_ELEMENT_THUMBNAIL);
if (element) if (element)
@ -1073,6 +1110,102 @@ struct node *tree_create_URL_node_shared(struct node *parent,
} }
/**
* Creates a tree entry for a cookie, and links it into the tree.
*
* All information is used directly from the url_data, and as such cannot be
* edited and should never be freed.
*
* \param parent the node to link to
* \param url the URL
* \param data the cookie data to use
* \return the node created, or NULL for failure
*/
struct node *tree_create_cookie_node(struct node *parent,
const struct cookie_data *data) {
struct node *node;
struct node_element *element;
char buffer[256];
char buffer2[16];
node = tree_create_leaf_node(parent, data->name);
if (!node)
return NULL;
node->data.data = TREE_ELEMENT_NAME;
node->editable = false;
element = tree_create_node_element(node, TREE_ELEMENT_PERSISTENT);
if (element) {
snprintf(buffer, 256, messages_get("TreePersistent"),
data->no_destroy ? messages_get("Yes") : messages_get("No"));
element->text = strdup(buffer);
}
element = tree_create_node_element(node, TREE_ELEMENT_VERSION);
if (element) {
snprintf(buffer2, 16, "TreeVersion%i", data->version);
snprintf(buffer, 256, messages_get("TreeVersion"), messages_get(buffer2));
element->text = strdup(buffer);
}
element = tree_create_node_element(node, TREE_ELEMENT_SECURE);
if (element) {
snprintf(buffer, 256, messages_get("TreeSecure"),
data->secure ? messages_get("Yes") : messages_get("No"));
element->text = strdup(buffer);
}
element = tree_create_node_element(node, TREE_ELEMENT_LAST_USED);
if (element) {
snprintf(buffer, 256, messages_get("TreeLastUsed"),
(data->last_used > 0) ?
ctime(&data->last_used) : messages_get("TreeUnknown"));
if (data->last_used > 0)
buffer[strlen(buffer) - 1] = '\0';
element->text = strdup(buffer);
}
element = tree_create_node_element(node, TREE_ELEMENT_EXPIRES);
if (element) {
snprintf(buffer, 256, messages_get("TreeExpires"),
(data->expires > 0) ?
ctime(&data->expires) : messages_get("TreeUnknown"));
if (data->expires > 0)
buffer[strlen(buffer) - 1] = '\0';
element->text = strdup(buffer);
}
element = tree_create_node_element(node, TREE_ELEMENT_PATH);
if (element) {
snprintf(buffer, 256, messages_get("TreePath"), data->path,
data->path_from_set ? messages_get("TreeHeaders") : "");
element->text = strdup(buffer);
}
element = tree_create_node_element(node, TREE_ELEMENT_DOMAIN);
if (element) {
snprintf(buffer, 256, messages_get("TreeDomain"), data->domain,
data->domain_from_set ? messages_get("TreeHeaders") : "");
element->text = strdup(buffer);
}
if ((data->comment) && (strcmp(data->comment, ""))) {
LOG(("Comment: '%s'", data->comment));
element = tree_create_node_element(node, TREE_ELEMENT_COMMENT);
if (element) {
snprintf(buffer, 256, messages_get("TreeComment"), data->comment);
element->text = strdup(buffer);
}
}
element = tree_create_node_element(node, TREE_ELEMENT_VALUE);
if (element) {
snprintf(buffer, 256, messages_get("TreeValue"),
data->value ? data->value : messages_get("TreeUnused"));
element->text = strdup(buffer);
}
/* add version, last_used, expires,
* path, domain, comment, value */
tree_set_node_sprite(node, "small_xxx", "small_xxx");
tree_recalculate_node(node, false);
return node;
}
/** /**
* Creates an empty text node element and links it to a node. * Creates an empty text node element and links it to a node.
* *

View File

@ -13,8 +13,10 @@
#define _NETSURF_DESKTOP_TREE_H_ #define _NETSURF_DESKTOP_TREE_H_
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h>
struct url_data; struct url_data;
struct cookie_data;
typedef enum { typedef enum {
TREE_ELEMENT_URL, TREE_ELEMENT_URL,
@ -23,7 +25,17 @@ typedef enum {
TREE_ELEMENT_VISITS, TREE_ELEMENT_VISITS,
TREE_ELEMENT_VISITED, TREE_ELEMENT_VISITED,
TREE_ELEMENT_THUMBNAIL, TREE_ELEMENT_THUMBNAIL,
TREE_ELEMENT_TITLE TREE_ELEMENT_TITLE,
TREE_ELEMENT_NAME,
TREE_ELEMENT_VALUE,
TREE_ELEMENT_COMMENT,
TREE_ELEMENT_DOMAIN,
TREE_ELEMENT_PATH,
TREE_ELEMENT_EXPIRES,
TREE_ELEMENT_LAST_USED,
TREE_ELEMENT_SECURE,
TREE_ELEMENT_VERSION,
TREE_ELEMENT_PERSISTENT
} node_element_data; } node_element_data;
#define NODE_INSTEP 40 #define NODE_INSTEP 40
@ -85,9 +97,9 @@ struct tree {
int window_width; /* <-- Tree window width */ int window_width; /* <-- Tree window width */
int window_height; /* <-- Tree window height */ int window_height; /* <-- Tree window height */
int edit_handle; /* <-- Handle for editing information */ int edit_handle; /* <-- Handle for editing information */
uintptr_t textarea_handle; /* <-- Handle for UTF-8 textarea */
bool movable; /* <-- Whether nodes can be moved */ bool movable; /* <-- Whether nodes can be moved */
struct node_element *editing; /* <-- Node element being edited */ struct node_element *editing; /* <-- Node element being edited */
char edit_buffer[256]; /* <-- Editing buffer */
struct node *temp_selection; /* <-- Temporarily selected node */ struct node *temp_selection; /* <-- Temporarily selected node */
struct toolbar *toolbar; /* <-- Tree toolbar */ struct toolbar *toolbar; /* <-- Tree toolbar */
}; };
@ -114,7 +126,6 @@ void tree_draw(struct tree *tree, int clip_x, int clip_y, int clip_width,
void tree_link_node(struct node *link, struct node *node, bool before); void tree_link_node(struct node *link, struct node *node, bool before);
void tree_delink_node(struct node *node); void tree_delink_node(struct node *node);
struct node *tree_create_folder_node(struct node *parent, const char *title); struct node *tree_create_folder_node(struct node *parent, const char *title);
struct node *tree_create_leaf_node(struct node *parent, const char *title);
void tree_set_node_sprite(struct node *node, const char *sprite, void tree_set_node_sprite(struct node *node, const char *sprite,
const char *expanded); const char *expanded);
struct node *tree_create_URL_node(struct node *parent, struct node *tree_create_URL_node(struct node *parent,
@ -122,6 +133,8 @@ struct node *tree_create_URL_node(struct node *parent,
const char *title); const char *title);
struct node *tree_create_URL_node_shared(struct node *parent, struct node *tree_create_URL_node_shared(struct node *parent,
const char *url, const struct url_data *data); const char *url, const struct url_data *data);
struct node *tree_create_cookie_node(struct node *parent,
const struct cookie_data *data);
void tree_set_node_expanded(struct node *node, bool expanded); void tree_set_node_expanded(struct node *node, bool expanded);
void tree_set_node_selected(struct tree *tree, struct node *node, void tree_set_node_selected(struct tree *tree, struct node *node,
bool selected); bool selected);

View File

@ -326,3 +326,7 @@ char *url_to_path(const char *url)
return strdup(url + 5); return strdup(url + 5);
} }
bool cookies_update(const char *domain, const struct cookie_data *data)
{
retutn true;
}

View File

@ -33,7 +33,7 @@ OBJECTS_RISCOS = $(OBJECTS_COMMON) $(OBJECTS_IMAGE)
OBJECTS_RISCOS += browser.o history_core.o netsurf.o selection.o \ OBJECTS_RISCOS += browser.o history_core.o netsurf.o selection.o \
textinput.o version.o gesture_core.o # desktop/ textinput.o version.o gesture_core.o # desktop/
OBJECTS_RISCOS += 401login.o artworks.o assert.o awrender.o bitmap.o \ OBJECTS_RISCOS += 401login.o artworks.o assert.o awrender.o bitmap.o \
buffer.o configure.o debugwin.o \ buffer.o cookies.o configure.o debugwin.o \
dialog.o download.o draw.o filetype.o font.o \ dialog.o download.o draw.o filetype.o font.o \
global_history.o gui.o help.o history.o hotlist.o image.o \ global_history.o gui.o help.o history.o hotlist.o image.o \
menus.o message.o palettes.o plotters.o plugin.o print.o \ menus.o message.o palettes.o plotters.o plugin.o print.o \

201
riscos/cookies.c Normal file
View File

@ -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 <info@tinct.net>
*/
/** \file
* Cookies (implementation).
*/
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#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;
}

19
riscos/cookies.h Normal file
View File

@ -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 <info@tinct.net>
*/
/** \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

View File

@ -12,6 +12,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "oslib/wimp.h" #include "oslib/wimp.h"
#include "netsurf/content/content.h"
#include "netsurf/riscos/dialog.h" #include "netsurf/riscos/dialog.h"
#include "netsurf/riscos/wimp_event.h" #include "netsurf/riscos/wimp_event.h"
#include "netsurf/utils/log.h" #include "netsurf/utils/log.h"

View File

@ -24,6 +24,7 @@
#include "netsurf/desktop/netsurf.h" #include "netsurf/desktop/netsurf.h"
#include "netsurf/render/font.h" #include "netsurf/render/font.h"
#include "netsurf/riscos/configure.h" #include "netsurf/riscos/configure.h"
#include "netsurf/riscos/cookies.h"
#include "netsurf/riscos/dialog.h" #include "netsurf/riscos/dialog.h"
#include "netsurf/riscos/global_history.h" #include "netsurf/riscos/global_history.h"
#include "netsurf/riscos/gui.h" #include "netsurf/riscos/gui.h"
@ -102,6 +103,9 @@ void ro_gui_dialog_init(void)
/* global history window */ /* global history window */
ro_gui_global_history_initialise(); ro_gui_global_history_initialise();
/* cookies window */
ro_gui_cookies_initialise();
/* theme installation */ /* theme installation */
dialog_theme_install = ro_gui_dialog_create("theme_inst"); dialog_theme_install = ro_gui_dialog_create("theme_inst");
ro_gui_wimp_event_register_cancel(dialog_theme_install, ro_gui_wimp_event_register_cancel(dialog_theme_install,

View File

@ -32,6 +32,7 @@
#include "oslib/wimpspriteop.h" #include "oslib/wimpspriteop.h"
#include "netsurf/content/fetch.h" #include "netsurf/content/fetch.h"
#include "netsurf/desktop/gui.h" #include "netsurf/desktop/gui.h"
#include "netsurf/desktop/netsurf.h"
#include "netsurf/riscos/dialog.h" #include "netsurf/riscos/dialog.h"
#include "netsurf/riscos/options.h" #include "netsurf/riscos/options.h"
#include "netsurf/riscos/save.h" #include "netsurf/riscos/save.h"

View File

@ -90,7 +90,6 @@ void ro_gui_global_history_initialise(void)
} }
global_history_tree->root->expanded = true; global_history_tree->root->expanded = true;
ro_gui_global_history_initialise_nodes(); ro_gui_global_history_initialise_nodes();
tree_initialise(global_history_tree);
global_history_tree->handle = (int)global_history_window; global_history_tree->handle = (int)global_history_window;
global_history_tree->movable = false; global_history_tree->movable = false;
ro_gui_wimp_event_set_user_data(global_history_window, 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; global_history_init = true;
urldb_iterate_entries(global_history_add_internal); urldb_iterate_entries(global_history_add_internal);
global_history_init = false; global_history_init = false;
tree_initialise(global_history_tree);
} }
/** /**

View File

@ -321,9 +321,11 @@ void gui_init(int argc, char** argv)
if (!option_toolbar_browser) if (!option_toolbar_browser)
option_toolbar_browser = strdup("0123|58|9"); option_toolbar_browser = strdup("0123|58|9");
if (!option_toolbar_hotlist) if (!option_toolbar_hotlist)
option_toolbar_hotlist = strdup("401|23"); option_toolbar_hotlist = strdup("40|12|3");
if (!option_toolbar_history) 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) if (!option_ca_bundle)
option_ca_bundle = strdup("NetSurf:Resources.ca-bundle"); option_ca_bundle = strdup("NetSurf:Resources.ca-bundle");
if (!option_cookie_file) if (!option_cookie_file)

View File

@ -15,12 +15,9 @@
#include <oslib/osspriteop.h> #include <oslib/osspriteop.h>
#include <oslib/wimp.h> #include <oslib/wimp.h>
#include <rufl.h> #include <rufl.h>
#include "netsurf/utils/config.h"
#include "netsurf/desktop/browser.h" #include "netsurf/desktop/browser.h"
#include "netsurf/desktop/netsurf.h" #include "netsurf/content/content_type.h"
#include "netsurf/desktop/gui.h" #include "netsurf/utils/config.h"
#include "netsurf/desktop/options.h"
#include "netsurf/desktop/tree.h"
#define RISCOS5 0xAA #define RISCOS5 0xAA
@ -33,6 +30,11 @@ extern const char * NETSURF_DIR;
struct toolbar; struct toolbar;
struct plotter_table; 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. */ 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 osspriteop_area *gui_sprites;
extern bool dialog_folder_add, dialog_entry_add, hotlist_insert; extern bool dialog_folder_add, dialog_entry_add, hotlist_insert;
extern bool print_active, print_text_black; 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, typedef enum { GUI_DRAG_NONE, GUI_DRAG_SELECTION, GUI_DRAG_DOWNLOAD_SAVE,
GUI_DRAG_SAVE, GUI_DRAG_SCROLL, GUI_DRAG_STATUS_RESIZE, GUI_DRAG_SAVE, GUI_DRAG_SCROLL, GUI_DRAG_STATUS_RESIZE,

View File

@ -17,6 +17,7 @@
#include "oslib/taskmanager.h" #include "oslib/taskmanager.h"
#include "oslib/wimp.h" #include "oslib/wimp.h"
#include "netsurf/desktop/tree.h" #include "netsurf/desktop/tree.h"
#include "netsurf/riscos/cookies.h"
#include "netsurf/riscos/global_history.h" #include "netsurf/riscos/global_history.h"
#include "netsurf/riscos/gui.h" #include "netsurf/riscos/gui.h"
#include "netsurf/riscos/help.h" #include "netsurf/riscos/help.h"
@ -35,15 +36,17 @@
Help keys should be registered using the wimp_event system to be Help keys should be registered using the wimp_event system to be
recognised. The only special case help values are: recognised. The only special case help values are:
HelpIconbar Iconbar (no icon suffix is used) HelpIconbar Iconbar (no icon suffix is used)
HelpHotlist Hotlist window [*] HelpBrowser Browser window [*]
HelpGHistory Global history window [*] HelpHotlist Hotlist window [*]
HelpBrowser Browser window [*] HelpGHistory Global history window [*]
HelpCookies Cookies window [*]
HelpIconMenu Iconbar menu HelpIconMenu Iconbar menu
HelpBrowserMenu Browser window menu HelpBrowserMenu Browser window menu
HelpHotlistMenu Hotlist window menu HelpHotlistMenu Hotlist window menu
HelpGHistoryMenu Global history window menu HelpGHistoryMenu Global history window menu
HelpCookiesMenu Cookie window menu
The prefixes are followed by either the icon number (eg 'HelpToolbar7'), The prefixes are followed by either the icon number (eg 'HelpToolbar7'),
or a series of numbers representing the menu structure (eg 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", sprintf(message_token, "HelpGHistory%i",
ro_gui_global_history_help(message_data->pos.x, ro_gui_global_history_help(message_data->pos.x,
message_data->pos.y)); 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) else if ((g = ro_gui_window_lookup(window)) != NULL)
sprintf(message_token, "HelpBrowser%i", (int)icon); sprintf(message_token, "HelpBrowser%i", (int)icon);
@ -153,6 +161,8 @@ void ro_gui_interactive_help_request(wimp_message *message) {
sprintf(message_token, "HelpHotlistMenu"); sprintf(message_token, "HelpHotlistMenu");
else if (current_menu == global_history_menu) else if (current_menu == global_history_menu)
sprintf(message_token, "HelpGHistoryMenu"); sprintf(message_token, "HelpGHistoryMenu");
else if (current_menu == cookies_menu)
sprintf(message_token, "HelpCookiesMenu");
else else
return; return;

View File

@ -71,6 +71,8 @@ void ro_gui_history_open(struct browser_window *bw,
os_box box = {0, 0, 0, 0}; os_box box = {0, 0, 0, 0};
wimp_window_state state; wimp_window_state state;
os_error *error; os_error *error;
assert(history);
history_current = history; history_current = history;
history_bw = bw; history_bw = bw;
@ -164,7 +166,7 @@ void ro_gui_history_mouse_at(wimp_pointer *pointer)
wimp_icon_state ic; wimp_icon_state ic;
os_box box = {0, 0, 0, 0}; os_box box = {0, 0, 0, 0};
os_error *error; os_error *error;
/* If the mouse hasn't moved, or if we don't want tooltips, exit */ /* 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) || if ((mouse_x == pointer->pos.x && mouse_y == pointer->pos.y) ||
!option_history_tooltip) !option_history_tooltip)

View File

@ -23,10 +23,12 @@
#include "netsurf/content/urldb.h" #include "netsurf/content/urldb.h"
#include "netsurf/desktop/gui.h" #include "netsurf/desktop/gui.h"
#include "netsurf/desktop/history_core.h" #include "netsurf/desktop/history_core.h"
#include "netsurf/desktop/netsurf.h"
#include "netsurf/render/box.h" #include "netsurf/render/box.h"
#include "netsurf/riscos/dialog.h" #include "netsurf/riscos/dialog.h"
#include "netsurf/render/form.h" #include "netsurf/render/form.h"
#include "netsurf/riscos/configure.h" #include "netsurf/riscos/configure.h"
#include "netsurf/riscos/cookies.h"
#include "netsurf/riscos/gui.h" #include "netsurf/riscos/gui.h"
#include "netsurf/riscos/global_history.h" #include "netsurf/riscos/global_history.h"
#include "netsurf/riscos/help.h" #include "netsurf/riscos/help.h"
@ -129,7 +131,7 @@ static wimp_i current_menu_icon;
/** The height of the iconbar menu */ /** The height of the iconbar menu */
int iconbar_menu_height = 5 * 44; int iconbar_menu_height = 5 * 44;
/** The available menus */ /** 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, *image_quality_menu, *browser_toolbar_menu,
*tree_toolbar_menu, *proxy_type_menu, *languages_menu; *tree_toolbar_menu, *proxy_type_menu, *languages_menu;
/** URL suggestion menu */ /** URL suggestion menu */
@ -148,7 +150,7 @@ wimp_menu *url_suggest_menu = (wimp_menu *)&url_suggest;
void ro_gui_menu_init(void) void ro_gui_menu_init(void)
{ {
/* iconbar menu */ /* iconbar menu */
NS_MENU(9) iconbar_definition = { NS_MENU(10) iconbar_definition = {
"NetSurf", { "NetSurf", {
{ "Info", NO_ACTION, dialog_info }, { "Info", NO_ACTION, dialog_info },
{ "AppHelp", HELP_OPEN_CONTENTS, 0 }, { "AppHelp", HELP_OPEN_CONTENTS, 0 },
@ -156,6 +158,7 @@ void ro_gui_menu_init(void)
{ "Open.OpenURL", BROWSER_NAVIGATE_URL, dialog_openurl }, { "Open.OpenURL", BROWSER_NAVIGATE_URL, dialog_openurl },
{ "Open.HotlistShow", HOTLIST_SHOW, 0 }, { "Open.HotlistShow", HOTLIST_SHOW, 0 },
{ "Open.HistGlobal", HISTORY_SHOW_GLOBAL, 0 }, { "Open.HistGlobal", HISTORY_SHOW_GLOBAL, 0 },
{ "Open.ShowCookies", COOKIES_SHOW, 0 },
{ "Choices", CHOICES_SHOW, 0 }, { "Choices", CHOICES_SHOW, 0 },
{ "Quit", APPLICATION_QUIT, 0 }, { "Quit", APPLICATION_QUIT, 0 },
{NULL, 0, 0} {NULL, 0, 0}
@ -165,7 +168,7 @@ void ro_gui_menu_init(void)
(struct ns_menu *)&iconbar_definition); (struct ns_menu *)&iconbar_definition);
/* browser menu */ /* browser menu */
NS_MENU(66) browser_definition = { NS_MENU(68) browser_definition = {
"NetSurf", { "NetSurf", {
{ "Page", BROWSER_PAGE, 0 }, { "Page", BROWSER_PAGE, 0 },
{ "Page.PageInfo",BROWSER_PAGE_INFO, dialog_pageinfo }, { "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", HISTORY_SHOW_GLOBAL, 0 },
{ "Utilities.History.HistLocal", HISTORY_SHOW_LOCAL, 0 }, { "Utilities.History.HistLocal", HISTORY_SHOW_LOCAL, 0 },
{ "Utilities.History.HistGlobal", HISTORY_SHOW_GLOBAL, 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.FindText", BROWSER_FIND_TEXT, dialog_search },
{ "Utilities.Window", NO_ACTION, 0 }, { "Utilities.Window", NO_ACTION, 0 },
{ "Utilities.Window.WindowSave", BROWSER_WINDOW_DEFAULT, 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( global_history_menu = ro_gui_menu_define_menu(
(struct ns_menu *)&global_history_definition); (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 */ /* image quality menu */
NS_MENU(5) images_definition = { NS_MENU(5) images_definition = {
"Display", { "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, void ro_gui_menu_set_entry_shaded(wimp_menu *menu, menu_action action,
bool shaded) { bool shaded) {
struct menu_definition_entry *entry = struct menu_definition_entry *entry;
ro_gui_menu_find_entry(menu, action); struct menu_definition *definition = ro_gui_menu_find_menu(menu);
if (entry) {
if (shaded) if (!definition)
entry->menu_entry->icon_flags |= wimp_ICON_SHADED; return;
else
entry->menu_entry->icon_flags &= ~wimp_ICON_SHADED; /* 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); ro_gui_tree_show(hotlist_tree);
return true; return true;
/* cookies actions */
case COOKIES_SHOW:
ro_gui_tree_show(cookies_tree);
return true;
/* page actions */ /* page actions */
case BROWSER_PAGE_INFO: case BROWSER_PAGE_INFO:
if (!c) if (!c)
@ -1787,6 +1827,12 @@ void ro_gui_menu_prepare_action(wimp_w owner, menu_action action,
!hotlist_tree); !hotlist_tree);
break; break;
/* cookies actions */
case COOKIES_SHOW:
ro_gui_menu_set_entry_shaded(current_menu, action,
!cookies_tree);
break;
/* page actions */ /* page actions */
case BROWSER_PAGE_INFO: case BROWSER_PAGE_INFO:
ro_gui_menu_set_entry_shaded(current_menu, 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)) if ((tree) && (tree->root))
ro_gui_menu_set_entry_shaded(current_menu, ro_gui_menu_set_entry_shaded(current_menu,
action, !tree->root->child); 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; break;
case TREE_SELECTION: case TREE_SELECTION:
if ((!tree) || (!tree->root)) 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) && else if ((global_history_tree) &&
(w == (wimp_w)global_history_tree->handle)) (w == (wimp_w)global_history_tree->handle))
*tree = global_history_tree; *tree = global_history_tree;
else if ((cookies_tree) && (w == (wimp_w)cookies_tree->handle))
*tree = cookies_tree;
else else
*tree = NULL; *tree = NULL;
if (*tree) if (*tree)

View File

@ -12,7 +12,7 @@
#include "oslib/wimp.h" #include "oslib/wimp.h"
#include "netsurf/riscos/gui.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, *global_history_menu, *image_quality_menu,
*browser_toolbar_menu, *tree_toolbar_menu, *proxy_type_menu; *browser_toolbar_menu, *tree_toolbar_menu, *proxy_type_menu;
extern wimp_menu *languages_menu, *url_suggest_menu; extern wimp_menu *languages_menu, *url_suggest_menu;
@ -40,6 +40,9 @@ typedef enum {
HOTLIST_ADD_URL, HOTLIST_ADD_URL,
HOTLIST_SHOW, HOTLIST_SHOW,
/* cookie actions */
COOKIES_SHOW,
/* page actions */ /* page actions */
BROWSER_PAGE, BROWSER_PAGE,
BROWSER_PAGE_INFO, BROWSER_PAGE_INFO,

View File

@ -32,6 +32,7 @@ extern bool option_toolbar_show_throbber;
extern char *option_toolbar_browser; extern char *option_toolbar_browser;
extern char *option_toolbar_hotlist; extern char *option_toolbar_hotlist;
extern char *option_toolbar_history; extern char *option_toolbar_history;
extern char *option_toolbar_cookies;
extern int option_window_x; extern int option_window_x;
extern int option_window_y; extern int option_window_y;
extern int option_window_width; extern int option_window_width;
@ -78,6 +79,7 @@ bool option_toolbar_show_throbber = true; \
char *option_toolbar_browser = 0; \ char *option_toolbar_browser = 0; \
char *option_toolbar_hotlist = 0; \ char *option_toolbar_hotlist = 0; \
char *option_toolbar_history = 0; \ char *option_toolbar_history = 0; \
char *option_toolbar_cookies = 0; \
int option_window_x = 0; \ int option_window_x = 0; \
int option_window_y = 0; \ int option_window_y = 0; \
int option_window_width = 0; \ int option_window_width = 0; \
@ -124,6 +126,7 @@ bool option_thumbnail_iconise = true;
{ "toolbar_browser", OPTION_STRING, &option_toolbar_browser }, \ { "toolbar_browser", OPTION_STRING, &option_toolbar_browser }, \
{ "toolbar_hotlist", OPTION_STRING, &option_toolbar_hotlist }, \ { "toolbar_hotlist", OPTION_STRING, &option_toolbar_hotlist }, \
{ "toolbar_history", OPTION_STRING, &option_toolbar_history }, \ { "toolbar_history", OPTION_STRING, &option_toolbar_history }, \
{ "toolbar_cookies", OPTION_STRING, &option_toolbar_cookies }, \
{ "window_x", OPTION_INTEGER, &option_window_x }, \ { "window_x", OPTION_INTEGER, &option_window_x }, \
{ "window_y", OPTION_INTEGER, &option_window_y }, \ { "window_y", OPTION_INTEGER, &option_window_y }, \
{ "window_width", OPTION_INTEGER, &option_window_width }, \ { "window_width", OPTION_INTEGER, &option_window_width }, \

View File

@ -24,6 +24,7 @@
#include "oslib/osspriteop.h" #include "oslib/osspriteop.h"
#include "oslib/wimp.h" #include "oslib/wimp.h"
#include "oslib/wimpspriteop.h" #include "oslib/wimpspriteop.h"
#include "netsurf/desktop/netsurf.h"
#include "netsurf/desktop/save_text.h" #include "netsurf/desktop/save_text.h"
#include "netsurf/desktop/selection.h" #include "netsurf/desktop/selection.h"
#include "netsurf/image/bitmap.h" #include "netsurf/image/bitmap.h"

View File

@ -25,6 +25,7 @@
#include "oslib/wimp.h" #include "oslib/wimp.h"
#include "oslib/wimpextend.h" #include "oslib/wimpextend.h"
#include "oslib/wimpspriteop.h" #include "oslib/wimpspriteop.h"
#include "netsurf/desktop/gui.h"
#include "netsurf/riscos/dialog.h" #include "netsurf/riscos/dialog.h"
#include "netsurf/riscos/gui.h" #include "netsurf/riscos/gui.h"
#include "netsurf/riscos/menus.h" #include "netsurf/riscos/menus.h"
@ -54,6 +55,8 @@ static const char * theme_hotlist_icons[] = {"delete", "expand", "open",
"launch", "create", NULL}; "launch", "create", NULL};
static const char * theme_history_icons[] = {"delete", "expand", "open", static const char * theme_history_icons[] = {"delete", "expand", "open",
"launch", NULL}; "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 bool ro_gui_theme_add_descriptor(const char *folder, const char *leafname);
static void ro_gui_theme_redraw(wimp_draw *redraw); 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, theme_history_icons,
option_toolbar_history); option_toolbar_history);
break; break;
case THEME_COOKIES_TOOLBAR:
ro_gui_theme_add_toolbar_icons(toolbar,
theme_cookies_icons,
option_toolbar_cookies);
break;
case THEME_BROWSER_EDIT_TOOLBAR: case THEME_BROWSER_EDIT_TOOLBAR:
ro_gui_theme_add_toolbar_icons(toolbar, ro_gui_theme_add_toolbar_icons(toolbar,
theme_browser_icons, theme_browser_icons,
@ -794,6 +802,11 @@ struct toolbar *ro_gui_theme_create_toolbar(struct theme_descriptor *descriptor,
theme_history_icons, theme_history_icons,
"0123|"); "0123|");
break; 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 /* Claim the memory for our Wimp indirection
@ -877,7 +890,8 @@ bool ro_gui_theme_update_toolbar(struct theme_descriptor *descriptor,
if ((toolbar->editor) || if ((toolbar->editor) ||
(toolbar->type == THEME_HOTLIST_EDIT_TOOLBAR) || (toolbar->type == THEME_HOTLIST_EDIT_TOOLBAR) ||
(toolbar->type == THEME_HISTORY_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 << theme_toolbar_window.work_flags |= (wimp_BUTTON_CLICK_DRAG <<
wimp_ICON_BUTTON_TYPE_SHIFT); wimp_ICON_BUTTON_TYPE_SHIFT);
theme_toolbar_window.flags &= ~wimp_WINDOW_AUTO_REDRAW; 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_HOTLIST_EDIT_TOOLBAR:
case THEME_HISTORY_TOOLBAR: case THEME_HISTORY_TOOLBAR:
case THEME_HISTORY_EDIT_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_wimp_event_register_mouse_click(toolbar->toolbar_handle,
ro_gui_tree_toolbar_click); ro_gui_tree_toolbar_click);
break; break;
@ -929,6 +945,9 @@ bool ro_gui_theme_update_toolbar(struct theme_descriptor *descriptor,
else if ((toolbar->type == THEME_HISTORY_TOOLBAR) || else if ((toolbar->type == THEME_HISTORY_TOOLBAR) ||
(toolbar->type == THEME_HISTORY_EDIT_TOOLBAR)) (toolbar->type == THEME_HISTORY_EDIT_TOOLBAR))
max_icon = ICON_TOOLBAR_HISTORY_LAST; 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 else
max_icon = ICON_TOOLBAR_LAST; max_icon = ICON_TOOLBAR_LAST;
new_icon.w = toolbar->toolbar_handle; new_icon.w = toolbar->toolbar_handle;
@ -939,6 +958,7 @@ bool ro_gui_theme_update_toolbar(struct theme_descriptor *descriptor,
if ((toolbar->editor) || if ((toolbar->editor) ||
(toolbar->type == THEME_HOTLIST_EDIT_TOOLBAR) || (toolbar->type == THEME_HOTLIST_EDIT_TOOLBAR) ||
(toolbar->type == THEME_HISTORY_EDIT_TOOLBAR) || (toolbar->type == THEME_HISTORY_EDIT_TOOLBAR) ||
(toolbar->type == THEME_COOKIES_EDIT_TOOLBAR) ||
(toolbar->type == THEME_BROWSER_EDIT_TOOLBAR)) (toolbar->type == THEME_BROWSER_EDIT_TOOLBAR))
new_icon.icon.flags |= (wimp_BUTTON_CLICK_DRAG << new_icon.icon.flags |= (wimp_BUTTON_CLICK_DRAG <<
wimp_ICON_BUTTON_TYPE_SHIFT); wimp_ICON_BUTTON_TYPE_SHIFT);
@ -1174,8 +1194,11 @@ bool ro_gui_theme_update_toolbar(struct theme_descriptor *descriptor,
break; break;
case THEME_HOTLIST_TOOLBAR: case THEME_HOTLIST_TOOLBAR:
case THEME_HISTORY_TOOLBAR: case THEME_HISTORY_TOOLBAR:
case THEME_COOKIES_TOOLBAR:
ro_gui_menu_prepare_action(toolbar->parent_handle, ro_gui_menu_prepare_action(toolbar->parent_handle,
TREE_SELECTION, false); TREE_SELECTION, false);
ro_gui_menu_prepare_action(toolbar->parent_handle,
TREE_EXPAND_ALL, false);
break; break;
default: default:
break; break;
@ -1822,6 +1845,10 @@ void ro_gui_theme_toggle_edit(struct toolbar *toolbar) {
free(option_toolbar_history); free(option_toolbar_history);
option_toolbar_history = option; option_toolbar_history = option;
break; break;
case THEME_COOKIES_TOOLBAR:
free(option_toolbar_cookies);
option_toolbar_cookies = option;
break;
default: default:
break; break;
} }
@ -1862,6 +1889,11 @@ void ro_gui_theme_toggle_edit(struct toolbar *toolbar) {
toolbar->descriptor, toolbar->descriptor,
THEME_HISTORY_EDIT_TOOLBAR); THEME_HISTORY_EDIT_TOOLBAR);
break; break;
case THEME_COOKIES_TOOLBAR:
toolbar->editor = ro_gui_theme_create_toolbar(
toolbar->descriptor,
THEME_COOKIES_EDIT_TOOLBAR);
break;
default: default:
return; 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, ro_gui_wimp_event_set_help_prefix(toolbar->toolbar_handle,
"HelpGHistToolbar"); "HelpGHistToolbar");
break; break;
case THEME_COOKIES_TOOLBAR:
ro_gui_wimp_event_set_help_prefix(toolbar->toolbar_handle,
"HelpCookiesToolbar");
break;
case THEME_BROWSER_EDIT_TOOLBAR: case THEME_BROWSER_EDIT_TOOLBAR:
case THEME_HOTLIST_EDIT_TOOLBAR: case THEME_HOTLIST_EDIT_TOOLBAR:
case THEME_HISTORY_EDIT_TOOLBAR: case THEME_HISTORY_EDIT_TOOLBAR:
case THEME_COOKIES_EDIT_TOOLBAR:
ro_gui_wimp_event_set_help_prefix(toolbar->toolbar_handle, ro_gui_wimp_event_set_help_prefix(toolbar->toolbar_handle,
"HelpEditToolbar"); "HelpEditToolbar");
break; break;

View File

@ -1,7 +1,7 @@
/* /*
* This file is part of NetSurf, http://netsurf.sourceforge.net/ * This file is part of NetSurf, http://netsurf.sourceforge.net/
* Licensed under the GNU General Public License, * 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 <info@tinct.net> * Copyright 2005 Richard Wilson <info@tinct.net>
*/ */
@ -38,6 +38,7 @@
#define ICON_TOOLBAR_DELETE 0 #define ICON_TOOLBAR_DELETE 0
#define ICON_TOOLBAR_EXPAND 1 #define ICON_TOOLBAR_EXPAND 1
#define ICON_TOOLBAR_OPEN 2 #define ICON_TOOLBAR_OPEN 2
#define ICON_TOOLBAR_COOKIES_LAST 4
#define ICON_TOOLBAR_LAUNCH 3 #define ICON_TOOLBAR_LAUNCH 3
#define ICON_TOOLBAR_HISTORY_LAST 4 #define ICON_TOOLBAR_HISTORY_LAST 4
#define ICON_TOOLBAR_CREATE 4 // must be after last history icon #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_BROWSER 11
#define ICON_TOOLBAR_SEPARATOR_HOTLIST 5 #define ICON_TOOLBAR_SEPARATOR_HOTLIST 5
#define ICON_TOOLBAR_SEPARATOR_HISTORY 4 #define ICON_TOOLBAR_SEPARATOR_HISTORY 4
#define ICON_TOOLBAR_SEPARATOR_COOKIES 3
typedef enum { typedef enum {
THEME_BROWSER_TOOLBAR, THEME_BROWSER_TOOLBAR,
THEME_HOTLIST_TOOLBAR, THEME_HOTLIST_TOOLBAR,
THEME_HISTORY_TOOLBAR, THEME_HISTORY_TOOLBAR,
THEME_BROWSER_EDIT_TOOLBAR, THEME_COOKIES_TOOLBAR,
THEME_HOTLIST_EDIT_TOOLBAR, THEME_BROWSER_EDIT_TOOLBAR,
THEME_HISTORY_EDIT_TOOLBAR THEME_HOTLIST_EDIT_TOOLBAR,
THEME_HISTORY_EDIT_TOOLBAR,
THEME_COOKIES_EDIT_TOOLBAR
} toolbar_type; } toolbar_type;
struct theme_file_header { struct theme_file_header {
@ -113,13 +117,13 @@ struct toolbar {
char *status_buffer; /**< buffer for status text (read only) */ char *status_buffer; /**< buffer for status text (read only) */
struct toolbar_icon *icon; /**< first toolbar icon (read only) */ struct toolbar_icon *icon; /**< first toolbar icon (read only) */
struct toolbar_icon *suggest; /**< suggestion 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) */ toolbar_type type; /**< toolbar type (read only) */
struct toolbar *editor; /**< toolbar editor */ struct toolbar *editor; /**< toolbar editor */
}; };
struct theme_descriptor { struct theme_descriptor {
char *leafname; /**< theme leafname */ char *leafname; /**< theme leafname */
char *filename; /**< theme filename */ char *filename; /**< theme filename */
char name[32]; /**< theme name */ char name[32]; /**< theme name */
char author[64]; /**< theme author */ char author[64]; /**< theme author */

View File

@ -11,6 +11,7 @@
#include <assert.h> #include <assert.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <swis.h> #include <swis.h>
@ -31,6 +32,7 @@
#include "netsurf/riscos/menus.h" #include "netsurf/riscos/menus.h"
#include "netsurf/riscos/theme.h" #include "netsurf/riscos/theme.h"
#include "netsurf/riscos/tinct.h" #include "netsurf/riscos/tinct.h"
#include "netsurf/riscos/textarea.h"
#include "netsurf/riscos/treeview.h" #include "netsurf/riscos/treeview.h"
#include "netsurf/riscos/wimp.h" #include "netsurf/riscos/wimp.h"
#include "netsurf/riscos/wimp_event.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); element = tree_find_element(node, TREE_ELEMENT_LAST_VISIT);
if (element) { if (element) {
if (data->last_visit > 0) { snprintf(buffer, 256, messages_get("TreeLast"),
snprintf(buffer, 256, messages_get("TreeLast"), (data->last_visit > 0) ?
ctime((time_t *)&data->last_visit)); ctime((time_t *)&data->last_visit) :
buffer[strlen(buffer) - 1] = '\0';
} else {
snprintf(buffer, 256, messages_get("TreeLast"),
messages_get("TreeUnknown")); messages_get("TreeUnknown"));
} if (data->last_visit > 0)
buffer[strlen(buffer) - 1] = '\0';
free(element->text); free(element->text);
element->text = strdup(buffer); 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_handle_node_element_changed(tree, &tree->temp_selection->data);
tree->temp_selection = NULL; 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_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, void ro_gui_tree_start_edit(struct tree *tree, struct node_element *element,
wimp_pointer *pointer) { wimp_pointer *pointer) {
os_error *error; os_error *error;
wimp_window_state state;
struct node *parent; struct node *parent;
int toolbar_height = 0; int toolbar_height = 0;
int caret_x, caret_height, caret_index;
assert(tree); assert(tree);
assert(element); assert(element);
@ -1014,8 +1013,6 @@ void ro_gui_tree_start_edit(struct tree *tree, struct node_element *element,
} }
tree->editing = 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.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.x0 = tree->offset_x + element->box.x - 2;
ro_gui_tree_edit_icon.icon.extent.x1 = tree->offset_x + 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; element->box.y - element->box.height;
if (element->type == NODE_ELEMENT_TEXT_PLUS_SPRITE) if (element->type == NODE_ELEMENT_TEXT_PLUS_SPRITE)
ro_gui_tree_edit_icon.icon.extent.x0 += NODE_INSTEP; 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, error = xwimp_create_icon(&ro_gui_tree_edit_icon,
(wimp_i *)&tree->edit_handle); (wimp_i *)&tree->edit_handle);
if (error) if (error)
LOG(("xwimp_create_icon: 0x%x: %s", LOG(("xwimp_create_icon: 0x%x: %s",
error->errnum, error->errmess)); error->errnum, error->errmess));
if (pointer) {
state.w = (wimp_w)tree->handle; tree->textarea_handle = textarea_create((wimp_w)tree->handle,
error = xwimp_get_window_state(&state); (wimp_i)tree->edit_handle, 0, "Homerton", 192);
if (error) if (!tree->textarea_handle) {
LOG(("xwimp_get_window_state: 0x%x: %s", ro_gui_tree_stop_edit(tree);
error->errnum, error->errmess)); return;
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);
} }
error = xwimp_set_caret_position((wimp_w)tree->handle, textarea_set_text(tree->textarea_handle, element->text);
(wimp_i)tree->edit_handle, if (pointer)
caret_x, 0, caret_height, caret_index); textarea_set_caret_xy(tree->textarea_handle,
if (error) pointer->pos.x, pointer->pos.y);
LOG(("xwimp_set_caret_position: 0x%x: %s", else
error->errnum, error->errmess)); textarea_set_caret(tree->textarea_handle, strlen(element->text));
tree_handle_node_element_changed(tree, element); tree_handle_node_element_changed(tree, element);
ro_gui_tree_scroll_visible(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->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); error = xwimp_delete_icon((wimp_w)tree->handle, (wimp_i)tree->edit_handle);
if (error) if (error)
LOG(("xwimp_delete_icon: 0x%x: %s", LOG(("xwimp_delete_icon: 0x%x: %s",
@ -1200,6 +1195,7 @@ void ro_gui_tree_open(wimp_open *open) {
if (tree->toolbar) if (tree->toolbar)
ro_gui_theme_process_toolbar(tree->toolbar, -1); 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_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) { bool ro_gui_tree_keypress(wimp_key *key) {
char *new_string; char *new_string;
struct tree *tree; struct tree *tree;
int strlen;
tree = (struct tree *)ro_gui_wimp_event_get_user_data(key->w); tree = (struct tree *)ro_gui_wimp_event_get_user_data(key->w);
if (!tree) if (!tree)
@ -1234,15 +1231,24 @@ bool ro_gui_tree_keypress(wimp_key *key) {
TREE_CLEAR_SELECTION, false); TREE_CLEAR_SELECTION, false);
return true; return true;
case wimp_KEY_RETURN: case wimp_KEY_RETURN:
if (tree->editing) { if ((tree->editing) && (tree->textarea_handle)) {
new_string = strdup(tree->edit_buffer); strlen = textarea_get_text(tree->textarea_handle,
if (new_string) { NULL, 0);
if (tree->editing->text) { if (strlen == -1) {
free(tree->editing->text); ro_gui_tree_stop_edit(tree);
tree->editing->text = NULL; return true;
} }
tree->editing->text = new_string; 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); ro_gui_tree_stop_edit(tree);
tree_recalculate_size(tree); tree_recalculate_size(tree);
} else { } 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_tree_current_drag_buttons == (wimp_CLICK_ADJUST << 4)));
ro_gui_menu_prepare_action((wimp_w)ro_gui_tree_current_drag_tree->handle, ro_gui_menu_prepare_action((wimp_w)ro_gui_tree_current_drag_tree->handle,
TREE_SELECTION, false); TREE_SELECTION, false);
ro_gui_menu_prepare_action((wimp_w)ro_gui_tree_current_drag_tree->handle,
TREE_EXPAND_ALL, false);
} }

View File

@ -13,7 +13,9 @@
#define _NETSURF_RISCOS_URLCOMPLETE_H_ #define _NETSURF_RISCOS_URLCOMPLETE_H_
#include <stdbool.h> #include <stdbool.h>
#include "netsurf/riscos/gui.h" #include "oslib/wimp.h"
struct gui_window;
void ro_gui_url_complete_start(struct gui_window *g); void ro_gui_url_complete_start(struct gui_window *g);
bool ro_gui_url_complete_keypress(struct gui_window *g, int key); bool ro_gui_url_complete_keypress(struct gui_window *g, int key);

View File

@ -36,6 +36,7 @@
#include "netsurf/desktop/knockout.h" #include "netsurf/desktop/knockout.h"
#include "netsurf/desktop/plotters.h" #include "netsurf/desktop/plotters.h"
#include "netsurf/desktop/textinput.h" #include "netsurf/desktop/textinput.h"
#include "netsurf/desktop/tree.h"
#include "netsurf/desktop/gui.h" #include "netsurf/desktop/gui.h"
#include "netsurf/render/box.h" #include "netsurf/render/box.h"
#include "netsurf/render/form.h" #include "netsurf/render/form.h"