[3330] | 1 | # -*- mode: tcl; indent-tabs-mode: nil -*- |
---|
[22] | 2 | # ---------------------------------------------------------------------- |
---|
| 3 | # COMPONENT: owner - manages Rappture controls |
---|
| 4 | # |
---|
| 5 | # This object represents an entity managing Rappture controls. |
---|
| 6 | # It is typically a Tool, a DeviceEditor, or some other large entity |
---|
| 7 | # that manages a Rappture XML tree. All controlling widgets are |
---|
| 8 | # registered with an owner, and the owner propagates notifications |
---|
| 9 | # out to clients who have an interest in a particular control. |
---|
| 10 | # ====================================================================== |
---|
| 11 | # AUTHOR: Michael McLennan, Purdue University |
---|
[3177] | 12 | # Copyright (c) 2004-2012 HUBzero Foundation, LLC |
---|
[115] | 13 | # |
---|
| 14 | # See the file "license.terms" for information on usage and |
---|
| 15 | # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
[22] | 16 | # ====================================================================== |
---|
| 17 | package require Itcl |
---|
| 18 | |
---|
| 19 | itcl::class Rappture::ControlOwner { |
---|
| 20 | constructor {owner} { # defined below } |
---|
| 21 | |
---|
| 22 | public method xml {args} |
---|
| 23 | |
---|
| 24 | public method load {newobj} |
---|
[23] | 25 | public method widgetfor {path args} |
---|
[193] | 26 | public method valuefor {path args} |
---|
[437] | 27 | public method dependenciesfor {path args} |
---|
[438] | 28 | public method ownerfor {path {skip ""}} |
---|
[22] | 29 | public method changed {path} |
---|
[437] | 30 | public method regularize {path} |
---|
[22] | 31 | public method notify {option owner args} |
---|
| 32 | public method sync {} |
---|
| 33 | public method tool {} |
---|
| 34 | |
---|
[438] | 35 | protected method _slave {option args} |
---|
| 36 | |
---|
[22] | 37 | protected variable _owner "" ;# ControlOwner containing this one |
---|
[437] | 38 | protected variable _path "" ;# paths within are relative to this |
---|
[438] | 39 | protected variable _slaves "" ;# this owner has these slaves |
---|
[22] | 40 | protected variable _xmlobj "" ;# Rappture XML description |
---|
| 41 | private variable _path2widget ;# maps path => widget on this page |
---|
| 42 | private variable _owner2paths ;# for notify: maps owner => interests |
---|
[1207] | 43 | private variable _type2curpath ;# maps type(path) => path's current value |
---|
[22] | 44 | private variable _callbacks ;# for notify: maps owner/path => callback |
---|
[437] | 45 | private variable _dependencies ;# maps path => other paths dep on this |
---|
[22] | 46 | } |
---|
[1207] | 47 | |
---|
[22] | 48 | # ---------------------------------------------------------------------- |
---|
| 49 | # CONSTRUCTOR |
---|
| 50 | # ---------------------------------------------------------------------- |
---|
| 51 | itcl::body Rappture::ControlOwner::constructor {owner} { |
---|
[438] | 52 | if {"" != $owner} { |
---|
[1929] | 53 | set parts [split $owner @] |
---|
| 54 | set _owner [lindex $parts 0] |
---|
| 55 | set _path [lindex $parts 1] |
---|
| 56 | $_owner _slave add $this |
---|
[438] | 57 | } |
---|
[1207] | 58 | |
---|
| 59 | # we are adding this so notes can be used |
---|
| 60 | # in coordination with loaders inside the load function |
---|
| 61 | array set _type2curpath { |
---|
[3139] | 62 | drawing all |
---|
[1929] | 63 | choice current |
---|
| 64 | boolean current |
---|
| 65 | image current |
---|
| 66 | integer current |
---|
| 67 | loader current |
---|
| 68 | note contents |
---|
| 69 | number current |
---|
[2753] | 70 | periodicelement current |
---|
[1929] | 71 | string current |
---|
[1207] | 72 | } |
---|
[22] | 73 | } |
---|
| 74 | |
---|
| 75 | # ---------------------------------------------------------------------- |
---|
| 76 | # USAGE: xml <subcommand> ?<arg> <arg> ...? |
---|
| 77 | # USAGE: xml object |
---|
| 78 | # |
---|
| 79 | # Used by clients to manipulate the underlying XML data for this |
---|
| 80 | # tool. The <subcommand> can be any operation supported by a |
---|
| 81 | # Rappture::library object. Clients can also request the XML object |
---|
| 82 | # directly by using the "object" subcommand. |
---|
| 83 | # ---------------------------------------------------------------------- |
---|
| 84 | itcl::body Rappture::ControlOwner::xml {args} { |
---|
| 85 | if {"object" == $args} { |
---|
[1929] | 86 | return $_xmlobj |
---|
[22] | 87 | } |
---|
| 88 | return [eval $_xmlobj $args] |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | # ---------------------------------------------------------------------- |
---|
| 92 | # USAGE: widgetfor <path> ?<widget>? |
---|
| 93 | # |
---|
| 94 | # Used by embedded widgets such as a Controls panel to register the |
---|
| 95 | # various controls associated with this page. That way, this |
---|
| 96 | # ControlOwner knows what widgets to look at when syncing itself |
---|
| 97 | # to the underlying XML data. |
---|
| 98 | # ---------------------------------------------------------------------- |
---|
[23] | 99 | itcl::body Rappture::ControlOwner::widgetfor {path args} { |
---|
[22] | 100 | # if this is a query operation, then look for the path |
---|
[23] | 101 | if {[llength $args] == 0} { |
---|
[1929] | 102 | set owner [ownerfor $path] |
---|
| 103 | if {$owner != $this && $owner != ""} { |
---|
| 104 | return [$owner widgetfor $path] |
---|
| 105 | } |
---|
| 106 | if {[info exists _path2widget($path)]} { |
---|
| 107 | return $_path2widget($path) |
---|
| 108 | } |
---|
| 109 | return "" |
---|
[22] | 110 | } |
---|
| 111 | |
---|
| 112 | # otherwise, associate the path with the given widget |
---|
[23] | 113 | set widget [lindex $args 0] |
---|
| 114 | if {"" != $widget} { |
---|
[1929] | 115 | if {[info exists _path2widget($path)]} { |
---|
| 116 | error "$path already associated with widget $_path2widget($path)" |
---|
| 117 | } |
---|
| 118 | set _path2widget($path) $widget |
---|
[23] | 119 | } else { |
---|
[1929] | 120 | catch {unset _path2widget($path)} |
---|
[22] | 121 | } |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | # ---------------------------------------------------------------------- |
---|
[193] | 125 | # USAGE: valuefor <path> ?<newValue>? |
---|
| 126 | # |
---|
| 127 | # Used by embedded widgets such as a Loader to query or set the |
---|
| 128 | # value of another control. With no extra args, it returns the |
---|
| 129 | # value of the widget at the <path> in the XML. Otherwise, it |
---|
| 130 | # sets the value of the widget to <newValue>. |
---|
| 131 | # ---------------------------------------------------------------------- |
---|
| 132 | itcl::body Rappture::ControlOwner::valuefor {path args} { |
---|
[438] | 133 | set owner [ownerfor $path] |
---|
| 134 | |
---|
[193] | 135 | # if this is a query operation, then look for the path |
---|
| 136 | if {[llength $args] == 0} { |
---|
[1929] | 137 | if {$owner != $this && $owner != ""} { |
---|
| 138 | return [$owner valuefor $path] |
---|
| 139 | } |
---|
| 140 | if {[info exists _path2widget($path)]} { |
---|
| 141 | return [$_path2widget($path) value] |
---|
| 142 | } |
---|
| 143 | # can't find the path? try removing the prefix for this owner |
---|
| 144 | set plen [string length $_path] |
---|
| 145 | if {[string equal -length $plen $_path $path]} { |
---|
| 146 | set relpath [string range $path [expr {$plen+1}] end] |
---|
| 147 | if {[info exists _path2widget($relpath)]} { |
---|
| 148 | return [$_path2widget($relpath) value] |
---|
| 149 | } |
---|
| 150 | } |
---|
| 151 | return "" |
---|
[193] | 152 | } |
---|
| 153 | |
---|
| 154 | # otherwise, set the value |
---|
[438] | 155 | if {$owner != $this && $owner != ""} { |
---|
[1929] | 156 | return [eval $owner valuefor $path $args] |
---|
[438] | 157 | } |
---|
[193] | 158 | if {[llength $args] > 1} { |
---|
[1929] | 159 | error "wrong # args: should be \"valuefor path ?newValue?\"" |
---|
[193] | 160 | } |
---|
| 161 | |
---|
| 162 | if {[info exists _path2widget($path)]} { |
---|
[1929] | 163 | $_path2widget($path) value [lindex $args 0] |
---|
[193] | 164 | } else { |
---|
[1929] | 165 | error "bad path \"$path\": should be one of [join [lsort [array names _path2widget]] {, }]" |
---|
[193] | 166 | } |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | # ---------------------------------------------------------------------- |
---|
[437] | 170 | # USAGE: dependenciesfor <path> ?<path>...? |
---|
| 171 | # |
---|
| 172 | # Used by embedded widgets such as a Controls panel to register the |
---|
| 173 | # various controls that are dependent on another one. If only one |
---|
| 174 | # path is specified, then this method returns all known dependencies |
---|
| 175 | # for the specified <path>. Otherwise, the additional <path>'s are |
---|
| 176 | # noted as being dependent on the first <path>. |
---|
| 177 | # ---------------------------------------------------------------------- |
---|
| 178 | itcl::body Rappture::ControlOwner::dependenciesfor {path args} { |
---|
[438] | 179 | if {"" != $_owner} { |
---|
[1929] | 180 | # |
---|
| 181 | # Keep all dependencies at the highest level. |
---|
| 182 | # That way, a structure can come and go, but the |
---|
| 183 | # dependencies remain fixed in the topmost tool. |
---|
| 184 | # |
---|
| 185 | set plen [string length $_path] |
---|
| 186 | if {"" != $_path && ![string equal -length $plen $_path $path]} { |
---|
| 187 | set path $_path.$path |
---|
| 188 | } |
---|
| 189 | return [eval $_owner dependenciesfor $path $args] |
---|
[438] | 190 | } |
---|
| 191 | |
---|
[437] | 192 | # if this is a query operation, then look for the path |
---|
| 193 | if {[llength $args] == 0} { |
---|
[1929] | 194 | if {[info exists _dependencies($path)]} { |
---|
| 195 | return $_dependencies($path) |
---|
| 196 | } |
---|
| 197 | return "" |
---|
[437] | 198 | } |
---|
| 199 | |
---|
| 200 | # add new dependencies |
---|
| 201 | if {![info exists _dependencies($path)]} { |
---|
[1929] | 202 | set _dependencies($path) "" |
---|
[437] | 203 | } |
---|
| 204 | foreach dpath $args { |
---|
[1929] | 205 | set i [lsearch -exact $_dependencies($path) $dpath] |
---|
| 206 | if {$i < 0} { |
---|
| 207 | lappend _dependencies($path) $dpath |
---|
| 208 | } |
---|
[437] | 209 | } |
---|
| 210 | } |
---|
| 211 | |
---|
| 212 | # ---------------------------------------------------------------------- |
---|
[438] | 213 | # USAGE: ownerfor <path> ?<skip>? |
---|
| 214 | # |
---|
| 215 | # Returns the ControlOwner that directly controls the specified <path>. |
---|
| 216 | # ---------------------------------------------------------------------- |
---|
| 217 | itcl::body Rappture::ControlOwner::ownerfor {path {skip ""}} { |
---|
| 218 | if {[info exists _path2widget($path)]} { |
---|
[1929] | 219 | return $this |
---|
[438] | 220 | } |
---|
| 221 | |
---|
| 222 | # can't find the path? try removing the prefix for this owner |
---|
| 223 | set plen [string length $_path] |
---|
| 224 | if {[string equal -length $plen $_path $path]} { |
---|
[1929] | 225 | set relpath [string range $path [expr {$plen+1}] end] |
---|
| 226 | if {[info exists _path2widget($relpath)]} { |
---|
| 227 | return $this |
---|
| 228 | } |
---|
[438] | 229 | } |
---|
| 230 | |
---|
| 231 | # couldn't find this path? then check all subordinates |
---|
| 232 | foreach slave $_slaves { |
---|
[1929] | 233 | if {$slave == $skip} { |
---|
| 234 | continue ;# skip this slave if it's already been searched |
---|
| 235 | } |
---|
| 236 | set rval [$slave ownerfor $path $this] |
---|
| 237 | if {"" != $rval} { |
---|
| 238 | return $rval |
---|
| 239 | } |
---|
[438] | 240 | } |
---|
| 241 | |
---|
| 242 | # check the owner as a last resort |
---|
| 243 | if {"" != $_owner && $_owner != $skip} { |
---|
[1929] | 244 | set rval [$_owner ownerfor $path $this] |
---|
| 245 | if {"" != $rval} { |
---|
| 246 | return $rval |
---|
| 247 | } |
---|
[438] | 248 | } |
---|
| 249 | |
---|
| 250 | return "" |
---|
| 251 | } |
---|
| 252 | |
---|
| 253 | # ---------------------------------------------------------------------- |
---|
[22] | 254 | # USAGE: load <xmlobj> |
---|
| 255 | # |
---|
| 256 | # Loads the contents of a Rappture <xmlobj> into the controls |
---|
| 257 | # associated with this tool. |
---|
| 258 | # ---------------------------------------------------------------------- |
---|
| 259 | itcl::body Rappture::ControlOwner::load {newobj} { |
---|
| 260 | if {![Rappture::library isvalid $newobj]} { |
---|
[1929] | 261 | error "\"$newobj\" is not a Rappture::library" |
---|
[22] | 262 | } |
---|
| 263 | foreach path [array names _path2widget] { |
---|
[1929] | 264 | # the following elements do not accept "current" tags, skip them |
---|
| 265 | set type [[tool] xml element -as type $path] |
---|
| 266 | if {[lsearch {group separator control} $type] >= 0} { |
---|
| 267 | continue |
---|
| 268 | } |
---|
[1159] | 269 | |
---|
[1929] | 270 | set type [[tool] xml element -as type $path] |
---|
| 271 | if {[info exists _type2curpath($type)]} { |
---|
[3139] | 272 | if { $_type2curpath($type) == "all" } { |
---|
| 273 | set currentpath $path |
---|
| 274 | } else { |
---|
| 275 | set currentpath $path.$_type2curpath($type) |
---|
| 276 | } |
---|
[1929] | 277 | } else { |
---|
| 278 | # default incase i forgot an input type in _type2curpath |
---|
| 279 | set currentpath $path.current |
---|
| 280 | } |
---|
[1207] | 281 | |
---|
[1929] | 282 | # copy new value to the XML tree |
---|
| 283 | # also copy to the widget associated with the tree |
---|
| 284 | # |
---|
| 285 | # we only copy the values if they existed in newobj |
---|
| 286 | # so we don't overwrite values that were set in previous loads. |
---|
| 287 | # this is needed for when the users specify copy.from and copy.to |
---|
| 288 | # in a loader. in this case, _path2widget holds a list of all |
---|
| 289 | # widgets. if there are two loaders loading two different widgets, |
---|
| 290 | # and each loader uses the copy from/to functionality, |
---|
| 291 | # the second load could wipe out the values set in the first load |
---|
| 292 | # because on the second load, the copied paths from the first load no |
---|
| 293 | # longer exist in newobj and blanks are copied to the paths |
---|
| 294 | # in [tool] xml set by the first loader. the solution is to check |
---|
| 295 | # newobj and see if the path exists. if the path exists, then we copy |
---|
| 296 | # it over to [tool] xml, otherwise we ignore it. |
---|
| 297 | if {"" != [$newobj element -as type $currentpath]} { |
---|
| 298 | [tool] xml copy $currentpath from $newobj $currentpath |
---|
| 299 | set val [$newobj get $currentpath] |
---|
| 300 | if {[string length $val] > 0 |
---|
| 301 | || [llength [$newobj children $currentpath]] == 0} { |
---|
| 302 | $_path2widget($path) value $val |
---|
| 303 | } else { |
---|
| 304 | set obj [$newobj element -as object $currentpath] |
---|
| 305 | $_path2widget($path) value $obj |
---|
| 306 | } |
---|
| 307 | } |
---|
[22] | 308 | } |
---|
| 309 | } |
---|
| 310 | |
---|
| 311 | # ---------------------------------------------------------------------- |
---|
| 312 | # USAGE: changed <path> |
---|
| 313 | # |
---|
| 314 | # Invoked automatically by the various widgets associated with this |
---|
| 315 | # tool whenever their value changes. Sends notifications to any |
---|
| 316 | # client that has registered an interest via "notify add". |
---|
| 317 | # ---------------------------------------------------------------------- |
---|
| 318 | itcl::body Rappture::ControlOwner::changed {path} { |
---|
| 319 | if {"" != $_owner} { |
---|
[1929] | 320 | set plen [string length $_path] |
---|
| 321 | if {"" != $_path && ![string equal -length $plen $_path $path]} { |
---|
| 322 | set path $_path.$path |
---|
| 323 | } |
---|
| 324 | $_owner changed $path |
---|
[22] | 325 | } else { |
---|
[1929] | 326 | # send out any callback notifications |
---|
| 327 | foreach owner [array names _owner2paths] { |
---|
| 328 | foreach pattern $_owner2paths($owner) { |
---|
| 329 | if {[string match $pattern $path]} { |
---|
| 330 | uplevel #0 $_callbacks($owner/$pattern) |
---|
| 331 | break |
---|
| 332 | } |
---|
| 333 | } |
---|
| 334 | } |
---|
[438] | 335 | |
---|
[1929] | 336 | # find the control panel for each dependency, and tell it |
---|
| 337 | # to update its layout. |
---|
| 338 | foreach cpath [dependenciesfor $path] { |
---|
| 339 | set wv [widgetfor $cpath] |
---|
| 340 | while {"" != $wv} { |
---|
| 341 | set wv [winfo parent $wv] |
---|
| 342 | if {[winfo class $wv] == "Controls"} { |
---|
| 343 | $wv refresh |
---|
| 344 | break |
---|
| 345 | } |
---|
| 346 | } |
---|
| 347 | } |
---|
[22] | 348 | } |
---|
| 349 | } |
---|
| 350 | |
---|
| 351 | # ---------------------------------------------------------------------- |
---|
[437] | 352 | # USAGE: regularize <path> |
---|
| 353 | # |
---|
| 354 | # Clients use this to get a full, regularized path for the specified |
---|
| 355 | # <path>, which may be relative to the current owner. |
---|
| 356 | # ---------------------------------------------------------------------- |
---|
| 357 | itcl::body Rappture::ControlOwner::regularize {path} { |
---|
[438] | 358 | set owner [ownerfor $path] |
---|
| 359 | if {$owner != $this && $owner != ""} { |
---|
[1929] | 360 | return [$owner regularize $path] |
---|
[438] | 361 | } |
---|
| 362 | set rpath "" |
---|
| 363 | if {"" != $_xmlobj} { |
---|
[1929] | 364 | set rpath [$_xmlobj element -as path $path] |
---|
[438] | 365 | |
---|
[1929] | 366 | # can't find the path? try removing the prefix for this owner |
---|
| 367 | if {"" == $rpath} { |
---|
| 368 | set plen [string length $_path] |
---|
| 369 | if {[string equal -length $plen $_path $path]} { |
---|
| 370 | set relpath [string range $path [expr {$plen+2}] end] |
---|
| 371 | set rpath [$_xmlobj element -as path $relpath] |
---|
| 372 | } |
---|
| 373 | } |
---|
[438] | 374 | |
---|
[1929] | 375 | if {"" != $rpath && "" != $_path} { |
---|
| 376 | # return a full name for the path |
---|
| 377 | set rpath "$_path.$rpath" |
---|
| 378 | } |
---|
[437] | 379 | } |
---|
| 380 | return $rpath |
---|
| 381 | } |
---|
| 382 | |
---|
| 383 | # ---------------------------------------------------------------------- |
---|
[22] | 384 | # USAGE: notify add <owner> <path> <callback> |
---|
| 385 | # USAGE: notify info ?<owner>? ?<path>? |
---|
| 386 | # USAGE: notify remove <owner> ?<path> ...? |
---|
| 387 | # |
---|
| 388 | # Clients use this to request notifications about changes to a |
---|
| 389 | # particular <path> for a control under this tool. Whenever the |
---|
| 390 | # value associated with <path> changes, the client identified by |
---|
| 391 | # <owner> is sent a message by invoking its <callback> routine. |
---|
| 392 | # |
---|
| 393 | # Notifications can be silenced by calling the "notify remove" |
---|
| 394 | # function. |
---|
| 395 | # ---------------------------------------------------------------------- |
---|
| 396 | itcl::body Rappture::ControlOwner::notify {option args} { |
---|
| 397 | switch -- $option { |
---|
[1929] | 398 | add { |
---|
| 399 | if {[llength $args] != 3} { |
---|
| 400 | error "wrong # args: should be \"notify add owner path callback\"" |
---|
| 401 | } |
---|
| 402 | set owner [lindex $args 0] |
---|
| 403 | set path [lindex $args 1] |
---|
| 404 | set cb [lindex $args 2] |
---|
[22] | 405 | |
---|
[1929] | 406 | if {[info exists _owner2paths($owner)]} { |
---|
| 407 | set plist $_owner2paths($owner) |
---|
| 408 | } else { |
---|
| 409 | set plist "" |
---|
| 410 | } |
---|
[22] | 411 | |
---|
[1929] | 412 | set i [lsearch -exact $plist $path] |
---|
| 413 | if {$i < 0} { lappend _owner2paths($owner) $path } |
---|
| 414 | set _callbacks($owner/$path) $cb |
---|
| 415 | } |
---|
| 416 | info { |
---|
| 417 | if {[llength $args] == 0} { |
---|
| 418 | # no args? then return all owners |
---|
| 419 | return [array names _owner2paths] |
---|
| 420 | } else { |
---|
| 421 | set owner [lindex $args 0] |
---|
| 422 | if {[info exists _owner2paths($owner)]} { |
---|
| 423 | set plist $_owner2paths($owner) |
---|
| 424 | } else { |
---|
| 425 | set plist "" |
---|
| 426 | } |
---|
| 427 | if {[llength $args] == 1} { |
---|
| 428 | # 1 arg? then return paths for this owner |
---|
| 429 | return $plist |
---|
| 430 | } elseif {[llength $args] == 2} { |
---|
| 431 | # 2 args? then return callback for this path |
---|
| 432 | set path [lindex $args 1] |
---|
| 433 | if {[info exists _callbacks($owner/$path)]} { |
---|
| 434 | return $_callbacks($owner/$path) |
---|
| 435 | } |
---|
| 436 | return "" |
---|
| 437 | } else { |
---|
| 438 | error "wrong # args: should be \"notify info ?owner? ?path?\"" |
---|
| 439 | } |
---|
| 440 | } |
---|
| 441 | } |
---|
| 442 | remove { |
---|
| 443 | if {[llength $args] < 1} { |
---|
| 444 | error "wrong # args: should be \"notify remove owner ?path ...?\"" |
---|
| 445 | } |
---|
| 446 | set owner [lindex $args 0] |
---|
[22] | 447 | |
---|
[1929] | 448 | if {[llength $args] == 1} { |
---|
| 449 | # no args? then delete all paths for this owner |
---|
| 450 | if {[info exists _owner2paths($owner)]} { |
---|
| 451 | set plist $_owner2paths($owner) |
---|
| 452 | } else { |
---|
| 453 | set plist "" |
---|
| 454 | } |
---|
| 455 | } else { |
---|
| 456 | set plist [lrange $args 1 end] |
---|
| 457 | } |
---|
[22] | 458 | |
---|
[1929] | 459 | # forget about the callback for each path |
---|
| 460 | foreach path $plist { |
---|
| 461 | catch {unset _callbacks($owner/$path)} |
---|
[22] | 462 | |
---|
[1929] | 463 | if {[info exists _owner2paths($owner)]} { |
---|
| 464 | set i [lsearch -exact $_owner2paths($owner) $path] |
---|
| 465 | if {$i >= 0} { |
---|
| 466 | set _owner2paths($owner) \ |
---|
| 467 | [lreplace $_owner2paths($owner) $i $i] |
---|
| 468 | } |
---|
| 469 | } |
---|
| 470 | } |
---|
| 471 | } |
---|
[22] | 472 | } |
---|
| 473 | } |
---|
| 474 | |
---|
| 475 | # ---------------------------------------------------------------------- |
---|
| 476 | # USAGE: sync |
---|
| 477 | # |
---|
| 478 | # Used by descendents such as a Controls panel to register the |
---|
| 479 | # various controls associated with this page. That way, this |
---|
| 480 | # ControlOwner knows what widgets to look at when syncing itself |
---|
| 481 | # to the underlying XML data. |
---|
| 482 | # ---------------------------------------------------------------------- |
---|
| 483 | itcl::body Rappture::ControlOwner::sync {} { |
---|
[438] | 484 | # sync all of the widgets under control of this owner |
---|
| 485 | if {"" != $_xmlobj} { |
---|
[1929] | 486 | foreach path [lsort [array names _path2widget]] { |
---|
| 487 | set type [$_xmlobj element -as type $path] |
---|
| 488 | if {[lsearch {group separator control note} $type] >= 0} { |
---|
| 489 | continue |
---|
| 490 | } |
---|
| 491 | $_xmlobj put $path.current [$_path2widget($path) value] |
---|
| 492 | } |
---|
[22] | 493 | } |
---|
[438] | 494 | |
---|
| 495 | # sync all subordinate slaves as well |
---|
| 496 | foreach slave $_slaves { |
---|
[1929] | 497 | $slave sync |
---|
[438] | 498 | } |
---|
[22] | 499 | } |
---|
| 500 | |
---|
| 501 | # ---------------------------------------------------------------------- |
---|
| 502 | # USAGE: tool |
---|
| 503 | # |
---|
| 504 | # Clients use this to figure out which tool is associated with |
---|
| 505 | # this object. If there is no parent ControlOwner, then this |
---|
| 506 | # must be the top-level tool. |
---|
| 507 | # ---------------------------------------------------------------------- |
---|
| 508 | itcl::body Rappture::ControlOwner::tool {} { |
---|
| 509 | if {"" != $_owner} { |
---|
[1929] | 510 | return [$_owner tool] |
---|
[22] | 511 | } |
---|
| 512 | return $this |
---|
| 513 | } |
---|
[438] | 514 | |
---|
| 515 | # ---------------------------------------------------------------------- |
---|
| 516 | # USAGE: _slave add <newobj>... |
---|
| 517 | # |
---|
| 518 | # Used internally to register the parent-child relationship whenever |
---|
| 519 | # one ControlOwner is registered to another. When the parent syncs, |
---|
| 520 | # it causes all of its children to sync. When a name is being |
---|
| 521 | # resolved, it is resolved locally first, then up to the parent for |
---|
| 522 | # further resolution. |
---|
| 523 | # ---------------------------------------------------------------------- |
---|
| 524 | itcl::body Rappture::ControlOwner::_slave {option args} { |
---|
| 525 | switch -- $option { |
---|
[1929] | 526 | add { |
---|
| 527 | eval lappend _slaves $args |
---|
| 528 | } |
---|
| 529 | default { |
---|
| 530 | error "bad option \"$option\": should be add" |
---|
| 531 | } |
---|
[438] | 532 | } |
---|
| 533 | } |
---|