DragText()

Syntax

Result = DragText(Text$ [, Actions])
Description
Starts a Drag & Drop operation with text data.

Parameters

Text$ The text to drag.
Actions (optional) A combination of the Drag & Drop actions that should be allowed for the data. If the parameter is not specified, #PB_Drag_Copy will be the only allowed action. Possible actions are: (they can be combined with '|')
  #PB_Drag_Copy: The text can be copied
  #PB_Drag_Move: The text can be moved
  #PB_Drag_Link: The text can be linked
The user can decide which of these actions to take by pressing modifier keys like Ctrl or Shift. The actions that can really be taken also depend on the actions allowed by the drop target. (On MacOSX, the actions are only treated as a suggestion. The drop target can still choose another action.)

Return value

Returns one of the above Drag & Drop action values to indicate what action the user took, or #PB_Drag_None if the user aborted the Drag & Drop operation.

Note that if #PB_Drag_Move is returned, it is your responsibility to remove the dragged text data from your application.

Remarks

Drag & Drop can basically be started any time, but the left mouse button should be currently pressed as otherwise the operation will end immediately without success. The usual time to start a Drag & Drop operation is when a Gadget reported an event with EventType() of #PB_EventType_DragStart. On MacOS X the #PB_EventType_DragStart event has to be handled using BindEvent() or BindGadgetEvent().

Example

  Procedure DragStartHandler()
    ExamineDraggedItems()
    While NextDraggedItem()
      Text$ + GetGadgetItemText(0, DraggedItemIndex()) + Chr(10)
    Wend
    
    Debug "Dragging text: " + Text$
    
    DragText(Text$)
  EndProcedure

  ; Select some files or folders and drag them to another application
  ;
  If OpenWindow(0, 200, 200, 400, 400, "Drag & Drop")
    ListViewGadget(0, 10, 10, 380, 380, #PB_ListView_MultiSelect)
    AddGadgetItem(0, -1, "Item 1")
    AddGadgetItem(0, -1, "Item 2")
    AddGadgetItem(0, -1, "Item 3")
    
    ; BindGadgetEvent() is required to handle the drag start event
    BindGadgetEvent(0, @DragStartHandler(), #PB_EventType_DragStart)
    
    Repeat
      Event = WaitWindowEvent()
    Until Event = #PB_Event_CloseWindow
  EndIf

See Also

DragFiles(), DragImage(), DragPrivate(), DragOSFormats(), SetDragCallback()

Supported OS

Windows, Linux

<- DragPrivate() - DragDrop Index - DraggedItemIndex() ->