TabWidget.st
changeset 369 8f003e44d5ef
parent 367 cff1a140978f
child 370 008888fdfc32
--- a/TabWidget.st	Tue Apr 22 19:55:11 1997 +0200
+++ b/TabWidget.st	Wed Apr 23 17:17:21 1997 +0200
@@ -19,14 +19,14 @@
 	category:'Views-Interactors'
 !
 
-TabWidget subclass:#Mac
+TabWidget subclass:#Window
 	instanceVariableNames:''
 	classVariableNames:''
 	poolDictionaries:''
 	privateIn:TabWidget
 !
 
-TabWidget subclass:#Window
+TabWidget subclass:#Mac
 	instanceVariableNames:''
 	classVariableNames:''
 	poolDictionaries:''
@@ -97,6 +97,11 @@
     style at:#labelAnchor put:( lftIns @ (topIns +level) ).
 
     self validateDimensions:style.
+    maxY := style at:#maxY.
+    maxX := style at:#maxX.
+
+ "/ caused by vertical layout for images
+    maxX < maxY ifTrue:[style at:#maxX put:maxY].
   ^ list
 !
 
@@ -133,7 +138,6 @@
     style at:#unselectedColor    put:unselectedColor.
     style at:#selectedColor      put:selectedColor.
     style at:#labelColor         put:(Color black).
-    style at:#selectionAtBottom  put:true.  "/ true: selected tab always moved to bottom
 
     style at:#expandSelection    put:0@0.    "/ expand selection extent x y when raised
     style at:#tabLevel           put:0.      "/ level
@@ -257,6 +261,65 @@
 
 !TabWidget methodsFor:'drawing'!
 
+redraw:isSelected
+    "redraw tab
+    "
+    |direction origin anchor x y|
+
+    direction := tabView direction.
+    anchor    := tabView styleAt:#labelAnchor.
+    origin    := self computeOrigin.
+
+    (direction == #top or:[direction == #bottom]) ifTrue:[
+        y := origin y.
+        x := origin x + anchor x.
+
+        direction == #top ifTrue:[
+            self redrawAtTop:isSelected.
+            y := y + anchor y.
+        ] ifFalse:[
+            self redrawAtBottom:isSelected.
+            y := y - anchor y - (label heightOn:tabView).
+        ].
+        label isString ifTrue:[y := y + tabView font ascent].
+        tabView paintColor:#labelColor.
+    ] ifFalse:[
+        direction == #right ifTrue:[
+            self redrawAtRight:isSelected.
+            x := origin x - anchor y - (label widthOn:tabView).
+        ] ifFalse:[
+            self redrawAtLeft:isSelected.
+            x := origin x + anchor y.
+        ].
+        tabView paintColor:#labelColor.
+        y := origin y + anchor x.
+
+        label isString ifTrue:[
+            direction == #right ifTrue:[
+                x := x + tabView font ascent.
+            ] ifFalse:[
+                x := x + tabView font descent.
+            ].
+            tabView paintColor:#labelColor.
+            tabView displayString:label x:x y:y angle:90.
+          ^ self.
+        ].
+    ].
+    label displayOn:tabView x:x y:y.
+
+! !
+
+!TabWidget methodsFor:'initialization'!
+
+label:aLabel for:aTabView
+    "initialize attributes
+    "
+    tabView := aTabView.
+    label   := aLabel.
+! !
+
+!TabWidget methodsFor:'private'!
+
 computeCorner
     "compute corner
     "
@@ -286,50 +349,6 @@
     d == #bottom ifTrue:[ ^ anchor ].
 
     self error
-!
-
-redraw:isSelected
-    "full redraw
-    "
-    |x y p a d|
-
-    d := tabView direction.
-
-    (d == #top or:[d == #bottom]) ifTrue:[
-        p := self computeOrigin.
-        a := tabView styleAt:#labelAnchor.
-        x := p x + a x.
-        
-        d == #top ifTrue:[
-            self redrawAtTop:isSelected.
-            y := p y + a y.
-        ] ifFalse:[
-            self redrawAtBottom:isSelected.
-            y := p y - (tabView styleAt:#labelBottomInset)
-                     - (tabView styleAt:#tabLevel)
-                     - (label heightOn:tabView).
-        ].
-        tabView paintColor:#labelColor.
-        label isString ifTrue:[y := y + tabView font ascent].
-        label displayOn:tabView x:x y:y.
-      ^ self
-    ].
-
-    d == #right ifTrue:[
-        ^ self redrawAtRight:isSelected
-    ].
-    d == #left ifTrue:[
-        ^ self redrawAtLeft:isSelected
-    ].
-! !
-
-!TabWidget methodsFor:'initialization'!
-
-label:aLabel for:aTabView
-    "initialize attributes
-    "
-    tabView := aTabView.
-    label   := aLabel.
 ! !
 
 !TabWidget methodsFor:'queries'!
