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