Default Drag and Drop Example

defaultdragdrop.png



rem ' DefaultDragDrop.src

open (unt)"X0"
sysgui! = BBjAPI().getSysGui()

window!= sysgui!.addWindow(100,100,850,800,"Default Drag/Drop",$00010083$)
window!.setCallback(sysgui!.ON_CLOSE,"Close")

rem ' Status Bar
id=100,statbar!=window!.addStatusBar(id)

rem ' BBjCEdit
id=id+1,rw_cedit!=window!.addCEdit(id,20,20,100,100,$$,$0102$)
id=id+1,ro_cedit!=window!.addCEdit(id,130,20,100,100,$$,$0302$)
rw_cedit!.setToolTipText("<html>Editable CEDIT controls support drag and drop in move or copy mode.<br>When dragging from here, the default drag action is move.<br>When dropping here from an editable text component, the default drop action is move.<br>When dropping here from a non-editable text component, or any other kind of control, the default drop action is copy.</html>")
rw_cedit!.setLongCue("Editable CEDIT controls support drag and drop in move or copy mode. Default drag action is move. Drop action is move or copy, depending on the drag source.")
ro_cedit!.setToolTipText("<html>Non-editable CEDIT controls support drag in copy mode.<br>Drop is not supported.</html>")
ro_cedit!.setLongCue("Non-editable CEDIT controls support drag in copy mode. Drop is not supported.")

rem ' BBjEditBox
id=id+1,rw_editbox!=window!.addEditBox(id,20,130,100,30,$$,$$)
id=id+1,ro_editbox!=window!.addEditBox(id,130,130,100,30,$$,$$)
ro_editbox!.setEditable(0)
rw_editbox!.setToolTipText("<html>Editable EDITBOX controls support drag and drop in move or copy mode.<br>When dragging from here, the default drag action is move.<br>When dropping here from an editable text component, the default drop action is move.<br>When dropping here from a non-editable text component, or any other kind of control, the default drop action is copy.</html>")
rw_editbox!.setLongCue("Editable EDITBOX controls support drag and drop in move or copy mode. Default drag action is move. Drop action is move or copy, depending on the drag source.")
ro_editbox!.setToolTipText("<html>Non-editable EDITBOX controls support drag in copy mode.<br>Drop is not supported.</html>")
ro_editbox!.setLongCue("Non-editable EDITBOX controls support drag in copy mode. Drop is not supported.")

rem ' Password BBjEditBox
id=id+1,rw_password!=window!.addEditBox(id,20,170,100,30,$$,$0400$)
id=id+1,ro_password!=window!.addEditBox(id,130,170,100,30,$$,$0400$)
ro_password!.setEditable(0)
rw_password!.setToolTipText("<html>Editable PASSWORD controls support drop in move or copy mode.<br><font color=red><b>For security reasons, drag is not supported.</b></font><br>When dropping here from an editable text component, the default drop action is move.<br>When dropping here from a non-editable text component, or any other kind of control, the default drop action is copy.</html>")
rw_password!.setLongCue("<html><font size=3>Editable PASSWORD controls support drop in move or copy mode.<font color=red><b>Drag is not supported.</b></font>Drop action is move or copy, depending on the drag source.</html>")
ro_password!.setToolTipText("<html>Non-editable PASSWORD controls do not support drag or drop</html>")
ro_password!.setLongCue("Non-editable PASSWORD controls do not support drag or drop.")

rem ' BBjInputE
id=id+1,rw_inpute!=window!.addInputE(id,20,210,100,30,$$,255,"","")
id=id+1,ro_inpute!=window!.addInputE(id,130,210,100,30,$$,255,"","")
ro_inpute!.setEditable(0)
rw_inpute!.setToolTipText("<html>Editable INPUTE controls support drag and drop in move or copy mode.<br>When dragging from here, the default drag action is move.<br>When dropping here from an editable text component, the default drop action is move.<br>When dropping here from a non-editable text component, or any other kind of control, the default drop action is copy.</html>")
rw_inpute!.setLongCue("Editable INPUTE controls support drag and drop in move or copy mode. Default drag action is move. Drop action is move or copy, depending on the drag source.")
ro_inpute!.setToolTipText("<html>Non-editable INPUTE controls support drag in copy mode.<br>Drop is not supported.</html>")
ro_inpute!.setLongCue("Non-editable INPUTE controls support drag in copy mode. Drop is not supported.")

