2014-05-21 00:06:32 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Ole Loots <ole@monochrom.net>
|
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
2014-10-17 00:23:51 +04:00
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
2014-10-25 18:37:03 +04:00
|
|
|
#include "desktop/browser.h"
|
2014-05-21 00:06:32 +04:00
|
|
|
#include "desktop/search.h"
|
2014-10-17 00:23:51 +04:00
|
|
|
#include "desktop/gui_search.h"
|
|
|
|
|
2013-01-11 05:12:30 +04:00
|
|
|
#include "atari/gui.h"
|
2014-05-21 00:06:32 +04:00
|
|
|
#include "atari/rootwin.h"
|
|
|
|
#include "atari/misc.h"
|
2013-01-23 01:28:20 +04:00
|
|
|
#include "atari/toolbar.h"
|
2012-11-19 02:22:43 +04:00
|
|
|
#include "atari/search.h"
|
2014-05-21 00:06:32 +04:00
|
|
|
#include "atari/gemtk/gemtk.h"
|
|
|
|
#include "atari/res/netsurf.rsh"
|
|
|
|
|
|
|
|
extern struct gui_window * input_window;
|
|
|
|
|
|
|
|
|
|
|
|
static void nsatari_search_set_status(bool found, void *p);
|
|
|
|
static void nsatari_search_set_hourglass(bool active, void *p);
|
|
|
|
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);
|
|
|
|
|
2014-03-19 02:32:52 +04:00
|
|
|
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;
|
|
|
|
|
2014-05-21 00:06:32 +04:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2015-05-28 11:11:32 +03:00
|
|
|
* Change the displayed search status.
|
|
|
|
* \param found search pattern matched in text
|
|
|
|
* \param p the pointer sent to search_verify_new() / search_create_context()
|
|
|
|
*/
|
2014-05-21 00:06:32 +04:00
|
|
|
void nsatari_search_set_status(bool found, void *p)
|
|
|
|
{
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("%p set status: %d\n", p, found);
|
2014-05-21 00:06:32 +04:00
|
|
|
// TODO: maybe update GUI
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-28 11:11:32 +03:00
|
|
|
/**
|
|
|
|
* display hourglass while searching
|
|
|
|
* \param active start/stop indicator
|
|
|
|
* \param p the pointer sent to search_verify_new() / search_create_context()
|
|
|
|
*/
|
2014-05-21 00:06:32 +04:00
|
|
|
void nsatari_search_set_hourglass(bool active, void *p)
|
|
|
|
{
|
|
|
|
SEARCH_FORM_SESSION s = (SEARCH_FORM_SESSION)p;
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("active: %d, session: %p", active, p);
|
2015-05-28 11:11:32 +03:00
|
|
|
if (active) {
|
2014-10-25 18:34:22 +04:00
|
|
|
gui_window_set_pointer(s->g, GUI_POINTER_PROGRESS);
|
2015-05-28 11:11:32 +03:00
|
|
|
} else {
|
2014-10-25 18:34:22 +04:00
|
|
|
gui_window_set_pointer(s->g, GUI_POINTER_DEFAULT);
|
2015-05-28 11:11:32 +03:00
|
|
|
}
|
2014-05-21 00:06:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-28 11:11:32 +03:00
|
|
|
/**
|
|
|
|
* 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()
|
|
|
|
*/
|
2014-05-21 00:06:32 +04:00
|
|
|
void nsatari_search_add_recent(const char *string, void *p)
|
|
|
|
{
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("%p add recent: %s\n", p, string);
|
2014-05-21 00:06:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-28 11:11:32 +03:00
|
|
|
/**
|
|
|
|
* activate search forwards button in gui
|
|
|
|
* \param active activate/inactivate
|
|
|
|
* \param p the pointer sent to search_verify_new() / search_create_context()
|
|
|
|
*/
|
2014-05-21 00:06:32 +04:00
|
|
|
void nsatari_search_set_forward_state(bool active, void *p)
|
2013-01-23 01:28:20 +04:00
|
|
|
{
|
|
|
|
struct gui_window *gw;
|
|
|
|
OBJECT *toolbar;
|
2014-05-21 00:06:32 +04:00
|
|
|
GRECT area;
|
|
|
|
SEARCH_FORM_SESSION s = (SEARCH_FORM_SESSION)p;
|
|
|
|
/* deactivate back cb */
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("%p: set forward state: %d\n", p, active);
|
2014-05-21 00:06:32 +04:00
|
|
|
|
2014-10-25 18:34:22 +04:00
|
|
|
gw = s->g;
|
2013-01-23 01:28:20 +04:00
|
|
|
|
|
|
|
toolbar = toolbar_get_form(gw->root->toolbar);
|
2015-05-28 11:11:32 +03:00
|
|
|
if (active) {
|
2013-01-23 01:28:20 +04:00
|
|
|
toolbar[TOOLBAR_BT_SEARCH_FWD].ob_state &= ~OS_DISABLED;
|
2015-05-28 11:11:32 +03:00
|
|
|
} else {
|
2013-01-23 01:28:20 +04:00
|
|
|
toolbar[TOOLBAR_BT_SEARCH_FWD].ob_state |= OS_DISABLED;
|
2015-05-28 11:11:32 +03:00
|
|
|
}
|
2013-01-23 01:28:20 +04:00
|
|
|
window_get_grect(gw->root, BROWSER_AREA_SEARCH, &area);
|
|
|
|
window_schedule_redraw_grect(gw->root, &area);
|
2014-05-21 00:06:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-28 11:11:32 +03:00
|
|
|
/**
|
|
|
|
* activate search back button in gui
|
|
|
|
* \param active activate/inactivate
|
|
|
|
* \param p the pointer sent to search_verify_new() / search_create_context()
|
|
|
|
*/
|
2014-05-21 00:06:32 +04:00
|
|
|
void nsatari_search_set_back_state(bool active, void *p)
|
|
|
|
{
|
2013-01-23 01:28:20 +04:00
|
|
|
struct gui_window *gw;
|
|
|
|
OBJECT *toolbar;
|
|
|
|
GRECT area;
|
2014-05-21 00:06:32 +04:00
|
|
|
SEARCH_FORM_SESSION s = (SEARCH_FORM_SESSION)p;
|
|
|
|
/* deactivate back cb */
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("%p: set back state: %d\n", p, active);
|
2013-01-17 04:18:27 +04:00
|
|
|
|
2013-01-23 01:28:20 +04:00
|
|
|
s->state.back_avail = active;
|
2014-10-25 18:34:22 +04:00
|
|
|
gw = s->g;
|
2013-01-23 01:28:20 +04:00
|
|
|
|
|
|
|
toolbar = toolbar_get_form(gw->root->toolbar);
|
2015-05-28 11:11:32 +03:00
|
|
|
if (active) {
|
2013-01-23 01:28:20 +04:00
|
|
|
toolbar[TOOLBAR_BT_SEARCH_BACK].ob_state &= ~OS_DISABLED;
|
2015-05-28 11:11:32 +03:00
|
|
|
} else {
|
2013-01-23 01:28:20 +04:00
|
|
|
toolbar[TOOLBAR_BT_SEARCH_BACK].ob_state |= OS_DISABLED;
|
2015-05-28 11:11:32 +03:00
|
|
|
}
|
2013-01-23 01:28:20 +04:00
|
|
|
window_get_grect(gw->root, BROWSER_AREA_SEARCH, &area);
|
2014-05-21 00:06:32 +04:00
|
|
|
window_schedule_redraw_grect(gw->root, &area);
|
2013-01-11 05:12:30 +04:00
|
|
|
}
|
2013-01-16 06:21:35 +04:00
|
|
|
|
2014-05-21 00:06:32 +04:00
|
|
|
|
|
|
|
static int apply_form(OBJECT *obj, struct s_search_form_state *s)
|
|
|
|
{
|
2013-01-16 06:21:35 +04:00
|
|
|
char * cstr;
|
2013-01-07 23:04:44 +04:00
|
|
|
|
2013-01-16 06:21:35 +04:00
|
|
|
assert(s != NULL);
|
2014-05-21 00:06:32 +04:00
|
|
|
|
2013-01-16 06:21:35 +04:00
|
|
|
s->flags = 0;
|
2014-05-21 00:06:32 +04:00
|
|
|
|
2015-05-28 11:11:32 +03:00
|
|
|
if ((obj[TOOLBAR_CB_CASESENSE].ob_state & OS_SELECTED) != 0 ) {
|
2014-05-21 00:06:32 +04:00
|
|
|
s->flags |= SEARCH_FLAG_CASE_SENSITIVE;
|
2015-05-28 11:11:32 +03:00
|
|
|
}
|
|
|
|
if ((obj[TOOLBAR_CB_SHOWALL].ob_state & OS_SELECTED) != 0 ) {
|
2014-05-21 00:06:32 +04:00
|
|
|
s->flags |= SEARCH_FLAG_SHOWALL;
|
2015-05-28 11:11:32 +03:00
|
|
|
}
|
2013-01-07 23:04:44 +04:00
|
|
|
|
2013-01-22 05:33:27 +04:00
|
|
|
cstr = gemtk_obj_get_text(obj, TOOLBAR_TB_SRCH);
|
2013-01-17 04:18:27 +04:00
|
|
|
snprintf(s->text, 32, "%s", cstr);
|
2014-05-21 00:06:32 +04:00
|
|
|
return ( 0 );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void set_text(OBJECT *obj, short idx, char * text, int len)
|
|
|
|
{
|
|
|
|
char spare[255];
|
|
|
|
|
2015-05-28 11:11:32 +03:00
|
|
|
if (len > 254) {
|
2014-05-21 00:06:32 +04:00
|
|
|
len = 254;
|
2015-05-28 11:11:32 +03:00
|
|
|
}
|
|
|
|
if (text != NULL) {
|
2014-05-21 00:06:32 +04:00
|
|
|
strncpy(spare, text, 254);
|
|
|
|
} else {
|
|
|
|
strcpy(spare, "");
|
2013-01-07 23:04:44 +04:00
|
|
|
}
|
2014-05-21 00:06:32 +04:00
|
|
|
|
|
|
|
set_string(obj, idx, spare);
|
2013-01-07 23:04:44 +04:00
|
|
|
}
|
2013-01-17 04:18:27 +04:00
|
|
|
|
2015-05-28 11:11:32 +03:00
|
|
|
|
2013-01-17 04:18:27 +04:00
|
|
|
void nsatari_search_restore_form( struct s_search_form_session *s, OBJECT *obj)
|
|
|
|
{
|
|
|
|
if ((s->state.flags & SEARCH_FLAG_SHOWALL) != 0) {
|
|
|
|
obj[TOOLBAR_CB_SHOWALL].ob_state |= OS_SELECTED;
|
2015-05-28 11:11:32 +03:00
|
|
|
} else {
|
2013-01-17 04:18:27 +04:00
|
|
|
obj[TOOLBAR_CB_SHOWALL].ob_state &= ~OS_SELECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((s->state.flags & SEARCH_FLAG_CASE_SENSITIVE) != 0) {
|
|
|
|
obj[TOOLBAR_CB_CASESENSE].ob_state |= OS_SELECTED;
|
2015-05-28 11:11:32 +03:00
|
|
|
} else {
|
2013-01-17 04:18:27 +04:00
|
|
|
obj[TOOLBAR_CB_CASESENSE].ob_state &= ~OS_SELECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s->state.back_avail == false) {
|
|
|
|
obj[TOOLBAR_BT_SEARCH_BACK].ob_state |= OS_DISABLED;
|
|
|
|
} else {
|
|
|
|
obj[TOOLBAR_BT_SEARCH_BACK].ob_state &= ~OS_DISABLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
TEDINFO *t = ((TEDINFO *)get_obspec(obj, TOOLBAR_TB_SRCH));
|
|
|
|
set_text(obj, TOOLBAR_TB_SRCH, s->state.text, t->te_txtlen);
|
|
|
|
}
|
2014-05-21 00:06:32 +04:00
|
|
|
|
2015-05-28 11:11:32 +03:00
|
|
|
|
2014-05-21 00:06:32 +04:00
|
|
|
void nsatari_search_session_destroy(struct s_search_form_session *s)
|
|
|
|
{
|
|
|
|
if (s != NULL) {
|
2016-04-30 13:34:45 +03:00
|
|
|
LOG("session %p", s);
|
2014-10-25 18:34:22 +04:00
|
|
|
browser_window_search_clear(s->g->browser->bw);
|
2014-05-21 00:06:32 +04:00
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-28 11:11:32 +03:00
|
|
|
|
2014-05-21 00:06:32 +04:00
|
|
|
/** checks for search parameters changes */
|
|
|
|
static bool search_session_compare(struct s_search_form_session *s, OBJECT *obj)
|
|
|
|
{
|
|
|
|
uint32_t flags_old;
|
2013-01-16 06:21:35 +04:00
|
|
|
uint32_t flags_mask = SEARCH_FLAG_SHOWALL | SEARCH_FLAG_CASE_SENSITIVE;
|
2014-05-21 00:06:32 +04:00
|
|
|
struct s_search_form_state cur;
|
2013-01-07 23:04:44 +04:00
|
|
|
|
2013-01-16 06:21:35 +04:00
|
|
|
assert(s != NULL && obj != NULL);
|
2014-05-21 00:06:32 +04:00
|
|
|
|
2013-01-16 06:21:35 +04:00
|
|
|
flags_old = s->state.flags;
|
2014-05-21 00:06:32 +04:00
|
|
|
|
|
|
|
apply_form(obj, &cur);
|
|
|
|
if ((cur.flags&flags_mask) != (flags_old&flags_mask)) {
|
|
|
|
return( true );
|
|
|
|
}
|
|
|
|
|
2013-01-07 23:04:44 +04:00
|
|
|
char * cstr;
|
2014-05-21 00:06:32 +04:00
|
|
|
cstr = gemtk_obj_get_text(obj, TOOLBAR_TB_SRCH);
|
2015-05-28 11:11:32 +03:00
|
|
|
if (cstr != NULL) {
|
2014-05-21 00:06:32 +04:00
|
|
|
if (strcmp(cstr, (char*)&s->state.text) != 0) {
|
|
|
|
return (true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-16 06:21:35 +04:00
|
|
|
void nsatari_search_perform(struct s_search_form_session *s, OBJECT *obj,
|
2015-05-28 11:11:32 +03:00
|
|
|
search_flags_t f)
|
2014-05-21 00:06:32 +04:00
|
|
|
{
|
2013-01-23 01:28:20 +04:00
|
|
|
assert(s!=null);
|
2014-10-25 18:34:22 +04:00
|
|
|
assert(input_window->browser->bw == s->g->browser->bw);
|
2014-05-21 00:06:32 +04:00
|
|
|
|
2015-05-28 11:11:32 +03:00
|
|
|
if (search_session_compare(s, obj)) {
|
2014-10-25 18:34:22 +04:00
|
|
|
browser_window_search_clear(s->g->browser->bw);
|
2014-05-21 00:06:32 +04:00
|
|
|
apply_form(obj, &s->state);
|
2013-01-16 06:21:35 +04:00
|
|
|
}
|
|
|
|
|
2014-05-21 00:06:32 +04:00
|
|
|
/* get search direction manually: */
|
2015-05-28 11:11:32 +03:00
|
|
|
if ( (f&SEARCH_FLAG_FORWARDS) != 0 ) {
|
2014-05-21 00:06:32 +04:00
|
|
|
s->state.flags |= SEARCH_FLAG_FORWARDS;
|
2015-05-28 11:11:32 +03:00
|
|
|
} else {
|
2013-01-16 06:21:35 +04:00
|
|
|
s->state.flags &= (~SEARCH_FLAG_FORWARDS);
|
2015-05-28 11:11:32 +03:00
|
|
|
}
|
2014-05-21 00:06:32 +04:00
|
|
|
|
2014-10-25 18:34:22 +04:00
|
|
|
browser_window_search(s->g->browser->bw, s,
|
2015-05-28 11:11:32 +03:00
|
|
|
s->state.flags,
|
|
|
|
gemtk_obj_get_text(obj, TOOLBAR_TB_SRCH));
|
2014-05-21 00:06:32 +04:00
|
|
|
}
|
|
|
|
|
2012-12-31 06:37:43 +04:00
|
|
|
|
2013-01-16 06:21:35 +04:00
|
|
|
struct s_search_form_session * nsatari_search_session_create(OBJECT * obj,
|
2015-05-28 11:11:32 +03:00
|
|
|
struct gui_window *gw)
|
2012-12-31 06:37:43 +04:00
|
|
|
{
|
2013-01-16 06:21:35 +04:00
|
|
|
struct s_search_form_session *sfs;
|
2012-12-31 06:37:43 +04:00
|
|
|
|
2013-01-16 06:21:35 +04:00
|
|
|
sfs = calloc(1, sizeof(struct s_search_form_session));
|
2012-12-31 06:37:43 +04:00
|
|
|
|
2013-01-17 04:18:27 +04:00
|
|
|
assert(obj);
|
2013-01-16 06:21:35 +04:00
|
|
|
assert(sfs);
|
2012-12-31 06:37:43 +04:00
|
|
|
|
2014-10-25 18:34:22 +04:00
|
|
|
sfs->g = gw;
|
2013-01-17 04:18:27 +04:00
|
|
|
|
2013-01-16 06:21:35 +04:00
|
|
|
apply_form(obj, &sfs->state);
|
2012-12-31 06:37:43 +04:00
|
|
|
|
2014-10-25 18:34:22 +04:00
|
|
|
browser_window_search_clear(gw->browser->bw);
|
2012-12-31 06:37:43 +04:00
|
|
|
|
2013-01-16 06:21:35 +04:00
|
|
|
return(sfs);
|
|
|
|
}
|