move page search gui callbacks to their own operations table

This commit is contained in:
Vincent Sanders 2014-03-18 22:32:52 +00:00
parent fec9f916b6
commit 4d4d74c8cd
28 changed files with 278 additions and 304 deletions

View File

@ -5167,6 +5167,7 @@ int main(int argc, char** argv)
.download = amiga_download_table,
.fetch = &amiga_fetch_table,
.utf8 = amiga_utf8_table,
.search = amiga_search_table,
};
/* Open popupmenu.library just to check the version.

View File

@ -69,14 +69,15 @@ 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 gui_search_callbacks ami_search_callbacks = {
ami_search_set_forward_state,
ami_search_set_back_state,
static struct gui_search_table search_table = {
ami_search_set_status,
ami_search_set_hourglass,
ami_search_add_recent
ami_search_add_recent,
ami_search_set_forward_state,
ami_search_set_back_state,
};
struct gui_search_table *amiga_search_table = &search_table;
/**
* Change the displayed search status.
@ -90,8 +91,6 @@ void ami_search_open(struct gui_window *gwin)
if(fwin)
{
browser_window_search_clear(fwin->gwin->shared->bw);
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;
@ -177,8 +176,6 @@ void ami_search_open(struct gui_window *gwin)
void ami_search_close(void)
{
browser_window_search_clear(fwin->gwin->shared->bw);
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);
@ -201,12 +198,7 @@ BOOL ami_search_event(void)
switch(result & WMHI_GADGETMASK)
{
case GID_SEARCHSTRING:
browser_window_search_clear(
fwin->gwin->shared->bw);
ami_search_set_forward_state(
true, NULL);
ami_search_set_back_state(
true, NULL);
browser_window_search_clear(fwin->gwin->shared->bw);
RefreshSetGadgetAttrs((struct Gadget *)fwin->objects[GID_PREV],
fwin->win, NULL,
@ -226,7 +218,7 @@ BOOL ami_search_event(void)
ami_search_flags();
browser_window_search(
fwin->gwin->shared->bw,
&ami_search_callbacks, NULL,
NULL,
flags, ami_search_string());
ActivateWindow(fwin->gwin->shared->win);
break;
@ -237,7 +229,7 @@ BOOL ami_search_event(void)
ami_search_flags();
browser_window_search(
fwin->gwin->shared->bw,
&ami_search_callbacks, NULL,
NULL,
flags, ami_search_string());
ActivateWindow(fwin->gwin->shared->win);
break;

View File

@ -28,6 +28,8 @@ struct find_window {
struct gui_window *gwin;
};
struct gui_search_table *amiga_search_table;
void ami_search_open(struct gui_window *gwin);
BOOL ami_search_event(void);
void ami_search_close(void);

View File

@ -1112,6 +1112,7 @@ int main(int argc, char** argv)
.download = atari_download_table,
.fetch = &atari_fetch_table,
.utf8 = atari_utf8_table,
.search = atari_search_table,
};
/* @todo logging file descriptor update belongs in a nslog_init callback */

View File

