TabWidget.st
changeset 697 e93da973b635
parent 670 6aefa9b9705c
child 703 f07158f92e36
--- a/TabWidget.st	Wed Jan 28 15:04:30 1998 +0100
+++ b/TabWidget.st	Wed Jan 28 15:09:48 1998 +0100
@@ -13,7 +13,8 @@
 
 
 Object subclass:#TabWidget
-	instanceVariableNames:'tabView label anchor extent lineNr'
+	instanceVariableNames:'model tabView label disabledLabel printableLabel anchor extent
+		lineNr fgColor labelType'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Views-Interactors'
@@ -80,10 +81,15 @@
     aTabView device isNil ifTrue:[
         self halt
     ].
-    list := aList collect:[:aLabel||y x|
-        (y := aLabel heightOn:aTabView) > maxY ifTrue:[maxY := y].
-        (x := aLabel  widthOn:aTabView) > maxX ifTrue:[maxX := x].
-        self new label:aLabel for:aTabView
+
+    list := aList collect:[:anEntry||y x tab lbl|
+        tab := self new label:anEntry for:aTabView.
+        lbl := tab printableLabel.
+
+        (y := lbl heightOn:aTabView) > maxY ifTrue:[maxY := y].
+        (x := lbl  widthOn:aTabView) > maxX ifTrue:[maxX := x].
+
+        tab
     ].
 
     style at:#labelMaxX put:maxX.
@@ -214,6 +220,41 @@
     "change line number
     "
     lineNr := aLineNr
+!
+
+printableLabel
+
+    |lbl dev|
+
+    printableLabel notNil ifTrue:[
+        ^ printableLabel
+    ].
+
+    model isNil ifTrue:[
+        lbl := label
+    ] ifFalse:[
+        lbl := model rawLabel
+    ].
+
+    dev := tabView device.
+
+    lbl isImage ifTrue:[
+        labelType := #image.
+        printableLabel := lbl onDevice:dev.
+        disabledLabel  := printableLabel lightened onDevice:dev. 
+    ] ifFalse:[
+        labelType := #string.
+
+        printableLabel := lbl ? ''.
+        disabledLabel  := printableLabel copy.
+
+        lbl class == LabelAndIcon ifTrue:[
+            lbl := printableLabel icon onDevice:dev.
+            printableLabel icon:lbl.
+            disabledLabel  icon:(lbl lightened onDevice:dev). 
+        ]
+    ].
+  ^ printableLabel
 ! !
 
 !TabWidget methodsFor:'accessing dimensions'!
@@ -258,7 +299,7 @@
     "
     ^    (tabView styleAt:#maxX)
        - (tabView styleAt:#labelMaxX)
-       + (label  widthOn:tabView).
+       + (self printableLabel widthOn:tabView).
 !
 
 preferredExtentY
@@ -266,7 +307,7 @@
     "
     ^    (tabView styleAt:#maxY)
        - (tabView styleAt:#labelMaxY)
-       + (label  heightOn:tabView).
+       + (self printableLabel heightOn:tabView).
 ! !
 
 !TabWidget methodsFor:'basic drawing'!
@@ -295,62 +336,62 @@
     ^ self subclassResponsibility
 ! !
 
+!TabWidget methodsFor:'change & update'!
+
+labelChanged
+    printableLabel := nil
+! !
+
 !TabWidget methodsFor:'drawing'!
 
 redraw:isSelected
     "redraw tab
     "
-    |direction origin anchor x y|
+    |direction|
 
     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].
-        self setLabelColor.
+    direction == #top ifTrue:[
+        self redrawAtTop:isSelected
     ] ifFalse:[
-        direction == #right ifTrue:[
-            self redrawAtRight:isSelected.
-            x := origin x - anchor y - (label heightOn:tabView).
+        direction == #bottom ifTrue:[
+            self redrawAtBottom:isSelected
         ] ifFalse:[
-            self redrawAtLeft:isSelected.
-            x := origin x + anchor y.
-        ].
-        self setLabelColor.
-        y := origin y + anchor x.
-
-        label isString ifTrue:[
-            x := x + tabView font descent.
-            tabView displayString:label x:x y:y angle:90.
-          ^ self.
-        ].
+            direction == #right ifTrue:[ self redrawAtRight:isSelected ]
+                               ifFalse:[ self redrawAtLeft:isSelected ]
+        ]
     ].
-    label displayOn:tabView x:x y:y.
-
-    "Modified: 23.4.1997 / 17:28:49 / cg"
+    self redrawLabel
 !
 
 redrawLabel
     "redraw label only
     "
-    |direction origin anchor x y|
+    |fg direction origin anchor x y label |
 
+    label     := self printableLabel.
     direction := tabView direction.
     anchor    := tabView styleAt:#labelAnchor.
     origin    := self computeOrigin.
 
-    self setLabelColor.
+ "/ set label color
+
+    self printableLabel.
+
+    self isEnabled ifTrue:[
+        label := printableLabel.
+        (model notNil and:[(fg := model foregroundColor) notNil]) ifTrue:[
+            fgColor = fg ifFalse:[
+                fgColor := fg on:(tabView device)
+            ].
+            tabView paint:fgColor
+        ] ifFalse:[
+            tabView paintColor:#labelColor
+        ]
+    ] ifFalse:[
+        label := disabledLabel.
+        tabView paintColor:#shadowColorUnselected.
+    ].
 
     (direction == #top or:[direction == #bottom]) ifTrue:[
         y := origin y.
@@ -361,7 +402,9 @@
         ] ifFalse:[
             y := y - anchor y - (label heightOn:tabView).
         ].
-        label isString ifTrue:[y := y + tabView font ascent].
+        labelType == #string ifTrue:[
+            y := y + tabView fontAscent
+        ].
     ] ifFalse:[
         direction == #right ifTrue:[
             x := origin x - anchor y - (label heightOn:tabView).
@@ -370,23 +413,13 @@
         ].
         y := origin y + anchor x.
 
-        label isString ifTrue:[
-            x := x + tabView font descent.
+        labelType == #string ifTrue:[
+            x := x + tabView fontDescent.
             tabView displayString:label x:x y:y angle:90.
           ^ self.
         ].
     ].
     label displayOn:tabView x:x y:y.
-!
-
-setLabelColor
-    "set the label color dependant on the enabled state of the tabView
-    "
-    (tabView isTabSelectable:self) ifTrue:[
-        tabView paintColor:#labelColor.
-    ] ifFalse:[
-        tabView paintColor:#shadowColorUnselected.
-    ]
 ! !
 
 !TabWidget methodsFor:'initialization'!
@@ -396,6 +429,8 @@
     "
     tabView := aTabView.
     label   := aLabel.
+    model   := (label isKindOf:TabItem) ifTrue:[label] ifFalse:[nil]
+        
 ! !
 
 !TabWidget methodsFor:'private'!
@@ -488,6 +523,17 @@
     ].
 
     ^ aRectangle intersects:irect
+!
+
+isEnabled
+
+    ^ (tabView isEnabled and:[(model isNil or:[model isEnabled])])
+
+!
+
+model
+    ^ model
+
 ! !
 
 !TabWidget::Mac class methodsFor:'accessing'!
@@ -998,5 +1044,5 @@
 !TabWidget class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/TabWidget.st,v 1.13 1998-01-20 19:00:34 ca Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/TabWidget.st,v 1.14 1998-01-28 14:09:48 ca Exp $'
 ! !