diff options
Diffstat (limited to 'atari')
60 files changed, 6627 insertions, 4726 deletions
diff --git a/atari/Makefile.target b/atari/Makefile.target index 7f0573407..e7755d56f 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,44 @@ 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\ - 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 +S_ATARI := \ + bitmap.c \ + caret.c \ + findfile.c \ + filetype.c \ + font.c \ + gui.c \ + misc.c \ + schedule.c \ + download.c \ + thumbnail.c \ + login.c \ + verify_ssl.c \ + treeview.c \ + hotlist.c \ + history.c\ + search.c \ + redrawslots.c \ + encoding.c \ + rootwin.c \ + toolbar.c \ + statusbar.c \ + browser.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/Makefile.target.orig b/atari/Makefile.target.orig new file mode 100644 index 000000000..25951b961 --- /dev/null +++ b/atari/Makefile.target.orig @@ -0,0 +1,120 @@ +# ---------------------------------------------------------------------------- +# Atari target setup +# ---------------------------------------------------------------------------- + +ifeq ($(ATARI_ARCH),68000) +PRGSUFFIX := 000.app +PKGNAME := ns000.zip +endif + +ifeq ($(ATARI_ARCH),68020-60) +CFLAGS += -m68020-60 +LDFLAGS += -m68020-60 +PRGSUFFIX := 020.app +PKGNAME := ns020.zip +endif + +ifeq ($(ATARI_ARCH),5475) +CFLAGS += -mcpu=5475 +LDFLAGS += -mcpu=5475 +PRGSUFFIX := v4e.app +PKGNAME := nsv4e.zip +endif + +# non-pkgconfig components + +FREETYPE_FONT_CFLAGS := $(shell freetype-config --cflags) -DWITH_FREETYPE_FONT_DRIVER +SPIDERMONKEY_CFLAGS := -DWITH_MOZJS -DXP_UNIX -DJS_HAS_FILE_OBJECT=0 -DJSOPTION_JIT=0 -DPOSIX_SOURCE -D_BSD_SOURCE + +$(eval $(call feature_enabled,MNG,-DWITH_MNG,-lmng,PNG/MNG/JNG (libmng))) +$(eval $(call feature_enabled,PNG,-DWITH_PNG,-lpng,PNG (libpng))) +$(eval $(call feature_enabled,MOZJS,$(SPIDERMONKEY_CFLAGS),-ljs,JavaScript (Spidermonkey))) +$(eval $(call feature_enabled,ATARI_FREETYPE_FONT,$(FREETYPE_FONT_CFLAGS),-lfreetype,(Freetype))) +$(eval $(call feature_enabled,ATARI_NETSURF_FONT,-DWITH_INTERNAL_FONT_DRIVER,,(Internal Font))) +$(eval $(call feature_enabled,ATARI_8BPP_SUPPORT,-DWITH_8BPP_SUPPORT,,(Indexed screen format support))) + +# define additional CFLAGS and LDFLAGS requirements for pkg-configed libs here +NETSURF_FEATURE_RSVG_CFLAGS := -DWITH_RSVG +NETSURF_FEATURE_HUBBUB_CFLAGS := -DWITH_HUBBUB +NETSURF_FEATURE_BMP_CFLAGS := -DWITH_BMP +NETSURF_FEATURE_GIF_CFLAGS := -DWITH_GIF +NETSURF_FEATURE_JS_CFLAGS := -DWITH_JS -DJS_HAS_FILE_OBJECT=0 +NETSURF_FEATURE_MOZJS_CFLAGS := -DWITH_MOZJS -DJS_HAS_FILE_OBJECT=0 + +ifeq ($(NETSURF_USE_MOZJS),YES) +NETSURF_USE_JS:=YES +NETSURF_USE_MOZJS:=YES +endif + +$(eval $(call pkg_config_find_and_add,BMP,libnsbmp,BMP)) +$(eval $(call pkg_config_find_and_add,GIF,libnsgif,GIF)) + +CFLAGS += -U__STRICT_ANSI__ -std=c99 -I. -Dsmall $(WARNFLAGS) -Dnsatari \ + -D_BSD_SOURCE \ + -D_XOPEN_SOURCE=600 \ + -D_POSIX_C_SOURCE=200112L \ + $(shell $(PKG_CONFIG) --cflags libhubbub libcss openssl ) \ + $(shell $(PKG_CONFIG) --cflags libxml-2.0 ) \ + $(shell $(PKG_CONFIG) --cflags libcurl ) + +LDFLAGS += -lcflib -lcurl +LDFLAGS += -lcss -lparserutils -ldom -lwapcaplet -lhubbub +LDFLAGS += -lssl -lcrypto +LDFLAGS += -lxml2 -lz -liconv -lcares -lHermes -lwindom -lgem -lm +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\ + 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 save.c settings.c +S_ATARI := $(addprefix atari/,$(S_ATARI)) + +# This is the final source build list +# Note this is deliberately *not* expanded here as common and image +# are not yet available +SOURCES = $(S_COMMON) $(S_IMAGE) $(S_BROWSER) $(S_ATARI) +EXETARGET := ns$(SUBTARGET)$(PRGSUFFIX) + +# ---------------------------------------------------------------------------- +# Install target +# ---------------------------------------------------------------------------- + +<<<<<<< Updated upstream +install-atari: + +# ---------------------------------------------------------------------------- +# Package target +# ---------------------------------------------------------------------------- + +package-atari: +======= +ATARI_INSTALL_TARGET_DIR := nsatari.package +ATARI_RES_DIR := atari/res + +install-atari: $(PKGNAME) + $(VQ)echo Creating $(PKGNAME) + +$(PKGNAME): $(EXETARGET) + $(Q)rm -rf $(ATARI_INSTALL_TARGET_DIR) + $(Q)mkdir $(ATARI_INSTALL_TARGET_DIR)/ + $(Q)mkdir $(ATARI_INSTALL_TARGET_DIR)/netsurf + $(Q)mkdir $(ATARI_INSTALL_TARGET_DIR)/netsurf/doc + $(Q)mkdir $(ATARI_INSTALL_TARGET_DIR)/netsurf/download + $(Q)mkdir $(ATARI_INSTALL_TARGET_DIR)/netsurf/res + $(Q)mkdir $(ATARI_INSTALL_TARGET_DIR)/netsurf/res/fonts + #$(Q)mkdir $(ATARI_INSTALL_TARGET_DIR)/netsurf/res/icons + $(Q)touch $(ATARI_INSTALL_TARGET_DIR)/netsurf/res/cookies + $(Q)cp $(ATARI_RES_DIR)/netsurf.rsc $(ATARI_INSTALL_TARGET_DIR)/netsurf/res/netsurf.rsc + $(Q)cp $(ATARI_RES_DIR)/icons/ $(ATARI_INSTALL_TARGET_DIR)/netsurf/res/icons/ -R + + + $(Q)cp $(EXETARGET) $(ATARI_INSTALL_TARGET_DIR)/netsurf + +>>>>>>> Stashed changes diff --git a/atari/browser.c b/atari/browser.c index 034f89a64..ec2a64df5 100755 --- a/atari/browser.c +++ b/atari/browser.c @@ -43,11 +43,9 @@ #include "css/css.h"
#include "utils/log.h"
#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"
#include "atari/redrawslots.h"
#include "atari/browser.h"
@@ -62,14 +60,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 +102,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 +113,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 +136,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 +206,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 +217,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;
@@ -278,9 +272,9 @@ static void __CDECL browser_evnt_mbutton( COMPONENT * c, long buff[8], void * da rel_cur_x, rel_cur_y);
}
}
- if( browser_redraw_required( gw ) ){
- browser_redraw( gw );
- }
+ //if( browser_redraw_required( gw ) ){
+ //browser_redraw( gw );
+ //}
graf_mkstate(&rel_cur_x, &rel_cur_y, &mbut, &dummy);
rel_cur_x = (rel_cur_x - cwork.g_x) + gw->browser->scroll.current.x;
rel_cur_y = (rel_cur_y - cwork.g_y) + gw->browser->scroll.current.y;
@@ -309,7 +303,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 +393,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;
@@ -483,14 +477,15 @@ static void browser_process_scroll( struct gui_window * gw, LGRECT bwrect ) }
b->scroll.requested.y = 0;
b->scroll.requested.x = 0;
- if( b->caret.requested.g_w > 0 ){
- b->caret.redraw = true;
- }
-
- gw->root->handle->xpos = b->scroll.current.x;
- gw->root->handle->ypos = b->scroll.current.y;
+// 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;
- mt_WindSlider( &app, gw->root->handle, HSLIDER|VSLIDER );
+ //mt_WindSlider( &app, gw->root->handle, HSLIDER|VSLIDER );
}
/*
@@ -502,7 +497,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;
@@ -561,35 +556,35 @@ bool browser_input( struct gui_window * gw, unsigned short nkc ) }
/* determines if a browser window needs redraw */
-bool browser_redraw_required( struct gui_window * gw)
-{
- bool ret = true;
- CMP_BROWSER b = gw->browser;
-
- if( b->bw->current_content == NULL )
- return ( false );
-
- /* disable redraws when the browser awaits WM_REDRAW caused by resize */
- if( b->reformat_pending )
- return( false );
-
- ret = ( ((b->redraw.areas_used > 0) )
- || b->scroll.required
- || b->caret.redraw);
- return( ret );
-}
+//bool browser_redraw_required( struct gui_window * gw)
+//{
+// bool ret = true;
+// CMP_BROWSER b = gw->browser;
+//
+// if( b->bw->current_content == NULL )
+// return ( false );
+//
+// /* disable redraws when the browser awaits WM_REDRAW caused by resize */
+// if( b->reformat_pending )
+// return( false );
+//
+// ret = ( ((b->redraw.areas_used > 0) )
+// || b->scroll.required
+// || b->caret.redraw);
+// return( ret );
+//}
/* schedule a redraw of content */
/* coords are relative to the framebuffer */
void browser_schedule_redraw_rect(struct gui_window * gw, short x, short y, short w, short h)
{
- if( x < 0 ){
+ if(x < 0){
w += x;
x = 0;
}
- if( y < 0 ) {
+ if(y < 0) {
h += y;
y = 0;
}
@@ -604,7 +599,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;
@@ -615,7 +610,7 @@ void browser_schedule_redraw(struct gui_window * gw, short x0, short y0, short x if( y0 > work.g_h )
return;
- redraw_slot_schedule( &b->redraw, x0, y0, x1, y1 );
+ redraw_slot_schedule(&b->redraw, x0, y0, x1, y1, false);
return;
}
@@ -644,295 +639,286 @@ 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)
-{
- CMP_BROWSER b = gw->browser;
- LGRECT rect;
- if( area == NULL ){
- browser_get_rect( gw, BR_CONTENT, &rect );
- area = ▭
- }
- /* This call restores the background and releases the memory: */
- // TODO: only release memory/clear flag when the caret is not clipped.
- // TODO: apply clipping.
- w_put_bkgr( &app,
- area->g_x-b->scroll.current.x+b->caret.current.g_x,
- area->g_y-b->scroll.current.y+b->caret.current.g_y,
- gw->browser->caret.current.g_w,
- gw->browser->caret.current.g_h+1,
- &gw->browser->caret.background
- );
- gw->browser->caret.background.fd_addr = NULL;
-}
+//void browser_restore_caret_background( struct gui_window * gw, GRECT * area)
+//{
+// CMP_BROWSER b = gw->browser;
+// GRECT rect;
+// if( area == NULL ){
+// browser_get_rect( gw, BR_CONTENT, &rect );
+// area = ▭
+// }
+// /* This call restores the background and releases the memory: */
+// // TODO: only release memory/clear flag when the caret is not clipped.
+// // TODO: apply clipping.
+// w_put_bkgr( &app,
+// area->g_x-b->scroll.current.x+b->caret.current.g_x,
+// area->g_y-b->scroll.current.y+b->caret.current.g_y,
+// gw->browser->caret.current.g_w,
+// gw->browser->caret.current.g_h+1,
+// &gw->browser->caret.background
+// );
+// gw->browser->caret.background.fd_addr = NULL;
+//}
/*
area: the browser canvas
*/
-void browser_redraw_caret( struct gui_window * gw, LGRECT * area )
-{ -
- if( gw->browser->caret.redraw && gw->browser->caret.requested.g_w > 0 ){ - - short wind_info[4]; - - /* 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]) { - return; - } - -
- LGRECT caret;
- struct s_browser * b = gw->browser;
- struct rect old_clip;
- struct rect clip;
-
- if( b->caret.current.g_w > 0 && b->caret.background.fd_addr != NULL ){
- browser_restore_caret_background( gw, area );
- }
-
- caret = b->caret.requested;
- 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 ) ) {
- return;
- }
-
- MFDB screen;
- short pxy[8];
-
- /* save background: */
- //assert( b->caret.background.fd_addr == NULL );
- init_mfdb(app.nplanes, caret.g_w, caret.g_h, 0,
- &b->caret.background);
- init_mfdb(0, caret.g_w, caret.g_h, 0, &screen);
- pxy[0] = caret.g_x;
- pxy[1] = caret.g_y;
- pxy[2] = caret.g_x + caret.g_w;
- pxy[3] = caret.g_y + caret.g_h;
- pxy[4] = 0;
- pxy[5] = 0;
- pxy[6] = caret.g_w;
- pxy[7] = caret.g_h;
- /* hide the mouse */
- v_hide_c (app.graf.handle);
- /* copy screen image */
- vro_cpyfm (app.graf.handle, S_ONLY, pxy, &screen, &b->caret.background);
- /* draw caret: */
- caret.g_x -= area->g_x;
- caret.g_y -= area->g_y;
- clip.x0 = caret.g_x;
- clip.y0 = caret.g_y;
- clip.x1 = caret.g_x + caret.g_w;
- clip.y1 = caret.g_y + caret.g_h;
- /* store old clip before adjusting it: */
- plot_get_clip( &old_clip );
- /* clip to cursor: */
- plot_clip( &clip );
- plot_line( caret.g_x, caret.g_y, caret.g_x, caret.g_y + caret.g_h,
- plot_style_caret );
- /* restore old clip area: */
- plot_clip( &old_clip );
- /* restore the mouse */
- v_show_c ( app.graf.handle, 1);
- b->caret.current.g_x = caret.g_x + gw->browser->scroll.current.x;
- b->caret.current.g_y = caret.g_y + gw->browser->scroll.current.y;
- b->caret.current.g_w = caret.g_w;
- b->caret.current.g_h = caret.g_h;
- }
-}
-
-void browser_redraw( struct gui_window * gw )
-{
- LGRECT bwrect;
- struct s_browser * b = gw->browser;
- short todo[4];
- struct rect clip;
- /* used for clipping of content redraw: */
- struct rect redraw_area;
-
- if( b->attached == false || b->bw->current_content == NULL ) {
- return;
- }
-
- browser_get_rect(gw, BR_CONTENT, &bwrect);
-
- plot_set_dimensions(bwrect.g_x, bwrect.g_y, bwrect.g_w, bwrect.g_h);
- clip.x0 = 0;
- clip.y0 = 0;
- clip.x1 = bwrect.g_w;
- clip.y1 = bwrect.g_h;
- plot_clip(&clip);
- if (plot_lock() == false)
- return;
-
- if( b->scroll.required == true && b->bw->current_content != NULL) {
- browser_process_scroll( gw, bwrect );
- b->scroll.required = false;
- }
-
- if ((b->redraw.areas_used > 0) && b->bw->current_content != NULL ) {
- if( (atari_plot_flags & PLOT_FLAG_OFFSCREEN) == 0 ) {
-
- int i;
- GRECT area;
- GRECT fbwork;
- short wf_top[4];
- todo[0] = bwrect.g_x;
- todo[1] = bwrect.g_y;
- todo[2] = todo[0] + bwrect.g_w-1;
- todo[3] = todo[1] + bwrect.g_h-1;
- vs_clip(atari_plot_vdi_handle, 1, (short*)&todo[0]);
-
- 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
- && wf_top[1] == _AESapid ){
- /* The window is on top, so there is no need to walk the */
- /* AES rectangle list. */
- for( i=0; i<b->redraw.areas_used; i++ ){
- fbwork.g_x = todo[0] - bwrect.g_x;
- fbwork.g_y = todo[1] - bwrect.g_y;
- if( fbwork.g_x < 0 ){
- fbwork.g_w = todo[2] + todo[0];
- fbwork.g_x = 0;
- } else {
- fbwork.g_w = todo[2];
- }
- if( fbwork.g_y < 0 ){
- fbwork.g_h = todo[3] + todo[1];
- fbwork.g_y = 0;
- } else {
- fbwork.g_h = todo[3];
- }
- area.g_x = b->redraw.areas[i].x0;
- area.g_y = b->redraw.areas[i].y0;
- area.g_w = b->redraw.areas[i].x1 - b->redraw.areas[i].x0;
- area.g_h = b->redraw.areas[i].y1 - b->redraw.areas[i].y0;
- if (rc_intersect((GRECT *)&fbwork,(GRECT *)&area)) {
- redraw_area.x0 = area.g_x;
- redraw_area.y0 = area.g_y;
- redraw_area.x1 = area.g_x + area.g_w;
- redraw_area.y1 = area.g_y + area.g_h;
- browser_redraw_content( gw, 0, 0, &redraw_area );
- } else {
- /* the area should be kept scheduled for later redraw,*/
- /* but because this is onscreen plotter, it doesn't */
- /* make much sense anyway... */
- }
- }
- } else {
- /* walk the AES rectangle list: */
- 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 framebuffer coords: */
- fbwork.g_x = todo[0] - bwrect.g_x;
- fbwork.g_y = todo[1] - bwrect.g_y;
- if( fbwork.g_x < 0 ){
- fbwork.g_w = todo[2] + todo[0];
- fbwork.g_x = 0;
- } else {
- fbwork.g_w = todo[2];
- }
- if( fbwork.g_y < 0 ){
- fbwork.g_h = todo[3] + todo[1];
- fbwork.g_y = 0;
- } else {
- fbwork.g_h = todo[3];
- }
- /* walk the redraw requests: */
- for( i=0; i<b->redraw.areas_used; i++ ){
- area.g_x = b->redraw.areas[i].x0;
- area.g_y = b->redraw.areas[i].y0;
- area.g_w = b->redraw.areas[i].x1 - b->redraw.areas[i].x0;
- area.g_h = b->redraw.areas[i].y1 - b->redraw.areas[i].y0;
- if (rc_intersect((GRECT *)&fbwork,(GRECT *)&area)) {
- redraw_area.x0 = area.g_x;
- redraw_area.y0 = area.g_y;
- redraw_area.x1 = area.g_x + area.g_w;
- redraw_area.y1 = area.g_y + area.g_h;
- browser_redraw_content( gw, 0, 0, &redraw_area );
- } else {
- /* the area should be kept scheduled for later redraw,*/
- /* but because this is onscreen plotter, it doesn't */
- /* make much sense anyway... */
- }
-
- }
- if (wind_get(gw->root->handle->handle, WF_NEXTXYWH,
- &todo[0], &todo[1], &todo[2], &todo[3])==0) {
- break;
- }
- }
- }
- }
- vs_clip(atari_plot_vdi_handle, 0, (short*)&todo);
- } else {
-
- /* its save to do a complete redraw without knowledge about GEM windows :) */
- /* walk the redraw requests: */
- int i;
- for( i=0; i<b->redraw.areas_used; i++ ){
- struct redraw_context ctx = {
- .interactive = true,
- .background_images = true,
- .plot = &atari_plotters
- };
- browser_window_redraw( b->bw, -b->scroll.current.x,
- -b->scroll.current.y, &b->redraw.areas[i], &ctx );
- }
- GRECT area;
- area.g_x = bwrect.g_x;
- area.g_y = bwrect.g_y;
- area.g_w = bwrect.g_w;
- area.g_h = bwrect.g_h;
- //plot_blit( plotter, &area );
- }
- b->redraw.areas_used = 0;
- }
- if( b->caret.redraw == true && b->bw->current_content != NULL ) {
- LGRECT area;
- todo[0] = bwrect.g_x;
- todo[1] = bwrect.g_y;
- todo[2] = todo[0] + bwrect.g_w;
- todo[3] = todo[1] + bwrect.g_h;
- area.g_x = bwrect.g_x;
- area.g_y = bwrect.g_y;
- area.g_w = bwrect.g_w;
- area.g_h = bwrect.g_h;
- vs_clip(atari_plot_vdi_handle, 1, (short*)&todo[0]);
- browser_redraw_caret( gw, &area );
- vs_clip(atari_plot_vdi_handle, 0, (short*)&todo[0]);
- b->caret.redraw = false;
- }
- plot_unlock();
- /* TODO: if we use offscreen bitmap, trigger content redraw here */
-}
-
-static void __CDECL browser_evnt_redraw( COMPONENT * c, long buff[8], void * data)
+//void browser_redraw_caret( struct gui_window * gw, GRECT * area )
+//{ +//
+// if( gw->browser->caret.redraw && gw->browser->caret.requested.g_w > 0 ){ +// +// short wind_info[4]; +// +// /* 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 (guiwin_get_handle(gw->root->win) != wind_info[0]) { +// return; +// } +// +//
+// GRECT caret;
+// struct s_browser * b = gw->browser;
+// struct rect old_clip;
+// struct rect clip;
+//
+// if( b->caret.current.g_w > 0 && b->caret.background.fd_addr != NULL ){
+// browser_restore_caret_background( gw, area );
+// }
+//
+// caret = b->caret.requested;
+// caret.g_x -= b->scroll.current.x - area->g_x;
+// caret.g_y -= b->scroll.current.y - area->g_y;
+//
+// if( !rc_intersect( area, &caret ) ) {
+// return;
+// }
+//
+// MFDB screen;
+// short pxy[8];
+//
+// /* save background: */
+// init_mfdb(app.nplanes, caret.g_w, caret.g_h, 0,
+// &b->caret.background);
+// init_mfdb(0, caret.g_w, caret.g_h, 0, &screen);
+// pxy[0] = caret.g_x;
+// pxy[1] = caret.g_y;
+// pxy[2] = caret.g_x + caret.g_w;
+// pxy[3] = caret.g_y + caret.g_h;
+// pxy[4] = 0;
+// pxy[5] = 0;
+// pxy[6] = caret.g_w;
+// pxy[7] = caret.g_h;
+// +// plot_lock();
+//
+// /* copy screen image behin the caret for later restore: */
+// vro_cpyfm (app.graf.handle, S_ONLY, pxy, &screen, &b->caret.background);
+// /* draw caret: */
+// caret.g_x -= area->g_x;
+// caret.g_y -= area->g_y;
+// clip.x0 = caret.g_x;
+// clip.y0 = caret.g_y;
+// clip.x1 = caret.g_x + caret.g_w;
+// clip.y1 = caret.g_y + caret.g_h;
+// /* store old clip before adjusting it: */
+// plot_get_clip( &old_clip );
+// /* clip to cursor: */
+// plot_clip( &clip );
+// plot_line( caret.g_x, caret.g_y, caret.g_x, caret.g_y + caret.g_h,
+// plot_style_caret );
+// /* restore old clip area: */
+// plot_clip( &old_clip );
+// /* restore the mouse */
+// plot_unlock();
+// b->caret.current.g_x = caret.g_x + gw->browser->scroll.current.x;
+// b->caret.current.g_y = caret.g_y + gw->browser->scroll.current.y;
+// b->caret.current.g_w = caret.g_w;
+// b->caret.current.g_h = caret.g_h;
+// }
+//}
+//
+//void browser_redraw( struct gui_window * gw )
+//{
+// GRECT bwrect;
+// struct s_browser * b = gw->browser;
+// short todo[4];
+// struct rect clip;
+// /* used for clipping of content redraw: */
+// struct rect redraw_area;
+//
+// if( b->attached == false || b->bw->current_content == NULL ) {
+// return;
+// }
+//
+// browser_get_rect(gw, BR_CONTENT, &bwrect);
+//
+// plot_set_dimensions(bwrect.g_x, bwrect.g_y, bwrect.g_w, bwrect.g_h);
+// clip.x0 = 0;
+// clip.y0 = 0;
+// clip.x1 = bwrect.g_w;
+// clip.y1 = bwrect.g_h;
+// plot_clip(&clip);
+// if (plot_lock() == false)
+// return;
+//
+// if( b->scroll.required == true && b->bw->current_content != NULL) {
+// browser_process_scroll( gw, bwrect );
+// b->scroll.required = false;
+// }
+//
+// if ((b->redraw.areas_used > 0) && b->bw->current_content != NULL ) {
+// if( (atari_plot_flags & PLOT_FLAG_OFFSCREEN) == 0 ) {
+//
+// int i;
+// GRECT area;
+// GRECT fbwork;
+// short wf_top[4];
+// todo[0] = bwrect.g_x;
+// todo[1] = bwrect.g_y;
+// todo[2] = todo[0] + bwrect.g_w-1;
+// todo[3] = todo[1] + bwrect.g_h-1;
+// vs_clip(atari_plot_vdi_handle, 1, (short*)&todo[0]);
+//
+// wind_get( 0, WF_TOP, &wf_top[0], &wf_top[1],
+// &wf_top[2], &wf_top[3] );
+//
+// 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. */
+// for( i=0; i<b->redraw.areas_used; i++ ){
+// fbwork.g_x = todo[0] - bwrect.g_x;
+// fbwork.g_y = todo[1] - bwrect.g_y;
+// if( fbwork.g_x < 0 ){
+// fbwork.g_w = todo[2] + todo[0];
+// fbwork.g_x = 0;
+// } else {
+// fbwork.g_w = todo[2];
+// }
+// if( fbwork.g_y < 0 ){
+// fbwork.g_h = todo[3] + todo[1];
+// fbwork.g_y = 0;
+// } else {
+// fbwork.g_h = todo[3];
+// }
+// area.g_x = b->redraw.areas[i].x0;
+// area.g_y = b->redraw.areas[i].y0;
+// area.g_w = b->redraw.areas[i].x1 - b->redraw.areas[i].x0;
+// area.g_h = b->redraw.areas[i].y1 - b->redraw.areas[i].y0;
+// if (rc_intersect((GRECT *)&fbwork,(GRECT *)&area)) {
+// redraw_area.x0 = area.g_x;
+// redraw_area.y0 = area.g_y;
+// redraw_area.x1 = area.g_x + area.g_w;
+// redraw_area.y1 = area.g_y + area.g_h;
+// browser_redraw_content( gw, 0, 0, &redraw_area );
+// } else {
+// /* the area should be kept scheduled for later redraw,*/
+// /* but because this is onscreen plotter, it doesn't */
+// /* make much sense anyway... */
+// }
+// }
+// } else {
+// /* 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: */
+// fbwork.g_x = todo[0] - bwrect.g_x;
+// fbwork.g_y = todo[1] - bwrect.g_y;
+// if( fbwork.g_x < 0 ){
+// fbwork.g_w = todo[2] + todo[0];
+// fbwork.g_x = 0;
+// } else {
+// fbwork.g_w = todo[2];
+// }
+// if( fbwork.g_y < 0 ){
+// fbwork.g_h = todo[3] + todo[1];
+// fbwork.g_y = 0;
+// } else {
+// fbwork.g_h = todo[3];
+// }
+// /* walk the redraw requests: */
+// for( i=0; i<b->redraw.areas_used; i++ ){
+// area.g_x = b->redraw.areas[i].x0;
+// area.g_y = b->redraw.areas[i].y0;
+// area.g_w = b->redraw.areas[i].x1 - b->redraw.areas[i].x0;
+// area.g_h = b->redraw.areas[i].y1 - b->redraw.areas[i].y0;
+// if (rc_intersect((GRECT *)&fbwork,(GRECT *)&area)) {
+// redraw_area.x0 = area.g_x;
+// redraw_area.y0 = area.g_y;
+// redraw_area.x1 = area.g_x + area.g_w;
+// redraw_area.y1 = area.g_y + area.g_h;
+// browser_redraw_content( gw, 0, 0, &redraw_area );
+// } else {
+// /* the area should be kept scheduled for later redraw,*/
+// /* but because this is onscreen plotter, it doesn't */
+// /* make much sense anyway... */
+// }
+// }
+// if (wind_get(aes_handle, WF_NEXTXYWH,
+// &todo[0], &todo[1], &todo[2], &todo[3])==0) {
+// break;
+// }
+// }
+// }
+// }
+// vs_clip(atari_plot_vdi_handle, 0, (short*)&todo);
+// } else {
+//
+// /* its save to do a complete redraw without knowledge about GEM windows :) */
+// /* walk the redraw requests: */
+// int i;
+// for( i=0; i<b->redraw.areas_used; i++ ){
+// struct redraw_context ctx = {
+// .interactive = true,
+// .background_images = true,
+// .plot = &atari_plotters
+// };
+// browser_window_redraw( b->bw, -b->scroll.current.x,
+// -b->scroll.current.y, &b->redraw.areas[i], &ctx );
+// }
+// GRECT area;
+// area.g_x = bwrect.g_x;
+// area.g_y = bwrect.g_y;
+// area.g_w = bwrect.g_w;
+// area.g_h = bwrect.g_h;
+// //plot_blit( plotter, &area );
+// }
+// b->redraw.areas_used = 0;
+// }
+// if( b->caret.redraw == true && b->bw->current_content != NULL ) {
+// GRECT area;
+// todo[0] = bwrect.g_x;
+// todo[1] = bwrect.g_y;
+// todo[2] = todo[0] + bwrect.g_w;
+// todo[3] = todo[1] + bwrect.g_h;
+// area.g_x = bwrect.g_x;
+// area.g_y = bwrect.g_y;
+// area.g_w = bwrect.g_w;
+// area.g_h = bwrect.g_h;
+// vs_clip(atari_plot_vdi_handle, 1, (short*)&todo[0]);
+// browser_redraw_caret( gw, &area );
+// vs_clip(atari_plot_vdi_handle, 0, (short*)&todo[0]);
+// b->caret.redraw = false;
+// }
+// plot_unlock();
+// /* TODO: if we use offscreen bitmap, trigger content redraw here */
+//}
+
+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 +939,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..a442380ef 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
};
@@ -58,10 +57,10 @@ struct s_scroll_info This struct holds information of the cursor within the browser
viewport.
*/
-struct s_caret
+struct s_caret_old
{
- 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/caret.c b/atari/caret.c new file mode 100644 index 000000000..42a35a452 --- /dev/null +++ b/atari/caret.c @@ -0,0 +1,129 @@ +#include <stdbool.h> + +#include "desktop/plot_style.h" +#include "atari/plot/plot.h" +#include "atari/caret.h" + +extern struct s_vdi_sysinfo vdi_sysinfo; + +static void caret_restore_background(struct s_caret *c, VdiHdl vh, GRECT *clip); + +void caret_show(struct s_caret *caret, VdiHdl vh, GRECT *dimensions, GRECT *clip) +{ + GRECT visible, old_dim; + MFDB screen; + short pxy[8]; + + struct rect old_clip; + + return; + + + + plot_get_clip(&old_clip); + plot_get_dimensions(&old_dim); + + + // store background: + visible = *dimensions; + visible.g_x += clip->g_x; + visible.g_y += clip->g_y; + + if(!rc_intersect(clip, &visible)){ + printf("no isect...\n"); + return; + } + + + // TODO: do not alloc / free on each move... + if (caret->background.fd_addr != NULL) { + //caret_restore_background(caret, vh, clip); + } + + plot_lock(); + plot_set_dimensions(clip->g_x, clip->g_y, clip->g_w, clip->g_h); + + caret->dimensions.g_x = dimensions->g_x; + caret->dimensions.g_y = dimensions->g_y; + caret->dimensions.g_w = visible.g_w; + caret->dimensions.g_h = visible.g_h; + + dbg_grect("clip", clip); + dbg_grect("visible", &visible); + // TODO: do not alloc / free on every redraw... + init_mfdb(vdi_sysinfo.scr_bpp, visible.g_w, visible.g_h, 0, + &caret->background); + init_mfdb(0, visible.g_w, visible.g_h, 0, &screen); + pxy[0] = visible.g_x;
+ pxy[1] = visible.g_y;
+ pxy[2] = visible.g_x + visible.g_w;
+ pxy[3] = visible.g_y + visible.g_h;
+ pxy[4] = 0;
+ pxy[5] = 0;
+ pxy[6] = visible.g_w;
+ pxy[7] = visible.g_h; + vro_cpyfm (vh, S_ONLY, pxy, &screen, &caret->background); + + plot_line(dimensions->g_x, dimensions->g_y, dimensions->g_x, + dimensions->g_y + dimensions->g_h, plot_style_caret); + + plot_set_dimensions(old_clip.x0, old_clip.y0, old_clip.x1, old_clip.y1); + plot_clip(&old_clip); + + plot_unlock(); + caret->visible = true; +} + +void caret_hide(struct s_caret *caret, VdiHdl vh, GRECT *clip) +{ + struct rect old_clip; + GRECT old_dim; + + plot_lock(); + plot_get_clip(&old_clip); + plot_get_dimensions(&old_dim); + plot_set_dimensions(clip->g_x, clip->g_y, clip->g_w, clip->g_h); + caret_restore_background(caret, vh, clip); + plot_set_dimensions(old_clip.x0, old_clip.y0, old_clip.x1, old_clip.y1); + plot_clip(&old_clip); + plot_unlock(); + caret->visible = false; +} + +static void caret_restore_background(struct s_caret *caret, VdiHdl vh, GRECT *clip) +{ + MFDB screen; + GRECT visible; + short pxy[8]; + + visible = caret->dimensions; + visible.g_x += clip->g_x; + visible.g_y += clip->g_y; + + dbg_grect("restore ", &visible); + + if(!rc_intersect(clip, &visible)){ + goto exit; + } + + // TODO: check isect + + // restore mfdb + + init_mfdb(0, caret->dimensions.g_w, caret->dimensions.g_h, 0, &screen); + pxy[0] = 0; + pxy[1] = 0;
+ pxy[2] = caret->dimensions.g_w; + pxy[3] = caret->dimensions.g_h;
+ pxy[4] = clip->g_x + caret->dimensions.g_x;
+ pxy[5] = clip->g_y + caret->dimensions.g_y;
+ pxy[6] = pxy[2];
+ pxy[7] = pxy[3]; + vro_cpyfm(vh, S_ONLY, pxy, &caret->background, &screen); + // exit: + // TODO: do not alloc / free on every redraw... + +exit: + free(caret->background.fd_addr); + caret->background.fd_addr = NULL; +} diff --git a/atari/caret.h b/atari/caret.h new file mode 100644 index 000000000..c9352dc8b --- /dev/null +++ b/atari/caret.h @@ -0,0 +1,17 @@ +#ifndef NS_ATARI_CARET_H +#define NS_ATARI_CARET_H + +#include <mt_gem.h> +#include <stdbool.h> + +struct s_caret { + GRECT dimensions; + MFDB background; + bool visible; +}; + +void caret_show(struct s_caret *c, VdiHdl vh, GRECT * dimensions, GRECT *clip); +void caret_hide(struct s_caret *c, VdiHdl vh, GRECT *clip); + +#endif // NS_ATARI_CARET_H + 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..c9189af22 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,14 +68,14 @@ 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;
h = bw->current_content;
ctxinfo.flags = 0;
- browser_get_rect( gw, BR_CONTENT, &bwrect );
+ guiwin_get_grect(gw->root->win, GUIWIN_AREA_CONTENT, &bwrect);
mx -= bwrect.g_x;
my -= bwrect.g_y;
if( (mx < 0 || mx > bwrect.g_w) || (my < 0 || my > bwrect.g_h) ){
@@ -109,7 +109,7 @@ static struct s_context_info * get_context_info( struct gui_window * gw, short m return( &ctxinfo );
}
-void context_popup( struct gui_window * gw, short x, short y )
+void context_popup(struct gui_window * gw, short x, short y)
{
#define POP_FIRST_ITEM POP_CTX_CUT_SEL
diff --git a/atari/deskmenu.c b/atari/deskmenu.c new file mode 100644 index 000000000..646a09c05 --- /dev/null +++ b/atari/deskmenu.c @@ -0,0 +1,659 @@ +#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/browser.h" +#include "atari/findfile.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 ) +{ + assert(h_gem_menu != NULL); + + 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]; + } + } + } +} + +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 && 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 ); + menu_icheck(h_gem_menu, 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)); + menu_icheck(h_gem_menu, 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)); + menu_icheck(h_gem_menu, 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; + menu_icheck(h_gem_menu, 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) +{ + menu_icheck(h_gem_menu, MAINMENU_M_DEBUG_RENDER, (html_redraw_debug) ? 1 : 0); + menu_icheck(h_gem_menu, MAINMENU_M_FG_IMAGES, + (nsoption_bool(foreground_images)) ? 1 : 0); + menu_icheck(h_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/download.c b/atari/download.c index e852a03b8..e35f31d9e 100755 --- a/atari/download.c +++ b/atari/download.c @@ -47,77 +47,167 @@ #include "atari/download.h"
#include "atari/osspec.h"
-extern struct gui_window * input_window;
-
-static void gui_download_window_destroy( struct gui_download_window * gdw );
+extern struct gui_window * input_window; +extern GRECT desk_area; + +static void gui_download_window_destroy( struct gui_download_window * gdw ); +static void on_abort_click(struct gui_download_window *dw); +static void on_cbrdy_click(struct gui_download_window *dw); +static void on_close(struct gui_download_window * dw); +static void on_redraw(struct gui_download_window *dw, GRECT *clip); + +static short on_aes_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8]) +{ + short retval = 0; + struct gui_download_window *data; + + GRECT clip; + + data = guiwin_get_user_data(win); + + if ((ev_out->emo_events & MU_MESAG) != 0) { + // handle message + //printf("download win msg: %d\n", msg[0]); + switch (msg[0]) { + + case WM_REDRAW: + clip.g_x = msg[4]; + clip.g_y = msg[5]; + clip.g_w = msg[6]; + clip.g_h = msg[7]; + on_redraw(data, &clip); + break; + + case WM_CLOSED: + // TODO: this needs to iterate through all gui windows and + // check if the rootwin is this window... + on_close(data); + break; + + case WM_TOOLBAR: + switch(msg[4]){ + + case DOWNLOAD_BT_ABORT: + on_abort_click(data); + break; + + case DOWNLOAD_CB_CLOSE_RDY: + on_cbrdy_click(data); + break; + + default: break; + } + break; + + default: + break; + } + } + if ((ev_out->emo_events & MU_KEYBD) != 0) { + + + } + if ((ev_out->emo_events & MU_BUTTON) != 0) { + + } + + return(retval); +}
+ +static void on_redraw(struct gui_download_window *dw, GRECT *clip) +{ + OBJECT *tree = dw->tree; + GRECT work, visible; + uint32_t p = 0; + + guiwin_get_grect(dw->guiwin, GUIWIN_AREA_TOOLBAR, &work); + tree->ob_x = work.g_x; + tree->ob_y = work.g_y; + + if(!rc_intersect(clip, &work)){ + return; + } + + /* + Update the AES Object to reflect current state of download: + */ + ((TEDINFO *)get_obspec(tree, DOWNLOAD_FILENAME))->te_ptext = &dw->lbl_file; + ((TEDINFO *)get_obspec(tree, DOWNLOAD_LBL_BYTES))->te_ptext = &dw->lbl_done; + ((TEDINFO *)get_obspec(tree, DOWNLOAD_LBL_PERCENT))->te_ptext = &dw->lbl_percent; + ((TEDINFO *)get_obspec(tree, DOWNLOAD_LBL_SPEED))->te_ptext = &dw->lbl_speed; + + if (dw->size_total > 0 ) {
+ p = ((double)dw->size_downloaded / (double)dw->size_total * 100);
+ } + tree[DOWNLOAD_PROGRESS_DONE].ob_width = MAX( MIN( p*(DOWNLOAD_BAR_MAX/100), + DOWNLOAD_BAR_MAX ), 1); + if (dw->close_on_finish) { + tree[DOWNLOAD_CB_CLOSE_RDY].ob_state |= (SELECTED | CROSSED); + } else { + tree[DOWNLOAD_CB_CLOSE_RDY].ob_state &= ~(SELECTED | CROSSED); + } + tree[DOWNLOAD_BT_ABORT].ob_state &= ~SELECTED; + + /*Walk the AES rectangle list and redraw the visible areas of the window: */ + wind_get_grect(dw->aes_handle, WF_FIRSTXYWH, &visible); + while (visible.g_x && visible.g_y) { + if (rc_intersect(&work, &visible)) { + objc_draw_grect(tree, 0, 8, &visible); + } + wind_get_grect(dw->aes_handle, WF_NEXTXYWH, &visible); + } +} -static void __CDECL evnt_bt_abort_click
-(
- WINDOW *win,
- int index,
- int unused,
- void * data
-)
+static void on_abort_click(struct gui_download_window *dw)
{
- struct gui_download_window * dw = (struct gui_download_window *)data;
- assert( dw != NULL );
- ObjcChange( OC_FORM, win, index, ~SELECTED, TRUE); if( dw->status == NSATARI_DOWNLOAD_COMPLETE || dw->status == NSATARI_DOWNLOAD_ERROR ) { - ApplWrite( _AESapid, WM_CLOSED, win->handle, 0,0,0,0); + guiwin_send_msg(dw->guiwin, WM_CLOSED, 0,0,0,0); }
else if( dw->status != NSATARI_DOWNLOAD_CANCELED ){
dw->abort = true;
}
}
-static void __CDECL evnt_cbrdy_click
-(
- WINDOW *win,
- int index,
- int unused,
- void * data
-)
-{
- struct gui_download_window * dw = (struct gui_download_window *)data;
- assert( dw != NULL ); - if( dw->status == NSATARI_DOWNLOAD_COMPLETE ){ - ApplWrite( _AESapid, WM_CLOSED, win->handle, 0,0,0,0); - }
+static void on_cbrdy_click(struct gui_download_window *dw)
+{ + dw->close_on_finish = !dw->close_on_finish;
+ if (dw->close_on_finish && dw->status == NSATARI_DOWNLOAD_COMPLETE) { + guiwin_send_msg(dw->guiwin, WM_CLOSED, 0,0,0,0); + } + guiwin_send_redraw(dw->guiwin, NULL); + evnt_timer(250);
}
-static void __CDECL evnt_close( WINDOW *win, short buff[8], void * data)
+static void on_close(struct gui_download_window * dw)
{
- struct gui_download_window * dw = (struct gui_download_window *)data;
- assert( dw != NULL );
- gui_download_window_destroy( dw );
- ApplWrite( _AESapid, WM_DESTROY, win->handle, 0,0,0,0);
+ gui_download_window_destroy(dw);
}
-static void gui_download_window_destroy( struct gui_download_window * gdw )
+static void gui_download_window_destroy( struct gui_download_window * gdw)
{
-
- if( gdw->status == NSATARI_DOWNLOAD_WORKING ){
- download_context_abort( gdw->ctx );
- }
- download_context_destroy( gdw->ctx );
- if( gdw->form != NULL ){
- /* first destroy the form, so that it won't acces the gdw members */
- ApplWrite( _AESapid, WM_DESTROY, gdw->form->handle, 0,0,0,0);
- EvntWindom( MU_MESAG );
+ + + LOG((""));
+ if (gdw->status == NSATARI_DOWNLOAD_WORKING) {
+ download_context_abort(gdw->ctx);
}
- if( gdw->destination ) {
+ + download_context_destroy(gdw->ctx);
+ + if (gdw->destination) {
free( gdw->destination );
}
- if( gdw->fd != NULL ){
+ if (gdw->fd != NULL) {
fclose(gdw->fd);
gdw->fd = NULL;
}
- if( gdw->fbuf != NULL ){
+ if (gdw->fbuf != NULL) {
free( gdw->fbuf );
- }
-
- free( gdw );
+ } + wind_close(gdw->aes_handle);
+ guiwin_remove(gdw->guiwin);
+ free(gdw);
} static char * select_filepath( const char * path, const char * filename ) @@ -141,11 +231,10 @@ static char * select_filepath( const char * path, const char * filename ) } return( ret ); }
-
-struct gui_download_window *gui_download_window_create(download_context *ctx,
- struct gui_window *parent)
-{
-
+ +struct gui_download_window * gui_download_window_create(download_context *ctx,
+ struct gui_window *parent) +{ char *filename;
char *destination;
char gdos_path[PATH_MAX];
@@ -154,12 +243,17 @@ struct gui_download_window *gui_download_window_create(download_context *ctx, int dlgres = 0; OBJECT * tree = get_tree(DOWNLOAD); + + LOG(("Creating download window for gui window: %p", parent)); + /* TODO: Implement real form and use messages file strings! */
- if( tree == NULL )
- return( NULL );
- - filename = download_context_get_filename( ctx ); + if (tree == NULL){ + die("Couldn't find AES Object tree for download window!"); + return(NULL); + } +
+ filename = download_context_get_filename(ctx); dlgres = form_alert(2, "[2][Accept download?][Yes|Save as...|No]");
if( dlgres == 3){
return( NULL );
@@ -178,8 +272,9 @@ struct gui_download_window *gui_download_window_create(download_context *ctx, snprintf( destination, dstsize, "%s/%s", gdos_path, filename ); } - gdw = calloc( 1, sizeof(struct gui_download_window) );
+ gdw = calloc(1, sizeof(struct gui_download_window));
if( gdw == NULL ){ + warn_user(NULL, "Out of memory!"); free( destination );
return( NULL ); } @@ -193,12 +288,16 @@ struct gui_download_window *gui_download_window_create(download_context *ctx, gdw->fbufsize = MAX(BUFSIZ, 48000);
gdw->size_downloaded = 0;
gdw->size_total = download_context_get_total_length(ctx); - gdw->destination = destination;
+ gdw->destination = destination; + gdw->tree = tree;
url = download_context_get_url(ctx);
- gdw->fd = fopen(gdw->destination, "wb" );
- if( gdw->fd == NULL ){
- free( filename );
+ gdw->fd = fopen(gdw->destination, "wb");
+ if( gdw->fd == NULL ){ + char spare[200]; + snprintf(spare, 200, "Couldn't open %s for writing!", gdw->destination); + msg_box_show(MSG_BOX_ALERT, spare);
+ free(filename);
gui_download_window_destroy(gdw);
return( NULL );
} @@ -206,70 +305,81 @@ struct gui_download_window *gui_download_window_create(download_context *ctx, gdw->fbuf = malloc( gdw->fbufsize+1 );
if( gdw->fbuf != NULL ){
setvbuf( gdw->fd, gdw->fbuf, _IOFBF, gdw->fbufsize );
- }
- gdw->form = mt_FormCreate( &app, tree, WAT_FORM,
- NULL, (char*)"Download",
- NULL, true, true );
- if( gdw->form == NULL || gdw->fd == NULL ){
+ } + + gdw->aes_handle = wind_create_grect(CLOSER | NAME | MOVER, &desk_area); + wind_set_str(gdw->aes_handle, WF_NAME, "Download"); + unsigned long gwflags = GW_FLAG_DEFAULTS; + gwflags &= ~GW_FLAG_TOOLBAR_REDRAW; + gdw->guiwin = guiwin_add(gdw->aes_handle, gwflags, on_aes_event); + if( gdw->guiwin == NULL || gdw->fd == NULL ){ + die("could not create guiwin");
free( filename );
gui_download_window_destroy(gdw);
return( NULL );
- }
+ } + guiwin_set_user_data(gdw->guiwin, gdw); + guiwin_set_toolbar(gdw->guiwin, tree, 0, 0);
- tree = ObjcTree(OC_FORM, gdw->form );
- ObjcAttachFormFunc( gdw->form, DOWNLOAD_BT_ABORT,
- evnt_bt_abort_click, gdw
- );
- ObjcAttachFormFunc( gdw->form, DOWNLOAD_CB_CLOSE_RDY,
- evnt_cbrdy_click, gdw
- );
- EvntDataAdd( gdw->form, WM_CLOSED, evnt_close, gdw, EV_TOP);
strncpy((char*)&gdw->lbl_file, filename, MAX_SLEN_LBL_FILE-1);
- ObjcString( tree, DOWNLOAD_FILENAME, (char*)&gdw->lbl_file );
- ObjcString( tree, DOWNLOAD_LBL_BYTES, (char*)&gdw->lbl_done );
- ObjcString( tree, DOWNLOAD_LBL_PERCENT, (char*)&gdw->lbl_percent );
- ObjcString( tree, DOWNLOAD_LBL_SPEED, (char*)&gdw->lbl_speed );
-
free( filename );
LOG(("created download: %s (total size: %d)",
gdw->destination, gdw->size_total
- ));
+ )); + + GRECT work, curr; + work.g_x = 0; + work.g_y = 0; + work.g_w = tree->ob_width; + work.g_h = tree->ob_height; + + wind_calc_grect(WC_BORDER, CLOSER | MOVER | NAME, &work, &curr); + + curr.g_x = (desk_area.g_w / 2) - (curr.g_w / 2); + curr.g_y = (desk_area.g_h / 2) - (curr.g_h / 2); + + wind_open_grect(gdw->aes_handle, &curr); + gdw->lastrdw = clock() / (CLOCKS_PER_SEC >> 3); + + return(gdw); +} - return gdw;
-}
nserror gui_download_window_data(struct gui_download_window *dw,
const char *data, unsigned int size)
{
+ + uint32_t clck = clock();
+ uint32_t tnow = clck / (CLOCKS_PER_SEC>>3);
+ uint32_t sdiff = (clck / (CLOCKS_PER_SEC)) - dw->start; uint32_t p = 0;
- uint32_t tnow = clock() / CLOCKS_PER_SEC;
- uint32_t sdiff = tnow - dw->start;
float speed;
- float pf = 0;
- OBJECT * tree;
-
- if( dw->abort == true ){
+ float pf = 0; + + LOG(("")); + + OBJECT * tree = dw->tree; + + if(dw->abort == true){ dw->status = NSATARI_DOWNLOAD_CANCELED;
dw->abort = false;
- download_context_abort( dw->ctx );
- ObjcChange( OC_FORM, dw->form, DOWNLOAD_BT_ABORT, DISABLED, TRUE);
- return( NSERROR_OK );
+ download_context_abort(dw->ctx); + guiwin_send_redraw(dw->guiwin, NULL);
+ return(NSERROR_OK);
}
/* save data */
fwrite( data , size, sizeof(unsigned char),dw->fd );
- dw->size_downloaded += size;
-
- /* Update the progress bar... */
- if( tnow - dw->lastrdw > 1 ) {
+ dw->size_downloaded += size; + + /* Update GUI */
+ if ((tnow - dw->lastrdw) > 1) { + dw->lastrdw = tnow;
- tree = ObjcTree(OC_FORM, dw->form );
- if( dw->size_total > 0 ){
- p = ((double)dw->size_downloaded / (double)dw->size_total * 100);
- }
speed = dw->size_downloaded / sdiff;
- tree[DOWNLOAD_PROGRESS_DONE].ob_width = MAX( MIN( p*(DOWNLOAD_BAR_MAX/100), DOWNLOAD_BAR_MAX ), 1);
- if( dw->size_total > 0 ){
+
+ if( dw->size_total > 0 ){ + p = ((double)dw->size_downloaded / (double)dw->size_total * 100);
snprintf( (char*)&dw->lbl_percent, MAX_SLEN_LBL_PERCENT,
"%lu%s", p, "%"
);
@@ -284,11 +394,9 @@ nserror gui_download_window_data(struct gui_download_window *dw, snprintf( (char*)&dw->lbl_done, MAX_SLEN_LBL_DONE, "%s / %s",
human_friendly_bytesize(dw->size_downloaded),
(dw->size_total>0) ? human_friendly_bytesize(dw->size_total) : "?"
- );
- ObjcString( tree, DOWNLOAD_LBL_BYTES, (char*)&dw->lbl_done );
- ObjcString( tree, DOWNLOAD_LBL_PERCENT, (char*)&dw->lbl_percent );
- ObjcString( tree, DOWNLOAD_LBL_SPEED, (char*)&dw->lbl_speed );
- snd_rdw( dw->form );
+ ); + + guiwin_send_redraw(dw->guiwin, NULL);
}
return NSERROR_OK;
}
@@ -299,15 +407,17 @@ void gui_download_window_error(struct gui_download_window *dw, LOG(("%s", error_msg));
strncpy((char*)&dw->lbl_file, error_msg, MAX_SLEN_LBL_FILE-1);
dw->status = NSATARI_DOWNLOAD_ERROR;
- snd_rdw( dw->form ); - gui_window_set_status(input_window, messages_get("Done") );
+ guiwin_send_redraw(dw->guiwin, NULL); + gui_window_set_status(input_window, messages_get("Done") ); + // TODO: change abort to close
}
void gui_download_window_done(struct gui_download_window *dw)
{ OBJECT * tree;
LOG(("")); -
+ +// TODO: change abort to close
dw->status = NSATARI_DOWNLOAD_COMPLETE; if( dw->fd != NULL ) {
@@ -315,24 +425,18 @@ void gui_download_window_done(struct gui_download_window *dw) dw->fd = NULL;
}
- - tree = ObjcTree(OC_FORM, dw->form ); -
- if( (tree[DOWNLOAD_CB_CLOSE_RDY].ob_state & SELECTED) != 0 ) {
- ApplWrite( _AESapid, WM_CLOSED, dw->form->handle, 0,0,0,0);
- } else {
- tree[DOWNLOAD_PROGRESS_DONE].ob_width = DOWNLOAD_BAR_MAX;
+ tree = dw->tree; + if (dw->close_on_finish) { + guiwin_send_msg(dw->guiwin, WM_CLOSED, 0, 0, 0, 0);
+ } else { snprintf( (char*)&dw->lbl_percent, MAX_SLEN_LBL_PERCENT,
"%lu%s", 100, "%"
);
snprintf( (char*)&dw->lbl_done, MAX_SLEN_LBL_DONE, "%s / %s",
human_friendly_bytesize(dw->size_downloaded),
(dw->size_total>0) ? human_friendly_bytesize(dw->size_total) : human_friendly_bytesize(dw->size_downloaded)
- ); - ObjcString( tree, DOWNLOAD_LBL_BYTES, (char*)&dw->lbl_done );
- ObjcString( tree, DOWNLOAD_LBL_PERCENT, (char*)&dw->lbl_percent ); - ObjcString( tree, DOWNLOAD_BT_ABORT, (char*)"Close" );
- snd_rdw( dw->form ); + );
+ guiwin_send_redraw(dw->guiwin, NULL); } gui_window_set_status(input_window, messages_get("Done") );
}
diff --git a/atari/download.h b/atari/download.h index ee5783e71..e25893d4a 100755 --- a/atari/download.h +++ b/atari/download.h @@ -38,7 +38,9 @@ typedef enum { struct gui_download_window {
struct download_context *ctx;
struct gui_window * parent;
- WINDOW * form;
+ GUIWIN *guiwin; + short aes_handle; + OBJECT *tree;
nsatari_download_status status;
char *destination;
FILE * fd;
@@ -52,7 +54,8 @@ struct gui_download_window { uint32_t size_downloaded;
char * fbuf;
size_t fbufsize;
- bool abort;
+ bool abort; + bool close_on_finish;
};
#endif
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/extract.php b/atari/extract.php new file mode 100755 index 000000000..865b70ed7 --- /dev/null +++ b/atari/extract.php @@ -0,0 +1,10 @@ +#!/usr/bin/php +<? +$lines = file("deskmenu.c"); + +foreach($lines as $line){ + if(stripos($line, "static void __CDECL menu_") === 0){ + echo $line; + } +} +?> 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..1225a0ccd --- /dev/null +++ b/atari/gemtk/gemtk.h @@ -0,0 +1,148 @@ +#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_scroll(GUIWIN *gw, short orientation, int units, bool refresh); +void guiwin_send_msg(GUIWIN *win, short msgtype, short a, short b, short c, + short d); +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..e587b97d1 --- /dev/null +++ b/atari/gemtk/guiwin.c @@ -0,0 +1,804 @@ +//#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 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; + } + guiwin_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; + } + guiwin_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 */ + guiwin_scroll(gw, GUIWIN_VSLIDER, -(g.g_h/slid->y_unit_px), + true); + break; + + case WA_UPLINE: + /* scroll line up */ + guiwin_scroll(gw, GUIWIN_VSLIDER, -1, true); + break; + + case WA_DNPAGE: + /* scroll page down */ + guiwin_scroll(gw, GUIWIN_VSLIDER, g.g_h/slid->y_unit_px, + true); + break; + + case WA_DNLINE: + /* scroll line down */ + guiwin_scroll(gw, GUIWIN_VSLIDER, +1, true); + break; + + case WA_LFPAGE: + /* scroll page left */ + guiwin_scroll(gw, GUIWIN_HSLIDER, -(g.g_w/slid->x_unit_px), + true); + break; + + case WA_LFLINE: + /* scroll line left */ + guiwin_scroll(gw, GUIWIN_HSLIDER, -1, + true); + break; + + case WA_RTPAGE: + /* scroll page right */ + guiwin_scroll(gw, GUIWIN_HSLIDER, (g.g_w/slid->x_unit_px), + true); + break; + + case WA_RTLINE: + /* scroll line right */ + guiwin_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 h_aes; + h_aes = wind_find(ev_out->emo_mouse.p_x, ev_out->emo_mouse.p_y); + if(h_aes > 0 && (ev_out->emo_events != MU_TIMER)) { + + dest = guiwin_find(h_aes); + + 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); + DEBUG_PRINT(("Toolbar index: %d\n", obj_idx)); + short msg_out[8] = {WM_TOOLBAR, gl_apid, 0, dest->handle, + obj_idx, ev_out->emo_mclicks, ev_out->emo_kmeta, 0 + }; + if (obj_idx > 0) { + if ((dest->toolbar[obj_idx].ob_flags & OF_SELECTABLE)!=0 + && ((dest->flags & GW_FLAG_CUSTOM_TOOLBAR) == 0) + && ((dest->flags & GW_FLAG_TOOLBAR_REDRAW) == 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; + } + + DEBUG_PRINT(("Added guiwin: %p, tb: %p\n", win, win->toolbar)); + 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) +{ + + assert(win != NULL); + + 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; + } + } +} + +void guiwin_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(newpos < 0){ + newpos = slid->y_pos = 0; + } + 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(newpos < 0){ + newpos = slid->x_pos = 0; + } + + 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); + } +} + +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_msg(GUIWIN *win, short msg_type, short a, short b, short c, + short d) +{ + short msg[8]; + + msg[0] = msg_type; + msg[1] = gl_apid; + msg[2] = 0; + msg[3] = win->handle; + msg[4] = a; + msg[5] = b; + msg[6] = c; + msg[7] = d; + + appl_write(gl_apid, 16, &msg); +} + +void guiwin_send_redraw(GUIWIN *win, GRECT *area) +{ + short msg[8]; + GRECT work; + + EVMULT_IN 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 event_out; + + if (area == NULL) { + guiwin_get_grect(win, GUIWIN_AREA_WORK, &work); + if (work.g_w < 1 || work.g_h < 1) { + if (win->toolbar != NULL) { + guiwin_get_grect(win, GUIWIN_AREA_TOOLBAR, &work); + if (work.g_w < 1 || work.g_h < 1) { + return; + } + } + } + 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; + + event_out.emo_events = MU_MESAG; + win->handler_func(win, &event_out, msg); + + //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/redrawslots.c b/atari/gemtk/redrawslots.c new file mode 100644 index 000000000..ee5627daf --- /dev/null +++ b/atari/gemtk/redrawslots.c @@ -0,0 +1,123 @@ +/*
+ * Copyright 2011 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> +#define WITH_RECT +#include "gemtk.h" +#undef WITH_RECT + +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 )
+{
+ if (box2->x1 < box1->x0)
+ return false;
+
+ if (box2->y1 < box1->y0)
+ return false;
+
+ if (box2->x0 > box1->x1)
+ return false;
+
+ if (box2->y0 > box1->y1)
+ return false;
+
+ return true;
+} + + +void redraw_slot_schedule_grect(struct s_redrw_slots * slots, GRECT *area, + bool force) +{ + redraw_slot_schedule(slots, area->g_x, area->g_y, + area->g_x + area->g_w, area->g_y + area->g_h, force); +} + +/*
+ schedule redraw coords.
+*/
+void redraw_slot_schedule(struct s_redrw_slots * slots, short x0, short y0, + short x1, short y1, bool force)
+{
+ int i = 0;
+ struct rect area;
+
+ area.x0 = x0;
+ area.y0 = y0;
+ area.x1 = x1;
+ area.y1 = y1;
+ + if (force == false) {
+ for (i=0; i<slots->areas_used; i++) {
+ if (slots->areas[i].x0 <= x0
+ && slots->areas[i].x1 >= x1
+ && slots->areas[i].y0 <= y0
+ && slots->areas[i].y1 >= y1) {
+ /* the area is already queued for redraw */
+ return;
+ } else {
+ if (rect_intersect(&slots->areas[i], &area )) {
+ slots->areas[i].x0 = MIN(slots->areas[i].x0, x0);
+ slots->areas[i].y0 = MIN(slots->areas[i].y0, y0);
+ slots->areas[i].x1 = MAX(slots->areas[i].x1, x1);
+ slots->areas[i].y1 = MAX(slots->areas[i].y1, y1);
+ return;
+ }
+ }
+ } + }
+
+ if (slots->areas_used < slots->size) {
+ slots->areas[slots->areas_used].x0 = x0;
+ slots->areas[slots->areas_used].x1 = x1;
+ slots->areas[slots->areas_used].y0 = y0;
+ slots->areas[slots->areas_used].y1 = y1;
+ slots->areas_used++;
+ } else {
+ /*
+ we are out of available slots, merge box with last slot
+ this is dumb... but also a very rare case.
+ */
+ slots->areas[slots->size-1].x0 = MIN(slots->areas[i].x0, x0);
+ slots->areas[slots->size-1].y0 = MIN(slots->areas[i].y0, y0);
+ 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: + 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/gemtk/redrawslots.h b/atari/gemtk/redrawslots.h new file mode 100644 index 000000000..d045b3965 --- /dev/null +++ b/atari/gemtk/redrawslots.h @@ -0,0 +1,28 @@ +/*
+ * Copyright 2012 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 ATARI_REDRAW_SLOTS_H +#define ATARI_REDRAW_SLOTS_H + +#include <mt_gem.h> +#include "utils/types.h" + + + +#endif 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 deleted file mode 100755 index 3b15af877..000000000 --- a/atari/global_evnt.c +++ /dev/null @@ -1,677 +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 <limits.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
-#include <stdbool.h>
-#include <assert.h>
-#include <windom.h>
-
-#include "desktop/gui.h"
-#include "desktop/netsurf.h"
-#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/gui.h"
-#include "atari/browser_win.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 "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] )
-{
- int i = 0;
- LOG((""));
- netsurf_quit = true;
-} - -
-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; - int nx, ny; -
- if( gw == NULL)
- return; - - 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 ){ - - // 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 ){
- within = true; - browser_window_mouse_track(
- input_window->browser->bw,
- 0,
- evnt.mx - bwbox.g_x + gw->browser->scroll.current.x,
- evnt.my - bwbox.g_y + gw->browser->scroll.current.y
- );
- } - - 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 )) {
- gem_set_cursor( &gem_cursors.ibeam );
- prev_url = true;
- } else { - if( prev_url ) {
- gem_set_cursor( &gem_cursors.arrow );
- prev_url = false;
- } - }
- } - } else { - gem_set_cursor( &gem_cursors.arrow ); - prev_url = false; - } - - prev_x = evnt.mx; - prev_y = evnt.my;
-}
-
-void __CDECL global_evnt_keybd( WINDOW * win, short buff[8], void * data)
-{
- char sascii;
- long kstate = 0;
- long kcode = 0;
- unsigned short nkc = 0;
- unsigned short nks = 0;
-
- int i=0;
- bool done = false;
- struct gui_window * gw = input_window;
- struct gui_window * gw_tmp;
- if( gw == NULL )
- return;
- kstate = evnt.mkstate;
- kcode = evnt.keybd;
- 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 ) ) {
- /* make sure we report for the root window and report...: */ - done = tb_url_input( gw, 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 );
- 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]; - } - } - } -}
-
-
-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, 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 deleted file mode 100755 index 1e13264a2..000000000 --- a/atari/global_evnt.h +++ /dev/null @@ -1,62 +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/>.
- */
-
-#ifndef NS_ATARI_GLOBAL_EVNT_H
-#define NS_ATARI_GLOBAL_EVNT_H
-
-struct s_keybd_evnt_data
-{
- char ascii;
-} keybd_evnt_data;
-
-struct s_evnt_data
-{
- bool ignore;
- union {
- struct s_keybd_evnt_data keybd;
- } 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;
-};
-
-/*
- Global & Menu 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..51865b987 100755 --- a/atari/gui.c +++ b/atari/gui.c @@ -1,1041 +1,1150 @@ -/*
- * 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/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; +GRECT desk_area; + + +/* 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 | MU_M1, + .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) +{ + + 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; + + if(aes_event_in.emi_tlow < 0){ + aes_event_in.emi_tlow = 10000; + printf("long poll!\n"); + } + + struct gui_window * g; + + if( !active ) { + if(input_window && input_window->root->redraw_slots.areas_used > 0){ + window_process_redraws(input_window->root); + } + /* 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: + bool skip = false; +/* + if (active || rendering){ + if ((clock() < next_poll)){ + skip = true; + } else { + next_poll = clock() + (CLOCKS_PER_SEC>>5); + } + } +*/ + //if (skip == false) { + do { + short mx, my, dummy; + + graf_mkstate(&mx, &my, &dummy, &dummy); + aes_event_in.emi_m1.g_x = mx; + aes_event_in.emi_m1.g_y = my; + 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) { + uint16_t 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 && input_window->root->redraw_slots.areas_used > 0){ + window_process_redraws(input_window->root); + } + //} else { + //printf("skip poll %d (%d)\n", next_poll, clock()); + //} + +} + + +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 */ + gui_set_input_gui_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__ )); + + if (input_window == w) { + gui_set_input_gui_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) { + gui_set_input_gui_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; + guiwin_get_grect(gw->root->win, GUIWIN_AREA_CONTENT, &rect); + window_schedule_redraw_grect(gw->root, &rect); +} + +void gui_window_update_box(struct gui_window *gw, const struct rect *rect) +{ + GRECT area; + struct guiwin_scroll_info_s *slid; + + if (gw == NULL) + return; + + slid = guiwin_get_scroll_info(gw->root->win); + + guiwin_get_grect(gw->root->win, GUIWIN_AREA_CONTENT, &area); + area.g_x += rect->x0 - (slid->x_pos * slid->x_unit_px); + area.g_y += rect->y0 - (slid->y_pos * slid->y_unit_px); + area.g_w = rect->x1 - rect->x0; + area.g_h = rect->y1 - rect->y0; + //dbg_grect("update box", &area); + window_schedule_redraw_grect(gw->root, &area); +} + +bool gui_window_get_scroll(struct gui_window *w, int *sx, int *sy) +{ + int x,y; + if (w == NULL) + return false; + + window_get_scroll(w->root, sx, sy); + + return( true ); +} + +void gui_window_set_scroll(struct gui_window *w, int sx, int sy) +{ + int units = 0; + if ((w == NULL) + || (w->browser->bw == NULL) + || (w->browser->bw->current_content == NULL)) + return; + + //printf("scroll %d, %d\n", sx, sy); + window_scroll_by(w->root, sx, sy); + 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)); + printf("scroll visible\n"); + 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 ) { + // TODO: store content size! + if(window_get_active_gui_window(gw->root) == gw){ + window_set_content_size( gw->root, + content_get_width(gw->browser->bw->current_content), + content_get_height(gw->browser->bw->current_content) + ); + window_update_back_forward(gw->root); + GRECT area; + guiwin_get_grect(gw->root->win, GUIWIN_AREA_CONTENT, &area); + window_schedule_redraw_grect(gw->root, &area); + } + } +} + + +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; + + if (gw->root->toolbar->throbber.running == false) + return; + + toolbar_throbber_progress(gw->root->toolbar); + schedule(100, throbber_advance, gw ); +} + +void gui_window_start_throbber(struct gui_window *w) +{ + GRECT work; + if (w == NULL) + return; + + toolbar_set_throbber_state(w->root->toolbar, true); + schedule(100, throbber_advance, w ); + rendering = true; +} + +void gui_window_stop_throbber(struct gui_window *w) +{ + if (w == NULL) + return; + if (w->root->toolbar->throbber.running == false) + return; + + schedule_remove(throbber_advance, w); + + toolbar_set_throbber_state(w->root->toolbar, false); + + rendering = false; +} + +/* Place caret in window */ +void gui_window_place_caret(struct gui_window *w, int x, int y, int height) +{ + + GRECT clip, dim; + struct guiwin_scroll_info_s * slid; + if (w == NULL) + return; + + slid = guiwin_get_scroll_info(w->root->win); + window_get_grect(w->root, BROWSER_AREA_CONTENT, &clip); + dim.g_x = x - (slid->x_pos * slid->x_unit_px); + dim.g_y = y - (slid->y_pos * slid->y_unit_px); + dim.g_h = height; + dim.g_w = 2; + caret_show(&w->caret, guiwin_get_vdi_handle(w->root->win), &dim, &clip); +// 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) +{ + struct guiwin_scroll_info_s *slid = guiwin_get_scroll_info(w->root->win); + slid->x_pos = 0; + slid->y_pos = 0; + guiwin_update_slider(w->root->win, GUIWIN_VH_SLIDER); + 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_set_input_gui_window(struct gui_window *gw) +{ + LOG(("Setting input window from: %p to %p\n", input_window, gw)); + input_window = gw; +} + +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)); + + 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)); + + wind_get_grect(0, WF_WORKXYWH, &desk_area); + aes_event_in.emi_m1leave = MO_LEAVE; + aes_event_in.emi_m1.g_w = 1; + aes_event_in.emi_m1.g_h = 1; + next_poll = clock() + (CLOCKS_PER_SEC>>3); + +} + +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(); + 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..0fc1a2c3c 100755 --- a/atari/gui.h +++ b/atari/gui.h @@ -19,7 +19,9 @@ #ifndef NS_ATARI_GUI_H_ #define NS_ATARI_GUI_H_ -#include <windom.h> +#include "atari/redrawslots.h" +#include "atari/caret.h" +#include "atari/gemtk/gemtk.h" struct point_s { int x; @@ -96,17 +98,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,11 +121,21 @@ 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 s_caret caret; struct gui_window *next, *prev; }; extern struct gui_window *window_list; +/* -------------------------------------------------------------------------- */ +/* Public - non standard gui window functions */ +/* -------------------------------------------------------------------------- */ +void gui_set_input_gui_window(struct gui_window *gw); + #endif diff --git a/atari/history.c b/atari/history.c index ad5deb2bd..f9faef555 100755 --- a/atari/history.c +++ b/atari/history.c @@ -39,86 +39,103 @@ #include "atari/history.h" extern char * tree_directory_icon_name; +extern GRECT desk_area; 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_WORKXYWH, &pos); + pos.g_x = desk_area.g_w - desk_area.g_w / 4; + pos.g_y = desk_area.g_y; + pos.g_w = desk_area.g_w / 4; + pos.g_h = desk_area.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 ) { + gl_history.open = false; + handle = wind_create(flags, 40, 40, desk_area.g_w, desk_area.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 ); } void global_history_destroy( void ) { + +void global_history_redraw( void )
+{
+ atari_treeview_redraw( gl_history.tv );
+} if( gl_history.init == false ) { return; } @@ -126,9 +143,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..3ea2621bf 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;
@@ -38,11 +39,8 @@ void global_history_destroy( void ); void global_history_open( void ); void global_history_close( void ); -inline void global_history_redraw( void ); -inline void global_history_redraw( void )
-{
- atari_treeview_redraw( gl_history.tv );
-} +void global_history_redraw( void ); + #endif diff --git a/atari/hotlist.c b/atari/hotlist.c index bdd10d922..66e7560ea 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,64 @@ #include "atari/treeview.h" #include "atari/hotlist.h" #include "atari/findfile.h" +#include "atari/gemtk/gemtk.h" #include "atari/res/netsurf.rsh" +extern GRECT desk_area; + 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 +111,24 @@ 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 ); + + handle = wind_create(flags, 0, 0, desk_area.g_w, desk_area.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,30 +151,41 @@ 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; + pos.g_x = desk_area.g_w - desk_area.g_w / 4; + pos.g_y = desk_area.g_y; + pos.g_w = desk_area.g_w / 4; + pos.g_h = desk_area.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 ); } void hotlist_destroy(void) { + +void hotlist_redraw(void)
+{ + int i = 01;
+ atari_treeview_redraw(hl.tv);
+} if( hl.init == false ) { return; } @@ -163,7 +193,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..ed965a5a7 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;
@@ -40,10 +41,7 @@ void hotlist_close( void ); void hotlist_destroy( void );
void atari_hotlist_add_page( const char * url, const char * title );
-inline void hotlist_redraw( void );
-inline void hotlist_redraw( void )
-{
- atari_treeview_redraw( hl.tv );
-}
+void hotlist_redraw( void );
+
#endif diff --git a/atari/login.c b/atari/login.c index ddcfeba43..0fad4cd60 100755 --- a/atari/login.c +++ b/atari/login.c @@ -21,7 +21,7 @@ #include <stdlib.h> #include <string.h> #include <stdbool.h> -#include <windom.h> +#include <cflib.h> #include "utils/config.h" #include "content/content.h" #include "content/hlcache.h" @@ -36,77 +36,39 @@ #include "utils/url.h" #include "content/urldb.h" #include "content/fetch.h" +#include "atari/misc.h" #include "atari/login.h" #include "atari/res/netsurf.rsh" -extern void * h_gem_rsrc; - -bool login_form_do( nsurl * url, char * realm, char ** out ) +bool login_form_do(nsurl * url, char * realm, char ** out) { - OBJECT *tree, *newtree; - WINDOW * form; char user[255]; char pass[255]; - bool bres = false; - int res = 0; - const char * auth; - lwc_string * host = nsurl_get_component(url, NSURL_HOST); - assert(host != NULL); - - if( realm == NULL ){ - realm = (char*)"Secure Area"; - } + //const char * auth; + short exit_obj = 0; + OBJECT * tree; - int len = strlen(realm) + lwc_string_length(host) + 4; - char * title = malloc( len ); - strncpy(title, realm, len ); - strncpy(title, ": ", len-strlen(realm) ); - strncat(title, lwc_string_data(host), len-strlen(realm)+2 ); - - lwc_string_unref(host); - - auth = urldb_get_auth_details(url, realm); user[0] = 0; pass[0] = 0; - /* - TODO: use auth details if available: - if( auth == NULL ){ - } else { - - }*/ - - RsrcGaddr (h_gem_rsrc , R_TREE, LOGIN, &tree); - ObjcChange( OC_OBJC, tree, LOGIN_BT_LOGIN, 0, 0 ); - ObjcChange( OC_OBJC, tree, LOGIN_BT_ABORT, 0, 0 ); - ObjcString( tree, LOGIN_TB_USER, (char*)&user ); - ObjcString( tree, LOGIN_TB_PASSWORD, (char*)&pass ); - form = FormWindBegin( tree, (char *)title ); - res = -1; - while( res != LOGIN_BT_LOGIN && res != LOGIN_BT_ABORT ){ - res = FormWindDo( MU_MESAG ); - switch( res ){ - case LOGIN_BT_LOGIN: - bres = true; - break; + // TODO: use auth details for predefined login data + // auth = urldb_get_auth_details(url, realm); + tree = get_tree(LOGIN); - case LOGIN_BT_ABORT: - bres = false; - break; - } - } - - if( bres ) { - *out = malloc(strlen((char*)&user) + strlen((char*)&pass) + 2 ); - strcpy(*out, (char*)&user); - strcat(*out, ":"); - strcat(*out, (char*)&pass); + assert(tree != NULL); + + exit_obj = simple_mdial(tree, 0); + + if(exit_obj == LOGIN_BT_LOGIN) { + get_string(tree, LOGIN_TB_USER, user); + get_string(tree, LOGIN_TB_PASSWORD, pass); + int size = strlen((char*)&user) + strlen((char*)&pass) + 2 ; + *out = malloc(size); + snprintf(*out, size, "%s:%s", user, pass); } else { *out = NULL; } - - FormWindEnd( ); - free( title ); - return( bres ); + return((exit_obj == LOGIN_BT_LOGIN)); } + diff --git a/atari/misc.c b/atari/misc.c index 8b745fd2f..d0d4cd5c0 100755 --- a/atari/misc.c +++ b/atari/misc.c @@ -39,10 +39,10 @@ #include "content/fetch.h"
#include "atari/gui.h"
#include "atari/toolbar.h"
-#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 @@ -551,19 +502,19 @@ void dbg_lgrect( char * str, LGRECT * r ) r->g_x, r->g_y, r->g_w, r->g_h );
}
-void dbg_grect( char * str, GRECT * r )
+void dbg_grect(const char * str, GRECT * r)
{
- printf("%s: x: %d, y: %d, w: %d, h: %d\n", str,
- r->g_x, r->g_y, r->g_w, r->g_h );
+ printf("%s: x: %d, y: %d, w: %d, h: %d (x2: %d, y2: %d)\n", str,
+ r->g_x, r->g_y, r->g_w, r->g_h, r->g_x + r->g_w, r->g_y + r->g_h);
}
-void dbg_pxy( char * str, short * pxy )
+void dbg_pxy(const char * str, short * pxy )
{
printf("%s: x: %d, y: %d, w: %d, h: %d\n", str,
pxy[0], pxy[1], pxy[2], pxy[3] );
} -void dbg_rect( char * str, int * pxy )
+void dbg_rect(const char * str, int * pxy)
{
printf("%s: x: %d, y: %d, w: %d, h: %d\n", str,
pxy[0], pxy[1], pxy[2], pxy[3] );
diff --git a/atari/misc.h b/atari/misc.h index 612113fc1..b59f19dd7 100755 --- a/atari/misc.h +++ b/atari/misc.h @@ -1,62 +1,61 @@ -/*
- * 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_MISC_H
+/* + * 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_MISC_H #define NS_ATARI_MISC_H +#include <windom.h> #include "cflib.h" #include "content/content.h" #include "content/hlcache.h" #include "desktop/textinput.h" #include "atari/gui.h" -
-#define SBUF8_TO_LBUF8(sbuf,lbuf)\
- lbuf[0] = (long)sbuf[0];\
- lbuf[1] = (long)sbuf[1];\
- lbuf[2] = (long)sbuf[2];\
- lbuf[3] = (long)sbuf[3];\
- lbuf[4] = (long)sbuf[4];\
- lbuf[5] = (long)sbuf[5];\
- lbuf[6] = (long)sbuf[6];\
- lbuf[7] = (long)sbuf[7];
-
+ +#define SBUF8_TO_LBUF8(sbuf,lbuf)\ + lbuf[0] = (long)sbuf[0];\ + lbuf[1] = (long)sbuf[1];\ + lbuf[2] = (long)sbuf[2];\ + lbuf[3] = (long)sbuf[3];\ + lbuf[4] = (long)sbuf[4];\ + lbuf[5] = (long)sbuf[5];\ + lbuf[6] = (long)sbuf[6];\ + lbuf[7] = (long)sbuf[7]; + /* Modes for find_gui_window: */ #define BY_WINDOM_HANDLE 0x0 #define BY_GEM_HANDLE 0x1 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 ); -bool is_process_running(const char * name);
-OBJECT *get_tree( int idx );
-char *get_rsc_string( int idx );
+ +struct gui_window * find_guiwin_by_aes_handle(short handle); +bool is_process_running(const char * name); void gem_set_cursor( MFORM_EX * cursor ); hlcache_handle *load_icon( const char *name, hlcache_handle_callback cb, - void * pw );
-void dbg_grect( char * str, GRECT * r ); -void dbg_lgrect( char * str, LGRECT * r );
-void dbg_pxy( char * str, short * pxy );
-void * ldg_open( char * name, short * global );
-void * ldg_find( char * name, short * ldg );
+ void * pw ); +void dbg_grect(const char * str, GRECT * r); +void dbg_lgrect( char * str, LGRECT * r); +void dbg_pxy(const char * str, short * pxy); +void dbg_rect(const char * str, int * pxy); +void * ldg_open( char * name, short * global ); +void * ldg_find( char * name, short * ldg ); const char * file_select( const char * title, const char * name ); int ldg_close( void * ldg, short * global ); long nkc_to_input_key(short nkc, long * ucs4_out); -#endif
+#endif 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/options.h b/atari/options.h index f48a0e871..f9bb3b4c5 100755 --- a/atari/options.h +++ b/atari/options.h @@ -29,9 +29,6 @@ int atari_font_monochrom; \ int atari_dither; \ int atari_transparency; \ - int atari_image_toolbar; \ - colour atari_toolbar_bg; \ - char *atari_image_toolbar_folder; \ char *atari_face_sans_serif; /* default sans face */ \ char *atari_face_sans_serif_bold; /* bold sans face */ \ char *atari_face_sans_serif_italic; /* bold sans face */ \ @@ -53,9 +50,6 @@ .atari_font_monochrom = 0, \ .atari_dither = 1, \ .atari_transparency = 1, \ - .atari_image_toolbar_folder = (char*)"default", \ - .atari_image_toolbar = 1, \ - .atari_toolbar_bg = 0xbbbbbb, \ .atari_face_sans_serif = NULL, \ .atari_face_sans_serif_bold = NULL, \ .atari_face_sans_serif_italic = NULL, \ @@ -75,12 +69,9 @@ #define NSOPTION_EXTRA_TABLE \ { "atari_font_driver", OPTION_STRING, &nsoptions.atari_font_driver },\ { "atari_font_monochrom", OPTION_INTEGER, &nsoptions.atari_font_monochrom },\ - { "atari_image_toolbar", OPTION_INTEGER, &nsoptions.atari_image_toolbar },\ - { "atari_toolbar_bg", OPTION_COLOUR, &nsoptions.atari_toolbar_bg },\ { "atari_transparency", OPTION_INTEGER, &nsoptions.atari_transparency },\ { "atari_dither", OPTION_INTEGER, &nsoptions.atari_dither },\ { "atari_editor", OPTION_STRING, &nsoptions.atari_editor },\ - { "atari_image_toolbar_folder", OPTION_STRING, &nsoptions.atari_image_toolbar_folder },\ { "font_face_sans_serif", OPTION_STRING, &nsoptions.atari_face_sans_serif },\ { "font_face_sans_serif_bold", OPTION_STRING, &nsoptions.atari_face_sans_serif_bold },\ { "font_face_sans_serif_italic", OPTION_STRING, &nsoptions.atari_face_sans_serif_italic },\ 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..81c97c18b 100755 --- a/atari/plot/plot.c +++ b/atari/plot/plot.c @@ -154,7 +154,7 @@ static HermesFormat vfmt; /* netsurf source bitmap format */ static HermesFormat nsfmt; -static struct s_vdi_sysinfo vdi_sysinfo; +struct s_vdi_sysinfo vdi_sysinfo; /* bit depth of framebuffers: */ static int atari_plot_bpp_virt; static struct s_view view; @@ -325,7 +325,7 @@ inline static bool fbrect_to_screen(GRECT box, GRECT * ret) inline static void plot_vdi_clip(bool set) { // TODO : check this - return; + if( set == true ) { struct rect c; short vdiflags[58]; @@ -340,6 +340,7 @@ inline static void plot_vdi_clip(bool set) newclip[1] = view.y + MAX(c.y0, 0); newclip[2] = MIN(view.x+view.w, newclip[0] + (c.x1 - c.x0) )-1; newclip[3] = MIN(view.y+view.h, newclip[1] + (c.y1 - c.y0) )-1; + //dbg_pxy("plot_vdi_clip", newclip); vs_clip(atari_plot_vdi_handle, 1, (short*)&newclip ); } else { vs_clip(atari_plot_vdi_handle, 1, (short *)&prev_vdi_clip ); @@ -1816,10 +1817,21 @@ 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); + + if((y0 > view.h-1) && (y1 > view.h-1)) + return(true); + + //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 +1846,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, @@ -1888,6 +1900,16 @@ bool plot_set_dimensions(int x, int y, int w, int h) return(true); } +bool plot_get_dimensions(GRECT *dst) +{ + + dst->g_x = view.x; + dst->g_y = view.y; + dst->g_w = view.w; + dst->g_h = view.h; + return(true); +} + bool plot_clip(const struct rect *clip) { // FIXME: consider the canvas size diff --git a/atari/plot/plot.h b/atari/plot/plot.h index 53a2645f8..0c1db0f7a 100755 --- a/atari/plot/plot.h +++ b/atari/plot/plot.h @@ -107,6 +107,7 @@ const char* plot_err_str(int i) ; bool plot_lock(void); bool plot_unlock(void); bool plot_set_dimensions( int x, int y, int w, int h ); +bool plot_get_dimensions(GRECT *dst); bool plot_get_clip(struct rect * out); /* Get clipping for current framebuffer as GRECT */ void plot_get_clip_grect(GRECT * out); diff --git a/atari/redrawslots.c b/atari/redrawslots.c index 9fe71610e..fdc35554a 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,38 +50,50 @@ 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, + bool force) +{ + redraw_slot_schedule(slots, area->g_x, area->g_y, + area->g_x + area->g_w, area->g_y + area->g_h, force); +} + /*
- 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, bool force)
{
- int i;
+ int i = 0;
struct rect area;
area.x0 = x0;
area.y0 = y0;
area.x1 = x1;
area.y1 = y1;
-
- for( i=0; i<slots->areas_used; i++) {
- if( slots->areas[i].x0 <= x0
- && slots->areas[i].x1 >= x1
- && slots->areas[i].y0 <= y0
- && slots->areas[i].y1 >= y1 ){
- /* the area is already queued for redraw */
- return;
- } else {
- if( rect_intersect(&slots->areas[i], &area ) ){
- slots->areas[i].x0 = MIN(slots->areas[i].x0, x0);
- slots->areas[i].y0 = MIN(slots->areas[i].y0, y0);
- slots->areas[i].x1 = MAX(slots->areas[i].x1, x1);
- slots->areas[i].y1 = MAX(slots->areas[i].y1, y1);
- return;
- }
- }
+ + if (force == false) {
+ for (i=0; i<slots->areas_used; i++) {
+ if (slots->areas[i].x0 <= x0
+ && slots->areas[i].x1 >= x1
+ && slots->areas[i].y0 <= y0
+ && slots->areas[i].y1 >= y1) {
+ /* the area is already queued for redraw */
+ return;
+ } else {
+ if (rect_intersect(&slots->areas[i], &area )) {
+ slots->areas[i].x0 = MIN(slots->areas[i].x0, x0);
+ slots->areas[i].y0 = MIN(slots->areas[i].y0, y0);
+ slots->areas[i].x1 = MAX(slots->areas[i].x1, x1);
+ slots->areas[i].y1 = MAX(slots->areas[i].y1, y1);
+ return;
+ }
+ }
+ } }
- if( slots->areas_used < slots->size ) {
+ if (slots->areas_used < slots->size) {
slots->areas[slots->areas_used].x0 = x0;
slots->areas[slots->areas_used].x1 = x1;
slots->areas[slots->areas_used].y0 = y0;
@@ -91,6 +109,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..2c932bbc1 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.
@@ -36,11 +40,15 @@ struct s_redrw_slots {
struct rect areas[MAX_REDRW_SLOTS]; short size;
- short areas_used;
+ short volatile areas_used;
}; 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, bool force); +void redraw_slot_schedule_grect(struct s_redrw_slots * slots, GRECT *area, + bool force); +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 Binary files differindex de493636b..cb8a3a046 100755 --- a/atari/res/netsurf.rsc +++ b/atari/res/netsurf.rsc diff --git a/atari/res/netsurf.rsh b/atari/res/netsurf.rsh index 3c2353ede..0b3961cd3 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 */
@@ -110,7 +113,7 @@ #define DOWNLOAD_LBL_BYTES 6 /* TEXT in tree DOWNLOAD */
#define DOWNLOAD_LBL_PERCENT 7 /* TEXT in tree DOWNLOAD */
#define DOWNLOAD_LBL_SPEED 8 /* TEXT in tree DOWNLOAD */
-#define DOWNLOAD_CB_CLOSE_RDY 9 /* BUTTON in tree DOWNLOAD */
+#define DOWNLOAD_CB_CLOSE_RDY 9 /* BOXCHAR in tree DOWNLOAD */
#define ABOUT 11 /* form/dial */
@@ -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..3e12e13f8 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@624@
#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@@
@@ -104,7 +107,7 @@ ResourceMaster v3.65 #O 6@21@LBL_BYTES@@
#O 7@21@LBL_PERCENT@@
#O 8@21@LBL_SPEED@@
-#O 9@26@CB_CLOSE_RDY@@
+#O 9@27@CB_CLOSE_RDY@@
#T 11@2@ABOUT@@2@@
#T 12@2@POP_CTX@@12@@
#O 1@21@CUT_SEL@@
@@ -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 205@
diff --git a/atari/rootwin.c b/atari/rootwin.c new file mode 100755 index 000000000..3a2af1c10 --- /dev/null +++ b/atari/rootwin.c @@ -0,0 +1,1097 @@ +/* + * 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/misc.h" +#include "atari/plot/plot.h" + +#include "atari/res/netsurf.rsh" + +#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/browser.h" +#include "atari/gemtk/gemtk.h" + +extern struct gui_window *input_window; +extern EVMULT_OUT aes_event_out; + +struct rootwin_data_s { + struct s_gui_win_root *rootwin; +}; + +/* -------------------------------------------------------------------------- */ +/* Static module event handlers */ +/* -------------------------------------------------------------------------- */ +static void on_redraw(ROOTWIN *rootwin, short msg[8]); +static void on_resized(ROOTWIN *rootwin); +static void on_file_dropped(ROOTWIN *rootwin, short msg[8]); +static short on_window_key_input(ROOTWIN * rootwin, unsigned short nkc); +static bool on_content_mouse_click(ROOTWIN *rootwin); +static bool on_content_mouse_move(ROOTWIN *rootwin, GRECT *content_area); + +static bool redraw_active = false; + +static const struct redraw_context rootwin_rdrw_ctx = { + .interactive = true, + .background_images = true, + .plot = &atari_plotters +}; + +/* -------------------------------------------------------------------------- */ +/* Module public functions: */ +/* -------------------------------------------------------------------------- */ + + +static short handle_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8]) +{ + short retval = 0; + GRECT content_area; + static bool prev_url = false; + static short prev_x=0; + static short prev_y=0; + 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: + on_redraw(data->rootwin, msg); + break; + + case WM_REPOSED: + case WM_SIZED: + case WM_MOVED: + case WM_FULLED: + on_resized(data->rootwin); + break; + + case WM_TOPPED: + case WM_NEWTOP: + case WM_UNICONIFY: + 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... + if (data->rootwin->active_gui_window != NULL) { + printf("destroy...\n"); + browser_window_destroy( + data->rootwin->active_gui_window->browser->bw); + } + break; + + case AP_DRAGDROP: + on_file_dropped(data->rootwin, msg); + break; + + case WM_TOOLBAR: + toolbar_mouse_input(data->rootwin->toolbar, msg[4]); + break; + + default: + break; + } + } + if ((ev_out->emo_events & MU_KEYBD) != 0) { + + // handle key + uint16_t nkc = gem_to_norm( (short)ev_out->emo_kmeta, + (short)ev_out->emo_kreturn); + retval = on_window_key_input(data->rootwin, nkc); + + } + if ((ev_out->emo_events & MU_BUTTON) != 0) { + guiwin_get_grect(data->rootwin->win, GUIWIN_AREA_CONTENT, + &content_area); + if (POINT_WITHIN(ev_out->emo_mouse.p_x, ev_out->emo_mouse.p_y, + content_area)) { + on_content_mouse_click(data->rootwin); + } + } + if ((ev_out->emo_events & (MU_M1)) != 0) { + + short ghandle = wind_find(ev_out->emo_mouse.p_x, ev_out->emo_mouse.p_y); + + if (guiwin_get_handle(data->rootwin->win)==ghandle) { + // The window found at x,y is an gui_window + // and it's the input window. + window_get_grect(data->rootwin, BROWSER_AREA_CONTENT, + &content_area); + if (POINT_WITHIN(ev_out->emo_mouse.p_x, ev_out->emo_mouse.p_y, + content_area)) { + on_content_mouse_move(data->rootwin, &content_area); + } else { + GRECT tb_area; + window_get_grect(data->rootwin, BROWSER_AREA_URL_INPUT, &tb_area); + if (POINT_WITHIN(ev_out->emo_mouse.p_x, ev_out->emo_mouse.p_y, + tb_area)) { + gem_set_cursor(&gem_cursors.ibeam);
+ prev_url = true; + } + else { + if(prev_url) { + struct gui_window *gw; + gw = window_get_active_gui_window(data->rootwin); + gem_set_cursor(gw->cursor);
+ prev_url = false;
+ } + } + } + } + } + + return(retval); +} + + +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); + + redraw_slots_init(&gw->root->redraw_slots, 8); + + // 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); + + struct rootwin_data_s * data = malloc(sizeof(struct rootwin_data_s)); + data->rootwin = gw->root; + guiwin_set_user_data(gw->root->win, (void*)data); + struct guiwin_scroll_info_s *slid = guiwin_get_scroll_info(gw->root->win); + slid->y_unit_px = 16; + slid->x_unit_px = 16; + + /* create toolbar component: */ + guiwin_set_toolbar(gw->root->win, get_tree(TOOLBAR), 0, 0); + 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); + + 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) { + gui_set_input_gui_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; + + assert(rootwin->active_gui_window != NULL); + + 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_attached(rootwin->toolbar, true); + toolbar_set_dimensions(rootwin->toolbar, &g); + window_update_back_forward(rootwin); + /*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); +} + +void window_scroll_by(ROOTWIN *root, int sx, int sy) +{ + int units; + GRECT content_area; + struct guiwin_scroll_info_s *slid = guiwin_get_scroll_info(root->win); + + if(sx < 0) { + sx = 0; + } + if(sy<0) { + sy = 0; + } + int xunits = sx / slid->x_unit_px; + int yunits = sy / slid->y_unit_px; + + guiwin_scroll(root->win, GUIWIN_VSLIDER, yunits - slid->y_pos, false); + guiwin_scroll(root->win, GUIWIN_HSLIDER, xunits - slid->x_pos, false); + guiwin_update_slider(root->win, GUIWIN_VH_SLIDER); +} + +void window_set_content_size(ROOTWIN *rootwin, int width, int height) +{ + GRECT area; + struct guiwin_scroll_info_s *slid = guiwin_get_scroll_info(rootwin->win); + + guiwin_get_grect(rootwin->win, GUIWIN_AREA_CONTENT, &area); + slid->x_units = (width/slid->x_unit_px); + slid->y_units = (height/slid->y_unit_px); + if(slid->x_units < slid->x_pos) + slid->x_pos = 0; + if(slid->y_units < slid->y_pos) + slid->y_pos = 0; + guiwin_update_slider(rootwin->win, GUIWIN_VH_SLIDER); + // TODO: reset slider to 0 +} + +/* 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) { + printf("set & redraw\n"); + 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); +} + +void window_get_scroll(ROOTWIN *rootwin, int *x, int *y) +{ + struct guiwin_scroll_info_s *slid; + + slid = guiwin_get_scroll_info(rootwin->win); + + *x = slid->x_pos * slid->x_unit_px; + *y = slid->y_pos * slid->y_unit_px; +} + +void window_get_grect(ROOTWIN *rootwin, enum browser_area_e which, GRECT *d) +{ + if (which == BROWSER_AREA_TOOLBAR) { + guiwin_get_grect(rootwin->win, GUIWIN_AREA_TOOLBAR, d); + } else if (which == BROWSER_AREA_CONTENT) { + guiwin_get_grect(rootwin->win, GUIWIN_AREA_CONTENT, d); + } else if (which == BROWSER_AREA_URL_INPUT) { + toolbar_get_grect(rootwin->toolbar, TOOLBAR_URL_AREA, d); + } else { + + } + +} + + +/** + * Redraw the favicon +*/ +void window_redraw_favicon(ROOTWIN *rootwin, GRECT *clip) +{ + GRECT work; + + assert(rootwin); + + printf("window_redraw_favicon: root: %p, win: %p\n", rootwin, rootwin->win); + + 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) { + printf("window_redraw_favicon OBJCTREE\n"); + 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 + printf("window_redraw_favicon image %p\n", rootwin->icon); + 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); + } +} + +/*** +* Schedule an redraw area, redraw requests during redraw are +* not optimized (merged) into other areas, so that the redraw +* functions can spot the change. +* +*/ +void window_schedule_redraw_grect(ROOTWIN *rootwin, GRECT *area) +{ + GRECT work; + + + //dbg_grect("window_schedule_redraw_grect input ", area); + + guiwin_get_grect(rootwin->win, GUIWIN_AREA_WORK, &work); + if(!rc_intersect(area, &work)) + return; + + //dbg_grect("window_schedule_redraw_grect intersection ", &work); + + redraw_slot_schedule_grect(&rootwin->redraw_slots, &work, redraw_active); +} + +static void window_redraw_content(ROOTWIN *rootwin, GRECT *content_area, + GRECT *clip, + struct guiwin_scroll_info_s * slid, + struct browser_window *bw) +{ + + struct rect redraw_area; + GRECT content_area_rel; + + if(bw->window->browser->reformat_pending) { + browser_window_reformat(bw, true, content_area->g_w, + content_area->g_h); + bw->window->browser->reformat_pending = false; + //return; + } + + //dbg_grect("browser redraw, content area", content_area); + //dbg_grect("browser redraw, content clip", clip); + + plot_set_dimensions(content_area->g_x, content_area->g_y, + content_area->g_w, content_area->g_h); + + + /* first, we make the coords relative to the content area: */ + content_area_rel.g_x = clip->g_x - content_area->g_x; + content_area_rel.g_y = clip->g_y - content_area->g_y; + content_area_rel.g_w = clip->g_w; + content_area_rel.g_h = clip->g_h; + + if (content_area_rel.g_x < 0) { + content_area_rel.g_w += content_area_rel.g_x; + content_area_rel.g_x = 0; + } + + if (content_area_rel.g_y < 0) { + content_area_rel.g_h += content_area_rel.g_y; + content_area_rel.g_y = 0; + } + + //dbg_grect("browser redraw, relative plot coords:", &content_area_rel); + + redraw_area.x0 = content_area_rel.g_x; + redraw_area.y0 = content_area_rel.g_y; + redraw_area.x1 = content_area_rel.g_x + content_area_rel.g_w; + redraw_area.y1 = content_area_rel.g_y + content_area_rel.g_h; + + plot_clip(&redraw_area); + + //dbg_rect("rdrw area", &redraw_area); + + browser_window_redraw( bw, -(slid->x_pos*slid->x_unit_px), + -(slid->y_pos*slid->y_unit_px), &redraw_area, &rootwin_rdrw_ctx ); +} + +void window_process_redraws(ROOTWIN * rootwin) +{ + GRECT work, visible_ro, tb_area, content_area; + short aes_handle, i; + bool toolbar_rdrw_required; + struct guiwin_scroll_info_s *slid =NULL; + + redraw_active = true; + + aes_handle = guiwin_get_handle(rootwin->win); + + guiwin_get_grect(rootwin->win, GUIWIN_AREA_TOOLBAR, &tb_area); + guiwin_get_grect(rootwin->win, GUIWIN_AREA_CONTENT, &content_area); + + //dbg_grect("content area", &content_area); + + short pxy_clip[4]; + + pxy_clip[0] = tb_area.g_x; + pxy_clip[0] = tb_area.g_y; + pxy_clip[0] = pxy_clip[0] + tb_area.g_w + content_area.g_w - 1; + pxy_clip[0] = pxy_clip[1] + tb_area.g_h + content_area.g_h - 1; + vs_clip(guiwin_get_vdi_handle(rootwin->win), 1, pxy_clip); + + 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_ro = { + 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 + }; + rc_intersect(&visible_ro, &rdrw_area_ro); + GRECT rdrw_area = rdrw_area_ro; + + if (rc_intersect(&tb_area, &rdrw_area)) { + toolbar_redraw(rootwin->toolbar, &rdrw_area); + } + + rdrw_area = rdrw_area_ro; + if (rc_intersect(&content_area, &rdrw_area)) { + if(slid == NULL) + slid = guiwin_get_scroll_info(rootwin->win); + window_redraw_content(rootwin, &content_area, &rdrw_area, slid, + rootwin->active_gui_window->browser->bw); + } + + } + wind_get_grect(aes_handle, WF_NEXTXYWH, &visible_ro); + } + vs_clip(guiwin_get_vdi_handle(rootwin->win), 0, pxy_clip); + rootwin->redraw_slots.areas_used = 0; + redraw_active = false; + + plot_unlock(); +} + + +/* -------------------------------------------------------------------------- */ +/* Event Handlers: */ +/* -------------------------------------------------------------------------- */ +static bool on_content_mouse_move(ROOTWIN *rootwin, GRECT *content_area) +{ + int mx, my, sx, sy; + struct guiwin_scroll_info_s *slid; + struct gui_window *gw; + struct browser_window *bw; + + // make relative mouse coords: + mx = aes_event_out.emo_mouse.p_x - content_area->g_x; + my = aes_event_out.emo_mouse.p_y - content_area->g_y; + + slid = guiwin_get_scroll_info(rootwin->win); + gw = window_get_active_gui_window(rootwin); + bw = gw->browser->bw; + + // calculate scroll pos. in pixel: + sx = slid->x_pos * slid->x_unit_px; + sy = slid->y_pos * slid->y_unit_px; + + browser_window_mouse_track(bw, 0, mx + sx, my + sy); +} + +static bool on_content_mouse_click(ROOTWIN *rootwin) +{ + short dummy, mbut, mx, my; + GRECT cwork; + browser_mouse_state bmstate = 0; + struct gui_window *gw; + struct guiwin_scroll_info_s *slid; + + gw = window_get_active_gui_window(rootwin); + if( input_window != gw ) { + gui_set_input_gui_window(gw); + } + + window_set_focus(gw->root, BROWSER, (void*)gw->browser ); + guiwin_get_grect(gw->root->win, GUIWIN_AREA_CONTENT, &cwork); + + /* convert screen coords to component coords: */ + mx = aes_event_out.emo_mouse.p_x - cwork.g_x; + my = aes_event_out.emo_mouse.p_y - cwork.g_y; + //printf("content click at %d,%d\n", mx, my); + + /* Translate GEM key state to netsurf mouse modifier */ + if ( aes_event_out.emo_kmeta & (K_RSHIFT | K_LSHIFT)) { + bmstate |= BROWSER_MOUSE_MOD_1; + } else { + bmstate &= ~(BROWSER_MOUSE_MOD_1); + } + if ( (aes_event_out.emo_kmeta & K_CTRL) ) { + bmstate |= BROWSER_MOUSE_MOD_2; + } else { + bmstate &= ~(BROWSER_MOUSE_MOD_2); + } + if ( (aes_event_out.emo_kmeta & K_ALT) ) { + bmstate |= BROWSER_MOUSE_MOD_3; + } else { + bmstate &= ~(BROWSER_MOUSE_MOD_3); + } + + /* convert component coords to scrolled content coords: */ + slid = guiwin_get_scroll_info(rootwin->win); + int sx_origin = mx; + int sy_origin = my; + + short rel_cur_x, rel_cur_y; + short prev_x=sx_origin, prev_y=sy_origin; + bool dragmode = false; + + /* Detect left mouse button state and compare with event state: */ + graf_mkstate(&rel_cur_x, &rel_cur_y, &mbut, &dummy); + if( (mbut & 1) && (aes_event_out.emo_mbutton & 1) ) { + /* Mouse still pressed, report drag */ + rel_cur_x = (rel_cur_x - cwork.g_x); + rel_cur_y = (rel_cur_y - cwork.g_y); + browser_window_mouse_click( gw->browser->bw, + BROWSER_MOUSE_DRAG_ON|BROWSER_MOUSE_DRAG_1, + rel_cur_x + slid->x_pos * slid->x_unit_px, + rel_cur_y + slid->y_pos * slid->y_unit_px); + do { + // only consider movements of 5px or more as drag...: + if( abs(prev_x-rel_cur_x) > 5 || abs(prev_y-rel_cur_y) > 5 ) { + browser_window_mouse_track( gw->browser->bw, + BROWSER_MOUSE_DRAG_ON|BROWSER_MOUSE_DRAG_1, + rel_cur_x + slid->x_pos * slid->x_unit_px, + rel_cur_y + slid->y_pos * slid->y_unit_px); + prev_x = rel_cur_x; + prev_y = rel_cur_y; + dragmode = true; + } else { + if( dragmode == false ) { + browser_window_mouse_track( gw->browser->bw,BROWSER_MOUSE_PRESS_1, + rel_cur_x + slid->x_pos * slid->x_unit_px, + rel_cur_y + slid->y_pos * slid->y_unit_px); + } + } + + // we may need to process scrolling: + // TODO: this doesn't work, because gemtk schedules redraw via + // AES window messages but we do not process them right here... + if (rootwin->redraw_slots.areas_used > 0) { + window_process_redraws(rootwin); + } + evnt_timer(150); + + graf_mkstate(&rel_cur_x, &rel_cur_y, &mbut, &dummy); + rel_cur_x = (rel_cur_x - cwork.g_x); + rel_cur_y = (rel_cur_y - cwork.g_y); + } while( mbut & 1 ); + browser_window_mouse_track(gw->browser->bw, 0, + rel_cur_x + slid->x_pos * slid->x_unit_px, + rel_cur_y + slid->y_pos * slid->y_unit_px); + } else { + /* Right button pressed? */ + if ((aes_event_out.emo_mbutton & 2 ) ) { + context_popup(gw, aes_event_out.emo_mouse.p_x, + aes_event_out.emo_mouse.p_y); + } else { + browser_window_mouse_click(gw->browser->bw, + bmstate|BROWSER_MOUSE_PRESS_1, + sx_origin + slid->x_pos * slid->x_unit_px, + sy_origin + slid->y_pos * slid->y_unit_px); + browser_window_mouse_click(gw->browser->bw, + bmstate|BROWSER_MOUSE_CLICK_1, + sx_origin + slid->x_pos * slid->x_unit_px, + sy_origin + slid->y_pos * slid->y_unit_px); + } + } + if (rootwin->redraw_slots.areas_used > 0) { + window_process_redraws(rootwin); + } +} + +/* + Report keypress to browser component. + parameter: + - unsigned short nkc ( CFLIB normalised key code ) +*/ +static bool on_content_keypress(struct browser_window *bw, unsigned short nkc) +{ + bool r = false; + unsigned char ascii = (nkc & 0xFF); + long ucs4; + long ik = nkc_to_input_key( nkc, &ucs4 ); + + // pass event to specific control? + + if (ik == 0) { + if (ascii >= 9) { + r = browser_window_key_press(bw, ucs4); + } + } else { + r = browser_window_key_press(bw, ik); + if (r == false) { + + GRECT g; + GUIWIN * w = bw->window->root->win; + guiwin_get_grect(w, GUIWIN_AREA_CONTENT, &g); + + struct guiwin_scroll_info_s *slid = guiwin_get_scroll_info(w); + + switch( ik ) { + case KEY_LINE_START: + guiwin_scroll(w, GUIWIN_HSLIDER, -(g.g_w/slid->x_unit_px), + false); + break; + + case KEY_LINE_END: + guiwin_scroll(w, GUIWIN_HSLIDER, (g.g_w/slid->x_unit_px), + false); + break; + + case KEY_PAGE_UP: + guiwin_scroll(w, GUIWIN_VSLIDER, (g.g_h/slid->y_unit_px), + false); + break; + + case KEY_PAGE_DOWN: + guiwin_scroll(w, GUIWIN_VSLIDER, (g.g_h/slid->y_unit_px), + false); + break; + + case KEY_RIGHT: + guiwin_scroll(w, GUIWIN_HSLIDER, -1, false); + break; + + case KEY_LEFT: + guiwin_scroll(w, GUIWIN_HSLIDER, 1, false); + break; + + case KEY_UP: + guiwin_scroll(w, GUIWIN_VSLIDER, -1, false); + break; + + case KEY_DOWN: + guiwin_scroll(w, GUIWIN_VSLIDER, 1, false); + break; + + default: + break; + } + guiwin_update_slider(w, GUIWIN_VSLIDER|GUIWIN_HSLIDER); + } + } + + return(r); +} + +static short on_window_key_input(ROOTWIN *rootwin, unsigned short nkc) +{ + bool done = false; + struct gui_window * gw = window_get_active_gui_window(rootwin); + struct gui_window * gw_tmp; + + if( gw == NULL ) + return(false); + + if(window_url_widget_has_focus((void*)gw->root)) { + /* make sure we report for the root window and report...: */ + 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(input_window->root, BROWSER, + (void*)gw_tmp->browser)) { + done = on_content_keypress(gw_tmp->browser->bw, nkc); + break; + } else { + gw_tmp = gw_tmp->next; + } + } + } + return((done==true) ? 1 : 0); +} + + +static void on_redraw(ROOTWIN *rootwin, short msg[8]) +{ + short handle; + + GRECT clip = {msg[4], msg[5], msg[6], msg[7]}; + + if(guiwin_get_state(rootwin->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); + } +} + +static void on_resized(ROOTWIN *rootwin) +{ + GRECT g; + short handle; + struct gui_window *gw; + + handle = guiwin_get_handle(rootwin->win); + gw = window_get_active_gui_window(rootwin); + + //printf("resized...\n"); + + assert(gw != NULL); + + if(gw == NULL) + return; + + 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... + //printf("reformat......\n"); + 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(rootwin->win, GUIWIN_AREA_TOOLBAR, &g); + toolbar_set_dimensions(rootwin->toolbar, &g); +} + +static void on_file_dropped(ROOTWIN *rootwin, 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 = window_get_active_gui_window(rootwin); + + if( gw == NULL ) + return; + + if(guiwin_get_state(rootwin->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); +} + diff --git a/atari/browser_win.h b/atari/rootwin.h index 28001baad..5f42a18b3 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)
@@ -26,41 +28,58 @@ #define WIDGET_TOOLBAR 0x2
#define WIDGET_SCROLL 0x4 #define WIDGET_RESIZE 0x8 - #define WIN_TOP 0x100 + +enum browser_area_e { + BROWSER_AREA_CONTENT = 1, + BROWSER_AREA_STATUSBAR, + BROWSER_AREA_TOOLBAR, + BROWSER_AREA_URL_INPUT +}; -/* WinDom & Custom bindings for gui window */
/* -------------------------------------------------------------------------- */
/* Public module functions: */
/* -------------------------------------------------------------------------- */
/* 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(ROOTWIN *rootwin);
/* show the window */
-void window_open( struct gui_window * gw, GRECT pos);
+void window_open(ROOTWIN *rootwin, GRECT pos);
-void window_snd_redraw(struct gui_window * gw, short x, short y, short w, short h );
+void window_snd_redraw(ROOTWIN *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(ROOTWIN *rootwin, CMP_BROWSER b);
/* set focus element */
-void window_set_focus( struct gui_window * gw, 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_focus(ROOTWIN *rootwin, enum focus_element_type type, + void * element );
/* 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(ROOTWIN *rootwin, enum focus_element_type t, + void * element);
+bool window_url_widget_has_focus(ROOTWIN *rootwin);
+void window_set_url(ROOTWIN *rootwin, const char * text);
+void window_set_stauts(ROOTWIN *rootwin, char * text); +void window_set_title(ROOTWIN *rootwin, char * text); +void window_set_content_size(ROOTWIN *rootwin, int w, int h);
+void window_set_icon(ROOTWIN *rootwin, struct bitmap * bmp ); +void window_set_active_gui_window(ROOTWIN *rootwin, struct gui_window *gw); +void window_scroll_by(ROOTWIN *rootwin, int x, int y); +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_get_scroll(ROOTWIN *rootwin, int *x, int *y); +void window_get_grect(ROOTWIN *rootwin, enum browser_area_e which, GRECT *d); +void window_redraw_favicon(struct s_gui_win_root * rootwin, GRECT *clip); +void window_unref_gui_window(ROOTWIN *rootwin, struct gui_window *gw); +bool window_key_input(unsigned short kcode, unsigned short kstate, + unsigned short nkc);
/* -------------------------------------------------------------------------- */
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..0aa78cc52 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,
@@ -391,7 +392,7 @@ static char * toolbar_iconset_popup( int x, int y ) /* Get current set (for pre-selection): */
memset( avail, 0, MAX_SETS );
- current = nsoption_charp(atari_image_toolbar_folder);
+ current = "";
/* locate the toolbar folder: */
atari_find_resource( toolbar_folder, fullpath, fullpath );
@@ -845,14 +846,6 @@ static void display_settings( void ) snprintf( spare, 255, "%3d", nsoption_int(font_size) );
set_text( CHOICES_EDIT_DEF_FONT_SIZE, spare , 3 );
- set_text(CHOICES_BT_TOOLBAR_ICONSET,
- nsoption_charp(atari_image_toolbar_folder), LABEL_ICONSET_MAX_LEN);
-
- tmp_option_atari_toolbar_bg = nsoption_int(atari_toolbar_bg);
- snprintf( spare, 255, "%06x", tmp_option_atari_toolbar_bg);
- set_text(CHOICES_INPUT_TOOLBAR_BGCOLOR, spare,
- INPUT_TOOLBAR_COLOR_MAX_LEN );
-
/* Only first tab is refreshed: */
ObjcDraw( OC_FORM, dlgwin, CHOICES_TAB_BROWSER, 4 );
@@ -891,10 +884,6 @@ static void apply_settings( void ) /* "Style" tab: */
nsoption_set_int(font_min_size, tmp_option_font_min_size);
nsoption_set_int(font_size, tmp_option_font_size);
- nsoption_set_colour(atari_toolbar_bg, tmp_option_atari_toolbar_bg);
- nsoption_set_charp(atari_image_toolbar_folder,
- ObjcString( dlgtree, CHOICES_BT_TOOLBAR_ICONSET, NULL)
- );
/* "Rendering" tab: */
nsoption_set_charp(atari_font_driver,
diff --git a/atari/statusbar.c b/atari/statusbar.c index 08a62c55d..bf241e2dc 100755 --- a/atari/statusbar.c +++ b/atari/statusbar.c @@ -38,9 +38,9 @@ #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"
#include "atari/plot/plot.h"
#include "atari/osspec.h"
@@ -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..c6bd74568 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,14 +42,49 @@ #include "atari/clipboard.h"
#include "atari/gui.h"
#include "atari/toolbar.h"
-#include "atari/browser_win.h"
-#include "atari/browser.h"
+#include "atari/rootwin.h"
+
#include "atari/clipboard.h"
#include "atari/misc.h"
-#include "atari/global_evnt.h"
+#include "atari/browser.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" + +
+#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; + enum e_toolbar_button_states state;
+ short index; + GRECT area;
+};
extern char * option_homepage_url;
@@ -58,17 +92,17 @@ extern void * h_gem_rsrc; extern struct gui_window * input_window; extern long atari_plot_flags; extern int atari_plot_vdi_handle; +extern EVMULT_OUT aes_event_out; -static OBJECT * 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";
static uint32_t toolbar_bg_color = 0xFFFFFF; 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 +111,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 { @@ -140,628 +173,115 @@ static struct s_toolbar_style toolbar_styles[] = {18, 34, 64, 64, 2, 0, 0 }, /* custom style: */ {18, 34, 64, 64, 2, 0, 0 } -};
+}; + +static const struct redraw_context toolbar_rdrw_ctx = {
+ .interactive = true,
+ .background_images = true,
+ .plot = &atari_plotters
+ };
-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 ); +/** +* Find a button for a specific resource ID +*/ +static struct s_tb_button *find_button(struct s_toolbar *tb, int rsc_id)
+{
+ int i = 0;
+ while (i < tb->btcnt) {
+ if (tb->buttons[i].rsc_id == rsc_id) {
+ return(&tb->buttons[i]);
+ }
+ i++;
+ } + return(NULL);
+} -void toolbar_init( void ) +/** +* Callback for textarea redraw +*/ +static void tb_txt_request_redraw(void *data, int x, int y, int w, int h)
{ - int i=0, n; - short vdicolor[3]; - uint32_t rgbcolor; - 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; - if( img_toolbar ){ -
- char imgfile[PATH_MAX]; - const char * imgfiletmpl = "toolbar/%s/%s";
+ GRECT area; + struct s_toolbar * tb = (struct s_toolbar *)data; - while( tb_buttons[i].rsc_id != 0){ - tb_buttons[i].index = i; - i++; - } - snprintf( imgfile, PATH_MAX-1, imgfiletmpl, toolbar_image_folder, - "main.png" ); - toolbar_image = load_icon( imgfile, - toolbar_icon_callback, NULL ); - snprintf( imgfile, PATH_MAX-1, imgfiletmpl, toolbar_image_folder, - "throbber.png" ); - throbber_image = load_icon( imgfile, - 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; - }
- n = (sizeof( toolbar_styles ) / sizeof( struct s_toolbar_style ));
- for (i=0; i<n; i++) { - toolbar_styles[i].icon_bgcolor = ABGR_TO_RGB(toolbar_bg_color);
+ if (tb->attached == false) { + return; } -} -void toolbar_exit( void ) -{ - if( toolbar_image ) - hlcache_handle_release( toolbar_image ); - if( throbber_image ) - hlcache_handle_release( throbber_image ); + toolbar_get_grect(tb, TOOLBAR_URL_AREA, &area); + area.g_x += x; + area.g_y += y; + area.g_w = w; + area.g_h = h; + //dbg_grect("tb_txt_request_redraw", &area); + window_schedule_redraw_grect(tb->owner, &area); + return;
} -/** - * 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) +static struct s_tb_button *button_init(struct s_toolbar *tb, OBJECT * tree, int index, + struct s_tb_button * instance)
{ - 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; -} -
-
-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;
- } + *instance = tb_buttons[index]; + instance->owner = tb; - 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;
- } - } + instance->area.g_w = toolbar_styles[tb->style].icon_width + \ + ( toolbar_styles[tb->style].button_vmargin * 2); - /* 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 );
- }
-}
+ return(instance);
+} -static void __CDECL button_click( COMPONENT *c, long buff[8], void * data )
+void toolbar_init( void ) { - 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 );
-}
+ int i=0, n; + short vdicolor[3]; + uint32_t rgbcolor; -
-static struct s_tb_button * find_button( struct gui_window * gw, int rsc_id )
-{
- 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; + aes_toolbar = get_tree(TOOLBAR); + throbber_form = get_tree(THROBBER);
+} - *instance = tb_buttons[index]; - instance->gw = t->owner; - comp_width = toolbar_styles[t->style].icon_width + \ - ( toolbar_styles[t->style].button_vmargin * 2 ); +void toolbar_exit(void) +{ + if (toolbar_image) + hlcache_handle_release(toolbar_image); + if (throbber_image) + hlcache_handle_release(throbber_image); +} - 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;
-}
-
-
-static
-void __CDECL evnt_throbber_redraw( COMPONENT *c, long buff[8])
+struct s_toolbar *toolbar_create(struct s_gui_win_root *owner)
{
- 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 ); - }
+ int i; - 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 );
- } - }
+ LOG((""));
-}
-
-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 );
-}
- + struct s_toolbar *t = calloc(sizeof(struct s_toolbar), 1);
-void tb_adjust_size( struct gui_window * gw )
-{
- LGRECT work;
- CMP_TOOLBAR t = gw->root->toolbar;
-
- mt_CompGetLGrect( &app, t->url.comp, WF_WORKXYWH, &work);
- work.g_w -= (TOOLBAR_URL_MARGIN_LEFT + TOOLBAR_URL_MARGIN_RIGHT);
- /* do not overwrite the black border, because of that, add 1 */
- work.g_h -= (TOOLBAR_URL_MARGIN_TOP + TOOLBAR_URL_MARGIN_BOTTOM+1);
- textarea_set_dimensions( t->url.textarea, work.g_w, work.g_h );
- tb_txt_request_redraw( t, 0,0, work.g_w-1, work.g_h-1);
-}
-
-static void __CDECL evnt_toolbar_redraw( COMPONENT *c, long buff[8], void *data )
-{
- LGRECT work, clip;
- 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 );
+ assert(t);
- 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,207 +290,308 @@ 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 );
- 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 );
+ t->url.textarea = textarea_create(300, ta_height, 0, &font_style_url, + tb_txt_request_redraw, t);
/* 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; - } else { - 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.index = THROBBER_INACTIVE_INDEX;
+ t->throbber.max_index = THROBBER_MAX_INDEX;
+ 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_reflow(struct s_toolbar *tb) { -
-#define FIRST_BUTTON TOOLBAR_BT_BACK + int i; + + // 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; + + aes_toolbar[TOOLBAR_THROBBER_AREA].ob_x = tb->area.g_w + - aes_toolbar[TOOLBAR_THROBBER_AREA].ob_width; + + 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 + 1); + + + // position throbber image: + throbber_form[tb->throbber.index].ob_x = tb->area.g_x + + aes_toolbar[TOOLBAR_THROBBER_AREA].ob_x; + + 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); + + // set button states: + for (i=0; i < tb->btcnt; i++ ) { + if (tb->buttons[i].state == button_off) { + aes_toolbar[tb->buttons[i].rsc_id].ob_state |= OS_DISABLED; + } + else if (tb->buttons[i].state == button_on) { + aes_toolbar[tb->buttons[i].rsc_id].ob_state &= ~OS_DISABLED; + }
+ } + tb->reflow = false; + // TODO: iterate through all other toolbars and set reflow = true +} + +void toolbar_redraw(struct s_toolbar *tb, GRECT *clip) +{ + GRECT area; + + if (tb->attached == false) { + return; + } + + if(tb->reflow == true) + toolbar_reflow(tb); + + + objc_draw_grect(aes_toolbar,0,8,clip); + + objc_draw_grect(&throbber_form[tb->throbber.index], 0, 1, clip); + + GRECT url_area; + toolbar_get_grect(tb, TOOLBAR_URL_AREA, &area); + url_area = area; + if (rc_intersect(clip, &area)) { + + struct rect r = {
+ .x0 = 0,
+ .y0 = 0,
+ .x1 = url_area.g_w,
+ .y1 = url_area.g_h
+ }; + + r.x0 = area.g_x - url_area.g_x; + r.x1 = r.x0 + area.g_w; + plot_set_dimensions(url_area.g_x, url_area.g_y, url_area.g_w, + url_area.g_h); + textarea_redraw(tb->url.textarea, 0, 0, &r, &toolbar_rdrw_ctx); + } +} + + +void toolbar_update_buttons(struct s_toolbar *tb, struct browser_window *bw, + short button) +{ + LOG(("")); 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 ){
+ GRECT area; + + assert(bw != NULL); + + if (button == TOOLBAR_BT_BACK || button <= 0 ) { + bt = find_button(tb, TOOLBAR_BT_BACK); + enable = browser_window_back_available(bw);
+ if (enable) {
bt->state = button_on;
} else {
bt->state = button_off;
} - 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 ); + if (button == TOOLBAR_BT_HOME || button <= 0 ){
+ }
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 = find_button(tb, TOOLBAR_BT_FORWARD); + enable = browser_window_forward_available(bw);
+ if (enable) {
bt->state = button_on;
} else {
bt->state = button_off;
- } - mt_CompEvntRedraw( &app, bt->comp );
+ }
}
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 = find_button(tb, TOOLBAR_BT_RELOAD); + enable = browser_window_reload_available(bw);
+ if (enable) {
bt->state = button_on;
} else {
bt->state = button_off;
} - mt_CompEvntRedraw( &app, bt->comp ); }
- if( button == TOOLBAR_BT_STOP || button <= 0 ){
- bt = &gw->root->toolbar->buttons[TOOLBAR_BT_STOP-FIRST_BUTTON]; - enable = browser_window_stop_available(gw->browser->bw);
- if( enable ){
+ if (button == TOOLBAR_BT_STOP || button <= 0) { + bt = find_button(tb, TOOLBAR_BT_STOP); + enable = browser_window_stop_available(bw);
+ if (enable) {
bt->state = button_on;
} else {
bt->state = button_off;
} - mt_CompEvntRedraw( &app, bt->comp ); } -#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;
+ if (tb->attached) { + if (button > 0) { + toolbar_get_grect(tb, button, &area); + window_schedule_redraw_grect(tb->owner, &area); + } + else { + toolbar_get_grect(tb, TOOLBAR_NAVIGATION_AREA, &area); + window_schedule_redraw_grect(tb->owner, &area); + } + } +} + + +void toolbar_set_dimensions(struct s_toolbar *tb, GRECT *area) +{ + + + if (area->g_w != tb->area.g_w || area->g_h != tb->area.g_h) { + tb->area = *area; + /* reflow now, just for url input calucation: */ + toolbar_reflow(tb); + /* this will request an textarea redraw: */ + textarea_set_dimensions(tb->url.textarea, + aes_toolbar[TOOLBAR_URL_AREA].ob_width, + 20); + } + else { + tb->area = *area; + } + /* reflow for next redraw: */ + /* TODO: that's only required because we do not reset others toolbars reflow + state on reflow */ + tb->reflow = true; +} + + +void toolbar_set_url(struct s_toolbar *tb, const char * text) +{ + LOG(("")); + textarea_set_text(tb->url.textarea, text); + + if (tb->attached) { + GRECT area; + toolbar_get_grect(tb, TOOLBAR_URL_AREA, &area); + window_schedule_redraw_grect(tb->owner, &area); + struct gui_window * gw = window_get_active_gui_window(tb->owner); + assert(gw != NULL); + toolbar_update_buttons(tb, gw->browser->bw , 0); + } +} + +void toolbar_set_throbber_state(struct s_toolbar *tb, bool active) +{ + GRECT throbber_area; + + tb->throbber.running = active; + if (active) { + tb->throbber.index = THROBBER_MIN_INDEX; + } else { + tb->throbber.index = THROBBER_INACTIVE_INDEX; + } + + tb->reflow = true; + toolbar_get_grect(tb, TOOLBAR_THROBBER_AREA, &throbber_area); + window_schedule_redraw_grect(tb->owner, &throbber_area); +} + +void toolbar_set_attached(struct s_toolbar *tb, bool attached) +{ + tb->attached = attached; + +} + +void toolbar_throbber_progress(struct s_toolbar *tb) +{ + GRECT throbber_area; + + assert(tb->throbber.running == true); + + if(tb->throbber.running == false) + return; + + tb->throbber.index++; + if(tb->throbber.index > THROBBER_MAX_INDEX) + tb->throbber.index = THROBBER_MIN_INDEX; + + tb->reflow = true; + toolbar_get_grect(tb, TOOLBAR_THROBBER_AREA, &throbber_area); + window_schedule_redraw_grect(tb->owner, &throbber_area); +} + +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) +{ + assert(tb!=NULL);
- LGRECT work;
- bool ret = false;
+ GRECT work;
+ bool ret = false; + + struct gui_window *gw = window_get_active_gui_window(tb->owner);
assert( gw != NULL );
long ucs4;
- long ik = nkc_to_input_key( nkc, &ucs4 );
+ long ik = nkc_to_input_key(nkc, &ucs4);
- if( ik == 0 ){
- if ( (nkc&0xFF) >= 9 ) {
- ret = textarea_keypress( tb->url.textarea, ucs4 );
+ if (ik == 0) {
+ if ((nkc&0xFF) >= 9) {
+ ret = textarea_keypress(tb->url.textarea, ucs4);
}
}
- else if( ik == KEY_CR || ik == KEY_NL ){
+ 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);
+ if ( textarea_get_text( tb->url.textarea, tmp_url, PATH_MAX) > 0 ) {
+ window_set_focus(tb->owner, BROWSER, gw->browser);
browser_window_go(gw->browser->bw, (const char*)&tmp_url, 0, true);
ret = true;
}
}
- else if( ik == KEY_COPY_SELECTION ){
+ 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 ){
+ if (text){
textarea_get_text( tb->url.textarea, text, len+1 );
scrap_txt_write( &app, text );
free( text );
}
} - else if( ik == KEY_PASTE ){ + else if ( ik == KEY_PASTE) { char * clip = scrap_txt_read( &app );
- if( clip != NULL ){ + if ( clip != NULL ){ int clip_length = strlen( clip );
if ( clip_length > 0 ) {
char *utf8;
@@ -979,7 +600,7 @@ bool tb_url_input( struct gui_window * gw, short nkc ) * convert to UTF8 */
res = utf8_from_local_encoding( clip, clip_length, &utf8 );
if ( res == UTF8_CONVERT_OK ) {
- tb_url_set( gw, utf8 );
+ toolbar_set_url(tb, utf8);
free(utf8); ret = true;
}
@@ -987,7 +608,7 @@ bool tb_url_input( struct gui_window * gw, short nkc ) } } } - else if( ik == KEY_ESCAPE ) { + else if (ik == KEY_ESCAPE) { textarea_keypress( tb->url.textarea, KEY_SELECT_ALL ); textarea_keypress( tb->url.textarea, KEY_DELETE_LEFT ); }
@@ -995,57 +616,180 @@ bool tb_url_input( struct gui_window * gw, short nkc ) ret = textarea_keypress( tb->url.textarea, ik );
}
- return( ret );
-}
+ return( ret ); +} + + +void toolbar_mouse_input(struct s_toolbar *tb, short obj) +{ + LOG(("")); + GRECT work;
+ short mx, my, mb, kstat;
+ int old; + + if (obj==TOOLBAR_URL_AREA){ + + graf_mkstate( &mx, &my, &mb, &kstat ); + toolbar_get_grect(tb, TOOLBAR_URL_AREA, &work); + mx -= work.g_x;
+ my -= work.g_y; -void tb_back_click( struct gui_window * gw )
-{
- struct browser_window *bw = gw->browser->bw;
+ /* TODO: reset mouse state of browser window? */
+ /* select whole text when newly focused, otherwise set caret to + end of text */ + if (!window_url_widget_has_focus(tb->owner)) { + window_set_focus(tb->owner, URL_WIDGET, (void*)&tb->url ); + } + /* url widget has focus and mouse button is still pressed... */ + else if (mb & 1) { + + textarea_mouse_action(tb->url.textarea, BROWSER_MOUSE_DRAG_1,
+ mx, my );
+ short prev_x = mx;
+ short prev_y = my;
+ do {
+ if (abs(prev_x-mx) > 5 || abs(prev_y-my) > 5) {
+ textarea_mouse_action( tb->url.textarea,
+ BROWSER_MOUSE_HOLDING_1, mx, my );
+ prev_x = mx;
+ prev_y = my; + window_schedule_redraw_grect(tb->owner, &work); + window_process_redraws(tb->owner);
+ }
+ graf_mkstate( &mx, &my, &mb, &kstat );
+ mx = mx - (work.g_x + TOOLBAR_URL_MARGIN_LEFT);
+ my = my - (work.g_y + TOOLBAR_URL_MARGIN_TOP); + } while (mb & 1); - if( history_back_available(bw->history) )
+ textarea_drag_end( tb->url.textarea, 0, mx, my ); + } + else { + /* when execution reaches here, mouse input is a click or dclick */ + /* TODO: recognize click + shitoolbar_update_buttonsft key */
+ int mstate = BROWSER_MOUSE_PRESS_1;
+ if( (kstat & (K_LSHIFT|K_RSHIFT)) != 0 ){
+ mstate = BROWSER_MOUSE_MOD_1; + } + if( aes_event_out.emo_mclicks == 2 ){ + textarea_mouse_action( tb->url.textarea,
+ BROWSER_MOUSE_DOUBLE_CLICK | BROWSER_MOUSE_CLICK_1, mx, + my); + toolbar_get_grect(tb, TOOLBAR_URL_AREA, &work); + window_schedule_redraw_grect(tb->owner, &work); + } else { + textarea_mouse_action(tb->url.textarea,
+ BROWSER_MOUSE_PRESS_1, mx, my ); + } + } + } else { + struct s_tb_button *bt = find_button(tb, obj); + if (bt != NULL && bt->state != button_off) { + bt->cb_click(tb); + struct gui_window * gw = window_get_active_gui_window(tb->owner); + toolbar_update_buttons(tb, gw->browser->bw, + 0); + } + + } +} + + +/** +* Receive a specific region of the toolbar. +* @param tb - the toolbar pointer +* @param which - the area to retrieve: TOOLBAR_URL_AREA, +* TOOLBAR_NAVIGATION_AREA, +* TOOLBAR_THROBBER_AREA +* @param dst - GRECT pointer receiving the area. +*/ + +void toolbar_get_grect(struct s_toolbar *tb, short which, GRECT *dst) +{ + if (tb->reflow == true) { + toolbar_reflow(tb); + } + + objc_offset(aes_toolbar, which, &dst->g_x, &dst->g_y); + dst->g_w = aes_toolbar[which].ob_width; + dst->g_h = aes_toolbar[which].ob_height; + + //printf("Toolbar get grect (%d): ", which); + //dbg_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)
+{ + struct browser_window * bw; + struct gui_window * gw; + + gw = window_get_active_gui_window(tb->owner); + assert(gw != NULL); + bw = gw->browser->bw; + assert(bw != NULL); + + if( history_back_available(bw->history) )
history_back(bw, bw->history);
}
-void tb_reload_click( struct gui_window * gw )
+void toolbar_reload_click(struct s_toolbar *tb)
{ - browser_window_reload( gw->browser->bw, true );
+ struct browser_window * bw; + struct gui_window * gw; + + gw = window_get_active_gui_window(tb->owner); + assert(gw != NULL); + bw = gw->browser->bw; + assert(bw != NULL); + + browser_window_reload(bw, true);
}
-void tb_forward_click( struct gui_window * gw )
-{
- struct browser_window *bw = gw->browser->bw;
+void toolbar_forward_click(struct s_toolbar *tb)
+{ + struct browser_window * bw; + struct gui_window * gw; + + gw = window_get_active_gui_window(tb->owner); + assert(gw != NULL); + bw = gw->browser->bw; + assert(bw != NULL); +
if (history_forward_available(bw->history))
history_forward(bw, bw->history);
}
-void 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);
+ struct browser_window * bw; + struct gui_window * gw; + + gw = window_get_active_gui_window(tb->owner); + assert(gw != NULL); + bw = gw->browser->bw; + assert(bw != NULL); + browser_window_go(bw, option_homepage_url, 0, true);
}
-void tb_stop_click( struct gui_window * gw )
+void toolbar_stop_click(struct s_toolbar *tb)
{ - browser_window_stop(gw->browser->bw);
-} + struct browser_window * bw; + struct gui_window * gw; + gw = window_get_active_gui_window(tb->owner); + assert(gw != NULL); + bw = gw->browser->bw; + assert(bw != NULL); + + browser_window_stop(bw);
+} -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..d13b59c6b 100755..100644 --- a/atari/toolbar.h +++ b/atari/toolbar.h @@ -1,118 +1,76 @@ -/*
- * 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" + +struct s_toolbar; + +enum toolbar_textarea { + URL_INPUT_TEXT_AREA = 1 +}; -#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 */
+{ + /* widget is only redrawn when this flag is set */
+ bool redraw;
struct text_area *textarea; - COMPONENT * comp; - GRECT rdw_area;
-};
-
+ GRECT rdw_area; + GRECT area;
+}; + struct s_throbber_widget
{
- COMPONENT * comp;
short index;
short max_index;
- bool running;
+ bool running; + GRECT area;
};
struct s_toolbar
{
- COMPONENT * comp;
- struct gui_window * owner; + struct s_gui_win_root *owner; struct s_url_widget url;
struct s_throbber_widget throbber; - GRECT btdim;
+ GRECT btdim; + GRECT area;
/* size & location of buttons: */ struct s_tb_button * buttons; - bool hidden;
+ bool attached;
int btcnt; int style; - bool redraw;
-};
+ bool redraw; + bool reflow;
+}; -/* 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 obj); +void toolbar_update_buttons(struct s_toolbar *tb, struct browser_window *bw, + short idx); +void toolbar_get_grect(struct s_toolbar *tb, short which, GRECT *g); +struct text_area *toolbar_get_textarea(struct s_toolbar *tb, + enum toolbar_textarea which); +void toolbar_set_throbber_state(struct s_toolbar *tb, bool active); +void toolbar_set_attached(struct s_toolbar *tb, bool attached); +void toolbar_redraw(struct s_toolbar *tb, GRECT *clip); +void toolbar_throbber_progress(struct s_toolbar *tb); +/* 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..52859e306 100755 --- a/atari/treeview.c +++ b/atari/treeview.c @@ -1,446 +1,547 @@ -/*
- * 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 ) { + on_keybd_event(tv, ev_out, msg); + } + 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)); + 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 |