03-29-2016, 04:16 AM
Hi again,
Please, any advice on how can I drop an item to other destination than the root?
Regards.
Function dialog_treeview_xml2
Function drag_test_proc2
Please, any advice on how can I drop an item to other destination than the root?
Regards.
Function dialog_treeview_xml2
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages
;create xml macro if does not exist
if !qmitem("TreeView_Test_XML" 1)
,_s=
;<x>
,;<x t="a">
,,;<x t="a1" />
,,;<x t="a2" />
,,;<x t="a3" />
,;</x>
,;<x t="b" />
;</x>
,newitem("TreeView_Test_XML" _s)
str controls = "5"
str e5
if(!ShowDialog("dialog_treeview_xml2" &dialog_treeview_xml2 &controls)) ret
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
;3 SysTreeView32 0x54010027 0x0 0 0 96 116 ""
;5 Edit 0x54030080 0x200 102 6 118 14 ""
;4 Button 0x54032000 0x0 102 24 118 14 "Add child of selected"
;6 Button 0x54032000 0x0 154 44 66 14 "Delete selected"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2030300 "" "" ""
ret
;messages
sel message
,case WM_INITDIALOG
,_s.getmacro("TreeView_Test_XML")
,if(_s.len) XmlToTreeView _s id(3 hDlg)
,
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_NOTIFY goto messages3
ret
;messages2
sel wParam
,case IDOK
,;save tree view control data to xml macro
,XmlFromTreeView _s id(3 hDlg)
,_s.setmacro("TreeView_Test_XML")
,
,case 4 ;;add child item of selected item
,_s.getwintext(id(5 hDlg))
,TvAdd id(3 hDlg) SendMessage(id(3 hDlg) TVM_GETNEXTITEM TVGN_CARET 0) _s
,InvalidateRect id(3 hDlg) 0 1 ;;redraw
,
,case 6 ;;delete selected item
,_i=SendMessage(id(3 hDlg) TVM_GETNEXTITEM TVGN_CARET 0)
,if(_i) SendMessage(id(3 hDlg) TVM_DELETEITEM 0 _i) ;;else deletes all
,
,case IDCANCEL
ret 1
;messages3
int i
NMHDR* nh=+lParam
sel nh.idFrom
,case 3
,NMTREEVIEW* nt=+nh
,if(nh.code=TVN_SELCHANGEDW or nh.code=TVN_SELCHANGED)
,,i=nt.itemNew.lParam ;;was set by TvAdd
,else if(nh.code=TVN_BEGINDRAGW or nh.code=TVN_BEGINDRAG)
,,type TVDRAG49 htv hidrag
,,TVDRAG49 td.htv=nh.hwndFrom; td.hidrag=nt.itemNew.hItem
,,Drag(hDlg &drag_test_proc2 &td)
,,SendMessage td.htv TVM_SELECTITEM TVGN_DROPHILITE 0
ret
Function drag_test_proc2
;/
function button TVDRAG49&td
TVHITTESTINFO ht
xm ht.pt; ScreenToClient(td.htv &ht.pt)
int hidrop=SendMessage(td.htv TVM_HITTEST 0 &ht)
int candrop=hidrop or ht.flags&TVHT_NOWHERE
if(button)
,SendMessage td.htv TVM_SELECTITEM TVGN_DROPHILITE 0
,if(!candrop) ret
,ret TvMoveItem(td.htv td.hidrag hidrop GetMod=2)
else
,SendMessage td.htv TVM_SELECTITEM TVGN_DROPHILITE hidrop
,if(!candrop) ret 3
,ret iif(GetMod=2 2 1)
;instead of TVM_SELECTITEM could use TVM_SETINSERTMARK, but then need more calculations