author | Stefan Vogel <sv@exept.de> |
Tue, 27 May 2008 13:34:53 +0200 | |
changeset 3413 | c7be2e00d9bc |
parent 3412 | edde712ea6ed |
child 3439 | e6af2a8f0cd4 |
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: |
|
227 |
#( veryLight lightened 100 87 67 50 33) |
|
228 |
) |
|
229 |
#( green |
|
230 |
green: |
|
231 |
#( veryLight lightened 100 87 67 50 33) |
|
232 |
) |
|
233 |
#( blue |
|
234 |
blue: |
|
235 |
#( veryLight lightened 100 87 67 50 33) |
|
236 |
) |
|
237 |
"/ nil "/ separator |
|
238 |
#( cyan |
|
239 |
cyan: |
|
240 |
#( veryLight lightened 100 87 67 50 33) |
|
241 |
) |
|
242 |
#( magenta |
|
243 |
magenta: |
|
244 |
#( veryLight lightened 100 87 67 50 33) |
|
245 |
) |
|
246 |
#( yellow |
|
247 |
yellow: |
|
248 |
#( veryLight lightened 100 87 67 50 33) |
|
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 |
||
259 |
"ColorMenuSpec := nil" |
|
3292 | 260 |
|
3280 | 261 |
ColorMenuSpec notNil ifTrue:[ ^ ColorMenuSpec ]. |
262 |
||
3404 | 263 |
menu := Menu new. |
3280 | 264 |
self colorMenuSpec do:[:aSlice| |
3404 | 265 |
menu addItem:(menuItem := MenuItem new). |
3280 | 266 |
|
267 |
aSlice notNil ifTrue:[ |
|
268 |
colorId := aSlice at:1. |
|
269 |
getColSel := aSlice at:2. |
|
270 |
baseColor := Color perform:colorId. |
|
271 |
||
3323 | 272 |
menuItem label:(Text string:' ' emphasis:(#backgroundColor->baseColor)). |
3280 | 273 |
menuItem submenu:(submenu := Menu new). |
3292 | 274 |
menuItem isButton:true. |
3404 | 275 |
menuItem activeHelpKey:('shadesOf',colorId asUppercaseFirst) asSymbol. |
3280 | 276 |
|
277 |
aSlice last do:[:el| |
|
278 |
color := label := nil. |
|
279 |
||
280 |
el isSymbol ifTrue:[ |
|
3322 | 281 |
el == #veryLight ifTrue:[ |
282 |
color := baseColor lightened lightened |
|
283 |
] ifFalse:[ el == #lightened ifTrue:[ |
|
284 |
color := baseColor perform:el |
|
285 |
] ifFalse:[ |
|
286 |
color := Color perform:el |
|
287 |
]]. |
|
3280 | 288 |
colorId == #gray ifTrue:[ label := el ]. |
289 |
] ifFalse:[ |
|
290 |
el isNumber ifTrue:[ |
|
291 |
color := Color perform:getColSel with:el. |
|
292 |
]. |
|
293 |
]. |
|
294 |
color notNil ifTrue:[ |
|
295 |
label isNil ifTrue:[ |
|
296 |
label := getColSel, ' ', el printString. |
|
297 |
]. |
|
3322 | 298 |
subItem := MenuItem label:' ',label,' '. |
3280 | 299 |
subItem argument:color. |
300 |
submenu addItem:subItem. |
|
301 |
]. |
|
302 |
] |
|
303 |
]. |
|
304 |
]. |
|
3404 | 305 |
ColorMenuSpec := menu. |
306 |
^ menu |
|
3280 | 307 |
! |
308 |
||
3292 | 309 |
resolveMenuItem:aMenuItem value:aValue labelAreColored:labelAreColored |
310 |
|menuItem label color fgColor submenu| |
|
311 |
||
312 |
label := aMenuItem rawLabel ? ''. |
|
313 |
menuItem := MenuItem label:label. |
|
314 |
menuItem isButton:(aMenuItem isButton). |
|
3404 | 315 |
menuItem activeHelpKey:(aMenuItem activeHelpKey). |
3292 | 316 |
|
317 |
aMenuItem hasSubmenu ifFalse:[ |
|
318 |
color := aMenuItem argument. |
|
319 |
menuItem argument:color. |
|
320 |
||
321 |
(color isColor and:[label isText not]) ifTrue:[ |
|
322 |
labelAreColored ifTrue:[ |
|
323 |
label := Text string:label color:color. |
|
324 |
] ifFalse:[ |
|
325 |
color brightness < 0.5 ifTrue:[ fgColor := Color white ] |
|
326 |
ifFalse:[ fgColor := Color black ]. |
|
327 |
||
328 |
label := Text string:label foregroundColor:fgColor backgroundColor:color. |
|
329 |
]. |
|
330 |
menuItem label:label. |
|
331 |
menuItem value:aValue. |
|
332 |
]. |
|
333 |
^ menuItem |
|
334 |
]. |
|
335 |
submenu := Menu new. |
|
336 |
aMenuItem submenu itemsDo:[:el| |
|
337 |
submenu addItem:(self resolveMenuItem:el value:aValue labelAreColored:labelAreColored). |
|
338 |
]. |
|
339 |
menuItem submenu:submenu. |
|
340 |
^ menuItem |
|
592 | 341 |
! ! |
342 |
||
1808 | 343 |
!ColorMenu methodsFor:'accepting'! |
412 | 344 |
|
345 |
accept:anItem |
|
3322 | 346 |
"accept the current selected item" |
664 | 347 |
|
412 | 348 |
|item holder color| |
349 |
||
3413
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
350 |
item := super accept:anItem. |
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
351 |
(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
|
352 |
holder := self colorHolder. |
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
353 |
holder == item ifTrue:[ |
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
354 |
enabledChannel value ifTrue:[ |
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
355 |
color := self color. |
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
356 |
] ifFalse:[ |
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
357 |
holder label:(Text string:' '). |
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
358 |
]. |
3322 | 359 |
] ifFalse:[ |
666 | 360 |
color := item argument. |
692 | 361 |
holder label:(Text string:' ' emphasis:(#backgroundColor->color)). |
412 | 362 |
]. |
3322 | 363 |
self choseColor:color. |
364 |
] |
|
365 |
! |
|
366 |
||
367 |
choseColor:aColor |
|
368 |
"accept the current selected item" |
|
369 |
||
3350 | 370 |
(model notNil |
371 |
and:[ model isSymbol not]) ifTrue:[ |
|
3322 | 372 |
model value:aColor. |
3323 | 373 |
aColor notNil ifTrue:[ |
374 |
RecentlyUsedColors isNil ifTrue:[ |
|
375 |
RecentlyUsedColors := OrderedCollection new. |
|
376 |
]. |
|
377 |
RecentlyUsedColors remove:aColor ifAbsent:[]. |
|
378 |
RecentlyUsedColors addFirst:aColor. |
|
379 |
RecentlyUsedColors size > 20 ifTrue:[ |
|
380 |
RecentlyUsedColors removeLast |
|
381 |
]. |
|
382 |
] |
|
412 | 383 |
] |
384 |
! ! |
|
385 |
||
386 |
!ColorMenu methodsFor:'accessing'! |
|
387 |
||
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
388 |
allowSymbolicColors |
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
389 |
^ allowSymbolicColors |
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
390 |
! |
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
391 |
|
3397
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
392 |
allowSymbolicColors:aBoolean |
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
393 |
allowSymbolicColors := aBoolean. |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
394 |
! |
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
395 |
|
412 | 396 |
color |
664 | 397 |
"get current color" |
398 |
||
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
399 |
^ color |
412 | 400 |
! |
401 |
||
402 |
color:aColor |
|
664 | 403 |
"set current color" |
404 |
||
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
405 |
|label newColor| |
412 | 406 |
|
3344 | 407 |
(aColor isColor or:[aColor isSymbol]) ifFalse:[ |
412 | 408 |
enabledChannel value:false |
2184 | 409 |
] ifTrue:[ |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
410 |
newColor := aColor. |
3344 | 411 |
aColor isSymbol ifTrue:[ |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
412 |
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
|
413 |
label := aColor. |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
414 |
] 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
|
415 |
"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
|
416 |
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
|
417 |
(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
|
418 |
|
edde712ea6ed
If allowSymbolicColors is false, do not allow 'color names' like halt or error.
Stefan Vogel <sv@exept.de>
parents:
3406
diff
changeset
|
419 |
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
|
420 |
]. |
3412
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 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
|
423 |
"show the selected color in the label" |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
424 |
label := Text string: ' ' emphasis:(#backgroundColor->newColor). |
3344 | 425 |
]. |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
426 |
color := newColor. |
3344 | 427 |
self disabledRedrawDo:[ |
428 |
enabledChannel value:true. |
|
429 |
self colorHolder label:label. |
|
430 |
self choseColor:aColor |
|
431 |
] |
|
412 | 432 |
] |
664 | 433 |
! |
434 |
||
3406 | 435 |
colorHolder |
436 |
"returns the item which keeps the selected color in its label" |
|
437 |
||
438 |
^ self itemAt:#selection |
|
439 |
! |
|
440 |
||
3397
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
441 |
labelsAreColored |
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
442 |
"controls if labels or their backgrounds will be colored" |
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
443 |
|
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
444 |
^ labelsAreColored |
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
445 |
! |
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
446 |
|
664 | 447 |
labelsAreColored: aBoolean |
448 |
"sets whether labels or their backgrounds will be colored" |
|
449 |
||
3280 | 450 |
|bool| |
451 |
||
452 |
bool := aBoolean ? false. |
|
664 | 453 |
|
3280 | 454 |
labelsAreColored ~~ bool ifTrue:[ |
455 |
labelsAreColored := bool. |
|
456 |
self setupMenu |
|
457 |
]. |
|
412 | 458 |
! ! |
459 |
||
1818 | 460 |
!ColorMenu methodsFor:'accessing-channels'! |
412 | 461 |
|
462 |
model:aValueHolder |
|
664 | 463 |
"set my color channel" |
464 |
||
2184 | 465 |
super model:aValueHolder. |
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
466 |
model notNil ifTrue:[ |
2186 | 467 |
self updateFromModel |
664 | 468 |
] |
412 | 469 |
! ! |
470 |
||
471 |
!ColorMenu methodsFor:'change & update'! |
|
472 |
||
2186 | 473 |
updateFromModel |
2184 | 474 |
self color:(model value) |
412 | 475 |
! ! |
476 |
||
477 |
!ColorMenu methodsFor:'initialization'! |
|
478 |
||
3322 | 479 |
colorHistorySubmenu |
480 |
|menu| |
|
481 |
||
482 |
RecentlyUsedColors isEmptyOrNil ifTrue:[^ nil]. |
|
483 |
||
484 |
menu := Menu new. |
|
485 |
||
3344 | 486 |
RecentlyUsedColors do:[:eachRecentlyUsedColor | |
3322 | 487 |
|label fgColor item| |
488 |
||
3344 | 489 |
eachRecentlyUsedColor isSymbol ifTrue:[ |
490 |
label := eachRecentlyUsedColor . |
|
491 |
] ifFalse:[ |
|
492 |
eachRecentlyUsedColor brightness < 0.5 |
|
493 |
ifTrue:[ fgColor := Color white ] |
|
494 |
ifFalse:[ fgColor := Color black ]. |
|
3322 | 495 |
|
3344 | 496 |
label := eachRecentlyUsedColor htmlPrintString. |
497 |
label := Text string:(' ', label, ' ') foregroundColor:fgColor backgroundColor:eachRecentlyUsedColor. |
|
498 |
]. |
|
499 |
||
3322 | 500 |
item := MenuItem labeled:label. |
3344 | 501 |
item argument:eachRecentlyUsedColor. |
3322 | 502 |
|
503 |
menu addItem:item. |
|
504 |
]. |
|
505 |
||
506 |
^ menu. |
|
507 |
! |
|
508 |
||
412 | 509 |
destroy |
664 | 510 |
"release color channel dependency" |
511 |
||
412 | 512 |
self model:nil. |
664 | 513 |
super destroy |
412 | 514 |
|
515 |
! |
|
516 |
||
517 |
initialize |
|
518 |
super initialize. |
|
3397
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
519 |
labelsAreColored := false. |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
520 |
verticalLayout := false. |
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
521 |
allowSymbolicColors := false. |
2254 | 522 |
|
412 | 523 |
self fitFirstPanel:false. |
895 | 524 |
enabledChannel := ValueHolder with:false. |
412 | 525 |
self setupMenu. |
895 | 526 |
|
527 |
"Modified: / 21.5.1998 / 03:07:26 / cg" |
|
412 | 528 |
! |
529 |
||
530 |
setupMenu |
|
3401 | 531 |
|menu item toggleItem| |
412 | 532 |
|
666 | 533 |
menu := self class colorMenu:labelsAreColored value:nil. |
3280 | 534 |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
535 |
menu |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
536 |
addItem:( |
3322 | 537 |
(MenuItem labeled:nil) |
538 |
labelImage:(ToolbarIconLibrary palette16x16Icon); |
|
539 |
value:[ self openColorEditDialog ]; |
|
540 |
nameKey:#pseudoDef; |
|
3404 | 541 |
activeHelpKey:#openColorEditor; |
542 |
isButton: true) |
|
543 |
beforeIndex:1. |
|
806 | 544 |
|
3322 | 545 |
menu |
546 |
addItem:( |
|
547 |
(MenuItem labeled:nil) |
|
548 |
labelImage:(ToolbarIconLibrary pipette16x16Icon); |
|
549 |
value:[ self pickColorFromScreen ]; |
|
550 |
nameKey:#pseudoPick; |
|
3404 | 551 |
activeHelpKey:#pickColorFromScreen; |
552 |
isButton: true) |
|
553 |
beforeIndex:1. |
|
3322 | 554 |
|
555 |
menu |
|
556 |
addItem:( |
|
557 |
(MenuItem labeled:nil) |
|
3323 | 558 |
labelImage:(ToolbarIconLibrary history16x16Icon); |
3322 | 559 |
submenuChannel:[ self colorHistorySubmenu ]; |
3401 | 560 |
nameKey:#pseudoHistory; |
3404 | 561 |
activeHelpKey:#recentlyUsedColors; |
3322 | 562 |
isButton: false) |
563 |
beforeIndex:1. |
|
564 |
||
565 |
"/ menu addItem:(MenuItem label:'') beforeIndex:1. |
|
566 |
||
3401 | 567 |
toggleItem := MenuItem labeled:(Text string:' ' emphasis:(#backgroundColor->DefaultViewBackgroundColor)). |
568 |
toggleItem value:#selection. |
|
3404 | 569 |
toggleItem isButton: false. |
570 |
toggleItem activeHelpKey:#useDefaultColorToggle. |
|
3401 | 571 |
menu addItem:toggleItem beforeIndex:1. |
806 | 572 |
|
412 | 573 |
self menu:menu. |
574 |
||
666 | 575 |
self do:[:anItem| |
3404 | 576 |
anItem value == #selection ifTrue:[ |
3322 | 577 |
anItem indication:enabledChannel |
666 | 578 |
] ifFalse:[ |
3322 | 579 |
anItem enabled:enabledChannel. |
412 | 580 |
] |
664 | 581 |
] |
412 | 582 |
! ! |
583 |
||
3406 | 584 |
!ColorMenu methodsFor:'user actions'! |
3322 | 585 |
|
586 |
openColorEditDialog |
|
587 |
|defineColorDialog| |
|
588 |
||
589 |
defineColorDialog := ColorEditDialog new color: self color. |
|
590 |
defineColorDialog open. |
|
591 |
defineColorDialog accept value ifTrue: [ |
|
592 |
self color:defineColorDialog color |
|
593 |
] |
|
594 |
! |
|
595 |
||
596 |
pickColorFromScreen |
|
597 |
|color| |
|
598 |
||
599 |
color := Color fromUser. |
|
600 |
color notNil ifTrue:[ |
|
601 |
self color:color. |
|
602 |
] |
|
412 | 603 |
! ! |
604 |
||
605 |
!ColorMenu class methodsFor:'documentation'! |
|
606 |
||
607 |
version |
|
3413
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
608 |
^ '$Header: /cvs/stx/stx/libwidg2/ColorMenu.st,v 1.54 2008-05-27 11:34:53 stefan Exp $' |
412 | 609 |
! ! |