From 4d4d74c8cd1a77a46cbe0816cf6150f8b4980947 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Tue, 18 Mar 2014 22:32:52 +0000 Subject: move page search gui callbacks to their own operations table --- render/html_interaction.c | 12 ++++----- render/html_internal.h | 3 +-- render/search.c | 67 ++++++++++++++++++----------------------------- render/search.h | 3 +-- render/textplain.c | 8 +++--- 5 files changed, 36 insertions(+), 57 deletions(-) (limited to 'render') diff --git a/render/html_interaction.c b/render/html_interaction.c index a2baf2d39..ce2f78c96 100644 --- a/render/html_interaction.c +++ b/render/html_interaction.c @@ -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; } diff --git a/render/html_internal.h b/render/html_internal.h index e7768e39f..05a085e22 100644 --- a/render/html_internal.h +++ b/render/html_internal.h @@ -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); diff --git a/render/search.c b/render/search.c index 46ec7d1fc..3bec9e199 100644 --- a/render/search.c +++ b/render/search.c @@ -21,27 +21,26 @@ /** \file * Free text search (core) */ -#include "utils/config.h" #include #include - #include +#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" -#include "utils/config.h" -#include "utils/log.h" -#include "utils/messages.h" -#include "utils/url.h" -#include "utils/utils.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); } diff --git a/render/search.h b/render/search.h index 43c93b3ab..a8354e77e 100644 --- a/render/search.h +++ b/render/search.h @@ -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 diff --git a/render/textplain.c b/render/textplain.c index b459efc6c..e08a04575 100644 --- a/render/textplain.c +++ b/render/textplain.c @@ -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; -- cgit v1.2.3