Search form inside browser windows starts to work.

This commit is contained in:
Ole Loots 2013-01-16 03:21:35 +01:00
parent 6a32f94cc2
commit 4f0ae4e128
16 changed files with 641 additions and 226 deletions

View File

@ -269,9 +269,7 @@ static void __CDECL menu_find(short item, short title, void *data)
static bool visible = false;
LOG(("%s", __FUNCTION__));
if( input_window != NULL ){
visible = !visible;
toolbar_set_visible(input_window->root->toolbar, TOOLBAR_AREA_SEARCH,
visible);
window_open_search(input_window->root);
}
}

View File

@ -102,7 +102,6 @@ short msg_box_show(short type, const char * msg);
#define GW_FLAG_RECV_PREPROC_WM 0x02 // get notified even when pre-processed
#define GW_FLAG_HAS_VTOOLBAR 0x04 // the attached toolbar is vertical
#define GW_FLAG_CUSTOM_TOOLBAR 0x08 // no internal toolbar handling
//#define GW_FLAG_TOOLBAR_REDRAW 0x10 // enable internal toolbar redraw
#define GW_FLAG_CUSTOM_SCROLLING 0x20 // no internal scroller handling
#define GW_FLAG_DEFAULTS (GW_FLAG_PREPROC_WM | GW_FLAG_RECV_PREPROC_WM)
@ -110,8 +109,7 @@ short msg_box_show(short type, const char * msg);
#define GW_STATUS_ICONIFIED 0x01
#define GW_STATUS_SHADED 0x02
#define GW_XTYPE_CHECKBOX (101 << 8)
#define GW_CB_SELECTED (OS_SELECTED | OS_CROSSED)
#define GW_CB_SELECTED (OS_SELECTED)
#define GUIWIN_VSLIDER 0x01
#define GUIWIN_HSLIDER 0x02

View File

@ -382,6 +382,10 @@ static short preproc_mu_button(GUIWIN * gw, EVMULT_OUT *ev_out, short msg[8])
gw->handler_func(gw, ev_out, msg_out);
ev_out->emo_events = oldevents;
retval = 1;
} else {
if (gw->toolbar_edit_obj != -1) {
gw->toolbar_edit_obj = -1;
}
}
}
@ -443,6 +447,10 @@ static short preproc_mu_button(GUIWIN * gw, EVMULT_OUT *ev_out, short msg[8])
evnt_timer(150);
}
}
else {
gw->form_edit_obj = -1;
}
}
return(retval);
@ -453,6 +461,40 @@ static short preproc_mu_button(GUIWIN * gw, EVMULT_OUT *ev_out, short msg[8])
*/
static short preproc_mu_keybd(GUIWIN * gw, EVMULT_OUT *ev_out, short msg[8])
{
short retval = 0;
if((gw->toolbar != NULL) && (gw->toolbar_edit_obj > -1) ) {
short next_edit_obj = gw->toolbar_edit_obj;
short next_char = -1;
short edit_idx;
short r;
r = form_wkeybd(gw->toolbar, gw->toolbar_edit_obj, next_edit_obj,
ev_out->emo_kreturn,
&next_edit_obj, &next_char, gw->handle);
if (next_edit_obj != gw->toolbar_edit_obj) {
if(gw->toolbar_edit_obj != -1) {
objc_wedit(gw->toolbar, gw->toolbar_edit_obj,
ev_out->emo_kreturn, &edit_idx,
EDEND, gw->handle);
}
gw->toolbar_edit_obj = next_edit_obj;
objc_wedit(gw->toolbar, gw->toolbar_edit_obj,
ev_out->emo_kreturn, &edit_idx,
EDINIT, gw->handle);
} else {
if(next_char > 13)
r = objc_wedit(gw->toolbar, gw->toolbar_edit_obj,
ev_out->emo_kreturn, &edit_idx,
EDCHAR, gw->handle);
}
retval = 1;
}
if((gw->form != NULL) && (gw->form_edit_obj > -1) ) {
@ -485,6 +527,7 @@ static short preproc_mu_keybd(GUIWIN * gw, EVMULT_OUT *ev_out, short msg[8])
EDCHAR, gw->handle);
}
}
return(retval);
}
/**
@ -563,6 +606,9 @@ short guiwin_dispatch_event(EVMULT_IN *ev_in, EVMULT_OUT *ev_out, short msg[8])
if ((ev_out->emo_events & MU_KEYBD)) {
retval = preproc_mu_keybd(dest, ev_out, msg);
if(retval != 0) {
handler_called = true;
}
}
if (handler_called==false) {

View File

@ -255,7 +255,7 @@ void gui_window_destroy(struct gui_window *w)
gui_set_input_gui_window(NULL);
}
search_destroy(w);
nsatari_search_session_destroy(w->search);
free(w->browser);
free(w->status);
free(w->title);

View File

@ -150,7 +150,7 @@ struct gui_window {
char * url;
struct bitmap * icon;
struct s_caret caret;
struct search_form_session *search;
struct s_search_form_session *search;
struct gui_window *next, *prev;
};

View File

@ -512,8 +512,10 @@ void dbg_pxy(const char * str, short * pxy )
void dbg_rect(const char * str, int * pxy)
{
printf("%s: x: %d, y: %d, w: %d, h: %d\n", str,
pxy[0], pxy[1], pxy[2], pxy[3] );
printf("%s: x0: %d, y0: %d, x1: %d, y1: %d (w: %d, h: %d)\n", str,
pxy[0], pxy[1], pxy[2], pxy[3],
pxy[2] - pxy[0],
pxy[3] - pxy[1] );
}
/* some LDG functions here to reduce dependencies */

