author | Claus Gittinger <cg@exept.de> |
Tue, 08 Jul 2014 16:46:49 +0200 | |
changeset 4643 | a658eca5de88 |
parent 4357 | f828b5cb3bc6 |
child 4705 | 63975d17295d |
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 |
||
4156 | 116 |
fgColor := bgColor contrastingBlackOrWhite. |
3292 | 117 |
|
118 |
aTitle isEmptyOrNil ifTrue:[ label := labels at:1 ifAbsent:defLabel ] |
|
119 |
ifFalse:[ label := aTitle ]. |
|
3280 | 120 |
|
3294 | 121 |
label := Text string:(' ', label, ' ') foregroundColor:fgColor backgroundColor:bgColor. |
4357 | 122 |
item := MenuItem label:label. |
3292 | 123 |
submenu addItem:item. |
124 |
||
125 |
size == 1 ifTrue:[ |
|
126 |
item argument:bgColor. |
|
127 |
] ifFalse:[ |
|
128 |
item submenu:(submenu := Menu new). |
|
3280 | 129 |
|
3292 | 130 |
aColors keysAndValuesDo:[:idx :aBgColor| |
4156 | 131 |
fgColor := aBgColor contrastingBlackOrWhite. |
3292 | 132 |
|
133 |
label := labels at:idx ifAbsent:defLabel. |
|
3294 | 134 |
label := Text string:(' ', label, ' ') foregroundColor:fgColor backgroundColor:aBgColor. |
4357 | 135 |
item := MenuItem label:label. |
3293 | 136 |
item argument:aBgColor. |
3292 | 137 |
|
138 |
submenu addItem:item. |
|
139 |
]. |
|
140 |
]. |
|
3280 | 141 |
|
142 |
" |
|
3292 | 143 |
ColorMenu removeAllUserDefinedColors. |
3280 | 144 |
|
3292 | 145 |
#( |
146 |
#( Black 16r000000 ) |
|
147 |
#( Red 16rff0000 ) |
|
148 |
nil |
|
149 |
#( Rust 16rff6600 16rff8533 16rffa366 16rffc299 16rffe0cc ) |
|
150 |
#( Tangerine 16rff9933 16rffad5c 16rffc285 16rffd6ad 16rffebd6 ) |
|
151 |
#( Sunflower 16rffcc00 16rfed633 16rfee066 16rffeb99 16rfff5cc ) |
|
152 |
#( Mango 16rffcc99 16rffd6ad 16rffe0c2 16rffebd6 16rfff5eb ) |
|
153 |
#( Buttercup 16rffff66 16rffff85 16rffffa3 16rffffc2 16rffffe0 ) |
|
154 |
#( Lemon 16rffffcc 16rffffd6 16rffffe0 16rffffeb 16rfffff5 ) |
|
3280 | 155 |
|
3292 | 156 |
) do:[:aDef| |colors title labels percentage| |
157 |
aDef isEmptyOrNil ifTrue:[ |
|
158 |
colors := labels := title := nil. |
|
159 |
] ifFalse:[ |
|
160 |
title := aDef first. |
|
161 |
colors := OrderedCollection new. |
|
162 |
labels := OrderedCollection new. |
|
163 |
percentage := 100. |
|
164 |
||
165 |
aDef from:2 do:[:rgb| |
|
166 |
colors add:(Color rgbValue:rgb). |
|
167 |
labels add:('%1 %2 %%' bindWith:title with:percentage). |
|
168 |
percentage := percentage - 20. |
|
169 |
]. |
|
170 |
]. |
|
171 |
ColorMenu addUserDefinedColors:colors labels:labels title:title. |
|
3280 | 172 |
]. |
3292 | 173 |
" |
3280 | 174 |
! |
175 |
||
3283 | 176 |
removeAllUserDefinedColors |
3322 | 177 |
"flush user defined colors" |
178 |
||
3292 | 179 |
ColorMenuSpec := nil. |
3322 | 180 |
! |
181 |
||
182 |
userDefinedSubmenu |
|
4643 | 183 |
<resource: #programMenu > |
184 |
||
3322 | 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. |
4357 | 195 |
item := MenuItem label:icon. |
3322 | 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 |
4643 | 282 |
<resource: #programMenu > |
283 |
||
3404 | 284 |
|menu menuItem subItem baseColor color label getColSel submenu colorId| |
285 |
||
3707 | 286 |
" |
287 |
ColorMenuSpec := nil |
|
288 |
" |
|
3292 | 289 |
|
3280 | 290 |
ColorMenuSpec notNil ifTrue:[ ^ ColorMenuSpec ]. |
291 |
||
3404 | 292 |
menu := Menu new. |
3280 | 293 |
self colorMenuSpec do:[:aSlice| |
3404 | 294 |
menu addItem:(menuItem := MenuItem new). |
3280 | 295 |
|
296 |
aSlice notNil ifTrue:[ |
|
297 |
colorId := aSlice at:1. |
|
298 |
getColSel := aSlice at:2. |
|
299 |
baseColor := Color perform:colorId. |
|
300 |
||
3323 | 301 |
menuItem label:(Text string:' ' emphasis:(#backgroundColor->baseColor)). |
3280 | 302 |
menuItem submenu:(submenu := Menu new). |
3292 | 303 |
menuItem isButton:true. |
3404 | 304 |
menuItem activeHelpKey:('shadesOf',colorId asUppercaseFirst) asSymbol. |
3280 | 305 |
|
306 |
aSlice last do:[:el| |
|
307 |
color := label := nil. |
|
308 |
||
309 |
el isSymbol ifTrue:[ |
|
3322 | 310 |
el == #veryLight ifTrue:[ |
311 |
color := baseColor lightened lightened |
|
312 |
] ifFalse:[ el == #lightened ifTrue:[ |
|
3996 | 313 |
color := baseColor lightened |
314 |
] ifFalse:[ el == #darkened ifTrue:[ |
|
315 |
color := baseColor darkened |
|
316 |
] ifFalse:[ el == #veryDark ifTrue:[ |
|
317 |
color := baseColor darkened darkened |
|
3322 | 318 |
] ifFalse:[ |
319 |
color := Color perform:el |
|
3996 | 320 |
]]]]. |
3280 | 321 |
colorId == #gray ifTrue:[ label := el ]. |
322 |
] ifFalse:[ |
|
323 |
el isNumber ifTrue:[ |
|
324 |
color := Color perform:getColSel with:el. |
|
325 |
]. |
|
326 |
]. |
|
327 |
color notNil ifTrue:[ |
|
328 |
label isNil ifTrue:[ |
|
329 |
label := getColSel, ' ', el printString. |
|
330 |
]. |
|
3322 | 331 |
subItem := MenuItem label:' ',label,' '. |
3280 | 332 |
subItem argument:color. |
333 |
submenu addItem:subItem. |
|
334 |
]. |
|
335 |
] |
|
336 |
]. |
|
337 |
]. |
|
3404 | 338 |
ColorMenuSpec := menu. |
339 |
^ menu |
|
3996 | 340 |
|
341 |
"Modified: / 23-01-2011 / 16:34:45 / cg" |
|
3280 | 342 |
! |
343 |
||
3995
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
344 |
resolveMenuItem:aMenuItem value:aValue labelsAreColored:labelsAreColored |
4643 | 345 |
<resource: #programMenu > |
346 |
||
3292 | 347 |
|menuItem label color fgColor submenu| |
348 |
||
349 |
label := aMenuItem rawLabel ? ''. |
|
350 |
menuItem := MenuItem label:label. |
|
351 |
menuItem isButton:(aMenuItem isButton). |
|
3404 | 352 |
menuItem activeHelpKey:(aMenuItem activeHelpKey). |
3292 | 353 |
|
354 |
aMenuItem hasSubmenu ifFalse:[ |
|
355 |
color := aMenuItem argument. |
|
356 |
menuItem argument:color. |
|
357 |
||
358 |
(color isColor and:[label isText not]) ifTrue:[ |
|
3995
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
359 |
labelsAreColored ifTrue:[ |
3292 | 360 |
label := Text string:label color:color. |
361 |
] ifFalse:[ |
|
4156 | 362 |
fgColor := color contrastingBlackOrWhite. |
3292 | 363 |
label := Text string:label foregroundColor:fgColor backgroundColor:color. |
364 |
]. |
|
4643 | 365 |
menuItem label:label itemValue:aValue. |
3292 | 366 |
]. |
367 |
^ menuItem |
|
368 |
]. |
|
3995
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
369 |
|
3292 | 370 |
submenu := Menu new. |
371 |
aMenuItem submenu itemsDo:[:el| |
|
3995
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
372 |
submenu addItem:(self resolveMenuItem:el value:aValue labelsAreColored:labelsAreColored). |
3292 | 373 |
]. |
374 |
menuItem submenu:submenu. |
|
375 |
^ menuItem |
|
3995
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
376 |
|
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
377 |
"Created: / 23-01-2011 / 14:59:19 / cg" |
592 | 378 |
! ! |
379 |
||
1808 | 380 |
!ColorMenu methodsFor:'accepting'! |
412 | 381 |
|
4307 | 382 |
accept |
383 |
"must be ignored, as sent by dialogBox's doAccept |
|
384 |
and is defined in superclass to call accept: with nil argument" |
|
385 |
||
386 |
"Created: / 26-07-2013 / 20:43:26 / cg" |
|
387 |
! |
|
388 |
||
412 | 389 |
accept:anItem |
4307 | 390 |
"accept the current selected item (called from my pulldown menus)" |
664 | 391 |
|
4068 | 392 |
|holder colorAccepted| |
412 | 393 |
|
4052 | 394 |
super accept:anItem. |
3738 | 395 |
|
4052 | 396 |
(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
|
397 |
holder := self colorHolder. |
4052 | 398 |
holder == anItem ifTrue:[ |
3996 | 399 |
self overwriteDefaultToggleChannel value ifTrue:[ |
4068 | 400 |
colorAccepted := self color. |
3413
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
401 |
] ifFalse:[ |
4068 | 402 |
holder label:' '. |
4057 | 403 |
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
|
404 |
]. |
3322 | 405 |
] ifFalse:[ |
4052 | 406 |
anItem value == #hasNilColorHolder: ifTrue:[ |
3998 | 407 |
self overwriteDefaultToggleChannel value ifFalse:[ |
408 |
model value:nil withoutNotifying:self |
|
409 |
]. |
|
410 |
] ifFalse:[ |
|
4068 | 411 |
colorAccepted := anItem argument. |
412 |
holder label:(Text string:' ' emphasis:(#backgroundColor->colorAccepted)). |
|
413 |
self chooseColor:colorAccepted. |
|
3998 | 414 |
]. |
412 | 415 |
]. |
4068 | 416 |
self class rememberRecentlyUsedColor:colorAccepted. |
3738 | 417 |
acceptAction notNil ifTrue:[ |
4068 | 418 |
acceptAction value:colorAccepted |
3738 | 419 |
]. |
3322 | 420 |
] |
3996 | 421 |
|
4068 | 422 |
"Modified: / 17-08-2011 / 08:57:12 / cg" |
4307 | 423 |
"Modified (comment): / 26-07-2013 / 20:43:19 / cg" |
3322 | 424 |
! |
425 |
||
3708
de8fd46e5363
changes to use ColorMenu for expecco
Claus Gittinger <cg@exept.de>
parents:
3707
diff
changeset
|
426 |
chooseColor:aColor |
3322 | 427 |
"accept the current selected item" |
428 |
||
3350 | 429 |
(model notNil |
430 |
and:[ model isSymbol not]) ifTrue:[ |
|
3998 | 431 |
model value:aColor. |
3708
de8fd46e5363
changes to use ColorMenu for expecco
Claus Gittinger <cg@exept.de>
parents:
3707
diff
changeset
|
432 |
]. |
3709 | 433 |
color := aColor. |
412 | 434 |
! ! |
435 |
||
436 |
!ColorMenu methodsFor:'accessing'! |
|
437 |
||
3738 | 438 |
acceptAction:something |
439 |
acceptAction := something. |
|
440 |
! |
|
441 |
||
3997 | 442 |
allowNilColor |
443 |
^ allowNilColor |
|
444 |
! |
|
445 |
||
446 |
allowNilColor:aBoolean |
|
447 |
allowNilColor ~~ aBoolean ifTrue:[ |
|
448 |
allowNilColor := aBoolean. |
|
3998 | 449 |
allowNilColor ifTrue:[ |
450 |
self overwriteDefaultToggleChannel value:true. |
|
451 |
self hasNilColorHolder value:(color notNil). |
|
3997 | 452 |
]. |
3998 | 453 |
self setupMenu. |
3997 | 454 |
]. |
455 |
||
456 |
"Created: / 24-01-2011 / 10:02:25 / cg" |
|
3998 | 457 |
"Modified: / 24-01-2011 / 20:06:28 / cg" |
3997 | 458 |
! |
459 |
||
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
460 |
allowSymbolicColors |
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
461 |
^ allowSymbolicColors |
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
462 |
! |
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
463 |
|
3397
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
464 |
allowSymbolicColors:aBoolean |
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
465 |
allowSymbolicColors := aBoolean. |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
466 |
! |
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
467 |
|
412 | 468 |
color |
664 | 469 |
"get current color" |
470 |
||
3998 | 471 |
self overwriteDefaultToggleChannel value ifFalse:[^ nil]. |
472 |
^ color |
|
3997 | 473 |
|
3998 | 474 |
"Modified: / 24-01-2011 / 20:14:27 / cg" |
412 | 475 |
! |
476 |
||
477 |
color:aColor |
|
664 | 478 |
"set current color" |
479 |
||
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
480 |
|label newColor| |
412 | 481 |
|
3998 | 482 |
self hasNilColorHolder setValue:aColor isNil. |
483 |
||
3344 | 484 |
(aColor isColor or:[aColor isSymbol]) ifFalse:[ |
3996 | 485 |
self overwriteDefaultToggleChannel value:false. |
3445 | 486 |
self colorHolder label:' '. |
3998 | 487 |
(aColor isNil and:[allowNilColor]) ifTrue:[ |
488 |
self chooseColor:aColor |
|
489 |
] |
|
2184 | 490 |
] ifTrue:[ |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
491 |
newColor := aColor. |
3344 | 492 |
aColor isSymbol ifTrue:[ |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
493 |
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
|
494 |
label := aColor. |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
495 |
] 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
|
496 |
"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
|
497 |
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
|
498 |
(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
|
499 |
|
edde712ea6ed
If allowSymbolicColors is false, do not allow 'color names' like halt or error.
Stefan Vogel <sv@exept.de>
parents:
3406
diff
changeset
|
500 |
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
|
501 |
]. |
3412
edde712ea6ed
If allowSymbolicColors is false, do not allow 'color names' like halt or error.
Stefan Vogel <sv@exept.de>
parents:
3406
diff
changeset
|
502 |
]. |
edde712ea6ed
If allowSymbolicColors is false, do not allow 'color names' like halt or error.
Stefan Vogel <sv@exept.de>
parents:
3406
diff
changeset
|
503 |
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
|
504 |
"show the selected color in the label" |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
505 |
label := Text string: ' ' emphasis:(#backgroundColor->newColor). |
3344 | 506 |
]. |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
507 |
color := newColor. |
3344 | 508 |
self disabledRedrawDo:[ |
3996 | 509 |
self overwriteDefaultToggleChannel value:true. |
3344 | 510 |
self colorHolder label:label. |
3708
de8fd46e5363
changes to use ColorMenu for expecco
Claus Gittinger <cg@exept.de>
parents:
3707
diff
changeset
|
511 |
self chooseColor:aColor |
3344 | 512 |
] |
412 | 513 |
] |
3996 | 514 |
|
3998 | 515 |
"Modified: / 24-01-2011 / 20:09:39 / cg" |
664 | 516 |
! |
517 |
||
3406 | 518 |
colorHolder |
519 |
"returns the item which keeps the selected color in its label" |
|
520 |
||
3738 | 521 |
^ self itemAt:#selection |
3406 | 522 |
! |
523 |
||
3698 | 524 |
contents |
525 |
^ self color |
|
526 |
! |
|
527 |
||
3996 | 528 |
enableChannel:aValueHolder |
529 |
super enableChannel:aValueHolder. |
|
530 |
self updateEnableChannel |
|
531 |
||
532 |
"Created: / 23-01-2011 / 16:08:52 / cg" |
|
533 |
! |
|
534 |
||
3981 | 535 |
enabledChannel |
3996 | 536 |
^ self overwriteDefaultToggleChannel |
537 |
"/ ^ enabledChannel |
|
538 |
||
539 |
"Modified: / 23-01-2011 / 16:24:12 / cg" |
|
3981 | 540 |
! |
541 |
||
3997 | 542 |
hasNilColorHolder |
543 |
hasNilColorHolder isNil ifTrue:[ |
|
544 |
hasNilColorHolder := false asValue. |
|
545 |
hasNilColorHolder onChangeSend:#hasNilColorHolderChanged to:self. |
|
546 |
]. |
|
547 |
^ hasNilColorHolder |
|
548 |
||
3998 | 549 |
"Created: / 24-01-2011 / 19:22:49 / cg" |
3997 | 550 |
! |
551 |
||
3397
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
552 |
labelsAreColored |
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
553 |
"controls if labels or their backgrounds will be colored" |
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
554 |
|
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
555 |
^ labelsAreColored |
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
556 |
! |
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
557 |
|
664 | 558 |
labelsAreColored: aBoolean |
559 |
"sets whether labels or their backgrounds will be colored" |
|
560 |
||
3280 | 561 |
|bool| |
562 |
||
563 |
bool := aBoolean ? false. |
|
664 | 564 |
|
3280 | 565 |
labelsAreColored ~~ bool ifTrue:[ |
566 |
labelsAreColored := bool. |
|
3998 | 567 |
self setupMenu |
3280 | 568 |
]. |
3981 | 569 |
! |
570 |
||
3996 | 571 |
overwriteDefaultToggleChannel |
572 |
overwriteDefaultToggleChannel isNil ifTrue:[ |
|
573 |
overwriteDefaultToggleChannel := false asValue. |
|
574 |
]. |
|
575 |
^ overwriteDefaultToggleChannel |
|
576 |
||
577 |
"Modified: / 23-01-2011 / 16:24:00 / cg" |
|
578 |
! |
|
579 |
||
3981 | 580 |
useDefaultColorToggleVisibleHolder |
581 |
useDefaultColorToggleVisibleHolder isNil ifTrue:[ |
|
582 |
useDefaultColorToggleVisibleHolder := true asValue |
|
583 |
]. |
|
584 |
^ useDefaultColorToggleVisibleHolder |
|
585 |
||
586 |
"Created: / 18-12-2010 / 13:03:48 / cg" |
|
412 | 587 |
! ! |
588 |
||
1818 | 589 |
!ColorMenu methodsFor:'accessing-channels'! |
412 | 590 |
|
591 |
model:aValueHolder |
|
664 | 592 |
"set my color channel" |
593 |
||
2184 | 594 |
super model:aValueHolder. |
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
595 |
model notNil ifTrue:[ |
2186 | 596 |
self updateFromModel |
664 | 597 |
] |
412 | 598 |
! ! |
599 |
||
4003 | 600 |
!ColorMenu methodsFor:'accessing-dimensions'! |
601 |
||
602 |
preferredExtent |
|
603 |
"workaround: will change the preferredExtent !!!! |
|
604 |
same in FontMenu" |
|
605 |
||
606 |
|extent| |
|
607 |
||
608 |
preferredExtent notNil ifTrue:[ |
|
609 |
^ super preferredExtent. |
|
610 |
]. |
|
611 |
extent := super preferredExtent. |
|
612 |
preferredExtent := nil. |
|
613 |
||
614 |
^ extent |
|
615 |
! ! |
|
616 |
||
412 | 617 |
!ColorMenu methodsFor:'change & update'! |
618 |
||
3997 | 619 |
hasNilColorHolderChanged |
3998 | 620 |
self overwriteDefaultToggleChannel value:(self hasNilColorHolder value not). |
4024
86fe84612950
changed: #hasNilColorHolderChanged
Claus Gittinger <cg@exept.de>
parents:
4003
diff
changeset
|
621 |
allowNilColor ifTrue:[ |
86fe84612950
changed: #hasNilColorHolderChanged
Claus Gittinger <cg@exept.de>
parents:
4003
diff
changeset
|
622 |
self hasNilColorHolder value ifTrue:[ |
86fe84612950
changed: #hasNilColorHolderChanged
Claus Gittinger <cg@exept.de>
parents:
4003
diff
changeset
|
623 |
model value:nil withoutNotifying:self |
86fe84612950
changed: #hasNilColorHolderChanged
Claus Gittinger <cg@exept.de>
parents:
4003
diff
changeset
|
624 |
] ifFalse:[ |
86fe84612950
changed: #hasNilColorHolderChanged
Claus Gittinger <cg@exept.de>
parents:
4003
diff
changeset
|
625 |
model value:color withoutNotifying:self |
86fe84612950
changed: #hasNilColorHolderChanged
Claus Gittinger <cg@exept.de>
parents:
4003
diff
changeset
|
626 |
]. |
86fe84612950
changed: #hasNilColorHolderChanged
Claus Gittinger <cg@exept.de>
parents:
4003
diff
changeset
|
627 |
]. |
3997 | 628 |
|
4024
86fe84612950
changed: #hasNilColorHolderChanged
Claus Gittinger <cg@exept.de>
parents:
4003
diff
changeset
|
629 |
"Modified: / 23-03-2011 / 20:02:18 / cg" |
3997 | 630 |
! |
631 |
||
2186 | 632 |
updateFromModel |
3998 | 633 |
self color:(model value) |
412 | 634 |
! ! |
635 |
||
3439 | 636 |
!ColorMenu methodsFor:'help'! |
637 |
||
638 |
flyByHelpSpec |
|
639 |
"This resource specification was automatically generated |
|
640 |
by the UIHelpTool of ST/X." |
|
641 |
||
642 |
"Do not manually edit this!! If it is corrupted, |
|
643 |
the UIHelpTool may not be able to read the specification." |
|
644 |
||
645 |
" |
|
646 |
UIHelpTool openOnClass:ColorEditDialog |
|
647 |
" |
|
648 |
||
649 |
<resource: #help> |
|
650 |
||
651 |
^ super flyByHelpSpec addPairsFrom:#( |
|
652 |
||
653 |
#useDefaultColorToggle |
|
654 |
'Turn on, to specify the color here. Turn off to use the default' |
|
655 |
||
656 |
#toggleSymbolicColor |
|
657 |
'Turn on, to specify a symbolic color. Turn off to specify a concrete color' |
|
658 |
||
659 |
#recentlyUsedColors |
|
660 |
'Recently used colors' |
|
661 |
||
662 |
#openColorEditor |
|
663 |
'Open a color editor' |
|
664 |
||
665 |
#pickColorFromScreen |
|
666 |
'Pick a color from the screen' |
|
667 |
||
668 |
) |
|
669 |
! ! |
|
670 |
||
412 | 671 |
!ColorMenu methodsFor:'initialization'! |
672 |
||
3322 | 673 |
colorHistorySubmenu |
4643 | 674 |
<resource: #programMenu > |
675 |
||
3322 | 676 |
|menu| |
677 |
||
678 |
RecentlyUsedColors isEmptyOrNil ifTrue:[^ nil]. |
|
679 |
||
680 |
menu := Menu new. |
|
681 |
||
3344 | 682 |
RecentlyUsedColors do:[:eachRecentlyUsedColor | |
3322 | 683 |
|label fgColor item| |
684 |
||
3344 | 685 |
eachRecentlyUsedColor isSymbol ifTrue:[ |
686 |
label := eachRecentlyUsedColor . |
|
687 |
] ifFalse:[ |
|
4156 | 688 |
fgColor := eachRecentlyUsedColor contrastingBlackOrWhite. |
3322 | 689 |
|
3344 | 690 |
label := eachRecentlyUsedColor htmlPrintString. |
691 |
label := Text string:(' ', label, ' ') foregroundColor:fgColor backgroundColor:eachRecentlyUsedColor. |
|
692 |
]. |
|
693 |
||
4357 | 694 |
item := MenuItem label:label. |
3344 | 695 |
item argument:eachRecentlyUsedColor. |
3322 | 696 |
|
697 |
menu addItem:item. |
|
698 |
]. |
|
699 |
||
700 |
^ menu. |
|
701 |
! |
|
702 |
||
412 | 703 |
destroy |
664 | 704 |
"release color channel dependency" |
705 |
||
412 | 706 |
self model:nil. |
664 | 707 |
super destroy |
412 | 708 |
|
709 |
! |
|
710 |
||
711 |
initialize |
|
712 |
super initialize. |
|
3397
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
713 |
labelsAreColored := false. |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
714 |
verticalLayout := false. |
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
715 |
allowSymbolicColors := false. |
4057 | 716 |
allowNilColor := true. |
2254 | 717 |
|
412 | 718 |
self fitFirstPanel:false. |
3996 | 719 |
"/ enabledChannel := ValueHolder with:false. |
3998 | 720 |
self setupMenu. |
895 | 721 |
|
4057 | 722 |
"Modified: / 17-07-2011 / 11:02:07 / cg" |
412 | 723 |
! |
724 |
||
725 |
setupMenu |
|
3707 | 726 |
|menu toggleItem| |
412 | 727 |
|
666 | 728 |
menu := self class colorMenu:labelsAreColored value:nil. |
3280 | 729 |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
730 |
menu |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
731 |
addItem:( |
4357 | 732 |
(MenuItem |
733 |
label:nil |
|
734 |
itemValue:[ self openColorEditDialog ] |
|
735 |
) |
|
3322 | 736 |
labelImage:(ToolbarIconLibrary palette16x16Icon); |
737 |
nameKey:#pseudoDef; |
|
3404 | 738 |
activeHelpKey:#openColorEditor; |
739 |
isButton: true) |
|
740 |
beforeIndex:1. |
|
806 | 741 |
|
3322 | 742 |
menu |
743 |
addItem:( |
|
4357 | 744 |
(MenuItem |
745 |
label:nil |
|
746 |
itemValue:[ self pickColorFromScreen ] |
|
747 |
) |
|
3322 | 748 |
labelImage:(ToolbarIconLibrary pipette16x16Icon); |
749 |
nameKey:#pseudoPick; |
|
3404 | 750 |
activeHelpKey:#pickColorFromScreen; |
751 |
isButton: true) |
|
752 |
beforeIndex:1. |
|
3322 | 753 |
|
754 |
menu |
|
755 |
addItem:( |
|
4357 | 756 |
(MenuItem |
757 |
label:nil |
|
758 |
submenuChannel:[ self colorHistorySubmenu ] |
|
759 |
) |
|
3707 | 760 |
labelImage:(ToolbarIconLibrary colorHistory16x16Icon); |
3401 | 761 |
nameKey:#pseudoHistory; |
3404 | 762 |
activeHelpKey:#recentlyUsedColors; |
3995
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
763 |
isButton: true) |
3322 | 764 |
beforeIndex:1. |
765 |
||
766 |
"/ menu addItem:(MenuItem label:'') beforeIndex:1. |
|
3738 | 767 |
"/ (showDefaultToggle ? true) ifTrue:[ |
4357 | 768 |
toggleItem := MenuItem |
769 |
label:(Text string:' ' emphasis:(#backgroundColor->DefaultViewBackgroundColor)) |
|
770 |
itemValue:#selection. |
|
3738 | 771 |
toggleItem isButton: false. |
772 |
toggleItem activeHelpKey:#useDefaultColorToggle. |
|
3981 | 773 |
toggleItem isVisible:(self useDefaultColorToggleVisibleHolder). |
3738 | 774 |
menu addItem:toggleItem beforeIndex:1. |
775 |
"/ ]. |
|
806 | 776 |
|
3997 | 777 |
allowNilColor ifTrue:[ |
4357 | 778 |
toggleItem := MenuItem |
779 |
label:'No Color' |
|
780 |
itemValue:#'hasNilColorHolder:'. |
|
3997 | 781 |
toggleItem isButton:false. |
782 |
toggleItem activeHelpKey:#noColor. |
|
783 |
toggleItem indication:self hasNilColorHolder. |
|
784 |
menu addItem:toggleItem. |
|
785 |
]. |
|
786 |
||
412 | 787 |
self menu:menu. |
3996 | 788 |
self updateEnableChannel |
789 |
||
4143 | 790 |
"Modified: / 09-09-2012 / 13:27:15 / cg" |
3996 | 791 |
! |
792 |
||
793 |
updateEnableChannel |
|
666 | 794 |
self do:[:anItem| |
3404 | 795 |
anItem value == #selection ifTrue:[ |
3996 | 796 |
anItem indication:self overwriteDefaultToggleChannel. |
797 |
"/ anItem enabled:enabledChannel. |
|
666 | 798 |
] ifFalse:[ |
3998 | 799 |
anItem value == #hasNilColorHolder: ifTrue:[ |
3997 | 800 |
] ifFalse:[ |
801 |
anItem enabled:self overwriteDefaultToggleChannel. |
|
802 |
] |
|
412 | 803 |
] |
664 | 804 |
] |
3981 | 805 |
|
3996 | 806 |
"Created: / 23-01-2011 / 16:08:06 / cg" |
3998 | 807 |
"Modified: / 24-01-2011 / 19:35:52 / cg" |
412 | 808 |
! ! |
809 |
||
3406 | 810 |
!ColorMenu methodsFor:'user actions'! |
3322 | 811 |
|
3530 | 812 |
keepColorHolderIndicationAlwaysEnabled |
813 |
self colorHolder indication:true. |
|
814 |
self colorHolder isButton:true. |
|
815 |
! |
|
816 |
||
3322 | 817 |
openColorEditDialog |
818 |
|defineColorDialog| |
|
819 |
||
820 |
defineColorDialog := ColorEditDialog new color: self color. |
|
821 |
defineColorDialog open. |
|
822 |
defineColorDialog accept value ifTrue: [ |
|
3736
1aa04cb6d849
ColorEditDialog was grazy - adapted to changed protocol
Claus Gittinger <cg@exept.de>
parents:
3709
diff
changeset
|
823 |
self color:defineColorDialog colorNameOrColor |
3322 | 824 |
] |
825 |
! |
|
826 |
||
827 |
pickColorFromScreen |
|
828 |
|color| |
|
829 |
||
830 |
color := Color fromUser. |
|
831 |
color notNil ifTrue:[ |
|
832 |
self color:color. |
|
833 |
] |
|
412 | 834 |
! ! |
835 |
||
836 |
!ColorMenu class methodsFor:'documentation'! |
|
837 |
||
3862
754cfd6ed4b5
changed: #addUserDefinedColors:labels:title:
Claus Gittinger <cg@exept.de>
parents:
3738
diff
changeset
|
838 |
version_CVS |
4643 | 839 |
^ '$Header: /cvs/stx/stx/libwidg2/ColorMenu.st,v 1.79 2014-07-08 14:46:49 cg Exp $' |
412 | 840 |
! ! |
4307 | 841 |