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