#!/usr/bin/wish
#Test putting dew's on a canvas
package require wylib

canvas .c -xscrollc ".xs set" -yscrollc ".ys set" -bd 2 -relief raised	;#-bg white 
scrollbar .xs -command ".c xview" -orient h
scrollbar .ys -command ".c yview"
pack .xs -side bottom -fill x
pack .ys -side right -fill y
pack .c -side right -fill both -expand yes

dew::dew .c.d1 ent {Entry 1:}		-bg pink -t {-width 10} -textv v1 -init hello -spf scm -help {A test entry} -data {-list {Now is the time for all good men to come to the aid of their lady}}
dew::dew .c.d2 chk {Entry Two:}		-bg pink -t {-width 10} -textv v2 -init 1 -help {A boolean widget}
dew::dew .c.d3 pdm {Entry Three:}	-bg pink -t {-width 10} -textv v3 -data {{hi {Hi There}} {you {That's you}}} -init you
dew::dew .c.d4 ent {Entry Four:}	-bg pink -t {-width 10} -textv v4 -init Howdy
frame .c.f1 -bg blue -height 10 -width 40

set id [.c create window 0  0 -window .c.d1 -anchor nw]
puts "id:$id"
.c create window 1 20 -window .c.d2 -anchor nw
.c create window 1 40 -window .c.d3 -anchor nw
.c create window 1 60 -window .c.d4 -anchor nw
.c create window 1 80 -window .c.f1 -anchor nw

.c configure -scrollregion {0 0 200 100}
#.c configure -scrollregion [.c bbox all]
puts "[.c bbox all]"

#.c create oval 130 130 140 140 -fill green -tag vertex
#.c raise vertex
#bind .c <3> "startdrag .c %x %y"
#bind .c <B3-Motion> "movedrag .c %x %y"

bind [.c.d1 t w] <3> "startdrag .c %W %x %y"
bind [.c.d1 t w] <B3-Motion> "movedrag .c %W %x %y"
#bind .c <Control-3> "puts HEY"

puts "bindtags:[bindtags .c]"

proc startdrag {c w x y} {
    global p
puts "W:$w x:$x y:$y"
#return
    set p(x) [$c itemcget canvasx $x]
    set p(y) [$c itemcget canvasy $y]
}

proc movedrag {c w x y} {
    global p
puts "w:$w px:$p(x) py:$p(y) x:$x y:$y"
#return
    set x [$c canvasx $x]
    set y [$c canvasy $y]
    $c move 1 [expr $x-$p(x)] [expr $y-$p(y)]
    set p(x) $x
    set p(y) $y
}
