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


class combobox{
    ctor(parent,tvalue){
       if(tvalue) {
       		select(tvalue.mode)
			{
				case "dropdown" 
					tvalue.style |= 0x2/*_CBS_DROPDOWN*/         //创建一个下拉式组合框
				case "dropdownlist"  
					tvalue.style |= 0x3/*_CBS_DROPDOWNLIST*/     //创建一个下拉式列表框
				case "simple" 
					tvalue.style |= 0x1/*_CBS_SIMPLE*/              
				//case "autohscroll" 
				//	tvalue.style |= 0x40/*_CBS_AUTOHSCROLL*/  								//当用户在编辑区域键入字符时，列表框自动滚动，使当前项的名称与键入的字符排序相同						
			} 	 
			tvalue.bottom += 100;
	        if(tvalue.edge) tvalue.exstyle |= 0x200/*_WS_EX_CLIENTEDGE*/;
		 
       }
    }
    oncreate = function(){
    	this._defCtrlRect.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 = ..win.ui.ctrl.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);
			tab = {};
			for(i=0;count-1;1){
				var len = ::SendMessage(owner.hwnd, _CB_GETTEXTLEN, topointer(i),null) ;  
				var ret,text  =  ::SendMessageByString(owner.hwnd , _CB_GETTEXT,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.find(__/*请输入文本*/) = 查找列表项
!combobox.items = 组合框内容
!combobox.selText = 读取或设置组合框当前选中文本
!combobox.count = 列表项数目
!combobox.selIndex = 获取或指定当前选中的项
!combobox.selText = 获取或指定当前选中的文本
!combobox.add(__/*请输入文本*/) = 添加到组合框
!combobox.clear() = 清除组合框所有内容
!combobox.delete() = 删除当前选中项
!combobox.findEx = 精确查找指定的项\n找不到返回0 
!combobox.hwnd = 控件句柄
!combobox.id = 控件ID
!combobox.parent = 父窗口
!combobox.parent.hwnd = 父窗口句柄
!combobox.hide = 控件是否隐藏
!combobox.disabled = 控件ID
!combobox.left = 左侧坐标
!combobox.right = 右侧坐标
!combobox.top = 顶部坐标
!combobox.bottom = 底部坐标
!combobox.redraw() = 刷新
!combobox.show(true__) = 显示控件
!combobox.rect = 控件区块位置(::RECT结构体)
!combobox.clientRect =  控件客户区块位置(::RECT结构体)
!combobox.font = 控件字体(::LOGFONT结构体)
!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.
end intellisense***/