//.. 控件工厂
import com.picture
import win.ui.ctrl.common;
import win.ui.ctrl.metaProperty;
import win.ui.ctrl.button; 
namespace win.ui.ctrl;  

//以下控件的库名与控件类名必须相同,发布时将从下面排除未使用的控件库
/*OPT_IMPORT{{*/
import win.ui.ctrl.static;
import win.ui.ctrl.picturebox;	
import win.ui.ctrl.edit;
import win.ui.ctrl.richedit;
import win.ui.ctrl.combobox;
import win.ui.ctrl.listbox;
import win.ui.ctrl.tab;
import win.ui.ctrl.progress;
import win.ui.ctrl.datetimepick;
import win.ui.ctrl.hotkey;
import win.ui.ctrl.listview;
import win.ui.ctrl.treeview;
import win.ui.ctrl.checklist;
import win.ui.ctrl.trackbar;
import win.ui.ctrl.scrollbar; 
import win.ui.ctrl.spin;
import win.ui.ctrl.custom;
import win.ui.ctrl.calendar;
/*}}*/

//控件工厂
namespace factory{

	create = function(tParam){
			//必须是子窗口
		    tParam.exstyle := 0;
			tParam.style := 0; 
			tParam.style |= 0x40000000/*_WS_CHILD*/ ;
			
			//获取通用的样式
			if( tParam.group ) tParam.style |= 0x20000/*_WS_GROUP*/
			if( tParam.tabstop )tParam.style |= 0x10000/*_WS_TABSTOP*/
			if( !tParam.hide )tParam.style |= 0x10000000/*_WS_VISIBLE*/ ;   
			if( tParam.disabled )tParam.style |= 0x8000000/*_WS_DISABLED*/
			if( tParam.hscroll )tParam.style |= 0x100000/*_WS_HSCROLL*/
	    	if( tParam.vscroll )tParam.style |= 0x200000/*_WS_VSCROLL*/
	    	if( tParam.border )tParam.style |= 0x800000/*_WS_BORDER*/
	    	if( tParam.frame )tParam.exstyle |= 0x1/*_WS_EX_DLGMODALFRAME*/
			if( tParam.acceptfiles )tParam.exstyle |= 0x10/*_WS_EX_ACCEPTFILES*/
		    if( tParam.cp )tParam.exstyle |= 0x10000/*_WS_EX_CONTROLPARENT*/
			
			if(!tParam.cls)return;
			tParam.cls = ..string.lower( tParam.cls )
			tParam.friendClassName  = tParam.cls;//记录友好类名 
			
			 //创建控件，并在每个构造函数中对tParam进行一些预处理，例如修改radiobutton类名为button，visible等属性更换为样式 
			 var cls = ..win.ui.ctrl[tParam.cls];
			 if(cls){
			 	var obj = cls(tParam.parent,tParam);
			 	obj.tParam = tParam;
			 	return obj;
			 } 
	}
	
	onCreateComplete = function(obj){
			var tParam = obj.tParam;
			obj.tParam = null;
			
			//记录控件窗口原始大小(以计算自动调整的比例)
			obj._defRect = ::RECT( tParam.left,tParam.top,tParam.right,tParam.bottom);
			obj._defClientRect := ::RECT( 0, 0, tParam.right - tParam.left, tParam.bottom - tParam.top);
			
			//去掉CreateWindowEx创建窗口时已经用到的属性 
		    obj.setFont( tParam.font : LOGFONT() );
		    tParam[["font"]]= null;
		    tParam[["style"]] = null;
		    tParam[["left"]] = null;
		    tParam[["right"]] = null;
		    tParam[["top"]] = null;
		    tParam[["bottom"]] = null;
		    tParam[["hide"]] = null;
		    tParam[["disabled"]] = null;
		    tParam[["exstyle"]] = null;
		    tParam[["autoResize"]] = null;
		    tParam[["hwnd"]] = null;
		      
		    //必须在设置其他属性以前调用初始化函数
		    var onCreate = obj[["onCreate"]];
		    if( onCreate ){ onCreate() }
		    
		    //初始化窗口的其他属性
		    ..table.mixin(obj,tParam);
		    
		    obj.className = tParam.cls;
		    obj.cls = tParam.friendClassName
		    tParam.cls = tParam.friendClassName //恢复友好类名
	}

}

 /**intellisense()
_NM_FIRST=@0x0/*_NM_FIRST*/
_NM_LAST=@0xFFFFFF9D/*_NM_LAST*/
_NM_OUTOFMEMORY=@0xFFFFFFFF/*_NM_OUTOFMEMORY*/
_NM_CLICK=@0xFFFFFFFE/*_NM_CLICK*/
_NM_DBLCLK=@0xFFFFFFFD/*_NM_DBLCLK*/
_NM_RETURN=@0xFFFFFFFC/*_NM_RETURN*/
_NM_RCLICK=@0xFFFFFFFB/*_NM_RCLICK*/
_NM_RDBLCLK=@0xFFFFFFFA/*_NM_RDBLCLK*/
_NM_SETFOCUS=@0xFFFFFFF9/*_NM_SETFOCUS*/
_NM_KILLFOCUS=@0xFFFFFFF8/*_NM_KILLFOCUS*/
_NM_CUSTOMDRAW=@0xFFFFFFF4/*_NM_CUSTOMDRAW*/
_NM_HOVER=@0xFFFFFFF3/*_NM_HOVER*/
_NM_NCHITTEST=@0xFFFFFFF2/*_NM_NCHITTEST*/
_NM_KEYDOWN=@0xFFFFFFF1/*_NM_KEYDOWN*/
_NM_RELEASEDCAPTURE=@0xFFFFFFF0/*_NM_RELEASEDCAPTURE*/
_NM_SETCURSOR=@0xFFFFFFEF/*_NM_SETCURSOR*/
_NM_CHAR=@0xFFFFFFEE/*_NM_CHAR*/
_NM_TOOLTIPSCREATED=@0xFFFFFFED/*_NM_TOOLTIPSCREATED*/
_NM_LDOWN=@0xFFFFFFEC/*_NM_LDOWN*/
_NM_RDOWN=@0xFFFFFFEB/*_NM_RDOWN*/
_NM_THEMECHANGED=@0xFFFFFFEA/*_NM_THEMECHANGED*/
_NM_FONTCHANGED=@0xFFFFFFE9/*_NM_FONTCHANGED*/
_NM_CUSTOMTEXT=@0xFFFFFFE8/*_NM_CUSTOMTEXT*/
_NM_TVSTATEIMAGECHANGING=@0xFFFFFFE8/*_NM_TVSTATEIMAGECHANGING*/
end intellisense**/
