//mshtml 文档对象
import inet.http;
import web.form;
namespace web

class mshtml{
	ctor(doc,...){
		if( doc ){
			this.document = ..com.IsObject(doc)  ?  doc : doc.getDoc(...)   
		}
		else {
			this.document = ..com.CreateObject("{25336920-03F9-11cf-8FD0-00AA00686F13}") 
		}
	}; 
	@_metaProperty;
}

namespace mshtml{ 
	_metaProperty = ..util.metaProperty(
	
		go = function(url,headers){  
			var str = ..string.load(url);
			if(!str){
				if(!owner.http){
					owner.http = ..inet.http()
				}
				str = owner.http.get(url,headers,owner[["location"]]);
			}
			if(str){
				owner.document.write(str)
				owner[["location"]] = url
			}
		}
		post = function(url,postdata,headers='\r\nContent-Type: application/x-www-form-urlencoded' ){ 
			if(headers=="")headers=null;
			if(!postdata)return owner.go(url); 
			if(!owner.http){
				owner.http = ..inet.http()
			}
			var str = owner.http.post(url,postdata,headers,owner[["location"]]); 
			if(str){
				owner.document.write(str)
				owner[["location"]] = url
			} 
		}
		getDoc = function(frame){  
			if(frame===null)
				return owner.document; 
			
			var ele = owner.getFrame(frame);  
   			if(ele){
   				var doc;
   				try{
   					doc = ele.Document; //ele.contentDocument
   				}
   				return doc;
   			}
		} 
		waitDoc = function( frame,timeout){ 
			var doc = owner.document
			var tk = 0;
			do{  
				if(doc.readyState == 'interactive' || doc.readyState == 'complete'  )	
					 return doc;
					  
				if( timeout && tk>timeout)
						return null,"Timeout!"
						
				tk+=101;  
			} while( ..win.delay(100) )
		}
		waitEle = function(name,frame,timeout,complete=true ){  
			var ele,t;
			var wb = owner;
			if(timeout){
				t = ..time.tick();
			}
			do{
				if(t && ((..time.tick()-t)>=timeout)){
					return ; 
				}
				ele = ele || wb.getEle(name,frame);
				if(ele && ( (!complete) || ele.readyState == 'loaded' || ele.readyState == 'complete')  )
					return ele;
			}while(..win.delay(200)) 
		}
		wait = function(url,timeout){
			owner.waitDoc(null,timeout);
			return true;
		} 
		write = function(strhtml,frame ){
			var doc = owner.getDoc(frame) 
			if(!doc)
				return false;
			
			doc.write(strhtml); 
			doc.close();
		}   
		@{ _get = ..web.form._metaProperty } /*属性表可继承*/ 
	)
}

