//listview原地编辑效果
//范例参考 http://www.aau.cn/thread-5446-1-1.html 
import win.ui;
/*DSG{{*/
var winform = win.form( right=522;bottom=300;parent=...;text="listview原地编辑效果 by adsadss ";border="resizable" )
winform.add( 
listview={ dr=1;dl=1;bgcolor=16777215;right=505;left=26;dt=1;db=1;cls="listview";bottom=217;top=23;z=1;gridLines=1;edge=1;fullRow=1 };
static={ bottom=278;color=255;right=498;left=28;top=228;font=LOGFONT( h=-14;weight=700 );transparent=1;text="static";z=2;cls="static" }
)
/*}}*/

winform.static.text=/*
点击单元格开始编辑。按回车键结束编辑。
listview必须有fullRow=1属性。
*/
winform.listview.insertColumn("测试项1",80) 
winform.listview.insertColumn("测试项2",100) 
winform.listview.insertColumn("测试项3",-1) 
for(i=1;29;1){
    winform.listview.addItem({tostring(i);"点我1";"点我2"});
}
 
winform.listview.onnotify = function(id,code,ptr){
    
    if(code=0xFFFFFFFE/*_NM_CLICK*/ ){
        var notifyMessage = winform.listview.getNotifyMessage(code,ptr);
        if( ! notifyMessage.iItem && notifyMessage.iSubItem ) return ; 
        
        var edit = winform.listview.editlable
        if( ! edit ){
            winform.listview.addCtrl(
                editlable = { 
                    cls="edit";font = LOGFONT( h = 11 );left = 0;top = 0;
                    right = 50;bottom = 50;autoResize = false ;hide = 1;edge = 1;  
                    wndproc = function( hwnd, message, wParam, lParam ){
                    	var update;
                        if( ( message = 0x8/*_WM_KILLFOCUS*/) 
                            || message == 0x101/*_WM_KEYUP*/ && wParam == 0xD/*_VK_RETURN*/){
                            update = true;
                        ｝
                        elseif(message == 0x201/*_WM_LBUTTONDOWN*/ || message == 0x202/*_WM_LBUTTONUP*/ ){
                        	var x,y = win.getMessagePos(lParam)
                        	var rc = edit.clientRect;  
                        	if( ! ::PtInRect(rc,x,y) ){
                        		update = true;
                        		edit.capture = false;
                        	}
                        	else{
                        		edit.capture = true;
                        	}
                        } 
                        
                        if( update ){
                            owner.parent.setItemText( owner.text, owner.listViewNotifyMessage.iItem
                                , owner.listViewNotifyMessage.iSubItem );
                            owner.show(false);
                        }
                    }  
                }
            )  
            edit = winform.listview.editlable;
        }
        edit.listViewNotifyMessage = notifyMessage; 
        edit.text=winform.listview.getItemText(notifyMessage.iItem,notifyMessage.iSubItem);
        var rc=winform.listview.getItemRect( notifyMessage.iItem,notifyMessage.iSubItem,,2/*_LVIR_LABEL*/ )
        rc.right += 5; rc.bottom += 5;
        edit.setRect(rc);
        edit.show(); 
        edit.setFocus();
        edit.capture = true;
    } 
}

winform.show()  
win.loopMessage();

