1
1
# ----------------------------------------------------------------------------
2
2
# button.tcl
3
3
# This file is part of Unifix BWidget Toolkit
4
- # $Id: button.tcl,v 1.14 2009/09/11 16:04:14 oberdorfer Exp $
4
+ # $Id: button.tcl,v 1.15 2009/11/01 20:20:50 oberdorfer Exp $
5
5
# ----------------------------------------------------------------------------
6
6
# Index of commands:
7
7
# Public commands
8
8
# - Button::create
9
9
# - Button::configure
10
10
# - Button::cget
11
11
# - Button::invoke
12
+ # - Button::getSlimButtonStyle
12
13
# Private commands (event bindings)
13
14
# - Button::_destroy
14
15
# - Button::_enter
15
16
# - Button::_leave
16
17
# - Button::_press
17
18
# - Button::_release
18
19
# - Button::_repeat
20
+ # - Button::_styleconfigure
19
21
# ----------------------------------------------------------------------------
20
22
21
23
namespace eval Button {
@@ -27,7 +29,7 @@ namespace eval Button {
27
29
lappend remove -repeatdelay -repeatinterval
28
30
}
29
31
30
- # if { [BWidget::using ttk] } { lappend remove -borderwidth }
32
+ if { [BWidget::using ttk] } { lappend remove -borderwidth }
31
33
32
34
Widget::tkinclude Button button :cmd remove $remove
33
35
@@ -73,47 +75,13 @@ namespace eval Button {
73
75
}
74
76
75
77
76
- proc Button::createButtonStyles {} {
77
- variable _styles_created
78
-
79
- if { [info exists _styles_created] && $_styles_created != 0 } {
80
- return
81
- }
82
- if { ![BWidget::using ttk] } { return }
83
-
84
- # create a new element for each available theme...
85
- foreach themeName [ttk::style theme names] {
86
-
87
- # temporarily sets the current theme to themeName,
88
- # evaluate script, then restore the previous theme.
89
-
90
- ttk::style theme settings $themeName {
91
-
92
- # emulate tk behavior, referenced later on such like:
93
- # -style "${relief}BW.TButton"
94
-
95
- ::ttk::style configure raisedBW.TButton -relief raised
96
- ::ttk::style configure sunkenBW.TButton -relief sunken
97
- ::ttk::style configure flatBW.TButton -relief flat
98
- ::ttk::style configure solidBW.TButton -relief solid
99
- ::ttk::style configure grooveBW.TButton -relief groove
100
- ::ttk::style configure linkBW.TButton -relief flat -bd 2
101
- }
102
- }
103
-
104
- set _styles_created 1
105
- }
106
-
107
-
108
-
109
78
# ----------------------------------------------------------------------------
110
79
# Command Button::create
111
80
# ----------------------------------------------------------------------------
112
81
proc Button::create { path args } {
113
82
variable _ttkunsupported_opt
114
83
115
84
if { [BWidget::using ttk] } {
116
- createButtonStyles
117
85
118
86
# remove unsupported tk options
119
87
# (hope that's all we need to take care about)
@@ -129,18 +97,16 @@ proc Button::create { path args } {
129
97
array set maps [list Button {} :cmd {}]
130
98
array set maps [Widget::parseArgs Button $args ]
131
99
132
- if {[BWidget::using ttk]} {
133
- eval [concat [list ttk::button $path ] $maps(:cmd) ]
134
- } else {
135
- eval [concat [list button $path ] $maps(:cmd) ]
136
- }
100
+ if { [BWidget::using ttk] } {
101
+ eval [concat [list ttk::button $path ] $maps(:cmd) ]
102
+ } else { eval [concat [list button $path ] $maps(:cmd) ] }
137
103
138
104
Widget::initFromODB Button $path $maps(Button)
139
105
140
- # Do some extra configuration on the button
106
+ # do some extra configuration on the button
141
107
set relief [Widget::getMegawidgetOption $path -relief]
142
108
143
- if { [string equal $relief " link" ] } {
109
+ if { ![BWidget::using ttk] && [string equal $relief " link" ] } {
144
110
set relief " flat"
145
111
}
146
112
set var [Widget::getMegawidgetOption $path -textvariable]
@@ -162,13 +128,17 @@ proc Button::create { path args } {
162
128
Widget::configure $path [list -underline $under ]
163
129
}
164
130
165
-
166
131
if { [BWidget::using ttk] } {
167
132
$path configure -text $text -underline $under \
168
133
-textvariable $var -state $st
169
134
170
- if { [$path cget -style] != " BWSlim.Toolbutton" } {
171
- $path configure -style " ${relief} BW.TButton"
135
+ # distinguish between a standard button (raised) which sould appear
136
+ # as declared in the celated style and button with user defined arg's
137
+ # where the style 'll be overwritten to emulate existing behavior
138
+
139
+ if { $relief != " raised" &&
140
+ [$path cget -style] != " BWSlim.Toolbutton" } {
141
+ $path configure -style " BW${relief} .Toolbutton"
172
142
}
173
143
} else {
174
144
$path configure -relief $relief -text $text -underline $under \
@@ -221,28 +191,27 @@ proc Button::configure { path args } {
221
191
if { $cr || $cs } {
222
192
set relief [Widget::cget $path -relief]
223
193
set state [Widget::cget $path -state]
224
- if { [string equal $relief " link" ] } {
194
+
195
+ if { ![BWidget::using ttk] && [string equal $relief " link" ] } {
225
196
if { [string equal $state " active" ] } {
226
- set relief " raised"
227
- } else {
228
- set relief " flat"
229
- }
197
+ set relief " raised"
198
+ } else { set relief " flat" }
230
199
}
231
200
232
201
if { [BWidget::using ttk] } {
233
202
$path :cmd configure -state $state
234
203
if { [string compare [$path :cmd cget -style] " BWSlim.Toolbutton" ] != 0 } {
235
- $path :cmd configure -style " ${relief} BW.TButton "
204
+ $path :cmd configure -style " BW ${relief} .Toolbutton "
236
205
}
237
206
} else {
238
207
$path :cmd configure -relief $relief -state $state
239
208
}
240
209
}
241
210
242
211
if { $cv || $cn || $ct || $cu } {
243
- set var [Widget::cget $path -textvariable]
244
- set text [Widget::cget $path -text]
245
- set under [Widget::cget $path -underline]
212
+ set var [Widget::cget $path -textvariable]
213
+ set text [Widget::cget $path -text]
214
+ set under [Widget::cget $path -underline]
246
215
if { ![string length $var ] } {
247
216
set desc [BWidget::getname [Widget::cget $path -name]]
248
217
if { [llength $desc ] } {
@@ -280,6 +249,13 @@ proc Button::cget { path option } {
280
249
}
281
250
282
251
252
+ proc Button::getSlimButtonStyle {} {
253
+ if { [BWidget::using ttk] } {
254
+ return " BWSlim.Toolbutton"
255
+ }
256
+ return " "
257
+ }
258
+
283
259
# ----------------------------------------------------------------------------
284
260
# Command Button::invoke
285
261
# ----------------------------------------------------------------------------
@@ -295,7 +271,7 @@ proc Button::invoke { path } {
295
271
}
296
272
after 100
297
273
set relief [Widget::getMegawidgetOption $path -relief]
298
- if { [string equal $relief " link" ] } {
274
+ if { ![BWidget::using ttk] && [string equal $relief " link" ] } {
299
275
set relief flat
300
276
}
301
277
@@ -326,11 +302,8 @@ proc Button::_enter { path } {
326
302
if { ![string equal [$path :cmd cget -state] " disabled" ] } {
327
303
$path :cmd configure -state active
328
304
if { $_pressed == $path } {
329
-
330
305
_styleconfigure $path sunken
331
-
332
306
} elseif { [string equal [Widget::cget $path -relief] " link" ] } {
333
-
334
307
_styleconfigure $path raised
335
308
}
336
309
}
@@ -342,7 +315,7 @@ proc Button::_styleconfigure { path relief_or_style } {
342
315
if { [BWidget::using ttk] } {
343
316
# do not override the toolbutton style:
344
317
if { [$path :cmd cget -style] != " BWSlim.Toolbutton" } {
345
- $path :cmd configure -style " ${relief_or_style} BW.TButton "
318
+ $path :cmd configure -style " BW ${relief_or_style} .Toolbutton "
346
319
}
347
320
} else {
348
321
$path :cmd configure -relief $relief_or_style
@@ -382,7 +355,7 @@ proc Button::_press { path } {
382
355
if { ![string equal [$path :cmd cget -state] " disabled" ] } {
383
356
set _pressed $path
384
357
385
- _styleconfigure $path sunken
358
+ if { ![BWidget::using ttk] } { _styleconfigure $path sunken }
386
359
387
360
set cmd [Widget::getMegawidgetOption $path -armcommand]
388
361
if { $cmd != " " } {
@@ -410,11 +383,12 @@ proc Button::_release { path } {
410
383
set _pressed " "
411
384
set relief [Widget::getMegawidgetOption $path -relief]
412
385
after cancel " Button::_repeat $path "
386
+
413
387
if { [string equal $relief " link" ] } {
414
388
set relief raised
415
389
}
416
390
417
- _styleconfigure $path $relief
391
+ if { ![BWidget::using ttk] } { _styleconfigure $path $relief }
418
392
419
393
set cmd [Widget::getMegawidgetOption $path -disarmcommand]
420
394
if { $cmd != " " } {
0 commit comments