author | Claus Gittinger <cg@exept.de> |
Mon, 24 Jan 2011 20:35:06 +0100 | |
changeset 3998 | b0ef8a3d446c |
parent 3997 | 35c107962304 |
child 4003 | ed34e80d3840 |
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. |
|
364 |
menuItem value:aValue. |
|
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 |
|
412 | 384 |
|item holder color| |
385 |
||
3413
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
386 |
item := super accept:anItem. |
3738 | 387 |
|
3413
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
388 |
(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
|
389 |
holder := self colorHolder. |
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
390 |
holder == item ifTrue:[ |
3996 | 391 |
self overwriteDefaultToggleChannel value ifTrue:[ |
3413
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
392 |
color := self color. |
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
393 |
] ifFalse:[ |
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
394 |
holder label:(Text string:' '). |
c7be2e00d9bc
Bug D000092: if mark is switched off, show transparent background
Stefan Vogel <sv@exept.de>
parents:
3412
diff
changeset
|
395 |
]. |
3322 | 396 |
] ifFalse:[ |
3998 | 397 |
item value == #hasNilColorHolder: ifTrue:[ |
398 |
self overwriteDefaultToggleChannel value ifFalse:[ |
|
399 |
model value:nil withoutNotifying:self |
|
400 |
]. |
|
401 |
] ifFalse:[ |
|
402 |
color := item argument. |
|
403 |
holder label:(Text string:' ' emphasis:(#backgroundColor->color)). |
|
404 |
self chooseColor:color. |
|
405 |
]. |
|
412 | 406 |
]. |
3709 | 407 |
self class rememberRecentlyUsedColor:color. |
3738 | 408 |
acceptAction notNil ifTrue:[ |
409 |
acceptAction value:color |
|
410 |
]. |
|
3322 | 411 |
] |
3996 | 412 |
|
3998 | 413 |
"Modified: / 24-01-2011 / 20:22:07 / cg" |
3322 | 414 |
! |
415 |
||
3708
de8fd46e5363
changes to use ColorMenu for expecco
Claus Gittinger <cg@exept.de>
parents:
3707
diff
changeset
|
416 |
chooseColor:aColor |
3322 | 417 |
"accept the current selected item" |
418 |
||
3350 | 419 |
(model notNil |
420 |
and:[ model isSymbol not]) ifTrue:[ |
|
3998 | 421 |
model value:aColor. |
3708
de8fd46e5363
changes to use ColorMenu for expecco
Claus Gittinger <cg@exept.de>
parents:
3707
diff
changeset
|
422 |
]. |
3709 | 423 |
color := aColor. |
412 | 424 |
! ! |
425 |
||
426 |
!ColorMenu methodsFor:'accessing'! |
|
427 |
||
3738 | 428 |
acceptAction:something |
429 |
acceptAction := something. |
|
430 |
! |
|
431 |
||
3997 | 432 |
allowNilColor |
433 |
^ allowNilColor |
|
434 |
! |
|
435 |
||
436 |
allowNilColor:aBoolean |
|
437 |
allowNilColor ~~ aBoolean ifTrue:[ |
|
438 |
allowNilColor := aBoolean. |
|
3998 | 439 |
allowNilColor ifTrue:[ |
440 |
self overwriteDefaultToggleChannel value:true. |
|
441 |
self hasNilColorHolder value:(color notNil). |
|
3997 | 442 |
]. |
3998 | 443 |
self setupMenu. |
3997 | 444 |
]. |
445 |
||
446 |
"Created: / 24-01-2011 / 10:02:25 / cg" |
|
3998 | 447 |
"Modified: / 24-01-2011 / 20:06:28 / cg" |
3997 | 448 |
! |
449 |
||
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
450 |
allowSymbolicColors |
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 |
! |
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
453 |
|
3397
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
454 |
allowSymbolicColors:aBoolean |
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
455 |
allowSymbolicColors := aBoolean. |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
456 |
! |
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
457 |
|
412 | 458 |
color |
664 | 459 |
"get current color" |
460 |
||
3998 | 461 |
self overwriteDefaultToggleChannel value ifFalse:[^ nil]. |
462 |
^ color |
|
3997 | 463 |
|
3998 | 464 |
"Modified: / 24-01-2011 / 20:14:27 / cg" |
412 | 465 |
! |
466 |
||
467 |
color:aColor |
|
664 | 468 |
"set current color" |
469 |
||
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
470 |
|label newColor| |
412 | 471 |
|
3998 | 472 |
self hasNilColorHolder setValue:aColor isNil. |
473 |
||
3344 | 474 |
(aColor isColor or:[aColor isSymbol]) ifFalse:[ |
3996 | 475 |
self overwriteDefaultToggleChannel value:false. |
3445 | 476 |
self colorHolder label:' '. |
3998 | 477 |
(aColor isNil and:[allowNilColor]) ifTrue:[ |
478 |
self chooseColor:aColor |
|
479 |
] |
|
2184 | 480 |
] ifTrue:[ |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
481 |
newColor := aColor. |
3344 | 482 |
aColor isSymbol ifTrue:[ |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
483 |
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
|
484 |
label := aColor. |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
485 |
] 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
|
486 |
"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
|
487 |
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
|
488 |
(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
|
489 |
|
edde712ea6ed
If allowSymbolicColors is false, do not allow 'color names' like halt or error.
Stefan Vogel <sv@exept.de>
parents:
3406
diff
changeset
|
490 |
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
|
491 |
]. |
3412
edde712ea6ed
If allowSymbolicColors is false, do not allow 'color names' like halt or error.
Stefan Vogel <sv@exept.de>
parents:
3406
diff
changeset
|
492 |
]. |
edde712ea6ed
If allowSymbolicColors is false, do not allow 'color names' like halt or error.
Stefan Vogel <sv@exept.de>
parents:
3406
diff
changeset
|
493 |
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
|
494 |
"show the selected color in the label" |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
495 |
label := Text string: ' ' emphasis:(#backgroundColor->newColor). |
3344 | 496 |
]. |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
497 |
color := newColor. |
3344 | 498 |
self disabledRedrawDo:[ |
3996 | 499 |
self overwriteDefaultToggleChannel value:true. |
3344 | 500 |
self colorHolder label:label. |
3708
de8fd46e5363
changes to use ColorMenu for expecco
Claus Gittinger <cg@exept.de>
parents:
3707
diff
changeset
|
501 |
self chooseColor:aColor |
3344 | 502 |
] |
412 | 503 |
] |
3996 | 504 |
|
3998 | 505 |
"Modified: / 24-01-2011 / 20:09:39 / cg" |
664 | 506 |
! |
507 |
||
3406 | 508 |
colorHolder |
509 |
"returns the item which keeps the selected color in its label" |
|
510 |
||
3738 | 511 |
^ self itemAt:#selection |
3406 | 512 |
! |
513 |
||
3698 | 514 |
contents |
515 |
^ self color |
|
516 |
! |
|
517 |
||
3996 | 518 |
enableChannel:aValueHolder |
519 |
super enableChannel:aValueHolder. |
|
520 |
self updateEnableChannel |
|
521 |
||
522 |
"Created: / 23-01-2011 / 16:08:52 / cg" |
|
523 |
! |
|
524 |
||
3981 | 525 |
enabledChannel |
3996 | 526 |
^ self overwriteDefaultToggleChannel |
527 |
"/ ^ enabledChannel |
|
528 |
||
529 |
"Modified: / 23-01-2011 / 16:24:12 / cg" |
|
3981 | 530 |
! |
531 |
||
3997 | 532 |
hasNilColorHolder |
533 |
hasNilColorHolder isNil ifTrue:[ |
|
534 |
hasNilColorHolder := false asValue. |
|
535 |
hasNilColorHolder onChangeSend:#hasNilColorHolderChanged to:self. |
|
536 |
]. |
|
537 |
^ hasNilColorHolder |
|
538 |
||
3998 | 539 |
"Created: / 24-01-2011 / 19:22:49 / cg" |
3997 | 540 |
! |
541 |
||
3397
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
542 |
labelsAreColored |
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
543 |
"controls if labels or their backgrounds will be colored" |
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
544 |
|
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
545 |
^ labelsAreColored |
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
546 |
! |
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
547 |
|
664 | 548 |
labelsAreColored: aBoolean |
549 |
"sets whether labels or their backgrounds will be colored" |
|
550 |
||
3280 | 551 |
|bool| |
552 |
||
553 |
bool := aBoolean ? false. |
|
664 | 554 |
|
3280 | 555 |
labelsAreColored ~~ bool ifTrue:[ |
556 |
labelsAreColored := bool. |
|
3998 | 557 |
self setupMenu |
3280 | 558 |
]. |
3981 | 559 |
! |
560 |
||
3996 | 561 |
overwriteDefaultToggleChannel |
562 |
overwriteDefaultToggleChannel isNil ifTrue:[ |
|
563 |
overwriteDefaultToggleChannel := false asValue. |
|
564 |
]. |
|
565 |
^ overwriteDefaultToggleChannel |
|
566 |
||
567 |
"Modified: / 23-01-2011 / 16:24:00 / cg" |
|
568 |
! |
|
569 |
||
3981 | 570 |
useDefaultColorToggleVisibleHolder |
571 |
useDefaultColorToggleVisibleHolder isNil ifTrue:[ |
|
572 |
useDefaultColorToggleVisibleHolder := true asValue |
|
573 |
]. |
|
574 |
^ useDefaultColorToggleVisibleHolder |
|
575 |
||
576 |
"Created: / 18-12-2010 / 13:03:48 / cg" |
|
412 | 577 |
! ! |
578 |
||
1818 | 579 |
!ColorMenu methodsFor:'accessing-channels'! |
412 | 580 |
|
581 |
model:aValueHolder |
|
664 | 582 |
"set my color channel" |
583 |
||
2184 | 584 |
super model:aValueHolder. |
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
585 |
model notNil ifTrue:[ |
2186 | 586 |
self updateFromModel |
664 | 587 |
] |
412 | 588 |
! ! |
589 |
||
590 |
!ColorMenu methodsFor:'change & update'! |
|
591 |
||
3997 | 592 |
hasNilColorHolderChanged |
3998 | 593 |
self overwriteDefaultToggleChannel value:(self hasNilColorHolder value not). |
594 |
"/ self hasNilColorHolder value ifTrue:[ |
|
595 |
"/ self color:nil |
|
596 |
"/ ]. |
|
3997 | 597 |
|
3998 | 598 |
"Modified: / 24-01-2011 / 20:14:01 / cg" |
3997 | 599 |
! |
600 |
||
2186 | 601 |
updateFromModel |
3998 | 602 |
self color:(model value) |
412 | 603 |
! ! |
604 |
||
3439 | 605 |
!ColorMenu methodsFor:'help'! |
606 |
||
607 |
flyByHelpSpec |
|
608 |
"This resource specification was automatically generated |
|
609 |
by the UIHelpTool of ST/X." |
|
610 |
||
611 |
"Do not manually edit this!! If it is corrupted, |
|
612 |
the UIHelpTool may not be able to read the specification." |
|
613 |
||
614 |
" |
|
615 |
UIHelpTool openOnClass:ColorEditDialog |
|
616 |
" |
|
617 |
||
618 |
<resource: #help> |
|
619 |
||
620 |
^ super flyByHelpSpec addPairsFrom:#( |
|
621 |
||
622 |
#useDefaultColorToggle |
|
623 |
'Turn on, to specify the color here. Turn off to use the default' |
|
624 |
||
625 |
#toggleSymbolicColor |
|
626 |
'Turn on, to specify a symbolic color. Turn off to specify a concrete color' |
|
627 |
||
628 |
#recentlyUsedColors |
|
629 |
'Recently used colors' |
|
630 |
||
631 |
#openColorEditor |
|
632 |
'Open a color editor' |
|
633 |
||
634 |
#pickColorFromScreen |
|
635 |
'Pick a color from the screen' |
|
636 |
||
637 |
) |
|
638 |
! ! |
|
639 |
||
412 | 640 |
!ColorMenu methodsFor:'initialization'! |
641 |
||
3322 | 642 |
colorHistorySubmenu |
643 |
|menu| |
|
644 |
||
645 |
RecentlyUsedColors isEmptyOrNil ifTrue:[^ nil]. |
|
646 |
||
647 |
menu := Menu new. |
|
648 |
||
3344 | 649 |
RecentlyUsedColors do:[:eachRecentlyUsedColor | |
3322 | 650 |
|label fgColor item| |
651 |
||
3344 | 652 |
eachRecentlyUsedColor isSymbol ifTrue:[ |
653 |
label := eachRecentlyUsedColor . |
|
654 |
] ifFalse:[ |
|
655 |
eachRecentlyUsedColor brightness < 0.5 |
|
656 |
ifTrue:[ fgColor := Color white ] |
|
657 |
ifFalse:[ fgColor := Color black ]. |
|
3322 | 658 |
|
3344 | 659 |
label := eachRecentlyUsedColor htmlPrintString. |
660 |
label := Text string:(' ', label, ' ') foregroundColor:fgColor backgroundColor:eachRecentlyUsedColor. |
|
661 |
]. |
|
662 |
||
3322 | 663 |
item := MenuItem labeled:label. |
3344 | 664 |
item argument:eachRecentlyUsedColor. |
3322 | 665 |
|
666 |
menu addItem:item. |
|
667 |
]. |
|
668 |
||
669 |
^ menu. |
|
670 |
! |
|
671 |
||
412 | 672 |
destroy |
664 | 673 |
"release color channel dependency" |
674 |
||
412 | 675 |
self model:nil. |
664 | 676 |
super destroy |
412 | 677 |
|
678 |
! |
|
679 |
||
680 |
initialize |
|
681 |
super initialize. |
|
3397
e2ed0ef2c908
default for labelsAreColored is FALSE
Claus Gittinger <cg@exept.de>
parents:
3350
diff
changeset
|
682 |
labelsAreColored := false. |
3349
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
683 |
verticalLayout := false. |
fb7d0dea3876
Configure wether symbolic colors are allowed
Stefan Vogel <sv@exept.de>
parents:
3348
diff
changeset
|
684 |
allowSymbolicColors := false. |
3997 | 685 |
allowNilColor := false. |
2254 | 686 |
|
412 | 687 |
self fitFirstPanel:false. |
3996 | 688 |
"/ enabledChannel := ValueHolder with:false. |
3998 | 689 |
self setupMenu. |
895 | 690 |
|
3998 | 691 |
"Modified: / 24-01-2011 / 19:20:55 / cg" |
412 | 692 |
! |
693 |
||
694 |
setupMenu |
|
3707 | 695 |
|menu toggleItem| |
412 | 696 |
|
666 | 697 |
menu := self class colorMenu:labelsAreColored value:nil. |
3280 | 698 |
|
2183
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
699 |
menu |
5c69691590eb
code cleanup; now inherit model instVar.
Claus Gittinger <cg@exept.de>
parents:
2167
diff
changeset
|
700 |
addItem:( |
3322 | 701 |
(MenuItem labeled:nil) |
702 |
labelImage:(ToolbarIconLibrary palette16x16Icon); |
|
703 |
value:[ self openColorEditDialog ]; |
|
704 |
nameKey:#pseudoDef; |
|
3404 | 705 |
activeHelpKey:#openColorEditor; |
706 |
isButton: true) |
|
707 |
beforeIndex:1. |
|
806 | 708 |
|
3322 | 709 |
menu |
710 |
addItem:( |
|
711 |
(MenuItem labeled:nil) |
|
712 |
labelImage:(ToolbarIconLibrary pipette16x16Icon); |
|
713 |
value:[ self pickColorFromScreen ]; |
|
714 |
nameKey:#pseudoPick; |
|
3404 | 715 |
activeHelpKey:#pickColorFromScreen; |
716 |
isButton: true) |
|
717 |
beforeIndex:1. |
|
3322 | 718 |
|
719 |
menu |
|
720 |
addItem:( |
|
721 |
(MenuItem labeled:nil) |
|
3707 | 722 |
labelImage:(ToolbarIconLibrary colorHistory16x16Icon); |
3322 | 723 |
submenuChannel:[ self colorHistorySubmenu ]; |
3401 | 724 |
nameKey:#pseudoHistory; |
3404 | 725 |
activeHelpKey:#recentlyUsedColors; |
3995
4917660dba28
added: #resolveMenuItem:value:labelsAreColored:
Claus Gittinger <cg@exept.de>
parents:
3981
diff
changeset
|
726 |
isButton: true) |
3322 | 727 |
beforeIndex:1. |
728 |
||
729 |
"/ menu addItem:(MenuItem label:'') beforeIndex:1. |
|
3738 | 730 |
"/ (showDefaultToggle ? true) ifTrue:[ |
731 |
toggleItem := MenuItem labeled:(Text string:' ' emphasis:(#backgroundColor->DefaultViewBackgroundColor)). |
|
732 |
toggleItem value:#selection. |
|
733 |
toggleItem isButton: false. |
|
734 |
toggleItem activeHelpKey:#useDefaultColorToggle. |
|
3981 | 735 |
toggleItem isVisible:(self useDefaultColorToggleVisibleHolder). |
3738 | 736 |
menu addItem:toggleItem beforeIndex:1. |
737 |
"/ ]. |
|
806 | 738 |
|
3997 | 739 |
allowNilColor ifTrue:[ |
740 |
toggleItem := MenuItem labeled:'No Color'. |
|
741 |
toggleItem isButton:false. |
|
742 |
toggleItem activeHelpKey:#noColor. |
|
743 |
toggleItem indication:self hasNilColorHolder. |
|
3998 | 744 |
toggleItem value:#'hasNilColorHolder:'. |
3997 | 745 |
menu addItem:toggleItem. |
746 |
]. |
|
747 |
||
412 | 748 |
self menu:menu. |
3996 | 749 |
self updateEnableChannel |
750 |
||
3998 | 751 |
"Modified: / 24-01-2011 / 19:35:23 / cg" |
3996 | 752 |
! |
753 |
||
754 |
updateEnableChannel |
|
666 | 755 |
self do:[:anItem| |
3404 | 756 |
anItem value == #selection ifTrue:[ |
3996 | 757 |
anItem indication:self overwriteDefaultToggleChannel. |
758 |
"/ anItem enabled:enabledChannel. |
|
666 | 759 |
] ifFalse:[ |
3998 | 760 |
anItem value == #hasNilColorHolder: ifTrue:[ |
3997 | 761 |
] ifFalse:[ |
762 |
anItem enabled:self overwriteDefaultToggleChannel. |
|
763 |
] |
|
412 | 764 |
] |
664 | 765 |
] |
3981 | 766 |
|
3996 | 767 |
"Created: / 23-01-2011 / 16:08:06 / cg" |
3998 | 768 |
"Modified: / 24-01-2011 / 19:35:52 / cg" |
412 | 769 |
! ! |
770 |
||
3406 | 771 |
!ColorMenu methodsFor:'user actions'! |
3322 | 772 |
|
3530 | 773 |
keepColorHolderIndicationAlwaysEnabled |
774 |
self colorHolder indication:true. |
|
775 |
self colorHolder isButton:true. |
|
776 |
! |
|
777 |
||
3322 | 778 |
openColorEditDialog |
779 |
|defineColorDialog| |
|
780 |
||
781 |
defineColorDialog := ColorEditDialog new color: self color. |
|
782 |
defineColorDialog open. |
|
783 |
defineColorDialog accept value ifTrue: [ |
|
3736
1aa04cb6d849
ColorEditDialog was grazy - adapted to changed protocol
Claus Gittinger <cg@exept.de>
parents:
3709
diff
changeset
|
784 |
self color:defineColorDialog colorNameOrColor |
3322 | 785 |
] |
786 |
! |
|
787 |
||
788 |
pickColorFromScreen |
|
789 |
|color| |
|
790 |
||
791 |
color := Color fromUser. |
|
792 |
color notNil ifTrue:[ |
|
793 |
self color:color. |
|
794 |
] |
|
412 | 795 |
! ! |
796 |
||
797 |
!ColorMenu class methodsFor:'documentation'! |
|
798 |
||
799 |
version |
|
3998 | 800 |
^ '$Header: /cvs/stx/stx/libwidg2/ColorMenu.st,v 1.69 2011-01-24 19:35:06 cg Exp $' |
3862
754cfd6ed4b5
changed: #addUserDefinedColors:labels:title:
Claus Gittinger <cg@exept.de>
parents:
3738
diff
changeset
|
801 |
! |
754cfd6ed4b5
changed: #addUserDefinedColors:labels:title:
Claus Gittinger <cg@exept.de>
parents:
3738
diff
changeset
|
802 |
|
754cfd6ed4b5
changed: #addUserDefinedColors:labels:title:
Claus Gittinger <cg@exept.de>
parents:
3738
diff
changeset
|
803 |
version_CVS |
3998 | 804 |
^ '$Header: /cvs/stx/stx/libwidg2/ColorMenu.st,v 1.69 2011-01-24 19:35:06 cg Exp $' |
412 | 805 |
! ! |