mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-23 04:26:50 +03:00
Clean up search gui callbacks.
This commit is contained in:
parent
119b5cca3f
commit
b51816c222
@ -84,7 +84,7 @@ 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 = {
|
||||
static struct gui_search_callbacks ami_search_callbacks = {
|
||||
ami_search_set_forward_state,
|
||||
ami_search_set_back_state,
|
||||
ami_search_set_status,
|
||||
|
@ -30,7 +30,7 @@ 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 search_callbacks nsatari_search_callbacks = {
|
||||
static struct gui_search_callbacks nsatari_search_callbacks = {
|
||||
nsatari_search_set_forward_state,
|
||||
nsatari_search_set_back_state,
|
||||
nsatari_search_set_status,
|
||||
@ -238,34 +238,34 @@ void search_destroy( struct gui_window * gw )
|
||||
SEARCH_FORM_SESSION open_browser_search( struct gui_window * gw )
|
||||
{
|
||||
char * title;
|
||||
SEARCH_FORM_SESSION sfs;
|
||||
SEARCH_FORM_SESSION sfs;
|
||||
GRECT pos, treesize;
|
||||
OBJECT * tree = get_tree(SEARCH);
|
||||
if( tree == NULL ){
|
||||
return( NULL );
|
||||
}
|
||||
}
|
||||
|
||||
sfs = calloc(1, sizeof(struct s_search_form_session));
|
||||
if( sfs == NULL )
|
||||
return( NULL );
|
||||
|
||||
|
||||
title = (char*)messages_get("FindTextNS");
|
||||
if( title == NULL )
|
||||
title = (char*)"Find text ...";
|
||||
|
||||
search_destroy( gw );
|
||||
|
||||
/* setup dipslay position: right corner */
|
||||
treesize.g_x = 0;
|
||||
treesize.g_y = 0;
|
||||
treesize.g_w = tree->ob_width;
|
||||
treesize.g_h = tree->ob_height;
|
||||
wind_calc_grect(WC_BORDER, WAT_FORM, &treesize, &pos);
|
||||
pos.g_x = app.w - pos.g_w;
|
||||
pos.g_y = app.h - pos.g_h;
|
||||
|
||||
search_destroy( gw );
|
||||
|
||||
current = sfs;
|
||||
/* setup dipslay position: right corner */
|
||||
treesize.g_x = 0;
|
||||
treesize.g_y = 0;
|
||||
treesize.g_w = tree->ob_width;
|
||||
treesize.g_h = tree->ob_height;
|
||||
wind_calc_grect(WC_BORDER, WAT_FORM, &treesize, &pos);
|
||||
pos.g_x = app.w - pos.g_w;
|
||||
pos.g_y = app.h - pos.g_h;
|
||||
|
||||
|
||||
current = sfs;
|
||||
sfs->bw = gw->browser->bw;
|
||||
sfs->formwind = mt_FormCreate( &app, tree, WAT_FORM,
|
||||
NULL, title,
|
||||
|
@ -26,7 +26,7 @@
|
||||
static void cocoa_search_set_back( bool active, void *p );
|
||||
static void cocoa_search_set_forward( bool active, void *p );
|
||||
|
||||
static struct search_callbacks cocoa_search_callbacks = {
|
||||
static struct gui_search_callbacks cocoa_search_callbacks = {
|
||||
.forward_state = cocoa_search_set_forward,
|
||||
.back_state = cocoa_search_set_back,
|
||||
.status = NULL,
|
||||
|
@ -46,9 +46,11 @@
|
||||
|
||||
|
||||
bool browser_window_search_create_context(struct browser_window *bw,
|
||||
struct search_callbacks *callbacks, void *p)
|
||||
struct gui_search_callbacks *gui_callbacks, void *gui_p)
|
||||
{
|
||||
struct search_callbacks callbacks;
|
||||
assert(bw != NULL);
|
||||
assert(gui_callbacks != NULL);
|
||||
|
||||
if (bw->cur_search != NULL)
|
||||
search_destroy_context(bw->cur_search);
|
||||
@ -57,8 +59,9 @@ bool browser_window_search_create_context(struct browser_window *bw,
|
||||
if (!bw->current_content)
|
||||
return false;
|
||||
|
||||
bw->cur_search = search_create_context(bw->current_content,
|
||||
callbacks, p);
|
||||
callbacks.gui = gui_callbacks;
|
||||
callbacks.gui_p = gui_p;
|
||||
bw->cur_search = search_create_context(bw->current_content, callbacks);
|
||||
|
||||
if (bw->cur_search == NULL)
|
||||
return false;
|
||||
@ -82,16 +85,17 @@ void browser_window_search_destroy_context(struct browser_window *bw)
|
||||
* non-NULL, creates a new search_context in case of a new search
|
||||
* \param bw the browser_window the search refers to
|
||||
* \param callbacks the callbacks to modify appearance according to results
|
||||
* \param p a pointer returned to the callbacks
|
||||
* \param gui_p a pointer returned to the callbacks
|
||||
* \return true for success
|
||||
*/
|
||||
bool browser_window_search_verify_new(struct browser_window *bw,
|
||||
struct search_callbacks *callbacks, void *p)
|
||||
struct gui_search_callbacks *gui_callbacks, void *gui_p)
|
||||
{
|
||||
if (bw == NULL)
|
||||
return false;
|
||||
if (bw->cur_search == NULL)
|
||||
return browser_window_search_create_context(bw, callbacks, p);
|
||||
return browser_window_search_create_context(bw,
|
||||
gui_callbacks, gui_p);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -22,8 +22,6 @@
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
struct search_context;
|
||||
|
||||
typedef enum {
|
||||
SEARCH_FLAG_CASE_SENSITIVE = (1 << 0),
|
||||
SEARCH_FLAG_FORWARDS = (1 << 1),
|
||||
@ -33,54 +31,54 @@ typedef enum {
|
||||
/**
|
||||
* Change the displayed search status.
|
||||
* \param found search pattern matched in text
|
||||
* \param p the pointer sent to search_step() / search_create_context()
|
||||
* \param p gui private data pointer provided with search callbacks
|
||||
*/
|
||||
typedef void (*search_status_callback)(bool found, void *p);
|
||||
typedef void (*gui_search_status)(bool found, void *p);
|
||||
|
||||
/**
|
||||
* display hourglass while searching
|
||||
* \param active start/stop indicator
|
||||
* \param p the pointer sent to search_step() / search_create_context()
|
||||
* \param p gui private data pointer provided with search callbacks
|
||||
*/
|
||||
typedef void (*search_hourglass_callback)(bool active, void *p);
|
||||
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 the pointer sent to search_step() / search_create_context()
|
||||
* \param p gui private data pointer provided with search callbacks
|
||||
*/
|
||||
typedef void (*search_add_recent_callback)(const char *string, void *p);
|
||||
typedef void (*gui_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_step() / search_create_context()
|
||||
* \param p gui private data pointer provided with search callbacks
|
||||
*/
|
||||
typedef void (*search_forward_state_callback)(bool active, void *p);
|
||||
typedef void (*gui_search_forward_state)(bool active, void *p);
|
||||
|
||||
/**
|
||||
* activate search back button in gui
|
||||
* \param active activate/inactivate
|
||||
* \param p the pointer sent to search_step() / search_create_context()
|
||||
* \param p gui private data pointer provided with search callbacks
|
||||
*/
|
||||
typedef void (*search_back_state_callback)(bool active, void *p);
|
||||
typedef void (*gui_search_back_state)(bool active, void *p);
|
||||
|
||||
struct search_callbacks {
|
||||
search_forward_state_callback forward_state;
|
||||
search_back_state_callback back_state;
|
||||
search_status_callback status;
|
||||
search_hourglass_callback hourglass;
|
||||
search_add_recent_callback add_recent;
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
bool browser_window_search_create_context(struct browser_window *bw,
|
||||
struct search_callbacks *callbacks, void *p);
|
||||
struct gui_search_callbacks *gui_callbacks, void *gui_p);
|
||||
void browser_window_search_destroy_context(struct browser_window *bw);
|
||||
bool browser_window_search_verify_new(struct browser_window *bw,
|
||||
struct search_callbacks *callbacks, void *p);
|
||||
struct gui_search_callbacks *gui_callbacks, void *gui_p);
|
||||
void browser_window_search_step(struct browser_window *bw,
|
||||
search_flags_t flags, const char *string);
|
||||
void browser_window_search_show_all(bool all, struct browser_window *bw);
|
||||
|
@ -47,7 +47,7 @@ static void nsgtk_search_set_status(bool found, void *p);
|
||||
static void nsgtk_search_set_hourglass(bool active, void *p);
|
||||
static void nsgtk_search_add_recent(const char *string, void *p);
|
||||
|
||||
static struct search_callbacks nsgtk_search_callbacks = {
|
||||
static struct gui_search_callbacks nsgtk_search_callbacks = {
|
||||
nsgtk_search_set_forward_state,
|
||||
nsgtk_search_set_back_state,
|
||||
nsgtk_search_set_status,
|
||||
|
@ -48,6 +48,7 @@ struct object_params;
|
||||
struct plotters;
|
||||
struct scrollbar;
|
||||
struct scrollbar_msg_data;
|
||||
struct search_context;
|
||||
|
||||
/**
|
||||
* Container for stylesheets used by an HTML document
|
||||
|
@ -64,15 +64,14 @@ struct list_entry {
|
||||
};
|
||||
|
||||
struct search_context {
|
||||
struct search_callbacks callbacks;
|
||||
struct content *c;
|
||||
struct list_entry *found;
|
||||
struct list_entry *current; /* first for select all */
|
||||
char *string;
|
||||
bool prev_case_sens;
|
||||
bool newsearch;
|
||||
bool is_html;
|
||||
void *p; /* front-specific data */
|
||||
struct search_callbacks *callbacks;
|
||||
struct list_entry *found;
|
||||
struct list_entry *current; /* first for select all */
|
||||
};
|
||||
|
||||
|
||||
@ -104,7 +103,7 @@ static struct browser_window *search_get_browser_window(
|
||||
* \return true for success
|
||||
*/
|
||||
struct search_context * search_create_context(hlcache_handle *h,
|
||||
struct search_callbacks *callbacks, void *p)
|
||||
struct search_callbacks callbacks)
|
||||
{
|
||||
struct search_context *context;
|
||||
struct list_entry *search_head;
|
||||
@ -147,7 +146,6 @@ struct search_context * search_create_context(hlcache_handle *h,
|
||||
context->c = c;
|
||||
context->is_html = (content_get_type(h) == CONTENT_HTML) ? true : false;
|
||||
context->callbacks = callbacks;
|
||||
context->p = p;
|
||||
|
||||
if (context->is_html) {
|
||||
html_set_search(context->c, context);
|
||||
@ -503,9 +501,10 @@ static void search_text(const char *string, int string_len,
|
||||
context->string[string_len] = '\0';
|
||||
}
|
||||
|
||||
if ((context->callbacks != NULL) &&
|
||||
(context->callbacks->hourglass != NULL))
|
||||
context->callbacks->hourglass(true, context->p);
|
||||
if ((context->callbacks.gui != NULL) &&
|
||||
(context->callbacks.gui->hourglass != NULL))
|
||||
context->callbacks.gui->hourglass(true,
|
||||
context->callbacks.gui_p);
|
||||
|
||||
if (context->is_html == true) {
|
||||
res = find_occurrences_html(string, string_len,
|
||||
@ -517,16 +516,17 @@ static void search_text(const char *string, int string_len,
|
||||
|
||||
if (!res) {
|
||||
free_matches(context);
|
||||
if ((context->callbacks != NULL) &&
|
||||
(context->callbacks->hourglass !=
|
||||
if ((context->callbacks.gui != NULL) &&
|
||||
(context->callbacks.gui->hourglass !=
|
||||
NULL))
|
||||
context->callbacks->hourglass(false,
|
||||
context->p);
|
||||
context->callbacks.gui->hourglass(false,
|
||||
context->callbacks.gui_p);
|
||||
return;
|
||||
}
|
||||
if ((context->callbacks != NULL) &&
|
||||
(context->callbacks->hourglass != NULL))
|
||||
context->callbacks->hourglass(false, context->p);
|
||||
if ((context->callbacks.gui != NULL) &&
|
||||
(context->callbacks.gui->hourglass != NULL))
|
||||
context->callbacks.gui->hourglass(false,
|
||||
context->callbacks.gui_p);
|
||||
|
||||
context->prev_case_sens = case_sensitive;
|
||||
/* LOG(("%d %p %p (%p, %p)", new, search_data.found->next, search_data.current,
|
||||
@ -547,20 +547,22 @@ static void search_text(const char *string, int string_len,
|
||||
}
|
||||
}
|
||||
|
||||
if (context->callbacks == NULL)
|
||||
if (context->callbacks.gui == NULL)
|
||||
return;
|
||||
if (context->callbacks->status != NULL)
|
||||
context->callbacks->status((context->current != NULL),
|
||||
context->p);
|
||||
if (context->callbacks.gui->status != NULL)
|
||||
context->callbacks.gui->status((context->current != NULL),
|
||||
context->callbacks.gui_p);
|
||||
search_show_all(showall, context);
|
||||
|
||||
if (context->callbacks->back_state != NULL)
|
||||
context->callbacks->back_state((context->current != NULL) &&
|
||||
if (context->callbacks.gui->back_state != NULL)
|
||||
context->callbacks.gui->back_state((context->current != NULL) &&
|
||||
(context->current->prev != NULL),
|
||||
context->p);
|
||||
if (context->callbacks->forward_state != NULL)
|
||||
context->callbacks->forward_state((context->current != NULL) &&
|
||||
(context->current->next != NULL), context->p);
|
||||
context->callbacks.gui_p);
|
||||
if (context->callbacks.gui->forward_state != NULL)
|
||||
context->callbacks.gui->forward_state(
|
||||
(context->current != NULL) &&
|
||||
(context->current->next != NULL),
|
||||
context->callbacks.gui_p);
|
||||
|
||||
if (context->current == NULL)
|
||||
return;
|
||||
@ -603,13 +605,14 @@ void search_step(struct search_context *context, search_flags_t flags,
|
||||
int string_len;
|
||||
int i = 0;
|
||||
|
||||
if ((context == NULL) || (context->callbacks == NULL)) {
|
||||
if ((context == NULL) || (context->callbacks.gui == NULL)) {
|
||||
warn_user("SearchError", 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (context->callbacks->add_recent != NULL)
|
||||
context->callbacks->add_recent(string, context->p);
|
||||
if (context->callbacks.gui->add_recent != NULL)
|
||||
context->callbacks.gui->add_recent(string,
|
||||
context->callbacks.gui_p);
|
||||
|
||||
string_len = strlen(string);
|
||||
for(i = 0; i < string_len; i++)
|
||||
@ -617,12 +620,15 @@ 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->callbacks->status != NULL)
|
||||
context->callbacks->status(true, context->p);
|
||||
if (context->callbacks->back_state != NULL)
|
||||
context->callbacks->back_state(false, context->p);
|
||||
if (context->callbacks->forward_state != NULL)
|
||||
context->callbacks->forward_state(false, context->p);
|
||||
if (context->callbacks.gui->status != NULL)
|
||||
context->callbacks.gui->status(true,
|
||||
context->callbacks.gui_p);
|
||||
if (context->callbacks.gui->back_state != NULL)
|
||||
context->callbacks.gui->back_state(false,
|
||||
context->callbacks.gui_p);
|
||||
if (context->callbacks.gui->forward_state != NULL)
|
||||
context->callbacks.gui->forward_state(false,
|
||||
context->callbacks.gui_p);
|
||||
|
||||
msg_data.scroll.area = false;
|
||||
msg_data.scroll.x0 = 0;
|
||||
@ -729,9 +735,10 @@ void search_destroy_context(struct search_context *context)
|
||||
else
|
||||
textplain_set_search(context->c, NULL);
|
||||
}
|
||||
if ((context->string != NULL) && (context->callbacks != NULL) &&
|
||||
(context->callbacks->add_recent != NULL)) {
|
||||
context->callbacks->add_recent(context->string, context->p);
|
||||
if ((context->string != NULL) && (context->callbacks.gui != NULL) &&
|
||||
(context->callbacks.gui->add_recent != NULL)) {
|
||||
context->callbacks.gui->add_recent(context->string,
|
||||
context->callbacks.gui_p);
|
||||
free(context->string);
|
||||
}
|
||||
free_matches(context);
|
||||
|
@ -24,13 +24,22 @@
|
||||
|
||||
#include "desktop/search.h"
|
||||
|
||||
/**
|
||||
* Called when a search context is destroyed
|
||||
* \param p pointer for client data
|
||||
*/
|
||||
typedef void (*search_destroy_callback)(void *p);
|
||||
|
||||
struct search_callbacks {
|
||||
struct gui_search_callbacks *gui;
|
||||
void *gui_p; /* private gui owned data */
|
||||
};
|
||||
|
||||
struct search_context;
|
||||
|
||||
|
||||
|
||||
|
||||
struct search_context * search_create_context(struct hlcache_handle *h,
|
||||
struct search_callbacks *callbacks, void *p);
|
||||
struct search_callbacks callbacks);
|
||||
void search_destroy_context(struct search_context *context);
|
||||
void search_step(struct search_context *context, search_flags_t flags,
|
||||
const char * string);
|
||||
|
@ -78,7 +78,7 @@ 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 = {
|
||||
static struct gui_search_callbacks ro_gui_search_callbacks = {
|
||||
ro_gui_search_set_forward_state,
|
||||
ro_gui_search_set_back_state,
|
||||
ro_gui_search_set_status,
|
||||
|
Loading…
Reference in New Issue
Block a user