//combobox 下拉框
import win.ui.ctrl.metaProperty;//导入控件属性元表支持
namespace win.ui.ctrl;  

class combobox{
    ctor(parent,tParam){
       if(tParam) {
       		select(tParam.mode) {
				case "dropdown" 
					tParam.style |= 0x2/*_CBS_DROPDOWN*/         //创建一个下拉式组合框
				case "dropdownlist"  
					tParam.style |= 0x3/*_CBS_DROPDOWNLIST*/     //创建一个下拉式列表框
				case "simple" 
					tParam.style |= 0x1/*_CBS_SIMPLE*/              
				//case "autohscroll" 
				//	tParam.style |= 0x40/*_CBS_AUTOHSCROLL*/  								//当用户在编辑区域键入字符时，列表框自动滚动，使当前项的名称与键入的字符排序相同						
			} 	 
			tParam.bottom += 100;
	        if(tParam.edge) tParam.exstyle |= 0x200/*_WS_EX_CLIENTEDGE*/; 
       } 
    }
    onCreate = function(){
    	this._defRect.bottom+=100;
    } 
   
	add = function( str){//listbox添加项 
        ::SendMessage(this.hwnd  , 0x143/*_CB_ADDSTRING*/, topointer( this.count ),str)
    } 
    clear = function(){
       ::SendMessage(this.hwnd , 0x14B/*_CB_RESETCONTENT*/ )
    } 
    delete = function(ind){
       if(!ind)
       		ind=this.selIndex;
       ::SendMessage(this.hwnd , 0x144/*_CB_DELETESTRING*/, topointer(ind-1 ) )
    }
    find = function(v){//在列表框里查找指定的项
    	var  ind =  ::SendMessage(owner.hwnd ,  0x14C/*_CB_FINDSTRING*/,  ,v);  
    	return ind!=-1/*_CB_ERR*/?ind+1:0 
    }  
	findEx = function( str ){//精确查找指定的项
		var ind = ::SendMessage(this.hwnd , 0x158/*_CB_FINDSTRINGEXACT*/, , str ) ;
		return ind!=-1/*_CB_ERR*/?ind+1:0
	} 
    

	@_metaProperty; 
 
}


combobox._metaProperty = metaProperty(

	count = {
		_get = function(){ 
			return ::SendMessage(owner.hwnd, 0x146/*_CB_GETCOUNT*/, null,null) 
		} 	
	};
	selIndex = {
		_get = function(){ 
			return ::SendMessage(owner.hwnd, 0x147/*_CB_GETCURSEL*/) + 1;
		}
		_set = function( v ){
		 	::SendMessage(owner.hwnd, 0x14E/*_CB_SETCURSEL*/, topointer(v-1) )  
	    }
	}; 
	selText = {
		_get = function(){ 
			var sel =  ::SendMessage(owner.hwnd, 0x147/*_CB_GETCURSEL*/ )
     		var len = ::SendMessage(owner.hwnd, 0x149/*_CB_GETLBTEXTLEN*/, topointer(sel)); 
     		var re ,text = ::SendMessageByString(owner.hwnd, 0x148/*_CB_GETLBTEXT*/,  sel  ,len+1);
     		return  ..string.str( text:"" )
		} 
		_set = function(v){
			::SendMessage(owner.hwnd, 0x14D/*_CB_SELECTSTRING*/, ,v);
		}
		
	}; 
	items = {
		_get = function(){ 
			var count = ::SendMessage(owner.hwnd, 0x146/*_CB_GETCOUNT*/, null, null);
			var tab = {};
			for(i=0;count-1;1){ 
				var len = ::SendMessageInt(owner.hwnd, 0x149/*_CB_GETLBTEXTLEN*/, i,0) ;  
				var ret,text  =  ::SendMessageByString(owner.hwnd , 0x148/*_CB_GETLBTEXT*/,i,len+1);

               	..table.push(tab,..string.str( text) )
            }
            
			return tab;
		}
		_set = function( v ){
			 if( type(v) == type.table )
			 { 
		       	for( i=1;#(v) ){ //0x14A/*_CB_INSERTSTRING*/插入，不排序，0x143/*_CB_ADDSTRING*/插入，支持0x100/*_CBS_SORT*/排序
				        ::SendMessage(owner.hwnd , 0x143/*_CB_ADDSTRING*/, null,v[i]);  
				} 
			 }
		} 	
	}
	
)


