PanelView.st
changeset 0 e6a541c1c0eb
child 3 9d7eefb5e69f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PanelView.st	Fri Jul 16 11:44:44 1993 +0200
@@ -0,0 +1,139 @@
+"
+ COPYRIGHT (c) 1989-92 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:#PanelView
+       instanceVariableNames:'layout verticalSpace horizontalSpace mustRearrange'
+       classVariableNames:''
+       poolDictionaries:''
+       category:'Views-Layout'
+!
+
+PanelView comment:'
+
+COPYRIGHT (c) 1989-92 by Claus Gittinger
+              All Rights Reserved
+
+this is a view for holding subviews. (layout-widget ?!)
+
+this one just tries to get everything into its space -
+if you dont like its layout, define a subclass ...
+
+HorizontalPanelView and VerticalPanelView are two of them.
+
+%W% %E%
+
+written spring/summer 89 by claus
+'!
+
+!PanelView methodsFor:'initialization'!
+
+initialize
+    super initialize.
+
+    layout := #center.
+    verticalSpace := ViewSpacing.
+    horizontalSpace := ViewSpacing.
+    mustRearrange := false
+!
+
+realize
+    mustRearrange ifTrue:[
+        self setChildPositions
+    ].
+    super realize
+! !
+
+!PanelView methodsFor:'accessing'!
+
+verticalSpace:numberOfPixels
+    "set the space between elements (default is 1mm)"
+
+    verticalSpace := numberOfPixels
+!
+
+horizontalSpace:numberOfPixels
+    "set the space between elements (default is 1mm)"
+
+    horizontalSpace := numberOfPixels
+!
+
+space:numberOfPixels
+    "set the space between elements (default is 1mm)"
+
+    horizontalSpace := numberOfPixels.
+    verticalSpace := numberOfPixels
+!
+
+layout:aSymbol
+    "change the layout - the argument, aSymbol is interpreted in subclasses
+     HorizontalPanelView and VerticalPanelView;
+     it may be: #left / #top; #spread; #center or #right / #bottom"
+
+    (layout ~~ aSymbol) ifTrue:[
+        layout := aSymbol.
+        self layoutChanged
+    ]
+!
+
+addSubView:aView
+    super addSubView:aView.
+    self layoutChanged
+! !
+
+!PanelView methodsFor:'event processing'!
+
+sizeChanged:how
+    super sizeChanged:how.
+    self setChildPositions
+! !
+
+!PanelView methodsFor:'private'!
+
+layoutChanged
+    (shown and:[realized]) ifTrue:[
+        self setChildPositions
+    ] ifFalse:[
+        mustRearrange := true
+    ]
+!
+
+setChildPositions
+    "(re)compute position of every child"
+
+    |first xpos ypos maxHeightInRow|
+
+    subViews notNil ifTrue:[
+        xpos := horizontalSpace.
+        ypos := verticalSpace.
+
+        maxHeightInRow := 0.
+        first := true.
+        subViews do:[:child |
+            "go to next row, if this subview won't fit"
+            first ifFalse: [
+                (xpos + child widthIncludingBorder + horizontalSpace) > width
+                ifTrue: [
+                    ypos := ypos + verticalSpace + maxHeightInRow.
+                    xpos := horizontalSpace.
+                    maxHeightInRow := 0
+                ]
+            ].
+            child origin:(xpos@ypos).
+            xpos := xpos + (child widthIncludingBorder) + horizontalSpace.
+            (maxHeightInRow < (child heightIncludingBorder)) ifTrue:[
+                maxHeightInRow := child heightIncludingBorder
+            ].
+            first := false
+        ]
+    ].
+    mustRearrange := false
+! !