What is #defaultColor, _really_?

Richard A. O'Keefe ok at cs.otago.ac.nz
Thu Aug 7 00:16:43 UTC 2003


One thing I'd like my little "dump Morph as XML" thingy to do is to
report on the colour of a morph when and only when that colour is not
the usual colour for that kind of morph.  For example, StringMorphs
usually have (Color black) as their colour.  So I wanted to do
something like this:

    (self color = self defaultColor)
        ifFalse: ["write out what self color is"].

The snag is that although the default colour for StringMorphs
((StringMorph contents: 'xxx') color) is black,
the #defaultColor for StringMorphs
((StringMorph contents: 'xxx') defaultColor) is blue.

What I expected to find in StringMorph was

    defaultColor
	^Color black

    initialize
	super initialize.
	color := self defaultColor.
	font := nil.
	emphasis :=0.
	hasFocus := false.

    initWithContents: aString font: aFont emphasis: emphasisCode
	super initialize.
	color := self defaultColor.
	font := aFont.
	emphasis := emphasisCode.
	hasFocus := false.
	self contents: aString.

What I actually found in StringMorph was

    initialize
	super initialize.
	color := Color black.
	font := nil.
	emphasis :=0.
	hasFocus := false.

    initWithContents: aString font: aFont emphasis: emphasisCode
	super initialize.
	color := Color black.
	font := aFont.
	emphasis := emphasisCode.
	hasFocus := false.
	self contents: aString.

This left me wondering what #defaultColor is really supposed to mean.
In Morph we find

    defaultColor
	"Return the default fill style for the receiver"
	^Color blue

which leaves me even more puzzled than before, because StringMorphs
don't have _any_ blue about them that I can see, unless you go and
change them.

In the same way, we find

    AlignmentMorph>>initialize
	"lots of stuff"
	color := Color r: 0.8 g: 1.0 b: 0.8.
	"more stuff"

and this is actually repeated in basicInitialize.

Have I totally misunderstood the nature and purpose of #defaultColor,
or are there a lot of Morph subclasses that should be overriding and
using it?  Is this something for the MCP?



More information about the Squeak-dev mailing list