class: NoteBookView
authorClaus Gittinger <cg@exept.de>
Sun, 10 May 2015 01:13:27 +0200
changeset 4761 574f905443bd
parent 4760 988451c16c3e
child 4762 b91fc50400f1
class: NoteBookView add tab button; unfinished.
NoteBookView.st
--- a/NoteBookView.st	Fri May 08 14:57:01 2015 +0200
+++ b/NoteBookView.st	Sun May 10 01:13:27 2015 +0200
@@ -28,13 +28,15 @@
 		showDestroyTabButton destroyTabAction activeTabMarkerColor
 		activeTabMarkerFGColor tabWasActiveWhenPressed removeTabIcon
 		removeTabEnteredIcon removeTabDisabledIcon
-		showingEnteredRemoveTabButton lastUserSelection minimumTabWidth'
+		showingEnteredRemoveTabButton lastUserSelection minimumTabWidth
+		addTabAction addTabIcon addTabEnteredIcon addTabDisabledIcon
+		showingEnteredAddTabButton'
 	classVariableNames:'DefaultForegroundColor DefaultBackgroundColor
 		DefaultActiveForegroundColor DefaultActiveBackgroundColor
 		DefaultShadowColor DefaultHalfShadowColor DefaultLightColor
 		DefaultHalfLightColor DefaultEdgeStyle DisabledForegroundColor
 		DefaultActiveTabMarkerColor DefaultActiveTabMarkerFgColor
-		RemoveTabIcon RemoveTabEnteredIcon'
+		RemoveTabIcon RemoveTabEnteredIcon AddTabIcon AddTabEnteredIcon'
 	poolDictionaries:''
 	category:'Views-Layout'
 !
@@ -79,7 +81,7 @@
 
 examples
 "
-    tabs at top & bottom
+  tabs at top & bottom
                                                                                 [exBegin]                                      
     |top tab1 tab2|
 
@@ -95,7 +97,7 @@
                                                                                 [exEnd]
 
 
-    tabs at left & right
+  tabs at left & right
                                                                                 [exBegin]                                      
     |top tab1 tab2|
 
@@ -110,6 +112,40 @@
     top open.
                                                                                 [exEnd]
 
+  tabs at top & bottom, with add-tab button
+                                                                                [exBegin]                                      
+    |top tab1 tab2|
+
+    top := StandardSystemView extent:300@100.
+    tab1 := NoteBookView origin:0.0 @ 0.0 corner:1.0 @ 0.5 in:top.
+    tab1 addTabAction:[ self halt ].
+    tab1 direction:#top.
+    tab1 list:#( 'Foo' 'Bagr' 'Baz' 'Bgar' 'Baqz'  ).
+
+    tab2 := NoteBookView origin:0.0 @ 0.5 corner:1.0 @ 1.0 in:top.
+    tab2 addTabAction:[ self halt ].
+    tab2 direction:#bottom.
+    tab2 list:#( 'Foo' 'Bagr' 'Baz' 'Bgar' 'Baqz'  ).
+    top open.
+                                                                                [exEnd]
+
+  tabs at left & right, with add-tab button
+                                                                                [exBegin]                                      
+    |top tab1 tab2|
+
+    top := StandardSystemView extent:100@300.
+    tab1 := NoteBookView origin:0.0 @ 0.0 corner:0.5 @ 01.0 in:top.
+    tab1 addTabAction:[ self halt ].
+    tab1 direction:#left.
+    tab1 list:#( 'Foo' 'Bagr' 'Baz' 'Bgar' 'Baqz'  ).
+
+    tab2 := NoteBookView origin:0.5 @ 0.0 corner:1.0 @ 1.0 in:top.
+    tab2 addTabAction:[ self halt ].
+    tab2 direction:#right.
+    tab2 list:#( 'Foo' 'Bagr' 'Baz' 'Bgar' 'Baqz'  ).
+    top open.
+                                                                                [exEnd]
+
 "
 ! !
 
@@ -182,6 +218,8 @@
     ] ifFalse:[
         RemoveTabIcon := RemoveTabEnteredIcon := nil.   
     ].
+    AddTabIcon := ToolbarIconLibrary addTabIcon.
+    AddTabEnteredIcon := ToolbarIconLibrary addTabEnteredIcon.   
 
     "
      self updateStyleCache
