diff options
author | John Mark Bell <jmb@netsurf-browser.org> | 2009-12-17 23:55:02 +0000 |
---|---|---|
committer | John Mark Bell <jmb@netsurf-browser.org> | 2009-12-17 23:55:02 +0000 |
commit | 355799ce0bbb078237dfc1ae9874bbc5342acbc4 (patch) | |
tree | 7ca980c01c0d4d1d55a3b7b15418c95c5618afae /amiga | |
parent | 4346b2b62b940182575e6612e46234355afa083c (diff) | |
download | netsurf-355799ce0bbb078237dfc1ae9874bbc5342acbc4.tar.gz netsurf-355799ce0bbb078237dfc1ae9874bbc5342acbc4.tar.bz2 |
Merge branches/MarkieB/gtkmain to trunk.
svn path=/trunk/netsurf/; revision=9729
Diffstat (limited to 'amiga')
-rw-r--r-- | amiga/download.c | 2 | ||||
-rwxr-xr-x | amiga/fetch_file.c | 26 | ||||
-rwxr-xr-x | amiga/gui.c | 19 | ||||
-rwxr-xr-x | amiga/gui.h | 2 | ||||
-rwxr-xr-x | amiga/menu.c | 2 | ||||
-rwxr-xr-x | amiga/save_complete.c | 843 | ||||
-rwxr-xr-x | amiga/search.c | 803 |
7 files changed, 298 insertions, 1399 deletions
diff --git a/amiga/download.c b/amiga/download.c index 48f719a60..baba92bd3 100644 --- a/amiga/download.c +++ b/amiga/download.c @@ -29,13 +29,13 @@ #include "amiga/download.h" #include "amiga/object.h" #include "amiga/options.h" -#include "amiga/save_complete.h" #include "amiga/bitmap.h" #include "amiga/iff_dr2d.h" #include "content/fetch.h" #include "desktop/selection.h" +#include "desktop/save_complete.h" #include "utils/messages.h" #include "utils/utils.h" diff --git a/amiga/fetch_file.c b/amiga/fetch_file.c index acc0d4724..953478423 100755 --- a/amiga/fetch_file.c +++ b/amiga/fetch_file.c @@ -215,11 +215,11 @@ void ami_fetch_file_free(void *vf) static void ami_fetch_file_send_callback(fetch_msg msg, struct ami_file_fetch_info *fetch, const void *data, - unsigned long size) + unsigned long size, fetch_error_code errorcode) { fetch->locked = true; /* LOG(("ami file fetcher callback %ld",msg)); */ - fetch_send_callback(msg,fetch->fetch_handle,data,size); + fetch_send_callback(msg,fetch->fetch_handle,data,size,errorcode); fetch->locked = false; } @@ -234,6 +234,7 @@ void ami_fetch_file_poll(const char *scheme_ignored) struct nsObject *node; struct nsObject *nnode; struct ami_file_fetch_info *fetch; + fetch_error_code errorcode; if(IsMinListEmpty(ami_file_fetcher_list)) return; @@ -241,6 +242,7 @@ void ami_fetch_file_poll(const char *scheme_ignored) do { + errorcode = FETCH_ERROR_NO_ERROR; nnode=(struct nsObject *)GetSucc((struct Node *)node); fetch = (struct ami_file_fetch_info *)node->objstruct; @@ -255,13 +257,19 @@ void ami_fetch_file_poll(const char *scheme_ignored) len = FRead(fetch->fh,ami_file_fetcher_buffer,1,1024); - ami_fetch_file_send_callback(FETCH_DATA, - fetch,ami_file_fetcher_buffer,len); + if (len == (ULONG)-1) + errorcode = FETCH_ERROR_MISC; + else if (len > 0) + ami_fetch_file_send_callback( + FETCH_DATA, fetch, + ami_file_fetcher_buffer, + len, errorcode); if((len<1024) && (!fetch->aborted)) { ami_fetch_file_send_callback(FETCH_FINISHED, - fetch, &fetch->cachedata, 0); + fetch, &fetch->cachedata, 0, + errorcode); fetch->aborted = true; } @@ -284,7 +292,8 @@ void ami_fetch_file_poll(const char *scheme_ignored) LOG(("mimetype %s len %ld",fetch->mimetype,fetch->len)); ami_fetch_file_send_callback(FETCH_TYPE, - fetch, fetch->mimetype, (ULONG)fetch->len); + fetch, fetch->mimetype, (ULONG)fetch->len, + errorcode); } else { @@ -292,8 +301,11 @@ void ami_fetch_file_poll(const char *scheme_ignored) errorstring = ASPrintf("%s %s",messages_get("FileError"),fetch->path); fetch_set_http_code(fetch->fetch_handle,404); + + errorcode = FETCH_ERROR_HTTP_NOT2; ami_fetch_file_send_callback(FETCH_ERROR, fetch, - errorstring, 0); + errorstring, 0, + errorcode); fetch->aborted = true; FreeVec(errorstring); } diff --git a/amiga/gui.c b/amiga/gui.c index bd8d4cb28..ebd5d6657 100755 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -47,6 +47,7 @@ #include "amiga/menu.h" #include "amiga/options.h" #include <libraries/keymap.h> +#include "desktop/save_complete.h" #include "desktop/textinput.h" #include <intuition/pointerclass.h> #include <math.h> @@ -66,7 +67,6 @@ #include "amiga/cookies.h" #include "amiga/clipboard.h" #include <proto/keymap.h> -#include "amiga/save_complete.h" #include "amiga/fetch_file.h" #include "amiga/fetch_mailto.h" #include "amiga/search.h" @@ -3410,6 +3410,23 @@ void gui_window_stop_throbber(struct gui_window *g) // g->shared->throbber_frame = 0; } +/** + * function to add retrieved favicon to gui + */ +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) +{ +} + void ami_update_throbber(struct gui_window_2 *g,bool redraw) { struct IBox *bbox; diff --git a/amiga/gui.h b/amiga/gui.h index ddf1dc9b2..47aace0db 100755 --- a/amiga/gui.h +++ b/amiga/gui.h @@ -56,6 +56,8 @@ enum GID_NEXT, GID_PREV, GID_SEARCHSTRING, + GID_SHOWALL, + GID_CASE, GID_HSCROLL, GID_LAST }; diff --git a/amiga/menu.c b/amiga/menu.c index f80907ccd..7ceb9191d 100755 --- a/amiga/menu.c +++ b/amiga/menu.c @@ -30,13 +30,13 @@ #include "amiga/save_pdf.h" #include "desktop/save_text.h" #include "desktop/save_pdf/pdf_plotters.h" +#include "desktop/save_complete.h" #include <string.h> #include "amiga/tree.h" #include "amiga/history.h" #include "amiga/cookies.h" #include <proto/exec.h> #include "amiga/arexx.h" -#include "amiga/save_complete.h" #include "utils/url.h" #include <dos/anchorpath.h> #include "desktop/textinput.h" diff --git a/amiga/save_complete.c b/amiga/save_complete.c index 29b58ba3b..1cadc2030 100755 --- a/amiga/save_complete.c +++ b/amiga/save_complete.c @@ -2,6 +2,7 @@ * Copyright 2004 John M Bell <jmb202@ecs.soton.ac.uk> * Copyright 2004-2007 James Bursa <bursa@users.sourceforge.net> * Copyright 2008 Chris Young <chris@unsatisfactorysoftware.co.uk> + * Copyright 2009 Mark Benjamin <netsurf-browser.org.MarkBenjamin@dfgh.net> * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -18,807 +19,97 @@ * 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 "utils/config.h" -#include "css/css.h" -#include "render/box.h" -#include "amiga/save_complete.h" -#include "utils/log.h" -#include "utils/url.h" +#include "desktop/save_complete.h" #include "utils/utils.h" -#include <proto/dos.h> #include <proto/icon.h> #include <workbench/icon.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); +#include "content/content.h" /** - * 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; - htmlParserCtxtPtr parser; - BPTR fh = 0; - - 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, source, - source + source_len); +* 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 */ - if(fh = FOpen(spath,MODE_NEWFILE,0)) - { - FWrite(fh,source,1,source_len); - FClose(fh); - SetComment(spath,c->url); - } - - 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), - obj->source_data, - 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; - } -*/ - if(fh = FOpen(spath,MODE_NEWFILE,0)) - { - FWrite(fh,obj->source_data,1,obj->source_size); - FClose(fh); - SetComment(spath,obj->url); - } - - } - - /*save_complete_list_dump();*/ - - /* make a copy of the document tree */ - parser = htmlCreateMemoryParserCtxt(c->source_data, c->source_size); - if (!parser) { +bool save_complete_gui_save(const char *path, const char *filename, size_t len, + const char *sourcedata, content_type type) +{ + int res; + int namelen; + char deftype[5]; + struct DiskObject *dobj = NULL; + namelen = strlen(path) + strlen(filename) + 2; + char *fullpath = malloc(namelen); + if (!fullpath) { warn_user("NoMemory", 0); return false; } - /* set parser charset */ - if (c->data.html.encoding) { - xmlCharEncodingHandler *enc_handler; - enc_handler = - xmlFindCharEncodingHandler(c->data.html.encoding); - if (enc_handler) { - xmlCtxtResetLastError(parser); - if (xmlSwitchToEncoding(parser, enc_handler)) { - xmlFreeDoc(parser->myDoc); - htmlFreeParserCtxt(parser); - warn_user("MiscError", - "Encoding switch failed"); - return false; - } - } - } - - htmlParseDocument(parser); - - /* rewrite all urls we know about */ - if (!rewrite_document_urls(parser->myDoc, c->data.html.base_url)) { - xmlFreeDoc(parser->myDoc); - htmlFreeParserCtxt(parser); - warn_user("NoMemory", 0); + snprintf(fullpath, namelen, "%s/%s", path, filename); + FILE *f = fopen(fullpath, "w"); + if (f == NULL) return false; - } - - /* save the html file out last of all */ - if (index) + res = fwrite(sourcedata, len, 1, f); + fclose(f); + switch(type) { - struct DiskObject *dobj = NULL; - - snprintf(spath, sizeof spath, "%s/index", path); - - dobj = GetIconTags(NULL,ICONGETA_GetDefaultName,"html", - ICONGETA_GetDefaultType,WBPROJECT, - TAG_DONE); - - PutIconTags(spath,dobj, - ICONPUTA_NotifyWorkbench,TRUE, - TAG_DONE); - } - else - { - snprintf(spath, sizeof spath, "%s/%x", path, (unsigned int)c); - } - - errno = 0; - if (htmlSaveFileFormat(spath, parser->myDoc, 0, 0) == -1) { - if (errno) - warn_user("SaveError", strerror(errno)); - else - warn_user("SaveError", "htmlSaveFileFormat failed"); - return false; - } - -/* - 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; - } -*/ - - xmlFreeDoc(parser->myDoc); - htmlFreeParserCtxt(parser); - - 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; - BPTR fh = 0; - - 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; - } - - if(fh = FOpen(spath,MODE_NEWFILE,0)) - { - FWrite(fh,source,1,source_len); - FClose(fh); - SetComment(spath,c->url); - } -/* - error = xosfile_save_stamped(spath, 0xf79, source, - 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) + case CONTENT_HTML: + strcpy(deftype,"html"); 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(n->name, "object") == 0) { - if (!rewrite_url(n, "data", base)) - return false; - } - /* 2 */ - else if (strcmp(n->name, "a") == 0 || - strcmp(n->name, "area") == 0 || - strcmp(n->name, "link") == 0) { - if (!rewrite_url(n, "href", base)) - return false; - } - /* 3 */ - else if (strcmp(n->name, "frame") == 0 || - strcmp(n->name, "iframe") == 0 || - strcmp(n->name, "input") == 0 || - strcmp(n->name, "img") == 0 || - strcmp(n->name, "script") == 0) { - if (!rewrite_url(n, "src", base)) + case CONTENT_CSS: + strcpy(deftype,"css"); + break; + default: + free(fullpath); return false; + break; } - /* 4 */ - else if (strcmp(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( - content, - strlen((char*)content), - &len, base); - xmlFree(content); - if (!rewritten) - return false; - - /* set new content */ - xmlNodeSetContentLen(child, - (const xmlChar*)rewritten, - len); - } - - return true; - } - /* 5 */ - else if (strcmp(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 = 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) + + dobj = GetIconTags(NULL,ICONGETA_GetDefaultName,deftype, + ICONGETA_GetDefaultType,WBPROJECT, + TAG_DONE); + + PutIconTags(fullpath, dobj, + ICONPUTA_NotifyWorkbench, TRUE, TAG_DONE); + free(fullpath); + if (res != 1) 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. - */ +* wrapper for lib function htmlSaveFileFormat; front sets path from +* path + filename in a filesystem-specific way +*/ -bool save_complete_inventory(const char *path) +int save_complete_htmlSaveFileFormat(const char *path, const char *filename, + xmlDocPtr cur, const char *encoding, int format) { - 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; + int ret; + int len = strlen(path) + strlen(filename) + 2; + struct DiskObject *dobj = NULL; + char *fullpath = malloc(len); + if (!fullpath){ + warn_user("NoMemory", 0); + return -1; + } + snprintf(fullpath, len, "%s/%s", path, filename); + ret = htmlSaveFileFormat(fullpath, cur, encoding, format); + dobj = GetIconTags(NULL,ICONGETA_GetDefaultName, "html", + ICONGETA_GetDefaultType,WBPROJECT, + TAG_DONE); + + PutIconTags(fullpath, dobj, + ICONPUTA_NotifyWorkbench, TRUE, TAG_DONE); + + free(fullpath); + return ret; } diff --git a/amiga/search.c b/amiga/search.c index 1de08a50c..b5008a89b 100755 --- a/amiga/search.c +++ b/amiga/search.c @@ -28,6 +28,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" @@ -44,10 +45,12 @@ #include <proto/string.h> #include <proto/button.h> #include <proto/label.h> +#include <proto/checkbox.h> #include <classes/window.h> #include <gadgets/layout.h> #include <gadgets/string.h> #include <gadgets/button.h> +#include <gadgets/checkbox.h> #include <images/label.h> #include <reaction/reaction_macros.h> @@ -68,580 +71,25 @@ struct list_entry { struct list_entry *next; }; -struct gui_window *search_current_window = NULL; +static bool search_insert; -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 find_window *fwin = NULL; -#define RECENT_SEARCHES 8 -bool search_insert; -static char *recent_search[RECENT_SEARCHES]; - -static void start_search(bool forwards,char *search_string); -static void do_search(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, 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); -/** - * 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,char *string) -{ - int string_len; - int i = 0; - - 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); - - RefreshSetGadgetAttrs(fwin->gadgets[GID_PREV],fwin->win,NULL, - GA_Disabled,TRUE, - TAG_DONE); - - RefreshSetGadgetAttrs(fwin->gadgets[GID_NEXT],fwin->win,NULL, - GA_Disabled,TRUE, - TAG_DONE); - - gui_window_set_scroll(search_current_window, 0, 0); - return; - } - - do_search(string, string_len, - false, // case sensitivity - forwards); -} - -/** - * Ends the search process, invalidating all global state and - * freeing the list of found boxes - * - * \param w the search window handle (not used) - */ -void ami_gui_search_end(void) -{ - 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(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->shared->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(false); - - RefreshSetGadgetAttrs(fwin->gadgets[GID_PREV],fwin->win,NULL, - GA_Disabled,(!search_current || !search_current->prev), - TAG_DONE); - - RefreshSetGadgetAttrs(fwin->gadgets[GID_NEXT],fwin->win,NULL, - GA_Disabled,(!search_current || !search_current->next), - TAG_DONE); - - 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, 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; -} - - -/** - * 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; -} - - -/** - * 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) -{ - 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; -} - - -/** - * 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 - */ - -struct list_entry *add_entry(unsigned start_idx, unsigned end_idx) -{ - 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; - - 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; -} - - -/** - * 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 - */ - -bool gui_search_term_highlighted(struct gui_window *g, - unsigned start_offset, unsigned end_offset, - unsigned *start_idx, unsigned *end_idx) -{ - 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; -} - - -/** - * Specifies whether all matches or just the current match should - * be highlighted in the search text. - */ - -void show_all(bool all) -{ - 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->shared->bw); - if (a->sel) { - struct content *c = search_current_window->shared->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); - } - } - } -} +search_flags_t ami_search_flags(void); +char *ami_search_string(void); +static void ami_search_set_status(bool found, void *p); +static void ami_search_set_hourglass(bool active, void *p); +static void ami_search_add_recent(const char *string, void *p); +static void ami_search_set_forward_state(bool active, void *p); +static void ami_search_set_back_state(bool active, void *p); + +static struct search_callbacks ami_search_callbacks = { + ami_search_set_forward_state, + ami_search_set_back_state, + ami_search_set_status, + ami_search_set_hourglass, + ami_search_add_recent +}; /** @@ -649,15 +97,6 @@ void show_all(bool all) * * \param found search pattern matched in text */ - -void show_status(bool found) -{ -/* - ro_gui_set_icon_string(dialog_search, ICON_SEARCH_STATUS, - found ? "" : messages_get("NotFound"), true); -*/ -} - void ami_search_open(struct gui_window *gwin) { struct content *c = gwin->shared->bw->current_content; @@ -667,12 +106,18 @@ void ami_search_open(struct gui_window *gwin) c->type != CONTENT_TEXTPLAIN)) return; - search_current_window = gwin; + if (gwin->shared->bw->search_context == NULL) + search_create_context(gwin->shared->bw, + &ami_search_callbacks, NULL); search_insert = true; if(fwin) { - ami_gui_search_end(); + if(fwin->gwin->shared->bw->search_context != NULL) + search_destroy_context(fwin->gwin->shared->bw-> + search_context); + ami_search_set_forward_state(true, NULL); + ami_search_set_back_state(true, NULL); fwin->gwin->shared->searchwin = NULL; fwin->gwin = gwin; gwin->shared->searchwin = fwin; @@ -709,6 +154,21 @@ void ami_search_open(struct gui_window *gwin) LabelEnd, */ CHILD_WeightedHeight,0, + LAYOUT_AddChild, fwin->gadgets[GID_CASE] = CheckBoxObject, + GA_ID,GID_CASE, + GA_Text,messages_get("CaseSens"), + GA_Selected,FALSE, + GA_TabCycle,TRUE, + GA_RelVerify,TRUE, + CheckBoxEnd, + LAYOUT_AddChild, fwin->gadgets[GID_SHOWALL] = CheckBoxObject, + GA_ID,GID_SHOWALL, + GA_Text,messages_get("ShowAll"), + GA_Selected,FALSE, + GA_TabCycle,TRUE, + GA_RelVerify,TRUE, + CheckBoxEnd, + LAYOUT_AddChild, HGroupObject, LAYOUT_AddChild, fwin->gadgets[GID_PREV] = ButtonObject, GA_ID,GID_PREV, @@ -739,7 +199,10 @@ void ami_search_open(struct gui_window *gwin) void ami_search_close(void) { - ami_gui_search_end(); + if (fwin->gwin->shared->bw->search_context != NULL) + search_destroy_context(fwin->gwin->shared->bw->search_context); + ami_search_set_forward_state(true, NULL); + ami_search_set_back_state(true, NULL); fwin->gwin->shared->searchwin = NULL; DisposeObject(fwin->objects[OID_MAIN]); DelObject(fwin->node); @@ -752,44 +215,158 @@ BOOL ami_search_event(void) ULONG class,result,relevent = 0; ULONG column; uint16 code; - char *text; + search_flags_t flags; while((result = RA_HandleInput(fwin->objects[OID_MAIN],&code)) != WMHI_LASTMSG) { switch(result & WMHI_CLASSMASK) // class - { - case WMHI_GADGETUP: - switch(result & WMHI_GADGETMASK) - { - case GID_NEXT: - search_insert = true; - GetAttr(STRINGA_TextVal,fwin->gadgets[GID_SEARCHSTRING],(ULONG *)&text); - start_search(true,text); - break; - - case GID_PREV: - search_insert = true; - GetAttr(STRINGA_TextVal,fwin->gadgets[GID_SEARCHSTRING],(ULONG *)&text); - start_search(false,text); - break; - - case GID_SEARCHSTRING: - RefreshSetGadgetAttrs(fwin->gadgets[GID_PREV],fwin->win,NULL, - GA_Disabled,FALSE, - TAG_DONE); - - RefreshSetGadgetAttrs(fwin->gadgets[GID_NEXT],fwin->win,NULL, - GA_Disabled,FALSE, - TAG_DONE); - break; - } + { + case WMHI_GADGETUP: + switch(result & WMHI_GADGETMASK) + { + case GID_NEXT: + search_insert = true; + flags = SEARCH_FLAG_FORWARDS | + ami_search_flags(); + if (search_verify_new( + search_data.search_window, + &ami_search_callbacks, NULL)) + search_step(fwin->gwin->shared->bw, + flags, + ami_search_string()); break; - case WMHI_CLOSEWINDOW: - ami_search_close(); - return TRUE; + case GID_PREV: + search_insert = true; + flags = ~SEARCH_FLAG_FORWARDS & + ami_search_flags(); + if (search_verify_new( + search_data.search_window, + &ami_search_callbacks, NULL)) + search_step(fwin->gwin->shared->bw, + flags, + ami_search_string()); + break; + + case GID_SEARCHSTRING: + if (fwin->gwin->shared-> + bw->search_context + != NULL) + search_destroy_context( + fwin->gwin-> + shared->bw-> + search_context); + ami_search_set_forward_state( + true, NULL); + ami_search_set_back_state( + true, NULL); + + RefreshSetGadgetAttrs(fwin->gadgets[GID_PREV],fwin->win,NULL, + GA_Disabled,FALSE, + TAG_DONE); + + RefreshSetGadgetAttrs(fwin->gadgets[GID_NEXT],fwin->win,NULL, + GA_Disabled,FALSE, + TAG_DONE); break; } + break; + + case WMHI_CLOSEWINDOW: + ami_search_close(); + return TRUE; + break; + } } return FALSE; } + +/** +* Change the displayed search status. +* \param found search pattern matched in text +* \param p the pointer sent to search_verify_new() / search_create_context() +*/ + +void ami_search_set_status(bool found, void *p) +{ +} + +/** +* display hourglass while searching +* \param active start/stop indicator +* \param p the pointer sent to search_verify_new() / search_create_context() +*/ + +void ami_search_set_hourglass(bool active, void *p) +{ + SetWindowPointer(fwin->win, + WA_BusyPointer,active, + WA_PointerDelay,active, + TAG_DONE); +} + +/** +* retrieve string being searched for from gui +*/ + +char *ami_search_string(void) +{ + char *text; + GetAttr(STRINGA_TextVal,fwin->gadgets[GID_SEARCHSTRING],(ULONG *)&text); + return text; + +} + +/** +* 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; +* core gives no guarantee of the integrity of the const char * +* \param string search pattern +* \param p the pointer sent to search_verify_new() / search_create_context() +*/ + +void ami_search_add_recent(const char *string, void *p) +{ +} + +/** +* activate search forwards button in gui +* \param active activate/inactivate +* \param p the pointer sent to search_verify_new() / search_create_context() +*/ + +void ami_search_set_forward_state(bool active, void *p) +{ + RefreshSetGadgetAttrs(fwin->gadgets[GID_NEXT],fwin->win,NULL, + GA_Disabled, active ? FALSE : TRUE, TAG_DONE); + +} + +/** +* activate search forwards button in gui +* \param active activate/inactivate +* \param p the pointer sent to search_verify_new() / search_create_context() +*/ + +void ami_search_set_back_state(bool active, void *p) +{ + RefreshSetGadgetAttrs(fwin->gadgets[GID_PREV],fwin->win,NULL, + GA_Disabled, active ? FALSE : TRUE, TAG_DONE); +} + +/** +* retrieve state of 'case sensitive', 'show all' checks in gui +*/ + +search_flags_t ami_search_flags(void) +{ + ULONG case_sensitive, showall; + search_flags_t flags; + GetAttr(GA_Selected,fwin->gadgets[GID_CASE],(ULONG *)&case_sensitive); + GetAttr(GA_Selected,fwin->gadgets[GID_SHOWALL],(ULONG *)&showall); + flags = 0 | (case_sensitive ? SEARCH_FLAG_CASE_SENSITIVE : 0) | + (showall ? SEARCH_FLAG_SHOWALL : 0); + return flags; +} + |