1.
2.
class richedit{
ctor(parent,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*/;
//保护成员
var m_wap = false //自动换行
}
@metaProperty;
}
richedit.metaProperty = editDecorateMeta ( ..win.ui.ctrl.metaProperty(
wrap = {
_get = function(){
return m_wap;
}
_set = function(v){
m_wap = v;
var hwnd = owner.hwnd;;
if (v) {
var hdc = ::GetDC(hwnd);
::SendMessageInt(hwnd, 0x448/*_EM_SETTARGETDEVICE*/, hdc, 0);
::ReleaseDC(hwnd, hdc);
}
else
::SendMessageInt(hwnd, 0x448/*_EM_SETTARGETDEVICE*/, 0, 1);
}
};
link = {
_set = function(v){
::SendMessageInt(owner.hwnd, 0x445/*_EM_SETEVENTMASK*/, 0, 0x4000000/*_ENM_LINK */| ::SendMessageInt(owner.hwnd, 0x43B/*_EM_GETEVENTMASK*/, 0, 0));
::SendMessageInt(owner.hwnd, 0x000045b/*EM_AUTOURLDETECT*/, 1, 0);
}
}
//这里我们使用一个反向的装饰继承类来封装edit与richedit控件的公用属性
class editDecorateMeta{
ctor(meta)begin
this = meta
end;
//公用属性
//--------------------------------------
modified = {
_get = function(){
return ::SendMessage(owner[["hwnd"]],0xB8/*_EM_GETMODIFY*/);
}
_set = function( v ){
::SendMessageInt(owner[["hwnd"]],0xB9/*_EM_SETMODIFY*/,0,v );
}
};
limit = {
_get = function(){
return ::SendMessage(owner[["hwnd"]], 0x425/*_EM_GETLIMITTEXT*/, null , null);
}
_set = function( v ){
assert( type(v) == type.number )
::SendMessage(owner[["hwnd"]], 0xC5/*_EM_LIMITTEXT*/, topointer(v) , null)
}
}
selText = {
_get = function(){
var re,min,max = ::SendMessageRefInt(owner[["hwnd"]],0xB0/*_EM_GETSEL*/,0,0);
if(max>min){
var re,str = ::SendMessageByString( owner[["hwnd"]],0x43E/*_EM_GETselText*/,0,max-min+1);
return str;
}
}
_set = function( v ){
::SendMessageByString(owner[["hwnd"]],0xC2/*_EM_REPLACESEL*/,0,v)
}
}
//公用方法
//--------------------------------------
getsel = function(){
//获取起始和结束位置
var re,min,max = ::SendMessageRefInt(owner[["hwnd"]],0xB0/*_EM_GETSEL*/,0,0);
return min;max ;
}
setsel = function(min=0,max=0){
//获取起始和结束位置
::SendMessageInt(owner[["hwnd"]],0xB1/*_EM_SETSEL*/,min ,max);
}
lineCount = {
_get = function(){
return ::SendMessage(owner[["hwnd"]],0xBA/*_EM_GETLINECOUNT*/);
}
};
lineText = function(ind){
ind++;
var len = ::SendMessage(owner[["hwnd"]],0xC1/*_EM_LINELENGTH*/,topointer(ind));
var buffer = ..raw.toarray( len,"INT" )
buffer.array = { len };//Before sending the message, set the first word of this buffer to the size, in TCHARs, of the buffer
::SendMessageByStruct( owner[["hwnd"]],0xC4/*_EM_GETLINE*/,ind,buffer);
return ..raw.tostring(buffer);
}
lineFromChar = function(pos){
pos--;
return ::SendMessage(owner[["hwnd"]],0xC9/*_EM_LINEFROMCHAR*/,topointer(pos) );
}
lineToChar = function(line){
line--;
return ::SendMessage(owner[["hwnd"]],0xBB/*_EM_LINEINDEX*/,topointer(line), );
}
lineScroll = function(line=0,h=0){
::SendMessageInt(owner[["hwnd"]],0xB6/*_EM_LINESCROLL*/,h,line-1 );
}
scrollCaret = function(){
::SendMessage( owner[["hwnd"]] , 0xB7/*_EM_SCROLLCARET*/);
}
}