Filled with curiosity, I played with it until I got it working. It is just a quick & dirty solution--to delete the original text, I put it in variable StartPosition for removal. If there is a way to remove it without that var, then please post it.
Code: Select all
; started from PB's HELP File, modified to allow drop in both directions,
; including upon starting gadget.
;
;
#Window = 0
Enumeration ; Images
#ImageSource
#ImageTarget
EndEnumeration
Enumeration ; Gadgets
#SourceText
#SourceImage
#SourceFiles
#SourcePrivate
#TargetText
#TargetImage
#TargetFiles
#TargetPrivate1
#TargetPrivate2
EndEnumeration
If OpenWindow(#Window, 0, 0, 760, 310, "Drag & Drop", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
; Create and fill the source gadgets
;
ListIconGadget(#SourceText, 10, 10, 140, 140, "Drag Text here", 130)
ListIconGadget(#SourcePrivate, 610, 10, 140, 140, "Drag private stuff here", 260)
AddGadgetItem(#SourceText, -1, "1 hello world")
AddGadgetItem(#SourceText, -1, "2 The quick brown fox jumped over the lazy dog")
AddGadgetItem(#SourceText, -1, "3 abcdefg")
AddGadgetItem(#SourceText, -1, "4 123456789")
AddGadgetItem(#SourcePrivate, -1, "Private type 1")
AddGadgetItem(#SourcePrivate, -1, "Private type 2")
; Create the target gadgets
;
ListIconGadget(#TargetText, 10, 160, 140, 140, "Drop Text here", 130)
ListIconGadget(#TargetPrivate1, 460, 160, 140, 140, "Drop Private Type 1 here", 130)
ListIconGadget(#TargetPrivate2, 610, 160, 140, 140, "Drop Private Type 2 here", 130)
; Now enable the dropping on the target gadgets
;
EnableGadgetDrop(#SourceText, #PB_Drop_Text, #PB_Drag_Move | #PB_Drag_Copy) ;this is new
EnableGadgetDrop(#TargetText, #PB_Drop_Text, #PB_Drag_Copy)
EnableGadgetDrop(#TargetPrivate1, #PB_Drop_Private, #PB_Drag_Copy, 1)
EnableGadgetDrop(#TargetPrivate2, #PB_Drop_Private, #PB_Drag_Copy, 2)
Repeat
Event = WaitWindowEvent()
; DragStart event on the source gadgets, initiate a drag & drop
;
If Event = #PB_Event_Gadget And EventType() = #PB_EventType_DragStart
Select EventGadget()
Case #TargetText
Text$ = GetGadgetItemText(#TargetText, GetGadgetState(#TargetText))
DragText(Text$)
Case #SourceText ;this is new.
StartPosition = GetGadgetState(#SourceText)
Text$ = GetGadgetItemText(#SourceText, StartPosition)
DragText(Text$)
; "Private" Drags only work within the program, everything else
; also works with other applications (Explorer, Word, etc)
;
Case #SourcePrivate
If GetGadgetState(#SourcePrivate) = 0
DragPrivate(1)
Else
DragPrivate(2)
EndIf
EndSelect
; Drop event on the target gadgets, receive the dropped data
;
ElseIf Event = #PB_Event_GadgetDrop
Select EventGadget()
Case #SourceText ; this is heavily edited.
temp=GetGadgetState(#SourceText)
RemoveGadgetItem(#SourceText, StartPosition) ; Is there a way to do this all within this CASE statement, no StartPosition var?
AddGadgetItem(#SourceText, GetGadgetState(#SourceText), EventDropText())
Case #TargetText
AddGadgetItem(#TargetText, GetGadgetState(#TargetText), EventDropText())
Case #TargetPrivate1
AddGadgetItem(#TargetPrivate1, -1, "Private type 1 dropped")
Case #TargetPrivate2
AddGadgetItem(#TargetPrivate2, -1, "Private type 2 dropped")
EndSelect
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
End
By the way, if you have been working with ListIcons, do you know how to tell what order the columns are in, and which column the mouse is over? I have only limited time on them, but could only get the first column information. Thanks.