colors derived from background
authorca
Wed, 11 Jun 1997 15:58:20 +0200
changeset 419 893e322a86e9
parent 418 94d3a2f73e75
child 420 b6f9fff472ef
colors derived from background
NoteBookView.st
TabWidget.st
--- a/NoteBookView.st	Wed Jun 11 15:57:43 1997 +0200
+++ b/NoteBookView.st	Wed Jun 11 15:58:20 1997 +0200
@@ -118,9 +118,16 @@
         corner := canvas corner.
         canvas destroy.
 
-        (canvas := aCanvas) isNil ifTrue:[canvas := View in:self]
-                                 ifFalse:[self addSubView:canvas].
+        (canvas := aCanvas) isNil ifTrue:[
+            canvas := View in:self
+        ] ifFalse:[
+            self addSubView:canvas.
 
+            canvas allSubViewsDo:[:s|
+                s font:font.
+                s viewBackground:viewBackground
+            ].
+        ].
         canvas origin:origin corner:corner.
     ]
 !
@@ -135,12 +142,33 @@
     ].
     canvasHolder := aValueHolder .
     self canvas:(canvasHolder value).
+! !
+
+!NoteBookView methodsFor:'accessing look'!
+
+backgroundColor:aColor
+    "change viewBackground
+    "
+    self viewBackground:aColor
 !
 
 font:aFont
+    "set a font
+    "
     super font:aFont.
     tabRaw font:aFont.
+    canvas allSubViewsDo:[:s| s font:font].
 
+!
+
+viewBackground:aColor
+    "viewBackground changed
+    "
+    viewBackground ~~ aColor ifTrue:[
+        super  viewBackground:aColor.
+        tabRaw viewBackground:viewBackground.
+        canvas allSubViewsDo:[:s| s viewBackground:viewBackground].
+    ]
 ! !
 
 !NoteBookView methodsFor:'actions'!
@@ -247,9 +275,9 @@
     tabRaw := TabView origin:0.0@0.0 corner:1.0@0.0 in:self.
     canvas := View    origin:0.0@0.0 corner:1.0@1.0 in:self.
     tabRaw addDependent:self.
