"
COPYRIGHT (c) 1991 by Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
"
View subclass:#FramedBox
instanceVariableNames:'label layout fgColor'
classVariableNames:''
poolDictionaries:''
category:'Views-Layout'
!
FramedBox comment:'
COPYRIGHT (c) 1991 by Claus Gittinger
All Rights Reserved
a frame around something. The frame may have a label, whose position
is controlled by the layout variable, aSymbol which may be one of:
[#topCenter #topLeft #topRight #bottomLeft #bottomCenter #bottomRight]
$Header: /cvs/stx/stx/libwidg/FramedBox.st,v 1.5 1994-01-13 00:15:44 claus Exp $
written spring 91 by claus
'!
!FramedBox methodsFor:'private'!
redrawIfShown
shown ifTrue:[
self clear.
self redraw
]
! !
!FramedBox methodsFor:'accessing'!
foregroundColor
"return the frame labels foreground color"
^ fgColor
!
foregroundColor:aColor
"set the frame labels foreground color"
aColor ~= fgColor ifTrue:[
fgColor := aColor.
self redrawIfShown
]
!
label
"return the frames labelstring"
^ label
!
label:aString
"set the frames labelstring"
(label ~= aString) ifTrue:[
label := aString.
self redrawIfShown
]
!
font:aFont
"set the frame labelstrings font"
(font ~= aFont) ifTrue:[
super font:aFont.
self redrawIfShown
]
!
viewRectangle
"return the inside area - redefined to save frame from
relative computations"
|m2 sep|
sep := font height.
m2 := sep + sep + sep.
^ (sep @ sep) extent:((width - m2) @ (height - m2))
!
layout
^ layout
!
layout:aSymbol
"define the position of the label;
aSymbol may be: topLeft, topCenter, topRight;
bottomLeft, bottomCenter or bottomRight"
layout ~~ aSymbol ifTrue:[
layout := aSymbol.
self redrawIfShown
]
! !
!FramedBox methodsFor:'events'!
sizeChanged:how
self redrawIfShown.
super sizeChanged:how
! !
!FramedBox methodsFor:'drawing'!
drawFrame
"redraw the frame"
|sep halfSep right bot left top bm1 rm3|
sep := font height.
halfSep := sep // 2.
self is3D ifFalse:[
self displayRectangleX:halfSep y:halfSep
width:(width - sep) height:(height - sep).
^ self
].
self paint:lightColor.
right := width - halfSep.
bot := height - halfSep.
self displayRectangleX:halfSep y:halfSep
width:(width - sep) height:(height - sep + 1).
self paint:shadowColor.
left := halfSep - 1.
top := halfSep - 1.
bm1 := bot - 1.
self displayLineFromX:left y:top toX:(right - 1) y:top.
self displayLineFromX:left y:top toX:left y:bm1.
rm3 := right - 3.
"
self displayLineFromX:rm3 y:(halfSep + 1) toX:rm3 y:bm1.
self displayLineFromX:(halfSep + 2) y:(bot - 2) toX:(right - 2) y:(bot - 2)
"
self displayLineFromX:rm3 y:(halfSep + 1) toX:rm3 y:bm1-1.
self displayLineFromX:(halfSep + 2) y:(bot - 2) toX:(right - 2 - 1) y:(bot - 2)
!
redraw
"redraw the frame and name if present"
|labelLen l x y|
label isNil ifTrue:[
l := ' '.
labelLen := 0
] ifFalse:[
l := ' ' , label , ' '.
labelLen := font widthOf:l
].
self drawFrame.
labelLen > 0 ifTrue:[
labelLen < width ifTrue:[
(#(topLeft topCenter topRight) includes:layout) ifTrue:[
y := font ascent.
] ifFalse:[
y := height - font descent.
].
(#(topLeft bottomLeft) includes:layout) ifTrue:[
x := font height
] ifFalse:[
(#(topRight bottomRight) includes:layout) ifTrue:[
x := width - labelLen - font height
] ifFalse:[
x := (width - labelLen) // 2
]
].
self paint:fgColor on:viewBackground.
self displayOpaqueString:l x:x y:y
]
]
! !
!FramedBox methodsFor:'initialization'!
initStyle
"default position is top-center, except for ms-windows, where
the text is positioned at top-left"
super initStyle.
fgColor := Black.
style == #mswindows ifTrue:[
layout := #topLeft
] ifFalse:[
layout := #topCenter
]
! !