Border.st
changeset 1321 b87667a37eef
child 1322 b473b0db6399
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Border.st	Mon Feb 10 15:45:13 1997 +0100
@@ -0,0 +1,361 @@
+Object subclass:#Border
+	instanceVariableNames:'left right top bottom leftColor rightColor topColor bottomColor'
+	classVariableNames:''
+	poolDictionaries:''
+	category:'Interface-Support'
+!
+
+!Border class methodsFor:'documentation'!
+
+documentation
+"
+    a border holdes the values of a views (or components) border.
+    It is (currently) not used by ST/X, but provided as a comatibility hook.
+    (... however, ST/X is being rewritten to make use of it soon).
+    Notice: 
+        this class was implemented using protocol information
+        from alpha testers, from reading PD programs and 
+        from the Hopkins/Horan book.
+        - it may not be complete or compatible to the corresponding ST-80 class. 
+        If you encounter any incompatibilities, please forward a note 
+        describing the incompatibility verbal (i.e. no code) to the ST/X team.
+
+    [see also:]
+        Wrapper SimpleView
+
+    [author:]
+        Claus Gittinger
+"
+
+
+!
+
+examples
+"
+    examples to be added.
+"
+!
+
+history
+    "Created: 10.2.1997 / 15:43:24 / cg"
+! !
+
+!Border class methodsFor:'instance creation'!
+
+width:borderWidth
+    "create a new instance of the receiver with a border of the given width  
+     (and default color)."
+
+    ^ self width:borderWidth color:View defaultBorderColor
+
+    "Modified: 10.2.1997 / 15:19:57 / cg"
+!
+
+width:borderWidth color:aColor
+    "create a new instance of the receiver with a border of the given width  
+     and color."
+
+    ^ self new
+        setBorderWidth:borderWidth color:aColor
+
+    "Modified: 10.2.1997 / 15:20:32 / cg"
+! !
+
+!Border methodsFor:'accessing'!
+
+bottom
+    "return the bottom border width"
+
+    ^ bottom
+
+    "Created: 10.2.1997 / 14:51:34 / cg"
+    "Modified: 10.2.1997 / 15:39:01 / cg"
+!
+
+bottomColor
+    "return the value of the instance variable 'bottomColor' (automatically generated)"
+
+    ^ bottomColor
+
+    "Created: 10.2.1997 / 14:51:34 / cg"
+!
+
+color:newColor
+    "set all four colors"
+
+    leftColor := rightColor := topColor := bottomColor := newColor
+
+    "Created: 10.2.1997 / 15:27:01 / cg"
+!
+
+left
+    "return the left border width"
+
+    ^ left
+
+    "Created: 10.2.1997 / 14:51:34 / cg"
+    "Modified: 10.2.1997 / 15:39:05 / cg"
+!
+
+leftColor
+    "return the value of the instance variable 'leftColor' (automatically generated)"
+
+    ^ leftColor
+
+    "Created: 10.2.1997 / 14:51:34 / cg"
+!
+
+right
+    "return the right border width"
+
+    ^ right
+
+    "Created: 10.2.1997 / 14:51:34 / cg"
+    "Modified: 10.2.1997 / 15:39:08 / cg"
+!
+
+rightColor
+    "return the value of the instance variable 'rightColor' (automatically generated)"
+
+    ^ rightColor
+
+    "Created: 10.2.1997 / 14:51:34 / cg"
+!
+
+setBottom:aSmallInteger
+    "set the bottom border width"
+
+    bottom := aSmallInteger
+
+    "Created: 10.2.1997 / 15:38:50 / cg"
+!
+
+setBottomColor:aColor
+    "set the bottomColor"
+
+    bottomColor := aColor
+
+    "Created: 10.2.1997 / 15:37:51 / cg"
+!
+
+setLeft:aSmallInteger
+    "set the left border width"
+
+    left := aSmallInteger
+
+    "Created: 10.2.1997 / 15:39:33 / cg"
+!
+
+setLeftColor:aColor
+    "set the leftColor"
+
+    leftColor := aColor
+
+    "Created: 10.2.1997 / 15:38:02 / cg"
+!
+
+setRight:aSmallInteger
+    "set the right border width"
+
+    right := aSmallInteger
+
+    "Created: 10.2.1997 / 15:39:44 / cg"
+!
+
+setRightColor:aColor
+    "set the rightColor"
+
+    rightColor := aColor
+
+    "Created: 10.2.1997 / 15:38:08 / cg"
+!
+
+setTop:aSmallInteger
+    "set the top border width"
+
+    top := aSmallInteger
+
+    "Created: 10.2.1997 / 15:39:27 / cg"
+!
+
+setTopColor:aColor
+    "set the topColor"
+
+    topColor := aColor
+
+    "Created: 10.2.1997 / 15:38:17 / cg"
+!
+
+top
+    "return the top border width"
+
+    ^ top
+
+    "Created: 10.2.1997 / 14:51:34 / cg"
+    "Modified: 10.2.1997 / 15:39:11 / cg"
+!
+
+topColor
+    "return the value of the instance variable 'topColor' (automatically generated)"
+
+    ^ topColor
+
+    "Created: 10.2.1997 / 14:51:34 / cg"
+! !
+
+!Border methodsFor:'displaying'!
+
+displayOn:aGC forDisplayBox:aRectangle
+    "display the borders represented by the receiver in the specified rectangle.
+     The gc is restored after the draw."
+
+    self displayOn:aGC forDisplayBox:aRectangle using:nil
+
+    "Modified: 10.2.1997 / 14:56:10 / cg"
+!
+
+displayOn:aGC forDisplayBox:aRectangle using:colorSource
+    "display the borders represented by the receiver borders in the given rectangle.
+     colorSource is ignored here, but subclasses (i.e. 3D-borders) may use
+     it to ask for shadow/lightColors.
+     The gc's state is restored after the drawing."
+
+    |clipRectangle paint oldPaint 
+     t r l b rL rR rT rB rW rH|
+
+"/    clipRectangle := aGC clippingBounds.
+"/    ((self insetDisplayBoxFor: aRectangle) contains: clipRectangle) ifTrue: [^self].
+
+    oldPaint := aGC paint.
+    r := aRectangle copy.
+
+    t := self top.
+    l := self left.
+    r := self right.
+    b := self bottom.
+
+    rL := aRectangle left.
+    rT := aRectangle top.
+    rR := aRectangle right.
+    rB := aRectangle bottom.
+    rH := aRectangle height.
+    rW := aRectangle width.
+
+    (l ~~ 0 and: [(paint := self leftColor) notNil]) ifTrue:[
+        aGC paint:paint.
+        aGC displayRectangleX:rL
+                            y:rT
+                        width:l
+                       height:rH + 1 - b
+    ].
+
+    (t ~~ 0 and: [(paint := self topColor) notNil]) ifTrue:[
+        aGC paint:paint.
+        aGC displayRectangleX:(rL + l)
+                            y:rT
+                        width:rW - l
+                       height:t
+    ].
+
+    (r ~~ 0 and: [(paint := self rightColor) notNil]) ifTrue:[
+        aGC paint:paint.
+        aGC displayRectangleX:(rR - r)
+                            y:(rT + t)
+                        width:r
+                       height:rH + 1 - t
+    ].
+
+    (b ~~ 0 and: [(paint := self bottomColor) notNil]) ifTrue:[
+        aGC paint:paint.
+        aGC displayRectangleX:(rL)
+                            y:(rB + 1 - b)
+                        width:rW - r
+                       height:b
+    ].
+
+    aGC paint: oldPaint
+
+    "
+     |v b|
+
+     v := StandardSystemView extent:10@10.
+     v openAndWait.
+
+     b := Border width:2 color:Color red.
+     b displayOn:v forDisplayBox:(0@0 corner:9@9).
+
+     Delay waitForSeconds:1.
+     b leftColor:Color blue.
+     b displayOn:v forDisplayBox:(0@0 corner:9@9).
+     Delay waitForSeconds:1.
+     b topColor:Color green.
+     b displayOn:v forDisplayBox:(0@0 corner:9@9).
+     Delay waitForSeconds:1.
+     b rightColor:Color magenta.
+     b displayOn:v forDisplayBox:(0@0 corner:9@9).
+
+    "
+
+    "Modified: 10.2.1997 / 15:30:22 / cg"
+! !
+
+!Border methodsFor:'private accessing'!
+
+setBorderWidth:aWidth color:aColor
+     left := right := top := bottom := aWidth.
+     leftColor := rightColor := topColor := bottomColor := aColor
+
+    "Created: 10.2.1997 / 15:21:27 / cg"
+! !
+
+!Border methodsFor:'queries'!
+
+allSidesEqual:aSmallInteger
+    left ~~ aSmallInteger ifTrue:[^ false].
+    top ~~ aSmallInteger ifTrue:[^ false].
+    right ~~ aSmallInteger ifTrue:[^ false].
+    bottom ~~ aSmallInteger ifTrue:[^ false].
+    ^ true
+
+    "Created: 10.2.1997 / 14:53:13 / cg"
+!
+
+displayBoxFor:aRectangle
+    "return a rectangle representing the overall display box of a component
+     bordered by the receiver, which has bounds of aRectangle.
+     That is, the argument outset by the receivers borders."
+
+    |insetRectangle|
+
+    insetRectangle := aRectangle copy.
+    insetRectangle left:(insetRectangle left - self left).
+    insetRectangle right:(insetRectangle right + self right).
+    insetRectangle top:(insetRectangle top - self top).
+    insetRectangle bottom:(insetRectangle bottom + self bottom).
+    ^ insetRectangle
+
+    "Created: 10.2.1997 / 15:43:00 / cg"
+!
+
+insetDisplayBoxFor:aRectangle
+    "return a rectangle representing the display box of a component
+     bordered by the receiver in the outer bounds, aRectangle.
+     That is, the argument inset by the receivers borders."
+
+    |insetRectangle|
+
+    insetRectangle := aRectangle copy.
+    insetRectangle left:(insetRectangle left + self left).
+    insetRectangle right:(insetRectangle right - self right).
+    insetRectangle top:(insetRectangle top + self top).
+    insetRectangle bottom:(insetRectangle bottom - self bottom).
+    ^ insetRectangle
+
+    "Created: 10.2.1997 / 15:42:06 / cg"
+! !
+
+!Border class methodsFor:'documentation'!
+
+version
+    ^ '$Header: /cvs/stx/stx/libview/Border.st,v 1.1 1997-02-10 14:45:13 cg Exp $'
+! !