3 # ----------------------------------------------------------------------
4 # Invoked automatically upon startup to customize the interpreter
5 # for [incr Tcl] when one of ::itcl::widget or ::itcl::widgetadaptor is called.
6 # ----------------------------------------------------------------------
7 # AUTHOR: Arnulf P. Wiedemann
9 # ----------------------------------------------------------------------
10 # Copyright (c) 2008 Arnulf P. Wiedemann
11 # ======================================================================
12 # See the file "license.terms" for information on usage and
13 # redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
15 package require Tk 8.6
16 # package require itclwidget [set ::itcl::version]
18 namespace eval ::itcl {
20 proc widget {name args} {
21 set result [uplevel 1 ::itcl::internal::commands::genericclass widget $name $args]
22 # we handle create by owerselfs !! allow classunknown to handle that
23 oo::objdefine $result unexport create
27 proc widgetadaptor {name args} {
28 set result [uplevel 1 ::itcl::internal::commands::genericclass widgetadaptor $name $args]
29 # we handle create by owerselfs !! allow classunknown to handle that
30 oo::objdefine $result unexport create
37 namespace eval ::itcl::internal::commands {
39 proc initWidgetOptions {varNsName widgetName className} {
40 set myDict [set ::itcl::internal::dicts::classOptions]
44 if {![dict exists $myDict $className]} {
47 set myDict [dict get $myDict $className]
48 foreach option [dict keys $myDict] {
49 set infos [dict get $myDict $option]
50 set resource [dict get $infos -resource]
51 set class [dict get $infos -class]
52 set value [::option get $widgetName $resource $class]
54 if {[dict exists $infos -default]} {
55 set defaultValue [dict get $infos -default]
56 uplevel 1 set ${varNsName}::itcl_options($option) $defaultValue
59 uplevel 1 set ${varNsName}::itcl_options($option) $value
64 proc initWidgetDelegatedOptions {varNsName widgetName className args} {
65 set myDict [set ::itcl::internal::dicts::classDelegatedOptions]
69 if {![dict exists $myDict $className]} {
72 set myDict [dict get $myDict $className]
73 foreach option [dict keys $myDict] {
74 set infos [dict get $myDict $option]
75 if {![dict exists $infos -resource]} {
76 # this is the case when delegating "*"
79 if {![dict exists $infos -component]} {
83 # check if not in the command line options
84 # these have higher priority
86 if {[dict exists $infos -as]} {
87 set myOption [dict get $infos -as]
90 foreach {optName optVal} $args {
91 if {$optName eq $myOption} {
99 set resource [dict get $infos -resource]
100 set class [dict get $infos -class]
101 set component [dict get $infos -component]
102 set value [::option get $widgetName $resource $class]
103 if {$component ne ""} {
105 set compVar [namespace eval ${varNsName}${className} "set $component"]
106 if {$compVar ne ""} {
107 uplevel 1 $compVar configure $myOption $value
114 proc widgetinitobjectoptions {varNsName widgetName className} {
115 #puts stderr "initWidgetObjectOptions!$varNsName!$widgetName!$className!"
118 proc deletehull {newName oldName what} {
119 if {$what eq "delete"} {
120 set name [namespace tail $newName]
121 regsub {hull[0-9]+} $name {} name
124 if {$what eq "rename"} {
125 set name [namespace tail $newName]
126 regsub {hull[0-9]+} $name {} name
131 proc hullandoptionsinstall {objectName className widgetClass hulltype args} {
132 if {$hulltype eq ""} {
137 foreach {optName optValue} $args {
138 if {$optName eq "-class"} {
140 set widgetClass $optValue
146 set args [lreplace $args $idx [expr {$idx + 1}]]
148 if {$widgetClass eq ""} {
149 set widgetClass $className
150 set widgetClass [string totitle $widgetClass]
152 set cmd "set win $objectName; ::itcl::builtin::installhull using $hulltype -class $widgetClass $args"
156 } ; # end ::itcl::internal::commands
158 namespace eval ::itcl::builtin {
160 proc installhull {args} {
163 set cmdPath ::itcl::internal::commands
164 set className [uplevel 1 info class]
165 set numArgs [llength $args]
168 error "wrong # args: should be \"installhull name|using <widgetType> ?arg ...?\""
173 set origWidgetName $widgetName
176 set widgetName [lindex $args 0]
178 set varNsName ::itcl::internal::variables::$widgetName
179 set myCmd [uplevel 1 ::info command $widgetName]
184 set args [lrange $args 1 end]
186 set widgetType [lindex $args 0]
187 set args [lrange $args 1 end]
190 set classOpt [lindex $args 0]
191 if {$classOpt eq "-class"} {
192 set classNam [lindex $args 1]
193 set args [lrange $args 2 end]
196 if {$classNam eq ""} {
197 set classNam [string totitle $widgetType]
199 uplevel 1 $widgetType $widgetName -class $classNam $args
200 uplevel 1 ${cmdPath}::initWidgetOptions $varNsName $widgetName $className
202 # initialize the itcl_hull variable
204 set nam ::itcl::internal::widgets::hull
207 set hullNam ${nam}${i}$widgetName
208 if {[::info command $hullNam] eq ""} {
212 uplevel 1 ${cmdPath}::sethullwindowname $widgetName
213 uplevel 1 rename $widgetName $hullNam
214 uplevel 1 trace add command $hullNam \[list delete rename\] ::itcl::internal::commands::deletehull
215 set objectName [namespace tail $win]
216 catch {${cmdPath}::checksetitclhull [list] 0}
217 namespace eval ${varNsName}${className} "set itcl_hull $hullNam"
218 catch {${cmdPath}::checksetitclhull [list] 2}
219 set cmd "${cmdPath}::initWidgetDelegatedOptions $varNsName $widgetName $className"
227 proc installcomponent {args} {
230 set className [uplevel 1 info class]
231 set myType [info types [namespace tail $className]]
236 set numArgs [llength $args]
237 set usage "usage: installcomponent <componentName> using <widgetType> <widgetPath> ?-option value ...?"
241 foreach {componentName using widgetType widgetPath} $args break
242 set opts [lrange $args 4 end]
243 if {$using ne "using"} {
247 set hullExists [uplevel 1 ::info exists itcl_hull]
249 error "cannot install \"$componentName\" before \"itcl_hull\" exists"
251 set hullVal [uplevel 1 set itcl_hull]
252 if {$hullVal eq ""} {
253 error "cannot install \"$componentName\" before \"itcl_hull\" exists"
256 # check for delegated option and ask the option database for the values
257 # first check for number of delegated options
260 set myDict [set ::itcl::internal::dicts::classDelegatedOptions]
261 if {[dict exists $myDict $className]} {
262 set myDict [dict get $myDict $className]
263 foreach option [dict keys $myDict] {
264 if {$option eq "*"} {
270 set myOptionDict [set ::itcl::internal::dicts::classOptions]
271 if {[dict exists $myOptionDict $className]} {
272 set myOptionDict [dict get $myOptionDict $className]
274 set cmd [list $widgetPath configure]
275 set cmd1 "set $componentName \[$widgetType $widgetPath\]"
278 upvar $componentName compName
279 set cmd1 [list $compName configure]
280 set configInfos [uplevel 1 $cmd1]
281 foreach entry $configInfos {
282 if {[llength $entry] > 2} {
283 foreach {optName resource class defaultValue} $entry break
286 set val [::option get $win $resource $class]
290 if {[dict exists $myDict $$optName]} {
293 set starDict [dict get $myDict "*"]
294 if {[dict exists $starDict -except]} {
295 set exceptions [dict get $starDict -except]
296 if {[lsearch $exceptions $optName] >= 0} {
301 if {[dict exists $myOptionDict $optName]} {
306 lappend cmd $optName $val
314 foreach optName [dict keys $myDict] {
315 set optInfos [dict get $myDict $optName]
316 set resource [dict get $optInfos -resource]
317 set class [namespace tail $className]
318 set class [string totitle $class]
321 set val [::option get $win $resource $class]
324 if {[dict exists $optInfos -as] } {
325 set optName [dict get $optInfos -as]
327 lappend cmd $optName $val
335 } ; # end ::itcl::builtin
337 set ::itcl::internal::dicts::hullTypes [list \
346 namespace eval ::itcl::builtin::Info {
348 proc hulltypes {args} {
349 namespace upvar ::itcl::internal::dicts hullTypes hullTypes
351 set numArgs [llength $args]
353 error "wrong # args should be: info hulltypes ?<pattern>?"
357 set pattern [lindex $args 0]
359 if {$pattern ne ""} {
360 return [lsearch -all -inline -glob $hullTypes $pattern]
366 proc widgetclasses {args} {
367 set numArgs [llength $args]
369 error "wrong # args should be: info widgetclasses ?<pattern>?"
373 set pattern [lindex $args 0]
375 set myDict [set ::itcl::internal::dicts::classes]
376 if {![dict exists $myDict widget]} {
379 set myDict [dict get $myDict widget]
381 if {$pattern ne ""} {
382 foreach key [dict keys $myDict] {
383 set myInfo [dict get $myDict $key]
384 set value [dict get $myInfo -widget]
385 if {[string match $pattern $value]} {
386 lappend result $value
390 foreach key [dict keys $myDict] {
391 set myInfo [dict get $myDict $key]
392 lappend result [dict get $myInfo -widget]
398 proc widgets {args} {
399 set numArgs [llength $args]
401 error "wrong # args should be: info widgets ?<pattern>?"
405 set pattern [lindex $args 0]
407 set myDict [set ::itcl::internal::dicts::classes]
408 if {![dict exists $myDict widget]} {
411 set myDict [dict get $myDict widget]
413 if {$pattern ne ""} {
414 foreach key [dict keys $myDict] {
415 set myInfo [dict get $myDict $key]
416 set value [dict get $myInfo -name]
417 if {[string match $pattern $value]} {
418 lappend result $value
422 foreach key [dict keys $myDict] {
423 set myInfo [dict get $myDict $key]
424 lappend result [dict get $myInfo -name]
430 proc widgetadaptors {args} {
431 set numArgs [llength $args]
433 error "wrong # args should be: info widgetadaptors ?<pattern>?"
437 set pattern [lindex $args 0]
439 set myDict [set ::itcl::internal::dicts::classes]
440 if {![dict exists $myDict widgetadaptor]} {
443 set myDict [dict get $myDict widgetadaptor]
445 if {$pattern ne ""} {
446 foreach key [dict keys $myDict] {
447 set myInfo [dict get $myDict $key]
448 set value [dict get $myInfo -name]
449 if {[string match $pattern $value]} {
450 lappend result $value
454 foreach key [dict keys $myDict] {
455 set myInfo [dict get $myDict $key]
456 lappend result [dict get $myInfo -name]
462 } ; # end ::itcl::builtin::Info