@@ -914,6 +952,13 @@
 
 !NoteBookView methodsFor:'accessing-style'!
 
+addTabAction:aBlockOrNil
+    "if not nil, an add-tab button is shown beside the tab list,
+     which calls aBlock"
+
+    addTabAction := aBlockOrNil
+!
+
 canvasInset
     "inset of the canvas relative to my frame
         tabLevel + canvasInset == origin of canvas
@@ -1304,6 +1349,33 @@
     ].
 !
 
+drawAddTabButton
+    "redraw the add-tab button"
+
+    |bFrame icon|
+
+    bFrame := self frameForAddTabButton.
+
+self paint:(showingEnteredAddTabButton ifTrue:[Color green]ifFalse:[Color red]).
+self fillRectangle:bFrame.
+self paint:Color black.
+
+    AddTabIcon notNil ifTrue:[
+        addTabIcon isNil ifTrue:[
+            addTabIcon := AddTabIcon onDevice:(self device).
+            addTabEnteredIcon := AddTabEnteredIcon onDevice:(self device).
+        ].
+        showingEnteredAddTabButton 
+            ifTrue:[icon := addTabEnteredIcon]
+            ifFalse:[icon := addTabIcon].
+        icon displayOn:self at:bFrame origin.
+    ] ifFalse:[
+        self displayRectangle:bFrame.
+        self displayLineFrom:bFrame leftCenter+(1@0) to:bFrame rightCenter-(1@0).
+        self displayLineFrom:bFrame topCenter+(0@1) to:bFrame bottomCenter-(0@1).
+    ]
+!
+
 drawBorderEdges
     |layout x0 x1 y0 y1 trans|
 
@@ -1665,11 +1737,11 @@
 
     numberOfLines isNil ifTrue:[
         self recomputeList.
-"/ CA original: - should we redraw all below anyway?
-"/        numberOfLines notNil ifTrue:[
-"/            self invalidate
-"/        ].
-"/        ^ self
+        "/ CA original: - should we redraw all below anyway?
+        "/        numberOfLines notNil ifTrue:[
+        "/            self invalidate
+        "/        ].
+        "/        ^ self
         numberOfLines isNil ifTrue:[
             ^ self
         ].
@@ -1682,6 +1754,7 @@
             ^ self
         ]
     ].
+    
     damage := Rectangle left:x top:y width:w height:h.
 
     "/ draw the damage intersects the tabs with my superViews background
@@ -1697,6 +1770,11 @@
         self fillRectangle:r.
     ].
 
+    addTabAction notNil ifTrue:[
+        (damage intersects:(self frameForAddTabButton)) ifTrue:[
+            self drawAddTabButton
+        ].
+    ].
 "/ OLD CODE    
 "/    myRectangle := Rectangle origin:0@0 extent:self extent.
 "/
@@ -1751,7 +1829,7 @@
 !NoteBookView methodsFor:'event handling'!
 
 buttonMotion:buttonState x:x y:y
-    |tab mustShowEntered|
+    |tab mustShowEntered newEntered|
 
     "/ if we have to show a different icon while over the tab...
     tab := self tabContainingPointX:x y:y.
@@ -1765,6 +1843,14 @@
         ].
     ].
 
+    addTabAction notNil ifTrue:[
+        newEntered := self frameForAddTabButton containsPoint:(x@y).
+        (newEntered ~= showingEnteredAddTabButton) ifTrue:[
+            showingEnteredAddTabButton := newEntered.
+            self drawAddTabButton.   
+        ].
+    ].
+
     super buttonMotion:buttonState x:x y:y
 
     "Modified: / 01-03-2007 / 17:07:41 / cg"
@@ -1827,6 +1913,13 @@
 
     isDestroyAction := false.
 
+    addTabAction notNil ifTrue:[
+        (self frameForAddTabButton containsPoint:(x@y)) ifTrue:[
+            addTabAction value.
+            ^ self.
+        ].
+    ].
+
     tabWasActiveWhenPressed ifTrue:[    
         idx := list findFirst:[:aTab| 
                             (self isDestroyTabButtonShownFor:aTab)
@@ -1900,6 +1993,12 @@
             self drawDestroyButtonForTab:tab.    
         ]
     ].
+    addTabAction notNil ifTrue:[ 
+        showingEnteredAddTabButton ifTrue:[
+            showingEnteredRemoveTabButton := false.
+            self drawAddTabButton.   
+        ].
+    ].
     super pointerLeave:state
 !
 