@@ -363,220 +382,6 @@
     ^ false
 ! !
 
-!TabWidget::Mac class methodsFor:'calculate dimensions'!
-
-validateDimensions:aStyle
-    "validate dimensions for a style; could be redifined
-    "
-    |maxY maxX anchor lftIns|
-
-    maxY   := aStyle at:#maxY.
-    maxX   := (aStyle at:#maxX) - (aStyle at:#labelLeftInset).
-    anchor := aStyle at:#labelAnchor.
-    lftIns := maxY // 2.
-
-    anchor x:lftIns.
-
-    aStyle at:#maxX         put:(maxX + lftIns + maxY).
-    aStyle at:#rightCovered put:(maxY // 2).
-! !
-
-!TabWidget::Mac methodsFor:'drawing'!
-
-redrawAtBottom:isSelected
-    "redraw tab at bottom of view
-    "
-    |origin corner polygon x y x1 eX eY color shadowColor lightColor|
-
-    isSelected ifFalse:[
-        color       := tabView styleAt:#unselectedColor.
-        shadowColor := tabView styleAt:#shadowColorUnselected.
-        lightColor  := tabView styleAt:#lightColorUnselected.
-    ] ifTrue:[
-        color       := tabView styleAt:#selectedColor.
-        shadowColor := tabView styleAt:#shadowColorSelected.
-        lightColor  := tabView styleAt:#lightColorSelected.
-    ].
-
-    polygon := Array new:5.
-    origin  := self computeOrigin.
-    corner  := self computeCorner.
-
-    x  := origin x.
-    y  := origin y.
-    eX := corner x.
-    eY := corner y.
-    x1 := eX - (tabView styleAt:#maxY).
-
-    polygon at:1 put:(Point x:x      y:eY).
-    polygon at:2 put:(Point x:x      y:y).
-    polygon at:3 put:(Point x:x1     y:y).
-    polygon at:4 put:(Point x:eX     y:(y-extent y)).
-    polygon at:5 put:(Point x:eX     y:eY).
-
-    tabView paint:color.
-    tabView fillPolygon:polygon.
-
-    tabView paint:lightColor.
-    tabView displayLineFromX:x+1 y:eY toX:x+1 y:y-1.
-    tabView displayLineFromX:x+1 y:y-1 toX:x1-1 y:y-1.
-    tabView displayLineFromX:x+1 y:y-1 toX:x1+1 y:y-1.
-
-    tabView paintColor:#labelColor.
-    tabView displayPolygon:polygon.
-
-    isSelected ifFalse:[
-        tabView paint:shadowColor.
-        tabView displayLineFromX:x y:eY toX:eX y:eY.
-    ]
-
-
-!
-
-redrawAtLeft:isSelected
-    "redraw tab at left of view
-    "
-    |origin corner polygon x y y1 eX eY color shadowColor lightColor|
-
-    isSelected ifFalse:[
-        color       := tabView styleAt:#unselectedColor.
-        shadowColor := tabView styleAt:#shadowColorUnselected.
-        lightColor  := tabView styleAt:#lightColorUnselected.
-    ] ifTrue:[
-        color       := tabView styleAt:#selectedColor.
-        shadowColor := tabView styleAt:#shadowColorSelected.
-        lightColor  := tabView styleAt:#lightColorSelected.
-    ].
-
-    polygon := Array new:5.
-    origin  := self computeOrigin.
-    corner  := self computeCorner.
-
-    x  := origin x.
-    y  := origin y.
-    eX := corner x.
-    eY := corner y.
-    y1 := eY - (tabView styleAt:#maxY).
-
-    polygon at:1 put:(Point x:eX           y:y).
-    polygon at:2 put:(Point x:x            y:y).
-    polygon at:3 put:(Point x:x            y:y1).
-    polygon at:4 put:(Point x:(x+extent x) y:eY).
-    polygon at:5 put:(Point x:eX           y:eY).
-
-    tabView paint:color.
-    tabView fillPolygon:polygon.
-
-    tabView paint:lightColor.
-    tabView displayLineFromX:eX  y:y+1 toX:x+2  y:y+1.
-    tabView displayLineFromX:x+1 y:y+1 toX:x+1  y:y1+1.
-
-    tabView paintColor:#labelColor.
-    tabView displayPolygon:polygon.
-"
-    isSelected ifFalse:[
-        tabView paint:shadowColor.
-        tabView displayLineFromX:0 y:y toX:0 y:eY.
-    ]
-"
-!
-
-redrawAtRight:isSelected
-    "redraw tab at right of view
-    "
-    |origin corner polygon x y y1 eY color shadowColor lightColor|
-
-    isSelected ifFalse:[
-        color       := tabView styleAt:#unselectedColor.
-        shadowColor := tabView styleAt:#shadowColorUnselected.
-        lightColor  := tabView styleAt:#lightColorUnselected.
-    ] ifTrue:[
-        color       := tabView styleAt:#selectedColor.
-        shadowColor := tabView styleAt:#shadowColorSelected.
-        lightColor  := tabView styleAt:#lightColorSelected.
-    ].
-
-    polygon := Array new:5.
-    origin  := self computeOrigin.
-    corner  := self computeCorner.
-
-    x  := origin x.
-    y  := origin y.
-    eY := corner y.
-    y1 := eY - (tabView styleAt:#maxY).
-
-    polygon at:1 put:(Point x:0            y:y).
-    polygon at:2 put:(Point x:x            y:y).
-    polygon at:3 put:(Point x:x            y:y1).
-    polygon at:4 put:(Point x:(x-extent x) y:eY).
-    polygon at:5 put:(Point x:0            y:eY).
-
-    tabView paint:color.
-    tabView fillPolygon:polygon.
-
-    tabView paint:lightColor.
-    tabView displayLineFromX:0   y:y+1 toX:x-1  y:y+1.
-    tabView displayLineFromX:x-1 y:y+1 toX:x-1  y:y1+1.
-
-    tabView paintColor:#labelColor.
-    tabView displayPolygon:polygon.
-
-    isSelected ifFalse:[
-        tabView paint:shadowColor.
-        tabView displayLineFromX:0 y:y toX:0 y:eY.
-    ]
-
-!
-
-redrawAtTop:isSelected
-    "redraw tab at top of view
-    "
-    |origin corner polygon x y x1 eX eY color shadowColor lightColor|
-
-    isSelected ifFalse:[
-        color       := tabView styleAt:#unselectedColor.
-        shadowColor := tabView styleAt:#shadowColorUnselected.
-        lightColor  := tabView styleAt:#lightColorUnselected.
-    ] ifTrue:[
-        color       := tabView styleAt:#selectedColor.
-        shadowColor := tabView styleAt:#shadowColorSelected.
-        lightColor  := tabView styleAt:#lightColorSelected.
-    ].
-
-    polygon := Array new:5.
-    origin  := self computeOrigin.
-    corner  := self computeCorner.
-
-    x  := origin x.
-    y  := origin y.
-    eX := corner x - 1.
-    eY := corner y.
-    x1 := eX - (tabView styleAt:#maxY).
-
-    polygon at:1 put:(Point x:x      y:eY).
-    polygon at:2 put:(Point x:x      y:y).
-    polygon at:3 put:(Point x:x1     y:y).
-    polygon at:4 put:(Point x:eX     y:(y+extent y)).
-    polygon at:5 put:(Point x:eX     y:eY).
-
-    tabView paint:color.
-    tabView fillPolygon:polygon.
-
-    tabView paint:lightColor.
-    tabView displayLineFromX:x+1 y:eY toX:x+1 y:y+1.
-    tabView displayLineFromX:x+1 y:y+1 toX:x1+1 y:y+1.
-
-    tabView paintColor:#labelColor.
-    tabView displayPolygon:polygon.
-
-    isSelected ifFalse:[
-        tabView paint:shadowColor.
-        tabView displayLineFromX:x y:eY-1 toX:eX y:eY-1.
-    ]
-
-
-! !
-
 !TabWidget::Window class methodsFor:'accessing'!
 
 tabStyleOn:aView
@@ -866,8 +671,224 @@
     ].
 ! !
 
+!TabWidget::Mac class methodsFor:'accessing'!
+
+tabStyleOn:aView
+    |style|
+
+    style := super tabStyleOn:aView.
+    style at:#tabLevel put:2.
+  ^ style.
+! !
+
+!TabWidget::Mac class methodsFor:'calculate dimensions'!
+
+validateDimensions:aStyle
+    "validate dimensions for a style; could be redifined
+    "
+    |maxY maxX anchor lftIns|
+
+    maxY   := aStyle at:#maxY.
+    maxX   := (aStyle at:#maxX) - (aStyle at:#labelLeftInset).
+    anchor := aStyle at:#labelAnchor.
+    lftIns := maxY // 2.
+
+    anchor x:lftIns.
+
+    aStyle at:#maxX         put:(maxX + lftIns + maxY).
+    aStyle at:#rightCovered put:(maxY // 2).
+! !
+
+!TabWidget::Mac methodsFor:'drawing'!
+
+redrawAtBottom:isSelected
+    "redraw tab at bottom of view
+    "
+    |origin corner level polygon x y x1 eX eY shadowColor lightColor|
+
+    isSelected ifFalse:[
+        lightColor  := tabView styleAt:#lightColorUnselected.
+        shadowColor := tabView styleAt:#shadowColorUnselected.
+        tabView paint:(tabView styleAt:#unselectedColor).
+    ] ifTrue:[
+        lightColor  := tabView styleAt:#lightColorSelected.
+        shadowColor := tabView styleAt:#shadowColorSelected.
+        tabView paint:(tabView styleAt:#selectedColor).
+    ].
+    polygon := Array new:5.
+    origin  := self computeOrigin.
+    corner  := self computeCorner.
+    level   := tabView styleAt:#tabLevel.
+
+    x  := origin x.
+    y  := origin y.
+    eX := corner x.
+    eY := corner y.
+    x1 := eX - (tabView styleAt:#maxY).
+
+    polygon at:1 put:(Point x:x  y:eY).
+    polygon at:2 put:(Point x:x  y:y).
+    polygon at:3 put:(Point x:x1 y:y).
+    polygon at:4 put:(Point x:eX y:(y-extent y)).
+    polygon at:5 put:(Point x:eX y:eY).
+
+    tabView fillPolygon:polygon.
+    tabView paint:lightColor.
+
+    1 to:level do:[:i|
+        tabView displayLineFromX:x+1 y:y-i toX:x1+i y:y-i.
+        tabView displayLineFromX:x+i y:y-1 toX:x+i  y:1.
+    ].
+    tabView paint:shadowColor.
+    tabView displayPolygon:polygon.
+
+    isSelected ifFalse:[
+        tabView displayLineFromX:x y:eY toX:eX y:eY.
+    ]
+!
+
+redrawAtLeft:isSelected
+    "redraw tab at left of view
+    "
+    |origin corner polygon level x y y1 eX eY shadowColor lightColor|
+
+    isSelected ifFalse:[
+        lightColor  := tabView styleAt:#lightColorUnselected.
+        shadowColor := tabView styleAt:#shadowColorUnselected.
+        tabView paint:(tabView styleAt:#unselectedColor).
+    ] ifTrue:[
+        lightColor  := tabView styleAt:#lightColorSelected.
+        shadowColor := tabView styleAt:#shadowColorSelected.
+        tabView paint:(tabView styleAt:#selectedColor).
+    ].
+    polygon := Array new:5.
+    origin  := self computeOrigin.
+    corner  := self computeCorner.
+    level   := tabView styleAt:#tabLevel.
+
+    x  := origin x.
+    y  := origin y.
+    eX := corner x.
+    eY := corner y.
+    y1 := eY - (tabView styleAt:#maxY).
+
+    polygon at:1 put:(Point x:eX           y:y).
+    polygon at:2 put:(Point x:x            y:y).
+    polygon at:3 put:(Point x:x            y:y1).
+    polygon at:4 put:(Point x:(x+extent x) y:eY).
+    polygon at:5 put:(Point x:eX           y:eY).
+
+    tabView fillPolygon:polygon.
+    tabView paint:lightColor.
+
+    1 to:level do:[:i|
+        tabView displayLineFromX:eX  y:y+i toX:x+2  y:y+i.
+        tabView displayLineFromX:x+i y:y+1 toX:x+i  y:y1+i.
+    ].
+    tabView paint:shadowColor.
+    tabView displayPolygon:polygon.
+
+    isSelected ifFalse:[
+        tabView displayLineFromX:eX-1 y:y toX:eX-1 y:eY.
+    ]
+!
+
+redrawAtRight:isSelected
+    "redraw tab at right of view
+    "
+    |origin corner level polygon x y y1 eY shadowColor lightColor|
+
+    isSelected ifFalse:[
+        lightColor  := tabView styleAt:#lightColorUnselected.
+        shadowColor := tabView styleAt:#shadowColorUnselected.
+        tabView paint:(tabView styleAt:#unselectedColor).
+    ] ifTrue:[
+        lightColor  := tabView styleAt:#lightColorSelected.
+        shadowColor := tabView styleAt:#shadowColorSelected.
+        tabView paint:(tabView styleAt:#selectedColor).
+    ].
+    polygon := Array new:5.
+    origin  := self computeOrigin.
+    corner  := self computeCorner.
+    level   := tabView styleAt:#tabLevel.
+
+    x  := origin x.
+    y  := origin y.
+    eY := corner y.
+    y1 := eY - (tabView styleAt:#maxY).
+
+    polygon at:1 put:(Point x:0            y:y).
+    polygon at:2 put:(Point x:x            y:y).
+    polygon at:3 put:(Point x:x            y:y1).
+    polygon at:4 put:(Point x:(x-extent x) y:eY).
+    polygon at:5 put:(Point x:0            y:eY).
+
+    tabView fillPolygon:polygon.
+    tabView paint:lightColor.
+
+    1 to:level do:[:i|
+        tabView displayLineFromX:0   y:y+i toX:x-1  y:y+i.
+        tabView displayLineFromX:x-i y:y+1 toX:x-i  y:y1+i.
+    ].
+    tabView paint:shadowColor.
+    tabView displayPolygon:polygon.
+
+    isSelected ifFalse:[
+        tabView displayLineFromX:0 y:y toX:0 y:eY.
+    ]
+
+!
+
+redrawAtTop:isSelected
+    "redraw tab at top of view
+    "
+    |origin corner level polygon x y x1 eX eY color shadowColor lightColor|
+
+    isSelected ifFalse:[
+        lightColor  := tabView styleAt:#lightColorUnselected.
+        shadowColor := tabView styleAt:#shadowColorUnselected.
+        tabView paint:(tabView styleAt:#unselectedColor).
+    ] ifTrue:[
+        lightColor  := tabView styleAt:#lightColorSelected.
+        shadowColor := tabView styleAt:#shadowColorSelected.
+        tabView paint:(tabView styleAt:#selectedColor).
+    ].
+    polygon := Array new:5.
+    origin  := self computeOrigin.
+    corner  := self computeCorner.
+    level   := tabView styleAt:#tabLevel.
+
+    x  := origin x.
+    y  := origin y.
+    eX := corner x - 1.
+    eY := corner y.
+    x1 := eX - (tabView styleAt:#maxY).
+
+    polygon at:1 put:(Point x:x  y:eY).
+    polygon at:2 put:(Point x:x  y:y).
+    polygon at:3 put:(Point x:x1 y:y).
+    polygon at:4 put:(Point x:eX y:(y+extent y)).
+    polygon at:5 put:(Point x:eX y:eY).
+
+    tabView fillPolygon:polygon.
+    tabView paint:lightColor.
+
+    1 to:level do:[:i|
+        tabView displayLineFromX:x+i y:eY  toX:x+i  y:y+1.
+        tabView displayLineFromX:x+1 y:y+i toX:x1+i y:y+i.
+    ].
+    tabView paint:shadowColor.
+    tabView displayPolygon:polygon.
+
+    isSelected ifFalse:[
+        tabView displayLineFromX:x y:eY-1 toX:eX y:eY-1.
+    ]
+
+
+! !
+
 !TabWidget class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/TabWidget.st,v 1.4 1997-04-22 16:56:29 ca Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/TabWidget.st,v 1.5 1997-04-23 15:17:21 ca Exp $'
 ! !