//menu 自定义菜单
import web.form;
import win.ui.menu; 
namespace web.form

class menu{
	ctor( wb,tMenus ){
		if(!wb[["_form"]] || (!type(tMenus) == type.table ) )
			error("参数错误",2)
			
		this._form = wb._form[["_parentForm"]] : wb._form;
	};
	popup = function(x,y,id,ele){
		var args = tMenus[id]
		if(!args)
			return;
	
		var popMenu = ..win.ui.popmenu( this._form );//创建弹出菜单
		var arg,command,proc,id;
		var queryCommandEnabled = ele.ownerDocument.queryCommandEnabled; 
		for(i=1;#args;1){
			arg = args[i] 
			command = arg[2] : arg.command
			id = arg[4] : arg.id
			 
			proc = null; 
			if( type(command)=="string" ){ 
				if(id===null){
					var commandProc = command;
					proc = function(id,hwnd,ele,x,y){
						wb.exec(commandProc);
					};
				}
			}
			else if( type(command) == type.function ){
				proc = command; 
				command = null;
			}
			
			if( #arg ){
				//parameter list
				popMenu.add(arg[1],proc ,arg[3],id ); 
			}
			else{
				//parameter table
				popMenu.add( ..table.mixin( arg, { proc = proc } ) ); 
			} 
			
			if( #cmd ){
				popMenu.enable(i, queryCommandEnabled( command ) );
			}
		}   
		
		popMenu.fireId( popMenu.popId(x,y,true) 
			,wb.hwndControl,ele,x,y );  
	} 
} 

//SHDOCLC.DLL
//http://www.aau.cn/doc/html/dhtml/commandids.html