//calendar 日历控件

import win.ui.ctrl.metaProperty;//导入控件属性元表支持
namespace win.ui.ctrl;  
 
class calendar{
    ctor(parent,tParam){ 
    	if(tParam){
    		tParam.cls  = "SysMonthCal32";
			if(tParam.edge) tParam.exstyle |= 0x200/*_WS_EX_CLIENTEDGE*/;	
 		
			this.pos2 = 0;
		}
    }
	@_metaProperty;
}
 
calendar._metaProperty = metaProperty(
	getColor = function(ind){
		::SendMessageInt(owner.hwnd,0x100B/*_MCM_GETCOLOR*/,ind,0);
	};
	setColor = function(ind,clr){
		::SendMessageInt(owner.hwnd,0x100A/*_MCM_SETCOLOR*/,ind,clr);
	};
	bgcolor = {
		_get = function(){
			return owner.getColor(0/*_MCSC_BACKGROUND*/)
		}
		_set = function(v){
			owner.setColor(0/*_MCSC_BACKGROUND*/,v)
		} 
	};
	color = {
		_get = function(){
			return owner.getColor(1/*_MCSC_TEXT*/) 
		}
		_set = function(v){
			owner.setColor(1/*_MCSC_TEXT*/,v) 
		} 
	};
	time = {
		_get = function(){ 
			var tm = ..time(,"%x")
			var hour,second,minute = tm.hour,tm.second,tm.minute
			var re,tm = ::SendMessageByStruct(owner.hwnd, 0x1001/*_MCM_GETCURSEL*/,0,..time(,"%x"));
     		return ..table.mixin(tm,{ hour = hour; second = second; minute = minute; } )
		}
		_set = function( v ){
			assert( ..time.istime(v),"无效的time对象")
		    ::SendMessageByStruct(owner.hwnd, 0x1002/*_MCM_SETCURSEL*/,0, v);
		} 	
	};
	setRange = function(tmMin,tmMax){ 
		var flag = 0;
		if( !tmMin )
			tmMin = ..time();
		elseif(! ..time.istime(tmMin) )
			error("最小时间参数不正确",2)
		else 
			flag |= 1/*_GDTR_MIN*/
			
		if( !tmMax )
			tmMax = ..time();
		elseif(! ..time.istime(tmMax) )
			error("最大时间参数不正确",2)
		else 
			flag |= 2/*_GDTR_MAX*/
			
		::SendMessageByStruct(owner.hwnd,0x1012/*_MCM_SETRANGE*/,flag,{struct tm[2]={tmMin;tmMax} });
	}
	getRange = function( ){
		var tm =  ..time();
		var tmRange = {struct array[2]={ ..time()  } }
		var tmMin,tmMax;
		var ret = ::SendMessageByStruct(owner.hwnd,0x1011/*_MCM_GETRANGE*/,0,tmRange);
 	 
		if( ret & 1/*_GDTR_MIN*/ ){
			tmMin = tmRange.array[1]; 
		}
		if( ret & 2/*_GDTR_MAX*/ ){
			tmMax = tmRange.array[2]; 
		}	
		return tmMin,tmMax
	}; 
)
 

/***intellisense() 
?win.ui.ctrl.calendar =!calendar.
win.ui.ctrl.calendar() = 日历控件\n!calendar.
!calendar.cls = 设计时类名
!calendar.className = 运行时类名
!calendar.time = 获取或设置时间
!calendar.setRange(.(时间下限,时间上限) = 设置时间范围,参数为time()对象\n可省略其中一个参数,仅指定下限或仅指定上限
!calendar.getRange() = 返回两个time()对象:时间范围下限,时间范围上限\n如果未调用setRange()指定上限或下限,相应值返回为空
!calendar.hwnd = 控件句柄
!calendar.id = 控件ID
!calendar.text = 控件文本
!calendar._parentForm = 控件所在的父窗口(指win.form对象)\n!winform.
!calendar.getParent() = 返回父窗口\n!static.
!calendar.setParent(__/*控件对象*/) = 改变父窗口 
!calendar.hide = 控件是否隐藏
!calendar.disabled = 是否禁用
!calendar.left = 左侧坐标
!calendar.right = 右侧坐标
!calendar.top = 顶部坐标
!calendar.bottom = 底部坐标
!calendar.width = 宽度
!calendar.height = 高度
!calendar.redraw() = 刷新
!calendar.show(true__) = 显示控件
!calendar.getRect() = 控件区块位置(::RECT结构体)
!calendar.getRect(true) = 控件屏幕区块位置(::RECT结构体)  
!calendar.setRect(rc) = 设置控件区块位置(::RECT结构体)  
!calendar.setRect(rc,true) = 设置控件屏幕区块位置(::RECT结构体)
!calendar.getClientRect() =  控件客户区块位置(::RECT结构体)\n!rect.
!calendar.getFont() = 控件字体(::LOGFONT结构体)\n!logfont.
!calendar.setFont(__/*指定字体*/) = 指定LOGFONT字体对象,或逻辑字体句柄 
!calendar.setFont(混入字体属性) = @.setFont(point=10;name="宋体");
!calendar.clientRect =  获取控件客户区块位置(::RECT结构体)
!calendar.theme = 外观主题,例如\nwinform.button.theme = "Explorer"\nwinform.button.theme = false
!calendar.modifyStyle(.(remove,add) = 如果指定第三个参数，则使用此参数调用::SetWidnowPos 
!calendar.modifyStyleEx(.(remove,add) = 如果指定第三个参数，则使用此参数调用::SetWidnowPos
!calendar.capture = 是否捕获全局鼠标消息
!calendar.close() = 关闭控件窗口
!calendar.invalidate(__/*可选使用::RECT()对象指定客户区*/) = 使窗口绘图区无效
!calendar.invalidate(__/*可选使用::RECT()对象指定客户区*/,0) = 使窗口绘图区无效\n不刷新背景
!calendar.update() = 重绘invalidate函数指定的区块 
!calendar.setFocus() = 设置焦点 
!calendar.setPos(.(x坐标,y坐标,宽,高,插入位置,参数) = 调整窗口位置或排序,所有参数可选\n同时指定x,y坐标则移动位置\n同时指定宽高则改变大小\n指定插入位置(句柄或_HWND前缀常量)则调整Z序
!calendar.getPos() = 返回相对坐标,宽,高\nx,y,cx,cy=win.getPos(hwnd)

_MCM_FIRST=@0x1000/*_MCM_FIRST*/ 
end intellisense***/

