summaryrefslogtreecommitdiff
path: root/atari/toolbar.c
diff options
context:
space:
mode:
authorOle Loots <ole@monochrom.net>2011-11-28 23:23:28 +0000
committerOle Loots <ole@monochrom.net>2011-11-28 23:23:28 +0000
commit999410adc818e9bc9e566580b38954720d7dad55 (patch)
tree6abf17a5a94a9835673e2b5b5a6542087f010737 /atari/toolbar.c
parenta7ba1b7ccd1178717e8e4a0546282270ed2fb1d6 (diff)
downloadnetsurf-999410adc818e9bc9e566580b38954720d7dad55.tar.gz
netsurf-999410adc818e9bc9e566580b38954720d7dad55.tar.bz2
I'm actually trying to simplify the frontend code, changes:
- Optimized browser window caret, uses back-buffer now. ( So no content redraw is scheduled by the frontend just for a caret move ) - Fixed a double redraw issue when the browser reformat is pending and the AES also sends an redraw request because of the resize. - Started to use netsurfs textarea instead of a custom implementation ( to reduce code size ). svn path=/trunk/netsurf/; revision=13191
Diffstat (limited to 'atari/toolbar.c')
-rwxr-xr-xatari/toolbar.c594
1 files changed, 249 insertions, 345 deletions
diff --git a/atari/toolbar.c b/atari/toolbar.c
index 9f41bf3d4..a5e747295 100755
--- a/atari/toolbar.c
+++ b/atari/toolbar.c
@@ -33,7 +33,8 @@
#include "desktop/history_core.h"
#include "desktop/netsurf.h"
#include "desktop/browser.h"
-#include "desktop/mouse.h"
+#include "desktop/mouse.h"
+#include "desktop/plot_style.h"
#include "desktop/plotters.h"
#include "atari/clipboard.h"
#include "atari/gui.h"
@@ -43,13 +44,26 @@
#include "atari/clipboard.h"
#include "atari/misc.h"
#include "atari/global_evnt.h"
+#include "atari/plot.h"
#include "cflib.h"
#include "atari/res/netsurf.rsh"
-#include "atari/plot/plotter.h"
-
+#include "atari/plot/plotter.h"
+
+
extern char * cfg_homepage_url;
extern short vdih;
-extern void * h_gem_rsrc;
+extern void * h_gem_rsrc;
+extern GEM_PLOTTER plotter;
+static OBJECT * throbber_form = NULL;
+
+static const plot_font_style_t font_style_url = {
+ .family = PLOT_FONT_FAMILY_SANS_SERIF,
+ .size = TOOLBAR_URL_TEXT_SIZE_PT*FONT_SIZE_SCALE,
+ .weight = 400,
+ .flags = FONTF_NONE,
+ .background = 0xffffff,
+ .foreground = 0x0
+ };
/* prototypes & order for button widgets: */
static struct s_tb_button tb_buttons[] =
@@ -60,10 +74,9 @@ static struct s_tb_button tb_buttons[] =
{ TOOLBAR_BT_RELOAD, tb_reload_click, NULL },
{ TOOLBAR_BT_STOP, tb_stop_click, NULL },
{ 0, NULL, NULL }
-};
-
-static OBJECT * throbber_form = NULL;
-
+};
+
+static void tb_txt_request_redraw(void *data, int x, int y, int w, int h);
static void __CDECL button_redraw( COMPONENT *c, long buff[8])
{
@@ -218,116 +231,67 @@ void __CDECL evnt_throbber_redraw( COMPONENT *c, long buff[8])
static
void __CDECL evnt_url_redraw( COMPONENT *c, long buff[8] )
-{
+{
LGRECT work, clip;
+ struct gui_window * gw;
short pxy[10];
- short i;
- short d;
- short mchars;
- struct gui_window * gw = (struct gui_window *)mt_CompDataSearch(&app, c, CDT_OWNER);
- assert( gw != NULL );
- assert( gw->browser != NULL );
- assert( gw->root != NULL );
- assert( gw->browser->bw != NULL );
- CMP_TOOLBAR tb = gw->root->toolbar;
+ gw = (struct gui_window *)mt_CompDataSearch(&app, c, CDT_OWNER);
+ if( gw == NULL )
+ return;
- mt_CompGetLGrect(&app, c, WF_WORKXYWH, &work);
+ CMP_TOOLBAR tb = gw->root->toolbar;
+ mt_CompGetLGrect(&app, tb->url.comp, WF_WORKXYWH, &work);
+
+ // this last pixel is drawn by the root component of the toolbar:
+ // it's the black border, so we leave it out:
+ work.g_h--;
clip = work;
- if ( !rc_lintersect( (LGRECT*)&buff[4], &clip ) ) return;
-
+ if ( !rc_lintersect( (LGRECT*)&buff[4], &clip ) ) return;
+
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 );
+ pxy[2] = clip.g_w + clip.g_x-1;
+ pxy[3] = clip.g_h + clip.g_y-1;
+ vs_clip( vdih, 1, (short*)&pxy );
- mchars = (work.g_w-6 / tb->url.char_size); /* subtract 6px -> 3px padding around text on each side */
-
- vswr_mode( vdih, MD_REPLACE);
vsf_perimeter( vdih, 0 );
vsf_interior( vdih , 1 );
- vsf_color( vdih, LWHITE );
- vst_point( vdih, 10, &pxy[0], &pxy[1], &pxy[2], &pxy[3] );
- vst_alignment(vdih, 0, 5, &d, &d );
- vst_effects( vdih, 0 );
- vst_color( vdih, BLACK );
- /* gray the whole component: */
-
+ vsf_color( vdih, LWHITE );
+
+ //left margin:
pxy[0] = work.g_x;
pxy[1] = work.g_y;
- pxy[2] = work.g_x + work.g_w;
- pxy[3] = work.g_y + work.g_h-2;
- v_bar( vdih, (short*)&pxy );
-
- /* draw outer line, left top: */
- pxy[0] = work.g_x + 2;
- pxy[1] = work.g_y + ((TOOLBAR_HEIGHT - URLBOX_HEIGHT)/2);
- /* right, top: */
- pxy[2] = work.g_x + work.g_w - 4;
- pxy[3] = work.g_y + ((TOOLBAR_HEIGHT - URLBOX_HEIGHT)/2);
- /* right, bottom: */
- pxy[4] = work.g_x + work.g_w - 4;
- pxy[5] = work.g_y + ((TOOLBAR_HEIGHT - URLBOX_HEIGHT)/2) + URLBOX_HEIGHT;
- /* left, bottom: */
- pxy[6] = work.g_x + 2;
- pxy[7] = work.g_y + ((TOOLBAR_HEIGHT - URLBOX_HEIGHT)/2) + URLBOX_HEIGHT;
- /* left, top again: */
- pxy[8] = work.g_x + 2;
- pxy[9] = work.g_y + ((TOOLBAR_HEIGHT - URLBOX_HEIGHT)/2);
- vsf_interior( vdih, FIS_SOLID );
- vsf_style( vdih, 1);
- vsl_color( vdih, BLACK);
- v_pline( vdih, 5, pxy );
-
- /* draw white txt box: */
- pxy[0] = pxy[0] + 1;
- pxy[1] = pxy[1] + ((TOOLBAR_HEIGHT - URLBOX_HEIGHT)/2) - 1;
- pxy[2] = pxy[2] - 1;
- pxy[3] = work.g_y + ((TOOLBAR_HEIGHT - URLBOX_HEIGHT)/2) + URLBOX_HEIGHT ;
- vsf_color( vdih, WHITE);
- v_bar( vdih, pxy );
- if( gw->root->toolbar->url.used > 1 ) {
- short curx;
- short vqw[4];
- char t[2];
- short cw = 0;
- t[0]=tb->url.text[0];
- t[1]=0;
- if( atari_sysinfo.sfont_monospaced ) {
- vqt_width( vdih, t[0], &vqw[0], &vqw[1], &vqw[2] );
- cw = vqw[0];
- }
- int maxx = (clip.g_x + clip.g_w) - cw;
- for( curx = work.g_x + 3, i=tb->url.scrollx ; curx < maxx && i < tb->url.used-1; i++ ){
- t[0] = tb->url.text[i];
- v_gtext( vdih, curx, work.g_y + ((TOOLBAR_HEIGHT - URLBOX_HEIGHT)/2) + 2, (char*)&t );
- if( !atari_sysinfo.sfont_monospaced ) {
- vqt_width( vdih, t[0], &vqw[0], &vqw[1], &vqw[2] );
- curx += vqw[0];
- } else {
- curx += cw;
- }
- }
- }
-
- if( window_url_widget_has_focus( gw ) ) {
- /* draw caret: */
- pxy[0] = 3 + work.g_x + ((tb->url.caret_pos - tb->url.scrollx) * tb->url.char_size);
- pxy[1] = pxy[1] + 1;
- pxy[2] = 3 + work.g_x + ((tb->url.caret_pos - tb->url.scrollx) * tb->url.char_size);
- pxy[3] = pxy[3] - 1 ;
- v_pline( vdih, 2, pxy );
- /* draw selection: */
- if( tb->url.selection_len != 0 ) {
- vswr_mode( vdih, MD_XOR);
- vsl_color( vdih, BLACK);
- pxy[0] = 3 + work.g_x + ((tb->url.caret_pos - tb->url.scrollx) * tb->url.char_size);
- pxy[2] = pxy[0] + ( gw->root->toolbar->url.selection_len * tb->url.char_size);
- v_bar( vdih, pxy );
- vswr_mode( vdih, MD_REPLACE );
- }
- }
- vs_clip( vdih, 0, (short*)&pxy );
+ pxy[2] = work.g_x + TOOLBAR_URL_MARGIN_LEFT-1;
+ pxy[3] = work.g_y + work.g_h-1;
+ v_bar( vdih, pxy );
+
+ // right margin:
+ pxy[0] = work.g_x+work.g_w-TOOLBAR_URL_MARGIN_RIGHT;
+ pxy[1] = work.g_y;
+ pxy[2] = work.g_x+work.g_w-1;
+ pxy[3] = work.g_y+work.g_h-1;
+ v_bar( vdih, pxy );
+
+ // top margin:
+ pxy[0] = work.g_x;
+ pxy[1] = work.g_y;
+ pxy[2] = work.g_x+work.g_w-1;
+ pxy[3] = work.g_y+TOOLBAR_URL_MARGIN_TOP-1;
+ v_bar( vdih, pxy );
+
+ // bottom margin:
+ pxy[0] = work.g_x;
+ pxy[1] = work.g_y+work.g_h-TOOLBAR_URL_MARGIN_BOTTOM;
+ pxy[2] = work.g_x+work.g_w-1;
+ pxy[3] = work.g_y+work.g_h-1;
+ v_bar( vdih, pxy );
+
+ vs_clip( vdih, 0, (short*)&pxy );
+
+ // TBD: request redraw of textarea for specific region.
+ clip.g_x -= work.g_x+TOOLBAR_URL_MARGIN_LEFT;
+ clip.g_y -= work.g_y+TOOLBAR_URL_MARGIN_TOP;
+ tb_txt_request_redraw( tb, clip.g_x, clip.g_y, clip.g_w, clip.g_h );
}
static
@@ -342,37 +306,45 @@ void __CDECL evnt_url_click( COMPONENT *c, long buff[8] )
assert( gw != NULL );
CMP_TOOLBAR tb = gw->root->toolbar;
mt_CompGetLGrect(&app, c, WF_WORKXYWH, &work);
- mx = evnt.mx - work.g_x;
- my = evnt.my - work.g_y;
+ mx = evnt.mx - (work.g_x + TOOLBAR_URL_MARGIN_LEFT);
+ my = evnt.my - (work.g_y + TOOLBAR_URL_MARGIN_TOP);
/* 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(gw) ) {
- tb_url_place_caret( gw, strlen(tb->url.text), true);
- tb->url.selection_len = -tb->url.caret_pos;
- window_set_focus( gw, URL_WIDGET, (void*)&tb->url );
+ // TODO select all ( needs textarea change )
+ window_set_focus( gw, URL_WIDGET, (void*)&tb->url );
+ textarea_mouse_action( tb->url.textarea, BROWSER_MOUSE_PRESS_1, mx, my );
} else {
if( mb & 1 ) {
- /* if the button is dragging, place selection: */
- old = tb->url.selection_len;
- tb->url.selection_len = (tb->url.scrollx + (mx / tb->url.char_size)) - tb->url.caret_pos;
- if(tb->url.caret_pos + tb->url.selection_len > (int)strlen(tb->url.text) )
- tb->url.selection_len = strlen(tb->url.text) - tb->url.caret_pos;
- if( old == tb->url.selection_len )
- /* avoid redraw when nothing changed */
- return;
+ /* TODO: if the button is dragging, report draw event */
} else {
- /* TODO: recognize click + shift key */
- tb->url.selection_len = 0;
- tb_url_place_caret( gw, tb->url.scrollx + (mx / tb->url.char_size), true);
+ /* TODO: recognize click + shift key */
+ int mstate = BROWSER_MOUSE_PRESS_1;
+ if( (kstat & (K_LSHIFT|K_RSHIFT)) != 0 )
+ mstate = BROWSER_MOUSE_MOD_1;
+ textarea_mouse_action( tb->url.textarea, BROWSER_MOUSE_PRESS_1, mx, my );
}
}
-
+ // 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;
+ CMP_TOOLBAR t = gw->root->toolbar;
+
+ mt_CompGetLGrect( &app, t->url.comp, WF_WORKXYWH, &work);
+ work.g_w -= (TOOLBAR_URL_MARGIN_LEFT + TOOLBAR_URL_MARGIN_RIGHT);
+ /* do not overwrite the black border, because of that, add 1 */
+ work.g_h -= (TOOLBAR_URL_MARGIN_TOP + TOOLBAR_URL_MARGIN_BOTTOM+1);
+ textarea_set_dimensions( t->url.textarea, work.g_w, work.g_h );
+ tb_txt_request_redraw( t, 0,0, work.g_w-1, work.g_h-1);
}
-
+
static void __CDECL evnt_toolbar_redraw( COMPONENT *c, long buff[8], void *data )
{
LGRECT work, clip;
@@ -392,9 +364,112 @@ static void __CDECL evnt_toolbar_redraw( COMPONENT *c, long buff[8], void *data
pxy[1] = pxy[3] = work.g_y + work.g_h-1 ;
pxy[2] = clip.g_x + clip.g_w;
v_pline( vdih, 2, (short*)&pxy );
+}
+
+
+static void tb_txt_request_redraw(void *data, int x, int y, int w, int h)
+{
+ LGRECT work;
+ if( data == NULL )
+ return;
+ CMP_TOOLBAR t = data;
+ if( t->url.redraw == false ){
+ t->url.redraw = true;
+ t->url.rdw_area.g_x = x;
+ t->url.rdw_area.g_y = y;
+ t->url.rdw_area.g_w = w;
+ t->url.rdw_area.g_h = h;
+ } else {
+ /* merge the redraw area to the new area.: */
+ int newx1 = x+w;
+ int newy1 = y+h;
+ int oldx1 = t->url.rdw_area.g_x + t->url.rdw_area.g_w;
+ int oldy1 = t->url.rdw_area.g_y + t->url.rdw_area.g_h;
+ t->url.rdw_area.g_x = MIN(t->url.rdw_area.g_x, x);
+ t->url.rdw_area.g_y = MIN(t->url.rdw_area.g_y, y);
+ t->url.rdw_area.g_w = ( oldx1 > newx1 ) ?
+ oldx1 - t->url.rdw_area.g_x : newx1 - t->url.rdw_area.g_x;
+ t->url.rdw_area.g_h = ( oldy1 > newy1 ) ?
+ oldy1 - t->url.rdw_area.g_y : newy1 - t->url.rdw_area.g_y;
+ }
+}
+
+void tb_url_redraw( struct gui_window * gw )
+{
+ CMP_TOOLBAR t = gw->root->toolbar;
+ if (t != NULL) {
+ if( t->url.redraw && ((plotter->flags & PLOT_FLAG_OFFSCREEN) == 0) ) {
+
+ const struct redraw_context ctx = {
+ .interactive = true,
+ .plot = &atari_plotters
+ };
+ short todo[4];
+ LGRECT work;
+
+ mt_CompGetLGrect(&app, gw->root->toolbar->url.comp, WF_WORKXYWH, &work);
+ work.g_x += TOOLBAR_URL_MARGIN_RIGHT;
+ work.g_y += TOOLBAR_URL_MARGIN_LEFT;
+ work.g_w -= TOOLBAR_URL_MARGIN_RIGHT;
+ work.g_h -= TOOLBAR_URL_MARGIN_BOTTOM;
+
+ plotter->resize(plotter, work.g_w, work.g_h );
+ plotter->move(plotter, work.g_x, work.g_y );
+ plotter->lock( plotter );
+
+ todo[0] = work.g_x;
+ todo[1] = work.g_y;
+ todo[2] = todo[0] + work.g_w-1;
+ todo[3] = todo[1] + work.g_h-1;
+ vs_clip(plotter->vdi_handle, 1, (short*)&todo );
+
+ if( wind_get(gw->root->handle->handle, WF_FIRSTXYWH,
+ &todo[0], &todo[1], &todo[2], &todo[3] )!=0 ) {
+ while (todo[2] && todo[3]) {
+
+ /* convert screen to relative coords: */
+ todo[0] = todo[0] - work.g_x;
+ todo[1] = todo[1] - work.g_y;
+ if( todo[0] < 0 ){
+ todo[2] = todo[2] + todo[0];
+ todo[0] = 0;
+ }
+ if( todo[1] < 0 ){
+ todo[3] = todo[3] + todo[1];
+ todo[1] = 0;
+ }
+
+ if (rc_intersect(&t->url.rdw_area,(GRECT *)&todo)) {
+ struct rect clip = {
+ .x0 = todo[0],
+ .y0 = todo[1],
+ .x1 = todo[0]+todo[2],
+ .y1 = todo[1]+todo[3]
+ };
+ textarea_redraw( t->url.textarea, 0, 0, &clip, &ctx );
+ }
+ if (wind_get(gw->root->handle->handle, WF_NEXTXYWH,
+ &todo[0], &todo[1], &todo[2], &todo[3])==0) {
+ break;
+ }
+ }
+ } else {
+ plotter->unlock( plotter );
+ return;
+ }
+ plotter->unlock( plotter );
+ vs_clip(plotter->vdi_handle, 0, (short*)&todo);
+ t->url.redraw = false;
+ t->url.rdw_area.g_x = 65000;
+ t->url.rdw_area.g_y = 65000;
+ t->url.rdw_area.g_w = -1;
+ t->url.rdw_area.g_h = -1;
+ } else {
+ /* just copy stuff from the offscreen buffer */
+ }
+ }
}
-
-
+
CMP_TOOLBAR tb_create( struct gui_window * gw )
{
int i;
@@ -404,7 +479,7 @@ CMP_TOOLBAR tb_create( struct gui_window * gw )
if( t == NULL )
return( NULL );
- t->owner = gw;
+ t->owner = gw;
/* create the root component: */
t->comp = (COMPONENT*)mt_CompCreate(&app, CLT_HORIZONTAL, TOOLBAR_HEIGHT, 0);
@@ -435,11 +510,13 @@ CMP_TOOLBAR tb_create( struct gui_window * gw )
}
/* create the url widget: */
- t->url.char_size = 8;
- t->url.text = malloc( 2*URL_WIDGET_BSIZE );
- strcpy( t->url.text, "http://" );
- t->url.allocated = 2*URL_WIDGET_BSIZE;
- t->url.scrollx = 0;
+ t->url.textarea = textarea_create( 300, TOOLBAR_TEXTAREA_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);
mt_CompEvntAttach( &app, t->url.comp, WM_REDRAW, evnt_url_redraw );
mt_CompEvntAttach( &app, t->url.comp, WM_XBUTTON, evnt_url_click );
@@ -475,9 +552,8 @@ void tb_destroy( CMP_TOOLBAR tb )
mt_ObjcFree( &app, (OBJECT*)mt_CompDataSearch(&app, tb->buttons[i].comp, CDT_OBJECT) );
i++;
}
- free( tb->buttons );
- if( tb->url.text != NULL )
- free( tb->url.text );
+ free( tb->buttons );
+ textarea_destroy( tb->url.textarea );
mt_CompDelete( &app, tb->comp);
free( tb );
}
@@ -535,7 +611,6 @@ void tb_update_buttons( struct gui_window * gw )
((OBJECT*)mt_CompDataSearch(&app, bt->comp, CDT_OBJECT))->ob_state &= ~OS_DISABLED;
}
mt_CompEvntRedraw( &app, bt->comp );
-
}
@@ -553,69 +628,21 @@ void tb_url_set( struct gui_window * gw, char * text )
if( gw->browser->attached == false )
return;
- struct s_url_widget * url = &gw->root->toolbar->url;
-
- if( len+1 > url->allocated ) {
- newsize = (len / (URL_WIDGET_BSIZE-1))+1;
- newtext = realloc( url->text, newsize*URL_WIDGET_BSIZE );
- if(newtext != NULL) {
- url->text = newtext;
- url->allocated = newsize * URL_WIDGET_BSIZE;
- }
- }
- if( len+1 < url->allocated - URL_WIDGET_BSIZE
- && url->allocated - URL_WIDGET_BSIZE > URL_WIDGET_BSIZE*2 ) {
- newsize = (len / (URL_WIDGET_BSIZE-1) )+1;
- newtext = realloc( url->text, newsize*URL_WIDGET_BSIZE );
- if(newtext != NULL) {
- url->text = newtext;
- url->allocated = newsize * URL_WIDGET_BSIZE;
- }
- }
-
- strncpy((char*)url->text, text, url->allocated-1 );
- url->used = MIN(len+1,url->allocated );
- tb_url_place_caret( gw, 0, true);
- url->scrollx = 0;
- mt_CompGetLGrect(&app, url->comp, WF_WORKXYWH, &work);
- ApplWrite( _AESapid, WM_REDRAW, gw->root->handle->handle,
- (short)work.g_x, (short)work.g_y, (short)work.g_w, (short)work.g_h );
-}
-
-
-/* place the caret and adjust scrolling position */
-void tb_url_place_caret( struct gui_window * gw, int steps, bool abs)
-{
- LGRECT work;
- CMP_TOOLBAR tb = gw->root->toolbar;
- assert(tb!=NULL);
- mt_CompGetLGrect(&app, tb->url.comp, WF_WORKXYWH, &work);
- int ws = (work.g_w / tb->url.char_size)-1; /* widget size in chars */
- if(abs) {
- tb->url.caret_pos = steps;
- } else {
- tb->url.caret_pos = tb->url.caret_pos + steps;
- }
- if( (int)tb->url.caret_pos > (int)strlen(tb->url.text) )
- tb->url.caret_pos = strlen(tb->url.text);
- if( tb->url.caret_pos > tb->url.allocated-2 )
- tb->url.caret_pos = tb->url.allocated-2;
- if( tb->url.caret_pos < 0)
- tb->url.caret_pos = 0;
-
- if( tb->url.caret_pos < tb->url.scrollx ) {
- /* the caret has moved out of the widget to the left */
- tb->url.scrollx -= ws;
- }
- if( tb->url.caret_pos > tb->url.scrollx + ws ) {
- /* the caret has moved out of the widget to the right */
- if(!abs)
- tb->url.scrollx += steps;
- else
- tb->url.scrollx = tb->url.caret_pos - ws;
- }
- if(tb->url.scrollx < 0)
- tb->url.scrollx = 0;
+ struct s_url_widget * url = &gw->root->toolbar->url;
+
+ assert( gw != NULL );
+ assert( gw->browser != NULL );
+ assert( gw->root != NULL );
+ assert( gw->browser->bw != NULL );
+
+ textarea_set_text(url->textarea, text);
+
+ mt_CompGetLGrect( &app, gw->root->toolbar->url.comp, WF_WORKXYWH, &work);
+ work.g_w -= (TOOLBAR_URL_MARGIN_LEFT + TOOLBAR_URL_MARGIN_RIGHT);
+ /* do not overwrite the black border, because of that, add 1 */
+ work.g_h -= (TOOLBAR_URL_MARGIN_TOP + TOOLBAR_URL_MARGIN_BOTTOM+1);
+ tb_txt_request_redraw( gw->root->toolbar, 0,0,work.g_w,work.g_h );
+ return;
}
@@ -628,153 +655,30 @@ bool tb_url_input( struct gui_window * gw, short nkc )
CMP_TOOLBAR tb = gw->root->toolbar;
assert(tb!=NULL);
LGRECT work;
- int start = 0;
- int i;
- char * newtext;
- short newsize;
- char backup;
- bool ctrl = (nkc & NKF_CTRL);
- bool shift = (nkc & NKF_SHIFT);
- bool alt = (nkc & NKF_ALT);
- bool ret = (ctrl) ? false : true;
- char code = (nkc & 0xFF);
+ bool ret = false;
- assert( gw != NULL );
+ 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( gw, BROWSER, gw->browser->bw);
+ browser_window_go(gw->browser->bw, (const char*)&tmp_url, 0, true);
+ ret = true;
+ }
+ }
+ else {
+ ret = textarea_keypress( tb->url.textarea, ik );
+ }
- if( (code == NK_LEFT) && !shift ){
- /* TODO: recognize shift + click */
- tb->url.selection_len = 0;
- tb_url_place_caret( gw, -1, false );
- }
- else if( (code == NK_RIGHT) && !shift ) {
- /* TODO: recognize shift + click */
- tb->url.selection_len = 0;
- tb_url_place_caret( gw, +1, false );
- }
- else if( (ctrl && code == 'C') ) {
- if( tb->url.selection_len != 0 ) {
- char * from;
- char tmp[abs(tb->url.selection_len)+1];
- int len;
- if( tb->url.selection_len < 0 ) {
- from = &tb->url.text[tb->url.caret_pos+tb->url.selection_len];
- } else {
- from = &tb->url.text[tb->url.caret_pos];
- }
- len = MIN( abs(tb->url.selection_len), (int)strlen(from) ) ;
- memcpy(&tmp, from, len);
- tmp[len] = 0;
- int r = scrap_txt_write(&app, (char*)&tmp);
- ret = true;
- }
- }
- else if( (ctrl && code == 'V') || code == NK_INS ) {
- char * clip = scrap_txt_read( &app );
- if( clip != NULL ) {
- size_t l = strlen( clip );
- unsigned int i = 0;
- for( i = 0; i<l; i++) {
- tb_url_input( gw, clip[i] );
- }
- free( clip );
- ret = true;
- }
- }
- else if( (code == NK_DEL) ) {
- if( tb->url.selection_len != 0 ) {
- if( tb->url.selection_len < 0 ) {
- strcpy(
- &tb->url.text[tb->url.caret_pos+tb->url.selection_len],
- &tb->url.text[tb->url.caret_pos]
- );
- tb_url_place_caret( gw, tb->url.selection_len, false );
- } else {
- strcpy(
- &tb->url.text[tb->url.caret_pos],
- &tb->url.text[tb->url.caret_pos+tb->url.selection_len]
- );
- }
- tb->url.used = strlen( tb->url.text ) + 1;
- } else {
- if( tb->url.caret_pos < tb->url.used -1) {
- strcpy(
- &tb->url.text[tb->url.caret_pos+tb->url.selection_len],
- &tb->url.text[tb->url.caret_pos+1]
- );
- tb->url.used--;
- }
- }
- tb->url.selection_len = 0;
- }
- else if( code == NK_BS ) {
- if( tb->url.caret_pos > 0 &&
- tb->url.selection_len != 0 ) {
- if( tb->url.selection_len < 0 ) {
- strcpy(&tb->url.text[tb->url.caret_pos+tb->url.selection_len], &tb->url.text[tb->url.caret_pos]);
- tb_url_place_caret( gw, tb->url.selection_len, false );
- } else {
- strcpy(&tb->url.text[tb->url.caret_pos], &tb->url.text[tb->url.caret_pos+tb->url.selection_len]);
- }
- tb->url.used = strlen( tb->url.text ) + 1;
- } else {
- tb->url.text[tb->url.caret_pos-1] = 0;
- tb->url.used--;
- strcat(tb->url.text, &tb->url.text[tb->url.caret_pos]);
- tb_url_place_caret( gw , -1, false );
- }
- tb->url.selection_len = 0;
- }
- else if( code == NK_ESC ) {
- tb->url.text[0] = 0;
- tb->url.scrollx = 0;
- tb->url.used = 1;
- tb_url_place_caret( gw, 0, true );
- }
- else if( code == NK_CLRHOME ) {
- tb_url_place_caret( gw, 0, true );
- }
- else if( code == NK_M_END ) {
- tb_url_place_caret( gw,
- strlen((char*)&tb->url.text)-1,
- true
- );
- }
- else if( code == NK_ENTER || code == NK_RET ) {
- tb_url_place_caret( gw, 0, true );
- window_set_focus( gw, BROWSER, gw->browser->bw);
- browser_window_go(gw->browser->bw, (const char*)tb->url.text, 0, true);
- }
- else if( code > 30 ) {
- if( tb->url.used+1 > tb->url.allocated ){
- newsize = ( (tb->url.used+1) / (URL_WIDGET_BSIZE-1))+1;
- newtext = realloc(tb->url.text, newsize*URL_WIDGET_BSIZE );
- if(newtext) {
- tb->url.text = newtext;
- tb->url.allocated = newsize * URL_WIDGET_BSIZE;
- }
- }
- i = tb->url.caret_pos;
- backup = tb->url.text[tb->url.caret_pos];
- while( i < tb->url.allocated - 1) {
- tb->url.text[i] = code;
- if( tb->url.text[i] == (char)0 )
- break;
- code = backup;
- i++;
- backup = tb->url.text[i];
- }
- tb->url.used++;
- tb->url.text[tb->url.allocated-1] = 0;
- tb_url_place_caret( gw, +1, false );
- tb->url.selection_len = 0;
- } else {
- ret = false;
- }
- if(tb->url.used < 1)
- tb->url.used = 1; /* at least one byte (0) is used */
- mt_CompGetLGrect(&app, tb->url.comp, WF_WORKXYWH, &work);
- ApplWrite( _AESapid, WM_REDRAW, gw->root->handle->handle,
- work.g_x, work.g_y, work.g_w, work.g_h );
return( ret );
}