rem ' BBjInputN
id=id+1,rw_inputn!=window!.addInputN(id,20,250,100,30,$$,"-###,###,###.00",$$,0,0)
id=id+1,ro_inputn!=window!.addInputN(id,130,250,100,30,$$,"-###,###,###.00",$$,0,0)
ro_inputn!.setEditable(0)
rw_inputn!.setToolTipText("<html>Editable INPUTN controls support drag and drop in move or copy mode.<br>When dragging from here, the default drag action is move.<br>When dropping here from an editable text component, the default drop action is move.<br>When dropping here from a non-editable text component, or any other kind of control, the default drop action is copy.</html>")
rw_inputn!.setLongCue("Editable INPUTN controls support drag and drop in move or copy mode. Default drag action is move. Drop action is move or copy, depending on the drag source.")
ro_inputn!.setToolTipText("<html>Non-editable INPUTN controls support drag in copy mode.<br>Drop is not supported.</html>")
ro_inputn!.setLongCue("Non-editable INPUTN controls support drag in copy mode. Drop is not supported.")

rem ' BBjInputD
id=id+1,rw_inputd!=window!.addInputD(id,20,290,100,30,$$,"",$$,0,0)
id=id+1,ro_inputd!=window!.addInputD(id,130,290,100,30,$$,"",$$,0,0)
ro_inputd!.setEditable(0)
rw_inputd!.setToolTipText("<html>Editable INPUTD controls support drag and drop in move or copy mode.<br>When dragging from here, the default drag action is move.<br>When dropping here from an editable text component, the default drop action is move.<br>When dropping here from a non-editable text component, or any other kind of control, the default drop action is copy.</html>")
rw_inputd!.setLongCue("Editable INPUTD controls support drag and drop in move or copy mode. Default drag action is move. Drop action is move or copy, depending on the drag source.")
ro_inputd!.setToolTipText("<html>Non-editable INPUTD controls support drag in copy mode.<br>Drop is not supported.</html>")
ro_inputd!.setLongCue("Non-editable INPUTD controls support drag in copy mode. Drop is not supported.")

rem ' BBjListEdit
id=id+1,rw_listedit!=window!.addListEdit(id,20,330,100,100,"")
id=id+1,ro_listedit!=window!.addListEdit(id,130,330,100,100,"")
ro_listedit!.setEditable(0)
rw_listedit!.setToolTipText("<html>Editable LISTEDIT controls support drag and drop in move or copy mode.<br>When dragging from here, the default drag action is move.<br>When dropping here from an editable text component, the default drop action is move.<br>When dropping here from a non-editable text component, or any other kind of control, the default drop action is copy.</html>")
rw_listedit!.setLongCue("Editable LISTEDIT controls support drag and drop in move or copy mode. Default drag action is move. Drop action is move or copy, depending on the drag source.")
ro_listedit!.setToolTipText("<html>Non-editable LISTEDIT controls support drag in copy mode.<br>Drop is not supported.</html>")
ro_listedit!.setLongCue("Non-editable LISTEDIT controls support drag in copy mode. Drop is not supported.")

rem ' BBjListBox
id=id+1,rw_listbox!=window!.addListBox(id,20,370,100,100,"",$0000$)
rw_listbox!.setMultipleSelection(1)
id=id+1,ro_listbox!=window!.addListBox(id,130,370,100,100,"",$0400$)
ro_listbox!.setEditable(0)
ro_listbox!.setMultipleSelection(1)
rw_listbox!.setToolTipText("<html>LISTEDIT controls support drag in copy mode.<br>Drop is not supported.</html>")
rw_listbox!.setLongCue("LISTEDIT controls support drag in copy mode. Drop is not supported.")
ro_listbox!.setToolTipText("<html>LISTEDIT controls support drag in copy mode.<br>Drop is not supported.</html>")
ro_listbox!.setLongCue("LISTEDIT controls support drag in copy mode. Drop is not supported.")

rem ' BBjTree
id=id+1,tree!=window!.addTree(id,20,480,220,130)
parent_id=0,node_id=100
tree!.setRoot(parent_id,"Shakespeare's Plays")
restore shakespeare
dim play$[1:3,0:16]
dread play$[all]
for group=1 to 3
  node_id=node_id+1
  tree!.addExpandableNode(node_id,parent_id,play$[group,0])
  play_parent_id=node_id
  for play=1 to 16
    if play$[group,play]="" then break
    node_id=node_id+1
    tree!.addNode(node_id,play_parent_id,play$[group,play])
  next play
