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