rem ' DragDropTypes.src
open (unt)"X0"
sysgui! = BBjAPI().getSysGui()
window!= sysgui!.addWindow(100,100,500,320,"Drag/Drop Types",$00010083$)
window!.setCallback(sysgui!.ON_CLOSE,"Close")
rem ' Status Bar
id=100,statbar!=window!.addStatusBar(id)
rem ' Init
dim drop![0:3],drop$[0:3]
drop![0]=BBjAPI().makeVector(),drop$[0]="Any"
drop![1]=BBjAPI().makeVector(),drop$[1]="A"
drop![1].add("A")
drop![2]=BBjAPI().makeVector(),drop$[2]="A/B"
drop![2].add("A")
drop![2].add("B")
drop![3]=BBjAPI().makeVector(),drop$[3]="B/C"
drop![3].add("B")
drop![3].add("C")
COPY=sysgui!.ACTION_COPY
MOVE=sysgui!.ACTION_MOVE
LINK=sysgui!.ACTION_LINK
NONE=sysgui!.ACTION_NONE
rem ' BBjGrid
id=id+1,rows=4,cols=4
grid!=window!.addGrid(id,20,20,222,182,$8040$,rows,cols)
grid!.setDefaultColumnWidth(55)
grid!.setRowHeight(45)
grid!.setEditable(1)
grid!.setMultipleSelection(1)
for col=0 to cols-1
if (col) then
drag$=chr(asc("A")+col-1)
text$="Drag "+drag$+"<br>Drop "+drop$[col]
grid!.setDragType(col,drag$)
grid!.setDropTypes(col,drop![col])
else
text$="Drag Any<br>Drop "+drop$[col]
endif
for row=0 to rows-1
grid!.setCellStyle(row,col,grid!.GRID_STYLE_TEXT)
grid!.setCellText(row,col,"<html><font size=2>"+text$+"</html>")
next row
next col
col=0
for row=0 to rows-1
if (row) then
drag$=chr(asc("A")+row-1)
text$="Drag "+drag$+"<br>Drop "+drop$[row]
grid!.setDragType(row,col,drag$)
grid!.setDropTypes(row,col,drop![row])
else
text$="Drag Any<br>Drop "+drop$[row]
endif
grid!.setCellStyle(row,col,grid!.GRID_STYLE_TEXT)
grid!.setCellText(row,col,"<html><font size=2>"+text$+"</html>")
next row
rem ' BBjTree
id=id+1,tree!=window!.addTree(id,260,20,220,180)
parent_id=0,node_id=100
tree!.setRoot(parent_id,"ABC Tree")
for i=0 to 3
node_id=node_id+1
if (i) then
drag$=chr(asc("A")+i-1)
tree!.addExpandableNode(node_id,parent_id,str(node_id)+": Drag "+drag$+", Drop "+drop$[i])
tree!.setDragType(node_id,drag$)
tree!.setDropTypes(node_id,drop![i])
else
tree!.addExpandableNode(node_id,parent_id,str(node_id)+": Drag Any, Drop "+drop$[i])
endif
group_parent_id=node_id
for j=0 to 3
node_id=node_id+1
if (j) then
drag$=chr(asc("A")+j-1)
tree!.addNode(node_id,group_parent_id,str(node_id)+": Drag "+drag$+", Drop "+drop$[j])
tree!.setDragType(node_id,drag$)
tree!.setDropTypes(node_id,drop![j])
else
tree!.addNode(node_id,group_parent_id,str(node_id)+": Drag Any, Drop "+drop$[j])
endif
next j
tree!.expandNode(group_parent_id)
next i
tree!.expandNode(0)
rem ' CEdits
id=id+1,c1!=window!.addCEdit(id,20,220,100,60,"Drag Any"+$0a$+"Drop "+drop$[0],$0102$)
c1!.setDragActions(COPY)
c1!.setDropActions(COPY)
id=id+1,c2!=window!.addCEdit(id,140,220,100,60,"Drag A"+$0a$+"Drop "+drop$[1],$0102$)
c2!.setDragActions(COPY)
c2!.setDropActions(COPY)
c2!.setDragType("A")
c2!.setDropTypes(drop![1])
id=id+1,c3!=window!.addCEdit(id,260,220,100,60,"Drag B"+$0A$+"Drop "+drop$[2],$0102$)
c3!.setDragActions(COPY)
c3!.setDropActions(COPY)
c3!.setDragType("B")
c3!.setDropTypes(drop![2])
id=id+1,c4!=window!.addCEdit(id,380,220,100,60,"Drag C"+$0A$+"Drop "+drop$[3],$0102$)
c4!.setDragActions(COPY)
c4!.setDropActions(COPY)
c4!.setDragType("C")
c4!.setDropTypes(drop![3])
rem ' Report drops to and from these controls
for i=101 to id
CALLBACK(ON_DROP_TARGET_DROP,DropTargetDrop,sysgui!.getContext(),i)
CALLBACK(ON_DRAG_SOURCE_DROP,DragSourceDrop,sysgui!.getContext(),i)
next i
process_events
DropTargetDrop:
event!=sysgui!.getLastEvent()
print 'lf',"ON_DROP_TARGET_DROP"
dragSource!=event!.getDragSource()
dropTarget!=event!.getControl()
info$="Data was dragged from "+fnControlType$(dragSource!)+" to "+fnControlType$(dropTarget!)+$0a$
if (dragSource!<>null()) then
info$=info$+"Drag Source actions were: "+fnActions$(dragSource!.getDragActions())+$0a$
endif
info$=info$+"Drop Target actions were: "+fnActions$(dropTarget!.getDropActions())+$0a$
selection$=fnSelection$(dragSource!,event!.getSelection())
if (len(selection$)) then
info$=info$+"Drag selection was "+fnTruncate$(selection$)+$0a$
endif
location$=fnDropLocation$(dropTarget!,event!.getDropLocation())
if (len(location$)) then
info$=info$+"Drop location was "+location$+$0a$
endif
info$=info$+"Action was "+fnAction$(event!.getAction())+$0a$
if (event!.getText()="") then
info$=info$+"Data is "+fnData$(event!.getData())
else
if (pos($0a$=event!.getText())) then
info$=info$+"Text data is:"+$0a$+fnTruncate$(event!.getText())
else
info$=info$+"Text data is """+fnTruncate$(event!.getText())+""""
endif
endif
i=msgbox(info$)
return
def fnVector!(string$)
vector! = BBjAPI().makeVector()
if (pos($0a$=string$,1,0)) then
if string$(len(string$))<>$0a$ then
string$=string$+$0a$
endif
count=pos($0a$=string$,1,0)
dim rec$:"line["+str(count)+"]:c(1*=10)"
let rec$=string$
for i=1 to count
vector!.add(rec.line$[i])
next i
else
vector!.add(string$)
endif
return vector!
fnend
def fnTruncate$(string$)
vector!=fnVector!(string$)
string$=$$,maxlines=16,maxwidth=128
for i=0 to min(vector!.size()-1,maxlines)
line$=str(vector!.get(i))
if len(line$) > maxwidth
string$=string$+line$(1,maxwidth)+"..."
else
string$=string$+line$
endif
if (vector!.size()>1) then
string$=string$+$0a$
endif
next i
if (vector!.size()>maxlines) then
string$=string$+"..."
endif
return string$
fnend
DragSourceDrop:
event!=sysgui!.getLastEvent()
print 'lf',"ON_DRAG_SOURCE_DROP"
control!=event!.getControl()
print "Data dragged from ",control!
print "Drop action ",fnAction$(event!.getAction())," was ",
if (event!.getSuccess()) then
print "completed successfully."
else
print "not completed successfully."
endif
return
def fnControlType$(BBjControl!)
if BBjControl!=null()
return "Unknown"
endif
switch BBjControl!.getControlType()
case BBjControl!.BARCHART_CONTROL
return "BBjBarChart"
case BBjControl!.CEDIT_CONTROL
return "BBjCEdit"
case BBjControl!.CHECKABLE_MENUITEM_CONTROL
return "BBjCheckableMenuItem"
case BBjControl!.CHECKBOX_CONTROL
return "BBjCheckbox"
case BBjControl!.CHILD_WINDOW
return "BBjChildWindow"
case BBjControl!.COLORCHOOSER_CONTROL
return "BBjColorChooser"
case BBjControl!.EDIT_CONTROL
return "BBjEditBox"
case BBjControl!.EDIT_SPINNER_CONTROL
return "BBjEditBoxSpinner"
case BBjControl!.FILECHOOSER_CONTROL
return "BBjFileChooser"
case BBjControl!.FONTCHOOSER_CONTROL
return "BBjFontChooser"
case BBjControl!.GRID_CONTROL
return "BBjGrid"
case BBjControl!.GROUPBOX_CONTROL
return "BBjGroupBox"
case BBjControl!.HSCROLL_CONTROL
return "BBjScrollBar"
case BBjControl!.HSLIDER_CONTROL
return "BBjSlider"
case BBjControl!.IMAGE_CONTROL
return "BBjImage"
case BBjControl!.INPUTD_CONTROL
return "BBjInputD"
case BBjControl!.INPUTD_SPINNER_CONTROL
return "BBjInputDSpinner"
case BBjControl!.INPUTE_CONTROL
return "BBjInputE"
case BBjControl!.INPUTE_SPINNER_CONTROL
return "BBjInputESpinner"
case BBjControl!.INPUTN_CONTROL
return "BBjInputN"
case BBjControl!.INPUTN_SPINNER_CONTROL
return "BBjInputNSpinner"
case BBjControl!.LINECHART_CONTROL
return "BBjLineChart"
case BBjControl!.LISTBOX_CONTROL
return "BBjListBox"
case BBjControl!.LISTBUTTON_CONTROL
return "BBjListButton"
case BBjControl!.LISTEDIT_CONTROL
return "BBjListEdit"
case BBjControl!.MAIN_WINDOW
return "BBjWindow"
case BBjControl!.MENUBUTTON_CONTROL
return "BBjMenuButton"
case BBjControl!.MENUITEM_CONTROL
return "BBjMenuItem"
case BBjControl!.NAVIGATOR_CONTROL
return "BBjNavigator"
case BBjControl!.PIECHART_CONTROL
return "BBjPieChart"
case BBjControl!.PROGRESS_CONTROL
return "BBjProgressBar"
case BBjControl!.PUSHBUTTON_CONTROL
return "BBjButton"
case BBjControl!.RADIOBUTTON_CONTROL
return "BBjRadioButton"
case BBjControl!.STATUSBAR_CONTROL
return "BBjStatusBar"
case BBjControl!.TAB_CONTROL
return "BBjTabCtrl"
case BBjControl!.TEXT_CONTROL
return "BBjStaticText"
case BBjControl!.TOOLBUTTON_CONTROL
return "BBjToolButton"
case BBjControl!.TREE_CONTROL
return "BBjTree"
case BBjControl!.VSCROLL_CONTROL
return "BBjScrollBar"
case BBjControl!.VSLIDER_CONTROL
return "BBjSlider"
case default
return "Unknown control type "+str(BBjControl!.getControlType())
swend
fnend
def fnSelection$(BBjControl!,BBjVector!)
if BBjControl!=null()
return ""
endif
switch BBjControl!.getControlType()
case BBjControl!.CEDIT_CONTROL
selection$="Offset "+str(BBjVector!.get(0))+
: " through "+str(BBjVector!.get(1))+" ("+
: "Paragraph "+str(BBjVector!.get(2))+
: ", offset "+str(BBjVector!.get(3))+" through "+
: "Paragraph "+str(BBjVector!.get(4))+
: ", offset "+str(BBjVector!.get(5))+")"
return selection$
case BBjControl!.GRID_CONTROL
selection$=""
for i=0 to BBjVector!.size()-1 step 2
selection$=selection$+
: "[row="+str(BBjVector!.get(i))+
: ",col="+str(BBjVector!.get(i+1))+"],"
next i
return selection$(1,len(selection$)-1)
case BBjControl!.LISTBOX_CONTROL
selection$=""
for i=0 to BBjVector!.size()-1
selection$=selection$+"[row="+str(BBjVector!.get(i))+"],"
next i
return selection$(1,len(selection$)-1)
case BBjControl!.TREE_CONTROL
selection$=""
for i=0 to BBjVector!.size()-1
selection$=selection$+"[node="+str(BBjVector!.get(i))+"],"
next i
return selection$(1,len(selection$)-1)
case BBjControl!.EDIT_CONTROL
case BBjControl!.EDIT_SPINNER_CONTROL
case BBjControl!.INPUTD_CONTROL
case BBjControl!.INPUTD_SPINNER_CONTROL
case BBjControl!.INPUTE_CONTROL
case BBjControl!.INPUTE_SPINNER_CONTROL
case BBjControl!.INPUTN_CONTROL
case BBjControl!.INPUTN_SPINNER_CONTROL
case BBjControl!.LISTEDIT_CONTROL
selection$="Offset "+str(BBjVector!.get(0))+
: " through "+str(BBjVector!.get(1))
return selection$
case default
return "N/A"
swend
fnend
def fnDropLocation$(BBjControl!,BBjVector!)
if BBjControl!=null()
return ""
endif
switch BBjControl!.getControlType()
case BBjControl!.CEDIT_CONTROL
location$="Offset "+str(BBjVector!.get(0))+" ("+
: "Paragraph "+str(BBjVector!.get(1))+
: ", offset "+str(BBjVector!.get(2))+")"
return location$
case BBjControl!.GRID_CONTROL
location$="[row="+str(BBjVector!.get(0))+
: ",col="+str(BBjVector!.get(1))+"]"
return location$
case BBjControl!.LISTBOX_CONTROL
location$="[row="+str(BBjVector!.get(0))+"]"
return location$
case BBjControl!.TREE_CONTROL
Node=BBjVector!.get(0)
location$="[node="+str(node)+"]: """+BBjControl!.getNodeText(node)+""""
return location$
case BBjControl!.EDIT_CONTROL
case BBjControl!.EDIT_SPINNER_CONTROL
case BBjControl!.INPUTD_CONTROL
case BBjControl!.INPUTD_SPINNER_CONTROL
case BBjControl!.INPUTE_CONTROL
case BBjControl!.INPUTE_SPINNER_CONTROL
case BBjControl!.INPUTN_CONTROL
case BBjControl!.INPUTN_SPINNER_CONTROL
case BBjControl!.LISTEDIT_CONTROL
location$="Offset "+str(BBjVector!.get(0))
return location$
case default
return ""
swend
fnend
def fnAction$(action)
switch action
case sysgui!.ACTION_NONE; return "NONE"
case sysgui!.ACTION_COPY; return "COPY"
case sysgui!.ACTION_MOVE; return "MOVE"
case sysgui!.ACTION_COPY_OR_MOVE; return "COPY_OR_MOVE"
case sysgui!.ACTION_LINK; return "LINK"
case default; return str(action)
swend
fnend
def fnActions$(action)
actions$=$$
if (fnIsBitSet(action,sysgui!.ACTION_COPY)) then
actions$=actions$+"COPY|"
endif
if (fnIsBitSet(action,sysgui!.ACTION_MOVE)) then
actions$=actions$+"MOVE|"
endif
if (fnIsBitSet(action,sysgui!.ACTION_LINK)) then
actions$=actions$+"LINK|"
endif
if (len(actions$)) then
return actions$(1,len(actions$)-1)
else
return "NONE"
endif
fnend
def fnIsBitSet(value,bit)
return sgn(dec(and(bin(value,4),bin(bit,4))))
fnend
def fnData$(data!)
if data!=null() or data!.isEmpty() then return "<Empty>"
data$=$$
key!=data!.keySet().iterator()
while key!.hasNext()
data$=data$+str(data!.get(key!.next()))+$0a$
wend
return data$(1,len(data$)-1)
fnend
Close:
release
|