--- a/DataSetLabel.st Tue Aug 24 16:02:48 1999 +0200
+++ b/DataSetLabel.st Tue Aug 24 17:29:09 1999 +0200
@@ -1,23 +1,16 @@
Object subclass:#DataSetLabel
- instanceVariableNames:'label selector argument adjust font fgColor bgColor layout
- preferredExtent'
+ instanceVariableNames:'label selector argument adjust font fgColor bgColor
+ preferredHeight preferredWidth'
classVariableNames:''
poolDictionaries:''
category:'Views-DataSet'
!
-!DataSetLabel class methodsFor:'instance creation'!
-
-columnDescription:aDescription builder:aBuilder on:aGC
- ^ self new columnDescription:aDescription builder:aBuilder on:aGC
-
-! !
-
!DataSetLabel methodsFor:'accessing colors'!
backgroundColor
- "returns the background color of the column or nil
+ "returns the background color or nil
"
^ bgColor
@@ -25,7 +18,7 @@
!
foregroundColor
- "returns the foreground color of the column or nil
+ "returns the foreground color or nil
"
^ fgColor
@@ -33,28 +26,16 @@
!DataSetLabel methodsFor:'accessing dimensions'!
-layout
- "returns the item's layout, a Rectangle
+preferredHeight
+ "returns my preferred height
"
- ^ layout
-
-
+ ^ preferredHeight
!
-layout:aLayout
- "set the item's layout, a Rectangle
+preferredWidth
+ "returns my preferred width
"
- layout := aLayout
-
-
-!
-
-preferredExtent
- "returns the preferred extent of the label
- "
- ^ preferredExtent
-
-
+ ^ preferredWidth
! !
!DataSetLabel methodsFor:'actions'!
@@ -75,122 +56,82 @@
!DataSetLabel methodsFor:'drawing'!
-drawLabel:aLabel atX:xLeft y:yTop hInset:hInset on:aGC
- "draw label
- "
- |x y|
-
- adjust == #left ifTrue:[
- x := xLeft + hInset.
- ] ifFalse:[
- x := layout width - (aLabel widthOn:aGC).
-
- adjust == #right ifTrue:[x := x - hInset]
- ifFalse:[x := x // 2].
- x := xLeft + x.
- ].
-
- aLabel isImageOrForm ifFalse:[
- y := yTop + (font ascent)
- ] ifTrue:[
- y := yTop
- ].
- aLabel displayOn:aGC x:x y:y.
-!
-
-redrawLabelOn:aGC hInset:hInset
+redrawX:xLeft w:width h:height inset:inset on:aGC
"redraw the label; the background is cleared and the paint is set
"
- |y|
+ |y0 margin x y ascent gcFont|
label isNil ifTrue:[ ^ self ].
- y := layout top + (layout height - preferredExtent y // 2).
- aGC font:font.
+ gcFont := aGC font.
+
+ font notNil ifTrue:[
+ aGC font:font.
+ ascent := font ascent
+ ] ifFalse:[
+ ascent := gcFont ascent
+ ].
+ y0 := height - preferredHeight // 2.
- (label isSequenceable and:[label isString not]) ifFalse:[
- self drawLabel:label atX:(layout left) y:y hInset:hInset on:aGC.
- ] ifTrue:[
- label do:[:el|
- el notNil ifTrue:[
- self drawLabel:el atX:(layout left) y:y hInset:hInset on:aGC.
- y := y + (el heightOn:aGC)
- ]
- ]
- ]
+ label do:[:aLabel|
+ adjust == #left ifTrue:[
+ x := xLeft + inset.
+ ] ifFalse:[
+ x := width - (aLabel widthOn:aGC).
-
+ adjust == #right ifTrue:[x := x - inset]
+ ifFalse:[x := x // 2].
+ x := xLeft + x.
+ ].
+ y := aLabel isImageOrForm ifTrue:[y0] ifFalse:[y0 + ascent].
+ aLabel displayOn:aGC x:x y:y.
+ y0 := y0 + (aLabel heightOn:aGC)
+ ].
+ font notNil ifTrue:[aGC font:gcFont]. "/ restore font
! !
!DataSetLabel methodsFor:'instance creation'!
-columnDescription:aDescription builder:aBuilder on:aGC
- |device x y|
+description:aDescription builder:aBuilder on:aGC
+ |device gcFont|
label := self resolveLabelFromDescription:aDescription withBuilder:aBuilder.
selector := aDescription labelActionSelector.
argument := (aDescription labelActionArgument) ? label.
adjust := (aDescription labelAlignment) ? #left.
- layout := Rectangle left:0 right:0 top:0 bottom:0.
+ device := aGC device.
fgColor := aDescription labelForegroundColor.
bgColor := aDescription labelBackgroundColor.
- device := aGC device.
-
- label isString ifTrue:[
- "/
- "/ check for empty label
- "/
- (label isEmpty or:[label withoutSeparators isEmpty]) ifTrue:[
- label := nil
- ]
- ].
fgColor notNil ifTrue:[ fgColor := fgColor onDevice:device ].
bgColor notNil ifTrue:[ bgColor := bgColor onDevice:device ].
- label isNil ifTrue:[
- preferredExtent := 0 @ 0.
- ^ self
+ preferredHeight := preferredWidth := 0.
+
+ (label isNil or:[label perform:#isEmpty ifNotUnderstood:false]) ifTrue:[
+ label := nil.
+ ^ self
].
- font := aDescription labelFont.
-
- font notNil ifTrue:[ font := font onDevice:device ]
- ifFalse:[ font := aGC font ].
-
- aGC font:font.
+ (font := aDescription labelFont) notNil ifTrue:[
+ (gcFont := aGC font) = font ifTrue:[
+ font := nil
+ ] ifFalse:[
+ aGC font:(font := font onDevice:device)
+ ]
+ ].
(label isSequenceable and:[label isString not]) ifFalse:[
- label := self label:label on:device.
- preferredExtent := Point x:(label widthOn:aGC) y:(label heightOn:aGC).
- ^ self
+ label := Array with:label
].
- x := y := 0.
label := label collect:[:el||lbl|
- (lbl := self label:el on:device) notNil ifTrue:[
- x := (lbl widthOn:aGC) max:x.
- y := y + (lbl heightOn:aGC)
- ].
+ lbl := self label:el on:device.
+ preferredWidth := (lbl widthOn:aGC) max:preferredWidth.
+ preferredHeight := preferredHeight + (lbl heightOn:aGC).
lbl
].
- preferredExtent := Point x:x y:y.
-
-
-! !
-
-!DataSetLabel methodsFor:'notifications'!
-
-originChanged:aDeltaPoint
- "called when the origin of the layout changed; scrolling left or right
- "
- |origin extent|
-
- origin := layout origin.
- extent := layout extent.
-
- layout origin:(origin - aDeltaPoint) extent:extent
-
+ font notNil ifTrue:[aGC font:gcFont]. "/ restore font
! !
!DataSetLabel methodsFor:'private'!
@@ -200,6 +141,8 @@
"
|lbl img|
+ aLabel isNil ifTrue:[^ ''].
+
aLabel isString ifFalse:[
aLabel isImageOrForm ifTrue:[
aLabel device ~~ aDevice ifTrue:[lbl := aLabel copy on:aDevice]
@@ -280,5 +223,5 @@
!DataSetLabel class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libwidg2/DataSetLabel.st,v 1.3 1999-08-18 15:09:46 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libwidg2/DataSetLabel.st,v 1.4 1999-08-24 15:29:09 cg Exp $'
! !