preferredExtent changes & fixes (ubs)
authorClaus Gittinger <cg@exept.de>
Tue, 22 Jul 2008 14:43:27 +0200
changeset 3488 d30da03147fe
parent 3487 5cc0a5d3e1f4
child 3489 f2f5a8273044
preferredExtent changes & fixes (ubs)
DSVColumnView.st
--- a/DSVColumnView.st	Tue Jul 22 14:26:56 2008 +0200
+++ b/DSVColumnView.st	Tue Jul 22 14:43:27 2008 +0200
@@ -29,7 +29,8 @@
 		separatorOneDColor selectionForegroundColor
 		selectionForegroundColorNoFocus selectionBackgroundColor
 		selectionBackgroundColorNoFocus previousExtent
-		selectConditionBlock scrollRowWise autoScrollToColumn'
+		selectConditionBlock scrollRowWise autoScrollToColumn
+		cachedPreferredExtent'
 	classVariableNames:'DefaultForegroundColor DefaultBackgroundColor
 		DefaultHilightForegroundColor DefaultHilightBackgroundColor
 		ButtonLightColor ButtonShadowColor CheckToggleActiveImage
@@ -331,10 +332,10 @@
 heightOfContents
     "return the height of the contents in pixels"
     
-    preferredExtent isNil ifTrue:[
+    cachedPreferredExtent isNil ifTrue:[
         self preferredExtent
     ].
-    ^ preferredExtent y
+    ^ cachedPreferredExtent y
 !
 
 labelView
@@ -374,7 +375,7 @@
 !
 
 preferredLabelViewHeight
-    ^ labelView preferredHeight + (labelView margin + self verticalSpacing * 2).
+    ^ labelView preferredHeight "/ + (labelView margin + self verticalSpacing * 2).
 !
 
 rowFontAscent
@@ -792,7 +793,7 @@
                 DataSetColumn new on:self description:dsc columnNumber:cid label:lbl
             ].
 