-    self delegate:(KeyboardForwarder from:self toView:tabRaw).
-    canvas viewBackground:(tabRaw styleAt:#selectedColor).
-
+    self delegate:(KeyboardForwarder toView:tabRaw
+                condition:nil
+                filter:[:key | key size > 6 and:[key startsWith:#Cursor]]).
 
 ! !
 
@@ -262,5 +290,5 @@
 !NoteBookView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/NoteBookView.st,v 1.5 1997-06-04 11:17:40 ca Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/NoteBookView.st,v 1.6 1997-06-11 13:58:20 ca Exp $'
 ! !
--- a/TabWidget.st	Wed Jun 11 15:57:43 1997 +0200
+++ b/TabWidget.st	Wed Jun 11 15:58:20 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:''
@@ -115,32 +115,65 @@
 
 !TabWidget class methodsFor:'accessing'!
 
+computeColorsOn:aView style:aStyle
+    "set colors dependent on selection color
+    "
+    |unselectedColor selectedColor|
+
+    selectedColor   := aView viewBackground.
+    unselectedColor := selectedColor lightened.
+
+    aStyle at:#shadowColorSelected
+         put:((selectedColor averageColorIn:(0@0 corner:7@7)) darkened  on:aView device).
+
+    aStyle at:#lightColorSelected
+         put:((selectedColor averageColorIn:(0@0 corner:7@7)) lightened on:aView device).
+
+    aStyle at:#shadowColorUnselected
+         put:((unselectedColor averageColorIn:(0@0 corner:7@7)) darkened  on:aView device).
+
+    aStyle at:#lightColorUnselected
+         put:((unselectedColor averageColorIn:(0@0 corner:7@7)) lightened on:aView device).
+
+    aStyle at:#unselectedColor    put:unselectedColor.
+    aStyle at:#selectedColor      put:selectedColor.
+    aStyle at:#labelColor         put:Color black.
+!
+
+computeColorsOn:aView style:aStyle selectionColor:aSelectedColor
+    "set colors dependent on selection color
+    "
+    |unselectedColor selectedColor|
+
+    unselectedColor := aView viewBackground.
+    selectedColor   := unselectedColor lightened.
+
+    aStyle at:#shadowColorSelected
+         put:((selectedColor averageColorIn:(0@0 corner:7@7)) darkened  on:aView device).
+
+    aStyle at:#lightColorSelected
+         put:((selectedColor averageColorIn:(0@0 corner:7@7)) lightened on:aView device).
+
+    aStyle at:#shadowColorUnselected
+         put:((unselectedColor averageColorIn:(0@0 corner:7@7)) darkened  on:aView device).
+
+    aStyle at:#lightColorUnselected
+         put:((unselectedColor averageColorIn:(0@0 corner:7@7)) lightened on:aView device).
+
+    aStyle at:#unselectedColor    put:unselectedColor.
+    aStyle at:#selectedColor      put:selectedColor.
+    aStyle at:#labelColor         put:Color black.
+!
+
 tabStyleOn:aView
     "returns default tab style
     "
-    |style selectedColor unselectedColor|
+    |style|
 
-    style    := IdentityDictionary new.
-    selectedColor   := Color gray:90.
-    unselectedColor := Color gray:75.
+    style := IdentityDictionary new.
 
     style at:#widget put:self.
-
-    style at:#shadowColorSelected
-         put:((selectedColor averageColorIn:(0@0 corner:7@7)) darkened  on:aView device).
-
-    style at:#lightColorSelected
-         put:((selectedColor averageColorIn:(0@0 corner:7@7)) lightened on:aView device).
-
-    style at:#shadowColorUnselected
-         put:((unselectedColor averageColorIn:(0@0 corner:7@7)) darkened  on:aView device).
-
-    style at:#lightColorUnselected
-         put:((unselectedColor averageColorIn:(0@0 corner:7@7)) lightened on:aView device).
-
-    style at:#unselectedColor    put:unselectedColor.
-    style at:#selectedColor      put:selectedColor.
-    style at:#labelColor         put:(Color black).
+    self computeColorsOn:aView style:style.
 
     style at:#expandSelection    put:0@0.    "/ expand selection extent x y when raised
     style at:#tabLevel           put:0.      "/ level
@@ -308,6 +341,44 @@
     "Modified: 23.4.1997 / 17:28:49 / cg"
 !
 
+redrawLabel
+    "redraw label only
+    "
+    |direction origin anchor x y|
+
+    direction := tabView direction.
+    anchor    := tabView styleAt:#labelAnchor.
+    origin    := self computeOrigin.
+
+    self setLabelColor.
+
+    (direction == #top or:[direction == #bottom]) ifTrue:[
+        y := origin y.
+        x := origin x + anchor x.
+
+        direction == #top ifTrue:[
+            y := y + anchor y.
+        ] ifFalse:[
+            y := y - anchor y - (label heightOn:tabView).
+        ].
+        label isString ifTrue:[y := y + tabView font ascent].
+    ] ifFalse:[
+        direction == #right ifTrue:[
+            x := origin x - anchor y - (label heightOn:tabView).
+        ] ifFalse:[
+            x := origin x + anchor y.
+        ].
+        y := origin y + anchor x.
+
+        label isString ifTrue:[
+            x := x + tabView font descent.
+            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
     "
@@ -391,222 +462,6 @@
     ^ false
 ! !
 
-!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::Window class methodsFor:'accessing'!
 
 tabStyleOn:aView
@@ -896,8 +751,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.8 1997-06-04 11:18:42 ca Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/TabWidget.st,v 1.9 1997-06-11 13:58:02 ca Exp $'
 ! !