#! ../mofe --f
# An example program for Motif 1.2 drag and drop,
# which is a little bit more elaborated.
# Gustaf Neumann,    Mohegan Lake, Jan 22, 1994
#
# Note, that drag an drop operations work within an
# application as well as between separate applications.
#
# A drag operation can be initiated with the middle mouse
# button. This program uses only the predefined actions
# (for XmPushButton and TextField widgets) from Motif 1.2.
#
# Short Introduction to Motif 1.2 drag and drop (for details,
# look into the Programmers guide of Motif 1.2):
# 1) Create widgets
# 2) For drag SOURCES, actions to allow dragging have to be provided.
#    Many Motif widgets have this already predefined (eg. the
#    XmPushButtonWidget has a ProcessDrag() action per default
#    defined; otherwise XmDragStart has to be called explicitely
#    by the application)
# 3) For drag TARGETS (dropSite, i.e. a widget or gadget where 
#    contents are dragged into), the command XmDropSiteRegister has to be 
#    issued, which defines among other things a drop procedure
# 4) When a drag action is started by the user, a unique dragContext is 
#    created automatically, which is destroyed automatically when the
#    drop is completed.
# 5) When a drop is performed in a drag target, the drop procedure
#    is executed and can access the dragContext 
# 6) The drop procedure should issue XmDropTransferStart to actually
#    transfer the data. This procedure creates a DropTransfer object
#    with several resources such as a transferProc
# 7) The transfer procedure receives destination (widget reference)
#    of the drag target and a (converted) value from the drag source

XmRowColumn rc topLevel
XmPushButton btn1 rc labelString "Drag me"
XmPushButton btn2 rc labelString "Drop into me"
XmPushButton quit rc labelString "Quit" activateCallback quit
XmTextField f rc 
realize

XmDropSiteRegister btn2 \
  dropProc {doDrop btn2 %W} \
  numImportTargets 1 \
  importTargets COMPOUND_TEXT

proc doDrop {target dragContext} {
  XmDropTransferStart $dragContext \
    transferProc {doTransfer %d "%v"} \
    dropTransfers "{COMPOUND_TEXT $target}" \
    numDropTransfers 1
}

proc doTransfer {dest value} {
#  puts stderr "\n### dotransfer dest=[format %x $dest] [widgetName $dest]"
  sV $dest labelString $value
}