/**intellisense()
web.mshtml = MSHTML支持库
web.mshtml() = 创建HTML文档对象\n!mshtm.
web.mshtml(doc) = 创建HTML文档对象\n可选指定一个document对象
web.mshtml(wb,框架名) = 创建HTML文档对象\n可选指定一个wb窗体,以及框架名
!mshtm.document = document. 
!mshtm.write("__") =  将字符串值写入网页、不允许追加
!mshtm.write("__","框架名") = 将字符串值写入框架网页、不允许追加 
!mshtm.write("__") = 将字符串值写入网页	
!mshtm.go("__/*网址*/") = 打开网址或本地路径\n注意驱动器根目录要以反斜杠结束
!mshtm.post(.("__/*网址*/","k=v&k2=v2") = 自动提交表单
!mshtm.post(.("__/*网址*/","k=v&k2=v2","自定义http头") = 自动提交表单
!mshtm.post(.("__/*网址*/","k=v&k2=v2","自定义http头","目标框架") = 自动提交表单
!mshtm.location = 当前网址
!mshtm.host = 当前网址所在主机名
!mshtm.go("__/*网址*/","自定义http头") = 打开网址
!mshtm.go("__/*网址*/","自定义http头","目标框架") = 打开网址
!mshtm.eachFrames() = @//创建迭代器,迭代页面所有框架窗口，例：\nfor i,frame in ??.eachFrames() {\n	__\n}\n
!mshtm.eachLinks() = @//创建迭代器,迭代页面所有超链接，例：\nfor i,link in ??.eachLinks() {\n	__\n}\n
!mshtm.eachAll() = @//创建迭代器,迭代页面所有节点，例：\nfor i,ele in ??.eachAll() {\n	__\n}\n
!mshtm.eachLinks("框架名") = @//创建迭代器,迭代页面所有超链接，例：\nfor i,link in ??.eachLinks("__/*框架名*/") {\n	\n}\n
!mshtm.eachLinks(父节点) = @//创建迭代器,迭代页面所有超链接，例：\nfor i,link in ??.eachLinks( ??.getEle("id") ) {\n	\n}\n
!mshtm.eachAll("input") = @//创建迭代器,迭代页面所有输入控件，例：\nfor i,input in ??.eachAll("input") {\n	__\n}\n
!mshtm.eachAll("input","框架名") = @//创建迭代器,迭代页面所有输入控件，例：\nfor i,input in ??.eachAll("input","框架名") {\n	__\n}\n
!mshtm.eachAll("DIV",父节点) = @//创建迭代器,迭代页面所有输入控件，例：\nfor i,input in ??.eachAll("DIV" ,??.getEle("id") ) {\n	__\n}\n
!mshtm.getScript(__/*框架名*/) = 网页脚本对象
!mshtm.getScript()  = !script.
!mshtm.script = 网页脚本对象\n!script.
!script.脚本函数名__() =  调用JS函数必须有实参\n无参数调用则返回函数类对象
!mshtm.getFrame(__/*框架名*/) = 返回框架窗口对象\n参数可以是框架名,ID,基于0的索引,或者frame节点
!mshtm.getDoc(__/*框架名*/) = 获取文档对象\n参数可以是框架名,ID,基于0的索引,或者frame节点
!mshtm.attach = @.attach(\n	function(event){\n		io.print("点击坐标", event.screenX,event.screenY )\n		io.print("触发节点", event.srcElement.innerText )\n	}\n	,"onclick__",ele/*也可输入getEle()所需参数,省略表示doc*/ \n)
!mshtm.attachAll = @.attachAll(  \n	/* html节点ID = 事件触发函数表 */\n	caption_button_min = {\n		onclick = function(event){\n			wb._form.hitmin();	\n		} \n	}\n)
!mshtm.select("控件名字",__/*输入选项索引,或选项值、选项文本*/) = 查找下拉选框的指定选项,选中并返回选项节点\n第一个参数也可以是ele对象
!mshtm.select("控件名字",__/*输入选项索引,或选项值、选项文本*/,false) = 查找下拉选框的指定选项,取消选定并返回选项节点\n第一个参数也可以是ele对象
!mshtm.exec("__") = 执行命令
!mshtm.exec("__", ) = 执行命令
!mshtm.exec("__", ,true) = 执行命令
!mshtm.execEle(ele,"__") = 执行命令
!mshtm.execEle(ele,"__", ) = 执行命令
!mshtm.execEle(ele,"__", ,true) = 执行命令  
!mshtm.doScript(.(js脚本) =执行js脚本
!mshtm.doScript(.(js脚本,框架名称) =执行js脚本
!mshtm.doScript(.(js脚本,框架名称,脚本语言名称="javascript") =执行js脚本
!mshtm.body = !ele.
!mshtm.head = !ele.
!mshtm.loadScript("js地址","框架名字") = 动态加载js文件
!mshtm.jQuery("__") = jQuery选择器,并可自动载入jQuery库\n首先尝试加载: "/res/js/jQuery/jQuery-1.6.1.min.js"\n失败则通过网络CDN加载
!mshtm.jQuery() = 无参数时返回jQuery类对象\n可自动初始化jQuery,首先加载: "/res/js/jQuery/jQuery-1.6.1.min.js"\n失败则通过网络CDN加载\n!jQuery.
!mshtm.getEle() = !ele.
!mshtm.waitEle("__") = 返回一个节点对像或框架内子节点对像\n并等待加载完成
!mshtm.getEle("__") = 返回一个节点对像或框架内子节点对像
!mshtm.getEle("__") = 返回一个节点对像或框架内子节点对像
!mshtm.waitEle("__","框架名字") = 返回一个节点对像或框架内子节点对像\n并等待加载完成
!mshtm.getEle("__","框架名字") = 返回一个节点对像或框架内子节点对像
!mshtm.waitEle("__","",20000) = 返回一个节点对像\n第三个参数指定超时值(毫秒)
!mshtm.getEles("__") = 返回同名的所有节点,例如\nele = wb.getEles("节点名字");\nele(1).setAttribute("属性名字", "修改第一个节点属性值");
!mshtm.getEles("__","框架名字") = 返回同名的所有节点,例如\nele = wb.getEles("节点名字");\nele(1).setAttribute("属性名字", "修改第一个节点属性值");
!mshtm.queryEles = @//可指定任意个属性条件值.支持模式匹配语法\n??.queryEles( parent = 可选指定父节点;className = "style2")
!mshtm.fromPoint(.(x坐标,y坐标) = 自指定的坐标获取节点
!mshtm.fromPoint(.(x坐标,y坐标,框架名) = 自指定的坐标获取节点
!mshtm.getPoint(ele__) = x,y=wb.getPoint(ele)\n返回对象的页面坐标
!mshtm.getPos(ele__) = x,y,cx,cy = wb.getPos(ele)\n返回对象的窗口客户区坐标
!mshtm.getPos(ele__,true) = x,y,cx,cy = wb.getPos(ele)\n返回对象的屏幕坐标
!mshtm.select() = !ele.
!mshtm.getDoc() = document.
!mshtm.waitDoc() = document.
end intellisense**/
