DragPrivate()

Syntax

Result = DragPrivate(Type [, Actions])
Description
Starts a "private" Drag & Drop operation. Unlike the other functions that start Drag & Drop, this data can only be dropped inside the application (Data dragged with functions like DragText() or DragImage() can be accepted by other applications as well). This function should be used to add Drag & Drop functionality between Gadgets or Windows with data that would not be understood by other applications.

Parameters

Type This parameter can be any integer value that identifies the data to be dragged in the application. The same value must be specified for EnableGadgetDrop() or EnableWindowDrop() for those Gadget/Windows that should accept this data.
This way it can be exactly defined which private drag operation will be accepted by Gadget/Window, which allows complex Drag & Drop schemes to be realized.
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 data can be copied
  #PB_Drag_Move: The data can be moved
  #PB_Drag_Link: The data 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.

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.

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.

If the operation was not aborted, the event loop will receive a #PB_Event_WindowDrop or #PB_Event_GadgetDrop event of type #PB_Drop_Private.

Example

  Enumeration ; Gadgets
    #List1
    #List2
  EndEnumeration
  
  If OpenWindow(0, 0, 0, 415, 410, "Drag from List1 to List2", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ListIconGadget(#List1, 5, 5, 200, 400, "List1" , 140)
    ListIconGadget(#List2, 210, 5, 200, 400, "List2" , 140)
    
    For i = 0 To 9
      AddGadgetItem(#List1, -1, "Item " + Str(i))
      AddGadgetItem(#List2, -1, "Item " + Str(i + 10))
    Next
    
    ; Allows dragging an element from #List1 to #List2
    EnableGadgetDrop(#List2, #PB_Drop_Private, #PB_Drag_Copy, 1)
    
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_GadgetDrop ; the drag event
          Select EventGadget()
            Case #List2
              Select EventDropType()
                Case #PB_Drop_Private
                  tmp = GetGadgetState(#List2)
                  AddGadgetItem(#List2, tmp, tmp$)
                  tmp = GetGadgetState(#List1)
                  RemoveGadgetItem(#List1, tmp)
              EndSelect
          EndSelect
        Case #PB_Event_Gadget
          Select EventGadget()
            Case #List1
              Select EventType()
                Case #PB_EventType_DragStart
                  tmp = GetGadgetState(#List1)
                  If tmp <> -1
                    tmp$ = GetGadgetItemText(#List1, tmp)
                    DragPrivate(1) ; set drag type = 1 until successful drop action (into #List2)
                  EndIf
              EndSelect
          EndSelect
        Case #PB_Event_CloseWindow
          End
      EndSelect
    ForEver
  EndIf

See Also

DragText(), DragImage(), DragFiles(), DragOSFormats(), SetDragCallback()

Supported OS

Windows, Linux

<- DragOSFormats() - DragDrop Index - DragText() ->