colorName:ifIllegal: - did return black for illegal color,
instead of raising an exception
--- a/WinWorkstation.st Tue Sep 08 19:19:48 2009 +0200
+++ b/WinWorkstation.st Tue Sep 08 19:20:14 2009 +0200
@@ -9255,18 +9255,19 @@
getRGBFromName:colorName into:aBlock
"get rgb components (0..100) of color named colorName,
- and evaluate the 3-arg block, aBlock with them"
+ and evaluate the 3-arg block, aBlock with them.
+ Return nil for unknown color names."
|val|
self getScaledRGBFromName:colorName into:[:r :g :b |
- r isNil ifTrue:[^nil].
- val := aBlock
- value:(r * 100.0 / 16rFFFF)
- value:(g * 100.0 / 16rFFFF)
- value:(b * 100.0 / 16rFFFF)
- ].
- ^val
+ r isNil ifTrue:[^nil].
+ val := aBlock
+ value:(r * 100.0 / 16rFFFF)
+ value:(g * 100.0 / 16rFFFF)
+ value:(b * 100.0 / 16rFFFF)
+ ].
+ ^ val
!
getScaledRGBFrom:index into:aBlock
@@ -9296,40 +9297,42 @@
getScaledRGBFromName:colorName into:aBlock
"get scaled rgb components (0..16rFFFF) of color named colorName,
- and evaluate the 3-arg block, aBlock with them"
+ and evaluate the 3-arg block, aBlock with them.
+ Return nil for unknown color names."
|triple r g b found cName|
r := g := b := 0.
found := false.
(colorName startsWith:$#) ifTrue:[
- "/ color in r/g/b hex notation
- r := Integer readFrom:(colorName copyFrom:2 to:3) radix:16.
- g := Integer readFrom:(colorName copyFrom:4 to:5) radix:16.
- b := Integer readFrom:(colorName copyFrom:6 to:7) radix:16.
- found := true.
+ "/ color in r/g/b hex notation
+ r := Integer readFrom:(colorName copyFrom:2 to:3) radix:16.
+ g := Integer readFrom:(colorName copyFrom:4 to:5) radix:16.
+ b := Integer readFrom:(colorName copyFrom:6 to:7) radix:16.
+ found := true.
] ifFalse:[
- cName := colorName asString.
- triple := StandardColorValues at:cName ifAbsent:nil.
- triple isNil ifTrue:[
- "/ try lowercase name
- cName := cName asLowercase.
- triple := StandardColorValues at:cName ifAbsent:nil.
- triple isNil ifTrue:[
- "/ try lowercase without intermixed spaces
- cName := cName asCollectionOfWords asStringWith:nil.
- triple := StandardColorValues at:cName ifAbsent:nil.
- ].
- ].
- triple notNil ifTrue:[
- r := triple at:1.
- g := triple at:2.
- b := triple at:3.
- found := true.
- ].
+ cName := colorName asString.
+ triple := StandardColorValues at:cName ifAbsent:nil.
+ triple isNil ifTrue:[
+ "/ try lowercase name
+ cName := cName asLowercase.
+ triple := StandardColorValues at:cName ifAbsent:nil.
+ triple isNil ifTrue:[
+ "/ try lowercase without intermixed spaces
+ cName := cName asCollectionOfWords asStringWith:nil.
+ triple := StandardColorValues at:cName ifAbsent:nil.
+ ].
+ ].
+ triple notNil ifTrue:[
+ r := triple at:1.
+ g := triple at:2.
+ b := triple at:3.
+ found := true.
+ ].
].
found ifFalse:[
- ('WinWorkstation: unknown color: ' , colorName) infoPrintCR.
+ "/ ('WinWorkstation: unknown color: ' , colorName) infoPrintCR.
+ ^ nil.
].
^ aBlock value:((r * 256) + r) value:((g * 256) + g) value:((b * 256) + b)
@@ -18972,7 +18975,7 @@
!WinWorkstation class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview/WinWorkstation.st,v 1.404 2009-08-28 11:45:41 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libview/WinWorkstation.st,v 1.405 2009-09-08 17:20:14 cg Exp $'
! !
WinWorkstation initialize!