2012-08-24 02:47:37 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2012 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/>.
|
|
|
|
*/
|
|
|
|
|
2011-01-30 22:24:03 +03:00
|
|
|
#include <limits.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <windom.h>
|
|
|
|
|
|
|
|
#include "desktop/gui.h"
|
|
|
|
#include "desktop/browser.h"
|
2012-08-22 20:14:42 +04:00
|
|
|
#include "desktop/browser_private.h"
|
2011-01-30 22:24:03 +03:00
|
|
|
#include "desktop/search.h"
|
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "atari/gui.h"
|
|
|
|
#include "atari/misc.h"
|
2011-05-10 02:10:02 +04:00
|
|
|
#include "atari/browser.h"
|
2011-01-30 22:24:03 +03:00
|
|
|
#include "atari/search.h"
|
|
|
|
#include "atari/res/netsurf.rsh"
|
|
|
|
|
2011-02-12 22:41:07 +03:00
|
|
|
extern struct gui_window * input_window;
|
2011-01-30 22:24:03 +03:00
|
|
|
extern void * h_gem_rsrc;
|
|
|
|
|
|
|
|
|
|
|
|
static SEARCH_FORM_SESSION current;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2012-08-14 16:41:30 +04:00
|
|
|
static struct gui_search_callbacks nsatari_search_callbacks = {
|
2011-01-30 22:24:03 +03:00
|
|
|
nsatari_search_set_forward_state,
|
|
|
|
nsatari_search_set_back_state,
|
|
|
|
nsatari_search_set_status,
|
|
|
|
nsatari_search_set_hourglass,
|
|
|
|
nsatari_search_add_recent
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change the displayed search status.
|
|
|
|
* \param found search pattern matched in text
|
|
|
|
* \param p the pointer sent to search_verify_new() / search_create_context()
|
|
|
|
*/
|
|
|
|
|
|
|
|
void nsatari_search_set_status(bool found, void *p)
|
|
|
|
{
|
|
|
|
LOG(("%p set status: %d\n", p, found));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* display hourglass while searching
|
|
|
|
* \param active start/stop indicator
|
|
|
|
* \param p the pointer sent to search_verify_new() / search_create_context()
|
|
|
|
*/
|
|
|
|
|
|
|
|
void nsatari_search_set_hourglass(bool active, void *p)
|
|
|
|
{
|
|
|
|
SEARCH_FORM_SESSION s = (SEARCH_FORM_SESSION)p;
|
2011-02-26 02:25:22 +03:00
|
|
|
LOG((""));
|
2011-09-19 22:38:48 +04:00
|
|
|
if( active && current != NULL )
|
2011-01-30 22:24:03 +03:00
|
|
|
gui_window_set_pointer(s->bw->window, GUI_POINTER_PROGRESS);
|
|
|
|
else
|
|
|
|
gui_window_set_pointer(s->bw->window, GUI_POINTER_DEFAULT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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()
|
|
|
|
*/
|
|
|
|
|
|
|
|
void nsatari_search_add_recent(const char *string, void *p)
|
|
|
|
{
|
|
|
|
LOG(("%p add recent: %s\n", p, string));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* activate search forwards button in gui
|
|
|
|
* \param active activate/inactivate
|
|
|
|
* \param p the pointer sent to search_verify_new() / search_create_context()
|
|
|
|
*/
|
|
|
|
|
|
|
|
void nsatari_search_set_forward_state(bool active, void *p)
|
|
|
|
{
|
|
|
|
SEARCH_FORM_SESSION s = (SEARCH_FORM_SESSION)p;
|
|
|
|
/* deactivate back cb */
|
|
|
|
LOG(("%p: set forward state: %d\n", p, active));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* activate search back button in gui
|
|
|
|
* \param active activate/inactivate
|
|
|
|
* \param p the pointer sent to search_verify_new() / search_create_context()
|
|
|
|
*/
|
|
|
|
|
|
|
|
void nsatari_search_set_back_state(bool active, void *p)
|
|
|
|
{
|
|
|
|
SEARCH_FORM_SESSION s = (SEARCH_FORM_SESSION)p;
|
|
|
|
/* deactivate back cb */
|
|
|
|
LOG(("%p: set back state: %d\n", p, active));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static SEARCH_FORM_SESSION get_search_session(WINDOW * win)
|
|
|
|
{
|
|
|
|
return (current);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void destroy_search_session( SEARCH_FORM_SESSION s )
|
|
|
|
{
|
2011-02-26 02:25:22 +03:00
|
|
|
if( s != NULL ){
|
|
|
|
LOG((""));
|
|
|
|
free( s );
|
|
|
|
}
|
2011-01-30 22:24:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int apply_form( WINDOW * win, struct s_search_form_state * s )
|
|
|
|
{
|
|
|
|
OBJECT * obj = ObjcTree(OC_FORM, win );
|
|
|
|
if( obj == NULL ){
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
s->flags = 0;
|
2011-02-12 22:41:07 +03:00
|
|
|
if( (obj[SEARCH_CB_FWD].ob_state & SELECTED) != 0 )
|
2011-01-30 22:24:03 +03:00
|
|
|
s->flags = SEARCH_FLAG_FORWARDS;
|
2011-02-12 22:41:07 +03:00
|
|
|
if( (obj[SEARCH_CB_CASESENSE].ob_state & SELECTED) != 0 )
|
2011-01-30 22:24:03 +03:00
|
|
|
s->flags |= SEARCH_FLAG_CASE_SENSITIVE;
|
2011-02-12 22:41:07 +03:00
|
|
|
if( (obj[SEARCH_CB_SHOWALL].ob_state & SELECTED) != 0 )
|
2011-01-30 22:24:03 +03:00
|
|
|
s->flags |= SEARCH_FLAG_SHOWALL;
|
|
|
|
|
|
|
|
char * cstr = ObjcString( obj, SEARCH_TB_SRCH, NULL );
|
|
|
|
if( cstr != NULL ) {
|
|
|
|
strncpy((char*)&s->text[0], cstr, 31 );
|
|
|
|
}
|
|
|
|
return ( 0 );
|
|
|
|
|
2011-09-19 22:38:48 +04:00
|
|
|
error:
|
|
|
|
s->flags = SEARCH_FLAG_FORWARDS;
|
2011-01-30 22:24:03 +03:00
|
|
|
/* s->forward = true; */
|
|
|
|
strncpy((char*)&s->text[0], "", 31 );
|
|
|
|
return( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* checks if search parameters changes */
|
|
|
|
static bool form_changed( WINDOW * w )
|
|
|
|
{
|
|
|
|
bool check;
|
|
|
|
struct s_search_form_state cur;
|
|
|
|
SEARCH_FORM_SESSION s = get_search_session(w);
|
2011-02-12 22:41:07 +03:00
|
|
|
if( s == NULL )
|
|
|
|
return false;
|
2011-01-30 22:24:03 +03:00
|
|
|
OBJECT * obj = ObjcTree(OC_FORM, w);
|
|
|
|
assert( s != NULL && obj != NULL );
|
|
|
|
uint32_t flags_old = s->state.flags;
|
|
|
|
apply_form(w, &cur);
|
2011-09-19 22:38:48 +04:00
|
|
|
|
2011-01-30 22:24:03 +03:00
|
|
|
/* adjust the forward flag, it should not init an new search */
|
|
|
|
flags_old |= SEARCH_FLAG_FORWARDS;
|
|
|
|
cur.flags |= SEARCH_FLAG_FORWARDS;
|
|
|
|
if( cur.flags != flags_old ){
|
|
|
|
return( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
char * cstr = ObjcString( obj, SEARCH_TB_SRCH, NULL );
|
|
|
|
if( cstr != NULL ){
|
|
|
|
if( strcmp(cstr, (char*)&s->state.text) != 0 ) {
|
|
|
|
return ( true );
|
|
|
|
}
|
|
|
|
}
|
2011-09-19 22:38:48 +04:00
|
|
|
|
2011-01-30 22:24:03 +03:00
|
|
|
return( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-19 22:38:48 +04:00
|
|
|
static void __CDECL evnt_bt_srch_click( WINDOW *win, int index, int unused, void *unused2)
|
2011-02-02 00:26:04 +03:00
|
|
|
{
|
2011-01-30 22:24:03 +03:00
|
|
|
|
|
|
|
bool fwd;
|
|
|
|
SEARCH_FORM_SESSION s = get_search_session(win);
|
|
|
|
OBJECT * obj = ObjcTree(OC_FORM, s->formwind );
|
|
|
|
search_flags_t flags = 0;
|
|
|
|
|
2011-09-19 22:38:48 +04:00
|
|
|
ObjcChange(OC_FORM, win, index, ~SELECTED , TRUE);
|
2011-08-24 16:32:51 +04:00
|
|
|
if( form_changed(win) ){
|
|
|
|
browser_window_search_destroy_context(s->bw);
|
2011-02-12 22:41:07 +03:00
|
|
|
apply_form( win, &s->state );
|
|
|
|
} else {
|
|
|
|
/* get search direction manually: */
|
|
|
|
if( (obj[SEARCH_CB_FWD].ob_state & SELECTED) != 0 )
|
|
|
|
s->state.flags |= SEARCH_FLAG_FORWARDS;
|
2011-09-19 22:38:48 +04:00
|
|
|
else
|
2011-02-12 22:41:07 +03:00
|
|
|
s->state.flags &= (~SEARCH_FLAG_FORWARDS);
|
|
|
|
}
|
2011-08-24 16:32:51 +04:00
|
|
|
if( browser_window_search_verify_new(s->bw, &nsatari_search_callbacks, s) ){
|
2011-09-19 22:38:48 +04:00
|
|
|
browser_window_search_step(s->bw, s->state.flags, ObjcString( obj, SEARCH_TB_SRCH, NULL ) );
|
2011-02-12 22:41:07 +03:00
|
|
|
}
|
2011-01-30 22:24:03 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-09-19 22:38:48 +04:00
|
|
|
static void __CDECL evnt_cb_click( WINDOW *win, int index, int unused, void *unused2)
|
2011-02-02 00:26:04 +03:00
|
|
|
{
|
2011-01-30 22:24:03 +03:00
|
|
|
|
|
|
|
short newstate;
|
|
|
|
OBJECT * obj = ObjcTree(OC_FORM, get_search_session(win)->formwind );
|
|
|
|
}
|
|
|
|
|
2011-09-19 22:38:48 +04:00
|
|
|
static void __CDECL evnt_close( WINDOW *win, short buff[8])
|
2011-02-02 00:26:04 +03:00
|
|
|
{
|
2011-01-30 22:24:03 +03:00
|
|
|
/* Free Search Contexts */
|
2011-02-26 02:25:22 +03:00
|
|
|
/* todo: destroy search context, if any? */
|
2011-02-12 22:41:07 +03:00
|
|
|
SEARCH_FORM_SESSION s = get_search_session(win);
|
2011-09-19 22:38:48 +04:00
|
|
|
if( s != NULL ){
|
2011-02-12 22:41:07 +03:00
|
|
|
destroy_search_session( s );
|
|
|
|
}
|
2011-01-30 22:24:03 +03:00
|
|
|
current = NULL;
|
2011-09-19 22:38:48 +04:00
|
|
|
ApplWrite( _AESapid, WM_DESTROY, win->handle, 0,0,0,0 );
|
2011-04-11 01:46:05 +04:00
|
|
|
}
|
|
|
|
|
2011-02-12 22:41:07 +03:00
|
|
|
void search_destroy( struct gui_window * gw )
|
|
|
|
{
|
2011-02-26 02:25:22 +03:00
|
|
|
LOG(("search_destroy %p / %p", gw, current ));
|
2011-09-09 23:59:36 +04:00
|
|
|
if( current != NULL && current->formwind != NULL ){
|
2011-02-12 22:41:07 +03:00
|
|
|
ApplWrite( _AESapid, WM_CLOSED, current->formwind->handle, 0,0,0,0);
|
|
|
|
/* Handle Close event */
|
|
|
|
EvntWindom( MU_MESAG );
|
|
|
|
/* Handle Destroy Event */
|
|
|
|
EvntWindom( MU_MESAG );
|
|
|
|
}
|
2011-02-26 02:25:22 +03:00
|
|
|
LOG(("done"));
|
2011-01-30 22:24:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
SEARCH_FORM_SESSION open_browser_search( struct gui_window * gw )
|
|
|
|
{
|
|
|
|
char * title;
|
2012-08-14 16:41:30 +04:00
|
|
|
SEARCH_FORM_SESSION sfs;
|
2012-07-27 05:35:53 +04:00
|
|
|
GRECT pos, treesize;
|
2011-01-30 22:24:03 +03:00
|
|
|
OBJECT * tree = get_tree(SEARCH);
|
|
|
|
if( tree == NULL ){
|
|
|
|
return( NULL );
|
2012-08-14 16:41:30 +04:00
|
|
|
}
|
2012-07-27 05:35:53 +04:00
|
|
|
|
2011-02-02 00:26:04 +03:00
|
|
|
sfs = calloc(1, sizeof(struct s_search_form_session));
|
2011-01-30 22:24:03 +03:00
|
|
|
if( sfs == NULL )
|
|
|
|
return( NULL );
|
2012-08-14 16:41:30 +04:00
|
|
|
|
2011-01-30 22:24:03 +03:00
|
|
|
title = (char*)messages_get("FindTextNS");
|
|
|
|
if( title == NULL )
|
|
|
|
title = (char*)"Find text ...";
|
|
|
|
|
2012-08-14 16:41:30 +04:00
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
current = sfs;
|
2011-01-30 22:24:03 +03:00
|
|
|
sfs->bw = gw->browser->bw;
|
|
|
|
sfs->formwind = mt_FormCreate( &app, tree, WAT_FORM,
|
2011-09-19 22:38:48 +04:00
|
|
|
NULL, title,
|
2012-07-27 05:35:53 +04:00
|
|
|
&pos, true, false);
|
2011-01-30 22:24:03 +03:00
|
|
|
|
|
|
|
ObjcAttachFormFunc( sfs->formwind, SEARCH_BT_SEARCH, evnt_bt_srch_click, NULL);
|
|
|
|
ObjcAttachFormFunc( sfs->formwind, SEARCH_CB_CASESENSE, evnt_cb_click, NULL);
|
|
|
|
ObjcAttachFormFunc( sfs->formwind, SEARCH_CB_SHOWALL, evnt_cb_click, NULL);
|
|
|
|
ObjcAttachFormFunc( sfs->formwind, SEARCH_CB_FWD, evnt_cb_click, NULL);
|
|
|
|
EvntAdd( sfs->formwind, WM_CLOSED, evnt_close, EV_TOP);
|
|
|
|
apply_form(sfs->formwind, &sfs->state );
|
|
|
|
strncpy( ObjcString( tree, SEARCH_TB_SRCH, NULL ), "", SEARCH_MAX_SLEN);
|
|
|
|
|
|
|
|
return( current );
|
2011-09-19 22:38:48 +04:00
|
|
|
|
2011-08-24 16:32:51 +04:00
|
|
|
}
|