@@ -2354,7 +2453,7 @@
     tabTopMargin    := styleSheet at:#'noteBook.tabTopMargin' default:4.
     tabBottomMargin := styleSheet at:#'noteBook.tabBottomMargin' default:1.
 
-    showingEnteredRemoveTabButton := false.
+    showingEnteredRemoveTabButton := showingEnteredAddTabButton := false.
     tabWasActiveWhenPressed := false.
 
     self lineWidth:0.
@@ -2491,6 +2590,42 @@
     ^ computedLayout
 !
 
+frameForAddTabButton
+    |firstTab w h m frameHeight frameWidth|
+
+    list isEmptyOrNil ifTrue:[^ nil].
+
+    m := 2.
+
+    w := h := 16.
+    addTabIcon notNil ifTrue:[
+        w := addTabIcon width.
+        h := addTabIcon height
+    ].
+
+    firstTab := list first unselectedLayout.
+
+    self isHorizontal ifTrue:[
+        frameHeight := firstTab height.
+        direction == #top ifTrue:[ 
+            ^ Rectangle origin:( (width-w-m) @ (frameHeight-h))
+                        extent:( w @ h )
+        ].
+        "/ bottom
+        ^ Rectangle origin:( (width-w-m) @ (height-frameHeight))
+                    extent:( w @ h)
+    ] ifFalse:[
+        frameWidth := firstTab width.
+        direction == #right ifTrue:[ 
+            ^ Rectangle origin:( (width-w-m) @ (height-20))
+                        extent:( w @ h)
+        ].
+        "/ left
+        ^ Rectangle origin:( m @ (height-20))
+                    extent:( w @ h)
+    ].
+!
+
 makeToBaseLine:aLnNr
     "rotate lines to make the line #aLnNr be the new base line (i.e.
      subtract (aLnNr-1) from all lines and take modulu the number of lines"
@@ -2599,6 +2734,9 @@
     rightMargin   := self tabRightMargin.
     minLeft       := leftMargin + selectionInsetX.
     maxRight      := self width - rightMargin - selectionInsetX.
+    addTabAction notNil ifTrue:[
+        maxRight := maxRight - self horizontalMarginForAddTabButton
+    ].
     xLeft         := minLeft.
     isScrollable  := self hasScrollButtons.
 
@@ -2696,7 +2834,7 @@
         ]
     ].
 
-    list do:[:aTab | aTab layout:aTab unselectedLayout; selectedLayout:nil ].
+    list do:[:eachTab | eachTab layout:eachTab unselectedLayout; selectedLayout:nil ].
 
     "Modified: / 16-07-2013 / 19:30:36 / cg"
 !
@@ -2728,6 +2866,9 @@
     rightMargin   := self tabRightMargin.
     minTop        := leftMargin + selectionInsetX.
     maxBottom     := self height - rightMargin - selectionInsetX.    
+    addTabAction notNil ifTrue:[
+        maxBottom := maxBottom - self verticalMarginForAddTabButton
+    ].
     yTop          := minTop.
     isScrollable  := self hasScrollButtons.
 
@@ -2902,12 +3043,26 @@
 
 !NoteBookView methodsFor:'private'!
 
+horizontalMarginForAddTabButton
+    "should be changed to be style specific;
+     some (win8) prefer an additional, empty short tab"
+
+    ^ 20 
+!
+
 indexOfTab:aTab
     ^ list indexOf:aTab 
 !
 
 tabContainingPointX:x y:y
     ^ list detect:[:aTab| aTab containsPointX:x y:y ] ifNone:nil.
+!
+
+verticalMarginForAddTabButton
+    "should be changed to be style specific;
+     some (win8) prefer an additional, empty short tab"
+
+    ^ 20 
 ! !
 
 !NoteBookView methodsFor:'private-buttons'!
@@ -3793,10 +3948,10 @@
 !NoteBookView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/NoteBookView.st,v 1.192 2015-05-08 12:57:01 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/NoteBookView.st,v 1.193 2015-05-09 23:13:27 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libwidg2/NoteBookView.st,v 1.192 2015-05-08 12:57:01 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/NoteBookView.st,v 1.193 2015-05-09 23:13:27 cg Exp $'
 ! !