From 3694345204f9d8b74a1a52a66a10760b220ec6a7 Mon Sep 17 00:00:00 2001 From: Ole Loots Date: Sun, 30 Jan 2011 19:24:03 +0000 Subject: Implemented Search Dialog svn path=/trunk/netsurf/; revision=11536 --- atari/bitmap.c | 0 atari/bitmap.h | 0 atari/browser.c | 0 atari/browser.h | 0 atari/browser_win.c | 0 atari/browser_win.h | 0 atari/clipboard.h | 0 atari/download.c | 0 atari/download.h | 0 atari/filetype.c | 0 atari/findfile.h | 0 atari/font.c | 0 atari/font.h | 0 atari/global_evnt.c | 0 atari/global_evnt.h | 0 atari/gui.c | 2 +- atari/gui.h | 0 atari/history.c | 0 atari/history.h | 0 atari/hotlist.c | 0 atari/hotlist.h | 0 atari/login.c | 0 atari/login.h | 0 atari/misc.c | 0 atari/misc.h | 0 atari/options.h | 0 atari/plot.c | 0 atari/plot.h | 0 atari/plot/eddi.h | 0 atari/plot/eddi.s | 0 atari/plot/font_freetype.c | 0 atari/plot/font_freetype.h | 0 atari/plot/font_vdi.c | 0 atari/plot/font_vdi.h | 0 atari/plot/plotter.c | 0 atari/plot/plotter.h | 0 atari/plot/plotter_vdi.c | 0 atari/plot/plotter_vdi.h | 0 atari/schedule.c | 0 atari/schedule.h | 0 atari/search.c | 257 +++++++++++++++++++++++++++++++++++++++++++++ atari/search.h | 23 ++++ atari/slider.c | 0 atari/slider.h | 0 atari/statusbar.c | 0 atari/statusbar.h | 0 atari/thumbnail.c | 0 atari/toolbar.c | 5 +- atari/toolbar.h | 0 atari/treeview.c | 0 atari/treeview.h | 0 atari/verify_ssl.c | 0 atari/verify_ssl.h | 0 53 files changed, 283 insertions(+), 4 deletions(-) mode change 100644 => 100755 atari/bitmap.c mode change 100644 => 100755 atari/bitmap.h mode change 100644 => 100755 atari/browser.c mode change 100644 => 100755 atari/browser.h mode change 100644 => 100755 atari/browser_win.c mode change 100644 => 100755 atari/browser_win.h mode change 100644 => 100755 atari/clipboard.h mode change 100644 => 100755 atari/download.c mode change 100644 => 100755 atari/download.h mode change 100644 => 100755 atari/filetype.c mode change 100644 => 100755 atari/findfile.h mode change 100644 => 100755 atari/font.c mode change 100644 => 100755 atari/font.h mode change 100644 => 100755 atari/global_evnt.c mode change 100644 => 100755 atari/global_evnt.h mode change 100644 => 100755 atari/gui.c mode change 100644 => 100755 atari/gui.h mode change 100644 => 100755 atari/history.c mode change 100644 => 100755 atari/history.h mode change 100644 => 100755 atari/hotlist.c mode change 100644 => 100755 atari/hotlist.h mode change 100644 => 100755 atari/login.c mode change 100644 => 100755 atari/login.h mode change 100644 => 100755 atari/misc.c mode change 100644 => 100755 atari/misc.h mode change 100644 => 100755 atari/options.h mode change 100644 => 100755 atari/plot.c mode change 100644 => 100755 atari/plot.h mode change 100644 => 100755 atari/plot/eddi.h mode change 100644 => 100755 atari/plot/eddi.s mode change 100644 => 100755 atari/plot/font_freetype.c mode change 100644 => 100755 atari/plot/font_freetype.h mode change 100644 => 100755 atari/plot/font_vdi.c mode change 100644 => 100755 atari/plot/font_vdi.h mode change 100644 => 100755 atari/plot/plotter.c mode change 100644 => 100755 atari/plot/plotter.h mode change 100644 => 100755 atari/plot/plotter_vdi.c mode change 100644 => 100755 atari/plot/plotter_vdi.h mode change 100644 => 100755 atari/schedule.c mode change 100644 => 100755 atari/schedule.h create mode 100644 atari/search.c create mode 100644 atari/search.h mode change 100644 => 100755 atari/slider.c mode change 100644 => 100755 atari/slider.h mode change 100644 => 100755 atari/statusbar.c mode change 100644 => 100755 atari/statusbar.h mode change 100644 => 100755 atari/thumbnail.c mode change 100644 => 100755 atari/toolbar.c mode change 100644 => 100755 atari/toolbar.h mode change 100644 => 100755 atari/treeview.c mode change 100644 => 100755 atari/treeview.h mode change 100644 => 100755 atari/verify_ssl.c mode change 100644 => 100755 atari/verify_ssl.h diff --git a/atari/bitmap.c b/atari/bitmap.c old mode 100644 new mode 100755 diff --git a/atari/bitmap.h b/atari/bitmap.h old mode 100644 new mode 100755 diff --git a/atari/browser.c b/atari/browser.c old mode 100644 new mode 100755 diff --git a/atari/browser.h b/atari/browser.h old mode 100644 new mode 100755 diff --git a/atari/browser_win.c b/atari/browser_win.c old mode 100644 new mode 100755 diff --git a/atari/browser_win.h b/atari/browser_win.h old mode 100644 new mode 100755 diff --git a/atari/clipboard.h b/atari/clipboard.h old mode 100644 new mode 100755 diff --git a/atari/download.c b/atari/download.c old mode 100644 new mode 100755 diff --git a/atari/download.h b/atari/download.h old mode 100644 new mode 100755 diff --git a/atari/filetype.c b/atari/filetype.c old mode 100644 new mode 100755 diff --git a/atari/findfile.h b/atari/findfile.h old mode 100644 new mode 100755 diff --git a/atari/font.c b/atari/font.c old mode 100644 new mode 100755 diff --git a/atari/font.h b/atari/font.h old mode 100644 new mode 100755 diff --git a/atari/global_evnt.c b/atari/global_evnt.c old mode 100644 new mode 100755 diff --git a/atari/global_evnt.h b/atari/global_evnt.h old mode 100644 new mode 100755 diff --git a/atari/gui.c b/atari/gui.c old mode 100644 new mode 100755 index 962570e57..c7147bb39 --- a/atari/gui.c +++ b/atari/gui.c @@ -1130,7 +1130,7 @@ int main(int argc, char** argv) netsurf_init(&argc, &argv, options, messages); gui_init(argc, argv); gui_init2(argc, argv); - browser_window_create(cfg_homepage_url, 0, 0, true, false); + //browser_window_create(cfg_homepage_url, 0, 0, true, false); graf_mouse( ARROW , NULL); netsurf_main_loop(); netsurf_exit(); diff --git a/atari/gui.h b/atari/gui.h old mode 100644 new mode 100755 diff --git a/atari/history.c b/atari/history.c old mode 100644 new mode 100755 diff --git a/atari/history.h b/atari/history.h old mode 100644 new mode 100755 diff --git a/atari/hotlist.c b/atari/hotlist.c old mode 100644 new mode 100755 diff --git a/atari/hotlist.h b/atari/hotlist.h old mode 100644 new mode 100755 diff --git a/atari/login.c b/atari/login.c old mode 100644 new mode 100755 diff --git a/atari/login.h b/atari/login.h old mode 100644 new mode 100755 diff --git a/atari/misc.c b/atari/misc.c old mode 100644 new mode 100755 diff --git a/atari/misc.h b/atari/misc.h old mode 100644 new mode 100755 diff --git a/atari/options.h b/atari/options.h old mode 100644 new mode 100755 diff --git a/atari/plot.c b/atari/plot.c old mode 100644 new mode 100755 diff --git a/atari/plot.h b/atari/plot.h old mode 100644 new mode 100755 diff --git a/atari/plot/eddi.h b/atari/plot/eddi.h old mode 100644 new mode 100755 diff --git a/atari/plot/eddi.s b/atari/plot/eddi.s old mode 100644 new mode 100755 diff --git a/atari/plot/font_freetype.c b/atari/plot/font_freetype.c old mode 100644 new mode 100755 diff --git a/atari/plot/font_freetype.h b/atari/plot/font_freetype.h old mode 100644 new mode 100755 diff --git a/atari/plot/font_vdi.c b/atari/plot/font_vdi.c old mode 100644 new mode 100755 diff --git a/atari/plot/font_vdi.h b/atari/plot/font_vdi.h old mode 100644 new mode 100755 diff --git a/atari/plot/plotter.c b/atari/plot/plotter.c old mode 100644 new mode 100755 diff --git a/atari/plot/plotter.h b/atari/plot/plotter.h old mode 100644 new mode 100755 diff --git a/atari/plot/plotter_vdi.c b/atari/plot/plotter_vdi.c old mode 100644 new mode 100755 diff --git a/atari/plot/plotter_vdi.h b/atari/plot/plotter_vdi.h old mode 100644 new mode 100755 diff --git a/atari/schedule.c b/atari/schedule.c old mode 100644 new mode 100755 diff --git a/atari/schedule.h b/atari/schedule.h old mode 100644 new mode 100755 diff --git a/atari/search.c b/atari/search.c new file mode 100644 index 000000000..6af6caf12 --- /dev/null +++ b/atari/search.c @@ -0,0 +1,257 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "desktop/gui.h" +#include "desktop/browser.h" +#include "desktop/search.h" +#include "utils/log.h" +#include "utils/messages.h" +#include "atari/gui.h" +#include "atari/misc.h" +#include "atari/search.h" +#include "atari/res/netsurf.rsh" + +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); + +static struct 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; + if( active ) + 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 ) +{ + free( s ); +} + +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; + if( (obj[SEARCH_CB_FWD].ob_state & CROSSED) != 0 ) + s->flags = SEARCH_FLAG_FORWARDS; + if( (obj[SEARCH_CB_CASESENSE].ob_state & CROSSED) != 0 ) + s->flags |= SEARCH_FLAG_CASE_SENSITIVE; + if( (obj[SEARCH_CB_SHOWALL].ob_state & CROSSED) != 0 ) + 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 ); + +error: + s->flags = SEARCH_FLAG_FORWARDS; + /* 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); + OBJECT * obj = ObjcTree(OC_FORM, w); + 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 = ObjcString( obj, SEARCH_TB_SRCH, NULL ); + if( cstr != NULL ){ + if( strcmp(cstr, (char*)&s->state.text) != 0 ) { + return ( true ); + } + } + + return( false ); +} + + +static void __CDECL evnt_bt_srch_click( WINDOW *win, int index, int unused, void *unused2) { + + ObjcChange( OC_FORM, win, index, ~SELECTED, TRUE); + bool fwd; + SEARCH_FORM_SESSION s = get_search_session(win); + OBJECT * obj = ObjcTree(OC_FORM, s->formwind ); + search_flags_t flags = 0; + + if( s->bw->search_context == NULL || form_changed(win) ){ + if( s->bw->search_context != NULL ) { + search_destroy_context(s->bw->search_context); + s->bw->search_context = NULL; + } + apply_form( win, &s->state ); + } else { + /* get search direction manually: */ + if( (obj[SEARCH_CB_FWD].ob_state & CROSSED) != 0 ) + s->state.flags |= SEARCH_FLAG_FORWARDS; + else + s->state.flags &= (~SEARCH_FLAG_FORWARDS); + } + if( search_verify_new(s->bw, &nsatari_search_callbacks, s) ){ + search_step(s->bw->search_context, s->state.flags, ObjcString( obj, SEARCH_TB_SRCH, NULL ) ); + } + +} + +static void __CDECL evnt_cb_click( WINDOW *win, int index, int unused, void *unused2) { + + short newstate; + OBJECT * obj = ObjcTree(OC_FORM, get_search_session(win)->formwind ); + ObjcChange( OC_FORM, win, index, ~SELECTED, TRUE); + newstate = (obj[index].ob_state & CROSSED) ? ~CROSSED : CROSSED; + ObjcChange( OC_FORM, win, index, newstate , TRUE); +} + +static void __CDECL evnt_close( WINDOW *win, short buff[8]) { + /* Free Search Contexts */ + /* todo: destroy search context, if any */ + destroy_search_session( get_search_session(win) ); + current = NULL; + ApplWrite( _AESapid, WM_DESTROY, win->handle, 0,0,0,0); +} + +SEARCH_FORM_SESSION open_browser_search( struct gui_window * gw ) +{ + char * title; + SEARCH_FORM_SESSION sfs; + OBJECT * tree = get_tree(SEARCH); + if( tree == NULL ){ + return( NULL ); + } + sfs = malloc(sizeof(struct s_search_form_session)); + if( sfs == NULL ) + return( NULL ); + memset(sfs, 0, sizeof(struct s_search_form_session)); + title = (char*)messages_get("FindTextNS"); + if( title == NULL ) + title = (char*)"Find text ..."; + + if( current != NULL ){ + ApplWrite( _AESapid, WM_CLOSED, current->formwind->handle, 0,0,0,0); + /* Handle Close event */ + EvntWindom( MU_MESAG ); + /* Handle Destroy Event */ + EvntWindom( MU_MESAG ); + } + current = sfs; + sfs->bw = gw->browser->bw; + /* todo: check if we already have an form for this gw! */ + sfs->formwind = mt_FormCreate( &app, tree, WAT_FORM, + NULL, title, + NULL, 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(sfs->formwind, &sfs->state ); + strncpy( ObjcString( tree, SEARCH_TB_SRCH, NULL ), "", SEARCH_MAX_SLEN); + + return( current ); + +} \ No newline at end of file diff --git a/atari/search.h b/atari/search.h new file mode 100644 index 000000000..f7e43dcb6 --- /dev/null +++ b/atari/search.h @@ -0,0 +1,23 @@ +#ifndef NS_ATARI_SEARCH_H +#define NS_ATARI_SEARCH_H + +#define SEARCH_MAX_SLEN 24 + +struct s_search_form_state +{ + char text[32]; + uint32_t flags; +}; + +struct s_search_form_session { + struct browser_window * bw; + WINDOW * formwind; + 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); + +#endif \ No newline at end of file diff --git a/atari/slider.c b/atari/slider.c old mode 100644 new mode 100755 diff --git a/atari/slider.h b/atari/slider.h old mode 100644 new mode 100755 diff --git a/atari/statusbar.c b/atari/statusbar.c old mode 100644 new mode 100755 diff --git a/atari/statusbar.h b/atari/statusbar.h old mode 100644 new mode 100755 diff --git a/atari/thumbnail.c b/atari/thumbnail.c old mode 100644 new mode 100755 diff --git a/atari/toolbar.c b/atari/toolbar.c old mode 100644 new mode 100755 index 5231f7da7..ca9100c65 --- a/atari/toolbar.c +++ b/atari/toolbar.c @@ -217,10 +217,10 @@ void __CDECL evnt_url_redraw( COMPONENT *c, long buff[8] ) vsf_perimeter( vdih, 0 ); vsf_interior( vdih , 1 ); vsf_color( vdih, LWHITE ); - vst_arbpt( vdih, 10, &pxy[0], &pxy[1], &pxy[2], &pxy[3] ); + vst_point( vdih, 10, &pxy[0], &pxy[1], &pxy[2], &pxy[3] ); vst_alignment(vdih, 0, 5, &d, &d ); vst_effects( vdih, 0 ); - + vst_color( vdih, BLACK ); /* gray the whole component: */ pxy[0] = work.g_x; @@ -261,7 +261,6 @@ void __CDECL evnt_url_redraw( COMPONENT *c, long buff[8] ) else strcpy( (char*)&textcpy, " " ); - vst_color( vdih, BLACK ); v_gtext( vdih, work.g_x + 3, work.g_y + ((TOOLBAR_HEIGHT - URLBOX_HEIGHT)/2) + 2, (char*)&textcpy ); if( window_url_widget_has_focus( gw ) ) { diff --git a/atari/toolbar.h b/atari/toolbar.h old mode 100644 new mode 100755 diff --git a/atari/treeview.c b/atari/treeview.c old mode 100644 new mode 100755 diff --git a/atari/treeview.h b/atari/treeview.h old mode 100644 new mode 100755 diff --git a/atari/verify_ssl.c b/atari/verify_ssl.c old mode 100644 new mode 100755 diff --git a/atari/verify_ssl.h b/atari/verify_ssl.h old mode 100644 new mode 100755 -- cgit v1.2.3