Result = DragOSFormats(Formats(), Count [, Actions])
Starts a Drag & Drop operation with a list of custom data formats. The types of formats available and the way in which they are represented depends on the Operating system. This function offers the possibility to work with formats not natively supported by PureBasic, while still using the simple mechanisms provided by this library to carry out the Drag & Drop operation.


Formats() An array of DragDataFormat structures containing one or more formats to drag. The structure has the following form:
  Structure DragDataFormat
    Format.i    ; The OS specific ID for the format to drag (see below for more information)
   *Buffer      ; The memory buffer containing the data in this format
    Size.i      ; The size of the data in the buffer
On Windows, the 'Format' field specifies a CLIPBOARDFORMAT value. It can be any standard clipboard format (found in the Windows SDK), or a format registered with the RegisterClipboardFormat_() API.
On Linux, the 'Format' field specifies a GdkAtom value. It can be created with the gdk function gdk_atom_intern_(). Widely understood atoms are the common mime types (ie "text/html" for html data). The atom can also be created with any string that is understood by the target application.
On MacOSX, the 'Format' field specifies a clipboard scrap type. These are 4 letter numeric character constants, for example 'TEXT'. There are a number of predefined scrap types, but also custom values can be used if the target program understands them.
Count The number of formats in the array.

If multiple formats are dragged, the target will accept the first one it recognizes. So the format that provides the most information (i.e. represents the data most accurately) should be first in the array, with less descriptive but more common formats later. This way each application will get the best representation of the data that it understands.
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. (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 data from your application.


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.

See Also

DragText(), DragImage(), DragFiles(), DragPrivate(), SetDragCallback()

Supported OS


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