View File

@ -1685,6 +1685,7 @@ bool plot_unlock(void)
wind_update(END_MCTRL);
wind_update(END_UPDATE);
graf_mouse(M_ON, NULL);
vs_clip_off(atari_plot_vdi_handle);
atari_plot_flags &= ~PLOT_FLAG_LOCKED;
return(false);
}
@ -1906,10 +1907,10 @@ bool plot_clip(const struct rect *clip)
plot_get_dimensions(&canvas);
view.clipping.x0 = clip->x0;
view.clipping.y0 = clip->y0;
view.clipping.x1 = clip->x1;
view.clipping.y1 = clip->y1;
view.clipping.x0 = clip->x0;
view.clipping.x1 = clip->x1;
plot_get_clip_grect(&gclip);
@ -1918,9 +1919,18 @@ bool plot_clip(const struct rect *clip)
rc_intersect(&canvas, &gclip);
//dbg_grect("canvas clipped: ", &gclip);
if(gclip.g_h < 0){
gclip.g_h = 0;
}
assert(rc_intersect(&screen, &gclip));
if (!rc_intersect(&screen, &gclip)) {
dbg_rect("cliprect: ", &view.clipping);
dbg_grect("screen: ", &canvas);
dbg_grect("canvas clipped: ", &gclip);
//assert(1 == 0);
}
//assert(rc_intersect(&screen, &gclip));
//dbg_grect("canvas clipped to screen", &gclip);
@ -1947,7 +1957,9 @@ bool plot_get_clip(struct rect * out)
void plot_get_clip_grect(GRECT * out)
{
struct rect clip={0,0,0,0};
plot_get_clip(&clip);
out->g_x = clip.x0;
out->g_y = clip.y0;
out->g_w = clip.x1 - clip.x0;

View File

@ -48,7 +48,7 @@
#define TOOLBAR_CB_SHOWALL 6 /* BUTTON in tree TOOLBAR */
#define TOOLBAR_TB_SRCH 7 /* FTEXT in tree TOOLBAR */
#define TOOLBAR_SEARCH_ALIGN_RIGHT 8 /* IBOX in tree TOOLBAR */
#define TOOLBAR_CLOSE_SEARCH 9 /* BUTTON in tree TOOLBAR */
#define TOOLBAR_BT_CLOSE_SEARCH 9 /* BUTTON in tree TOOLBAR */
#define TOOLBAR_AREA_NAVIGATION 10 /* BOX in tree TOOLBAR */
#define TOOLBAR_AREA_BUTTONS 11 /* IBOX in tree TOOLBAR */
#define TOOLBAR_BT_BACK 12 /* CICON in tree TOOLBAR */

View File

@ -51,7 +51,7 @@ ResourceMaster v3.65
#O 6@26@CB_SHOWALL@@
#O 7@29@TB_SRCH@@
#O 8@25@SEARCH_ALIGN_RIGHT@@
#O 9@26@CLOSE_SEARCH@@
#O 9@26@BT_CLOSE_SEARCH@@
#O 10@20@AREA_NAVIGATION@@
#O 11@25@AREA_BUTTONS@@
#O 12@33@BT_BACK@@

View File

@ -598,6 +598,32 @@ void window_get_grect(ROOTWIN *rootwin, enum browser_area_e which, GRECT *d)
}
void window_open_search(ROOTWIN *rootwin)
{
struct browser_window *bw;
GRECT area;
bw = rootwin->active_gui_window->browser->bw;
toolbar_set_visible(rootwin->toolbar, TOOLBAR_AREA_SEARCH, true);
window_get_grect(rootwin, BROWSER_AREA_SEARCH, &area);
window_schedule_redraw_grect(rootwin, &area);
window_get_grect(rootwin, BROWSER_AREA_CONTENT, &area);
browser_window_reformat(bw, false, area.g_w, area.g_h);
}
void window_close_search(ROOTWIN *rootwin)
{
struct browser_window *bw;
GRECT area;
bw = rootwin->active_gui_window->browser->bw;
toolbar_set_visible(rootwin->toolbar, TOOLBAR_AREA_SEARCH, false);
window_get_grect(rootwin, BROWSER_AREA_CONTENT, &area);
browser_window_reformat(bw, false, area.g_w, area.g_h);
}
/**
* Redraw the favicon
*/
@ -885,15 +911,15 @@ void window_process_redraws(ROOTWIN * rootwin)
// hide caret:
window_place_caret(rootwin, 0, -1, -1, -1, &content_area);
}
/*
short pxy_clip[4];
pxy_clip[0] = tb_area.g_x;
pxy_clip[0] = tb_area.g_y;
pxy_clip[0] = pxy_clip[0] + tb_area.g_w + content_area.g_w - 1;
pxy_clip[0] = pxy_clip[1] + tb_area.g_h + content_area.g_h - 1;
vs_clip(guiwin_get_vdi_handle(rootwin->win), 1, pxy_clip);
//guiwin_clear(rootwin->win);
*/
wind_get_grect(rootwin->aes_handle, WF_FIRSTXYWH, &visible_ro);
while (visible_ro.g_w > 0 && visible_ro.g_h > 0) {
@ -914,7 +940,7 @@ void window_process_redraws(ROOTWIN * rootwin)
GRECT rdrw_area = rdrw_area_ro;
if (rc_intersect(&tb_area, &rdrw_area)) {
toolbar_redraw(rootwin->toolbar, &rdrw_area);
toolbar_redraw(rootwin->toolbar, &rdrw_area);
}
rdrw_area = rdrw_area_ro;
@ -945,6 +971,7 @@ void window_process_redraws(ROOTWIN * rootwin)
caret_rdrw_required = true;
}
}
}
}
wind_get_grect(rootwin->aes_handle, WF_NEXTXYWH, &visible_ro);
@ -952,7 +979,7 @@ void window_process_redraws(ROOTWIN * rootwin)
// disable clipping:
vs_clip(guiwin_get_vdi_handle(rootwin->win), 0, pxy_clip);
//vs_clip(guiwin_get_vdi_handle(rootwin->win), 0, pxy_clip);
if (caret_rdrw_required && ((rootwin->caret.state & CARET_STATE_ENABLED)!=0)) {

View File

@ -73,6 +73,8 @@ void window_set_title(ROOTWIN *rootwin, char * text);
void window_set_content_size(ROOTWIN *rootwin, int w, int h);
void window_set_icon(ROOTWIN *rootwin, struct bitmap * bmp );
void window_set_active_gui_window(ROOTWIN *rootwin, struct gui_window *gw);
void window_open_search(ROOTWIN *rootwin);
void window_close_search(ROOTWIN *rootwin);
void window_scroll_by(ROOTWIN *rootwin, int x, int y);
void window_schedule_redraw_grect(ROOTWIN *rootwin, GRECT *area);
void window_process_redraws(ROOTWIN * rootwin);

View File

@ -44,15 +44,8 @@
#include "atari/res/netsurf.rsh"
extern struct gui_window * input_window;
extern void * h_gem_rsrc;
extern GRECT desk_area;
static SEARCH_FORM_SESSION current;
static OBJECT *dlgtree;
static GUIWIN *searchwin;
static short h_aes_win;
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);
@ -76,7 +69,8 @@ static struct gui_search_callbacks nsatari_search_callbacks = {
void nsatari_search_set_status(bool found, void *p)
{
LOG(("%p set status: %d\n", p, found));
LOG(("%p set status: %d\n", p, found));
// TODO: maybe update GUI
}
/**
@ -88,8 +82,8 @@ void nsatari_search_set_status(bool found, void *p)
void nsatari_search_set_hourglass(bool active, void *p)
{
SEARCH_FORM_SESSION s = (SEARCH_FORM_SESSION)p;
LOG((""));
if (active && current != NULL)
LOG(("active: %d, session: %p", active, p));
if (active)
gui_window_set_pointer(s->bw->window, GUI_POINTER_PROGRESS);
else
gui_window_set_pointer(s->bw->window, GUI_POINTER_DEFAULT);
@ -119,7 +113,8 @@ 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));
LOG(("%p: set forward state: %d\n", p, active));
// TODO: update gui
}
/**
@ -132,46 +127,31 @@ 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));
}
/*
void search_redraw(void *session, GRECT *clip)
{
GRECT area, clipped_area;
struct gui_window *gw = input_window;
short pxy[4];
VdiHdl vh;
if(gw == NULL)
return;
window_get_grect(gw->root, BROWSER_AREA_SEARCH, &area);
clipped_area = area;
if (!rc_intersect(clip, &clipped_area)) {
return;
}
OBJECT * tree = get_tree(SEARCH);
tree->ob_x = area.g_x;
tree->ob_y = area.g_y;
tree->ob_width = area.g_w;
tree->ob_height = area.g_h;
objc_draw_grect(tree, 0, 8, &clipped_area);
LOG(("%p: set back state: %d\n", p, active));
// TODO: update gui
}
*/
static SEARCH_FORM_SESSION get_search_session(GUIWIN * win)
static int apply_form(OBJECT *obj, struct s_search_form_state *s)
{
return (current);
char * cstr;
assert(s != NULL);
s->flags = 0;
if( (obj[TOOLBAR_CB_CASESENSE].ob_state & OS_SELECTED) != 0 )
s->flags |= SEARCH_FLAG_CASE_SENSITIVE;
if( (obj[TOOLBAR_CB_SHOWALL].ob_state & OS_SELECTED) != 0 )
s->flags |= SEARCH_FLAG_SHOWALL;
cstr = get_text(obj, TOOLBAR_TB_SRCH);
snprintf(s->text, 11, "%s", cstr);
return ( 0 );
}
static void set_text( short idx, char * text, int len )
static void set_text(OBJECT *obj, short idx, char * text, int len )
{
char spare[255];
@ -183,66 +163,37 @@ static void set_text( short idx, char * text, int len )
strcpy(spare, "");
}
set_string(dlgtree, idx, spare);
set_string(obj, idx, spare);
}
static void destroy_search_session(SEARCH_FORM_SESSION s)
void nsatari_search_session_destroy(struct s_search_form_session *s)
{
if(s != NULL ){
LOG((""));
if (s != NULL) {
LOG((""));
browser_window_search_destroy_context(s->bw);
free(s);
}
}
static int apply_form(GUIWIN *win, struct s_search_form_state * s)
{
OBJECT * obj = dlgtree;
char * cstr;
if( obj == NULL ){
goto error;
}
s->flags = 0;
if( (obj[SEARCH_CB_FWD].ob_state & OS_SELECTED) != 0 )
s->flags = SEARCH_FLAG_FORWARDS;
if( (obj[SEARCH_CB_CASESENSE].ob_state & OS_SELECTED) != 0 )
s->flags |= SEARCH_FLAG_CASE_SENSITIVE;
if( (obj[SEARCH_CB_SHOWALL].ob_state & OS_SELECTED) != 0 )
s->flags |= SEARCH_FLAG_SHOWALL;
cstr = get_text(dlgtree, SEARCH_TB_SRCH);
snprintf(s->text, 31, "%s", cstr);
return ( 0 );
error:
s->flags = SEARCH_FLAG_FORWARDS;
strncpy((char*)&s->text[0], "", 31 );
return( 1 );
}
/* checks for search parameters changes */
static bool form_changed(GUIWIN * w)
static bool search_session_compare(struct s_search_form_session *s, OBJECT *obj)
{
bool check;
bool check;
uint32_t flags_old;
uint32_t flags_mask = SEARCH_FLAG_SHOWALL | SEARCH_FLAG_CASE_SENSITIVE;
struct s_search_form_state cur;
SEARCH_FORM_SESSION s = get_search_session(w);
if( s == NULL )
return false;
OBJECT * obj = dlgtree;
assert(s != NULL && obj != NULL);
uint32_t flags_old = s->state.flags;
apply_form(w, &cur);
assert(s != NULL && obj != NULL);
/* 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 ){
flags_old = s->state.flags;
apply_form(obj, &cur);
if ((cur.flags&flags_mask) != (flags_old&flags_mask)) {
return( true );
}
char * cstr;
cstr = get_text(obj, SEARCH_TB_SRCH);
cstr = get_text(obj, TOOLBAR_TB_SRCH);
if (cstr != NULL){
if (strcmp(cstr, (char*)&s->state.text) != 0) {
return (true);
@ -253,123 +204,51 @@ static bool form_changed(GUIWIN * w)
}
static void __CDECL evnt_bt_srch_click(GUIWIN * win, int index, int unused, void *unused2)
void nsatari_search_perform(struct s_search_form_session *s, OBJECT *obj,
search_flags_t f)
{
bool fwd;
SEARCH_FORM_SESSION s = get_search_session(searchwin);
OBJECT * obj = dlgtree;
search_flags_t flags = 0;
search_flags_t flags = f;
assert(s!=null);
if( form_changed(searchwin) ){
if(search_session_compare(s, obj)){
printf("reset search form\n");
browser_window_search_destroy_context(s->bw);
apply_form(searchwin, &s->state);
apply_form(obj, &s->state);
} else {
/* get search direction manually: */
if( (obj[SEARCH_CB_FWD].ob_state & OS_SELECTED) != 0 )
s->state.flags |= SEARCH_FLAG_FORWARDS;
else
s->state.flags &= (~SEARCH_FLAG_FORWARDS);
}
if( browser_window_search_verify_new(s->bw, &nsatari_search_callbacks, s) ){
browser_window_search_step(s->bw, s->state.flags, get_text(obj, SEARCH_TB_SRCH));
}
}
static void __CDECL evnt_cb_click(GUIWIN *win, int index, int unused, void *unused2)
{
short newstate;
}
static void __CDECL evnt_close(GUIWIN *win, short buff[8])
{
}
}
void search_destroy(struct gui_window *gw)
/* get search direction manually: */
if ( (f&SEARCH_FLAG_FORWARDS) != 0 )
s->state.flags |= SEARCH_FLAG_FORWARDS;
else
s->state.flags &= (~SEARCH_FLAG_FORWARDS);
if( browser_window_search_verify_new(s->bw, &nsatari_search_callbacks, s) ){
printf("searching for: %s\n", get_text(obj, TOOLBAR_TB_SRCH));
browser_window_search_step(s->bw, s->state.flags,
get_text(obj, TOOLBAR_TB_SRCH));
}
}
struct s_search_form_session * nsatari_search_session_create(OBJECT * obj,
struct browser_window *bw)
{
/* Free Search Contexts */
/* todo: destroy search context, if any? */
LOG((""));
if (current != NULL){
destroy_search_session(current);
current = NULL;
}
struct s_search_form_session *sfs;
guiwin_remove(searchwin);
searchwin = NULL;
sfs = calloc(1, sizeof(struct s_search_form_session));
wind_close(h_aes_win);
wind_delete(h_aes_win);
h_aes_win = -1;
assert(sfs);
LOG(("done"));
sfs->bw = bw;
apply_form(obj, &sfs->state);
browser_window_search_destroy_context(bw);
return(sfs);
}
SEARCH_FORM_SESSION open_browser_search(struct gui_window * gw)
{
char * title;
SEARCH_FORM_SESSION sfs;
GRECT pos, treesize;
uint32_t kind = CLOSER | NAME | MOVER;
if (dlgtree == NULL) {
dlgtree = get_tree(SEARCH);
if (dlgtree == NULL) {
return( NULL );
}
}
if(searchwin){
search_destroy(gw);
}
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 ...";
/* setup dipslay position: right corner */
treesize.g_x = 0;
treesize.g_y = 0;
treesize.g_w = dlgtree->ob_width;
treesize.g_h = dlgtree->ob_height;
wind_calc_grect(WC_BORDER, kind, &treesize, &pos);
pos.g_x = desk_area.g_w - pos.g_w;
pos.g_y = desk_area.g_h - pos.g_h;
/* create the dialog: */
h_aes_win = wind_create_grect(kind, &pos);
wind_set_str(h_aes_win, WF_NAME, title);
current = sfs;
sfs->bw = gw->browser->bw;
/*
sfs->formwind = mt_FormCreate( &app, tree, WAT_FORM,
NULL, title,
&pos, true, false);
*/
/*
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(searchwin, &sfs->state );
set_text(SEARCH_TB_SRCH, (char*)"", 31);
return(current);
}

375
atari/search.c.old Normal file
View File

@ -0,0 +1,375 @@
/*
* 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/>.
*
* Module Description:
*
*
*
*/
#include <limits.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdbool.h>
#include <assert.h>
#include "desktop/gui.h"
#include "desktop/browser.h"
#include "desktop/browser_private.h"
#include "desktop/search.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "atari/gui.h"
#include "atari/rootwin.h"
#include "atari/misc.h"
#include "atari/search.h"
#include "atari/gemtk/gemtk.h"
#include "atari/res/netsurf.rsh"
extern struct gui_window * input_window;
extern void * h_gem_rsrc;
extern GRECT desk_area;
static SEARCH_FORM_SESSION current;
static OBJECT *dlgtree;
static GUIWIN *searchwin;
static short h_aes_win;
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);
static struct gui_search_callbacks nsatari_search_callbacks = {
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;
LOG((""));
if (active && current != NULL)
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));
}
/*
void search_redraw(void *session, GRECT *clip)
{
GRECT area, clipped_area;
struct gui_window *gw = input_window;
short pxy[4];
VdiHdl vh;
if(gw == NULL)
return;
window_get_grect(gw->root, BROWSER_AREA_SEARCH, &area);
clipped_area = area;
if (!rc_intersect(clip, &clipped_area)) {
return;
}
OBJECT * tree = get_tree(SEARCH);
tree->ob_x = area.g_x;
tree->ob_y = area.g_y;
tree->ob_width = area.g_w;
tree->ob_height = area.g_h;
objc_draw_grect(tree, 0, 8, &clipped_area);
}
*/
static SEARCH_FORM_SESSION get_search_session(GUIWIN * win)
{
return (current);
}
static void set_text( short idx, char * text, int len )
{
char spare[255];
if( len > 254 )
len = 254;
if( text != NULL ){
strncpy(spare, text, 254);
} else {
strcpy(spare, "");
}
set_string(dlgtree, idx, spare);
}
static void destroy_search_session(SEARCH_FORM_SESSION s)
{
if(s != NULL ){
LOG((""));
free(s);
}
}
static int apply_form(GUIWIN *win, struct s_search_form_state * s)
{
OBJECT * obj = dlgtree;
char * cstr;
if( obj == NULL ){
goto error;
}
s->flags = 0;
if( (obj[SEARCH_CB_FWD].ob_state & OS_SELECTED) != 0 )
s->flags = SEARCH_FLAG_FORWARDS;
if( (obj[SEARCH_CB_CASESENSE].ob_state & OS_SELECTED) != 0 )
s->flags |= SEARCH_FLAG_CASE_SENSITIVE;
if( (obj[SEARCH_CB_SHOWALL].ob_state & OS_SELECTED) != 0 )
s->flags |= SEARCH_FLAG_SHOWALL;
cstr = get_text(dlgtree, SEARCH_TB_SRCH);
snprintf(s->text, 31, "%s", cstr);
return ( 0 );
error:
s->flags = SEARCH_FLAG_FORWARDS;
strncpy((char*)&s->text[0], "", 31 );
return( 1 );
}
/* checks for search parameters changes */
static bool form_changed(GUIWIN * w)
{
bool check;
struct s_search_form_state cur;
SEARCH_FORM_SESSION s = get_search_session(w);
if( s == NULL )
return false;
OBJECT * obj = dlgtree;
assert(s != NULL && obj != NULL);
uint32_t flags_old = s->state.flags;
apply_form(w, &cur);
/* 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;
cstr = get_text(obj, SEARCH_TB_SRCH);
if (cstr != NULL){
if (strcmp(cstr, (char*)&s->state.text) != 0) {
return (true);
}
}
return( false );
}
static void __CDECL evnt_bt_srch_click(GUIWIN * win, int index, int unused, void *unused2)
{
bool fwd;
SEARCH_FORM_SESSION s = get_search_session(searchwin);
OBJECT * obj = dlgtree;
search_flags_t flags = 0;
if( form_changed(searchwin) ){
browser_window_search_destroy_context(s->bw);
apply_form(searchwin, &s->state);
} else {
/* get search direction manually: */
if( (obj[SEARCH_CB_FWD].ob_state & OS_SELECTED) != 0 )
s->state.flags |= SEARCH_FLAG_FORWARDS;
else
s->state.flags &= (~SEARCH_FLAG_FORWARDS);
}
if( browser_window_search_verify_new(s->bw, &nsatari_search_callbacks, s) ){
browser_window_search_step(s->bw, s->state.flags, get_text(obj, SEARCH_TB_SRCH));
}
}
static void __CDECL evnt_cb_click(GUIWIN *win, int index, int unused, void *unused2)
{
short newstate;
}
static void __CDECL evnt_close(GUIWIN *win, short buff[8])
{
}
void search_destroy(struct gui_window *gw)
{
/* Free Search Contexts */
/* todo: destroy search context, if any? */
LOG((""));
if (current != NULL){
destroy_search_session(current);
current = NULL;
}
guiwin_remove(searchwin);
searchwin = NULL;
wind_close(h_aes_win);
wind_delete(h_aes_win);
h_aes_win = -1;
LOG(("done"));
}
SEARCH_FORM_SESSION open_browser_search(struct gui_window * gw)
{
char * title;
SEARCH_FORM_SESSION sfs;
GRECT pos, treesize;
uint32_t kind = CLOSER | NAME | MOVER;
if (dlgtree == NULL) {
dlgtree = get_tree(SEARCH);
if (dlgtree == NULL) {
return( NULL );
}
}
if(searchwin){
search_destroy(gw);
}
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 ...";
/* setup dipslay position: right corner */
treesize.g_x = 0;
treesize.g_y = 0;
treesize.g_w = dlgtree->ob_width;
treesize.g_h = dlgtree->ob_height;
wind_calc_grect(WC_BORDER, kind, &treesize, &pos);
pos.g_x = desk_area.g_w - pos.g_w;
pos.g_y = desk_area.g_h - pos.g_h;
/* create the dialog: */
h_aes_win = wind_create_grect(kind, &pos);
wind_set_str(h_aes_win, WF_NAME, title);
current = sfs;
sfs->bw = gw->browser->bw;
/*
sfs->formwind = mt_FormCreate( &app, tree, WAT_FORM,
NULL, title,
&pos, true, false);
*/
/*
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(searchwin, &sfs->state );
set_text(SEARCH_TB_SRCH, (char*)"", 31);
return(current);
}

View File

@ -21,6 +21,7 @@
*
*/
#include "desktop/search.h"
#ifndef NS_ATARI_SEARCH_H
#define NS_ATARI_SEARCH_H
@ -44,9 +45,10 @@ struct s_search_form_session {
typedef struct s_search_form_session * SEARCH_FORM_SESSION;
SEARCH_FORM_SESSION open_browser_search(struct gui_window * gw);
void search_destroy(struct gui_window * gw);
void search_redraw(void *session, GRECT *clip);
struct s_search_form_session * nsatari_search_session_create(OBJECT * obj,
struct browser_window *bw);
void nsatari_search_session_destroy(struct s_search_form_session *s);
void nsatari_search_perform(struct s_search_form_session *s, OBJECT *obj,
search_flags_t f);
#endif

52
atari/search.h.old Normal file
View File

@ -0,0 +1,52 @@
/*
* 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/>.
*
* Module Description:
*
*
*
*/
#ifndef NS_ATARI_SEARCH_H
#define NS_ATARI_SEARCH_H
#define SEARCH_MAX_SLEN 24
struct gui_window;
struct browser_window;
struct s_search_form_state
{
char text[32];
uint32_t flags;
};
struct s_search_form_session {
struct browser_window * bw;
struct s_search_form_state state;
};
typedef struct s_search_form_session * SEARCH_FORM_SESSION;
SEARCH_FORM_SESSION open_browser_search(struct gui_window * gw);
void search_destroy(struct gui_window * gw);
struct s_search_session
#endif

View File

@ -410,7 +410,7 @@ void toolbar_redraw(struct s_toolbar *tb, GRECT *clip)
.x1 = MAX(0,area.g_x - area_ro.g_x) + area.g_w,
.y1 = MAX(0,area.g_y - area_ro.g_y) + area.g_h
};
//dbg_rect("tb textarea clip: ", &r);
dbg_rect("tb textarea clip: ", &r);
textarea_redraw(tb->url.textarea, 0, 0, &r, &toolbar_rdrw_ctx);
}
}
@ -701,6 +701,9 @@ void toolbar_mouse_input(struct s_toolbar *tb, short obj, short button)
GRECT work;
short mx, my, mb, kstat;
int old;
OBJECT * toolbar_tree;
struct gui_window * gw;
if (obj==TOOLBAR_AREA_URL){
@ -759,9 +762,28 @@ void toolbar_mouse_input(struct s_toolbar *tb, short obj, short button)
BROWSER_MOUSE_PRESS_1, mx, my );
}
}
} else {
}
else if (obj==TOOLBAR_BT_SEARCH_FWD) {
gw = tb->owner->active_gui_window;
toolbar_tree = get_tree(TOOLBAR);
if (gw->search == NULL) {
struct browser_window * bw = gw->browser->bw;
gw->search = nsatari_search_session_create(toolbar_tree, bw);
}
assert(gw->search);
nsatari_search_perform(gw->search, toolbar_tree, SEARCH_FLAG_FORWARDS);
}
else if (obj==TOOLBAR_BT_CLOSE_SEARCH) {
gw = tb->owner->active_gui_window;
toolbar_tree = get_tree(TOOLBAR);
if (gw->search != NULL) {
nsatari_search_session_destroy(gw->search);
gw->search = NULL;
}
window_close_search(tb->owner);
}
else {
struct s_tb_button *bt = find_button(tb, obj);
printf("found button: %p\n", bt);
if (bt != NULL && bt->state != button_off) {
bt->cb_click(tb);
struct gui_window * gw = window_get_active_gui_window(tb->owner);