From a0227890e917681daa771a3b2f8499305fd0136e Mon Sep 17 00:00:00 2001 From: Ole Loots Date: Mon, 14 Jan 2013 01:01:22 +0100 Subject: Further work on search in browser window. --- atari/deskmenu.c | 10 ++- atari/gemtk/gemtk.h | 3 + atari/gemtk/guiwin.c | 27 ++++++- atari/gui.h | 2 + atari/res/netsurf.rsc | Bin 34858 -> 35238 bytes atari/res/netsurf.rsh | 30 +++++--- atari/res/netsurf.rsm | 38 +++++---- atari/rootwin.c | 124 +++++++++++++++-------------- atari/search.c | 6 +- atari/toolbar.c | 210 ++++++++++++++++++++++++++++++++------------------ atari/toolbar.h | 17 ++-- 11 files changed, 291 insertions(+), 176 deletions(-) (limited to 'atari') diff --git a/atari/deskmenu.c b/atari/deskmenu.c index c01c50312..0a48631e3 100644 --- a/atari/deskmenu.c +++ b/atari/deskmenu.c @@ -345,10 +345,14 @@ static void __CDECL menu_paste(short item, short title, void *data) } static void __CDECL menu_find(short item, short title, void *data) -{ +{ + static bool visible = false; LOG(("%s", __FUNCTION__)); - if( input_window != NULL ) - open_browser_search( input_window ); + if( input_window != NULL ){ + visible = !visible; + toolbar_set_visible(input_window->root->toolbar, TOOLBAR_AREA_SEARCH, + visible); + } } static void __CDECL menu_choices(short item, short title, void *data) diff --git a/atari/gemtk/gemtk.h b/atari/gemtk/gemtk.h index e5d7c76a4..755a1d7d2 100644 --- a/atari/gemtk/gemtk.h +++ b/atari/gemtk/gemtk.h @@ -223,6 +223,9 @@ guiwin_set_content_units(GUIWIN * win, short x, short y); void guiwin_set_form(GUIWIN *win, OBJECT *tree, short index); +void +guiwin_set_toolbar_size(GUIWIN *win, uint16_t w, uint16_t h); + bool guiwin_update_slider(GUIWIN *win, short mode); diff --git a/atari/gemtk/guiwin.c b/atari/gemtk/guiwin.c index 0d5257fae..4569453d3 100644 --- a/atari/gemtk/guiwin.c +++ b/atari/gemtk/guiwin.c @@ -481,7 +481,8 @@ short guiwin_dispatch_event(EVMULT_IN *ev_in, EVMULT_OUT *ev_out, short msg[8]) bool handler_called = false; if( (ev_out->emo_events & MU_MESAG) != 0 ) { - DEBUG_PRINT(("guiwin_handle_event_multi_fast: %d\n", msg[0])); + DEBUG_PRINT(("guiwin_handle_event_multi_fast: %d (%x)\n", msg[0], + msg[0])); switch (msg[0]) { case WM_REDRAW: case WM_CLOSED: @@ -680,6 +681,9 @@ void guiwin_get_grect(GUIWIN *win, enum guwin_area_e mode, GRECT *dest) assert(win != NULL); wind_get_grect(win->handle, WF_WORKXYWH, dest); + + dbg_grect("gw base rect", dest); + if (mode == GUIWIN_AREA_CONTENT) { GRECT tb_area; guiwin_get_grect(win, GUIWIN_AREA_TOOLBAR, &tb_area); @@ -694,10 +698,11 @@ void guiwin_get_grect(GUIWIN *win, enum guwin_area_e mode, GRECT *dest) } else if (mode == GUIWIN_AREA_TOOLBAR) { if (win->toolbar) { if (win->flags & GW_FLAG_HAS_VTOOLBAR) { - dest->g_w = win->toolbar[win->toolbar_idx].ob_width; + dest->g_w = win->toolbar[win->toolbar_idx].ob_width; } else { dest->g_h = win->toolbar[win->toolbar_idx].ob_height; } + dbg_grect("gw tb rect", dest); } else { dest->g_w = 0; @@ -921,6 +926,22 @@ void guiwin_set_toolbar(GUIWIN *win, OBJECT *toolbar, short idx, uint32_t flags) } } +/** Update width/height of the toolbar region +* \param win the GUIWIN +* \param w The new width of the toolbar area +* \param h The new height of the toolbar area +*/ +void guiwin_set_toolbar_size(GUIWIN *win, uint16_t w, uint16_t h) +{ + bool is_custom = (win->flags & GW_FLAG_CUSTOM_TOOLBAR); + + if (win->toolbar && is_custom == false) { + assert(win->toolbar_idx > -1); + win->toolbar[win->toolbar_idx].ob_width = w; + win->toolbar[win->toolbar_idx].ob_height = h; + } +} + /** * Attach an arbitary pointer to the GUIWIN */ @@ -1104,8 +1125,8 @@ void guiwin_toolbar_redraw(GUIWIN *gw, GRECT *clip) // Update object position: gw->toolbar[gw->toolbar_idx].ob_x = tb_area_ro.g_x; - gw->toolbar[gw->toolbar_idx].ob_width = tb_area_ro.g_w; gw->toolbar[gw->toolbar_idx].ob_y = tb_area_ro.g_y; + gw->toolbar[gw->toolbar_idx].ob_width = tb_area_ro.g_w; gw->toolbar[gw->toolbar_idx].ob_height = tb_area_ro.g_h; wind_get_grect(gw->handle, WF_FIRSTXYWH, &g); diff --git a/atari/gui.h b/atari/gui.h index 209dc5d85..4bbca493b 100755 --- a/atari/gui.h +++ b/atari/gui.h @@ -22,6 +22,7 @@ #include #include +#include "atari/search.h" #include "atari/redrawslots.h" #include "atari/gemtk/gemtk.h" @@ -149,6 +150,7 @@ struct gui_window { char * url; struct bitmap * icon; struct s_caret caret; + struct search_form_session *search; struct gui_window *next, *prev; }; diff --git a/atari/res/netsurf.rsc b/atari/res/netsurf.rsc index d49199d8e..1dbb913a4 100755 Binary files a/atari/res/netsurf.rsc and b/atari/res/netsurf.rsc differ diff --git a/atari/res/netsurf.rsh b/atari/res/netsurf.rsh index 092faa06a..39b98ed3b 100755 --- a/atari/res/netsurf.rsh +++ b/atari/res/netsurf.rsh @@ -41,13 +41,24 @@ #define MAINMENU_M_HELP_CONTENT 61 /* STRING in tree MAINMENU */ #define TOOLBAR 1 /* form/dial */ -#define TOOLBAR_NAVIGATION_AREA 1 /* BOX in tree TOOLBAR */ +#define TOOLBAR_AREA_SEARCH 9 /* BOX in tree TOOLBAR */ +#define TOOLBAR_BT_SEARCH 10 /* BUTTON in tree TOOLBAR */ +#define TOOLBAR_BT_SEARCH_BACK 12 /* BUTTON in tree TOOLBAR */ +#define TOOLBAR_CB_CASESENSE 14 /* BOXCHAR in tree TOOLBAR */ +#define TOOLBAR_CB_SHOWALL 15 /* BOXCHAR in tree TOOLBAR */ +#define TOOLBAR_LBL_SHOWALL 16 /* STRING in tree TOOLBAR */ +#define TOOLBAR_LBL_CASESENSE 17 /* TEXT in tree TOOLBAR */ +#define TOOLBAR_TB_SRCH 18 /* FTEXT in tree TOOLBAR */ +#define TOOLBAR_SEARCH_ALIGN_RIGHT 20 /* IBOX in tree TOOLBAR */ +#define TOOLBAR_CLOSE_SEARCH 11 /* BUTTON in tree TOOLBAR */ +#define TOOLBAR_AREA_NAVIGATION 19 /* BOX in tree TOOLBAR */ +#define TOOLBAR_AREA_BUTTONS 1 /* IBOX in tree TOOLBAR */ #define TOOLBAR_BT_BACK 2 /* CICON in tree TOOLBAR */ #define TOOLBAR_BT_HOME 3 /* CICON in tree TOOLBAR */ #define TOOLBAR_BT_FORWARD 4 /* CICON in tree TOOLBAR */ #define TOOLBAR_BT_STOP 5 /* CICON in tree TOOLBAR */ #define TOOLBAR_BT_RELOAD 6 /* CICON in tree TOOLBAR */ -#define TOOLBAR_URL_AREA 7 /* BOX in tree TOOLBAR */ +#define TOOLBAR_AREA_URL 7 /* BOX in tree TOOLBAR */ #define TOOLBAR_THROBBER_AREA 8 /* BOX in tree TOOLBAR */ #define ICONIFY 2 /* form/dial */ @@ -80,14 +91,13 @@ #define SEARCH 8 /* form/dial */ #define SEARCH_BT_SEARCH 1 /* BUTTON in tree SEARCH */ -#define SEARCH_LBL_FWD 2 /* STRING in tree SEARCH */ -#define SEARCH_CB_FWD 3 /* BUTTON in tree SEARCH */ -#define SEARCH_BT_SEARCH_BACK 4 /* BUTTON in tree SEARCH */ -#define SEARCH_CB_CASESENSE 6 /* BOXCHAR in tree SEARCH */ -#define SEARCH_CB_SHOWALL 7 /* BOXCHAR in tree SEARCH */ -#define SEARCH_LBL_SHOWALL 8 /* STRING in tree SEARCH */ -#define SEARCH_LBL_CASESENSE 9 /* TEXT in tree SEARCH */ -#define SEARCH_TB_SRCH 10 /* FTEXT in tree SEARCH */ +#define SEARCH_CB_FWD 2 /* BUTTON in tree SEARCH */ +#define SEARCH_BT_SEARCH_BACK 3 /* BUTTON in tree SEARCH */ +#define SEARCH_CB_CASESENSE 5 /* BOXCHAR in tree SEARCH */ +#define SEARCH_CB_SHOWALL 6 /* BOXCHAR in tree SEARCH */ +#define SEARCH_LBL_SHOWALL 7 /* STRING in tree SEARCH */ +#define SEARCH_LBL_CASESENSE 8 /* TEXT in tree SEARCH */ +#define SEARCH_TB_SRCH 9 /* FTEXT in tree SEARCH */ #define DOWNLOAD 9 /* form/dial */ /* Width ist 400, code depends on that! If you change it, change it in download.c */ diff --git a/atari/res/netsurf.rsm b/atari/res/netsurf.rsm index 3993f4ae7..3177c9e0a 100755 --- a/atari/res/netsurf.rsm +++ b/atari/res/netsurf.rsm @@ -3,7 +3,7 @@ ResourceMaster v3.65 #N 99@32@AZAaza___ _@AZAaza090___ _@@_@ #FoC-Header@rsm2out@C-Header@rsh@@@[C-Header@0@ #R 0@0@2@1@2@1@ -#M 20010100@0@7728@633@ +#M 20010100@0@7728@635@ #T 0@1@MAINMENU@@62@@ #O 4@32@T_FILE@@ #O 5@32@T_EDIT@@ @@ -43,14 +43,25 @@ ResourceMaster v3.65 #O 58@28@M_CHOICES@@ #O 59@28@M_VLOG@@ #O 61@28@M_HELP_CONTENT@@ -#T 1@2@TOOLBAR@@9@@ -#O 1@20@NAVIGATION_AREA@@ +#T 1@2@TOOLBAR@@21@@ +#O 9@20@AREA_SEARCH@@ +#O 10@26@BT_SEARCH@@ +#O 12@26@BT_SEARCH_BACK@@ +#O 14@27@CB_CASESENSE@@ +#O 15@27@CB_SHOWALL@@ +#O 16@28@LBL_SHOWALL@@ +#O 17@21@LBL_CASESENSE@@ +#O 18@29@TB_SRCH@@ +#O 20@25@SEARCH_ALIGN_RIGHT@@ +#O 11@26@CLOSE_SEARCH@@ +#O 19@20@AREA_NAVIGATION@@ +#O 1@25@AREA_BUTTONS@@ #O 2@33@BT_BACK@@ #O 3@33@BT_HOME@@ #O 4@33@BT_FORWARD@@ #O 5@33@BT_STOP@@ #O 6@33@BT_RELOAD@@ -#O 7@20@URL_AREA@@ +#O 7@20@AREA_URL@@ #O 8@20@THROBBER_AREA@@ #T 2@2@ICONIFY@@3@@ #O 1@33@GLOBE@@ @@ -74,16 +85,15 @@ ResourceMaster v3.65 #O 2@33@CREATE_FOLDER@@ #O 3@33@DELETE@@ #O 4@33@EDIT@@ -#T 8@2@SEARCH@@11@@ +#T 8@2@SEARCH@@10@@ #O 1@26@BT_SEARCH@@ -#O 2@28@LBL_FWD@@ -#O 3@26@CB_FWD@@ -#O 4@26@BT_SEARCH_BACK@@ -#O 6@27@CB_CASESENSE@@ -#O 7@27@CB_SHOWALL@@ -#O 8@28@LBL_SHOWALL@@ -#O 9@21@LBL_CASESENSE@@ -#O 10@29@TB_SRCH@@ +#O 2@26@CB_FWD@@ +#O 3@26@BT_SEARCH_BACK@@ +#O 5@27@CB_CASESENSE@@ +#O 6@27@CB_SHOWALL@@ +#O 7@28@LBL_SHOWALL@@ +#O 8@21@LBL_CASESENSE@@ +#O 9@29@TB_SRCH@@ #T 9@2@DOWNLOAD@@10@@ #O 1@20@PROGRESS@Width ist 400, code depends on that! If you change it, change it in download.c@ #O 2@20@PROGRESS_DONE@@ @@ -198,4 +208,4 @@ ResourceMaster v3.65 #T 15@2@POP_FONT_RENDERER@@3@@ #O 1@28@INTERNAL@@ #O 2@28@FREETYPE@@ -#c 25055@ +#c 32249@ diff --git a/atari/rootwin.c b/atari/rootwin.c index 81a470955..c0859641f 100755 --- a/atari/rootwin.c +++ b/atari/rootwin.c @@ -123,22 +123,25 @@ static short handle_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8]) on_resized(data->rootwin); break; - case WM_ICONIFY: - // TODO: find next active gui window and schedule redraw for that. - break; + case WM_ICONIFY: + // TODO: find next active gui window and schedule redraw for that. + break; case WM_TOPPED: case WM_NEWTOP: case WM_UNICONIFY: input_window = data->rootwin->active_gui_window; + // TODO: use something like "restore_active_gui_window_state()" + toolbar_set_reflow(data->rootwin->toolbar, true); + printf("top msg\n"); break; case WM_CLOSED: // TODO: this needs to iterate through all gui windows and // check if the rootwin is this window... if (data->rootwin->active_gui_window != NULL) { - LOG(("WM_CLOSED initiated destroy for bw %p", - data->rootwin->active_gui_window->browser->bw)); + LOG(("WM_CLOSED initiated destroy for bw %p", + data->rootwin->active_gui_window->browser->bw)); browser_window_destroy( data->rootwin->active_gui_window->browser->bw); } @@ -149,7 +152,7 @@ static short handle_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8]) break; case WM_TOOLBAR: - toolbar_mouse_input(data->rootwin->toolbar, msg[4], msg[7]); + toolbar_mouse_input(data->rootwin->toolbar, msg[4], msg[7]); break; default: @@ -239,7 +242,7 @@ int window_create(struct gui_window * gw, redraw_slots_init(&gw->root->redraw_slots, 8); gw->root->aes_handle = wind_create(flags, 40, 40, desk_area.g_w, - desk_area.g_h); + desk_area.g_h); if(gw->root->aes_handle<0) { free(gw->root->title); free(gw->root); @@ -269,11 +272,11 @@ int window_create(struct gui_window * gw, assert(gw->browser); - gw->browser->bw = bw; - if(clone) - gw->browser->bw->scale = clone->scale; - else - gw->browser->bw->scale = 1; + gw->browser->bw = bw; + if(clone) + gw->browser->bw->scale = clone->scale; + else + gw->browser->bw->scale = 1; /* create statusbar component: */ @@ -548,56 +551,48 @@ void window_get_scroll(ROOTWIN *rootwin, int *x, int *y) void window_get_grect(ROOTWIN *rootwin, enum browser_area_e which, GRECT *d) { - d->g_x = 0; - d->g_y = 0; - d->g_w = 0; - d->g_h = 0; + d->g_x = 0; + d->g_y = 0; + d->g_w = 0; + d->g_h = 0; if (which == BROWSER_AREA_TOOLBAR) { - guiwin_get_grect(rootwin->win, GUIWIN_AREA_TOOLBAR, d); + // guiwin_get_grect(rootwin->win, GUIWIN_AREA_TOOLBAR, d); + toolbar_get_grect(rootwin->toolbar, 0, d); + dbg_grect("toolbar reported size: ", d); } else if (which == BROWSER_AREA_CONTENT) { - GRECT search_area; - - guiwin_get_grect(rootwin->win, GUIWIN_AREA_CONTENT, d); + GRECT tb_area; + guiwin_get_grect(rootwin->win, GUIWIN_AREA_WORK, d); + toolbar_get_grect(rootwin->toolbar, 0, &tb_area); - window_get_grect(rootwin, BROWSER_AREA_SEARCH, &search_area); - - d->g_y += search_area.g_h; - d->g_h -= search_area.g_h; + d->g_y += tb_area.g_h; + d->g_h -= tb_area.g_h; } else if (which == BROWSER_AREA_URL_INPUT) { - toolbar_get_grect(rootwin->toolbar, TOOLBAR_URL_AREA, d); + toolbar_get_grect(rootwin->toolbar, TOOLBAR_AREA_URL, d); } else if (which == BROWSER_AREA_SEARCH) { - // TODO: check if search is open - GRECT work; - OBJECT * tree; - - guiwin_get_grect(rootwin->win, GUIWIN_AREA_WORK, &work); - guiwin_get_grect(rootwin->win, GUIWIN_AREA_TOOLBAR, d); - tree = get_tree(SEARCH); - - d->g_x = work.g_x; - d->g_w = work.g_w; - d->g_y += d->g_h; - d->g_h = tree->ob_height; - } - else { + // todo: check if search is visible + toolbar_get_grect(rootwin->toolbar, TOOLBAR_AREA_SEARCH, d); + } else { } - // sanitize the results + // sanitize the results if (d->g_h < 0) { - d->g_h = 0; + d->g_h = 0; } if (d->g_w < 0) { - d->g_w = 0; + d->g_w = 0; } + printf("window_get_grect %d:", which); + dbg_grect("", d); + } @@ -852,8 +847,8 @@ void window_place_caret(ROOTWIN *rootwin, short mode, int content_x, // draw caret to screen coords: vrt_cpyfm(vh, /*MD_REPLACE*/ MD_XOR, pxy, &caret->symbol, &screen, colors); - // update state: - caret->state |= CARET_STATE_VISIBLE; + // update state: + caret->state |= CARET_STATE_VISIBLE; } exit: @@ -863,22 +858,24 @@ exit: void window_process_redraws(ROOTWIN * rootwin) { - GRECT work, visible_ro, tb_area, search_area, content_area; + GRECT work, visible_ro, tb_area, content_area; short i; - short scroll_x=0, scroll_y=0; + short scroll_x=0, scroll_y=0; bool toolbar_rdrw_required; bool caret_rdrw_required = false; struct guiwin_scroll_info_s *slid =NULL; int caret_h = 0; struct s_caret *caret = &rootwin->caret; + printf("process redraw...\n"); + redraw_active = true; - window_get_grect(rootwin, BROWSER_AREA_TOOLBAR, &tb_area); - window_get_grect(rootwin, BROWSER_AREA_SEARCH, &search_area); - window_get_grect(rootwin, BROWSER_AREA_CONTENT, &content_area); + window_get_grect(rootwin, BROWSER_AREA_TOOLBAR, &tb_area); + window_get_grect(rootwin, BROWSER_AREA_CONTENT, &content_area); //dbg_grect("content area", &content_area); + dbg_grect("window_process_redraws toolbar area", &tb_area); while(plot_lock() == false); @@ -919,11 +916,6 @@ void window_process_redraws(ROOTWIN * rootwin) toolbar_redraw(rootwin->toolbar, &rdrw_area); } - rdrw_area = rdrw_area_ro; - if (rc_intersect(&search_area, &rdrw_area)) { - search_redraw(NULL, &rdrw_area); - } - rdrw_area = rdrw_area_ro; if (rc_intersect(&content_area, &rdrw_area)) { @@ -931,7 +923,7 @@ void window_process_redraws(ROOTWIN * rootwin) slid = guiwin_get_scroll_info(rootwin->win); scroll_x = slid->x_pos * slid->x_unit_px; - scroll_y = slid->y_pos * slid->y_unit_px; + scroll_y = slid->y_pos * slid->y_unit_px; } window_redraw_content(rootwin, &content_area, &rdrw_area, @@ -1226,6 +1218,8 @@ static void on_redraw(ROOTWIN *rootwin, short msg[8]) GRECT clip = {msg[4], msg[5], msg[6], msg[7]}; + dbg_grect("on_redraw", &clip); + if(guiwin_get_state(rootwin->win) & GW_STATUS_ICONIFIED) { GRECT clip = {msg[4], msg[5], msg[6], msg[7]}; window_redraw_favicon(rootwin, &clip); @@ -1236,7 +1230,8 @@ static void on_redraw(ROOTWIN *rootwin, short msg[8]) static void on_resized(ROOTWIN *rootwin) { - GRECT g; + GRECT g, toolbar_area; + OBJECT *toolbar; struct gui_window *gw; gw = window_get_active_gui_window(rootwin); @@ -1264,8 +1259,21 @@ static void on_resized(ROOTWIN *rootwin) // } rootwin->loc = g; - window_get_grect(rootwin, BROWSER_AREA_TOOLBAR, &g); + + guiwin_get_grect(rootwin->win, GUIWIN_AREA_TOOLBAR, &g); + dbg_grect("new toolbar area1", &g); + + /* fetch old, height: */ + toolbar_get_grect(rootwin->toolbar, 0, &toolbar_area); + g.g_h = toolbar_area.g_h; + + /* update origin and width: */ + dbg_grect("new toolbar area2", &g); toolbar_set_dimensions(rootwin->toolbar, &g); + + /* fetch new coords: */ + toolbar_get_grect(rootwin->toolbar, 0, &g); + } static void on_file_dropped(ROOTWIN *rootwin, short msg[8]) @@ -1318,7 +1326,7 @@ static void on_file_dropped(ROOTWIN *rootwin, short msg[8]) mx = mx - content_area.g_x; my = my - content_area.g_y; if( (mx < 0 || mx > content_area.g_w) - || (my < 0 || my > content_area.g_h) ) + || (my < 0 || my > content_area.g_h) ) return; utf8_convert_ret ret; diff --git a/atari/search.c b/atari/search.c index d535d5517..15a3b9a66 100644 --- a/atari/search.c +++ b/atari/search.c @@ -134,7 +134,8 @@ void nsatari_search_set_back_state(bool active, void *p) /* deactivate back cb */ LOG(("%p: set back state: %d\n", p, active)); } - + +/* void search_redraw(void *session, GRECT *clip) { GRECT area, clipped_area; @@ -161,6 +162,7 @@ void search_redraw(void *session, GRECT *clip) objc_draw_grect(tree, 0, 8, &clipped_area); } +*/ static SEARCH_FORM_SESSION get_search_session(GUIWIN * win) { @@ -368,6 +370,6 @@ SEARCH_FORM_SESSION open_browser_search(struct gui_window * gw) apply_form(searchwin, &sfs->state ); set_text(SEARCH_TB_SRCH, "", 31); - return( current ); + return(current); } diff --git a/atari/toolbar.c b/atari/toolbar.c index bdcbae0a5..63dedcbdc 100644 --- a/atari/toolbar.c +++ b/atari/toolbar.c @@ -95,13 +95,10 @@ extern EVMULT_OUT aes_event_out; static OBJECT * aes_toolbar = NULL; static OBJECT * throbber_form = NULL; -static char * toolbar_image_folder = (char *)"default"; -static uint32_t toolbar_bg_color = 0xFFFFFF; -static hlcache_handle * toolbar_image; -static hlcache_handle * throbber_image; -static bool toolbar_image_ready = false; -static bool throbber_image_ready = false; static bool init = false; +static int area_navigation_height = 0; +static int area_search_height = 0; +static int area_full_height = 0; static plot_font_style_t font_style_url = { .family = PLOT_FONT_FAMILY_SANS_SERIF, @@ -151,27 +148,21 @@ static struct s_tb_button tb_buttons[] = { 0, 0, {0,0}, 0, -1, 0, {0,0,0,0}} }; +// TODO: most of this struct can be deleted struct s_toolbar_style { int font_height_pt; - int height; - int icon_width; - int icon_height; - int button_hmargin; - int button_vmargin; - /* RRGGBBAA: */ - uint32_t icon_bgcolor; }; static struct s_toolbar_style toolbar_styles[] = { /* small (18 px height) */ - { 9, 18, 16, 16, 0, 0, 0 }, + {9}, /* medium (default - 26 px height) */ - {14, 26, 24, 24, 1, 4, 0 }, + {14}, /* large ( 49 px height ) */ - {18, 34, 64, 64, 2, 0, 0 }, + {18}, /* custom style: */ - {18, 34, 64, 64, 2, 0, 0 } + {18} }; static const struct redraw_context toolbar_rdrw_ctx = { @@ -212,7 +203,7 @@ static void tb_txt_request_redraw(void *data, int x, int y, int w, int h) return; } - toolbar_get_grect(tb, TOOLBAR_URL_AREA, &area); + toolbar_get_grect(tb, TOOLBAR_AREA_URL, &area); area.g_x += x; area.g_y += y; area.g_w = w; @@ -228,48 +219,49 @@ static struct s_tb_button *button_init(struct s_toolbar *tb, OBJECT * tree, int *instance = tb_buttons[index]; instance->owner = tb; - instance->area.g_w = toolbar_styles[tb->style].icon_width + \ - ( toolbar_styles[tb->style].button_vmargin * 2); - return(instance); } void toolbar_init( void ) { - int i=0, n; - short vdicolor[3]; - uint32_t rgbcolor; - aes_toolbar = get_tree(TOOLBAR); - throbber_form = get_tree(THROBBER); + throbber_form = get_tree(THROBBER); + + 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; + + init = true; } void toolbar_exit(void) { - if (toolbar_image) - hlcache_handle_release(toolbar_image); - if (throbber_image) - hlcache_handle_release(throbber_image); + } struct s_toolbar *toolbar_create(struct s_gui_win_root *owner) { int i; + GRECT url_area; + struct s_toolbar *t; + + LOG(("")); - LOG(("")); + assert(init == true); - struct s_toolbar *t = calloc(sizeof(struct s_toolbar), 1); + t = calloc(sizeof(struct s_toolbar), 1); assert(t); - + + /* initialize the toolbar values: */ t->owner = owner; - t->style = 1; - - /* create the root component: */ - t->area.g_h = toolbar_styles[t->style].height; + t->style = 1; + t->search_visible = false; + t->visible = true; + t->reflow = true; /* count buttons and add them as components: */ i = 0; @@ -287,15 +279,12 @@ struct s_toolbar *toolbar_create(struct s_gui_win_root *owner) font_style_url.size = toolbar_styles[t->style].font_height_pt * FONT_SIZE_SCALE; - int ta_height = toolbar_styles[t->style].height; - ta_height -= (TOOLBAR_URL_MARGIN_TOP + TOOLBAR_URL_MARGIN_BOTTOM); - t->url.textarea = textarea_create(300, ta_height, 0, &font_style_url, + toolbar_get_grect(t, TOOLBAR_AREA_URL, &url_area); + url_area.g_h -= (TOOLBAR_URL_MARGIN_TOP + TOOLBAR_URL_MARGIN_BOTTOM); + t->url.textarea = textarea_create(300, url_area.g_h, 0, &font_style_url, tb_txt_request_redraw, t); /* create the throbber widget: */ - t->throbber.area.g_h = toolbar_styles[t->style].height; - t->throbber.area.g_w = toolbar_styles[t->style].icon_width + \ - (2*toolbar_styles[t->style].button_vmargin ); t->throbber.index = THROBBER_INACTIVE_INDEX; t->throbber.max_index = THROBBER_MAX_INDEX; t->throbber.running = false; @@ -309,10 +298,29 @@ struct s_toolbar *toolbar_create(struct s_gui_win_root *owner) void toolbar_destroy(struct s_toolbar *tb) { free(tb->buttons); - textarea_destroy( tb->url.textarea ); + textarea_destroy(tb->url.textarea); free(tb); } +static int toolbar_calculate_height(struct s_toolbar *tb) +{ + int r = 0; + + if (tb->visible == false) { + printf("toolbar height calc: %d (hidden)\n", 0); + return(0); + } + + r += area_navigation_height; + + if (tb->search_visible) { + r += area_search_height; + } + + printf("toolbar height calc: %d \n", r); + return(r); +} + static void toolbar_reflow(struct s_toolbar *tb) { int i; @@ -321,13 +329,30 @@ static void toolbar_reflow(struct s_toolbar *tb) 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 = tb->area.g_h; + aes_toolbar->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; + + if (tb->search_visible) { + aes_toolbar[TOOLBAR_AREA_SEARCH].ob_state &= ~OF_HIDETREE; + } else { + aes_toolbar[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; - aes_toolbar[TOOLBAR_URL_AREA].ob_width = tb->area.g_w - - (aes_toolbar[TOOLBAR_NAVIGATION_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; + + // 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); @@ -359,7 +384,7 @@ static void toolbar_reflow(struct s_toolbar *tb) void toolbar_redraw(struct s_toolbar *tb, GRECT *clip) { - GRECT area; + GRECT area, area_ro; if (tb->attached == false) { return; @@ -368,27 +393,26 @@ void toolbar_redraw(struct s_toolbar *tb, GRECT *clip) if(tb->reflow == true) toolbar_reflow(tb); + dbg_grect("toolbar redraw clip", clip); objc_draw_grect(aes_toolbar,0,8,clip); - objc_draw_grect(&throbber_form[tb->throbber.index], 0, 1, clip); - GRECT url_area; - toolbar_get_grect(tb, TOOLBAR_URL_AREA, &area); - url_area = area; + toolbar_get_grect(tb, TOOLBAR_AREA_URL, &area_ro); + area = area_ro; + if (rc_intersect(clip, &area)) { struct rect r = { - .x0 = 0, - .y0 = 0, - .x1 = url_area.g_w, - .y1 = url_area.g_h + .x0 = area.g_x - area_ro.g_x, + .y0 = area.g_y - area_ro.g_y, + .x1 = area.g_w, + .y1 = area.g_h }; - r.x0 = area.g_x - url_area.g_x; + r.x0 = area.g_x - area_ro.g_x; r.x1 = r.x0 + area.g_w; - plot_set_dimensions(url_area.g_x, url_area.g_y, url_area.g_w, - url_area.g_h); + plot_set_dimensions(area_ro.g_x, area_ro.g_y, area_ro.g_w, area_ro.g_h); textarea_redraw(tb->url.textarea, 0, 0, &r, &toolbar_rdrw_ctx); } } @@ -455,7 +479,7 @@ void toolbar_update_buttons(struct s_toolbar *tb, struct browser_window *bw, window_schedule_redraw_grect(tb->owner, &area); } else { - toolbar_get_grect(tb, TOOLBAR_NAVIGATION_AREA, &area); + toolbar_get_grect(tb, TOOLBAR_AREA_BUTTONS, &area); window_schedule_redraw_grect(tb->owner, &area); } } @@ -465,22 +489,24 @@ void toolbar_update_buttons(struct s_toolbar *tb, struct browser_window *bw, void toolbar_set_dimensions(struct s_toolbar *tb, GRECT *area) { - + dbg_grect("toolbar_set_dimensions", area); if (area->g_w != tb->area.g_w || area->g_h != tb->area.g_h) { + tb->area = *area; + /* reflow now, just for url input calucation: */ toolbar_reflow(tb); /* this will request an textarea redraw: */ textarea_set_dimensions(tb->url.textarea, - aes_toolbar[TOOLBAR_URL_AREA].ob_width, - 20); + aes_toolbar[TOOLBAR_AREA_URL].ob_width, + aes_toolbar[TOOLBAR_AREA_URL].ob_height); } else { tb->area = *area; } - /* reflow for next redraw: */ - /* TODO: that's only required because we do not reset others toolbars reflow - state on reflow */ + /* reflow for next redraw: */ + /* TODO: that's only required because we do not reset others toolbars reflow + state on reflow */ tb->reflow = true; } @@ -492,7 +518,7 @@ void toolbar_set_url(struct s_toolbar *tb, const char * text) if (tb->attached) { GRECT area; - toolbar_get_grect(tb, TOOLBAR_URL_AREA, &area); + toolbar_get_grect(tb, TOOLBAR_AREA_URL, &area); window_schedule_redraw_grect(tb->owner, &area); struct gui_window * gw = window_get_active_gui_window(tb->owner); assert(gw != NULL); @@ -516,6 +542,28 @@ void toolbar_set_throbber_state(struct s_toolbar *tb, bool active) window_schedule_redraw_grect(tb->owner, &throbber_area); } +void toolbar_set_visible(struct s_toolbar *tb, short area, bool visible) +{ + if (area == 0) { + if ((visible == false) && (tb->visible == true)) { + tb->visible = false; + tb->reflow = true; + } else if((visible == true) && (tb->visible == false)) { + tb->visible = false; + tb->reflow = true; + } + } + else if (area == TOOLBAR_AREA_SEARCH) { + tb->search_visible = visible; + tb->reflow = true; + } +} + +void toolbar_set_reflow(struct s_toolbar *tb, bool do_reflow) +{ + tb->reflow = true; +} + void toolbar_set_attached(struct s_toolbar *tb, bool attached) { tb->attached = attached; @@ -626,10 +674,10 @@ void toolbar_mouse_input(struct s_toolbar *tb, short obj, short button) short mx, my, mb, kstat; int old; - if (obj==TOOLBAR_URL_AREA){ + if (obj==TOOLBAR_AREA_URL){ graf_mkstate( &mx, &my, &mb, &kstat ); - toolbar_get_grect(tb, TOOLBAR_URL_AREA, &work); + toolbar_get_grect(tb, TOOLBAR_AREA_URL, &work); mx -= work.g_x; my -= work.g_y; @@ -676,7 +724,7 @@ void toolbar_mouse_input(struct s_toolbar *tb, short obj, short button) textarea_mouse_action( tb->url.textarea, BROWSER_MOUSE_DOUBLE_CLICK | BROWSER_MOUSE_CLICK_1, mx, my); - toolbar_get_grect(tb, TOOLBAR_URL_AREA, &work); + toolbar_get_grect(tb, TOOLBAR_AREA_URL, &work); window_schedule_redraw_grect(tb->owner, &work); } else { textarea_mouse_action(tb->url.textarea, @@ -688,8 +736,7 @@ void toolbar_mouse_input(struct s_toolbar *tb, short obj, short button) if (bt != NULL && bt->state != button_off) { bt->cb_click(tb); struct gui_window * gw = window_get_active_gui_window(tb->owner); - toolbar_update_buttons(tb, gw->browser->bw, - 0); + toolbar_update_buttons(tb, gw->browser->bw, 0); } } @@ -699,24 +746,30 @@ void toolbar_mouse_input(struct s_toolbar *tb, short obj, short button) /** * Receive a specific region of the toolbar. * @param tb - the toolbar pointer -* @param which - the area to retrieve: TOOLBAR_URL_AREA, -* TOOLBAR_NAVIGATION_AREA, -* TOOLBAR_THROBBER_AREA +* @param which - the area to retrieve: 0 to receive the workarea, + all other values must be + an resource ID of the TOOLBAR tree. * @param dst - GRECT pointer receiving the area. */ void toolbar_get_grect(struct s_toolbar *tb, short which, GRECT *dst) { + #define LAST_TOOLBAR_AREA TOOLBAR_AREA_SEARCH + if (tb->reflow == true) { toolbar_reflow(tb); } objc_offset(aes_toolbar, 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; + + printf("Toolbar get grect (%d): ", which); + dbg_grect("", dst); - //printf("Toolbar get grect (%d): ", which); - //dbg_grect("", dst); + #undef LAST_TOOLBAR_AREA } @@ -788,8 +841,11 @@ void toolbar_stop_click(struct s_toolbar *tb) struct gui_window * gw; gw = window_get_active_gui_window(tb->owner); + assert(gw != NULL); + bw = gw->browser->bw; + assert(bw != NULL); browser_window_stop(bw); diff --git a/atari/toolbar.h b/atari/toolbar.h index 1e552d520..81949796a 100644 --- a/atari/toolbar.h +++ b/atari/toolbar.h @@ -14,11 +14,8 @@ enum toolbar_textarea { }; struct s_url_widget -{ - /* widget is only redrawn when this flag is set */ - bool redraw; +{ struct textarea *textarea; - GRECT rdw_area; GRECT area; }; @@ -26,8 +23,7 @@ struct s_throbber_widget { short index; short max_index; - bool running; - GRECT area; + bool running; }; struct s_toolbar @@ -35,15 +31,16 @@ struct s_toolbar struct s_gui_win_root *owner; struct s_url_widget url; struct s_throbber_widget throbber; - GRECT btdim; GRECT area; /* size & location of buttons: */ struct s_tb_button * buttons; - bool attached; int btcnt; int style; + bool attached; bool redraw; - bool reflow; + bool reflow; + bool visible; + bool search_visible; }; @@ -63,6 +60,8 @@ struct textarea *toolbar_get_textarea(struct s_toolbar *tb, enum toolbar_textarea which); void toolbar_set_throbber_state(struct s_toolbar *tb, bool active); void toolbar_set_attached(struct s_toolbar *tb, bool attached); +void toolbar_set_visible(struct s_toolbar *tb, short area, bool visible); +void toolbar_set_reflow(struct s_toolbar *tb, bool do_reflow); void toolbar_redraw(struct s_toolbar *tb, GRECT *clip); void toolbar_throbber_progress(struct s_toolbar *tb); /* public events handlers: */ -- cgit v1.2.3