From 786be41d01b1a2940aae1012dd9db128acee594d Mon Sep 17 00:00:00 2001 From: Ole Loots Date: Tue, 10 Apr 2012 23:12:13 +0000 Subject: Initial support for (truecolor) image toolbar ( toolbar icons loaded from image file, not from resource ). svn path=/trunk/netsurf/; revision=13848 --- atari/options.h | 67 ++++----- atari/toolbar.c | 435 +++++++++++++++++++++++++++++++++++++------------------- atari/toolbar.h | 27 ++-- 3 files changed, 338 insertions(+), 191 deletions(-) (limited to 'atari') diff --git a/atari/options.h b/atari/options.h index 6da17cbd9..640386ed4 100755 --- a/atari/options.h +++ b/atari/options.h @@ -24,54 +24,57 @@ #define NS_ATARI_OPTIONS_H_ -#define NSOPTION_EXTRA_DEFINE \ - char *atari_screen_driver; \ - char *atari_font_driver; \ - int atari_font_monochrom; \ - int atari_dither; \ - int atari_transparency; \ - char *atari_face_sans_serif; /* default sans face */ \ - char *atari_face_sans_serif_bold; /* bold sans face */ \ - char *atari_face_sans_serif_italic; /* bold sans face */ \ +#define NSOPTION_EXTRA_DEFINE \ + char *atari_screen_driver; \ + char *atari_font_driver; \ + int atari_font_monochrom; \ + int atari_dither; \ + int atari_transparency; \ + int atari_image_toolbar; \ + char *atari_face_sans_serif; /* default sans face */ \ + char *atari_face_sans_serif_bold; /* bold sans face */ \ + char *atari_face_sans_serif_italic; /* bold sans face */ \ char *atari_face_sans_serif_italic_bold; /* bold sans face */ \ - char *atari_face_monospace; /* monospace face */ \ - char *atari_face_monospace_bold; /* monospace face */ \ - char *atari_face_serif; /* serif face */ \ - char *atari_face_serif_bold; /* bold serif face */ \ - char *atari_face_cursive; \ - char *atari_face_fantasy; \ - char *atari_editor; \ - char *downloads_path; \ - char *url_file; \ - char *hotlist_file; \ + char *atari_face_monospace; /* monospace face */ \ + char *atari_face_monospace_bold; /* monospace face */ \ + char *atari_face_serif; /* serif face */ \ + char *atari_face_serif_bold; /* bold serif face */ \ + char *atari_face_cursive; \ + char *atari_face_fantasy; \ + char *atari_editor; \ + char *downloads_path; \ + char *url_file; \ + char *hotlist_file; \ char *tree_icons_path #define NSOPTION_EXTRA_DEFAULTS \ - .atari_screen_driver = (char*)"vdi", \ + .atari_screen_driver = (char*)"vdi", \ .atari_font_driver = (char*)"vdi", \ - .atari_font_monochrom = 0, \ - .atari_dither = 1, \ + .atari_font_monochrom = 0, \ + .atari_dither = 1, \ .atari_transparency = 1, \ - .atari_face_sans_serif = NULL, \ - .atari_face_sans_serif_bold = NULL, \ - .atari_face_sans_serif_italic = NULL, \ - .atari_face_sans_serif_italic_bold = NULL, \ - .atari_face_monospace = NULL, \ - .atari_face_monospace_bold = NULL, \ + .atari_image_toolbar = 0, \ + .atari_face_sans_serif = NULL, \ + .atari_face_sans_serif_bold = NULL, \ + .atari_face_sans_serif_italic = NULL, \ + .atari_face_sans_serif_italic_bold = NULL, \ + .atari_face_monospace = NULL, \ + .atari_face_monospace_bold = NULL, \ .atari_face_serif = NULL, \ - .atari_face_serif_bold = NULL, \ + .atari_face_serif_bold = NULL, \ .atari_face_cursive = NULL, \ .atari_face_fantasy = NULL, \ .atari_editor = (char*)"", \ - .downloads_path = (char*)"", \ - .url_file = (char*)"url.db", \ - .hotlist_file = (char*)"hotlist", \ + .downloads_path = (char*)"", \ + .url_file = (char*)"url.db", \ + .hotlist_file = (char*)"hotlist", \ .tree_icons_path = (char*)"./res/icons" #define NSOPTION_EXTRA_TABLE \ { "atari_screen_driver", OPTION_STRING, &nsoptions.atari_screen_driver },\ { "atari_font_driver", OPTION_STRING, &nsoptions.atari_font_driver },\ { "atari_font_monochrom", OPTION_INTEGER, &nsoptions.atari_font_monochrom },\ + { "atari_image_toolbar", OPTION_INTEGER, &nsoptions.atari_image_toolbar },\ { "atari_transparency", OPTION_INTEGER, &nsoptions.atari_transparency },\ { "atari_dither", OPTION_INTEGER, &nsoptions.atari_dither },\ { "atari_editor", OPTION_STRING, &nsoptions.atari_editor },\ diff --git a/atari/toolbar.c b/atari/toolbar.c index 57671ab99..8fc762336 100755 --- a/atari/toolbar.c +++ b/atari/toolbar.c @@ -35,7 +35,8 @@ #include "desktop/browser.h" #include "desktop/mouse.h" #include "desktop/plot_style.h" -#include "desktop/plotters.h" +#include "desktop/plotters.h" +#include "desktop/tree.h" #include "atari/clipboard.h" #include "atari/gui.h" #include "atari/toolbar.h" @@ -54,65 +55,126 @@ extern char * cfg_homepage_url; extern short vdih; extern void * h_gem_rsrc; extern GEM_PLOTTER plotter; -static OBJECT * throbber_form = NULL; +static OBJECT * throbber_form = NULL; +static bool img_toolbar = false; -static const plot_font_style_t font_style_url = { + +static plot_font_style_t font_style_url = { .family = PLOT_FONT_FAMILY_SANS_SERIF, - .size = TOOLBAR_URL_TEXT_SIZE_PT*FONT_SIZE_SCALE, + .size = 14*FONT_SIZE_SCALE, .weight = 400, .flags = FONTF_NONE, .background = 0xffffff, .foreground = 0x0 - }; + }; + +/* prototypes & order for button widgets: */ -/* prototypes & order for button widgets: */ static struct s_tb_button tb_buttons[] = { - { TOOLBAR_BT_BACK, tb_back_click, NULL }, - { TOOLBAR_BT_HOME, tb_home_click, NULL }, - { TOOLBAR_BT_FORWARD, tb_forward_click, NULL }, - { TOOLBAR_BT_RELOAD, tb_reload_click, NULL }, - { TOOLBAR_BT_STOP, tb_stop_click, NULL }, - { 0, NULL, NULL } + { TOOLBAR_BT_BACK, tb_back_click, "back.png", 0, 0, 0, 0, 0 }, + { TOOLBAR_BT_HOME, tb_home_click, "home.png", 0, 0, 0, 0, 0 }, + { TOOLBAR_BT_FORWARD, tb_forward_click, "forward.png", 0, 0, 0, 0, 0 }, + { TOOLBAR_BT_RELOAD, tb_reload_click, "reload.png", 0, 0, 0, 0, 0 }, + { TOOLBAR_BT_STOP, tb_stop_click, "stop.png", 0, 0, 0, 0, 0 }, + { 0, 0, 0, 0, 0, 0, 0, -1 } +}; + +struct s_toolbar_style { + int font_height_pt; + int height; + int button_width; + int button_margin; + short bgcolor; +}; + +static struct s_toolbar_style toolbar_styles[] = +{ + /* small (18 px height) */ + { 9, 18, 16, 0, LWHITE}, + /* medium (default - 26 px height) */ + {14, 26, 24, 1, LWHITE}, + /* large ( 49 px height ) */ + {18, 34, 64, 2, LWHITE} }; -static void tb_txt_request_redraw(void *data, int x, int y, int w, int h); +static void tb_txt_request_redraw(void *data, int x, int y, int w, int h); + +void toolbar_init( void ) +{ + img_toolbar = (nsoption_int( atari_image_toolbar ) > 0 ) ? true : false; +} + +/** + * Callback for load_icon(). Should be removed once bitmaps get loaded directly + * from disc + */ +static nserror toolbar_icon_callback(hlcache_handle *handle, + const hlcache_event *event, void *pw) +{ + if ( event->type != CONTENT_MSG_READY ){ + return( NSERROR_OK ); + } + struct s_tb_button * bt = (struct s_tb_button *)pw; + struct gui_window * gw = (struct gui_window *)bt->gw; + mt_CompEvntRedraw( &app, bt->comp ); + return NSERROR_OK; +} -static void __CDECL button_redraw( COMPONENT *c, long buff[8]) -{ - OBJECT *tree = (OBJECT*)mt_CompDataSearch( &app, c, CDT_OBJECT ); - struct gui_window * gw = mt_CompDataSearch( &app, c, CDT_OWNER ); - LGRECT work,clip; - GRECT todo,crect; - short pxy[4]; - mt_CompGetLGrect(&app, c, WF_WORKXYWH, &work); +static void __CDECL button_redraw( COMPONENT *c, long buff[8], void * data ) +{ + + OBJECT *tree; + LGRECT work,clip; + GRECT todo,crect; + struct s_tb_button *bt = (struct s_tb_button*)data; + struct gui_window * gw = bt->gw; + struct s_toolbar * tb = gw->root->toolbar; + + short pxy[4]; + int bmpx, bmpy, bmpw, bmph; + struct bitmap * icon; + bool draw_bitmap = false; + + mt_CompGetLGrect(&app, c, WF_WORKXYWH, &work); + work.g_h = work.g_h - 1; clip = work; /* return if component and redraw region does not intersect: */ if ( !rc_lintersect( (LGRECT*)&buff[4], &clip ) ) { return; - } - /* clip contains intersecting part: */ - pxy[0] = clip.g_x; - pxy[1] = clip.g_y; - pxy[2] = clip.g_w + clip.g_x; - pxy[3] = clip.g_h + clip.g_y; - - vs_clip( vdih, 1, (short*)&pxy ); - - tree->ob_x = work.g_x+1; - tree->ob_y = work.g_y+2; - tree->ob_width = work.g_w; - tree->ob_height = work.g_h; + } + + if( img_toolbar ){ + if( bt->icon != NULL && bt->iconfile != NULL ){ + draw_bitmap = true; + } + } + + if( draw_bitmap == false ){ + /* Place the CICON into workarea: */ + tree = bt->aes_object; + if( tree == NULL ) + return; + tree->ob_x = work.g_x; + tree->ob_y = work.g_y + (work.g_h - tree->ob_height) / 2; + } else { + icon = content_get_bitmap(bt->icon); + /* Check if icon content is available: */ + /* ( It may isn't loaded yet ) */ + if( icon == NULL ) + return; + bmpw = bitmap_get_width(icon); + bmph = toolbar_styles[tb->style].height - (toolbar_styles[tb->style].button_margin*2); + bmpx = toolbar_styles[tb->style].button_margin; + bmpy = toolbar_styles[tb->style].button_margin; + } + + /* Setup draw mode: */ vsf_interior( vdih , 1 ); - vsf_color( vdih, LWHITE ); - pxy[0] = (short)buff[4]; - pxy[1] = (short)buff[5]; - pxy[2] = (short)buff[4] + buff[6]; - pxy[3] = MIN( (short)buff[5] + buff[7], work.g_y + work.g_h - 2); - vswr_mode( vdih, MD_REPLACE); - v_bar( vdih, (short*)&pxy ); - + vsf_color( vdih, toolbar_styles[tb->style].bgcolor ); + vswr_mode( vdih, MD_REPLACE); + /* go through the rectangle list, using classic AES methods. */ /* Windom ComGetLGrect is buggy for WF_FIRST/NEXTXYWH */ crect.g_x = clip.g_x; @@ -123,46 +185,49 @@ static void __CDECL button_redraw( COMPONENT *c, long buff[8]) &todo.g_x, &todo.g_y, &todo.g_w, &todo.g_h ); while( (todo.g_w > 0) && (todo.g_h > 0) ){ - if( rc_intersect(&crect, &todo) ){ - objc_draw( tree, 0, 0, todo.g_x, todo.g_y, todo.g_w, todo.g_h ); + if( rc_intersect( &crect, &todo ) ){ + pxy[0] = todo.g_x; + pxy[1] = todo.g_y; + pxy[2] = todo.g_w + todo.g_x-1; + pxy[3] = todo.g_h + todo.g_y-1; + vs_clip( vdih, 1, (short*)&pxy ); + v_bar( vdih, (short*)&pxy ); + if( draw_bitmap ){ + plotter->resize( plotter, work.g_w+1, work.g_h+1 ); + plotter->move( plotter, work.g_x, work.g_y ); + atari_plotters.bitmap( bmpx, bmpy, bmpw, bmph, icon, + 0, BITMAPF_BUFFER_NATIVE ); + } else { + objc_draw( tree, 0, 0, todo.g_x, todo.g_y, todo.g_w, todo.g_h ); + } + vs_clip( vdih, 0, (short*)&clip ); } wind_get(gw->root->handle->handle, WF_NEXTXYWH, &todo.g_x, &todo.g_y, &todo.g_w, &todo.g_h ); } - - if( gw->root->toolbar->buttons[0].comp == c && work.g_x == buff[4] ){ - vsl_color( vdih, LWHITE ); - pxy[0] = (short)buff[4]; - pxy[1] = (short)buff[5]; - pxy[2] = (short)buff[4]; - pxy[3] = (short)buff[5] + buff[7]; - v_pline( vdih, 2, (short*) pxy ); - } - vs_clip( vdih, 0, (short*)&clip ); } -static void __CDECL button_enable( COMPONENT *c, long buff[8]) -{ - ((OBJECT*)mt_CompDataSearch(&app, c, CDT_OBJECT))->ob_state &= ~OS_DISABLED; +static void __CDECL button_enable( COMPONENT *c, long buff[8], void * data ) +{ + printf("enb..."); + struct s_tb_button * bt = (struct s_tb_button *)data; + bt->aes_object->ob_state &= ~OS_DISABLED; } -static void __CDECL button_disable( COMPONENT *c, long buff[8]) -{ - ((OBJECT*)mt_CompDataSearch(&app, c, CDT_OBJECT))->ob_state |= OS_DISABLED; +static void __CDECL button_disable( COMPONENT *c, long buff[8], void * data ) +{ + printf("dis..."); + struct s_tb_button * bt = (struct s_tb_button *)data; + bt->aes_object->ob_state |= OS_DISABLED; } -static void __CDECL button_click( COMPONENT *c, long buff[8]) -{ +static void __CDECL button_click( COMPONENT *c, long buff[8], void * data ) +{ + struct s_tb_button * bt = (struct s_tb_button *)data; int i = 0; - struct gui_window * gw = (struct gui_window *)mt_CompDataSearch(&app, c, CDT_OWNER); + struct gui_window * gw = bt->gw; assert( gw ); - while( i < gw->root->toolbar->btcnt ) { - if(c == gw->root->toolbar->buttons[i].comp ) { - gw->root->toolbar->buttons[i].cb_click( gw ); - break; - } - i++; - } + gw->root->toolbar->buttons[i].cb_click( gw ); } static struct s_tb_button * find_button( struct gui_window * gw, int rsc_id ) @@ -177,17 +242,41 @@ static struct s_tb_button * find_button( struct gui_window * gw, int rsc_id ) } -static COMPONENT *button_create( OBJECT *o, short type, long size, short flex ) -{ - COMPONENT *c = mt_CompCreate( &app, type, size, flex ); - OBJECT *oc = mt_ObjcNDup( &app, o, NULL, 1); - oc->ob_next = oc->ob_head = oc->ob_tail = -1; - mt_CompDataAttach( &app, c, CDT_OBJECT, oc ); - mt_CompEvntAttach( &app, c, WM_REDRAW, button_redraw ); - mt_CompEvntAttach( &app, c, WM_XBUTTON, button_click ); - mt_CompEvntAttach( &app, c, CM_GETFOCUS, button_enable ); - mt_CompEvntAttach( &app, c, CM_LOSEFOCUS, button_disable ); - return c; +static COMPONENT *button_init( CMP_TOOLBAR t, OBJECT * tree, int index, + struct s_tb_button * instance ) +{ + instance->index = index; + instance->gw = t->owner; + instance->rsc_id = tb_buttons[index].rsc_id; + instance->cb_click = tb_buttons[index].cb_click; + + instance->comp = mt_CompCreate( &app, CLT_VERTICAL, TB_BUTTON_WIDTH, 0 ); + + assert( instance->comp ); + + if( img_toolbar == false ){ + OBJECT *oc = mt_ObjcNDup( &app, &tree[instance->rsc_id], NULL, 1); + oc->ob_next = oc->ob_head = oc->ob_tail = -1; + instance->aes_object = oc; + } else { + if( (tb_buttons[index].iconfile != NULL) ){ + /* Fixme: use one a single icon instance! */ + instance->iconfile = tb_buttons[index].iconfile; + instance->icon = load_icon( instance->iconfile, + toolbar_icon_callback, instance ); + } + instance->comp->bounds.max_width = TB_BUTTON_WIDTH; + } + + mt_CompEvntDataAttach( &app, instance->comp, WM_REDRAW, button_redraw, + instance ); + mt_CompEvntDataAttach( &app, instance->comp, WM_XBUTTON, button_click, + instance ); + mt_CompEvntDataAttach( &app, instance->comp, CM_GETFOCUS, button_enable, + instance ); + mt_CompEvntDataAttach( &app, instance->comp, CM_LOSEFOCUS, button_disable, + instance ); + return instance->comp; } @@ -346,9 +435,9 @@ void __CDECL evnt_url_click( COMPONENT *c, long buff[8] ) // TODO: do not send an complete redraw! ApplWrite( _AESapid, WM_REDRAW, gw->root->handle->handle, work.g_x, work.g_y, work.g_w, work.g_h ); - } - + + void tb_adjust_size( struct gui_window * gw ) { LGRECT work; @@ -391,7 +480,8 @@ static void tb_txt_request_redraw(void *data, int x, int y, int w, int h) return; CMP_TOOLBAR t = data; if( t->url.redraw == false ){ - t->url.redraw = true; + t->url.redraw = true; + //t->redraw = true; t->url.rdw_area.g_x = x; t->url.rdw_area.g_y = y; t->url.rdw_area.g_w = w; @@ -492,51 +582,57 @@ void tb_url_redraw( struct gui_window * gw ) CMP_TOOLBAR tb_create( struct gui_window * gw ) { int i; - OBJECT * tbut; + OBJECT * tbut = NULL; CMP_TOOLBAR t = malloc( sizeof(struct s_toolbar) ); if( t == NULL ) return( NULL ); - t->owner = gw; + t->owner = gw; + t->style = 1; /* create the root component: */ - t->comp = (COMPONENT*)mt_CompCreate(&app, CLT_HORIZONTAL, TOOLBAR_HEIGHT, 0); - t->comp->rect.g_h = TOOLBAR_HEIGHT; - t->comp->bounds.max_height = TOOLBAR_HEIGHT; - mt_CompEvntDataAdd(&app, t->comp, WM_REDRAW, evnt_toolbar_redraw, NULL, EV_BOT); + t->comp = (COMPONENT*)mt_CompCreate(&app, CLT_HORIZONTAL, + toolbar_styles[t->style].height, 0 ); + t->comp->rect.g_h = toolbar_styles[t->style].height; + t->comp->bounds.max_height = toolbar_styles[t->style].height; + mt_CompEvntDataAdd(&app, t->comp, WM_REDRAW, evnt_toolbar_redraw, + NULL, EV_BOT); + + if( img_toolbar == false ){ + RsrcGaddr( h_gem_rsrc, R_TREE, TOOLBAR, &tbut ); + } /* count buttons and add them as components: */ - RsrcGaddr( h_gem_rsrc, R_TREE, TOOLBAR , &tbut ); - t->btdim.g_x = 0; - t->btdim.g_y = 1; - t->btdim.g_w = 0; - t->btdim.g_h = TB_BUTTON_HEIGHT+1; i = 0; while( tb_buttons[i].rsc_id > 0 ) { i++; } t->btcnt = i; - t->buttons = malloc( sizeof(struct s_tb_button) * t->btcnt ); + t->buttons = malloc( t->btcnt * sizeof(struct s_tb_button) ); + memset( t->buttons, 0, t->btcnt * sizeof(struct s_tb_button) ); for( i=0; i < t->btcnt; i++ ) { - t->buttons[i].rsc_id = tb_buttons[i].rsc_id; - t->buttons[i].cb_click = tb_buttons[i].cb_click; - t->buttons[i].comp = button_create( &tbut[t->buttons[i].rsc_id] , CLT_VERTICAL, TB_BUTTON_WIDTH+1, 0); - mt_CompDataAttach( &app, t->buttons[i].comp, CDT_OWNER, gw ); - t->buttons[i].comp->bounds.max_width = TB_BUTTON_WIDTH+1; + button_init( t, tbut, i, &t->buttons[i] ); mt_CompAttach( &app, t->comp, t->buttons[i].comp ); - t->btdim.g_w += TB_BUTTON_WIDTH+1; } - /* create the url widget: */ - t->url.textarea = textarea_create( 300, TOOLBAR_TEXTAREA_HEIGHT, 0, + /* create the url widget: */ + 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, tb_txt_request_redraw, t ); if( t->url.textarea != NULL ){ textarea_set_text(t->url.textarea, "http://"); } - t->url.comp = (COMPONENT*)mt_CompCreate(&app, CLT_HORIZONTAL, TOOLBAR_HEIGHT, 1); + t->url.comp = (COMPONENT*)mt_CompCreate(&app, CLT_HORIZONTAL, + toolbar_styles[t->style].height, 1); mt_CompEvntAttach( &app, t->url.comp, WM_REDRAW, evnt_url_redraw ); mt_CompEvntAttach( &app, t->url.comp, WM_XBUTTON, evnt_url_click ); mt_CompDataAttach( &app, t->url.comp, CDT_OWNER, gw ); @@ -548,10 +644,11 @@ CMP_TOOLBAR tb_create( struct gui_window * gw ) throbber_form->ob_x = 0; throbber_form->ob_y = 0; } - t->throbber.comp = (COMPONENT*)mt_CompCreate(&app, CLT_HORIZONTAL, TOOLBAR_HEIGHT, 0); - t->throbber.comp->rect.g_h = TOOLBAR_HEIGHT; + t->throbber.comp = (COMPONENT*)mt_CompCreate(&app, CLT_HORIZONTAL, + toolbar_styles[t->style].height, 0); + t->throbber.comp->rect.g_h = toolbar_styles[t->style].height; t->throbber.comp->rect.g_w = 32; - t->throbber.comp->bounds.max_height = TOOLBAR_HEIGHT; + t->throbber.comp->bounds.max_height = toolbar_styles[t->style].height; t->throbber.comp->bounds.max_width = 32; t->throbber.index = THROBBER_MIN_INDEX; t->throbber.max_index = THROBBER_MAX_INDEX; @@ -559,16 +656,17 @@ CMP_TOOLBAR tb_create( struct gui_window * gw ) mt_CompEvntAttach( &app, t->throbber.comp, WM_REDRAW, evnt_throbber_redraw ); mt_CompDataAttach( &app, t->throbber.comp, CDT_OWNER, gw ); mt_CompAttach( &app, t->comp, t->throbber.comp ); - return( t ); } void tb_destroy( CMP_TOOLBAR tb ) { - int i=0; - while( i < tb->btcnt ) { - mt_ObjcFree( &app, (OBJECT*)mt_CompDataSearch(&app, tb->buttons[i].comp, CDT_OBJECT) ); + int i=0; + while( i < tb->btcnt ) { + if( tb->buttons[i].aes_object ){ + mt_ObjcFree( &app, tb->buttons[i].aes_object ); + } i++; } free( tb->buttons ); @@ -594,42 +692,81 @@ struct gui_window * tb_gui_window( CMP_TOOLBAR tb ) } -void tb_update_buttons( struct gui_window * gw ) -{ - struct s_tb_button * bt; - return; /* not working correctly, buttons disabled, even if it shouldn't */ - - bt = find_button( gw, TOOLBAR_BT_BACK ); - if( browser_window_back_available(gw->browser->bw) ) { - ((OBJECT*)mt_CompDataSearch(&app, bt->comp, CDT_OBJECT))->ob_state |= OS_DISABLED; - } else { - ((OBJECT*)mt_CompDataSearch(&app, bt->comp, CDT_OBJECT))->ob_state &= ~OS_DISABLED; - } - mt_CompEvntRedraw( &app, bt->comp ); +void tb_update_buttons( struct gui_window * gw, short button ) +{ - bt = find_button( gw, TOOLBAR_BT_FORWARD ); - if( browser_window_forward_available(gw->browser->bw) ) { - ((OBJECT*)mt_CompDataSearch(&app, bt->comp, CDT_OBJECT))->ob_state |= OS_DISABLED; - } else { - ((OBJECT*)mt_CompDataSearch(&app, bt->comp, CDT_OBJECT))->ob_state &= ~OS_DISABLED; +#define FIRST_BUTTON TOOLBAR_BT_BACK + + struct s_tb_button * bt; + bool enable = false; + return; + if( button == TOOLBAR_BT_BACK || button <= 0 ){ + bt = &gw->root->toolbar->buttons[TOOLBAR_BT_BACK-FIRST_BUTTON]; + enable = browser_window_back_available(gw->browser->bw); + if( bt->aes_object ){ + if( enable ) { + bt->aes_object->ob_state |= OS_DISABLED; + } else { + bt->aes_object->ob_state &= ~OS_DISABLED; + } + mt_CompEvntRedraw( &app, bt->comp ); + } else { + // TODOs + } + + } + + if( button == TOOLBAR_BT_HOME || button <= 0 ){ + bt = &gw->root->toolbar->buttons[TOOLBAR_BT_HOME-FIRST_BUTTON]; + mt_CompEvntRedraw( &app, bt->comp ); } - mt_CompEvntRedraw( &app, bt->comp ); - - bt = find_button( gw, TOOLBAR_BT_RELOAD ); - if( browser_window_reload_available(gw->browser->bw) ) { - ((OBJECT*)mt_CompDataSearch(&app, bt->comp, CDT_OBJECT))->ob_state |= OS_DISABLED; - } else { - ((OBJECT*)mt_CompDataSearch(&app, bt->comp, CDT_OBJECT))->ob_state &= ~OS_DISABLED; + + if( button == TOOLBAR_BT_FORWARD || button <= 0 ){ + bt = &gw->root->toolbar->buttons[TOOLBAR_BT_FORWARD-FIRST_BUTTON]; + enable = browser_window_forward_available(gw->browser->bw); + if( bt->aes_object ){ + if( enable ) { + bt->aes_object->ob_state |= OS_DISABLED; + } else { + bt->aes_object->ob_state &= ~OS_DISABLED; + } + mt_CompEvntRedraw( &app, bt->comp ); + } else { + // TODOs + } } - mt_CompEvntRedraw( &app, bt->comp ); - - bt = find_button( gw, TOOLBAR_BT_STOP ); - if( browser_window_stop_available(gw->browser->bw) ) { - ((OBJECT*)mt_CompDataSearch(&app, bt->comp, CDT_OBJECT))->ob_state |= OS_DISABLED; - } else { - ((OBJECT*)mt_CompDataSearch(&app, bt->comp, CDT_OBJECT))->ob_state &= ~OS_DISABLED; + + if( button == TOOLBAR_BT_RELOAD || button <= 0 ){ + bt = &gw->root->toolbar->buttons[TOOLBAR_BT_RELOAD-FIRST_BUTTON]; + enable = browser_window_reload_available(gw->browser->bw); + if( bt->aes_object ){ + if( enable ) { + bt->aes_object->ob_state |= OS_DISABLED; + } else { + bt->aes_object->ob_state &= ~OS_DISABLED; + } + mt_CompEvntRedraw( &app, bt->comp ); + } else { + // TODOs + } } - mt_CompEvntRedraw( &app, bt->comp ); + + if( button == TOOLBAR_BT_STOP || button <= 0 ){ + bt = &gw->root->toolbar->buttons[TOOLBAR_BT_STOP-FIRST_BUTTON]; + enable = browser_window_stop_available(gw->browser->bw); + if( bt->aes_object ){ + if( enable ) { + bt->aes_object->ob_state |= OS_DISABLED; + } else { + bt->aes_object->ob_state &= ~OS_DISABLED; + } + mt_CompEvntRedraw( &app, bt->comp ); + } else { + // TODOs + } + } + +#undef FIRST_BUTON } @@ -724,7 +861,7 @@ void tb_back_click( struct gui_window * gw ) if( history_back_available(bw->history) ) history_back(bw, bw->history); - tb_update_buttons(gw); + tb_update_buttons(gw, TOOLBAR_BT_BACK ); } void tb_reload_click( struct gui_window * gw ) @@ -739,13 +876,13 @@ void tb_forward_click( struct gui_window * gw ) if (history_forward_available(bw->history)) history_forward(bw, bw->history); - tb_update_buttons(gw); + tb_update_buttons(gw, TOOLBAR_BT_FORWARD ); } void tb_home_click( struct gui_window * gw ) { browser_window_go(gw->browser->bw, cfg_homepage_url, 0, true); - tb_update_buttons(gw); + tb_update_buttons(gw, TOOLBAR_BT_HOME ); } @@ -766,8 +903,8 @@ void tb_hide( struct gui_window * gw, short mode ) } else { tb->hidden = false; - tb->comp->rect.g_h = TOOLBAR_HEIGHT; - tb->comp->bounds.max_height = TOOLBAR_HEIGHT; + tb->comp->rect.g_h = toolbar_styles[tb->style].height; + tb->comp->bounds.max_height = toolbar_styles[tb->style].height; } gw->browser->reformat_pending = true; browser_update_rects( gw ); diff --git a/atari/toolbar.h b/atari/toolbar.h index 27bf4396f..32366f5c7 100755 --- a/atari/toolbar.h +++ b/atari/toolbar.h @@ -21,28 +21,30 @@ #include "desktop/textarea.h" #include "desktop/textinput.h" +#include "content/hlcache.h" #include "atari/browser.h" #define TB_BUTTON_WIDTH 32 -#define TB_BUTTON_HEIGHT 21 /* includes 1px 3d effect */ -#define TOOLBAR_HEIGHT 25 #define THROBBER_WIDTH 32 #define THROBBER_MIN_INDEX 1 #define THROBBER_MAX_INDEX 12 #define THROBBER_INACTIVE_INDEX 13 -#define URLBOX_HEIGHT 21 -#define TOOLBAR_URL_TEXT_SIZE_PT 14 -#define TOOLBAR_TEXTAREA_HEIGHT 19 #define TOOLBAR_URL_MARGIN_LEFT 2 #define TOOLBAR_URL_MARGIN_RIGHT 2 #define TOOLBAR_URL_MARGIN_TOP 2 -#define TOOLBAR_URL_MARGIN_BOTTOM 2 +#define TOOLBAR_URL_MARGIN_BOTTOM 2 + struct s_tb_button { short rsc_id; void (*cb_click)(struct gui_window * gw); - COMPONENT * comp; + const char * iconfile; + COMPONENT * comp; + OBJECT * aes_object; + hlcache_handle * icon; + struct gui_window * gw; + short index; }; @@ -72,10 +74,15 @@ struct s_toolbar /* size & location of buttons: */ struct s_tb_button * buttons; bool hidden; - int btcnt; + int btcnt; + int style; + bool redraw; }; -/* interface to the toolbar */ +/* interface to the toolbar */ + +/* Must be called before any other toolbar function is called: */ +void toolbar_init( void ); CMP_TOOLBAR tb_create( struct gui_window * gw ); void tb_destroy( CMP_TOOLBAR tb ); /* recalculate size/position of nested controls within the toolbar: */ @@ -88,7 +95,7 @@ void tb_forward_click( struct gui_window * gw ); void tb_home_click( struct gui_window * gw ); void tb_stop_click( struct gui_window * gw ); /* enable / disable buttons etc. */ -void tb_update_buttons( struct gui_window * gw ); +void tb_update_buttons( struct gui_window * gw, short buttonid ); /* handles clicks on url widget: */ void tb_url_click( struct gui_window * gw, short mx, short my, short mb, short kstat ); /* handle keybd event while url widget has focus:*/ -- cgit v1.2.3