From 577ff3cffc5fb99041c5da2d828b1f25cfb13dc9 Mon Sep 17 00:00:00 2001 From: Ole Loots Date: Tue, 22 Jan 2013 22:28:20 +0100 Subject: The Window toolbar now have independet AES objects, which means no state restore is required before redraw. --- atari/gemtk/gemtk.h | 6 +- atari/gemtk/guiwin.c | 32 ++-- atari/gemtk/objc.c | 410 +++++++++++++++++++++++++++++++++++++++------------ atari/gui.h | 1 + atari/rootwin.c | 54 ++++--- atari/search.c | 40 ++++- atari/toolbar.c | 104 ++++++++----- atari/toolbar.h | 3 +- 8 files changed, 466 insertions(+), 184 deletions(-) diff --git a/atari/gemtk/gemtk.h b/atari/gemtk/gemtk.h index 1fb1426f9..e187aea6c 100644 --- a/atari/gemtk/gemtk.h +++ b/atari/gemtk/gemtk.h @@ -171,8 +171,7 @@ enum guwin_area_e { short gemtk_wm_init(void); -void -gemtk_wm_exit(void); +void gemtk_wm_exit(void); GUIWIN * gemtk_wm_add(short handle, uint32_t flags, gemtk_wm_event_handler_f handler); @@ -210,6 +209,8 @@ void gemtk_wm_set_form(GUIWIN *win, OBJECT *tree, short index); void gemtk_wm_set_toolbar_size(GUIWIN *win, uint16_t s); +void gemtk_wm_set_toolbar_edit_obj(GUIWIN *win, uint16_t obj, short kreturn); + void gemtk_wm_set_toolbar_redraw_func(GUIWIN *win, gemtk_wm_redraw_f func); bool gemtk_wm_update_slider(GUIWIN *win, short mode); @@ -248,4 +249,5 @@ GRECT * gemtk_obj_screen_rect(OBJECT * tree, short obj); bool gemtk_obj_is_inside(OBJECT * tree, short obj, GRECT *area); OBJECT *gemtk_obj_get_tree(int idx); void gemtk_obj_mouse_sprite(OBJECT *tree, int index); +OBJECT *gemtk_obj_tree_copy(OBJECT *tree); #endif // GEMTK_H_INCLUDED diff --git a/atari/gemtk/guiwin.c b/atari/gemtk/guiwin.c index 9dc3868a9..95e9b085c 100644 --- a/atari/gemtk/guiwin.c +++ b/atari/gemtk/guiwin.c @@ -476,17 +476,8 @@ static short preproc_mu_keybd(GUIWIN * gw, EVMULT_OUT *ev_out, short msg[8]) 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); + gemtk_wm_set_toolbar_edit_obj(gw, next_edit_obj, + ev_out->emo_kreturn); } else { if(next_char > 13) r = objc_wedit(gw->toolbar, gw->toolbar_edit_obj, @@ -999,6 +990,25 @@ void gemtk_wm_set_toolbar_size(GUIWIN *win, uint16_t s) win->toolbar_size = s; } +/** Set the current active edit object */ +void gemtk_wm_set_toolbar_edit_obj(GUIWIN *win, uint16_t obj, short kreturn) +{ + short edit_idx; + + if (obj != win->toolbar_edit_obj) { + + if(win->toolbar_edit_obj != -1) { + objc_wedit(win->toolbar, win->toolbar_edit_obj, kreturn, &edit_idx, + EDEND, win->handle); + } + + win->toolbar_edit_obj = obj; + + objc_wedit(win->toolbar, win->toolbar_edit_obj, kreturn, &edit_idx, + EDINIT, win->handle); + } +} + /** Set an custom toolbar redraw function which is called instead of * default drawing routine. * \param win the GUIWIN diff --git a/atari/gemtk/objc.c b/atari/gemtk/objc.c index 25586946e..2a5eaae5b 100644 --- a/atari/gemtk/objc.c +++ b/atari/gemtk/objc.c @@ -1,127 +1,127 @@ -/* - * Copyright 2013 Ole Loots - * - * 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 . - * - * Module Description: - * - * AES Object tree tools. - * +/* + * Copyright 2013 Ole Loots + * + * 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 . + * + * Module Description: + * + * AES Object tree tools. + * */ #include - #include "gemtk.h" +#include "gemtk.h" char *gemtk_obj_get_text(OBJECT * tree, short idx) { - static char p[]=""; - USERBLK *user; - char *retval; - - switch (tree[idx].ob_type & 0x00FF) { - case G_BUTTON: - case G_STRING: - case G_TITLE: - return( tree[idx].ob_spec.free_string); - case G_TEXT: - case G_BOXTEXT: - case G_FTEXT: - case G_FBOXTEXT: - return (tree[idx].ob_spec.tedinfo->te_ptext); - case G_ICON: - case G_CICON: - return (tree[idx].ob_spec.iconblk->ib_ptext); - break; - - default: break; - } - return (p); + static char p[]=""; + USERBLK *user; + char *retval; + + switch (tree[idx].ob_type & 0x00FF) { + case G_BUTTON: + case G_STRING: + case G_TITLE: + return( tree[idx].ob_spec.free_string); + case G_TEXT: + case G_BOXTEXT: + case G_FTEXT: + case G_FBOXTEXT: + return (tree[idx].ob_spec.tedinfo->te_ptext); + case G_ICON: + case G_CICON: + return (tree[idx].ob_spec.iconblk->ib_ptext); + break; + + default: + break; + } + 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); +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); + 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 *gemtk_obj_get_tree(int idx) -{ +{ + + OBJECT *tree; - OBJECT *tree; - - rsrc_gaddr(R_TREE, idx, &tree); - - return tree; + rsrc_gaddr(R_TREE, idx, &tree); + + return tree; } bool gemtk_obj_is_inside(OBJECT * tree, short obj, GRECT *area) { - GRECT obj_screen; - bool ret = false; + GRECT obj_screen; + bool ret = false; - objc_offset(tree, obj, &obj_screen.g_x, &obj_screen.g_y); - obj_screen.g_w = tree[obj].ob_width; - obj_screen.g_h = tree[obj].ob_height; + objc_offset(tree, obj, &obj_screen.g_x, &obj_screen.g_y); + obj_screen.g_w = tree[obj].ob_width; + obj_screen.g_h = tree[obj].ob_height; - ret = RC_WITHIN(&obj_screen, area); + ret = RC_WITHIN(&obj_screen, area); - return(ret); + return(ret); } GRECT * gemtk_obj_screen_rect(OBJECT * tree, short obj) { - static GRECT obj_screen; + static GRECT obj_screen; - get_objframe(tree, obj, &obj_screen); + get_objframe(tree, obj, &obj_screen); - return(&obj_screen); + return(&obj_screen); } @@ -146,3 +146,223 @@ void gemtk_obj_mouse_sprite(OBJECT *tree, int index) } graf_mouse(USER_DEF, &mform); } + + +/* + * gemtk_obj_tree_copy + * + * Copy a complete object-tree including all substructures (optional). + * + * CAUTION: The object-tree *must* have the LASTOB-flag (0x20) set in + * it's physically last member. + * + * BUG: Up to now tree_copy won't copy the color-icon-structure, + * because I'm too lazy ;) Maybe I'll do that one day. If you need it + * urgently, contact me and force me to work... Btw, this doesn't mean + * that G_CICONs won't be copied at all, but the copied tree will + * share the CICONBLKs with the original. + * + * Input: + * tree: Pointer to tree which should be copied + * what: Specifies what substructures should be copied, too (see the + * C_xxx-definitions in tree-copy.h for details) + * + * Output: + * NULL: Tree couldn't be copied (due to lack of memory) + * otherwise: Pointer to copied tree, use free to dealloc it's memory + */ +OBJECT *gemtk_obj_tree_copy(OBJECT *tree) +{ + int16_t i, objects; + size_t to_malloc, size; + OBJECT *new_tree; + char *area; + + /* Calculate the number of bytes we need for the new tree */ + to_malloc = (size_t) 0; + for (i = 0;;) { + + /* Size of the OBJECT-structure itself */ + to_malloc += sizeof(OBJECT); + + switch (tree[i].ob_type & 0xff) { + case G_TEXT: + case G_BOXTEXT: + case G_FTEXT: + case G_FBOXTEXT: + /* Size of a TEDINFO-structure */ + to_malloc += sizeof(TEDINFO); + + /* Sizes of the strings in the TEDINFO-structure */ + to_malloc += (size_t)tree[i].ob_spec.tedinfo->te_txtlen; + to_malloc += (size_t)tree[i].ob_spec.tedinfo->te_txtlen; + to_malloc += (size_t)tree[i].ob_spec.tedinfo->te_tmplen; + break; + + case G_IMAGE: + + /* Size of the BITBLK-structure */ + to_malloc += sizeof(BITBLK); + + /* Size of the image-data in the BITBLK-structure */ + to_malloc += (size_t)((int32_t)tree[i].ob_spec.bitblk->bi_wb * + (int32_t)tree[i].ob_spec.bitblk->bi_hl); + + break; + + case G_USERDEF: + /* Size of the USERBLK-structure */ + to_malloc += sizeof(USERBLK); + break; + + case G_BUTTON: + case G_STRING: + case G_TITLE: + /* Size of the string (with one null character at the end) */ + to_malloc += strlen(tree[i].ob_spec.free_string) + 1L; + break; + + case G_ICON: + /* Size of the ICONBLK-structure */ + to_malloc += sizeof(BITBLK); + + /* Sizes of icon-data, icon-mask and icon-text */ + to_malloc += (size_t)((int32_t)tree[i].ob_spec.iconblk->ib_wicon * + (int32_t)tree[i].ob_spec.iconblk->ib_hicon / + 4L + 1L + + (int32_t)strlen(tree[i].ob_spec.iconblk->ib_ptext)); + + break; + } + + /* If the size is odd, make it even */ + if ((long)to_malloc & 1) + to_malloc++; + + /* Exit if we've reached the last object in the tree */ + if (tree[i].ob_flags & OF_LASTOB) + break; + + i++; + } + + objects = i + 1; + + /* If there's not enough memory left for the new tree, return NULL */ + if ((new_tree = (OBJECT *)calloc(1, to_malloc)) == NULL) { + return(NULL); + } + + /* + * area contains a pointer to the area where we copy the structures to + */ + area = (char *)((int32_t)new_tree+(int32_t)objects*(int32_t)sizeof(OBJECT)); + + for (i = 0; i < objects; i++) { + + /* Copy the contents of the OBJECT-structure */ + new_tree[i] = tree[i]; + + /* This was added to assure true copies of the object type */ + new_tree[i].ob_type = tree[i].ob_type; + + switch (tree[i].ob_type & 0xff) { + case G_TEXT: + case G_BOXTEXT: + case G_FTEXT: + case G_FBOXTEXT: + + /* Copy the contents of the TEDINFO-structure */ + *(TEDINFO *)area = *tree[i].ob_spec.tedinfo; + new_tree[i].ob_spec.tedinfo = (TEDINFO *)area; + area += sizeof(TEDINFO); + + /* Copy the strings in the TEDINFO-structure */ + strncpy(area, tree[i].ob_spec.tedinfo->te_ptext, + tree[i].ob_spec.tedinfo->te_txtlen); + new_tree[i].ob_spec.tedinfo->te_ptext = area; + area += tree[i].ob_spec.tedinfo->te_txtlen; + strncpy(area, tree[i].ob_spec.tedinfo->te_ptmplt, + tree[i].ob_spec.tedinfo->te_tmplen); + new_tree[i].ob_spec.tedinfo->te_ptmplt = area; + area += tree[i].ob_spec.tedinfo->te_tmplen; + strncpy(area, tree[i].ob_spec.tedinfo->te_pvalid, + tree[i].ob_spec.tedinfo->te_txtlen); + new_tree[i].ob_spec.tedinfo->te_pvalid = area; + area += tree[i].ob_spec.tedinfo->te_txtlen; + + break; + + case G_IMAGE: + + /* Copy the contents of the BITBLK-structure */ + *(BITBLK *)area = *tree[i].ob_spec.bitblk; + new_tree[i].ob_spec.bitblk = (BITBLK *)area; + area += sizeof(BITBLK); + + /* Copy the image-data */ + size = (size_t)((int32_t)tree[i].ob_spec.bitblk->bi_wb * + (int32_t)tree[i].ob_spec.bitblk->bi_hl); + memcpy(area, tree[i].ob_spec.bitblk->bi_pdata, size); + new_tree[i].ob_spec.bitblk->bi_pdata = (int16_t *)area; + area += size; + + break; + + case G_USERDEF: + + /* Copy the contents of the USERBLK-structure */ + *(USERBLK *)area = *tree[i].ob_spec.userblk; + new_tree[i].ob_spec.userblk = (USERBLK *)area; + area += sizeof(USERBLK); + + break; + + case G_BUTTON: + case G_STRING: + case G_TITLE: + + /* Copy the string */ + size = strlen(tree[i].ob_spec.free_string) + 1L; + strcpy(area, tree[i].ob_spec.free_string); + new_tree[i].ob_spec.free_string = area; + area += size; + + break; + + case G_ICON: + + /* Copy the contents of the ICONBLK-structure */ + *(ICONBLK *)area = *tree[i].ob_spec.iconblk; + new_tree[i].ob_spec.iconblk = (ICONBLK *)area; + area += sizeof(ICONBLK); + + size = (size_t)((int32_t)tree[i].ob_spec.iconblk->ib_wicon * + (int32_t)tree[i].ob_spec.iconblk->ib_hicon / + 8L); + /* Copy the mask-data */ + memcpy(area, tree[i].ob_spec.iconblk->ib_pmask, size); + new_tree[i].ob_spec.iconblk->ib_pmask = (int16_t *)area; + area += size; + + /* Copy the icon-data */ + memcpy(area, tree[i].ob_spec.iconblk->ib_pdata, size); + new_tree[i].ob_spec.iconblk->ib_pdata = (int16_t *)area; + area += size; + size = strlen(tree[i].ob_spec.iconblk->ib_ptext) + 1L; + + /* Copy the icon-string */ + strcpy(area, tree[i].ob_spec.iconblk->ib_ptext); + new_tree[i].ob_spec.iconblk->ib_ptext = area; + area += size; + + break; + } + + /* Assure that area contains an even address */ + if ((int32_t)area & 1) + area++; + } + + return(new_tree); +} diff --git a/atari/gui.h b/atari/gui.h index c11438493..fef686a57 100755 --- a/atari/gui.h +++ b/atari/gui.h @@ -75,6 +75,7 @@ struct s_gem_cursors { enum focus_element_type { WIDGET_NONE=0, URL_WIDGET, + SEARCH_INPUT, BROWSER }; diff --git a/atari/rootwin.c b/atari/rootwin.c index 44eec330f..a0d773f90 100755 --- a/atari/rootwin.c +++ b/atari/rootwin.c @@ -139,7 +139,7 @@ static short handle_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8]) case WM_UNICONIFY: LOG(("WM_TOPPED")); gui_set_input_gui_window(data->rootwin->active_gui_window); - window_restore_active_gui_window(data->rootwin); + //window_restore_active_gui_window(data->rootwin); // TODO: use something like "restore_active_gui_window_state()" break; @@ -275,7 +275,7 @@ int window_create(struct gui_window * gw, if(tb) { gw->root->toolbar = toolbar_create(gw->root); assert(gw->root->toolbar); - gemtk_wm_set_toolbar(gw->root->win, gemtk_obj_get_tree(TOOLBAR), 0, 0); + gemtk_wm_set_toolbar(gw->root->win, gw->root->toolbar->form, 0, 0); gemtk_wm_set_toolbar_redraw_func(gw->root->win, toolbar_redraw_cb); } else { gw->root->toolbar = NULL; @@ -415,10 +415,7 @@ void window_restore_active_gui_window(ROOTWIN *rootwin) window_set_title(rootwin, gw->title); if (gw->search != NULL) { - nsatari_search_restore_form(gw->search, gemtk_obj_get_tree(TOOLBAR)); - window_open_search(rootwin, false); - } else { - toolbar_set_visible(rootwin->toolbar, TOOLBAR_AREA_SEARCH, false); + // TODO: update search session (especially browser window) } toolbar_get_grect(rootwin->toolbar, 0, &tb_area); @@ -509,21 +506,26 @@ void window_set_focus(struct s_gui_win_root *rootwin, LOG(("Set focus: %p (%d)\n", element, type)); rootwin->focus.type = type; rootwin->focus.element = element; - if( element != NULL ) { - switch( type ) { + switch( type ) { - case URL_WIDGET: + case URL_WIDGET: // TODO: make something like: toolbar_text_select_all(); - ta = toolbar_get_textarea(rootwin->toolbar, - URL_INPUT_TEXT_AREA); - textarea_keypress(ta, KEY_SELECT_ALL); - break; + toolbar_key_input(rootwin->toolbar, (short)(NKF_CTRL | 'A') ); +/* + ta = toolbar_get_textarea(rootwin->toolbar, + URL_INPUT_TEXT_AREA); + textarea_keypress(ta, KEY_SELECT_ALL); + */ + break; - default: - break; + case SEARCH_INPUT: + gemtk_wm_set_toolbar_edit_obj(rootwin->win, TOOLBAR_TB_SRCH, 0); + break; - } - } + default: + break; + + } } } @@ -584,7 +586,8 @@ void window_set_active_gui_window(ROOTWIN *rootwin, struct gui_window *gw) } } -struct gui_window * window_get_active_gui_window(ROOTWIN * rootwin) { +struct gui_window * window_get_active_gui_window(ROOTWIN * rootwin) +{ return(rootwin->active_gui_window); } @@ -652,20 +655,12 @@ void window_open_search(ROOTWIN *rootwin, bool reformat) struct gui_window *gw; GRECT area; OBJECT *obj; - static bool init = false; LOG(("")); gw = rootwin->active_gui_window; bw = gw->browser->bw; - obj = gemtk_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; - } + obj = toolbar_get_form(rootwin->toolbar); if (gw->search == NULL) { gw->search = nsatari_search_session_create(obj, bw); @@ -676,6 +671,9 @@ void window_open_search(ROOTWIN *rootwin, bool reformat) gemtk_wm_set_toolbar_size(rootwin->win, area.g_h); window_get_grect(rootwin, BROWSER_AREA_SEARCH, &area); window_schedule_redraw_grect(rootwin, &area); + window_process_redraws(rootwin); + window_set_focus(rootwin, SEARCH_INPUT, NULL); + window_get_grect(rootwin, BROWSER_AREA_CONTENT, &area); if (reformat) { browser_window_reformat(bw, false, area.g_w, area.g_h); @@ -699,8 +697,6 @@ void window_close_search(ROOTWIN *rootwin) 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); gemtk_wm_set_toolbar_size(rootwin->win, area.g_h); diff --git a/atari/search.c b/atari/search.c index 02462505b..17241d1ae 100644 --- a/atari/search.c +++ b/atari/search.c @@ -39,6 +39,7 @@ #include "atari/gui.h" #include "atari/rootwin.h" #include "atari/misc.h" +#include "atari/toolbar.h" #include "atari/search.h" #include "atari/gemtk/gemtk.h" #include "atari/res/netsurf.rsh" @@ -110,11 +111,24 @@ void nsatari_search_add_recent(const char *string, void *p) */ void nsatari_search_set_forward_state(bool active, void *p) -{ +{ + struct gui_window *gw; + OBJECT *toolbar; + GRECT area; SEARCH_FORM_SESSION s = (SEARCH_FORM_SESSION)p; /* deactivate back cb */ LOG(("%p: set forward state: %d\n", p, active)); - // TODO: update gui + + gw = s->bw->window; + + toolbar = toolbar_get_form(gw->root->toolbar); + if(active) + toolbar[TOOLBAR_BT_SEARCH_FWD].ob_state &= ~OS_DISABLED; + else + toolbar[TOOLBAR_BT_SEARCH_FWD].ob_state |= OS_DISABLED; + window_get_grect(gw->root, BROWSER_AREA_SEARCH, &area); + window_schedule_redraw_grect(gw->root, &area); + } /** @@ -125,12 +139,23 @@ void nsatari_search_set_forward_state(bool active, void *p) void nsatari_search_set_back_state(bool active, void *p) { + struct gui_window *gw; + OBJECT *toolbar; + GRECT area; 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 + s->state.back_avail = active; + gw = s->bw->window; + + toolbar = toolbar_get_form(gw->root->toolbar); + if(active) + toolbar[TOOLBAR_BT_SEARCH_BACK].ob_state &= ~OS_DISABLED; + else + toolbar[TOOLBAR_BT_SEARCH_BACK].ob_state |= OS_DISABLED; + window_get_grect(gw->root, BROWSER_AREA_SEARCH, &area); + window_schedule_redraw_grect(gw->root, &area); } @@ -204,7 +229,7 @@ void nsatari_search_session_destroy(struct s_search_form_session *s) } } -/* checks for search parameters changes */ +/** checks for search parameters changes */ static bool search_session_compare(struct s_search_form_session *s, OBJECT *obj) { bool check; @@ -240,10 +265,11 @@ void nsatari_search_perform(struct s_search_form_session *s, OBJECT *obj, bool fwd; search_flags_t flags = f; - assert(s!=null); + assert(s!=null); + assert(input_window->browser->bw == s->bw); + if(search_session_compare(s, obj)){ - printf("reset search form\n"); browser_window_search_destroy_context(s->bw); apply_form(obj, &s->state); } else { diff --git a/atari/toolbar.c b/atari/toolbar.c index a4a1ed367..c81c969ee 100644 --- a/atari/toolbar.c +++ b/atari/toolbar.c @@ -239,6 +239,12 @@ void toolbar_init( void ) userblk.ub_parm = (long) aes_toolbar[TOOLBAR_AREA_URL].ob_spec.userblk; aes_toolbar[TOOLBAR_AREA_URL].ob_spec.userblk = &userblk; + aes_toolbar[TOOLBAR_CB_SHOWALL].ob_state &= ~OS_SELECTED; + aes_toolbar[TOOLBAR_CB_CASESENSE].ob_state &= ~OS_SELECTED; + + /* init default values: */ + gemtk_obj_set_str_safe(aes_toolbar, TOOLBAR_TB_SRCH, (char*)""); + area_full_height = aes_toolbar->ob_height; area_search_height = aes_toolbar[TOOLBAR_AREA_SEARCH].ob_height; area_navigation_height = aes_toolbar[TOOLBAR_AREA_NAVIGATION].ob_height; @@ -272,7 +278,11 @@ struct s_toolbar *toolbar_create(struct s_gui_win_root *owner) t->style = 1; t->search_visible = false; t->visible = true; - t->reflow = true; + t->reflow = true; + + /* dublicate the form template: */ + t->form = gemtk_obj_tree_copy(aes_toolbar); + /* count buttons and add them as components: */ i = 0; @@ -309,7 +319,10 @@ struct s_toolbar *toolbar_create(struct s_gui_win_root *owner) void toolbar_destroy(struct s_toolbar *tb) { free(tb->buttons); + free(tb->form); + textarea_destroy(tb->url.textarea); + free(tb); } @@ -335,56 +348,56 @@ static void toolbar_reflow(struct s_toolbar *tb) int i; // position toolbar areas: - aes_toolbar->ob_x = tb->area.g_x; - aes_toolbar->ob_y = tb->area.g_y; - aes_toolbar->ob_width = tb->area.g_w; - aes_toolbar->ob_height = toolbar_calculate_height(tb); + tb->form->ob_x = tb->area.g_x; + tb->form->ob_y = tb->area.g_y; + tb->form->ob_width = tb->area.g_w; + tb->form->ob_height = toolbar_calculate_height(tb); // expand the "main" areas to the current width: - aes_toolbar[TOOLBAR_AREA_NAVIGATION].ob_width = tb->area.g_w; - aes_toolbar[TOOLBAR_AREA_SEARCH].ob_width = tb->area.g_w; + tb->form[TOOLBAR_AREA_NAVIGATION].ob_width = tb->area.g_w; + tb->form[TOOLBAR_AREA_SEARCH].ob_width = tb->area.g_w; if (tb->search_visible) { - aes_toolbar[TOOLBAR_AREA_SEARCH].ob_state &= ~OF_HIDETREE; + tb->form[TOOLBAR_AREA_SEARCH].ob_state &= ~OF_HIDETREE; } else { - aes_toolbar[TOOLBAR_AREA_SEARCH].ob_state |= OF_HIDETREE; + tb->form[TOOLBAR_AREA_SEARCH].ob_state |= OF_HIDETREE; } // align the throbber area at right edge: - aes_toolbar[TOOLBAR_THROBBER_AREA].ob_x = tb->area.g_w - - aes_toolbar[TOOLBAR_THROBBER_AREA].ob_width; + tb->form[TOOLBAR_THROBBER_AREA].ob_x = tb->area.g_w + - tb->form[TOOLBAR_THROBBER_AREA].ob_width; // align the search button: - aes_toolbar[TOOLBAR_SEARCH_ALIGN_RIGHT].ob_x = tb->area.g_w - - aes_toolbar[TOOLBAR_SEARCH_ALIGN_RIGHT].ob_width; + tb->form[TOOLBAR_SEARCH_ALIGN_RIGHT].ob_x = tb->area.g_w + - tb->form[TOOLBAR_SEARCH_ALIGN_RIGHT].ob_width; // center the URL area: - aes_toolbar[TOOLBAR_AREA_URL].ob_width = tb->area.g_w - - (aes_toolbar[TOOLBAR_AREA_BUTTONS].ob_width - + aes_toolbar[TOOLBAR_THROBBER_AREA].ob_width + 1); + tb->form[TOOLBAR_AREA_URL].ob_width = tb->area.g_w + - (tb->form[TOOLBAR_AREA_BUTTONS].ob_width + + tb->form[TOOLBAR_THROBBER_AREA].ob_width + 1); // position throbber image: throbber_form[tb->throbber.index].ob_x = tb->area.g_x + - aes_toolbar[TOOLBAR_THROBBER_AREA].ob_x; + tb->form[TOOLBAR_THROBBER_AREA].ob_x; throbber_form[tb->throbber.index].ob_x = tb->area.g_x - + aes_toolbar[TOOLBAR_THROBBER_AREA].ob_x + - ((aes_toolbar[TOOLBAR_THROBBER_AREA].ob_width + + tb->form[TOOLBAR_THROBBER_AREA].ob_x + + ((tb->form[TOOLBAR_THROBBER_AREA].ob_width - throbber_form[tb->throbber.index].ob_width) >> 1); throbber_form[tb->throbber.index].ob_y = tb->area.g_y + - ((aes_toolbar[TOOLBAR_THROBBER_AREA].ob_height + ((tb->form[TOOLBAR_THROBBER_AREA].ob_height - throbber_form[tb->throbber.index].ob_height) >> 1); // set button states: for (i=0; i < tb->btcnt; i++ ) { if (tb->buttons[i].state == button_off) { - aes_toolbar[tb->buttons[i].rsc_id].ob_state |= OS_DISABLED; + tb->form[tb->buttons[i].rsc_id].ob_state |= OS_DISABLED; } else if (tb->buttons[i].state == button_on) { - aes_toolbar[tb->buttons[i].rsc_id].ob_state &= ~OS_DISABLED; + tb->form[tb->buttons[i].rsc_id].ob_state &= ~OS_DISABLED; } } tb->reflow = false; @@ -406,7 +419,7 @@ void toolbar_redraw(struct s_toolbar *tb, GRECT *clip) //dbg_grect("toolbar redraw clip", clip); - objc_draw_grect(aes_toolbar,0,8,clip); + objc_draw_grect(tb->form,0,8,clip); objc_draw_grect(&throbber_form[tb->throbber.index], 0, 1, clip); toolbar_get_grect(tb, TOOLBAR_AREA_URL, &area_ro); @@ -509,8 +522,8 @@ void toolbar_set_width(struct s_toolbar *tb, short w) toolbar_reflow(tb); /* this will request an textarea redraw: */ textarea_set_dimensions(tb->url.textarea, - aes_toolbar[TOOLBAR_AREA_URL].ob_width, - aes_toolbar[TOOLBAR_AREA_URL].ob_height); + tb->form[TOOLBAR_AREA_URL].ob_width, + tb->form[TOOLBAR_AREA_URL].ob_height); tb->reflow = true; } } @@ -538,8 +551,8 @@ void toolbar_set_dimensions(struct s_toolbar *tb, GRECT *area) toolbar_reflow(tb); /* this will request an textarea redraw: */ textarea_set_dimensions(tb->url.textarea, - aes_toolbar[TOOLBAR_AREA_URL].ob_width, - aes_toolbar[TOOLBAR_AREA_URL].ob_height); + tb->form[TOOLBAR_AREA_URL].ob_width, + tb->form[TOOLBAR_AREA_URL].ob_height); } else { tb->area = *area; @@ -728,10 +741,7 @@ void toolbar_mouse_input(struct s_toolbar *tb, short obj, short button) /* select whole text when newly focused, otherwise set caret to end of text */ if (!window_url_widget_has_focus(tb->owner)) { - window_set_focus(tb->owner, URL_WIDGET, (void*)&tb->url ); - } - if (button & 2) { - // TODO: open a context popup + window_set_focus(tb->owner, URL_WIDGET, (void*)&tb->url); } /* url widget has focus and mouse button is still pressed... */ else if (mb & 1) { @@ -756,14 +766,17 @@ void toolbar_mouse_input(struct s_toolbar *tb, short obj, short button) textarea_drag_end( tb->url.textarea, 0, mx, my); } + else if (button & 2) { + // TODO: open a context popup + } else { /* when execution reaches here, mouse input is a click or dclick */ /* TODO: recognize click + shitoolbar_update_buttonsft key */ int mstate = BROWSER_MOUSE_PRESS_1; - if( (kstat & (K_LSHIFT|K_RSHIFT)) != 0 ){ + if ((kstat & (K_LSHIFT|K_RSHIFT)) != 0) { mstate = BROWSER_MOUSE_MOD_1; } - if( aes_event_out.emo_mclicks == 2 ){ + if (aes_event_out.emo_mclicks == 2 ) { textarea_mouse_action( tb->url.textarea, BROWSER_MOUSE_DOUBLE_CLICK | BROWSER_MOUSE_CLICK_1, mx, my); @@ -774,14 +787,22 @@ void toolbar_mouse_input(struct s_toolbar *tb, short obj, short button) BROWSER_MOUSE_PRESS_1, mx, my ); } } + } + else if(obj==TOOLBAR_TB_SRCH) { + window_set_focus(tb->owner, SEARCH_INPUT, NULL); } else if (obj==TOOLBAR_BT_SEARCH_FWD) { gw = tb->owner->active_gui_window; - toolbar_tree = gemtk_obj_get_tree(TOOLBAR); assert(gw->search); - nsatari_search_perform(gw->search, toolbar_tree, SEARCH_FLAG_FORWARDS); + nsatari_search_perform(gw->search, tb->form, SEARCH_FLAG_FORWARDS); + } + else if (obj==TOOLBAR_BT_SEARCH_BACK) { + gw = tb->owner->active_gui_window; + assert(gw->search); + nsatari_search_perform(gw->search, tb->form, 0); } else if (obj==TOOLBAR_BT_CLOSE_SEARCH) { + tb->form[TOOLBAR_BT_CLOSE_SEARCH].ob_state &= ~OS_SELECTED; window_close_search(tb->owner); } else { @@ -813,11 +834,11 @@ void toolbar_get_grect(struct s_toolbar *tb, short which, GRECT *dst) toolbar_reflow(tb); } - objc_offset(aes_toolbar, which, &dst->g_x, &dst->g_y); + objc_offset(tb->form, which, &dst->g_x, &dst->g_y); - dst->g_w = aes_toolbar[which].ob_width; - dst->g_h = aes_toolbar[which].ob_height; - //aes_toolbar[which].ob_height; + dst->g_w = tb->form[which].ob_width; + dst->g_h = tb->form[which].ob_height; + //tb->form[which].ob_height; //printf("Toolbar get grect (%d): ", which); //dbg_grect("", dst); @@ -832,6 +853,11 @@ struct textarea *toolbar_get_textarea(struct s_toolbar *tb, return(tb->url.textarea); } +OBJECT *toolbar_get_form(struct s_toolbar *tb) +{ + return(tb->form); +} + /* public event handler */ void toolbar_back_click(struct s_toolbar *tb) diff --git a/atari/toolbar.h b/atari/toolbar.h index 24ea9e26a..3116aa9d6 100644 --- a/atari/toolbar.h +++ b/atari/toolbar.h @@ -31,13 +31,13 @@ struct s_toolbar struct s_gui_win_root *owner; struct s_url_widget url; struct s_throbber_widget throbber; + OBJECT *form; GRECT area; /* size & location of buttons: */ struct s_tb_button * buttons; int btcnt; int style; bool attached; - bool redraw; bool reflow; bool visible; bool search_visible; @@ -54,6 +54,7 @@ void toolbar_mouse_input(struct s_toolbar *tb, short obj, short mbut); void toolbar_update_buttons(struct s_toolbar *tb, struct browser_window *bw, short idx); void toolbar_get_grect(struct s_toolbar *tb, short which, GRECT *g); +OBJECT *toolbar_get_form(struct s_toolbar *tb); struct textarea *toolbar_get_textarea(struct s_toolbar *tb, enum toolbar_textarea which); void toolbar_set_throbber_state(struct s_toolbar *tb, bool active); -- cgit v1.2.3