TreeGadget - Drag'n'Drop - scroll automatically
Posted: Tue May 25, 2010 11:56 am
I've got a TreeGadget which is populated with entries to be drag'n'drop sorted, into an order a user is happy with (similar to a playlist).
Now I've got the d&d sorting done, but would like the TreeGadget to scroll automatically if the item being dragged is brought above the top or below the bottom of the gadget, so the item can be dragged in one motion, rather than dropping it - scrolling - re-drag and then drop.
Any suggestions?
For example, In following code I want to drag'n'drop Item0 between Item49 & Item50. This takes three d&d and two scrolls (and would be more if there was more items in the list). I would like to be able to do it in one drag'n'drop.
Now I've got the d&d sorting done, but would like the TreeGadget to scroll automatically if the item being dragged is brought above the top or below the bottom of the gadget, so the item can be dragged in one motion, rather than dropping it - scrolling - re-drag and then drop.
Any suggestions?
For example, In following code I want to drag'n'drop Item0 between Item49 & Item50. This takes three d&d and two scrolls (and would be more if there was more items in the list). I would like to be able to do it in one drag'n'drop.
Code: Select all
#PrivateType = 0
#Tree = 51
Procedure TreeMoveItem(SourceItem,TargetItem)
; copy everything here (also colors and GetGadgetItemData() etc if you use that)
text.s=GetGadgetItemText(#Tree, SourceItem)
RemoveGadgetItem(#Tree, SourceItem)
AddGadgetItem(#Tree, TargetItem, text, 0, -1)
; paste details back here
SetGadgetState(#Tree, TargetItem)
EndProcedure
If OpenWindow(0, 100, 100, 300, 400, "DRAG FOLLOW TEST", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget)
TreeGadget(#Tree,0,0,300,400,#PB_Tree_NoLines | #PB_Tree_NoButtons | #PB_Tree_AlwaysShowSelection)
EnableGadgetDrop(#Tree, #PB_Drop_Private, #PB_Drag_Move, #PrivateType)
For i = 0 To 50
AddGadgetItem(#Tree, -1, "Item" + Str(i), 0, 0)
Next i
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case #Tree
If EventType() = #PB_EventType_DragStart
SourceItem = GetGadgetState(#Tree)
DragPrivate(#PrivateType, #PB_Drag_Move)
EndIf
EndSelect
Case #PB_Event_GadgetDrop
If EventDropType() = #PB_Drop_Private And EventDropPrivate() = #PrivateType
TargetItem = GetGadgetState(#Tree)
If TargetItem = -1
TargetItem = CountGadgetItems(#Tree)
EndIf
If SourceItem <> TargetItem
If TargetItem > SourceItem
TreeMoveItem(SourceItem,TargetItem)
ElseIf TargetItem <= SourceItem
TargetItem+1
TreeMoveItem(SourceItem,TargetItem)
EndIf
EndIf
EndIf
EndSelect
Until Event = #PB_Event_CloseWindow
EndIf
End