I have a problem with drag and drop in Blt 2.4. In the following small
example, Blt crashes (SegFault, just click button 3 on the label), if the
two lines following "# crash line" are moved before the line following "#
crash here". I don't understand why the order of the lines matters...
Second problem with the source is registering the data types for source and
target doesn't work correctly. I registered dt0 as source type for .c0.f.l
and .c0.f and as target for .c1.f.l and .c1.f and vice versa with dt1. But
if start I dragging from .c0.f.l, then .c0.l accepts dt0, so I'm forced to
use "-send" to explicitly put dt0 as source data type. "-send dt0" forces
the correct behaviour, but leads to a message on the console
saying "source/target mismatch: No matching types". The expected behaviour
is that .c0.f rejects dt0.
I tested the example on Linux Fedora 7 with Blt 2.4 and Tk 8.4.13
Are these known bugs in Blt? Or is there any other advice, where the code is
wrong?
Thanks for any advice
Regards
Stephan
-------------------------------------------------------------------------------
#!/bin/sh
#\
exec wish "$0" "$@"
puts [package require Tk]
puts [package require BLT]
canvas .c0 -width 200 -height 300 -bg black
pack .c0 -side left -expand 1 -fill both
frame .c0.f -bg #888888
pack .c0.f -expand 0 -pady 50 -padx 50
label .c0.f.l -text "Label 0" -bd 2 -relief raised -background #8888ff
pack .c0.f.l -expand 0 -pady 20 -padx 20
canvas .c1 -width 200 -height 300 -bg white
pack .c1 -side left -expand 1 -fill both
frame .c1.f -bg #888888
pack .c1.f -expand 0 -pady 50 -padx 50
label .c1.f.l -text "Label 1" -bd 2 -relief raised -background #ff8888
pack .c1.f.l -expand 0 -pady 20 -padx 20
proc pkgCmd {dt t w} {
puts "pkgCmd {$dt $t $w}"
if { ![winfo exists $t.l] } {
label $t.l -text "Token for $dt - $w" -background red
pack $t.l
} else {
$t.l configure -background red
}
return $dt
}
proc siteCmd {d s t} {
puts "siteCmd {$d $s $t}"
if {$s} {
$t.l configure -background green
return true
} else {
$t.l configure -background red
return false
}
}
proc sourceHandler {i v W} {
puts "sourceHandler {$i $v $W}"
return "$v"
}
proc targetHandler {v t} {
puts "targetHandler {$v $t}"
set validHandler [::blt::drag&drop target $t handler]
if { $validHandler ne $v} {
puts "HANDLER: $validHandler"
error "HANDLER: $validHandler"
}
}
blt::drag&drop errors ""
blt::drag&drop source .c0.f -packagecmd "pkgCmd dt0 %t %W" -tokenanchor c
# removing "-send dt0" leads to wrong behaviour
blt::drag&drop source .c0.f -sitecmd "siteCmd dt0 %s %t" -send dt0
blt::drag&drop source .c0.f handler dt0 sourceHandler %i %v %W
# crash here
blt::drag&drop source .c0.f.l -packagecmd "pkgCmd dt0 %t %W" -tokenanchor c
# removing "-send dt0" leads to wrong behaviour
blt::drag&drop source .c0.f.l -sitecmd "siteCmd dt0 %s %t" -send dt0
# crash line
blt::drag&drop source .c0.f.l handler dt0 sourceHandler %i %v %W
blt::drag&drop source .c1.f -packagecmd "pkgCmd dt1 %t %W" -tokenanchor c
# removing "-send dt1" leads to wrong behaviour
blt::drag&drop source .c1.f -sitecmd "siteCmd dt1 %s %t" -send dt1
blt::drag&drop source .c1.f handler dt1 sourceHandler {"%i"} {"%v"} {"%W"}
# crash here
blt::drag&drop source .c1.f.l -packagecmd "pkgCmd dt1 %t %W" -tokenanchor c
# removing "-send dt1" leads to wrong behaviour
blt::drag&drop source .c1.f.l -sitecmd "siteCmd dt1 %s %t" -send dt1
# crash line
blt::drag&drop source .c1.f.l handler dt1 sourceHandler {"%i"} {"%v"} {"%W"}
blt::drag&drop target .c0.f handler dt1 "targetHandler {%v} {%W}"
blt::drag&drop target .c0.f.l handler dt1 "targetHandler {%v} {%W}"
blt::drag&drop target .c1.f handler dt0 "targetHandler {%v} {%W}"
blt::drag&drop target .c1.f.l handler dt0 "targetHandler {%v} {%W}"