From ea025e60083af859001ea709065efab6600c5bab Mon Sep 17 00:00:00 2001 From: Ole Loots Date: Fri, 30 Nov 2012 03:20:52 +0100 Subject: Toolbar is now finished, started work on browser redraw/scrolling. --- atari/toolbar.c | 327 +++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 298 insertions(+), 29 deletions(-) (limited to 'atari/toolbar.c') diff --git a/atari/toolbar.c b/atari/toolbar.c index e57171cdd..a6cb548f1 100644 --- a/atari/toolbar.c +++ b/atari/toolbar.c @@ -81,7 +81,7 @@ struct s_tb_button void (*cb_click)(struct s_toolbar *tb); hlcache_handle *icon[TOOLBAR_BUTTON_NUM_STATES]; struct s_toolbar *owner; - short state; + enum e_toolbar_button_states state; short index; GRECT area; }; @@ -92,6 +92,7 @@ extern void * h_gem_rsrc; extern struct gui_window * input_window; extern long atari_plot_flags; extern int atari_plot_vdi_handle; +extern EVMULT_OUT aes_event_out; static OBJECT * aes_toolbar = NULL; static OBJECT * throbber_form = NULL; @@ -185,6 +186,21 @@ static void tb_txt_request_redraw(void *data, int x, int y, int w, int h ); static nserror toolbar_icon_callback( hlcache_handle *handle, const hlcache_event *event, void *pw ); +/** +* Find a button for a specific resource ID +*/ +static struct s_tb_button *find_button(struct s_toolbar *tb, int rsc_id) +{ + int i = 0; + while (i < tb->btcnt) { + if (tb->buttons[i].rsc_id == rsc_id) { + return(&tb->buttons[i]); + } + i++; + } + return(NULL); +} + /** * Callback for textarea redraw */ @@ -194,14 +210,16 @@ static void tb_txt_request_redraw(void *data, int x, int y, int w, int h) GRECT area; struct s_toolbar * tb = (struct s_toolbar *)data; + if (tb->attached == false) { + return; + } + toolbar_get_grect(tb, TOOLBAR_URL_AREA, &area); area.g_x += x; area.g_y += y; area.g_w = w; area.g_h = h; - - dbg_grect("toolbar redraw request", &area); - + dbg_grect("tb_txt_request_redraw", &area); window_schedule_redraw_grect(tb->owner, &area); return; } @@ -354,6 +372,7 @@ void toolbar_destroy(struct s_toolbar *tb) static void toolbar_reflow(struct s_toolbar *tb) { + int i; // position toolbar areas: aes_toolbar->ob_x = tb->area.g_x; @@ -382,14 +401,27 @@ static void toolbar_reflow(struct s_toolbar *tb) ((aes_toolbar[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; + } + else if (tb->buttons[i].state == button_on) { + aes_toolbar[tb->buttons[i].rsc_id].ob_state &= ~OS_DISABLED; + } + } tb->reflow = false; + // TODO: iterate through all other toolbars and set reflow = true } void toolbar_redraw(struct s_toolbar *tb, GRECT *clip) { GRECT area; + if (tb->attached == false) { + return; + } + if(tb->reflow == true) toolbar_reflow(tb); @@ -414,9 +446,6 @@ void toolbar_redraw(struct s_toolbar *tb, GRECT *clip) 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); - textarea_set_dimensions(tb->url.textarea, - aes_toolbar[TOOLBAR_URL_AREA].ob_width, - 20); textarea_redraw(tb->url.textarea, 0, 0, &r, &toolbar_rdrw_ctx); } } @@ -426,12 +455,89 @@ void toolbar_update_buttons(struct s_toolbar *tb, struct browser_window *bw, short button) { LOG(("")); + + struct s_tb_button * bt; + bool enable = false; + GRECT area; + + assert(bw != NULL); + + if (button == TOOLBAR_BT_BACK || button <= 0 ) { + bt = find_button(tb, TOOLBAR_BT_BACK); + enable = browser_window_back_available(bw); + if (enable) { + bt->state = button_on; + } else { + bt->state = button_off; + } + } + + if (button == TOOLBAR_BT_HOME || button <= 0 ){ + + } + + if( button == TOOLBAR_BT_FORWARD || button <= 0 ){ + bt = find_button(tb, TOOLBAR_BT_FORWARD); + enable = browser_window_forward_available(bw); + if (enable) { + bt->state = button_on; + } else { + bt->state = button_off; + } + } + + if( button == TOOLBAR_BT_RELOAD || button <= 0 ){ + bt = find_button(tb, TOOLBAR_BT_RELOAD); + enable = browser_window_reload_available(bw); + if (enable) { + bt->state = button_on; + } else { + bt->state = button_off; + } + } + + if (button == TOOLBAR_BT_STOP || button <= 0) { + bt = find_button(tb, TOOLBAR_BT_STOP); + enable = browser_window_stop_available(bw); + if (enable) { + bt->state = button_on; + } else { + bt->state = button_off; + } + } + + if (tb->attached) { + if (button > 0) { + toolbar_get_grect(tb, button, &area); + window_schedule_redraw_grect(tb->owner, &area); + } + else { + toolbar_get_grect(tb, TOOLBAR_NAVIGATION_AREA, &area); + window_schedule_redraw_grect(tb->owner, &area); + } + } } void toolbar_set_dimensions(struct s_toolbar *tb, GRECT *area) { - tb->area = *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); + } + else { + tb->area = *area; + } + /* reflow for next redraw: */ + /* TODO: that's only required because we do not reset others toolbars reflow + state on reflow */ tb->reflow = true; } @@ -441,10 +547,14 @@ void toolbar_set_url(struct s_toolbar *tb, const char * text) LOG(("")); textarea_set_text(tb->url.textarea, text); - GRECT area; - toolbar_get_grect(tb, TOOLBAR_URL_AREA, &area); - - window_schedule_redraw_grect(tb->owner, &area); + if (tb->attached) { + GRECT area; + toolbar_get_grect(tb, TOOLBAR_URL_AREA, &area); + window_schedule_redraw_grect(tb->owner, &area); + struct gui_window * gw = window_get_active_gui_window(tb->owner); + assert(gw != NULL); + toolbar_update_buttons(tb, gw->browser->bw , 0); + } } void toolbar_set_throbber_state(struct s_toolbar *tb, bool active) @@ -463,6 +573,12 @@ void toolbar_set_throbber_state(struct s_toolbar *tb, bool active) window_schedule_redraw_grect(tb->owner, &throbber_area); } +void toolbar_set_attached(struct s_toolbar *tb, bool attached) +{ + tb->attached = attached; + +} + void toolbar_throbber_progress(struct s_toolbar *tb) { GRECT throbber_area; @@ -492,17 +608,145 @@ bool toolbar_text_input(struct s_toolbar *tb, char *text) bool toolbar_key_input(struct s_toolbar *tb, short nkc) { - bool handled = true; - LOG(("")); + assert(tb!=NULL); + GRECT work; + bool ret = false; - return(handled); + struct gui_window *gw = window_get_active_gui_window(tb->owner); + + assert( gw != NULL ); + + long ucs4; + long ik = nkc_to_input_key(nkc, &ucs4); + + if (ik == 0) { + if ((nkc&0xFF) >= 9) { + ret = textarea_keypress(tb->url.textarea, ucs4); + } + } + else if (ik == KEY_CR || ik == KEY_NL) { + char tmp_url[PATH_MAX]; + if ( textarea_get_text( tb->url.textarea, tmp_url, PATH_MAX) > 0 ) { + window_set_focus(tb->owner, BROWSER, gw->browser); + browser_window_go(gw->browser->bw, (const char*)&tmp_url, 0, true); + ret = true; + } + } + else if (ik == KEY_COPY_SELECTION) { + // copy whole text + char * text; + int len; + len = textarea_get_text( tb->url.textarea, NULL, 0 ); + text = malloc( len+1 ); + if (text){ + textarea_get_text( tb->url.textarea, text, len+1 ); + scrap_txt_write( &app, text ); + free( text ); + } + } + else if ( ik == KEY_PASTE) { + char * clip = scrap_txt_read( &app ); + if ( clip != NULL ){ + int clip_length = strlen( clip ); + if ( clip_length > 0 ) { + char *utf8; + utf8_convert_ret res; + /* Clipboard is in local encoding so + * convert to UTF8 */ + res = utf8_from_local_encoding( clip, clip_length, &utf8 ); + if ( res == UTF8_CONVERT_OK ) { + toolbar_set_url(tb, utf8); + free(utf8); + ret = true; + } + free( clip ); + } + } + } + else if (ik == KEY_ESCAPE) { + textarea_keypress( tb->url.textarea, KEY_SELECT_ALL ); + textarea_keypress( tb->url.textarea, KEY_DELETE_LEFT ); + } + else { + ret = textarea_keypress( tb->url.textarea, ik ); + } + + return( ret ); } -void toolbar_mouse_input(struct s_toolbar *tb, short mx, short my) +void toolbar_mouse_input(struct s_toolbar *tb, short obj) { LOG(("")); + GRECT work; + short mx, my, mb, kstat; + int old; + + if (obj==TOOLBAR_URL_AREA){ + + graf_mkstate( &mx, &my, &mb, &kstat ); + toolbar_get_grect(tb, TOOLBAR_URL_AREA, &work); + mx -= work.g_x; + my -= work.g_y; + + /* TODO: reset mouse state of browser window? */ + /* 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 ); + } + /* url widget has focus and mouse button is still pressed... */ + else if (mb & 1) { + + textarea_mouse_action(tb->url.textarea, BROWSER_MOUSE_DRAG_1, + mx, my ); + short prev_x = mx; + short prev_y = my; + do { + if (abs(prev_x-mx) > 5 || abs(prev_y-my) > 5) { + textarea_mouse_action( tb->url.textarea, + BROWSER_MOUSE_HOLDING_1, mx, my ); + prev_x = mx; + prev_y = my; + window_schedule_redraw_grect(tb->owner, &work); + window_process_redraws(tb->owner); + } + graf_mkstate( &mx, &my, &mb, &kstat ); + mx = mx - (work.g_x + TOOLBAR_URL_MARGIN_LEFT); + my = my - (work.g_y + TOOLBAR_URL_MARGIN_TOP); + } while (mb & 1); + + textarea_drag_end( tb->url.textarea, 0, mx, my ); + } + 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 ){ + mstate = BROWSER_MOUSE_MOD_1; + } + if( aes_event_out.emo_mclicks == 2 ){ + textarea_mouse_action( tb->url.textarea, + BROWSER_MOUSE_DOUBLE_CLICK | BROWSER_MOUSE_CLICK_1, mx, + my); + toolbar_get_grect(tb, TOOLBAR_URL_AREA, &work); + window_schedule_redraw_grect(tb->owner, &work); + } else { + textarea_mouse_action(tb->url.textarea, + BROWSER_MOUSE_PRESS_1, mx, my ); + } + } + } else { + struct s_tb_button *bt = find_button(tb, obj); + 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); + } + + } } @@ -540,43 +784,68 @@ struct text_area *toolbar_get_textarea(struct s_toolbar *tb, /* public event handler */ void toolbar_back_click(struct s_toolbar *tb) { - assert(input_window != NULL); - - struct browser_window *bw = input_window->browser->bw; - - if( history_back_available(bw->history) ) + struct browser_window * bw; + struct gui_window * gw; + + gw = window_get_active_gui_window(tb->owner); + assert(gw != NULL); + bw = gw->browser->bw; + assert(bw != NULL); + + if( history_back_available(bw->history) ) history_back(bw, bw->history); } void toolbar_reload_click(struct s_toolbar *tb) { - assert(input_window != NULL); - browser_window_reload(input_window->browser->bw, true); + struct browser_window * bw; + struct gui_window * gw; + + gw = window_get_active_gui_window(tb->owner); + assert(gw != NULL); + bw = gw->browser->bw; + assert(bw != NULL); + + browser_window_reload(bw, true); } void toolbar_forward_click(struct s_toolbar *tb) { - assert(input_window != NULL); - struct browser_window *bw = input_window->browser->bw; + struct browser_window * bw; + struct gui_window * gw; + + gw = window_get_active_gui_window(tb->owner); + assert(gw != NULL); + bw = gw->browser->bw; + assert(bw != NULL); + if (history_forward_available(bw->history)) history_forward(bw, bw->history); } void toolbar_home_click(struct s_toolbar *tb) { - assert(input_window != NULL); struct browser_window * bw; struct gui_window * gw; gw = window_get_active_gui_window(tb->owner); + assert(gw != NULL); bw = gw->browser->bw; + assert(bw != NULL); browser_window_go(bw, option_homepage_url, 0, true); } void toolbar_stop_click(struct s_toolbar *tb) { - assert(input_window != NULL); - browser_window_stop(input_window->browser->bw); + struct browser_window * bw; + 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); } -- cgit v1.2.3