/***intellisense()
!combobox.cls = 设计时类名
!combobox.className = 运行时类名
!combobox.find(__/*请输入文本*/) = 查找列表项
!combobox.items = 组合框内容
!combobox.selText = 读取或设置组合框当前选中文本
!combobox.text = 组合框当前输入文本
!combobox.count = 列表项数目
!combobox.selIndex = 获取或指定当前选中的项
!combobox.selText = 获取或指定当前选中的文本
!combobox.add(__/*请输入文本*/) = 添加到组合框
!combobox.clear() = 清除组合框所有内容
!combobox.delete() = 删除当前选中项
!combobox.findEx = 精确查找指定的项\n找不到返回0 
!combobox.hwnd = 控件句柄
!combobox.id = 控件ID
!combobox._parentForm = 控件所在的父窗口(指win.form对象)\n!winform.
!combobox.getParent() = 返回父窗口\n!static.
!combobox.setParent(__/*控件对象*/) = 改变父窗口 
!combobox.hide = 控件是否隐藏
!combobox.disabled = 是否禁用
!combobox.left = 左侧坐标
!combobox.right = 右侧坐标
!combobox.top = 顶部坐标
!combobox.bottom = 底部坐标
!combobox.width = 宽度
!combobox.height = 高度
!combobox.redraw() = 刷新
!combobox.show(true__) = 显示控件
!combobox.getRect() = 控件区块位置(::RECT结构体)
!combobox.getRect(true) = 控件屏幕区块位置(::RECT结构体)  
!combobox.setRect(rc) = 设置控件区块位置(::RECT结构体)  
!combobox.setRect(rc,true) = 设置控件屏幕区块位置(::RECT结构体)
!combobox.getClientRect() =  控件客户区块位置(::RECT结构体)\n!rect.
!combobox.getFont() = 控件字体(::LOGFONT结构体)\n!logfont.
!combobox.setFont(__/*指定字体*/) = 指定LOGFONT字体对象,或逻辑字体句柄 
!combobox.setFont(混入字体属性) = @.setFont(point=10;name="宋体");
!combobox.clientRect =  获取控件客户区块位置(::RECT结构体)
!combobox.theme = 外观主题,例如\nwinform.button.theme = "Explorer"\nwinform.button.theme = false
!combobox.modifyStyle(.(remove,add) = 如果指定第三个参数，则使用此参数调用::SetWidnowPos 
!combobox.modifyStyleEx(.(remove,add) = 如果指定第三个参数，则使用此参数调用::SetWidnowPos
!combobox.capture = 是否捕获全局鼠标消息
!combobox.close() = 关闭控件窗口
!combobox.invalidate(__/*可选使用::RECT()对象指定客户区*/) = 使窗口绘图区无效
!combobox.invalidate(__/*可选使用::RECT()对象指定客户区*/,0) = 使窗口绘图区无效\n不刷新背景
!combobox.update() = 重绘invalidate函数指定的区块
!combobox.setFocus() = 设置焦点 
!combobox.setPos(.(x坐标,y坐标,宽,高,插入位置,参数) = 调整窗口位置或排序,所有参数可选\n同时指定x,y坐标则移动位置\n同时指定宽高则改变大小\n指定插入位置(句柄或_HWND前缀常量)则调整Z序
!combobox.getPos() = 返回相对坐标,宽,高\nx,y,cx,cy=win.getPos(hwnd)
?win.ui.ctrl.combobox  =!combobox.
win.ui.ctrl.combobox() = 下拉框控件\n!combobox.
end intellisense***/