summaryrefslogtreecommitdiff
path: root/atari
diff options
context:
space:
mode:
Diffstat (limited to 'atari')
-rw-r--r--atari/Makefile.target45
-rwxr-xr-xatari/browser.c178
-rwxr-xr-xatari/browser.h23
-rwxr-xr-xatari/browser_win.c589
-rwxr-xr-xatari/clipboard.h6
-rw-r--r--atari/ctxmenu.c4
-rw-r--r--atari/deskmenu.c663
-rw-r--r--atari/deskmenu.h12
-rwxr-xr-xatari/dragdrop.h19
-rwxr-xr-xatari/findfile.c1
-rwxr-xr-xatari/gemtk/dragdrop.c (renamed from atari/dragdrop.c)4
-rwxr-xr-xatari/gemtk/dragdrop.h4
-rw-r--r--atari/gemtk/gemtk.h146
-rw-r--r--atari/gemtk/guiwin.c748
-rw-r--r--atari/gemtk/guiwin.h4
-rw-r--r--atari/gemtk/msgbox.c (renamed from atari/msgbox.c)4
-rw-r--r--atari/gemtk/msgbox.h5
-rw-r--r--atari/gemtk/utils.c45
-rw-r--r--atari/gemtk/utils.h5
-rwxr-xr-xatari/global_evnt.c560
-rwxr-xr-xatari/global_evnt.h23
-rwxr-xr-xatari/gui.c2178
-rwxr-xr-xatari/gui.h15
-rwxr-xr-xatari/history.c96
-rwxr-xr-xatari/history.h3
-rwxr-xr-xatari/hotlist.c104
-rwxr-xr-xatari/hotlist.h3
-rwxr-xr-xatari/misc.c69
-rwxr-xr-xatari/misc.h6
-rw-r--r--atari/msgbox.h10
-rw-r--r--atari/osspec.c35
-rw-r--r--atari/osspec.h28
-rwxr-xr-xatari/plot/plot.c18
-rw-r--r--atari/redrawslots.c30
-rw-r--r--atari/redrawslots.h11
-rwxr-xr-xatari/res/netsurf.rscbin34322 -> 35788 bytes
-rwxr-xr-xatari/res/netsurf.rsh12
-rwxr-xr-xatari/res/netsurf.rsm19
-rwxr-xr-xatari/rootwin.c868
-rwxr-xr-xatari/rootwin.h (renamed from atari/browser_win.h)42
-rwxr-xr-xatari/schedule.c6
-rw-r--r--atari/search.c16
-rw-r--r--atari/settings.c9
-rwxr-xr-xatari/statusbar.c9
-rwxr-xr-xatari/statusbar.h2
-rw-r--r--[-rwxr-xr-x]atari/toolbar.c1155
-rw-r--r--[-rwxr-xr-x]atari/toolbar.h143
-rwxr-xr-xatari/treeview.c994
-rwxr-xr-xatari/treeview.h107
49 files changed, 5059 insertions, 4017 deletions
diff --git a/atari/Makefile.target b/atari/Makefile.target
index ad908075b..9faa52d66 100644
--- a/atari/Makefile.target
+++ b/atari/Makefile.target
@@ -7,7 +7,7 @@
# manually via env. variables, because the m68k-atari-mint
# toolchain is located in /usr/bin and the wildcard matching
# fails then. So this wildcard matches only works for
-# the netsurf environment!
+# the netsurf environment!
STRIP := $(wildcard $(GCCSDK_INSTALL_CROSSBIN)/*strip)
STACK := $(wildcard $(GCCSDK_INSTALL_CROSSBIN)/*stack)
@@ -73,15 +73,42 @@ LDFLAGS += -L$(GCCSDK_INSTALL_ENV)/lib
# S_ATARI are sources purely for the Atari FreeMiNT build
-S_ATARI := gui.c findfile.c filetype.c misc.c bitmap.c schedule.c \
- download.c thumbnail.c login.c verify_ssl.c treeview.c hotlist.c history.c\
+S_ATARI := gui.c \
+ findfile.c \
+ filetype.c \
+ misc.c \
+ bitmap.c \
+ schedule.c \
+ download.c \
+ thumbnail.c \
+ login.c \
+ verify_ssl.c \
+ treeview.c \
+ hotlist.c \
+ history.c\
search.c font.c \
- plot/plot.c plot/fontplot.c plot/eddi.s \
- plot/font_freetype.c plot/font_internal.c \
- redrawslots.c encoding.c \
- browser_win.c toolbar.c statusbar.c browser.c \
- global_evnt.c osspec.c dragdrop.c system_colour.c \
- ctxmenu.c settings.c msgbox.c
+ redrawslots.c \
+ encoding.c \
+ rootwin.c \
+ toolbar.c \
+ statusbar.c \
+ browser.c \
+ global_evnt.c \
+ osspec.c \
+ system_colour.c \
+ ctxmenu.c \
+ settings.c \
+ deskmenu.c \
+ plot/plot.c \
+ plot/fontplot.c \
+ plot/eddi.s \
+ plot/font_freetype.c \
+ plot/font_internal.c \
+ gemtk/utils.c \
+ gemtk/dragdrop.c \
+ gemtk/msgbox.c \
+ gemtk/guiwin.c
+
S_ATARI := $(addprefix atari/,$(S_ATARI))
# This is the final source build list
diff --git a/atari/browser.c b/atari/browser.c
index 034f89a64..d0337f569 100755
--- a/atari/browser.c
+++ b/atari/browser.c
@@ -45,7 +45,7 @@
#include "utils/messages.h"
#include "atari/gui.h"
-#include "atari/browser_win.h"
+#include "atari/rootwin.h"
#include "atari/misc.h"
#include "atari/global_evnt.h"
#include "atari/res/netsurf.rsh"
@@ -62,14 +62,14 @@ extern struct gui_window *input_window;
extern long atari_plot_flags;
extern int atari_plot_vdi_handle;
-static void browser_process_scroll( struct gui_window * gw, LGRECT bwrect );
+static void browser_process_scroll( struct gui_window * gw, GRECT bwrect );
static void browser_redraw_content( struct gui_window * gw, int xoff, int yoff,
struct rect * area );
-static void __CDECL browser_evnt_destroy( COMPONENT * c, long buff[8],
+static void __CDECL browser_evnt_destroy( COMPONENT * c, short buff[8],
void * data);
-static void __CDECL browser_evnt_redraw( COMPONENT * c, long buff[8],
+static void __CDECL browser_evnt_redraw( COMPONENT * c, short buff[8],
void * data);
-static void __CDECL browser_evnt_mbutton( COMPONENT * c, long buff[8],
+static void __CDECL browser_evnt_mbutton( COMPONENT * c, short buff[8],
void * data);
@@ -104,7 +104,9 @@ struct s_browser * browser_create
return(NULL);
}
- /* Attach events to the component: */
+ /* Attach events to the component: */
+ // TODO: implement event chaining in rootwin
+ /*
mt_CompEvntDataAdd( &app, bnew->comp, WM_XBUTTON,
browser_evnt_mbutton, (void*)gw, EV_BOT
);
@@ -113,7 +115,8 @@ struct s_browser * browser_create
);
mt_CompEvntDataAttach( &app, bnew->comp, WM_DESTROY,
browser_evnt_destroy, (void*)bnew
- );
+ );
+ */
/* Set the gui_window owner. */
/* it is an link to the netsurf window system */
@@ -135,76 +138,69 @@ bool browser_destroy( struct s_browser * b )
LOG(("%s\n", b->bw->name ));
assert( b != NULL );
- assert( b->comp != NULL );
assert( b->bw != NULL );
+
+ struct gui_window * gw = b->bw->window;
+ LOG(("%s\n",gw->browser->bw->name));
+
+ assert( b != NULL );
+ assert( gw != NULL );
+ free( b );
+ gw->browser = NULL;
- if( b->comp != NULL ){
- mt_CompDelete(&app, b->comp );
- }
return( true );
}
/*
Query the browser component for widget rectangles.
*/
-void browser_get_rect( struct gui_window * gw, enum browser_rect type, LGRECT * out)
+void browser_get_rect( struct gui_window * gw, enum browser_rect type, GRECT * out)
{
- LGRECT cur;
-
+ GRECT cur;
+
+ // TODO: update browser get grect
/* Query component for it's current size: */
- mt_CompGetLGrect(&app, gw->browser->comp, WF_WORKXYWH, &cur);
-
/* And extract the different widget dimensions: */
- if( type == BR_CONTENT ){
- out->g_w = cur.g_w;
- out->g_h = cur.g_h;
- out->g_x = cur.g_x;
- out->g_y = cur.g_y;
- }
+ if (type == BR_CONTENT ) {
+ guiwin_get_grect(gw->root->win, GUIWIN_AREA_CONTENT, out);
+ }
+ else if (type==BR_URL_INPUT) {
+ // TODO: calculate url input area somehow
+ guiwin_get_grect(gw->root->win, GUIWIN_AREA_TOOLBAR, out);
+ }
+ else if (type==BR_THROBBER) {
+ // TODO: calculate throbber area somehow
+ guiwin_get_grect(gw->root->win, GUIWIN_AREA_TOOLBAR, out);
+ }
- return;
-}
-/* Report an resize to the COMPONENT interface */
-void browser_update_rects(struct gui_window * gw )
-{
- short buff[8];
- 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);
+ return;
}
void browser_set_content_size(struct gui_window * gw, int w, int h)
{
CMP_BROWSER b = gw->browser;
- LGRECT work;
+ GRECT work;
browser_get_rect( gw, BR_CONTENT, &work );
-
- gw->root->handle->xpos_max = w;
- gw->root->handle->ypos_max = h;
-
- if( w < work.g_w + b->scroll.current.x || w < work.g_h + b->scroll.current.y ) {
- /* 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 );
- /* force update of scrollbars: */
- b->scroll.required = true;
- }
+
+ // TODO: implement new content size setter
+ //gw->root->handle->xpos_max = w;
+ //gw->root->handle->ypos_max = h;
+
+// if( w < work.g_w + b->scroll.current.x || w < work.g_h + b->scroll.current.y ) {
+// /* 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 );
+// /* force update of scrollbars: */
+// b->scroll.required = true;
+// }
}
-static void __CDECL browser_evnt_destroy( COMPONENT * c, long buff[8], void * data)
+static void __CDECL browser_evnt_destroy( COMPONENT * c, short buff[8], void * data)
{
struct s_browser * b = (struct s_browser*)data;
- struct gui_window * gw = b->bw->window;
- LOG(("%s\n",gw->browser->bw->name));
- assert( b != NULL );
- assert( gw != NULL );
- free( b );
- gw->browser = NULL;
LOG(("evnt_destroy done!"));
}
@@ -212,10 +208,10 @@ static void __CDECL browser_evnt_destroy( COMPONENT * c, long buff[8], void * da
Mouse Button handler for browser component.
*/
-static void __CDECL browser_evnt_mbutton( COMPONENT * c, long buff[8], void * data)
+static void __CDECL browser_evnt_mbutton( COMPONENT * c, short buff[8], void * data)
{
short mx, my, dummy, mbut;
- LGRECT cwork;
+ GRECT cwork;
browser_mouse_state bmstate = 0;
struct gui_window * gw = data;
@@ -223,8 +219,8 @@ static void __CDECL browser_evnt_mbutton( COMPONENT * c, long buff[8], void * da
input_window = gw;
}
- window_set_focus( gw, BROWSER, (void*)gw->browser );
- browser_get_rect( gw, BR_CONTENT, &cwork );
+ window_set_focus(gw->root, BROWSER, (void*)gw->browser );
+ browser_get_rect(gw, BR_CONTENT, &cwork );
/* convert screen coords to component coords: */
mx = evnt.mx - cwork.g_x;
@@ -309,7 +305,7 @@ static void __CDECL browser_evnt_mbutton( COMPONENT * c, long buff[8], void * da
*/
void browser_scroll( struct gui_window * gw, short mode, int value, bool abs )
{
- LGRECT work;
+ GRECT work;
int max_y_scroll;
int max_x_scroll;
int oldx = gw->browser->scroll.current.x;
@@ -399,7 +395,7 @@ void browser_scroll( struct gui_window * gw, short mode, int value, bool abs )
bwrect -> the dimensions of the browser, so that this function
doesn't need to get it.
*/
-static void browser_process_scroll( struct gui_window * gw, LGRECT bwrect )
+static void browser_process_scroll( struct gui_window * gw, GRECT bwrect )
{
struct s_browser * b = gw->browser;
GRECT src;
@@ -486,11 +482,12 @@ static void browser_process_scroll( struct gui_window * gw, LGRECT bwrect )
if( b->caret.requested.g_w > 0 ){
b->caret.redraw = true;
}
+
+ // TODO: implement new sliding
+ //gw->root->handle->xpos = b->scroll.current.x;
+ //gw->root->handle->ypos = b->scroll.current.y;
- gw->root->handle->xpos = b->scroll.current.x;
- gw->root->handle->ypos = b->scroll.current.y;
-
- mt_WindSlider( &app, gw->root->handle, HSLIDER|VSLIDER );
+ //mt_WindSlider( &app, gw->root->handle, HSLIDER|VSLIDER );
}
/*
@@ -502,7 +499,7 @@ static void browser_process_scroll( struct gui_window * gw, LGRECT bwrect )
*/
bool browser_input( struct gui_window * gw, unsigned short nkc )
{
- LGRECT work;
+ GRECT work;
bool r = false;
unsigned char ascii = (nkc & 0xFF);
long ucs4;
@@ -604,7 +601,7 @@ void browser_schedule_redraw(struct gui_window * gw, short x0, short y0, short x
{
assert( gw != NULL );
CMP_BROWSER b = gw->browser;
- LGRECT work;
+ GRECT work;
if( y1 < 0 || x1 < 0 )
return;
@@ -644,10 +641,10 @@ static void browser_redraw_content( struct gui_window * gw, int xoff, int yoff,
/*
area: the browser canvas
*/
-void browser_restore_caret_background( struct gui_window * gw, LGRECT * area)
+void browser_restore_caret_background( struct gui_window * gw, GRECT * area)
{
CMP_BROWSER b = gw->browser;
- LGRECT rect;
+ GRECT rect;
if( area == NULL ){
browser_get_rect( gw, BR_CONTENT, &rect );
area = &rect;
@@ -668,7 +665,7 @@ void browser_restore_caret_background( struct gui_window * gw, LGRECT * area)
/*
area: the browser canvas
*/
-void browser_redraw_caret( struct gui_window * gw, LGRECT * area )
+void browser_redraw_caret( struct gui_window * gw, GRECT * area )
{
if( gw->browser->caret.redraw && gw->browser->caret.requested.g_w > 0 ){
@@ -677,12 +674,12 @@ void browser_redraw_caret( struct gui_window * gw, LGRECT * area )
/* Only redraw caret when window is topped. */
wind_get( 0, WF_TOP, &wind_info[0], &wind_info[1], &wind_info[2], &wind_info[3]);
- if (gw->root->handle->handle != wind_info[0]) {
+ if (guiwin_get_handle(gw->root->win) != wind_info[0]) {
return;
}
- LGRECT caret;
+ GRECT caret;
struct s_browser * b = gw->browser;
struct rect old_clip;
struct rect clip;
@@ -695,7 +692,7 @@ void browser_redraw_caret( struct gui_window * gw, LGRECT * area )
caret.g_x -= b->scroll.current.x - area->g_x;
caret.g_y -= b->scroll.current.y - area->g_y;
- if( !rc_lintersect( area, &caret ) ) {
+ if( !rc_intersect( area, &caret ) ) {
return;
}
@@ -745,7 +742,7 @@ void browser_redraw_caret( struct gui_window * gw, LGRECT * area )
void browser_redraw( struct gui_window * gw )
{
- LGRECT bwrect;
+ GRECT bwrect;
struct s_browser * b = gw->browser;
short todo[4];
struct rect clip;
@@ -788,7 +785,7 @@ void browser_redraw( struct gui_window * gw )
wind_get( 0, WF_TOP, &wf_top[0], &wf_top[1],
&wf_top[2], &wf_top[3] );
- if( wf_top[0] == gw->root->handle->handle
+ if( wf_top[0] == guiwin_get_handle(gw->root->win)
&& wf_top[1] == _AESapid ){
/* The window is on top, so there is no need to walk the */
/* AES rectangle list. */
@@ -824,8 +821,9 @@ void browser_redraw( struct gui_window * gw )
}
}
} else {
- /* walk the AES rectangle list: */
- if( wind_get(gw->root->handle->handle, WF_FIRSTXYWH,
+ /* walk the AES rectangle list: */
+ short aes_handle = guiwin_get_handle(gw->root->win);
+ if( wind_get(aes_handle, WF_FIRSTXYWH,
&todo[0], &todo[1], &todo[2], &todo[3] )!=0 ) {
while (todo[2] && todo[3]) {
/* convert screen to framebuffer coords: */
@@ -860,9 +858,8 @@ void browser_redraw( struct gui_window * gw )
/* but because this is onscreen plotter, it doesn't */
/* make much sense anyway... */
}
-
}
- if (wind_get(gw->root->handle->handle, WF_NEXTXYWH,
+ if (wind_get(aes_handle, WF_NEXTXYWH,
&todo[0], &todo[1], &todo[2], &todo[3])==0) {
break;
}
@@ -894,7 +891,7 @@ void browser_redraw( struct gui_window * gw )
b->redraw.areas_used = 0;
}
if( b->caret.redraw == true && b->bw->current_content != NULL ) {
- LGRECT area;
+ GRECT area;
todo[0] = bwrect.g_x;
todo[1] = bwrect.g_y;
todo[2] = todo[0] + bwrect.g_w;
@@ -912,27 +909,18 @@ void browser_redraw( struct gui_window * gw )
/* TODO: if we use offscreen bitmap, trigger content redraw here */
}
-static void __CDECL browser_evnt_redraw( COMPONENT * c, long buff[8], void * data)
+static void __CDECL browser_evnt_redraw( COMPONENT * c, short buff[8], void * data)
{
struct gui_window * gw = (struct gui_window *) data;
CMP_BROWSER b = gw->browser;
- LGRECT work, lclip;
+ GRECT work, lclip;
browser_get_rect( gw, BR_CONTENT, &work );
lclip = work;
- if ( !rc_lintersect( (LGRECT*)&buff[4], &lclip ) ) return;
-
- 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 );
+ if ( !rc_intersect( (GRECT*)&buff[4], &lclip ) ) return;
+
+ if( b->bw->current_content == NULL ){
+ guiwin_clear(gw->root->win);
return;
}
@@ -953,13 +941,15 @@ static void __CDECL browser_evnt_redraw( COMPONENT * c, long buff[8], void * dat
if( lclip.g_h > 0 && lclip.g_w > 0 ) {
if( gw->browser->reformat_pending == true ){
- LGRECT newsize;
+ GRECT newsize;
gw->browser->reformat_pending = false;
browser_get_rect(gw, BR_CONTENT, &newsize);
/* this call will also schedule an redraw for the complete */
/* area. */
/* Resize must be handled here, because otherwise */
- /* a redraw is scheduled twice (1. by the frontend, 2. by AES) */
+ /* a redraw is scheduled twice (1. by the frontend, 2. by AES) */
+ // TODO: this was introduced because
+ // of bad knowledge about the AES system...
browser_window_reformat(b->bw, false, newsize.g_w, newsize.g_h );
} else {
browser_schedule_redraw( gw, lclip.g_x, lclip.g_y,
diff --git a/atari/browser.h b/atari/browser.h
index 3eb94374f..e855e591c 100755
--- a/atari/browser.h
+++ b/atari/browser.h
@@ -35,10 +35,9 @@
enum browser_rect
{
- BR_CONTENT = 1,
- BR_FULL = 2,
- BR_HSLIDER = 3,
- BR_VSLIDER = 4
+ BR_CONTENT = 1,
+ BR_URL_INPUT,
+ BR_THROBBER
};
@@ -60,8 +59,8 @@ struct s_scroll_info
*/
struct s_caret
{
- LGRECT requested;
- LGRECT current;
+ GRECT requested;
+ GRECT current;
bool redraw;
MFDB background;
};
@@ -89,17 +88,21 @@ struct s_browser
bool reformat_pending;
};
-struct s_browser * browser_create( struct gui_window * gw, struct browser_window * clone, struct browser_window *bw, int lt, int w, int flex );
+struct s_browser * browser_create( struct gui_window * gw,
+ struct browser_window * clone,
+ struct browser_window *bw, int lt, int w,
+ int flex );
bool browser_destroy( struct s_browser * b );
-void browser_get_rect( struct gui_window * gw, enum browser_rect type, LGRECT * out);
+void browser_get_rect( struct gui_window * gw, enum browser_rect type,
+ GRECT * out);
bool browser_input( struct gui_window * gw, unsigned short nkc ) ;
void browser_redraw( struct gui_window * gw );
void browser_set_content_size(struct gui_window * gw, int w, int h);
void browser_scroll( struct gui_window * gw, short MODE, int value, bool abs );
struct gui_window * browser_find_root( struct gui_window * gw );
bool browser_redraw_required( struct gui_window * gw);
-void browser_redraw_caret( struct gui_window * gw, LGRECT * area);
-void browser_restore_caret_background(struct gui_window * gw, LGRECT * area);
+void browser_redraw_caret( struct gui_window * gw, GRECT * area);
+void browser_restore_caret_background(struct gui_window * gw, GRECT * area);
/* update loc / size of the browser widgets: */
void browser_update_rects(struct gui_window * gw );
/*
diff --git a/atari/browser_win.c b/atari/browser_win.c
deleted file mode 100755
index f6daf37c4..000000000
--- a/atari/browser_win.c
+++ /dev/null
@@ -1,589 +0,0 @@
-/*
- * 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
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include <windom.h>
-#include <assert.h>
-#include <math.h>
-#include <osbind.h>
-
-#include "utils/log.h"
-#include "desktop/gui.h"
-#include "desktop/history_core.h"
-#include "desktop/netsurf.h"
-#include "desktop/browser.h"
-#include "desktop/browser_private.h"
-#include "desktop/mouse.h"
-#include "desktop/plotters.h"
-#include "desktop/textinput.h"
-#include "content/content.h"
-#include "content/hlcache.h"
-#include "content/urldb.h"
-#include "css/css.h"
-#include "atari/gui.h"
-#include "atari/browser_win.h"
-#include "atari/browser.h"
-#include "atari/misc.h"
-#include "atari/plot/plot.h"
-#include "atari/global_evnt.h"
-#include "atari/res/netsurf.rsh"
-#include "atari/browser.h"
-#include "atari/toolbar.h"
-#include "atari/statusbar.h"
-#include "atari/dragdrop.h"
-#include "atari/search.h"
-#include "atari/osspec.h"
-#include "atari/encoding.h"
-#include "atari/toolbar.h"
-
-extern void * h_gem_rsrc;
-extern struct gui_window *input_window;
-
-void __CDECL std_szd( WINDOW * win, short buff[8], void * );
-void __CDECL std_mvd( WINDOW * win, short buff[8], void * );
-
-
-/* -------------------------------------------------------------------------- */
-/* Static module methods follow here: */
-/* -------------------------------------------------------------------------- */
-static void __CDECL evnt_window_icondraw( WINDOW *win, short buff[8], void *data );
-static void __CDECL evnt_window_newtop( WINDOW *win, short buff[8], void *data );
-void __CDECL evnt_window_resize( WINDOW *win, short buff[8], void * data );
-static void __CDECL evnt_window_move( WINDOW *win, short buff[8], void * data );
-static void __CDECL evnt_window_rt_resize( WINDOW *win, short buff[8], void * date );
-static void __CDECL evnt_window_close( WINDOW *win, short buff[8], void *data );
-static void __CDECL evnt_window_dd( WINDOW *win, short wbuff[8], void * data ) ;
-static void __CDECL evnt_window_destroy( WINDOW *win, short buff[8], void *data );
-static void __CDECL evnt_window_slider( WINDOW * win, short buff[8], void * data);
-static void __CDECL evnt_window_arrowed( WINDOW *win, short buff[8], void *data );
-static void __CDECL evnt_window_uniconify( WINDOW *win, short buff[8], void * data );
-static void __CDECL evnt_window_iconify( WINDOW *win, short buff[8], void * data );
-
-/* -------------------------------------------------------------------------- */
-/* Module public functions: */
-/* -------------------------------------------------------------------------- */
-
-
-int window_create( struct gui_window * gw,
- struct browser_window * bw,
- unsigned long inflags )
-{
- int err = 0;
- bool tb, sb;
- int flags;
-
- tb = (inflags & WIDGET_TOOLBAR );
- sb = (inflags & WIDGET_STATUSBAR );
-
- flags = CLOSER | MOVER | NAME | FULLER | SMALLER;
- if( inflags & WIDGET_SCROLL ){
- flags |= (UPARROW | DNARROW | LFARROW | RTARROW | VSLIDE | HSLIDE);
- }
- if( inflags & WIDGET_RESIZE ){
- flags |= ( SIZER );
- }
- if( inflags & WIDGET_STATUSBAR ){
- flags |= ( INFO );
- }
-
- gw->root = malloc( sizeof(struct s_gui_win_root) );
- if( gw->root == NULL )
- return( -1 );
- memset( gw->root, 0, sizeof(struct s_gui_win_root) );
- gw->root->title = malloc(atari_sysinfo.aes_max_win_title_len+1);
- gw->root->handle = WindCreate( flags, 40, 40, app.w, app.h );
- if( gw->root->handle == NULL ) {
- free( gw->root->title );
- free( gw->root );
- return( -1 );
- }
-
- /* set scroll / content granularity ( 1 unit ) */
- gw->root->handle->w_u = 1;
- gw->root->handle->h_u = 1;
-
- /* Create Root component: */
- gw->root->cmproot = mt_CompCreate(&app, CLT_VERTICAL, 1, 1);
- WindSetPtr( gw->root->handle, WF_COMPONENT, gw->root->cmproot, NULL);
-
- /* create toolbar component: */
- if( tb ) {
- gw->root->toolbar = tb_create( gw );
- assert( gw->root->toolbar );
- mt_CompAttach( &app, gw->root->cmproot, gw->root->toolbar->comp );
-
- } else {
- gw->root->toolbar = NULL;
- }
-
- /* create browser component: */
- gw->browser = browser_create( gw, bw, NULL, CLT_HORIZONTAL, 1, 1 );
- mt_CompAttach( &app, gw->root->cmproot, gw->browser->comp );
-
- /* create statusbar component: */
- if( sb ) {
- gw->root->statusbar = sb_create( gw );
-#ifdef WITH_COMOPONENT_STATUSBAR
- mt_CompAttach( &app, gw->root->cmproot, gw->root->statusbar->comp );
-#endif
- } else {
- gw->root->statusbar = NULL;
- }
-
- WindSetStr(gw->root->handle, WF_ICONTITLE, (char*)"NetSurf");
-
- /* Event Handlers: */
- EvntDataAttach( gw->root->handle, WM_CLOSED, evnt_window_close, gw );
- /* capture resize/move events so we can handle that manually */
- EvntDataAdd( gw->root->handle, WM_SIZED, evnt_window_rt_resize, gw, EV_BOT );
- EvntDataAdd( gw->root->handle, WM_MOVED, evnt_window_rt_resize, gw, EV_BOT );
- EvntDataAdd( gw->root->handle, WM_FULLED, evnt_window_rt_resize, gw, EV_BOT );
- EvntDataAdd( gw->root->handle, WM_DESTROY,evnt_window_destroy, gw, EV_TOP );
- EvntDataAdd( gw->root->handle, WM_ARROWED,evnt_window_arrowed, gw, EV_TOP );
- EvntDataAdd( gw->root->handle, WM_NEWTOP, evnt_window_newtop, gw, EV_BOT);
- EvntDataAdd( gw->root->handle, WM_TOPPED, evnt_window_newtop, gw, EV_BOT);
- EvntDataAdd( gw->root->handle, WM_ICONIFY, evnt_window_iconify, gw, EV_BOT);
- EvntDataAdd( gw->root->handle, WM_UNICONIFY, evnt_window_uniconify, gw, EV_BOT);
- EvntDataAttach( gw->root->handle, AP_DRAGDROP, evnt_window_dd, gw );
- EvntDataAttach( gw->root->handle, WM_ICONDRAW, evnt_window_icondraw, gw);
- EvntDataAttach( gw->root->handle, WM_SLIDEXY, evnt_window_slider, gw );
-
- if (inflags & WIN_TOP) {
- window_set_focus( gw, BROWSER, gw->browser);
- }
-
- return (err);
-}
-
-int window_destroy( struct gui_window * gw)
-{
- int err = 0;
-
- search_destroy( gw );
- if( input_window == gw )
- input_window = NULL;
-
- if( gw->root ) {
- if( gw->root->toolbar )
- tb_destroy( gw->root->toolbar );
-
- if( gw->root->statusbar )
- sb_destroy( gw->root->statusbar );
- }
-
- search_destroy( gw );
-
- if( gw->browser )
- browser_destroy( gw->browser );
-
- /* needed? */ /*listRemove( (LINKABLE*)gw->root->cmproot ); */
- if( gw->root ) {
- /* TODO: check if no other browser is bound to this root window! */
- /* only needed for tabs */
- if( gw->root->title )
- free( gw->root->title );
- if( gw->root->cmproot )
- mt_CompDelete( &app, gw->root->cmproot );
- ApplWrite( _AESapid, WM_DESTROY, gw->root->handle->handle, 0, 0, 0, 0);
- EvntWindom( MU_MESAG );
- gw->root->handle = NULL;
- free( gw->root );
- gw->root = NULL;
- }
- return( err );
-}
-
-
-
-void window_open( struct gui_window * gw, GRECT pos )
-{
- LGRECT br;
-
- WindOpen(gw->root->handle, pos.g_x, pos.g_y, pos.g_w, pos.g_h );
- WindClear( gw->root->handle );
- WindSetStr( gw->root->handle, WF_NAME, (char *)"" );
-
- /* apply focus to the root frame: */
- long lfbuff[8] = { CM_GETFOCUS };
- mt_CompEvntExec( gl_appvar, gw->browser->comp, lfbuff );
-
- /* recompute the nested component sizes and positions: */
- browser_update_rects( gw );
- mt_WindGetGrect( &app, gw->root->handle, WF_CURRXYWH, (GRECT*)&gw->root->loc);
- browser_get_rect( gw, BR_CONTENT, &br );
- plot_set_dimensions(br.g_x, br.g_y, br.g_w, br.g_h);
- gw->browser->attached = true;
- if( gw->root->statusbar != NULL ){
- sb_attach(gw->root->statusbar, gw);
- }
- tb_adjust_size( gw );
- /*TBD: get already present content and set size? */
- input_window = gw;
- window_set_focus( gw, BROWSER, gw->browser );
-}
-
-
-
-/* update back forward buttons (see tb_update_buttons (bug) ) */
-void window_update_back_forward( struct gui_window * gw)
-{
- tb_update_buttons( gw, -1 );
-}
-
-void window_set_stauts(struct gui_window * gw , char * text )
-{
- if( gw->root == NULL )
- return;
-
- CMP_STATUSBAR sb = gw->root->statusbar;
-
- if( sb == NULL || gw->browser->attached == false )
- return;
-
- sb_set_text( sb, text );
-}
-
-/* set focus to an arbitary element */
-void window_set_focus( struct gui_window * gw, enum focus_element_type type, void * element )
-{
- if( gw->root->focus.type != type || gw->root->focus.element != element ) {
- LOG(("Set focus: %p (%d)\n", element, type));
- gw->root->focus.type = type;
- gw->root->focus.element = element;
- if( element != NULL ){
- switch( type ){
-
- case URL_WIDGET:
- textarea_keypress(((struct s_url_widget*)(element))->textarea,
- KEY_SELECT_ALL );
- break;
-
- default: break;
-
- }
- }
- }
-}
-
-/* check if the url widget has focus */
-bool window_url_widget_has_focus( struct gui_window * gw )
-{
- assert( gw );
- assert( gw->root );
- if( gw->root->focus.type == URL_WIDGET && gw->root->focus.element != NULL ) {
- assert( ( &gw->root->toolbar->url == (struct s_url_widget*)gw->root->focus.element ) );
- assert( GUIWIN_VISIBLE(gw) );
- return true;
- }
- return false;
-}
-
-/* check if an arbitary window widget / or frame has the focus */
-bool window_widget_has_focus( struct gui_window * gw, enum focus_element_type t, void * element )
-{
- if( gw == NULL )
- return( false );
- if( element == NULL ){
- assert( 1 != 0 );
- return( (gw->root->focus.type == t ) );
- }
- assert( gw->root != NULL );
- return( ( element == gw->root->focus.element && t == gw->root->focus.type) );
-}
-
-void window_set_icon(struct gui_window *gw, struct bitmap * bmp )
-{
- gw->icon = bmp;
- /* redraw window when it is iconyfied: */
- if (gw->icon != NULL) {
- short info, dummy;
- WindGet(gw->root->handle, WF_ICONIFY, &info, &dummy, &dummy, &dummy);
- if (info == 1) {
- window_redraw_favicon(gw, NULL);
- }
- }
-}
-
-
-/**
- * Redraw the favicon
-*/
-void window_redraw_favicon(struct gui_window *gw, GRECT *clip)
-{
- GRECT work;
-
- assert(gw->root);
-
- WINDOW * bw = gw->root->handle;
-
- WindClear(bw);
- WindGet(bw, WF_WORKXYWH, &work.g_x, &work.g_y, &work.g_w, &work.g_h);
- if (clip == NULL) {
- clip = &work;
- }
-
- if (gw->icon == NULL) {
- OBJECT * tree;
- RsrcGaddr( h_gem_rsrc, R_TREE, ICONIFY , &tree);
- tree->ob_x = work.g_x;
- tree->ob_y = work.g_y;
- tree->ob_width = work.g_w;
- tree->ob_height = work.g_h;
- objc_draw(tree, 0, 8, clip->g_x, clip->g_y, clip->g_w, clip->g_h);
- } else {
- // TODO: consider the clipping rectangle
- struct rect work_clip = { 0,0,work.g_w,work.g_h };
- int xoff=0;
- if (work.g_w > work.g_h) {
- xoff = ((work.g_w-work.g_h)/2);
- work.g_w = work.g_h;
- }
- plot_set_dimensions( work.g_x+xoff, work.g_y, work.g_w, work.g_h);
- plot_clip(&work_clip);
- atari_plotters.bitmap(0, 0, work.g_w, work.g_h, gw->icon, 0xffffff, 0);
- }
-}
-
-
-/* -------------------------------------------------------------------------- */
-/* Event Handlers: */
-/* -------------------------------------------------------------------------- */
-
-static void __CDECL evnt_window_arrowed( WINDOW *win, short buff[8], void *data )
-{
- bool abs = false;
- LGRECT cwork;
- struct gui_window * gw = data;
- int value = BROWSER_SCROLL_SVAL;
-
- assert( gw != NULL );
-
- browser_get_rect( gw, BR_CONTENT, &cwork );
-
- switch( buff[4] ) {
- case WA_UPPAGE:
- case WA_DNPAGE:
- value = cwork.g_h;
- break;
-
-
- case WA_LFPAGE:
- case WA_RTPAGE:
- value = cwork.g_w;
- break;
-
- default:
- break;
- }
- browser_scroll( gw, buff[4], value, abs );
-}
-
-
-static void __CDECL evnt_window_dd( WINDOW *win, short wbuff[8], void * data )
-{
- struct gui_window * gw = (struct gui_window *)data;
- char file[DD_NAMEMAX];
- char name[DD_NAMEMAX];
- char *buff=NULL;
- int dd_hdl;
- int dd_msg; /* pipe-handle */
- long size;
- char ext[32];
- short mx,my,bmstat,mkstat;
- graf_mkstate(&mx, &my, &bmstat, &mkstat);
-
- if( gw == NULL )
- return;
- if( (win->status & WS_ICONIFY))
- return;
-
- dd_hdl = ddopen( wbuff[7], DD_OK);
- if( dd_hdl<0)
- return; /* pipe not open */
- memset( ext, 0, 32);
- strcpy( ext, "ARGS");
- dd_msg = ddsexts( dd_hdl, ext);
- if( dd_msg<0)
- goto error;
- dd_msg = ddrtry( dd_hdl, (char*)&name[0], (char*)&file[0], (char*)&ext[0], &size);
- if( size+1 >= PATH_MAX )
- goto error;
- if( !strncmp( ext, "ARGS", 4) && dd_msg > 0)
- {
- ddreply(dd_hdl, DD_OK);
- buff = (char*)malloc(sizeof(char)*(size+1));
- if (buff != NULL)
- {
- if (Fread(dd_hdl, size, buff ) == size)
- buff[size] = 0;
- LOG(("file: %s, ext: %s, size: %d dropped at: %d,%d\n",
- (char*)buff, (char*)&ext,
- size, mx, my
- ));
- {
- LGRECT bwrect;
- struct browser_window * bw = gw->browser->bw;
- browser_get_rect( gw, BR_CONTENT, &bwrect );
- mx = mx - bwrect.g_x;
- my = my - bwrect.g_y;
- if( (mx < 0 || mx > bwrect.g_w) || (my < 0 || my > bwrect.g_h) )
- return;
-
- utf8_convert_ret ret;
- char *utf8_fn;
-
- ret = utf8_from_local_encoding(buff, 0, &utf8_fn);
- if (ret != UTF8_CONVERT_OK) {
- free(buff);
- /* A bad encoding should never happen */
- LOG(("utf8_from_local_encoding failed"));
- assert(ret != UTF8_CONVERT_BADENC);
- /* no memory */
- return;
- }
- browser_window_drop_file_at_point( gw->browser->bw,
- mx+gw->browser->scroll.current.x,
- my+gw->browser->scroll.current.y,
- utf8_fn );
- free(utf8_fn);
- free(buff);
- }
- }
- }
-error:
- ddclose( dd_hdl);
-}
-
-static void __CDECL evnt_window_destroy( WINDOW *win, short buff[8], void *data )
-{
- LOG(("%s\n", __FUNCTION__ ));
-}
-
-static void __CDECL evnt_window_close( WINDOW *win, short buff[8], void *data )
-{
- struct gui_window * gw = (struct gui_window *) data ;
- if( gw != NULL ) {
- browser_window_destroy( gw->browser->bw );
- }
-}
-
-
-static void __CDECL evnt_window_newtop( WINDOW *win, short buff[8], void *data )
-{
- input_window = (struct gui_window *) data;
- window_set_focus( input_window, BROWSER, input_window->browser );
- LOG(("newtop gui window: %p, WINDOW: %p", input_window, win ));
- assert( input_window != NULL );
-}
-
-static void __CDECL evnt_window_slider( WINDOW * win, short buff[8], void * data)
-{
- int dx = buff[4];
- int dy = buff[5];
- struct gui_window * gw = data;
-
- if (!dx && !dy) return;
-
- if( input_window == NULL || input_window != gw ) {
- return;
- }
-
- /* update the sliders _before_ we call redraw
- (which might depend on the slider possitions) */
- WindSlider( win, (dx?HSLIDER:0) | (dy?VSLIDER:0) );
-
- if( dy > 0 )
- browser_scroll( gw, WA_DNPAGE, abs(dy), false );
- else if ( dy < 0)
- browser_scroll( gw, WA_UPPAGE, abs(dy), false );
- if( dx > 0 )
- browser_scroll( gw, WA_RTPAGE, abs(dx), false );
- else if( dx < 0 )
- browser_scroll( gw, WA_LFPAGE, abs(dx), false );
-}
-
-static void __CDECL evnt_window_uniconify( WINDOW *win, short buff[8], void * data )
-{
- struct gui_window * gw = (struct gui_window *)data;
-
- input_window = gw;
- WindTop( gw->root->handle );
- window_set_focus( gw, BROWSER, gw->browser );
-}
-
-static void __CDECL evnt_window_iconify( WINDOW *win, short buff[8], void * data )
-{
- struct gui_window * gw = (struct gui_window *)data;
- if( input_window == gw){
- input_window = NULL;
- }
-}
-
-
-static void __CDECL evnt_window_icondraw(WINDOW *win, short buff[8], void * data)
-{
- struct gui_window *gw = (struct gui_window*) data;
- GRECT clip = {buff[4], buff[5], buff[6], buff[7]};
- window_redraw_favicon(gw, &clip);
-}
-
-/* perform the actual resize */
-static void __CDECL evnt_window_rt_resize( WINDOW *win, short buff[8], void * data )
-{
- short x,y,w,h;
- struct gui_window * gw;
-
- wind_get( win->handle, WF_CURRXYWH, &x, &y, &w, &h );
- gw = (struct gui_window *)data;
-
- assert( gw != NULL );
-
- if(gw->root->loc.g_w != w || gw->root->loc.g_h != h ){
- /* report resize to component interface: */
- browser_update_rects( gw );
- tb_adjust_size( gw );
- if( gw->browser->bw->current_content != NULL ){
- /* Reformat will happen when next redraw message arrives: */
- gw->browser->reformat_pending = true;
- if( sys_XAAES() ){
- if( gw->root->loc.g_w > w || gw->root->loc.g_h > h ){
- ApplWrite( _AESapid, WM_REDRAW, gw->root->handle->handle,
- gw->root->loc.g_x, gw->root->loc.g_y,
- gw->root->loc.g_w, gw->root->loc.g_h );
- }
- }
- mt_WindGetGrect( &app, gw->root->handle, WF_CURRXYWH,
- (GRECT*)&gw->root->loc);
- }
- else {
- WindClear( gw->root->handle );
- }
- } else {
- if(gw->root->loc.g_x != x || gw->root->loc.g_y != y ){
- mt_WindGetGrect( &app, gw->root->handle, WF_CURRXYWH, (GRECT*)&gw->root->loc);
- browser_update_rects( gw );
- }
- }
-}
diff --git a/atari/clipboard.h b/atari/clipboard.h
index e505d9f6d..aa032b7fd 100755
--- a/atari/clipboard.h
+++ b/atari/clipboard.h
@@ -17,9 +17,11 @@
*/
#ifndef NS_ATARI_CLIPBOARD_H
-#define NS_ATARI_CLIPBOARD_H
+#define NS_ATARI_CLIPBOARD_H
+
+#include <windom.h>
int scrap_txt_write( APPvar app, char *str);
char *scrap_txt_read( APPvar app );
-#endif \ No newline at end of file
+#endif
diff --git a/atari/ctxmenu.c b/atari/ctxmenu.c
index 1a1755b12..66c4b7f65 100644
--- a/atari/ctxmenu.c
+++ b/atari/ctxmenu.c
@@ -41,7 +41,7 @@
#include "atari/gui.h"
#include "atari/browser.h"
-#include "atari/browser_win.h"
+#include "atari/rootwin.h"
#include "atari/misc.h"
#include "atari/clipboard.h"
#include "desktop/options.h"
@@ -68,7 +68,7 @@ struct s_context_info ctxinfo;
static struct s_context_info * get_context_info( struct gui_window * gw, short mx, short my )
{
hlcache_handle *h;
- LGRECT bwrect;
+ GRECT bwrect;
struct contextual_content ccdata;
struct browser_window * bw = gw->browser->bw;
diff --git a/atari/deskmenu.c b/atari/deskmenu.c
new file mode 100644
index 000000000..2502184cd
--- /dev/null
+++ b/atari/deskmenu.c
@@ -0,0 +1,663 @@
+#include <stdlib.h>
+#include <windom.h>
+
+#include "utils/log.h"
+#include "utils/messages.h"
+#include "utils/url.h"
+#include "desktop/browser.h"
+#include "desktop/browser_private.h"
+#include "desktop/options.h"
+#include "desktop/save_complete.h"
+
+#include "atari/res/netsurf.rsh"
+#include "atari/gemtk/gemtk.h"
+#include "atari/deskmenu.h"
+#include "atari/hotlist.h"
+#include "atari/history.h"
+#include "atari/toolbar.h"
+#include "atari/settings.h"
+#include "atari/search.h"
+#include "atari/misc.h"
+#include "atari/gui.h"
+#include "atari/findfile.h"
+#include "atari/browser.h"
+#include "atari/rootwin.h"
+
+typedef void __CDECL (*menu_evnt_func)(short item, short title, void * data);
+
+struct s_accelerator
+{
+ char ascii; /* either ascii or */
+ long keycode; /* normalised keycode is valid */
+ short mod; /* shift / ctrl etc */
+};
+
+struct s_menu_item_evnt {
+ short title; /* to which menu this item belongs */
+ short rid; /* resource ID */
+ menu_evnt_func menu_func; /* click handler */
+ struct s_accelerator accel; /* accelerator info */
+ char * menustr;
+};
+
+static void register_menu_str(struct s_menu_item_evnt * mi);
+static void __CDECL evnt_menu(WINDOW * win, short buff[8]);
+
+extern void *h_gem_rsrc;
+extern bool html_redraw_debug;
+extern struct gui_window * input_window;
+extern char options[PATH_MAX];
+extern const char * option_homepage_url;
+extern int option_window_width;
+extern int option_window_height;
+extern int option_window_x;
+extern int option_window_y;
+
+static OBJECT * h_gem_menu;
+
+
+/* Zero based resource tree ids: */
+#define T_ABOUT 0
+#define T_FILE MAINMENU_T_FILE - MAINMENU_T_FILE + 1
+#define T_EDIT MAINMENU_T_EDIT - MAINMENU_T_FILE + 1
+#define T_VIEW MAINMENU_T_VIEW - MAINMENU_T_FILE + 1
+#define T_NAV MAINMENU_T_NAVIGATE - MAINMENU_T_FILE + 1
+#define T_UTIL MAINMENU_T_UTIL - MAINMENU_T_FILE + 1
+#define T_HELP MAINMENU_T_NAVIGATE - MAINMENU_T_FILE + 1
+/* Count of the above defines: */
+#define NUM_MENU_TITLES 7
+
+
+static void __CDECL menu_about(short item, short title, void *data);
+static void __CDECL menu_new_win(short item, short title, void *data);
+static void __CDECL menu_open_url(short item, short title, void *data);
+static void __CDECL menu_open_file(short item, short title, void *data);
+static void __CDECL menu_close_win(short item, short title, void *data);
+static void __CDECL menu_save_page(short item, short title, void *data);
+static void __CDECL menu_quit(short item, short title, void *data);
+static void __CDECL menu_cut(short item, short title, void *data);
+static void __CDECL menu_copy(short item, short title, void *data);
+static void __CDECL menu_paste(short item, short title, void *data);
+static void __CDECL menu_find(short item, short title, void *data);
+static void __CDECL menu_choices(short item, short title, void *data);
+static void __CDECL menu_stop(short item, short title, void *data);
+static void __CDECL menu_reload(short item, short title, void *data);
+static void __CDECL menu_toolbars(short item, short title, void *data);
+static void __CDECL menu_savewin(short item, short title, void *data);
+static void __CDECL menu_debug_render(short item, short title, void *data);
+static void __CDECL menu_fg_images(short item, short title, void *data);
+static void __CDECL menu_bg_images(short item, short title, void *data);
+static void __CDECL menu_back(short item, short title, void *data);
+static void __CDECL menu_forward(short item, short title, void *data);
+static void __CDECL menu_home(short item, short title, void *data);
+static void __CDECL menu_lhistory(short item, short title, void *data);
+static void __CDECL menu_ghistory(short item, short title, void *data);
+static void __CDECL menu_add_bookmark(short item, short title, void *data);
+static void __CDECL menu_bookmarks(short item, short title, void *data);
+static void __CDECL menu_vlog(short item, short title, void *data);
+static void __CDECL menu_help_content(short item, short title, void *data);
+
+struct s_menu_item_evnt menu_evnt_tbl[] =
+{
+ {T_ABOUT,MAINMENU_M_ABOUT, menu_about, {0,0,0}, NULL },
+ {T_FILE, MAINMENU_M_NEWWIN, menu_new_win, {0,0,0}, NULL},
+ {T_FILE, MAINMENU_M_OPENURL, menu_open_url, {'G',0,K_CTRL}, NULL},
+ {T_FILE, MAINMENU_M_OPENFILE, menu_open_file, {'O',0,K_CTRL}, NULL},
+ {T_FILE, MAINMENU_M_CLOSEWIN, menu_close_win, {0,0,0}, NULL},
+ {T_FILE, MAINMENU_M_SAVEPAGE, menu_save_page, {0,NK_F3,0}, NULL},
+ {T_FILE, MAINMENU_M_QUIT, menu_quit, {'Q',0,K_CTRL}, NULL},
+ {T_EDIT, MAINMENU_M_CUT, menu_cut, {'X',0,K_CTRL}, NULL},
+ {T_EDIT, MAINMENU_M_COPY, menu_copy, {'C',0,K_CTRL}, NULL},
+ {T_EDIT, MAINMENU_M_PASTE, menu_paste, {'V',0,K_CTRL}, NULL},
+ {T_EDIT, MAINMENU_M_FIND, menu_find, {0,NK_F4,0}, NULL},
+ {T_VIEW, MAINMENU_M_RELOAD, menu_reload, {0,NK_F5,0}, NULL},
+ {T_VIEW, MAINMENU_M_TOOLBARS, menu_toolbars, {0,NK_F1,K_CTRL}, NULL},
+ {T_VIEW, MAINMENU_M_SAVEWIN, menu_savewin, {0,0,0}, NULL},
+ {T_VIEW, MAINMENU_M_DEBUG_RENDER, menu_debug_render, {0,0,0}, NULL},
+ {T_VIEW, MAINMENU_M_FG_IMAGES, menu_fg_images, {0,0,0}, NULL},
+ {T_VIEW, MAINMENU_M_BG_IMAGES, menu_bg_images, {0,0,0}, NULL},
+ {T_VIEW, MAINMENU_M_STOP, menu_stop, {0,NK_ESC,K_ALT}, NULL},
+ {T_NAV, MAINMENU_M_BACK, menu_back, {0,NK_LEFT,K_ALT}, NULL},
+ {T_NAV, MAINMENU_M_FORWARD, menu_forward, {0,NK_RIGHT,K_ALT}, NULL},
+ {T_NAV, MAINMENU_M_HOME, menu_home, {0,NK_CLRHOME,0}, NULL},
+ {T_UTIL, MAINMENU_M_LHISTORY,menu_lhistory, {0,NK_F7,0}, NULL},
+ {T_UTIL, MAINMENU_M_GHISTORY, menu_ghistory, {0,NK_F7,K_CTRL}, NULL},
+ {T_UTIL, MAINMENU_M_ADD_BOOKMARK, menu_add_bookmark, {'D',0,K_CTRL}, NULL},
+ {T_UTIL, MAINMENU_M_BOOKMARKS, menu_bookmarks, {0,NK_F6,0}, NULL},
+ {T_UTIL, MAINMENU_M_CHOICES, menu_choices, {0,0,0}, NULL},
+ {T_UTIL, MAINMENU_M_VLOG, menu_vlog, {'V',0,K_ALT}, NULL},
+ {T_HELP, MAINMENU_M_HELP_CONTENT, menu_help_content, {0,NK_F1,0}, NULL},
+ {-1, -1, NULL,{0,0,0}, NULL }
+};
+
+
+/*
+ Parse encoded menu key shortcut
+
+ The format is:
+
+ "[" - marks start of the shortcut
+ "@,^,<" - If the keyshortcut is only valid
+ with modifier keys, one of these characters must directly
+ follow the start mark.
+ Meaning:
+ @ -> Alternate
+ ^ -> Control
+ "#" - keycode or ascii character.
+ The value is handled as keycode if the character value
+ is <= 28 ( Atari chracter table )
+ or if it is interpreted as function key string.
+ (strings: F1 - F10)
+
+*/
+static void register_menu_str( struct s_menu_item_evnt * mi )
+{
+ OBJECT *gem_menu = deskmenu_get_obj_tree();
+
+ assert(gem_menu != NULL);
+
+ char * str = ObjcString( gem_menu, mi->rid, NULL );
+ int l = strlen(str);
+ int i = l;
+ int x = -1;
+ struct s_accelerator * accel = &mi->accel;
+
+ while (i > 2) {
+ if( str[i] == '['){
+ x = i;
+ break;
+ }
+ i--;
+ }
+ if( x > -1 ){
+ mi->menustr = malloc( l+1 );
+ strcpy(mi->menustr, str );
+ mi->menustr[x]=' ';
+ x++;
+ if( str[x] == '@' ){
+ accel->mod = K_ALT;
+ mi->menustr[x] = 0x07;
+ x++;
+ }
+ else if( str[x] == '^' ) {
+ accel->mod = K_CTRL;
+ x++;
+ }
+ if( str[x] <= 28 ){
+ // parse symbol
+ unsigned short keycode=0;
+ switch( str[x] ){
+ case 0x03:
+ accel->keycode = NK_RIGHT;
+ break;
+ case 0x04:
+ accel->keycode = NK_LEFT;
+ break;
+ case 0x1B:
+ accel->keycode = NK_ESC;
+ break;
+ default:
+ break;
+ }
+ } else {
+ if(str[x] == 'F' && ( str[x+1] >= '1' && str[x+1] <= '9') ){
+ // parse function key
+ short fkey = atoi( &str[x+1] );
+ if( (fkey >= 0) && (fkey <= 10) ){
+ accel->keycode = NK_F1 - 1 + fkey;
+ }
+ } else {
+ accel->ascii = str[x];
+ }
+ }
+ }
+}
+
+static void __CDECL evnt_menu(WINDOW * win, short buff[8])
+{
+ int title = buff[3];
+ INT16 x,y;
+ char *str;
+ struct gui_window * gw = window_list;
+ int i=0;
+
+ deskmenu_dispatch_item(buff[3], buff[4]);
+}
+
+/*
+ Menu item event handlers:
+*/
+
+static void __CDECL menu_about(short item, short title, void *data)
+{
+ LOG(("%s", __FUNCTION__));
+ char buf[PATH_MAX];
+ strcpy((char*)&buf, "file://");
+ strncat((char*)&buf, (char*)"./doc/README.TXT",
+ PATH_MAX - (strlen("file://")+1) );
+ browser_window_create((char*)&buf, 0, 0, true, false);
+}
+
+static void __CDECL menu_new_win(short item, short title, void *data)
+{
+ LOG(("%s", __FUNCTION__));
+ browser_window_create(option_homepage_url, 0, 0, true, false);
+}
+
+static void __CDECL menu_open_url(short item, short title, void *data)
+{
+ struct gui_window * gw;
+ struct browser_window * bw ;
+ LOG(("%s", __FUNCTION__));
+
+ gw = input_window;
+ if( gw == NULL ) {
+ bw = browser_window_create("", 0, 0, true, false);
+ gw = bw->window;
+ }
+ /* Loose focus: */
+ window_set_focus(gw->root, WIDGET_NONE, NULL );
+
+ /* trigger on-focus event (select all text): */
+ window_set_focus(gw->root, URL_WIDGET, NULL);
+
+ /* delete selection: */
+ toolbar_key_input(gw->root->toolbar, NK_DEL);
+}
+
+static void __CDECL menu_open_file(short item, short title, void *data)
+{
+ struct gui_window * gw;
+ struct browser_window * bw ;
+
+ LOG(("%s", __FUNCTION__));
+
+ const char * filename = file_select(messages_get("OpenFile"), "");
+ if( filename != NULL ){
+ char * url = local_file_to_url( filename );
+ if( url ){
+ bw = browser_window_create(url, NULL, NULL, true, false);
+ free( url );
+ }
+ }
+}
+
+static void __CDECL menu_close_win(short item, short title, void *data)
+{
+ LOG(("%s", __FUNCTION__));
+ if( input_window == NULL )
+ return;
+ gui_window_destroy( input_window );
+}
+
+static void __CDECL menu_save_page(short item, short title, void *data)
+{
+ LOG(("%s", __FUNCTION__));
+ static bool init = true;
+ bool is_folder=false;
+ const char * path;
+
+ if( !input_window )
+ return;
+
+ if( init ){
+ init = false;
+ save_complete_init();
+ }
+
+ do {
+ // TODO: localize string
+ path = file_select("Select folder", "");
+ if (path)
+ is_folder = is_dir(path);
+ } while( !is_folder && path != NULL );
+
+ if( path != NULL ){
+ save_complete( input_window->browser->bw->current_content, path, NULL );
+ }
+
+}
+
+static void __CDECL menu_quit(short item, short title, void *data)
+{
+ short buff[8];
+ memset( &buff, 0, sizeof(short)*8 );
+ LOG(("%s", __FUNCTION__));
+ netsurf_quit = true;
+}
+
+static void __CDECL menu_cut(short item, short title, void *data)
+{
+ if( input_window != NULL )
+ browser_window_key_press( input_window->browser->bw, KEY_CUT_SELECTION);
+}
+
+static void __CDECL menu_copy(short item, short title, void *data)
+{
+ LOG(("%s", __FUNCTION__));
+ if( input_window != NULL )
+ browser_window_key_press( input_window->browser->bw, KEY_COPY_SELECTION);
+}
+
+static void __CDECL menu_paste(short item, short title, void *data)
+{
+ LOG(("%s", __FUNCTION__));
+ if( input_window != NULL )
+ browser_window_key_press( input_window->browser->bw, KEY_PASTE);
+}
+
+static void __CDECL menu_find(short item, short title, void *data)
+{
+ LOG(("%s", __FUNCTION__));
+ if( input_window != NULL )
+ open_browser_search( input_window );
+}
+
+static void __CDECL menu_choices(short item, short title, void *data)
+{
+ static WINDOW * settings_dlg = NULL;
+ LOG(("%s", __FUNCTION__));
+ settings_dlg = open_settings();
+}
+
+static void __CDECL menu_stop(short item, short title, void *data)
+{
+ LOG(("%s", __FUNCTION__));
+ if( input_window == NULL )
+ return;
+
+ assert(input_window->root);
+ toolbar_stop_click(input_window->root->toolbar);
+
+}
+
+static void __CDECL menu_reload(short item, short title, void *data)
+{
+ if(input_window == NULL)
+ return;
+ toolbar_reload_click(input_window->root->toolbar);
+ LOG(("%s", __FUNCTION__));
+}
+
+static void __CDECL menu_toolbars(short item, short title, void *data)
+{
+ static int state = 0;
+ LOG(("%s", __FUNCTION__));
+ if( input_window != null && input_window->root->toolbar != null ){
+ state = !state;
+ // TODO: implement toolbar hide
+ //toolbar_hide(input_window->root->toolbar, state );
+ }
+}
+
+static void __CDECL menu_savewin(short item, short title, void *data)
+{
+ LOG(("%s", __FUNCTION__));
+ if (input_window && input_window->browser) {
+ GRECT rect;
+ wind_get_grect(guiwin_get_handle(input_window->root->win), WF_CURRXYWH,
+ &rect);
+ option_window_width = rect.g_w;
+ option_window_height = rect.g_h;
+ option_window_x = rect.g_x;
+ option_window_y = rect.g_y;
+ nsoption_set_int(window_width, rect.g_w);
+ nsoption_set_int(window_height, rect.g_h);
+ nsoption_set_int(window_x, rect.g_x);
+ nsoption_set_int(window_y, rect.g_y);
+ nsoption_write((const char*)&options);
+ }
+
+}
+
+static void __CDECL menu_debug_render(short item, short title, void *data)
+{
+ LOG(("%s", __FUNCTION__));
+ html_redraw_debug = !html_redraw_debug;
+ if( input_window != NULL ) {
+ if ( input_window->browser != NULL
+ && input_window->browser->bw != NULL) {
+ GRECT rect;
+ browser_get_rect( input_window, BR_CONTENT, &rect );
+ browser_window_reformat(input_window->browser->bw, false,
+ rect.g_w, rect.g_h );
+ MenuIcheck(NULL, MAINMENU_M_DEBUG_RENDER,
+ (html_redraw_debug) ? 1 : 0 );
+ }
+ }
+}
+
+static void __CDECL menu_fg_images(short item, short title, void *data)
+{
+ nsoption_set_bool(foreground_images, !nsoption_bool(foreground_images));
+ MenuIcheck( NULL, MAINMENU_M_FG_IMAGES,
+ (nsoption_bool(foreground_images)) ? 1 : 0);
+}
+
+static void __CDECL menu_bg_images(short item, short title, void *data)
+{
+ nsoption_set_bool(background_images, !nsoption_bool(background_images));
+ MenuIcheck( NULL, MAINMENU_M_BG_IMAGES,
+ (nsoption_bool(background_images)) ? 1 : 0);
+}
+
+static void __CDECL menu_back(short item, short title, void *data)
+{
+ LOG(("%s", __FUNCTION__));
+ if( input_window == NULL )
+ return;
+ toolbar_back_click(input_window->root->toolbar);
+}
+
+static void __CDECL menu_forward(short item, short title, void *data)
+{
+ LOG(("%s", __FUNCTION__));
+ if( input_window == NULL )
+ return;
+ toolbar_forward_click(input_window->root->toolbar);
+}
+
+static void __CDECL menu_home(short item, short title, void *data)
+{
+ LOG(("%s", __FUNCTION__));
+ if( input_window == NULL )
+ return;
+ toolbar_home_click(input_window->root->toolbar);
+}
+
+static void __CDECL menu_lhistory(short item, short title, void *data)
+{
+ LOG(("%s", __FUNCTION__));
+ if( input_window == NULL )
+ return;
+}
+
+static void __CDECL menu_ghistory(short item, short title, void *data)
+{
+ LOG(("%s", __FUNCTION__));
+ global_history_open();
+}
+
+static void __CDECL menu_add_bookmark(short item, short title, void *data)
+{
+ LOG(("%s", __FUNCTION__));
+ if (input_window) {
+ if( input_window->browser->bw->current_content != NULL ){
+ atari_hotlist_add_page(
+ nsurl_access(hlcache_handle_get_url(input_window->browser->bw->current_content)),
+ NULL
+ );
+ }
+ }
+}
+
+static void __CDECL menu_bookmarks(short item, short title, void *data)
+{
+ LOG(("%s", __FUNCTION__));
+ hotlist_open();
+}
+
+static void __CDECL menu_vlog(short item, short title, void *data)
+{
+ LOG(("%s", __FUNCTION__));
+ verbose_log = !verbose_log;
+ MenuIcheck(NULL, MAINMENU_M_VLOG, (verbose_log) ? 1 : 0 );
+}
+
+static void __CDECL menu_help_content(short item, short title, void *data)
+{
+ LOG(("%s", __FUNCTION__));
+}
+
+/*
+ Public deskmenu interface:
+*/
+
+
+/**
+* Setup & display an desktop menu.
+*/
+
+void deskmenu_init(void)
+{
+ int i;
+
+ h_gem_menu = get_tree(MAINMENU);
+
+ // TODO: remove that call somehow...
+
+ /* parse and update menu items: */
+ i = 0;
+ while( menu_evnt_tbl[i].rid != -1 ) {
+ char * str = ObjcString(h_gem_menu, menu_evnt_tbl[i].rid, NULL );
+ register_menu_str( &menu_evnt_tbl[i] );
+ /* Update menu string if not null: */
+ if( menu_evnt_tbl[i].menustr != NULL ){
+ menu_text(h_gem_menu, menu_evnt_tbl[i].rid,
+ menu_evnt_tbl[i].menustr);
+ }
+ i++;
+ }
+ deskmenu_update();
+
+ /* Install menu: */
+ menu_bar(h_gem_menu, MENU_INSTALL);
+ /* Redraw menu: */
+ menu_bar(h_gem_menu, MENU_UPDATE);
+}
+
+/**
+* Uninstall the desktop menu
+*/
+void deskmenu_destroy(void)
+{
+ int i;
+
+ /* Remove menu from desktop: */
+ menu_bar(h_gem_menu, MENU_REMOVE);
+
+ /* Free modified menu titles: */
+ i=0;
+ while(menu_evnt_tbl[i].rid != -1) {
+ if( menu_evnt_tbl[i].menustr != NULL )
+ free(menu_evnt_tbl[i].menustr);
+ i++;
+ }
+}
+
+/**
+* Return the deskmenu AES OBJECT tree
+*/
+OBJECT * deskmenu_get_obj_tree(void)
+{
+ return(h_gem_menu);
+}
+
+/**
+* Handle an menu item event
+*/
+int deskmenu_dispatch_item(short title, short item)
+{
+ int i=0;
+ int retval = 0;
+ OBJECT * menu_root = deskmenu_get_obj_tree();
+
+ menu_tnormal(menu_root, item, 1);
+ menu_tnormal(menu_root, title, 1);
+ menu_bar(menu_root, 1);
+
+ // legacy code, is this sensible?:
+ /*
+ while( gw ) {
+ window_set_focus( gw, WIDGET_NONE, NULL );
+ gw = gw->next;
+ }
+ */
+
+
+ while (menu_evnt_tbl[i].rid != -1) {
+ if (menu_evnt_tbl[i].rid == item) {
+ if (menu_evnt_tbl[i].menu_func != NULL) {
+ menu_evnt_tbl[i].menu_func(item, title, NULL);
+ }
+ break;
+ }
+ i++;
+ }
+
+ return(retval);
+}
+
+/**
+* Handle an keypress (check for accelerator)
+*/
+int deskmenu_dispatch_keypress(unsigned short kcode, unsigned short kstate,
+ unsigned short nkc)
+{
+ char sascii;
+ bool done = 0;
+ int i = 0;
+
+ sascii = keybd2ascii(kcode, K_LSHIFT);
+
+ /* Iterate through the menu function table: */
+ while( menu_evnt_tbl[i].rid != -1 && done == false) {
+ if( kstate == menu_evnt_tbl[i].accel.mod
+ && menu_evnt_tbl[i].accel.ascii != 0) {
+ if( menu_evnt_tbl[i].accel.ascii == sascii) {
+ deskmenu_dispatch_item(menu_evnt_tbl[i].title,
+ menu_evnt_tbl[i].rid);
+ done = true;
+ break;
+ }
+ } else {
+ /* the accel code hides in the keycode: */
+ if( menu_evnt_tbl[i].accel.keycode != 0) {
+ if( menu_evnt_tbl[i].accel.keycode == (nkc & 0xFF) &&
+ kstate == menu_evnt_tbl[i].accel.mod) {
+ deskmenu_dispatch_item(menu_evnt_tbl[i].title,
+ menu_evnt_tbl[i].rid);
+ done = true;
+ break;
+ }
+ }
+ }
+ i++;
+ }
+ return((done==true) ? 1 : 0);
+}
+
+/**
+* Refresh the desk menu, reflecting netsurf current state.
+*/
+void deskmenu_update(void)
+{
+ OBJECT * gem_menu = deskmenu_get_obj_tree();
+
+ menu_icheck(gem_menu, MAINMENU_M_DEBUG_RENDER, (html_redraw_debug) ? 1 : 0);
+ menu_icheck(gem_menu, MAINMENU_M_FG_IMAGES,
+ (nsoption_bool(foreground_images)) ? 1 : 0);
+ menu_icheck(gem_menu, MAINMENU_M_BG_IMAGES,
+ (nsoption_bool(background_images)) ? 1 : 0);
+}
+
diff --git a/atari/deskmenu.h b/atari/deskmenu.h
new file mode 100644
index 000000000..6ab00dcc9
--- /dev/null
+++ b/atari/deskmenu.h
@@ -0,0 +1,12 @@
+#ifndef DESKMENU_H_INCLUDED
+#define DESKMENU_H_INCLUDED
+
+void deskmenu_init(void);
+void deskmenu_destroy(void);
+int deskmenu_dispatch_item(short title, short item);
+int deskmenu_dispatch_keypress(unsigned short kcode, unsigned short kstate,
+ unsigned short nkc);
+OBJECT * deskmenu_get_obj_tree(void);
+void deskmenu_update( void );
+
+#endif // DESKMENU_H_INCLUDED
diff --git a/atari/dragdrop.h b/atari/dragdrop.h
deleted file mode 100755
index dccd3e371..000000000
--- a/atari/dragdrop.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
-* MultiTOS Drag&Drop Header file
-*/
-
-/*
-* Declarations
-*/
-
-short ddcreate(short *pipe);
-short ddmessage(short apid, short fd, short winid, short mx, short my, short kstate, short pipename);
-short ddrexts(short fd, char *exts);
-short ddstry(short fd, char *ext, char *text, char *name, long size);
-void ddclose(short fd);
-void ddgetsig(long *oldsig);
-void ddsetsig(long oldsig);
-short ddopen(short ddnam, char ddmsg);
-short ddsexts(short fd, char *exts);
-short ddrtry(short fd, char *name, char *file, char *whichext, long *size);
-short ddreply(short fd, char ack);
diff --git a/atari/findfile.c b/atari/findfile.c
index 93bf4638e..00502c9e6 100755
--- a/atari/findfile.c
+++ b/atari/findfile.c
@@ -28,6 +28,7 @@
#include "utils/log.h"
#include "utils/url.h"
+#include "atari/gemtk/gemtk.h"
#include "atari/findfile.h"
#include "atari/gui.h"
#include "atari/misc.h"
diff --git a/atari/dragdrop.c b/atari/gemtk/dragdrop.c
index bc7f5659b..d9fd9c723 100755
--- a/atari/dragdrop.c
+++ b/atari/gemtk/dragdrop.c
@@ -18,8 +18,8 @@
#include <string.h>
#include <stdio.h>
-#include "windom.h"
-#include "dragdrop.h"
+//#include "windom.h"
+#include "gemtk.h"
#include "cflib.h"
#ifndef EACCDN
diff --git a/atari/gemtk/dragdrop.h b/atari/gemtk/dragdrop.h
new file mode 100755
index 000000000..38466137b
--- /dev/null
+++ b/atari/gemtk/dragdrop.h
@@ -0,0 +1,4 @@
+#ifndef DD_H_INCLUDED
+#define DD_H_INCLUDED
+
+#endif
diff --git a/atari/gemtk/gemtk.h b/atari/gemtk/gemtk.h
new file mode 100644
index 000000000..ddcad785a
--- /dev/null
+++ b/atari/gemtk/gemtk.h
@@ -0,0 +1,146 @@
+#ifndef GEMTK_H_INCLUDED
+#define GEMTK_H_INCLUDED
+
+#include <gem.h>
+#include <mint/osbind.h>
+#include <mint/cookie.h>
+#include <stdint.h>
+#include <stdbool.h>
+
+/* System type detection added by [GS] */
+/* detect the system type, AES + kernel */
+#define SYS_TOS 0x0001
+#define SYS_MAGIC 0x0002
+#define SYS_MINT 0x0004
+#define SYS_GENEVA 0x0010
+#define SYS_NAES 0x0020
+#define SYS_XAAES 0x0040
+#define sys_type() (_systype_v ? _systype_v : _systype())
+#define sys_MAGIC() ((sys_type() & SYS_MAGIC) != 0)
+#define sys_NAES() ((sys_type() & SYS_NAES) != 0)
+#define sys_XAAES() ((sys_type() & SYS_XAAES) != 0)
+
+#define TOS4VER 0x03300 /* this is assumed to be the last single tasking OS */
+
+extern unsigned short _systype_v;
+
+/*
+ Utils
+*/
+unsigned short _systype (void);
+OBJECT *get_tree( int idx );
+
+/*
+* MultiTOS Drag&Drop
+*/
+short ddcreate(short *pipe);
+short ddmessage(short apid, short fd, short winid, short mx, short my, short kstate, short pipename);
+short ddrexts(short fd, char *exts);
+short ddstry(short fd, char *ext, char *text, char *name, long size);
+void ddclose(short fd);
+void ddgetsig(long *oldsig);
+void ddsetsig(long oldsig);
+short ddopen(short ddnam, char ddmsg);
+short ddsexts(short fd, char *exts);
+short ddrtry(short fd, char *name, char *file, char *whichext, long *size);
+short ddreply(short fd, char ack);
+
+/*
+ Message box
+*/
+#define MSG_BOX_ALERT 1
+#define MSG_BOX_CONFIRM 2
+
+short msg_box_show(short type, const char * msg);
+
+/*
+ Guiwin
+*/
+#define GW_FLAG_PREPROC_WM 0x01 // let guiwin API handle some events
+#define GW_FLAG_RECV_PREPROC_WM 0x02 // get notified even when pre-processed
+#define GW_FLAG_HAS_VTOOLBAR 0x04 // the attached toolbar is vertical
+#define GW_FLAG_CUSTOM_TOOLBAR 0x08 // no internal toolbar handling
+#define GW_FLAG_TOOLBAR_REDRAW 0x10 // enable internal toolbar redraw
+#define GW_FLAG_CUSTOM_SCROLLING 0x20 // no internal scroller handling
+
+#define GW_FLAG_DEFAULTS (GW_FLAG_PREPROC_WM | GW_FLAG_RECV_PREPROC_WM \
+ | GW_FLAG_TOOLBAR_REDRAW)
+
+#define GW_STATUS_ICONIFIED 0x01
+#define GW_STATUS_SHADED 0x02
+
+#define GUIWIN_VSLIDER 0x01
+#define GUIWIN_HSLIDER 0x02
+#define GUIWIN_VH_SLIDER 0x03
+
+struct gui_window_s;
+typedef struct gui_window_s GUIWIN;
+typedef short (*guiwin_event_handler_f)(GUIWIN *gw,
+ EVMULT_OUT *ev_out, short msg[8]);
+struct guiwin_scroll_info_s {
+ int x_unit_px;
+ int y_unit_px;
+ int x_pos;
+ int y_pos;
+ int x_units;
+ int y_units;
+};
+
+enum guwin_area_e {
+ GUIWIN_AREA_WORK = 0,
+ GUIWIN_AREA_TOOLBAR,
+ GUIWIN_AREA_CONTENT
+};
+
+short guiwin_init(void);
+void guiwin_exit(void);
+GUIWIN * guiwin_add(short handle, uint32_t flags,
+ guiwin_event_handler_f handler);
+GUIWIN *guiwin_find(short handle);
+short guiwin_remove(GUIWIN *win);
+GUIWIN *guiwin_validate_ptr(GUIWIN *win);
+short guiwin_dispatch_event(EVMULT_IN *ev_in, EVMULT_OUT *ev_out,
+ short msg[8]);
+void guiwin_get_grect(GUIWIN *win, enum guwin_area_e mode, GRECT *dest);
+short guiwin_get_handle(GUIWIN *win);
+uint32_t guiwin_get_state(GUIWIN *win);
+void guiwin_set_toolbar(GUIWIN *win, OBJECT *toolbar, short idx,
+ uint32_t flags);
+void guiwin_set_event_handler(GUIWIN *win,guiwin_event_handler_f cb);
+void guiwin_set_user_data(GUIWIN *win, void *data);
+void *guiwin_get_user_data(GUIWIN *win);
+struct guiwin_scroll_info_s * guiwin_get_scroll_info(GUIWIN *win);
+bool guiwin_update_slider(GUIWIN *win, short mode);
+void guiwin_send_redraw(GUIWIN *win, GRECT *area);
+VdiHdl guiwin_get_vdi_handle(GUIWIN *win);
+bool guiwin_has_intersection(GUIWIN *win, GRECT *work);
+void guiwin_toolbar_redraw(GUIWIN *win, GRECT *clip);
+void guiwin_clear(GUIWIN *win);
+
+
+/*
+* AES Scroller Object
+*/
+
+#ifndef POINT_WITHIN
+#define POINT_WITHIN(_x,_y, r) ((_x >= r.g_x) && (_x <= r.g_x + r.g_w ) \
+ && (_y >= r.g_y) && (_y <= r.g_y + r.g_h))
+#endif
+
+#ifndef RC_WITHIN
+#define RC_WITHIN(a,b) \
+ (((a)->g_x >= (b)->g_x) \
+ && (((a)->g_x + (a)->g_w) <= ((b)->g_x + (b)->g_w))) \
+ && (((a)->g_y >= (b)->g_y) \
+ && (((a)->g_y + (a)->g_h) <= ((b)->g_y + (b)->g_h)))
+#endif
+
+#ifndef MAX
+#define MAX(_a,_b) ((_a>_b) ? _a : _b)
+#endif
+
+#ifndef MIN
+#define MIN(_a,_b) ((_a<_b) ? _a : _b)
+#endif
+
+#endif // GEMTK_H_INCLUDED
diff --git a/atari/gemtk/guiwin.c b/atari/gemtk/guiwin.c
new file mode 100644
index 000000000..7f06c91da
--- /dev/null
+++ b/atari/gemtk/guiwin.c
@@ -0,0 +1,748 @@
+//#include "global.h"
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <assert.h>
+#include <cflib.h>
+
+
+#include <gem.h>
+#include <mt_gem.h>
+#include "gemtk.h"
+
+//#define DEBUG_PRINT(x) printf x
+#define DEBUG_PRINT(x)
+
+struct gui_window_s {
+ short handle;
+ guiwin_event_handler_f handler_func;
+ uint32_t flags;
+ uint32_t state;
+ OBJECT * toolbar;
+ short toolbar_idx;
+ struct guiwin_scroll_info_s scroll_info;
+ void *user_data;
+ struct gui_window_s *next, *prev;
+};
+
+static GUIWIN * winlist;
+static VdiHdl v_vdi_h = -1;
+static short work_out[57];
+
+static void move_rect(GUIWIN * win, GRECT *rect, int dx, int dy)
+{
+ INT16 xy[ 8];
+ long dum = 0L;
+ GRECT g;
+
+ VdiHdl vh = guiwin_get_vdi_handle(win);
+
+ while(!wind_update(BEG_UPDATE));
+ graf_mouse(M_OFF, 0L);
+
+ /* get intersection with screen area */
+ wind_get_grect(0, WF_CURRXYWH, &g);
+ rc_intersect(&g, rect);
+ xy[0] = rect->g_x;
+ xy[1] = rect->g_y;
+ xy[2] = xy[0] + rect->g_w-1;
+ xy[3] = xy[1] + rect->g_h-1;
+ xy[4] = xy[0] + dx;
+ xy[5] = xy[1] + dy;
+ xy[6] = xy[2] + dx;
+ xy[7] = xy[3] + dy;
+ vro_cpyfm(vh, S_ONLY, xy, (MFDB *)&dum, (MFDB *)&dum);
+
+ graf_mouse(M_ON, 0L);
+ wind_update(END_UPDATE);
+}
+
+static void preproc_scroll(GUIWIN *gw, short orientation, int units,
+ bool refresh)
+{
+ struct guiwin_scroll_info_s *slid = guiwin_get_scroll_info(gw);
+ int oldpos = 0, newpos = 0, vis_units=0, pix = 0;
+ int abs_pix = 0;
+ GRECT *redraw=NULL, g, g_ro;
+
+ guiwin_get_grect(gw, GUIWIN_AREA_CONTENT, &g);
+ g_ro = g;
+
+ if (orientation == GUIWIN_VSLIDER) {
+ pix = units*slid->y_unit_px;
+ abs_pix = abs(pix);
+ oldpos = slid->y_pos;
+ vis_units = g.g_h/slid->y_unit_px;
+ newpos = slid->y_pos = MIN(slid->y_units-vis_units,
+ MAX(0, slid->y_pos+units));
+ if(oldpos == newpos)
+ return;
+ if (units>=vis_units || guiwin_has_intersection(gw, &g_ro)) {
+ // send complete redraw
+ redraw = &g_ro;
+ } else {
+ // only adjust ypos when scrolling down:
+ if(pix < 0 ) {
+ // blit screen area:
+ g.g_h -= abs_pix;
+ move_rect(gw, &g, 0, abs_pix);
+ g.g_y = g_ro.g_y;
+ g.g_h = abs_pix;
+ redraw = &g;
+ } else {
+ // blit screen area:
+ g.g_y += abs_pix;
+ g.g_h -= abs_pix;
+ move_rect(gw, &g, 0, -abs_pix);
+ g.g_y = g_ro.g_y + g_ro.g_h - abs_pix;
+ g.g_h = abs_pix;
+ redraw = &g;
+ }
+ }
+ } else {
+ pix = units*slid->x_unit_px;
+ abs_pix = abs(pix);
+ oldpos = slid->x_pos;
+ vis_units = g.g_w/slid->x_unit_px;
+ newpos = slid->x_pos = MIN(slid->x_units-vis_units,
+ MAX(0, slid->x_pos+units));
+ if(oldpos == newpos)
+ return;
+ if (units>=vis_units || guiwin_has_intersection(gw, &g_ro)) {
+ // send complete redraw
+ redraw = &g_ro;
+ } else {
+ // only adjust ypos when scrolling down:
+ if(pix < 0 ) {
+ // blit screen area:
+ g.g_w -= abs_pix;
+ move_rect(gw, &g, abs_pix, 0);
+ g.g_x = g_ro.g_x;
+ g.g_w = abs_pix;
+ redraw = &g;
+ } else {
+ // blit screen area:
+ g.g_x += abs_pix;
+ g.g_w -= abs_pix;
+ move_rect(gw, &g, -abs_pix, 0);
+ g.g_x = g_ro.g_x + g_ro.g_w - abs_pix;
+ g.g_w = abs_pix;
+ redraw = &g;
+ }
+ }
+ }
+
+ if (refresh) {
+ guiwin_update_slider(gw, orientation);
+ }
+
+ if ((redraw != NULL) && (redraw->g_h > 0)) {
+ guiwin_send_redraw(gw, redraw);
+ }
+}
+
+static short preproc_wm(GUIWIN * gw, EVMULT_OUT *ev_out, short msg[8])
+{
+ GRECT g, g_ro, g2;
+ short retval = 1;
+ int val = 1, old_val;
+ struct guiwin_scroll_info_s *slid;
+
+ switch(msg[0]) {
+
+ case WM_HSLID:
+ guiwin_get_grect(gw, GUIWIN_AREA_CONTENT, &g);
+ wind_set(gw->handle, WF_HSLIDE, msg[4], 0, 0, 0);
+ slid = guiwin_get_scroll_info(gw);
+ val = (float)(slid->x_units-(g.g_w/slid->x_unit_px))/1000*(float)msg[4];
+ if(val != slid->x_pos) {
+ if (val < slid->x_pos) {
+ val = -(MAX(0, slid->x_pos-val));
+ }
+ else {
+ val = val-slid->x_pos;
+ }
+ preproc_scroll(gw, GUIWIN_HSLIDER, val, false);
+ }
+ break;
+
+ case WM_VSLID:
+ guiwin_get_grect(gw, GUIWIN_AREA_CONTENT, &g);
+ wind_set(gw->handle, WF_VSLIDE, msg[4], 0, 0, 0);
+ slid = guiwin_get_scroll_info(gw);
+ val = (float)(slid->y_units-(g.g_h/slid->y_unit_px))/1000*(float)msg[4];
+ if(val != slid->y_pos) {
+ if (val < slid->y_pos) {
+ val = -(slid->y_pos - val);
+ }
+ else {
+ val = val -slid->y_pos;
+ }
+ preproc_scroll(gw, GUIWIN_VSLIDER, val, false);
+ }
+ break;
+
+ case WM_ARROWED:
+ if((gw->flags & GW_FLAG_CUSTOM_SCROLLING) == 0) {
+
+ slid = guiwin_get_scroll_info(gw);
+ guiwin_get_grect(gw, GUIWIN_AREA_CONTENT, &g);
+ g_ro = g;
+
+ switch(msg[4]) {
+
+ case WA_UPPAGE:
+ /* scroll page up */
+ preproc_scroll(gw, GUIWIN_VSLIDER, -(g.g_h/slid->y_unit_px),
+ true);
+ break;
+
+ case WA_UPLINE:
+ /* scroll line up */
+ preproc_scroll(gw, GUIWIN_VSLIDER, -1, true);
+ break;
+
+ case WA_DNPAGE:
+ /* scroll page down */
+ preproc_scroll(gw, GUIWIN_VSLIDER, g.g_h/slid->y_unit_px,
+ true);
+ break;
+
+ case WA_DNLINE:
+ /* scroll line down */
+ preproc_scroll(gw, GUIWIN_VSLIDER, +1, true);
+ break;
+
+ case WA_LFPAGE:
+ /* scroll page left */
+ preproc_scroll(gw, GUIWIN_HSLIDER, -(g.g_w/slid->x_unit_px),
+ true);
+ break;
+
+ case WA_LFLINE:
+ /* scroll line left */
+ preproc_scroll(gw, GUIWIN_HSLIDER, -1,
+ true);
+ break;
+
+ case WA_RTPAGE:
+ /* scroll page right */
+ preproc_scroll(gw, GUIWIN_HSLIDER, (g.g_w/slid->x_unit_px),
+ true);
+ break;
+
+ case WA_RTLINE:
+ /* scroll line right */
+ preproc_scroll(gw, GUIWIN_HSLIDER, 1,
+ true);
+ break;
+
+ default:
+ break;
+ }
+ }
+ break;
+
+ case WM_TOPPED:
+ wind_set(gw->handle, WF_TOP, 1, 0, 0, 0);
+ break;
+
+ case WM_MOVED:
+ wind_get_grect(gw->handle, WF_CURRXYWH, &g);
+ wind_set(gw->handle, WF_CURRXYWH, msg[4], msg[5], g.g_w, g.g_h);
+ break;
+
+ case WM_SIZED:
+ case WM_REPOSED:
+ wind_get_grect(gw->handle, WF_CURRXYWH, &g);
+ wind_set(gw->handle, WF_CURRXYWH, g.g_x, g.g_y, msg[6], msg[7]);
+ if((gw->flags & GW_FLAG_CUSTOM_SCROLLING) == 0) {
+ if(guiwin_update_slider(gw, GUIWIN_VH_SLIDER)) {
+ guiwin_send_redraw(gw, NULL);
+ }
+ }
+ break;
+
+ case WM_FULLED:
+ wind_get_grect(gw->handle, WF_FULLXYWH, &g);
+ wind_get_grect(gw->handle, WF_CURRXYWH, &g2);
+ if(g.g_w == g2.g_w && g.g_h == g2.g_h){
+ wind_get_grect(gw->handle, WF_PREVXYWH, &g);
+ }
+ wind_set_grect(gw->handle, WF_CURRXYWH, &g);
+ if((gw->flags & GW_FLAG_CUSTOM_SCROLLING) == 0) {
+ if(guiwin_update_slider(gw, GUIWIN_VH_SLIDER)) {
+ guiwin_send_redraw(gw, NULL);
+ }
+ }
+ break;
+
+ case WM_ICONIFY:
+ wind_set(gw->handle, WF_ICONIFY, msg[4], msg[5], msg[6], msg[7]);
+ gw->state |= GW_STATUS_ICONIFIED;
+ break;
+
+ case WM_UNICONIFY:
+ wind_set(gw->handle, WF_UNICONIFY, msg[4], msg[5], msg[6], msg[7]);
+ gw->state &= ~(GW_STATUS_ICONIFIED);
+ break;
+
+ case WM_SHADED:
+ gw->state |= GW_STATUS_SHADED;
+ break;
+
+ case WM_UNSHADED:
+ gw->state &= ~(GW_STATUS_SHADED);
+ break;
+
+ case WM_REDRAW:
+ if ((gw->flags & GW_FLAG_TOOLBAR_REDRAW)
+ && (gw->flags & GW_FLAG_CUSTOM_TOOLBAR) == 0) {
+ g.g_x = msg[4];
+ g.g_y = msg[5];
+ g.g_w = msg[6];
+ g.g_h = msg[7];
+ guiwin_toolbar_redraw(gw, &g);
+ }
+ break;
+
+ default:
+ retval = 0;
+ break;
+
+ }
+
+ return(retval);
+}
+
+short guiwin_dispatch_event(EVMULT_IN *ev_in, EVMULT_OUT *ev_out, short msg[8])
+{
+ GUIWIN *dest;
+ short retval = 0;
+ bool handler_called = false;
+
+ if( (ev_out->emo_events & MU_MESAG) != 0 ) {
+ DEBUG_PRINT(("guiwin_handle_event_multi_fast: %d\n", msg[0]));
+ switch (msg[0]) {
+ case WM_REDRAW:
+ case WM_CLOSED:
+ case WM_TOPPED:
+ case WM_ARROWED:
+ case WM_HSLID:
+ case WM_VSLID:
+ case WM_FULLED:
+ case WM_SIZED:
+ case WM_REPOSED:
+ case WM_MOVED:
+ case WM_NEWTOP:
+ case WM_UNTOPPED:
+ case WM_ONTOP:
+ case WM_BOTTOM:
+ case WM_ICONIFY:
+ case WM_UNICONIFY:
+ case WM_ALLICONIFY:
+ case WM_TOOLBAR:
+ case AP_DRAGDROP:
+ case AP_TERM:
+ case AP_TFAIL:
+ dest = guiwin_find(msg[3]);
+ if (dest) {
+ DEBUG_PRINT(("Found WM_ dest: %p (%d), flags: %d, cb: %p\n", dest, dest->handle, dest->flags, dest->handler_func));
+ if (dest->flags&GW_FLAG_PREPROC_WM) {
+ retval = preproc_wm(dest, ev_out, msg);
+ if(((retval == 0)||(dest->flags&GW_FLAG_RECV_PREPROC_WM))) {
+ retval = dest->handler_func(dest, ev_out, msg);
+ handler_called = true;
+ }
+ } else {
+ if (dest->handler_func) {
+ retval = dest->handler_func(dest, ev_out, msg);
+ handler_called = true;
+ }
+ }
+
+ }
+ break;
+ }
+ } else {
+
+ short info[4];
+ wind_get( 0, WF_TOP, &info[0], &info[1], &info[2], &info[3]);
+
+ if(info[0] != 0 && info[1] == gl_apid) {
+
+ dest = guiwin_find(info[0]);
+
+ if(dest == NULL || dest->handler_func == NULL)
+ return(0);
+
+ if( (ev_out->emo_events & MU_BUTTON) != 0) {
+ DEBUG_PRINT(("Found MU_BUTTON dest: %p (%d), flags: %d, cb: %p\n", dest, dest->handle, dest->flags, dest->handler_func));
+
+ // toolbar handling:
+ if((dest->flags & GW_FLAG_CUSTOM_TOOLBAR) == 0
+ && dest->toolbar != NULL) {
+ GRECT tb_area;
+ guiwin_get_grect(dest, GUIWIN_AREA_TOOLBAR, &tb_area);
+ if (POINT_WITHIN(ev_out->emo_mouse.p_x,
+ ev_out->emo_mouse.p_y, tb_area)) {
+ // send WM_TOOLBAR message
+ dest->toolbar[dest->toolbar_idx].ob_x = tb_area.g_x;
+ dest->toolbar[dest->toolbar_idx].ob_y = tb_area.g_y;
+ short obj_idx = objc_find(dest->toolbar,
+ dest->toolbar_idx, 8,
+ ev_out->emo_mouse.p_x,
+ ev_out->emo_mouse.p_y);
+ short msg_out[8] = {WM_TOOLBAR, gl_apid, 0, dest->handle,
+ obj_idx, ev_out->emo_mclicks, ev_out->emo_kmeta, 0
+ };
+ if (((dest->flags & GW_FLAG_CUSTOM_TOOLBAR) == 0)
+ && obj_idx > 0) {
+ dest->toolbar[obj_idx].ob_state |= OS_SELECTED;
+ // TODO: optimize redraw by setting the object clip:
+ guiwin_toolbar_redraw(dest, NULL);
+ }
+ short oldevents = ev_out->emo_events;
+ ev_out->emo_events = MU_MESAG;
+ // notify the window about toolbar click:
+ dest->handler_func(dest, ev_out, msg_out);
+ handler_called=true;
+ ev_out->emo_events = oldevents;
+ retval = 1;
+ }
+ }
+ }
+ if (handler_called==false) {
+ dest->handler_func(dest, ev_out, msg);
+ }
+ }
+ }
+
+ return(retval);
+}
+
+short guiwin_init(void)
+{
+ if(v_vdi_h == -1) {
+ short dummy;
+ static short work_in[12] = {1,1,1,1,1,1,1,1,1,1,2,1};
+ v_vdi_h=graf_handle(&dummy, &dummy, &dummy, &dummy);
+ v_opnvwk(work_in, &v_vdi_h, work_out);
+ }
+ return(0);
+}
+
+void guiwin_exit(void)
+{
+ v_clsvwk(v_vdi_h);
+}
+
+GUIWIN * guiwin_add(short handle, uint32_t flags, guiwin_event_handler_f cb)
+{
+
+ GUIWIN *win = calloc(sizeof(GUIWIN),1);
+
+ assert(win!=NULL);
+ DEBUG_PRINT(("guiwin_add: %d, %p, cb: %p\n", handle, win, cb));
+
+ win->handle = handle;
+ win->handler_func = cb;
+ win->flags = flags;
+ if (winlist == NULL) {
+ winlist = win;
+ win->next = NULL;
+ win->prev = NULL;
+ } else {
+ GUIWIN *tmp = winlist;
+ while( tmp->next != NULL ) {
+ tmp = tmp->next;
+ }
+ tmp->next = win;
+ win->prev = tmp;
+ win->next = NULL;
+ }
+ return(win);
+}
+
+GUIWIN *guiwin_find(short handle)
+{
+ GUIWIN *g;
+ DEBUG_PRINT(("guiwin search handle: %d\n", handle));
+ for( g = winlist; g != NULL; g=g->next ) {
+ if(g->handle == handle) {
+ DEBUG_PRINT(("guiwin found handle: %p\n", g));
+ return(g);
+ }
+ }
+ return(NULL);
+}
+
+GUIWIN *guiwin_validate_ptr(GUIWIN *win)
+{
+ GUIWIN *g;
+ for( g = winlist; g != NULL; g=g->next ) {
+ DEBUG_PRINT(("guiwin guiwin_validate_ptr check: %p\n", g));
+ if(g == win) {
+ DEBUG_PRINT(("guiwin_validate_ptr valid: %p\n", g));
+ return(g);
+ }
+ }
+ return(NULL);
+}
+
+short guiwin_remove(GUIWIN *win)
+{
+ win = guiwin_validate_ptr(win);
+ if (win == NULL)
+ return(-1);
+
+ /* unlink the window: */
+ if(win->prev != NULL ) {
+ win->prev->next = win->next;
+ } else {
+ winlist = win->next;
+ }
+ if (win->next != NULL) {
+ win->next->prev = win->prev;
+ }
+ DEBUG_PRINT(("guiwin free: %p\n", win));
+ free(win);
+ return(0);
+}
+
+void guiwin_get_grect(GUIWIN *win, enum guwin_area_e mode, GRECT *dest)
+{
+ wind_get_grect(win->handle, WF_WORKXYWH, dest);
+ if (mode == GUIWIN_AREA_CONTENT) {
+ GRECT tb_area;
+ guiwin_get_grect(win, GUIWIN_AREA_TOOLBAR, &tb_area);
+ if (win->flags & GW_FLAG_HAS_VTOOLBAR) {
+ dest->g_x += tb_area.g_w;
+ dest->g_w -= tb_area.g_w;
+ } else {
+ dest->g_y += tb_area.g_h;
+ dest->g_h -= tb_area.g_h;
+ }
+ } else if (mode == GUIWIN_AREA_TOOLBAR) {
+ if (win->toolbar != NULL) {
+ if (win->flags & GW_FLAG_HAS_VTOOLBAR) {
+ dest->g_w = win->toolbar[win->toolbar_idx].ob_width;
+ } else {
+ dest->g_h = win->toolbar[win->toolbar_idx].ob_height;
+ }
+ } else {
+ dest->g_h = 0;
+ dest->g_w = 0;
+ }
+ }
+}
+
+bool guiwin_update_slider(GUIWIN *win, short mode)
+{
+ GRECT viewport;
+ struct guiwin_scroll_info_s * slid;
+ unsigned long size, pos;
+ int old_x, old_y;
+
+ short handle = guiwin_get_handle(win);
+ guiwin_get_grect(win, GUIWIN_AREA_CONTENT, &viewport);
+ slid = guiwin_get_scroll_info(win);
+
+ old_x = slid->x_pos;
+ old_y = slid->y_pos;
+
+ if((mode & GUIWIN_VSLIDER) && (slid->y_unit_px > 0)) {
+ if ( slid->y_units < (long)viewport.g_h/slid->y_unit_px) {
+ size = 1000L;
+ } else
+ size = MAX( 50L, (unsigned long)viewport.g_h*1000L/
+ (unsigned long)(slid->y_unit_px*slid->y_units));
+ wind_set(handle, WF_VSLSIZE, (int)size, 0, 0, 0);
+
+ if (slid->y_units > (long)viewport.g_h/slid->y_unit_px) {
+ pos = (unsigned long)slid->y_pos *1000L/
+ (unsigned long)(slid->y_units-viewport.g_h/slid->y_unit_px);
+ wind_set(handle, WF_VSLIDE, (int)pos, 0, 0, 0);
+ } else if (slid->y_pos) {
+ slid->y_pos = 0;
+ wind_set(handle, WF_VSLIDE, 0, 0, 0, 0);
+ }
+ }
+ if((mode & GUIWIN_HSLIDER) && (slid->x_unit_px > 0)) {
+ if ( slid->x_units < (long)viewport.g_w/slid->x_unit_px)
+ size = 1000L;
+ else
+ size = MAX( 50L, (unsigned long)viewport.g_w*1000L/
+ (unsigned long)(slid->x_unit_px*slid->x_units));
+ wind_set(handle, WF_HSLSIZE, (int)size, 0, 0, 0);
+
+ if( slid->x_units > (long)viewport.g_w/slid->x_unit_px) {
+ pos = (unsigned long)slid->x_pos*1000L/
+ (unsigned long)(slid->x_units-viewport.g_w/slid->x_unit_px);
+ wind_set(handle, WF_HSLIDE, (int)pos, 0, 0, 0);
+ } else if (slid->x_pos) {
+ slid->x_pos = 0;
+ wind_set(handle, WF_HSLIDE, 0, 0, 0, 0);
+ }
+ }
+
+ if(old_x != slid->x_pos || old_y != slid->y_pos) {
+ return(true);
+ }
+ return(false);
+}
+
+short guiwin_get_handle(GUIWIN *win)
+{
+ return(win->handle);
+}
+
+VdiHdl guiwin_get_vdi_handle(GUIWIN *win)
+{
+ return(v_vdi_h);
+}
+
+uint32_t guiwin_get_state(GUIWIN *win)
+{
+ return(win->state);
+}
+
+void guiwin_set_event_handler(GUIWIN *win,guiwin_event_handler_f cb)
+{
+ win->handler_func = cb;
+}
+
+void guiwin_set_toolbar(GUIWIN *win, OBJECT *toolbar, short idx, uint32_t flags)
+{
+ win->toolbar = toolbar;
+ win->toolbar_idx = idx;
+ if(flags & GW_FLAG_HAS_VTOOLBAR) {
+ win->flags |= GW_FLAG_HAS_VTOOLBAR;
+ }
+}
+
+void guiwin_set_user_data(GUIWIN *win, void *data)
+{
+ win->user_data = data;
+}
+
+void *guiwin_get_user_data(GUIWIN *win)
+{
+ return(win->user_data);
+}
+
+struct guiwin_scroll_info_s *guiwin_get_scroll_info(GUIWIN *win) {
+ return(&win->scroll_info);
+}
+
+void guiwin_send_redraw(GUIWIN *win, GRECT *area)
+{
+ short msg[8];
+ GRECT work;
+
+ if(area == NULL) {
+ guiwin_get_grect(win, GUIWIN_AREA_WORK, &work);
+ area = &work;
+ }
+
+ msg[0] = WM_REDRAW;
+ msg[1] = gl_apid;
+ msg[2] = 0;
+ msg[3] = win->handle;
+ msg[4] = area->g_x;
+ msg[5] = area->g_y;
+ msg[6] = area->g_w;
+ msg[7] = area->g_h;
+
+ appl_write(gl_apid, 16, &msg);
+}
+
+
+
+bool guiwin_has_intersection(GUIWIN *win, GRECT *work)
+{
+ GRECT area, mywork;
+ bool retval = true;
+
+ if (work == NULL) {
+ guiwin_get_grect(win, GUIWIN_AREA_CONTENT, &mywork);
+ work = &mywork;
+ }
+
+ wind_get_grect(win->handle, WF_FIRSTXYWH, &area);
+ while (area.g_w && area.g_w) {
+ //GRECT * ptr = &area;
+ if (RC_WITHIN(work, &area)) {
+ retval = false;
+ }
+ wind_get_grect(win->handle, WF_NEXTXYWH, &area);
+ }
+
+ return(retval);
+}
+
+void guiwin_toolbar_redraw(GUIWIN *gw, GRECT *clip)
+{
+ GRECT tb_area, tb_area_ro, g;
+
+ guiwin_get_grect(gw, GUIWIN_AREA_TOOLBAR, &tb_area_ro);
+
+ if(clip == NULL) {
+ clip = &tb_area_ro;
+ }
+
+ tb_area = tb_area_ro;
+
+ if(rc_intersect(clip, &tb_area)) {
+
+ // Update object position:
+ gw->toolbar[gw->toolbar_idx].ob_x = tb_area_ro.g_x;
+ gw->toolbar[gw->toolbar_idx].ob_width = tb_area_ro.g_w;
+ gw->toolbar[gw->toolbar_idx].ob_y = tb_area_ro.g_y;
+ gw->toolbar[gw->toolbar_idx].ob_height = tb_area_ro.g_h;
+
+ wind_get_grect(gw->handle, WF_FIRSTXYWH, &g);
+ while (g.g_h > 0 || g.g_w > 0) {
+ if(rc_intersect(&tb_area, &g)) {
+ objc_draw(gw->toolbar, gw->toolbar_idx, 8, g.g_x, g.g_y,
+ g.g_w, g.g_h);
+
+ }
+ wind_get_grect(gw->handle, WF_NEXTXYWH, &g);
+ }
+ }
+}
+
+void guiwin_clear(GUIWIN *win)
+{
+ GRECT area, g;
+ short pxy[4];
+ VdiHdl vh;
+
+ vh = guiwin_get_vdi_handle(win);
+
+ if(win->state & GW_STATUS_ICONIFIED){
+ // also clear the toolbar area when iconified:
+ guiwin_get_grect(win, GUIWIN_AREA_WORK, &area);
+ } else {
+ guiwin_get_grect(win, GUIWIN_AREA_CONTENT, &area);
+ }
+
+ vsf_interior(vh, FIS_SOLID);
+ vsf_color(vh, 0);
+ vswr_mode(vh, MD_REPLACE);
+ wind_get_grect(win->handle, WF_FIRSTXYWH, &g);
+ while (g.g_h > 0 || g.g_w > 0) {
+ if(rc_intersect(&area, &g)) {
+ pxy[0] = g.g_x;
+ pxy[1] = g.g_y;
+ pxy[2] = g.g_x+g.g_w-1;
+ pxy[3] = g.g_y+g.g_h-1;
+ v_bar(vh, pxy);
+ }
+ wind_get_grect(win->handle, WF_NEXTXYWH, &g);
+ }
+}
+
+
+
diff --git a/atari/gemtk/guiwin.h b/atari/gemtk/guiwin.h
new file mode 100644
index 000000000..6daf16ca9
--- /dev/null
+++ b/atari/gemtk/guiwin.h
@@ -0,0 +1,4 @@
+#ifndef OPKG_GUI_GUIWIN_H
+#define OPKG_GUI_GUIWIN_
+
+#endif /* OPKG_GUIWIN_H */
diff --git a/atari/msgbox.c b/atari/gemtk/msgbox.c
index a9de5d299..770e0af15 100644
--- a/atari/msgbox.c
+++ b/atari/gemtk/msgbox.c
@@ -2,13 +2,13 @@
#include <stdlib.h>
#include <string.h>
#include <gem.h>
-#include "atari/msgbox.h"
+#include "gemtk.h"
#ifndef min
# define min(x,y) ((x<y) ? x : y )
#endif
-short msg_box_show(short type, char * msg)
+short msg_box_show(short type, const char * msg)
{
#define MSG_BOX_STR_SIZE 256
short retval=0, i=0, z=0, l=0;
diff --git a/atari/gemtk/msgbox.h b/atari/gemtk/msgbox.h
new file mode 100644
index 000000000..7a46900ef
--- /dev/null
+++ b/atari/gemtk/msgbox.h
@@ -0,0 +1,5 @@
+#ifndef GUIMSG_H_INCLUDED
+#define GUIMSG_H_INCLUDED
+
+
+#endif // GUIMSG_H_INCLUDED
diff --git a/atari/gemtk/utils.c b/atari/gemtk/utils.c
new file mode 100644
index 000000000..4a24d8261
--- /dev/null
+++ b/atari/gemtk/utils.c
@@ -0,0 +1,45 @@
+#include <stdlib.h>
+#include <stdint.h>
+#include <gem.h>
+#include "gemtk.h"
+
+/* -------------------------------------------------------------------------- */
+/* GEM Utillity functions: */
+/* -------------------------------------------------------------------------- */
+
+unsigned short _systype_v;
+unsigned short _systype (void)
+{
+ int32_t * cptr = NULL;
+ _systype_v = SYS_TOS;
+
+ cptr = (int32_t *)Setexc(0x0168, -1L);
+ if (cptr == NULL ) {
+ return _systype_v; /* stone old TOS without any cookie support */
+ }
+ while (*cptr) {
+ if (*cptr == C_MgMc || *cptr == C_MgMx ) {
+ _systype_v = (_systype_v & ~0xF) | SYS_MAGIC;
+ } else if (*cptr == C_MiNT ) {
+ _systype_v = (_systype_v & ~0xF) | SYS_MINT;
+ } else if (*cptr == C_Gnva /* Gnva */ ) {
+ _systype_v |= SYS_GENEVA;
+ } else if (*cptr == C_nAES /* nAES */ ) {
+ _systype_v |= SYS_NAES;
+ }
+ cptr += 2;
+ }
+ if (_systype_v & SYS_MINT) { /* check for XaAES */
+ short out = 0, u;
+ if (wind_get (0, (((short)'X') <<8)|'A', &out, &u,&u,&u) && out) {
+ _systype_v |= SYS_XAAES;
+ }
+ }
+ return _systype_v;
+}
+
+OBJECT *get_tree( int idx) {
+ OBJECT *tree;
+ rsrc_gaddr(R_TREE, idx, &tree);
+ return tree;
+}
diff --git a/atari/gemtk/utils.h b/atari/gemtk/utils.h
new file mode 100644
index 000000000..7ebbcf228
--- /dev/null
+++ b/atari/gemtk/utils.h
@@ -0,0 +1,5 @@
+#ifndef UTILS_H_INCLUDED
+#define UTILS_H_INCLUDED
+
+
+#endif // UTILS_H_INCLUDED
diff --git a/atari/global_evnt.c b/atari/global_evnt.c
index 3b15af877..dfee0dd37 100755
--- a/atari/global_evnt.c
+++ b/atari/global_evnt.c
@@ -26,379 +26,31 @@
#include <windom.h>
#include "desktop/gui.h"
-#include "desktop/netsurf.h"
-#include "desktop/browser.h"
-#include "desktop/browser_private.h"
-#include "desktop/mouse.h"
-#include "desktop/textinput.h"
-#include "desktop/hotlist.h"
-#include "desktop/save_complete.h"
-#include "desktop/options.h"
#include "utils/log.h"
-#include "utils/messages.h"
-#include "utils/url.h"
+#include "atari/misc.h"
#include "atari/gui.h"
-#include "atari/browser_win.h"
+#include "atari/rootwin.h"
#include "atari/toolbar.h"
#include "atari/browser.h"
-#include "atari/hotlist.h"
-#include "atari/history.h"
-#include "atari/misc.h"
#include "atari/global_evnt.h"
-#include "atari/browser_win.h"
#include "atari/res/netsurf.rsh"
-#include "atari/search.h"
-#include "atari/findfile.h"
-#include "atari/settings.h"
+#include "atari/deskmenu.h"
#include "cflib.h"
extern struct gui_window *input_window;
-extern OBJECT * h_gem_menu;
extern int mouse_click_time[3];
extern int mouse_hold_start[3];
extern browser_mouse_state bmstate;
extern short last_drag_x;
extern short last_drag_y;
-extern bool html_redraw_debug;
-
-extern const char * option_homepage_url;
-extern int option_window_width;
-extern int option_window_height;
-extern int option_window_x;
-extern int option_window_y;
-extern char options[PATH_MAX];
-
-/* Zero based resource tree ids: */
-#define T_ABOUT 0
-#define T_FILE MAINMENU_T_FILE - MAINMENU_T_FILE + 1
-#define T_EDIT MAINMENU_T_EDIT - MAINMENU_T_FILE + 1
-#define T_VIEW MAINMENU_T_VIEW - MAINMENU_T_FILE + 1
-#define T_NAV MAINMENU_T_NAVIGATE - MAINMENU_T_FILE + 1
-#define T_UTIL MAINMENU_T_UTIL - MAINMENU_T_FILE + 1
-#define T_HELP MAINMENU_T_NAVIGATE - MAINMENU_T_FILE + 1
-/* Count of the above defines: */
-#define NUM_MENU_TITLES 7
/* Global event handlers: */
static void __CDECL global_evnt_apterm( WINDOW * win, short buff[8] );
-static void __CDECL global_evnt_menu( WINDOW * win, short buff[8] );
static void __CDECL global_evnt_m1( WINDOW * win, short buff[8] );
static void __CDECL global_evnt_keybd( WINDOW * win, short buff[8],void * data);
-/* Menu event handlers: */
-static void __CDECL menu_about(WINDOW *win, int item, int title, void *data);
-
-
-/* Menu event handlers: */
-static void __CDECL menu_about(WINDOW *win, int item, int title, void *data)
-{
- LOG(("%s", __FUNCTION__));
- char buf[PATH_MAX];
- strcpy((char*)&buf, "file://");
- strncat((char*)&buf, (char*)"./doc/README.TXT", PATH_MAX - (strlen("file://")+1) );
- browser_window_create((char*)&buf, 0, 0, true, false);
-}
-
-static void __CDECL menu_new_win(WINDOW *win, int item, int title, void *data)
-{
- LOG(("%s", __FUNCTION__));
- browser_window_create(option_homepage_url, 0, 0, true, false);
-}
-
-static void __CDECL menu_open_url(WINDOW *win, int item, int title, void *data)
-{
- struct gui_window * gw;
- struct browser_window * bw ;
- LOG(("%s", __FUNCTION__));
-
- gw = input_window;
- if( gw == NULL ) {
- bw = browser_window_create("", 0, 0, true, false);
- gw = bw->window;
-
- }
- /* Loose focus: */
- window_set_focus( gw, WIDGET_NONE, NULL );
-
- /* trigger on-focus event (select all text): */
- window_set_focus( gw, URL_WIDGET, &gw->root->toolbar->url );
-
- /* delete selection: */
- tb_url_input( gw, NK_DEL );
-}
-
-static void __CDECL menu_open_file(WINDOW *win, int item, int title, void *data)
-{
- struct gui_window * gw;
- struct browser_window * bw ;
-
- LOG(("%s", __FUNCTION__));
-
- const char * filename = file_select( messages_get("OpenFile"), "" );
- if( filename != NULL ){
- char * url = local_file_to_url( filename );
- if( url ){
- bw = browser_window_create(url, NULL, NULL, true, false);
- free( url );
- }
- }
-}
-
-static void __CDECL menu_close_win(WINDOW *win, int item, int title, void *data)
-{
- LOG(("%s", __FUNCTION__));
- if( input_window == NULL )
- return;
- gui_window_destroy( input_window );
-}
-
-static void __CDECL menu_save_page(WINDOW *win, int item, int title, void *data)
-{
- LOG(("%s", __FUNCTION__));
- static bool init = true;
- bool is_folder=false;
- const char * path;
-
- if( !input_window )
- return;
-
- if( init ){
- init = false;
- save_complete_init();
- }
-
- do {
- // TODO: localize string
- path = file_select("Select folder", "");
- if (path)
- is_folder = is_dir(path);
- } while( !is_folder && path != NULL );
-
- if( path != NULL ){
- save_complete( input_window->browser->bw->current_content, path, NULL );
- }
-
-}
-
-static void __CDECL menu_quit(WINDOW *win, int item, int title, void *data)
-{
- short buff[8];
- memset( &buff, 0, sizeof(short)*8 );
- LOG(("%s", __FUNCTION__));
- global_evnt_apterm( NULL, buff );
-}
-
-static void __CDECL menu_cut(WINDOW *win, int item, int title, void *data)
-{
- if( input_window != NULL )
- browser_window_key_press( input_window->browser->bw, KEY_CUT_SELECTION);
-}
-
-static void __CDECL menu_copy(WINDOW *win, int item, int title, void *data)
-{
- LOG(("%s", __FUNCTION__));
- if( input_window != NULL )
- browser_window_key_press( input_window->browser->bw, KEY_COPY_SELECTION);
-}
-
-static void __CDECL menu_paste(WINDOW *win, int item, int title, void *data)
-{
- LOG(("%s", __FUNCTION__));
- if( input_window != NULL )
- browser_window_key_press( input_window->browser->bw, KEY_PASTE);
-}
-
-static void __CDECL menu_find(WINDOW *win, int item, int title, void *data)
-{
- LOG(("%s", __FUNCTION__));
- if( input_window != NULL )
- open_browser_search( input_window );
-}
-
-static void __CDECL menu_choices(WINDOW *win, int item, int title, void *data)
-{
- static WINDOW * settings_dlg = NULL;
- LOG(("%s", __FUNCTION__));
- settings_dlg = open_settings();
-}
-
-static void __CDECL menu_stop(WINDOW *win, int item, int title, void *data)
-{
- LOG(("%s", __FUNCTION__));
- if( input_window == NULL )
- return;
- tb_stop_click( input_window );
-
-}
-
-static void __CDECL menu_reload(WINDOW *win, int item, int title, void *data)
-{
- if( input_window == NULL)
- return;
- tb_reload_click( input_window );
- LOG(("%s", __FUNCTION__));
-}
-
-static void __CDECL menu_toolbars(WINDOW *win, int item, int title, void *data)
-{
- static int state = 0;
- LOG(("%s", __FUNCTION__));
- if( input_window != null && input_window->root->toolbar != null ){
- state = !state;
- tb_hide( input_window, state );
- }
-}
-
-static void __CDECL menu_savewin(WINDOW *win, int item, int title, void *data)
-{
- LOG(("%s", __FUNCTION__));
- if (input_window && input_window->browser) {
- GRECT rect;
- wind_get_grect(input_window->root->handle->handle, WF_CURRXYWH, &rect);
- option_window_width = rect.g_w;
- option_window_height = rect.g_h;
- option_window_x = rect.g_x;
- option_window_y = rect.g_y;
- nsoption_set_int(window_width, rect.g_w);
- nsoption_set_int(window_height, rect.g_h);
- nsoption_set_int(window_x, rect.g_x);
- nsoption_set_int(window_y, rect.g_y);
- nsoption_write((const char*)&options);
- }
-
-}
-
-static void __CDECL menu_debug_render(WINDOW *win, int item, int title, void *data)
-{
- LOG(("%s", __FUNCTION__));
- html_redraw_debug = !html_redraw_debug;
- if( input_window != NULL ) {
- if ( input_window->browser != NULL && input_window->browser->bw != NULL) {
- LGRECT rect;
- browser_get_rect( input_window, BR_CONTENT, &rect );
- browser_window_reformat(input_window->browser->bw, false,
- rect.g_w, rect.g_h );
- MenuIcheck(NULL, MAINMENU_M_DEBUG_RENDER,
- (html_redraw_debug) ? 1 : 0 );
- }
- }
-}
-
-static void __CDECL menu_fg_images(WINDOW *win, int item, int title, void *data)
-{
- nsoption_set_bool(foreground_images, !nsoption_bool(foreground_images));
- MenuIcheck( NULL, MAINMENU_M_FG_IMAGES, (nsoption_bool(foreground_images)) ? 1 : 0);
-}
-
-static void __CDECL menu_bg_images(WINDOW *win, int item, int title, void *data)
-{
- nsoption_set_bool(background_images, !nsoption_bool(background_images));
- MenuIcheck( NULL, MAINMENU_M_BG_IMAGES, (nsoption_bool(background_images)) ? 1 : 0);
-}
-
-static void __CDECL menu_back(WINDOW *win, int item, int title, void *data)
-{
- LOG(("%s", __FUNCTION__));
- if( input_window == NULL )
- return;
- tb_back_click( input_window );
-}
-
-static void __CDECL menu_forward(WINDOW *win, int item, int title, void *data)
-{
- LOG(("%s", __FUNCTION__));
- if( input_window == NULL )
- return;
- tb_forward_click( input_window );
-}
-
-static void __CDECL menu_home(WINDOW *win, int item, int title, void *data)
-{
- LOG(("%s", __FUNCTION__));
- if( input_window == NULL )
- return;
- tb_home_click( input_window );
-}
-
-static void __CDECL menu_lhistory(WINDOW *win, int item, int title, void *data)
-{
- LOG(("%s", __FUNCTION__));
- if( input_window == NULL )
- return;
-}
-
-static void __CDECL menu_ghistory(WINDOW *win, int item, int title, void *data)
-{
- LOG(("%s", __FUNCTION__));
- global_history_open();
-}
-
-static void __CDECL menu_add_bookmark(WINDOW *win, int item, int title, void *data)
-{
- LOG(("%s", __FUNCTION__));
- if( input_window ) {
- if( input_window->browser->bw->current_content != NULL ){
- atari_hotlist_add_page(
- nsurl_access(hlcache_handle_get_url( input_window->browser->bw->current_content)),
- NULL
- );
- }
- }
-}
-
-static void __CDECL menu_bookmarks(WINDOW *win, int item, int title, void *data)
-{
- LOG(("%s", __FUNCTION__));
- hotlist_open();
-}
-
-static void __CDECL menu_vlog(WINDOW *win, int item, int title, void *data)
-{
- LOG(("%s", __FUNCTION__));
- verbose_log = !verbose_log;
- MenuIcheck(NULL, MAINMENU_M_VLOG, (verbose_log) ? 1 : 0 );
-}
-
-static void __CDECL menu_help_content(WINDOW *win, int item, int title, void *data)
-{
- LOG(("%s", __FUNCTION__));
-}
-
-static struct s_menu_item_evnt menu_evnt_tbl[] =
-{
- {T_ABOUT,MAINMENU_M_ABOUT, menu_about, {0,0,0}, NULL },
- {T_FILE, MAINMENU_M_NEWWIN, menu_new_win, {0,0,0}, NULL},
- {T_FILE, MAINMENU_M_OPENURL, menu_open_url, {'G',0,K_CTRL}, NULL},
- {T_FILE, MAINMENU_M_OPENFILE, menu_open_file, {'O',0,K_CTRL}, NULL},
- {T_FILE, MAINMENU_M_CLOSEWIN, menu_close_win, {0,0,0}, NULL},
- {T_FILE, MAINMENU_M_SAVEPAGE, menu_save_page, {0,NK_F3,0}, NULL},
- {T_FILE, MAINMENU_M_QUIT, menu_quit, {'Q',0,K_CTRL}, NULL},
- {T_EDIT, MAINMENU_M_CUT, menu_cut, {'X',0,K_CTRL}, NULL},
- {T_EDIT, MAINMENU_M_COPY, menu_copy, {'C',0,K_CTRL}, NULL},
- {T_EDIT, MAINMENU_M_PASTE, menu_paste, {'V',0,K_CTRL}, NULL},
- {T_EDIT, MAINMENU_M_FIND, menu_find, {0,NK_F4,0}, NULL},
- {T_VIEW, MAINMENU_M_RELOAD, menu_reload, {0,NK_F5,0}, NULL},
- {T_VIEW, MAINMENU_M_TOOLBARS, menu_toolbars, {0,NK_F1,K_CTRL}, NULL},
- {T_VIEW, MAINMENU_M_SAVEWIN, menu_savewin, {0,0,0}, NULL},
- {T_VIEW, MAINMENU_M_DEBUG_RENDER, menu_debug_render, {0,0,0}, NULL},
- {T_VIEW, MAINMENU_M_FG_IMAGES, menu_fg_images, {0,0,0}, NULL},
- {T_VIEW, MAINMENU_M_BG_IMAGES, menu_bg_images, {0,0,0}, NULL},
- {T_VIEW, MAINMENU_M_STOP, menu_stop, {0,NK_ESC,K_ALT}, NULL},
- {T_NAV, MAINMENU_M_BACK, menu_back, {0,NK_LEFT,K_ALT}, NULL},
- {T_NAV, MAINMENU_M_FORWARD, menu_forward, {0,NK_RIGHT,K_ALT}, NULL},
- {T_NAV, MAINMENU_M_HOME, menu_home, {0,NK_CLRHOME,0}, NULL},
- {T_UTIL, MAINMENU_M_LHISTORY,menu_lhistory, {0,NK_F7,0}, NULL},
- {T_UTIL, MAINMENU_M_GHISTORY, menu_ghistory, {0,NK_F7,K_CTRL}, NULL},
- {T_UTIL, MAINMENU_M_ADD_BOOKMARK, menu_add_bookmark, {'D',0,K_CTRL}, NULL},
- {T_UTIL, MAINMENU_M_BOOKMARKS, menu_bookmarks, {0,NK_F6,0}, NULL},
- {T_UTIL, MAINMENU_M_CHOICES, menu_choices, {0,0,0}, NULL},
- {T_UTIL, MAINMENU_M_VLOG, menu_vlog, {'V',0,K_ALT}, NULL},
- {T_HELP, MAINMENU_M_HELP_CONTENT, menu_help_content, {0,NK_F1,0}, NULL},
- {T_HELP, -1, NULL,{0,0,0}, NULL }
-};
-
-void __CDECL global_evnt_apterm( WINDOW * win, short buff[8] )
+void __CDECL global_evnt_apterm(WINDOW * win, short buff[8])
{
int i = 0;
LOG((""));
@@ -406,33 +58,31 @@ void __CDECL global_evnt_apterm( WINDOW * win, short buff[8] )
}
-static void __CDECL global_evnt_m1( WINDOW * win, short buff[8] )
+static void __CDECL global_evnt_m1(WINDOW * win, short buff[8])
{
struct gui_window * gw = input_window;
static bool prev_url = false;
static short prev_x=0;
static short prev_y=0;
bool within = false;
- LGRECT urlbox, bwbox, sbbox;
+ GRECT urlbox, bwbox, sbbox;
int nx, ny;
- if( gw == NULL)
+ if (gw == NULL)
return;
- if( prev_x == evnt.mx && prev_y == evnt.my ){
+ if (prev_x == evnt.mx && prev_y == evnt.my) {
return;
}
short ghandle = wind_find( evnt.mx, evnt.my );
- if( input_window->root->handle->handle == ghandle ){
+ if (guiwin_get_handle(input_window->root->win)==ghandle) {
// The window found at x,y is an gui_window
// and it's the input window.
- browser_get_rect( gw, BR_CONTENT, &bwbox );
-
- if( evnt.mx > bwbox.g_x && evnt.mx < bwbox.g_x + bwbox.g_w &&
- evnt.my > bwbox.g_y && evnt.my < bwbox.g_y + bwbox.g_h ){
+ browser_get_rect(gw, BR_CONTENT, &bwbox);
+ if (POINT_WITHIN(evnt.mx, evnt.my, bwbox)) {
within = true;
browser_window_mouse_track(
input_window->browser->bw,
@@ -442,10 +92,9 @@ static void __CDECL global_evnt_m1( WINDOW * win, short buff[8] )
);
}
- if( gw->root->toolbar && within == false ) {
- mt_CompGetLGrect(&app, gw->root->toolbar->url.comp, WF_WORKXYWH, &urlbox);
- if( (evnt.mx > urlbox.g_x && evnt.mx < urlbox.g_x + urlbox.g_w ) &&
- (evnt.my > urlbox.g_y && evnt.my < + urlbox.g_y + urlbox.g_h )) {
+ if (gw->root->toolbar && within == false) {
+ browser_get_rect(gw, BR_URL_INPUT, &urlbox);
+ if(POINT_WITHIN(evnt.mx, evnt.my, urlbox)) {
gem_set_cursor( &gem_cursors.ibeam );
prev_url = true;
} else {
@@ -464,9 +113,8 @@ static void __CDECL global_evnt_m1( WINDOW * win, short buff[8] )
prev_y = evnt.my;
}
-void __CDECL global_evnt_keybd( WINDOW * win, short buff[8], void * data)
+void __CDECL global_evnt_keybd(WINDOW * win, short buff[8], void * data)
{
- char sascii;
long kstate = 0;
long kcode = 0;
unsigned short nkc = 0;
@@ -483,195 +131,41 @@ void __CDECL global_evnt_keybd( WINDOW * win, short buff[8], void * data)
nkc= gem_to_norm( (short)kstate, (short)kcode );
nks = (nkc & 0xFF00);
if( kstate & (K_LSHIFT|K_RSHIFT))
- kstate |= K_LSHIFT|K_RSHIFT;
- if( window_url_widget_has_focus( gw ) ) {
+ kstate |= K_LSHIFT|K_RSHIFT;
+
+ if(window_url_widget_has_focus((void*)gw->root)) {
/* make sure we report for the root window and report...: */
- done = tb_url_input( gw, nkc );
+ done = toolbar_key_input(gw->root->toolbar, nkc);
} else {
gw_tmp = window_list;
/* search for active browser component: */
while( gw_tmp != NULL && done == false ) {
/* todo: only handle when input_window == ontop */
- if( window_widget_has_focus( (struct gui_window *)input_window,
- BROWSER,(void*)gw_tmp->browser)) {
- done = browser_input( gw_tmp, nkc );
+ if( window_widget_has_focus(input_window->root, BROWSER,
+ (void*)gw_tmp->browser)) {
+ done = browser_input(gw_tmp, nkc);
break;
} else {
gw_tmp = gw_tmp->next;
}
}
- }
- sascii = keybd2ascii( evnt.keybd, K_LSHIFT);
- while( menu_evnt_tbl[i].rid != -1 && done == false) {
- if( kstate == menu_evnt_tbl[i].accel.mod && menu_evnt_tbl[i].accel.ascii != 0) {
- if( menu_evnt_tbl[i].accel.ascii == sascii) {
- menu_evnt_tbl[i].menu_func( NULL, menu_evnt_tbl[i].rid, MAINMENU, buff);
- done = true;
- break;
- }
- } else {
- /* the accel code hides in the keycode: */
- if( menu_evnt_tbl[i].accel.keycode != 0) {
- if( menu_evnt_tbl[i].accel.keycode == (nkc & 0xFF) &&
- kstate == menu_evnt_tbl[i].accel.mod &&
- menu_evnt_tbl[i].menu_func != NULL) {
- menu_evnt_tbl[i].menu_func( NULL,
- menu_evnt_tbl[i].rid,
- MAINMENU, buff
- );
- done = true;
- break;
- }
- }
- }
- i++;
- }
-}
-
-/*
- Parse encoded menu key shortcut
-
- The format is:
-
- "[" - marks start of the shortcut
- "@,^,<" - If the keyshortcut is only valid
- with modifier keys, one of these characters must directly
- follow the start mark.
- Meaning:
- @ -> Alternate
- ^ -> Control
- "#" - keycode or ascii character.
- The value is handled as keycode if the character value
- is <= 28 ( Atari chracter table )
- or if it is interpreted as function key string.
- (strings: F1 - F10)
-
-*/
-static void register_menu_str( struct s_menu_item_evnt * mi )
-{
- char * str = ObjcString( h_gem_menu, mi->rid, NULL );
- int l = strlen(str);
- int i = l;
- int x = -1;
- struct s_accelerator * accel = &mi->accel;
-
-
-
- while( i>2 ){
- if( str[i] == '['){
- x = i;
- break;
- }
- i--;
- }
- if( x > -1 ){
- mi->menustr = malloc( l+1 );
- strcpy(mi->menustr, str );
- mi->menustr[x]=' ';
- x++;
- if( str[x] == '@' ){
- accel->mod = K_ALT;
- mi->menustr[x] = 0x07;
- x++;
- }
- else if( str[x] == '^' ) {
- accel->mod = K_CTRL;
- x++;
- }
- if( str[x] <= 28 ){
- // parse symbol
- unsigned short keycode=0;
- switch( str[x] ){
- case 0x03:
- accel->keycode = NK_RIGHT;
- break;
- case 0x04:
- accel->keycode = NK_LEFT;
- break;
- case 0x1B:
- accel->keycode = NK_ESC;
- break;
- default:
- break;
- }
- } else {
- if(str[x] == 'F' && ( str[x+1] >= '1' && str[x+1] <= '9') ){
- // parse function key
- short fkey = atoi( &str[x+1] );
- if( (fkey >= 0) && (fkey <= 10) ){
- accel->keycode = NK_F1 - 1 + fkey;
- }
- } else {
- accel->ascii = str[x];
- }
- }
}
+ if(!done)
+ deskmenu_dispatch_keypress(evnt.keybd, kstate, nkc);
}
-
-
-void __CDECL global_evnt_menu( WINDOW * win, short buff[8] )
-{
- int title = buff[ 3];
- INT16 x,y;
- char *str;
- struct gui_window * gw = window_list;
- int i=0;
- MenuTnormal( NULL, title, 1);
- while( gw ) {
- window_set_focus( gw, WIDGET_NONE, NULL );
- gw = gw->next;
- }
- while( menu_evnt_tbl[i].rid != -1) {
- if( menu_evnt_tbl[i].rid == buff[4] ) {
- menu_evnt_tbl[i].menu_func(win, (int)buff[4], (int)buff[3], NULL );
- break;
- }
- i++;
- }
-}
-
-void main_menu_update( void )
-{
- MenuIcheck( NULL, MAINMENU_M_DEBUG_RENDER, (html_redraw_debug) ? 1 : 0);
- MenuIcheck( NULL, MAINMENU_M_FG_IMAGES, (nsoption_bool(foreground_images)) ? 1 : 0);
- MenuIcheck( NULL, MAINMENU_M_BG_IMAGES, (nsoption_bool(background_images)) ? 1 : 0);
-}
-
+
/* Bind global and menu events to event handler functions, create accelerators */
void bind_global_events( void )
{
- int i, len;
- int maxlen[NUM_MENU_TITLES]={0};
- char * m, *u, *t;
- char spare[128];
memset( (void*)&evnt_data, 0, sizeof(struct s_evnt_data) );
EvntDataAttach( NULL, WM_XKEYBD, global_evnt_keybd, (void*)&evnt_data );
- EvntAttach( NULL, AP_TERM, global_evnt_apterm );
- EvntAttach( NULL, MN_SELECTED, global_evnt_menu );
+ EvntAttach( NULL, AP_TERM, global_evnt_apterm );
EvntAttach( NULL, WM_XM1, global_evnt_m1 );
-
- /* parse and update menu items: */
- i = 0;
- while( menu_evnt_tbl[i].rid != -1 ) {
- char * str = ObjcString( h_gem_menu, menu_evnt_tbl[i].rid, NULL );
- register_menu_str( &menu_evnt_tbl[i] );
- if( menu_evnt_tbl[i].menustr != NULL ){
- MenuText( NULL, menu_evnt_tbl[i].rid, menu_evnt_tbl[i].menustr );
- }
- i++;
- }
- main_menu_update();
}
void unbind_global_events( void )
{
- int i;
- i=0;
- while(menu_evnt_tbl[i].rid != -1) {
- if( menu_evnt_tbl[i].menustr != NULL )
- free(menu_evnt_tbl[i].menustr);
- i++;
- }
+
}
diff --git a/atari/global_evnt.h b/atari/global_evnt.h
index 1e13264a2..76e73fc6b 100755
--- a/atari/global_evnt.h
+++ b/atari/global_evnt.h
@@ -18,6 +18,8 @@
#ifndef NS_ATARI_GLOBAL_EVNT_H
#define NS_ATARI_GLOBAL_EVNT_H
+
+#include <stdbool.h>
struct s_keybd_evnt_data
{
@@ -32,31 +34,14 @@ struct s_evnt_data
} u;
};
-struct s_evnt_data evnt_data;
-
-struct s_accelerator
-{
- char ascii; /* either ascii or */
- long keycode; /* normalised keycode is valid */
- short mod; /* shift / ctrl etc */
-};
-
-typedef void __CDECL (*menu_evnt_func)(WINDOW * win, int item, int title, void * data);
-struct s_menu_item_evnt {
- short title; /* to which menu this item belongs */
- short rid; /* resource ID */
- menu_evnt_func menu_func; /* click handler */
- struct s_accelerator accel; /* accelerator info */
- char * menustr;
-};
+struct s_evnt_data evnt_data;
/*
- Global & Menu event handlers
+ Global event handlers
*/
void bind_global_events( void );
void unbind_global_events( void );
-void main_menu_update( void );
#endif
diff --git a/atari/gui.c b/atari/gui.c
index c2158e05e..2528eff1f 100755
--- a/atari/gui.c
+++ b/atari/gui.c
@@ -1,1041 +1,1137 @@
-/*
- * Copyright 2010 <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
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
- /*
- This File provides all the mandatory functions prefixed with gui_
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <time.h>
-#include <limits.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdbool.h>
-#include <windom.h>
-#include <hubbub/hubbub.h>
-
-#include "content/urldb.h"
-#include "content/fetch.h"
-#include "content/fetchers/resource.h"
-#include "css/utils.h"
-#include "desktop/gui.h"
-#include "desktop/history_core.h"
-#include "desktop/plotters.h"
-#include "desktop/netsurf.h"
-#include "desktop/401login.h"
-
-#include "desktop/options.h"
-#include "desktop/save_complete.h"
-#include "desktop/selection.h"
-#include "desktop/textinput.h"
-#include "desktop/browser.h"
-#include "desktop/browser_private.h"
-#include "desktop/mouse.h"
-#include "render/font.h"
-#include "utils/schedule.h"
-#include "utils/url.h"
-#include "utils/log.h"
-#include "utils/messages.h"
-#include "utils/utils.h"
-
-#include "atari/gui.h"
-#include "atari/misc.h"
-#include "atari/findfile.h"
-#include "atari/schedule.h"
-#include "atari/browser_win.h"
-#include "atari/browser.h"
-#include "atari/statusbar.h"
-#include "atari/toolbar.h"
-#include "atari/verify_ssl.h"
-#include "atari/hotlist.h"
-#include "atari/history.h"
-#include "atari/login.h"
-#include "atari/global_evnt.h"
-#include "atari/encoding.h"
-#include "atari/res/netsurf.rsh"
-#include "atari/plot/plot.h"
-#include "atari/clipboard.h"
-#include "atari/osspec.h"
-#include "atari/search.h"
-#include "cflib.h"
-
-#define TODO() (0)/*printf("%s Unimplemented!\n", __FUNCTION__)*/
-
-char *tmp_clipboard;
-struct gui_window *input_window = NULL;
-struct gui_window *window_list = NULL;
-void * h_gem_rsrc;
-OBJECT * h_gem_menu;
-OBJECT **rsc_trindex;
-short rsc_ntree;
-long next_poll;
-bool rendering = false;
-
-
-/* Comandline / Options: */
-int option_window_width;
-int option_window_height;
-int option_window_x;
-int option_window_y;
-
-/* Defaults to option_homepage_url, commandline options overwrites that value */
-const char * option_homepage_url;
-
-/* path to choices file: */
-char options[PATH_MAX];
-
-
-void gui_poll(bool active)
-{
- short winloc[4];
- // int timeout; /* timeout in milliseconds */
- int flags = MU_MESAG | MU_KEYBD | MU_BUTTON ;
- short mx, my, dummy;
-
- evnt.timer = schedule_run();
-
- if( active || rendering ) {
- if( clock() >= next_poll ) {
- evnt.timer = 0;
- flags |= MU_TIMER;
- EvntWindom( flags );
- next_poll = clock() + (CLOCKS_PER_SEC>>3);
- }
- } else {
- if (input_window != NULL) {
- wind_get( 0, WF_TOP, &winloc[0], &winloc[1], &winloc[2], &winloc[3]);
- if (winloc[1] == _AESapid) {
- /* only check for mouse move when netsurf is on top: */
- // move that into m1 event handler
- graf_mkstate( &mx, &my, &dummy, &dummy );
- flags |= MU_M1;
- evnt.m1_flag = MO_LEAVE;
- evnt.m1_w = evnt.m1_h = 1;
- evnt.m1_x = mx;
- evnt.m1_y = my;
- }
- }
- flags |= MU_TIMER;
- EvntWindom( flags );
- }
-
- struct gui_window * g;
- for( g = window_list; g != NULL; g=g->next ) {
- if( browser_redraw_required( g ) ){
- browser_redraw( g );
- }
- if( g->root->toolbar ){
- if(g->root->toolbar->url.redraw ){
- tb_url_redraw( g );
- }
- }
- }
- if( evnt.timer != 0 && !active ){
- /* this suits for stuff with lower priority */
- /* TBD: really be spare on redraws??? */
- hotlist_redraw();
- global_history_redraw();
- }
-}
-
-struct gui_window *
-gui_create_browser_window(struct browser_window *bw,
- struct browser_window *clone,
- bool new_tab)
-{
- struct gui_window *gw=NULL;
- LOG(( "gw: %p, BW: %p, clone %p, tab: %d\n" , gw, bw, clone,
- (int)new_tab
- ));
-
- gw = malloc( sizeof(struct gui_window) );
- if (gw == NULL)
- return NULL;
- memset( gw, 0, sizeof(struct gui_window) );
-
- LOG(("new window: %p, bw: %p\n", gw, bw));
- window_create(gw, bw, WIDGET_STATUSBAR|WIDGET_TOOLBAR|WIDGET_RESIZE|WIDGET_SCROLL );
- if( gw->root->handle ) {
- GRECT pos = {
- option_window_x, option_window_y,
- option_window_width, option_window_height
- };
- window_open( gw , pos );
- /* Recalculate windows browser area now */
- browser_update_rects( gw );
- tb_update_buttons( gw, -1 );
- input_window = gw;
- /* TODO:... this line: placeholder to create a local history widget ... */
- }
-
- /* add the window to the window list: */
- if( window_list == NULL ) {
- window_list = gw;
- gw->next = NULL;
- gw->prev = NULL;
- } else {
- struct gui_window * tmp = window_list;
- while( tmp->next != NULL ) {
- tmp = tmp->next;
- }
- tmp->next = gw;
- gw->prev = tmp;
- gw->next = NULL;
- }
-
- return( gw );
-
-}
-
-void gui_window_destroy(struct gui_window *w)
-{
- if (w == NULL)
- return;
-
- LOG(("%s\n", __FUNCTION__ ));
-
- input_window = NULL;
-
- window_destroy( w );
-
- /* unlink the window: */
- if(w->prev != NULL ) {
- w->prev->next = w->next;
- } else {
- window_list = w->next;
- }
- if( w->next != NULL ) {
- w->next->prev = w->prev;
- }
- free(w);
- w = NULL;
-
- w = window_list;
- while( w != NULL ) {
- if( w->root ) {
- input_window = w;
- break;
- }
- w = w->next;
- }
-}
-
-void gui_window_get_dimensions(struct gui_window *w, int *width, int *height,
- bool scaled)
-{
- if (w == NULL)
- return;
- LGRECT rect;
- browser_get_rect( w, BR_CONTENT, &rect );
- *width = rect.g_w;
- *height = rect.g_h;
-}
-
-void gui_window_set_title(struct gui_window *gw, const char *title)
-{
- int l;
- char * conv;
-
- if (gw == NULL)
- return;
- if( gw->root ){
- l = strlen(title);
- if( utf8_to_local_encoding(title, l, &conv) == UTF8_CONVERT_OK ){
- strncpy(gw->root->title, conv, atari_sysinfo.aes_max_win_title_len);
- free( conv );
- } else {
- strncpy(gw->root->title, title, atari_sysinfo.aes_max_win_title_len);
- }
- gw->root->title[atari_sysinfo.aes_max_win_title_len] = 0;
- WindSetStr( gw->root->handle, WF_NAME, gw->root->title );
- }
-}
-
-/**
- * set the status bar message
- */
-void gui_window_set_status(struct gui_window *w, const char *text)
-{
- if (w == NULL || text == NULL )
- return;
- window_set_stauts( w , (char*)text );
-}
-
-void gui_window_redraw_window(struct gui_window *gw)
-{
- CMP_BROWSER b;
- LGRECT rect;
- if (gw == NULL)
- return;
- b = gw->browser;
- browser_get_rect( gw, BR_CONTENT, &rect );
- browser_schedule_redraw( gw, 0, 0, rect.g_w, rect.g_h );
-}
-
-void gui_window_update_box(struct gui_window *gw, const struct rect *rect)
-{
- CMP_BROWSER b;
- if (gw == NULL)
- return;
- b = gw->browser;
- int x0 = rect->x0 - b->scroll.current.x;
- int y0 = rect->y0 - b->scroll.current.y;
- int w,h;
- w = rect->x1 - rect->x0;
- h = rect->y1 - rect->y0;
- browser_schedule_redraw_rect( gw, x0, y0, w, h );
-}
-
-bool gui_window_get_scroll(struct gui_window *w, int *sx, int *sy)
-{
- if (w == NULL)
- return false;
- *sx = w->browser->scroll.current.x;
- *sy = w->browser->scroll.current.y;
- return( true );
-}
-
-void gui_window_set_scroll(struct gui_window *w, int sx, int sy)
-{
- if ((w == NULL) ||
- (w->browser->bw == NULL) ||
- (w->browser->bw->current_content == NULL))
- return;
- if( sx != 0 ) {
- if( sx < 0 ) {
- browser_scroll(w, WA_LFLINE, abs(sx), true );
- } else {
- browser_scroll(w, WA_RTLINE, abs(sx), true );
- }
- }
-
- if( sy != 0 ) {
- if( sy < 0) {
- browser_scroll(w, WA_UPLINE, abs(sy), true );
- } else {
- browser_scroll(w, WA_DNLINE, abs(sy), true );
- }
- }
- return;
-
-}
-
-void gui_window_scroll_visible(struct gui_window *w, int x0, int y0, int x1, int y1)
-{
- LOG(("%s:(%p, %d, %d, %d, %d)", __func__, w, x0, y0, x1, y1));
- gui_window_set_scroll(w,x0,y0);
- browser_schedule_redraw_rect( w, 0, 0, x1-x0,y1-y0);
-}
-
-
-/* It seems this method is called when content size got adjusted,
- so that we can adjust scroll info. We also have to call it when tab
- change occurs.
-*/
-void gui_window_update_extent(struct gui_window *gw)
-{
- int oldx, oldy;
- oldx = gw->browser->scroll.current.x;
- oldy = gw->browser->scroll.current.y;
- if( gw->browser->bw->current_content != NULL ) {
- browser_set_content_size( gw,
- content_get_width(gw->browser->bw->current_content),
- content_get_height(gw->browser->bw->current_content)
- );
- }
-}
-
-
-void gui_clear_selection(struct gui_window *g)
-{
-
-}
-
-
-
-/**
- * set the pointer shape
- */
-void gui_window_set_pointer(struct gui_window *w, gui_pointer_shape shape)
-{
- if (w == NULL)
- return;
- switch (shape) {
- case GUI_POINTER_POINT: /* link */
- gem_set_cursor(&gem_cursors.hand);
- break;
-
- case GUI_POINTER_MENU:
- gem_set_cursor(&gem_cursors.menu);
- break;
-
- case GUI_POINTER_CARET: /* input */
- gem_set_cursor(&gem_cursors.ibeam);
- break;
-
- case GUI_POINTER_CROSS:
- gem_set_cursor(&gem_cursors.cross);
- break;
-
- case GUI_POINTER_MOVE:
- gem_set_cursor(&gem_cursors.sizeall);
- break;
-
- case GUI_POINTER_RIGHT:
- case GUI_POINTER_LEFT:
- gem_set_cursor(&gem_cursors.sizewe);
- break;
-
- case GUI_POINTER_UP:
- case GUI_POINTER_DOWN:
- gem_set_cursor(&gem_cursors.sizens);
- break;
-
- case GUI_POINTER_RU:
- case GUI_POINTER_LD:
- gem_set_cursor(&gem_cursors.sizenesw);
- break;
-
- case GUI_POINTER_RD:
- case GUI_POINTER_LU:
- gem_set_cursor(&gem_cursors.sizenwse);
- break;
-
- case GUI_POINTER_WAIT:
- gem_set_cursor(&gem_cursors.wait);
- break;
-
- case GUI_POINTER_PROGRESS:
- gem_set_cursor(&gem_cursors.appstarting);
- break;
-
- case GUI_POINTER_NO_DROP:
- gem_set_cursor(&gem_cursors.nodrop);
- break;
-
- case GUI_POINTER_NOT_ALLOWED:
- gem_set_cursor(&gem_cursors.deny);
- break;
-
- case GUI_POINTER_HELP:
- gem_set_cursor(&gem_cursors.help);
- break;
-
- default:
- gem_set_cursor(&gem_cursors.arrow);
- break;
- }
-}
-
-void gui_window_hide_pointer(struct gui_window *w)
-{
- TODO();
-}
-
-
-void gui_window_set_url(struct gui_window *w, const char *url)
-{
- if (w == NULL)
- return;
- tb_url_set(w, (char*)url );
-}
-
-static void throbber_advance( void * data )
-{
- LGRECT work;
- struct gui_window * gw = (struct gui_window *)data;
- if( gw->root == NULL )
- return;
- if( gw->root->toolbar == NULL )
- return;
- if( gw->root->toolbar->throbber.running == false )
- return;
- mt_CompGetLGrect(&app, gw->root->toolbar->throbber.comp,
- WF_WORKXYWH, &work);
- gw->root->toolbar->throbber.index++;
- if( gw->root->toolbar->throbber.index > gw->root->toolbar->throbber.max_index )
- gw->root->toolbar->throbber.index = THROBBER_MIN_INDEX;
- ApplWrite( _AESapid, WM_REDRAW, gw->root->handle->handle,
- work.g_x, work.g_y, work.g_w, work.g_h );
- schedule(100, throbber_advance, gw );
-}
-
-void gui_window_start_throbber(struct gui_window *w)
-{
- LGRECT work;
- if (w == NULL)
- return;
- if( w->root->toolbar->throbber.running == true )
- return;
- mt_CompGetLGrect(&app, w->root->toolbar->throbber.comp,
- WF_WORKXYWH, &work);
- w->root->toolbar->throbber.running = true;
- w->root->toolbar->throbber.index = THROBBER_MIN_INDEX;
- schedule(100, throbber_advance, w );
- ApplWrite( _AESapid, WM_REDRAW, w->root->handle->handle,
- work.g_x, work.g_y, work.g_w, work.g_h );
-
- rendering = true;
-}
-
-void gui_window_stop_throbber(struct gui_window *w)
-{
- LGRECT work;
- if (w == NULL)
- return;
- if( w->root->toolbar->throbber.running == false )
- return;
-
- schedule_remove(throbber_advance, w);
-
- /* refresh toolbar buttons: */
- tb_update_buttons( w, -1 );
-
- /* redraw throbber: */
- mt_CompGetLGrect(&app, w->root->toolbar->throbber.comp,
- WF_WORKXYWH, &work);
- w->root->toolbar->throbber.running = false;
- ApplWrite( _AESapid, WM_REDRAW, w->root->handle->handle,
- work.g_x, work.g_y, work.g_w, work.g_h );
-
- rendering = false;
-}
-
-/* Place caret in window */
-void gui_window_place_caret(struct gui_window *w, int x, int y, int height)
-{
- if (w == NULL)
- return;
- if( w->browser->caret.current.g_w > 0 )
- gui_window_remove_caret( w );
- w->browser->caret.requested.g_x = x;
- w->browser->caret.requested.g_y = y;
- w->browser->caret.requested.g_w = 1;
- w->browser->caret.requested.g_h = height;
- w->browser->caret.redraw = true;
- return;
-}
-
-
-/**
- * clear window caret
- */
-void
-gui_window_remove_caret(struct gui_window *w)
-{
- if (w == NULL)
- return;
-
- if( w->browser->caret.background.fd_addr != NULL ){
- browser_restore_caret_background( w, NULL );
- w->browser->caret.requested.g_w = 0;
- w->browser->caret.current.g_w = 0;
- }
- return;
-}
-
-void
-gui_window_set_icon(struct gui_window *g, hlcache_handle *icon)
-{
- struct bitmap *bmp_icon;
-
- bmp_icon = (icon != NULL) ? content_get_bitmap(icon) : NULL;
-
- window_set_icon(g, bmp_icon);
-}
-
-void
-gui_window_set_search_ico(hlcache_handle *ico)
-{
- TODO();
-}
-
-void gui_window_new_content(struct gui_window *w)
-{
- w->browser->scroll.current.x = 0;
- w->browser->scroll.current.y = 0;
- w->browser->scroll.requested.x = 0;
- w->browser->scroll.requested.y = 0;
- w->browser->scroll.required = true;
- gui_window_redraw_window( w );
-}
-
-bool gui_window_scroll_start(struct gui_window *w)
-{
- TODO();
- return true;
-}
-
-bool gui_window_drag_start(struct gui_window *g, gui_drag_type type,
- const struct rect *rect)
-{
- TODO();
- return true;
-}
-
-void gui_window_save_link(struct gui_window *g, const char *url,
- const char *title)
-{
- LOG(("%s -> %s", title, url ));
- TODO();
-}
-
-void gui_drag_save_object(gui_save_type type, hlcache_handle *c,
- struct gui_window *w)
-{
- LOG((""));
- TODO();
-}
-
-void gui_drag_save_selection(struct selection *s, struct gui_window *w)
-{
- LOG((""));
- TODO();
-}
-
-void gui_start_selection(struct gui_window *w)
-{
- gui_empty_clipboard();
-}
-
-void gui_paste_from_clipboard(struct gui_window *w, int x, int y)
-{
- char * clip = scrap_txt_read( &app );
- if( clip == NULL )
- return;
- int clip_length = strlen( clip );
- if (clip_length > 0) {
- char *utf8;
- utf8_convert_ret ret;
- /* Clipboard is in local encoding so
- * convert to UTF8 */
- ret = utf8_from_local_encoding(clip,
- clip_length, &utf8);
- if (ret == UTF8_CONVERT_OK) {
- browser_window_paste_text(w->browser->bw, utf8,
- strlen(utf8), true);
- free(utf8);
- }
- free( clip );
- }
-}
-
-bool gui_empty_clipboard(void)
-{
- if( tmp_clipboard != NULL ){
- free( tmp_clipboard );
- tmp_clipboard = NULL;
- }
- return true;
-}
-
-bool gui_add_to_clipboard(const char *text_utf8, size_t length_utf8, bool space,
- const plot_font_style_t *fstyle)
-{
- LOG(("(%s): %s (%d)\n", (space)?"space":"", (char*)text_utf8, (int)length_utf8));
- char * oldptr = tmp_clipboard;
- size_t oldlen = 0;
- size_t newlen = 0;
- char * text = NULL;
- char * text2 = NULL;
- bool retval;
- int length = 0;
- if( length_utf8 > 0 && text_utf8 != NULL ) {
- utf8_to_local_encoding(text_utf8,length_utf8,&text);
- if( text == NULL ) {
- LOG(("Conversion failed (%s)", text_utf8));
- goto error;
- } else {
- text2 = text;
- }
- } else {
- if( space == false ) {
- goto success;
- }
- text = malloc(length + 2);
- if( text == NULL ) {
- goto error;
- }
- text2 = text;
- text[length+1] = 0;
- memset(text, ' ', length+1);
- }
- length = strlen(text);
- if( tmp_clipboard != NULL ) {
- oldlen = strlen( tmp_clipboard );
- }
- newlen = oldlen + length + 1;
- if( tmp_clipboard == NULL){
- tmp_clipboard = malloc(newlen);
- if( tmp_clipboard == NULL ) {
- goto error;
- }
- strncpy(tmp_clipboard, text, newlen);
- } else {
- tmp_clipboard = realloc( tmp_clipboard, newlen);
- if( tmp_clipboard == NULL ) {
- goto error;
- }
- strncpy(tmp_clipboard, oldptr, newlen);
- strncat(tmp_clipboard, text, newlen-oldlen);
- }
- goto success;
-
-error:
- retval = false;
- goto fin;
-
-success:
- retval = true;
-
-fin:
- if( text2 != NULL )
- free( text2 );
- return(retval);
-
-}
-
-bool gui_commit_clipboard(void)
-{
- int r = scrap_txt_write(&app, tmp_clipboard);
- return( (r>0)?true:false );
-}
-
-bool gui_copy_to_clipboard(struct selection *s)
-{
- bool ret = false;
- if( s->defined ) {
- gui_empty_clipboard();
- if(selection_copy_to_clipboard(s)){
- ret = gui_commit_clipboard();
- }
- }
- gui_empty_clipboard();
- return ret;
-}
-
-
-void gui_create_form_select_menu(struct browser_window *bw,
- struct form_control *control)
-{
- TODO();
-}
-
-/**
- * Broadcast an URL that we can't handle.
- */
-void gui_launch_url(const char *url)
-{
- TODO();
- LOG(("launch file: %s\n", url));
-}
-
-void gui_401login_open(nsurl *url, const char *realm,
- nserror (*cb)(bool proceed, void *pw), void *cbpw)
-{
- bool bres;
- char * out = NULL;
- bres = login_form_do( url, (char*)realm, &out );
- if( bres ) {
- LOG(("url: %s, realm: %s, auth: %s\n", url, realm, out ));
- urldb_set_auth_details(url, realm, out );
- }
- if( out != NULL ){
- free( out );
- }
- if( cb != NULL )
- cb(bres, cbpw);
-}
-
-void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs,
- unsigned long num,
- nserror (*cb)(bool proceed, void *pw), void *cbpw)
-{
- LOG((""));
-
- bool bres;
- /*bres = verify_ssl_form_do(url, certs, num);
- if( bres )
- urldb_set_cert_permissions(url, true);
- */
- // TODO: localize string
- int b = form_alert(1, "[2][SSL Verify failed, continue?][Continue|Abort]");
- bres = (b==1)? true : false;
- LOG(("Trust: %d", bres ));
- urldb_set_cert_permissions(url, bres);
- cb(bres, cbpw);
-}
-
-void gui_quit(void)
-{
- LOG((""));
-
- struct gui_window * gw = window_list;
- struct gui_window * tmp = window_list;
-
- while( gw ) {
- tmp = gw->next;
- browser_window_destroy(gw->browser->bw);
- gw = tmp;
- }
-
- global_history_destroy();
- hotlist_destroy();
- toolbar_exit();
-
- urldb_save_cookies(nsoption_charp(cookie_file));
- urldb_save(nsoption_charp(url_file));
-
- RsrcXtype( 0, rsc_trindex, rsc_ntree);
- unbind_global_events();
- MenuBar( h_gem_menu , 0 );
- if( h_gem_rsrc != NULL ) {
- RsrcXfree(h_gem_rsrc );
- }
- LOG(("Shutting down plotter"));
- plot_finalise();
- if( tmp_clipboard != NULL ){
- free( tmp_clipboard );
- tmp_clipboard = NULL;
- }
- LOG(("done"));
-}
-
-
-
-
-static bool
-process_cmdline(int argc, char** argv)
-{
- int opt;
- bool set_default_dimensions = true;
-
- LOG(("argc %d, argv %p", argc, argv));
-
- if ((nsoption_int(window_width) != 0) && (nsoption_int(window_height) != 0)) {
-
- option_window_width = nsoption_int(window_width);
- option_window_height = nsoption_int(window_height);
- option_window_x = nsoption_int(window_x);
- option_window_y = nsoption_int(window_y);
-
- if (option_window_width <= app.w && option_window_height < app.h) {
- set_default_dimensions = false;
- }
- }
-
- if (set_default_dimensions) {
- if( sys_type() == SYS_TOS ){
- /* on single tasking OS, start as fulled window: */
- option_window_width = app.w;
- option_window_height = app.h-20;
- option_window_x = app.w/2-(option_window_width/2);
- option_window_y = (app.h/2)-(option_window_height/2);
- } else {
- option_window_width = 600;
- option_window_height = 360;
- option_window_x = 10;
- option_window_y = 30;
- }
- }
-
- if (nsoption_charp(homepage_url) != NULL)
- option_homepage_url = nsoption_charp(homepage_url);
- else
- option_homepage_url = NETSURF_HOMEPAGE;
-
- while((opt = getopt(argc, argv, "w:h:")) != -1) {
- switch (opt) {
- case 'w':
- option_window_width = atoi(optarg);
- break;
-
- case 'h':
- option_window_height = atoi(optarg);
- break;
-
- default:
- fprintf(stderr,
- "Usage: %s [w,h,v] url\n",
- argv[0]);
- return false;
- }
- }
-
- if (optind < argc) {
- option_homepage_url = argv[optind];
- }
- return true;
-}
-
-static inline void create_cursor(int flags, short mode, void * form, MFORM_EX * m)
-{
- m->flags = flags;
- m->number = mode;
- if( flags & MFORM_EX_FLAG_USERFORM ) {
- m->number = mode;
- m->tree = (OBJECT*)form;
- }
-}
-
-nsurl *gui_get_resource_url(const char *path)
-{
- char buf[PATH_MAX];
- char *raw;
- nsurl *url = NULL;
-
- atari_find_resource((char*)&buf, path, path);
- raw = path_to_url((char*)&buf);
- if (raw != NULL) {
- nsurl_create(raw, &url);
- free(raw);
- }
-
- return url;
-}
-
-/* Documented in desktop/options.h */
-void gui_options_init_defaults(void)
-{
- /* Set defaults for absent option strings */
- nsoption_setnull_charp(cookie_file, strdup("cookies"));
-
- if (nsoption_charp(cookie_file) == NULL) {
- die("Failed initialising string options");
- }
-}
-
-static void gui_init(int argc, char** argv)
-{
- char buf[PATH_MAX];
- OBJECT * cursors;
-
- atari_find_resource(buf, "netsurf.rsc", "./res/netsurf.rsc");
- LOG(("%s ", (char*)&buf));
- h_gem_rsrc = RsrcXload( (char*) &buf );
-
- if( !h_gem_rsrc )
- die("Uable to open GEM Resource file!");
- rsc_trindex = RsrcGhdr(h_gem_rsrc)->trindex;
- rsc_ntree = RsrcGhdr(h_gem_rsrc)->ntree;
-
- RsrcGaddr( h_gem_rsrc, R_TREE, MAINMENU , &h_gem_menu );
- RsrcXtype( RSRC_XTYPE, rsc_trindex, rsc_ntree);
-
- create_cursor(0, POINT_HAND, NULL, &gem_cursors.hand );
- create_cursor(0, TEXT_CRSR, NULL, &gem_cursors.ibeam );
- create_cursor(0, THIN_CROSS, NULL, &gem_cursors.cross);
- create_cursor(0, BUSY_BEE, NULL, &gem_cursors.wait);
- create_cursor(0, ARROW, NULL, &gem_cursors.arrow);
- create_cursor(0, OUTLN_CROSS, NULL, &gem_cursors.sizeall);
- create_cursor(0, OUTLN_CROSS, NULL, &gem_cursors.sizenesw);
- create_cursor(0, OUTLN_CROSS, NULL, &gem_cursors.sizenwse);
- RsrcGaddr( h_gem_rsrc, R_TREE, CURSOR , &cursors );
- create_cursor(MFORM_EX_FLAG_USERFORM, CURSOR_APPSTART,
- cursors, &gem_cursors.appstarting);
- gem_set_cursor( &gem_cursors.appstarting );
- create_cursor(MFORM_EX_FLAG_USERFORM, CURSOR_SIZEWE,
- cursors, &gem_cursors.sizewe);
- create_cursor(MFORM_EX_FLAG_USERFORM, CURSOR_SIZENS,
- cursors, &gem_cursors.sizens);
- create_cursor(MFORM_EX_FLAG_USERFORM, CURSOR_NODROP,
- cursors, &gem_cursors.nodrop);
- create_cursor(MFORM_EX_FLAG_USERFORM, CURSOR_DENY,
- cursors, &gem_cursors.deny);
- create_cursor(MFORM_EX_FLAG_USERFORM, CURSOR_MENU,
- cursors, &gem_cursors.menu);
- create_cursor(MFORM_EX_FLAG_USERFORM, CURSOR_HELP,
- cursors, &gem_cursors.help);
-
- LOG(("Enabling core select menu"));
- nsoption_set_bool(core_select_menu, true);
-
- LOG(("Loading url.db from: %s", nsoption_charp(url_file) ));
- if( strlen(nsoption_charp(url_file)) ){
- urldb_load(nsoption_charp(url_file));
- }
-
- LOG(("Loading cookies from: %s", nsoption_charp(cookie_file) ));
- if( strlen(nsoption_charp(cookie_file)) ){
- urldb_load_cookies(nsoption_charp(cookie_file));
- }
-
- if (process_cmdline(argc,argv) != true)
- die("unable to process command line.\n");
-
- nkc_init();
- plot_init(nsoption_charp(atari_font_driver));
-}
-
-static char *theapp = (char*)"NetSurf";
-static void gui_init2(int argc, char** argv)
-{
- MenuBar( h_gem_menu , 1 );
- bind_global_events();
- menu_register( -1, theapp);
- if (sys_type() & (SYS_MAGIC|SYS_NAES|SYS_XAAES)) {
- menu_register( _AESapid, (char*)" NetSurf ");
- }
- tree_set_icon_dir( nsoption_charp(tree_icons_path) );
- global_history_init();
- hotlist_init();
- toolbar_init();
-}
-
-/* #define WITH_DBG_LOGFILE 1 */
-/** Entry point from OS.
- *
- * /param argc The number of arguments in the string vector.
- * /param argv The argument string vector.
- * /return The return code to the OS
- */
-int main(int argc, char** argv)
-{
- char messages[PATH_MAX];
-
- setbuf(stderr, NULL);
- setbuf(stdout, NULL);
-#ifdef WITH_DBG_LOGFILE
- freopen("stdout.log", "a+", stdout);
- freopen("stderr.log", "a+", stderr);
-#endif
- ApplInit();
- graf_mouse(BUSY_BEE, NULL);
- init_os_info();
- atari_find_resource((char*)&messages, "messages", "res/messages");
- atari_find_resource((char*)&options, "Choices", "Choices");
- netsurf_init(&argc, &argv, options, messages);
- gui_init(argc, argv);
- gui_init2(argc, argv);
- browser_window_create(option_homepage_url, 0, 0, true, false);
- graf_mouse( ARROW , NULL);
- netsurf_main_loop();
- netsurf_exit();
- LOG(("ApplExit"));
- ApplExit();
-#ifdef WITH_DBG_LOGFILE
- fclose(stdout);
- fclose(stderr);
-#endif
-
- return 0;
-}
-
-
+/*
+ * Copyright 2010 <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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ This File provides all the mandatory functions prefixed with gui_
+*/
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <time.h>
+#include <limits.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdbool.h>
+#include <windom.h>
+#include <hubbub/hubbub.h>
+
+#include "content/urldb.h"
+#include "content/fetch.h"
+#include "content/fetchers/resource.h"
+#include "css/utils.h"
+#include "desktop/gui.h"
+#include "desktop/history_core.h"
+#include "desktop/plotters.h"
+#include "desktop/netsurf.h"
+#include "desktop/401login.h"
+
+#include "desktop/options.h"
+#include "desktop/save_complete.h"
+#include "desktop/selection.h"
+#include "desktop/textinput.h"
+#include "desktop/browser.h"
+#include "desktop/browser_private.h"
+#include "desktop/mouse.h"
+#include "render/font.h"
+#include "utils/schedule.h"
+#include "utils/url.h"
+#include "utils/log.h"
+#include "utils/messages.h"
+#include "utils/utils.h"
+
+#include "atari/gemtk/gemtk.h"
+#include "atari/gui.h"
+#include "atari/misc.h"
+#include "atari/findfile.h"
+#include "atari/schedule.h"
+#include "atari/rootwin.h"
+#include "atari/browser.h"
+#include "atari/statusbar.h"
+#include "atari/toolbar.h"
+#include "atari/verify_ssl.h"
+#include "atari/hotlist.h"
+#include "atari/history.h"
+#include "atari/login.h"
+#include "atari/global_evnt.h"
+#include "atari/encoding.h"
+#include "atari/res/netsurf.rsh"
+#include "atari/plot/plot.h"
+#include "atari/clipboard.h"
+#include "atari/osspec.h"
+#include "atari/search.h"
+#include "atari/deskmenu.h"
+#include "cflib.h"
+
+#define TODO() (0)/*printf("%s Unimplemented!\n", __FUNCTION__)*/
+
+char *tmp_clipboard;
+struct gui_window *input_window = NULL;
+struct gui_window *window_list = NULL;
+void * h_gem_rsrc;
+long next_poll;
+bool rendering = false;
+bool gui_poll_repeat = false;
+
+
+/* Comandline / Options: */
+int option_window_width;
+int option_window_height;
+int option_window_x;
+int option_window_y;
+
+/* Defaults to option_homepage_url, commandline options overwrites that value */
+const char * option_homepage_url;
+
+/* path to choices file: */
+char options[PATH_MAX];
+
+EVMULT_IN aes_event_in = {
+ .emi_flags = MU_MESAG | MU_TIMER | MU_KEYBD | MU_BUTTON,
+ .emi_bclicks = 258,
+ .emi_bmask = 3,
+ .emi_bstate = 0,
+ .emi_m1leave = MO_ENTER,
+ .emi_m1 = {0,0,0,0},
+ .emi_m2leave = 0,
+ .emi_m2 = {0,0,0,0},
+ .emi_tlow = 0,
+ .emi_thigh = 0
+};
+EVMULT_OUT aes_event_out;
+short aes_msg_out[8];
+
+void gui_poll(bool active)
+{
+ int flags = MU_MESAG | MU_KEYBD | MU_BUTTON;
+ short mx, my, dummy;
+ unsigned short nkc = 0;
+
+ gui_poll_repeat = false;
+
+ aes_event_in.emi_tlow = schedule_run();
+
+ if(active || rendering)
+ aes_event_in.emi_tlow = 0;
+
+ struct gui_window * g;
+
+ if(input_window->root->redraw_slots.areas_used > 0){
+ window_process_redraws(input_window->root);
+ }
+
+// for( g = window_list; g != NULL; g=g->next ) {
+// if( browser_redraw_required( g ) ) {
+// browser_redraw(g);
+// }
+// if(g->root->toolbar) {
+// //if(g->root->toolbar->url.redraw ) {
+// // TODO: implement toolbar redraw mechanism
+// //tb_url_redraw( g );
+// //}
+// }
+// }
+
+ if( !active ) {
+ /* this suits for stuff with lower priority */
+ /* TBD: really be spare on redraws??? */
+ hotlist_redraw();
+ global_history_redraw();
+ }
+
+ // Handle events until there are no more messages pending or
+ // until the engine indicates activity:
+ do {
+ evnt_multi_fast(&aes_event_in, aes_msg_out, &aes_event_out);
+ if(!guiwin_dispatch_event(&aes_event_in, &aes_event_out, aes_msg_out)) {
+ if( (aes_event_out.emo_events & MU_MESAG) != 0 ) {
+ LOG(("WM: %d\n", aes_msg_out[0]));
+ switch(aes_msg_out[0]) {
+
+ case MN_SELECTED:
+ LOG(("Menu Item: %d\n",aes_msg_out[4]));
+ deskmenu_dispatch_item(aes_msg_out[3], aes_msg_out[4]);
+ break;
+ default:
+ break;
+ }
+ }
+
+ if( (aes_event_out.emo_events & MU_KEYBD) != 0 ) {
+ printf("key: %d, %d\n", aes_event_out.emo_kreturn,
+ aes_event_out.emo_kmeta);
+ nkc= gem_to_norm( (short)aes_event_out.emo_kmeta,
+ (short)aes_event_out.emo_kreturn);
+ deskmenu_dispatch_keypress(aes_event_out.emo_kreturn,
+ aes_event_out.emo_kmeta, nkc);
+ }
+ }
+ } while ( gui_poll_repeat && !(active||rendering));
+
+ if(input_window->root->redraw_slots.areas_used > 0){
+ window_process_redraws(input_window->root);
+ }
+}
+
+
+struct gui_window *
+gui_create_browser_window(struct browser_window *bw,
+ struct browser_window *clone,
+ bool new_tab) {
+ struct gui_window *gw=NULL;
+ LOG(( "gw: %p, BW: %p, clone %p, tab: %d\n" , gw, bw, clone,
+ (int)new_tab
+ ));
+
+ gw = calloc( sizeof(struct gui_window), 1);
+ if (gw == NULL)
+ return NULL;
+
+ LOG(("new window: %p, bw: %p\n", gw, bw));
+ window_create(gw, bw, WIDGET_STATUSBAR|WIDGET_TOOLBAR|WIDGET_RESIZE\
+ |WIDGET_SCROLL);
+ if (gw->root->win) {
+ GRECT pos = {
+ option_window_x, option_window_y,
+ option_window_width, option_window_height
+ };
+ gui_window_set_url(gw, "");
+ gui_window_set_pointer(gw, BROWSER_POINTER_DEFAULT);
+ window_set_active_gui_window(gw->root, gw);
+ window_open(gw->root, pos );
+ /* Recalculate windows browser area now */
+ toolbar_update_buttons(gw->root->toolbar, gw->browser->bw, -1);
+ input_window = gw;
+ /* TODO:... this line: placeholder to create a local history widget ... */
+ }
+
+ /* add the window to the window list: */
+ if( window_list == NULL ) {
+ window_list = gw;
+ gw->next = NULL;
+ gw->prev = NULL;
+ } else {
+ struct gui_window * tmp = window_list;
+ while( tmp->next != NULL ) {
+ tmp = tmp->next;
+ }
+ tmp->next = gw;
+ gw->prev = tmp;
+ gw->next = NULL;
+ }
+
+ return( gw );
+
+}
+
+void gui_window_destroy(struct gui_window *w)
+{
+ if (w == NULL)
+ return;
+
+ LOG(("%s\n", __FUNCTION__ ));
+
+ input_window = NULL;
+
+ search_destroy(w);
+ browser_destroy(w->browser);
+ free(w->status);
+ free(w->title);
+ free(w->url);
+
+ /* unlink the window: */
+ if(w->prev != NULL ) {
+ w->prev->next = w->next;
+ } else {
+ window_list = w->next;
+ }
+ if( w->next != NULL ) {
+ w->next->prev = w->prev;
+ }
+
+ window_unref_gui_window(w->root, w);
+
+ free(w);
+ w = NULL;
+
+ if(input_window == NULL){
+ w = window_list;
+ while( w != NULL ) {
+ if(w->root) {
+ input_window = w;
+ break;
+ }
+ w = w->next;
+ }
+ }
+}
+
+void gui_window_get_dimensions(struct gui_window *w, int *width, int *height,
+ bool scaled)
+{
+ if (w == NULL)
+ return;
+ GRECT rect;
+ browser_get_rect( w, BR_CONTENT, &rect );
+ *width = rect.g_w;
+ *height = rect.g_h;
+}
+
+void gui_window_set_title(struct gui_window *gw, const char *title)
+{
+
+ if (gw == NULL)
+ return;
+
+ if (gw->root) {
+
+ int l;
+ char * conv;
+ l = strlen(title)+1;
+ if (utf8_to_local_encoding(title, l, &conv) == UTF8_CONVERT_OK ) {
+ l = MIN((uint32_t)atari_sysinfo.aes_max_win_title_len, strlen(conv));
+ if(gw->title == NULL)
+ gw->title = malloc(l);
+ else
+ gw->title = realloc(gw->title, l);
+
+ strncpy(gw->title, conv, l);
+ free( conv );
+ } else {
+ l = MIN((size_t)atari_sysinfo.aes_max_win_title_len, strlen(title));
+ if(gw->title == NULL)
+ gw->title = malloc(l);
+ else
+ gw->title = realloc(gw->title, l);
+ strncpy(gw->title, title, l);
+ }
+ gw->title[l] = 0;
+ if(input_window == gw)
+ window_set_title(gw->root, gw->title);
+ }
+}
+
+/**
+ * set the status bar message
+ */
+void gui_window_set_status(struct gui_window *w, const char *text)
+{
+ int l;
+ if (w == NULL || text == NULL)
+ return;
+
+ assert(w->root);
+
+ l = strlen(text)+1;
+ if(w->status == NULL)
+ w->status = malloc(l);
+ else
+ w->status = realloc(w->status, l);
+
+ strncpy(w->status, text, l);
+ w->status[l] = 0;
+
+ if(input_window == w)
+ window_set_stauts(w->root, (char*)text);
+}
+
+void gui_window_redraw_window(struct gui_window *gw)
+{
+ CMP_BROWSER b;
+ GRECT rect;
+ if (gw == NULL)
+ return;
+ b = gw->browser;
+ browser_get_rect(gw, BR_CONTENT, &rect);
+ browser_schedule_redraw(gw, 0, 0, rect.g_w, rect.g_h );
+}
+
+void gui_window_update_box(struct gui_window *gw, const struct rect *rect)
+{
+ CMP_BROWSER b;
+ if (gw == NULL)
+ return;
+ b = gw->browser;
+ int x0 = rect->x0 - b->scroll.current.x;
+ int y0 = rect->y0 - b->scroll.current.y;
+ int w,h;
+ w = rect->x1 - rect->x0;
+ h = rect->y1 - rect->y0;
+ browser_schedule_redraw_rect( gw, x0, y0, w, h );
+}
+
+bool gui_window_get_scroll(struct gui_window *w, int *sx, int *sy)
+{
+ if (w == NULL)
+ return false;
+ *sx = w->browser->scroll.current.x;
+ *sy = w->browser->scroll.current.y;
+ return( true );
+}
+
+void gui_window_set_scroll(struct gui_window *w, int sx, int sy)
+{
+ if ((w == NULL) ||
+ (w->browser->bw == NULL) ||
+ (w->browser->bw->current_content == NULL))
+ return;
+ if( sx != 0 ) {
+ if( sx < 0 ) {
+ browser_scroll(w, WA_LFLINE, abs(sx), true );
+ } else {
+ browser_scroll(w, WA_RTLINE, abs(sx), true );
+ }
+ }
+
+ if( sy != 0 ) {
+ if( sy < 0) {
+ browser_scroll(w, WA_UPLINE, abs(sy), true );
+ } else {
+ browser_scroll(w, WA_DNLINE, abs(sy), true );
+ }
+ }
+ return;
+
+}
+
+void gui_window_scroll_visible(struct gui_window *w, int x0, int y0, int x1, int y1)
+{
+ LOG(("%s:(%p, %d, %d, %d, %d)", __func__, w, x0, y0, x1, y1));
+ gui_window_set_scroll(w,x0,y0);
+ browser_schedule_redraw_rect( w, 0, 0, x1-x0,y1-y0);
+}
+
+
+/* It seems this method is called when content size got adjusted,
+ so that we can adjust scroll info. We also have to call it when tab
+ change occurs.
+*/
+void gui_window_update_extent(struct gui_window *gw)
+{
+ int oldx, oldy;
+ oldx = gw->browser->scroll.current.x;
+ oldy = gw->browser->scroll.current.y;
+ if( gw->browser->bw->current_content != NULL ) {
+ browser_set_content_size( gw,
+ content_get_width(gw->browser->bw->current_content),
+ content_get_height(gw->browser->bw->current_content)
+ );
+ }
+}
+
+
+void gui_clear_selection(struct gui_window *g)
+{
+
+}
+
+
+
+/**
+ * set the pointer shape
+ */
+void gui_window_set_pointer(struct gui_window *gw, gui_pointer_shape shape)
+{
+ if (gw == NULL)
+ return;
+
+ switch (shape) {
+ case GUI_POINTER_POINT: /* link */
+ gw->cursor = &gem_cursors.hand;
+ break;
+
+ case GUI_POINTER_MENU:
+ gw->cursor = &gem_cursors.menu;
+ break;
+
+ case GUI_POINTER_CARET: /* input */
+ gw->cursor = &gem_cursors.ibeam;
+ break;
+
+ case GUI_POINTER_CROSS:
+ gw->cursor = &gem_cursors.cross;
+ break;
+
+ case GUI_POINTER_MOVE:
+ gw->cursor = &gem_cursors.sizeall;
+ break;
+
+ case GUI_POINTER_RIGHT:
+ case GUI_POINTER_LEFT:
+ gw->cursor = &gem_cursors.sizewe;
+ break;
+
+ case GUI_POINTER_UP:
+ case GUI_POINTER_DOWN:
+ gw->cursor = &gem_cursors.sizens;
+ break;
+
+ case GUI_POINTER_RU:
+ case GUI_POINTER_LD:
+ gw->cursor = &gem_cursors.sizenesw;
+ break;
+
+ case GUI_POINTER_RD:
+ case GUI_POINTER_LU:
+ gw->cursor = &gem_cursors.sizenwse;
+ break;
+
+ case GUI_POINTER_WAIT:
+ gw->cursor = &gem_cursors.wait;
+ break;
+
+ case GUI_POINTER_PROGRESS:
+ gw->cursor = &gem_cursors.appstarting;
+ break;
+
+ case GUI_POINTER_NO_DROP:
+ gw->cursor = &gem_cursors.nodrop;
+ break;
+
+ case GUI_POINTER_NOT_ALLOWED:
+ gw->cursor = &gem_cursors.deny;
+ break;
+
+ case GUI_POINTER_HELP:
+ gw->cursor = &gem_cursors.help;
+ break;
+
+ default:
+ gw->cursor = &gem_cursors.arrow;
+ break;
+ }
+
+ if (input_window == gw) {
+ gem_set_cursor(gw->cursor);
+ }
+}
+
+void gui_window_hide_pointer(struct gui_window *w)
+{
+ TODO();
+}
+
+
+void gui_window_set_url(struct gui_window *w, const char *url)
+{
+ int l;
+
+ if (w == NULL)
+ return;
+
+ l = strlen(url)+1;
+
+ if (w->url == NULL) {
+ w->url = malloc(l);
+ } else {
+ w->url = realloc(w->url, l);
+ }
+ strncpy(w->url, url, l);
+ w->url[l] = 0;
+ if(input_window == w->root->active_gui_window){
+ toolbar_set_url(w->root->toolbar, url);
+ }
+}
+
+static void throbber_advance( void * data )
+{
+ LGRECT work;
+ struct gui_window * gw = (struct gui_window *)data;
+ if( gw->root == NULL )
+ return;
+ if( gw->root->toolbar == NULL )
+ return;
+ // TODO: implement access to throbber
+ //if( gw->root->toolbar->throbber.running == false)
+ // return;
+// mt_CompGetLGrect(&app, gw->root->toolbar->throbber.comp,
+// WF_WORKXYWH, &work);
+// gw->root->toolbar->throbber.index++;
+// if( gw->root->toolbar->throbber.index > gw->root->toolbar->throbber.max_index )
+// gw->root->toolbar->throbber.index = THROBBER_MIN_INDEX;
+// ApplWrite(_AESapid, WM_REDRAW, guiwin_get_handle(gw->root->win),
+// work.g_x, work.g_y, work.g_w, work.g_h);
+ schedule(100, throbber_advance, gw );
+}
+
+void gui_window_start_throbber(struct gui_window *w)
+{
+ GRECT work;
+ if (w == NULL)
+ return;
+ // TODO: implement throbber acess
+ //if( w->root->toolbar->throbber.running == true )
+ // return;
+// browser_get_rect(w, BR_THROBBER, &work);
+// w->root->toolbar->throbber.running = true;
+// w->root->toolbar->throbber.index = THROBBER_MIN_INDEX;
+ schedule(100, throbber_advance, w );
+// ApplWrite( _AESapid, WM_REDRAW, guiwin_get_handle(w->root->win),
+// work.g_x, work.g_y, work.g_w, work.g_h );
+
+ rendering = true;
+}
+
+void gui_window_stop_throbber(struct gui_window *w)
+{
+ LGRECT work;
+ if (w == NULL)
+ return;
+ // TODO: implement something like throbber_is_running();
+ //if( w->root->toolbar->throbber.running == false )
+ // return;
+
+ schedule_remove(throbber_advance, w);
+
+ /* refresh toolbar buttons: */
+ toolbar_update_buttons(w->root->toolbar, w->browser->bw, -1);
+
+ /* redraw throbber: */
+// mt_CompGetLGrect(&app, w->root->toolbar->throbber.comp,
+// WF_WORKXYWH, &work);
+// w->root->toolbar->throbber.running = false;
+// ApplWrite( _AESapid, WM_REDRAW, guiwin_get_handle(w->root->win),
+// work.g_x, work.g_y, work.g_w, work.g_h );
+ // TODO: send throbber redraw
+
+ rendering = false;
+}
+
+/* Place caret in window */
+void gui_window_place_caret(struct gui_window *w, int x, int y, int height)
+{
+ if (w == NULL)
+ return;
+ if( w->browser->caret.current.g_w > 0 )
+ gui_window_remove_caret( w );
+ w->browser->caret.requested.g_x = x;
+ w->browser->caret.requested.g_y = y;
+ w->browser->caret.requested.g_w = 1;
+ w->browser->caret.requested.g_h = height;
+ w->browser->caret.redraw = true;
+ return;
+}
+
+
+/**
+ * clear window caret
+ */
+void
+gui_window_remove_caret(struct gui_window *w)
+{
+ if (w == NULL)
+ return;
+
+ if( w->browser->caret.background.fd_addr != NULL ) {
+ browser_restore_caret_background( w, NULL );
+ w->browser->caret.requested.g_w = 0;
+ w->browser->caret.current.g_w = 0;
+ }
+ return;
+}
+
+void
+gui_window_set_icon(struct gui_window *g, hlcache_handle *icon)
+{
+ struct bitmap *bmp_icon;
+
+ bmp_icon = (icon != NULL) ? content_get_bitmap(icon) : NULL;
+ g->icon = bmp_icon;
+
+ if(input_window == g){
+ window_set_icon(g->root, bmp_icon);
+ }
+}
+
+void
+gui_window_set_search_ico(hlcache_handle *ico)
+{
+ TODO();
+}
+
+void gui_window_new_content(struct gui_window *w)
+{
+ w->browser->scroll.current.x = 0;
+ w->browser->scroll.current.y = 0;
+ w->browser->scroll.requested.x = 0;
+ w->browser->scroll.requested.y = 0;
+ w->browser->scroll.required = true;
+ gui_window_redraw_window( w );
+}
+
+bool gui_window_scroll_start(struct gui_window *w)
+{
+ TODO();
+ return true;
+}
+
+bool gui_window_drag_start(struct gui_window *g, gui_drag_type type,
+ const struct rect *rect)
+{
+ TODO();
+ return true;
+}
+
+void gui_window_save_link(struct gui_window *g, const char *url,
+ const char *title)
+{
+ LOG(("%s -> %s", title, url ));
+ TODO();
+}
+
+void gui_drag_save_object(gui_save_type type, hlcache_handle *c,
+ struct gui_window *w)
+{
+ LOG((""));
+ TODO();
+}
+
+void gui_drag_save_selection(struct selection *s, struct gui_window *w)
+{
+ LOG((""));
+ TODO();
+}
+
+void gui_start_selection(struct gui_window *w)
+{
+ gui_empty_clipboard();
+}
+
+void gui_paste_from_clipboard(struct gui_window *w, int x, int y)
+{
+ char * clip = scrap_txt_read( &app );
+ if( clip == NULL )
+ return;
+ int clip_length = strlen( clip );
+ if (clip_length > 0) {
+ char *utf8;
+ utf8_convert_ret ret;
+ /* Clipboard is in local encoding so
+ * convert to UTF8 */
+ ret = utf8_from_local_encoding(clip,
+ clip_length, &utf8);
+ if (ret == UTF8_CONVERT_OK) {
+ browser_window_paste_text(w->browser->bw, utf8,
+ strlen(utf8), true);
+ free(utf8);
+ }
+ free( clip );
+ }
+}
+
+bool gui_empty_clipboard(void)
+{
+ if( tmp_clipboard != NULL ) {
+ free( tmp_clipboard );
+ tmp_clipboard = NULL;
+ }
+ return true;
+}
+
+bool gui_add_to_clipboard(const char *text_utf8, size_t length_utf8, bool space,
+ const plot_font_style_t *fstyle)
+{
+ LOG(("(%s): %s (%d)\n", (space)?"space":"", (char*)text_utf8, (int)length_utf8));
+ char * oldptr = tmp_clipboard;
+ size_t oldlen = 0;
+ size_t newlen = 0;
+ char * text = NULL;
+ char * text2 = NULL;
+ bool retval;
+ int length = 0;
+ if( length_utf8 > 0 && text_utf8 != NULL ) {
+ utf8_to_local_encoding(text_utf8,length_utf8,&text);
+ if( text == NULL ) {
+ LOG(("Conversion failed (%s)", text_utf8));
+ goto error;
+ } else {
+ text2 = text;
+ }
+ } else {
+ if( space == false ) {
+ goto success;
+ }
+ text = malloc(length + 2);
+ if( text == NULL ) {
+ goto error;
+ }
+ text2 = text;
+ text[length+1] = 0;
+ memset(text, ' ', length+1);
+ }
+ length = strlen(text);
+ if( tmp_clipboard != NULL ) {
+ oldlen = strlen( tmp_clipboard );
+ }
+ newlen = oldlen + length + 1;
+ if( tmp_clipboard == NULL) {
+ tmp_clipboard = malloc(newlen);
+ if( tmp_clipboard == NULL ) {
+ goto error;
+ }
+ strncpy(tmp_clipboard, text, newlen);
+ } else {
+ tmp_clipboard = realloc( tmp_clipboard, newlen);
+ if( tmp_clipboard == NULL ) {
+ goto error;
+ }
+ strncpy(tmp_clipboard, oldptr, newlen);
+ strncat(tmp_clipboard, text, newlen-oldlen);
+ }
+ goto success;
+
+error:
+ retval = false;
+ goto fin;
+
+success:
+ retval = true;
+
+fin:
+ if( text2 != NULL )
+ free( text2 );
+ return(retval);
+
+}
+
+bool gui_commit_clipboard(void)
+{
+ int r = scrap_txt_write(&app, tmp_clipboard);
+ return( (r>0)?true:false );
+}
+
+bool gui_copy_to_clipboard(struct selection *s)
+{
+ bool ret = false;
+ if( s->defined ) {
+ gui_empty_clipboard();
+ if(selection_copy_to_clipboard(s)) {
+ ret = gui_commit_clipboard();
+ }
+ }
+ gui_empty_clipboard();
+ return ret;
+}
+
+
+void gui_create_form_select_menu(struct browser_window *bw,
+ struct form_control *control)
+{
+ TODO();
+}
+
+/**
+ * Broadcast an URL that we can't handle.
+ */
+void gui_launch_url(const char *url)
+{
+ TODO();
+ LOG(("launch file: %s\n", url));
+}
+
+void gui_401login_open(nsurl *url, const char *realm,
+ nserror (*cb)(bool proceed, void *pw), void *cbpw)
+{
+ bool bres;
+ char * out = NULL;
+ bres = login_form_do( url, (char*)realm, &out );
+ if( bres ) {
+ LOG(("url: %s, realm: %s, auth: %s\n", url, realm, out ));
+ urldb_set_auth_details(url, realm, out );
+ }
+ if( out != NULL ) {
+ free( out );
+ }
+ if( cb != NULL )
+ cb(bres, cbpw);
+}
+
+void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs,
+ unsigned long num,
+ nserror (*cb)(bool proceed, void *pw), void *cbpw)
+{
+ LOG((""));
+
+ bool bres;
+ /*bres = verify_ssl_form_do(url, certs, num);
+ if( bres )
+ urldb_set_cert_permissions(url, true);
+ */
+ // TODO: localize string
+ int b = form_alert(1, "[2][SSL Verify failed, continue?][Continue|Abort]");
+ bres = (b==1)? true : false;
+ LOG(("Trust: %d", bres ));
+ urldb_set_cert_permissions(url, bres);
+ cb(bres, cbpw);
+}
+
+void gui_quit(void)
+{
+ LOG((""));
+
+ struct gui_window * gw = window_list;
+ struct gui_window * tmp = window_list;
+
+ unbind_global_events();
+
+ while( gw ) {
+ tmp = gw->next;
+ browser_window_destroy(gw->browser->bw);
+ gw = tmp;
+ }
+
+ global_history_destroy();
+ hotlist_destroy();
+ toolbar_exit();
+
+ urldb_save_cookies(nsoption_charp(cookie_file));
+ urldb_save(nsoption_charp(url_file));
+
+ deskmenu_destroy();
+ guiwin_exit();
+
+ rsrc_free();
+
+ LOG(("Shutting down plotter"));
+ plot_finalise();
+ if( tmp_clipboard != NULL ) {
+ free( tmp_clipboard );
+ tmp_clipboard = NULL;
+ }
+ LOG(("done"));
+}
+
+
+
+
+static bool
+process_cmdline(int argc, char** argv)
+{
+ int opt;
+ bool set_default_dimensions = true;
+
+ LOG(("argc %d, argv %p", argc, argv));
+
+ if ((nsoption_int(window_width) != 0) && (nsoption_int(window_height) != 0)) {
+
+ option_window_width = nsoption_int(window_width);
+ option_window_height = nsoption_int(window_height);
+ option_window_x = nsoption_int(window_x);
+ option_window_y = nsoption_int(window_y);
+
+ if (option_window_width <= app.w && option_window_height < app.h) {
+ set_default_dimensions = false;
+ }
+ }
+
+ if (set_default_dimensions) {
+ if( sys_type() == SYS_TOS ) {
+ /* on single tasking OS, start as fulled window: */
+ option_window_width = app.w;
+ option_window_height = app.h-20;
+ option_window_x = app.w/2-(option_window_width/2);
+ option_window_y = (app.h/2)-(option_window_height/2);
+ } else {
+ option_window_width = 600;
+ option_window_height = 360;
+ option_window_x = 10;
+ option_window_y = 30;
+ }
+ }
+
+ if (nsoption_charp(homepage_url) != NULL)
+ option_homepage_url = nsoption_charp(homepage_url);
+ else
+ option_homepage_url = NETSURF_HOMEPAGE;
+
+ while((opt = getopt(argc, argv, "w:h:")) != -1) {
+ switch (opt) {
+ case 'w':
+ option_window_width = atoi(optarg);
+ break;
+
+ case 'h':
+ option_window_height = atoi(optarg);
+ break;
+
+ default:
+ fprintf(stderr,
+ "Usage: %s [w,h,v] url\n",
+ argv[0]);
+ return false;
+ }
+ }
+
+ if (optind < argc) {
+ option_homepage_url = argv[optind];
+ }
+ return true;
+}
+
+static inline void create_cursor(int flags, short mode, void * form,
+ MFORM_EX * m)
+{
+ m->flags = flags;
+ m->number = mode;
+ if( flags & MFORM_EX_FLAG_USERFORM ) {
+ m->number = mode;
+ m->tree = (OBJECT*)form;
+ }
+}
+
+nsurl *gui_get_resource_url(const char *path)
+{
+ char buf[PATH_MAX];
+ char *raw;
+ nsurl *url = NULL;
+
+ atari_find_resource((char*)&buf, path, path);
+ raw = path_to_url((char*)&buf);
+ if (raw != NULL) {
+ nsurl_create(raw, &url);
+ free(raw);
+ }
+
+ return url;
+}
+
+/* Documented in desktop/options.h */
+void gui_options_init_defaults(void)
+{
+ /* Set defaults for absent option strings */
+ nsoption_setnull_charp(cookie_file, strdup("cookies"));
+
+ if (nsoption_charp(cookie_file) == NULL) {
+ die("Failed initialising string options");
+ }
+}
+
+static void gui_init(int argc, char** argv)
+{
+ char buf[PATH_MAX];
+ OBJECT * cursors;
+
+ atari_find_resource(buf, "netsurf.rsc", "./res/netsurf.rsc");
+ LOG(("%s ", (char*)&buf));
+ if (rsrc_load(buf)==0) {
+ die("Uable to open GEM Resource file!");
+ }
+
+ create_cursor(0, POINT_HAND, NULL, &gem_cursors.hand );
+ create_cursor(0, TEXT_CRSR, NULL, &gem_cursors.ibeam );
+ create_cursor(0, THIN_CROSS, NULL, &gem_cursors.cross);
+ create_cursor(0, BUSY_BEE, NULL, &gem_cursors.wait);
+ create_cursor(0, ARROW, NULL, &gem_cursors.arrow);
+ create_cursor(0, OUTLN_CROSS, NULL, &gem_cursors.sizeall);
+ create_cursor(0, OUTLN_CROSS, NULL, &gem_cursors.sizenesw);
+ create_cursor(0, OUTLN_CROSS, NULL, &gem_cursors.sizenwse);
+ cursors = get_tree(CURSOR);
+ create_cursor(MFORM_EX_FLAG_USERFORM, CURSOR_APPSTART,
+ cursors, &gem_cursors.appstarting);
+ gem_set_cursor( &gem_cursors.appstarting );
+ create_cursor(MFORM_EX_FLAG_USERFORM, CURSOR_SIZEWE,
+ cursors, &gem_cursors.sizewe);
+ create_cursor(MFORM_EX_FLAG_USERFORM, CURSOR_SIZENS,
+ cursors, &gem_cursors.sizens);
+ create_cursor(MFORM_EX_FLAG_USERFORM, CURSOR_NODROP,
+ cursors, &gem_cursors.nodrop);
+ create_cursor(MFORM_EX_FLAG_USERFORM, CURSOR_DENY,
+ cursors, &gem_cursors.deny);
+ create_cursor(MFORM_EX_FLAG_USERFORM, CURSOR_MENU,
+ cursors, &gem_cursors.menu);
+ create_cursor(MFORM_EX_FLAG_USERFORM, CURSOR_HELP,
+ cursors, &gem_cursors.help);
+
+ LOG(("Enabling core select menu"));
+ nsoption_set_bool(core_select_menu, true);
+
+ LOG(("Loading url.db from: %s", nsoption_charp(url_file) ));
+ if( strlen(nsoption_charp(url_file)) ) {
+ urldb_load(nsoption_charp(url_file));
+ }
+
+ LOG(("Loading cookies from: %s", nsoption_charp(cookie_file) ));
+ if( strlen(nsoption_charp(cookie_file)) ) {
+ urldb_load_cookies(nsoption_charp(cookie_file));
+ }
+
+ if (process_cmdline(argc,argv) != true)
+ die("unable to process command line.\n");
+
+ nkc_init();
+ plot_init(nsoption_charp(atari_font_driver));
+ tree_set_icon_dir( nsoption_charp(tree_icons_path) );
+}
+
+static char *theapp = (char*)"NetSurf";
+static void gui_init2(int argc, char** argv)
+{
+ deskmenu_init();
+ menu_register( -1, theapp);
+ if (sys_type() & (SYS_MAGIC|SYS_NAES|SYS_XAAES)) {
+ menu_register( _AESapid, (char*)" NetSurf ");
+ }
+ guiwin_init();
+ bind_global_events();
+ global_history_init();
+ hotlist_init();
+ toolbar_init();
+}
+
+/* #define WITH_DBG_LOGFILE 1 */
+/** Entry point from OS.
+ *
+ * /param argc The number of arguments in the string vector.
+ * /param argv The argument string vector.
+ * /return The return code to the OS
+ */
+int main(int argc, char** argv)
+{
+ char messages[PATH_MAX];
+
+ setbuf(stderr, NULL);
+ setbuf(stdout, NULL);
+#ifdef WITH_DBG_LOGFILE
+ freopen("stdout.log", "a+", stdout);
+ freopen("stderr.log", "a+", stderr);
+#endif
+ // todo: replace with appl_init
+ ApplInit();
+ gl_apid = _AESapid;
+ graf_mouse(BUSY_BEE, NULL);
+ init_os_info();
+ atari_find_resource((char*)&messages, "messages", "res/messages");
+ atari_find_resource((char*)&options, "Choices", "Choices");
+ netsurf_init(&argc, &argv, options, messages);
+ gui_init(argc, argv);
+ gui_init2(argc, argv);
+ browser_window_create(option_homepage_url, 0, 0, true, false);
+ graf_mouse( ARROW , NULL);
+ netsurf_main_loop();
+ netsurf_exit();
+ LOG(("ApplExit"));
+ ApplExit();
+#ifdef WITH_DBG_LOGFILE
+ fclose(stdout);
+ fclose(stderr);
+#endif
+
+ return 0;
+}
+
+
diff --git a/atari/gui.h b/atari/gui.h
index 76de07f37..88601917e 100755
--- a/atari/gui.h
+++ b/atari/gui.h
@@ -19,7 +19,8 @@
#ifndef NS_ATARI_GUI_H_
#define NS_ATARI_GUI_H_
-#include <windom.h>
+#include "atari/redrawslots.h"
+#include "atari/gemtk/gemtk.h"
struct point_s {
int x;
@@ -96,17 +97,19 @@ typedef struct s_browser * CMP_BROWSER;
*/
struct s_gui_win_root
{
- WINDOW * handle;
+ GUIWIN *win;
CMP_TOOLBAR toolbar;
CMP_STATUSBAR statusbar;
- COMPONENT * cmproot;
- MFORM_EX cursor;
struct s_focus_info focus;
float scale;
char * title;
+ struct bitmap * icon;
+ struct gui_window *active_gui_window;
+ struct s_redrw_slots redraw_slots;
/* current size of window on screen: */
GRECT loc;
};
+typedef struct s_gui_win_root ROOTWIN;
/*
This is the part of the gui which is known by netsurf core.
@@ -117,7 +120,11 @@ struct s_gui_win_root
struct gui_window {
struct s_gui_win_root * root;
CMP_BROWSER browser;
+ MFORM_EX *cursor;
/* icon to be drawn when iconified, or NULL for default resource. */
+ char * status;
+ char * title;
+ char * url;
struct bitmap * icon;
struct gui_window *next, *prev;
};
diff --git a/atari/history.c b/atari/history.c
index ad5deb2bd..6e84ad30e 100755
--- a/atari/history.c
+++ b/atari/history.c
@@ -45,74 +45,87 @@ struct s_atari_global_history gl_history;
void global_history_open( void )
{
- GRECT pos = {app.w - (app.w/3), app.y, app.w/3, app.h/2};
-
if (gl_history.init == false ) {
- printf("history not init");
return;
}
if( gl_history.open == false ) {
- WindOpen( gl_history.window, pos.g_x, pos.g_y, pos.g_w, pos.g_h);
+
+ GRECT pos;
+ wind_get_grect(0, WF_FULLXYWH, &pos);
+ pos.g_x = pos.g_w - pos.g_w / 4;
+ pos.g_y = pos.g_y;
+ pos.g_w = pos.g_w / 4;
+ pos.g_h = pos.g_h;
+
+ wind_open(guiwin_get_handle(gl_history.window), pos.g_x, pos.g_y,
+ pos.g_w, pos.g_h);
gl_history.open = true;
- atari_treeview_open( gl_history.tv );
+ atari_treeview_open(gl_history.tv);
} else {
- WindTop( gl_history.window );
+ wind_set(guiwin_get_handle(gl_history.window), WF_TOP, 1, 0, 0, 0);
}
}
void global_history_close( void )
{
- WindClose(gl_history.window);
+ wind_close(guiwin_get_handle(gl_history.window));
gl_history.open = false;
- atari_treeview_close( gl_history.tv );
+ atari_treeview_close(gl_history.tv);
}
-
-static void __CDECL evnt_history_close( WINDOW *win, short buff[8] )
+static short handle_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8])
{
- global_history_close();
-}
+ NSTREEVIEW tv=NULL;
+ printf("Hotlist event %d, open: %d\n", ev_out->emo_events, gl_history.open);
-static void __CDECL evnt_history_mbutton( WINDOW *win, short buff[8] )
-{
- /* todo: implement popup?
- if(evnt.mbut & 2) {
+ if(ev_out->emo_events & MU_MESAG){
+ switch (msg[0]) {
+
+ case WM_CLOSED:
+ global_history_close();
+ break;
+ default: break;
+ }
}
- */
+
+ // TODO: implement selectable objects in toolbar API:
+ // ObjcChange( OC_TOOLBAR, win, buff[4], ~SELECTED, OC_MSG );
}
bool global_history_init( void )
{
- if( gl_history.init == false ) {
+ if( gl_history.init == false ) {
+
+ short handle;
+ GRECT desk;
+ int flags = ATARI_TREEVIEW_WIDGETS;
- int flags = ATARI_TREEVIEW_WIDGETS;
- gl_history.open = false;
- gl_history.window = WindCreate( flags, 40, 40, app.w, app.h );
- if( gl_history.window == NULL ) {
+ wind_get_grect(0, WF_FULLXYWH, &desk);
+
+ gl_history.open = false;
+ handle = wind_create(flags, 40, 40, desk.g_w, desk.g_h);
+ gl_history.window = guiwin_add(handle, GW_FLAG_DEFAULTS, NULL);
+ if( gl_history.window == NULL ) {
LOG(("Failed to allocate history window"));
return( false );
}
- WindSetStr(gl_history.window, WF_NAME, messages_get("GlobalHistory"));
- //WindSetPtr( gl_history.window, WF_TOOLBAR, tree, evnt_history_toolbar );
- EvntAttach( gl_history.window, WM_CLOSED, evnt_history_close );
- EvntAttach( gl_history.window, WM_XBUTTON,evnt_history_mbutton );
-
- gl_history.tv = atari_treeview_create(
- history_global_get_tree_flags(),
- gl_history.window
- );
- if (gl_history.tv == NULL) {
- /* handle it properly, clean up previous allocs */
- LOG(("Failed to allocate history treeview"));
- return( false );
- }
+ wind_set_str(handle, WF_NAME, (char*)messages_get("GlobalHistory"));
- history_global_initialise( gl_history.tv->tree, "dir.png" );
- gl_history.init = true;
- }
+ gl_history.tv = atari_treeview_create(history_global_get_tree_flags(),
+ gl_history.window, handle_event);
+
+ if (gl_history.tv == NULL) {
+ /* TODO: handle it properly, clean up previous allocs */
+ LOG(("Failed to allocate history treeview"));
+ return( false );
+ }
+
+ history_global_initialise(gl_history.tv->tree, "dir.png");
+ gl_history.init = true;
+ }
return( true );
}
@@ -126,9 +139,10 @@ void global_history_destroy( void )
history_global_cleanup();
if( gl_history.open )
global_history_close();
- WindDelete( gl_history.window );
+ wind_delete(guiwin_get_handle(gl_history.window));
+ guiwin_remove(gl_history.window);
gl_history.window = NULL;
- atari_treeview_destroy( gl_history.tv );
+ atari_treeview_destroy(gl_history.tv);
gl_history.init = false;
}
LOG(("done"));
diff --git a/atari/history.h b/atari/history.h
index bfea9ec1d..2935793ac 100755
--- a/atari/history.h
+++ b/atari/history.h
@@ -23,9 +23,10 @@
#include <windom.h>
#include "desktop/tree.h"
#include "atari/treeview.h"
+#include "atari/gemtk/gemtk.h"
struct s_atari_global_history {
- WINDOW * window;
+ GUIWIN *window; /*< The GEMTK window ref */
NSTREEVIEW tv; /*< The history treeview handle. */
bool open;
bool init;
diff --git a/atari/hotlist.c b/atari/hotlist.c
index bdd10d922..72d3445b5 100755
--- a/atari/hotlist.c
+++ b/atari/hotlist.c
@@ -22,6 +22,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
+
#include "desktop/browser.h"
#include "content/content.h"
#include "content/hlcache.h"
@@ -40,49 +41,62 @@
#include "atari/treeview.h"
#include "atari/hotlist.h"
#include "atari/findfile.h"
+#include "atari/gemtk/gemtk.h"
#include "atari/res/netsurf.rsh"
struct atari_hotlist hl;
-static void evnt_hl_toolbar( WINDOW *win, short buff[8]) {
- /* handle toolbar object (index in buff[4] ) */
- switch( buff[4] ) {
- case TOOLBAR_HOTLIST_CREATE_FOLDER:
- hotlist_add_folder(true);
- break;
+static short handle_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8])
+{
+ NSTREEVIEW tv=NULL;
+ GRECT tb_area;
- case TOOLBAR_HOTLIST_ADD:
- atari_hotlist_add_page("http://www.de", "");
- break;
+ if(ev_out->emo_events & MU_MESAG){
+ switch (msg[0]) {
- case TOOLBAR_HOTLIST_DELETE:
- hotlist_delete_selected();
- break;
+ case WM_TOOLBAR:
- case TOOLBAR_HOTLIST_EDIT:
- hotlist_edit_selected();
- break;
- }
- ObjcChange( OC_TOOLBAR, win, buff[4], ~SELECTED, OC_MSG );
-}
+ tv = (NSTREEVIEW) guiwin_get_user_data(win);
+ switch (msg[4]) {
+ case TOOLBAR_HOTLIST_CREATE_FOLDER:
+ hotlist_add_folder(true);
+ break;
-static void __CDECL evnt_hl_close( WINDOW *win, short buff[8] )
-{
- hotlist_close();
-}
+ case TOOLBAR_HOTLIST_ADD:
+ atari_hotlist_add_page("http://www.de", "");
+ break;
+ case TOOLBAR_HOTLIST_DELETE:
+ hotlist_delete_selected();
+ guiwin_send_redraw(tv->window, NULL);
+ break;
-static void __CDECL evnt_hl_mbutton( WINDOW *win, short buff[8] )
-{
- /* todo: implement popup?
- if(evnt.mbut & 2) {
+ case TOOLBAR_HOTLIST_EDIT:
+ hotlist_edit_selected();
+ break;
+ }
+
+ get_tree(TOOLBAR_HOTLIST)[msg[4]].ob_state &= ~OS_SELECTED;
+ guiwin_get_grect(tv->window, GUIWIN_AREA_TOOLBAR, &tb_area);
+ evnt_timer(150);
+ guiwin_send_redraw(tv->window, &tb_area);
+ break;
+
+ case WM_CLOSED:
+ hotlist_close();
+ break;
+ default: break;
+ }
}
- */
+
+ // TODO: implement selectable objects in toolbar API:
+ // ObjcChange( OC_TOOLBAR, win, buff[4], ~SELECTED, OC_MSG );
}
+
void hotlist_init(void)
{
if( strcmp(nsoption_charp(hotlist_file), "") == 0 ){
@@ -95,21 +109,26 @@ void hotlist_init(void)
if( hl.window == NULL ){
int flags = ATARI_TREEVIEW_WIDGETS;
+ short handle = -1;
+ GRECT desk;
OBJECT * tree = get_tree(TOOLBAR_HOTLIST);
assert( tree );
hl.open = false;
- hl.window = WindCreate( flags, 40, 40, app.w, app.h );
+
+ wind_get_grect(0, WF_FULLXYWH, &desk);
+
+ handle = wind_create(flags, 0, 0, desk.g_w, desk.g_h);
+ hl.window = guiwin_add(handle, GW_FLAG_DEFAULTS, NULL);
if( hl.window == NULL ) {
LOG(("Failed to allocate Hotlist"));
return;
}
- WindSetStr( hl.window, WF_NAME, (char*)messages_get("Hotlist") );
- WindSetPtr( hl.window, WF_TOOLBAR, tree, evnt_hl_toolbar );
- EvntAttach( hl.window, WM_CLOSED, evnt_hl_close );
- EvntAttach( hl.window, WM_XBUTTON,evnt_hl_mbutton );
+ wind_set_str(handle, WF_NAME, (char*)messages_get("Hotlist"));
+ guiwin_set_toolbar(hl.window, tree, 0, 0);
hl.tv = atari_treeview_create(
hotlist_get_tree_flags(),
- hl.window
+ hl.window,
+ handle_event
);
if (hl.tv == NULL) {
/* handle it properly, clean up previous allocs */
@@ -132,24 +151,30 @@ void hotlist_init(void)
void hotlist_open(void)
{
- GRECT pos = {app.w - (app.w/3), app.y, app.w/3, app.h/2};
-
if( hl.init == false ) {
return;
}
if( hl.open == false ) {
- WindOpen( hl.window, pos.g_x, pos.g_y, pos.g_w, pos.g_h);
+
+ GRECT pos;
+ wind_get_grect(0, WF_FULLXYWH, &pos);
+ pos.g_x = pos.g_w - pos.g_w / 4;
+ pos.g_y = pos.g_y;
+ pos.g_w = pos.g_w / 4;
+ pos.g_h = pos.g_h;
+
+ wind_open_grect(guiwin_get_handle(hl.window), &pos);
hl.open = true;
atari_treeview_open( hl.tv );
} else {
- WindTop( hl.window );
+ wind_set(guiwin_get_handle(hl.window), WF_TOP, 1, 0, 0, 0);
}
}
void hotlist_close(void)
{
- WindClose(hl.window);
+ wind_close(guiwin_get_handle(hl.window));
hl.open = false;
atari_treeview_close( hl.tv );
}
@@ -163,7 +188,8 @@ void hotlist_destroy(void)
hotlist_cleanup( (char*)&hl.path );
if( hl.open )
hotlist_close();
- WindDelete( hl.window );
+ wind_delete(guiwin_get_handle(hl.window));
+ guiwin_remove(hl.window);
hl.window = NULL;
atari_treeview_destroy( hl.tv );
hl.init = false;
diff --git a/atari/hotlist.h b/atari/hotlist.h
index 70b4d8a70..858d1a1bf 100755
--- a/atari/hotlist.h
+++ b/atari/hotlist.h
@@ -21,11 +21,12 @@
#include <stdbool.h>
#include <windom.h>
#include "desktop/tree.h"
+#include "atari/gemtk/gemtk.h"
#include "atari/treeview.h"
/* The hotlist window, toolbar and treeview data. */
struct atari_hotlist {
- WINDOW * window;
+ GUIWIN * window;
NSTREEVIEW tv; /*< The hotlist treeview handle. */
bool open;
bool init;
diff --git a/atari/misc.c b/atari/misc.c
index 8b745fd2f..22f820eb6 100755
--- a/atari/misc.c
+++ b/atari/misc.c
@@ -42,7 +42,7 @@
#include "atari/browser.h"
#include "atari/misc.h"
#include "atari/encoding.h"
-#include "atari/msgbox.h"
+#include "atari/gemtk/gemtk.h"
#include "cflib.h"
extern void * h_gem_rsrc;
@@ -111,10 +111,7 @@ bool path_add_part(char *path, int length, const char *newpart)
return true;
}
-/*
- TBD: make use of this function or remove it...
-*/
-struct gui_window * find_gui_window( unsigned long handle, short mode ){
+struct gui_window * find_guiwin_by_aes_handle(short handle){
struct gui_window * gw;
gw = window_list;
@@ -122,47 +119,20 @@ struct gui_window * find_gui_window( unsigned long handle, short mode ){
if( handle == 0 ){
return( NULL );
}
- else if( mode == BY_WINDOM_HANDLE ){
- WINDOW * win = (WINDOW*) handle;
- while( gw != NULL) {
- if( gw->root->handle == win ) {
- return( gw );
- }
- else
- gw = gw->next;
- }
- }
- else if( mode == BY_GEM_HANDLE ){
- short ghandle = (short)handle;
- while( gw != NULL) {
- if( gw->root->handle != NULL
- && gw->root->handle->handle == ghandle ) {
- return( gw );
- }
- else
- gw = gw->next;
- }
- }
-
- return( NULL );
-}
-
-
-struct gui_window * find_cmp_window( COMPONENT * c )
-{
- struct gui_window * gw;
- gw = window_list;
- while( gw != NULL ) {
- assert( gw->browser != NULL );
- if( gw->browser->comp == c ) {
- return( gw );
+
+ while(gw != NULL) {
+ if( gw->root->win != NULL
+ && guiwin_get_handle(gw->root->win) == handle ) {
+ return(gw);
}
else
gw = gw->next;
}
+
return( NULL );
}
-
+
+
static int scan_process_list(scan_process_callback cb, void *data)
{
int pid, count = 0;
@@ -260,25 +230,6 @@ bool is_process_running(const char * name)
}
-/* -------------------------------------------------------------------------- */
-/* GEM Utillity functions: */
-/* -------------------------------------------------------------------------- */
-
-/* Return a string from resource file */
-char *get_rsc_string( int idx) {
- char *txt;
- RsrcGaddr( h_gem_rsrc, R_STRING, idx, &txt );
- return txt;
-}
-
-OBJECT *get_tree( int idx) {
- OBJECT *tree;
- RsrcGaddr( h_gem_rsrc, R_TREE, idx, &tree);
- return tree;
-}
-
-
-
/**
* Callback for load_icon(). Should be removed once bitmaps get loaded directly
* from disc
diff --git a/atari/misc.h b/atari/misc.h
index 612113fc1..cab2a8cb7 100755
--- a/atari/misc.h
+++ b/atari/misc.h
@@ -19,6 +19,7 @@
#ifndef NS_ATARI_MISC_H
#define NS_ATARI_MISC_H
+#include <windom.h>
#include "cflib.h"
#include "content/content.h"
#include "content/hlcache.h"
@@ -42,11 +43,8 @@
typedef int (*scan_process_callback)(int pid, void *data);
-struct gui_window * find_gui_window( unsigned long, short mode );
-struct gui_window * find_cmp_window( COMPONENT * c );
+struct gui_window * find_guiwin_by_aes_handle(short handle);
bool is_process_running(const char * name);
-OBJECT *get_tree( int idx );
-char *get_rsc_string( int idx );
void gem_set_cursor( MFORM_EX * cursor );
hlcache_handle *load_icon( const char *name, hlcache_handle_callback cb,
void * pw );
diff --git a/atari/msgbox.h b/atari/msgbox.h
deleted file mode 100644
index 204a49050..000000000
--- a/atari/msgbox.h
+++ /dev/null
@@ -1,10 +0,0 @@
-#ifndef GUIMSG_H_INCLUDED
-#define GUIMSG_H_INCLUDED
-
-#define MSG_BOX_ALERT 1
-#define MSG_BOX_CONFIRM 2
-
-short msg_box_show(short type, char * msg);
-
-
-#endif // GUIMSG_H_INCLUDED
diff --git a/atari/osspec.c b/atari/osspec.c
index d697f43d9..c2e2252dd 100644
--- a/atari/osspec.c
+++ b/atari/osspec.c
@@ -28,7 +28,8 @@
#include <windom.h>
#include "utils/log.h"
-#include "atari/osspec.h"
+#include "atari/osspec.h"
+#include "atari/gemtk/gemtk.h"
#ifndef PATH_MAX
#define PATH_MAX 1024
@@ -36,38 +37,6 @@
NS_ATARI_SYSINFO atari_sysinfo;
-unsigned short _systype_v;
-unsigned short _systype (void)
-{
- int32_t * cptr = NULL;
- _systype_v = SYS_TOS;
-
- cptr = (int32_t *)Setexc(0x0168, -1L);
- if (cptr == NULL ) {
- return _systype_v; /* stone old TOS without any cookie support */
- }
- while (*cptr) {
- if (*cptr == C_MgMc || *cptr == C_MgMx ) {
- _systype_v = (_systype_v & ~0xF) | SYS_MAGIC;
- } else if (*cptr == C_MiNT ) {
- _systype_v = (_systype_v & ~0xF) | SYS_MINT;
- } else if (*cptr == C_Gnva /* Gnva */ ) {
- _systype_v |= SYS_GENEVA;
- } else if (*cptr == C_nAES /* nAES */ ) {
- _systype_v |= SYS_NAES;
- }
- cptr += 2;
- }
- if (_systype_v & SYS_MINT) { /* check for XaAES */
- short out = 0, u;
- if (wind_get (0, (((short)'X') <<8)|'A', &out, &u,&u,&u) && out) {
- _systype_v |= SYS_XAAES;
- }
- }
- LOG(("Detected OS: %d\n", _systype_v ));
- return _systype_v;
-}
-
void init_os_info(void)
{
int16_t out[4];
diff --git a/atari/osspec.h b/atari/osspec.h
index 91cf2f03b..29f87cccf 100644
--- a/atari/osspec.h
+++ b/atari/osspec.h
@@ -17,27 +17,13 @@
*/
#ifndef NS_ATARI_OSSPEC_H
-#define NS_ATARI_OSSPEC_H
-
+#define NS_ATARI_OSSPEC_H
+
typedef struct {
long c;
long v;
} COOKIE;
-/* System type detection added by [GS] */
-#define SYS_TOS 0x0001
-#define SYS_MAGIC 0x0002
-#define SYS_MINT 0x0004
-#define SYS_GENEVA 0x0010
-#define SYS_NAES 0x0020
-#define SYS_XAAES 0x0040
-/* detect the system type, AES + kernel */
-#define sys_type() (_systype_v ? _systype_v : _systype())
-#define sys_MAGIC() ((sys_type() & SYS_MAGIC) != 0)
-#define sys_NAES() ((sys_type() & SYS_NAES) != 0)
-#define sys_XAAES() ((sys_type() & SYS_XAAES) != 0)
-
-
typedef struct {
unsigned short gemdos_version;
unsigned short gdos_FSMC;
@@ -50,13 +36,9 @@ typedef struct {
} NS_ATARI_SYSINFO;
extern NS_ATARI_SYSINFO atari_sysinfo;
-extern unsigned short _systype_v;
-
-#define TOS4VER 0x03300 /* this is assumed to be the last single tasking OS */
void init_os_info(void);
-int tos_getcookie( long tag, long * value );
void fix_path(char * path);
-char * gemdos_realpath(const char * path, char * rpath);
-unsigned short _systype (void);
-#endif \ No newline at end of file
+char * gemdos_realpath(const char * path, char * rpath);
+int tos_getcookie( long tag, long * value );
+#endif
diff --git a/atari/plot/plot.c b/atari/plot/plot.c
index ca3f2b726..9937c0bad 100755
--- a/atari/plot/plot.c
+++ b/atari/plot/plot.c
@@ -1816,10 +1816,18 @@ bool plot_line(int x0, int y0, int x1, int y1,
uint32_t lt;
int sw = pstyle->stroke_width;
- pxy[0] = view.x + x0;
- pxy[1] = view.y + y0;
- pxy[2] = view.x + x1;
- pxy[3] = view.y + y1;
+ if((x0 < 0 && x1 < 0) || (y0 < 0 && y1 < 0)){
+ return(true);
+ }
+
+ pxy[0] = view.x + MAX(0,x0);
+ pxy[1] = view.y + MAX(0,y0);
+ pxy[2] = view.x + MAX(0,x1);
+ pxy[3] = view.y + MAX(0,y1);
+
+
+ //printf("view: %d,%d,%d,%d\n", view.x, view.y, view.w, view.h);
+ //printf("line: %d,%d,%d,%d\n", x0, y0, x1, y1);
plot_vdi_clip(true);
if( sw == 0)
@@ -1834,7 +1842,7 @@ bool plot_line(int x0, int y0, int x1, int y1,
vsl_rgbcolor(atari_plot_vdi_handle, pstyle->stroke_colour);
v_pline(atari_plot_vdi_handle, 2, (short *)&pxy );
plot_vdi_clip(false);
- return ( true );
+ return (true);
}
static bool plot_polygon(const int *p, unsigned int n,
diff --git a/atari/redrawslots.c b/atari/redrawslots.c
index 9fe71610e..d2f74e4fb 100644
--- a/atari/redrawslots.c
+++ b/atari/redrawslots.c
@@ -23,10 +23,16 @@
void redraw_slots_init(struct s_redrw_slots * slots, short size)
{
+ // TODO: allocate slots dynamically!
slots->size = MIN( MAX_REDRW_SLOTS , size);
slots->areas_used = 0;
}
+void redraw_slots_free(struct s_redrw_slots * slots)
+{
+ // TOOD: free areas...
+}
+
static inline bool rect_intersect( struct rect * box1, struct rect * box2 )
{
@@ -44,10 +50,19 @@ static inline bool rect_intersect( struct rect * box1, struct rect * box2 )
return true;
}
+
+
+void redraw_slot_schedule_grect(struct s_redrw_slots * slots, GRECT *area)
+{
+ redraw_slot_schedule(slots, area->g_x, area->g_y,
+ area->g_x + area->g_w, area->g_y + area->g_h);
+}
+
/*
- schedule a slots, coords are relative.
+ schedule redraw coords.
*/
-void redraw_slot_schedule(struct s_redrw_slots * slots, short x0, short y0, short x1, short y1)
+void redraw_slot_schedule(struct s_redrw_slots * slots, short x0, short y0,
+ short x1, short y1)
{
int i;
struct rect area;
@@ -91,6 +106,15 @@ void redraw_slot_schedule(struct s_redrw_slots * slots, short x0, short y0, shor
slots->areas[slots->size-1].x1 = MAX(slots->areas[i].x1, x1);
slots->areas[slots->size-1].y1 = MAX(slots->areas[i].y1, y1);
}
-done:
+done:
return;
}
+
+void redraw_slots_remove_area(struct s_redrw_slots * slots, int i)
+{
+ int x;
+ for(x = i+1; i<slots->areas_used; x++){
+ slots->areas[x-1] = slots->areas[x];
+ }
+ slots->areas_used--;
+}
diff --git a/atari/redrawslots.h b/atari/redrawslots.h
index d1f0fc285..8558b7ee6 100644
--- a/atari/redrawslots.h
+++ b/atari/redrawslots.h
@@ -20,6 +20,10 @@
#ifndef ATARI_REDRAW_SLOTS_H
#define ATARI_REDRAW_SLOTS_H
+#include <mt_gem.h>
+#include "utils/types.h"
+
+
/*
MAX_REDRW_SLOTS
This is the number of redraw requests that the slotlist can store.
@@ -40,7 +44,10 @@ struct s_redrw_slots
};
void redraw_slots_init(struct s_redrw_slots * slots, short size);
-void redraw_slot_schedule(struct s_redrw_slots * slots, short x0, short y0, short x1, short y1);
-
+void redraw_slot_schedule(struct s_redrw_slots * slots, short x0, short y0,
+ short x1, short y1);
+void redraw_slot_schedule_grect(struct s_redrw_slots * slots, GRECT *area);
+void redraw_slots_remove_area(struct s_redrw_slots * slots, int i);
+void redraw_slots_free(struct s_redrw_slots * slots);
#endif
diff --git a/atari/res/netsurf.rsc b/atari/res/netsurf.rsc
index de493636b..803cb2b7d 100755
--- a/atari/res/netsurf.rsc
+++ b/atari/res/netsurf.rsc
Binary files differ
diff --git a/atari/res/netsurf.rsh b/atari/res/netsurf.rsh
index 3c2353ede..824552688 100755
--- a/atari/res/netsurf.rsh
+++ b/atari/res/netsurf.rsh
@@ -41,11 +41,14 @@
#define MAINMENU_M_HELP_CONTENT 61 /* STRING in tree MAINMENU */
#define TOOLBAR 1 /* form/dial */
+#define TOOLBAR_NAVIGATION_AREA 1 /* BOX in tree TOOLBAR */
#define TOOLBAR_BT_BACK 2 /* CICON in tree TOOLBAR */
#define TOOLBAR_BT_HOME 3 /* CICON in tree TOOLBAR */
#define TOOLBAR_BT_FORWARD 4 /* CICON in tree TOOLBAR */
#define TOOLBAR_BT_STOP 5 /* CICON in tree TOOLBAR */
#define TOOLBAR_BT_RELOAD 6 /* CICON in tree TOOLBAR */
+#define TOOLBAR_URL_AREA 7 /* BOX in tree TOOLBAR */
+#define TOOLBAR_THROBBER_AREA 8 /* BOX in tree TOOLBAR */
#define ICONIFY 2 /* form/dial */
#define ICONIFY_GLOBE 1 /* CICON in tree ICONIFY */
@@ -197,3 +200,12 @@
#define CHOICES_CB_BG_IMAGES 107 /* BUTTON in tree CHOICES */
#define CHOICES_ABORT 108 /* BUTTON in tree CHOICES */
#define CHOICES_OK 109 /* BUTTON in tree CHOICES */
+
+#define VSCROLLER 14 /* form/dial */
+#define VSCROLLER_AREA 1 /* BOX in tree VSCROLLER */
+#define VSCROLLER_SLIDER_AREA 2 /* BUTTON in tree VSCROLLER */
+#define VSCROLLER_SLIDER 3 /* BUTTON in tree VSCROLLER */
+#define VSCROLLER_BT_DOWN 7 /* IBOX in tree VSCROLLER */
+#define VSCROLLER_BT_DOWN_PIC 5 /* CICON in tree VSCROLLER */
+#define VSCROLLER_BT_UP 6 /* IBOX in tree VSCROLLER */
+#define VSCROLLER_BT_UP_PIC 4 /* CICON in tree VSCROLLER */
diff --git a/atari/res/netsurf.rsm b/atari/res/netsurf.rsm
index 67af68f5c..587fefa45 100755
--- a/atari/res/netsurf.rsm
+++ b/atari/res/netsurf.rsm
@@ -1,9 +1,9 @@
ResourceMaster v3.65
-#C 14@0@0@0@
+#C 15@0@0@0@
#N 99@32@AZAaza___ _@AZAaza090___ _@@_@
#FoC-Header@rsm2out@C-Header@rsh@@@[C-Header@0@
#R 0@0@1@1@1@1@
-#M 20010100@0@7728@603@
+#M 20010100@0@7728@618@
#T 0@1@MAINMENU@@62@@
#O 4@32@T_FILE@@
#O 5@32@T_EDIT@@
@@ -43,12 +43,15 @@ ResourceMaster v3.65
#O 58@28@M_CHOICES@@
#O 59@28@M_VLOG@@
#O 61@28@M_HELP_CONTENT@@
-#T 1@2@TOOLBAR@@7@@
+#T 1@2@TOOLBAR@@9@@
+#O 1@20@NAVIGATION_AREA@@
#O 2@33@BT_BACK@@
#O 3@33@BT_HOME@@
#O 4@33@BT_FORWARD@@
#O 5@33@BT_STOP@@
#O 6@33@BT_RELOAD@@
+#O 7@20@URL_AREA@@
+#O 8@20@THROBBER_AREA@@
#T 2@2@ICONIFY@@3@@
#O 1@33@GLOBE@@
#T 3@2@FAVICON@@2@@
@@ -187,4 +190,12 @@ ResourceMaster v3.65
#O 107@26@CB_BG_IMAGES@@
#O 108@26@ABORT@@
#O 109@26@OK@@
-#c 31683@
+#T 14@2@VSCROLLER@@8@@
+#O 1@20@AREA@@
+#O 2@26@SLIDER_AREA@@
+#O 3@26@SLIDER@@
+#O 7@25@BT_DOWN@@
+#O 5@33@BT_DOWN_PIC@@
+#O 6@25@BT_UP@@
+#O 4@33@BT_UP_PIC@@
+#c 770@
diff --git a/atari/rootwin.c b/atari/rootwin.c
new file mode 100755
index 000000000..c0ad68863
--- /dev/null
+++ b/atari/rootwin.c
@@ -0,0 +1,868 @@
+/*
+ * 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <windom.h>
+#include <assert.h>
+#include <math.h>
+#include <osbind.h>
+
+#include "utils/log.h"
+#include "desktop/gui.h"
+#include "desktop/history_core.h"
+#include "desktop/netsurf.h"
+#include "desktop/browser.h"
+#include "desktop/browser_private.h"
+#include "desktop/mouse.h"
+#include "desktop/plotters.h"
+#include "desktop/textinput.h"
+#include "content/content.h"
+#include "content/hlcache.h"
+#include "content/urldb.h"
+#include "css/css.h"
+#include "atari/gemtk/gemtk.h"
+#include "atari/gui.h"
+#include "atari/rootwin.h"
+#include "atari/browser.h"
+#include "atari/misc.h"
+#include "atari/plot/plot.h"
+#include "atari/global_evnt.h"
+#include "atari/res/netsurf.rsh"
+#include "atari/browser.h"
+#include "atari/toolbar.h"
+#include "atari/statusbar.h"
+#include "atari/search.h"
+#include "atari/osspec.h"
+#include "atari/encoding.h"
+#include "atari/redrawslots.h"
+#include "atari/toolbar.h"
+#include "atari/gemtk/gemtk.h"
+
+extern struct gui_window *input_window;
+
+struct rootwin_data_s {
+ struct s_gui_win_root *rootwin;
+};
+
+/* -------------------------------------------------------------------------- */
+/* Static module methods: */
+/* -------------------------------------------------------------------------- */
+static void redraw(GUIWIN *win, short msg[8]);
+static void resized(GUIWIN *win);
+static void file_dropped(GUIWIN *win, short msg[8]);
+
+static void __CDECL evnt_window_slider( WINDOW * win, short buff[8], void * data);
+static void __CDECL evnt_window_arrowed( WINDOW *win, short buff[8], void *data );
+
+#define FIND_NS_GUI_WINDOW(w) \
+ find_guiwin_by_aes_handle(guiwin_get_handle(w));
+
+/* -------------------------------------------------------------------------- */
+/* Module public functions: */
+/* -------------------------------------------------------------------------- */
+
+static short handle_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8])
+{
+ struct gui_window * gw;
+
+ struct rootwin_data_s * data = guiwin_get_user_data(win);
+
+ if( (ev_out->emo_events & MU_MESAG) != 0 ) {
+ // handle message
+ printf("root win msg: %d\n", msg[0]);
+ switch (msg[0]) {
+
+ case WM_REDRAW:
+ redraw(win, msg);
+ break;
+
+ case WM_REPOSED:
+ case WM_SIZED:
+ case WM_MOVED:
+ case WM_FULLED:
+ resized(win);
+ break;
+
+ case WM_ICONIFY:
+ data = guiwin_get_user_data(win);
+ if( input_window->root == data->rootwin) {
+ input_window = NULL;
+ }
+ break;
+
+ case WM_TOPPED:
+ case WM_NEWTOP:
+ case WM_UNICONIFY:
+ data = guiwin_get_user_data(win);
+ input_window = data->rootwin->active_gui_window;
+ break;
+
+ case WM_CLOSED:
+ // TODO: this needs to iterate through all gui windows and
+ // check if the rootwin is this window...
+ data = guiwin_get_user_data(win);
+ gw = data->rootwin->active_gui_window;
+ if( gw != NULL ) {
+ browser_window_destroy(gw->browser->bw);
+ }
+ break;
+
+ case AP_DRAGDROP:
+ file_dropped(win, msg);
+ break;
+
+ case WM_TOOLBAR:
+ printf("toolbar click at %d,%d (obj: %d)!\n", ev_out->emo_mouse.p_x,
+ ev_out->emo_mouse.p_y, msg[4]);
+ break;
+
+ default:
+ break;
+ }
+ }
+ if( (ev_out->emo_events & MU_KEYBD) != 0 ) {
+ printf("root win keybd\n");
+ // handle key
+ }
+ if( (ev_out->emo_events & MU_TIMER) != 0 ) {
+ // handle_timer();
+ }
+ if( (ev_out->emo_events & MU_BUTTON) != 0 ) {
+ LOG(("Mouse click at: %d,%d\n", ev_out->emo_mouse.p_x,
+ ev_out->emo_mouse.p_y));
+ printf("Mouse click at: %d,%d\n", ev_out->emo_mouse.p_x,
+ ev_out->emo_mouse.p_y);
+ //handle_mbutton(gw, ev_out);
+ }
+
+ return(0);
+}
+
+
+int window_create(struct gui_window * gw,
+ struct browser_window * bw,
+ unsigned long inflags)
+{
+ int err = 0;
+ bool tb, sb;
+ int flags;
+ short aes_handle;
+
+ tb = (inflags & WIDGET_TOOLBAR);
+ sb = (inflags & WIDGET_STATUSBAR);
+
+ flags = CLOSER | MOVER | NAME | FULLER | SMALLER;
+ if( inflags & WIDGET_SCROLL ) {
+ flags |= (UPARROW | DNARROW | LFARROW | RTARROW | VSLIDE | HSLIDE);
+ }
+ if( inflags & WIDGET_RESIZE ) {
+ flags |= ( SIZER );
+ }
+ if( inflags & WIDGET_STATUSBAR ) {
+ flags |= ( INFO );
+ }
+
+ gw->root = malloc( sizeof(struct s_gui_win_root) );
+ if( gw->root == NULL )
+ return( -1 );
+ memset( gw->root, 0, sizeof(struct s_gui_win_root) );
+ gw->root->title = malloc(atari_sysinfo.aes_max_win_title_len+1);
+ // TODO: use desk size
+
+ aes_handle = wind_create(flags, 40, 40, app.w, app.h);
+ if(aes_handle<0) {
+ free(gw->root->title);
+ free(gw->root);
+ return( -1 );
+ }
+ gw->root->win = guiwin_add(aes_handle,
+ GW_FLAG_PREPROC_WM | GW_FLAG_RECV_PREPROC_WM, handle_event);
+
+ /* create toolbar component: */
+ if( tb ) {
+ gw->root->toolbar = toolbar_create(gw->root);
+ assert(gw->root->toolbar);
+ } else {
+ gw->root->toolbar = NULL;
+ }
+
+ /* create browser component: */
+ gw->browser = browser_create( gw, bw, NULL, CLT_HORIZONTAL, 1, 1 );
+
+ /* create statusbar component: */
+ if(sb) {
+ gw->root->statusbar = sb_create( gw );
+ } else {
+ gw->root->statusbar = NULL;
+ }
+
+ // Setup some window defaults:
+ wind_set_str(aes_handle, WF_ICONTITLE, (char*)"NetSurf");
+ wind_set(aes_handle, WF_OPTS, 1, WO0_FULLREDRAW, 0, 0);
+ wind_set(aes_handle, WF_OPTS, 1, WO0_NOBLITW, 0, 0);
+ wind_set(aes_handle, WF_OPTS, 1, WO0_NOBLITH, 0, 0);
+
+ redraw_slots_init(&gw->root->redraw_slots, 8);
+
+ guiwin_set_toolbar(gw->root->win, get_tree(TOOLBAR), 0, 0);
+ struct rootwin_data_s * data = malloc(sizeof(struct rootwin_data_s));
+ data->rootwin = gw->root;
+ guiwin_set_user_data(gw->root->win, (void*)data);
+
+ if (inflags & WIN_TOP) {
+ window_set_focus(gw->root, BROWSER, gw->browser);
+ }
+
+ return (err);
+}
+
+void window_unref_gui_window(ROOTWIN *rootwin, struct gui_window *gw)
+{
+ struct gui_window *w;
+ input_window = NULL;
+
+ LOG(("window: %p, gui_window: %p", rootwin, gw));
+
+ w = window_list;
+ // find the next active tab:
+ while( w != NULL ) {
+ if(w->root == rootwin && w != gw) {
+ input_window = w;
+ break;
+ }
+ w = w->next;
+ }
+ if(input_window == NULL){
+ // the last gui window for this rootwin was removed:
+ redraw_slots_free(&rootwin->redraw_slots);
+ window_destroy(rootwin);
+ }
+}
+
+int window_destroy(ROOTWIN *rootwin)
+{
+ int err = 0;
+ struct gui_window *w;
+
+ assert(rootwin != NULL);
+
+ LOG(("%p", rootwin));
+
+ if (guiwin_get_user_data(rootwin->win) != NULL) {
+ free(guiwin_get_user_data(rootwin->win));
+ }
+
+ // make sure we do not destroy windows which have gui_windows attached:
+ w = window_list;
+ while( w != NULL ) {
+ if(w->root == rootwin) {
+ assert(rootwin == NULL);
+ }
+ w = w->next;
+ }
+
+ if (rootwin->toolbar)
+ toolbar_destroy(rootwin->toolbar);
+
+ if(rootwin->statusbar)
+ sb_destroy(rootwin->statusbar);
+
+ if(rootwin->title)
+ free(rootwin->title);
+
+ guiwin_remove(rootwin->win);
+ free(rootwin);
+ return(err);
+}
+
+
+
+void window_open(ROOTWIN *rootwin, GRECT pos)
+{
+ GRECT br, g;
+
+ short aes_handle = guiwin_get_handle(rootwin->win);
+ wind_open(aes_handle, pos.g_x, pos.g_y, pos.g_w, pos.g_h );
+ wind_set_str(aes_handle, WF_NAME, (char *)"");
+
+ rootwin->active_gui_window->browser->attached = true;
+ if(rootwin->statusbar != NULL) {
+ sb_attach(rootwin->statusbar, rootwin->active_gui_window);
+ }
+ guiwin_get_grect(rootwin->win, GUIWIN_AREA_TOOLBAR, &g);
+ toolbar_set_dimensions(rootwin->toolbar, &g);
+ /*TBD: get already present content and set size? */
+ input_window = rootwin->active_gui_window;
+ window_set_focus(rootwin, BROWSER, rootwin->active_gui_window->browser);
+}
+
+
+
+/* update back forward buttons (see tb_update_buttons (bug) ) */
+void window_update_back_forward(struct s_gui_win_root *rootwin)
+{
+ struct gui_window * active_gw = rootwin->active_gui_window;
+ toolbar_update_buttons(rootwin->toolbar, active_gw->browser->bw, -1);
+}
+
+void window_set_stauts(struct s_gui_win_root *rootwin, char * text)
+{
+ assert(rootwin != NULL);
+
+ CMP_STATUSBAR sb = rootwin->statusbar;
+
+ if( sb == NULL)
+ return;
+
+ if(text != NULL)
+ sb_set_text(sb, text);
+ else
+ sb_set_text(sb, "");
+}
+
+void window_set_title(struct s_gui_win_root * rootwin, char *title)
+{
+ wind_set_str(guiwin_get_handle(rootwin->win), WF_NAME, title);
+}
+
+/* set focus to an arbitary element */
+void window_set_focus(struct s_gui_win_root *rootwin,
+ enum focus_element_type type, void * element)
+{
+ struct text_area * ta;
+
+ assert(rootwin != NULL);
+
+ if (rootwin->focus.type != type || rootwin->focus.element != element) {
+ LOG(("Set focus: %p (%d)\n", element, type));
+ rootwin->focus.type = type;
+ rootwin->focus.element = element;
+ if( element != NULL ) {
+ switch( type ) {
+
+ case URL_WIDGET:
+ // TODO: make something like: toolbar_text_select_all();
+ ta = toolbar_get_textarea(rootwin->toolbar,
+ URL_INPUT_TEXT_AREA);
+ textarea_keypress(ta, KEY_SELECT_ALL);
+ break;
+
+ default:
+ break;
+
+ }
+ }
+ }
+}
+
+/* check if the url widget has focus */
+bool window_url_widget_has_focus(struct s_gui_win_root *rootwin)
+{
+ assert(rootwin != NULL);
+ if (rootwin->focus.type == URL_WIDGET) {
+ return true;
+ }
+ return false;
+}
+
+/* check if an arbitary window widget / or frame has the focus */
+bool window_widget_has_focus(struct s_gui_win_root *rootwin,
+ enum focus_element_type t, void * element)
+{
+ assert(rootwin != NULL);
+ if( element == NULL ) {
+ return((rootwin->focus.type == t));
+ }
+
+ return((element == rootwin->focus.element && t == rootwin->focus.type));
+}
+
+void window_set_icon(ROOTWIN *rootwin, struct bitmap * bmp )
+{
+ rootwin->icon = bmp;
+ /* redraw window when it is iconyfied: */
+ if (rootwin->icon != NULL) {
+ short info, dummy;
+ if (guiwin_get_state(rootwin->win) & GW_STATUS_ICONIFIED) {
+ window_redraw_favicon(rootwin, NULL);
+ }
+ }
+}
+
+void window_set_active_gui_window(ROOTWIN *rootwin, struct gui_window *gw)
+{
+ if (rootwin->active_gui_window != NULL) {
+ if(rootwin->active_gui_window == gw){
+ return;
+ }
+ }
+ rootwin->active_gui_window = gw;
+ window_set_icon(rootwin, gw->icon);
+ window_set_stauts(rootwin, gw->status);
+ window_set_title(rootwin, gw->title);
+ toolbar_set_url(rootwin->toolbar, gw->url);
+ // TODO: implement window_restore_browser()
+ // window_restore_browser(gw->browser);
+}
+
+struct gui_window * window_get_active_gui_window(ROOTWIN * rootwin)
+{
+ return(rootwin->active_gui_window);
+}
+
+
+/**
+ * Redraw the favicon
+*/
+void window_redraw_favicon(ROOTWIN *rootwin, GRECT *clip)
+{
+ GRECT work;
+
+ assert(rootwin);
+
+ guiwin_clear(rootwin->win);
+ guiwin_get_grect(rootwin->win, GUIWIN_AREA_WORK, &work);
+
+ if (clip == NULL) {
+ clip = &work;
+ } else {
+ if(!rc_intersect(&work, clip)){
+ return;
+ }
+ }
+
+ if (rootwin->icon == NULL) {
+ OBJECT * tree = get_tree(ICONIFY);
+ tree->ob_x = work.g_x;
+ tree->ob_y = work.g_y;
+ tree->ob_width = work.g_w;
+ tree->ob_height = work.g_h;
+ objc_draw(tree, 0, 8, clip->g_x, clip->g_y, clip->g_w, clip->g_h);
+ } else {
+ // TODO: consider the clipping rectangle
+ struct rect work_clip = { 0,0,work.g_w,work.g_h };
+ int xoff=0;
+ if (work.g_w > work.g_h) {
+ xoff = ((work.g_w-work.g_h)/2);
+ work.g_w = work.g_h;
+ }
+ plot_set_dimensions( work.g_x+xoff, work.g_y, work.g_w, work.g_h);
+ plot_clip(&work_clip);
+ atari_plotters.bitmap(0, 0, work.g_w, work.g_h, rootwin->icon, 0xffffff, 0);
+ }
+}
+
+void window_schedule_redraw_grect(ROOTWIN *rootwin, GRECT *area)
+{
+ GRECT work;
+
+ guiwin_get_grect(rootwin->win, GUIWIN_AREA_WORK, &work);
+ rc_intersect(area, &work);
+ redraw_slot_schedule_grect(&rootwin->redraw_slots, &work);
+}
+
+/*
+bool window_requires_redraw(ROOTWIN * rootwin)
+{
+ if (rootwin->redraw_slots.areas_used > 0)
+ return(true);
+
+ return(false);
+}
+*/
+
+void window_process_redraws(ROOTWIN * rootwin)
+{
+ GRECT work, visible_ro, tb_area = {0,0,0,0};
+ short aes_handle, i;
+ bool toolbar_rdrw_required;
+
+ aes_handle = guiwin_get_handle(rootwin->win);
+
+ guiwin_get_grect(rootwin->win, GUIWIN_AREA_TOOLBAR, &tb_area);
+
+ while(plot_lock() == false);
+
+ wind_get_grect(aes_handle, WF_FIRSTXYWH, &visible_ro);
+ while (visible_ro.g_w > 0 && visible_ro.g_h > 0) {
+
+ // TODO: optimze the rectangle list -
+ // remove rectangles which were completly inside the visible area.
+ // that way we don't have to loop over again...
+ for(i=0; i<rootwin->redraw_slots.areas_used; i++){
+
+ GRECT rdrw_area = {
+ rootwin->redraw_slots.areas[i].x0,
+ rootwin->redraw_slots.areas[i].y0,
+ rootwin->redraw_slots.areas[i].x1 +
+ rootwin->redraw_slots.areas[i].x0,
+ rootwin->redraw_slots.areas[i].y1 +
+ rootwin->redraw_slots.areas[i].y0
+ };
+ GRECT visible = visible_ro;
+
+ rc_intersect(&rdrw_area, &visible);
+ if (rc_intersect(&tb_area, &visible)) {
+ toolbar_redraw(rootwin->toolbar, &visible);
+ }
+ }
+ wind_get_grect(aes_handle, WF_NEXTXYWH, &visible_ro);
+ }
+ rootwin->redraw_slots.areas_used = 0;
+
+ plot_unlock();
+}
+
+
+/* -------------------------------------------------------------------------- */
+/* Event Handlers: */
+/* -------------------------------------------------------------------------- */
+
+static void __CDECL evnt_window_arrowed(WINDOW *win, short buff[8], void *data)
+{
+ bool abs = false;
+ GRECT cwork;
+ struct gui_window * gw = data;
+ int value = BROWSER_SCROLL_SVAL;
+
+ assert( gw != NULL );
+
+ browser_get_rect(gw, BR_CONTENT, &cwork );
+
+ switch( buff[4] ) {
+ case WA_UPPAGE:
+ case WA_DNPAGE:
+ value = cwork.g_h;
+ break;
+
+
+ case WA_LFPAGE:
+ case WA_RTPAGE:
+ value = cwork.g_w;
+ break;
+
+ default:
+ break;
+ }
+ browser_scroll( gw, buff[4], value, abs );
+}
+
+//
+//static void __CDECL evnt_window_dd( WINDOW *win, short wbuff[8], void * data )
+//{
+// struct gui_window * gw = (struct gui_window *)data;
+// char file[DD_NAMEMAX];
+// char name[DD_NAMEMAX];
+// char *buff=NULL;
+// int dd_hdl;
+// int dd_msg; /* pipe-handle */
+// long size;
+// char ext[32];
+// short mx,my,bmstat,mkstat;
+// graf_mkstate(&mx, &my, &bmstat, &mkstat);
+//
+// if( gw == NULL )
+// return;
+// if( (win->status & WS_ICONIFY))
+// return;
+//
+// dd_hdl = ddopen( wbuff[7], DD_OK);
+// if( dd_hdl<0)
+// return; /* pipe not open */
+// memset( ext, 0, 32);
+// strcpy( ext, "ARGS");
+// dd_msg = ddsexts( dd_hdl, ext);
+// if( dd_msg<0)
+// goto error;
+// dd_msg = ddrtry( dd_hdl, (char*)&name[0], (char*)&file[0], (char*)&ext[0], &size);
+// if( size+1 >= PATH_MAX )
+// goto error;
+// if( !strncmp( ext, "ARGS", 4) && dd_msg > 0) {
+// ddreply(dd_hdl, DD_OK);
+// buff = (char*)malloc(sizeof(char)*(size+1));
+// if (buff != NULL) {
+// if (Fread(dd_hdl, size, buff ) == size)
+// buff[size] = 0;
+// LOG(("file: %s, ext: %s, size: %d dropped at: %d,%d\n",
+// (char*)buff, (char*)&ext,
+// size, mx, my
+// ));
+// {
+// LGRECT bwrect;
+// struct browser_window * bw = gw->browser->bw;
+// browser_get_rect( gw, BR_CONTENT, &bwrect );
+// mx = mx - bwrect.g_x;
+// my = my - bwrect.g_y;
+// if( (mx < 0 || mx > bwrect.g_w) || (my < 0 || my > bwrect.g_h) )
+// return;
+//
+// utf8_convert_ret ret;
+// char *utf8_fn;
+//
+// ret = utf8_from_local_encoding(buff, 0, &utf8_fn);
+// if (ret != UTF8_CONVERT_OK) {
+// free(buff);
+// /* A bad encoding should never happen */
+// LOG(("utf8_from_local_encoding failed"));
+// assert(ret != UTF8_CONVERT_BADENC);
+// /* no memory */
+// return;
+// }
+// browser_window_drop_file_at_point( gw->browser->bw,
+// mx+gw->browser->scroll.current.x,
+// my+gw->browser->scroll.current.y,
+// utf8_fn );
+// free(utf8_fn);
+// free(buff);
+// }
+// }
+// }
+//error:
+// ddclose( dd_hdl);
+//}
+
+static void __CDECL evnt_window_destroy( WINDOW *win, short buff[8], void *data )
+{
+ LOG(("%s\n", __FUNCTION__ ));
+}
+
+//static void __CDECL evnt_window_close( WINDOW *win, short buff[8], void *data )
+//{
+// struct gui_window * gw = (struct gui_window *) data ;
+// if( gw != NULL ) {
+// browser_window_destroy( gw->browser->bw );
+// }
+//}
+
+
+//static void __CDECL evnt_window_newtop( WINDOW *win, short buff[8], void *data )
+//{
+// input_window = (struct gui_window *) data;
+// window_set_focus( input_window, BROWSER, input_window->browser );
+// LOG(("newtop gui window: %p, WINDOW: %p", input_window, win ));
+// assert( input_window != NULL );
+//}
+
+static void __CDECL evnt_window_slider( WINDOW * win, short buff[8], void * data)
+{
+ int dx = buff[4];
+ int dy = buff[5];
+ struct gui_window * gw = data;
+
+ if (!dx && !dy) return;
+
+ if( input_window == NULL || input_window != gw ) {
+ return;
+ }
+
+ /* update the sliders _before_ we call redraw
+ (which might depend on the slider possitions) */
+ WindSlider( win, (dx?HSLIDER:0) | (dy?VSLIDER:0) );
+
+ if( dy > 0 )
+ browser_scroll( gw, WA_DNPAGE, abs(dy), false );
+ else if ( dy < 0)
+ browser_scroll( gw, WA_UPPAGE, abs(dy), false );
+ if( dx > 0 )
+ browser_scroll( gw, WA_RTPAGE, abs(dx), false );
+ else if( dx < 0 )
+ browser_scroll( gw, WA_LFPAGE, abs(dx), false );
+}
+
+static void redraw(GUIWIN *win, short msg[8])
+{
+ short handle;
+ struct rootwin_data_s *data = guiwin_get_user_data(win);
+ ROOTWIN *rootwin = data->rootwin;
+ GRECT clip = {msg[4], msg[5], msg[6], msg[7]};
+
+ if(guiwin_get_state(win) & GW_STATUS_ICONIFIED) {
+ GRECT clip = {msg[4], msg[5], msg[6], msg[7]};
+ window_redraw_favicon(rootwin, &clip);
+ } else {
+ window_schedule_redraw_grect(rootwin, &clip);
+
+ // TODO: remove this call when browser redraw is implemented:
+ guiwin_clear(win);
+ }
+}
+
+static void resized(GUIWIN *win)
+{
+ GRECT g;
+ short handle;
+ struct gui_window *gw;
+ struct rootwin_data_s *data = guiwin_get_user_data(win);
+ ROOTWIN *rootwin = data->rootwin;
+
+ printf("resized win: %p\n", win);
+
+ handle = guiwin_get_handle(win);
+
+ printf("resized handle: %d\n", handle);
+ gw = data->rootwin->active_gui_window;
+
+ assert(gw != NULL);
+
+ printf("resized gw: %p\n", gw);
+
+ if(gw == NULL)
+ return;
+ //assert( gw != NULL );
+
+ wind_get_grect(handle, WF_CURRXYWH, &g);
+
+ if (rootwin->loc.g_w != g.g_w || rootwin->loc.g_h != g.g_h) {
+ if ( gw->browser->bw->current_content != NULL ) {
+ /* Reformat will happen when redraw is processed: */
+ // TODO: call reformat directly, this was introduced because
+ // of bad AES knowledge, it's ok to call it directly here...
+ rootwin->active_gui_window->browser->reformat_pending = true;
+ }
+ }
+// if (rootwin->loc.g_x != g.g_x || rootwin->loc.g_y != g.g_y) {
+// // moved
+// }
+
+ rootwin->loc = g;
+ guiwin_get_grect(win, GUIWIN_AREA_TOOLBAR, &g);
+ toolbar_set_dimensions(rootwin->toolbar, &g);
+}
+
+static void __CDECL file_dropped(GUIWIN *win, short msg[8])
+{
+ char file[DD_NAMEMAX];
+ char name[DD_NAMEMAX];
+ char *buff=NULL;
+ int dd_hdl;
+ int dd_msg; /* pipe-handle */
+ long size;
+ char ext[32];
+ short mx,my,bmstat,mkstat;
+ struct gui_window *gw;
+
+ graf_mkstate(&mx, &my, &bmstat, &mkstat);
+
+ gw = FIND_NS_GUI_WINDOW(win);
+
+ if( gw == NULL )
+ return;
+
+ if(guiwin_get_state(win) & GW_STATUS_ICONIFIED)
+ return;
+
+ dd_hdl = ddopen( msg[7], DD_OK);
+ if( dd_hdl<0)
+ return; /* pipe not open */
+ memset( ext, 0, 32);
+ strcpy( ext, "ARGS");
+ dd_msg = ddsexts( dd_hdl, ext);
+ if( dd_msg<0)
+ goto error;
+ dd_msg = ddrtry( dd_hdl, (char*)&name[0], (char*)&file[0], (char*)&ext[0], &size);
+ if( size+1 >= PATH_MAX )
+ goto error;
+ if( !strncmp( ext, "ARGS", 4) && dd_msg > 0) {
+ ddreply(dd_hdl, DD_OK);
+ buff = (char*)malloc(sizeof(char)*(size+1));
+ if (buff != NULL) {
+ if (Fread(dd_hdl, size, buff ) == size)
+ buff[size] = 0;
+ LOG(("file: %s, ext: %s, size: %d dropped at: %d,%d\n",
+ (char*)buff, (char*)&ext,
+ size, mx, my
+ ));
+ {
+ GRECT bwrect;
+ struct browser_window * bw = gw->browser->bw;
+ browser_get_rect( gw, BR_CONTENT, &bwrect );
+ mx = mx - bwrect.g_x;
+ my = my - bwrect.g_y;
+ if( (mx < 0 || mx > bwrect.g_w) || (my < 0 || my > bwrect.g_h) )
+ return;
+
+ utf8_convert_ret ret;
+ char *utf8_fn;
+
+ ret = utf8_from_local_encoding(buff, 0, &utf8_fn);
+ if (ret != UTF8_CONVERT_OK) {
+ free(buff);
+ /* A bad encoding should never happen */
+ LOG(("utf8_from_local_encoding failed"));
+ assert(ret != UTF8_CONVERT_BADENC);
+ /* no memory */
+ return;
+ }
+ browser_window_drop_file_at_point( gw->browser->bw,
+ mx+gw->browser->scroll.current.x,
+ my+gw->browser->scroll.current.y,
+ utf8_fn );
+ free(utf8_fn);
+ free(buff);
+ }
+ }
+ }
+error:
+ ddclose( dd_hdl);
+}
+
+///* perform the actual resize */
+//static void __CDECL evnt_window_rt_resize( WINDOW *win, short buff[8], void * data )
+//{
+// short x,y,w,h;
+// struct gui_window * gw;
+//
+// wind_get( win->handle, WF_CURRXYWH, &x, &y, &w, &h );
+// gw = (struct gui_window *)data;
+//
+// assert( gw != NULL );
+//
+// if(gw->root->loc.g_w != w || gw->root->loc.g_h != h ){
+// /* report resize to component interface: */
+// browser_update_rects( gw );
+// tb_adjust_size( gw );
+// if( gw->browser->bw->current_content != NULL ){
+// /* Reformat will happen when next redraw message arrives: */
+// gw->browser->reformat_pending = true;
+// if( sys_XAAES() ){
+// if( gw->root->loc.g_w > w || gw->root->loc.g_h > h ){
+// ApplWrite( _AESapid, WM_REDRAW, gw->root->handle->handle,
+// gw->root->loc.g_x, gw->root->loc.g_y,
+// gw->root->loc.g_w, gw->root->loc.g_h );
+// }
+// }
+// mt_WindGetGrect( &app, gw->root->handle, WF_CURRXYWH,
+// (GRECT*)&gw->root->loc);
+// }
+// else {
+// WindClear( gw->root->handle );
+// }
+// } else {
+// if(gw->root->loc.g_x != x || gw->root->loc.g_y != y ){
+// mt_WindGetGrect( &app, gw->root->handle, WF_CURRXYWH, (GRECT*)&gw->root->loc);
+// browser_update_rects( gw );
+// }
+// }
+//}
diff --git a/atari/browser_win.h b/atari/rootwin.h
index 28001baad..2fa3ec5bb 100755
--- a/atari/browser_win.h
+++ b/atari/rootwin.h
@@ -17,7 +17,9 @@
*/
#ifndef NS_ATARI_BROWSER_WIN_H
-#define NS_ATARI_BROWSER_WIN_H
+#define NS_ATARI_BROWSER_WIN_H
+
+#include <atari/gui.h>
#define GUIWIN_VISIBLE(gw) (gw->root->handle->status & WS_OPEN)
#define GEMWIN_VISIBLE(win) (win->status & WS_OPEN)
@@ -36,31 +38,41 @@
/* -------------------------------------------------------------------------- */
/* Creates an normal Browser window with [toolbar], [statusbar] */
-int window_create( struct gui_window * gw,
+int window_create(struct gui_window * gw,
struct browser_window * bw, unsigned long flags );
/* Destroys WinDom part of gui_window */
-int window_destroy( struct gui_window * gw );
+int window_destroy(struct s_gui_win_root * rootwin);
/* show the window */
-void window_open( struct gui_window * gw, GRECT pos);
+void window_open(struct s_gui_win_root * rootwin, GRECT pos);
-void window_snd_redraw(struct gui_window * gw, short x, short y, short w, short h );
+void window_snd_redraw(struct s_gui_win_root * rootwin, short x, short y,
+ short w, short h );
/* Update Shade / Unshade state of the fwd/back buttons*/
-void window_update_back_forward(struct gui_window * gw);
+void window_update_back_forward(struct s_gui_win_root * rootwin);
/* set root browser component: */
-void window_attach_browser( struct gui_window * gw, CMP_BROWSER b);
+void window_attach_browser(struct s_gui_win_root * rootwin, CMP_BROWSER b);
/* set focus element */
-void window_set_focus( struct gui_window * gw, enum focus_element_type type, void * element );
+void window_set_focus(struct s_gui_win_root * rootwin,
+ enum focus_element_type type, void * element );
/* adjust scroll settings */
-void window_set_scroll_info(struct gui_window *gw, int content_h, int content_w);
+void window_set_scroll_info(struct s_gui_win_root * rootwin, int content_h,
+ int content_w);
/* Shade / Unshade the forward/back bt. of toolbar, depending on history.*/
-bool window_widget_has_focus( struct gui_window * gw, enum focus_element_type t, void * element);
-bool window_url_widget_has_focus( struct gui_window * gw );
-void window_set_url( struct gui_window * gw, const char * text);
-void window_set_stauts( struct gui_window * gw , char * text );
-void window_set_icon(struct gui_window * gw, struct bitmap * bmp );
-void window_redraw_favicon(struct gui_window *gw, GRECT *clip);
+bool window_widget_has_focus(struct s_gui_win_root * rootwin,
+ enum focus_element_type t, void * element);
+bool window_url_widget_has_focus(struct s_gui_win_root * rootwin);
+void window_set_url(struct s_gui_win_root * rootwin, const char * text);
+void window_set_stauts(struct s_gui_win_root * rootwin, char * text);
+void window_set_title(struct s_gui_win_root * rootwin, char * text);
+void window_set_icon(struct s_gui_win_root * rootwin, struct bitmap * bmp );
+void window_set_active_gui_window(ROOTWIN *rootwin, struct gui_window *gw);
+void window_schedule_redraw_grect(ROOTWIN *rootwin, GRECT *area);
+void window_process_redraws(ROOTWIN * rootwin);
+struct gui_window * window_get_active_gui_window(ROOTWIN * rootwin);
+void window_redraw_favicon(struct s_gui_win_root * rootwin, GRECT *clip);
+void window_unref_gui_window(ROOTWIN *rootwin, struct gui_window *gw);
/* -------------------------------------------------------------------------- */
diff --git a/atari/schedule.c b/atari/schedule.c
index 8040c80a8..a91c510b3 100755
--- a/atari/schedule.c
+++ b/atari/schedule.c
@@ -158,8 +158,8 @@ schedule_run(void)
prev_nscb = NULL;
nexttime = cur_nscb->timeout;
- while ( cur_nscb != NULL ) {
- if ( now > cur_nscb->timeout ) {
+ while (cur_nscb != NULL) {
+ if (now > cur_nscb->timeout) {
/* scheduled time */
/* remove callback */
@@ -194,7 +194,7 @@ schedule_run(void)
/* if the time to the event is sooner than the
* currently recorded soonest event record it
*/
- if( nexttime > cur_nscb->timeout ){
+ if (nexttime > cur_nscb->timeout) {
nexttime = cur_nscb->timeout;
}
/* move to next element */
diff --git a/atari/search.c b/atari/search.c
index b5e2fdd61..473712515 100644
--- a/atari/search.c
+++ b/atari/search.c
@@ -34,7 +34,8 @@
#include "atari/gui.h"
#include "atari/misc.h"
#include "atari/browser.h"
-#include "atari/search.h"
+#include "atari/search.h"
+#include "atari/gemtk/gemtk.h"
#include "atari/res/netsurf.rsh"
extern struct gui_window * input_window;
@@ -139,7 +140,7 @@ static void destroy_search_session( SEARCH_FORM_SESSION s )
}
}
-static int apply_form( WINDOW * win, struct s_search_form_state * s )
+static int apply_form(WINDOW * win, struct s_search_form_state * s)
{
OBJECT * obj = ObjcTree(OC_FORM, win );
if( obj == NULL ){
@@ -290,11 +291,12 @@ SEARCH_FORM_SESSION open_browser_search( struct gui_window * gw )
NULL, title,
&pos, true, false);
- ObjcAttachFormFunc( sfs->formwind, SEARCH_BT_SEARCH, evnt_bt_srch_click, NULL);
- ObjcAttachFormFunc( sfs->formwind, SEARCH_CB_CASESENSE, evnt_cb_click, NULL);
- ObjcAttachFormFunc( sfs->formwind, SEARCH_CB_SHOWALL, evnt_cb_click, NULL);
- ObjcAttachFormFunc( sfs->formwind, SEARCH_CB_FWD, evnt_cb_click, NULL);
- EvntAdd( sfs->formwind, WM_CLOSED, evnt_close, EV_TOP);
+ ObjcAttachFormFunc(sfs->formwind, SEARCH_BT_SEARCH, evnt_bt_srch_click,
+ NULL);
+ ObjcAttachFormFunc(sfs->formwind, SEARCH_CB_CASESENSE, evnt_cb_click, NULL);
+ ObjcAttachFormFunc(sfs->formwind, SEARCH_CB_SHOWALL, evnt_cb_click, NULL);
+ ObjcAttachFormFunc(sfs->formwind, SEARCH_CB_FWD, evnt_cb_click, NULL);
+ EvntAdd(sfs->formwind, WM_CLOSED, evnt_close, EV_TOP);
apply_form(sfs->formwind, &sfs->state );
strncpy( ObjcString( tree, SEARCH_TB_SRCH, NULL ), "", SEARCH_MAX_SLEN);
diff --git a/atari/settings.c b/atari/settings.c
index 8143cdcc6..ff39903e9 100644
--- a/atari/settings.c
+++ b/atari/settings.c
@@ -31,11 +31,12 @@
#include "desktop/plot_style.h"
#include "atari/res/netsurf.rsh"
#include "atari/settings.h"
-#include "atari/global_evnt.h"
-#include "atari/misc.h"
+#include "atari/deskmenu.h"
+#include "atari/misc.h"
#include "atari/plot/plot.h"
#include "atari/bitmap.h"
-#include "atari/findfile.h"
+#include "atari/findfile.h"
+#include "atari/gemtk/gemtk.h"
extern char options[PATH_MAX];
@@ -232,7 +233,7 @@ saveform( WINDOW *win, int index, int unused, void *unused2)
close_settings();
ObjcChange( OC_FORM, win, index, NORMAL, TRUE);
form_alert(1, "[1][Some options require an netsurf restart!][OK]");
- main_menu_update();
+ deskmenu_update();
}
static void __CDECL clear_history( WINDOW *win, int index, int unused,
diff --git a/atari/statusbar.c b/atari/statusbar.c
index 08a62c55d..d76cf6365 100755
--- a/atari/statusbar.c
+++ b/atari/statusbar.c
@@ -38,7 +38,7 @@
#include "atari/gui.h"
#include "atari/statusbar.h"
-#include "atari/browser_win.h"
+#include "atari/rootwin.h"
#include "atari/misc.h"
#include "atari/global_evnt.h"
#include "atari/res/netsurf.rsh"
@@ -182,7 +182,7 @@ void sb_destroy( CMP_STATUSBAR s )
}
}
-void sb_set_text( CMP_STATUSBAR sb , char * text )
+void sb_set_text(CMP_STATUSBAR sb , const char * text)
{
LGRECT work;
@@ -221,13 +221,12 @@ void sb_destroy( CMP_STATUSBAR s )
void sb_attach(CMP_STATUSBAR sb, struct gui_window * gw)
{
- sb->aes_win = gw->root->handle->handle;
+ sb->aes_win = guiwin_get_handle(gw->root->win);
sb->attached = true;
}
-void sb_set_text(CMP_STATUSBAR sb, char * text )
+void sb_set_text(CMP_STATUSBAR sb, const char * text )
{
- LGRECT work;
assert( sb != NULL );
strncpy(sb->text, text, STATUSBAR_MAX_SLEN);
sb->text[STATUSBAR_MAX_SLEN]=0;
diff --git a/atari/statusbar.h b/atari/statusbar.h
index fc6749e91..7739c6fed 100755
--- a/atari/statusbar.h
+++ b/atari/statusbar.h
@@ -36,6 +36,6 @@ struct s_statusbar
CMP_STATUSBAR sb_create( struct gui_window * gw );
void sb_destroy( CMP_STATUSBAR s );
-void sb_set_text( CMP_STATUSBAR sb , char * text );
+void sb_set_text( CMP_STATUSBAR sb , const char * text );
void sb_attach(CMP_STATUSBAR sb, struct gui_window * gw);
#endif
diff --git a/atari/toolbar.c b/atari/toolbar.c
index 3594d24c0..75d7abe28 100755..100644
--- a/atari/toolbar.c
+++ b/atari/toolbar.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2010 Ole Loots <ole@monochrom.net>
+ * Copyright 2012 Ole Loots <ole@monochrom.net>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
@@ -24,7 +24,6 @@
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
-#include <windom.h>
#include <assert.h>
#include <math.h>
@@ -43,23 +42,91 @@
#include "atari/clipboard.h"
#include "atari/gui.h"
#include "atari/toolbar.h"
-#include "atari/browser_win.h"
+#include "atari/rootwin.h"
#include "atari/browser.h"
#include "atari/clipboard.h"
#include "atari/misc.h"
#include "atari/global_evnt.h"
#include "atari/plot/plot.h"
#include "cflib.h"
-#include "atari/res/netsurf.rsh"
+#include "atari/res/netsurf.rsh"
+
+#include "desktop/textarea.h"
+#include "desktop/textinput.h"
+#include "content/hlcache.h"
+#include "atari/browser.h"
+
+#define TB_BUTTON_WIDTH 32
+#define THROBBER_WIDTH 32
+#define THROBBER_MIN_INDEX 1
+#define THROBBER_MAX_INDEX 12
+#define THROBBER_INACTIVE_INDEX 13
+
+#define TOOLBAR_URL_MARGIN_LEFT 2
+#define TOOLBAR_URL_MARGIN_RIGHT 2
+#define TOOLBAR_URL_MARGIN_TOP 2
+#define TOOLBAR_URL_MARGIN_BOTTOM 2
+
+enum e_toolbar_button_states {
+ button_on = 0,
+ button_off = 1
+};
+#define TOOLBAR_BUTTON_NUM_STATES 2
+
+struct s_toolbar;
+
+struct s_tb_button
+{
+ short rsc_id;
+ void (*cb_click)(struct s_toolbar *tb);
+ hlcache_handle *icon[TOOLBAR_BUTTON_NUM_STATES];
+ struct s_toolbar *owner;
+ short state;
+ short index;
+ GRECT area;
+};
+struct s_url_widget
+{
+ /* widget is only redrawn when this flag is set */
+ bool redraw;
+ struct text_area *textarea;
+ GRECT rdw_area;
+ GRECT area;
+};
+
+struct s_throbber_widget
+{
+ short index;
+ short max_index;
+ bool running;
+ GRECT area;
+};
+
+struct s_toolbar
+{
+ struct s_gui_win_root *owner;
+ struct s_url_widget url;
+ struct s_throbber_widget throbber;
+ GRECT btdim;
+ GRECT area;
+ /* size & location of buttons: */
+ struct s_tb_button * buttons;
+ bool hidden;
+ int btcnt;
+ int style;
+ bool redraw;
+ bool reflow;
+};
+
extern char * option_homepage_url;
extern void * h_gem_rsrc;
extern struct gui_window * input_window;
extern long atari_plot_flags;
extern int atari_plot_vdi_handle;
-static OBJECT * toolbar_buttons = NULL;
+static OBJECT * aes_toolbar = NULL;
static OBJECT * throbber_form = NULL;
static bool img_toolbar = false;
static char * toolbar_image_folder = (char *)"default";
@@ -68,7 +135,7 @@ static hlcache_handle * toolbar_image;
static hlcache_handle * throbber_image;
static bool toolbar_image_ready = false;
static bool throbber_image_ready = false;
-
+static bool init = false;
static plot_font_style_t font_style_url = {
.family = PLOT_FONT_FAMILY_SANS_SERIF,
@@ -77,46 +144,45 @@ static plot_font_style_t font_style_url = {
.flags = FONTF_NONE,
.background = 0xffffff,
.foreground = 0x0
- };
+ };
+
/* prototypes & order for button widgets: */
+
static struct s_tb_button tb_buttons[] =
{
{
TOOLBAR_BT_BACK,
- tb_back_click,
- 0,
+ toolbar_back_click,
{0,0},
- 0, 0, 0
+ 0, 0, 0, {0,0,0,0}
},
{
TOOLBAR_BT_HOME,
- tb_home_click,
- 0, {0,0}, 0, 0, 0
+ toolbar_home_click,
+ {0,0},
+ 0, 0, 0, {0,0,0,0}
},
{
TOOLBAR_BT_FORWARD,
- tb_forward_click,
- 0,
- {0,0},
- 0, 0, 0
+ toolbar_forward_click,
+ {0,0},
+ 0, 0, 0, {0,0,0,0}
},
{
TOOLBAR_BT_STOP,
- tb_stop_click,
- 0,
- {0,0},
- 0, 0, 0
+ toolbar_stop_click,
+ {0,0},
+ 0, 0, 0, {0,0,0,0}
},
{
TOOLBAR_BT_RELOAD,
- tb_reload_click,
- 0,
- {0,0},
- 0, 0, 0
+ toolbar_reload_click,
+ {0,0},
+ 0, 0, 0, {0,0,0,0}
},
- { 0, 0, 0, {0,0}, 0, 0, -1 }
+ { 0, 0, {0,0}, 0, -1, 0, {0,0,0,0}}
};
struct s_toolbar_style {
@@ -142,10 +208,93 @@ static struct s_toolbar_style toolbar_styles[] =
{18, 34, 64, 64, 2, 0, 0 }
};
-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 );
static nserror toolbar_icon_callback( hlcache_handle *handle,
const hlcache_event *event, void *pw );
+/**
+* Callback for textarea redraw
+*/
+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->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;
+ }
+}
+
+/**
+ * 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 ){
+ if( handle == toolbar_image ){
+ toolbar_image_ready = true;
+ if(input_window != NULL )
+ toolbar_update_buttons(input_window->root->toolbar,
+ input_window->browser->bw, 0);
+ }
+ else if(handle == throbber_image ){
+ throbber_image_ready = true;
+ }
+ }
+
+ return NSERROR_OK;
+}
+
+static struct s_tb_button *button_init(struct s_toolbar *tb, OBJECT * tree, int index,
+ struct s_tb_button * instance)
+{
+ *instance = tb_buttons[index];
+ instance->owner = tb;
+
+ instance->area.g_w = toolbar_styles[tb->style].icon_width + \
+ ( toolbar_styles[tb->style].button_vmargin * 2);
+
+ return(instance);
+}
+
+
+static void toolbar_reflow(struct s_toolbar *tb)
+{
+ LOG((""));
+/*
+ int i=0, x=0;
+
+ x = 2;
+ while (tb->buttons[i].rsc_id > 0) {
+ tb->buttons[i].area.g_x = x;
+ x += tb->buttons[i].area.g_w;
+ x += 2;
+ i++;
+ }
+ tb->url.area.g_x = x;
+*/
+}
+
void toolbar_init( void )
{
@@ -155,7 +304,7 @@ void toolbar_init( void )
toolbar_image_folder = nsoption_charp(atari_image_toolbar_folder);
toolbar_bg_color = (nsoption_colour(atari_toolbar_bg));
- img_toolbar = (nsoption_int( atari_image_toolbar ) > 0 ) ? true : false;
+ img_toolbar = (nsoption_int(atari_image_toolbar) > 0 ) ? true : false;
if( img_toolbar ){
char imgfile[PATH_MAX];
@@ -175,13 +324,8 @@ void toolbar_init( void )
toolbar_icon_callback, NULL );
} else {
- RsrcGaddr( h_gem_rsrc, R_TREE, TOOLBAR, &toolbar_buttons );
- toolbar_buttons->ob_x = 0;
- toolbar_buttons->ob_y = 0;
-
- RsrcGaddr( h_gem_rsrc, R_TREE, THROBBER , &throbber_form );
- throbber_form->ob_x = 0;
- throbber_form->ob_y = 0;
+ aes_toolbar = get_tree(TOOLBAR);
+ throbber_form = get_tree(THROBBER);
}
n = (sizeof( toolbar_styles ) / sizeof( struct s_toolbar_style ));
for (i=0; i<n; i++) {
@@ -189,579 +333,42 @@ void toolbar_init( void )
}
}
-void toolbar_exit( void )
-{
- if( toolbar_image )
- hlcache_handle_release( toolbar_image );
- if( throbber_image )
- hlcache_handle_release( throbber_image );
-}
-/**
- * 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)
+void toolbar_exit(void)
{
- if( event->type == CONTENT_MSG_READY ){
- if( handle == toolbar_image ){
- toolbar_image_ready = true;
- if( input_window != NULL )
- tb_update_buttons( input_window, 0 );
- }
- else if( handle == throbber_image ){
- throbber_image_ready = true;
- }
- }
-
- return NSERROR_OK;
+ if (toolbar_image)
+ hlcache_handle_release(toolbar_image);
+ if (throbber_image)
+ hlcache_handle_release(throbber_image);
}
-
-
-static void __CDECL button_redraw( COMPONENT *c, long buff[8], void * data )
-{
-
- OBJECT *tree=NULL;
- 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=0, bmpy=0, bmpw=0, bmph = 0, drawstate=0;
- struct bitmap * icon = NULL;
- struct rect icon_clip;
- GRECT icon_dim = {0,0,0,0};
- plot_style_t plot_style_background = {
- .fill_type = PLOT_OP_TYPE_SOLID,
- .fill_colour = toolbar_bg_color,
- .stroke_type = PLOT_OP_TYPE_NONE
- };
-
-
- 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;
- }
-
- drawstate = bt->state;
- if( img_toolbar ){
- if( toolbar_image_ready == false ){
- return;
- }
-
- icon = content_get_bitmap( toolbar_image );
- if( icon == NULL ){
- return;
- }
-
- bmpw = bitmap_get_width(icon);
- bmph = bitmap_get_height(icon);
- bmpx = 0;
- bmpy = 0;
- icon_clip.x0 = bmpx+(toolbar_styles[tb->style].icon_width*bt->index);
- icon_clip.y0 = bmpy+(toolbar_styles[tb->style].icon_height*drawstate);
- icon_clip.x1 = icon_clip.x0+toolbar_styles[tb->style].icon_width;
- icon_clip.y1 = icon_clip.y0+toolbar_styles[tb->style].icon_height;
- icon_dim.g_x = work.g_x-(toolbar_styles[tb->style].icon_width * bt->index)+toolbar_styles[tb->style].button_vmargin;
- icon_dim.g_y = work.g_y-(toolbar_styles[tb->style].icon_height * drawstate)+toolbar_styles[tb->style].button_hmargin;
- icon_dim.g_w = toolbar_styles[tb->style].icon_width*(bt->index+1);
- icon_dim.g_h = toolbar_styles[tb->style].icon_height*(drawstate+1);
- } else {
- /* Place the CICON into workarea: */
- tree = &toolbar_buttons[bt->rsc_id];
- if( tree == NULL )
- return;
- tree->ob_x = work.g_x;
- tree->ob_y = work.g_y + (work.g_h - tree->ob_height) / 2;
- if( drawstate == button_off ) {
- tree->ob_state |= OS_DISABLED;
- } else {
- tree->ob_state &= ~OS_DISABLED;
- }
- }
-
- /* Setup draw mode: */
- vsf_interior(atari_plot_vdi_handle , 1 );
- vswr_mode(atari_plot_vdi_handle, 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;
- crect.g_y = clip.g_y;
- crect.g_w = clip.g_w;
- crect.g_h = clip.g_h;
- wind_get(gw->root->handle->handle, WF_FIRSTXYWH,
- &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 )) {
-
- struct rect bgclip = {0,0,todo.g_w, todo.g_h};
- 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(atari_plot_vdi_handle, 1, (short*)&pxy );
- plot_set_dimensions(todo.g_x, todo.g_y, todo.g_w, todo.g_h);
- plot_rectangle(0, 0, crect.g_w, crect.g_h, &plot_style_background);
-
- if( img_toolbar == true ){
- plot_set_dimensions(icon_dim.g_x, icon_dim.g_y,
- icon_dim.g_w, icon_dim.g_h);
- plot_clip( &icon_clip );
- atari_plotters.bitmap( bmpx, bmpy, bmpw, bmph, icon,
- toolbar_styles[tb->style].icon_bgcolor,
- BITMAPF_BUFFER_NATIVE );
- } else {
- objc_draw( tree, 0, 0, todo.g_x, todo.g_y, todo.g_w, todo.g_h );
- }
- vs_clip(atari_plot_vdi_handle, 0, (short*)&clip );
- }
- wind_get(gw->root->handle->handle, WF_NEXTXYWH,
- &todo.g_x, &todo.g_y, &todo.g_w, &todo.g_h );
- }
-}
-
-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 = bt->gw;
- assert( gw );
- gw->root->toolbar->buttons[bt->index].cb_click( gw );
-}
-
-
-static struct s_tb_button * find_button( struct gui_window * gw, int rsc_id )
+struct s_toolbar *toolbar_create(struct s_gui_win_root *owner)
{
- int i = 0;
- while( i < gw->root->toolbar->btcnt ) {
- if( gw->root->toolbar->buttons[i].rsc_id == rsc_id ) {
- return( &gw->root->toolbar->buttons[i] );
- }
- i++;
- }
-}
-
-
-static COMPONENT *button_init( CMP_TOOLBAR t, OBJECT * tree, int index,
- struct s_tb_button * instance )
-{
- int comp_width;
-
- *instance = tb_buttons[index];
- instance->gw = t->owner;
+ int i;
- comp_width = toolbar_styles[t->style].icon_width + \
- ( toolbar_styles[t->style].button_vmargin * 2 );
-
- instance->comp = mt_CompCreate( &app, CLT_VERTICAL, comp_width, 0 );
- assert( instance->comp );
-
- instance->comp->bounds.max_width = comp_width;
- mt_CompEvntDataAttach( &app, instance->comp, WM_REDRAW, button_redraw,
- instance );
- mt_CompEvntDataAttach( &app, instance->comp, WM_XBUTTON, button_click,
- instance );
- return instance->comp;
-}
+ LOG((""));
-
-static
-void __CDECL evnt_throbber_redraw( COMPONENT *c, long buff[8])
-{
- LGRECT work, clip;
- int idx;
- short pxy[4];
- struct s_toolbar * tb;
- struct gui_window * gw = (struct gui_window *)mt_CompDataSearch(&app,
- c,
- CDT_OWNER );
- plot_style_t plot_style_background = {
- .fill_type = PLOT_OP_TYPE_SOLID,
- .fill_colour = toolbar_bg_color,
- .stroke_type = PLOT_OP_TYPE_NONE
- };
-
- tb = gw->root->toolbar;
- mt_CompGetLGrect(&app, c, WF_WORKXYWH, &work);
- clip = work;
- if ( !rc_lintersect( (LGRECT*)&buff[4], &clip ) ) return;
-
- vsf_interior(atari_plot_vdi_handle , 1 );
- pxy[0] = (short)buff[4];
- pxy[1] = (short)buff[5];
- pxy[2] = (short)buff[4] + buff[6]-1;
- pxy[3] = (short)buff[5] + buff[7]-2;
- vs_clip(atari_plot_vdi_handle, 1, (short*)&pxy );
-
- if (app.nplanes > 2 ) {
- plot_set_dimensions(work.g_x, work.g_y, work.g_w, work.g_h);
- plot_rectangle( 0, 0, work.g_w, work.g_h, &plot_style_background);
- }
- else {
- vsf_color(atari_plot_vdi_handle, WHITE );
- v_bar(atari_plot_vdi_handle, (short*)&pxy );
- }
+ struct s_toolbar *t = calloc(sizeof(struct s_toolbar), 1);
- if( img_toolbar ){
-
- int bmpx=0, bmpy=0, bmpw=0, bmph = 0, drawstate=0;
- struct rect icon_clip;
- struct bitmap * icon = NULL;
-
- if( throbber_image_ready == false ){
- return;
- }
- icon = content_get_bitmap( throbber_image );
- if( icon == NULL ){
- return;
- }
-
- if( tb->throbber.running == false ) {
- idx = 0;
- }
- else {
- idx = tb->throbber.index;
- if( idx > tb->throbber.max_index ) {
- idx = tb->throbber.index = 1;
- }
- }
- bmpw = bitmap_get_width(icon);
- bmph = bitmap_get_height(icon);
- bmpx = 0;
- bmpy = 0;
-
- /*
- for some reason, adding
- toolbar_styles[tb->style].button_vmargin to the x pos of
- the plotter shifts the icon a bit to much.
- Maybe that's becasue the icon is inside an padded form.
- */
- plot_set_dimensions(
- work.g_x-(toolbar_styles[tb->style].icon_width * idx),
- work.g_y+toolbar_styles[tb->style].button_hmargin,
- toolbar_styles[tb->style].icon_width*(idx+1),
- toolbar_styles[tb->style].icon_height
- );
- icon_clip.x0 = bmpx+(toolbar_styles[tb->style].icon_width*idx);
- icon_clip.y0 = bmpy;
- icon_clip.x1 = icon_clip.x0+toolbar_styles[tb->style].icon_width;
- icon_clip.y1 = icon_clip.y0+toolbar_styles[tb->style].icon_height;
- plot_clip( &icon_clip );
- atari_plotters.bitmap( bmpx, bmpy, bmpw, bmph, icon,
- toolbar_styles[tb->style].icon_bgcolor,
- BITMAPF_BUFFER_NATIVE );
- }
- else {
- if( throbber_form != NULL ) {
- if( gw->root->toolbar->throbber.running == false ) {
- idx = THROBBER_INACTIVE_INDEX;
- } else {
- idx = gw->root->toolbar->throbber.index;
- if( idx > THROBBER_MAX_INDEX || idx < THROBBER_MIN_INDEX ) {
- idx = THROBBER_MIN_INDEX;
- }
- }
- throbber_form[idx].ob_x = work.g_x+1;
- throbber_form[idx].ob_y = work.g_y+4;
- mt_objc_draw( throbber_form, idx, 8, clip.g_x, clip.g_y, clip.g_w, clip.g_h, app.aes_global );
- }
- }
-
-}
-
-static
-void __CDECL evnt_url_redraw( COMPONENT *c, long buff[8], void * data)
-{
- LGRECT work, clip;
- struct gui_window * gw;
- short pxy[10];
- plot_style_t plot_style_background = {
- .fill_type = PLOT_OP_TYPE_SOLID,
- .fill_colour = toolbar_bg_color,
- .stroke_type = PLOT_OP_TYPE_NONE
- };
-
- CMP_TOOLBAR tb = (CMP_TOOLBAR)data;
- 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;
-
- plot_set_dimensions(work.g_x, work.g_y, work.g_w, work.g_h);
-
- //left margin:
- plot_rectangle(0, 0, TOOLBAR_URL_MARGIN_LEFT, work.g_h,
- &plot_style_background);
- // right margin:
- plot_rectangle(work.g_w-TOOLBAR_URL_MARGIN_RIGHT, 0, work.g_w, work.g_h,
- &plot_style_background);
-
- // top margin:
- plot_rectangle(0, 0, work.g_w, TOOLBAR_URL_MARGIN_TOP,
- &plot_style_background);
-
- // bottom margin:
- plot_rectangle(0, work.g_h-TOOLBAR_URL_MARGIN_BOTTOM, work.g_w, work.g_h,
- &plot_style_background);
-
- // 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
-void __CDECL evnt_url_click( COMPONENT *c, long buff[8] )
-{
- LGRECT work;
- short pxy[4];
- short mx, my, mb, kstat;
- int old;
- graf_mkstate( &mx, &my, &mb, &kstat );
- struct gui_window * gw = (struct gui_window *)mt_CompDataSearch(&app, c, CDT_OWNER);
- assert( gw != NULL );
- CMP_TOOLBAR tb = gw->root->toolbar;
- mt_CompGetLGrect(&app, c, WF_WORKXYWH, &work);
- 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) ) {
- window_set_focus( gw, URL_WIDGET, (void*)&tb->url );
- } 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;
- if( tb->url.redraw ){
- tb_url_redraw( gw );
- }
- }
- 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 {
- /* TODO: recognize click + shift key */
- int mstate = BROWSER_MOUSE_PRESS_1;
- if( (kstat & (K_LSHIFT|K_RSHIFT)) != 0 )
- mstate = BROWSER_MOUSE_MOD_1;
- if( evnt.nb_click == 2 ){
- textarea_mouse_action( tb->url.textarea,
- BROWSER_MOUSE_DOUBLE_CLICK | BROWSER_MOUSE_CLICK_1,
- mx, my );
- } else {
- 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;
+ assert(t);
- 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;
- short pxy[4];
- const plot_style_t plot_style_background = {
- .fill_type = PLOT_OP_TYPE_SOLID,
- .fill_colour = toolbar_bg_color,
- .stroke_type = PLOT_OP_TYPE_NONE
- };
-
- mt_CompGetLGrect(&app, c, WF_WORKXYWH, &work);
- clip = work;
- if( !rc_lintersect( (LGRECT*)&buff[4], &clip ) ) return;
- if( work.g_y + work.g_h != clip.g_y + clip.g_h ) return;
-
- vswr_mode(atari_plot_vdi_handle, MD_REPLACE );
- vsl_color(atari_plot_vdi_handle, BLACK );
- vsl_type(atari_plot_vdi_handle, 1 );
- vsl_width(atari_plot_vdi_handle, 1 );
- pxy[0] = clip.g_x;
- pxy[1] = pxy[3] = work.g_y + work.g_h-1 ;
- pxy[2] = clip.g_x + clip.g_w;
- v_pline(atari_plot_vdi_handle, 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->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 && ((atari_plot_flags & PLOT_FLAG_OFFSCREEN) == 0) ) {
-
- const struct redraw_context ctx = {
- .interactive = true,
- .background_images = 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;
-
- plot_set_dimensions( work.g_x, work.g_y, work.g_w, work.g_h );
- if(plot_lock() == false)
- return;
-
- 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(atari_plot_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 {
- plot_unlock();
- return;
- }
- plot_unlock();
- vs_clip(atari_plot_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;
-
-
- CMP_TOOLBAR t = malloc( sizeof(struct s_toolbar) );
- if( t == NULL )
- return( NULL );
-
- t->owner = gw;
+ t->owner = owner;
t->style = 1;
/* create the root component: */
- 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,
- gw, EV_BOT);
+ t->area.g_h = toolbar_styles[t->style].height;
/* count buttons and add them as components: */
i = 0;
- while( tb_buttons[i].rsc_id > 0 ) {
+ while(tb_buttons[i].rsc_id > 0) {
i++;
}
t->btcnt = i;
- 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++ ) {
- button_init( t, toolbar_buttons, i, &t->buttons[i] );
- mt_CompAttach( &app, t->comp, t->buttons[i].comp );
+ 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++ ) {
+ button_init(t, aes_toolbar, i, &t->buttons[i]);
}
/* create the url widget: */
@@ -770,30 +377,16 @@ CMP_TOOLBAR tb_create( struct gui_window * gw )
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 );
+ 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_styles[t->style].height, 1);
- mt_CompEvntDataAttach( &app, t->url.comp, WM_REDRAW, evnt_url_redraw, t);
- mt_CompEvntAttach( &app, t->url.comp, WM_XBUTTON, evnt_url_click );
- mt_CompDataAttach( &app, t->url.comp, CDT_OWNER, gw );
- mt_CompAttach( &app, t->comp, t->url.comp );
/* create the throbber widget: */
- 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 = t->throbber.comp->bounds.max_width = \
- toolbar_styles[t->style].icon_width + \
+ t->throbber.area.g_h = toolbar_styles[t->style].height;
+ t->throbber.area.g_w = toolbar_styles[t->style].icon_width + \
(2*toolbar_styles[t->style].button_vmargin );
- t->throbber.comp->bounds.max_height = toolbar_styles[t->style].height;
if( img_toolbar == true ){
t->throbber.index = 0;
t->throbber.max_index = 8;
@@ -801,251 +394,163 @@ CMP_TOOLBAR tb_create( struct gui_window * gw )
t->throbber.index = THROBBER_MIN_INDEX;
t->throbber.max_index = THROBBER_MAX_INDEX;
}
- t->throbber.running = false;
- 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 );
+ t->throbber.running = false;
+
+ LOG(("created toolbar: %p, root: %p, textarea: %p, throbber: %p", t,
+ owner, t->url.textarea, t->throbber));
return( t );
-}
-
-
-void tb_destroy( CMP_TOOLBAR tb )
+}
+
+
+void toolbar_destroy(struct s_toolbar *tb)
{
- free( tb->buttons );
+ free(tb->buttons);
textarea_destroy( tb->url.textarea );
- mt_CompDelete( &app, tb->comp);
- free( tb );
-}
-
-
-struct gui_window * tb_gui_window( CMP_TOOLBAR tb )
-{
- struct gui_window * gw;
- gw = window_list;
- while( gw != NULL ) {
- if( gw->root->toolbar == tb ) {
- LOG(("found tb gw: %p (tb: %p) for tb: %p", gw, gw->root->toolbar, tb ));
- return( gw );
- }
- else
- gw = gw->next;
- }
- return( NULL );
-}
-
-
-void tb_update_buttons( struct gui_window * gw, short button )
+ free(tb);
+}
+
+static void toolbar_objc_reflow(struct s_toolbar *tb)
{
-
-#define FIRST_BUTTON TOOLBAR_BT_BACK
-
- struct s_tb_button * bt;
- bool enable = false;
- 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( enable ){
- bt->state = button_on;
- } else {
- bt->state = button_off;
- }
- mt_CompEvntRedraw( &app, bt->comp );
- }
- if( button == TOOLBAR_BT_HOME || button <= 0 ){
- bt = &gw->root->toolbar->buttons[TOOLBAR_BT_HOME-FIRST_BUTTON];
- mt_CompEvntRedraw( &app, bt->comp );
- }
+ // position toolbar areas:
+ aes_toolbar->ob_x = tb->area.g_x;
+ aes_toolbar->ob_y = tb->area.g_y;
+ aes_toolbar->ob_width = tb->area.g_w;
+ aes_toolbar->ob_height = tb->area.g_h;
- 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( enable ){
- bt->state = button_on;
- } else {
- bt->state = button_off;
- }
- mt_CompEvntRedraw( &app, bt->comp );
- }
+ aes_toolbar[TOOLBAR_THROBBER_AREA].ob_x = tb->area.g_w
+ - aes_toolbar[TOOLBAR_THROBBER_AREA].ob_width;
- 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( enable ){
- bt->state = button_on;
- } else {
- bt->state = button_off;
- }
- mt_CompEvntRedraw( &app, bt->comp );
- }
+ aes_toolbar[TOOLBAR_URL_AREA].ob_width = tb->area.g_w
+ - (aes_toolbar[TOOLBAR_NAVIGATION_AREA].ob_width
+ + aes_toolbar[TOOLBAR_THROBBER_AREA].ob_width);
- 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( enable ){
- bt->state = button_on;
- } else {
- bt->state = button_off;
- }
- mt_CompEvntRedraw( &app, bt->comp );
- }
+ // position throbber image:
+ throbber_form[tb->throbber.index].ob_x = tb->area.g_x +
+ aes_toolbar[TOOLBAR_THROBBER_AREA].ob_x;
-#undef FIRST_BUTON
-}
-
-
-
-void tb_url_set( struct gui_window * gw, char * text )
-{
- LGRECT work;
- int len = strlen(text);
- char * newtext;
- int newsize;
-
- if( gw->root->toolbar == NULL )
- return;
-
- if( gw->browser->attached == false )
- return;
-
- 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 );
- tb_update_buttons( gw, TOOLBAR_BT_STOP );
- return;
-}
-
-
-/* -------------------------------------------------------------------------- */
-/* Public Module event handlers: */
-/* -------------------------------------------------------------------------- */
-
-bool tb_url_input( struct gui_window * gw, short nkc )
-{
- CMP_TOOLBAR tb = gw->root->toolbar;
- assert(tb!=NULL);
- LGRECT work;
- bool ret = false;
-
- 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);
- 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 ) {
- tb_url_set( gw, 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 );
-}
+ throbber_form[tb->throbber.index].ob_x = tb->area.g_x
+ + aes_toolbar[TOOLBAR_THROBBER_AREA].ob_x +
+ ((aes_toolbar[TOOLBAR_THROBBER_AREA].ob_width
+ - throbber_form[tb->throbber.index].ob_width) >> 1);
+
+ throbber_form[tb->throbber.index].ob_y = tb->area.g_y +
+ ((aes_toolbar[TOOLBAR_THROBBER_AREA].ob_height
+ - throbber_form[tb->throbber.index].ob_height) >> 1);
+
+ tb->reflow = false;
+}
+
+void toolbar_redraw(struct s_toolbar *tb, GRECT *clip)
+{
+ if(tb->reflow == true)
+ toolbar_objc_reflow(tb);
+
+ objc_draw_grect(aes_toolbar,0,8,clip);
+
+ objc_draw_grect(&throbber_form[tb->throbber.index], 0, 1, clip);
+}
+
+
+void toolbar_update_buttons(struct s_toolbar *tb, struct browser_window *bw,
+ short button)
+{
+ LOG((""));
+}
+
+
+void toolbar_set_dimensions(struct s_toolbar *tb, GRECT *area)
+{
+ tb->area = *area;
+ tb->reflow = true;
+}
+
+
+void toolbar_set_url(struct s_toolbar *tb, const char * text)
+{
+ LOG((""));
+}
+
+
+bool toolbar_text_input(struct s_toolbar *tb, char *text)
+{
+ bool handled = true;
+
+ LOG((""));
+
+ return(handled);
+}
+
+bool toolbar_key_input(struct s_toolbar *tb, short nkc)
+{
+ bool handled = true;
+
+ LOG((""));
+
+ return(handled);
+}
+
+
+void toolbar_mouse_input(struct s_toolbar *tb, short mx, short my)
+{
+ LOG((""));
+}
+
+
+
+void toolbar_get_grect(struct s_toolbar *tb, short which, short opt, GRECT *dst)
+{
+
+}
+
+
+struct text_area *toolbar_get_textarea(struct s_toolbar *tb,
+ enum toolbar_textarea which)
+{
+ return(tb->url.textarea);
+}
+
+
+/* public event handler */
+void toolbar_back_click(struct s_toolbar *tb)
+{
+ assert(input_window != NULL);
-void tb_back_click( struct gui_window * gw )
-{
- struct browser_window *bw = gw->browser->bw;
+ struct browser_window *bw = input_window->browser->bw;
if( history_back_available(bw->history) )
history_back(bw, bw->history);
}
-void tb_reload_click( struct gui_window * gw )
+void toolbar_reload_click(struct s_toolbar *tb)
{
- browser_window_reload( gw->browser->bw, true );
+ assert(input_window != NULL);
+ browser_window_reload(input_window->browser->bw, true);
}
-void tb_forward_click( struct gui_window * gw )
-{
- struct browser_window *bw = gw->browser->bw;
+void toolbar_forward_click(struct s_toolbar *tb)
+{
+ assert(input_window != NULL);
+ struct browser_window *bw = input_window->browser->bw;
if (history_forward_available(bw->history))
history_forward(bw, bw->history);
}
-void tb_home_click( struct gui_window * gw )
+void toolbar_home_click(struct s_toolbar *tb)
{
- browser_window_go(gw->browser->bw, option_homepage_url, 0, true);
+ assert(input_window != NULL);
+ struct browser_window * bw;
+ struct gui_window * gw;
+
+ gw = window_get_active_gui_window(tb->owner);
+ bw = gw->browser->bw;
+ browser_window_go(bw, option_homepage_url, 0, true);
}
-void tb_stop_click( struct gui_window * gw )
+void toolbar_stop_click(struct s_toolbar *tb)
{
- browser_window_stop(gw->browser->bw);
+ assert(input_window != NULL);
+ browser_window_stop(input_window->browser->bw);
}
-
-void tb_hide( struct gui_window * gw, short mode )
-{
- CMP_TOOLBAR tb = gw->root->toolbar;
- assert( tb != NULL );
- if( mode == 1 ){
- tb->hidden = true;
- tb->comp->rect.g_h = 0;
- tb->comp->bounds.max_height = 0;
-
- } else {
- tb->hidden = false;
- 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 );
- snd_rdw( gw->root->handle );
-}
-
diff --git a/atari/toolbar.h b/atari/toolbar.h
index 7f8640843..17cb16d08 100755..100644
--- a/atari/toolbar.h
+++ b/atari/toolbar.h
@@ -1,118 +1,39 @@
-/*
- * 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
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef NS_ATARI_TOOLBAR_H
+#ifndef NS_ATARI_TOOLBAR_H
#define NS_ATARI_TOOLBAR_H
+#include <stdbool.h>
+#include <stdint.h>
+
#include "desktop/textarea.h"
-#include "desktop/textinput.h"
-#include "content/hlcache.h"
-#include "atari/browser.h"
-
-#define TB_BUTTON_WIDTH 32
-#define THROBBER_WIDTH 32
-#define THROBBER_MIN_INDEX 1
-#define THROBBER_MAX_INDEX 12
-#define THROBBER_INACTIVE_INDEX 13
+#include "desktop/browser.h"
-#define TOOLBAR_URL_MARGIN_LEFT 2
-#define TOOLBAR_URL_MARGIN_RIGHT 2
-#define TOOLBAR_URL_MARGIN_TOP 2
-#define TOOLBAR_URL_MARGIN_BOTTOM 2
-
-enum e_toolbar_button_states {
- button_on = 0,
- button_off = 1
-};
-#define TOOLBAR_BUTTON_NUM_STATES 2
-
-struct s_tb_button
-{
- short rsc_id;
- void (*cb_click)(struct gui_window * gw);
- COMPONENT * comp;
- hlcache_handle * icon[TOOLBAR_BUTTON_NUM_STATES];
- struct gui_window * gw;
- short state;
- short index;
-};
-
-
-struct s_url_widget
-{
- bool redraw; /* widget is only redrawn when this flag is set */
- struct text_area *textarea;
- COMPONENT * comp;
- GRECT rdw_area;
-};
-
-struct s_throbber_widget
-{
- COMPONENT * comp;
- short index;
- short max_index;
- bool running;
-};
+struct s_toolbar;
-struct s_toolbar
-{
- COMPONENT * comp;
- struct gui_window * owner;
- struct s_url_widget url;
- struct s_throbber_widget throbber;
- GRECT btdim;
- /* size & location of buttons: */
- struct s_tb_button * buttons;
- bool hidden;
- int btcnt;
- int style;
- bool redraw;
-};
+enum toolbar_textarea {
+ URL_INPUT_TEXT_AREA = 1
+};
-/* interface to the toolbar */
-
-/* Must be called before any other toolbar function is called: */
-void toolbar_init( void );
-/*Must be called when netsurf exits to free toolbar resources: */
+void toolbar_init(void);
+struct s_toolbar *toolbar_create(struct s_gui_win_root *owner);
+void toolbar_destroy(struct s_toolbar * tb);
void toolbar_exit( void );
-CMP_TOOLBAR tb_create( struct gui_window * gw );
-void tb_destroy( CMP_TOOLBAR tb );
-/* recalculate size/position of nested controls within the toolbar: */
-void tb_adjust_size( struct gui_window * gw );
-/* report click to toolbar, relative coords : */
-void tb_click( struct gui_window * gw, short mx, short my, short mb, short kstat );
-void tb_back_click( struct gui_window * gw );
-void tb_reload_click( struct gui_window * gw );
-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, 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:*/
-bool tb_url_input( struct gui_window * gw, short keycode );
-/* set the url: */
-void tb_url_set( struct gui_window * gw, char * text );
-/* perform redraw of invalidated url textinput areas: */
-void tb_url_redraw( struct gui_window * gw );
-struct gui_window * tb_gui_window( CMP_TOOLBAR tb );
-/* hide toolbar, mode = 1: hide, mode = 0: show */
-void tb_hide( struct gui_window * gw, short mode );
-
-#endif
+void toolbar_set_dimensions(struct s_toolbar *tb, GRECT *area);
+void toolbar_set_url(struct s_toolbar *tb, const char *text);
+bool toolbar_text_input(struct s_toolbar *tb, char *text);
+bool toolbar_key_input(struct s_toolbar *tb, short nkc);
+void toolbar_mouse_input(struct s_toolbar *tb, short mx, short my);
+void toolbar_update_buttons(struct s_toolbar *tb, struct browser_window *bw,
+ short idx);
+void toolbar_get_grect(struct s_toolbar *tb, short which, short opt, GRECT *g);
+struct text_area *toolbar_get_textarea(struct s_toolbar *tb,
+ enum toolbar_textarea which);
+void toolbar_redraw(struct s_toolbar *tb, GRECT *clip);
+/* public events handlers: */
+void toolbar_back_click(struct s_toolbar *tb);
+void toolbar_reload_click(struct s_toolbar *tb);
+void toolbar_forward_click(struct s_toolbar *tb);
+void toolbar_home_click(struct s_toolbar *tb);
+void toolbar_stop_click(struct s_toolbar *tb);
+
+
+#endif
diff --git a/atari/treeview.c b/atari/treeview.c
index 4a5cb0a75..7144d212c 100755
--- a/atari/treeview.c
+++ b/atari/treeview.c
@@ -1,446 +1,554 @@
-/*
- * 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
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <stdbool.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <windom.h>
-
-#include "content/urldb.h"
-#include "desktop/browser.h"
-#include "desktop/plotters.h"
-#include "desktop/textinput.h"
-#include "desktop/tree.h"
-#include "desktop/tree_url_node.h"
-#include "desktop/textinput.h"
-#include "utils/log.h"
-#include "utils/messages.h"
-#include "utils/utils.h"
-#include "atari/gui.h"
-#include "atari/treeview.h"
-#include "atari/plot/plot.h"
-#include "atari/misc.h"
-#include "cflib.h"
-
-extern int mouse_hold_start[3];
-extern browser_mouse_state bmstate;
-extern short last_drag_x;
-extern short last_drag_y;
+/*
+ * 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#include "content/urldb.h"
+#include "desktop/browser.h"
+#include "desktop/plotters.h"
+#include "desktop/textinput.h"
+#include "desktop/tree.h"
+#include "desktop/tree_url_node.h"
+#include "desktop/textinput.h"
+#include "utils/log.h"
+#include "utils/messages.h"
+#include "utils/utils.h"
+#include "atari/gui.h"
+#include "atari/treeview.h"
+#include "atari/plot/plot.h"
+#include "atari/misc.h"
+#include "atari/gemtk/gemtk.h"
+#include "cflib.h"
+
+enum treeview_area_e {
+ TREEVIEW_AREA_WORK = 0,
+ TREEVIEW_AREA_TOOLBAR,
+ TREEVIEW_AREA_CONTENT
+};
+
+extern int mouse_hold_start[3];
+extern browser_mouse_state bmstate;
+extern short last_drag_x;
+extern short last_drag_y;
extern long atari_plot_flags;
extern int atari_plot_vdi_handle;
-
-static void atari_treeview_resized(struct tree *tree,int w,int h,void *pw);
-static void atari_treeview_scroll_visible(int y, int h, void *pw);
-static void atari_treeview_get_dimensions(int *width, int *height,void *pw);
-
-static const struct treeview_table atari_tree_callbacks = {
- atari_treeview_request_redraw,
- atari_treeview_resized,
- atari_treeview_scroll_visible,
- atari_treeview_get_dimensions
-};
-
-static void __CDECL evnt_tv_keybd( WINDOW *win, short buff[8], void * data )
-{
- bool r=false;
- long kstate = 0;
- long kcode = 0;
- long ucs4;
- long ik;
- unsigned short nkc = 0;
- unsigned short nks = 0;
- unsigned char ascii;
-
- NSTREEVIEW tv = (NSTREEVIEW) data;
- kstate = evnt.mkstate;
- kcode = evnt.keybd;
- nkc= gem_to_norm( (short)kstate, (short)kcode );
- ascii = (nkc & 0xFF);
- ik = nkc_to_input_key( nkc, &ucs4 );
-
- if( ik == 0 ){
- if (ascii >= 9 ) {
- r = tree_keypress( tv->tree, ucs4 );
- }
- } else {
- r = tree_keypress( tv->tree, ik );
- }
-}
-
-
-static void __CDECL evnt_tv_redraw( WINDOW *win, short buff[8], void * data )
-{
- GRECT work, clip;
- NSTREEVIEW tv = (NSTREEVIEW) data;
- if( tv == NULL )
- return;
- WindGetGrect( win, WF_WORKXYWH, &work );
- clip = work;
- if ( !rc_intersect( (GRECT*)&buff[4], &clip ) ) return;
- clip.g_x -= work.g_x;
- clip.g_y -= work.g_y;
- if( clip.g_x < 0 ) {
- clip.g_w = work.g_w + clip.g_x;
- clip.g_x = 0;
- }
- if( clip.g_y < 0 ) {
- clip.g_h = work.g_h + clip.g_y;
- clip.g_y = 0;
- }
- if( clip.g_h > 0 && clip.g_w > 0 ) {
- atari_treeview_request_redraw(
- win->xpos*win->w_u + clip.g_x,
- win->ypos*win->h_u + clip.g_y,
- clip.g_w, clip.g_h, tv
- );
- }
-}
-
-static void __CDECL evnt_tv_mbutton( WINDOW *win, short buff[8], void * data )
-{
- GRECT work;
- NSTREEVIEW tv = (NSTREEVIEW) data;
- if( tv == NULL )
- return;
- if( evnt.mbut & 2 ) {
- /* do not handle right click */
- return;
- }
-
- WindGetGrect( tv->window, WF_WORKXYWH, &work );
-
- /* mouse click relative origin: */
- short origin_rel_x = (evnt.mx-work.g_x)+(win->xpos*win->w_u);
- short origin_rel_y = (evnt.my-work.g_y)+(win->ypos*win->h_u);
-
- if( origin_rel_x >= 0 && origin_rel_y >= 0
- && evnt.mx < work.g_x + work.g_w
- && evnt.my < work.g_y + work.g_h )
- {
- int bms;
- bool ignore=false;
- short cur_rel_x, cur_rel_y, dummy, mbut;
-
- if( evnt.nb_click == 2 ){
- tree_mouse_action(tv->tree,
- BROWSER_MOUSE_CLICK_1 | BROWSER_MOUSE_DOUBLE_CLICK,
- origin_rel_x, origin_rel_y );
- return;
- }
-
- graf_mkstate(&cur_rel_x, &cur_rel_x, &mbut, &dummy);
- if( (mbut&1) == 0 ){
- bms = BROWSER_MOUSE_CLICK_1 | BROWSER_MOUSE_PRESS_1;
- if( evnt.nb_click == 2 ) {
- bms = BROWSER_MOUSE_DOUBLE_CLICK;
- }
- tree_mouse_action(tv->tree, bms, origin_rel_x, origin_rel_y );
- } else {
- /* button still pressed */
-
- short prev_x = origin_rel_x;
- short prev_y = origin_rel_y;
-
- cur_rel_x = origin_rel_x;
- cur_rel_y = origin_rel_y;
-
- if( tree_is_edited(tv->tree) ){
- gem_set_cursor(&gem_cursors.ibeam);
- } else {
- gem_set_cursor(&gem_cursors.hand);
- }
-
- tv->startdrag.x = origin_rel_x;
- tv->startdrag.y = origin_rel_y;
-
- tree_mouse_action( tv->tree,
- BROWSER_MOUSE_DRAG_1 | BROWSER_MOUSE_DRAG_ON ,
- cur_rel_x, cur_rel_y );
- do{
- if( abs(prev_x-cur_rel_x) > 5 || abs(prev_y-cur_rel_y) > 5 ){
- tree_mouse_action( tv->tree,
- BROWSER_MOUSE_HOLDING_1 | BROWSER_MOUSE_DRAG_ON,
- cur_rel_x, cur_rel_y);
- prev_x = cur_rel_x;
- prev_y = cur_rel_y;
- }
-
- if( tv->redraw )
- atari_treeview_redraw( tv );
- /* sample mouse button state: */
- graf_mkstate(&cur_rel_x, &cur_rel_y, &mbut, &dummy);
- cur_rel_x = (cur_rel_x-work.g_x)+(win->xpos*win->w_u);
- cur_rel_y = (cur_rel_y-work.g_y)+(win->ypos*win->h_u);
- } while( mbut & 1 );
-
- tree_drag_end(tv->tree, 0, tv->startdrag.x, tv->startdrag.y,
- cur_rel_x, cur_rel_y );
- gem_set_cursor(&gem_cursors.arrow);
- }
- }
-}
-
-NSTREEVIEW atari_treeview_create( uint32_t flags, WINDOW *win )
-{
- if( win == NULL )
- return( NULL );
- NSTREEVIEW new = malloc(sizeof(struct atari_treeview));
- if (new == NULL)
- return NULL;
- memset( new, 0, sizeof(struct atari_treeview));
- new->tree = tree_create(flags, &atari_tree_callbacks, new);
- if (new->tree == NULL) {
- free(new);
- return NULL;
- }
- new->window = win;
-
- win->w_u = 16;
- win->h_u = 16;
-
- EvntDataAdd( new->window, WM_XBUTTON, evnt_tv_mbutton, new, EV_BOT );
- EvntDataAttach( new->window, WM_REDRAW, evnt_tv_redraw, new );
- EvntDataAttach( new->window, WM_XKEYBD, evnt_tv_keybd, new );
-
- return(new);
-}
-
-void atari_treeview_open( NSTREEVIEW tv )
-{
- if( tv->window != NULL ) {
- tree_set_redraw(tv->tree, true);
- }
-}
-
-void atari_treeview_close( NSTREEVIEW tv )
-{
- if( tv->window != NULL ) {
- tree_set_redraw(tv->tree, false);
- }
-}
-
-void atari_treeview_destroy( NSTREEVIEW tv )
-{
- if( tv != NULL ){
- tv->disposing = true;
- LOG(("tree: %p", tv));
- if( tv->tree != NULL ) {
- tree_delete(tv->tree);
- tv->tree = NULL;
- }
- free( tv );
- }
-}
-
-bool atari_treeview_mevent( NSTREEVIEW tv, browser_mouse_state bms, int x, int y)
-{
- if( tv == NULL )
- return ( false );
- GRECT work;
- WindGetGrect( tv->window, WF_WORKXYWH, &work );
- int rx = (x-work.g_x)+(tv->window->xpos*tv->window->w_u);
- int ry = (y-work.g_y)+(tv->window->ypos*tv->window->h_u);
- tree_mouse_action(tv->tree, bms, rx, ry );
- tv->click.x = rx;
- tv->click.y = ry;
- return( true );
-}
-
-
-
-void atari_treeview_redraw( NSTREEVIEW tv)
+
+static void atari_treeview_resized(struct tree *tree,int w,int h, void *pw);
+static void atari_treeview_scroll_visible(int y, int h, void *pw);
+static void atari_treeview_get_dimensions(int *width, int *height, void *pw);
+static void atari_treeview_get_grect(NSTREEVIEW tree,
+ enum treeview_area_e mode, GRECT *dest);
+
+static const struct treeview_table atari_tree_callbacks = {
+ atari_treeview_request_redraw,
+ atari_treeview_resized,
+ atari_treeview_scroll_visible,
+ atari_treeview_get_dimensions
+};
+
+static void __CDECL on_mbutton_event(NSTREEVIEW tv, EVMULT_OUT *ev_out,
+ short msg[8]);
+static void __CDECL on_keybd_event(NSTREEVIEW tv, EVMULT_OUT *ev_out,
+ short msg[8]);
+static void __CDECL on_redraw_event(NSTREEVIEW tv, EVMULT_OUT *ev_out,
+ short msg[8]);
+
+static short handle_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8])
{
-
- if (tv != NULL) {
- if( tv->redraw && ((atari_plot_flags & PLOT_FLAG_OFFSCREEN) == 0) ) {
- short todo[4];
- GRECT work;
- WindGetGrect( tv->window, WF_WORKXYWH, &work );
-
- struct redraw_context ctx = {
- .interactive = true,
- .background_images = true,
- .plot = &atari_plotters
- };
- plot_set_dimensions(work.g_x, work.g_y, work.g_w, work.g_h);
- if (plot_lock() == false)
- return;
-
- 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(atari_plot_vdi_handle, 1, (short*)&todo );
-
- if( wind_get(tv->window->handle, WF_FIRSTXYWH,
- &todo[0], &todo[1], &todo[2], &todo[3] )!=0 ) {
- while (todo[2] && todo[3]) {
-
- /* convert screen to treeview coords: */
- todo[0] = todo[0] - work.g_x + tv->window->xpos*tv->window->w_u;
- todo[1] = todo[1] - work.g_y + tv->window->ypos*tv->window->h_u;
- 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((GRECT *)&tv->rdw_area,(GRECT *)&todo)) {
- tree_draw(tv->tree, -tv->window->xpos*16, -tv->window->ypos*16,
- todo[0], todo[1], todo[2], todo[3], &ctx
- );
- }
- if (wind_get(tv->window->handle, WF_NEXTXYWH,
- &todo[0], &todo[1], &todo[2], &todo[3])==0) {
- break;
- }
- }
- } else {
- plot_unlock();
- return;
- }
- plot_unlock();
- vs_clip(atari_plot_vdi_handle, 0, (short*)&todo);
- tv->redraw = false;
- tv->rdw_area.g_x = 65000;
- tv->rdw_area.g_y = 65000;
- tv->rdw_area.g_w = -1;
- tv->rdw_area.g_h = -1;
- } else {
- /* just copy stuff from the offscreen buffer */
- }
- }
-}
-
-
-/**
- * Callback to force a redraw of part of the treeview window.
- *
- * \param x Min X Coordinate of area to be redrawn.
- * \param y Min Y Coordinate of area to be redrawn.
- * \param width Width of area to be redrawn.
- * \param height Height of area to be redrawn.
- * \param pw The treeview object to be redrawn.
- */
-void atari_treeview_request_redraw(int x, int y, int w, int h, void *pw)
-{
- if ( pw != NULL ) {
- NSTREEVIEW tv = (NSTREEVIEW) pw;
- if( tv->redraw == false ){
- tv->redraw = true;
- tv->rdw_area.g_x = x;
- tv->rdw_area.g_y = y;
- tv->rdw_area.g_w = w;
- tv->rdw_area.g_h = h;
- } else {
- /* merge the redraw area to the new area.: */
- int newx1 = x+w;
- int newy1 = y+h;
- int oldx1 = tv->rdw_area.g_x + tv->rdw_area.g_w;
- int oldy1 = tv->rdw_area.g_y + tv->rdw_area.g_h;
- tv->rdw_area.g_x = MIN(tv->rdw_area.g_x, x);
- tv->rdw_area.g_y = MIN(tv->rdw_area.g_y, y);
- tv->rdw_area.g_w = ( oldx1 > newx1 ) ? oldx1 - tv->rdw_area.g_x : newx1 - tv->rdw_area.g_x;
- tv->rdw_area.g_h = ( oldy1 > newy1 ) ? oldy1 - tv->rdw_area.g_y : newy1 - tv->rdw_area.g_y;
- }
- }
-}
-
-
-/**
- * Callback to notify us of a new overall tree size.
- *
- * \param tree The tree being resized.
- * \param width The new width of the window.
- * \param height The new height of the window.
- * \param *pw The treeview object to be resized.
- */
-
-void atari_treeview_resized(struct tree *tree, int width, int height, void *pw)
-{
- if (pw != NULL) {
- NSTREEVIEW tv = (NSTREEVIEW) pw;
- if( tv->disposing )
- return;
- tv->extent.x = width;
- tv->extent.y = height;
- tv->window->ypos_max = (height / tv->window->w_u)+0.5;
- tv->window->xpos_max = (width / tv->window->h_u)+0.5;
- WindSlider( tv->window, HSLIDER|VSLIDER );
- }
-}
-
-
-/**
- * Callback to request that a section of the tree is scrolled into view.
- *
- * \param y The Y coordinate of top of the area in NS units.
- * \param height The height of the area in NS units.
- * \param *pw The treeview object affected.
- */
-
-void atari_treeview_scroll_visible(int y, int height, void *pw)
-{
- /* we don't support dragging outside the treeview */
- /* so we don't need to implement this? */
-}
-
-/**
- * Callback to return the tree window dimensions to the treeview system.
- *
- * \param *width Return the window width.
- * \param *height Return the window height.
- * \param *pw The treeview object to use.
- */
-
-void atari_treeview_get_dimensions(int *width, int *height,
- void *pw)
-{
- if (pw != NULL && (width != NULL || height != NULL)) {
- NSTREEVIEW tv = (NSTREEVIEW) pw;
- GRECT work;
- WindGetGrect( tv->window, WF_WORKXYWH, &work );
- *width = work.g_w;
- *height = work.g_h;
- }
-}
-
-
-/**
- * Translates a content_type to the name of a respective icon
- *
- * \param content_type content type
- * \param buffer buffer for the icon name
- */
-void tree_icon_name_from_content_type(char *buffer, content_type type)
-{
- switch (type) {
- case CONTENT_HTML:
- case CONTENT_TEXTPLAIN:
- case CONTENT_CSS:
- case CONTENT_IMAGE:
- default:
- strcpy( buffer, "content.png" );
- break;
- }
-}
+
+ NSTREEVIEW tv = (NSTREEVIEW) guiwin_get_user_data(win);
+
+ if( (ev_out->emo_events & MU_MESAG) != 0 ) {
+ // handle message
+ switch (msg[0]) {
+
+ case WM_REDRAW:
+ on_redraw_event(tv, ev_out, msg);
+ break;
+
+ case WM_SIZED:
+ case WM_FULLED:
+ //atari_treeview_resized(tv->tree, tv->extent.x, tv->extent.y, tv);
+ break;
+
+ default:
+ break;
+ }
+ }
+ if( (ev_out->emo_events & MU_KEYBD) != 0 ) {
+ printf("Treeview keybd\n");
+ on_keybd_event(tv, ev_out, msg);
+ // handle key
+ }
+ if( (ev_out->emo_events & MU_TIMER) != 0 ) {
+ // handle_timer();
+ }
+ if( (ev_out->emo_events & MU_BUTTON) != 0 ) {
+ LOG(("Treeview click at: %d,%d\n", ev_out->emo_mouse.p_x,
+ ev_out->emo_mouse.p_y));
+ printf("Treeview click at: %d,%d\n", ev_out->emo_mouse.p_x,
+ ev_out->emo_mouse.p_y);
+ on_mbutton_event(tv, ev_out, msg);
+ }
+
+ if(tv != NULL && tv->user_func != NULL){
+ tv->user_func(win, ev_out, msg);
+ }
+
+ return(0);
+}
+
+static void __CDECL on_keybd_event(NSTREEVIEW tv, EVMULT_OUT *ev_out,
+ short msg[8])
+{
+ bool r=false;
+ long kstate = 0;
+ long kcode = 0;
+ long ucs4;
+ long ik;
+ unsigned short nkc = 0;
+ unsigned short nks = 0;
+ unsigned char ascii;
+
+ kstate = ev_out->emo_kmeta;
+ kcode = ev_out->emo_kreturn;
+ nkc= gem_to_norm( (short)kstate, (short)kcode );
+ ascii = (nkc & 0xFF);
+ ik = nkc_to_input_key( nkc, &ucs4 );
+
+ if( ik == 0 ){
+ if (ascii >= 9 ) {
+ r = tree_keypress( tv->tree, ucs4 );
+ }
+ } else {
+ r = tree_keypress( tv->tree, ik );
+ }
+}
+
+
+static void __CDECL on_redraw_event(NSTREEVIEW tv, EVMULT_OUT *ev_out,
+ short msg[8])
+{
+ GRECT work, clip;
+ struct guiwin_scroll_info_s *slid;
+
+ if( tv == NULL )
+ return;
+
+ guiwin_get_grect(tv->window, GUIWIN_AREA_CONTENT, &work);
+ slid = guiwin_get_scroll_info(tv->window);
+
+ clip = work;
+ if ( !rc_intersect( (GRECT*)&msg[4], &clip ) ) return;
+ clip.g_x -= work.g_x;
+ clip.g_y -= work.g_y;
+ if( clip.g_x < 0 ) {
+ clip.g_w = work.g_w + clip.g_x;
+ clip.g_x = 0;
+ }
+ if( clip.g_y < 0 ) {
+ clip.g_h = work.g_h + clip.g_y;
+ clip.g_y = 0;
+ }
+ if( clip.g_h > 0 && clip.g_w > 0 ) {
+ // TODO: get slider values
+ atari_treeview_request_redraw((slid->x_pos*slid->x_unit_px) + clip.g_x,
+ (slid->y_pos*slid->y_unit_px) + clip.g_y,
+ clip.g_w, clip.g_h, tv
+ );
+ }
+}
+
+static void __CDECL on_mbutton_event(NSTREEVIEW tv, EVMULT_OUT *ev_out,
+ short msg[8])
+{
+ struct guiwin_scroll_info_s *slid;
+ GRECT work;
+
+ if(tv == NULL)
+ return;
+ if( evnt.mbut & 2 ) {
+ /* do not handle right click */
+ return;
+ }
+
+ guiwin_get_grect(tv->window, GUIWIN_AREA_CONTENT, &work);
+ slid = guiwin_get_scroll_info(tv->window);
+
+ /* mouse click relative origin: */
+
+ short origin_rel_x = (ev_out->emo_mouse.p_x-work.g_x) +
+ (slid->x_pos*slid->x_unit_px);
+ short origin_rel_y = (ev_out->emo_mouse.p_y-work.g_y) +
+ (slid->y_pos*slid->y_unit_px);
+
+ if( origin_rel_x >= 0 && origin_rel_y >= 0
+ && evnt.mx < work.g_x + work.g_w
+ && evnt.my < work.g_y + work.g_h )
+ {
+ int bms;
+ bool ignore=false;
+ short cur_rel_x, cur_rel_y, dummy, mbut;
+
+ if( evnt.nb_click == 2 ){
+ tree_mouse_action(tv->tree,
+ BROWSER_MOUSE_CLICK_1 | BROWSER_MOUSE_DOUBLE_CLICK,
+ origin_rel_x, origin_rel_y );
+ return;
+ }
+
+ graf_mkstate(&cur_rel_x, &cur_rel_x, &mbut, &dummy);
+ if( (mbut&1) == 0 ){
+ bms = BROWSER_MOUSE_CLICK_1 | BROWSER_MOUSE_PRESS_1;
+ if( evnt.nb_click == 2 ) {
+ bms = BROWSER_MOUSE_DOUBLE_CLICK;
+ }
+ tree_mouse_action(tv->tree, bms, origin_rel_x, origin_rel_y );
+ } else {
+ /* button still pressed */
+
+ short prev_x = origin_rel_x;
+ short prev_y = origin_rel_y;
+
+ cur_rel_x = origin_rel_x;
+ cur_rel_y = origin_rel_y;
+
+ if( tree_is_edited(tv->tree) ){
+ gem_set_cursor(&gem_cursors.ibeam);
+ } else {
+ gem_set_cursor(&gem_cursors.hand);
+ }
+
+ tv->startdrag.x = origin_rel_x;
+ tv->startdrag.y = origin_rel_y;
+
+ tree_mouse_action( tv->tree,
+ BROWSER_MOUSE_DRAG_1 | BROWSER_MOUSE_DRAG_ON ,
+ cur_rel_x, cur_rel_y );
+ do{
+ if( abs(prev_x-cur_rel_x) > 5 || abs(prev_y-cur_rel_y) > 5 ){
+ tree_mouse_action( tv->tree,
+ BROWSER_MOUSE_HOLDING_1 | BROWSER_MOUSE_DRAG_ON,
+ cur_rel_x, cur_rel_y);
+ prev_x = cur_rel_x;
+ prev_y = cur_rel_y;
+ }
+
+ if( tv->redraw )
+ atari_treeview_redraw( tv );
+ /* sample mouse button state: */
+ graf_mkstate(&cur_rel_x, &cur_rel_y, &mbut, &dummy);
+ cur_rel_x = (cur_rel_x-work.g_x)+(slid->x_pos*slid->x_unit_px);
+ cur_rel_y = (cur_rel_y-work.g_y)+(slid->y_pos*slid->y_unit_px);
+ } while( mbut & 1 );
+
+ tree_drag_end(tv->tree, 0, tv->startdrag.x, tv->startdrag.y,
+ cur_rel_x, cur_rel_y );
+ gem_set_cursor(&gem_cursors.arrow);
+ }
+ }
+}
+
+NSTREEVIEW atari_treeview_create(uint32_t flags, GUIWIN *win,
+ guiwin_event_handler_f user_func)
+{
+ struct guiwin_scroll_info_s *slid;
+
+ if( win == NULL )
+ return( NULL );
+ NSTREEVIEW new = malloc(sizeof(struct atari_treeview));
+ if (new == NULL)
+ return NULL;
+ memset( new, 0, sizeof(struct atari_treeview));
+ new->tree = tree_create(flags, &atari_tree_callbacks, new);
+ if (new->tree == NULL) {
+ free(new);
+ return NULL;
+ }
+ new->window = win;
+ new->user_func = user_func;
+
+ guiwin_set_event_handler(win, handle_event);
+ guiwin_set_user_data(win, (void*)new);
+
+ slid = guiwin_get_scroll_info(new->window);
+ slid->y_unit_px = 16;
+ slid->x_unit_px = 16;
+
+ return(new);
+}
+
+void atari_treeview_open( NSTREEVIEW tv )
+{
+ if( tv->window != NULL ) {
+ tree_set_redraw(tv->tree, true);
+ }
+}
+
+void atari_treeview_close( NSTREEVIEW tv )
+{
+ if( tv->window != NULL ) {
+ tree_set_redraw(tv->tree, false);
+ }
+}
+
+void atari_treeview_destroy( NSTREEVIEW tv )
+{
+ if( tv != NULL ){
+ tv->disposing = true;
+ LOG(("tree: %p", tv));
+ if( tv->tree != NULL ) {
+ tree_delete(tv->tree);
+ tv->tree = NULL;
+ }
+ free( tv );
+ }
+}
+
+bool atari_treeview_mevent( NSTREEVIEW tv, browser_mouse_state bms, int x, int y)
+{
+ GRECT work;
+ struct guiwin_scroll_info_s *slid;
+
+ if( tv == NULL )
+ return ( false );
+
+ guiwin_get_grect(tv->window, GUIWIN_AREA_CONTENT, &work);
+ slid = guiwin_get_scroll_info(tv->window);
+
+ int rx = (x-work.g_x)+(slid->x_pos*slid->x_unit_px);
+ int ry = (y-work.g_y)+(slid->y_pos*slid->y_unit_px);
+
+ tree_mouse_action(tv->tree, bms, rx, ry);
+
+ tv->click.x = rx;
+ tv->click.y = ry;
+
+ return( true );
+}
+
+
+
+void atari_treeview_redraw( NSTREEVIEW tv)
+{
+ if (tv != NULL) {
+ if( tv->redraw && ((atari_plot_flags & PLOT_FLAG_OFFSCREEN) == 0) ) {
+
+ short todo[4];
+ GRECT work;
+ short handle = guiwin_get_handle(tv->window);
+ struct guiwin_scroll_info_s *slid;
+
+ guiwin_get_grect(tv->window, GUIWIN_AREA_CONTENT, &work);
+ slid = guiwin_get_scroll_info(tv->window);
+
+ struct redraw_context ctx = {
+ .interactive = true,
+ .background_images = true,
+ .plot = &atari_plotters
+ };
+ plot_set_dimensions(work.g_x, work.g_y, work.g_w, work.g_h);
+ if (plot_lock() == false)
+ return;
+
+ if( wind_get(handle, WF_FIRSTXYWH,
+ &todo[0], &todo[1], &todo[2], &todo[3] )!=0 ) {
+ while (todo[2] && todo[3]) {
+
+ short pxy[4];
+ pxy[0] = todo[0];
+ pxy[1] = todo[1];
+ pxy[2] = todo[0] + todo[2]-1;
+ pxy[3] = todo[1] + todo[3]-1;
+ vs_clip(atari_plot_vdi_handle, 1, (short*)&pxy);
+
+ /* convert screen to treeview coords: */
+ todo[0] = todo[0] - work.g_x + slid->x_pos*slid->x_unit_px;
+ todo[1] = todo[1] - work.g_y + slid->y_pos*slid->y_unit_px;
+ 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;
+ }
+
+ // TODO: get slider values
+ if (rc_intersect((GRECT *)&tv->rdw_area,(GRECT *)&todo)) {
+ tree_draw(tv->tree, -(slid->x_pos*slid->x_unit_px),
+ -(slid->y_pos*slid->y_unit_px),
+ todo[0], todo[1], todo[2], todo[3], &ctx
+ );
+ }
+ vs_clip(atari_plot_vdi_handle, 0, (short*)&pxy);
+ if (wind_get(handle, WF_NEXTXYWH,
+ &todo[0], &todo[1], &todo[2], &todo[3])==0) {
+ break;
+ }
+ }
+ } else {
+ plot_unlock();
+ return;
+ }
+ plot_unlock();
+ tv->redraw = false;
+ tv->rdw_area.g_x = 65000;
+ tv->rdw_area.g_y = 65000;
+ tv->rdw_area.g_w = -1;
+ tv->rdw_area.g_h = -1;
+ } else {
+ /* just copy stuff from the offscreen buffer */
+ }
+ }
+}
+
+
+/**
+ * Callback to force a redraw of part of the treeview window.
+ *
+ * \param x Min X Coordinate of area to be redrawn.
+ * \param y Min Y Coordinate of area to be redrawn.
+ * \param width Width of area to be redrawn.
+ * \param height Height of area to be redrawn.
+ * \param pw The treeview object to be redrawn.
+ */
+void atari_treeview_request_redraw(int x, int y, int w, int h, void *pw)
+{
+ if ( pw != NULL ) {
+ NSTREEVIEW tv = (NSTREEVIEW) pw;
+ if( tv->redraw == false ){
+ tv->redraw = true;
+ tv->rdw_area.g_x = x;
+ tv->rdw_area.g_y = y;
+ tv->rdw_area.g_w = w;
+ tv->rdw_area.g_h = h;
+ } else {
+ /* merge the redraw area to the new area.: */
+ int newx1 = x+w;
+ int newy1 = y+h;
+ int oldx1 = tv->rdw_area.g_x + tv->rdw_area.g_w;
+ int oldy1 = tv->rdw_area.g_y + tv->rdw_area.g_h;
+ tv->rdw_area.g_x = MIN(tv->rdw_area.g_x, x);
+ tv->rdw_area.g_y = MIN(tv->rdw_area.g_y, y);
+ tv->rdw_area.g_w = ( oldx1 > newx1 ) ? oldx1 - tv->rdw_area.g_x : newx1 - tv->rdw_area.g_x;
+ tv->rdw_area.g_h = ( oldy1 > newy1 ) ? oldy1 - tv->rdw_area.g_y : newy1 - tv->rdw_area.g_y;
+ }
+ dbg_grect("atari_treeview_request_redraw", &tv->rdw_area);
+ }
+}
+
+
+/**
+ * Callback to notify us of a new overall tree size.
+ *
+ * \param tree The tree being resized.
+ * \param width The new width of the window.
+ * \param height The new height of the window.
+ * \param *pw The treeview object to be resized.
+ */
+
+void atari_treeview_resized(struct tree *tree, int width, int height, void *pw)
+{
+ GRECT area;
+ if (pw != NULL) {
+ NSTREEVIEW tv = (NSTREEVIEW) pw;
+ if( tv->disposing )
+ return;
+ tv->extent.x = width;
+ tv->extent.y = height;
+ struct guiwin_scroll_info_s *slid = guiwin_get_scroll_info(tv->window);
+ guiwin_get_grect(tv->window, GUIWIN_AREA_CONTENT, &area);
+ slid->x_units = (width/slid->x_unit_px);
+ slid->y_units = (height/slid->y_unit_px);
+ /*printf("units content: %d, units viewport: %d\n", (height/slid->y_unit_px),
+ (area.g_h/slid->y_unit_px));*/
+ guiwin_update_slider(tv->window, GUIWIN_VH_SLIDER);
+ }
+}
+
+
+/**
+ * Callback to request that a section of the tree is scrolled into view.
+ *
+ * \param y The Y coordinate of top of the area in NS units.
+ * \param height The height of the area in NS units.
+ * \param *pw The treeview object affected.
+ */
+
+void atari_treeview_scroll_visible(int y, int height, void *pw)
+{
+ /* we don't support dragging outside the treeview */
+ /* so we don't need to implement this? */
+}
+
+static void atari_treeview_get_grect(NSTREEVIEW tv, enum treeview_area_e mode,
+ GRECT *dest)
+{
+
+ if (mode == TREEVIEW_AREA_CONTENT) {
+ guiwin_get_grect(tv->window, GUIWIN_AREA_CONTENT, dest);
+ }
+ else if (mode == TREEVIEW_AREA_TOOLBAR) {
+ guiwin_get_grect(tv->window, GUIWIN_AREA_TOOLBAR, dest);
+ }
+}
+
+/**
+ * Callback to return the tree window dimensions to the treeview system.
+ *
+ * \param *width Return the window width.
+ * \param *height Return the window height.
+ * \param *pw The treeview object to use.
+ */
+
+void atari_treeview_get_dimensions(int *width, int *height,
+ void *pw)
+{
+ if (pw != NULL && (width != NULL || height != NULL)) {
+ NSTREEVIEW tv = (NSTREEVIEW) pw;
+ GRECT work;
+ atari_treeview_get_grect(tv, TREEVIEW_AREA_CONTENT, &work);
+ *width = work.g_w;
+ *height = work.g_h;
+ }
+}
+
+
+/**
+ * Translates a content_type to the name of a respective icon
+ *
+ * \param content_type content type
+ * \param buffer buffer for the icon name
+ */
+void tree_icon_name_from_content_type(char *buffer, content_type type)
+{
+ switch (type) {
+ case CONTENT_HTML:
+ case CONTENT_TEXTPLAIN:
+ case CONTENT_CSS:
+ case CONTENT_IMAGE:
+ default:
+ strcpy( buffer, "content.png" );
+ break;
+ }
+}
diff --git a/atari/treeview.h b/atari/treeview.h
index 3796665af..8683bc349 100755
--- a/atari/treeview.h
+++ b/atari/treeview.h
@@ -1,53 +1,56 @@
-/*
- * 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
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef NS_ATARI_TREEVIEW_H
-#define NS_ATARI_TREEVIEW_H
-
-#include <stdbool.h>
-#include <windom.h>
-#include "desktop/tree.h"
-#include "atari/gui.h"
-
-#define ATARI_TREEVIEW_WIDGETS (CLOSER | MOVER | SIZER| NAME | FULLER | SMALLER | VSLIDE | HSLIDE | UPARROW | DNARROW | LFARROW | RTARROW)
-
-struct atari_treeview
-{
- struct tree * tree;
- WINDOW * window;
- bool disposing;
- bool redraw;
- GRECT rdw_area;
- POINT click;
- POINT extent;
- POINT startdrag;
-};
-
-typedef struct atari_treeview * NSTREEVIEW;
-
-NSTREEVIEW atari_treeview_create( uint32_t flags, WINDOW * win );
-void atari_treeview_destroy( NSTREEVIEW tv );
-void atari_treeview_open( NSTREEVIEW tv );
-void atari_treeview_close( NSTREEVIEW tv );
-void atari_treeview_request_redraw(int x, int y, int w, int h, void *pw);
-void atari_treeview_redraw( NSTREEVIEW tv );
-bool atari_treeview_mevent( NSTREEVIEW tv, browser_mouse_state bms, int x, int y);
-
-
-
+/*
+ * 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NS_ATARI_TREEVIEW_H
+#define NS_ATARI_TREEVIEW_H
+
+#include <stdbool.h>
+#include <windom.h>
+#include "desktop/tree.h"
+#include "atari/gui.h"
+#include "atari/gemtk/gemtk.h"
+
+#define ATARI_TREEVIEW_WIDGETS (CLOSER | MOVER | SIZER| NAME | FULLER | SMALLER | VSLIDE | HSLIDE | UPARROW | DNARROW | LFARROW | RTARROW)
+
+struct atari_treeview
+{
+ struct tree * tree;
+ GUIWIN * window;
+ bool disposing;
+ bool redraw;
+ GRECT rdw_area;
+ POINT extent;
+ POINT click;
+ POINT startdrag;
+ guiwin_event_handler_f user_func;
+};
+
+typedef struct atari_treeview * NSTREEVIEW;
+
+NSTREEVIEW atari_treeview_create( uint32_t flags, GUIWIN *win,
+ guiwin_event_handler_f user_func);
+void atari_treeview_destroy( NSTREEVIEW tv );
+void atari_treeview_open( NSTREEVIEW tv );
+void atari_treeview_close( NSTREEVIEW tv );
+void atari_treeview_request_redraw(int x, int y, int w, int h, void *pw);
+void atari_treeview_redraw( NSTREEVIEW tv );
+bool atari_treeview_mevent( NSTREEVIEW tv, browser_mouse_state bms, int x, int y);
+
+
+
#endif