
import win.ui;
import console;
/*DSG{{*/
var winform = win.form( bottom=480;parent=...;text="HTMLayout 界面应用程序";border="resizable";right=800 )
winform.add( 
browserMain={ dr=1;dl=1;bottom=480;right=800;left=0;dt=1;top=135;z=1;db=1;cls="static" };
layoutHeader={ dr=1;dl=1;bottom=135;right=800;left=0;dt=1;top=0;z=2;cls="static" }
)
/*}}*/

import web.layout;
var wbLayout = web.layout(winform.layoutHeader);
wbLayout.go("/layout/index.htm"); 

import web.form;   
var wbBrowser = web.form( winform.browserMain,0x4/*_UIFLAG_NO3DBORDER*/ | 0x200000/*_UIFLAG_NO3DOUTERBORDER*/, , ,true/*securityTrusted*/); 
wbBrowser.noScriptErr = !_STUDIO_INVOKED ;

/*网页接口{{*/   
wbBrowser.external = {   
	config = config;
	log = function(...){
		if( _STUDIO_INVOKED ){
			console.log(...) 
		};
	}; 
	loadServer = function (option) { 
		//将 /html/some.html 映射到 /lib/html/some.aau 用户库中定义的类 
		var url = option.document.location.href;
		var path = "server." + string.replace(
			assert( string.match(url, "[/\\]res[/\\]([\w/\\]+)\.html" ) ) 
			, "[/\\]", ".") ; 
		
		global.import(path);  
	   	return ..table.getByNamespace(path)( wbBrowser, option.document ).external;
	}; 	  
}
/*}}*/

/*自定义网页右键菜单{{*/ 
import web.form.menu;
var webmenu = web.form.menu( wbBrowser, {
	[2/*_CONTEXT_MENU_CONTROL*/] = {  
		{ "撤消";"Undo" }; 
		{ /*-----*/};  
		{ "剪切";"Cut"}; 
		{ "复制";"Copy"}; 
		{ "粘贴";"Paste"};
		{ "删除";"Delete"}; 
		{ /*-----*/};
		{ "全选";"SelectAll"};  
	};
	[4/*_CONTEXT_MENU_TEXTSELECT */] = {  
		{ "剪切";"Cut" }; 
		{ "复制";"Copy" }; 
		{ "粘贴";"Paste" };
		{ "删除";"Delete" };
	};  
} );
wbBrowser.showMenu = function( x,y,id,ele ) {
	return webmenu.popup( x,y,id,ele ) 
}
/*}}*/ 

wbBrowser.go("/res/main.html")
 
wbLayout.onButtonClick = {
	btn_cut = function (layoutEle,reason,behaviorParams) {
		winform.msgbox("剪切")
	} 
	btn_copy = function (layoutEle,reason,behaviorParams) {
		winform.msgbox("复制")
	} 
	btn_paste = function (layoutEle,reason,behaviorParams) {
		winform.msgbox("粘贴")
	} 
	btn_homepage = function (layoutEle,reason,behaviorParams) {
		wbBrowser.write("请稍候......")
		wbBrowser.go("/res/main.html")
	} 
	btn_about = function (layoutEle,reason,behaviorParams) {
		wbBrowser.write("请稍候......")
		wbBrowser.go("http://www.aau.cn/forum-128-1.html")
	}
}

wbLayout.onMenuItemClick = {
	menu_item_new = function (layoutEle,reason,behaviorParams) {
		winform.msgbox("新建")
	} 
	menu_item_open = function (layoutEle,reason,behaviorParams) {
		winform.msgbox("打开")
	} 
	menu_item_save = function (layoutEle,reason,behaviorParams) {
		winform.msgbox("保存")
	} 
	menu_item_saveas = function (layoutEle,reason,behaviorParams) {
		winform.msgbox("另存为")
	} 
	menu_item_exit = function (layoutEle,reason,behaviorParams) {
		winform.close();
	}  
}
 

wbLayout.onMouseClick  = {
	tabHome = function (layoutEle, x,y,mouseParams) { 
		wbBrowser.write("请稍候......")
		winform.setTimeout( 
			function(){
				wbBrowser.go("http://www.aau.cn/thread-5509-1-1.html")
			} 
		);  
	};
	tabAbout = function (layoutEle, x,y,mouseParams) {
		wbBrowser.write("请稍候......")
		winform.setTimeout( 
			function(){
				wbBrowser.go("http://www.aau.cn/thread-5508-1-1.html")
			} 
		);  
	}; 
}
  
/* 定义加速键表 */  
import win.ui.accelerator; 
var accel = win.ui.accelerator({
	{ ctrl = true; vkey = 'N'#; oncommand = wbLayout.onMenuItemClick.menu_item_new }
	{ ctrl = true; vkey = 'O'#; oncommand = wbLayout.onMenuItemClick.menu_item_open }
	{ ctrl = true; vkey = 'S'#; oncommand = wbLayout.onMenuItemClick.menu_item_save }
	{ ctrl = true; vkey = 'H'#;  oncommand = wbLayout.onButtonClick.btn_homepage }
	{ ctrl = true; vkey = 'U'#;  oncommand = wbLayout.onButtonClick.btn_about  }
},winform);

winform.wndproc = function(hwnd,message,wParam,lParam){
	if (message === 0x14/*_WM_ERASEBKGND*/) {
		return 1;
	} 
}
 
winform.show( );
win.loopMessage();
