From 13f22099ce9877a90caf376d626771beea7395c3 Mon Sep 17 00:00:00 2001 From: Ole Loots Date: Thu, 17 Jan 2013 01:18:27 +0100 Subject: [PATCH] Search is functional. --- atari/deskmenu.c | 4 +- atari/gemtk/gemtk.h | 1 + atari/gemtk/guiwin.c | 4 +- atari/gemtk/objc.c | 42 ++++++++++++++++ atari/gui.c | 5 +- atari/rootwin.c | 116 +++++++++++++++++++++++++++++++++++-------- atari/rootwin.h | 7 +-- atari/search.c | 37 ++++++++++++-- atari/search.h | 5 +- atari/toolbar.c | 12 +---- 10 files changed, 188 insertions(+), 45 deletions(-) diff --git a/atari/deskmenu.c b/atari/deskmenu.c index 9c96c69fc..d4621a30f 100644 --- a/atari/deskmenu.c +++ b/atari/deskmenu.c @@ -269,7 +269,7 @@ static void __CDECL menu_find(short item, short title, void *data) static bool visible = false; LOG(("%s", __FUNCTION__)); if( input_window != NULL ){ - window_open_search(input_window->root); + window_open_search(input_window->root, true); } } @@ -460,7 +460,7 @@ static void register_menu_str( struct s_menu_item_evnt * mi ) int i, l=0, x=-1; char str[255]; - get_string(h_gem_menu, mi->rid, &str); + get_string(h_gem_menu, mi->rid, str); i = l = strlen(str); while (i > 2) { diff --git a/atari/gemtk/gemtk.h b/atari/gemtk/gemtk.h index 8361a1488..e31fc8ea1 100644 --- a/atari/gemtk/gemtk.h +++ b/atari/gemtk/gemtk.h @@ -243,6 +243,7 @@ void guiwin_clear(GUIWIN *win); /* -------------------------------------------------------------------------- */ /* AES OBJECT TREE TOOLS */ /* -------------------------------------------------------------------------- */ +char gemtk_obj_set_str_safe(OBJECT * tree, short idx, char *txt); char *get_text(OBJECT * tree, short idx); GRECT * obj_screen_rect(OBJECT * tree, short obj); bool obj_is_inside(OBJECT * tree, short obj, GRECT *area); diff --git a/atari/gemtk/guiwin.c b/atari/gemtk/guiwin.c index 93bc1bfdd..9f756a6be 100644 --- a/atari/gemtk/guiwin.c +++ b/atari/gemtk/guiwin.c @@ -356,7 +356,7 @@ static short preproc_mu_button(GUIWIN * gw, EVMULT_OUT *ev_out, short msg[8]) uint16_t type = (gw->toolbar[obj_idx].ob_type & 0xFF); uint16_t nextobj; - DEBUG_PRINT(("type: %d\n", type)); + DEBUG_PRINT(("toolbar item type: %d\n", type)); // report mouse click to the tree: retval = form_wbutton(gw->toolbar, gw->toolbar_focus_obj, ev_out->emo_mclicks, &nextobj, @@ -383,6 +383,8 @@ static short preproc_mu_button(GUIWIN * gw, EVMULT_OUT *ev_out, short msg[8]) ev_out->emo_events = oldevents; retval = 1; } else { + printf("not within"); + dbg_grect("tb", &tb_area); if (gw->toolbar_edit_obj != -1) { gw->toolbar_edit_obj = -1; } diff --git a/atari/gemtk/objc.c b/atari/gemtk/objc.c index 3bf8ebbe0..3221fdae6 100644 --- a/atari/gemtk/objc.c +++ b/atari/gemtk/objc.c @@ -21,6 +21,7 @@ * */ +#include #include "gemtk.h" char *get_text(OBJECT * tree, short idx) @@ -49,6 +50,47 @@ char *get_text(OBJECT * tree, short idx) return (p); } +static void set_text(OBJECT *obj, 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(obj, idx, spare); +} + +char gemtk_obj_set_str_safe(OBJECT * tree, short idx, char *txt) +{ + char spare[204]; + short type = 0; + short maxlen = 0; + TEDINFO *ted; + + + type = (tree[idx].ob_type & 0xFF); + if (type == G_FTEXT || type == G_FBOXTEXT) { + TEDINFO *ted = ((TEDINFO *)get_obspec(tree, idx)); + maxlen = ted->te_txtlen+1; + if (maxlen > 200) { + maxlen = 200; + } + else if (maxlen < 0) { + maxlen = 0; + } + } else { + assert((type == G_FTEXT) || (type == G_FBOXTEXT)); + } + + snprintf(spare, maxlen, "%s", txt); + set_string(tree, idx, spare); +} + OBJECT *get_tree(int idx) { diff --git a/atari/gui.c b/atari/gui.c index bb12f3f87..fa56823ad 100644 --- a/atari/gui.c +++ b/atari/gui.c @@ -218,11 +218,8 @@ gui_create_browser_window(struct browser_window *bw, }; gui_window_set_url(gw, ""); gui_window_set_pointer(gw, BROWSER_POINTER_DEFAULT); - window_set_active_gui_window(gw->root, gw); - window_open(gw->root, pos ); - /* Recalculate windows browser area now */ gui_set_input_gui_window(gw); - /* TODO:... this line: placeholder to create a local history widget ... */ + window_open(gw->root, gw, pos); } /* add the window to the window list: */ diff --git a/atari/rootwin.c b/atari/rootwin.c index 3ed5264d3..a8aefe223 100755 --- a/atari/rootwin.c +++ b/atari/rootwin.c @@ -109,6 +109,7 @@ static short handle_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8]) switch (msg[0]) { case WM_REDRAW: + LOG(("WM_REDRAW")); on_redraw(data->rootwin, msg); break; @@ -116,6 +117,7 @@ static short handle_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8]) case WM_SIZED: case WM_MOVED: case WM_FULLED: + LOG(("WM_SIZED")); on_resized(data->rootwin); break; @@ -126,10 +128,11 @@ static short handle_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8]) case WM_TOPPED: case WM_NEWTOP: case WM_UNICONIFY: - input_window = data->rootwin->active_gui_window; + LOG(("WM_TOPPED")); + gui_set_input_gui_window(data->rootwin->active_gui_window); + window_restore_active_gui_window(data->rootwin); // TODO: use something like "restore_active_gui_window_state()" - toolbar_set_reflow(data->rootwin->toolbar, true); - printf("top msg\n"); + break; case WM_CLOSED: @@ -312,6 +315,7 @@ void window_unref_gui_window(ROOTWIN *rootwin, struct gui_window *gw) // find the next active tab: while( w != NULL ) { if(w->root == rootwin && w != gw) { + LOG(("activating next tab %p", w)); gui_set_input_gui_window(w); break; } @@ -363,10 +367,12 @@ int window_destroy(ROOTWIN *rootwin) } -void window_open(ROOTWIN *rootwin, GRECT pos) +void window_open(ROOTWIN *rootwin, struct gui_window *gw, GRECT pos) { GRECT br, g; + rootwin->active_gui_window = gw; + assert(rootwin->active_gui_window != NULL); wind_open(rootwin->aes_handle, pos.g_x, pos.g_y, pos.g_w, pos.g_h ); @@ -380,11 +386,40 @@ void window_open(ROOTWIN *rootwin, GRECT pos) toolbar_set_attached(rootwin->toolbar, true); toolbar_set_dimensions(rootwin->toolbar, &g); window_update_back_forward(rootwin); - /*TBD: get already present content and set size? */ - input_window = rootwin->active_gui_window; + window_set_focus(rootwin, BROWSER, rootwin->active_gui_window->browser); } +void window_restore_active_gui_window(ROOTWIN *rootwin) +{ + GRECT tb_area; + struct gui_window *gw; + + LOG(("")); + + assert(rootwin->active_gui_window); + + gw = rootwin->active_gui_window; + + window_set_icon(rootwin, gw->icon); + window_set_stauts(rootwin, gw->status); + window_set_title(rootwin, gw->title); + + if (gw->search != NULL) { + nsatari_search_restore_form(gw->search, get_tree(TOOLBAR)); + window_open_search(rootwin, false); + } else { + toolbar_set_visible(rootwin->toolbar, TOOLBAR_AREA_SEARCH, false); + } + + toolbar_get_grect(rootwin->toolbar, 0, &tb_area); + guiwin_set_toolbar_size(rootwin->win, tb_area.g_h); + + window_update_back_forward(rootwin); + + toolbar_set_url(rootwin->toolbar, gw->url); +} + /* update back forward buttons (see tb_update_buttons (bug) ) */ void window_update_back_forward(struct s_gui_win_root *rootwin) @@ -521,19 +556,24 @@ void window_set_icon(ROOTWIN *rootwin, struct bitmap * bmp ) void window_set_active_gui_window(ROOTWIN *rootwin, struct gui_window *gw) { + struct gui_window *old_gw = rootwin->active_gui_window; + + LOG(("")); + if (rootwin->active_gui_window != NULL) { if(rootwin->active_gui_window == gw) { + LOG(("nothing to do...")); return; } } - rootwin->active_gui_window = gw; - window_set_icon(rootwin, gw->icon); - window_set_stauts(rootwin, gw->status); - window_set_title(rootwin, gw->title); - toolbar_set_url(rootwin->toolbar, gw->url); - // TODO: implement window_restore_browser() - // window_restore_browser(gw->browser); + // TODO: when the window isn't on top, initiate WM_TOPPED. + + rootwin->active_gui_window = gw; + if (old_gw != NULL) { + LOG(("restoring window...")); + window_restore_active_gui_window(rootwin); + } } struct gui_window * window_get_active_gui_window(ROOTWIN * rootwin) { @@ -598,28 +638,64 @@ void window_get_grect(ROOTWIN *rootwin, enum browser_area_e which, GRECT *d) } -void window_open_search(ROOTWIN *rootwin) +void window_open_search(ROOTWIN *rootwin, bool reformat) { struct browser_window *bw; + struct gui_window *gw; GRECT area; + OBJECT *obj; + static bool init = false; - bw = rootwin->active_gui_window->browser->bw; + LOG(("")); + + gw = rootwin->active_gui_window; + bw = gw->browser->bw; + obj = get_tree(TOOLBAR); + + if (init == false) { + obj[TOOLBAR_CB_SHOWALL].ob_state &= ~OS_SELECTED; + obj[TOOLBAR_CB_CASESENSE].ob_state &= ~OS_SELECTED; + gemtk_obj_set_str_safe(obj, TOOLBAR_TB_SRCH, (char*)""); + init = true; + } + + if (gw->search == NULL) { + gw->search = nsatari_search_session_create(obj, bw); + } toolbar_set_visible(rootwin->toolbar, TOOLBAR_AREA_SEARCH, true); + window_get_grect(rootwin, BROWSER_AREA_TOOLBAR, &area); + guiwin_set_toolbar_size(rootwin->win, area.g_h); 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); + if (reformat) { + browser_window_reformat(bw, false, area.g_w, area.g_h); + } } void window_close_search(ROOTWIN *rootwin) { struct browser_window *bw; + struct gui_window *gw; GRECT area; + OBJECT *obj; - bw = rootwin->active_gui_window->browser->bw; + + gw = rootwin->active_gui_window; + bw = gw->browser->bw; + obj = get_tree(TOOLBAR); + + if (gw->search != NULL) { + nsatari_search_session_destroy(gw->search); + gw->search = NULL; + } + + obj[TOOLBAR_BT_CLOSE_SEARCH].ob_state &= ~OS_SELECTED; toolbar_set_visible(rootwin->toolbar, TOOLBAR_AREA_SEARCH, false); + window_get_grect(rootwin, BROWSER_AREA_TOOLBAR, &area); + guiwin_set_toolbar_size(rootwin->win, area.g_h); window_get_grect(rootwin, BROWSER_AREA_CONTENT, &area); browser_window_reformat(bw, false, area.g_w, area.g_h); } @@ -898,11 +974,11 @@ void window_process_redraws(ROOTWIN * rootwin) redraw_active = true; toolbar_get_grect(rootwin->toolbar, 0, &tb_area); - guiwin_set_toolbar_size(rootwin->win, tb_area.g_h); + //guiwin_set_toolbar_size(rootwin->win, tb_area.g_h); window_get_grect(rootwin, BROWSER_AREA_CONTENT, &content_area); //dbg_grect("content area", &content_area); - dbg_grect("window_process_redraws toolbar area", &tb_area); + //dbg_grect("window_process_redraws toolbar area", &tb_area); while(plot_lock() == false); @@ -1033,7 +1109,7 @@ static bool on_content_mouse_click(ROOTWIN *rootwin) struct guiwin_scroll_info_s *slid; gw = window_get_active_gui_window(rootwin); - if( input_window != gw ) { + if(input_window != gw) { gui_set_input_gui_window(gw); } diff --git a/atari/rootwin.h b/atari/rootwin.h index 78f2d1c6c..3be8ecf11 100755 --- a/atari/rootwin.h +++ b/atari/rootwin.h @@ -51,8 +51,8 @@ int window_create(struct gui_window * gw, /* Destroys WinDom part of gui_window */ int window_destroy(ROOTWIN *rootwin); -/* show the window */ -void window_open(ROOTWIN *rootwin, GRECT pos); +/** show the window at specified position and make gw the active tab. */ +void window_open(ROOTWIN *rootwin, struct gui_window *gw, GRECT pos); void window_snd_redraw(ROOTWIN *rootwin, short x, short y, short w, short h ); /* Update Shade / Unshade state of the fwd/back buttons*/ @@ -73,7 +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_restore_active_gui_window(ROOTWIN *rootwin); +void window_open_search(ROOTWIN *rootwin, bool reformat); 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); diff --git a/atari/search.c b/atari/search.c index dac93fc2a..85695481b 100644 --- a/atari/search.c +++ b/atari/search.c @@ -128,6 +128,8 @@ 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)); + + s->state.back_avail = true; // TODO: update gui } @@ -146,12 +148,12 @@ static int apply_form(OBJECT *obj, struct s_search_form_state *s) s->flags |= SEARCH_FLAG_SHOWALL; cstr = get_text(obj, TOOLBAR_TB_SRCH); - snprintf(s->text, 11, "%s", cstr); + snprintf(s->text, 32, "%s", cstr); return ( 0 ); } -static void set_text(OBJECT *obj, short idx, char * text, int len ) +static void set_text(OBJECT *obj, short idx, char * text, int len) { char spare[255]; @@ -165,6 +167,33 @@ static void set_text(OBJECT *obj, short idx, char * text, int len ) set_string(obj, idx, spare); } + +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; + } + else { + 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; + } + else { + 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); + +} void nsatari_search_session_destroy(struct s_search_form_session *s) { @@ -228,7 +257,7 @@ void nsatari_search_perform(struct s_search_form_session *s, OBJECT *obj, 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)); + LOG(("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)); } @@ -243,9 +272,11 @@ struct s_search_form_session * nsatari_search_session_create(OBJECT * obj, sfs = calloc(1, sizeof(struct s_search_form_session)); + assert(obj); assert(sfs); sfs->bw = bw; + apply_form(obj, &sfs->state); browser_window_search_destroy_context(bw); diff --git a/atari/search.h b/atari/search.h index 56ee7a681..00671e4a7 100644 --- a/atari/search.h +++ b/atari/search.h @@ -21,6 +21,7 @@ * */ +#include "desktop/browser.h" #include "desktop/search.h" #ifndef NS_ATARI_SEARCH_H @@ -34,7 +35,8 @@ struct browser_window; struct s_search_form_state { char text[32]; - uint32_t flags; + uint32_t flags; + bool back_avail; }; struct s_search_form_session { @@ -50,5 +52,6 @@ struct s_search_form_session * nsatari_search_session_create(OBJECT * obj, 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); +void nsatari_search_restore_form( struct s_search_form_session *s, OBJECT *obj); #endif diff --git a/atari/toolbar.c b/atari/toolbar.c index d4a9af4b3..349d2c5e6 100644 --- a/atari/toolbar.c +++ b/atari/toolbar.c @@ -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); } } @@ -766,20 +766,10 @@ void toolbar_mouse_input(struct s_toolbar *tb, short obj, short button) 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 {