@ -53,13 +53,16 @@ static void nsatari_search_add_recent(const char *string, void *p);
void nsatari_search_set_forward_state(bool active, void *p);
void nsatari_search_set_back_state(bool active, void *p);
static struct gui_search_callbacks nsatari_search_callbacks = {
nsatari_search_set_forward_state,
nsatari_search_set_back_state,
nsatari_search_set_status,
nsatari_search_set_hourglass,
nsatari_search_add_recent
};
static struct gui_search_table search_table = {
nsatari_search_set_status,
nsatari_search_set_hourglass,
nsatari_search_add_recent,
nsatari_search_set_forward_state,
nsatari_search_set_back_state,
};
struct gui_search_table *atari_search_table = &search_table;
/**
@ -282,7 +285,7 @@ void nsatari_search_perform(struct s_search_form_session *s, OBJECT *obj,
else
s->state.flags &= (~SEARCH_FLAG_FORWARDS);
browser_window_search(s->bw, &nsatari_search_callbacks, s,
browser_window_search(s->bw, s,
s->state.flags,
gemtk_obj_get_text(obj, TOOLBAR_TB_SRCH));

View File

@ -49,6 +49,9 @@ typedef struct s_search_form_session * SEARCH_FORM_SESSION;
struct s_search_form_session * nsatari_search_session_create(OBJECT * obj,
struct browser_window *bw);
struct gui_search_table *atari_search_table;
void nsatari_search_session_destroy(struct s_search_form_session *s);
void nsatari_search_perform(struct s_search_form_session *s, OBJECT *obj,
search_flags_t f);

View File

@ -21,6 +21,7 @@
#import "cocoa/gui.h"
#import "cocoa/plotter.h"
#import "cocoa/DownloadWindowController.h"
#import "cocoa/SearchWindowController.h"
#import "cocoa/selection.h"
#import "cocoa/fetch.h"
@ -190,6 +191,7 @@ int main( int argc, char **argv )
.clipboard = cocoa_clipboard_table,
.download = cocoa_download_table,
.fetch = cocoa_fetch_table,
.search = cocoa_search_table,
};
cocoa_autorelease();

View File

@ -49,4 +49,6 @@ typedef enum {
- (void) search: (SearchDirection)direction;
struct gui_search_table *cocoa_search_table;
@end

View File

@ -26,14 +26,13 @@
static void cocoa_search_set_back( bool active, void *p );
static void cocoa_search_set_forward( bool active, void *p );
static struct gui_search_callbacks cocoa_search_callbacks = {
static struct gui_search_table search_table = {
.forward_state = cocoa_search_set_forward,
.back_state = cocoa_search_set_back,
.status = NULL,
.hourglass = NULL,
.add_recent = NULL
};
struct gui_search_table *cocoa_search_table = &search_table;
@implementation SearchWindowController
@synthesize caseSensitive;
@ -76,7 +75,7 @@ static struct gui_search_callbacks cocoa_search_callbacks = {
if (selectAll) flags |= SEARCH_FLAG_SHOWALL;
struct browser_window *bw = [browser browser];
browser_window_search( bw, &cocoa_search_callbacks, self, flags, [searchString UTF8String] );
browser_window_search( bw, self, flags, [searchString UTF8String] );
}
- (IBAction) searchStringDidChange: (id) sender;

View File

@ -838,15 +838,15 @@ bool content_drop_file_at_point(struct hlcache_handle *h,
}
void content_search(struct hlcache_handle *h,
struct gui_search_callbacks *gui_callbacks, void *gui_data,
void content_search(struct hlcache_handle *h, void *context,
search_flags_t flags, const char *string)
{
struct content *c = hlcache_handle_get_content(h);
assert(c != 0);
if (c->handler->search != NULL)
c->handler->search(c, gui_callbacks, gui_data, flags, string);
if (c->handler->search != NULL) {
c->handler->search(c, context, flags, string);
}
}
@ -855,8 +855,9 @@ void content_search_clear(struct hlcache_handle *h)
struct content *c = hlcache_handle_get_content(h);
assert(c != 0);
if (c->handler->search_clear != NULL)
if (c->handler->search_clear != NULL) {
c->handler->search_clear(c);
}
}

View File

@ -266,10 +266,11 @@ bool content_scroll_at_point(struct hlcache_handle *h,
int x, int y, int scrx, int scry);
bool content_drop_file_at_point(struct hlcache_handle *h,
int x, int y, char *file);
void content_search(struct hlcache_handle *h,
struct gui_search_callbacks *gui_callbacks, void *gui_data,
void content_search(struct hlcache_handle *h, void *context,
search_flags_t flags, const char *string);
void content_search_clear(struct hlcache_handle *h);
void content_debug_dump(struct hlcache_handle *h, FILE *f);
struct content_rfc5988_link *content_find_rfc5988_link(struct hlcache_handle *c,
lwc_string *rel);

View File

@ -73,10 +73,8 @@ struct content_handler {
int scrx, int scry);
bool (*drop_file_at_point)(struct content *c, int x, int y,
char *file);
void (*search)(struct content *c,
struct gui_search_callbacks *gui_callbacks,
void *gui_data, search_flags_t flags,
const char *string);
void (*search)(struct content *c, void *context, search_flags_t flags,
const char *string);
void (*search_clear)(struct content *c);
void (*debug_dump)(struct content *c, FILE *f);
nserror (*clone)(const struct content *old, struct content **newc);

View File

@ -422,6 +422,52 @@ struct gui_utf8_table {
nserror (*local_to_utf8)(const char *string, size_t len, char **result);
};
/**
* function table for page text search.
*/
struct gui_search_table {
/**
* Change the displayed search status.
*
* \param found search pattern matched in text
* \param p gui private data pointer provided with search callbacks
*/
void (*status)(bool found, void *p);
/**
* display hourglass while searching.
*
* \param active start/stop indicator
* \param p gui private data pointer provided with search callbacks
*/
void (*hourglass)(bool active, void *p);
/**
* add search string to recent searches list
* front has full liberty how to implement the bare notification;
* core gives no guarantee of the integrity of the string
*
* \param string search pattern
* \param p gui private data pointer provided with search callbacks
*/
void (*add_recent)(const char *string, void *p);
/**
* activate search forwards button in gui
*
* \param active activate/inactivate
* \param p gui private data pointer provided with search callbacks
*/
void (*forward_state)(bool active, void *p);
/**
* activate search back button in gui
*
* \param active activate/inactivate
* \param p gui private data pointer provided with search callbacks
*/
void (*back_state)(bool active, void *p);
};
/**
* Graphical user interface browser misc function table.
@ -528,6 +574,14 @@ struct gui_table {
* implies the local encoding is utf8.
*/
struct gui_utf8_table *utf8;
/**
*
* Page search table.
*
* Provides routines for the interactive text search on a page.
*/
struct gui_search_table *search;
};