next group
tree!.setToolTipText("<html>TREE controls support drag in copy mode.<br>Drop is not supported.<br>Selected nodes are copied in plain text and as an HTML list.</html>")
tree!.setLongCue("TREE controls support drag in copy mode. Drop is not supported. Selected nodes are copied in plain text and as an HTML list.")

rem ' BBjHtmlView
id=id+1,htmlview!=window!.addHtmlView(id,240,20,600,400,"")
htmlview!.setUrl("http://smacie.com/randomizer/simpsons/homer.html")
htmlview!.setUrl("http://www.drecknet.com/cgi-bin/fortune.pl")
htmlview!.setToolTipText("<html>HTMLVIEW controls support drag in copy mode.<br>Text is copied in plain text and HTML format.<br>Drop is not supported.</html>")
htmlview!.setLongCue("HTMLVIEW controls support drag in copy mode. Text is copied in plain text and HTML format. Drop is not supported.")
CALLBACK(ON_HYPERLINK_ACTIVATE,Click,sysgui!.getContext(),htmlview!.getID())

rem ' BBjFileChooser
id=id+1,FileChooser!=window!.addFileChooser(id,240,430,600,340,dir(""))
FileChooser!.setMultiSelectionEnabled(1)
FileChooser!.setToolTipText("<html>FILECHOOSER controls support drag in copy mode.<br>Selected file names are copied in text and as an HTML list.<br>Drop is not supported.</html>")
FileChooser!.setLongCue("FILECHOOSER controls support drag in copy mode. Selected file names are copied in plain text and as an HTML list. Drop is not supported.")

rem ' Test area
id=id+1,scratch!=window!.addCEdit(id,20,620,220,110,$$,$0102$)
scratch!.setToolTipText("<html>Drag and drop selected text here.</html>")
scratch!.setLongCue("Drag and drop selected text here.")

rem ' Reset
reload!=window!.addButton(1,20,740,220,30,"Reset")
reload!.setToolTipText("Reset all controls to default values.")
reload!.setLongCue("Reset all controls to default values.")
CALLBACK(ON_BUTTON_PUSH,Init,sysgui!.getContext(),reload!.getID())

rem ' Report completion of drops that start with these controls
for i=101 to id
  CALLBACK(ON_DRAG_SOURCE_DROP,DragSourceDrop,sysgui!.getContext(),i)
next i

gosub init

process_events

DragSourceDrop:
  event!=sysgui!.getLastEvent()
  print "ON_DRAG_SOURCE_DROP"
  control!=event!.getControl()
  print "Data dragged from ",control!
  print "Drop action ",fnAction$(event!)," was ",
  print iff(event!.getSuccess(),"completed successfully","not completed successfully")
return

def fnAction$(event!)
  switch event!.getAction()
     case event!.ACTION_NONE; return "NONE"
     case event!.ACTION_COPY; return "COPY"
     case event!.ACTION_MOVE; return "MOVE"
     case event!.ACTION_COPY_OR_MOVE; return "COPY_OR_MOVE"
     case event!.ACTION_LINK; return "LINK"
     case default; return str(event!.getAction())
  swend
fnend

Click:
  url$=sysgui!.getLastEvent().getUrl()
  htmlview!.setUrl("http://www.google.com")
  htmlview!.setUrl(url$)
return

rem ' Initialize
init:
  restore 0
  dread text$
  rw_cedit!.setText(text$)
  ro_cedit!.setText(text$)

  dread text$
  rw_editbox!.setText(text$)
  ro_editbox!.setText(text$)

  dread text$
  rw_password!.setText(text$)
  ro_password!.setText(text$)

  dread text$
  rw_inpute!.setText(text$)
  ro_inpute!.setText(text$)

  dread text$
  rw_inputn!.setText(text$)
  ro_inputn!.setText(text$)

  dread text$
  rw_inputd!.setText(text$)
  ro_inputd!.setText(text$)

  rw_listedit!.removeAllItems()
  ro_listedit!.removeAllItems()
  rw_listbox!.removeAllItems()
  ro_listbox!.removeAllItems()
  dread state$,name$
  while len(state$)
    rw_listedit!.addItem(name$)
    ro_listedit!.addItem(name$)
    rw_listbox!.addItem(name$)
    ro_listbox!.addItem(name$)
    dread state$,name$
  wend
  rw_listedit!.selectIndex(0)
  ro_listedit!.selectIndex(0)
  rw_listbox!.selectIndex(0)
  ro_listbox!.selectIndex(0)

  rem url$=htmlview!.getUrl()
  rem htmlview!.setUrl("http://www.google.com")
  rem htmlview!.setUrl(url$)

  scratch!.setText($$)
