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