2 # $Id: ttk.tcl,v 1.7 2007/06/21 00:29:16 hobbs Exp $
4 # Ttk widget set initialization script.
7 ### Source library scripts.
10 namespace eval ::ttk {
12 if {![info exists library
]} {
13 set library
[file dirname
[info script
]]
17 source [file join $::ttk::library fonts.tcl
]
18 source [file join $::ttk::library cursors.tcl
]
19 source [file join $::ttk::library utils.tcl
]
21 ## ttk::deprecated $old $new --
22 # Define $old command as a deprecated alias for $new command
23 # $old and $new must be fully namespace-qualified.
25 proc ttk
::deprecated {old new
} {
26 interp alias
{} $old {} ttk
::do'deprecate
$old $new
29 # Implementation procedure for deprecated commands --
30 # issue a warning (once), then re-alias old to new.
32 proc ttk
::do'deprecate
{old new args
} {
33 deprecated'warning
$old $new
34 interp alias
{} $old {} $new
35 uplevel 1 [linsert $args 0 $new]
38 ## deprecated'warning --
39 # Gripe about use of deprecated commands.
41 proc ttk
::deprecated'warning
{old new
} {
42 puts stderr
"$old deprecated -- use $new instead"
45 ### Backward-compatibility.
48 package ifneeded tile
0.8.0 { package require Tk
; package provide tile
0.8.0 }
50 # ttk::panedwindow used to be named ttk::paned. Keep the alias for now.
52 ::ttk::deprecated ::ttk::paned ::ttk::panedwindow
54 ### ::ttk::ThemeChanged --
55 # Called from [::ttk::style theme use].
56 # Sends a <<ThemeChanged>> virtual event to all widgets.
58 proc ::ttk::ThemeChanged {} {
60 while {[llength $Q]} {
63 event generate
$w <<ThemeChanged
>>
64 foreach child
[winfo children
$w] {
75 proc ::ttk::themes {{ptn
*}} {
78 foreach pkg
[lsearch -inline -all -glob [package names
] ttk
::theme::$ptn] {
79 lappend themes
[namespace tail
$pkg]
85 ## ttk::setTheme $theme --
86 # Set the current theme to $theme, loading it if necessary.
88 proc ::ttk::setTheme {theme
} {
89 variable currentTheme
;# @@@ Temp -- [::ttk::style theme use] doesn't work
90 if {$theme ni
[::ttk::style theme names
]} {
91 package require ttk
::theme::$theme
93 ::ttk::style theme use
$theme
94 set currentTheme
$theme
97 ### Load widget bindings.
99 source [file join $::ttk::library button.tcl
]
100 source [file join $::ttk::library menubutton.tcl
]
101 source [file join $::ttk::library scrollbar.tcl
]
102 source [file join $::ttk::library scale.tcl
]
103 source [file join $::ttk::library progress.tcl
]
104 source [file join $::ttk::library notebook.tcl
]
105 source [file join $::ttk::library panedwindow.tcl
]
106 source [file join $::ttk::library entry.tcl
]
107 source [file join $::ttk::library combobox.tcl
] ;# dependency: entry.tcl
108 source [file join $::ttk::library treeview.tcl
]
109 source [file join $::ttk::library sizegrip.tcl
]
111 ## Label and Labelframe bindings:
112 # (not enough to justify their own file...)
114 bind TLabelframe
<<Invoke
>> { tk::TabToWindow [tk_focusNext %W
] }
115 bind TLabel
<<Invoke
>> { tk::TabToWindow [tk_focusNext %W
] }
117 ### Load settings for built-in themes:
119 proc ttk
::LoadThemes {} {
122 # "default" always present:
123 uplevel #0 [list source [file join $library defaults.tcl]]
125 set builtinThemes
[style theme names
]
126 foreach {theme script
} {
127 classic classicTheme.tcl
130 winnative winTheme.tcl
134 if {[lsearch -exact $builtinThemes $theme] >= 0} {
135 uplevel #0 [list source [file join $library $script]]
140 ttk
::LoadThemes; rename ::ttk::LoadThemes {}
142 ### Select platform-specific default theme:
145 # + On OSX, aqua theme is the default
146 # + On Windows, xpnative takes precedence over winnative if available.
147 # + On X11, users can use the X resource database to
148 # specify a preferred theme (*TkTheme: themeName);
149 # otherwise "default" is used.
152 proc ttk
::DefaultTheme {} {
153 set preferred
[list aqua xpnative winnative
]
155 set userTheme
[option get . tkTheme TkTheme
]
156 if {$userTheme != {} && ![catch {
157 uplevel #0 [list package require ttk::theme::$userTheme]
162 foreach theme
$preferred {
163 if {[package provide ttk
::theme::$theme] != ""} {
170 ttk
::setTheme [ttk
::DefaultTheme] ; rename ttk
::DefaultTheme {}