author | Claus Gittinger <cg@exept.de> |
Sun, 09 Sep 2012 15:15:43 +0200 | |
changeset 4143 | c979a5bea623 |
parent 4068 | b4641443cef0 |
child 4156 | 7ee9d00b78f7 |
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 |
3996 | 15 |
instanceVariableNames:'overwriteDefaultToggleChannel enabledChannel labelsAreColored |
16 |
color colorName allowSymbolicColors showDefaultToggle |
|
3997 | 17 |
acceptAction useDefaultColorToggleVisibleHolder allowNilColor |
3998 | 18 |
hasNilColorHolder' |
3322 | 19 |
classVariableNames:'ColorMenuSpec RecentlyUsedColors' |
412 | 20 |
poolDictionaries:'' |
21 |
category:'Interface-UIPainter' |
|
22 |
! |
|
23 |
||
24 |
!ColorMenu class methodsFor:'documentation'! |
|
25 |
||
422 | 26 |
copyright |
27 |
" |
|
28 |
COPYRIGHT (c) 1995 by eXept Software AG |
|
29 |
All Rights Reserved |
|
30 |
||
31 |
This software is furnished under a license and may be used |
|
32 |
only in accordance with the terms of that license and with the |
|
33 |
inclusion of the above copyright notice. This software may not |
|
34 |
be provided or otherwise made available to, or used by, any |
|
35 |
other person. No title to or ownership of the software is |
|
36 |
hereby transferred. |
|
37 |
" |
|
38 |
||
39 |
||
40 |
! |
|
41 |
||
412 | 42 |
documentation |
43 |
" |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
44 |
A simple ColorMenu used by the UIPainter |
412 | 45 |
|
46 |
[see also:] |
|
47 |
UIPainter |
|
48 |
ColorMenuSpec |
|
422 | 49 |
|
50 |
[author:] |
|
51 |
Claus Atzkern |
|
412 | 52 |
" |
53 |
! |
|
54 |
||
55 |
examples |
|
56 |
" |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
57 |
very simple example |
412 | 58 |
[exBegin] |
59 |
|tool top channel| |
|
60 |
||
61 |
top := StandardSystemView new. |
|
62 |
top extent:250@30. |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
63 |
|
412 | 64 |
channel := (Color red) asValue. |
65 |
tool := self origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
66 |
tool model:channel. |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
67 |
|
412 | 68 |
top open. |
69 |
[exEnd] |
|
70 |
" |
|
71 |
! ! |
|
72 |
||
3322 | 73 |
!ColorMenu class methodsFor:'instance creation'! |
74 |
||
3995
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
75 |
colorMenu:labelsAreColored value:aValue |
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
76 |
"returns a color menu" |
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
77 |
|
3322 | 78 |
|menu| |
79 |
||
80 |
menu := Menu new. |
|
81 |
||
82 |
self colorMenu itemsDo:[:el| |
|
3995
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
83 |
menu addItem:(self resolveMenuItem:el value:aValue labelsAreColored:labelsAreColored). |
3322 | 84 |
]. |
85 |
^ menu |
|
86 |
||
87 |
" |
|
88 |
(ColorMenu colorMenu:true value:nil) startUp |
|
89 |
(ColorMenu colorMenu:false value:#aSelector:) startUp |
|
90 |
" |
|
3995
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
91 |
|
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
92 |
"Modified: / 23-01-2011 / 14:58:32 / cg" |
3322 | 93 |
! ! |
94 |
||
95 |
!ColorMenu class methodsFor:'adding & removing user defined items'! |
|
3280 | 96 |
|
3292 | 97 |
addUserDefinedColors:aColors labels:labelsOrNil title:aTitle |
3322 | 98 |
"add user colors to ALL colormenus" |
99 |
||
100 |
"cg: I think this is a bad hack, as it is too global." |
|
101 |
||
3292 | 102 |
|size submenu item label fgColor bgColor labels defLabel| |
103 |
||
104 |
submenu := self userDefinedSubmenu. |
|
105 |
size := aColors size. |
|
106 |
||
107 |
size == 0 ifTrue:[ "/ separator |
|
3862
754cfd6ed4b5
changed: #addUserDefinedColors:labels:title:
Claus Gittinger <cg@exept.de>
parents:
3738
diff
changeset
|
108 |
submenu addSeparator. |
3292 | 109 |
^ self |
110 |
]. |
|
111 |
||
112 |
labels := labelsOrNil ? #(). |
|
113 |
bgColor := aColors first. |
|
114 |
defLabel := ' '. |
|
115 |
||
116 |
bgColor brightness < 0.5 ifTrue:[ fgColor := Color white ] |
|
117 |
ifFalse:[ fgColor := Color black ]. |
|
118 |
||
119 |
aTitle isEmptyOrNil ifTrue:[ label := labels at:1 ifAbsent:defLabel ] |
|
120 |
ifFalse:[ label := aTitle ]. |
|
3280 | 121 |
|
3294 | 122 |
label := Text string:(' ', label, ' ') foregroundColor:fgColor backgroundColor:bgColor. |
3292 | 123 |
item := MenuItem labeled:label. |
124 |
submenu addItem:item. |
|
125 |
||
126 |
size == 1 ifTrue:[ |
|
127 |
item argument:bgColor. |
|
128 |
] ifFalse:[ |
|
129 |
item submenu:(submenu := Menu new). |
|
3280 | 130 |
|
3292 | 131 |
aColors keysAndValuesDo:[:idx :aBgColor| |
132 |
aBgColor brightness < 0.5 ifTrue:[ fgColor := Color white ] |
|
133 |
ifFalse:[ fgColor := Color black ]. |
|
134 |
||
135 |
label := labels at:idx ifAbsent:defLabel. |
|
3294 | 136 |
label := Text string:(' ', label, ' ') foregroundColor:fgColor backgroundColor:aBgColor. |
3292 | 137 |
item := MenuItem labeled:label. |
3293 | 138 |
item argument:aBgColor. |
3292 | 139 |
|
140 |
submenu addItem:item. |
|
141 |
]. |
|
142 |
]. |
|
3280 | 143 |
|
144 |
" |
|
3292 | 145 |
ColorMenu removeAllUserDefinedColors. |
3280 | 146 |
|
3292 | 147 |
#( |
148 |
#( Black 16r000000 ) |
|
149 |
#( Red 16rff0000 ) |
|
150 |
nil |
|
151 |
#( Rust 16rff6600 16rff8533 16rffa366 16rffc299 16rffe0cc ) |
|
152 |
#( Tangerine 16rff9933 16rffad5c 16rffc285 16rffd6ad 16rffebd6 ) |
|
153 |
#( Sunflower 16rffcc00 16rfed633 16rfee066 16rffeb99 16rfff5cc ) |
|
154 |
#( Mango 16rffcc99 16rffd6ad 16rffe0c2 16rffebd6 16rfff5eb ) |
|
155 |
#( Buttercup 16rffff66 16rffff85 16rffffa3 16rffffc2 16rffffe0 ) |
|
156 |
#( Lemon 16rffffcc 16rffffd6 16rffffe0 16rffffeb 16rfffff5 ) |
|
3280 | 157 |
|
3292 | 158 |
) do:[:aDef| |colors title labels percentage| |
159 |
aDef isEmptyOrNil ifTrue:[ |
|
160 |
colors := labels := title := nil. |
|
161 |
] ifFalse:[ |
|
162 |
title := aDef first. |
|
163 |
colors := OrderedCollection new. |
|
164 |
labels := OrderedCollection new. |
|
165 |
percentage := 100. |
|
166 |
||
167 |
aDef from:2 do:[:rgb| |
|
168 |
colors add:(Color rgbValue:rgb). |
|
169 |
labels add:('%1 %2 %%' bindWith:title with:percentage). |
|
170 |
percentage := percentage - 20. |
|
171 |
]. |
|
172 |
]. |
|
173 |
ColorMenu addUserDefinedColors:colors labels:labels title:title. |
|
3280 | 174 |
]. |
3292 | 175 |
" |
3280 | 176 |
! |
177 |
||
3283 | 178 |
removeAllUserDefinedColors |
3322 | 179 |
"flush user defined colors" |
180 |
||
3292 | 181 |
ColorMenuSpec := nil. |
3322 | 182 |
! |
183 |
||
184 |
userDefinedSubmenu |
|
185 |
"answer the menu entry under which the userdefined color entries are placed" |
|
186 |
||
187 |
|menu submenu item icon| |
|
188 |
||
189 |
menu := self colorMenu. |
|
190 |
item := menu detectItem:[:el| (el nameKey == #userDefined and:[el submenu notNil]) ] |
|
191 |
ifNone:nil. |
|
192 |
||
193 |
item isNil ifTrue:[ |
|
3323 | 194 |
icon := ToolbarIconLibrary colorHistory16x16Icon. |
3322 | 195 |
item := MenuItem labeled:icon. |
196 |
item nameKey:#userDefined. |
|
197 |
item activeHelpKey:#userDefinedColors. |
|
198 |
menu addItem:item beforeIndex:1. |
|
199 |
]. |
|
200 |
||
201 |
(submenu := item submenu) isNil ifTrue:[ |
|
202 |
submenu := Menu new. |
|
203 |
item submenu:submenu. |
|
204 |
]. |
|
205 |
^ submenu |
|
3280 | 206 |
! ! |
207 |
||
3709 | 208 |
!ColorMenu class methodsFor:'history'! |
209 |
||
210 |
rememberRecentlyUsedColor:aColor |
|
211 |
aColor notNil ifTrue:[ |
|
212 |
RecentlyUsedColors isNil ifTrue:[ |
|
213 |
RecentlyUsedColors := OrderedCollection new. |
|
214 |
]. |
|
215 |
RecentlyUsedColors remove:aColor ifAbsent:[]. |
|
216 |
RecentlyUsedColors addFirst:aColor. |
|
217 |
RecentlyUsedColors size > 20 ifTrue:[ |
|
218 |
RecentlyUsedColors removeLast |
|
219 |
]. |
|
220 |
]. |
|
221 |
! ! |
|
222 |
||
3341 | 223 |
!ColorMenu class methodsFor:'menu specs'! |
412 | 224 |
|
3322 | 225 |
colorMenuSpec |
226 |
"color definitions used to build a color menu |
|
3292 | 227 |
" |
3996 | 228 |
"because it is cached, you have to: |
229 |
ColorMenuSpec := nil. |
|
230 |
when changing |
|
3322 | 231 |
" |
232 |
^ #( |
|
233 |
#( gray |
|
234 |
gray: |
|
235 |
#( white |
|
236 |
veryLightGray |
|
237 |
lightGray |
|
238 |
gray |
|
239 |
darkGray |
|
240 |
veryDarkGray |
|
241 |
black |
|
242 |
) |
|
243 |
) |
|
244 |
"/ nil "/ separator |
|
245 |
#( red |
|
246 |
red: |
|
3707 | 247 |
#( veryLight lightened 100 87 67 50 33 25) |
3322 | 248 |
) |
249 |
#( green |
|
250 |
green: |
|
3707 | 251 |
#( veryLight lightened 100 87 67 50 33 25) |
3322 | 252 |
) |
253 |
#( blue |
|
254 |
blue: |
|
3707 | 255 |
#( veryLight lightened 100 87 67 50 33 25) |
3322 | 256 |
) |
257 |
"/ nil "/ separator |
|
258 |
#( cyan |
|
259 |
cyan: |
|
3707 | 260 |
#( veryLight lightened 100 87 67 50 33 25) |
3322 | 261 |
) |
262 |
#( magenta |
|
263 |
magenta: |
|
3707 | 264 |
#( veryLight lightened 100 87 67 50 33 25) |
3322 | 265 |
) |
266 |
#( yellow |
|
267 |
yellow: |
|
3707 | 268 |
#( veryLight lightened 100 87 67 50 33 25) |
3322 | 269 |
) |
3996 | 270 |
#( brown |
271 |
brown: |
|
272 |
#( veryLight lightened brown darkened veryDark) |
|
273 |
) |
|
274 |
) |
|
3292 | 275 |
|
3996 | 276 |
"Modified: / 23-01-2011 / 16:33:33 / cg" |
3292 | 277 |
! ! |
278 |
||
279 |
!ColorMenu class methodsFor:'private'! |
|
280 |
||
3280 | 281 |
colorMenu |
3404 | 282 |
|menu menuItem subItem baseColor color label getColSel submenu colorId| |
283 |
||
3707 | 284 |
" |
285 |
ColorMenuSpec := nil |
|
286 |
" |
|
3292 | 287 |
|
3280 | 288 |
ColorMenuSpec notNil ifTrue:[ ^ ColorMenuSpec ]. |
289 |
||
3404 | 290 |
menu := Menu new. |
3280 | 291 |
self colorMenuSpec do:[:aSlice| |
3404 | 292 |
menu addItem:(menuItem := MenuItem new). |
3280 | 293 |
|
294 |
aSlice notNil ifTrue:[ |
|
295 |
colorId := aSlice at:1. |
|
296 |
getColSel := aSlice at:2. |
|
297 |
baseColor := Color perform:colorId. |
|
298 |
||
3323 | 299 |
menuItem label:(Text string:' ' emphasis:(#backgroundColor->baseColor)). |
3280 | 300 |
menuItem submenu:(submenu := Menu new). |
3292 | 301 |
menuItem isButton:true. |
3404 | 302 |
menuItem activeHelpKey:('shadesOf',colorId asUppercaseFirst) asSymbol. |
3280 | 303 |
|
304 |
aSlice last do:[:el| |
|
305 |
color := label := nil. |
|
306 |
||
307 |
el isSymbol ifTrue:[ |
|
3322 | 308 |
el == #veryLight ifTrue:[ |
309 |
color := baseColor lightened lightened |
|
310 |
] ifFalse:[ el == #lightened ifTrue:[ |
|
3996 | 311 |
color := baseColor lightened |
312 |
] ifFalse:[ el == #darkened ifTrue:[ |
|
313 |
color := baseColor darkened |
|
314 |
] ifFalse:[ el == #veryDark ifTrue:[ |
|
315 |
color := baseColor darkened darkened |
|
3322 | 316 |
] ifFalse:[ |
317 |
color := Color perform:el |
|
3996 | 318 |
]]]]. |
3280 | 319 |
colorId == #gray ifTrue:[ label := el ]. |
320 |
] ifFalse:[ |
|
321 |
el isNumber ifTrue:[ |
|
322 |
color := Color perform:getColSel with:el. |
|
323 |
]. |
|
324 |
]. |
|
325 |
color notNil ifTrue:[ |
|
326 |
label isNil ifTrue:[ |
|
327 |
label := getColSel, ' ', el printString. |
|
328 |
]. |
|
3322 | 329 |
subItem := MenuItem label:' ',label,' '. |
3280 | 330 |
subItem argument:color. |
331 |
submenu addItem:subItem. |
|
332 |
]. |
|
333 |
] |
|
334 |
]. |
|
335 |
]. |
|
3404 | 336 |
ColorMenuSpec := menu. |
337 |
^ menu |
|
3996 | 338 |
|
339 |
"Modified: / 23-01-2011 / 16:34:45 / cg" |
|
3280 | 340 |
! |
341 |
||
3995
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
342 |
resolveMenuItem:aMenuItem value:aValue labelsAreColored:labelsAreColored |
3292 | 343 |
|menuItem label color fgColor submenu| |
344 |
||
345 |
label := aMenuItem rawLabel ? ''. |
|
346 |
menuItem := MenuItem label:label. |
|
347 |
menuItem isButton:(aMenuItem isButton). |
|
3404 | 348 |
menuItem activeHelpKey:(aMenuItem activeHelpKey). |
3292 | 349 |
|
350 |
aMenuItem hasSubmenu ifFalse:[ |
|
351 |
color := aMenuItem argument. |
|
352 |
menuItem argument:color. |
|
353 |
||
354 |
(color isColor and:[label isText not]) ifTrue:[ |
|
3995
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
355 |
labelsAreColored ifTrue:[ |
3292 | 356 |
label := Text string:label color:color. |
357 |
] ifFalse:[ |
|
358 |
color brightness < 0.5 ifTrue:[ fgColor := Color white ] |
|
359 |
ifFalse:[ fgColor := Color black ]. |
|
360 |
||
361 |
label := Text string:label foregroundColor:fgColor backgroundColor:color. |
|
362 |
]. |
|
363 |
menuItem label:label. |
|
4143 | 364 |
menuItem itemValue:aValue. |
3292 | 365 |
]. |
366 |
^ menuItem |
|
367 |
]. |
|
3995
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
368 |
|
3292 | 369 |
submenu := Menu new. |
370 |
aMenuItem submenu itemsDo:[:el| |
|
3995
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
371 |
submenu addItem:(self resolveMenuItem:el value:aValue labelsAreColored:labelsAreColored). |
3292 | 372 |
]. |
373 |
menuItem submenu:submenu. |
|
374 |
^ menuItem |
|
3995
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
375 |
|
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
376 |
"Created: / 23-01-2011 / 14:59:19 / cg" |
592 | 377 |
! ! |
378 |
||
1808 | 379 |
!ColorMenu methodsFor:'accepting'! |
412 | 380 |
|
381 |
accept:anItem |
|
3322 | 382 |
"accept the current selected item" |
664 | 383 |
|
4068 | 384 |
|holder colorAccepted| |
412 | 385 |
|
4052 | 386 |
super accept:anItem. |
3738 | 387 |
|
4052 | 388 |
(anItem notNil and:[((anItem nameKey ? '') startsWith:'pseudo') not]) ifTrue:[ |
3413
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
389 |
holder := self colorHolder. |
4052 | 390 |
holder == anItem ifTrue:[ |
3996 | 391 |
self overwriteDefaultToggleChannel value ifTrue:[ |
4068 | 392 |
colorAccepted := self color. |
3413
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
393 |
] ifFalse:[ |
4068 | 394 |
holder label:' '. |
4057 | 395 |
model value:nil withoutNotifying:self |
3413
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
396 |
]. |
3322 | 397 |
] ifFalse:[ |
4052 | 398 |
anItem value == #hasNilColorHolder: ifTrue:[ |
3998 | 399 |
self overwriteDefaultToggleChannel value ifFalse:[ |
400 |
model value:nil withoutNotifying:self |
|
401 |
]. |
|
402 |
] ifFalse:[ |
|
4068 | 403 |
colorAccepted := anItem argument. |
404 |
holder label:(Text string:' ' emphasis:(#backgroundColor->colorAccepted)). |
|
405 |
self chooseColor:colorAccepted. |
|
3998 | 406 |
]. |
412 | 407 |
]. |
4068 | 408 |
self class rememberRecentlyUsedColor:colorAccepted. |
3738 | 409 |
acceptAction notNil ifTrue:[ |
4068 | 410 |
acceptAction value:colorAccepted |
3738 | 411 |
]. |
3322 | 412 |
] |
3996 | 413 |
|
4068 | 414 |
"Modified: / 17-08-2011 / 08:57:12 / cg" |
3322 | 415 |
! |
416 |
||
3708
de8fd46e5363
changes to use ColorMenu for expecco
Claus Gittinger <cg@exept.de>
parents:
3707
diff
changeset
|
417 |
chooseColor:aColor |
3322 | 418 |
"accept the current selected item" |
419 |
||
3350 | 420 |
(model notNil |
421 |
and:[ model isSymbol not]) ifTrue:[ |
|
3998 | 422 |
model value:aColor. |
3708
de8fd46e5363
changes to use ColorMenu for expecco
Claus Gittinger <cg@exept.de>
parents:
3707
diff
changeset
|
423 |
]. |
3709 | 424 |
color := aColor. |
412 | 425 |
! ! |
426 |
||
427 |
!ColorMenu methodsFor:'accessing'! |
|
428 |
||
3738 | 429 |
acceptAction:something |
430 |
acceptAction := something. |
|
431 |
! |
|
432 |
||
3997 | 433 |
allowNilColor |
434 |
^ allowNilColor |
|
435 |
! |
|
436 |
||
437 |
allowNilColor:aBoolean |
|
438 |
allowNilColor ~~ aBoolean ifTrue:[ |
|
439 |
allowNilColor := aBoolean. |
|
3998 | 440 |
allowNilColor ifTrue:[ |
441 |
self overwriteDefaultToggleChannel value:true. |
|
442 |
self hasNilColorHolder value:(color notNil). |
|
3997 | 443 |
]. |
3998 | 444 |
self setupMenu. |
3997 | 445 |
]. |
446 |
||
447 |
"Created: / 24-01-2011 / 10:02:25 / cg" |
|
3998 | 448 |
"Modified: / 24-01-2011 / 20:06:28 / cg" |
3997 | 449 |
! |
450 |
||
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
451 |
allowSymbolicColors |
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
452 |
^ allowSymbolicColors |
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
453 |
! |
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
454 |
|
3397
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
455 |
allowSymbolicColors:aBoolean |
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
456 |
allowSymbolicColors := aBoolean. |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
457 |
! |
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
458 |
|
412 | 459 |
color |
664 | 460 |
"get current color" |
461 |
||
3998 | 462 |
self overwriteDefaultToggleChannel value ifFalse:[^ nil]. |
463 |
^ color |
|
3997 | 464 |
|
3998 | 465 |
"Modified: / 24-01-2011 / 20:14:27 / cg" |
412 | 466 |
! |
467 |
||
468 |
color:aColor |
|
664 | 469 |
"set current color" |
470 |
||
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
471 |
|label newColor| |
412 | 472 |
|
3998 | 473 |
self hasNilColorHolder setValue:aColor isNil. |
474 |
||
3344 | 475 |
(aColor isColor or:[aColor isSymbol]) ifFalse:[ |
3996 | 476 |
self overwriteDefaultToggleChannel value:false. |
3445 | 477 |
self colorHolder label:' '. |
3998 | 478 |
(aColor isNil and:[allowNilColor]) ifTrue:[ |
479 |
self chooseColor:aColor |
|
480 |
] |
|
2184 | 481 |
] ifTrue:[ |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
482 |
newColor := aColor. |
3344 | 483 |
aColor isSymbol ifTrue:[ |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
484 |
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
|
485 |
label := aColor. |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
486 |
] 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
|
487 |
"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
|
488 |
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
|
489 |
(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
|
490 |
|
edde712ea6ed
If allowSymbolicColors is false, do not allow 'color names' like halt or error.
Stefan Vogel <sv@exept.de>
parents:
3406
diff
changeset
|
491 |
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
|
492 |
]. |
3412
edde712ea6ed
If allowSymbolicColors is false, do not allow 'color names' like halt or error.
Stefan Vogel <sv@exept.de>
parents:
3406
diff
changeset
|
493 |
]. |
edde712ea6ed
If allowSymbolicColors is false, do not allow 'color names' like halt or error.
Stefan Vogel <sv@exept.de>
parents:
3406
diff
changeset
|
494 |
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
|
495 |
"show the selected color in the label" |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
496 |
label := Text string: ' ' emphasis:(#backgroundColor->newColor). |
3344 | 497 |
]. |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
498 |
color := newColor. |
3344 | 499 |
self disabledRedrawDo:[ |
3996 | 500 |
self overwriteDefaultToggleChannel value:true. |
3344 | 501 |
self colorHolder label:label. |
3708
de8fd46e5363
changes to use ColorMenu for expecco
Claus Gittinger <cg@exept.de>
parents:
3707
diff
changeset
|
502 |
self chooseColor:aColor |
3344 | 503 |
] |
412 | 504 |
] |
3996 | 505 |
|
3998 | 506 |
"Modified: / 24-01-2011 / 20:09:39 / cg" |
664 | 507 |
! |
508 |
||
3406 | 509 |
colorHolder |
510 |
"returns the item which keeps the selected color in its label" |
|
511 |
||
3738 | 512 |
^ self itemAt:#selection |
3406 | 513 |
! |
514 |
||
3698 | 515 |
contents |
516 |
^ self color |
|
517 |
! |
|
518 |
||
3996 | 519 |
enableChannel:aValueHolder |
520 |
super enableChannel:aValueHolder. |
|
521 |
self updateEnableChannel |
|
522 |
||
523 |
"Created: / 23-01-2011 / 16:08:52 / cg" |
|
524 |
! |
|
525 |
||
3981 | 526 |
enabledChannel |
3996 | 527 |
^ self overwriteDefaultToggleChannel |
528 |
"/ ^ enabledChannel |
|
529 |
||
530 |
"Modified: / 23-01-2011 / 16:24:12 / cg" |
|
3981 | 531 |
! |
532 |
||
3997 | 533 |
hasNilColorHolder |
534 |
hasNilColorHolder isNil ifTrue:[ |
|
535 |
hasNilColorHolder := false asValue. |
|
536 |
hasNilColorHolder onChangeSend:#hasNilColorHolderChanged to:self. |
|
537 |
]. |
|
538 |
^ hasNilColorHolder |
|
539 |
||
3998 | 540 |
"Created: / 24-01-2011 / 19:22:49 / cg" |
3997 | 541 |
! |
542 |
||
3397
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
543 |
labelsAreColored |
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
544 |
"controls if labels or their backgrounds will be colored" |
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
545 |
|
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
546 |
^ labelsAreColored |
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
547 |
! |
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
548 |
|
664 | 549 |
labelsAreColored: aBoolean |
550 |
"sets whether labels or their backgrounds will be colored" |
|
551 |
||
3280 | 552 |
|bool| |
553 |
||
554 |
bool := aBoolean ? false. |
|
664 | 555 |
|
3280 | 556 |
labelsAreColored ~~ bool ifTrue:[ |
557 |
labelsAreColored := bool. |
|
3998 | 558 |
self setupMenu |
3280 | 559 |
]. |
3981 | 560 |
! |
561 |
||
3996 | 562 |
overwriteDefaultToggleChannel |
563 |
overwriteDefaultToggleChannel isNil ifTrue:[ |
|
564 |
overwriteDefaultToggleChannel := false asValue. |
|
565 |
]. |
|
566 |
^ overwriteDefaultToggleChannel |
|
567 |
||
568 |
"Modified: / 23-01-2011 / 16:24:00 / cg" |
|
569 |
! |
|
570 |
||
3981 | 571 |
useDefaultColorToggleVisibleHolder |
572 |
useDefaultColorToggleVisibleHolder isNil ifTrue:[ |
|
573 |
useDefaultColorToggleVisibleHolder := true asValue |
|
574 |
]. |
|
575 |
^ useDefaultColorToggleVisibleHolder |
|
576 |
||
577 |
"Created: / 18-12-2010 / 13:03:48 / cg" |
|
412 | 578 |
! ! |
579 |
||
1818 | 580 |
!ColorMenu methodsFor:'accessing-channels'! |
412 | 581 |
|
582 |
model:aValueHolder |
|
664 | 583 |
"set my color channel" |
584 |
||
2184 | 585 |
super model:aValueHolder. |
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
586 |
model notNil ifTrue:[ |
2186 | 587 |
self updateFromModel |
664 | 588 |
] |
412 | 589 |
! ! |
590 |
||
4003 | 591 |
!ColorMenu methodsFor:'accessing-dimensions'! |
592 |
||
593 |
preferredExtent |
|
594 |
"workaround: will change the preferredExtent !!!! |
|
595 |
same in FontMenu" |
|
596 |
||
597 |
|extent| |
|
598 |
||
599 |
preferredExtent notNil ifTrue:[ |
|
600 |
^ super preferredExtent. |
|
601 |
]. |
|
602 |
extent := super preferredExtent. |
|
603 |
preferredExtent := nil. |
|
604 |
||
605 |
^ extent |
|
606 |
! ! |
|
607 |
||
412 | 608 |
!ColorMenu methodsFor:'change & update'! |
609 |
||
3997 | 610 |
hasNilColorHolderChanged |
3998 | 611 |
self overwriteDefaultToggleChannel value:(self hasNilColorHolder value not). |
4024
86fe84612950
changed: #hasNilColorHolderChanged
Claus Gittinger <cg@exept.de>
parents:
4003
diff
changeset
|
612 |
allowNilColor ifTrue:[ |
86fe84612950
changed: #hasNilColorHolderChanged
Claus Gittinger <cg@exept.de>
parents:
4003
diff
changeset
|
613 |
self hasNilColorHolder value ifTrue:[ |
86fe84612950
changed: #hasNilColorHolderChanged
Claus Gittinger <cg@exept.de>
parents:
4003
diff
changeset
|
614 |
model value:nil withoutNotifying:self |
86fe84612950
changed: #hasNilColorHolderChanged
Claus Gittinger <cg@exept.de>
parents:
4003
diff
changeset
|
615 |
] ifFalse:[ |
86fe84612950
changed: #hasNilColorHolderChanged
Claus Gittinger <cg@exept.de>
parents:
4003
diff
changeset
|
616 |
model value:color withoutNotifying:self |
86fe84612950
changed: #hasNilColorHolderChanged
Claus Gittinger <cg@exept.de>
parents:
4003
diff
changeset
|
617 |
]. |
86fe84612950
changed: #hasNilColorHolderChanged
Claus Gittinger <cg@exept.de>
parents:
4003
diff
changeset
|
618 |
]. |
3997 | 619 |
|
4024
86fe84612950
changed: #hasNilColorHolderChanged
Claus Gittinger <cg@exept.de>
parents:
4003
diff
changeset
|
620 |
"Modified: / 23-03-2011 / 20:02:18 / cg" |
3997 | 621 |
! |
622 |
||
2186 | 623 |
updateFromModel |
3998 | 624 |
self color:(model value) |
412 | 625 |
! ! |
626 |
||
3439 | 627 |
!ColorMenu methodsFor:'help'! |
628 |
||
629 |
flyByHelpSpec |
|
630 |
"This resource specification was automatically generated |
|
631 |
by the UIHelpTool of ST/X." |
|
632 |
||
633 |
"Do not manually edit this!! If it is corrupted, |
|
634 |
the UIHelpTool may not be able to read the specification." |
|
635 |
||
636 |
" |
|
637 |
UIHelpTool openOnClass:ColorEditDialog |
|
638 |
" |
|
639 |
||
640 |
<resource: #help> |
|
641 |
||
642 |
^ super flyByHelpSpec addPairsFrom:#( |
|
643 |
||
644 |
#useDefaultColorToggle |
|
645 |
'Turn on, to specify the color here. Turn off to use the default' |
|
646 |
||
647 |
#toggleSymbolicColor |
|
648 |
'Turn on, to specify a symbolic color. Turn off to specify a concrete color' |
|
649 |
||
650 |
#recentlyUsedColors |
|
651 |
'Recently used colors' |
|
652 |
||
653 |
#openColorEditor |
|
654 |
'Open a color editor' |
|
655 |
||
656 |
#pickColorFromScreen |
|
657 |
'Pick a color from the screen' |
|
658 |
||
659 |
) |
|
660 |
! ! |
|
661 |
||
412 | 662 |
!ColorMenu methodsFor:'initialization'! |
663 |
||
3322 | 664 |
colorHistorySubmenu |
665 |
|menu| |
|
666 |
||
667 |
RecentlyUsedColors isEmptyOrNil ifTrue:[^ nil]. |
|
668 |
||
669 |
menu := Menu new. |
|
670 |
||
3344 | 671 |
RecentlyUsedColors do:[:eachRecentlyUsedColor | |
3322 | 672 |
|label fgColor item| |
673 |
||
3344 | 674 |
eachRecentlyUsedColor isSymbol ifTrue:[ |
675 |
label := eachRecentlyUsedColor . |
|
676 |
] ifFalse:[ |
|
677 |
eachRecentlyUsedColor brightness < 0.5 |
|
678 |
ifTrue:[ fgColor := Color white ] |
|
679 |
ifFalse:[ fgColor := Color black ]. |
|
3322 | 680 |
|
3344 | 681 |
label := eachRecentlyUsedColor htmlPrintString. |
682 |
label := Text string:(' ', label, ' ') foregroundColor:fgColor backgroundColor:eachRecentlyUsedColor. |
|
683 |
]. |
|
684 |
||
3322 | 685 |
item := MenuItem labeled:label. |
3344 | 686 |
item argument:eachRecentlyUsedColor. |
3322 | 687 |
|
688 |
menu addItem:item. |
|
689 |
]. |
|
690 |
||
691 |
^ menu. |
|
692 |
! |
|
693 |
||
412 | 694 |
destroy |
664 | 695 |
"release color channel dependency" |
696 |
||
412 | 697 |
self model:nil. |
664 | 698 |
super destroy |
412 | 699 |
|
700 |
! |
|
701 |
||
702 |
initialize |
|
703 |
super initialize. |
|
3397
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
704 |
labelsAreColored := false. |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
705 |
verticalLayout := false. |
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
706 |
allowSymbolicColors := false. |
4057 | 707 |
allowNilColor := true. |
2254 | 708 |
|
412 | 709 |
self fitFirstPanel:false. |
3996 | 710 |
"/ enabledChannel := ValueHolder with:false. |
3998 | 711 |
self setupMenu. |
895 | 712 |
|
4057 | 713 |
"Modified: / 17-07-2011 / 11:02:07 / cg" |
412 | 714 |
! |
715 |
||
716 |
setupMenu |
|
3707 | 717 |
|menu toggleItem| |
412 | 718 |
|
666 | 719 |
menu := self class colorMenu:labelsAreColored value:nil. |
3280 | 720 |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
721 |
menu |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
722 |
addItem:( |
3322 | 723 |
(MenuItem labeled:nil) |
724 |
labelImage:(ToolbarIconLibrary palette16x16Icon); |
|
4143 | 725 |
itemValue:[ self openColorEditDialog ]; |
3322 | 726 |
nameKey:#pseudoDef; |
3404 | 727 |
activeHelpKey:#openColorEditor; |
728 |
isButton: true) |
|
729 |
beforeIndex:1. |
|
806 | 730 |
|
3322 | 731 |
menu |
732 |
addItem:( |
|
733 |
(MenuItem labeled:nil) |
|
734 |
labelImage:(ToolbarIconLibrary pipette16x16Icon); |
|
4143 | 735 |
itemValue:[ self pickColorFromScreen ]; |
3322 | 736 |
nameKey:#pseudoPick; |
3404 | 737 |
activeHelpKey:#pickColorFromScreen; |
738 |
isButton: true) |
|
739 |
beforeIndex:1. |
|
3322 | 740 |
|
741 |
menu |
|
742 |
addItem:( |
|
743 |
(MenuItem labeled:nil) |
|
3707 | 744 |
labelImage:(ToolbarIconLibrary colorHistory16x16Icon); |
3322 | 745 |
submenuChannel:[ self colorHistorySubmenu ]; |
3401 | 746 |
nameKey:#pseudoHistory; |
3404 | 747 |
activeHelpKey:#recentlyUsedColors; |
3995
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
748 |
isButton: true) |
3322 | 749 |
beforeIndex:1. |
750 |
||
751 |
"/ menu addItem:(MenuItem label:'') beforeIndex:1. |
|
3738 | 752 |
"/ (showDefaultToggle ? true) ifTrue:[ |
753 |
toggleItem := MenuItem labeled:(Text string:' ' emphasis:(#backgroundColor->DefaultViewBackgroundColor)). |
|
4143 | 754 |
toggleItem itemValue:#selection. |
3738 | 755 |
toggleItem isButton: false. |
756 |
toggleItem activeHelpKey:#useDefaultColorToggle. |
|
3981 | 757 |
toggleItem isVisible:(self useDefaultColorToggleVisibleHolder). |
3738 | 758 |
menu addItem:toggleItem beforeIndex:1. |
759 |
"/ ]. |
|
806 | 760 |
|
3997 | 761 |
allowNilColor ifTrue:[ |
762 |
toggleItem := MenuItem labeled:'No Color'. |
|
763 |
toggleItem isButton:false. |
|
764 |
toggleItem activeHelpKey:#noColor. |
|
765 |
toggleItem indication:self hasNilColorHolder. |
|
4143 | 766 |
toggleItem itemValue:#'hasNilColorHolder:'. |
3997 | 767 |
menu addItem:toggleItem. |
768 |
]. |
|
769 |
||
412 | 770 |
self menu:menu. |
3996 | 771 |
self updateEnableChannel |
772 |
||
4143 | 773 |
"Modified: / 09-09-2012 / 13:27:15 / cg" |
3996 | 774 |
! |
775 |
||
776 |
updateEnableChannel |
|
666 | 777 |
self do:[:anItem| |
3404 | 778 |
anItem value == #selection ifTrue:[ |
3996 | 779 |
anItem indication:self overwriteDefaultToggleChannel. |
780 |
"/ anItem enabled:enabledChannel. |
|
666 | 781 |
] ifFalse:[ |
3998 | 782 |
anItem value == #hasNilColorHolder: ifTrue:[ |
3997 | 783 |
] ifFalse:[ |
784 |
anItem enabled:self overwriteDefaultToggleChannel. |
|
785 |
] |
|
412 | 786 |
] |
664 | 787 |
] |
3981 | 788 |
|
3996 | 789 |
"Created: / 23-01-2011 / 16:08:06 / cg" |
3998 | 790 |
"Modified: / 24-01-2011 / 19:35:52 / cg" |
412 | 791 |
! ! |
792 |
||
3406 | 793 |
!ColorMenu methodsFor:'user actions'! |
3322 | 794 |
|
3530 | 795 |
keepColorHolderIndicationAlwaysEnabled |
796 |
self colorHolder indication:true. |
|
797 |
self colorHolder isButton:true. |
|
798 |
! |
|
799 |
||
3322 | 800 |
openColorEditDialog |
801 |
|defineColorDialog| |
|
802 |
||
803 |
defineColorDialog := ColorEditDialog new color: self color. |
|
804 |
defineColorDialog open. |
|
805 |
defineColorDialog accept value ifTrue: [ |
|
3736
1aa04cb6d849
ColorEditDialog was grazy - adapted to changed protocol
Claus Gittinger <cg@exept.de>
parents:
3709
diff
changeset
|
806 |
self color:defineColorDialog colorNameOrColor |
3322 | 807 |
] |
808 |
! |
|
809 |
||
810 |
pickColorFromScreen |
|
811 |
|color| |
|
812 |
||
813 |
color := Color fromUser. |
|
814 |
color notNil ifTrue:[ |
|
815 |
self color:color. |
|
816 |
] |
|
412 | 817 |
! ! |
818 |
||
819 |
!ColorMenu class methodsFor:'documentation'! |
|
820 |
||
3862
754cfd6ed4b5
changed: #addUserDefinedColors:labels:title:
Claus Gittinger <cg@exept.de>
parents:
3738
diff
changeset
|
821 |
version_CVS |
4143 | 822 |
^ '$Header: /cvs/stx/stx/libwidg2/ColorMenu.st,v 1.75 2012-09-09 13:15:43 cg Exp $' |
412 | 823 |
! ! |