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