Update of /cvsroot/pure-data/pd/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13541
Modified Files: Tag: desiredata desire.tk Log Message: TextBox clean up
Index: desire.tk =================================================================== RCS file: /cvsroot/pure-data/pd/src/Attic/desire.tk,v retrieving revision 1.1.2.600.2.339 retrieving revision 1.1.2.600.2.340 diff -C2 -d -r1.1.2.600.2.339 -r1.1.2.600.2.340 *** desire.tk 10 Aug 2007 22:43:58 -0000 1.1.2.600.2.339 --- desire.tk 11 Aug 2007 01:54:10 -0000 1.1.2.600.2.340 *************** *** 2492,2496 **** set t [[$self get_canvas] widget].${self}text if {![winfo exists $t]} {$self draw_edit} ! $self item text window [l+ $@textoffset [$self xy]] -window $t -anchor nw -tags "${self}text $self text" } else { set fw [font measure [$self look font] 0] --- 2492,2497 ---- set t [[$self get_canvas] widget].${self}text if {![winfo exists $t]} {$self draw_edit} ! $self item text window [l+ $@textoffset [$self xy]] -window $t -anchor nw \ ! -tags "${self}text $self text" } else { set fw [font measure [$self look font] 0] *************** *** 2506,2514 ****
def TextBox edit {} { ! if {$@edit} {return} ! set @edit 1; $self changed edit if {[[$self class] <= AtomBox]} {set @clear 1} }
def TextBox draw_edit {} { set c [$self cwidget] --- 2507,2529 ----
def TextBox edit {} { ! if {$@edit} {return}; set @edit 1; $self changed edit if {[[$self class] <= AtomBox]} {set @clear 1} }
+ def TextBox new_bind {} { + set t [$self cwidget].${self}text + bind $t <Key> "$self key_input %W %x %y %K %A 0" + bind $t <Control-Return> "$self key_input %W %x %y 10 %A 0" + bind $t <Control-v> "$self paste_resize" + bind $t <Return> "$self unedit" + bind $t <Escape> "$self unedit 0" + bind $t <Up> "$self scroll_history +1" + bind $t <Down> "$self scroll_history -1" + bind $t <Control-p> "$self scroll_history +1" + bind $t <Control-n> "$self scroll_history -1" + bind $t <Alt-BackSpace> "$self clear" + + } + def TextBox draw_edit {} { set c [$self cwidget] *************** *** 2522,2527 **** set @tab_repeats 0 obj_hist histi= 0 - # stores which line is the longest if multiple line - set @longline 1 set @max_width 40 set @selected? 1 --- 2537,2540 ---- *************** *** 2531,2607 **** set new_size [format %.0f [expr [lindex $font_str 1]*[$@canvas zoom]]] set font_str [lreplace $font_str 1 1 $new_size] - set l {};set nl 1;set newline {-1};set i 0;set width 0 foreach char [split $@text ""] {lappend l [scan $char %c]} ! foreach val $l {if {$val == 10} {incr nl; lappend newline $i}; incr i} ! lappend newline "end" ! for {set i 0} {$i < $nl} {incr i} { ! set line [string range $@text [expr [lindex $newline $i] + 1] [lindex $newline [expr $i+1]]] ! if {[string length $line] > $width} {set width [string length $line]} ! } ! if {[[$self class] <= AtomBox]} { ! set insertbg [$self look bg] ! #so don't have red as object bg for now.. ! set fg "red" ! } else { ! set insertbg [$self look fg] ! set fg [$self look fg] ! } if {$width > $@max_width} {set width $@max_width} ! if {$width == 0} {set width $@max_width} ! text $t -height $nl -width $width -relief flat -bg [$self look bgedit] -borderwidth 0 \ -highlightthickness 0 -font $font_str -fg $fg -insertbackground $insertbg -wrap word ! #bind $t <Key> "$self key_input %W %x %y %K %A 0; after 1 [$self resize %K]" ! bind $t <Key> "$self key_input %W %x %y %K %A 0" ! bind $t <Control-Return> "$self key_input %W %x %y 10 %A 0" ! bind $t <Control-v> "$self paste_resize" ! bind $t <Return> "$self unedit" ! bind $t <Escape> "$self unedit 0" ! bind $t <Up> "$self scroll_history +1" ! bind $t <Down> "$self scroll_history -1" ! bind $t <Control-p> "$self scroll_history +1" ! bind $t <Control-n> "$self scroll_history -1" ! bind $t <Alt-BackSpace> "$self clear" ! #bind $t <FocusOut> "$self unedit" $@canvas focus= $self - mset {cx cy} [$self xy] $self item text window [l+ $@textoffset [$self xy]] -window $t -anchor nw -tags "${self}text $self text" - #$t configure -pady 0 -padx 0 $t insert 1.0 $@text - set line_height [$t count -displaylines 1.0 end] $t configure -pady 0 -padx 0 - #$t insert 1.0 [$self filter_text 1] - if {[[$self class] <= AtomBox]} {} else {$self resize none} focus $t }
! def TextBox resize {key} { if {[[$self class] <= AtomBox]} {return} set c [$self cwidget] set t $c.${self}text ! $self long_line ! set fixed [font metrics [$self look font] -fixed] ! #set text [$t get $@longline.0 "$@longline.end + 1 chars"] ! set text [$t get 1.0 end] ! if {$fixed} { ! set width [string length $text] ! } else { ! set textpix [font measure [$self look font] $text] ! set fwidth [font measure [$self look font] 0] ! set width [expr (($textpix+$fwidth-1)/$fwidth)+1] ! } ! set maxwidth $@max_width ! #if {$key == "BackSpace"} {set width [expr $width - 2]} ! mset {y1 y2} [$t yview] ! set height [$t cget -height] ! if {$y2-$y1 < 1} { ! set height [expr $height/($y2-$y1)] ! } ! set line_height [$t count -displaylines 1.0 end] ! #if {$width < $maxwidth} {set height 1} {set height [expr $width/$maxwidth]} ! $t configure -width [min $width $maxwidth] -height $line_height -wrap word }
def TextBox key_input {widget x y key iso shift} { ! after 0 "$self after_key $widget $key" set c [$@canvas widget] set t $c.${self}text --- 2544,2574 ---- set new_size [format %.0f [expr [lindex $font_str 1]*[$@canvas zoom]]] set font_str [lreplace $font_str 1 1 $new_size] foreach char [split $@text ""] {lappend l [scan $char %c]} ! set width [string length $@text] ! set height [expr int(ceil($width/$@max_width.0))]; #this don's work well with variable width font.. ! set insertbg [$self look bg]; set fg [$self look fg] ! if {[[$self class] <= AtomBox]} {set fg "red"; set insertbg [$self look bgedit]} if {$width > $@max_width} {set width $@max_width} ! text $t -width [expr $width+1] -height $height -relief flat -bg [$self look bgedit] -borderwidth 0 \ -highlightthickness 0 -font $font_str -fg $fg -insertbackground $insertbg -wrap word ! $self new_bind $@canvas focus= $self $self item text window [l+ $@textoffset [$self xy]] -window $t -anchor nw -tags "${self}text $self text" $t insert 1.0 $@text $t configure -pady 0 -padx 0 focus $t }
! def TextBox resize {} { if {[[$self class] <= AtomBox]} {return} set c [$self cwidget] set t $c.${self}text ! set width [$t count -chars 1.0 end] ! set height [$t count -displaylines 1.0 end] ! $t configure -width [expr [min $width $@max_width]+1] -height $height -wrap word }
def TextBox key_input {widget x y key iso shift} { ! after 0 "$self after_key $widget" set c [$@canvas widget] set t $c.${self}text *************** *** 2617,2624 **** }
! def TextBox after_key {widget key} { ! $widget configure -state normal ! $self resize $key ! #$self long_line $self changed } --- 2584,2590 ---- }
! def TextBox after_key {widget} { ! $widget configure -state normal; # for in case there is completion box ! $self resize $self changed } *************** *** 2628,2632 **** set c [$self cwidget] set t $c.${self}text - $self long_line set fixed [font metrics [$self look font] -fixed] set text [clipboard get] --- 2594,2597 ---- *************** *** 2669,2684 **** }
- #checks which line should be used as the width of the objectbox - def TextBox long_line {} { - set c [$self cwidget] - set t $c.${self}text - set lines [lindex [$t configure -height] 4] - for {set line 1} {$line <= $lines} {incr line} { - set len [string length [$c.${self}text get $line.0 $line.end]] - set len2 [string length [$c.${self}text get $@longline.0 $@longline.end]] - if {$len > $len2} {set @longline $line} - } - } - def TextBox text {} {return $@text}
--- 2634,2637 ---- *************** *** 6745,6749 **** bind $@textbox <Return> "$@textself unedit" bind $@textbox <Tab> "$@textself key_input %W %x %y %K %A 0" ! focus $@textbox; $self delete } def ClassBrowser delete {} {set @exist 0; super} --- 6698,6703 ---- bind $@textbox <Return> "$@textself unedit" bind $@textbox <Tab> "$@textself key_input %W %x %y %K %A 0" ! focus $@textbox ! $self delete } def ClassBrowser delete {} {set @exist 0; super}