1 # vim: foldmarker=<<<,>>>
4 # onchange() fired when the data is changed
5 # onchange_text(newtext) fired when the data is changed, passes new data
7 option add *Vartextbox.labelSticky wn widgetDefault
8 option add *Vartextbox.labelPos wn widgetDefault
9 option add *Vartextbox.textBackground white widgetDefault
10 option add *Vartextbox.width 30 widgetDefault
11 option add *Vartextbox.height 4 widgetDefault
12 option add *Vartextbox.wrap word widgetDefault
13 option add *Vartextbox.textBorderWidth 2 widgetDefault
14 option add *Vartextbox.textRelief sunken widgetDefault
16 ::itk::usual tlc::Vartextbox {
17 keep -font -cursor -textbackground -background
20 proc tlc::vartextbox {pathName args} {
21 uplevel tlc::Vartextbox $pathName $args
24 class tlc::Vartextbox {
25 inherit tlc::Border tlc::Handlers
30 itk_option define -textvariable textVariable Variable ""
31 # itk_option define -reservespace reserveSpace Bool 0
32 itk_option define -state state State "normal"
33 itk_option define -disabledbackground disabledBackground DisabledBackground $::tlc::config(disabledbackground)
34 itk_option define -highlightargs highlightArgs HighlightArgs {-background yellow}
35 itk_option define -highlightignorecase highlightIgnoreCase HighlightIgnoreCase 1 need_check_highlight
36 itk_option define -wrap wrap Wrap word
37 itk_option define -vscrollmode vScrollMode VScrollMode "fancy"
38 itk_option define -hscrollmode vScrollMode VScrollMode "dynamic"
41 variable highlight_text "" need_check_highlight
43 method insert {index chars}
45 method need_check_highlight {}
50 variable old_textvariable ""
53 variable highlightafterid ""
55 # variable xstate "shown"
56 # variable ystate "shown"
59 method newvalue {args}
62 method check_highlight {}
70 configbody tlc::Vartextbox::wrap { #<<<1
71 if {$itk_option(-wrap) == "none"} {
72 blt::table $w $w.hs 2,1 -fill x
74 catch {blt::table forget $w.hs}
79 configbody tlc::Vartextbox::highlightargs { #<<<1
80 eval [list $itk_component(text) tag configure highlighted] $itk_option(-highlightargs)
84 configbody tlc::Vartextbox::state { #<<<1
85 switch -- $itk_option(-state) {
87 set tbg $itk_option(-disabledbackground)
92 set tbg $tlc::config(textbackground)
96 [component text] configure -background $tbg
100 configbody tlc::Vartextbox::disabledbackground { #<<<1
101 if {$itk_option(-state) == "disabled"} {
102 set tbg $itk_option(-disabledbackground)
104 [component text] configure -background $tbg
109 #configbody tlc::Vartextbox::reservespace { #<<<1
110 # if {$itk_option(-reservespace)} {
111 # blt::table configure $w r2 -height $w.hs
112 # blt::table configure $w c2 -width $w.vs
114 # blt::table configure $w r2 -height {}
115 # blt::table configure $w c2 -width {}
120 configbody tlc::Vartextbox::textvariable { #<<<1
121 if {$old_textvariable != ""} {
122 trace vdelete $old_textvariable w [code $this newvalue]
124 if {$itk_option(-textvariable) != ""} {
125 trace variable $itk_option(-textvariable) wu [code $this newvalue]
126 set old_textvariable $itk_option(-textvariable)
132 configbody tlc::Vartextbox::hscrollmode { #<<<1
133 if {[winfo exists $w.hs]} {
134 $w.hs configure -mode $itk_option(-hscrollmode)
139 configbody tlc::Vartextbox::vscrollmode { #<<<1
140 if {[winfo exists $w.vs]} {
141 $w.vs configure -mode $itk_option(-vscrollmode)
146 body tlc::Vartextbox::constructor {args} { #<<<1
149 itk_component add text {
151 -xscrollcommand [list $w.hs set] \
152 -yscrollcommand [list $w.vs set]
155 keep -state -font -foreground
156 keep -width -height -tabs
158 rename -background -textbackground textBackground Background
159 rename -highlightbackground -texthighlightbackground textHighlightBackground TextHighlightBackground
160 rename -borderwidth -textborderwidth textBorderWidth TextBorderWidth
161 rename -relief -textrelief textRelief TextRelief
164 eval itk_initialize $args
166 myscrollbar_win32 $w.vs -orient v -command [list $w.text yview] \
167 -mode $itk_option(-vscrollmode)
169 myscrollbar_win32 $w.hs -orient h -command [list $w.text xview] \
170 -mode $itk_option(-hscrollmode)
171 # unless instructed otherwise, this box should have the background chrome
172 # color for the highlightbackground, like every other widget
173 configure -texthighlightbackground [. cget -bg]
176 $w.text 1,1 -fill both \
178 blt::table configure $w r2 c2 -resize none
180 set anybinds [bind Text]
181 foreach binding $anybinds {
182 bind $itk_component(text) $binding "+[code $this getnewtext]"
187 body tlc::Vartextbox::destructor {} { #<<<1
188 # set anybinds [bind Text]
189 # foreach binding $anybinds {
190 # bind $itk_component(text) $binding ""
193 after cancel $after_id; set after_id ""
194 after cancel $highlightafterid; set highlightafterid ""
198 body tlc::Vartextbox::newvalue {args} { #<<<1
199 if {[lindex $args 2] == "u"} {
200 log error "var unset"
205 set st [$itk_component(text) cget -state]
206 if {$st == "disabled"} {$itk_component(text) configure -state normal}
208 $itk_component(text) delete 1.0 end
209 if {[info exists $itk_option(-textvariable)]} {
210 $itk_component(text) insert 1.0 [set $itk_option(-textvariable)]
213 if {$st == "disabled"} {$itk_component(text) configure -state $st}
218 body tlc::Vartextbox::newtext {} { #<<<1
220 if {$itk_option(-textvariable) == ""} return
223 set tmp [$itk_component(text) get 1.0 "end - 1 chars"]
224 if {![info exists $itk_option(-textvariable)] || $tmp != [set $itk_option(-textvariable)]} {
225 uplevel #0 [list set $itk_option(-textvariable) $tmp]
227 invoke_handlers onchange
228 invoke_handlers onchange_text $tmp
234 body tlc::Vartextbox::insert {index chars} { #<<<1
235 return [$itk_component(text) insert $index $chars]
239 body tlc::Vartextbox::getnewtext {} { #<<<1
240 if {$after_id != ""} return
241 set after_id [after idle [code $this newtext]]
245 #body tlc::Vartextbox::xtap {args} {
246 # foreach {op first last} $args {break}
247 # if {$first == 0.0 && $last == 1.0} {
248 # if {$xstate != "hidden"} {
249 # blt::table forget $w.hs
250 # set xstate "hidden"
253 # if {$xstate != "shown"} {
254 # blt::table $w $w.hs 2,1 -fill x
258 # uplevel $w.hs $args
262 #body tlc::Vartextbox::ytap {args} {
263 # foreach {op first last} $args {break}
264 # if {$first == 0.0 && $last == 1.0} {
265 # if {$ystate != "hidden"} {
266 # blt::table forget $w.vs
267 # set ystate "hidden"
270 # if {$ystate != "shown"} {
271 # blt::table $w $w.vs 1,2 -fill y
275 # uplevel $w.vs $args
279 body tlc::Vartextbox::force_reget {} { #<<<1
284 body tlc::Vartextbox::need_check_highlight {} { #<<<1
285 if {$highlightafterid != ""} return
286 set highlightafterid [after idle [code $this check_highlight]]
290 body tlc::Vartextbox::check_highlight {} { #<<<1
291 after cancel $highlightafterid; set highlightafterid ""
293 set text [$itk_component(text) get 1.0 "end - 1 chars"]
294 $itk_component(text) tag remove highlighted 1.0 end
296 if {$itk_option(-highlightignorecase)} {
297 set text [string tolower $text]
298 set match [string tolower $highlight_text]
300 set match $highlight_text
303 if {$highlight_text == ""} return
305 set span [string length $match]
310 set idx [string first $match $text $idx]
311 if {$idx == -1} break
315 $itk_component(text) tag add highlighted "1.0 + $from chars" "1.0 + $to chars"