|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package require Tk 8.6 |
|
|
|
namespace eval ::itcl::internal::commands { |
|
|
|
|
|
|
|
proc widgetDeleted {oldName newName op} { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
set cmdName [namespace tail $oldName] |
|
set flds [split $cmdName {.}] |
|
set cmdName .[join [lrange $flds 1 end] {.}] |
|
|
|
rename $cmdName {} |
|
} |
|
|
|
} |
|
|
|
namespace eval ::itcl::builtin { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc createhull {widget_type path args} { |
|
variable hullCount |
|
upvar this this |
|
upvar win win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
set my_this $this |
|
set tmp $my_this |
|
|
|
|
|
rename ::$my_this ${tmp}_ |
|
set options [list] |
|
foreach {option_name value} $args { |
|
switch -glob -- $option_name { |
|
-class { |
|
lappend options $option_name [namespace tail $value] |
|
} |
|
-* { |
|
lappend options $option_name $value |
|
} |
|
default { |
|
return -code error "bad option name\"$option_name\" options must start with a \"-\"" |
|
} |
|
} |
|
} |
|
set my_win [namespace tail $path] |
|
set cmd [list $widget_type $my_win] |
|
|
|
if {[llength $options] > 0} { |
|
lappend cmd {*}$options |
|
} |
|
set widget [uplevel 1 $cmd] |
|
|
|
trace add command $widget delete ::itcl::internal::commands::widgetDeleted |
|
set opts [uplevel 1 info delegated options] |
|
foreach entry $opts { |
|
foreach {optName compName} $entry break |
|
if {$compName eq "itcl_hull"} { |
|
set optInfos [uplevel 1 info delegated option $optName] |
|
set realOptName [lindex $optInfos 4] |
|
|
|
set myOptName [string range $realOptName 1 end] |
|
set my_opt_val [option get $my_win $myOptName *] |
|
if {$my_opt_val ne ""} { |
|
$my_win configure -$myOptName $my_opt_val |
|
} |
|
} |
|
} |
|
set idx 1 |
|
while {1} { |
|
set widgetName ::itcl::internal::widgets::hull${idx}$my_win |
|
|
|
if {[string length [::info command $widgetName]] == 0} { |
|
break |
|
} |
|
incr idx |
|
} |
|
|
|
set dorename 0 |
|
rename $widget $widgetName |
|
|
|
rename ${tmp}_ ::$tmp |
|
set exists [uplevel 1 ::info exists itcl_hull] |
|
if {!$exists} { |
|
|
|
::itcl::addcomponent $my_this itcl_hull |
|
} |
|
upvar itcl_hull itcl_hull |
|
::itcl::setcomponent $my_this itcl_hull $widgetName |
|
|
|
set exists [uplevel 1 ::info exists itcl_interior] |
|
if {!$exists} { |
|
|
|
::itcl::addcomponent $this itcl_interior |
|
} |
|
upvar itcl_interior itcl_interior |
|
set itcl_interior $my_win |
|
|
|
return $my_win |
|
} |
|
|
|
|
|
|
|
proc addToItclOptions {my_class my_win myOptions argsDict} { |
|
upvar win win |
|
upvar itcl_hull itcl_hull |
|
|
|
set opt_lst [list configure] |
|
foreach opt [lsort $myOptions] { |
|
|
|
set isClass [::itcl::is class $my_class] |
|
set found 0 |
|
if {$isClass} { |
|
if {[catch { |
|
set resource [namespace eval $my_class info option $opt -resource] |
|
set class [namespace eval $my_class info option $opt -class] |
|
set default_val [uplevel 2 info option $opt -default] |
|
set found 1 |
|
} msg]} { |
|
|
|
} |
|
} else { |
|
set tmp_win [uplevel #0 $my_class .___xx] |
|
|
|
set my_info [$tmp_win configure $opt] |
|
set resource [lindex $my_info 1] |
|
set class [lindex $my_info 2] |
|
set default_val [lindex $my_info 3] |
|
uplevel #0 destroy $tmp_win |
|
set found 1 |
|
} |
|
if {$found} { |
|
if {[catch { |
|
set val [uplevel #0 ::option get $win $resource $class] |
|
} msg]} { |
|
set val "" |
|
} |
|
if {[::dict exists $argsDict $opt]} { |
|
|
|
set val [::dict get $argsDict $opt] |
|
} else { |
|
if {[string length $val] == 0} { |
|
set val $default_val |
|
} |
|
} |
|
set ::itcl::internal::variables::${my_win}::itcl_options($opt) $val |
|
set ::itcl::internal::variables::${my_win}::__itcl_option_infos($opt) [list $resource $class $default_val] |
|
|
|
|
|
if {[catch {uplevel 1 $win configure $opt [list $val]} msg]} { |
|
|
|
} |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
proc setupcomponent {comp using widget_type path args} { |
|
upvar this this |
|
upvar win win |
|
upvar itcl_hull itcl_hull |
|
|
|
|
|
|
|
|
|
|
|
|
|
set my_comp_object [lindex [uplevel 1 info context] 1] |
|
if {[::info exists ::itcl::internal::component_objects($my_comp_object)]} { |
|
set my_comp_object [set ::itcl::internal::component_objects($my_comp_object)] |
|
} else { |
|
set ::itcl::internal::component_objects($path) $my_comp_object |
|
} |
|
set options [list] |
|
foreach {option_name value} $args { |
|
switch -glob -- $option_name { |
|
-* { |
|
lappend options $option_name $value |
|
} |
|
default { |
|
return -code error "bad option name\"$option_name\" options must start with a \"-\"" |
|
} |
|
} |
|
} |
|
if {[llength $args]} { |
|
set argsDict [dict create {*}$args] |
|
} else { |
|
set argsDict [dict create] |
|
} |
|
set cmd [list $widget_type $path] |
|
if {[llength $options] > 0} { |
|
lappend cmd {*}$options |
|
} |
|
|
|
|
|
|
|
set my_comp [uplevel #0 $cmd] |
|
|
|
::itcl::setcomponent $this $comp $my_comp |
|
set opts [uplevel 1 info delegated options] |
|
foreach entry $opts { |
|
foreach {optName compName} $entry break |
|
if {$compName eq $my_comp} { |
|
set optInfos [uplevel 1 info delegated option $optName] |
|
set realOptName [lindex $optInfos 4] |
|
|
|
set myOptName [string range $realOptName 1 end] |
|
set my_opt_val [option get $my_win $myOptName *] |
|
if {$my_opt_val ne ""} { |
|
$my_comp configure -$myOptName $my_opt_val |
|
} |
|
} |
|
} |
|
set my_class $widget_type |
|
set my_parent_class [uplevel 1 namespace current] |
|
if {[catch { |
|
set myOptions [namespace eval $my_class {info classoptions}] |
|
} msg]} { |
|
set myOptions [list] |
|
} |
|
foreach entry [$path configure] { |
|
foreach {opt dummy1 dummy2 dummy3} $entry break |
|
lappend myOptions $opt |
|
} |
|
|
|
addToItclOptions $widget_type $my_comp_object $myOptions $argsDict |
|
|
|
} |
|
|
|
proc itcl_initoptions {args} { |
|
puts stderr "ITCL_INITOPT!$args!" |
|
} |
|
|
|
|
|
|
|
proc initoptions {args} { |
|
upvar win win |
|
upvar itcl_hull itcl_hull |
|
upvar itcl_option_components itcl_option_components |
|
|
|
|
|
if {[llength $args]} { |
|
set argsDict [dict create {*}$args] |
|
} else { |
|
set argsDict [dict create] |
|
} |
|
set my_class [uplevel 1 namespace current] |
|
set myOptions [namespace eval $my_class {info classoptions}] |
|
if {[dict exists $::itcl::internal::dicts::classComponents $my_class]} { |
|
set class_info_dict [dict get $::itcl::internal::dicts::classComponents $my_class] |
|
|
|
foreach comp [uplevel 1 info components] { |
|
if {[dict exists $class_info_dict $comp -keptoptions]} { |
|
foreach my_opt [dict get $class_info_dict $comp -keptoptions] { |
|
if {[lsearch $myOptions $my_opt] < 0} { |
|
|
|
lappend myOptions $my_opt |
|
} |
|
} |
|
} |
|
} |
|
} else { |
|
set class_info_dict [list] |
|
} |
|
|
|
set opt_lst [list configure] |
|
set my_win $win |
|
foreach opt [lsort $myOptions] { |
|
set found 0 |
|
if {[catch { |
|
set resource [uplevel 1 info option $opt -resource] |
|
set class [uplevel 1 info option $opt -class] |
|
set default_val [uplevel 1 info option $opt -default] |
|
set found 1 |
|
} msg]} { |
|
|
|
} |
|
|
|
if {$found} { |
|
if {[catch { |
|
set val [uplevel #0 ::option get $my_win $resource $class] |
|
} msg]} { |
|
set val "" |
|
} |
|
if {[::dict exists $argsDict $opt]} { |
|
|
|
set val [::dict get $argsDict $opt] |
|
} else { |
|
if {[string length $val] == 0} { |
|
set val $default_val |
|
} |
|
} |
|
set ::itcl::internal::variables::${win}::itcl_options($opt) $val |
|
set ::itcl::internal::variables::${win}::__itcl_option_infos($opt) [list $resource $class $default_val] |
|
|
|
|
|
if {[catch {uplevel 1 $my_win configure $opt [list $val]} msg]} { |
|
puts stderr "initoptions ERR!$msg!$my_class!$my_win!configure!$opt!$val!" |
|
} |
|
} |
|
foreach comp [dict keys $class_info_dict] { |
|
|
|
if {[dict exists $class_info_dict $comp -keptoptions]} { |
|
if {[lsearch [dict get $class_info_dict $comp -keptoptions] $opt] >= 0} { |
|
if {$found == 0} { |
|
|
|
|
|
|
|
set my_info [uplevel 1 \[set $comp\] configure $opt] |
|
set resource [lindex $my_info 1] |
|
set class [lindex $my_info 2] |
|
set default_val [lindex $my_info 3] |
|
set found 2 |
|
set val [uplevel #0 ::option get $my_win $resource $class] |
|
if {[::dict exists $argsDict $opt]} { |
|
|
|
set val [::dict get $argsDict $opt] |
|
} else { |
|
if {[string length $val] == 0} { |
|
set val $default_val |
|
} |
|
} |
|
|
|
set ::itcl::internal::variables::${win}::itcl_options($opt) $val |
|
set ::itcl::internal::variables::${win}::__itcl_option_infos($opt) [list $resource $class $default_val] |
|
|
|
} |
|
if {[catch {uplevel 1 \[set $comp\] configure $opt [list $val]} msg]} { |
|
puts stderr "initoptions ERR2!$msg!$my_class!$comp!configure!$opt!$val!" |
|
} |
|
if {![uplevel 1 info exists itcl_option_components($opt)]} { |
|
set itcl_option_components($opt) [list] |
|
} |
|
if {[lsearch [set itcl_option_components($opt)] $comp] < 0} { |
|
if {![catch { |
|
set optval [uplevel 1 [list set itcl_options($opt)]] |
|
} msg3]} { |
|
uplevel 1 \[set $comp\] configure $opt $optval |
|
} |
|
lappend itcl_option_components($opt) $comp |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
|
} |
|
|
|
|
|
|
|
proc setoptions {args} { |
|
|
|
|
|
if {[llength $args]} { |
|
set argsDict [dict create {*}$args] |
|
} else { |
|
set argsDict [dict create] |
|
} |
|
set my_class [uplevel 1 namespace current] |
|
set myOptions [namespace eval $my_class {info options}] |
|
|
|
set opt_lst [list configure] |
|
foreach opt [lsort $myOptions] { |
|
set found 0 |
|
if {[catch { |
|
set resource [uplevel 1 info option $opt -resource] |
|
set class [uplevel 1 info option $opt -class] |
|
set default_val [uplevel 1 info option $opt -default] |
|
set found 1 |
|
} msg]} { |
|
|
|
} |
|
|
|
if {$found} { |
|
set val "" |
|
if {[::dict exists $argsDict $opt]} { |
|
|
|
set val [::dict get $argsDict $opt] |
|
} else { |
|
if {[string length $val] == 0} { |
|
set val $default_val |
|
} |
|
} |
|
set myObj [uplevel 1 set this] |
|
|
|
set ::itcl::internal::variables::${myObj}::itcl_options($opt) $val |
|
set ::itcl::internal::variables::${myObj}::__itcl_option_infos($opt) [list $resource $class $default_val] |
|
|
|
uplevel 1 [list set itcl_options($opt) [list $val]] |
|
|
|
|
|
|
|
} |
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc keepcomponentoption {args} { |
|
upvar win win |
|
upvar itcl_hull itcl_hull |
|
|
|
set usage "wrong # args, should be: keepcomponentoption componentName optionName ?optionName ...?" |
|
|
|
|
|
if {[llength $args] < 2} { |
|
puts stderr $usage |
|
return -code error |
|
} |
|
set my_hull [uplevel 1 set itcl_hull] |
|
set my_class [uplevel 1 namespace current] |
|
set comp [lindex $args 0] |
|
set args [lrange $args 1 end] |
|
set class_info_dict [dict get $::itcl::internal::dicts::classComponents $my_class] |
|
if {![dict exists $class_info_dict $comp]} { |
|
puts stderr "keepcomponentoption cannot find component \"$comp\"" |
|
return -code error |
|
} |
|
set class_comp_dict [dict get $class_info_dict $comp] |
|
if {![dict exists $class_comp_dict -keptoptions]} { |
|
dict set class_comp_dict -keptoptions [list] |
|
} |
|
foreach opt $args { |
|
|
|
if {[string range $opt 0 0] ne "-"} { |
|
puts stderr "keepcomponentoption: option must begin with a \"-\"!" |
|
return -code error |
|
} |
|
if {[lsearch [dict get $class_comp_dict -keptoptions] $opt] < 0} { |
|
dict lappend class_comp_dict -keptoptions $opt |
|
} |
|
} |
|
if {![info exists ::itcl::internal::component_objects([lindex [uplevel 1 info context] 1])]} { |
|
set comp_object $::itcl::internal::component_objects([lindex [uplevel 1 info context] 1]) |
|
} else { |
|
set comp_object "unknown_comp_obj_$comp!" |
|
} |
|
dict set class_info_dict $comp $class_comp_dict |
|
dict set ::itcl::internal::dicts::classComponents $my_class $class_info_dict |
|
puts stderr "CLDI!$class_comp_dict!" |
|
addToItclOptions $my_class $comp_object $args [list] |
|
} |
|
|
|
proc ignorecomponentoption {args} { |
|
puts stderr "IGNORE_COMPONENT_OPTION!$args!" |
|
} |
|
|
|
proc renamecomponentoption {args} { |
|
puts stderr "rename_COMPONENT_OPTION!$args!" |
|
} |
|
|
|
proc addoptioncomponent {args} { |
|
puts stderr "ADD_OPTION_COMPONENT!$args!" |
|
} |
|
|
|
proc ignoreoptioncomponent {args} { |
|
puts stderr "IGNORE_OPTION_COMPONENT!$args!" |
|
} |
|
|
|
proc renameoptioncomponent {args} { |
|
puts stderr "RENAME_OPTION_COMPONENT!$args!" |
|
} |
|
|
|
proc getEclassOptions {args} { |
|
upvar win win |
|
|
|
|
|
|
|
set result [list] |
|
foreach opt [array names ::itcl::internal::variables::${win}::itcl_options] { |
|
if {[catch { |
|
foreach {res cls def} [set ::itcl::internal::variables::${win}::__itcl_option_infos($opt)] break |
|
lappend result [list $opt $res $cls $def [set ::itcl::internal::variables::${win}::itcl_options($opt)]] |
|
} msg]} { |
|
} |
|
} |
|
return $result |
|
} |
|
|
|
proc eclassConfigure {args} { |
|
upvar win win |
|
|
|
|
|
if {[llength $args] > 1} { |
|
foreach {opt val} $args break |
|
if {[::info exists ::itcl::internal::variables::${win}::itcl_options($opt)]} { |
|
set ::itcl::internal::variables::${win}::itcl_options($opt) $val |
|
return |
|
} |
|
} else { |
|
foreach {opt} $args break |
|
if {[::info exists ::itcl::internal::variables::${win}::itcl_options($opt)]} { |
|
|
|
foreach {res cls def} [set ::itcl::internal::variables::${win}::__itcl_option_infos($opt)] break |
|
return [list $opt $res $cls $def [set ::itcl::internal::variables::${win}::itcl_options($opt)]] |
|
} |
|
} |
|
return -code error |
|
} |
|
|
|
} |
|
|