DSVColumnView.st
changeset 861 a227a3ca27e7
parent 859 e63eb6f321e1
child 872 ad92183a6e6b
equal deleted inserted replaced
860:64d52b8e3dbd 861:a227a3ca27e7
   693 
   693 
   694 add:aRow beforeIndex:aRowNr
   694 add:aRow beforeIndex:aRowNr
   695     "add a new row before slot aRowNr and redisplay; returns nil in case
   695     "add a new row before slot aRowNr and redisplay; returns nil in case
   696      of an invalid index or the row
   696      of an invalid index or the row
   697     "
   697     "
   698     |y0 y1 h dH|
   698     self addAll:(Array with:aRow) beforeIndex:aRowNr.
   699 
   699     ^ aRow.
   700     list isNil ifTrue:[
   700 !
   701         list := OrderedCollection new.
   701 
   702         preferredExtent := nil.         "/ force a recomputation
   702 addAll:aList beforeIndex:start
       
   703     "add a collection of rows before slot start and redisplay
       
   704     "
       
   705     |y0 y1 yD h dH size noSel|
       
   706 
       
   707     (size := aList size) == 0 ifTrue:[
       
   708         ^ self
       
   709     ].
       
   710 
       
   711     self size == 0 ifTrue:[
       
   712         ^ self list:aList
   703     ].
   713     ].
   704 
   714 
   705     beDependentOfRows ifTrue:[
   715     beDependentOfRows ifTrue:[
   706         aRow notNil ifTrue:[aRow addDependent:self].
   716         aList do:[:aRow| aRow notNil ifTrue:[aRow addDependent:self]]
   707     ].
   717     ].
   708 
   718 
   709     list add:aRow beforeIndex:aRowNr.
   719     noSel := self numberOfSelections.
   710 
   720 
   711     self recomputeHeightOfContents.
   721     noSel ~~ 0 ifTrue:[
   712 
   722         multipleSelectOk ifFalse:[
   713     (y0 := self numberOfSelections) ~~ 0 ifTrue:[
   723             selectedRowIndex >= start ifTrue:[
   714         y0 == 1 ifTrue:[
   724                 selectedRowIndex := selectedRowIndex + size
   715             (y0 := self firstIndexSelected) >= aRowNr ifTrue:[
   725             ]
   716                 y0 := y0 + 1.
   726         ] ifTrue:[
   717                 multipleSelectOk ifFalse:[
   727             1 to:noSel do:[:i||v|
   718                     selectedRowIndex := y0
   728                 (v := selectedRowIndex at:i) >= start ifTrue:[
   719                 ] ifTrue:[
   729                     selectedRowIndex at:i put:(v + size)
   720                     selectedRowIndex at:1 put:y0
       
   721                 ]
   730                 ]
   722             ]
   731             ]
   723         ] ifFalse:[
   732         ]
   724             self deselect
   733     ].
   725         ]
   734     list addAll:aList beforeIndex:start.
   726     ].
   735     self recomputeHeightOfContents.
   727 
   736 
   728     y0 := (aRowNr - 1) * rowHeight.
   737     y0 := (start - 1) * rowHeight.
       
   738     yD := size * rowHeight.
       
   739     y1 := y0 + yD.
   729 
   740 
   730     y0 < viewOrigin y ifTrue:[
   741     y0 < viewOrigin y ifTrue:[
   731         self originWillChange.
   742         self originWillChange.
   732         viewOrigin y:(rowHeight + viewOrigin y).
   743         viewOrigin y:(yD + viewOrigin y).
   733         self originChanged:(0 @ rowHeight).        
   744         self originChanged:(0 @ yD).
   734     ].
   745     ].
   735 
   746 
   736     (shown not or:[self sensor hasDamageFor:self]) ifFalse:[
   747     (shown not or:[self sensor hasDamageFor:self]) ifTrue:[
   737         y0 := self yVisibleOfRowNr:aRowNr.
   748         ^ self contentsChanged.
   738         y1 := y0 + rowHeight.
   749     ].
   739 
   750 
   740         (y1 > margin and:[y0 < (h := height - margin)]) ifTrue:[
   751     y0 := self yVisibleOfRowNr:start.
   741             h  := h - y1.
   752     y1 := y0 + yD.
   742             y0 := y0 max:margin.
   753 
   743             dH := y1 - y0.
   754     (y1 > margin and:[y0 < (h := height - margin)]) ifTrue:[
   744             aRowNr == list size ifFalse:[
   755         h  := h - y1.
   745                 self catchExpose.
   756         y0 := y0 max:margin.
   746 
   757         dH := y1 - y0.
   747                 self copyFrom:self x:0 y:y0
   758 
   748                                  toX:0 y:y1
   759         start == list size ifFalse:[
   749                                width:width height:h async:true.
   760             self catchExpose.
   750 
   761 
   751                 self waitForExpose
   762             self copyFrom:self x:0 y:y0
   752             ].
   763                              toX:0 y:y1
   753             self redrawX:margin y:y0 width:width - margin - margin height:dH.
   764                            width:width height:h async:true.
   754         ]
   765 
       
   766             self waitForExpose
       
   767         ].
       
   768         self redrawX:margin y:y0 width:width - margin - margin height:dH.
   755     ].
   769     ].
   756     self contentsChanged.
   770     self contentsChanged.
   757   ^ aRow
   771 
   758 !
       
   759 
       
   760 addAll:aCollection beforeIndex:aRowNr
       
   761     "add a collection of rows before slot aRowNr and redisplay
       
   762     "
       
   763     aCollection size ~~ 0 ifTrue:[
       
   764         self size == 0 ifTrue:[
       
   765             ^ self list:aCollection
       
   766         ].
       
   767         aCollection reverseDo:[:aRow|
       
   768             self add:aRow beforeIndex:aRowNr
       
   769         ]
       
   770     ].
       
   771 !
   772 !
   772 
   773 
   773 addFirst:aRow
   774 addFirst:aRow
   774     "insert a row at start
   775     "insert a row at start
   775     "
   776     "
   780     "remove first row; returns the removed row
   781     "remove first row; returns the removed row
   781     "
   782     "
   782     self removeIndex:1
   783     self removeIndex:1
   783 !
   784 !
   784 
   785 
   785 removeIndex:aRowNr
   786 removeFrom:startIndex to:stopIndex
   786     "remove row at an index; returns the removed row
   787     "remove rows from start to stop
   787     "
   788     "
   788     |y0 y1 h dY oY yB noRedraw row|
   789     |coll noRedraw
   789 
   790      noSel "{ Class: SmallInteger }"
   790     row := list at:aRowNr ifAbsent:[^ self subscriptBoundsError:aRowNr].
   791      size  "{ Class: SmallInteger }"
   791 
   792      start "{ Class: SmallInteger }"
   792     (beDependentOfRows and:[row notNil]) ifTrue:[
   793      stop  "{ Class: SmallInteger }"
   793         row removeDependent:self
   794      y0    "{ Class: SmallInteger }"
   794     ].
   795      y1    "{ Class: SmallInteger }"
   795 
   796      oY    "{ Class: SmallInteger }"
   796     (y0 := self numberOfSelections) ~~ 0 ifTrue:[
   797      dY    "{ Class: SmallInteger }"
   797         y0 == 1 ifTrue:[
   798      yB    "{ Class: SmallInteger }"
   798             (y0 := self firstIndexSelected) > aRowNr ifTrue:[
   799      h     "{ Class: SmallInteger }"
   799                 y0 := y0 - 1.
   800     |
   800                 multipleSelectOk ifFalse:[
   801 
   801                     selectedRowIndex := y0
   802     (    (start := startIndex) < 1
   802                 ] ifTrue:[
   803      or:[(stop := stopIndex) > list size]
   803                     selectedRowIndex at:1 put:y0
   804     ) ifTrue:[
   804                 ]
   805         ^ self subscriptBoundsError:start
   805             ] ifFalse:[
   806     ].
   806                 y0 == aRowNr ifTrue:[
   807     size := stop - start + 1.
       
   808 
       
   809     beDependentOfRows ifTrue:[
       
   810         list from:start to:stop do:[:r| r notNil ifTrue:[r removeDependent:self]].
       
   811     ].
       
   812     noSel := self numberOfSelections.
       
   813 
       
   814     noSel ~~ 0 ifTrue:[
       
   815         noSel == 1 ifTrue:[
       
   816             noSel := self firstIndexSelected.
       
   817 
       
   818             noSel < start ifFalse:[
       
   819                 noSel > stop ifTrue:[
       
   820                     noSel := noSel - size.
       
   821 
       
   822                     multipleSelectOk ifFalse:[selectedRowIndex := noSel]
       
   823                                       ifTrue:[selectedRowIndex at:1 put:noSel]
       
   824                 ] ifFalse:[
   807                     editValue notNil ifTrue:[
   825                     editValue notNil ifTrue:[
   808                         editValue removeDependent:self.
   826                         editValue removeDependent:self.
   809                         editValue := nil.
   827                         editValue := nil.
   810                     ].
   828                     ].
   811                     self deselect
   829                     self deselect.
   812                 ]
   830                 ]
   813             ]
   831             ]
   814         ] ifFalse:[
   832         ] ifFalse:[
   815             self deselect
   833             coll := OrderedCollection new:noSel.
   816         ]
   834 
   817     ].
   835             selectedRowIndex do:[:i|
   818     y1 := aRowNr * rowHeight.
   836                 i < start ifTrue:[
   819     y0 := y1 - rowHeight.
   837                     coll add:i
       
   838                 ] ifFalse:[
       
   839                     i > stop ifTrue:[
       
   840                         coll add:(i - size)
       
   841                     ]
       
   842                 ]
       
   843             ].
       
   844             coll size == 0 ifTrue:[
       
   845                 self deselect
       
   846             ] ifFalse:[
       
   847                 selectedRowIndex := coll
       
   848             ]
       
   849         ]
       
   850     ].
       
   851     list removeFrom:start to:stop.
       
   852 
       
   853     y0 := start - 1 * rowHeight.
       
   854     dY := size * rowHeight.
       
   855     y1 := dY + y0.
   820     yB := y1 + margin - viewOrigin y.
   856     yB := y1 + margin - viewOrigin y.
   821 
       
   822     list removeIndex:aRowNr.
       
   823     self recomputeHeightOfContents.
   857     self recomputeHeightOfContents.
   824 
   858 
   825     y0 < (oY := viewOrigin y) ifTrue:[
   859     y0 < (oY := viewOrigin y) ifTrue:[
   826         (noRedraw := y1 <= oY) ifFalse:[dY := y0 - oY]
   860         (noRedraw := y1 <= oY) ifFalse:[dY := y0 - oY]
   827                                 ifTrue:[dY := rowHeight negated].
   861                                 ifTrue:[dY := dY negated].
   828         self originWillChange.
   862         self originWillChange.
   829         viewOrigin y:(dY + oY).
   863         viewOrigin y:(dY + oY).
   830         self originChanged:(0 @ dY).        
   864         self originChanged:(0 @ dY).        
   831     ] ifFalse:[
   865     ] ifFalse:[
   832         noRedraw := y0 > (height + viewOrigin y)
   866         noRedraw := y0 > (height + viewOrigin y)
   833     ].
   867     ].
   834 
   868 
   835     (noRedraw or:[shown not]) ifFalse:[
   869     (noRedraw or:[shown not]) ifFalse:[
   836         y1 := yB.
   870         y1 := yB.
   837         y0 := self yVisibleOfRowNr:aRowNr.
   871         y0 := self yVisibleOfRowNr:start.
   838         h  := height - margin - yB.
   872         h  := height - margin - yB.
   839         y0 := y0 max:margin.
   873         y0 := y0 max:margin.
   840 
   874 
   841         h > 0 ifTrue:[
   875         h > 0 ifTrue:[
   842             self catchExpose.
   876             self catchExpose.
   845         ].
   879         ].
   846         y0 := y0 + h.
   880         y0 := y0 + h.
   847         self redrawX:margin y:y0 width:width - margin - margin height:(height - y0).
   881         self redrawX:margin y:y0 width:width - margin - margin height:(height - y0).
   848     ].
   882     ].
   849     self contentsChanged.
   883     self contentsChanged.
   850   ^ row.
   884 
       
   885 !
       
   886 
       
   887 removeIndex:aRowNr
       
   888     "remove row at an index; returns the removed row
       
   889     "
       
   890     |row|
       
   891 
       
   892     row := list at:aRowNr ifAbsent:nil.
       
   893     self removeFrom:aRowNr to:aRowNr.
       
   894   ^ row
   851 !
   895 !
   852 
   896 
   853 removeLast
   897 removeLast
   854     "remove last row; the row is returned
   898     "remove last row; the row is returned
   855     "
   899     "
  1263         ]
  1307         ]
  1264     ].
  1308     ].
  1265     selectedRowIndex add:(clickPosition := idx).
  1309     selectedRowIndex add:(clickPosition := idx).
  1266 
  1310 
  1267     scr == 0 ifTrue:[
  1311     scr == 0 ifTrue:[
  1268         self redrawX:margin y:y width:width - margin - margin height:1
  1312         self redrawRowAt:idx colAt:0.
  1269     ] ifFalse:[
  1313     ] ifFalse:[
  1270         self scrollTo:(viewOrigin + (0 @ scr)) redraw:true
  1314         self scrollTo:(viewOrigin + (0 @ scr)) redraw:true
  1271     ].
  1315     ].
  1272 !
  1316 !
  1273 
  1317 
  1328                         self selectionChanged.
  1372                         self selectionChanged.
  1329                       ^ self sensor flushMotionEventsFor:self.
  1373                       ^ self sensor flushMotionEventsFor:self.
  1330                     ]
  1374                     ]
  1331                 ]
  1375                 ]
  1332             ].
  1376             ].
  1333 
       
  1334             (self canDrag and:[self isSelected:rowNr inColumn:colNr]) ifTrue:[
  1377             (self canDrag and:[self isSelected:rowNr inColumn:colNr]) ifTrue:[
  1335                 clickPosition   := x @ y.
  1378                 clickPosition   := x @ y.
  1336                 dragAccessPoint := (colNr @ rowNr).
  1379                 dragAccessPoint := (colNr @ rowNr).
  1337             ] ifFalse:[
  1380             ] ifFalse:[
  1338                 self selectRowAt:rowNr colAt:colNr atPoint:(x @ y)
  1381                 self selectRowAt:rowNr colAt:colNr atPoint:(x @ y)
  2580 ! !
  2623 ! !
  2581 
  2624 
  2582 !DSVColumnView class methodsFor:'documentation'!
  2625 !DSVColumnView class methodsFor:'documentation'!
  2583 
  2626 
  2584 version
  2627 version
  2585     ^ '$Header: /cvs/stx/stx/libwidg2/DSVColumnView.st,v 1.33 1998-04-14 13:36:18 ca Exp $'
  2628     ^ '$Header: /cvs/stx/stx/libwidg2/DSVColumnView.st,v 1.34 1998-04-16 11:00:21 ca Exp $'
  2586 ! !
  2629 ! !