-    preferredExtent := nil.
+    cachedPreferredExtent := nil.
     labelView columns:columnDescriptors.
 
     shown ifTrue:[
@@ -1048,7 +1049,7 @@
     selectedRowIndex := multipleSelectOk ifTrue:[nil] ifFalse:[0].
 
     shown ifFalse:[
-        preferredExtent := nil
+        cachedPreferredExtent := nil
     ] ifTrue:[
         aList size == 0 ifTrue:[  
             "/ keep old column-width information
@@ -1056,7 +1057,7 @@
             columnDescriptors notNil ifTrue:[
                 columnDescriptors do:[:aCol| aCol invalidate ].
             ].
-            preferredExtent := nil.
+            cachedPreferredExtent := nil.
         ]
     ].
 
@@ -1084,6 +1085,7 @@
     selectionHasChanged ifTrue:[
         self selectionChanged.
     ].
+    cachedPreferredExtent := nil.
     self contentsChanged.
 ! !
 
@@ -1094,6 +1096,7 @@
     
     (aFont notNil and:[ aFont ~~ font ]) ifTrue:[
         super font:(aFont onDevice:device).
+        rowFontAscent := font ascent.
         realized ifTrue:[
             columnDescriptors do:[:aCol | 
                 aCol invalidate
@@ -1379,7 +1382,7 @@
     ].
     list removeFrom:start to:stop.
 
-    y0 := start - 1 * rowHeight.
+    y0 := (start - 1) * rowHeight.
     dY := size * rowHeight.
     y1 := dY + y0.
     yB := y1 + margin - viewOrigin y.
@@ -1500,7 +1503,7 @@
 changeWidthOfColumn:aColumn deltaX:aDeltaX
 
     aColumn setDescWidth:(aColumn width + aDeltaX).
-    preferredExtent notNil ifTrue:[self fitColumns]
+    cachedPreferredExtent notNil ifTrue:[self fitColumns]
 !
 
 update:what with:aPara from:chgObj 
@@ -1509,6 +1512,7 @@
     |row listHoldersList arg1 arg2 col|
 
     chgObj == columnHolder ifTrue:[
+        cachedPreferredExtent := nil.
         self columnDescriptors:(columnHolder value). 
         ^ self. 
     ].
@@ -1530,11 +1534,13 @@
             ^ self. 
         ].
         what == #list ifTrue:[
+            cachedPreferredExtent := nil.
             self listHolder:model list. 
             ^ self. 
         ].
         what == #value ifTrue:[
             model == listHolder ifTrue:[
+                cachedPreferredExtent := nil.
                 self list:(listHolder value)
             ] ifFalse:[
                 self selectRowIndex:model value
@@ -1544,6 +1550,7 @@
         ^ self
     ].
     chgObj == listHolder ifTrue:[
+        cachedPreferredExtent := nil.
         listHoldersList := listHolder value.
         what == #value ifTrue:[
             self list:listHoldersList. ^ self. 
@@ -1592,6 +1599,7 @@
         self list:listHoldersList.
         ^ self
     ].
+
     arg1 := aPara ? what.
     row := (what isNumber) ifTrue:[what] ifFalse:[chgObj].
     self invalidateVisibleRow:row readSelector:arg1.
@@ -2007,10 +2015,10 @@
             h > minRowHeight ifTrue:[
                 minRowHeight := h.
 
-                preferredExtent notNil ifTrue:[
-                    rowHeight := (minRowHeight + separatorSize + verticalSpacing + verticalSpacing + 1) // 2 * 2.
-                    preferredExtent := Point 
-                                            x: preferredExtent x
+                cachedPreferredExtent notNil ifTrue:[
+"/                    rowHeight := (minRowHeight + separatorSize + verticalSpacing + verticalSpacing + 1) // 2 * 2.
+                    cachedPreferredExtent := Point 
+                                            x: cachedPreferredExtent x
                                             y: (list size * rowHeight).
                     self contentsChanged.
                 ].
@@ -2956,11 +2964,15 @@
     super initialize.
     self lineWidth:0.
 
+    separatorSize      := 1.                            "/ separators mode 2D
+    verticalSpacing    := self class verticalSpacing.
+    horizontalSpacing  := self class horizontalSpacing.
     tabIntern          := true.
     useIndex           := true.
     viewOrigin         := 0@0.
     font               := font onDevice:device.
-    rowHeight          := font height.
+    rowFontAscent      := font ascent.
+    rowHeight          := verticalSpacing + font height + verticalSpacing + separatorSize.
     minRowHeight       := rowHeight.
     multipleSelectOk   := false.                        "/ multiselect disabled
     selectedRowIndex   := 0.                            "/ no selection
@@ -2968,12 +2980,8 @@
     registererImages   := Dictionary new.
     columnDescriptors  := #().
     beDependentOfRows  := false.
-    verticalSpacing    := self class verticalSpacing.
-    horizontalSpacing  := self class horizontalSpacing.
     colorMap           := Dictionary new.
     catchChangeEvents  := false.
-    rowFontAscent      := 1.                            "/ dummy initialization
-    separatorSize      := 1.                            "/ separators mode 2D
     selectRowOnDefault := true.
     autoScroll         := true.
     autoScrollToColumn := true.
@@ -3108,10 +3116,10 @@
 
     |selectedColumn list width changed dX sz oldOrgX newOrgX oldWidth|
 
-    preferredExtent isNil ifTrue:[
+    cachedPreferredExtent isNil ifTrue:[
         self preferredExtent.
     ] ifFalse:[
-        oldWidth := preferredExtent x.
+        oldWidth := cachedPreferredExtent x.
     ].
 
     columnDescriptors isEmpty ifTrue:[
@@ -3128,7 +3136,7 @@
         ].
         width := width + aCol minWidth.
     ].
-    preferredExtent := Point
+    cachedPreferredExtent := Point
                         x: width
                         y: (self preferredHeight).
     width := self innerWidth - width.
@@ -3348,28 +3356,38 @@
 hasPreferredExtent
     "returns true if preferred extent is accumulated"
     
-    ^ preferredExtent notNil
+    ^ cachedPreferredExtent notNil
 !
 
 preferredExtent
-    "recompute preferred extent; raise notification"
+    "return my preferred extent"
     
-    |x|
+    |numRows prefWidth prefHeight|
 
     preferredExtent notNil ifTrue:[
         ^ preferredExtent
     ].
-    x := 3.
+    cachedPreferredExtent notNil ifTrue:[
+        ^ cachedPreferredExtent
+    ].
+    "/ cg: ????? why 3
+    prefWidth := 3.
     columnDescriptors do:[:aCol | 
         minRowHeight := (aCol heightOfHighestRow) max:minRowHeight.
-        x := x + (aCol minWidth).
+        prefWidth := prefWidth + (aCol minWidth).
     ].
-    rowHeight := (minRowHeight + separatorSize + verticalSpacing 
-                + verticalSpacing + 1) 
-                // 2 * 2.
-    preferredExtent := x @ (list size * rowHeight).
-    rowFontAscent := font ascent.
-    ^ preferredExtent
+"/    rowHeight := (minRowHeight + separatorSize + verticalSpacing 
+"/                + verticalSpacing + 1) 
+"/                // 2 * 2.
+    numRows := list size.
+
+    rowHeight := (verticalSpacing + minRowHeight + verticalSpacing + separatorSize). 
+    "/ no need for a separator after the last row.
+    prefHeight := (numRows * rowHeight) - separatorSize.
+    prefHeight := (self preferredLabelViewHeight) + separatorSize + prefHeight + separatorSize.
+
+    cachedPreferredExtent := prefHeight @ prefHeight.
+    ^ cachedPreferredExtent
 !
 
 preferredExtentChanged
@@ -3383,19 +3401,20 @@
     (y ~~ 0 or:[ x ~~ 0 ]) ifTrue:[
         self originWillChange.
         viewOrigin := 0 @ 0.
-        preferredExtent := nil.
+        cachedPreferredExtent := nil.
         self originChanged:(x negated @ y negated).
     ]
 !
 
 recomputeHeightOfContents
     "recompute height of contents( scrolling )"
-    
-    preferredExtent notNil ifTrue:[
-        preferredExtent y:(rowHeight * list size)
-    ] ifFalse:[
-        self preferredExtent
-    ].
+
+    cachedPreferredExtent := nil.
+"/    cachedPreferredExtent notNil ifTrue:[
+"/        cachedPreferredExtent y:(rowHeight * list size)
+"/    ] ifFalse:[
+"/        self preferredExtent
+"/    ].
 ! !
 
 !DSVColumnView methodsFor:'scroller interface'!
@@ -3422,10 +3441,10 @@
 widthOfContents
     "return the width of the contents in pixels"
     
-    preferredExtent isNil ifTrue:[
+    cachedPreferredExtent isNil ifTrue:[
         self preferredExtent
     ].
-    ^ preferredExtent x
+    ^ cachedPreferredExtent x
 !
 
 xOriginOfContents
@@ -4411,5 +4430,5 @@
 !DSVColumnView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/DSVColumnView.st,v 1.234 2008-07-16 16:34:39 fm Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/DSVColumnView.st,v 1.235 2008-07-22 12:43:27 cg Exp $'
 ! !