From 21c068f1916330e90f814bed461fe0821d1665ec Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Sun, 9 Oct 2011 16:36:37 +0000 Subject: checked in pd-0.43-0.src.tar.gz svn path=/trunk/; revision=15557 --- pd/tcl/pdtk_text.tcl | 53 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 10 deletions(-) (limited to 'pd/tcl/pdtk_text.tcl') diff --git a/pd/tcl/pdtk_text.tcl b/pd/tcl/pdtk_text.tcl index bb37ccc3..5818926c 100644 --- a/pd/tcl/pdtk_text.tcl +++ b/pd/tcl/pdtk_text.tcl @@ -1,20 +1,53 @@ package provide pdtk_text 0.1 -############ pdtk_text_new -- create a new text object #2########### -proc pdtk_text_new {mycanvas canvasitem x y text font_size color} { - $mycanvas create text $x $y -tags $canvasitem -text $text -fill $color \ +# these procs are currently all in the global namespace because all of them +# are used by 'pd' and therefore need to be in the global namespace. + +# create a new text object (ie. obj, msg, comment) +proc pdtk_text_new {tkcanvas tags x y text font_size color} { + $tkcanvas create text $x $y -tags $tags -text $text -fill $color \ -anchor nw -font [get_font_for_size $font_size] - $mycanvas bind $canvasitem "$mycanvas icursor $canvasitem 0" - $mycanvas bind $canvasitem "$mycanvas icursor $canvasitem end" + set mytag [lindex $tags 0] + $tkcanvas bind $mytag "$tkcanvas icursor $mytag 0" + $tkcanvas bind $mytag "$tkcanvas icursor $mytag end" + # select all + $tkcanvas bind $mytag \ + "pdtk_text_selectall $tkcanvas $mytag" if {$::windowingsystem eq "aqua"} { # emacs bindings for Mac OS X - $mycanvas bind $canvasitem "$mycanvas icursor $canvasitem 0" - $mycanvas bind $canvasitem "$mycanvas icursor $canvasitem end" + $tkcanvas bind $mytag "$tkcanvas icursor $mytag 0" + $tkcanvas bind $mytag "$tkcanvas icursor $mytag end" + } +} + +# change the text in an existing text box +proc pdtk_text_set {tkcanvas tag text} { + $tkcanvas itemconfig $tag -text $text +} + +# paste into an existing text box by literally "typing" the contents of the +# clipboard, i.e. send the contents one character at a time via 'pd key' +proc pdtk_pastetext {args} { + catch {set pdtk_pastebuffer [clipboard get]} + for {set i 0} {$i < [string length $pdtk_pastebuffer]} {incr i 1} { + set cha [string index $pdtk_pastebuffer $i] + scan $cha %c keynum + pdsend "pd key 1 $keynum 0" } } -################ pdtk_text_set -- change the text ################## -proc pdtk_text_set {mycanvas canvasitem text} { - $mycanvas itemconfig $canvasitem -text $text +# select all of the text in an existing text box +proc pdtk_text_selectall {tkcanvas mytag} { + if {$::editmode([winfo toplevel $tkcanvas])} { + $tkcanvas select from $mytag 0 + $tkcanvas select to $mytag end + } } +# de/activate a text box for editing based on $editing flag +proc pdtk_text_editing {mytoplevel tag editing} { + set tkcanvas [tkcanvas_name $mytoplevel] + if {$editing == 0} {selection clear $tkcanvas} + $tkcanvas focus $tag + set ::editingtext($mytoplevel) $editing +} -- cgit v1.2.1