From c415f9bf989f83c7ced6bb930e3421dab6f4093b Mon Sep 17 00:00:00 2001 From: Ole Loots Date: Sun, 18 Nov 2012 23:22:43 +0100 Subject: Start to remove windom, wip. - Refactored menu event handling. - Load plain GEM resources. - Refactored Event handling --- atari/browser.c | 2 +- atari/ctxmenu.c | 2 +- atari/deskmenu.c | 660 +++++++++++++++ atari/deskmenu.h | 12 + atari/findfile.c | 1 + atari/gemtk/dragdrop.c | 516 ++++++++++++ atari/gemtk/dragdrop.h | 4 + atari/gemtk/gemtk.h | 100 +++ atari/gemtk/guiwin.c | 301 +++++++ atari/gemtk/guiwin.h | 5 + atari/gemtk/msgbox.c | 84 ++ atari/gemtk/msgbox.h | 5 + atari/gemtk/utils.c | 45 + atari/gemtk/utils.h | 5 + atari/global_evnt.c | 536 +----------- atari/global_evnt.h | 23 +- atari/gui.c | 2178 +++++++++++++++++++++++++----------------------- atari/hotlist.c | 1 + atari/misc.c | 56 +- atari/misc.h | 4 +- atari/osspec.c | 35 +- atari/osspec.h | 28 +- atari/redrawslots.c | 2 +- atari/rootwin.c | 816 ++++++++++++++++++ atari/rootwin.h | 70 ++ atari/search.c | 16 +- atari/settings.c | 9 +- atari/statusbar.c | 3 +- atari/toolbar.c | 10 +- atari/treeview.c | 42 +- 30 files changed, 3864 insertions(+), 1707 deletions(-) create mode 100644 atari/deskmenu.c create mode 100644 atari/deskmenu.h create mode 100755 atari/gemtk/dragdrop.c create mode 100755 atari/gemtk/dragdrop.h create mode 100644 atari/gemtk/gemtk.h create mode 100644 atari/gemtk/guiwin.c create mode 100644 atari/gemtk/guiwin.h create mode 100644 atari/gemtk/msgbox.c create mode 100644 atari/gemtk/msgbox.h create mode 100644 atari/gemtk/utils.c create mode 100644 atari/gemtk/utils.h create mode 100755 atari/rootwin.c create mode 100755 atari/rootwin.h (limited to 'atari') diff --git a/atari/browser.c b/atari/browser.c index 034f89a64..1b3661ecf 100755 --- a/atari/browser.c +++ b/atari/browser.c @@ -45,7 +45,7 @@ #include "utils/messages.h" #include "atari/gui.h" -#include "atari/browser_win.h" +#include "atari/rootwin.h" #include "atari/misc.h" #include "atari/global_evnt.h" #include "atari/res/netsurf.rsh" diff --git a/atari/ctxmenu.c b/atari/ctxmenu.c index 1a1755b12..6239f216e 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" diff --git a/atari/deskmenu.c b/atari/deskmenu.c new file mode 100644 index 000000000..d486803f8 --- /dev/null +++ b/atari/deskmenu.c @@ -0,0 +1,660 @@ +#include +#include + +#include "utils/log.h" +#include "utils/messages.h" +#include "utils/url.h" +#include "desktop/browser.h" +#include "desktop/browser_private.h" +#include "desktop/options.h" +#include "desktop/save_complete.h" + +#include "atari/res/netsurf.rsh" +#include "atari/gemtk/gemtk.h" +#include "atari/deskmenu.h" +#include "atari/hotlist.h" +#include "atari/history.h" +#include "atari/toolbar.h" +#include "atari/settings.h" +#include "atari/search.h" +#include "atari/misc.h" +#include "atari/gui.h" +#include "atari/findfile.h" +#include "atari/browser.h" +#include "atari/rootwin.h" + +typedef void __CDECL (*menu_evnt_func)(short item, short title, void * data); + +struct s_accelerator +{ + char ascii; /* either ascii or */ + long keycode; /* normalised keycode is valid */ + short mod; /* shift / ctrl etc */ +}; + +struct s_menu_item_evnt { + short title; /* to which menu this item belongs */ + short rid; /* resource ID */ + menu_evnt_func menu_func; /* click handler */ + struct s_accelerator accel; /* accelerator info */ + char * menustr; +}; + +static void register_menu_str(struct s_menu_item_evnt * mi); +static void __CDECL evnt_menu(WINDOW * win, short buff[8]); + +extern void *h_gem_rsrc; +extern bool html_redraw_debug; +extern struct gui_window * input_window; +extern char options[PATH_MAX]; +extern const char * option_homepage_url; +extern int option_window_width; +extern int option_window_height; +extern int option_window_x; +extern int option_window_y; + +static OBJECT * h_gem_menu; + + +/* Zero based resource tree ids: */ +#define T_ABOUT 0 +#define T_FILE MAINMENU_T_FILE - MAINMENU_T_FILE + 1 +#define T_EDIT MAINMENU_T_EDIT - MAINMENU_T_FILE + 1 +#define T_VIEW MAINMENU_T_VIEW - MAINMENU_T_FILE + 1 +#define T_NAV MAINMENU_T_NAVIGATE - MAINMENU_T_FILE + 1 +#define T_UTIL MAINMENU_T_UTIL - MAINMENU_T_FILE + 1 +#define T_HELP MAINMENU_T_NAVIGATE - MAINMENU_T_FILE + 1 +/* Count of the above defines: */ +#define NUM_MENU_TITLES 7 + + +static void __CDECL menu_about(short item, short title, void *data); +static void __CDECL menu_new_win(short item, short title, void *data); +static void __CDECL menu_open_url(short item, short title, void *data); +static void __CDECL menu_open_file(short item, short title, void *data); +static void __CDECL menu_close_win(short item, short title, void *data); +static void __CDECL menu_save_page(short item, short title, void *data); +static void __CDECL menu_quit(short item, short title, void *data); +static void __CDECL menu_cut(short item, short title, void *data); +static void __CDECL menu_copy(short item, short title, void *data); +static void __CDECL menu_paste(short item, short title, void *data); +static void __CDECL menu_find(short item, short title, void *data); +static void __CDECL menu_choices(short item, short title, void *data); +static void __CDECL menu_stop(short item, short title, void *data); +static void __CDECL menu_reload(short item, short title, void *data); +static void __CDECL menu_toolbars(short item, short title, void *data); +static void __CDECL menu_savewin(short item, short title, void *data); +static void __CDECL menu_debug_render(short item, short title, void *data); +static void __CDECL menu_fg_images(short item, short title, void *data); +static void __CDECL menu_bg_images(short item, short title, void *data); +static void __CDECL menu_back(short item, short title, void *data); +static void __CDECL menu_forward(short item, short title, void *data); +static void __CDECL menu_home(short item, short title, void *data); +static void __CDECL menu_lhistory(short item, short title, void *data); +static void __CDECL menu_ghistory(short item, short title, void *data); +static void __CDECL menu_add_bookmark(short item, short title, void *data); +static void __CDECL menu_bookmarks(short item, short title, void *data); +static void __CDECL menu_vlog(short item, short title, void *data); +static void __CDECL menu_help_content(short item, short title, void *data); + +struct s_menu_item_evnt menu_evnt_tbl[] = +{ + {T_ABOUT,MAINMENU_M_ABOUT, menu_about, {0,0,0}, NULL }, + {T_FILE, MAINMENU_M_NEWWIN, menu_new_win, {0,0,0}, NULL}, + {T_FILE, MAINMENU_M_OPENURL, menu_open_url, {'G',0,K_CTRL}, NULL}, + {T_FILE, MAINMENU_M_OPENFILE, menu_open_file, {'O',0,K_CTRL}, NULL}, + {T_FILE, MAINMENU_M_CLOSEWIN, menu_close_win, {0,0,0}, NULL}, + {T_FILE, MAINMENU_M_SAVEPAGE, menu_save_page, {0,NK_F3,0}, NULL}, + {T_FILE, MAINMENU_M_QUIT, menu_quit, {'Q',0,K_CTRL}, NULL}, + {T_EDIT, MAINMENU_M_CUT, menu_cut, {'X',0,K_CTRL}, NULL}, + {T_EDIT, MAINMENU_M_COPY, menu_copy, {'C',0,K_CTRL}, NULL}, + {T_EDIT, MAINMENU_M_PASTE, menu_paste, {'V',0,K_CTRL}, NULL}, + {T_EDIT, MAINMENU_M_FIND, menu_find, {0,NK_F4,0}, NULL}, + {T_VIEW, MAINMENU_M_RELOAD, menu_reload, {0,NK_F5,0}, NULL}, + {T_VIEW, MAINMENU_M_TOOLBARS, menu_toolbars, {0,NK_F1,K_CTRL}, NULL}, + {T_VIEW, MAINMENU_M_SAVEWIN, menu_savewin, {0,0,0}, NULL}, + {T_VIEW, MAINMENU_M_DEBUG_RENDER, menu_debug_render, {0,0,0}, NULL}, + {T_VIEW, MAINMENU_M_FG_IMAGES, menu_fg_images, {0,0,0}, NULL}, + {T_VIEW, MAINMENU_M_BG_IMAGES, menu_bg_images, {0,0,0}, NULL}, + {T_VIEW, MAINMENU_M_STOP, menu_stop, {0,NK_ESC,K_ALT}, NULL}, + {T_NAV, MAINMENU_M_BACK, menu_back, {0,NK_LEFT,K_ALT}, NULL}, + {T_NAV, MAINMENU_M_FORWARD, menu_forward, {0,NK_RIGHT,K_ALT}, NULL}, + {T_NAV, MAINMENU_M_HOME, menu_home, {0,NK_CLRHOME,0}, NULL}, + {T_UTIL, MAINMENU_M_LHISTORY,menu_lhistory, {0,NK_F7,0}, NULL}, + {T_UTIL, MAINMENU_M_GHISTORY, menu_ghistory, {0,NK_F7,K_CTRL}, NULL}, + {T_UTIL, MAINMENU_M_ADD_BOOKMARK, menu_add_bookmark, {'D',0,K_CTRL}, NULL}, + {T_UTIL, MAINMENU_M_BOOKMARKS, menu_bookmarks, {0,NK_F6,0}, NULL}, + {T_UTIL, MAINMENU_M_CHOICES, menu_choices, {0,0,0}, NULL}, + {T_UTIL, MAINMENU_M_VLOG, menu_vlog, {'V',0,K_ALT}, NULL}, + {T_HELP, MAINMENU_M_HELP_CONTENT, menu_help_content, {0,NK_F1,0}, NULL}, + {-1, -1, NULL,{0,0,0}, NULL } +}; + + +/* + Parse encoded menu key shortcut + + The format is: + + "[" - marks start of the shortcut + "@,^,<" - If the keyshortcut is only valid + with modifier keys, one of these characters must directly + follow the start mark. + Meaning: + @ -> Alternate + ^ -> Control + "#" - keycode or ascii character. + The value is handled as keycode if the character value + is <= 28 ( Atari chracter table ) + or if it is interpreted as function key string. + (strings: F1 - F10) + +*/ +static void register_menu_str( struct s_menu_item_evnt * mi ) +{ + OBJECT *gem_menu = deskmenu_get_obj_tree(); + + assert(gem_menu != NULL); + + char * str = ObjcString( gem_menu, mi->rid, NULL ); + int l = strlen(str); + int i = l; + int x = -1; + struct s_accelerator * accel = &mi->accel; + + while (i > 2) { + if( str[i] == '['){ + x = i; + break; + } + i--; + } + if( x > -1 ){ + mi->menustr = malloc( l+1 ); + strcpy(mi->menustr, str ); + mi->menustr[x]=' '; + x++; + if( str[x] == '@' ){ + accel->mod = K_ALT; + mi->menustr[x] = 0x07; + x++; + } + else if( str[x] == '^' ) { + accel->mod = K_CTRL; + x++; + } + if( str[x] <= 28 ){ + // parse symbol + unsigned short keycode=0; + switch( str[x] ){ + case 0x03: + accel->keycode = NK_RIGHT; + break; + case 0x04: + accel->keycode = NK_LEFT; + break; + case 0x1B: + accel->keycode = NK_ESC; + break; + default: + break; + } + } else { + if(str[x] == 'F' && ( str[x+1] >= '1' && str[x+1] <= '9') ){ + // parse function key + short fkey = atoi( &str[x+1] ); + if( (fkey >= 0) && (fkey <= 10) ){ + accel->keycode = NK_F1 - 1 + fkey; + } + } else { + accel->ascii = str[x]; + } + } + } +} + +static void __CDECL evnt_menu(WINDOW * win, short buff[8]) +{ + int title = buff[3]; + INT16 x,y; + char *str; + struct gui_window * gw = window_list; + int i=0; + + deskmenu_dispatch_item(buff[3], buff[4]); +} + +/* + Menu item event handlers: +*/ + +static void __CDECL menu_about(short item, short title, void *data) +{ + LOG(("%s", __FUNCTION__)); + char buf[PATH_MAX]; + strcpy((char*)&buf, "file://"); + strncat((char*)&buf, (char*)"./doc/README.TXT", + PATH_MAX - (strlen("file://")+1) ); + browser_window_create((char*)&buf, 0, 0, true, false); +} + +static void __CDECL menu_new_win(short item, short title, void *data) +{ + LOG(("%s", __FUNCTION__)); + browser_window_create(option_homepage_url, 0, 0, true, false); +} + +static void __CDECL menu_open_url(short item, short title, void *data) +{ + struct gui_window * gw; + struct browser_window * bw ; + LOG(("%s", __FUNCTION__)); + + gw = input_window; + if( gw == NULL ) { + bw = browser_window_create("", 0, 0, true, false); + gw = bw->window; + + } + /* Loose focus: */ + window_set_focus( gw, 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(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; + tb_stop_click( input_window ); + +} + +static void __CDECL menu_reload(short item, short title, void *data) +{ + if( input_window == NULL) + return; + tb_reload_click( input_window ); + 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; + tb_hide( input_window, 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(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(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) { + 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(short item, short title, void *data) +{ + nsoption_set_bool(foreground_images, !nsoption_bool(foreground_images)); + MenuIcheck( NULL, MAINMENU_M_FG_IMAGES, + (nsoption_bool(foreground_images)) ? 1 : 0); +} + +static void __CDECL menu_bg_images(short item, short title, void *data) +{ + nsoption_set_bool(background_images, !nsoption_bool(background_images)); + MenuIcheck( NULL, MAINMENU_M_BG_IMAGES, + (nsoption_bool(background_images)) ? 1 : 0); +} + +static void __CDECL menu_back(short item, short title, void *data) +{ + LOG(("%s", __FUNCTION__)); + if( input_window == NULL ) + return; + tb_back_click( input_window ); +} + +static void __CDECL menu_forward(short item, short title, void *data) +{ + LOG(("%s", __FUNCTION__)); + if( input_window == NULL ) + return; + tb_forward_click( input_window ); +} + +static void __CDECL menu_home(short item, short title, void *data) +{ + LOG(("%s", __FUNCTION__)); + if( input_window == NULL ) + return; + tb_home_click( input_window ); +} + +static void __CDECL menu_lhistory(short item, short title, void *data) +{ + LOG(("%s", __FUNCTION__)); + if( input_window == NULL ) + return; +} + +static void __CDECL menu_ghistory(short item, short title, void *data) +{ + LOG(("%s", __FUNCTION__)); + global_history_open(); +} + +static void __CDECL menu_add_bookmark(short item, short title, void *data) +{ + LOG(("%s", __FUNCTION__)); + if (input_window) { + if( input_window->browser->bw->current_content != NULL ){ + atari_hotlist_add_page( + nsurl_access(hlcache_handle_get_url(input_window->browser->bw->current_content)), + NULL + ); + } + } +} + +static void __CDECL menu_bookmarks(short item, short title, void *data) +{ + LOG(("%s", __FUNCTION__)); + hotlist_open(); +} + +static void __CDECL menu_vlog(short item, short title, void *data) +{ + LOG(("%s", __FUNCTION__)); + verbose_log = !verbose_log; + MenuIcheck(NULL, MAINMENU_M_VLOG, (verbose_log) ? 1 : 0 ); +} + +static void __CDECL menu_help_content(short item, short title, void *data) +{ + LOG(("%s", __FUNCTION__)); +} + +/* + Public deskmenu interface: +*/ + + +/** +* Setup & display an desktop menu. +*/ + +void deskmenu_init(void) +{ + int i; + + h_gem_menu = get_tree(MAINMENU); + + // TODO: remove that call somehow... + + /* parse and update menu items: */ + i = 0; + while( menu_evnt_tbl[i].rid != -1 ) { + char * str = ObjcString(h_gem_menu, menu_evnt_tbl[i].rid, NULL ); + register_menu_str( &menu_evnt_tbl[i] ); + /* Update menu string if not null: */ + if( menu_evnt_tbl[i].menustr != NULL ){ + menu_text(h_gem_menu, menu_evnt_tbl[i].rid, + menu_evnt_tbl[i].menustr); + } + i++; + } + deskmenu_update(); + + /* Install menu: */ + menu_bar(h_gem_menu, MENU_INSTALL); + /* Redraw menu: */ + menu_bar(h_gem_menu, MENU_UPDATE); +} + +/** +* Uninstall the desktop menu +*/ +void deskmenu_destroy(void) +{ + int i; + + /* Remove menu from desktop: */ + menu_bar(h_gem_menu, MENU_REMOVE); + + /* Free modified menu titles: */ + i=0; + while(menu_evnt_tbl[i].rid != -1) { + if( menu_evnt_tbl[i].menustr != NULL ) + free(menu_evnt_tbl[i].menustr); + i++; + } +} + +/** +* Return the deskmenu AES OBJECT tree +*/ +OBJECT * deskmenu_get_obj_tree(void) +{ + return(h_gem_menu); +} + +/** +* Handle an menu item event +*/ +int deskmenu_dispatch_item(short title, short item) +{ + int i=0; + int retval = 0; + OBJECT * menu_root = deskmenu_get_obj_tree(); + + menu_tnormal(menu_root, item, 1); + menu_tnormal(menu_root, title, 1); + menu_bar(menu_root, 1); + + // legacy code, is this sensible?: + /* + while( gw ) { + window_set_focus( gw, WIDGET_NONE, NULL ); + gw = gw->next; + } + */ + + + while (menu_evnt_tbl[i].rid != -1) { + if (menu_evnt_tbl[i].rid == item) { + if (menu_evnt_tbl[i].menu_func != NULL) { + menu_evnt_tbl[i].menu_func(item, title, NULL); + } + break; + } + i++; + } + + return(retval); +} + +/** +* Handle an keypress (check for accelerator) +*/ +int deskmenu_dispatch_keypress(unsigned short kcode, unsigned short kstate, + unsigned short nkc) +{ + char sascii; + bool done = 0; + int i = 0; + + sascii = keybd2ascii(kcode, K_LSHIFT); + + /* Iterate through the menu function table: */ + while( menu_evnt_tbl[i].rid != -1 && done == false) { + if( kstate == menu_evnt_tbl[i].accel.mod + && menu_evnt_tbl[i].accel.ascii != 0) { + if( menu_evnt_tbl[i].accel.ascii == sascii) { + deskmenu_dispatch_item(menu_evnt_tbl[i].title, + menu_evnt_tbl[i].rid); + done = true; + break; + } + } else { + /* the accel code hides in the keycode: */ + if( menu_evnt_tbl[i].accel.keycode != 0) { + if( menu_evnt_tbl[i].accel.keycode == (nkc & 0xFF) && + kstate == menu_evnt_tbl[i].accel.mod) { + deskmenu_dispatch_item(menu_evnt_tbl[i].title, + menu_evnt_tbl[i].rid); + done = true; + break; + } + } + } + i++; + } + return((done==true) ? 1 : 0); +} + +/** +* Refresh the desk menu, reflecting netsurf current state. +*/ +void deskmenu_update(void) +{ + OBJECT * gem_menu = deskmenu_get_obj_tree(); + + menu_icheck(gem_menu, MAINMENU_M_DEBUG_RENDER, (html_redraw_debug) ? 1 : 0); + menu_icheck(gem_menu, MAINMENU_M_FG_IMAGES, + (nsoption_bool(foreground_images)) ? 1 : 0); + menu_icheck(gem_menu, MAINMENU_M_BG_IMAGES, + (nsoption_bool(background_images)) ? 1 : 0); +} + diff --git a/atari/deskmenu.h b/atari/deskmenu.h new file mode 100644 index 000000000..6ab00dcc9 --- /dev/null +++ b/atari/deskmenu.h @@ -0,0 +1,12 @@ +#ifndef DESKMENU_H_INCLUDED +#define DESKMENU_H_INCLUDED + +void deskmenu_init(void); +void deskmenu_destroy(void); +int deskmenu_dispatch_item(short title, short item); +int deskmenu_dispatch_keypress(unsigned short kcode, unsigned short kstate, + unsigned short nkc); +OBJECT * deskmenu_get_obj_tree(void); +void deskmenu_update( void ); + +#endif // DESKMENU_H_INCLUDED diff --git a/atari/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/gemtk/dragdrop.c b/atari/gemtk/dragdrop.c new file mode 100755 index 000000000..d9fd9c723 --- /dev/null +++ b/atari/gemtk/dragdrop.c @@ -0,0 +1,516 @@ +/* +* Routine pour Drag and drop sous MultiTos +* source: D&D Atari, demo OEP (Alexander Lorenz) +* +* Struktur OEP (oep.apid): AES-ID der Applikation +* +* (Tab = 4) +*/ + +#ifdef __PUREC__ +#include +#else +#include +#include +#include +#endif + +#include +#include + +//#include "windom.h" +#include "gemtk.h" +#include "cflib.h" + +#ifndef EACCDN +#define EACCDN (-36) +#endif + +#ifndef FA_HIDDEN +#define FA_HIDDEN 0x02 +#endif + +static char pipename[] = "U:\\PIPE\\DRAGDROP.AA"; +static long pipesig; + +/* +* Routinen fr den Sender +*/ + +/* +* Erzeugt Pipe fr D&D +* +* Eingabeparameter: +* pipe - Pointer auf 2 Byte Buffer fr Pipeextension +* +* Ausgabeparameters: +* keine +* +* Returnwert: +* >0: Filehandle der Pipe +* -1: Fehler beim Erzeugen der Pipe +*/ + +short ddcreate(short *pipe) +{ + long fd = -1; + + pipename[17] = 'A'; + pipename[18] = 'A' - 1; + + do /* ouvre un pipe inoccup‚ */ + { + pipename[18]++; + if (pipename[18] > 'Z') + { + pipename[17]++; + if (pipename[17] > 'Z') + break; + else + pipename[18] = 'A'; + } + + /* FA_HIDDEN fr Pipe notwendig! */ + + fd = Fcreate(pipename, FA_HIDDEN); + + } while (fd == (long) EACCDN); + + if (fd < 0L) + return(-1); + + *pipe = (pipename[17] << 8) | pipename[18]; + + + /* Signalhandler konfigurieren */ + + ddgetsig(&pipesig); + + + return((short) fd); +} + + + +/* +* Sendet AP_DRAGDROP an Empf„ngerapplikation +* +* Eingabeparameter: +* apid - AES-ID der Emf„ngerapp. +* fd - Filehandle der D&D-Pipe +* winid - Handle des Zielfensters (0 fr Desktopfenster) +* mx/my - Maus X und Y Koord. +* (-1/-1 fr einen fake Drag&Drop) +* kstate - Sondertastenstatus +* pipename - Extension der D&D-Pipe +* +* Ausgabeparameter: +* keine +* +* Returnwert: +* >0: kein Fehler +* -1: Empf„ngerapp. gibt DD_NAK zurck +* -2: Empf„ngerapp. antwortet nicht (Timeout) +* -3: Fehler bei appl_write() +*/ + +short ddmessage(short apid, short fd, short winid, short mx, short my, short kstate, short pipeid) +{ + char c; + short i, msg[8]; + long fd_mask; + + + /* AES-Message define and post */ + + msg[0] = AP_DRAGDROP; + msg[1] = _AESapid; + msg[2] = 0; + msg[3] = winid; + msg[4] = mx; + msg[5] = my; + msg[6] = kstate; + msg[7] = pipeid; + + i = appl_write(apid, 16, msg); + + if (i == 0) + { + ddclose(fd); + return(-3); + } + + + /* receiver reaction */ + + fd_mask = (1L << fd); + i = Fselect(DD_TIMEOUT, &fd_mask, 0L, 0L); + if (!i || !fd_mask) + { + /* Timeout eingetreten */ + + ddclose(fd); + return(-2); + } + + + /* le recepteur refuse (lecture du pipe) */ + + if (Fread(fd, 1L, &c) != 1L) + { + ddclose(fd); + return(-1); + } + + if (c != DD_OK) + { + ddclose(fd); + return(-1); + } + + return(1); +} + + + +/* +* Liest die 8 "bevorzugten" Extensionen der Empf„ngerapplikation +* +* Eingabeparameter: +* fd - Filehandle der D&D-Pipe +* +* Ausgabeparameters: +* exts - 32 Bytebuffer fr die 8 bevorzugten Extensionen +* der Zielapp. +* +* Returnwert: +* >0: kein Fehler +* -1: Fehler beim Lesen aus der Pipe +*/ + +short ddrexts(short fd, char *exts) +{ + if (Fread(fd, DD_EXTSIZE, exts) != DD_EXTSIZE) + { + ddclose(fd); + return(-1); + } + + return(1); +} + + + +/* +* Testet, ob der Empf„nger einen Datentyp akzeptiert +* +* Eingabeparameter: +* fd - Filehandle (von ddcreate()) +* ext - Zeiger auf Datentyp (4 Bytes zB. "ARGS") +* text - Zeiger auf Datenbeschreibung (optional, zB. "DESKTOP args") +* name - Zeiger auf Datendateiname (optional, zB. "SAMPLE.TXT") +* size - Anzahl Bytes der zu sendenden Daten +* +* Ausgabeparameter: +* keine +* +* Returnwert: +* DD_OK - Empf„nger akzeptiert Datentyp +* DD_NAK - Empf„nger brach Drag&Drop ab +* DD_EXT - Empf„nger lehnt Datentyp ab +* DD_LEN - Empf„nger kann Datenmenge nicht verarbeiten +* DD_TRASH - Drop erfolgte auf Mlleimer +* DD_PRINTER - Drop erfolgte auf Drucker +* DD_CLIPBOARD - Drop erfolgte auf Clipboard +*/ + +short ddstry(short fd, char *ext, char *text, char *name, long size) +{ + char c; + short hdrlen, i; + + /* 4 Bytes fr "ext", 4 Bytes fr "size", + 2 Bytes fr Stringendnullen */ + + hdrlen = (short) (4 + 4 + strlen(text)+1 + strlen(name)+1); + + + /* Header senden */ + + if (Fwrite(fd, 2L, &hdrlen) != 2L) + return(DD_NAK); + + i = (short) Fwrite(fd, 4L, ext); + i += (short) Fwrite(fd, 4L, &size); + i += (short) Fwrite(fd, strlen(text)+1, text); + i += (short) Fwrite(fd, strlen(name)+1, name); + + if (i != hdrlen) + return(DD_NAK); + + + /* auf die Antwort warten */ + + if (Fread(fd, 1L, &c) != 1L) + return(DD_NAK); + + return(c); +} + + + +/* Routinen fr Sender und Empf„nger */ + +/* +* Pipe schliežen (Drag&Drop beenden/abbrechen) +*/ + +void ddclose(short fd) +{ + /* Signalhandler restaurieren */ + + ddsetsig(pipesig); + + + Fclose(fd); +} + + +/* +* Signalhandler fr D&D konfigurieren +* +* Eingabeparameter: +* oldsig - Zeiger auf 4 Byte Puffer fr alten Handlerwert +* +* Ausgabeparameter: +* keine +* +* Returnwerte: +* keine +*/ + +void ddgetsig(long *oldsig) +{ + *oldsig = (long) Psignal(SIGPIPE, (void *) SIG_IGN); +} + + +/* +* Signalhandler nach D&D restaurieren +* +* Eingabeparameter: +* oldsig - Alter Handlerwert (von ddgetsig) +* +* Ausgabeparameter: +* keine +* +* Returnwerte: +* keine +*/ + +void ddsetsig(long oldsig) +{ + if (oldsig != -32L) + Psignal(SIGPIPE, (void *) oldsig); +} + + + +/* Routinen fr Empf„nger */ + +/* +* Drag&Drop Pipe ”ffnen +* +* Eingabeparameter: +* ddnam - Extension der Pipe (letztes short von AP_DRAGDROP) +* ddmsg - DD_OK oder DD_NAK +* +* Ausgabeparameter: +* keine +* +* Returnwerte: +* >0 - Filehandle der Drag&Drop pipe +* -1 - Drag&Drop abgebrochen +*/ + +short ddopen(short ddnam, char ddmsg) +{ + long fd; + + pipename[17] = (ddnam & 0xff00) >> 8; + pipename[18] = ddnam & 0x00ff; + + fd = Fopen(pipename, 2); + + if (fd < 0L) + return(-1); + + + /* Signalhandler konfigurieren */ + + ddgetsig(&pipesig); + + + if (Fwrite((short) fd, 1L, &ddmsg) != 1L) + { + ddclose((short) fd); + return(-1); + } + + return((short) fd); +} + + + +/* +* Schreibt die 8 "bevorzugten" Extensionen der Applikation +* +* Eingabeparameter: +* fd - Filehandle der D&D-Pipe +* exts - Liste aus acht 4 Byte Extensionen die verstanden +* werden. Diese Liste sollte nach bevorzugten Datentypen +* sortiert sein. Sollten weniger als DD_NUMEXTS +* Extensionen untersttzt werden, muž die Liste mit +* Nullen (0) aufgefllt werden! +* +* Ausgabeparameter: +* keine +* +* Returnwert: +* >0: kein Fehler +* -1: Fehler beim Schreiben in die Pipe +*/ + +short ddsexts(short fd, char *exts) +{ + if (Fwrite(fd, DD_EXTSIZE, exts) != DD_EXTSIZE) + { + ddclose(fd); + return(-1); + } + + return(1); +} + + + +/* +* N„chsten Header vom Sender holen +* +* Eingabeparameter: +* fd - Filehandle der Pipe (von ddopen()) +* +* Ausgabeparameters: +* name - Zeiger auf Buffer fr Datenbeschreibung (min. DD_NAMEMAX!) +* file - Zeiger auf Buffer fr Datendateiname (min. DD_NAMEMAX!) +* whichext- Zeiger auf Buffer fr Extension (4 Bytes) +* size - Zeiger auf Buffer fr Datengr”že (4 Bytes) +* +* Returnwert: +* >0: kein Fehler +* -1: Sender brach Drag&Drop ab +* +* On lit dans le pipe qui normalement est constitu‚ de: +* 1 short: taille du header +* 4 CHAR: type de donn‚e (extension) +* 1 long: taille des donn‚es +* STRING: description des donn‚es +* STRING: nom du fichiers +* soit au minimun 11 octets (cas ou les string sont r‚duites … \0) +* les string sont limit‚ a 128 octets +*/ + +short ddrtry(short fd, char *name, char *file, char *whichext, long *size) +{ + char buf[DD_NAMEMAX * 2]; + short hdrlen, i, len; + + if (Fread(fd, 2L, &hdrlen) != 2L) + return(-1); + + + if (hdrlen < 9) /* il reste au minimum 11 - 2 = 9 octets a lire */ + { + /* sollte eigentlich nie passieren */ + + return(-1); /* erreur taille incorrecte */ + } + + if (Fread(fd, 4L, whichext) != 4L) /* lecture de l'extension */ + return(-1); + + if (Fread(fd, 4L, size) != 4L) /* lecture de la longueurs des donn‚es */ + return(-1); + + hdrlen -= 8; /* on a lu 8 octets */ + + if (hdrlen > DD_NAMEMAX*2) + i = DD_NAMEMAX*2; + else + i = hdrlen; + + len = i; + + if (Fread(fd, (long) i, buf) != (long) i) + return(-1); + + hdrlen -= i; + + strncpy(name, buf, DD_NAMEMAX); + + i = (short) strlen(name) + 1; + + if (len - i > 0) + strncpy(file, buf + i, DD_NAMEMAX); + else + file[0] = '\0'; + + + /* weitere Bytes im Header in den Mll */ + + while (hdrlen > DD_NAMEMAX*2) + { + if (Fread(fd, DD_NAMEMAX*2, buf) != DD_NAMEMAX*2) + return(-1); + + hdrlen -= DD_NAMEMAX*2; + } + + if (hdrlen > 0) + { + if (Fread(fd, (long) hdrlen, buf) != (long) hdrlen) + return(-1); + } + + return(1); +} + + + +/* +* Sendet der Senderapplikation eine 1 Byte Antwort +* +* Eingabeparameter: +* fd - Filehandle der Pipe (von ddopen()) +* ack - Byte das gesendet werden soll (zB. DD_OK) +* +* Ausgabeparameter: +* keine +* +* Returnwert: +* >0: kein Fehler +* -1: Fehler (die Pipe wird automatisch geschlossen!) +*/ + +short ddreply(short fd, char ack) +{ + if (Fwrite(fd, 1L, &ack) != 1L) + { + ddclose(fd); + return(-1); + } + + return(1); +} + + 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..fe59209fe --- /dev/null +++ b/atari/gemtk/gemtk.h @@ -0,0 +1,100 @@ +#ifndef GEMTK_H_INCLUDED +#define GEMTK_H_INCLUDED + +#include +#include +#include +#include + +/* 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_STATUS_ICONIFIED 0x01 +#define GW_STATUS_SHADED 0x02 + +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]); +enum guwin_area_e { + GUIWIN_AREA_WORK = 0, + GUIWIN_AREA_TOOLBAR, + GUIWIN_AREA_CONTENT +}; + +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_set_event_handler(guiwin_event_handler_f); +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); + +/* +* 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 + + +#endif // GEMTK_H_INCLUDED diff --git a/atari/gemtk/guiwin.c b/atari/gemtk/guiwin.c new file mode 100644 index 000000000..6d525c698 --- /dev/null +++ b/atari/gemtk/guiwin.c @@ -0,0 +1,301 @@ +//#include "global.h" + +#include +#include +#include + +#include +#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 gui_window_s *next, *prev; +}; + +static GUIWIN * winlist; + +static short preproc_wm(GUIWIN * gw, EVMULT_OUT *ev_out, short msg[8]) +{ + GRECT g, tb_area, tb_area_ro; + short retval = 1; + + switch(msg[0]) { + + 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]); + break; + + case WM_FULLED: + wind_get_grect(0, WF_WORKXYWH, &g); + wind_set_grect(gw->handle, WF_CURRXYWH, &g); + 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: + guiwin_get_grect(gw, GUIWIN_AREA_TOOLBAR, &tb_area_ro); + tb_area = tb_area_ro; + if(rc_intersect((GRECT*)&msg[4], &tb_area)){ + wind_get_grect(gw->handle, WF_FIRSTXYWH, &g); + while (g.g_h > 0 || g.g_w > 0) { + gw->toolbar[gw->toolbar_idx].ob_x = tb_area_ro.g_x; + gw->toolbar[gw->toolbar_idx].ob_y = tb_area_ro.g_y; + 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); + } + } + 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; + + 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); + } + } + else { + if (dest->handler_func) { + retval = dest->handler_func(dest, ev_out, msg); + } + } + + } + break; + } + } + if( (ev_out->emo_events & MU_BUTTON) != 0){ + short info[4]; + + wind_get( 0, WF_TOP, &info[0], &info[1], &info[2], &info[3]); + if(info[0] != 0 && info[1] == gl_apid){ + dest = guiwin_find(info[0]); + if (dest) { + DEBUG_PRINT(("Found MU_BUTTON dest: %p (%d), flags: %d, cb: %p\n", dest, dest->handle, dest->flags, dest->handler_func)); + if(dest->toolbar != NULL && dest->handler_func != 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 + short obj_idx = 0; + short msg_out[8] = {WM_TOOLBAR, gl_apid, 0, dest->handle, + obj_idx, ev_out->emo_mclicks, ev_out->emo_kmeta, 0}; + short oldevents = ev_out->emo_events; + ev_out->emo_events = MU_MESAG; + dest->handler_func(dest, ev_out, msg_out); + ev_out->emo_events = oldevents; + retval = 1; + } + } + /* + if (dest->flags&GW_FLAG_PREPROC_WM) { + preproc_wm(dest, ev_in, ev_out, msg); + } + if (dest->handler_func) { + retval = dest->handler_func(dest, ev_in, ev_out, msg); + } + */ + } + } + } + return(retval); +} + +GUIWIN * guiwin_add(short handle, uint32_t flags, guiwin_event_handler_f cb) +{ + GUIWIN *win = malloc(sizeof(GUIWIN)); + + assert(win!=NULL); + DEBUG_PRINT(("guiwin_add: %d, %p, cb: %p\n", handle, win, cb)); + + win->handle = handle; + win->handler_func = cb; + win->flags = flags; + if (winlist == NULL) { + winlist = win; + win->next = NULL; + win->prev = NULL; + } else { + GUIWIN *tmp = winlist; + while( tmp->next != NULL ) { + tmp = tmp->next; + } + tmp->next = win; + win->prev = tmp; + win->next = NULL; + } + return(win); +} + +GUIWIN *guiwin_find(short handle) +{ + GUIWIN *g; + DEBUG_PRINT(("guiwin_find: handle: %d\n", handle)); + for( g = winlist; g != NULL; g=g->next ) { + DEBUG_PRINT(("guiwin search: %d\n", g->handle)); + if(g->handle == handle) { + DEBUG_PRINT(("guiwin_find: %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; + } + + free(win); + return(0); +} + +void guiwin_get_grect(GUIWIN *win, enum guwin_area_e mode, GRECT *dest) +{ + wind_get_grect(win->handle, WF_WORKXYWH, dest); + if (mode == GUIWIN_AREA_CONTENT) { + GRECT tb_area; + guiwin_get_grect(win, GUIWIN_AREA_TOOLBAR, &tb_area); + if (win->flags & GW_FLAG_HAS_VTOOLBAR) { + dest->g_x += tb_area.g_w; + dest->g_w -= tb_area.g_w; + } else { + dest->g_y += tb_area.g_h; + dest->g_w -= tb_area.g_h; + } + dbg_grect("guiwin_get_grect content", dest); + } + 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; + } + dbg_grect("guiwin_get_grect toolbar", dest); + } +} + +short guiwin_get_handle(GUIWIN *win) +{ + return(win->handle); +} + +uint32_t guiwin_get_state(GUIWIN *win) +{ + return(win->state); +} + +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; + } +} + + + diff --git a/atari/gemtk/guiwin.h b/atari/gemtk/guiwin.h new file mode 100644 index 000000000..dba112cd6 --- /dev/null +++ b/atari/gemtk/guiwin.h @@ -0,0 +1,5 @@ +#ifndef OPKG_GUI_GUIWIN_H +#define OPKG_GUI_GUIWIN_H + + +#endif /* OPKG_GUIWIN_H */ diff --git a/atari/gemtk/msgbox.c b/atari/gemtk/msgbox.c new file mode 100644 index 000000000..770e0af15 --- /dev/null +++ b/atari/gemtk/msgbox.c @@ -0,0 +1,84 @@ +#include +#include +#include +#include +#include "gemtk.h" + +#ifndef min +# define min(x,y) ((x +#include +#include +#include "gemtk.h" + +/* -------------------------------------------------------------------------- */ +/* GEM Utillity functions: */ +/* -------------------------------------------------------------------------- */ + +unsigned short _systype_v; +unsigned short _systype (void) +{ + int32_t * cptr = NULL; + _systype_v = SYS_TOS; + + cptr = (int32_t *)Setexc(0x0168, -1L); + if (cptr == NULL ) { + return _systype_v; /* stone old TOS without any cookie support */ + } + while (*cptr) { + if (*cptr == C_MgMc || *cptr == C_MgMx ) { + _systype_v = (_systype_v & ~0xF) | SYS_MAGIC; + } else if (*cptr == C_MiNT ) { + _systype_v = (_systype_v & ~0xF) | SYS_MINT; + } else if (*cptr == C_Gnva /* Gnva */ ) { + _systype_v |= SYS_GENEVA; + } else if (*cptr == C_nAES /* nAES */ ) { + _systype_v |= SYS_NAES; + } + cptr += 2; + } + if (_systype_v & SYS_MINT) { /* check for XaAES */ + short out = 0, u; + if (wind_get (0, (((short)'X') <<8)|'A', &out, &u,&u,&u) && out) { + _systype_v |= SYS_XAAES; + } + } + return _systype_v; +} + +OBJECT *get_tree( int idx) { + OBJECT *tree; + rsrc_gaddr(R_TREE, idx, &tree); + return tree; +} diff --git a/atari/gemtk/utils.h b/atari/gemtk/utils.h new file mode 100644 index 000000000..7ebbcf228 --- /dev/null +++ b/atari/gemtk/utils.h @@ -0,0 +1,5 @@ +#ifndef UTILS_H_INCLUDED +#define UTILS_H_INCLUDED + + +#endif // UTILS_H_INCLUDED diff --git a/atari/global_evnt.c b/atari/global_evnt.c index 3b15af877..40b88593a 100755 --- a/atari/global_evnt.c +++ b/atari/global_evnt.c @@ -26,379 +26,31 @@ #include #include "desktop/gui.h" -#include "desktop/netsurf.h" -#include "desktop/browser.h" -#include "desktop/browser_private.h" -#include "desktop/mouse.h" -#include "desktop/textinput.h" -#include "desktop/hotlist.h" -#include "desktop/save_complete.h" -#include "desktop/options.h" #include "utils/log.h" -#include "utils/messages.h" -#include "utils/url.h" +#include "atari/misc.h" #include "atari/gui.h" -#include "atari/browser_win.h" +#include "atari/rootwin.h" #include "atari/toolbar.h" #include "atari/browser.h" -#include "atari/hotlist.h" -#include "atari/history.h" -#include "atari/misc.h" #include "atari/global_evnt.h" -#include "atari/browser_win.h" #include "atari/res/netsurf.rsh" -#include "atari/search.h" -#include "atari/findfile.h" -#include "atari/settings.h" +#include "atari/deskmenu.h" #include "cflib.h" extern struct gui_window *input_window; -extern OBJECT * h_gem_menu; extern int mouse_click_time[3]; extern int mouse_hold_start[3]; extern browser_mouse_state bmstate; extern short last_drag_x; extern short last_drag_y; -extern bool html_redraw_debug; - -extern const char * option_homepage_url; -extern int option_window_width; -extern int option_window_height; -extern int option_window_x; -extern int option_window_y; -extern char options[PATH_MAX]; - -/* Zero based resource tree ids: */ -#define T_ABOUT 0 -#define T_FILE MAINMENU_T_FILE - MAINMENU_T_FILE + 1 -#define T_EDIT MAINMENU_T_EDIT - MAINMENU_T_FILE + 1 -#define T_VIEW MAINMENU_T_VIEW - MAINMENU_T_FILE + 1 -#define T_NAV MAINMENU_T_NAVIGATE - MAINMENU_T_FILE + 1 -#define T_UTIL MAINMENU_T_UTIL - MAINMENU_T_FILE + 1 -#define T_HELP MAINMENU_T_NAVIGATE - MAINMENU_T_FILE + 1 -/* Count of the above defines: */ -#define NUM_MENU_TITLES 7 /* Global event handlers: */ static void __CDECL global_evnt_apterm( WINDOW * win, short buff[8] ); -static void __CDECL global_evnt_menu( WINDOW * win, short buff[8] ); static void __CDECL global_evnt_m1( WINDOW * win, short buff[8] ); static void __CDECL global_evnt_keybd( WINDOW * win, short buff[8],void * data); -/* Menu event handlers: */ -static void __CDECL menu_about(WINDOW *win, int item, int title, void *data); - - -/* Menu event handlers: */ -static void __CDECL menu_about(WINDOW *win, int item, int title, void *data) -{ - LOG(("%s", __FUNCTION__)); - char buf[PATH_MAX]; - strcpy((char*)&buf, "file://"); - strncat((char*)&buf, (char*)"./doc/README.TXT", PATH_MAX - (strlen("file://")+1) ); - browser_window_create((char*)&buf, 0, 0, true, false); -} - -static void __CDECL menu_new_win(WINDOW *win, int item, int title, void *data) -{ - LOG(("%s", __FUNCTION__)); - browser_window_create(option_homepage_url, 0, 0, true, false); -} - -static void __CDECL menu_open_url(WINDOW *win, int item, int title, void *data) -{ - struct gui_window * gw; - struct browser_window * bw ; - LOG(("%s", __FUNCTION__)); - - gw = input_window; - if( gw == NULL ) { - bw = browser_window_create("", 0, 0, true, false); - gw = bw->window; - - } - /* Loose focus: */ - window_set_focus( gw, WIDGET_NONE, NULL ); - - /* trigger on-focus event (select all text): */ - window_set_focus( gw, URL_WIDGET, &gw->root->toolbar->url ); - - /* delete selection: */ - tb_url_input( gw, NK_DEL ); -} - -static void __CDECL menu_open_file(WINDOW *win, int item, int title, void *data) -{ - struct gui_window * gw; - struct browser_window * bw ; - - LOG(("%s", __FUNCTION__)); - - const char * filename = file_select( messages_get("OpenFile"), "" ); - if( filename != NULL ){ - char * url = local_file_to_url( filename ); - if( url ){ - bw = browser_window_create(url, NULL, NULL, true, false); - free( url ); - } - } -} - -static void __CDECL menu_close_win(WINDOW *win, int item, int title, void *data) -{ - LOG(("%s", __FUNCTION__)); - if( input_window == NULL ) - return; - gui_window_destroy( input_window ); -} - -static void __CDECL menu_save_page(WINDOW *win, int item, int title, void *data) -{ - LOG(("%s", __FUNCTION__)); - static bool init = true; - bool is_folder=false; - const char * path; - - if( !input_window ) - return; - - if( init ){ - init = false; - save_complete_init(); - } - - do { - // TODO: localize string - path = file_select("Select folder", ""); - if (path) - is_folder = is_dir(path); - } while( !is_folder && path != NULL ); - - if( path != NULL ){ - save_complete( input_window->browser->bw->current_content, path, NULL ); - } - -} - -static void __CDECL menu_quit(WINDOW *win, int item, int title, void *data) -{ - short buff[8]; - memset( &buff, 0, sizeof(short)*8 ); - LOG(("%s", __FUNCTION__)); - global_evnt_apterm( NULL, buff ); -} - -static void __CDECL menu_cut(WINDOW *win, int item, int title, void *data) -{ - if( input_window != NULL ) - browser_window_key_press( input_window->browser->bw, KEY_CUT_SELECTION); -} - -static void __CDECL menu_copy(WINDOW *win, int item, int title, void *data) -{ - LOG(("%s", __FUNCTION__)); - if( input_window != NULL ) - browser_window_key_press( input_window->browser->bw, KEY_COPY_SELECTION); -} - -static void __CDECL menu_paste(WINDOW *win, int item, int title, void *data) -{ - LOG(("%s", __FUNCTION__)); - if( input_window != NULL ) - browser_window_key_press( input_window->browser->bw, KEY_PASTE); -} - -static void __CDECL menu_find(WINDOW *win, int item, int title, void *data) -{ - LOG(("%s", __FUNCTION__)); - if( input_window != NULL ) - open_browser_search( input_window ); -} - -static void __CDECL menu_choices(WINDOW *win, int item, int title, void *data) -{ - static WINDOW * settings_dlg = NULL; - LOG(("%s", __FUNCTION__)); - settings_dlg = open_settings(); -} - -static void __CDECL menu_stop(WINDOW *win, int item, int title, void *data) -{ - LOG(("%s", __FUNCTION__)); - if( input_window == NULL ) - return; - tb_stop_click( input_window ); - -} - -static void __CDECL menu_reload(WINDOW *win, int item, int title, void *data) -{ - if( input_window == NULL) - return; - tb_reload_click( input_window ); - LOG(("%s", __FUNCTION__)); -} - -static void __CDECL menu_toolbars(WINDOW *win, int item, int title, void *data) -{ - static int state = 0; - LOG(("%s", __FUNCTION__)); - if( input_window != null && input_window->root->toolbar != null ){ - state = !state; - tb_hide( input_window, state ); - } -} - -static void __CDECL menu_savewin(WINDOW *win, int item, int title, void *data) -{ - LOG(("%s", __FUNCTION__)); - if (input_window && input_window->browser) { - GRECT rect; - wind_get_grect(input_window->root->handle->handle, WF_CURRXYWH, &rect); - option_window_width = rect.g_w; - option_window_height = rect.g_h; - option_window_x = rect.g_x; - option_window_y = rect.g_y; - nsoption_set_int(window_width, rect.g_w); - nsoption_set_int(window_height, rect.g_h); - nsoption_set_int(window_x, rect.g_x); - nsoption_set_int(window_y, rect.g_y); - nsoption_write((const char*)&options); - } - -} - -static void __CDECL menu_debug_render(WINDOW *win, int item, int title, void *data) -{ - LOG(("%s", __FUNCTION__)); - html_redraw_debug = !html_redraw_debug; - if( input_window != NULL ) { - if ( input_window->browser != NULL && input_window->browser->bw != NULL) { - LGRECT rect; - browser_get_rect( input_window, BR_CONTENT, &rect ); - browser_window_reformat(input_window->browser->bw, false, - rect.g_w, rect.g_h ); - MenuIcheck(NULL, MAINMENU_M_DEBUG_RENDER, - (html_redraw_debug) ? 1 : 0 ); - } - } -} - -static void __CDECL menu_fg_images(WINDOW *win, int item, int title, void *data) -{ - nsoption_set_bool(foreground_images, !nsoption_bool(foreground_images)); - MenuIcheck( NULL, MAINMENU_M_FG_IMAGES, (nsoption_bool(foreground_images)) ? 1 : 0); -} - -static void __CDECL menu_bg_images(WINDOW *win, int item, int title, void *data) -{ - nsoption_set_bool(background_images, !nsoption_bool(background_images)); - MenuIcheck( NULL, MAINMENU_M_BG_IMAGES, (nsoption_bool(background_images)) ? 1 : 0); -} - -static void __CDECL menu_back(WINDOW *win, int item, int title, void *data) -{ - LOG(("%s", __FUNCTION__)); - if( input_window == NULL ) - return; - tb_back_click( input_window ); -} - -static void __CDECL menu_forward(WINDOW *win, int item, int title, void *data) -{ - LOG(("%s", __FUNCTION__)); - if( input_window == NULL ) - return; - tb_forward_click( input_window ); -} - -static void __CDECL menu_home(WINDOW *win, int item, int title, void *data) -{ - LOG(("%s", __FUNCTION__)); - if( input_window == NULL ) - return; - tb_home_click( input_window ); -} - -static void __CDECL menu_lhistory(WINDOW *win, int item, int title, void *data) -{ - LOG(("%s", __FUNCTION__)); - if( input_window == NULL ) - return; -} - -static void __CDECL menu_ghistory(WINDOW *win, int item, int title, void *data) -{ - LOG(("%s", __FUNCTION__)); - global_history_open(); -} - -static void __CDECL menu_add_bookmark(WINDOW *win, int item, int title, void *data) -{ - LOG(("%s", __FUNCTION__)); - if( input_window ) { - if( input_window->browser->bw->current_content != NULL ){ - atari_hotlist_add_page( - nsurl_access(hlcache_handle_get_url( input_window->browser->bw->current_content)), - NULL - ); - } - } -} - -static void __CDECL menu_bookmarks(WINDOW *win, int item, int title, void *data) -{ - LOG(("%s", __FUNCTION__)); - hotlist_open(); -} - -static void __CDECL menu_vlog(WINDOW *win, int item, int title, void *data) -{ - LOG(("%s", __FUNCTION__)); - verbose_log = !verbose_log; - MenuIcheck(NULL, MAINMENU_M_VLOG, (verbose_log) ? 1 : 0 ); -} - -static void __CDECL menu_help_content(WINDOW *win, int item, int title, void *data) -{ - LOG(("%s", __FUNCTION__)); -} - -static struct s_menu_item_evnt menu_evnt_tbl[] = -{ - {T_ABOUT,MAINMENU_M_ABOUT, menu_about, {0,0,0}, NULL }, - {T_FILE, MAINMENU_M_NEWWIN, menu_new_win, {0,0,0}, NULL}, - {T_FILE, MAINMENU_M_OPENURL, menu_open_url, {'G',0,K_CTRL}, NULL}, - {T_FILE, MAINMENU_M_OPENFILE, menu_open_file, {'O',0,K_CTRL}, NULL}, - {T_FILE, MAINMENU_M_CLOSEWIN, menu_close_win, {0,0,0}, NULL}, - {T_FILE, MAINMENU_M_SAVEPAGE, menu_save_page, {0,NK_F3,0}, NULL}, - {T_FILE, MAINMENU_M_QUIT, menu_quit, {'Q',0,K_CTRL}, NULL}, - {T_EDIT, MAINMENU_M_CUT, menu_cut, {'X',0,K_CTRL}, NULL}, - {T_EDIT, MAINMENU_M_COPY, menu_copy, {'C',0,K_CTRL}, NULL}, - {T_EDIT, MAINMENU_M_PASTE, menu_paste, {'V',0,K_CTRL}, NULL}, - {T_EDIT, MAINMENU_M_FIND, menu_find, {0,NK_F4,0}, NULL}, - {T_VIEW, MAINMENU_M_RELOAD, menu_reload, {0,NK_F5,0}, NULL}, - {T_VIEW, MAINMENU_M_TOOLBARS, menu_toolbars, {0,NK_F1,K_CTRL}, NULL}, - {T_VIEW, MAINMENU_M_SAVEWIN, menu_savewin, {0,0,0}, NULL}, - {T_VIEW, MAINMENU_M_DEBUG_RENDER, menu_debug_render, {0,0,0}, NULL}, - {T_VIEW, MAINMENU_M_FG_IMAGES, menu_fg_images, {0,0,0}, NULL}, - {T_VIEW, MAINMENU_M_BG_IMAGES, menu_bg_images, {0,0,0}, NULL}, - {T_VIEW, MAINMENU_M_STOP, menu_stop, {0,NK_ESC,K_ALT}, NULL}, - {T_NAV, MAINMENU_M_BACK, menu_back, {0,NK_LEFT,K_ALT}, NULL}, - {T_NAV, MAINMENU_M_FORWARD, menu_forward, {0,NK_RIGHT,K_ALT}, NULL}, - {T_NAV, MAINMENU_M_HOME, menu_home, {0,NK_CLRHOME,0}, NULL}, - {T_UTIL, MAINMENU_M_LHISTORY,menu_lhistory, {0,NK_F7,0}, NULL}, - {T_UTIL, MAINMENU_M_GHISTORY, menu_ghistory, {0,NK_F7,K_CTRL}, NULL}, - {T_UTIL, MAINMENU_M_ADD_BOOKMARK, menu_add_bookmark, {'D',0,K_CTRL}, NULL}, - {T_UTIL, MAINMENU_M_BOOKMARKS, menu_bookmarks, {0,NK_F6,0}, NULL}, - {T_UTIL, MAINMENU_M_CHOICES, menu_choices, {0,0,0}, NULL}, - {T_UTIL, MAINMENU_M_VLOG, menu_vlog, {'V',0,K_ALT}, NULL}, - {T_HELP, MAINMENU_M_HELP_CONTENT, menu_help_content, {0,NK_F1,0}, NULL}, - {T_HELP, -1, NULL,{0,0,0}, NULL } -}; - -void __CDECL global_evnt_apterm( WINDOW * win, short buff[8] ) +void __CDECL global_evnt_apterm(WINDOW * win, short buff[8]) { int i = 0; LOG(("")); @@ -406,7 +58,7 @@ void __CDECL global_evnt_apterm( WINDOW * win, short buff[8] ) } -static void __CDECL global_evnt_m1( WINDOW * win, short buff[8] ) +static void __CDECL global_evnt_m1(WINDOW * win, short buff[8]) { struct gui_window * gw = input_window; static bool prev_url = false; @@ -416,23 +68,23 @@ static void __CDECL global_evnt_m1( WINDOW * win, short buff[8] ) LGRECT urlbox, bwbox, sbbox; int nx, ny; - if( gw == NULL) + if (gw == NULL) return; - if( prev_x == evnt.mx && prev_y == evnt.my ){ + if (prev_x == evnt.mx && prev_y == evnt.my) { return; } short ghandle = wind_find( evnt.mx, evnt.my ); - if( input_window->root->handle->handle == ghandle ){ + if (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 ){ + 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, @@ -442,7 +94,7 @@ static void __CDECL global_evnt_m1( WINDOW * win, short buff[8] ) ); } - if( gw->root->toolbar && within == false ) { + 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 )) { @@ -466,7 +118,6 @@ static void __CDECL global_evnt_m1( WINDOW * win, short buff[8] ) void __CDECL global_evnt_keybd( WINDOW * win, short buff[8], void * data) { - char sascii; long kstate = 0; long kcode = 0; unsigned short nkc = 0; @@ -500,178 +151,23 @@ void __CDECL global_evnt_keybd( WINDOW * win, short buff[8], void * data) 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); + if(!done) + deskmenu_dispatch_keypress(evnt.keybd, kstate, nkc); } - + /* Bind global and menu events to event handler functions, create accelerators */ void bind_global_events( void ) { - int i, len; - int maxlen[NUM_MENU_TITLES]={0}; - char * m, *u, *t; - char spare[128]; memset( (void*)&evnt_data, 0, sizeof(struct s_evnt_data) ); EvntDataAttach( NULL, WM_XKEYBD, global_evnt_keybd, (void*)&evnt_data ); - EvntAttach( NULL, AP_TERM, global_evnt_apterm ); - EvntAttach( NULL, MN_SELECTED, global_evnt_menu ); + EvntAttach( NULL, AP_TERM, global_evnt_apterm ); EvntAttach( NULL, WM_XM1, global_evnt_m1 ); - - /* parse and update menu items: */ - i = 0; - while( menu_evnt_tbl[i].rid != -1 ) { - char * str = ObjcString( h_gem_menu, menu_evnt_tbl[i].rid, NULL ); - register_menu_str( &menu_evnt_tbl[i] ); - if( menu_evnt_tbl[i].menustr != NULL ){ - MenuText( NULL, menu_evnt_tbl[i].rid, menu_evnt_tbl[i].menustr ); - } - i++; - } - main_menu_update(); } void unbind_global_events( void ) { - int i; - i=0; - while(menu_evnt_tbl[i].rid != -1) { - if( menu_evnt_tbl[i].menustr != NULL ) - free(menu_evnt_tbl[i].menustr); - i++; - } + } diff --git a/atari/global_evnt.h b/atari/global_evnt.h index 1e13264a2..76e73fc6b 100755 --- a/atari/global_evnt.h +++ b/atari/global_evnt.h @@ -18,6 +18,8 @@ #ifndef NS_ATARI_GLOBAL_EVNT_H #define NS_ATARI_GLOBAL_EVNT_H + +#include struct s_keybd_evnt_data { @@ -32,31 +34,14 @@ struct s_evnt_data } u; }; -struct s_evnt_data evnt_data; - -struct s_accelerator -{ - char ascii; /* either ascii or */ - long keycode; /* normalised keycode is valid */ - short mod; /* shift / ctrl etc */ -}; - -typedef void __CDECL (*menu_evnt_func)(WINDOW * win, int item, int title, void * data); -struct s_menu_item_evnt { - short title; /* to which menu this item belongs */ - short rid; /* resource ID */ - menu_evnt_func menu_func; /* click handler */ - struct s_accelerator accel; /* accelerator info */ - char * menustr; -}; +struct s_evnt_data evnt_data; /* - Global & Menu event handlers + Global event handlers */ void bind_global_events( void ); void unbind_global_events( void ); -void main_menu_update( void ); #endif diff --git a/atari/gui.c b/atari/gui.c index c2158e05e..4f7a97b9f 100755 --- a/atari/gui.c +++ b/atari/gui.c @@ -1,1041 +1,1143 @@ -/* - * Copyright 2010 - * - * 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 . - */ - - /* - This File provides all the mandatory functions prefixed with gui_ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#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) +/* + * Copyright 2010 + * + * 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 . + */ + +/* + This File provides all the mandatory functions prefixed with gui_ +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "content/urldb.h" +#include "content/fetch.h" +#include "content/fetchers/resource.h" +#include "css/utils.h" +#include "desktop/gui.h" +#include "desktop/history_core.h" +#include "desktop/plotters.h" +#include "desktop/netsurf.h" +#include "desktop/401login.h" + +#include "desktop/options.h" +#include "desktop/save_complete.h" +#include "desktop/selection.h" +#include "desktop/textinput.h" +#include "desktop/browser.h" +#include "desktop/browser_private.h" +#include "desktop/mouse.h" +#include "render/font.h" +#include "utils/schedule.h" +#include "utils/url.h" +#include "utils/log.h" +#include "utils/messages.h" +#include "utils/utils.h" + +#include "atari/gemtk/gemtk.h" +#include "atari/gui.h" +#include "atari/misc.h" +#include "atari/findfile.h" +#include "atari/schedule.h" +#include "atari/rootwin.h" +#include "atari/browser.h" +#include "atari/statusbar.h" +#include "atari/toolbar.h" +#include "atari/verify_ssl.h" +#include "atari/hotlist.h" +#include "atari/history.h" +#include "atari/login.h" +#include "atari/global_evnt.h" +#include "atari/encoding.h" +#include "atari/res/netsurf.rsh" +#include "atari/plot/plot.h" +#include "atari/clipboard.h" +#include "atari/osspec.h" +#include "atari/search.h" +#include "atari/deskmenu.h" +#include "cflib.h" + +#define TODO() (0)/*printf("%s Unimplemented!\n", __FUNCTION__)*/ + +char *tmp_clipboard; +struct gui_window *input_window = NULL; +struct gui_window *window_list = NULL; +void * h_gem_rsrc; +long next_poll; +bool rendering = false; + + +/* Comandline / Options: */ +int option_window_width; +int option_window_height; +int option_window_x; +int option_window_y; + +/* Defaults to option_homepage_url, commandline options overwrites that value */ +const char * option_homepage_url; + +/* path to choices file: */ +char options[PATH_MAX]; + +EVMULT_IN aes_event_in = { + .emi_flags = MU_MESAG | MU_TIMER | MU_KEYBD | MU_BUTTON, + .emi_bclicks = 258, + .emi_bmask = 3, + .emi_bstate = 0, + .emi_m1leave = MO_ENTER, + .emi_m1 = {0,0,0,0}, + .emi_m2leave = 0, + .emi_m2 = {0,0,0,0}, + .emi_tlow = 0, + .emi_thigh = 0 +}; +EVMULT_OUT aes_event_out; +short aes_msg_out[8]; + + +void __CDECL global_evnt_keybd( WINDOW * win, short buff[8], void * data) { - if (w == NULL) + 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; - - 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; + 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; + } } - } - - 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; -} - - + } + if(!done) + deskmenu_dispatch_keypress(evnt.keybd, kstate, nkc); +} + +void gui_poll(bool active) +{ + int flags = MU_MESAG | MU_KEYBD | MU_BUTTON; + short mx, my, dummy; + unsigned short nkc = 0; + + evnt.timer = schedule_run(); + + if(active || rendering) { + if (clock() >= next_poll) { + aes_event_in.emi_tlow = 0; + evnt_multi_fast(&aes_event_in, aes_msg_out, &aes_event_out); + next_poll = clock() + (CLOCKS_PER_SEC>>4); + } + } else { + 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)) { + //global_dispatch_event(&aes_event_in, &aes_event_out, msg); + if( (aes_event_out.emo_events & MU_MESAG) != 0 ) { + LOG(("WM: %d\n", aes_msg_out[0])); + switch(aes_msg_out[0]) { + + case MN_SELECTED: + LOG(("Menu Item: %d\n",aes_msg_out[4])); + deskmenu_dispatch_item(aes_msg_out[3], aes_msg_out[4]); + break; + + default: + break; + } + } + + if( (aes_event_out.emo_events & MU_KEYBD) != 0 ) { + printf("key: %d, %d\n", aes_event_out.emo_kreturn, + aes_event_out.emo_kmeta); + nkc= gem_to_norm( (short)aes_event_out.emo_kmeta, + (short)aes_event_out.emo_kreturn); + deskmenu_dispatch_keypress(aes_event_out.emo_kreturn, + aes_event_out.emo_kmeta, nkc); + } + } + +} + +void gui_poll_old(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; + + unbind_global_events(); + + while( gw ) { + tmp = gw->next; + browser_window_destroy(gw->browser->bw); + gw = tmp; + } + + global_history_destroy(); + hotlist_destroy(); + toolbar_exit(); + + urldb_save_cookies(nsoption_charp(cookie_file)); + urldb_save(nsoption_charp(url_file)); + + deskmenu_destroy(); + + 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!"); + } + //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; + + //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)); + tree_set_icon_dir( nsoption_charp(tree_icons_path) ); +} + +static char *theapp = (char*)"NetSurf"; +static void gui_init2(int argc, char** argv) +{ + deskmenu_init(); + menu_register( -1, theapp); + if (sys_type() & (SYS_MAGIC|SYS_NAES|SYS_XAAES)) { + menu_register( _AESapid, (char*)" NetSurf "); + } + bind_global_events(); + global_history_init(); + hotlist_init(); + toolbar_init(); +} + +/* #define WITH_DBG_LOGFILE 1 */ +/** Entry point from OS. + * + * /param argc The number of arguments in the string vector. + * /param argv The argument string vector. + * /return The return code to the OS + */ +int main(int argc, char** argv) +{ + char messages[PATH_MAX]; + + setbuf(stderr, NULL); + setbuf(stdout, NULL); +#ifdef WITH_DBG_LOGFILE + freopen("stdout.log", "a+", stdout); + freopen("stderr.log", "a+", stderr); +#endif + 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; +} + + diff --git a/atari/hotlist.c b/atari/hotlist.c index bdd10d922..5d54d061b 100755 --- a/atari/hotlist.c +++ b/atari/hotlist.c @@ -40,6 +40,7 @@ #include "atari/treeview.h" #include "atari/hotlist.h" #include "atari/findfile.h" +#include "atari/gemtk/gemtk.h" #include "atari/res/netsurf.rsh" struct atari_hotlist hl; diff --git a/atari/misc.c b/atari/misc.c index 8b745fd2f..575e96491 100755 --- a/atari/misc.c +++ b/atari/misc.c @@ -42,7 +42,7 @@ #include "atari/browser.h" #include "atari/misc.h" #include "atari/encoding.h" -#include "atari/msgbox.h" +#include "atari/gemtk/gemtk.h" #include "cflib.h" extern void * h_gem_rsrc; @@ -111,10 +111,7 @@ bool path_add_part(char *path, int length, const char *newpart) return true; } -/* - TBD: make use of this function or remove it... -*/ -struct gui_window * find_gui_window( unsigned long handle, short mode ){ +struct gui_window * find_guiwin_by_aes_handle(short handle){ struct gui_window * gw; gw = window_list; @@ -122,29 +119,17 @@ 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; - } + + while(gw != NULL) { + if( gw->root->handle != NULL + && gw->root->handle->handle == handle ) { + return(gw); + } + else + gw = gw->next; } - return( NULL ); + return( NULL ); } @@ -260,25 +245,6 @@ bool is_process_running(const char * name) } -/* -------------------------------------------------------------------------- */ -/* GEM Utillity functions: */ -/* -------------------------------------------------------------------------- */ - -/* Return a string from resource file */ -char *get_rsc_string( int idx) { - char *txt; - RsrcGaddr( h_gem_rsrc, R_STRING, idx, &txt ); - return txt; -} - -OBJECT *get_tree( int idx) { - OBJECT *tree; - RsrcGaddr( h_gem_rsrc, R_TREE, idx, &tree); - return tree; -} - - - /** * Callback for load_icon(). Should be removed once bitmaps get loaded directly * from disc diff --git a/atari/misc.h b/atari/misc.h index 612113fc1..5359d724c 100755 --- a/atari/misc.h +++ b/atari/misc.h @@ -42,11 +42,9 @@ typedef int (*scan_process_callback)(int pid, void *data); -struct gui_window * find_gui_window( unsigned long, short mode ); +struct gui_window * find_guiwin_by_aes_handle(short handle); 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 ); void gem_set_cursor( MFORM_EX * cursor ); hlcache_handle *load_icon( const char *name, hlcache_handle_callback cb, void * pw ); 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 #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/redrawslots.c b/atari/redrawslots.c index 9fe71610e..069e6cc91 100644 --- a/atari/redrawslots.c +++ b/atari/redrawslots.c @@ -45,7 +45,7 @@ static inline bool rect_intersect( struct rect * box1, struct rect * box2 ) return true; } /* - schedule a slots, coords are relative. + schedule redraw coords, coords are relative. */ void redraw_slot_schedule(struct s_redrw_slots * slots, short x0, short y0, short x1, short y1) { diff --git a/atari/rootwin.c b/atari/rootwin.c new file mode 100755 index 000000000..16d3363d5 --- /dev/null +++ b/atari/rootwin.c @@ -0,0 +1,816 @@ +/* + * Copyright 2010 Ole Loots + * + * 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 . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "utils/log.h" +#include "desktop/gui.h" +#include "desktop/history_core.h" +#include "desktop/netsurf.h" +#include "desktop/browser.h" +#include "desktop/browser_private.h" +#include "desktop/mouse.h" +#include "desktop/plotters.h" +#include "desktop/textinput.h" +#include "content/content.h" +#include "content/hlcache.h" +#include "content/urldb.h" +#include "css/css.h" +#include "atari/gemtk/gemtk.h" +#include "atari/gui.h" +#include "atari/rootwin.h" +#include "atari/browser.h" +#include "atari/misc.h" +#include "atari/plot/plot.h" +#include "atari/global_evnt.h" +#include "atari/res/netsurf.rsh" +#include "atari/browser.h" +#include "atari/toolbar.h" +#include "atari/statusbar.h" +#include "atari/search.h" +#include "atari/osspec.h" +#include "atari/encoding.h" +#include "atari/toolbar.h" +#include "atari/gemtk/gemtk.h" + +extern struct gui_window *input_window; + +/* -------------------------------------------------------------------------- */ +/* 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_rt_resize( WINDOW *win, short buff[8], void * date ); +static void redraw(GUIWIN *win, short msg[8]); +static void resized(GUIWIN *win); +static void file_dropped(GUIWIN *win, short msg[8]); +//static void __CDECL evnt_window_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 ); + +#define FIND_NS_GUI_WINDOW(w) \ + find_guiwin_by_aes_handle(guiwin_get_handle(w)); + +/* -------------------------------------------------------------------------- */ +/* Module public functions: */ +/* -------------------------------------------------------------------------- */ + +static short handle_event(GUIWIN *win, EVMULT_OUT *ev_out, short msg[8]) +{ + struct gui_window * gw; + + if( (ev_out->emo_events & MU_MESAG) != 0 ) { + // handle message + printf("root win msg: %d\n", msg[0]); + switch (msg[0]) { + + case WM_REDRAW: + redraw(win, msg); + break; + + case WM_REPOSED: + case WM_SIZED: + case WM_MOVED: + case WM_FULLED: + resized(win); + break; + + case WM_ICONIFY: + gw = FIND_NS_GUI_WINDOW(win); + if( input_window == gw) { + input_window = NULL; + } + break; + + case WM_TOPPED: + case WM_NEWTOP: + case WM_UNICONIFY: + input_window = FIND_NS_GUI_WINDOW(win); + break; + + case WM_CLOSED: + gw = FIND_NS_GUI_WINDOW(win); + if( gw != NULL ) { + browser_window_destroy( gw->browser->bw ); + } + break; + + case AP_DRAGDROP: + file_dropped(win, msg); + break; + + case WM_TOOLBAR: + printf("toolbar click at %d,%d!\n", ev_out->emo_mouse.p_x, + ev_out->emo_mouse.p_y); + break; + + default: + break; + } + } + if( (ev_out->emo_events & MU_KEYBD) != 0 ) { + printf("root win keybd\n"); + // handle key + } + if( (ev_out->emo_events & MU_TIMER) != 0 ) { + // handle_timer(); + } + if( (ev_out->emo_events & MU_BUTTON) != 0 ) { + LOG(("Mouse click at: %d,%d\n", ev_out->emo_mouse.p_x, + ev_out->emo_mouse.p_y)); + printf("Mouse click at: %d,%d\n", ev_out->emo_mouse.p_x, + ev_out->emo_mouse.p_y); + //handle_mbutton(gw, ev_out); + } + + return(0); +} + + +int window_create( struct gui_window * gw, + struct browser_window * bw, + unsigned long inflags ) +{ + int err = 0; + bool tb, sb; + int flags; + + 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); + } + + GUIWIN * guiwin = guiwin_add(gw->root->handle->handle, + GW_FLAG_PREPROC_WM | GW_FLAG_RECV_PREPROC_WM, handle_event); + guiwin_set_toolbar(guiwin, get_tree(TOOLBAR), 0, 0); + 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 ); + + guiwin_remove(guiwin_find(gw->root->handle->handle)); + + 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 = get_tree(ICONIFY); + tree->ob_x = work.g_x; + tree->ob_y = work.g_y; + tree->ob_width = work.g_w; + tree->ob_height = work.g_h; + objc_draw(tree, 0, 8, clip->g_x, clip->g_y, clip->g_w, clip->g_h); + } else { + // TODO: consider the clipping rectangle + struct rect work_clip = { 0,0,work.g_w,work.g_h }; + int xoff=0; + if (work.g_w > work.g_h) { + xoff = ((work.g_w-work.g_h)/2); + work.g_w = work.g_h; + } + plot_set_dimensions( work.g_x+xoff, work.g_y, work.g_w, work.g_h); + plot_clip(&work_clip); + atari_plotters.bitmap(0, 0, work.g_w, work.g_h, 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); +//} + +static void redraw(GUIWIN *win, short msg[8]) +{ + short handle; + struct gui_window *gw; + + handle = guiwin_get_handle(win); + gw = (struct gui_window*)find_guiwin_by_aes_handle(handle); + + assert(gw != NULL); + + if(guiwin_get_state(win) & GW_STATUS_ICONIFIED) { + GRECT clip = {msg[4], msg[5], msg[6], msg[7]}; + window_redraw_favicon(gw, &clip); + } else { + GRECT area; + short pxy[8]; + guiwin_get_grect(win, GUIWIN_AREA_CONTENT, &area); + /* + pxy[0] = area.g_x; + pxy[1] = area.g_y; + pxy[2] = pxy[0] + area.g_w; + pxy[3] = pxy[1]; + pxy[4] = pxy[2]; + pxy[5] = pxy[1] + area.g_h; + pxy[6] = pxy[0]; + pxy[7] = pxy[5]; + */ + //const plot_style_fill_white + plot_rectangle(area.g_x, area.g_y, area.g_x+area.g_h, + area.g_y + area.g_h, + plot_style_fill_white); + + + //WindClear(gw->root->handle); + } +} + +static void resized(GUIWIN *win) +{ + short x,y,w,h; + short handle; + struct gui_window *gw; + + handle = guiwin_get_handle(win); + gw = (struct gui_window*)find_guiwin_by_aes_handle(handle); + + assert( gw != NULL ); + + wind_get(handle, WF_CURRXYWH, &x, &y, &w, &h); + + if (gw->root->loc.g_w != w || gw->root->loc.g_h != h) { + // resized + tb_adjust_size( gw ); + if ( gw->browser->bw->current_content != NULL ) { + /* Reformat will happen when next redraw message arrives: */ + gw->browser->reformat_pending = true; + /* but on xaaes an resize doesn't trigger an redraw, */ + /* when the window is shrinked, deal with it: */ + if( sys_XAAES() ) { + if( gw->root->loc.g_w > w || gw->root->loc.g_h > h ) { + ApplWrite(_AESapid, WM_REDRAW, gw->root->handle->handle, + x, y, w, h); + } + } + } + } + if (gw->root->loc.g_x != x || gw->root->loc.g_y != y) { + // moved + } + gw->root->loc.g_x = x; + gw->root->loc.g_y = y; + gw->root->loc.g_w = w; + gw->root->loc.g_h = h; +} + +static void __CDECL file_dropped(GUIWIN *win, short msg[8]) +{ + char file[DD_NAMEMAX]; + char name[DD_NAMEMAX]; + char *buff=NULL; + int dd_hdl; + int dd_msg; /* pipe-handle */ + long size; + char ext[32]; + short mx,my,bmstat,mkstat; + struct gui_window *gw; + + graf_mkstate(&mx, &my, &bmstat, &mkstat); + + gw = FIND_NS_GUI_WINDOW(win); + + if( gw == NULL ) + return; + + if(guiwin_get_state(win) & GW_STATUS_ICONIFIED) + return; + + dd_hdl = ddopen( msg[7], DD_OK); + if( dd_hdl<0) + return; /* pipe not open */ + memset( ext, 0, 32); + strcpy( ext, "ARGS"); + dd_msg = ddsexts( dd_hdl, ext); + if( dd_msg<0) + goto error; + dd_msg = ddrtry( dd_hdl, (char*)&name[0], (char*)&file[0], (char*)&ext[0], &size); + if( size+1 >= PATH_MAX ) + goto error; + if( !strncmp( ext, "ARGS", 4) && dd_msg > 0) { + ddreply(dd_hdl, DD_OK); + buff = (char*)malloc(sizeof(char)*(size+1)); + if (buff != NULL) { + if (Fread(dd_hdl, size, buff ) == size) + buff[size] = 0; + LOG(("file: %s, ext: %s, size: %d dropped at: %d,%d\n", + (char*)buff, (char*)&ext, + size, mx, my + )); + { + 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); +} + +///* 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/rootwin.h b/atari/rootwin.h new file mode 100755 index 000000000..28001baad --- /dev/null +++ b/atari/rootwin.h @@ -0,0 +1,70 @@ +/* + * Copyright 2010 Ole Loots + * + * 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 . + */ + +#ifndef NS_ATARI_BROWSER_WIN_H +#define NS_ATARI_BROWSER_WIN_H + +#define GUIWIN_VISIBLE(gw) (gw->root->handle->status & WS_OPEN) +#define GEMWIN_VISIBLE(win) (win->status & WS_OPEN) + +#define WIDGET_STATUSBAR 0x1 +#define WIDGET_TOOLBAR 0x2 +#define WIDGET_SCROLL 0x4 +#define WIDGET_RESIZE 0x8 + +#define WIN_TOP 0x100 + +/* WinDom & Custom bindings for gui window */ + +/* -------------------------------------------------------------------------- */ +/* Public module functions: */ +/* -------------------------------------------------------------------------- */ + +/* Creates an normal Browser window with [toolbar], [statusbar] */ +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 ); + +/* show the window */ +void window_open( struct gui_window * gw, GRECT pos); + +void window_snd_redraw(struct gui_window * gw, 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); +/* set root browser component: */ +void window_attach_browser( struct gui_window * gw, 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); +/* 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); + + +/* -------------------------------------------------------------------------- */ +/* Public event handlers: */ +/* -------------------------------------------------------------------------- */ + +#endif diff --git a/atari/search.c b/atari/search.c index b5e2fdd61..473712515 100644 --- a/atari/search.c +++ b/atari/search.c @@ -34,7 +34,8 @@ #include "atari/gui.h" #include "atari/misc.h" #include "atari/browser.h" -#include "atari/search.h" +#include "atari/search.h" +#include "atari/gemtk/gemtk.h" #include "atari/res/netsurf.rsh" extern struct gui_window * input_window; @@ -139,7 +140,7 @@ static void destroy_search_session( SEARCH_FORM_SESSION s ) } } -static int apply_form( WINDOW * win, struct s_search_form_state * s ) +static int apply_form(WINDOW * win, struct s_search_form_state * s) { OBJECT * obj = ObjcTree(OC_FORM, win ); if( obj == NULL ){ @@ -290,11 +291,12 @@ SEARCH_FORM_SESSION open_browser_search( struct gui_window * gw ) NULL, title, &pos, true, false); - ObjcAttachFormFunc( sfs->formwind, SEARCH_BT_SEARCH, evnt_bt_srch_click, NULL); - ObjcAttachFormFunc( sfs->formwind, SEARCH_CB_CASESENSE, evnt_cb_click, NULL); - ObjcAttachFormFunc( sfs->formwind, SEARCH_CB_SHOWALL, evnt_cb_click, NULL); - ObjcAttachFormFunc( sfs->formwind, SEARCH_CB_FWD, evnt_cb_click, NULL); - EvntAdd( sfs->formwind, WM_CLOSED, evnt_close, EV_TOP); + ObjcAttachFormFunc(sfs->formwind, SEARCH_BT_SEARCH, evnt_bt_srch_click, + NULL); + ObjcAttachFormFunc(sfs->formwind, SEARCH_CB_CASESENSE, evnt_cb_click, NULL); + ObjcAttachFormFunc(sfs->formwind, SEARCH_CB_SHOWALL, evnt_cb_click, NULL); + ObjcAttachFormFunc(sfs->formwind, SEARCH_CB_FWD, evnt_cb_click, NULL); + EvntAdd(sfs->formwind, WM_CLOSED, evnt_close, EV_TOP); apply_form(sfs->formwind, &sfs->state ); strncpy( ObjcString( tree, SEARCH_TB_SRCH, NULL ), "", SEARCH_MAX_SLEN); diff --git a/atari/settings.c b/atari/settings.c index 8143cdcc6..ff39903e9 100644 --- a/atari/settings.c +++ b/atari/settings.c @@ -31,11 +31,12 @@ #include "desktop/plot_style.h" #include "atari/res/netsurf.rsh" #include "atari/settings.h" -#include "atari/global_evnt.h" -#include "atari/misc.h" +#include "atari/deskmenu.h" +#include "atari/misc.h" #include "atari/plot/plot.h" #include "atari/bitmap.h" -#include "atari/findfile.h" +#include "atari/findfile.h" +#include "atari/gemtk/gemtk.h" extern char options[PATH_MAX]; @@ -232,7 +233,7 @@ saveform( WINDOW *win, int index, int unused, void *unused2) close_settings(); ObjcChange( OC_FORM, win, index, NORMAL, TRUE); form_alert(1, "[1][Some options require an netsurf restart!][OK]"); - main_menu_update(); + deskmenu_update(); } static void __CDECL clear_history( WINDOW *win, int index, int unused, diff --git a/atari/statusbar.c b/atari/statusbar.c index 08a62c55d..c8f8688c6 100755 --- a/atari/statusbar.c +++ b/atari/statusbar.c @@ -38,7 +38,7 @@ #include "atari/gui.h" #include "atari/statusbar.h" -#include "atari/browser_win.h" +#include "atari/rootwin.h" #include "atari/misc.h" #include "atari/global_evnt.h" #include "atari/res/netsurf.rsh" @@ -227,7 +227,6 @@ void sb_attach(CMP_STATUSBAR sb, struct gui_window * gw) void sb_set_text(CMP_STATUSBAR sb, char * text ) { - LGRECT work; assert( sb != NULL ); strncpy(sb->text, text, STATUSBAR_MAX_SLEN); sb->text[STATUSBAR_MAX_SLEN]=0; diff --git a/atari/toolbar.c b/atari/toolbar.c index 3594d24c0..396cccbc4 100755 --- a/atari/toolbar.c +++ b/atari/toolbar.c @@ -43,7 +43,7 @@ #include "atari/clipboard.h" #include "atari/gui.h" #include "atari/toolbar.h" -#include "atari/browser_win.h" +#include "atari/rootwin.h" #include "atari/browser.h" #include "atari/clipboard.h" #include "atari/misc.h" @@ -176,8 +176,8 @@ void toolbar_init( void ) } else { RsrcGaddr( h_gem_rsrc, R_TREE, TOOLBAR, &toolbar_buttons ); - toolbar_buttons->ob_x = 0; - toolbar_buttons->ob_y = 0; + //toolbar_buttons->ob_x = 0; + //toolbar_buttons->ob_y = 0; RsrcGaddr( h_gem_rsrc, R_TREE, THROBBER , &throbber_form ); throbber_form->ob_x = 0; @@ -279,8 +279,8 @@ static void __CDECL button_redraw( COMPONENT *c, long buff[8], void * data ) 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; + //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 { diff --git a/atari/treeview.c b/atari/treeview.c index 4a5cb0a75..6e567f569 100755 --- a/atari/treeview.c +++ b/atari/treeview.c @@ -37,7 +37,19 @@ #include "atari/treeview.h" #include "atari/plot/plot.h" #include "atari/misc.h" -#include "cflib.h" +#include "cflib.h" + +/* +#define TREEVIEW_RECT_WORKAREA 0 +#define TREEVIEW_RECT_TOOLBAR 1 +#define TREEVIEW_RECT_CONTENT 2 +*/ + +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; @@ -46,9 +58,11 @@ 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_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_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, @@ -403,6 +417,24 @@ 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) +{ + + wind_get_grect(tv->window->handle, WF_WORKXYWH, dest); + if (mode == TREEVIEW_AREA_CONTENT) { + GRECT tb_grect; + atari_treeview_get_grect(tv, TREEVIEW_AREA_TOOLBAR, &tb_grect); + dest->g_y += tb_grect.g_h; + dest->g_h -= tb_grect.g_h; + } + else if (mode == TREEVIEW_AREA_TOOLBAR) { + // TODO: this requires something like: + // guiwin_get_toolbar(); + dest->g_h = 16; + } } /** @@ -418,8 +450,8 @@ void atari_treeview_get_dimensions(int *width, int *height, { if (pw != NULL && (width != NULL || height != NULL)) { NSTREEVIEW tv = (NSTREEVIEW) pw; - GRECT work; - WindGetGrect( tv->window, WF_WORKXYWH, &work ); + GRECT work; + atari_treeview_get_grect(tv, TREEVIEW_AREA_CONTENT, &work); *width = work.g_w; *height = work.g_h; } -- cgit v1.2.3