summaryrefslogtreecommitdiff
path: root/riscos
diff options
context:
space:
mode:
Diffstat (limited to 'riscos')
-rw-r--r--riscos/gui.c2
-rw-r--r--riscos/gui.h2
-rw-r--r--riscos/menus.c2
-rw-r--r--riscos/save.c67
-rw-r--r--riscos/save_complete.c759
-rw-r--r--riscos/search.c813
-rw-r--r--riscos/searchweb.c (renamed from riscos/save_complete.h)16
-rw-r--r--riscos/window.c15
8 files changed, 286 insertions, 1390 deletions
diff --git a/riscos/gui.c b/riscos/gui.c
index 594488341..3fa95eaca 100644
--- a/riscos/gui.c
+++ b/riscos/gui.c
@@ -57,6 +57,7 @@
#include "desktop/gui.h"
#include "desktop/netsurf.h"
#include "desktop/options.h"
+#include "desktop/save_complete.h"
#include "desktop/tree.h"
#include "render/box.h"
#include "render/font.h"
@@ -76,7 +77,6 @@
#include "riscos/print.h"
#include "riscos/query.h"
#include "riscos/save.h"
-#include "riscos/save_complete.h"
#include "riscos/textselection.h"
#include "riscos/theme.h"
#include "riscos/treeview.h"
diff --git a/riscos/gui.h b/riscos/gui.h
index 2eaf7cb27..f7ddedd73 100644
--- a/riscos/gui.h
+++ b/riscos/gui.h
@@ -199,7 +199,7 @@ void ro_gui_debugwin_open(void);
/* in search.c */
void ro_gui_search_init(void);
-void ro_gui_search_prepare(struct gui_window *g);
+void ro_gui_search_prepare(struct browser_window *g);
bool ro_gui_search_prepare_menu(void);
/* in print.c */
diff --git a/riscos/menus.c b/riscos/menus.c
index ab286a1c9..3e6fe7615 100644
--- a/riscos/menus.c
+++ b/riscos/menus.c
@@ -2284,7 +2284,7 @@ void ro_gui_menu_prepare_action(wimp_w owner, menu_action action,
ro_gui_menu_set_entry_shaded(current_menu,
action, result);
if ((!result) && (windows)) {
- ro_gui_search_prepare(g);
+ ro_gui_search_prepare(g->bw);
}
if ((t) && (!t->editor) &&
(t->type == THEME_BROWSER_TOOLBAR))
diff --git a/riscos/save.c b/riscos/save.c
index 292c46194..44a2b1835 100644
--- a/riscos/save.c
+++ b/riscos/save.c
@@ -35,7 +35,9 @@
#include "oslib/osspriteop.h"
#include "oslib/wimp.h"
#include "oslib/wimpspriteop.h"
+#include "content/content.h"
#include "desktop/netsurf.h"
+#include "desktop/save_complete.h"
#include "desktop/save_text.h"
#include "desktop/selection.h"
#include "image/bitmap.h"
@@ -48,7 +50,6 @@
#include "riscos/options.h"
#include "riscos/query.h"
#include "riscos/save.h"
-#include "riscos/save_complete.h"
#include "riscos/save_draw.h"
#include "riscos/save_pdf.h"
#include "riscos/textselection.h"
@@ -988,6 +989,70 @@ void ro_gui_save_done(void)
gui_save_content = 0;
}
+/**
+* conducts the filesystem save appropriate to the gui
+* \param path save path
+* \param filename name of file to save
+* \param len data length
+* \param sourcedata pointer to data to save, NULL when all data in c
+* \param type content type
+* \return true for success
+*/
+
+bool save_complete_gui_save(const char *path, const char *filename, size_t len,
+ const char *sourcedata, content_type type)
+{
+ char *fullpath;
+ os_error *error;
+ int namelen = strlen(path) + strlen(filename) + 2;
+ int rotype;
+ fullpath = malloc(namelen);
+ if (fullpath == NULL) {
+ warn_user("NoMemory", 0);
+ return false;
+ }
+ snprintf(fullpath, namelen, "%s.%s", path, filename);
+ rotype = ro_content_filetype_from_type(type);
+ error = xosfile_save_stamped(fullpath, rotype, (byte *) sourcedata,
+ (byte *) sourcedata + len);
+ free(fullpath);
+ if (error) {
+ LOG(("xosfile_save_stamped: 0x%x: %s",
+ error->errnum, error->errmess));
+ warn_user("SaveError", error->errmess);
+ return false;
+ }
+ return true;
+}
+
+/**
+* wrapper for lib function htmlSaveFileFormat; front sets path from
+* path + filename in a filesystem-specific way
+*/
+
+int save_complete_htmlSaveFileFormat(const char *path, const char *filename,
+ xmlDocPtr cur, const char *encoding, int format)
+{
+ os_error *error;
+ int ret;
+ int len = strlen(path) + strlen(filename) + 2;
+ char *fullpath = malloc(len);
+ if (fullpath == NULL){
+ warn_user("NoMemory", 0);
+ return -1;
+ }
+ snprintf(fullpath, len, "%s.%s", path, filename);
+ ret = htmlSaveFileFormat(fullpath, cur, encoding, format);
+ error = xosfile_set_type(fullpath, 0xFAF);
+ if (error) {
+ LOG(("xosfile_save_stamped: 0x%x: %s",
+ error->errnum, error->errmess));
+ warn_user("SaveError", error->errmess);
+ return false;
+ }
+ free(fullpath);
+ return ret;
+}
/**
* Prepare an application directory and save_complete() to it.
diff --git a/riscos/save_complete.c b/riscos/save_complete.c
deleted file mode 100644
index 3ac559784..000000000
--- a/riscos/save_complete.c
+++ /dev/null
@@ -1,759 +0,0 @@
-/*
- * Copyright 2004 John M Bell <jmb202@ecs.soton.ac.uk>
- * Copyright 2004-2007 James Bursa <bursa@users.sourceforge.net>
- *
- * This file is part of NetSurf, http://www.netsurf-browser.org/
- *
- * NetSurf is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * NetSurf is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/** \file
- * Save HTML document with dependencies (implementation).
- */
-
-#include "utils/config.h"
-
-#define _GNU_SOURCE /* for strndup */
-#include <assert.h>
-#include <ctype.h>
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <regex.h>
-#include <libxml/HTMLtree.h>
-#include <libxml/parserInternals.h>
-#include "oslib/osfile.h"
-#include "utils/config.h"
-#include "content/content.h"
-#include "css/css.h"
-#include "render/box.h"
-#include "riscos/gui.h"
-#include "riscos/save_complete.h"
-#include "utils/log.h"
-#include "utils/url.h"
-#include "utils/utils.h"
-
-regex_t save_complete_import_re;
-
-/** An entry in save_complete_list. */
-struct save_complete_entry {
- struct content *content;
- struct save_complete_entry *next; /**< Next entry in list */
-};
-
-/** List of urls seen and saved so far. */
-static struct save_complete_entry *save_complete_list = 0;
-
-static bool save_complete_html(struct content *c, const char *path,
- bool index);
-static bool save_imported_sheets(struct content *c, const char *path);
-static char * rewrite_stylesheet_urls(const char *source, unsigned int size,
- int *osize, const char *base);
-static bool rewrite_document_urls(xmlDoc *doc, const char *base);
-static bool rewrite_urls(xmlNode *n, const char *base);
-static bool rewrite_url(xmlNode *n, const char *attr, const char *base);
-static bool save_complete_list_add(struct content *content);
-static struct content * save_complete_list_find(const char *url);
-static bool save_complete_list_check(struct content *content);
-/* static void save_complete_list_dump(void); */
-static bool save_complete_inventory(const char *path);
-
-/**
- * Save an HTML page with all dependencies.
- *
- * \param c CONTENT_HTML to save
- * \param path directory to save to (must exist)
- * \return true on success, false on error and error reported
- */
-
-bool save_complete(struct content *c, const char *path)
-{
- bool result;
-
- result = save_complete_html(c, path, true);
-
- if (result)
- result = save_complete_inventory(path);
-
- /* free save_complete_list */
- while (save_complete_list) {
- struct save_complete_entry *next = save_complete_list->next;
- free(save_complete_list);
- save_complete_list = next;
- }
-
- return result;
-}
-
-
-/**
- * Save an HTML page with all dependencies, recursing through imported pages.
- *
- * \param c CONTENT_HTML to save
- * \param path directory to save to (must exist)
- * \param index true to save as "index"
- * \return true on success, false on error and error reported
- */
-
-bool save_complete_html(struct content *c, const char *path, bool index)
-{
- char spath[256];
- unsigned int i;
- xmlDocPtr doc;
- os_error *error;
-
- if (c->type != CONTENT_HTML)
- return false;
-
- if (save_complete_list_check(c))
- return true;
-
- /* save stylesheets, ignoring the base and adblocking sheets */
- for (i = STYLESHEET_START; i != c->data.html.stylesheet_count; i++) {
- struct content *css = c->data.html.stylesheets[i].c;
- char *source;
- int source_len;
- bool is_style;
-
- if (!css)
- continue;
- if (save_complete_list_check(css))
- continue;
-
- is_style = (strcmp(css->url, c->data.html.base_url) == 0);
-
- if (is_style == false) {
- if (!save_complete_list_add(css)) {
- warn_user("NoMemory", 0);
- return false;
- }
- }
-
- if (!save_imported_sheets(css, path))
- return false;
-
- if (is_style)
- continue; /* don't save <style> elements */
-
- snprintf(spath, sizeof spath, "%s.%x", path,
- (unsigned int) css);
- source = rewrite_stylesheet_urls(css->source_data,
- css->source_size, &source_len, css->url);
- if (!source) {
- warn_user("NoMemory", 0);
- return false;
- }
-
- error = xosfile_save_stamped(spath, 0xf79,
- (byte *) source, (byte *) source + source_len);
- free(source);
- if (error) {
- LOG(("xosfile_save_stamped: 0x%x: %s",
- error->errnum, error->errmess));
- warn_user("SaveError", error->errmess);
- return false;
- }
- }
-
- /* save objects */
- for (i = 0; i != c->data.html.object_count; i++) {
- struct content *obj = c->data.html.object[i].content;
-
- /* skip difficult content types */
- if (!obj || obj->type >= CONTENT_OTHER || !obj->source_data)
- continue;
- if (save_complete_list_check(obj))
- continue;
-
- if (!save_complete_list_add(obj)) {
- warn_user("NoMemory", 0);
- return false;
- }
-
- if (obj->type == CONTENT_HTML) {
- if (!save_complete_html(obj, path, false))
- return false;
- continue;
- }
-
- snprintf(spath, sizeof spath, "%s.%x", path,
- (unsigned int) obj);
- error = xosfile_save_stamped(spath,
- ro_content_filetype(obj),
- (byte *) obj->source_data,
- (byte *) obj->source_data + obj->source_size);
- if (error) {
- LOG(("xosfile_save_stamped: 0x%x: %s",
- error->errnum, error->errmess));
- warn_user("SaveError", error->errmess);
- return false;
- }
- }
-
- /*save_complete_list_dump();*/
-
- /* copy document */
- doc = xmlCopyDoc(c->data.html.document, 1);
- if (doc == NULL) {
- warn_user("NoMemory", 0);
- return false;
- }
-
- /* rewrite all urls we know about */
- if (!rewrite_document_urls(doc, c->data.html.base_url)) {
- xmlFreeDoc(doc);
- warn_user("NoMemory", 0);
- return false;
- }
-
- /* save the html file out last of all */
- if (index)
- snprintf(spath, sizeof spath, "%s.index", path);
- else
- snprintf(spath, sizeof spath, "%s.%x", path, (unsigned int)c);
-
- errno = 0;
- if (htmlSaveFileFormat(spath, doc, 0, 0) == -1) {
- if (errno)
- warn_user("SaveError", strerror(errno));
- else
- warn_user("SaveError", "htmlSaveFileFormat failed");
-
- xmlFreeDoc(doc);
- return false;
- }
-
- xmlFreeDoc(doc);
-
- error = xosfile_set_type(spath, 0xfaf);
- if (error) {
- LOG(("xosfile_set_type: 0x%x: %s",
- error->errnum, error->errmess));
- warn_user("SaveError", error->errmess);
- return false;
- }
-
- return true;
-}
-
-
-/**
- * Save stylesheets imported by a CONTENT_CSS.
- *
- * \param c a CONTENT_CSS
- * \param path path to save to
- * \return true on success, false on error and error reported
- */
-
-bool save_imported_sheets(struct content *c, const char *path)
-{
- char spath[256];
- unsigned int j;
- char *source;
- int source_len;
- os_error *error;
-
- for (j = 0; j != c->data.css.import_count; j++) {
- struct content *css = c->data.css.imports[j].c;
-
- if (!css)
- continue;
- if (save_complete_list_check(css))
- continue;
-
- if (!save_complete_list_add(css)) {
- warn_user("NoMemory", 0);
- return false;
- }
-
- if (!save_imported_sheets(css, path))
- return false;
-
- snprintf(spath, sizeof spath, "%s.%x", path,
- (unsigned int) css);
- source = rewrite_stylesheet_urls(css->source_data,
- css->source_size, &source_len, css->url);
- if (!source) {
- warn_user("NoMemory", 0);
- return false;
- }
-
- error = xosfile_save_stamped(spath, 0xf79,
- (byte *) source, (byte *) source + source_len);
- free(source);
- if (error) {
- LOG(("xosfile_save_stamped: 0x%x: %s",
- error->errnum, error->errmess));
- warn_user("SaveError", error->errmess);
- return false;
- }
- }
-
- return true;
-}
-
-
-/**
- * Initialise the save_complete module.
- */
-
-void save_complete_init(void)
-{
- /* Match an @import rule - see CSS 2.1 G.1. */
- regcomp_wrapper(&save_complete_import_re,
- "@import" /* IMPORT_SYM */
- "[ \t\r\n\f]*" /* S* */
- /* 1 */
- "(" /* [ */
- /* 2 3 */
- "\"(([^\"]|[\\]\")*)\"" /* STRING (approximated) */
- "|"
- /* 4 5 */
- "'(([^']|[\\]')*)'"
- "|" /* | */
- "url\\([ \t\r\n\f]*" /* URI (approximated) */
- /* 6 7 */
- "\"(([^\"]|[\\]\")*)\""
- "[ \t\r\n\f]*\\)"
- "|"
- "url\\([ \t\r\n\f]*"
- /* 8 9 */
- "'(([^']|[\\]')*)'"
- "[ \t\r\n\f]*\\)"
- "|"
- "url\\([ \t\r\n\f]*"
- /* 10 */
- "([^) \t\r\n\f]*)"
- "[ \t\r\n\f]*\\)"
- ")", /* ] */
- REG_EXTENDED | REG_ICASE);
-}
-
-
-/**
- * Rewrite stylesheet \@import rules for save complete.
- *
- * @param source stylesheet source
- * @param size size of source
- * @param osize updated with the size of the result
- * @param base url of stylesheet
- * @return converted source, or 0 on out of memory
- */
-
-char * rewrite_stylesheet_urls(const char *source, unsigned int size,
- int *osize, const char *base)
-{
- char *res;
- const char *url;
- char *url2;
- char buf[20];
- unsigned int offset = 0;
- int url_len = 0;
- struct content *content;
- int m;
- unsigned int i;
- unsigned int imports = 0;
- regmatch_t match[11];
- url_func_result result;
-
- /* count number occurences of @import to (over)estimate result size */
- /* can't use strstr because source is not 0-terminated string */
- for (i = 0; 7 < size && i != size - 7; i++) {
- if (source[i] == '@' &&
- tolower(source[i + 1]) == 'i' &&
- tolower(source[i + 2]) == 'm' &&
- tolower(source[i + 3]) == 'p' &&
- tolower(source[i + 4]) == 'o' &&
- tolower(source[i + 5]) == 'r' &&
- tolower(source[i + 6]) == 't')
- imports++;
- }
-
- res = malloc(size + imports * 20);
- if (!res)
- return 0;
- *osize = 0;
-
- while (offset < size) {
- m = regexec(&save_complete_import_re, source + offset,
- 11, match, 0);
- if (m)
- break;
-
- /*for (unsigned int i = 0; i != 11; i++) {
- if (match[i].rm_so == -1)
- continue;
- fprintf(stderr, "%i: '%.*s'\n", i,
- match[i].rm_eo - match[i].rm_so,
- source + offset + match[i].rm_so);
- }*/
-
- url = 0;
- if (match[2].rm_so != -1) {
- url = source + offset + match[2].rm_so;
- url_len = match[2].rm_eo - match[2].rm_so;
- } else if (match[4].rm_so != -1) {
- url = source + offset + match[4].rm_so;
- url_len = match[4].rm_eo - match[4].rm_so;
- } else if (match[6].rm_so != -1) {
- url = source + offset + match[6].rm_so;
- url_len = match[6].rm_eo - match[6].rm_so;
- } else if (match[8].rm_so != -1) {
- url = source + offset + match[8].rm_so;
- url_len = match[8].rm_eo - match[8].rm_so;
- } else if (match[10].rm_so != -1) {
- url = source + offset + match[10].rm_so;
- url_len = match[10].rm_eo - match[10].rm_so;
- }
- assert(url);
-
- url2 = strndup(url, url_len);
- if (!url2) {
- free(res);
- return 0;
- }
- result = url_join(url2, base, (char**)&url);
- free(url2);
- if (result == URL_FUNC_NOMEM) {
- free(res);
- return 0;
- }
-
- /* copy data before match */
- memcpy(res + *osize, source + offset, match[0].rm_so);
- *osize += match[0].rm_so;
-
- if (result == URL_FUNC_OK) {
- content = save_complete_list_find(url);
- if (content) {
- /* replace import */
- snprintf(buf, sizeof buf, "@import '%x'",
- (unsigned int) content);
- memcpy(res + *osize, buf, strlen(buf));
- *osize += strlen(buf);
- } else {
- /* copy import */
- memcpy(res + *osize, source + offset + match[0].rm_so,
- match[0].rm_eo - match[0].rm_so);
- *osize += match[0].rm_eo - match[0].rm_so;
- }
- }
- else {
- /* copy import */
- memcpy(res + *osize, source + offset + match[0].rm_so,
- match[0].rm_eo - match[0].rm_so);
- *osize += match[0].rm_eo - match[0].rm_so;
- }
-
- assert(0 < match[0].rm_eo);
- offset += match[0].rm_eo;
- }
-
- /* copy rest of source */
- if (offset < size) {
- memcpy(res + *osize, source + offset, size - offset);
- *osize += size - offset;
- }
-
- return res;
-}
-
-
-/**
- * Rewrite URLs in a HTML document to be relative.
- *
- * \param doc root of the document tree
- * \param base base url of document
- * \return true on success, false on out of memory
- */
-
-bool rewrite_document_urls(xmlDoc *doc, const char *base)
-{
- xmlNode *node;
-
- for (node = doc->children; node; node = node->next)
- if (node->type == XML_ELEMENT_NODE)
- if (!rewrite_urls(node, base))
- return false;
-
- return true;
-}
-
-
-/**
- * Traverse tree, rewriting URLs as we go.
- *
- * \param n xmlNode of type XML_ELEMENT_NODE to rewrite
- * \param base base url of document
- * \return true on success, false on out of memory
- *
- * URLs in the tree rooted at element n are rewritten.
- */
-
-bool rewrite_urls(xmlNode *n, const char *base)
-{
- xmlNode *child;
-
- assert(n->type == XML_ELEMENT_NODE);
-
- /**
- * We only need to consider the following cases:
- *
- * Attribute: Elements:
- *
- * 1) data <object>
- * 2) href <a> <area> <link>
- * 3) src <script> <input> <frame> <iframe> <img>
- * 4) n/a <style>
- * 5) n/a any <base> tag
- * 6) background any (except those above)
- */
- if (!n->name) {
- /* ignore */
- }
- /* 1 */
- else if (strcmp((const char *) n->name, "object") == 0) {
- if (!rewrite_url(n, "data", base))
- return false;
- }
- /* 2 */
- else if (strcmp((const char *) n->name, "a") == 0 ||
- strcmp((const char *) n->name, "area") == 0 ||
- strcmp((const char *) n->name, "link") == 0) {
- if (!rewrite_url(n, "href", base))
- return false;
- }
- /* 3 */
- else if (strcmp((const char *) n->name, "frame") == 0 ||
- strcmp((const char *) n->name, "iframe") == 0 ||
- strcmp((const char *) n->name, "input") == 0 ||
- strcmp((const char *) n->name, "img") == 0 ||
- strcmp((const char *) n->name, "script") == 0) {
- if (!rewrite_url(n, "src", base))
- return false;
- }
- /* 4 */
- else if (strcmp((const char *) n->name, "style") == 0) {
- unsigned int len;
- xmlChar *content;
-
- for (child = n->children; child != 0; child = child->next) {
- /* Get current content */
- content = xmlNodeGetContent(child);
- if (!content)
- /* unfortunately we don't know if this is
- * due to memory exhaustion, or because
- * there is no content for this node */
- continue;
-
- /* Rewrite @import rules */
- char *rewritten = rewrite_stylesheet_urls(
- (const char *) content,
- strlen((const char *) content),
- (int *) &len, base);
- xmlFree(content);
- if (!rewritten)
- return false;
-
- /* set new content */
- xmlNodeSetContentLen(child,
- (const xmlChar*)rewritten,
- len);
- }
-
- return true;
- }
- /* 5 */
- else if (strcmp((const char *) n->name, "base") == 0) {
- /* simply remove any <base> tags from the document */
- xmlUnlinkNode(n);
- xmlFreeNode(n);
- /* base tags have no content, so there's no point recursing
- * additionally, we've just destroyed this node, so trying
- * to recurse would result in bad things happening */
- return true;
- }
- /* 6 */
- else {
- if (!rewrite_url(n, "background", base))
- return false;
- }
-
- /* now recurse */
- for (child = n->children; child;) {
- /* we must extract the next child now, as if the current
- * child is a <base> element, it will be removed from the
- * tree (see 5, above), thus preventing extraction of the
- * next child */
- xmlNode *next = child->next;
- if (child->type == XML_ELEMENT_NODE) {
- if (!rewrite_urls(child, base))
- return false;
- }
- child = next;
- }
-
- return true;
-}
-
-
-/**
- * Rewrite an URL in a HTML document.
- *
- * \param n The node to modify
- * \param attr The html attribute to modify
- * \param base base url of document
- * \return true on success, false on out of memory
- */
-
-bool rewrite_url(xmlNode *n, const char *attr, const char *base)
-{
- char *url, *data;
- char rel[20];
- struct content *content;
- url_func_result res;
-
- if (!xmlHasProp(n, (const xmlChar *) attr))
- return true;
-
- data = (char *) xmlGetProp(n, (const xmlChar *) attr);
- if (!data)
- return false;
-
- res = url_join(data, base, &url);
- xmlFree(data);
- if (res == URL_FUNC_NOMEM)
- return false;
- else if (res == URL_FUNC_OK) {
- content = save_complete_list_find(url);
- if (content) {
- /* found a match */
- free(url);
- snprintf(rel, sizeof rel, "%x",
- (unsigned int) content);
- if (!xmlSetProp(n, (const xmlChar *) attr,
- (xmlChar *) rel))
- return false;
- } else {
- /* no match found */
- if (!xmlSetProp(n, (const xmlChar *) attr,
- (xmlChar *) url)) {
- free(url);
- return false;
- }
- free(url);
- }
- }
-
- return true;
-}
-
-
-/**
- * Add a content to the save_complete_list.
- *
- * \param content content to add
- * \return true on success, false on out of memory
- */
-
-bool save_complete_list_add(struct content *content)
-{
- struct save_complete_entry *entry;
- entry = malloc(sizeof (*entry));
- if (!entry)
- return false;
- entry->content = content;
- entry->next = save_complete_list;
- save_complete_list = entry;
- return true;
-}
-
-
-/**
- * Look up a url in the save_complete_list.
- *
- * \param url url to find
- * \return content if found, 0 otherwise
- */
-
-struct content * save_complete_list_find(const char *url)
-{
- struct save_complete_entry *entry;
- for (entry = save_complete_list; entry; entry = entry->next)
- if (strcmp(url, entry->content->url) == 0)
- return entry->content;
- return 0;
-}
-
-
-/**
- * Look up a content in the save_complete_list.
- *
- * \param content pointer to content
- * \return true if the content is in the save_complete_list
- */
-
-bool save_complete_list_check(struct content *content)
-{
- struct save_complete_entry *entry;
- for (entry = save_complete_list; entry; entry = entry->next)
- if (entry->content == content)
- return true;
- return false;
-}
-
-
-#if 0
-/**
- * Dump save complete list to stderr
- */
-void save_complete_list_dump(void)
-{
- struct save_complete_entry *entry;
- for (entry = save_complete_list; entry; entry = entry->next)
- fprintf(stderr, "%p : %s\n", entry->content,
- entry->content->url);
-}
-#endif
-
-
-/**
- * Create the inventory file listing original URLs.
- */
-
-bool save_complete_inventory(const char *path)
-{
- char spath[256];
- FILE *fp;
-
- snprintf(spath, sizeof spath, "%s.Inventory", path);
-
- fp = fopen(spath, "w");
- if (!fp) {
- LOG(("fopen(): errno = %i", errno));
- warn_user("SaveError", strerror(errno));
- return false;
- }
-
- struct save_complete_entry *entry;
- for (entry = save_complete_list; entry; entry = entry->next)
- fprintf(fp, "%x %s\n",
- (unsigned int) entry->content,
- entry->content->url);
-
- fclose(fp);
-
- return true;
-}
-
diff --git a/riscos/search.c b/riscos/search.c
index 0dd502272..79f2a46af 100644
--- a/riscos/search.c
+++ b/riscos/search.c
@@ -31,6 +31,7 @@
#include "content/content.h"
#include "desktop/browser.h"
#include "desktop/gui.h"
+#include "desktop/search.h"
#include "desktop/selection.h"
#include "render/box.h"
#include "render/html.h"
@@ -42,35 +43,19 @@
#include "utils/messages.h"
#include "utils/utils.h"
-#ifndef NOF_ELEMENTS
-#define NOF_ELEMENTS(array) (sizeof(array)/sizeof(*(array)))
-#endif
-
-struct list_entry {
- unsigned start_idx; /* start position of match */
- unsigned end_idx; /* end of match */
-
- struct box *start_box; /* used only for html contents */
- struct box *end_box;
-
- struct selection *sel;
+#define RECENT_SEARCHES 8
- struct list_entry *prev;
- struct list_entry *next;
+struct search_static_data {
+ char *recent_searches[RECENT_SEARCHES];
+ bool search_insert;
+ struct browser_window *search_window;
+ search_flags_t flags;
+ char *string;
};
-struct gui_window *search_current_window = NULL;
-
-static char *search_string = NULL;
-static struct list_entry search_head = { 0, 0, NULL, NULL, NULL, NULL, NULL };
-static struct list_entry *search_found = &search_head;
-static struct list_entry *search_current = NULL;
-static struct content *search_content = NULL;
-static bool search_prev_case_sens = false;
+static struct search_static_data search_data =
+ {{NULL}, false, NULL, 0, NULL};
-#define RECENT_SEARCHES 8
-bool search_insert;
-static char *recent_search[RECENT_SEARCHES];
static wimp_MENU(RECENT_SEARCHES) menu_recent;
wimp_menu *recent_search_menu = (wimp_menu *)&menu_recent;
#define DEFAULT_FLAGS (wimp_ICON_TEXT | wimp_ICON_FILLED | \
@@ -78,26 +63,24 @@ wimp_menu *recent_search_menu = (wimp_menu *)&menu_recent;
(wimp_COLOUR_WHITE << wimp_ICON_BG_COLOUR_SHIFT))
-static void start_search(bool forwards);
-static void do_search(const char *string, int string_len, bool case_sens,
- bool forwards);
-static const char *find_pattern(const char *string, int s_len,
- const char *pattern, int p_len, bool case_sens,
- unsigned int *m_len);
-static bool find_occurrences_html(const char *pattern, int p_len,
- struct box *cur, bool case_sens);
-static bool find_occurrences_text(const char *pattern, int p_len,
- struct content *c, bool case_sens);
-static struct list_entry *add_entry(unsigned start_idx, unsigned end_idx);
-static void free_matches(void);
-static void show_all(bool all);
-static void show_status(bool found);
-
static void ro_gui_search_end(wimp_w w);
static bool ro_gui_search_next(wimp_w w);
static bool ro_gui_search_click(wimp_pointer *pointer);
static bool ro_gui_search_keypress(wimp_key *key);
-static void ro_gui_search_add_recent(const char *search);
+static search_flags_t ro_gui_search_update_flags(void);
+static void ro_gui_search_set_forward_state(bool active, void *p);
+static void ro_gui_search_set_back_state(bool active, void *p);
+static void ro_gui_search_set_status(bool found, void *p);
+static void ro_gui_search_set_hourglass(bool active, void *p);
+static void ro_gui_search_add_recent(const char *string, void *p);
+
+static struct search_callbacks ro_gui_search_callbacks = {
+ ro_gui_search_set_forward_state,
+ ro_gui_search_set_back_state,
+ ro_gui_search_set_status,
+ ro_gui_search_set_hourglass,
+ ro_gui_search_add_recent
+};
void ro_gui_search_init(void)
{
@@ -132,30 +115,66 @@ void ro_gui_search_init(void)
*/
bool ro_gui_search_next(wimp_w w)
{
- search_insert = true;
- start_search(true);
+ search_data.search_insert = true;
+ search_flags_t flags = SEARCH_FLAG_FORWARDS |
+ ro_gui_search_update_flags();
+ if (search_verify_new(search_data.search_window,
+ &ro_gui_search_callbacks, NULL))
+ search_step(search_data.search_window->search_context, flags,
+ ro_gui_get_icon_string(dialog_search,
+ ICON_SEARCH_TEXT));
return false;
}
bool ro_gui_search_click(wimp_pointer *pointer)
{
+ search_flags_t flags;
switch (pointer->i) {
case ICON_SEARCH_FIND_PREV:
- search_insert = true;
- start_search(false);
+ search_data.search_insert = true;
+ flags = ~SEARCH_FLAG_FORWARDS &
+ ro_gui_search_update_flags();
+ if (search_verify_new(search_data.search_window,
+ &ro_gui_search_callbacks, NULL))
+ search_step(search_data.search_window->
+ search_context, flags,
+ ro_gui_get_icon_string(
+ dialog_search,
+ ICON_SEARCH_TEXT));
return true;
case ICON_SEARCH_CASE_SENSITIVE:
- start_search(true);
+ flags = SEARCH_FLAG_FORWARDS |
+ ro_gui_search_update_flags();
+ if (search_verify_new(search_data.search_window,
+ &ro_gui_search_callbacks, NULL))
+ search_step(search_data.search_window->
+ search_context, flags,
+ ro_gui_get_icon_string(
+ dialog_search,
+ ICON_SEARCH_TEXT));
return true;
case ICON_SEARCH_SHOW_ALL:
- show_all(ro_gui_get_icon_selected_state(pointer->w,
- pointer->i));
+ if (search_data.search_window->search_context != NULL)
+ search_show_all(ro_gui_get_icon_selected_state(
+ pointer->w, pointer->i),
+ search_data.search_window->
+ search_context);
return true;
}
return false;
}
-void ro_gui_search_add_recent(const char *search)
+/**
+ * add search string to recent searches list
+ * front is at liberty how to implement the bare notification
+ * should normally store a strdup() of the string in
+ * search_global_data.recent[];
+ * core gives no guarantee of the integrity of the const char *
+ * \param string search pattern
+ * \param p the pointer sent to search_verify_new()
+ */
+
+void ro_gui_search_add_recent(const char *search, void *p)
{
char *tmp;
int i;
@@ -163,15 +182,15 @@ void ro_gui_search_add_recent(const char *search)
if ((search == NULL) || (search[0] == '\0'))
return;
- if (!search_insert) {
- free(recent_search[0]);
- recent_search[0] = strdup(search);
+ if (!search_data.search_insert) {
+ free(search_data.recent_searches[0]);
+ search_data.recent_searches[0] = strdup(search);
ro_gui_search_prepare_menu();
return;
}
- if ((recent_search[0] != NULL) &&
- (!strcmp(recent_search[0], search)))
+ if ((search_data.recent_searches[0] != NULL) &&
+ (!strcmp(search_data.recent_searches[0], search)))
return;
tmp = strdup(search);
@@ -179,11 +198,11 @@ void ro_gui_search_add_recent(const char *search)
warn_user("NoMemory", 0);
return;
}
- free(recent_search[RECENT_SEARCHES - 1]);
+ free(search_data.recent_searches[RECENT_SEARCHES - 1]);
for (i = RECENT_SEARCHES - 1; i > 0; i--)
- recent_search[i] = recent_search[i - 1];
- recent_search[0] = tmp;
- search_insert = false;
+ search_data.recent_searches[i] = search_data.recent_searches[i - 1];
+ search_data.recent_searches[0] = tmp;
+ search_data.search_insert = false;
ro_gui_set_icon_shaded_state(dialog_search, ICON_SEARCH_MENU, false);
ro_gui_search_prepare_menu();
@@ -196,7 +215,7 @@ bool ro_gui_search_prepare_menu(void)
int suggestions = 0;
for (i = 0; i < RECENT_SEARCHES; i++)
- if (recent_search[i] != NULL)
+ if (search_data.recent_searches[i] != NULL)
suggestions++;
if (suggestions == 0)
@@ -205,9 +224,9 @@ bool ro_gui_search_prepare_menu(void)
for (i = 0; i < suggestions; i++) {
recent_search_menu->entries[i].menu_flags &= ~wimp_MENU_LAST;
recent_search_menu->entries[i].data.indirected_text.text =
- recent_search[i];
+ search_data.recent_searches[i];
recent_search_menu->entries[i].data.indirected_text.size =
- strlen(recent_search[i]) + 1;
+ strlen(search_data.recent_searches[i]) + 1;
}
recent_search_menu->entries[suggestions - 1].menu_flags |=
wimp_MENU_LAST;
@@ -226,26 +245,29 @@ bool ro_gui_search_prepare_menu(void)
/**
* Open the search dialog
*
- * \param g the gui window to search
+ * \param bw the browser window to search
*/
-void ro_gui_search_prepare(struct gui_window *g)
+void ro_gui_search_prepare(struct browser_window *bw)
{
struct content *c;
- assert(g != NULL);
+ assert(bw != NULL);
- c = g->bw->current_content;
+ c = bw->current_content;
/* only handle html/textplain contents */
if ((!c) || (c->type != CONTENT_HTML &&
c->type != CONTENT_TEXTPLAIN))
return;
- /* if the search dialogue is reopened over a new window, we still
+ /* if the search dialogue is reopened over a new window, we may
need to cancel the previous search */
- ro_gui_search_end(dialog_search);
+ ro_gui_search_set_forward_state(true, bw);
+ ro_gui_search_set_back_state(true, bw);
+
+ search_create_context(bw, &ro_gui_search_callbacks, NULL);
- search_current_window = g;
+ search_data.search_window = bw;
ro_gui_set_icon_string(dialog_search, ICON_SEARCH_TEXT, "", true);
ro_gui_set_icon_selected_state(dialog_search,
@@ -253,14 +275,10 @@ void ro_gui_search_prepare(struct gui_window *g)
ro_gui_set_icon_selected_state(dialog_search,
ICON_SEARCH_SHOW_ALL, false);
- show_status(true);
- ro_gui_set_icon_shaded_state(dialog_search,
- ICON_SEARCH_FIND_PREV, true);
- ro_gui_set_icon_shaded_state(dialog_search,
- ICON_SEARCH_FIND_NEXT, true);
+ ro_gui_search_set_status(true, NULL);
ro_gui_wimp_event_memorise(dialog_search);
- search_insert = true;
+ search_data.search_insert = true;
}
/**
@@ -272,6 +290,7 @@ void ro_gui_search_prepare(struct gui_window *g)
bool ro_gui_search_keypress(wimp_key *key)
{
bool state;
+ search_flags_t flags;
switch (key->c) {
case 1: { /* ctrl a */
@@ -279,7 +298,9 @@ bool ro_gui_search_keypress(wimp_key *key)
ICON_SEARCH_SHOW_ALL);
ro_gui_set_icon_selected_state(key->w,
ICON_SEARCH_SHOW_ALL, sel);
- show_all(sel);
+ if (search_data.search_window->search_context != NULL)
+ search_show_all(sel,
+ search_data.search_window->search_context);
}
break;
case 9: /* ctrl i */
@@ -287,27 +308,79 @@ bool ro_gui_search_keypress(wimp_key *key)
ICON_SEARCH_CASE_SENSITIVE);
ro_gui_set_icon_selected_state(dialog_search,
ICON_SEARCH_CASE_SENSITIVE, !state);
- start_search(true);
+ flags = SEARCH_FLAG_FORWARDS |
+ ro_gui_search_update_flags();
+ if (search_verify_new(search_data.search_window,
+ &ro_gui_search_callbacks, NULL))
+ search_step(search_data.search_window->
+ search_context, flags,
+ ro_gui_get_icon_string(
+ dialog_search,
+ ICON_SEARCH_TEXT));
return true;
case IS_WIMP_KEY | wimp_KEY_UP:
- search_insert = true;
- start_search(false);
+ search_data.search_insert = true;
+ flags = ~SEARCH_FLAG_FORWARDS &
+ ro_gui_search_update_flags();
+ if (search_verify_new(search_data.search_window,
+ &ro_gui_search_callbacks, NULL))
+ search_step(search_data.search_window->
+ search_context, flags,
+ ro_gui_get_icon_string(
+ dialog_search,
+ ICON_SEARCH_TEXT));
return true;
case IS_WIMP_KEY | wimp_KEY_DOWN:
- search_insert = true;
- start_search(true);
+ search_data.search_insert = true;
+ flags = SEARCH_FLAG_FORWARDS |
+ ro_gui_search_update_flags();
+ if (search_verify_new(search_data.search_window,
+ &ro_gui_search_callbacks, NULL))
+ search_step(search_data.search_window->
+ search_context, flags,
+ ro_gui_get_icon_string(
+ dialog_search,
+ ICON_SEARCH_TEXT));
return true;
default:
if (key->c == 21) {
/* ctrl+u means the user's starting
* a new search */
- search_insert = true;
+ if (search_data.search_window->search_context != NULL)
+ search_destroy_context(
+ search_data.
+ search_window->
+ search_context);
+ ro_gui_search_set_forward_state(true,
+ search_data.search_window);
+ ro_gui_search_set_back_state(true,
+ search_data.search_window);
+ search_data.search_insert = true;
}
if (key->c == 8 || /* backspace */
key->c == 21 || /* ctrl u */
(key->c >= 0x20 && key->c <= 0x7f)) {
- start_search(true);
+ flags = SEARCH_FLAG_FORWARDS |
+ ro_gui_search_update_flags();
+ if (search_data.search_window->search_context
+ != NULL)
+ search_destroy_context(
+ search_data.
+ search_window->
+ search_context);
+ ro_gui_search_set_forward_state(true,
+ search_data.search_window);
+ ro_gui_search_set_back_state(true,
+ search_data.search_window);
+ if (search_verify_new(search_data.search_window,
+ &ro_gui_search_callbacks,
+ NULL))
+ search_step(search_data.search_window->
+ search_context, flags,
+ ro_gui_get_icon_string(
+ dialog_search,
+ ICON_SEARCH_TEXT));
return true;
}
break;
@@ -317,564 +390,80 @@ bool ro_gui_search_keypress(wimp_key *key)
}
/**
- * Begins/continues the search process
- * Note that this may be called many times for a single search.
- *
- * \param forwards search forwards from start/current position
- */
-
-void start_search(bool forwards)
-{
- int string_len;
- const char *string;
- int i = 0;
-
- string = ro_gui_get_icon_string(dialog_search, ICON_SEARCH_TEXT);
- assert(string);
-
- ro_gui_search_add_recent(string);
-
- string_len = strlen(string);
- for(i = 0; i < string_len; i++)
- if (string[i] != '#' && string[i] != '*') break;
- if (i >= string_len) {
- free_matches();
- show_status(true);
- ro_gui_set_icon_shaded_state(dialog_search,
- ICON_SEARCH_FIND_PREV, true);
- ro_gui_set_icon_shaded_state(dialog_search,
- ICON_SEARCH_FIND_NEXT, true);
- gui_window_set_scroll(search_current_window, 0, 0);
- return;
- }
-
- do_search(string, string_len,
- ro_gui_get_icon_selected_state(dialog_search,
- ICON_SEARCH_CASE_SENSITIVE),
- forwards);
-}
-
-/**
- * Ends the search process, invalidating all global state and
- * freeing the list of found boxes
- *
- * \param w the search window handle (not used)
+ * Ends the search
+ * \param w the search window handle (not used)
*/
void ro_gui_search_end(wimp_w w)
{
- search_current_window = 0;
-
- if (search_string) {
- ro_gui_search_add_recent(search_string);
- free(search_string);
- }
- search_string = 0;
-
- free_matches();
-
- search_current = 0;
-
- search_content = 0;
-
- search_prev_case_sens = false;
-}
-
-
-/**
- * Release the memory used by the list of matches,
- * deleting selection objects too
- */
-
-void free_matches(void)
-{
- struct list_entry *a = search_found->next;
- struct list_entry *b;
-
- /* empty the list before clearing and deleting the
- selections because the the clearing updates the
- screen immediately, causing nested accesses to the list */
-
- search_found->prev = 0;
- search_found->next = 0;
-
- for (; a; a = b) {
- b = a->next;
- if (a->sel) {
- selection_clear(a->sel, true);
- selection_destroy(a->sel);
- }
- free(a);
- }
-}
-
-
-/**
- * Search for a string in the box tree
- *
- * \param string the string to search for
- * \param string_len length of search string
- * \param case_sens whether to perform a case sensitive search
- * \param forwards direction to search in
- */
-void do_search(const char *string, int string_len, bool case_sens,
- bool forwards)
-{
- struct rect bounds;
- struct content *c;
- struct box *box;
- bool new = false;
-
- if (!search_current_window)
- return;
-
- c = search_current_window->bw->current_content;
-
- /* only handle html contents */
- if ((!c) || (c->type != CONTENT_HTML &&
- c->type != CONTENT_TEXTPLAIN))
- return;
-
- box = c->data.html.layout;
-
- if (!box)
- return;
-
-// LOG(("do_search '%s' - '%s' (%p, %p) %p (%d, %d) %d",
-// search_string, string, search_content, c, search_found->next,
-// search_prev_case_sens, case_sens, forwards));
-
- /* check if we need to start a new search or continue an old one */
- if (!search_string || c != search_content || !search_found->next ||
- search_prev_case_sens != case_sens ||
- (case_sens && strcmp(string, search_string) != 0) ||
- (!case_sens && strcasecmp(string, search_string) != 0)) {
- bool res;
-
- if (search_string)
- free(search_string);
- search_current = 0;
- free_matches();
-
- search_string = malloc(string_len + 1);
- if (search_string) {
- memcpy(search_string, string, string_len);
- search_string[string_len] = '\0';
- }
-
- xhourglass_on();
-
- if (c->type == CONTENT_HTML)
- res = find_occurrences_html(string, string_len,
- box, case_sens);
- else {
- assert(c->type == CONTENT_TEXTPLAIN);
- res = find_occurrences_text(string, string_len,
- c, case_sens);
- }
-
- if (!res) {
- free_matches();
- xhourglass_off();
- return;
- }
- xhourglass_off();
-
- new = true;
- search_content = c;
- search_prev_case_sens = case_sens;
- }
-
-// LOG(("%d %p %p (%p, %p)", new, search_found->next, search_current, search_current->prev, search_current->next));
-
- if (new) {
- /* new search, beginning at the top of the page */
- search_current = search_found->next;
- }
- else if (search_current) {
- /* continued search in the direction specified */
- if (forwards) {
- if (search_current->next)
- search_current = search_current->next;
- }
- else {
- if (search_current->prev)
- search_current = search_current->prev;
- }
- }
-
- show_status(search_current != NULL);
- show_all(ro_gui_get_icon_selected_state(dialog_search,
- ICON_SEARCH_SHOW_ALL));
-
- ro_gui_set_icon_shaded_state(dialog_search, ICON_SEARCH_FIND_PREV,
- !search_current || !search_current->prev);
- ro_gui_set_icon_shaded_state(dialog_search, ICON_SEARCH_FIND_NEXT,
- !search_current || !search_current->next);
-
- if (!search_current)
- return;
-
- switch (c->type) {
- case CONTENT_HTML:
- /* get box position and jump to it */
- box_coords(search_current->start_box,
- &bounds.x0, &bounds.y0);
- /* \todo: move x0 in by correct idx */
- box_coords(search_current->end_box,
- &bounds.x1, &bounds.y1);
- /* \todo: move x1 in by correct idx */
- bounds.x1 += search_current->end_box->width;
- bounds.y1 += search_current->end_box->height;
- break;
-
- default:
- assert(c->type == CONTENT_TEXTPLAIN);
- textplain_coords_from_range(c,
- search_current->start_idx,
- search_current->end_idx, &bounds);
- break;
- }
-
- gui_window_scroll_visible(search_current_window,
- bounds.x0, bounds.y0, bounds.x1, bounds.y1);
-}
-
-
-/**
- * Find the first occurrence of 'match' in 'string' and return its index
- *
- * /param string the string to be searched (unterminated)
- * /param s_len length of the string to be searched
- * /param pattern the pattern for which we are searching (unterminated)
- * /param p_len length of pattern
- * /param case_sens true iff case sensitive match required
- * /param m_len accepts length of match in bytes
- * /return pointer to first match, NULL if none
- */
-
-const char *find_pattern(const char *string, int s_len, const char *pattern,
- int p_len, bool case_sens, unsigned int *m_len)
-{
- struct { const char *ss, *s, *p; bool first; } context[16];
- const char *ep = pattern + p_len;
- const char *es = string + s_len;
- const char *p = pattern - 1; /* a virtual '*' before the pattern */
- const char *ss = string;
- const char *s = string;
- bool first = true;
- int top = 0;
-
- while (p < ep) {
- bool matches;
- if (p < pattern || *p == '*') {
- char ch;
-
- /* skip any further asterisks; one is the same as many */
- do p++; while (p < ep && *p == '*');
-
- /* if we're at the end of the pattern, yes, it matches */
- if (p >= ep) break;
-
- /* anything matches a # so continue matching from
- here, and stack a context that will try to match
- the wildcard against the next character */
-
- ch = *p;
- if (ch != '#') {
- /* scan forwards until we find a match for this char */
- if (!case_sens) ch = toupper(ch);
- while (s < es) {
- if (case_sens) {
- if (*s == ch) break;
- } else if (toupper(*s) == ch)
- break;
- s++;
- }
- }
-
- if (s < es) {
- /* remember where we are in case the match fails;
- we can then resume */
- if (top < (int)NOF_ELEMENTS(context)) {
- context[top].ss = ss;
- context[top].s = s + 1;
- context[top].p = p - 1; /* ptr to last asterisk */
- context[top].first = first;
- top++;
- }
-
- if (first) {
- ss = s; /* remember first non-'*' char */
- first = false;
- }
-
- matches = true;
- }
- else
- matches = false;
- }
- else if (s < es) {
- char ch = *p;
- if (ch == '#')
- matches = true;
- else {
- if (case_sens)
- matches = (*s == ch);
- else
- matches = (toupper(*s) == toupper(ch));
- }
- if (matches && first) {
- ss = s; /* remember first non-'*' char */
- first = false;
- }
- }
- else
- matches = false;
-
- if (matches) {
- p++; s++;
- }
- else {
- /* doesn't match, resume with stacked context if we have one */
- if (--top < 0) return NULL; /* no match, give up */
-
- ss = context[top].ss;
- s = context[top].s;
- p = context[top].p;
- first = context[top].first;
- }
- }
-
- /* end of pattern reached */
- *m_len = max(s - ss, 1);
- return ss;
+ if (search_data.search_window->search_context != NULL)
+ search_destroy_context(search_data.search_window->
+ search_context);
+ ro_gui_search_set_forward_state(true, search_data.search_window);
+ ro_gui_search_set_back_state(true, search_data.search_window);
}
-
/**
- * Finds all occurrences of a given string in the html box tree
- *
- * \param pattern the string pattern to search for
- * \param p_len pattern length
- * \param cur pointer to the current box
- * \param case_sens whether to perform a case sensitive search
- * \return true on success, false on memory allocation failure
- */
-bool find_occurrences_html(const char *pattern, int p_len, struct box *cur,
- bool case_sens)
-{
- struct box *a;
-
- /* ignore this box, if there's no visible text */
- if (!cur->object && cur->text) {
- const char *text = cur->text;
- unsigned length = cur->length;
-
- while (length > 0) {
- struct list_entry *entry;
- unsigned match_length;
- unsigned match_offset;
- const char *new_text;
- const char *pos = find_pattern(text, length,
- pattern, p_len, case_sens,
- &match_length);
- if (!pos) break;
-
- /* found string in box => add to list */
- match_offset = pos - cur->text;
-
- entry = add_entry(cur->byte_offset + match_offset,
- cur->byte_offset +
- match_offset +
- match_length);
- if (!entry)
- return false;
-
- entry->start_box = cur;
- entry->end_box = cur;
-
- new_text = pos + match_length;
- length -= (new_text - text);
- text = new_text;
- }
- }
-
- /* and recurse */
- for (a = cur->children; a; a = a->next) {
- if (!find_occurrences_html(pattern, p_len, a, case_sens))
- return false;
- }
-
- return true;
-}
+* Change the displayed search status.
+* \param found search pattern matched in text
+* \param p the pointer sent to search_verify_new() / search_create_context()
+*/
-
-/**
- * Finds all occurrences of a given string in a textplain content
- *
- * \param pattern the string pattern to search for
- * \param p_len pattern length
- * \param c the content to be searched
- * \param case_sens wheteher to perform a case sensitive search
- * \return true on success, false on memory allocation failure
- */
-
-bool find_occurrences_text(const char *pattern, int p_len,
- struct content *c, bool case_sens)
+void ro_gui_search_set_status(bool found, void *p)
{
- int nlines = textplain_line_count(c);
- int line;
-
- for(line = 0; line < nlines; line++) {
- size_t offset, length;
- const char *text = textplain_get_line(c, line,
- &offset, &length);
- if (text) {
- while (length > 0) {
- struct list_entry *entry;
- unsigned match_length;
- size_t start_idx;
- const char *new_text;
- const char *pos = find_pattern(text, length,
- pattern, p_len, case_sens,
- &match_length);
- if (!pos) break;
-
- /* found string in line => add to list */
- start_idx = offset + (pos - text);
- entry = add_entry(start_idx, start_idx +
- match_length);
- if (!entry)
- return false;
-
- new_text = pos + match_length;
- offset += (new_text - text);
- length -= (new_text - text);
- text = new_text;
- }
- }
- }
-
- return true;
+ ro_gui_set_icon_string(dialog_search, ICON_SEARCH_STATUS, found ? "" :
+ messages_get("NotFound"), true);
}
-
/**
- * Add a new entry to the list of matches
- *
- * \param start_idx offset of match start within textual representation
- * \param end_idx offset of match end
- * \return pointer to added entry, NULL iff failed
- */
+* display hourglass while searching
+* \param active start/stop indicator
+* \param p the pointer sent to search_verify_new() / search_create_context()
+*/
-struct list_entry *add_entry(unsigned start_idx, unsigned end_idx)
+void ro_gui_search_set_hourglass(bool active, void *p)
{
- struct list_entry *entry;
-
- /* found string in box => add to list */
- entry = calloc(1, sizeof(*entry));
- if (!entry) {
- warn_user("NoMemory", 0);
- return NULL;
- }
-
- entry->start_idx = start_idx;
- entry->end_idx = end_idx;
- entry->sel = NULL;
+ if (active)
+ xhourglass_on();
- entry->next = 0;
- entry->prev = search_found->prev;
- if (!search_found->prev)
- search_found->next = entry;
else
- search_found->prev->next = entry;
- search_found->prev = entry;
-
- return entry;
+ xhourglass_off();
}
-
/**
- * Determines whether any portion of the given text box should be
- * selected because it matches the current search string.
- *
- * \param g gui window
- * \param start_offset byte offset within text of string to be checked
- * \param end_offset byte offset within text
- * \param start_idx byte offset within string of highlight start
- * \param end_idx byte offset of highlight end
- * \return true iff part of the box should be highlighted
- */
+* activate search forwards button in gui
+* \param active activate/inactivate
+* \param p the pointer sent to search_verify_new() / search_create_context()
+*/
-bool gui_search_term_highlighted(struct gui_window *g,
- unsigned start_offset, unsigned end_offset,
- unsigned *start_idx, unsigned *end_idx)
+void ro_gui_search_set_forward_state(bool active, void *p)
{
- if (g == search_current_window) {
- struct list_entry *a;
- for(a = search_found->next; a; a = a->next)
- if (a->sel && selection_defined(a->sel) &&
- selection_highlighted(a->sel,
- start_offset, end_offset,
- start_idx, end_idx))
- return true;
- }
-
- return false;
+ ro_gui_set_icon_shaded_state(dialog_search, ICON_SEARCH_FIND_NEXT,
+ !active);
}
-
/**
- * Specifies whether all matches or just the current match should
- * be highlighted in the search text.
- */
+* activate search forwards button in gui
+* \param active activate/inactivate
+* \param p the pointer sent to search_verify_new() / search_create_context()
+*/
-void show_all(bool all)
+void ro_gui_search_set_back_state(bool active, void *p)
{
- struct list_entry *a;
-
- for (a = search_found->next; a; a = a->next) {
- bool add = true;
- if (!all && a != search_current) {
- add = false;
- if (a->sel) {
- selection_clear(a->sel, true);
- selection_destroy(a->sel);
- a->sel = NULL;
- }
- }
- if (add && !a->sel) {
- a->sel = selection_create(search_current_window->bw);
- if (a->sel) {
- struct content *c = search_current_window->bw->current_content;
- switch (c->type) {
- case CONTENT_HTML:
- selection_init(a->sel,
- c->data.html.layout);
- break;
- default:
- assert(c->type ==
- CONTENT_TEXTPLAIN);
- selection_init(a->sel, NULL);
- break;
- }
- selection_set_start(a->sel, a->start_idx);
- selection_set_end(a->sel, a->end_idx);
- }
- }
- }
+ ro_gui_set_icon_shaded_state(dialog_search, ICON_SEARCH_FIND_PREV,
+ !active);
}
-
/**
- * Change the displayed search status.
- *
- * \param found search pattern matched in text
- */
-
-void show_status(bool found)
+* retrieve state of 'case sensitive', 'show all' checks in gui
+*/
+search_flags_t ro_gui_search_update_flags(void)
{
- ro_gui_set_icon_string(dialog_search, ICON_SEARCH_STATUS,
- found ? "" : messages_get("NotFound"), true);
+ search_flags_t flags;
+ flags = 0 | (ro_gui_get_icon_selected_state(dialog_search,
+ ICON_SEARCH_CASE_SENSITIVE) ?
+ SEARCH_FLAG_CASE_SENSITIVE : 0) |
+ (ro_gui_get_icon_selected_state(dialog_search,
+ ICON_SEARCH_SHOW_ALL) ? SEARCH_FLAG_SHOWALL : 0);
+ return flags;
}
diff --git a/riscos/save_complete.h b/riscos/searchweb.c
index 63db0e44d..14246d228 100644
--- a/riscos/save_complete.h
+++ b/riscos/searchweb.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2004 John M Bell <jmb202@ecs.soton.ac.uk>
+ * Copyright 2009 Mark Benjamin <netsurf-browser.org.MarkBenjamin@dfgh.net>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
@@ -16,17 +16,3 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-/** \file
- * Save HTML document with dependencies (interface).
- */
-
-#ifndef _NETSURF_RISCOS_SAVE_COMPLETE_H_
-#define _NETSURF_RISCOS_SAVE_COMPLETE_H_
-
-#include <stdbool.h>
-struct content;
-
-void save_complete_init(void);
-bool save_complete(struct content *c, const char *path);
-
-#endif
diff --git a/riscos/window.c b/riscos/window.c
index 764a014ed..effb4dac6 100644
--- a/riscos/window.c
+++ b/riscos/window.c
@@ -1104,6 +1104,21 @@ void gui_window_stop_throbber(struct gui_window *g)
}
}
+/**
+ * set favicon
+ */
+void gui_window_set_icon(struct gui_window *g, struct content *icon)
+{
+}
+
+/**
+* set gui display of a retrieved favicon representing the search provider
+* \param ico may be NULL for local calls; then access current cache from
+* search_web_ico()
+*/
+void gui_window_set_search_ico(struct content *ico)
+{
+}
/**
* Place the caret in a browser window.