//picturebox 图像控件
import win.ui.ctrl.metaProperty;//导入控件属性元表支持
import com.picture;
namespace win.ui.ctrl; 

class picturebox{
    ctor(parent,tParam){
    	if(tParam){
    		tParam.style |= 0xE/*_SS_BITMAP*/;
    		tParam.cls = "static" 
			if(tParam.edge) tParam.exstyle |= 0x20000/*_WS_EX_STATICEDGE*/;  
			if(tParam.transparent)tParam.exstyle |= 0x20/*_WS_EX_TRANSPARENT*/;
			if(tParam.notify)tParam.style |= 0x100/*_SS_NOTIFY*/  
			if(!tParam.autosize)
				tParam.style |= 0x40/*_SS_REALSIZECONTROL*/;
			if(tParam.center)
				tParam.style |= 0x200/*_SS_CENTERIMAGE*/
    	}
    }
	@_metaProperty;
}

var loadIpicture = ..com.picture.load;
picturebox._metaProperty = metaProperty( 
	
	image = {
		_get = function(){   
			return topointer(  
				::SendMessage(owner.hwnd, 
			    	..win.getStyle(owner.hwnd,0xE/*_SS_BITMAP*/)?0x173/*_STM_GETIMAGE*/: 0x171/*_STM_GETICON*/ 
			    ) 
			)
		}
		_set = function( v ){
			if(type(v)==type.pointer)
				return owner.setImage(h);
				
			var ipic = loadIpicture(v)
			if(!ipic){
				owner.modifyStyle( 0x3/*_SS_ICON*/  |  0xE/*_SS_BITMAP*/);
				return;
			}
			
			var hpic,imgtype = ipic.CopyHandle() ; 
			if( imgtype ==0x1/*_IMAGE_ICON*/ )	{  
			     owner.setIcon(hpic); 
		    }
		    else if( imgtype ==0x0/*_IMAGE_BITMAP*/ ){
		        owner.setImage(hpic); 
		    }
		    ..com.Release(ipic)
		} 	
	}  
	setIcon = function(h,delPrev=true){ 
		return owner.setImage(h,delPrev,0x170/*_STM_SETICON*/,0x1/*_IMAGE_ICON*/)
	}
	setImage = function(h,delPrev=true,ss = 0xE/*_SS_BITMAP*/,tt = 0x0/*_IMAGE_BITMAP*/ ){
		owner.modifyStyle( ,ss); 
		var l,t,r,b = owner._getPosRatio();  
		var retPrev =  ::SendMessage(owner.hwnd,0x172/*_STM_SETIMAGE*/, topointer(tt),h);
		if(retPrev){
			if(delPrev){
				::DeleteObject(topointer(retPrev));
				retPrev = true;
			}
		} 
		owner._setPosRatio(l,t,r,b);  
		return retPrev;
	}
	autosize =  {
		_get = function(){   
			return !..win.getStyle(owner.hwnd,0x40/*_SS_REALSIZECONTROL*/);
		}
		_set = function( v ){
			owner.modifyStyle( 0x40/*_SS_REALSIZECONTROL*/,!v?0x40/*_SS_REALSIZECONTROL*/:0 ) 
		}	
	}
	center =  {
		_get = function(){   
			return !!..win.getStyle(owner.hwnd,0x200/*_SS_CENTERIMAGE*/);
		}
		_set = function( v ){
			owner.modifyStyle( 0x200/*_SS_CENTERIMAGE*/,v?0x200/*_SS_CENTERIMAGE*/:0 ) 
		}	
	}  
)
  
/***intellisense()
!picturebox.cls = 设计时类名
!picturebox.className = 运行时类名
!picturebox.image = 按钮图片或图标\n赋值必须是图片文件路径或数据\n位图句柄由窗体负责销毁\n取值时返回位图句柄
!picturebox.setIcon(__/*图标句柄*/) = 设置图标\n成功返回true,自动销毁原来的位图
!picturebox.setImage(__/*图片句柄*/) = 设置图片\n成功返回true,自动销毁原来的位图
!picturebox.setIcon(__/*图标句柄*/,false) = 设置图标\n成功返回控件原来的位图句柄,\n必须调用::DeleteObject()函数销毁该句柄
!picturebox.setImage(__/*图片句柄*/,false) = 设置图片\n成功返回控件原来的位图句柄,\n必须调用::DeleteObject()函数销毁该句柄
!picturebox.hwnd = 控件句柄
!picturebox.id = 控件ID
!picturebox._parentForm = 控件所在的父窗口(指win.form对象)\n!winform.
!picturebox.getParent() = 返回父窗口\n!static.
!picturebox.setParent(__/*控件对象*/) = 改变父窗口 
!picturebox.hide = 控件是否隐藏
!picturebox.disabled = 是否禁用
!picturebox.left = 左侧坐标
!picturebox.right = 右侧坐标
!picturebox.top = 顶部坐标
!picturebox.bottom = 底部坐标
!picturebox.width = 宽度
!picturebox.height = 高度
!picturebox.redraw() = 刷新
!picturebox.show(true__) = 显示控件
!picturebox.getRect() = 控件区块位置(::RECT结构体)
!picturebox.getRect(true) = 控件屏幕区块位置(::RECT结构体)  
!picturebox.setRect(rc) = 设置控件区块位置(::RECT结构体)  
!picturebox.setRect(rc,true) = 设置控件屏幕区块位置(::RECT结构体)
!picturebox.getClientRect() =  控件客户区块位置(::RECT结构体)\n!rect. 
!picturebox.clientRect =  获取控件客户区块位置(::RECT结构体)
!picturebox.theme = 外观主题,例如\nwinform.button.theme = "Explorer"\nwinform.button.theme = false
!picturebox.modifyStyle(.(remove,add) = 如果指定第三个参数，则使用此参数调用::SetWidnowPos 
!picturebox.modifyStyleEx(.(remove,add) = 如果指定第三个参数，则使用此参数调用::SetWidnowPos
!picturebox.capture = 是否捕获全局鼠标消息
!picturebox.close() = 关闭控件
!picturebox.invalidate(__/*可选使用::RECT()对象指定客户区*/) = 使窗口绘图区无效
!picturebox.invalidate(__/*可选使用::RECT()对象指定客户区*/,0) = 使窗口绘图区无效\n不刷新背景
!picturebox.update() = 重绘invalidate函数指定的区块
!picturebox.setFocus() = 设置焦点 
!picturebox.autosize = 是否允许控件自适应图片大小\n设置center属性为true时,autosize属性无效
!picturebox.center = 图像居中显示,并禁用图象缩放,\n禁止控件自动调整大小
!picturebox.setPos(.(x坐标,y坐标,宽,高,插入位置,参数) = 调整窗口位置或排序,所有参数可选\n同时指定x,y坐标则移动位置\n同时指定宽高则改变大小\n指定插入位置(句柄或_HWND前缀常量)则调整Z序
!picturebox.getPos() = 返回相对坐标,宽,高\nx,y,cx,cy=win.getPos(hwnd)
?win.ui.ctrl.picturebox  =!picturebox.
win.ui.ctrl.picturebox() = 图片控件\n!picturebox.
end intellisense***/



