author | Claus Gittinger <cg@exept.de> |
Thu, 28 May 2009 08:37:26 +0200 | |
changeset 3707 | 380dcd111024 |
parent 3698 | bd2778e6a26b |
child 3708 | de8fd46e5363 |
permissions | -rw-r--r-- |
422 | 1 |
" |
2 |
COPYRIGHT (c) 1995 by eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
2935
e3fa9d1a7a64
Moved ColorMenu and FontMenu from libtool2
Stefan Vogel <sv@exept.de>
parents:
2704
diff
changeset
|
12 |
"{ Package: 'stx:libwidg2' }" |
1803 | 13 |
|
412 | 14 |
MenuPanel subclass:#ColorMenu |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
15 |
instanceVariableNames:'enabledChannel labelsAreColored color colorName |
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
16 |
allowSymbolicColors' |
3322 | 17 |
classVariableNames:'ColorMenuSpec RecentlyUsedColors' |
412 | 18 |
poolDictionaries:'' |
19 |
category:'Interface-UIPainter' |
|
20 |
! |
|
21 |
||
22 |
!ColorMenu class methodsFor:'documentation'! |
|
23 |
||
422 | 24 |
copyright |
25 |
" |
|
26 |
COPYRIGHT (c) 1995 by eXept Software AG |
|
27 |
All Rights Reserved |
|
28 |
||
29 |
This software is furnished under a license and may be used |
|
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
||
37 |
||
38 |
! |
|
39 |
||
412 | 40 |
documentation |
41 |
" |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
42 |
A simple ColorMenu used by the UIPainter |
412 | 43 |
|
44 |
[see also:] |
|
45 |
UIPainter |
|
46 |
ColorMenuSpec |
|
422 | 47 |
|
48 |
[author:] |
|
49 |
Claus Atzkern |
|
412 | 50 |
" |
51 |
! |
|
52 |
||
53 |
examples |
|
54 |
" |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
55 |
very simple example |
412 | 56 |
[exBegin] |
57 |
|tool top channel| |
|
58 |
||
59 |
top := StandardSystemView new. |
|
60 |
top extent:250@30. |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
61 |
|
412 | 62 |
channel := (Color red) asValue. |
63 |
tool := self origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
64 |
tool model:channel. |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
65 |
|
412 | 66 |
top open. |
67 |
[exEnd] |
|
68 |
" |
|
69 |
! ! |
|
70 |
||
3322 | 71 |
!ColorMenu class methodsFor:'instance creation'! |
72 |
||
73 |
colorMenu:labelAreColored value:aValue |
|
74 |
"returns a color menu |
|
75 |
" |
|
76 |
|menu| |
|
77 |
||
78 |
menu := Menu new. |
|
79 |
||
80 |
self colorMenu itemsDo:[:el| |
|
81 |
menu addItem:(self resolveMenuItem:el value:aValue labelAreColored:labelAreColored). |
|
82 |
]. |
|
83 |
^ menu |
|
84 |
||
85 |
" |
|
86 |
(ColorMenu colorMenu:true value:nil) startUp |
|
87 |
(ColorMenu colorMenu:false value:#aSelector:) startUp |
|
88 |
" |
|
89 |
! ! |
|
90 |
||
91 |
!ColorMenu class methodsFor:'adding & removing user defined items'! |
|
3280 | 92 |
|
3292 | 93 |
addUserDefinedColors:aColors labels:labelsOrNil title:aTitle |
3322 | 94 |
"add user colors to ALL colormenus" |
95 |
||
96 |
"cg: I think this is a bad hack, as it is too global." |
|
97 |
||
3292 | 98 |
|size submenu item label fgColor bgColor labels defLabel| |
99 |
||
100 |
submenu := self userDefinedSubmenu. |
|
101 |
size := aColors size. |
|
102 |
||
103 |
size == 0 ifTrue:[ "/ separator |
|
104 |
submenu addItem:(MenuItem label:'-'). |
|
105 |
^ self |
|
106 |
]. |
|
107 |
||
108 |
labels := labelsOrNil ? #(). |
|
109 |
bgColor := aColors first. |
|
110 |
defLabel := ' '. |
|
111 |
||
112 |
bgColor brightness < 0.5 ifTrue:[ fgColor := Color white ] |
|
113 |
ifFalse:[ fgColor := Color black ]. |
|
114 |
||
115 |
aTitle isEmptyOrNil ifTrue:[ label := labels at:1 ifAbsent:defLabel ] |
|
116 |
ifFalse:[ label := aTitle ]. |
|
3280 | 117 |
|
3294 | 118 |
label := Text string:(' ', label, ' ') foregroundColor:fgColor backgroundColor:bgColor. |
3292 | 119 |
item := MenuItem labeled:label. |
120 |
submenu addItem:item. |
|
121 |
||
122 |
size == 1 ifTrue:[ |
|
123 |
item argument:bgColor. |
|
124 |
] ifFalse:[ |
|
125 |
item submenu:(submenu := Menu new). |
|
3280 | 126 |
|
3292 | 127 |
aColors keysAndValuesDo:[:idx :aBgColor| |
128 |
aBgColor brightness < 0.5 ifTrue:[ fgColor := Color white ] |
|
129 |
ifFalse:[ fgColor := Color black ]. |
|
130 |
||
131 |
label := labels at:idx ifAbsent:defLabel. |
|
3294 | 132 |
label := Text string:(' ', label, ' ') foregroundColor:fgColor backgroundColor:aBgColor. |
3292 | 133 |
item := MenuItem labeled:label. |
3293 | 134 |
item argument:aBgColor. |
3292 | 135 |
|
136 |
submenu addItem:item. |
|
137 |
]. |
|
138 |
]. |
|
3280 | 139 |
|
140 |
" |
|
3292 | 141 |
ColorMenu removeAllUserDefinedColors. |
3280 | 142 |
|
3292 | 143 |
#( |
144 |
#( Black 16r000000 ) |
|
145 |
#( Red 16rff0000 ) |
|
146 |
nil |
|
147 |
#( Rust 16rff6600 16rff8533 16rffa366 16rffc299 16rffe0cc ) |
|
148 |
#( Tangerine 16rff9933 16rffad5c 16rffc285 16rffd6ad 16rffebd6 ) |
|
149 |
#( Sunflower 16rffcc00 16rfed633 16rfee066 16rffeb99 16rfff5cc ) |
|
150 |
#( Mango 16rffcc99 16rffd6ad 16rffe0c2 16rffebd6 16rfff5eb ) |
|
151 |
#( Buttercup 16rffff66 16rffff85 16rffffa3 16rffffc2 16rffffe0 ) |
|
152 |
#( Lemon 16rffffcc 16rffffd6 16rffffe0 16rffffeb 16rfffff5 ) |
|
3280 | 153 |
|
3292 | 154 |
) do:[:aDef| |colors title labels percentage| |
155 |
aDef isEmptyOrNil ifTrue:[ |
|
156 |
colors := labels := title := nil. |
|
157 |
] ifFalse:[ |
|
158 |
title := aDef first. |
|
159 |
colors := OrderedCollection new. |
|
160 |
labels := OrderedCollection new. |
|
161 |
percentage := 100. |
|
162 |
||
163 |
aDef from:2 do:[:rgb| |
|
164 |
colors add:(Color rgbValue:rgb). |
|
165 |
labels add:('%1 %2 %%' bindWith:title with:percentage). |
|
166 |
percentage := percentage - 20. |
|
167 |
]. |
|
168 |
]. |
|
169 |
ColorMenu addUserDefinedColors:colors labels:labels title:title. |
|
3280 | 170 |
]. |
3292 | 171 |
" |
3280 | 172 |
! |
173 |
||
3283 | 174 |
removeAllUserDefinedColors |
3322 | 175 |
"flush user defined colors" |
176 |
||
3292 | 177 |
ColorMenuSpec := nil. |
3322 | 178 |
! |
179 |
||
180 |
userDefinedSubmenu |
|
181 |
"answer the menu entry under which the userdefined color entries are placed" |
|
182 |
||
183 |
|menu submenu item icon| |
|
184 |
||
185 |
menu := self colorMenu. |
|
186 |
item := menu detectItem:[:el| (el nameKey == #userDefined and:[el submenu notNil]) ] |
|
187 |
ifNone:nil. |
|
188 |
||
189 |
item isNil ifTrue:[ |
|
3323 | 190 |
icon := ToolbarIconLibrary colorHistory16x16Icon. |
3322 | 191 |
item := MenuItem labeled:icon. |
192 |
item nameKey:#userDefined. |
|
193 |
item activeHelpKey:#userDefinedColors. |
|
194 |
menu addItem:item beforeIndex:1. |
|
195 |
]. |
|
196 |
||
197 |
(submenu := item submenu) isNil ifTrue:[ |
|
198 |
submenu := Menu new. |
|
199 |
item submenu:submenu. |
|
200 |
]. |
|
201 |
^ submenu |
|
3280 | 202 |
! ! |
203 |
||
3341 | 204 |
!ColorMenu class methodsFor:'menu specs'! |
412 | 205 |
|
3322 | 206 |
colorMenuSpec |
207 |
"color definitions used to build a color menu |
|
3292 | 208 |
" |
3322 | 209 |
" |
210 |
ColorMenuSpec := nil. |
|
211 |
" |
|
212 |
^ #( |
|
213 |
#( gray |
|
214 |
gray: |
|
215 |
#( white |
|
216 |
veryLightGray |
|
217 |
lightGray |
|
218 |
gray |
|
219 |
darkGray |
|
220 |
veryDarkGray |
|
221 |
black |
|
222 |
) |
|
223 |
) |
|
224 |
"/ nil "/ separator |
|
225 |
#( red |
|
226 |
red: |
|
3707 | 227 |
#( veryLight lightened 100 87 67 50 33 25) |
3322 | 228 |
) |
229 |
#( green |
|
230 |
green: |
|
3707 | 231 |
#( veryLight lightened 100 87 67 50 33 25) |
3322 | 232 |
) |
233 |
#( blue |
|
234 |
blue: |
|
3707 | 235 |
#( veryLight lightened 100 87 67 50 33 25) |
3322 | 236 |
) |
237 |
"/ nil "/ separator |
|
238 |
#( cyan |
|
239 |
cyan: |
|
3707 | 240 |
#( veryLight lightened 100 87 67 50 33 25) |
3322 | 241 |
) |
242 |
#( magenta |
|
243 |
magenta: |
|
3707 | 244 |
#( veryLight lightened 100 87 67 50 33 25) |
3322 | 245 |
) |
246 |
#( yellow |
|
247 |
yellow: |
|
3707 | 248 |
#( veryLight lightened 100 87 67 50 33 25) |
3322 | 249 |
) |
3292 | 250 |
|
3322 | 251 |
) |
3292 | 252 |
! ! |
253 |
||
254 |
!ColorMenu class methodsFor:'private'! |
|
255 |
||
3280 | 256 |
colorMenu |
3404 | 257 |
|menu menuItem subItem baseColor color label getColSel submenu colorId| |
258 |
||
3707 | 259 |
" |
260 |
ColorMenuSpec := nil |
|
261 |
" |
|
3292 | 262 |
|
3280 | 263 |
ColorMenuSpec notNil ifTrue:[ ^ ColorMenuSpec ]. |
264 |
||
3404 | 265 |
menu := Menu new. |
3280 | 266 |
self colorMenuSpec do:[:aSlice| |
3404 | 267 |
menu addItem:(menuItem := MenuItem new). |
3280 | 268 |
|
269 |
aSlice notNil ifTrue:[ |
|
270 |
colorId := aSlice at:1. |
|
271 |
getColSel := aSlice at:2. |
|
272 |
baseColor := Color perform:colorId. |
|
273 |
||
3323 | 274 |
menuItem label:(Text string:' ' emphasis:(#backgroundColor->baseColor)). |
3280 | 275 |
menuItem submenu:(submenu := Menu new). |
3292 | 276 |
menuItem isButton:true. |
3404 | 277 |
menuItem activeHelpKey:('shadesOf',colorId asUppercaseFirst) asSymbol. |
3280 | 278 |
|
279 |
aSlice last do:[:el| |
|
280 |
color := label := nil. |
|
281 |
||
282 |
el isSymbol ifTrue:[ |
|
3322 | 283 |
el == #veryLight ifTrue:[ |
284 |
color := baseColor lightened lightened |
|
285 |
] ifFalse:[ el == #lightened ifTrue:[ |
|
286 |
color := baseColor perform:el |
|
287 |
] ifFalse:[ |
|
288 |
color := Color perform:el |
|
289 |
]]. |
|
3280 | 290 |
colorId == #gray ifTrue:[ label := el ]. |
291 |
] ifFalse:[ |
|
292 |
el isNumber ifTrue:[ |
|
293 |
color := Color perform:getColSel with:el. |
|
294 |
]. |
|
295 |
]. |
|
296 |
color notNil ifTrue:[ |
|
297 |
label isNil ifTrue:[ |
|
298 |
label := getColSel, ' ', el printString. |
|
299 |
]. |
|
3322 | 300 |
subItem := MenuItem label:' ',label,' '. |
3280 | 301 |
subItem argument:color. |
302 |
submenu addItem:subItem. |
|
303 |
]. |
|
304 |
] |
|
305 |
]. |
|
306 |
]. |
|
3404 | 307 |
ColorMenuSpec := menu. |
308 |
^ menu |
|
3280 | 309 |
! |
310 |
||
3292 | 311 |
resolveMenuItem:aMenuItem value:aValue labelAreColored:labelAreColored |
312 |
|menuItem label color fgColor submenu| |
|
313 |
||
314 |
label := aMenuItem rawLabel ? ''. |
|
315 |
menuItem := MenuItem label:label. |
|
316 |
menuItem isButton:(aMenuItem isButton). |
|
3404 | 317 |
menuItem activeHelpKey:(aMenuItem activeHelpKey). |
3292 | 318 |
|
319 |
aMenuItem hasSubmenu ifFalse:[ |
|
320 |
color := aMenuItem argument. |
|
321 |
menuItem argument:color. |
|
322 |
||
323 |
(color isColor and:[label isText not]) ifTrue:[ |
|
324 |
labelAreColored ifTrue:[ |
|
325 |
label := Text string:label color:color. |
|
326 |
] ifFalse:[ |
|
327 |
color brightness < 0.5 ifTrue:[ fgColor := Color white ] |
|
328 |
ifFalse:[ fgColor := Color black ]. |
|
329 |
||
330 |
label := Text string:label foregroundColor:fgColor backgroundColor:color. |
|
331 |
]. |
|
332 |
menuItem label:label. |
|
333 |
menuItem value:aValue. |
|
334 |
]. |
|
335 |
^ menuItem |
|
336 |
]. |
|
337 |
submenu := Menu new. |
|
338 |
aMenuItem submenu itemsDo:[:el| |
|
339 |
submenu addItem:(self resolveMenuItem:el value:aValue labelAreColored:labelAreColored). |
|
340 |
]. |
|
341 |
menuItem submenu:submenu. |
|
342 |
^ menuItem |
|
592 | 343 |
! ! |
344 |
||
1808 | 345 |
!ColorMenu methodsFor:'accepting'! |
412 | 346 |
|
347 |
accept:anItem |
|
3322 | 348 |
"accept the current selected item" |
664 | 349 |
|
412 | 350 |
|item holder color| |
351 |
||
3413
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
352 |
item := super accept:anItem. |
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
353 |
(item notNil and:[((item nameKey ? '') startsWith:'pseudo') not]) ifTrue:[ |
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
354 |
holder := self colorHolder. |
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
355 |
holder == item ifTrue:[ |
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
356 |
enabledChannel value ifTrue:[ |
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
357 |
color := self color. |
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
358 |
] ifFalse:[ |
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
359 |
holder label:(Text string:' '). |
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
360 |
]. |
3322 | 361 |
] ifFalse:[ |
666 | 362 |
color := item argument. |
692 | 363 |
holder label:(Text string:' ' emphasis:(#backgroundColor->color)). |
412 | 364 |
]. |
3322 | 365 |
self choseColor:color. |
366 |
] |
|
367 |
! |
|
368 |
||
369 |
choseColor:aColor |
|
370 |
"accept the current selected item" |
|
371 |
||
3350 | 372 |
(model notNil |
373 |
and:[ model isSymbol not]) ifTrue:[ |
|
3322 | 374 |
model value:aColor. |
3323 | 375 |
aColor notNil ifTrue:[ |
376 |
RecentlyUsedColors isNil ifTrue:[ |
|
377 |
RecentlyUsedColors := OrderedCollection new. |
|
378 |
]. |
|
379 |
RecentlyUsedColors remove:aColor ifAbsent:[]. |
|
380 |
RecentlyUsedColors addFirst:aColor. |
|
381 |
RecentlyUsedColors size > 20 ifTrue:[ |
|
382 |
RecentlyUsedColors removeLast |
|
383 |
]. |
|
384 |
] |
|
412 | 385 |
] |
386 |
! ! |
|
387 |
||
388 |
!ColorMenu methodsFor:'accessing'! |
|
389 |
||
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
390 |
allowSymbolicColors |
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
391 |
^ allowSymbolicColors |
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
392 |
! |
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
393 |
|
3397
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
394 |
allowSymbolicColors:aBoolean |
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
395 |
allowSymbolicColors := aBoolean. |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
396 |
! |
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
397 |
|
412 | 398 |
color |
664 | 399 |
"get current color" |
400 |
||
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
401 |
^ color |
412 | 402 |
! |
403 |
||
404 |
color:aColor |
|
664 | 405 |
"set current color" |
406 |
||
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
407 |
|label newColor| |
412 | 408 |
|
3344 | 409 |
(aColor isColor or:[aColor isSymbol]) ifFalse:[ |
3445 | 410 |
enabledChannel value:false. |
411 |
self colorHolder label:' '. |
|
2184 | 412 |
] ifTrue:[ |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
413 |
newColor := aColor. |
3344 | 414 |
aColor isSymbol ifTrue:[ |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
415 |
allowSymbolicColors ifTrue:[ |
3412
edde712ea6ed
If allowSymbolicColors is false, do not allow 'color names' like halt or error.
Stefan Vogel <sv@exept.de>
parents:
3406
diff
changeset
|
416 |
label := aColor. |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
417 |
] ifFalse:[ |
3412
edde712ea6ed
If allowSymbolicColors is false, do not allow 'color names' like halt or error.
Stefan Vogel <sv@exept.de>
parents:
3406
diff
changeset
|
418 |
"our caller does not handle symbolic colors (UIPainter does) - convert now. |
edde712ea6ed
If allowSymbolicColors is false, do not allow 'color names' like halt or error.
Stefan Vogel <sv@exept.de>
parents:
3406
diff
changeset
|
419 |
Be careful - for security reasons - do not perform arbitrary symbols here |
edde712ea6ed
If allowSymbolicColors is false, do not allow 'color names' like halt or error.
Stefan Vogel <sv@exept.de>
parents:
3406
diff
changeset
|
420 |
(could be #halt, #error)!!" |
edde712ea6ed
If allowSymbolicColors is false, do not allow 'color names' like halt or error.
Stefan Vogel <sv@exept.de>
parents:
3406
diff
changeset
|
421 |
|
edde712ea6ed
If allowSymbolicColors is false, do not allow 'color names' like halt or error.
Stefan Vogel <sv@exept.de>
parents:
3406
diff
changeset
|
422 |
newColor := Color name:aColor ifIllegal:[color "keep old"]. |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
423 |
]. |
3412
edde712ea6ed
If allowSymbolicColors is false, do not allow 'color names' like halt or error.
Stefan Vogel <sv@exept.de>
parents:
3406
diff
changeset
|
424 |
]. |
edde712ea6ed
If allowSymbolicColors is false, do not allow 'color names' like halt or error.
Stefan Vogel <sv@exept.de>
parents:
3406
diff
changeset
|
425 |
newColor isSymbol ifFalse:[ |
edde712ea6ed
If allowSymbolicColors is false, do not allow 'color names' like halt or error.
Stefan Vogel <sv@exept.de>
parents:
3406
diff
changeset
|
426 |
"show the selected color in the label" |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
427 |
label := Text string: ' ' emphasis:(#backgroundColor->newColor). |
3344 | 428 |
]. |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
429 |
color := newColor. |
3344 | 430 |
self disabledRedrawDo:[ |
431 |
enabledChannel value:true. |
|
432 |
self colorHolder label:label. |
|
433 |
self choseColor:aColor |
|
434 |
] |
|
412 | 435 |
] |
664 | 436 |
! |
437 |
||
3406 | 438 |
colorHolder |
439 |
"returns the item which keeps the selected color in its label" |
|
440 |
||
441 |
^ self itemAt:#selection |
|
442 |
! |
|
443 |
||
3698 | 444 |
contents |
445 |
^ self color |
|
446 |
! |
|
447 |
||
3397
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
448 |
labelsAreColored |
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
449 |
"controls if labels or their backgrounds will be colored" |
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
450 |
|
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
451 |
^ labelsAreColored |
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
452 |
! |
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
453 |
|
664 | 454 |
labelsAreColored: aBoolean |
455 |
"sets whether labels or their backgrounds will be colored" |
|
456 |
||
3280 | 457 |
|bool| |
458 |
||
459 |
bool := aBoolean ? false. |
|
664 | 460 |
|
3280 | 461 |
labelsAreColored ~~ bool ifTrue:[ |
462 |
labelsAreColored := bool. |
|
463 |
self setupMenu |
|
464 |
]. |
|
412 | 465 |
! ! |
466 |
||
1818 | 467 |
!ColorMenu methodsFor:'accessing-channels'! |
412 | 468 |
|
469 |
model:aValueHolder |
|
664 | 470 |
"set my color channel" |
471 |
||
2184 | 472 |
super model:aValueHolder. |
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
473 |
model notNil ifTrue:[ |
2186 | 474 |
self updateFromModel |
664 | 475 |
] |
412 | 476 |
! ! |
477 |
||
478 |
!ColorMenu methodsFor:'change & update'! |
|
479 |
||
2186 | 480 |
updateFromModel |
2184 | 481 |
self color:(model value) |
412 | 482 |
! ! |
483 |
||
3439 | 484 |
!ColorMenu methodsFor:'help'! |
485 |
||
486 |
flyByHelpSpec |
|
487 |
"This resource specification was automatically generated |
|
488 |
by the UIHelpTool of ST/X." |
|
489 |
||
490 |
"Do not manually edit this!! If it is corrupted, |
|
491 |
the UIHelpTool may not be able to read the specification." |
|
492 |
||
493 |
" |
|
494 |
UIHelpTool openOnClass:ColorEditDialog |
|
495 |
" |
|
496 |
||
497 |
<resource: #help> |
|
498 |
||
499 |
^ super flyByHelpSpec addPairsFrom:#( |
|
500 |
||
501 |
#useDefaultColorToggle |
|
502 |
'Turn on, to specify the color here. Turn off to use the default' |
|
503 |
||
504 |
#toggleSymbolicColor |
|
505 |
'Turn on, to specify a symbolic color. Turn off to specify a concrete color' |
|
506 |
||
507 |
#recentlyUsedColors |
|
508 |
'Recently used colors' |
|
509 |
||
510 |
#openColorEditor |
|
511 |
'Open a color editor' |
|
512 |
||
513 |
#pickColorFromScreen |
|
514 |
'Pick a color from the screen' |
|
515 |
||
516 |
) |
|
517 |
! ! |
|
518 |
||
412 | 519 |
!ColorMenu methodsFor:'initialization'! |
520 |
||
3322 | 521 |
colorHistorySubmenu |
522 |
|menu| |
|
523 |
||
524 |
RecentlyUsedColors isEmptyOrNil ifTrue:[^ nil]. |
|
525 |
||
526 |
menu := Menu new. |
|
527 |
||
3344 | 528 |
RecentlyUsedColors do:[:eachRecentlyUsedColor | |
3322 | 529 |
|label fgColor item| |
530 |
||
3344 | 531 |
eachRecentlyUsedColor isSymbol ifTrue:[ |
532 |
label := eachRecentlyUsedColor . |
|
533 |
] ifFalse:[ |
|
534 |
eachRecentlyUsedColor brightness < 0.5 |
|
535 |
ifTrue:[ fgColor := Color white ] |
|
536 |
ifFalse:[ fgColor := Color black ]. |
|
3322 | 537 |
|
3344 | 538 |
label := eachRecentlyUsedColor htmlPrintString. |
539 |
label := Text string:(' ', label, ' ') foregroundColor:fgColor backgroundColor:eachRecentlyUsedColor. |
|
540 |
]. |
|
541 |
||
3322 | 542 |
item := MenuItem labeled:label. |
3344 | 543 |
item argument:eachRecentlyUsedColor. |
3322 | 544 |
|
545 |
menu addItem:item. |
|
546 |
]. |
|
547 |
||
548 |
^ menu. |
|
549 |
! |
|
550 |
||
412 | 551 |
destroy |
664 | 552 |
"release color channel dependency" |
553 |
||
412 | 554 |
self model:nil. |
664 | 555 |
super destroy |
412 | 556 |
|
557 |
! |
|
558 |
||
559 |
initialize |
|
560 |
super initialize. |
|
3397
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
561 |
labelsAreColored := false. |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
562 |
verticalLayout := false. |
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
563 |
allowSymbolicColors := false. |
2254 | 564 |
|
412 | 565 |
self fitFirstPanel:false. |
895 | 566 |
enabledChannel := ValueHolder with:false. |
412 | 567 |
self setupMenu. |
895 | 568 |
|
569 |
"Modified: / 21.5.1998 / 03:07:26 / cg" |
|
412 | 570 |
! |
571 |
||
572 |
setupMenu |
|
3707 | 573 |
|menu toggleItem| |
412 | 574 |
|
666 | 575 |
menu := self class colorMenu:labelsAreColored value:nil. |
3280 | 576 |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
577 |
menu |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
578 |
addItem:( |
3322 | 579 |
(MenuItem labeled:nil) |
580 |
labelImage:(ToolbarIconLibrary palette16x16Icon); |
|
581 |
value:[ self openColorEditDialog ]; |
|
582 |
nameKey:#pseudoDef; |
|
3404 | 583 |
activeHelpKey:#openColorEditor; |
584 |
isButton: true) |
|
585 |
beforeIndex:1. |
|
806 | 586 |
|
3322 | 587 |
menu |
588 |
addItem:( |
|
589 |
(MenuItem labeled:nil) |
|
590 |
labelImage:(ToolbarIconLibrary pipette16x16Icon); |
|
591 |
value:[ self pickColorFromScreen ]; |
|
592 |
nameKey:#pseudoPick; |
|
3404 | 593 |
activeHelpKey:#pickColorFromScreen; |
594 |
isButton: true) |
|
595 |
beforeIndex:1. |
|
3322 | 596 |
|
597 |
menu |
|
598 |
addItem:( |
|
599 |
(MenuItem labeled:nil) |
|
3707 | 600 |
labelImage:(ToolbarIconLibrary colorHistory16x16Icon); |
3322 | 601 |
submenuChannel:[ self colorHistorySubmenu ]; |
3401 | 602 |
nameKey:#pseudoHistory; |
3404 | 603 |
activeHelpKey:#recentlyUsedColors; |
3322 | 604 |
isButton: false) |
605 |
beforeIndex:1. |
|
606 |
||
607 |
"/ menu addItem:(MenuItem label:'') beforeIndex:1. |
|
608 |
||
3401 | 609 |
toggleItem := MenuItem labeled:(Text string:' ' emphasis:(#backgroundColor->DefaultViewBackgroundColor)). |
610 |
toggleItem value:#selection. |
|
3404 | 611 |
toggleItem isButton: false. |
612 |
toggleItem activeHelpKey:#useDefaultColorToggle. |
|
3401 | 613 |
menu addItem:toggleItem beforeIndex:1. |
806 | 614 |
|
412 | 615 |
self menu:menu. |
616 |
||
666 | 617 |
self do:[:anItem| |
3404 | 618 |
anItem value == #selection ifTrue:[ |
3322 | 619 |
anItem indication:enabledChannel |
666 | 620 |
] ifFalse:[ |
3322 | 621 |
anItem enabled:enabledChannel. |
412 | 622 |
] |
664 | 623 |
] |
412 | 624 |
! ! |
625 |
||
3406 | 626 |
!ColorMenu methodsFor:'user actions'! |
3322 | 627 |
|
3530 | 628 |
keepColorHolderIndicationAlwaysEnabled |
629 |
self colorHolder indication:true. |
|
630 |
self colorHolder isButton:true. |
|
631 |
! |
|
632 |
||
3322 | 633 |
openColorEditDialog |
634 |
|defineColorDialog| |
|
635 |
||
636 |
defineColorDialog := ColorEditDialog new color: self color. |
|
637 |
defineColorDialog open. |
|
638 |
defineColorDialog accept value ifTrue: [ |
|
639 |
self color:defineColorDialog color |
|
640 |
] |
|
641 |
! |
|
642 |
||
643 |
pickColorFromScreen |
|
644 |
|color| |
|
645 |
||
646 |
color := Color fromUser. |
|
647 |
color notNil ifTrue:[ |
|
648 |
self color:color. |
|
649 |
] |
|
412 | 650 |
! ! |
651 |
||
652 |
!ColorMenu class methodsFor:'documentation'! |
|
653 |
||
654 |
version |
|
3707 | 655 |
^ '$Header: /cvs/stx/stx/libwidg2/ColorMenu.st,v 1.59 2009-05-28 06:37:26 cg Exp $' |
412 | 656 |
! ! |