1
1
# ----------------------------------------------------------------------------
2
2
# font.tcl
3
3
# This file is part of Unifix BWidget Toolkit
4
+ # $Id: font.tcl,v 1.17 2009/09/06 21:14:46 oberdorfer Exp $
4
5
# ----------------------------------------------------------------------------
5
6
# Index of commands:
6
7
# - SelectFont::create
12
13
# - SelectFont::_update
13
14
# - SelectFont::_getfont
14
15
# - SelectFont::_init
16
+ # - SelectFont::_themechanged
15
17
# ----------------------------------------------------------------------------
16
18
17
19
namespace eval SelectFont {
@@ -20,8 +22,10 @@ namespace eval SelectFont {
20
22
Widget::declare SelectFont {
21
23
{-title String " Font selection" 0}
22
24
{-parent String " " 0}
23
- {-background TkResource " " 0 frame}
24
-
25
+ {-foreground Color " SystemWindowText" 0}
26
+ {-background Color " SystemWindow" 0}
27
+ {-selectbackground Color " SystemHighlight" 0}
28
+ {-selectforeground Color " SystemHighlightText" 0}
25
29
{-type Enum dialog 0 {dialog toolbar}}
26
30
{-font TkResource " " 0 label}
27
31
{-initialcolor String " " 0}
@@ -105,6 +109,10 @@ namespace eval SelectFont {
105
109
presetall $presetAll \
106
110
]
107
111
112
+ if {[lsearch [bindtags .] SelectFontThemeChanged] < 0} {
113
+ bindtags . [linsert [bindtags .] 1 SelectFontThemeChanged]
114
+ }
115
+
108
116
variable _widget
109
117
}
110
118
@@ -128,20 +136,31 @@ proc SelectFont::create { path args } {
128
136
set bg [Widget::getoption " $path #SelectFont" -background]
129
137
set _styles [Widget::getoption " $path #SelectFont" -styles]
130
138
if { [Widget::getoption " $path #SelectFont" -type] == " dialog" } {
139
+
131
140
Dialog::create $path -modal local -anchor e -default 0 -cancel 1 \
132
- -background $bg \
133
- -title [Widget::getoption " $path #SelectFont" -title] \
134
- -parent [Widget::getoption " $path #SelectFont" -parent]
141
+ -title [Widget::getoption " $path #SelectFont" -title] \
142
+ -parent [Widget::getoption " $path #SelectFont" -parent]
143
+
144
+ $path configure -background $bg
135
145
136
146
set frame [Dialog::getframe $path ]
137
- set topf [frame $frame .topf -relief flat -borderwidth 0 -background $bg ]
147
+
148
+ set topf [frame \
149
+ $frame .topf -relief flat -borderwidth 0 \
150
+ -background $bg ]
138
151
139
152
set labf1 [LabelFrame::create $topf .labf1 -text " Font" -name font \
140
153
-side top -anchor w -relief flat -background $bg ]
141
154
set sw [ScrolledWindow::create [LabelFrame::getframe $labf1 ].sw \
142
155
-background $bg ]
143
156
set lbf [listbox $sw .lb \
144
- -height 5 -width 25 -exportselection false -selectmode browse]
157
+ -height 5 -width 25 \
158
+ -exportselection false -selectmode browse \
159
+ -foreground $BWidget::colors(SystemWindowText) \
160
+ -background $BWidget::colors(SystemWindow) \
161
+ -selectforeground $BWidget::colors(SystemHighlightText) \
162
+ -selectbackground $BWidget::colors(SystemHighlight) ]
163
+
145
164
ScrolledWindow::setwidget $sw $lbf
146
165
LabelFrame::configure $labf1 -focus $lbf
147
166
if { [Widget::getoption " $path #SelectFont" -querysystem] } {
@@ -165,7 +184,13 @@ proc SelectFont::create { path args } {
165
184
set sw [ScrolledWindow::create [LabelFrame::getframe $labf2 ].sw \
166
185
-scrollbar vertical -background $bg ]
167
186
set lbs [listbox $sw .lb \
168
- -height 5 -width 6 -exportselection false -selectmode browse]
187
+ -height 5 -width 6 -exportselection false \
188
+ -selectmode browse \
189
+ -foreground $BWidget::colors(SystemWindowText) \
190
+ -background $BWidget::colors(SystemWindow) \
191
+ -selectforeground $BWidget::colors(SystemHighlightText) \
192
+ -selectbackground $BWidget::colors(SystemHighlight) ]
193
+
169
194
ScrolledWindow::setwidget $sw $lbs
170
195
LabelFrame::configure $labf2 -focus $lbs
171
196
eval [list $lbs insert end] $_sizes
@@ -186,12 +211,20 @@ proc SelectFont::create { path args } {
186
211
if { $name == " " } {
187
212
set name [string toupper $name 0]
188
213
}
189
- checkbutton $subf .$st -text $name \
190
- -variable SelectFont::$path \( $st \) \
191
- -background $bg \
192
- -command [list SelectFont::_update $path ]
214
+
215
+ if { [BWidget::using ttk] } {
216
+ ttk::checkbutton $subf .$st -text $name \
217
+ -variable SelectFont::$path \( $st \) \
218
+ -command [list SelectFont::_update $path ]
219
+ } else {
220
+ checkbutton $subf .$st -text $name \
221
+ -variable SelectFont::$path \( $st \) \
222
+ -background $bg \
223
+ -command [list SelectFont::_update $path ]
224
+ }
225
+
193
226
bind $subf .$st <Return> break
194
- pack $subf .$st -anchor w
227
+ pack $subf .$st -anchor w -padx 5
195
228
}
196
229
LabelFrame::configure $labf3 -focus $subf .[lindex $_styles 0]
197
230
@@ -204,11 +237,13 @@ proc SelectFont::create { path args } {
204
237
set botf [frame $frame .botf -width 100 -height 50 \
205
238
-bg white -bd 0 -relief flat \
206
239
-highlightthickness 1 -takefocus 0 \
207
- -highlightbackground black \
208
- -highlightcolor black]
240
+ -background $BWidget::colors(SystemWindow) \
241
+ -highlightbackground $BWidget::colors(SystemWindowText) \
242
+ -highlightcolor $BWidget::colors(SystemWindowText) ]
209
243
210
244
set lab [label $botf .label \
211
- -background white -foreground black \
245
+ -foreground $BWidget::colors(SystemWindowText) \
246
+ -background $BWidget::colors(SystemWindow) \
212
247
-borderwidth 0 -takefocus 0 -highlightthickness 0 \
213
248
-text [Widget::getoption " $path #SelectFont" -sampletext]]
214
249
place $lab -relx 0.5 -rely 0.5 -anchor c
@@ -217,19 +252,21 @@ proc SelectFont::create { path args } {
217
252
218
253
if { [Widget::getoption " $path #SelectFont" -initialcolor] != " " } {
219
254
set thecolor [Widget::getoption " $path #SelectFont" -initialcolor]
220
- set colf [frame $frame .colf]
221
-
222
- set frc [frame $colf .frame -width 50 -height 20 -bg $thecolor -bd 0 -relief flat\
255
+
256
+ set colf [frame $frame .colf]
257
+ set frc [frame $colf .frame -width 50 -height 20 -bg $thecolor -bd 0 -relief flat\
223
258
-highlightthickness 1 -takefocus 0 \
224
259
-highlightbackground black \
225
260
-highlightcolor black]
226
-
227
- set script " set [ list SelectFont::${path} (fontcolor)] \[ tk_chooseColor -parent $colf .button -initialcolor \[ set [ list SelectFont::${path} (fontcolor)] \]\] ;\
228
- SelectFont::_update [ list $path ] "
229
-
230
- set but [button $colf .button -command $script \
231
- -text " Color..." ]
261
+
262
+ set script " set [ list SelectFont::${path} (fontcolor)] \
263
+ \[ SelectColor::dialog $colf .coldlg -parent $colf .button \
264
+ -color \[ set [ list SelectFont::${path} (fontcolor)] \]\] ; \
265
+ SelectFont::_update [ list $path ] "
232
266
267
+ set but [Button $colf .button -command $script \
268
+ -text " Color..." ]
269
+
233
270
$lab configure -foreground $thecolor
234
271
$frc configure -bg $thecolor
235
272
@@ -265,7 +302,7 @@ proc SelectFont::create { path args } {
265
302
set fams " preset"
266
303
append fams [Widget::getoption " $path #SelectFont" -families]
267
304
}
268
- if {[Widget::theme] } {
305
+ if { [BWidget::using ttk] } {
269
306
ttk::frame $path
270
307
set lbf [ttk::combobox $path .font \
271
308
-takefocus 0 -exportselection 0 \
@@ -287,25 +324,27 @@ proc SelectFont::create { path args } {
287
324
-values $_families($fams) \
288
325
-textvariable SelectFont::$path \( family\) \
289
326
-editable 0 \
290
- -modifycmd [list SelectFont::_update $path ]]
327
+ -modifycmd [list SelectFont::_update $path ] \
328
+ -hottrack 1]
291
329
set lbs [ComboBox::create $path .size \
292
330
-highlightthickness 0 -takefocus 0 -background $bg \
293
331
-width 4 \
294
332
-values $_sizes \
295
333
-textvariable SelectFont::$path \( size\) \
296
334
-editable 0 \
297
- -modifycmd [list SelectFont::_update $path ]]
335
+ -modifycmd [list SelectFont::_update $path ] \
336
+ -hottrack 1]
298
337
}
299
338
bind $path <Destroy> [list SelectFont::_destroy $path ]
300
339
pack $lbf -side left -anchor w
301
340
pack $lbs -side left -anchor w -padx 4
302
341
foreach st $_styles {
303
- if {$::Widget::_theme } {
342
+ if { [BWidget::using ttk] } {
304
343
ttk::checkbutton $path .$st -takefocus 0 \
305
- -style BWSlim.Toolbutton \
306
344
-image [Bitmap::get $st ] \
307
345
-variable SelectFont::${path} ($st ) \
308
- -command [list SelectFont::_update $path ]
346
+ -command [list SelectFont::_update $path ] \
347
+ -style " BWSlimCB.Toolbutton"
309
348
} else {
310
349
button $path .$st \
311
350
-highlightthickness 0 -takefocus 0 -padx 0 -pady 0 \
@@ -320,6 +359,9 @@ proc SelectFont::create { path args } {
320
359
set data(lbs) $lbs
321
360
_getfont $path
322
361
362
+ bind SelectFontThemeChanged <<ThemeChanged>> \
363
+ " + [ namespace current] ::_themechanged $path "
364
+
323
365
return [Widget::create SelectFont $path ]
324
366
}
325
367
@@ -357,12 +399,14 @@ proc SelectFont::configure { path args } {
357
399
}
358
400
}
359
401
toolbar {
360
- $path configure -background $bg
361
- ComboBox::configure $path .font -background $bg
362
- ComboBox::configure $path .size -background $bg
363
- foreach st $_styles {
364
- $path .$st configure -background $bg
365
- }
402
+ if { ![BWidget::using ttk] } {
403
+ $path :cmd configure -background $bg
404
+ ComboBox::configure $path .font -background $bg
405
+ ComboBox::configure $path .size -background $bg
406
+ foreach st $_styles {
407
+ $path .$st configure -background $bg
408
+ }
409
+ }
366
410
}
367
411
}
368
412
}
@@ -545,7 +589,7 @@ proc SelectFont::_getfont { path } {
545
589
} else {
546
590
set data(family) $font(-family)
547
591
set data(size) $font(-size)
548
- if {![Widget::theme] } {
592
+ if { ![BWidget::using ttk] } {
549
593
foreach st $_styles {
550
594
$path .$st configure \
551
595
-relief [expr {$data($st) ? " sunken" :" raised" }]
@@ -564,3 +608,13 @@ proc SelectFont::_destroy { path } {
564
608
unset data
565
609
Widget::destroy " $path #SelectFont"
566
610
}
611
+
612
+ # ----------------------------------------------------------------------------
613
+ # Command SelectFont::_themechanged
614
+ # ----------------------------------------------------------------------------
615
+ proc SelectFont::_themechanged { path } {
616
+ if { ![winfo exists $path ] } { return }
617
+ BWidget::set_themedefaults
618
+ $path configure -background $BWidget::colors(SystemWindowFrame)
619
+ }
620
+
0 commit comments