[11] | 1 | # ---------------------------------------------------------------------- |
---|
| 2 | # COMPONENT: textentry - general-purpose text entry widget |
---|
| 3 | # |
---|
| 4 | # This widget is a cross between the Tk entry and text widgets. For |
---|
| 5 | # one-line messages, it acts like an entry widget. For larger |
---|
| 6 | # messages, it morphs into a text widget. |
---|
| 7 | # ====================================================================== |
---|
| 8 | # AUTHOR: Michael McLennan, Purdue University |
---|
[115] | 9 | # Copyright (c) 2004-2005 Purdue Research Foundation |
---|
| 10 | # |
---|
| 11 | # See the file "license.terms" for information on usage and |
---|
| 12 | # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
[11] | 13 | # ====================================================================== |
---|
| 14 | package require Itk |
---|
| 15 | |
---|
| 16 | option add *TextEntry.size auto widgetDefault |
---|
| 17 | option add *TextEntry.width 0 widgetDefault |
---|
| 18 | option add *TextEntry.height 0 widgetDefault |
---|
| 19 | option add *TextEntry.editable yes widgetDefault |
---|
| 20 | option add *TextEntry.textBackground white widgetDefault |
---|
[437] | 21 | option add *TextEntry*disabledForeground #a3a3a3 widgetDefault |
---|
| 22 | option add *TextEntry*disabledBackground white widgetDefault |
---|
[11] | 23 | |
---|
| 24 | option add *TextEntry.hintForeground gray50 widgetDefault |
---|
| 25 | option add *TextEntry.hintFont \ |
---|
[676] | 26 | -*-helvetica-medium-r-normal-*-10-* widgetDefault |
---|
[674] | 27 | option add *TextEntry.codeFont \ |
---|
[640] | 28 | -*-courier-medium-r-normal-*-12-* widgetDefault |
---|
[11] | 29 | |
---|
[22] | 30 | |
---|
[11] | 31 | itcl::class Rappture::TextEntry { |
---|
| 32 | inherit itk::Widget |
---|
| 33 | |
---|
| 34 | itk_option define -editable editable Editable "" |
---|
[437] | 35 | itk_option define -state state State "normal" |
---|
[11] | 36 | itk_option define -width width Width 0 |
---|
| 37 | itk_option define -height height Height 0 |
---|
| 38 | |
---|
[22] | 39 | constructor {owner path args} { # defined below } |
---|
[11] | 40 | |
---|
| 41 | public method value {args} |
---|
| 42 | |
---|
| 43 | public method label {} |
---|
| 44 | public method tooltip {} |
---|
| 45 | public method size {} { return $_size } |
---|
| 46 | |
---|
| 47 | protected method _layout {} |
---|
[640] | 48 | protected method _setValue {value} |
---|
[43] | 49 | protected method _newValue {} |
---|
[437] | 50 | protected method _edit {option args} |
---|
| 51 | protected method _fixState {} |
---|
[640] | 52 | protected method _uploadValue {args} |
---|
| 53 | protected method _downloadValue {} |
---|
[11] | 54 | |
---|
| 55 | private variable _dispatcher "" ;# dispatcher for !events |
---|
[640] | 56 | private variable _owner "" ;# thing managing this control |
---|
| 57 | private variable _path "" ;# path in XML to this number |
---|
[11] | 58 | |
---|
[640] | 59 | private variable _layout "" ;# entry or full text size |
---|
| 60 | private variable _mode "ascii" ;# ascii text or binary data |
---|
| 61 | private variable _value "" ;# value inside the widget |
---|
[11] | 62 | private variable _size "" ;# size hint from XML |
---|
| 63 | } |
---|
[1342] | 64 | |
---|
[11] | 65 | itk::usual TextEntry { |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | # ---------------------------------------------------------------------- |
---|
| 69 | # CONSTRUCTOR |
---|
| 70 | # ---------------------------------------------------------------------- |
---|
[22] | 71 | itcl::body Rappture::TextEntry::constructor {owner path args} { |
---|
| 72 | if {[catch {$owner isa Rappture::ControlOwner} valid] != 0 || !$valid} { |
---|
[1342] | 73 | error "bad object \"$owner\": should be Rappture::ControlOwner" |
---|
[11] | 74 | } |
---|
[22] | 75 | set _owner $owner |
---|
[11] | 76 | set _path $path |
---|
| 77 | |
---|
| 78 | Rappture::dispatcher _dispatcher |
---|
| 79 | $_dispatcher register !layout |
---|
| 80 | $_dispatcher dispatch $this !layout "[itcl::code $this _layout]; list" |
---|
| 81 | |
---|
[22] | 82 | set _size [$_owner xml get $path.size] |
---|
[11] | 83 | |
---|
[22] | 84 | set hints [$_owner xml get $path.about.hints] |
---|
[11] | 85 | if {[string length $hints] > 0} { |
---|
[1342] | 86 | itk_component add hints { |
---|
| 87 | ::label $itk_interior.hints -anchor w -text $hints |
---|
| 88 | } { |
---|
| 89 | usual |
---|
| 90 | rename -foreground -hintforeground hintForeground Foreground |
---|
| 91 | rename -font -hintfont hintFont Font |
---|
| 92 | } |
---|
| 93 | pack $itk_component(hints) -side bottom -fill x |
---|
[11] | 94 | } |
---|
| 95 | |
---|
| 96 | eval itk_initialize $args |
---|
| 97 | |
---|
[22] | 98 | set str [$_owner xml get $path.default] |
---|
[69] | 99 | if {"" != $str} { |
---|
[1342] | 100 | _layout ;# must fix layout or value won't take |
---|
| 101 | value $str |
---|
[69] | 102 | } |
---|
[11] | 103 | } |
---|
| 104 | |
---|
| 105 | # ---------------------------------------------------------------------- |
---|
| 106 | # USAGE: value ?-check? ?<newval>? |
---|
| 107 | # |
---|
| 108 | # Clients use this to query/set the value for this widget. With |
---|
| 109 | # no args, it returns the current value for the widget. If the |
---|
| 110 | # <newval> is specified, it sets the value of the widget and |
---|
| 111 | # sends a <<Value>> event. If the -check flag is included, the |
---|
| 112 | # new value is not actually applied, but just checked for correctness. |
---|
| 113 | # ---------------------------------------------------------------------- |
---|
| 114 | itcl::body Rappture::TextEntry::value {args} { |
---|
| 115 | set onlycheck 0 |
---|
| 116 | set i [lsearch -exact $args -check] |
---|
| 117 | if {$i >= 0} { |
---|
[1342] | 118 | set onlycheck 1 |
---|
| 119 | set args [lreplace $args $i $i] |
---|
[11] | 120 | } |
---|
| 121 | |
---|
| 122 | if {[llength $args] == 1} { |
---|
[1342] | 123 | if {$onlycheck} { |
---|
| 124 | # someday we may add validation... |
---|
| 125 | return |
---|
| 126 | } |
---|
| 127 | set newval [lindex $args 0] |
---|
| 128 | _setValue $newval |
---|
[640] | 129 | |
---|
[1342] | 130 | $_dispatcher event -idle !layout |
---|
| 131 | event generate $itk_component(hull) <<Value>> |
---|
| 132 | return $newval |
---|
[11] | 133 | |
---|
| 134 | } elseif {[llength $args] != 0} { |
---|
[1342] | 135 | error "wrong # args: should be \"value ?-check? ?newval?\"" |
---|
[11] | 136 | } |
---|
| 137 | |
---|
| 138 | # |
---|
| 139 | # Query the value and return. |
---|
| 140 | # |
---|
[640] | 141 | if {$_mode == "ascii"} { |
---|
[1342] | 142 | if {$_layout == "entry"} { |
---|
| 143 | return [$itk_component(entry) get] |
---|
| 144 | } elseif {$_layout == "text"} { |
---|
| 145 | return [$itk_component(text) get 1.0 end-1char] |
---|
| 146 | } |
---|
[640] | 147 | } else { |
---|
[1342] | 148 | return $_value |
---|
[11] | 149 | } |
---|
| 150 | return "" |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | # ---------------------------------------------------------------------- |
---|
| 154 | # USAGE: label |
---|
| 155 | # |
---|
| 156 | # Clients use this to query the label associated with this widget. |
---|
| 157 | # Reaches into the XML and pulls out the appropriate label string. |
---|
| 158 | # ---------------------------------------------------------------------- |
---|
| 159 | itcl::body Rappture::TextEntry::label {} { |
---|
[22] | 160 | set label [$_owner xml get $_path.about.label] |
---|
[11] | 161 | if {"" == $label} { |
---|
[1342] | 162 | set label "String" |
---|
[11] | 163 | } |
---|
| 164 | return $label |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | # ---------------------------------------------------------------------- |
---|
| 168 | # USAGE: tooltip |
---|
| 169 | # |
---|
| 170 | # Clients use this to query the tooltip associated with this widget. |
---|
| 171 | # Reaches into the XML and pulls out the appropriate description |
---|
| 172 | # string. Returns the string that should be used with the |
---|
| 173 | # Rappture::Tooltip facility. |
---|
| 174 | # ---------------------------------------------------------------------- |
---|
| 175 | itcl::body Rappture::TextEntry::tooltip {} { |
---|
[22] | 176 | set str [$_owner xml get $_path.about.description] |
---|
[11] | 177 | return [string trim $str] |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | # ---------------------------------------------------------------------- |
---|
| 181 | # USAGE: _layout |
---|
| 182 | # |
---|
| 183 | # Used internally to change the layout of this widget depending |
---|
| 184 | # on the .size hint and its contents. Switches between an entry |
---|
| 185 | # and a text widget. |
---|
| 186 | # ---------------------------------------------------------------------- |
---|
| 187 | itcl::body Rappture::TextEntry::_layout {} { |
---|
| 188 | set size $_size |
---|
| 189 | if {$size == "" || $size == "auto"} { |
---|
[1342] | 190 | # |
---|
| 191 | # If the size is "auto", then look at the current value |
---|
| 192 | # and count its lines/characters. |
---|
| 193 | # |
---|
| 194 | set val "" |
---|
| 195 | if {$_layout == "entry"} { |
---|
| 196 | set val [$itk_component(entry) get] |
---|
| 197 | } elseif {$_layout == "text"} { |
---|
| 198 | set val [$itk_component(text) get 1.0 end-1char] |
---|
| 199 | } |
---|
[11] | 200 | |
---|
[1342] | 201 | set chars 0 |
---|
| 202 | set lines 0 |
---|
| 203 | foreach line [split $val \n] { |
---|
| 204 | incr lines |
---|
| 205 | if {[string length $line] > $chars} { |
---|
| 206 | set chars [string length $line] |
---|
| 207 | } |
---|
| 208 | } |
---|
| 209 | incr chars |
---|
[11] | 210 | |
---|
[1342] | 211 | if {$lines > 1} { |
---|
| 212 | set size "${chars}x${lines}" |
---|
| 213 | } else { |
---|
| 214 | set size $chars |
---|
| 215 | } |
---|
[11] | 216 | } |
---|
| 217 | |
---|
| 218 | if {[regexp {^[0-9]+$} $size]} { |
---|
[1342] | 219 | # |
---|
| 220 | # If the size is WW, then flip to entry mode, with |
---|
| 221 | # a requested size of WW characters. |
---|
| 222 | # |
---|
| 223 | if {$_layout != "entry"} { |
---|
| 224 | set val "" |
---|
| 225 | if {$_layout == "text"} { |
---|
| 226 | set val [$itk_component(text) get 1.0 end-1char] |
---|
| 227 | destroy $itk_component(text) |
---|
| 228 | destroy $itk_component(scrollbars) |
---|
| 229 | } |
---|
[11] | 230 | |
---|
[1342] | 231 | itk_component add entry { |
---|
| 232 | entry $itk_interior.entry |
---|
| 233 | } { |
---|
| 234 | usual |
---|
| 235 | rename -background -textbackground textBackground Background |
---|
| 236 | rename -foreground -textforeground textForeground Foreground |
---|
| 237 | } |
---|
| 238 | pack $itk_component(entry) -expand yes -fill both |
---|
| 239 | $itk_component(entry) configure \ |
---|
| 240 | -background $itk_option(-textbackground) \ |
---|
| 241 | -foreground $itk_option(-textforeground) |
---|
[11] | 242 | |
---|
[1342] | 243 | bind $itk_component(entry) <KeyPress> [itcl::code $this _newValue] |
---|
| 244 | bind $itk_component(entry) <Control-KeyPress-a> \ |
---|
| 245 | "[list $itk_component(entry) selection range 0 end]; break" |
---|
[43] | 246 | |
---|
[1342] | 247 | itk_component add emenu { |
---|
| 248 | menu $itk_component(entry).menu -tearoff 0 |
---|
| 249 | } |
---|
| 250 | $itk_component(emenu) add command -label "Cut" -accelerator "^X" \ |
---|
| 251 | -command [list event generate $itk_component(entry) <<Cut>>] |
---|
| 252 | $itk_component(emenu) add command -label "Copy" -accelerator "^C" \ |
---|
| 253 | -command [list event generate $itk_component(entry) <<Copy>>] |
---|
| 254 | $itk_component(emenu) add command -label "Paste" -accelerator "^V" \ |
---|
| 255 | -command [list event generate $itk_component(entry) <<Paste>>] |
---|
| 256 | $itk_component(emenu) add command -label "Select All" -accelerator "^A" -command [list $itk_component(entry) selection range 0 end] |
---|
| 257 | bind $itk_component(entry) <<PopupMenu>> \ |
---|
| 258 | [itcl::code $this _edit menu emenu %X %Y] |
---|
[17] | 259 | |
---|
[1342] | 260 | set _layout "entry" |
---|
| 261 | _setValue $val |
---|
| 262 | } |
---|
| 263 | $itk_component(entry) configure -width $size |
---|
[11] | 264 | |
---|
| 265 | } elseif {[regexp {^([0-9]+)x([0-9]+)$} $size match w h]} { |
---|
[1342] | 266 | # |
---|
| 267 | # If the size is WWxHH, then flip to text mode, with |
---|
| 268 | # a requested size of HH lines by WW characters. |
---|
| 269 | # |
---|
| 270 | if {$_layout != "text"} { |
---|
| 271 | set val "" |
---|
| 272 | if {$_layout == "entry"} { |
---|
| 273 | set val [$itk_component(entry) get] |
---|
| 274 | destroy $itk_component(entry) |
---|
| 275 | } |
---|
[11] | 276 | |
---|
[1342] | 277 | itk_component add scrollbars { |
---|
[1651] | 278 | blt::scrollset $itk_interior.scrl \ |
---|
| 279 | -xscrollbar $itk_interior.scrl.xs \ |
---|
| 280 | -yscrollbar $itk_interior.scrl.ys \ |
---|
| 281 | -window $itk_interior.scrl.text |
---|
[1342] | 282 | } |
---|
[1651] | 283 | blt::tk::scrollbar $itk_interior.scrl.xs |
---|
| 284 | blt::tk::scrollbar $itk_interior.scrl.ys |
---|
[1342] | 285 | pack $itk_component(scrollbars) -expand yes -fill both |
---|
[11] | 286 | |
---|
[1342] | 287 | itk_component add text { |
---|
| 288 | text $itk_component(scrollbars).text \ |
---|
| 289 | -width 1 -height 1 -wrap char |
---|
| 290 | } { |
---|
| 291 | usual |
---|
| 292 | rename -background -textbackground textBackground Background |
---|
| 293 | rename -foreground -textforeground textForeground Foreground |
---|
| 294 | rename -font -codefont codeFont CodeFont |
---|
| 295 | } |
---|
| 296 | $itk_component(text) configure \ |
---|
| 297 | -background $itk_option(-textbackground) \ |
---|
| 298 | -foreground $itk_option(-textforeground) \ |
---|
| 299 | -font $itk_option(-codefont) |
---|
[11] | 300 | |
---|
[1342] | 301 | bind $itk_component(text) <KeyPress> [itcl::code $this _newValue] |
---|
| 302 | bind $itk_component(text) <Control-KeyPress-a> \ |
---|
| 303 | "[list $itk_component(text) tag add sel 1.0 end]; break" |
---|
[43] | 304 | |
---|
[1342] | 305 | itk_component add tmenu { |
---|
| 306 | menu $itk_component(text).menu -tearoff 0 |
---|
| 307 | } |
---|
| 308 | $itk_component(tmenu) add command -label "Cut" -accelerator "^X" \ |
---|
| 309 | -command [list event generate $itk_component(text) <<Cut>>] |
---|
| 310 | $itk_component(tmenu) add command -label "Copy" -accelerator "^C" \ |
---|
| 311 | -command [list event generate $itk_component(text) <<Copy>>] |
---|
| 312 | $itk_component(tmenu) add command -label "Paste" -accelerator "^V" \ |
---|
| 313 | -command [list event generate $itk_component(text) <<Paste>>] |
---|
| 314 | $itk_component(tmenu) add command -label "Select All" -accelerator "^A" -command [list $itk_component(text) tag add sel 1.0 end] |
---|
| 315 | $itk_component(tmenu) add separator |
---|
[1077] | 316 | |
---|
[1342] | 317 | $itk_component(tmenu) add command \ |
---|
| 318 | -label [Rappture::filexfer::label upload] \ |
---|
| 319 | -command [itcl::code $this _uploadValue -start] |
---|
| 320 | $itk_component(tmenu) add command \ |
---|
| 321 | -label [Rappture::filexfer::label download] \ |
---|
| 322 | -command [itcl::code $this _downloadValue] |
---|
[1077] | 323 | |
---|
[1342] | 324 | bind $itk_component(text) <<PopupMenu>> \ |
---|
| 325 | [itcl::code $this _edit menu tmenu %X %Y] |
---|
[17] | 326 | |
---|
[1342] | 327 | set _layout "text" |
---|
| 328 | _setValue $val |
---|
| 329 | } |
---|
| 330 | $itk_component(text) configure -width $w -height $h |
---|
[11] | 331 | } |
---|
| 332 | |
---|
| 333 | # |
---|
| 334 | # Fix the overall widget size according to -width / -height |
---|
| 335 | # |
---|
| 336 | if {$itk_option(-width) == 0 && $itk_option(-height) == 0} { |
---|
[1342] | 337 | pack propagate $itk_component(hull) yes |
---|
[11] | 338 | } else { |
---|
[1342] | 339 | pack propagate $itk_component(hull) no |
---|
| 340 | component hull configure \ |
---|
| 341 | -width $itk_option(-width) -height $itk_option(-width) |
---|
[11] | 342 | } |
---|
| 343 | } |
---|
| 344 | |
---|
| 345 | # ---------------------------------------------------------------------- |
---|
[640] | 346 | # USAGE: _setValue <newValue> |
---|
| 347 | # |
---|
| 348 | # Used internally to set the value for this widget. If the <newValue> |
---|
| 349 | # string is ASCII, then it is stored directly and the widget is enabled |
---|
| 350 | # for editing. Otherwise, the value is cached and a representation of |
---|
| 351 | # the data is displayed. |
---|
| 352 | # ---------------------------------------------------------------------- |
---|
| 353 | itcl::body Rappture::TextEntry::_setValue {newval} { |
---|
[649] | 354 | if {[Rappture::encoding::is binary $newval]} { |
---|
[1342] | 355 | # looks like a binary file |
---|
| 356 | set _mode "binary" |
---|
| 357 | set _value $newval |
---|
[640] | 358 | |
---|
[1342] | 359 | if {$_layout == "entry" || [string match {*x[01]} $_size]} { |
---|
| 360 | set newval [Rappture::utils::hexdump -lines 0 $_value] |
---|
| 361 | } else { |
---|
| 362 | set newval [Rappture::utils::hexdump -lines 1000 $_value] |
---|
| 363 | } |
---|
[640] | 364 | } else { |
---|
[1342] | 365 | # ascii file -- map carriage returns to line feeds |
---|
| 366 | set _mode "ascii" |
---|
| 367 | set _value "" |
---|
| 368 | regsub -all "\r\n" $newval "\n" newval |
---|
| 369 | regsub -all "\r" $newval "\n" newval |
---|
[640] | 370 | } |
---|
| 371 | |
---|
| 372 | if {$_layout == "entry"} { |
---|
[1342] | 373 | $itk_component(entry) configure -state normal |
---|
| 374 | $itk_component(emenu) entryconfigure "Cut" -state normal |
---|
| 375 | $itk_component(emenu) entryconfigure "Paste" -state normal |
---|
| 376 | $itk_component(entry) delete 0 end |
---|
| 377 | $itk_component(entry) insert 0 $newval |
---|
| 378 | if {!$itk_option(-editable) || $_mode == "binary"} { |
---|
| 379 | $itk_component(entry) configure -state disabled |
---|
| 380 | $itk_component(emenu) entryconfigure "Cut" -state disabled |
---|
| 381 | $itk_component(emenu) entryconfigure "Paste" -state disabled |
---|
| 382 | } |
---|
[640] | 383 | } elseif {$_layout == "text"} { |
---|
[1342] | 384 | $itk_component(text) configure -state normal |
---|
| 385 | $itk_component(tmenu) entryconfigure "Cut" -state normal |
---|
| 386 | $itk_component(tmenu) entryconfigure "Paste" -state normal |
---|
| 387 | $itk_component(text) delete 1.0 end |
---|
| 388 | $itk_component(text) insert end $newval |
---|
| 389 | if {!$itk_option(-editable) || $_mode == "binary"} { |
---|
| 390 | set hull $itk_component(hull) |
---|
| 391 | set dfg [option get $hull disabledForeground Foreground] |
---|
| 392 | set dbg [option get $hull disabledBackground Background] |
---|
| 393 | $itk_component(text) configure -state disabled \ |
---|
| 394 | -background $dbg -foreground $dfg |
---|
| 395 | $itk_component(tmenu) entryconfigure "Cut" -state disabled |
---|
| 396 | $itk_component(tmenu) entryconfigure "Paste" -state disabled |
---|
| 397 | } else { |
---|
| 398 | $itk_component(text) configure \ |
---|
| 399 | -background $itk_option(-textbackground) \ |
---|
| 400 | -foreground $itk_option(-textforeground) |
---|
| 401 | } |
---|
[640] | 402 | } |
---|
| 403 | } |
---|
| 404 | |
---|
| 405 | # ---------------------------------------------------------------------- |
---|
[43] | 406 | # USAGE: _newValue |
---|
| 407 | # |
---|
| 408 | # Invoked automatically whenever the value in the entry changes. |
---|
| 409 | # Sends a <<Value>> event to notify clients of the change. |
---|
| 410 | # ---------------------------------------------------------------------- |
---|
| 411 | itcl::body Rappture::TextEntry::_newValue {} { |
---|
| 412 | event generate $itk_component(hull) <<Value>> |
---|
| 413 | } |
---|
| 414 | |
---|
| 415 | # ---------------------------------------------------------------------- |
---|
[437] | 416 | # USAGE: _edit menu <which> <X> <Y> |
---|
| 417 | # |
---|
| 418 | # Used internally to manage edit operations. |
---|
[11] | 419 | # ---------------------------------------------------------------------- |
---|
[437] | 420 | itcl::body Rappture::TextEntry::_edit {option args} { |
---|
| 421 | if {$itk_option(-state) == "disabled"} { |
---|
[1342] | 422 | return ;# disabled? then bail out here! |
---|
[11] | 423 | } |
---|
[437] | 424 | switch -- $option { |
---|
[1342] | 425 | menu { |
---|
| 426 | if {[llength $args] != 3} { |
---|
| 427 | error "wrong # args: should be \"_edit $option which x y\"" |
---|
| 428 | } |
---|
| 429 | set mname [lindex $args 0] |
---|
| 430 | set x [lindex $args 1] |
---|
| 431 | set y [lindex $args 2] |
---|
| 432 | tk_popup $itk_component($mname) $x $y |
---|
| 433 | } |
---|
| 434 | default { |
---|
| 435 | error "bad option \"$option\": should be menu" |
---|
| 436 | } |
---|
[437] | 437 | } |
---|
| 438 | } |
---|
[11] | 439 | |
---|
[437] | 440 | # ---------------------------------------------------------------------- |
---|
| 441 | # USAGE: _fixState |
---|
| 442 | # |
---|
| 443 | # Used internally to update the internal widgets whenever the |
---|
| 444 | # -state/-editable options change. Enables or disables various |
---|
| 445 | # widgets. |
---|
| 446 | # ---------------------------------------------------------------------- |
---|
| 447 | itcl::body Rappture::TextEntry::_fixState {} { |
---|
| 448 | if {$itk_option(-editable) && $itk_option(-state) == "normal"} { |
---|
[1342] | 449 | set state normal |
---|
[11] | 450 | } else { |
---|
[1342] | 451 | set state disabled |
---|
[11] | 452 | } |
---|
[640] | 453 | if {$_layout == "entry"} { |
---|
[1342] | 454 | $itk_component(entry) configure -state $state |
---|
| 455 | $itk_component(emenu) entryconfigure "Cut" -state $state |
---|
| 456 | $itk_component(emenu) entryconfigure "Copy" -state $state |
---|
| 457 | $itk_component(emenu) entryconfigure "Paste" -state $state |
---|
[640] | 458 | } elseif {$_layout == "text"} { |
---|
[1342] | 459 | $itk_component(text) configure -state $state |
---|
| 460 | $itk_component(tmenu) entryconfigure "Cut" -state $state |
---|
| 461 | $itk_component(tmenu) entryconfigure "Copy" -state $state |
---|
| 462 | $itk_component(tmenu) entryconfigure "Paste" -state $state |
---|
[11] | 463 | } |
---|
| 464 | } |
---|
| 465 | |
---|
| 466 | # ---------------------------------------------------------------------- |
---|
[640] | 467 | # USAGE: _uploadValue -start |
---|
| 468 | # USAGE: _uploadValue -assign <key> <value> <key> <value> ... |
---|
| 469 | # |
---|
| 470 | # Used internally to initiate an upload operation. Prompts the |
---|
| 471 | # user to upload into the text area of this widget. |
---|
| 472 | # ---------------------------------------------------------------------- |
---|
| 473 | itcl::body Rappture::TextEntry::_uploadValue {args} { |
---|
| 474 | switch -- $_layout { |
---|
[1342] | 475 | entry { set widget $itk_component(entry) } |
---|
| 476 | text { set widget $itk_component(text) } |
---|
| 477 | default { set widget $itk_component(hull) } |
---|
[640] | 478 | } |
---|
| 479 | |
---|
| 480 | set opt [lindex $args 0] |
---|
| 481 | switch -- $opt { |
---|
[1342] | 482 | -start { |
---|
| 483 | set tool [Rappture::Tool::resources -appname] |
---|
| 484 | set cntls [list $_path [label] [tooltip]] |
---|
| 485 | Rappture::filexfer::upload \ |
---|
| 486 | $tool $cntls [itcl::code $this _uploadValue -assign] |
---|
| 487 | } |
---|
| 488 | -assign { |
---|
| 489 | array set data [lrange $args 1 end] ;# skip option |
---|
| 490 | if {[info exists data(error)]} { |
---|
| 491 | Rappture::Tooltip::cue $widget $data(error) |
---|
| 492 | } |
---|
| 493 | if {[info exists data(data)]} { |
---|
| 494 | Rappture::Tooltip::cue hide ;# take down note about the popup |
---|
| 495 | _setValue $data(data) |
---|
| 496 | _newValue |
---|
| 497 | } |
---|
| 498 | } |
---|
| 499 | default { |
---|
| 500 | error "bad option \"$opt\": should be -start or -assign" |
---|
| 501 | } |
---|
[640] | 502 | } |
---|
| 503 | } |
---|
| 504 | |
---|
| 505 | # ---------------------------------------------------------------------- |
---|
| 506 | # USAGE: _downloadValue |
---|
| 507 | # |
---|
| 508 | # Used internally to initiate a download operation. Takes the current |
---|
| 509 | # value and downloads it to the user in a new browser window. |
---|
| 510 | # ---------------------------------------------------------------------- |
---|
| 511 | itcl::body Rappture::TextEntry::_downloadValue {} { |
---|
| 512 | set mesg [Rappture::filexfer::download [value] input.txt] |
---|
| 513 | |
---|
| 514 | if {"" != $mesg} { |
---|
[1342] | 515 | switch -- $_layout { |
---|
| 516 | entry { set widget $itk_component(entry) } |
---|
| 517 | text { set widget $itk_component(text) } |
---|
| 518 | default { set widget $itk_component(hull) } |
---|
| 519 | } |
---|
| 520 | Rappture::Tooltip::cue $widget $mesg |
---|
[640] | 521 | } |
---|
| 522 | } |
---|
| 523 | |
---|
| 524 | # ---------------------------------------------------------------------- |
---|
[437] | 525 | # CONFIGURATION OPTION: -editable |
---|
| 526 | # ---------------------------------------------------------------------- |
---|
| 527 | itcl::configbody Rappture::TextEntry::editable { |
---|
| 528 | if {![string is boolean -strict $itk_option(-editable)]} { |
---|
[1342] | 529 | error "bad value \"$itk_option(-editable)\": should be boolean" |
---|
[437] | 530 | } |
---|
| 531 | _fixState |
---|
| 532 | } |
---|
| 533 | |
---|
| 534 | # ---------------------------------------------------------------------- |
---|
| 535 | # CONFIGURATION OPTION: -state |
---|
| 536 | # ---------------------------------------------------------------------- |
---|
| 537 | itcl::configbody Rappture::TextEntry::state { |
---|
| 538 | set valid {normal disabled} |
---|
| 539 | if {[lsearch -exact $valid $itk_option(-state)] < 0} { |
---|
[1342] | 540 | error "bad value \"$itk_option(-state)\": should be [join $valid {, }]" |
---|
[437] | 541 | } |
---|
[640] | 542 | if {$_layout == "text"} { |
---|
[1342] | 543 | if {$itk_option(-state) == "disabled"} { |
---|
| 544 | set fg [option get $itk_component(text) disabledForeground Foreground] |
---|
| 545 | } else { |
---|
| 546 | set fg $itk_option(-foreground) |
---|
| 547 | } |
---|
| 548 | $itk_component(text) configure -foreground $fg |
---|
[437] | 549 | } |
---|
| 550 | _fixState |
---|
| 551 | } |
---|
| 552 | |
---|
| 553 | # ---------------------------------------------------------------------- |
---|
[11] | 554 | # CONFIGURATION OPTION: -width |
---|
| 555 | # ---------------------------------------------------------------------- |
---|
| 556 | itcl::configbody Rappture::TextEntry::width { |
---|
| 557 | # check size to see if it has the proper form |
---|
| 558 | winfo pixels $itk_component(hull) $itk_option(-width) |
---|
| 559 | $_dispatcher event -idle !layout |
---|
| 560 | } |
---|
| 561 | |
---|
| 562 | # ---------------------------------------------------------------------- |
---|
| 563 | # CONFIGURATION OPTION: -height |
---|
| 564 | # ---------------------------------------------------------------------- |
---|
| 565 | itcl::configbody Rappture::TextEntry::height { |
---|
| 566 | # check size to see if it has the proper form |
---|
| 567 | winfo pixels $itk_component(hull) $itk_option(-height) |
---|
| 568 | $_dispatcher event -idle !layout |
---|
| 569 | } |
---|