import com.picture;
import win.ui.ctrl.metaProperty;
import win.ui.ctrl.static;
import win.ui.ctrl.button; 
import win.ui.ctrl.custom;
namespace win.ui.ctrl;  

//发布时将从下面排除未使用的控件库
/*OPT_IMPORT{{*/
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.calendar;
import win.ui.ctrl.thread;
import win.ui.ctrl.splitter;
import win.ui.ctrl.plus;
import win.ui.ctrl.atlax;
import win.ui.ctrl.syslink;
import win.ui.ctrl.ipaddress;
import win.ui.ctrl.bk;
import win.ui.ctrl.bkplus;
/*}}*/

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.clip )tParam.style |= 0x4000000/*_WS_CLIPSIBLINGS*/
		if( tParam.clipch ) tParam.style |=  0x2000000/*_WS_CLIPCHILDREN*/; 
		if( tParam.transparent ) tParam.exstyle |= 0x20/*_WS_EX_TRANSPARENT*/; 

		if(!tParam.cls) return;
		tParam.$friendClassName  = tParam.cls;//记录原始类名 
					
		var cls = ..win.ui.ctrl[tParam.cls];
		if(!cls) cls = ..table.getByNamespace(tParam.cls,..win.ui.ctrl); 
		
		if(cls){
			var parent = tParam.parent;
			tParam.parent = null;
			
			//创建控件,并在每个构造函数中对tParam进行一些预处理
			var obj = cls(parent,tParam);
			obj.tParam = tParam;
			obj[["initializing"]] = true;
			return obj;
		} 
		elseif( ..string.endWith(tParam.cls,".aardio",true) ){
			var parent = tParam.parent;
			tParam.parent = null;
			 
			var frmCreate;
			var frm =  ..win.loadForm(tParam.cls,function(tParam2){
			tParam2.parent = parent ;
			tParam2.mode="child";
			tParam2.exmode="none";
			tParam2.border="none"
			tParam2.title=false;  
			tParam2.text=tParam.text; 
			tParam2.bgcolor=tParam.bgcolor;
			if(tParam.bkImage){
				tParam2.image=tParam.bkImage;
				tParam2.bkBottom = tParam.bkBottom : 0;
				tParam2.bkRight = tParam.bkRight : 0;
				tParam2.bkTop = tParam.bkTop : 0;
				tParam2.bkLeft = tParam.bkLeft : 0;
			}
			tParam.cls="custom";
			tParam2.tParam=tParam;
			
			frmCreate =  ..win.form(tParam2);
			return frmCreate;	
		},parent);
		
		if(!frm) frm = frmCreate;
		if(!frm) return;
		
		frm.tParam = tParam;
			frm[["initializing"]] = true;
			return frm;
		} 
	}
		
	onCreateComplete = function(obj,dpiScaleX,dpiScaleY){ 
		var tParam = obj.tParam;
		obj.tParam = null;
		
		obj[["className"]] = tParam.cls;
		
		if(tParam.$friendClassName){
			obj[["cls"]] = tParam.$friendClassName;
			tParam.cls = tParam.$friendClassName;	
			tParam.$friendClassName = 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);
			
		obj.setFont( tParam.font || ::LOGFONT() ); 
		//去掉CreateWindowEx创建窗口时已经用到的属性 
		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; 
		tParam[["text"]] = null;  
			
		//必须在设置其他属性以前调用初始化函数
		var onCreate = obj[["onCreate"]];
		if( onCreate ){ obj.onCreate() }
		
		//初始化窗口的其他属性
		..table.assign(obj,tParam);
		if(dpiScaleX && dpiScaleY && obj.enableDpiScaling){
			obj.enableDpiScaling(dpiScaleX,dpiScaleY);
		}
		obj[["initializing"]] = false;  
		
		//窗口所有属性已初始化
		var onCreated = obj[["onCreated"]];
		if( onCreated ){ obj.onCreated() }
	}
}

::Comctl32 := ..raw.loadDll("Comctl32.dll");
::Comctl32.InitCommonControlsEx({INT size = 8;INT ic = 0x897F;})

/**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**/