Clean up search gui callbacks.

This commit is contained in:
Michael Drake 2012-08-14 13:41:30 +01:00
parent 119b5cca3f
commit b51816c222
10 changed files with 106 additions and 87 deletions

View File

@ -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_forward_state(bool active, void *p);
static void ami_search_set_back_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_forward_state,
ami_search_set_back_state, ami_search_set_back_state,
ami_search_set_status, ami_search_set_status,

View File

@ -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_forward_state(bool active, void *p);
void nsatari_search_set_back_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_forward_state,
nsatari_search_set_back_state, nsatari_search_set_back_state,
nsatari_search_set_status, nsatari_search_set_status,

View File

@ -26,7 +26,7 @@
static void cocoa_search_set_back( bool active, void *p ); static void cocoa_search_set_back( bool active, void *p );
static void cocoa_search_set_forward( 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, .forward_state = cocoa_search_set_forward,
.back_state = cocoa_search_set_back, .back_state = cocoa_search_set_back,
.status = NULL, .status = NULL,

View File

@ -46,9 +46,11 @@
bool browser_window_search_create_context(struct browser_window *bw, 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(bw != NULL);
assert(gui_callbacks != NULL);
if (bw->cur_search != NULL) if (bw->cur_search != NULL)
search_destroy_context(bw->cur_search); search_destroy_context(bw->cur_search);
@ -57,8 +59,9 @@ bool browser_window_search_create_context(struct browser_window *bw,
if (!bw->current_content) if (!bw->current_content)
return false; return false;
bw->cur_search = search_create_context(bw->current_content, callbacks.gui = gui_callbacks;
callbacks, p); callbacks.gui_p = gui_p;
bw->cur_search = search_create_context(bw->current_content, callbacks);
if (bw->cur_search == NULL) if (bw->cur_search == NULL)
return false; 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 * non-NULL, creates a new search_context in case of a new search
* \param bw the browser_window the search refers to * \param bw the browser_window the search refers to
* \param callbacks the callbacks to modify appearance according to results * \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 * \return true for success
*/ */
bool browser_window_search_verify_new(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)
{ {
if (bw == NULL) if (bw == NULL)
return false; return false;
if (bw->cur_search == NULL) 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; return true;
} }

View File

@ -22,8 +22,6 @@
#include <ctype.h> #include <ctype.h>
#include <string.h> #include <string.h>
struct search_context;
typedef enum { typedef enum {
SEARCH_FLAG_CASE_SENSITIVE = (1 << 0), SEARCH_FLAG_CASE_SENSITIVE = (1 << 0),
SEARCH_FLAG_FORWARDS = (1 << 1), SEARCH_FLAG_FORWARDS = (1 << 1),
@ -33,54 +31,54 @@ typedef enum {
/** /**
* Change the displayed search status. * Change the displayed search status.
* \param found search pattern matched in text * \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 * display hourglass while searching
* \param active start/stop indicator * \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 * add search string to recent searches list
* front has full liberty how to implement the bare notification; * front has full liberty how to implement the bare notification;
* core gives no guarantee of the integrity of the const char * * core gives no guarantee of the integrity of the const char *
* \param string search pattern * \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 * activate search forwards button in gui
* \param active activate/inactivate * \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 * activate search back button in gui
* \param active activate/inactivate * \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 { struct gui_search_callbacks {
search_forward_state_callback forward_state; gui_search_forward_state forward_state;
search_back_state_callback back_state; gui_search_back_state back_state;
search_status_callback status; gui_search_status status;
search_hourglass_callback hourglass; gui_search_hourglass hourglass;
search_add_recent_callback add_recent; gui_search_add_recent add_recent;
}; };
bool browser_window_search_create_context(struct browser_window *bw, 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); void browser_window_search_destroy_context(struct browser_window *bw);
bool browser_window_search_verify_new(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, void browser_window_search_step(struct browser_window *bw,
search_flags_t flags, const char *string); search_flags_t flags, const char *string);
void browser_window_search_show_all(bool all, struct browser_window *bw); void browser_window_search_show_all(bool all, struct browser_window *bw);

View File

@ -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_set_hourglass(bool active, void *p);
static void nsgtk_search_add_recent(const char *string, 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_forward_state,
nsgtk_search_set_back_state, nsgtk_search_set_back_state,
nsgtk_search_set_status, nsgtk_search_set_status,

View File

@ -48,6 +48,7 @@ struct object_params;
struct plotters; struct plotters;
struct scrollbar; struct scrollbar;
struct scrollbar_msg_data; struct scrollbar_msg_data;
struct search_context;
/** /**
* Container for stylesheets used by an HTML document * Container for stylesheets used by an HTML document

View File

@ -64,15 +64,14 @@ struct list_entry {
}; };
struct search_context { struct search_context {
struct search_callbacks callbacks;
struct content *c; struct content *c;
struct list_entry *found;
struct list_entry *current; /* first for select all */
char *string; char *string;
bool prev_case_sens; bool prev_case_sens;
bool newsearch; bool newsearch;
bool is_html; 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 * \return true for success
*/ */
struct search_context * search_create_context(hlcache_handle *h, struct search_context * search_create_context(hlcache_handle *h,
struct search_callbacks *callbacks, void *p) struct search_callbacks callbacks)
{ {
struct search_context *context; struct search_context *context;
struct list_entry *search_head; struct list_entry *search_head;
@ -147,7 +146,6 @@ struct search_context * search_create_context(hlcache_handle *h,
context->c = c; context->c = c;
context->is_html = (content_get_type(h) == CONTENT_HTML) ? true : false; context->is_html = (content_get_type(h) == CONTENT_HTML) ? true : false;
context->callbacks = callbacks; context->callbacks = callbacks;
context->p = p;
if (context->is_html) { if (context->is_html) {
html_set_search(context->c, context); 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'; context->string[string_len] = '\0';
} }
if ((context->callbacks != NULL) && if ((context->callbacks.gui != NULL) &&
(context->callbacks->hourglass != NULL)) (context->callbacks.gui->hourglass != NULL))
context->callbacks->hourglass(true, context->p); context->callbacks.gui->hourglass(true,
context->callbacks.gui_p);
if (context->is_html == true) { if (context->is_html == true) {
res = find_occurrences_html(string, string_len, res = find_occurrences_html(string, string_len,
@ -517,16 +516,17 @@ static void search_text(const char *string, int string_len,
if (!res) { if (!res) {
free_matches(context); free_matches(context);
if ((context->callbacks != NULL) && if ((context->callbacks.gui != NULL) &&
(context->callbacks->hourglass != (context->callbacks.gui->hourglass !=
NULL)) NULL))
context->callbacks->hourglass(false, context->callbacks.gui->hourglass(false,
context->p); context->callbacks.gui_p);
return; return;
} }
if ((context->callbacks != NULL) && if ((context->callbacks.gui != NULL) &&
(context->callbacks->hourglass != NULL)) (context->callbacks.gui->hourglass != NULL))
context->callbacks->hourglass(false, context->p); context->callbacks.gui->hourglass(false,
context->callbacks.gui_p);
context->prev_case_sens = case_sensitive; context->prev_case_sens = case_sensitive;
/* LOG(("%d %p %p (%p, %p)", new, search_data.found->next, search_data.current, /* 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; return;
if (context->callbacks->status != NULL) if (context->callbacks.gui->status != NULL)
context->callbacks->status((context->current != NULL), context->callbacks.gui->status((context->current != NULL),
context->p); context->callbacks.gui_p);
search_show_all(showall, context); search_show_all(showall, context);
if (context->callbacks->back_state != NULL) if (context->callbacks.gui->back_state != NULL)
context->callbacks->back_state((context->current != NULL) && context->callbacks.gui->back_state((context->current != NULL) &&
(context->current->prev != NULL), (context->current->prev != NULL),
context->p); context->callbacks.gui_p);
if (context->callbacks->forward_state != NULL) if (context->callbacks.gui->forward_state != NULL)
context->callbacks->forward_state((context->current != NULL) && context->callbacks.gui->forward_state(
(context->current->next != NULL), context->p); (context->current != NULL) &&
(context->current->next != NULL),
context->callbacks.gui_p);
if (context->current == NULL) if (context->current == NULL)
return; return;
@ -603,13 +605,14 @@ void search_step(struct search_context *context, search_flags_t flags,
int string_len; int string_len;
int i = 0; int i = 0;
if ((context == NULL) || (context->callbacks == NULL)) { if ((context == NULL) || (context->callbacks.gui == NULL)) {
warn_user("SearchError", 0); warn_user("SearchError", 0);
return; return;
} }
if (context->callbacks->add_recent != NULL) if (context->callbacks.gui->add_recent != NULL)
context->callbacks->add_recent(string, context->p); context->callbacks.gui->add_recent(string,
context->callbacks.gui_p);
string_len = strlen(string); string_len = strlen(string);
for(i = 0; i < string_len; i++) 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) { if (i >= string_len) {
union content_msg_data msg_data; union content_msg_data msg_data;
free_matches(context); free_matches(context);
if (context->callbacks->status != NULL) if (context->callbacks.gui->status != NULL)
context->callbacks->status(true, context->p); context->callbacks.gui->status(true,
if (context->callbacks->back_state != NULL) context->callbacks.gui_p);
context->callbacks->back_state(false, context->p); if (context->callbacks.gui->back_state != NULL)
if (context->callbacks->forward_state != NULL) context->callbacks.gui->back_state(false,
context->callbacks->forward_state(false, context->p); 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.area = false;
msg_data.scroll.x0 = 0; msg_data.scroll.x0 = 0;
@ -729,9 +735,10 @@ void search_destroy_context(struct search_context *context)
else else
textplain_set_search(context->c, NULL); textplain_set_search(context->c, NULL);
} }
if ((context->string != NULL) && (context->callbacks != NULL) && if ((context->string != NULL) && (context->callbacks.gui != NULL) &&
(context->callbacks->add_recent != NULL)) { (context->callbacks.gui->add_recent != NULL)) {
context->callbacks->add_recent(context->string, context->p); context->callbacks.gui->add_recent(context->string,
context->callbacks.gui_p);
free(context->string); free(context->string);
} }
free_matches(context); free_matches(context);

View File

@ -24,13 +24,22 @@
#include "desktop/search.h" #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;
struct search_context * search_create_context(struct hlcache_handle *h, 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_destroy_context(struct search_context *context);
void search_step(struct search_context *context, search_flags_t flags, void search_step(struct search_context *context, search_flags_t flags,
const char * string); const char * string);

View File

@ -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_set_hourglass(bool active, void *p);
static void ro_gui_search_add_recent(const char *string, 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_forward_state,
ro_gui_search_set_back_state, ro_gui_search_set_back_state,
ro_gui_search_set_status, ro_gui_search_set_status,