import win.ui.ctrl.edit;
namespace win.ui.ctrl; 

var CHARRANGE = class {
	int cpMin;
	int cpMax;
}
var ENLINK_STRUCT = class {
	struct	hdr = ..win.ui.NMHDR();
	int		msg;
	int		wParam;
	int		lParam;
	struct	chrg = CHARRANGE();
} 

class richedit{
    ctor(parent,tvalue){ 
        if( tvalue ){
			if(! _STUDIO_INVOKED)
      				_dll := ..raw.loadDll("RICHED20.DLL"); 
			
			tvalue.cls = "RichEdit20A";
			
			if( tvalue.multiline ) 
					tvalue.style |= 0x4/*_ES_MULTILINE*/  
					
			if( tvalue.multiline ){
				tvalue.style |= 0x4/*_ES_MULTILINE*/
				tvalue.style |= 0x1000/*_ES_WANTRETURN*/;
			}
				
			if( tvalue.readonly )
				tvalue.style |= 0x800/*_ES_READONLY*/
			if( tvalue.password )
				tvalue.style |= 0x20/*_ES_PASSWORD*/
			if(! tvalue.hidesel )
				tvalue.style |= 0x100/*_ES_NOHIDESEL*/
				
			tvalue.bgcolor := 16777215;
			
			//输入时文本框自动向右，向下滚动
			tvalue.style |=  ( 0x80/*_ES_AUTOHSCROLL*/ |  0x40/*_ES_AUTOVSCROLL*/ )
			
			select(tvalue.align) {
			case  "center"   
			tvalue.style |= 0x1/*_ES_CENTER*/; 
			case "right" 
			tvalue.style |= 0x2/*_ES_RIGHT*/; 
			else 
			tvalue.style |= 0x0/*_ES_LEFT*/;
			}
				
			if(tvalue.edge) tvalue.exstyle |= 0x200/*_WS_EX_CLIENTEDGE*/;
	    }
	    
    }
   
	@metaProperty;
} 

richedit.metaProperty = editDecorateMeta ( ..win.ui.ctrl.metaProperty(
	modifyEvent = function( remove=0,add=0 ){ 
		var e = ( ::SendMessage(owner.hwnd, 0x43B/*_EM_GETEVENTMASK*/ ) & ~remove ) | add ; 
		::SendMessageInt(owner.hwnd, 0x445/*_EM_SETEVENTMASK*/, 0, e )
		return e;
	}
	limit = {  
		_set = function( v ){ 
     		::SendMessageInt(owner[["hwnd"]], 0x435/*_EM_EXLIMITTEXT*/, 0, v) 
		} 	
	} 
	wrap = { 
    	_set = function(v){
    		m_wap = v;
    		var hwnd = owner.hwnd;;
    		if (v) {  
        		var hdc = ::GetDC(hwnd); 
        		::SendMessage(hwnd, 0x448/*_EM_SETTARGETDEVICE*/, hdc);
        		::ReleaseDC(hwnd, hdc);
    		}
    		else 
        		::SendMessageInt(hwnd, 0x448/*_EM_SETTARGETDEVICE*/, 0, 1); 
	
    	}
    	
	};
	link =  {
		_set = function(v){  
			owner.modifyEvent( , 0x4000000/*_ENM_LINK */ ) 
			::SendMessageInt(owner.hwnd, 0x000045b/*EM_AUTOURLDETECT*/, v?1:0, 0);    
		}
		
	} 
	_prenotify = function(id,code,nmdr){
    	if(code== 0x070B/*_EN_LINK*/ && owner.onlink ){
    		var link = ENLINK_STRUCT();
			..raw.convert(nmdr, link);
			 owner.onlink(link.msg,owner.rangeText( link.chrg.cpMin,link.chrg.cpMax) )
    	}
    }
	

 ) )
 


/***intellisense()
?win.ui.ctrl.richedit  =!richedit.
!richedit.modifyEvent(.(移除通知,添加通知) = 启用或禁用通知消息,返回EVENTMASK值
!richedit.lineCount = 获取行数
!richedit.setsel(1,__) = 设置选区,参数(起始位置,结束位置)
!richedit.getsel() = 获取选区起始位置,结束位置
!richedit.selText = 获取或设置选区文本
!richedit.modified = 文本内容是否已修改
!richedit.rangeText(.(起始位置,结束位置) = 返回指定位置文本
!richedit.text = 编辑控件文本属性
!richedit.hwnd = 控件句柄
!richedit.id = 控件ID
!richedit.parent = 父窗口
!richedit.parent.hwnd = 父窗口句柄
!richedit.hide = 控件是否隐藏
!richedit.disabled = 控件时否可见
!richedit.left = 左侧坐标
!richedit.right = 右侧坐标
!richedit.top = 顶部坐标
!richedit.bottom = 底部坐标
!richedit.limit = 字符数限制
!richedit.scrollCaret = 滚动到光标处
!richedit.lineScroll(.(滚动到指定行) = 滚动条移动到指定行
!richedit.lineScroll(.(滚动指定行) = 滚动条移动到指定行
!richedit.lineToChar = 获取指定行首字符偏移位置
!richedit.lineFromChar = 返回指定位置行数
!richedit.lineText = 获取指定行文本
!richedit.redraw() = 刷新
!richedit.show(true__) = 显示控件
!richedit.rect = 控件区块位置(::RECT结构体)
!richedit.clientRect =  控件客户区块位置(::RECT结构体)
!richedit.font = 控件字体(::LOGFONT结构体)
!richedit.clientRect =  获取控件客户区块位置(::RECT结构体)
!richedit.theme = 外观主题,例如\nwinform.button.theme = "Explorer"\nwinform.button.theme = false
!richedit.modifyStyle(.(remove,add) = 如果指定第三个参数，则使用此参数调用::SetWidnowPos 
!richedit.modifyStyleEx(.(remove,add) = 如果指定第三个参数，则使用此参数调用::SetWidnowPos
!richedit.capture = 是否捕获全局鼠标消自息
!richedit.close() = 关闭控件窗
!richedit.invalidate(__/*可选使用::RECT()对象指定客户区*/) = 使窗口绘图区无效
!richedit.invalidate(__/*可选使用::RECT()对象指定客户区*/,0) = 使窗口绘图区无效\n不刷新背景
!richedit.update() = 重绘invalidate函数指定的区块
!richedit.wrap = 是否启用自动换行，仅richedit支持
!richedit.onlink = @.onlink=function(msg,title){\n	\n}
!richedit.setFocus() = 设置焦点 
!richedit.setPos(.(x坐标,y坐标,宽,高,插入位置,参数) = 调整窗口位置或排序,所有参数可选\n同时指定x,y坐标则移动位置\n同时指定宽高则改变大小\n指定插入位置(句柄或_HWND前缀常量)则调整Z序
!richedit.getPos() = 返回相对坐标,宽,高\nx,y,cx,cy=win.getPos(hwnd)
end intellisense***/