return

rem ' BBjCEdit
data "A man stood upon a railroad bridge in northern Alabama, looking down into the swift water twenty feet below. The man's hands were behind his back, the wrists bound with a cord. A rope closely encircled his neck. It was attached to a stout cross-timber above his head and the slack fell to the level of his knees. Some loose boards laid upon the ties supporting the rails of the railway supplied a footing for him and his executioners--two private soldiers of the Federal army, directed by a sergeant who in civil life may have been a deputy sheriff. At a short remove upon the same temporary platform was an officer in the uniform of his rank, armed. He was a captain. A sentinel at each end of the bridge stood with his rifle in the position known as 'support,' that is to say, vertical in front of the left shoulder, the hammer resting on the forearm thrown straight across the chest--a formal and unnatural position, enforcing an erect carriage of the body. It did not appear to be the duty of these two men to know what was occurring at the center of the bridge; they merely blockaded the two ends of the foot planking that traversed it. (For the rest of the story, see: http://www.gutenberg.org/etext/375)."

rem ' BBjEditBox
data "The quick brown fox jumps over the lazy dog."

rem ' BBjEditBox Password field
data "xyzzy"

rem ' BBjInputE
data "The quick brown fox jumps over the lazy dog."

rem ' BBjInputN
data "1234567.89"

rem ' BBjInputD
data "7/7/7"

rem ' BBjListEdit, BBjListBox
DATA "AK","Alaska"
DATA "AL","Alabama"
DATA "AR","Arkansas"
DATA "AZ","Arizona"
DATA "CA","California"
DATA "CO","Colorado"
DATA "CT","Connecticut"
DATA "DC","District of Columbia"
DATA "DE","Delaware"
DATA "FL","Florida"
DATA "GA","Georgia"
DATA "GU","Guam"
DATA "HI","Hawaii"
DATA "IA","Iowa"
DATA "ID","Idaho"
DATA "IL","Illinois"
DATA "IN","Indiana"
DATA "KS","Kansas"
DATA "KY","Kentucky"
DATA "LA","Louisiana"
DATA "MA","Massachusetts"
DATA "MD","Maryland"
DATA "ME","Maine"
DATA "MI","Michigan"
DATA "MN","Minnesota"
DATA "MO","Missouri"
DATA "MS","Mississippi"
DATA "MT","Montana"
DATA "NC","North Carolina"
DATA "ND","North Dakota"
DATA "NE","Nebraska"
DATA "NH","New Hampshire"
DATA "NJ","New Jersey"
DATA "NM","New Mexico"
DATA "NV","Nevada"
DATA "NY","New York"
DATA "OH","Ohio"
DATA "OK","Oklahoma"
DATA "OR","Oregon"
DATA "PA","Pennsylvania"
DATA "PR","Puerto Rico"
DATA "RI","Rhode Island"
DATA "SC","South Carolina"
DATA "SD","South Dakota"
DATA "TN","Tennessee"
DATA "TX","Texas"
DATA "UT","Utah"
DATA "VA","Virginia"
DATA "VI","Virgin Islands"
DATA "VT","Vermont"
DATA "WA","Washington"
DATA "WI","Wisconsin"
DATA "WV","West Virginia"
DATA "WY","Wyoming"
DATA "",""

rem ' BBjTree
shakespeare:
data "Comedies","The Tempest ","The Two Gentlemen of Verona","The Merry Wives of Windsor","Measure for Measure ","The Comedy of Errors","Much Ado About Nothing","Love's Labour's Lost","A Midsummer Night's Dream","The Merchant of Venice ","As You Like It","The Taming of the Shrew","All's Well That Ends Well","Twelfth Night or What You Will","The Winter's Tale ","Pericles, Prince of Tyre","The Two Noble Kinsmen"
data "Histories","King John","Richard II","Henry IV, Part 1","Henry IV, Part 2","Henry V","Henry VI, Part 1","Henry VI, Part 2","Henry VI, Part 3","Richard III","Henry VIII","","","","","",""
data "Tragedies","Troilus and Cressida ","Coriolanus","Titus Andronicus","Romeo and Juliet","Timon of Athens","Julius Caesar","Macbeth","Hamlet","King Lear","Othello","Antony and Cleopatra","Cymbeline","","","",""

Close:
release