2011-01-06 00:02:22 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2010 Ole Loots <ole@monochrom.net>
|
|
|
|
*
|
|
|
|
* 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
|
2011-11-05 05:46:41 +04:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Module Description:
|
|
|
|
*
|
|
|
|
* This WinDom compo
|
|
|
|
*
|
|
|
|
*
|
2011-01-06 00:02:22 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <limits.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <windom.h>
|
|
|
|
|
|
|
|
#include "desktop/gui.h"
|
|
|
|
#include "desktop/netsurf.h"
|
2011-09-19 22:38:48 +04:00
|
|
|
#include "desktop/browser.h"
|
2011-01-06 00:02:22 +03:00
|
|
|
#include "desktop/mouse.h"
|
2011-09-19 22:38:48 +04:00
|
|
|
#include "desktop/textinput.h"
|
|
|
|
#include "content/content.h"
|
|
|
|
#include "content/hlcache.h"
|
|
|
|
#include "content/urldb.h"
|
|
|
|
#include "css/css.h"
|
|
|
|
#include "render/box.h"
|
|
|
|
#include "render/form.h"
|
2011-01-06 00:02:22 +03:00
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
|
|
|
|
#include "atari/gui.h"
|
|
|
|
#include "atari/browser_win.h"
|
|
|
|
#include "atari/misc.h"
|
|
|
|
#include "atari/global_evnt.h"
|
|
|
|
#include "atari/res/netsurf.rsh"
|
|
|
|
#include "atari/browser.h"
|
|
|
|
#include "atari/plot/plotter.h"
|
|
|
|
#include "atari/plot.h"
|
2011-09-19 22:38:48 +04:00
|
|
|
#include "atari/font.h"
|
|
|
|
#include "atari/ctxmenu.h"
|
2011-06-26 00:03:28 +04:00
|
|
|
#include "cflib.h"
|
2011-01-06 00:02:22 +03:00
|
|
|
|
|
|
|
extern browser_mouse_state bmstate;
|
2011-02-05 17:27:30 +03:00
|
|
|
extern int mouse_click_time[3];
|
|
|
|
extern int mouse_hold_start[3];
|
2011-01-06 00:02:22 +03:00
|
|
|
extern GEM_PLOTTER plotter;
|
|
|
|
extern struct gui_window *input_window;
|
2011-04-11 01:52:07 +04:00
|
|
|
extern short last_drag_x;
|
|
|
|
extern short last_drag_y;
|
|
|
|
|
2011-01-06 00:02:22 +03:00
|
|
|
|
|
|
|
|
|
|
|
static void __CDECL browser_evnt_wdestroy( WINDOW * c, short buff[8], void * data);
|
|
|
|
COMPONENT *comp_widget_create( APPvar *app, WINDOW *win, int size, int flex );
|
2011-11-05 05:46:41 +04:00
|
|
|
|
2011-01-06 00:02:22 +03:00
|
|
|
|
2011-11-05 05:46:41 +04:00
|
|
|
/*
|
2011-11-05 19:18:19 +04:00
|
|
|
Create an browser component.
|
2011-11-05 05:46:41 +04:00
|
|
|
Currently, this area is the area which is used to display HTML content.
|
|
|
|
However, it could also contains other areas, these need to be handled within
|
|
|
|
"browser_get_rect" function.
|
|
|
|
*/
|
2011-07-01 00:20:27 +04:00
|
|
|
struct s_browser * browser_create
|
|
|
|
(
|
|
|
|
struct gui_window * gw,
|
|
|
|
struct browser_window *bw,
|
|
|
|
struct browser_window * clone,
|
2011-09-19 22:38:48 +04:00
|
|
|
int lt, int w, int flex
|
2011-07-01 00:20:27 +04:00
|
|
|
)
|
2011-01-06 00:02:22 +03:00
|
|
|
{
|
|
|
|
LGRECT cwork;
|
|
|
|
COMPONENT * scrollv, * scrollh, * drawable;
|
|
|
|
|
|
|
|
CMP_BROWSER bnew = (CMP_BROWSER)malloc( sizeof(struct s_browser) );
|
|
|
|
if( bnew )
|
|
|
|
{
|
|
|
|
memset(bnew, 0, sizeof(struct s_browser) );
|
|
|
|
bnew->bw = bw;
|
|
|
|
bnew->attached = false;
|
|
|
|
if(clone)
|
|
|
|
bw->scale = clone->scale;
|
|
|
|
else
|
|
|
|
bw->scale = 1;
|
2011-11-05 19:18:19 +04:00
|
|
|
bnew->redraw.areas_used = 0;
|
|
|
|
bnew->comp = (COMPONENT*)mt_CompCreate(&app, CLT_HORIZONTAL, 100, 1);
|
2011-01-06 00:02:22 +03:00
|
|
|
if( bnew->comp == NULL ) {
|
|
|
|
free(bnew);
|
|
|
|
return(NULL);
|
2011-11-05 05:46:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Attach events to the component: */
|
2011-11-05 19:18:19 +04:00
|
|
|
mt_CompEvntDataAdd( &app, bnew->comp, WM_XBUTTON,
|
|
|
|
browser_evnt_mbutton, (void*)gw, EV_BOT
|
|
|
|
);
|
2011-09-19 22:38:48 +04:00
|
|
|
mt_CompEvntDataAttach( &app, bnew->comp, WM_REDRAW,
|
2011-11-05 19:18:19 +04:00
|
|
|
browser_evnt_redraw, (void*)gw
|
|
|
|
);
|
2011-09-19 22:38:48 +04:00
|
|
|
mt_CompEvntDataAttach( &app, bnew->comp, WM_DESTROY,
|
2011-11-05 19:18:19 +04:00
|
|
|
browser_evnt_destroy, (void*)bnew
|
|
|
|
);
|
2011-11-05 05:46:41 +04:00
|
|
|
|
|
|
|
/* Set the gui_window owner. */
|
|
|
|
/* it is an link to the netsurf window system */
|
2011-09-19 22:38:48 +04:00
|
|
|
mt_CompDataAttach( &app, bnew->comp, CDT_OWNER, gw );
|
2011-11-05 19:18:19 +04:00
|
|
|
|
2011-09-19 22:38:48 +04:00
|
|
|
bnew->scroll.requested.y = 0;
|
2011-03-21 01:33:56 +03:00
|
|
|
bnew->scroll.requested.x = 0;
|
|
|
|
bnew->scroll.current.x = 0;
|
2011-11-05 19:18:19 +04:00
|
|
|
bnew->scroll.current.y = 0;
|
|
|
|
|
2011-01-06 00:02:22 +03:00
|
|
|
}
|
|
|
|
return( bnew );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool browser_destroy( struct s_browser * b )
|
|
|
|
{
|
|
|
|
|
2011-11-05 19:18:19 +04:00
|
|
|
LOG(("%s\n", b->bw->name ));
|
|
|
|
|
2011-01-06 00:02:22 +03:00
|
|
|
assert( b != NULL );
|
|
|
|
assert( b->comp != NULL );
|
|
|
|
assert( b->bw != NULL );
|
2011-11-05 19:18:19 +04:00
|
|
|
|
|
|
|
if( b->comp != NULL ){
|
|
|
|
mt_CompDelete(&app, b->comp );
|
2011-01-06 00:02:22 +03:00
|
|
|
}
|
|
|
|
return( true );
|
|
|
|
}
|
2011-11-05 05:46:41 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
Query the browser component for widget rectangles.
|
|
|
|
*/
|
2011-01-06 00:02:22 +03:00
|
|
|
void browser_get_rect( struct gui_window * gw, enum browser_rect type, LGRECT * out)
|
2011-11-05 19:18:19 +04:00
|
|
|
{
|
|
|
|
LGRECT cur;
|
2011-11-05 05:46:41 +04:00
|
|
|
|
|
|
|
/* Query component for it's current size: */
|
|
|
|
|
2011-11-05 19:18:19 +04:00
|
|
|
mt_CompGetLGrect(&app, gw->browser->comp, WF_WORKXYWH, &cur);
|
2011-11-05 05:46:41 +04:00
|
|
|
/* And extract the different widget dimensions: */
|
|
|
|
|
|
|
|
/* Redraw area of html content: */
|
2011-01-06 00:02:22 +03:00
|
|
|
if( type == BR_CONTENT ){
|
|
|
|
out->g_w = cur.g_w;
|
2011-11-05 19:18:19 +04:00
|
|
|
out->g_h = cur.g_h;
|
|
|
|
out->g_x = cur.g_x;
|
2011-01-06 00:02:22 +03:00
|
|
|
out->g_y = cur.g_y;
|
2011-11-05 19:18:19 +04:00
|
|
|
return;
|
2011-01-06 00:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Report an resize to the COMPONENT interface */
|
|
|
|
void browser_update_rects(struct gui_window * gw )
|
|
|
|
{
|
|
|
|
short buff[8];
|
2011-08-24 17:42:59 +04:00
|
|
|
LGRECT cmprect;
|
2011-01-06 00:02:22 +03:00
|
|
|
mt_WindGetGrect( &app, gw->root->handle, WF_CURRXYWH, (GRECT*)&buff[4]);
|
|
|
|
buff[0] = CM_REFLOW;
|
|
|
|
buff[1] = _AESapid;
|
|
|
|
buff[2] = 0;
|
|
|
|
EvntExec(gw->root->handle, buff);
|
2011-09-19 22:38:48 +04:00
|
|
|
}
|
2011-01-06 00:02:22 +03:00
|
|
|
|
|
|
|
void browser_set_content_size(struct gui_window * gw, int w, int h)
|
|
|
|
{
|
|
|
|
CMP_BROWSER b = gw->browser;
|
2011-02-05 17:27:30 +03:00
|
|
|
LGRECT work;
|
2011-11-05 19:18:19 +04:00
|
|
|
browser_get_rect( gw, BR_CONTENT, &work );
|
|
|
|
|
|
|
|
gw->root->handle->xpos_max = w;
|
|
|
|
gw->root->handle->ypos_max = h;
|
|
|
|
|
2011-02-05 17:27:30 +03:00
|
|
|
if( w < work.g_w + b->scroll.current.x || w < work.g_h + b->scroll.current.y ) {
|
2011-02-12 22:41:50 +03:00
|
|
|
/* let the scroll routine detect invalid scroll values... */
|
|
|
|
browser_scroll(gw, WA_LFLINE, b->scroll.current.x, true );
|
|
|
|
browser_scroll(gw, WA_UPLINE, b->scroll.current.y, true );
|
2011-02-05 17:27:30 +03:00
|
|
|
/* force update of scrollbars: */
|
|
|
|
b->scroll.required = true;
|
|
|
|
}
|
2011-01-06 00:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __CDECL browser_evnt_destroy( COMPONENT * c, long buff[8], void * data)
|
|
|
|
{
|
|
|
|
struct s_browser * b = (struct s_browser*)data;
|
|
|
|
struct gui_window * gw = b->bw->window;
|
2011-07-01 00:20:27 +04:00
|
|
|
LOG(("%s\n",gw->browser->bw->name));
|
|
|
|
|
2011-01-06 00:02:22 +03:00
|
|
|
assert( b != NULL );
|
|
|
|
assert( gw != NULL );
|
|
|
|
free( b );
|
|
|
|
gw->browser = NULL;
|
2011-02-05 17:27:30 +03:00
|
|
|
LOG(("evnt_destroy done!"));
|
2011-01-06 00:02:22 +03:00
|
|
|
}
|
2011-11-05 05:46:41 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
Mouse Button handler for browser component.
|
|
|
|
*/
|
2011-01-06 00:02:22 +03:00
|
|
|
|
2011-11-05 19:18:19 +04:00
|
|
|
static void __CDECL browser_evnt_mbutton( COMPONENT * c, long buff[8], void * data)
|
2011-09-19 22:38:48 +04:00
|
|
|
{
|
2011-01-06 00:02:22 +03:00
|
|
|
long lbuff[8];
|
2011-04-11 01:52:07 +04:00
|
|
|
short mx, my, dummy, mbut;
|
2011-02-05 17:27:30 +03:00
|
|
|
uint32_t tnow = clock()*1000 / CLOCKS_PER_SEC;
|
2011-01-06 00:02:22 +03:00
|
|
|
LGRECT cwork;
|
|
|
|
struct gui_window * gw = data;
|
2011-09-10 02:18:49 +04:00
|
|
|
if( input_window != gw ) {
|
|
|
|
return;
|
|
|
|
}
|
2011-09-19 22:38:48 +04:00
|
|
|
|
2011-01-06 00:02:22 +03:00
|
|
|
window_set_focus( gw, BROWSER, (void*)gw->browser );
|
|
|
|
browser_get_rect( gw, BR_CONTENT, &cwork );
|
2011-09-19 22:38:48 +04:00
|
|
|
mx = evnt.mx - cwork.g_x;
|
2011-04-11 01:52:07 +04:00
|
|
|
my = evnt.my - cwork.g_y;
|
|
|
|
LOG(("mevent (%d) within %s at %d / %d\n", evnt.nb_click, gw->browser->bw->name, mx, my ));
|
2011-11-05 05:46:41 +04:00
|
|
|
|
|
|
|
/* Translate GEM key state to netsurf mouse modifier */
|
2011-04-11 01:52:07 +04:00
|
|
|
if( evnt.mkstate & (K_RSHIFT | K_LSHIFT) ){
|
2011-02-05 17:27:30 +03:00
|
|
|
bmstate |= BROWSER_MOUSE_MOD_1;
|
|
|
|
} else {
|
|
|
|
bmstate &= ~(BROWSER_MOUSE_MOD_1);
|
2011-01-06 00:02:22 +03:00
|
|
|
}
|
2011-04-11 01:52:07 +04:00
|
|
|
if( (evnt.mkstate & K_CTRL) ){
|
2011-02-05 17:27:30 +03:00
|
|
|
bmstate |= BROWSER_MOUSE_MOD_2;
|
|
|
|
} else {
|
2011-04-11 01:52:07 +04:00
|
|
|
bmstate &= ~(BROWSER_MOUSE_MOD_2);
|
2011-01-06 00:02:22 +03:00
|
|
|
}
|
2011-04-11 01:52:07 +04:00
|
|
|
if( (evnt.mkstate & K_ALT) ){
|
2011-02-05 17:27:30 +03:00
|
|
|
bmstate |= BROWSER_MOUSE_MOD_3;
|
|
|
|
} else {
|
2011-04-11 01:52:07 +04:00
|
|
|
bmstate &= ~(BROWSER_MOUSE_MOD_3);
|
|
|
|
}
|
2011-02-05 17:27:30 +03:00
|
|
|
int sx = (mx + gw->browser->scroll.current.x);
|
|
|
|
int sy = (my + gw->browser->scroll.current.y);
|
2011-11-05 05:46:41 +04:00
|
|
|
|
|
|
|
/* Detect left mouse button state and compare with event state: */
|
2011-04-11 01:52:07 +04:00
|
|
|
graf_mkstate(&dummy, &dummy, &mbut, &dummy);
|
2011-09-19 22:38:48 +04:00
|
|
|
if( (mbut & 1) && (evnt.mbut & 1) ) {
|
|
|
|
if( mouse_hold_start[0] == 0 ) {
|
|
|
|
mouse_hold_start[0] = tnow;
|
|
|
|
LOG(("Drag starts at %d,%d\n", sx, sy));
|
|
|
|
browser_window_mouse_click(gw->browser->bw,BROWSER_MOUSE_PRESS_1,sx,sy);
|
|
|
|
bmstate |= BROWSER_MOUSE_HOLDING_1 | BROWSER_MOUSE_DRAG_ON;
|
2011-04-11 01:52:07 +04:00
|
|
|
} else {
|
2011-09-19 22:38:48 +04:00
|
|
|
bmstate |= BROWSER_MOUSE_DRAG_1 | BROWSER_MOUSE_DRAG_ON;
|
|
|
|
}
|
|
|
|
if( (abs(mx-last_drag_x)>5) || (abs(mx-last_drag_y)>5) ){
|
|
|
|
browser_window_mouse_track(
|
|
|
|
gw->browser->bw,
|
|
|
|
bmstate,
|
|
|
|
sx, sy
|
|
|
|
);
|
|
|
|
last_drag_x = mx;
|
|
|
|
last_drag_y = my;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if( (evnt.mbut & 1) ) {
|
|
|
|
mouse_click_time[0] = tnow; /* clock in ms */
|
|
|
|
/* check if this event was during an drag op, only handle if it wasn't: */
|
|
|
|
if( mouse_hold_start[0] == 0 ) {
|
|
|
|
LOG(("Click within %s at %d / %d\n", gw->browser->bw->name, sx, sy ));
|
|
|
|
browser_window_mouse_click(gw->browser->bw,BROWSER_MOUSE_PRESS_1,sx,sy);
|
|
|
|
browser_window_mouse_click(gw->browser->bw,BROWSER_MOUSE_CLICK_1,sx,sy);
|
|
|
|
bmstate &= ~( BROWSER_MOUSE_HOLDING_1 | BROWSER_MOUSE_DRAG_1 | BROWSER_MOUSE_CLICK_1);
|
2011-02-05 17:27:30 +03:00
|
|
|
}
|
2011-09-19 22:38:48 +04:00
|
|
|
mouse_hold_start[0] = 0;
|
|
|
|
}
|
|
|
|
|
2011-11-05 05:46:41 +04:00
|
|
|
/* Right button pressed? */
|
2011-09-19 22:38:48 +04:00
|
|
|
if( (evnt.mbut & 2 ) ) {
|
|
|
|
context_popup( gw, evnt.mx, evnt.my );
|
|
|
|
}
|
|
|
|
|
2011-01-06 00:02:22 +03:00
|
|
|
}
|
2011-11-05 05:46:41 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
Report scroll event to the browser component.
|
|
|
|
*/
|
2011-01-06 00:02:22 +03:00
|
|
|
void browser_scroll( struct gui_window * gw, short mode, int value, bool abs )
|
|
|
|
{
|
|
|
|
LGRECT work;
|
|
|
|
int max_y_scroll;
|
|
|
|
int max_x_scroll;
|
|
|
|
int oldx = gw->browser->scroll.current.x;
|
|
|
|
int oldy = gw->browser->scroll.current.y;
|
|
|
|
struct s_browser * b = gw->browser;
|
|
|
|
LOG((""));
|
2011-02-12 22:41:50 +03:00
|
|
|
|
|
|
|
if( b->bw->current_content != NULL ) {
|
|
|
|
browser_get_rect( gw, BR_CONTENT, &work);
|
|
|
|
max_y_scroll = (content_get_height( b->bw->current_content ) - work.g_h );
|
|
|
|
max_x_scroll = (content_get_width( b->bw->current_content ) - work.g_w);
|
|
|
|
} else {
|
2011-01-06 00:02:22 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-12 22:41:50 +03:00
|
|
|
|
2011-01-06 00:02:22 +03:00
|
|
|
switch( mode ) {
|
2011-02-12 22:41:50 +03:00
|
|
|
|
2011-01-06 00:02:22 +03:00
|
|
|
case WA_UPPAGE:
|
2011-09-19 22:38:48 +04:00
|
|
|
case WA_UPLINE:
|
2011-03-21 01:33:56 +03:00
|
|
|
if( max_y_scroll < 1 )
|
|
|
|
return;
|
2011-01-06 00:02:22 +03:00
|
|
|
if( abs == false )
|
|
|
|
b->scroll.requested.y -= value;
|
2011-09-19 22:38:48 +04:00
|
|
|
else
|
2011-01-06 00:02:22 +03:00
|
|
|
b->scroll.requested.y = value - b->scroll.current.y;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WA_DNPAGE:
|
|
|
|
case WA_DNLINE:
|
2011-03-21 01:33:56 +03:00
|
|
|
if( max_y_scroll < 1 )
|
|
|
|
return;
|
2011-01-06 00:02:22 +03:00
|
|
|
if( abs == false )
|
|
|
|
b->scroll.requested.y += value;
|
|
|
|
else
|
|
|
|
b->scroll.requested.y = value - b->scroll.current.y;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WA_LFPAGE:
|
2011-09-19 22:38:48 +04:00
|
|
|
case WA_LFLINE:
|
2011-03-21 01:33:56 +03:00
|
|
|
if( max_x_scroll < 1 )
|
|
|
|
return;
|
2011-01-06 00:02:22 +03:00
|
|
|
if( abs == false )
|
|
|
|
b->scroll.requested.x -= value;
|
|
|
|
else
|
|
|
|
b->scroll.requested.x = value - b->scroll.current.x;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WA_RTPAGE:
|
|
|
|
case WA_RTLINE:
|
2011-03-21 01:33:56 +03:00
|
|
|
if( max_x_scroll < 1 )
|
|
|
|
return;
|
2011-01-06 00:02:22 +03:00
|
|
|
if( abs == false )
|
|
|
|
b->scroll.requested.x += value;
|
|
|
|
else
|
|
|
|
b->scroll.requested.x = value - b->scroll.current.x;
|
|
|
|
break;
|
|
|
|
|
2011-09-19 22:38:48 +04:00
|
|
|
default: break;
|
2011-01-06 00:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if( b->scroll.current.y + b->scroll.requested.y < 0 ) {
|
|
|
|
b->scroll.requested.y = -b->scroll.current.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( b->scroll.current.y + b->scroll.requested.y > max_y_scroll ) {
|
|
|
|
b->scroll.requested.y = max_y_scroll - b->scroll.current.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( b->scroll.current.x + b->scroll.requested.x < 0 ) {
|
|
|
|
b->scroll.requested.x = -b->scroll.current.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( b->scroll.current.x + b->scroll.requested.x > max_x_scroll ) {
|
|
|
|
b->scroll.requested.x = max_x_scroll - b->scroll.current.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( oldy != b->scroll.current.y + b->scroll.requested.y ||
|
|
|
|
oldx != b->scroll.current.x + b->scroll.requested.x ) {
|
|
|
|
b->scroll.required = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
perform the requested scrolling.
|
|
|
|
gw -> the browser window to act upon.
|
|
|
|
bwrect -> the dimensions of the browser, so that this function
|
2011-09-19 22:38:48 +04:00
|
|
|
doesn't need to get it.
|
2011-01-06 00:02:22 +03:00
|
|
|
*/
|
|
|
|
static void browser_process_scroll( struct gui_window * gw, LGRECT bwrect )
|
|
|
|
{
|
|
|
|
struct s_browser * b = gw->browser;
|
|
|
|
GRECT src;
|
|
|
|
GRECT dst;
|
|
|
|
short h,w;
|
2011-08-31 01:38:54 +04:00
|
|
|
|
2011-02-12 22:41:50 +03:00
|
|
|
if( gw->browser->bw->current_content == NULL )
|
|
|
|
return;
|
|
|
|
|
2011-01-06 00:02:22 +03:00
|
|
|
h = (short) abs( b->scroll.requested.y );
|
2011-09-19 22:38:48 +04:00
|
|
|
w = (short) abs( b->scroll.requested.x );
|
2011-01-06 00:02:22 +03:00
|
|
|
|
|
|
|
/* if the request exceeds the browser size, redraw the whole area */
|
|
|
|
if ( b->scroll.requested.y > bwrect.g_h || b->scroll.requested.y < -bwrect.g_h ||
|
|
|
|
b->scroll.requested.x > bwrect.g_w || b->scroll.requested.x < -bwrect.g_w ) {
|
|
|
|
b->scroll.current.y += b->scroll.requested.y;
|
|
|
|
b->scroll.current.x += b->scroll.requested.x;
|
|
|
|
browser_schedule_redraw( gw, 0, 0, bwrect.g_w, bwrect.g_h);
|
|
|
|
/* don't scroll again: */
|
|
|
|
b->scroll.requested.y = 0;
|
|
|
|
b->scroll.requested.x = 0;
|
|
|
|
}
|
|
|
|
if( b->scroll.requested.y < 0 ) {
|
|
|
|
/* scroll up */
|
|
|
|
src.g_x = 0;
|
|
|
|
src.g_y = 0;
|
|
|
|
src.g_w = bwrect.g_w;
|
|
|
|
src.g_h = bwrect.g_h - h;
|
|
|
|
dst.g_x = 0;
|
2011-08-31 01:38:54 +04:00
|
|
|
dst.g_y = h;
|
2011-01-06 00:02:22 +03:00
|
|
|
dst.g_w = src.g_w;
|
|
|
|
dst.g_h = src.g_h;
|
|
|
|
plotter->copy_rect( plotter, src, dst );
|
|
|
|
b->scroll.current.y += b->scroll.requested.y;
|
2011-09-19 22:38:48 +04:00
|
|
|
browser_schedule_redraw( gw, 0, 0, bwrect.g_w, h ) ;
|
2011-01-06 00:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if( b->scroll.requested.y > 0 ) {
|
2011-09-19 22:38:48 +04:00
|
|
|
/* scroll down */
|
2011-01-06 00:02:22 +03:00
|
|
|
src.g_x = 0;
|
|
|
|
src.g_y = h;
|
|
|
|
src.g_w = bwrect.g_w;
|
|
|
|
src.g_h = bwrect.g_h - h;
|
|
|
|
dst.g_x = 0;
|
|
|
|
dst.g_y = 0;
|
|
|
|
dst.g_w = bwrect.g_w;
|
|
|
|
dst.g_h = bwrect.g_h - h;
|
|
|
|
plotter->copy_rect( plotter, src, dst );
|
|
|
|
b->scroll.current.y += b->scroll.requested.y;
|
|
|
|
browser_schedule_redraw( gw, 0, bwrect.g_h - h, bwrect.g_w, bwrect.g_h );
|
2011-09-19 22:38:48 +04:00
|
|
|
}
|
2011-01-06 00:02:22 +03:00
|
|
|
|
|
|
|
if( b->scroll.requested.x < 0 ) {
|
|
|
|
/* scroll to the left */
|
|
|
|
src.g_x = 0;
|
|
|
|
src.g_y = 0;
|
|
|
|
src.g_w = bwrect.g_w - w;
|
|
|
|
src.g_h = bwrect.g_h;
|
|
|
|
dst.g_x = w;
|
|
|
|
dst.g_y = 0;
|
|
|
|
dst.g_w = bwrect.g_w - w;
|
|
|
|
dst.g_h = bwrect.g_h;
|
|
|
|
plotter->copy_rect( plotter, src, dst );
|
|
|
|
b->scroll.current.x += b->scroll.requested.x;
|
|
|
|
browser_schedule_redraw( gw, 0, 0, w, bwrect.g_h );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( b->scroll.requested.x > 0 ) {
|
|
|
|
/* scroll to the right */
|
|
|
|
src.g_x = w;
|
|
|
|
src.g_y = 0;
|
|
|
|
src.g_w = bwrect.g_w - w;
|
|
|
|
src.g_h = bwrect.g_h;
|
|
|
|
dst.g_x = 0;
|
|
|
|
dst.g_y = 0;
|
|
|
|
dst.g_w = bwrect.g_w - w;
|
|
|
|
dst.g_h = bwrect.g_h;
|
|
|
|
plotter->copy_rect( plotter, src, dst );
|
|
|
|
b->scroll.current.x += b->scroll.requested.x;
|
|
|
|
browser_schedule_redraw( gw, bwrect.g_w - w, 0, bwrect.g_w, bwrect.g_h );
|
2011-09-19 22:38:48 +04:00
|
|
|
}
|
2011-01-06 00:02:22 +03:00
|
|
|
b->scroll.requested.y = 0;
|
|
|
|
b->scroll.requested.x = 0;
|
2011-11-05 19:18:19 +04:00
|
|
|
|
|
|
|
gw->root->handle->xpos = b->scroll.current.x;
|
|
|
|
gw->root->handle->ypos = b->scroll.current.y;
|
|
|
|
|
|
|
|
mt_WindSlider( &app, gw->root->handle, HSLIDER|VSLIDER );
|
2011-01-06 00:02:22 +03:00
|
|
|
}
|
|
|
|
|
2011-11-05 05:46:41 +04:00
|
|
|
/*
|
|
|
|
Report keypress to browser component.
|
|
|
|
The browser component doesn't list for keyinput by itself.
|
|
|
|
parameter:
|
|
|
|
- gui_window ( compocnent owner ).
|
|
|
|
- unsigned short nkc ( CFLIB normalised key code )
|
|
|
|
*/
|
2011-09-19 22:38:48 +04:00
|
|
|
bool browser_input( struct gui_window * gw, unsigned short nkc )
|
2011-01-06 00:02:22 +03:00
|
|
|
{
|
|
|
|
LGRECT work;
|
|
|
|
bool r = false;
|
|
|
|
unsigned char ascii = (nkc & 0xFF);
|
|
|
|
nkc = (nkc & (NKF_CTRL|NKF_SHIFT|0xFF));
|
|
|
|
browser_get_rect(gw, BR_CONTENT, &work);
|
|
|
|
|
|
|
|
if( (nkc & NKF_CTRL) != 0 ) {
|
|
|
|
switch ( ascii ) {
|
|
|
|
case 'A':
|
|
|
|
r = browser_window_key_press(gw->browser->bw, KEY_SELECT_ALL);
|
|
|
|
break;
|
2011-07-01 00:20:27 +04:00
|
|
|
|
2011-01-06 00:02:22 +03:00
|
|
|
case 'C':
|
|
|
|
r = browser_window_key_press(gw->browser->bw, KEY_COPY_SELECTION);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'X':
|
|
|
|
r = browser_window_key_press(gw->browser->bw, KEY_CUT_SELECTION);
|
|
|
|
break;
|
2011-07-01 00:20:27 +04:00
|
|
|
|
2011-01-06 00:02:22 +03:00
|
|
|
case 'V':
|
|
|
|
r = browser_window_key_press(gw->browser->bw, KEY_PASTE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2011-07-01 00:20:27 +04:00
|
|
|
break;
|
|
|
|
}
|
2011-01-06 00:02:22 +03:00
|
|
|
}
|
|
|
|
if( (nkc & NKF_SHIFT) != 0 ) {
|
|
|
|
switch( ascii ) {
|
|
|
|
|
|
|
|
case NK_TAB:
|
2011-09-19 22:38:48 +04:00
|
|
|
r = browser_window_key_press(gw->browser->bw, KEY_SHIFT_TAB);
|
2011-01-06 00:02:22 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NK_LEFT:
|
|
|
|
if( browser_window_key_press(gw->browser->bw, KEY_LINE_START) == false) {
|
|
|
|
browser_scroll( gw, WA_LFPAGE, work.g_w, false );
|
|
|
|
r = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NK_RIGHT:
|
|
|
|
if( browser_window_key_press(gw->browser->bw, KEY_LINE_END) == false) {
|
|
|
|
browser_scroll( gw, WA_RTPAGE, work.g_w, false );
|
|
|
|
r = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NK_UP:
|
|
|
|
if ( browser_window_key_press(gw->browser->bw, KEY_PAGE_UP) ==false ){
|
|
|
|
browser_scroll( gw, WA_UPPAGE, work.g_h, false );
|
|
|
|
r = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NK_DOWN:
|
|
|
|
if (browser_window_key_press(gw->browser->bw, KEY_PAGE_DOWN) == false) {
|
|
|
|
browser_scroll( gw, WA_DNPAGE, work.g_h, false );
|
|
|
|
r = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( (nkc & (NKF_SHIFT|NKF_CTRL) ) == 0 ) {
|
|
|
|
switch( ascii ) {
|
|
|
|
case NK_BS:
|
|
|
|
r = browser_window_key_press(gw->browser->bw, KEY_DELETE_LEFT);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NK_DEL:
|
|
|
|
r = browser_window_key_press(gw->browser->bw, KEY_DELETE_RIGHT);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NK_TAB:
|
|
|
|
r = browser_window_key_press(gw->browser->bw, KEY_TAB);
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case NK_ENTER:
|
|
|
|
r = browser_window_key_press(gw->browser->bw, KEY_NL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NK_RET:
|
|
|
|
r = browser_window_key_press(gw->browser->bw, KEY_CR);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NK_ESC:
|
2011-09-19 22:38:48 +04:00
|
|
|
r = browser_window_key_press(gw->browser->bw, KEY_ESCAPE);
|
2011-01-06 00:02:22 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NK_CLRHOME:
|
|
|
|
r = browser_window_key_press(gw->browser->bw, KEY_TEXT_START);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NK_RIGHT:
|
|
|
|
if (browser_window_key_press(gw->browser->bw, KEY_RIGHT) == false){
|
|
|
|
browser_scroll( gw, WA_RTLINE, 16, false );
|
|
|
|
r = true;
|
|
|
|
}
|
2011-09-19 22:38:48 +04:00
|
|
|
break;
|
2011-01-06 00:02:22 +03:00
|
|
|
|
|
|
|
case NK_LEFT:
|
|
|
|
if (browser_window_key_press(gw->browser->bw, KEY_LEFT) == false) {
|
|
|
|
browser_scroll( gw, WA_LFLINE, 16, false );
|
|
|
|
r = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NK_UP:
|
|
|
|
if (browser_window_key_press(gw->browser->bw, KEY_UP) == false) {
|
|
|
|
browser_scroll( gw, WA_UPLINE, 16, false);
|
|
|
|
r = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NK_DOWN:
|
|
|
|
if (browser_window_key_press(gw->browser->bw, KEY_DOWN) == false) {
|
|
|
|
browser_scroll( gw, WA_DNLINE, 16, false);
|
|
|
|
r = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NK_M_PGUP:
|
|
|
|
if ( browser_window_key_press(gw->browser->bw, KEY_PAGE_UP) ==false ) {
|
|
|
|
browser_scroll( gw, WA_UPPAGE, work.g_h, false );
|
|
|
|
r = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-09-19 22:38:48 +04:00
|
|
|
case NK_M_PGDOWN:
|
2011-01-06 00:02:22 +03:00
|
|
|
if (browser_window_key_press(gw->browser->bw, KEY_PAGE_DOWN) == false) {
|
|
|
|
browser_scroll( gw, WA_DNPAGE, work.g_h, false );
|
|
|
|
r = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( r == false && ( (nkc & NKF_CTRL)==0) ) {
|
|
|
|
if (ascii >= 9 ) {
|
|
|
|
int ucs4 = atari_to_ucs4(ascii);
|
|
|
|
r = browser_window_key_press(gw->browser->bw, ucs4 );
|
|
|
|
}
|
|
|
|
}
|
2011-08-31 01:38:54 +04:00
|
|
|
return( r );
|
2011-01-06 00:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* determines if a browser window needs redraw */
|
2011-08-31 01:38:54 +04:00
|
|
|
bool browser_redraw_required( struct gui_window * gw)
|
2011-01-06 00:02:22 +03:00
|
|
|
{
|
|
|
|
bool ret = true;
|
|
|
|
CMP_BROWSER b = gw->browser;
|
|
|
|
|
2011-01-31 01:08:49 +03:00
|
|
|
if( b->bw->current_content == NULL )
|
|
|
|
return ( false );
|
|
|
|
|
2011-07-01 00:20:27 +04:00
|
|
|
ret = ( ((b->redraw.areas_used > 0) )
|
|
|
|
|| b->scroll.required
|
2011-05-10 02:10:02 +04:00
|
|
|
|| b->caret.redraw );
|
2011-01-06 00:02:22 +03:00
|
|
|
return( ret );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-12 22:41:50 +03:00
|
|
|
/* schedule a redraw of content */
|
|
|
|
/* coords are relative to the framebuffer */
|
|
|
|
void browser_schedule_redraw_rect(struct gui_window * gw, short x, short y, short w, short h)
|
|
|
|
{
|
|
|
|
if( x < 0 ){
|
|
|
|
w += x;
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( y < 0 ) {
|
|
|
|
h += y;
|
2011-08-31 01:38:54 +04:00
|
|
|
y = 0;
|
2011-02-12 22:41:50 +03:00
|
|
|
}
|
|
|
|
browser_schedule_redraw( gw, x, y, x+w, y+h );
|
|
|
|
}
|
|
|
|
|
2011-08-31 01:38:54 +04:00
|
|
|
static inline bool rect_intersect( struct rect * box1, struct rect * box2 )
|
2011-05-10 02:10:02 +04:00
|
|
|
{
|
2011-08-31 01:38:54 +04:00
|
|
|
if (box2->x1 < box1->x0)
|
|
|
|
return false;
|
2011-05-10 02:10:02 +04:00
|
|
|
|
2011-08-31 01:38:54 +04:00
|
|
|
if (box2->y1 < box1->y0)
|
|
|
|
return false;
|
2011-05-10 02:10:02 +04:00
|
|
|
|
2011-08-31 01:38:54 +04:00
|
|
|
if (box2->x0 > box1->x1)
|
|
|
|
return false;
|
2011-05-10 02:10:02 +04:00
|
|
|
|
2011-08-31 01:38:54 +04:00
|
|
|
if (box2->y0 > box1->y1)
|
|
|
|
return false;
|
2011-05-10 02:10:02 +04:00
|
|
|
|
2011-08-31 01:38:54 +04:00
|
|
|
return true;
|
2011-05-10 02:10:02 +04:00
|
|
|
}
|
|
|
|
|
2011-08-31 01:38:54 +04:00
|
|
|
/*
|
2011-05-10 02:10:02 +04:00
|
|
|
schedule a redraw of content, coords are relative to the framebuffer
|
|
|
|
*/
|
2011-01-06 00:02:22 +03:00
|
|
|
void browser_schedule_redraw(struct gui_window * gw, short x0, short y0, short x1, short y1)
|
|
|
|
{
|
2011-02-12 22:41:50 +03:00
|
|
|
assert( gw != NULL );
|
2011-01-06 00:02:22 +03:00
|
|
|
CMP_BROWSER b = gw->browser;
|
2011-05-10 02:10:02 +04:00
|
|
|
int i;
|
2011-08-31 01:38:54 +04:00
|
|
|
struct rect area;
|
2011-02-12 22:41:50 +03:00
|
|
|
LGRECT work;
|
|
|
|
|
|
|
|
if( y1 < 0 || x1 < 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
browser_get_rect( gw, BR_CONTENT, &work);
|
|
|
|
if( x0 > work.g_w )
|
|
|
|
return;
|
|
|
|
if( y0 > work.g_h )
|
|
|
|
return;
|
|
|
|
|
2011-08-31 01:38:54 +04:00
|
|
|
area.x0 = x0;
|
|
|
|
area.y0 = y0;
|
|
|
|
area.x1 = x1;
|
|
|
|
area.y1 = y1;
|
|
|
|
|
2011-05-10 02:10:02 +04:00
|
|
|
for( i=0; i<b->redraw.areas_used; i++) {
|
2011-08-31 01:38:54 +04:00
|
|
|
if( b->redraw.areas[i].x0 <= x0
|
2011-05-10 02:10:02 +04:00
|
|
|
&& b->redraw.areas[i].x1 >= x1
|
2011-08-31 01:38:54 +04:00
|
|
|
&& b->redraw.areas[i].y0 <= y0
|
2011-05-10 02:10:02 +04:00
|
|
|
&& b->redraw.areas[i].y1 >= y1 ){
|
|
|
|
/* the area is already queued for redraw */
|
|
|
|
return;
|
|
|
|
} else {
|
2011-08-31 01:38:54 +04:00
|
|
|
if( rect_intersect(&b->redraw.areas[i], &area ) ){
|
2011-05-10 02:10:02 +04:00
|
|
|
b->redraw.areas[i].x0 = MIN(b->redraw.areas[i].x0, x0);
|
|
|
|
b->redraw.areas[i].y0 = MIN(b->redraw.areas[i].y0, y0);
|
|
|
|
b->redraw.areas[i].x1 = MAX(b->redraw.areas[i].x1, x1);
|
|
|
|
b->redraw.areas[i].y1 = MAX(b->redraw.areas[i].y1, y1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2011-09-19 22:38:48 +04:00
|
|
|
}
|
2011-05-10 02:10:02 +04:00
|
|
|
|
|
|
|
if( b->redraw.areas_used < MAX_REDRW_SLOTS ) {
|
|
|
|
b->redraw.areas[b->redraw.areas_used].x0 = x0;
|
|
|
|
b->redraw.areas[b->redraw.areas_used].x1 = x1;
|
|
|
|
b->redraw.areas[b->redraw.areas_used].y0 = y0;
|
|
|
|
b->redraw.areas[b->redraw.areas_used].y1 = y1;
|
|
|
|
b->redraw.areas_used++;
|
|
|
|
} else {
|
2011-08-31 01:38:54 +04:00
|
|
|
/*
|
2011-05-10 02:10:02 +04:00
|
|
|
we are out of available slots, merge box with last slot
|
|
|
|
this is dumb... but also a very rare case.
|
|
|
|
*/
|
|
|
|
b->redraw.areas[MAX_REDRW_SLOTS-1].x0 = MIN(b->redraw.areas[i].x0, x0);
|
|
|
|
b->redraw.areas[MAX_REDRW_SLOTS-1].y0 = MIN(b->redraw.areas[i].y0, y0);
|
|
|
|
b->redraw.areas[MAX_REDRW_SLOTS-1].x1 = MAX(b->redraw.areas[i].x1, x1);
|
|
|
|
b->redraw.areas[MAX_REDRW_SLOTS-1].y1 = MAX(b->redraw.areas[i].y1, y1);
|
|
|
|
}
|
2011-08-31 01:38:54 +04:00
|
|
|
done:
|
2011-05-10 02:10:02 +04:00
|
|
|
return;
|
2011-01-06 00:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void browser_redraw_content( struct gui_window * gw, int xoff, int yoff )
|
|
|
|
{
|
|
|
|
LGRECT work;
|
|
|
|
CMP_BROWSER b = gw->browser;
|
|
|
|
|
2011-06-30 19:48:07 +04:00
|
|
|
struct redraw_context ctx = {
|
|
|
|
.interactive = true,
|
|
|
|
.plot = &atari_plotters
|
|
|
|
};
|
|
|
|
|
2011-08-31 01:38:54 +04:00
|
|
|
LOG(("%s : %d,%d - %d,%d\n", b->bw->name, b->redraw.area.x0,
|
2011-01-06 00:02:22 +03:00
|
|
|
b->redraw.area.y0, b->redraw.area.x1, b->redraw.area.y1
|
|
|
|
));
|
2011-02-05 17:27:30 +03:00
|
|
|
|
2011-08-31 01:38:54 +04:00
|
|
|
|
2011-02-20 19:17:43 +03:00
|
|
|
browser_window_redraw( b->bw, -b->scroll.current.x,
|
2011-08-31 01:38:54 +04:00
|
|
|
-b->scroll.current.y, &b->redraw.area, &ctx );
|
2011-02-20 19:17:43 +03:00
|
|
|
|
2011-01-06 00:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void browser_redraw_caret( struct gui_window * gw, GRECT * area )
|
|
|
|
{
|
|
|
|
GRECT caret;
|
|
|
|
struct s_browser * b = gw->browser;
|
|
|
|
if( b->caret.redraw == true ){
|
2011-02-26 02:14:41 +03:00
|
|
|
struct rect old_clip;
|
|
|
|
struct rect clip;
|
|
|
|
|
2011-01-06 00:02:22 +03:00
|
|
|
caret = b->caret.requested;
|
|
|
|
caret.g_x -= gw->browser->scroll.current.x;
|
2011-11-05 05:46:41 +04:00
|
|
|
caret.g_y -= gw->browser->scroll.current.y;
|
2011-02-15 01:05:39 +03:00
|
|
|
clip.x0 = caret.g_x - 1;
|
|
|
|
clip.y0 = caret.g_y - 1;
|
|
|
|
clip.x1 = caret.g_x + caret.g_w + 1;
|
2011-03-01 22:28:12 +03:00
|
|
|
clip.y1 = caret.g_y + caret.g_h + 1;
|
2011-02-26 02:14:41 +03:00
|
|
|
/* store old clip before adjusting it: */
|
|
|
|
plot_get_clip( &old_clip );
|
2011-01-06 00:02:22 +03:00
|
|
|
/* clip to cursor: */
|
2011-02-15 01:05:39 +03:00
|
|
|
plot_clip( &clip );
|
2011-09-19 22:38:48 +04:00
|
|
|
plot_rectangle( caret.g_x, caret.g_y,
|
2011-01-06 00:02:22 +03:00
|
|
|
caret.g_x+caret.g_w, caret.g_y+caret.g_h,
|
|
|
|
plot_style_caret );
|
2011-02-26 02:14:41 +03:00
|
|
|
/* restore old clip area: */
|
2011-02-15 01:05:39 +03:00
|
|
|
plot_clip( &old_clip );
|
2011-02-12 22:41:50 +03:00
|
|
|
b->caret.current.g_x = caret.g_x + gw->browser->scroll.current.x;
|
|
|
|
b->caret.current.g_y = caret.g_y + gw->browser->scroll.current.y;
|
|
|
|
b->caret.current.g_w = caret.g_w;
|
2011-09-19 22:38:48 +04:00
|
|
|
b->caret.current.g_h = caret.g_h;
|
2011-01-06 00:02:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-19 22:38:48 +04:00
|
|
|
void browser_redraw( struct gui_window * gw )
|
2011-08-31 01:38:54 +04:00
|
|
|
{
|
2011-01-06 00:02:22 +03:00
|
|
|
LGRECT bwrect;
|
|
|
|
struct s_browser * b = gw->browser;
|
|
|
|
short todo[4];
|
2011-02-26 02:14:41 +03:00
|
|
|
struct rect clip;
|
2011-01-06 00:02:22 +03:00
|
|
|
|
2011-03-01 22:28:12 +03:00
|
|
|
if( b->attached == false || b->bw->current_content == NULL ) {
|
2011-01-06 00:02:22 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
browser_get_rect(gw, BR_CONTENT, &bwrect);
|
|
|
|
|
|
|
|
plotter->resize(plotter, bwrect.g_w, bwrect.g_h);
|
|
|
|
plotter->move(plotter, bwrect.g_x, bwrect.g_y );
|
2011-02-26 02:14:41 +03:00
|
|
|
clip.x0 = 0;
|
|
|
|
clip.y0 = 0;
|
|
|
|
clip.x1 = bwrect.g_w;
|
|
|
|
clip.y1 = bwrect.g_h;
|
|
|
|
plotter->clip( plotter, &clip );
|
2011-01-22 19:23:30 +03:00
|
|
|
plotter->lock(plotter);
|
2011-01-06 00:02:22 +03:00
|
|
|
|
|
|
|
if( b->scroll.required == true && b->bw->current_content != NULL) {
|
|
|
|
browser_process_scroll( gw, bwrect );
|
|
|
|
b->scroll.required = false;
|
|
|
|
}
|
|
|
|
|
2011-05-10 02:10:02 +04:00
|
|
|
if ((b->redraw.areas_used > 0) && b->bw->current_content != NULL ) {
|
2011-01-06 00:02:22 +03:00
|
|
|
if( (plotter->flags & PLOT_FLAG_OFFSCREEN) == 0 ) {
|
2011-05-10 02:10:02 +04:00
|
|
|
int i;
|
2011-01-06 00:02:22 +03:00
|
|
|
GRECT area;
|
2011-05-10 02:10:02 +04:00
|
|
|
GRECT fbwork;
|
2011-01-06 00:02:22 +03:00
|
|
|
todo[0] = bwrect.g_x;
|
|
|
|
todo[1] = bwrect.g_y;
|
2011-01-22 19:23:30 +03:00
|
|
|
todo[2] = todo[0] + bwrect.g_w-1;
|
|
|
|
todo[3] = todo[1] + bwrect.g_h-1;
|
2011-01-06 00:02:22 +03:00
|
|
|
vs_clip(plotter->vdi_handle, 1, (short*)&todo[0]);
|
2011-08-31 01:38:54 +04:00
|
|
|
if( wind_get(gw->root->handle->handle, WF_FIRSTXYWH,
|
2011-01-06 00:02:22 +03:00
|
|
|
&todo[0], &todo[1], &todo[2], &todo[3] )!=0 ) {
|
|
|
|
while (todo[2] && todo[3]) {
|
|
|
|
/* convert screen to framebuffer coords: */
|
2011-08-31 01:38:54 +04:00
|
|
|
fbwork.g_x = todo[0] - bwrect.g_x;
|
2011-05-10 02:10:02 +04:00
|
|
|
fbwork.g_y = todo[1] - bwrect.g_y;
|
|
|
|
if( fbwork.g_x < 0 ){
|
|
|
|
fbwork.g_w = todo[2] + todo[0];
|
|
|
|
fbwork.g_x = 0;
|
|
|
|
} else {
|
|
|
|
fbwork.g_w = todo[2];
|
2011-01-06 00:02:22 +03:00
|
|
|
}
|
2011-05-10 02:10:02 +04:00
|
|
|
if( fbwork.g_y < 0 ){
|
|
|
|
fbwork.g_h = todo[3] + todo[1];
|
|
|
|
fbwork.g_y = 0;
|
|
|
|
} else {
|
|
|
|
fbwork.g_h = todo[3];
|
2011-01-06 00:02:22 +03:00
|
|
|
}
|
2011-05-10 02:10:02 +04:00
|
|
|
/* walk the redraw requests: */
|
|
|
|
for( i=0; i<b->redraw.areas_used; i++ ){
|
|
|
|
area.g_x = b->redraw.areas[i].x0;
|
|
|
|
area.g_y = b->redraw.areas[i].y0;
|
|
|
|
area.g_w = b->redraw.areas[i].x1 - b->redraw.areas[i].x0;
|
2011-09-19 22:38:48 +04:00
|
|
|
area.g_h = b->redraw.areas[i].y1 - b->redraw.areas[i].y0;
|
2011-05-10 02:10:02 +04:00
|
|
|
if (rc_intersect((GRECT *)&fbwork,(GRECT *)&area)) {
|
2011-08-31 01:38:54 +04:00
|
|
|
b->redraw.area.x0 = area.g_x;
|
|
|
|
b->redraw.area.y0 = area.g_y;
|
|
|
|
b->redraw.area.x1 = area.g_x + area.g_w;
|
|
|
|
b->redraw.area.y1 = area.g_y + area.g_h;
|
2011-05-10 02:10:02 +04:00
|
|
|
browser_redraw_content( gw, 0, 0 );
|
|
|
|
} else {
|
2011-08-31 01:38:54 +04:00
|
|
|
/*
|
2011-05-10 02:10:02 +04:00
|
|
|
the area should be kept scheduled for later redraw, but because this
|
2011-08-31 01:38:54 +04:00
|
|
|
is onscreen plotter, it doesn't make much sense anyway...
|
|
|
|
*/
|
2011-05-10 02:10:02 +04:00
|
|
|
}
|
|
|
|
|
2011-01-06 00:02:22 +03:00
|
|
|
}
|
2011-08-31 01:38:54 +04:00
|
|
|
if (wind_get(gw->root->handle->handle, WF_NEXTXYWH,
|
2011-01-06 00:02:22 +03:00
|
|
|
&todo[0], &todo[1], &todo[2], &todo[3])==0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
vs_clip(plotter->vdi_handle, 0, (short*)&todo);
|
|
|
|
} else {
|
|
|
|
/* its save to do a complete redraw :) */
|
|
|
|
}
|
2011-05-10 02:10:02 +04:00
|
|
|
b->redraw.areas_used = 0;
|
2011-01-06 00:02:22 +03:00
|
|
|
}
|
|
|
|
if( b->caret.redraw == true && b->bw->current_content != NULL ) {
|
|
|
|
GRECT area;
|
|
|
|
todo[0] = bwrect.g_x;
|
|
|
|
todo[1] = bwrect.g_y;
|
|
|
|
todo[2] = todo[0] + bwrect.g_w;
|
|
|
|
todo[3] = todo[1] + bwrect.g_h;
|
|
|
|
area.g_x = bwrect.g_x;
|
|
|
|
area.g_y = bwrect.g_y;
|
|
|
|
area.g_w = bwrect.g_w;
|
|
|
|
area.g_h = bwrect.g_h;
|
|
|
|
vs_clip(plotter->vdi_handle, 1, (short*)&todo[0]);
|
|
|
|
browser_redraw_caret( gw, &area );
|
|
|
|
vs_clip(plotter->vdi_handle, 0, (short*)&todo[0]);
|
|
|
|
b->caret.redraw = false;
|
|
|
|
}
|
2011-01-22 19:23:30 +03:00
|
|
|
plotter->unlock(plotter);
|
2011-01-06 00:02:22 +03:00
|
|
|
/* TODO: if we use offscreen bitmap, trigger content redraw here */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __CDECL browser_evnt_redraw( COMPONENT * c, long buff[8], void * data)
|
2011-08-31 01:38:54 +04:00
|
|
|
{
|
2011-01-06 00:02:22 +03:00
|
|
|
short pxy[8];
|
|
|
|
struct gui_window * gw = (struct gui_window *) data;
|
|
|
|
CMP_BROWSER b = gw->browser;
|
|
|
|
LGRECT work, lclip, rwork;
|
2011-07-01 00:20:27 +04:00
|
|
|
|
|
|
|
// TODO: maybe implement something like validate_gw()
|
|
|
|
// to fetch spurious redraw events? the function should
|
|
|
|
// traverse all gui_windows and see if gw exists in the list
|
|
|
|
|
2011-01-06 00:02:22 +03:00
|
|
|
int xoff,yoff,width,heigth;
|
|
|
|
short cw, ch, cellw, cellh;
|
2011-04-11 01:52:07 +04:00
|
|
|
/* use that instead of browser_find_root() ? */
|
2011-01-06 00:02:22 +03:00
|
|
|
browser_get_rect( gw, BR_CONTENT, &work );
|
|
|
|
lclip = work;
|
|
|
|
if ( !rc_lintersect( (LGRECT*)&buff[4], &lclip ) ) return;
|
2011-11-05 19:18:19 +04:00
|
|
|
|
|
|
|
if( b->bw->current_content == NULL ){
|
|
|
|
short pxy[4];
|
|
|
|
pxy[0] = lclip.g_x;
|
|
|
|
pxy[1] = lclip.g_y;
|
|
|
|
pxy[2] = lclip.g_x + lclip.g_w - 1;
|
|
|
|
pxy[3] = lclip.g_y + lclip.g_h - 1;
|
|
|
|
vsf_color( gw->root->handle->graf->handle, WHITE );
|
|
|
|
vsf_perimeter( gw->root->handle->graf->handle, 0);
|
|
|
|
vsf_interior( gw->root->handle->graf->handle, FIS_SOLID );
|
|
|
|
vsf_style( gw->root->handle->graf->handle, 1);
|
|
|
|
v_bar( gw->root->handle->graf->handle, (short*)&pxy );
|
|
|
|
return;
|
|
|
|
}
|
2011-07-01 00:20:27 +04:00
|
|
|
|
2011-01-06 00:02:22 +03:00
|
|
|
/* convert redraw coords to framebuffer coords: */
|
|
|
|
lclip.g_x -= work.g_x;
|
|
|
|
lclip.g_y -= work.g_y;
|
2011-07-01 00:20:27 +04:00
|
|
|
|
2011-01-06 00:02:22 +03:00
|
|
|
if( lclip.g_x < 0 ) {
|
|
|
|
lclip.g_w = work.g_w + lclip.g_x;
|
|
|
|
lclip.g_x = 0;
|
|
|
|
}
|
2011-07-01 00:20:27 +04:00
|
|
|
|
2011-01-06 00:02:22 +03:00
|
|
|
if( lclip.g_y < 0 ) {
|
|
|
|
lclip.g_h = work.g_h + lclip.g_y;
|
|
|
|
lclip.g_y = 0;
|
|
|
|
}
|
2011-11-05 19:18:19 +04:00
|
|
|
|
2011-07-01 00:20:27 +04:00
|
|
|
|
2011-11-05 19:18:19 +04:00
|
|
|
if( lclip.g_h > 0 && lclip.g_w > 0 ) {
|
2011-07-01 00:20:27 +04:00
|
|
|
browser_schedule_redraw( gw, lclip.g_x, lclip.g_y,
|
|
|
|
lclip.g_x + lclip.g_w, lclip.g_y + lclip.g_h
|
2011-11-05 19:18:19 +04:00
|
|
|
);
|
2011-01-06 00:02:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
2011-05-25 01:44:20 +04:00
|
|
|
}
|