View File

@ -343,6 +343,62 @@ static nserror verify_utf8_register(struct gui_utf8_table *gut)
return NSERROR_OK;
}
static void gui_default_status(bool found, void *p)
{
}
static void gui_default_hourglass(bool active, void *p)
{
}
static void gui_default_add_recent(const char *string, void *p)
{
}
static void gui_default_forward_state(bool active, void *p)
{
}
static void gui_default_back_state(bool active, void *p)
{
}
static struct gui_search_table default_search_table = {
.status = gui_default_status,
.hourglass = gui_default_hourglass,
.add_recent = gui_default_add_recent,
.forward_state = gui_default_forward_state,
.back_state = gui_default_back_state,
};
/** verify search table is valid */
static nserror verify_search_register(struct gui_search_table *gst)
{
/* check table is present */
if (gst == NULL) {
return NSERROR_BAD_PARAMETER;
}
/* fill in the optional entries with defaults */
if (gst->status == NULL) {
gst->status = default_search_table.status;
}
if (gst->hourglass == NULL) {
gst->hourglass = default_search_table.hourglass;
}
if (gst->add_recent == NULL) {
gst->add_recent = default_search_table.add_recent;
}
if (gst->forward_state == NULL) {
gst->forward_state = default_search_table.forward_state;
}
if (gst->back_state == NULL) {
gst->back_state = default_search_table.back_state;
}
return NSERROR_OK;
}
static nsurl *gui_default_get_resource_url(const char *path)
{
return NULL;
@ -525,7 +581,7 @@ nserror gui_factory_register(struct gui_table *gt)
/* utf8 table */
if (gt->utf8 == NULL) {
/* set default clipboard table */
/* set default utf8 table */
gt->utf8 = &default_utf8_table;
}
err = verify_utf8_register(gt->utf8);
@ -533,6 +589,16 @@ nserror gui_factory_register(struct gui_table *gt)
return err;
}
/* search table */
if (gt->search == NULL) {
/* set default search table */
gt->search = &default_search_table;
}
err = verify_search_register(gt->search);
if (err != NSERROR_OK) {
return err;
}
guit = gt;
return NSERROR_OK;

View File

@ -21,66 +21,27 @@
/** \file
* Free text search (core)
*/
#include "utils/config.h"
#include <ctype.h>
#include <string.h>
#include <dom/dom.h>
#include "content/content.h"
#include "content/hlcache.h"
#include "desktop/browser_private.h"
#include "utils/nsoption.h"
#include "desktop/search.h"
#include "desktop/selection.h"
#include "render/box.h"
#include "render/html.h"
#include "render/search.h"
#include "render/textplain.h"
#include "utils/config.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/url.h"
#include "utils/utils.h"
/**
* Starts or continues an existing search.
*
* \param bw the browser_window to search
* \param callbacks callbacks vtable to update frontend according to results
* \param gui_data a pointer returned to the callbacks
* \param flags search flags
* \param string string to search for
*/
void browser_window_search(struct browser_window *bw,
struct gui_search_callbacks *gui_callbacks, void *gui_data,
/* exported function documented in desktop/search.h */
void browser_window_search(struct browser_window *bw, void *context,
search_flags_t flags, const char *string)
{
assert(gui_callbacks != NULL);
if (bw == NULL || bw->current_content == NULL)
return;
content_search(bw->current_content, gui_callbacks, gui_data,
flags, string);
if ((bw != NULL) &&
(bw->current_content != NULL)) {
content_search(bw->current_content, context, flags, string);
}
}
/**
* Clear up a search. Frees any memory used by the search
*
* \param bw the browser_window to search
* \param callbacks callbacks vtable to update frontend according to results
* \param gui_data a pointer returned to the callbacks
* \param flags search flags
* \param string string to search for
*/
/* exported function documented in desktop/search.h */
void browser_window_search_clear(struct browser_window *bw)
{
if (bw == NULL || bw->current_content == NULL)
return;
content_search_clear(bw->current_content);
if ((bw != NULL) &&
(bw->current_content != NULL)) {
content_search_clear(bw->current_content);
}
}

View File

@ -33,54 +33,24 @@ typedef enum {
} search_flags_t;
/**
* Change the displayed search status.
* \param found search pattern matched in text
* \param p gui private data pointer provided with search callbacks
* Starts or continues an existing search.
*
* \param bw The browser_window to search.
* \param context A context pointer passed to the callbacks.
* \param flags Flags controlling the search operation.
* \param string The string being searched for.
*/
typedef void (*gui_search_status)(bool found, void *p);
void browser_window_search(struct browser_window *bw, void *context, search_flags_t flags, const char *string);
/**
* display hourglass while searching
* \param active start/stop indicator
* \param p gui private data pointer provided with search callbacks
* Clear up a search.
*
* Frees any memory used by the search.
*
* \param bw The browser window to clean up the search for.
* \param context A context pointer passed to the callbacks.
*/
typedef void (*gui_search_hourglass)(bool active, void *p);
/**
* add search string to recent searches list
* front has full liberty how to implement the bare notification;
* core gives no guarantee of the integrity of the const char *
* \param string search pattern
* \param p gui private data pointer provided with search callbacks
*/
typedef void (*gui_search_add_recent)(const char *string, void *p);
/**
* activate search forwards button in gui
* \param active activate/inactivate
* \param p gui private data pointer provided with search callbacks
*/
typedef void (*gui_search_forward_state)(bool active, void *p);
/**
* activate search back button in gui
* \param active activate/inactivate
* \param p gui private data pointer provided with search callbacks
*/
typedef void (*gui_search_back_state)(bool active, void *p);
struct gui_search_callbacks {
gui_search_forward_state forward_state;
gui_search_back_state back_state;
gui_search_status status;
gui_search_hourglass hourglass;
gui_search_add_recent add_recent;
};
void browser_window_search(struct browser_window *bw,
struct gui_search_callbacks *gui_callbacks, void *gui_data,
search_flags_t flags, const char *string);
void browser_window_search_clear(struct browser_window *bw);
#endif

View File

@ -69,6 +69,7 @@
#include "gtk/window.h"
#include "gtk/schedule.h"
#include "gtk/selection.h"
#include "gtk/search.h"
#include "render/form.h"
#include "utils/filepath.h"
@ -1015,6 +1016,7 @@ int main(int argc, char** argv)
.clipboard = nsgtk_clipboard_table,
.download = nsgtk_download_table,
.fetch = nsgtk_fetch_table,
.search = nsgtk_search_table,
};
/* check home directory is available */

