|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc ::tk_setPalette {args} { |
|
if {[winfo depth .] == 1} { |
|
|
|
return |
|
} |
|
|
|
|
|
|
|
|
|
if {[llength $args] == 1} { |
|
set new(background) [lindex $args 0] |
|
} else { |
|
array set new $args |
|
} |
|
if {![info exists new(background)]} { |
|
return -code error -errorcode {TK SET_PALETTE BACKGROUND} \ |
|
"must specify a background color" |
|
} |
|
set bg [winfo rgb . $new(background)] |
|
if {![info exists new(foreground)]} { |
|
|
|
|
|
|
|
foreach {r g b} $bg {break} |
|
if {$r+1.5*$g+0.5*$b > 100000} { |
|
set new(foreground) black |
|
} else { |
|
set new(foreground) white |
|
} |
|
} |
|
lassign [winfo rgb . $new(foreground)] fg_r fg_g fg_b |
|
lassign $bg bg_r bg_g bg_b |
|
set darkerBg [format #%02x%02x%02x [expr {(9*$bg_r)/2560}] \ |
|
[expr {(9*$bg_g)/2560}] [expr {(9*$bg_b)/2560}]] |
|
|
|
foreach i {activeForeground insertBackground selectForeground \ |
|
highlightColor} { |
|
if {![info exists new($i)]} { |
|
set new($i) $new(foreground) |
|
} |
|
} |
|
if {![info exists new(disabledForeground)]} { |
|
set new(disabledForeground) [format #%02x%02x%02x \ |
|
[expr {(3*$bg_r + $fg_r)/1024}] \ |
|
[expr {(3*$bg_g + $fg_g)/1024}] \ |
|
[expr {(3*$bg_b + $fg_b)/1024}]] |
|
} |
|
if {![info exists new(highlightBackground)]} { |
|
set new(highlightBackground) $new(background) |
|
} |
|
if {![info exists new(activeBackground)]} { |
|
|
|
|
|
|
|
|
|
|
|
foreach i {0 1 2} color $bg { |
|
set light($i) [expr {$color/256}] |
|
set inc1 [expr {($light($i)*15)/100}] |
|
set inc2 [expr {(255-$light($i))/3}] |
|
if {$inc1 > $inc2} { |
|
incr light($i) $inc1 |
|
} else { |
|
incr light($i) $inc2 |
|
} |
|
if {$light($i) > 255} { |
|
set light($i) 255 |
|
} |
|
} |
|
set new(activeBackground) [format #%02x%02x%02x $light(0) \ |
|
$light(1) $light(2)] |
|
} |
|
if {![info exists new(selectBackground)]} { |
|
set new(selectBackground) $darkerBg |
|
} |
|
if {![info exists new(troughColor)]} { |
|
set new(troughColor) $darkerBg |
|
} |
|
|
|
|
|
|
|
toplevel .___tk_set_palette |
|
wm withdraw .___tk_set_palette |
|
foreach q { |
|
button canvas checkbutton entry frame label labelframe |
|
listbox menubutton menu message radiobutton scale scrollbar |
|
spinbox text |
|
} { |
|
$q .___tk_set_palette.$q |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
eval [tk::RecolorTree . new] |
|
|
|
destroy .___tk_set_palette |
|
|
|
|
|
|
|
|
|
foreach option [array names new] { |
|
option add *$option $new($option) widgetDefault |
|
} |
|
|
|
|
|
|
|
|
|
array set ::tk::Palette [array get new] |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc ::tk::RecolorTree {w colors} { |
|
upvar $colors c |
|
set result {} |
|
set prototype .___tk_set_palette.[string tolower [winfo class $w]] |
|
if {![winfo exists $prototype]} { |
|
unset prototype |
|
} |
|
foreach dbOption [array names c] { |
|
set option -[string tolower $dbOption] |
|
set class [string replace $dbOption 0 0 [string toupper \ |
|
[string index $dbOption 0]]] |
|
if {![catch {$w configure $option} value]} { |
|
|
|
|
|
|
|
set defaultcolor [option get $w $dbOption $class] |
|
if {$defaultcolor eq "" || \ |
|
([info exists prototype] && \ |
|
[$prototype cget $option] ne "$defaultcolor")} { |
|
set defaultcolor [lindex $value 3] |
|
} |
|
if {$defaultcolor ne ""} { |
|
set defaultcolor [winfo rgb . $defaultcolor] |
|
} |
|
set chosencolor [lindex $value 4] |
|
if {$chosencolor ne ""} { |
|
set chosencolor [winfo rgb . $chosencolor] |
|
} |
|
if {[string match $defaultcolor $chosencolor]} { |
|
|
|
|
|
append result ";\noption add [list \ |
|
*[winfo class $w].$dbOption $c($dbOption) 60]" |
|
$w configure $option $c($dbOption) |
|
} |
|
} |
|
} |
|
foreach child [winfo children $w] { |
|
append result ";\n[::tk::RecolorTree $child c]" |
|
} |
|
return $result |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc ::tk::Darken {color percent} { |
|
if {$percent < 0} { |
|
return #000000 |
|
} elseif {$percent > 200} { |
|
return #ffffff |
|
} elseif {$percent <= 100} { |
|
lassign [winfo rgb . $color] r g b |
|
set r [expr {($r/256)*$percent/100}] |
|
set g [expr {($g/256)*$percent/100}] |
|
set b [expr {($b/256)*$percent/100}] |
|
} elseif {$percent > 100} { |
|
lassign [winfo rgb . $color] r g b |
|
set r [expr {255 - ((65535-$r)/256)*(200-$percent)/100}] |
|
set g [expr {255 - ((65535-$g)/256)*(200-$percent)/100}] |
|
set b [expr {255 - ((65535-$b)/256)*(200-$percent)/100}] |
|
} |
|
return [format #%02x%02x%02x $r $g $b] |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc ::tk_bisque {} { |
|
tk_setPalette activeBackground #e6ceb1 activeForeground black \ |
|
background #ffe4c4 disabledForeground #b0b0b0 foreground black \ |
|
highlightBackground #ffe4c4 highlightColor black \ |
|
insertBackground black \ |
|
selectBackground #e6ceb1 selectForeground black \ |
|
troughColor #cdb79e |
|
} |
|
|