View File

@ -1385,9 +1385,6 @@ MULTIHANDLER(reload)
/* clear potential search effects */
browser_window_search_clear(bw);
nsgtk_search_set_forward_state(true, g->top_level);
nsgtk_search_set_back_state(true, g->top_level);
browser_window_reload(bw, true);
return TRUE;
@ -1404,9 +1401,6 @@ MULTIHANDLER(back)
/* clear potential search effects */
browser_window_search_clear(bw);
nsgtk_search_set_forward_state(true, g->top_level);
nsgtk_search_set_back_state(true, g->top_level);
browser_window_history_back(bw, false);
nsgtk_window_update_back_forward(g);
@ -1424,9 +1418,6 @@ MULTIHANDLER(forward)
/* clear potential search effects */
browser_window_search_clear(bw);
nsgtk_search_set_forward_state(true, g->top_level);
nsgtk_search_set_back_state(true, g->top_level);
browser_window_history_forward(bw, false);
nsgtk_window_update_back_forward(g);
@ -2399,8 +2390,6 @@ void nsgtk_scaffolding_toggle_search_bar_visibility(nsgtk_scaffolding *g)
if (bw != NULL) {
browser_window_search_clear(bw);
}
nsgtk_search_set_forward_state(true, g->top_level);
nsgtk_search_set_back_state(true, g->top_level);
gtk_widget_hide(GTK_WIDGET(g->search->bar));
} else {
@ -2438,9 +2427,6 @@ void nsgtk_scaffolding_set_top_level(struct gui_window *gw)
/* clear effects of potential searches */
browser_window_search_clear(bw);
nsgtk_search_set_forward_state(true, gw);
nsgtk_search_set_back_state(true, gw);
nsgtk_scaffolding_set_icon(gw);
/* Ensure the window's title bar is updated */

View File

@ -25,10 +25,6 @@
#include <string.h>
#include <gdk/gdkkeysyms.h>
#include "gtk/compat.h"
#include "gtk/search.h"
#include "gtk/scaffolding.h"
#include "gtk/window.h"
#include "utils/config.h"
#include "content/content.h"
#include "content/hlcache.h"
@ -40,41 +36,18 @@
#include "utils/messages.h"
#include "utils/utils.h"
/**
* Change the displayed search status.
* \param found search pattern matched in text
* \param p the pointer sent to search_verify_new() / search_create_context()
*/
static void nsgtk_search_set_status(bool found, void *p)
{
}
#include "gtk/compat.h"
#include "gtk/search.h"
#include "gtk/scaffolding.h"
#include "gtk/window.h"
/**
* display hourglass while searching
* \param active start/stop indicator
* \param p the pointer sent to search_verify_new() / search_create_context()
*/
static void nsgtk_search_set_hourglass(bool active, void *p)
{
}
/**
* 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()
*/
static void nsgtk_search_add_recent(const char *string, void *p)
{
}
/* exported function documented in gtk/search.h */
void nsgtk_search_set_forward_state(bool active, struct gui_window *gw)
* activate search forwards button in gui.
*
* \param active activate/inactivate
* \param p the pointer sent to search_verify_new() / search_create_context()
*/
static void nsgtk_search_set_forward_state(bool active, struct gui_window *gw)
{
if (gw != NULL && nsgtk_get_browser_window(gw) != NULL) {
struct gtk_scaffolding *g = nsgtk_get_scaffold(gw);
@ -84,8 +57,13 @@ void nsgtk_search_set_forward_state(bool active, struct gui_window *gw)
}
}
/* exported function documented in gtk/search.h */
void nsgtk_search_set_back_state(bool active, struct gui_window *gw)
/**
* activate search back button in gui.
*
* \param active activate/inactivate
* \param p the pointer sent to search_verify_new() / search_create_context()
*/
static void nsgtk_search_set_back_state(bool active, struct gui_window *gw)
{
if (gw != NULL && nsgtk_get_browser_window(gw) != NULL) {
struct gtk_scaffolding *g = nsgtk_get_scaffold(gw);
@ -94,14 +72,6 @@ void nsgtk_search_set_back_state(bool active, struct gui_window *gw)
}
}
static struct gui_search_callbacks nsgtk_search_callbacks = {
(void *)nsgtk_search_set_forward_state,
(void *)nsgtk_search_set_back_state,
nsgtk_search_set_status,
nsgtk_search_set_hourglass,
nsgtk_search_add_recent
};
/** connected to the search forward button */
gboolean nsgtk_search_forward_button_clicked(GtkWidget *widget, gpointer data)
@ -120,7 +90,7 @@ gboolean nsgtk_search_forward_button_clicked(GtkWidget *widget, gpointer data)
nsgtk_scaffolding_search(g)->checkAll)) ?
SEARCH_FLAG_SHOWALL : 0);
browser_window_search(bw, &nsgtk_search_callbacks, (void *)gw, flags,
browser_window_search(bw, gw, flags,
gtk_entry_get_text(nsgtk_scaffolding_search(g)->entry));
return TRUE;
}
@ -143,7 +113,7 @@ gboolean nsgtk_search_back_button_clicked(GtkWidget *widget, gpointer data)
nsgtk_scaffolding_search(g)->checkAll)) ?
SEARCH_FLAG_SHOWALL : 0);
browser_window_search(bw, &nsgtk_search_callbacks, (void *)gw, flags,
browser_window_search(bw, gw, flags,
gtk_entry_get_text(nsgtk_scaffolding_search(g)->entry));
return TRUE;
}
@ -178,7 +148,7 @@ gboolean nsgtk_search_entry_changed(GtkWidget *widget, gpointer data)
nsgtk_scaffolding_search(g)->checkAll)) ?
SEARCH_FLAG_SHOWALL : 0);
browser_window_search(bw, &nsgtk_search_callbacks, (void *)gw, flags,
browser_window_search(bw, gw, flags,
gtk_entry_get_text(nsgtk_scaffolding_search(g)->entry));
return TRUE;
}
@ -201,7 +171,7 @@ gboolean nsgtk_search_entry_activate(GtkWidget *widget, gpointer data)
nsgtk_scaffolding_search(g)->checkAll)) ?
SEARCH_FLAG_SHOWALL : 0);
browser_window_search(bw, &nsgtk_search_callbacks, (void *)gw, flags,
browser_window_search(bw, gw, flags,
gtk_entry_get_text(nsgtk_scaffolding_search(g)->entry));
return FALSE;
}
@ -249,3 +219,9 @@ gboolean nsgtk_websearch_clear(GtkWidget *widget, GdkEventFocus *f,
static struct gui_search_table search_table = {
.forward_state = (void *)nsgtk_search_set_forward_state,
.back_state = (void *)nsgtk_search_set_back_state,
};
struct gui_search_table *nsgtk_search_table = &search_table;

View File

@ -19,8 +19,9 @@
#ifndef _NETSURF_GTK_SEARCH_H_
#define _NETSURF_GTK_SEARCH_H_
#include <gtk/gtk.h>
#include "gtk/scaffolding.h"
struct gui_search_table *nsgtk_search_table;
struct gtk_scaffolding;
void nsgtk_search_bar_toggle_visibility(struct gtk_scaffolding * g);
gboolean nsgtk_search_entry_changed(GtkWidget *widget, gpointer data);
@ -31,21 +32,5 @@ gboolean nsgtk_search_back_button_clicked(GtkWidget *widget, gpointer data);
gboolean nsgtk_search_close_button_clicked(GtkWidget *widget, gpointer data);
gboolean nsgtk_websearch_activate(GtkWidget *widget, gpointer data);
gboolean nsgtk_websearch_clear(GtkWidget *widget, GdkEventFocus *f, gpointer data);
/**
* activate search forwards button in gui.
*
* \param active activate/inactivate
* \param p the pointer sent to search_verify_new() / search_create_context()
*/
void nsgtk_search_set_forward_state(bool active, struct gui_window *gw);
/**
* activate search back button in gui.
*
* \param active activate/inactivate
* \param p the pointer sent to search_verify_new() / search_create_context()
*/
void nsgtk_search_set_back_state(bool active, struct gui_window *gw);
#endif

View File

@ -1072,13 +1072,11 @@ bool html_keypress(struct content *c, uint32_t key)
* Handle search.
*
* \param c content of type HTML
* \param gui_callbacks vtable for updating front end
* \param gui_data front end private data
* \param context front end private data
* \param flags search flags
* \param string search string
*/
void html_search(struct content *c,
struct gui_search_callbacks *gui_callbacks, void *gui_data,
void html_search(struct content *c, void *context,
search_flags_t flags, const char *string)
{
html_content *html = (html_content *)c;
@ -1103,8 +1101,7 @@ void html_search(struct content *c,
html->search = NULL;
}
html->search = search_create_context(c, CONTENT_HTML,
gui_callbacks, gui_data);
html->search = search_create_context(c, CONTENT_HTML, context);
if (html->search == NULL)
return;
@ -1135,8 +1132,9 @@ void html_search_clear(struct content *c)
free(html->search_string);
html->search_string = NULL;
if (html->search != NULL)
if (html->search != NULL) {
search_destroy_context(html->search);
}
html->search = NULL;
}

View File

@ -254,8 +254,7 @@ void html_mouse_action(struct content *c, struct browser_window *bw,
bool html_keypress(struct content *c, uint32_t key);
void html_overflow_scroll_callback(void *client_data,
struct scrollbar_msg_data *scrollbar_data);
void html_search(struct content *c,
struct gui_search_callbacks *gui_callbacks, void *gui_data,
void html_search(struct content *c, void *context,
search_flags_t flags, const char *string);
void html_search_clear(struct content *c);

View File

@ -21,27 +21,26 @@
/** \file
* Free text search (core)
*/
#include "utils/config.h"
#include <ctype.h>
#include <string.h>
#include <dom/dom.h>
#include "content/content.h"
#include "content/hlcache.h"
#include "desktop/selection.h"
#include "render/box.h"
#include "render/html.h"
#include "render/html_internal.h"
#include "render/search.h"
#include "render/textplain.h"
#include "utils/config.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/url.h"
#include "utils/utils.h"
#include "content/content.h"
#include "content/hlcache.h"
#include "desktop/selection.h"
#include "desktop/gui_factory.h"
#include "render/box.h"
#include "render/html.h"
#include "render/html_internal.h"
#include "render/search.h"
#include "render/textplain.h"
#ifndef NOF_ELEMENTS
#define NOF_ELEMENTS(array) (sizeof(array)/sizeof(*(array)))
@ -62,7 +61,6 @@ struct list_entry {
};
struct search_context {
struct gui_search_callbacks *gui;
void *gui_p;
struct content *c;
struct list_entry *found;
@ -76,8 +74,7 @@ struct search_context {
/* Exported function documented in search.h */
struct search_context * search_create_context(struct content *c,
content_type type, struct gui_search_callbacks *callbacks,
void *gui_data)
content_type type, void *gui_data)
{
struct search_context *context;
struct list_entry *search_head;
@ -114,7 +111,6 @@ struct search_context * search_create_context(struct content *c,
context->newsearch = true;
context->c = c;
context->is_html = (type == CONTENT_HTML) ? true : false;
context->gui = callbacks;
context->gui_p = gui_data;
return context;
@ -468,8 +464,7 @@ static void search_text(const char *string, int string_len,
context->string[string_len] = '\0';
}
if ((context->gui != NULL) && (context->gui->hourglass != NULL))
context->gui->hourglass(true, context->gui_p);
guit->search->hourglass(true, context->gui_p);
if (context->is_html == true) {
res = find_occurrences_html(string, string_len,
@ -481,14 +476,10 @@ static void search_text(const char *string, int string_len,
if (!res) {
free_matches(context);
if ((context->gui != NULL) &&
(context->gui->hourglass != NULL))
context->gui->hourglass(false, context->gui_p);
guit->search->hourglass(false, context->gui_p);
return;
}
if ((context->gui != NULL) &&
(context->gui->hourglass != NULL))
context->gui->hourglass(false, context->gui_p);
guit->search->hourglass(false, context->gui_p);
context->prev_case_sens = case_sensitive;
@ -507,20 +498,14 @@ static void search_text(const char *string, int string_len,
}
}
if (context->gui == NULL)
return;
if (context->gui->status != NULL)
context->gui->status((context->current != NULL),
context->gui_p);
guit->search->status((context->current != NULL), context->gui_p);
search_show_all(showall, context);
if (context->gui->back_state != NULL)
context->gui->back_state((context->current != NULL) &&
guit->search->back_state((context->current != NULL) &&
(context->current->prev != NULL),
context->gui_p);
if (context->gui->forward_state != NULL)
context->gui->forward_state((context->current != NULL) &&
guit->search->forward_state((context->current != NULL) &&
(context->current->next != NULL),
context->gui_p);
@ -557,13 +542,12 @@ void search_step(struct search_context *context, search_flags_t flags,
int string_len;
int i = 0;
if ((context == NULL) || (context->gui == NULL)) {
if (context == NULL) {
warn_user("SearchError", 0);
return;
}
if (context->gui->add_recent != NULL)
context->gui->add_recent(string, context->gui_p);
guit->search->add_recent(string, context->gui_p);
string_len = strlen(string);
for (i = 0; i < string_len; i++)
@ -572,12 +556,10 @@ void search_step(struct search_context *context, search_flags_t flags,
if (i >= string_len) {
union content_msg_data msg_data;
free_matches(context);
if (context->gui->status != NULL)
context->gui->status(true, context->gui_p);
if (context->gui->back_state != NULL)
context->gui->back_state(false, context->gui_p);
if (context->gui->forward_state != NULL)
context->gui->forward_state(false, context->gui_p);
guit->search->status(true, context->gui_p);
guit->search->back_state(false, context->gui_p);
guit->search->forward_state(false, context->gui_p);
msg_data.scroll.area = false;
msg_data.scroll.x0 = 0;
@ -653,11 +635,14 @@ void search_destroy_context(struct search_context *context)
{
assert(context != NULL);
if ((context->string != NULL) && (context->gui != NULL) &&
(context->gui->add_recent != NULL)) {
context->gui->add_recent(context->string, context->gui_p);
if (context->string != NULL) {
guit->search->add_recent(context->string, context->gui_p);
free(context->string);
}
guit->search->forward_state(true, context->gui_p);
guit->search->back_state(true, context->gui_p);
free_matches(context);
free(context);
}

View File

@ -36,8 +36,7 @@ struct search_context;
* \return true for success
*/
struct search_context * search_create_context(struct content *c,
content_type type, struct gui_search_callbacks *callbacks,
void *gui_data);
content_type type, void *context);
/**
* Ends the search process, invalidating all state

View File

@ -112,8 +112,7 @@ static void textplain_mouse_track(struct content *c, struct browser_window *bw,
static void textplain_mouse_action(struct content *c, struct browser_window *bw,
browser_mouse_state mouse, int x, int y);
static bool textplain_keypress(struct content *c, uint32_t key);
static void textplain_search(struct content *c,
struct gui_search_callbacks *gui_callbacks, void *gui_data,
static void textplain_search(struct content *c, void *gui_data,
search_flags_t flags, const char *string);
static void textplain_search_clear(struct content *c);
static void textplain_reformat(struct content *c, int width, int height);
@ -760,8 +759,7 @@ bool textplain_keypress(struct content *c, uint32_t key)
* \param flags search flags
* \param string search string
*/
void textplain_search(struct content *c,
struct gui_search_callbacks *gui_callbacks, void *gui_data,
void textplain_search(struct content *c, void *gui_data,
search_flags_t flags, const char *string)
{
textplain_content *text = (textplain_content *) c;
@ -787,7 +785,7 @@ void textplain_search(struct content *c,
}
text->search = search_create_context(c, CONTENT_TEXTPLAIN,
gui_callbacks, gui_data);
gui_data);
if (text->search == NULL)
return;

View File

@ -2387,6 +2387,7 @@ int main(int argc, char** argv)
.download = riscos_download_table,
.fetch = &riscos_fetch_table,
.utf8 = riscos_utf8_table,
.search = riscos_search_table,
};
/* Consult NetSurf$Logging environment variable to decide if logging

View File

@ -203,6 +203,7 @@ nserror riscos_schedule(int t, void (*callback)(void *p), void *p);
/* in search.c */
void ro_gui_search_init(void);
void ro_gui_search_prepare(struct browser_window *g);
struct gui_search_table *riscos_search_table;
/* in print.c */
void ro_gui_print_init(void);

View File

@ -76,14 +76,16 @@ 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 gui_search_callbacks ro_gui_search_callbacks = {
ro_gui_search_set_forward_state,
ro_gui_search_set_back_state,
static struct gui_search_table search_table = {
ro_gui_search_set_status,
ro_gui_search_set_hourglass,
ro_gui_search_add_recent
ro_gui_search_add_recent,
ro_gui_search_set_forward_state,
ro_gui_search_set_back_state,
};
struct gui_search_table *riscos_search_table = &search_table;
void ro_gui_search_init(void)
{
dialog_search = ro_gui_dialog_create("search");
@ -122,8 +124,7 @@ bool ro_gui_search_next(wimp_w w)
search_data.search_insert = true;
search_flags_t flags = SEARCH_FLAG_FORWARDS |
ro_gui_search_update_flags();
browser_window_search(search_data.search_window,
&ro_gui_search_callbacks, NULL, flags,
browser_window_search(search_data.search_window, NULL, flags,
ro_gui_get_icon_string(dialog_search,
ICON_SEARCH_TEXT));
return false;
@ -163,8 +164,7 @@ bool ro_gui_search_click(wimp_pointer *pointer)
search_data.search_insert = true;
flags = ~SEARCH_FLAG_FORWARDS &
ro_gui_search_update_flags();
browser_window_search(search_data.search_window,
&ro_gui_search_callbacks, NULL,
browser_window_search(search_data.search_window, NULL,
flags,
ro_gui_get_icon_string(dialog_search,
ICON_SEARCH_TEXT));
@ -172,8 +172,7 @@ bool ro_gui_search_click(wimp_pointer *pointer)
case ICON_SEARCH_CASE_SENSITIVE:
flags = SEARCH_FLAG_FORWARDS |
ro_gui_search_update_flags();
browser_window_search(search_data.search_window,
&ro_gui_search_callbacks, NULL,
browser_window_search(search_data.search_window, NULL,
flags,
ro_gui_get_icon_string(dialog_search,
ICON_SEARCH_TEXT));
@ -182,8 +181,7 @@ bool ro_gui_search_click(wimp_pointer *pointer)
flags = ro_gui_get_icon_selected_state(
pointer->w, pointer->i) ?
SEARCH_FLAG_SHOWALL : SEARCH_FLAG_NONE;
browser_window_search(search_data.search_window,
&ro_gui_search_callbacks, NULL,
browser_window_search(search_data.search_window, NULL,
flags,
ro_gui_get_icon_string(dialog_search,
ICON_SEARCH_TEXT));
@ -313,8 +311,7 @@ bool ro_gui_search_keypress(wimp_key *key)
case 1: {
flags = ro_gui_search_update_flags()
^ SEARCH_FLAG_SHOWALL;
browser_window_search(search_data.search_window,
&ro_gui_search_callbacks, NULL,
browser_window_search(search_data.search_window, NULL,
flags,
ro_gui_get_icon_string(dialog_search,
ICON_SEARCH_TEXT));
@ -327,8 +324,7 @@ bool ro_gui_search_keypress(wimp_key *key)
ICON_SEARCH_CASE_SENSITIVE, !state);
flags = SEARCH_FLAG_FORWARDS |
ro_gui_search_update_flags();
browser_window_search(search_data.search_window,
&ro_gui_search_callbacks, NULL,
browser_window_search(search_data.search_window, NULL,
flags,
ro_gui_get_icon_string(dialog_search,
ICON_SEARCH_TEXT));
@ -337,8 +333,7 @@ bool ro_gui_search_keypress(wimp_key *key)
search_data.search_insert = true;
flags = ~SEARCH_FLAG_FORWARDS &
ro_gui_search_update_flags();
browser_window_search(search_data.search_window,
&ro_gui_search_callbacks, NULL,
browser_window_search(search_data.search_window, NULL,
flags,
ro_gui_get_icon_string(dialog_search,
ICON_SEARCH_TEXT));
@ -347,8 +342,7 @@ bool ro_gui_search_keypress(wimp_key *key)
search_data.search_insert = true;
flags = SEARCH_FLAG_FORWARDS |
ro_gui_search_update_flags();
browser_window_search(search_data.search_window,
&ro_gui_search_callbacks, NULL,
browser_window_search(search_data.search_window, NULL,
flags,
ro_gui_get_icon_string(dialog_search,
ICON_SEARCH_TEXT));
@ -360,10 +354,6 @@ bool ro_gui_search_keypress(wimp_key *key)
* a new search */
browser_window_search_clear(
search_data.search_window);
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 */
@ -376,7 +366,7 @@ bool ro_gui_search_keypress(wimp_key *key)
ro_gui_search_set_back_state(true,
search_data.search_window);
browser_window_search(search_data.search_window,
&ro_gui_search_callbacks, NULL,
NULL,
flags,
ro_gui_get_icon_string(
dialog_search,
@ -396,8 +386,6 @@ bool ro_gui_search_keypress(wimp_key *key)
void ro_gui_search_end(wimp_w w)
{
browser_window_search_clear(search_data.search_window);
ro_gui_search_set_forward_state(true, search_data.search_window);
ro_gui_search_set_back_state(true, search_data.search_window);
}
/**