SelectionInTreeView.st
changeset 900 cd74dcab7e3f
parent 860 64d52b8e3dbd
child 902 de7a2459bd3b
equal deleted inserted replaced
899:68770c9d162d 900:cd74dcab7e3f
    16 		showLines listOfNodes imageInset textInset labelOffsetY lineMask
    16 		showLines listOfNodes imageInset textInset labelOffsetY lineMask
    17 		lineColor computeResources showRoot showDirectoryIndicator
    17 		lineColor computeResources showRoot showDirectoryIndicator
    18 		closeIndicator openIndicator showDirectoryIndicatorForRoot
    18 		closeIndicator openIndicator showDirectoryIndicatorForRoot
    19 		imageOpened imageClosed imageItem discardMotionEvents
    19 		imageOpened imageClosed imageItem discardMotionEvents
    20 		registeredImages supportsExpandAll buildInArray
    20 		registeredImages supportsExpandAll buildInArray
    21 		drawVLinesFromLevel'
    21 		drawVLinesFromLevel highlightMode'
    22 	classVariableNames:''
    22 	classVariableNames:'DefaultHilightMode'
    23 	poolDictionaries:''
    23 	poolDictionaries:''
    24 	category:'Views-Text'
    24 	category:'Views-Text'
    25 !
    25 !
    26 
    26 
    27 !SelectionInTreeView class methodsFor:'documentation'!
    27 !SelectionInTreeView class methodsFor:'documentation'!
   122   ^ 6
   122   ^ 6
   123 
   123 
   124 
   124 
   125 ! !
   125 ! !
   126 
   126 
       
   127 !SelectionInTreeView class methodsFor:'defaults'!
       
   128 
       
   129 updateStyleCache
       
   130     "extract values from the styleSheet and cache them in class variables"
       
   131 
       
   132     <resource: #style (#'selection.highlightMode')>
       
   133 
       
   134     DefaultHilightMode := StyleSheet at:'selection.highlightMode' default:#line.
       
   135     "
       
   136      self updateStyleCache
       
   137     "
       
   138 
       
   139 
       
   140 ! !
       
   141 
   127 !SelectionInTreeView class methodsFor:'resources'!
   142 !SelectionInTreeView class methodsFor:'resources'!
   128 
   143 
   129 closeIndicator
   144 closeIndicator
   130     <resource: #fileImage>
   145     <resource: #fileImage>
   131 
   146 
   180 
   195 
   181 
   196 
   182 ! !
   197 ! !
   183 
   198 
   184 !SelectionInTreeView methodsFor:'accessing'!
   199 !SelectionInTreeView methodsFor:'accessing'!
       
   200 
       
   201 highlightMode
       
   202     "get the mode how to draw a selected line:
       
   203         #line           draw whole line selected
       
   204         #label          draw label selected
       
   205     "
       
   206     ^ highlightMode
       
   207 !
       
   208 
       
   209 highlightMode:aMode
       
   210     "set the mode how to draw a selected line:
       
   211         #line           draw whole line selected
       
   212         #label          draw label selected
       
   213     "
       
   214     |mode|
       
   215 
       
   216     (mode := aMode) == #label ifFalse:[
       
   217         mode := #line
       
   218     ].
       
   219 
       
   220     mode ~~ highlightMode ifTrue:[
       
   221         highlightMode := mode.
       
   222 
       
   223         shown ifTrue:[
       
   224             self invalidate
       
   225         ]
       
   226     ]
       
   227 !
   185 
   228 
   186 lineColor
   229 lineColor
   187     "returns user configured line color or nil
   230     "returns user configured line color or nil
   188     "
   231     "
   189     ^ lineColor
   232     ^ lineColor
   577 
   620 
   578 ! !
   621 ! !
   579 
   622 
   580 !SelectionInTreeView methodsFor:'drawing'!
   623 !SelectionInTreeView methodsFor:'drawing'!
   581 
   624 
   582 drawFromVisibleLine:startVisLineNr to:endVisLineNr with:fg and:bg
       
   583     "redraw a visible line range with clearing the background
       
   584     "
       
   585     |y0 y1 sz|
       
   586 
       
   587     shown ifTrue:[
       
   588         y0  := self yOfVisibleLine:startVisLineNr.
       
   589         y0  := y0 - 1.
       
   590         sz  := endVisLineNr - startVisLineNr + 1.
       
   591         y1  := sz * fontHeight.
       
   592 
       
   593     "/  clear rectangle line and set background color
       
   594         self paint:bg.
       
   595         self fillRectangleX:0 y:y0 width:width height:y1.
       
   596 
       
   597         (y1 := self visibleLineToAbsoluteLine:startVisLineNr) notNil ifTrue:[
       
   598             self redrawLinesX:0 y:y0 toX:width start:y1 stop:(y1 + sz)
       
   599         ]
       
   600     ]
       
   601 !
       
   602 
       
   603 drawLine:line atX:atX inVisible:visLineNr with:fg and:bg
   625 drawLine:line atX:atX inVisible:visLineNr with:fg and:bg
   604     self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg
   626     self drawFromVisibleLine:visLineNr to:visLineNr with:fg and:bg
   605 
   627 
   606 !
   628 !
   607 
   629 
   698         self displayForm:img x:x y:(y - ext y)
   720         self displayForm:img x:x y:(y - ext y)
   699     ].
   721     ].
   700 
   722 
   701 
   723 
   702 
   724 
       
   725 !
       
   726 
       
   727 redrawVisibleLine:visLineNr
       
   728     self drawFromVisibleLine:visLineNr to:visLineNr with:fgColor and:bgColor
       
   729 !
       
   730 
       
   731 redrawVisibleLine:visLineNr from:startCol to:endCol
       
   732     self drawFromVisibleLine:visLineNr to:visLineNr with:fgColor and:bgColor
   703 ! !
   733 ! !
   704 
   734 
   705 !SelectionInTreeView methodsFor:'drawing basics'!
   735 !SelectionInTreeView methodsFor:'drawing basics'!
   706 
   736 
   707 drawLabelIndex:anIndex atX:x y:yCenter
   737 drawFromVisibleLine:startVisLineNr to:endVisLineNr with:fg and:bg
   708     "draw text label at x and y centered
   738     "redraw a visible line range with clearing the background
   709     "
   739     "
   710     |lbl y|
   740     |y h|
   711 
   741 
   712     (lbl := (listOfNodes at:anIndex) name) notNil ifTrue:[
   742     y := self yOfVisibleLine:startVisLineNr.
   713         y := yCenter + labelOffsetY.
   743     h := endVisLineNr - startVisLineNr + 1 * fontHeight.
   714         self displayOpaqueString:lbl x:x y:y.
   744 
   715     ]    
   745     y + h > height ifTrue:[
       
   746         h := height - y
       
   747     ].
       
   748     self redrawX:0 y:y width:width height:h.
   716 !
   749 !
   717 
   750 
   718 drawVHLinesX:x0 y:y0 toX:x1 start:start stop:stop
   751 drawVHLinesX:x0 y:y0 toX:x1 start:start stop:stop
   719     "redraw from line to line without clearing the background
   752     "redraw from line to line without clearing the background
   720     "
   753     "
   833     ].
   866     ].
   834     self mask:nil.
   867     self mask:nil.
   835 
   868 
   836 !
   869 !
   837 
   870 
       
   871 drawVisibleLineSelected:visLineNr with:fg and:bg
       
   872     "redraw a single line as selected."
       
   873     |y|
       
   874 
       
   875     (self visibleLineToListLine:visLineNr) isNil ifTrue:[
       
   876         ^ super drawVisibleLine:visLineNr with:fg and:bg
       
   877     ].
       
   878     self redrawX:0
       
   879                y:(self yOfVisibleLine:visLineNr)
       
   880            width:width
       
   881           height:fontHeight
       
   882 !
       
   883 
       
   884 redrawLabelAt:x y:yTop index:anIndex
       
   885     |isSelected y0 x0 x1 maxX w label i|
       
   886 
       
   887     label       := (listOfNodes at:anIndex) name.
       
   888     isSelected  := self isInSelection:anIndex.
       
   889 
       
   890     highlightMode == #label ifTrue:[
       
   891         x0 := x + 4.
       
   892 
       
   893         isSelected ifTrue:[
       
   894             w  := (label notNil ifTrue:[label widthOn:self] ifFalse:[60]) + 8.
       
   895             self paint:hilightBgColor.
       
   896             self fillRectangleX:x y:yTop width:w height:fontHeight.
       
   897         ]
       
   898     ] ifFalse:[
       
   899         x0 := x
       
   900     ].
       
   901 
       
   902     label notNil ifTrue:[
       
   903         isSelected ifTrue:[self paint:hilightFgColor on:hilightBgColor]
       
   904                   ifFalse:[self paint:fgColor on:bgColor].
       
   905 
       
   906         self displayOpaqueString:label x:x0 y:yTop + (fontHeight // 2) + labelOffsetY.
       
   907     ].
       
   908 
       
   909     (isSelected and:[highlightMode == #label]) ifTrue:[
       
   910         self redrawSelFrameAtX:x y:yTop toX:(x + w)
       
   911     ].
       
   912 
       
   913 !
       
   914 
   838 redrawLinesX:x0 y:y0 toX:x1 start:start stop:stop
   915 redrawLinesX:x0 y:y0 toX:x1 start:start stop:stop
   839     "redraw from line to line without clearing the background
   916     "redraw from line to line without clearing the background
   840     "
   917     "
   841     |node prevNode parent icon showIndc showIcon showText nxtPrnt
   918     |node prevNode parent icon showIndc showIcon showText nxtPrnt
   842 
   919 
   909         (showIcon and:[(icon := self figureFor:node) notNil]) ifTrue:[
   986         (showIcon and:[(icon := self figureFor:node) notNil]) ifTrue:[
   910             self displayForm:icon x:xIcon y:(yCtr - (icon height // 2))
   987             self displayForm:icon x:xIcon y:(yCtr - (icon height // 2))
   911         ].
   988         ].
   912 
   989 
   913         showText ifTrue:[
   990         showText ifTrue:[
   914             (self isInSelection:anIndex) ifFalse:[
   991             self redrawLabelAt:xText y:(yBot - fontHeight) index:anIndex
   915                 self paint:fgColor on:bgColor
       
   916             ] ifTrue:[
       
   917                 self paint:hilightFgColor on:hilightBgColor
       
   918             ].
       
   919             self drawLabelIndex:anIndex atX:xText y:yCtr .
       
   920         ].
   992         ].
   921         (showIndc and:[node showIndicator]) ifTrue:[
   993         (showIndc and:[node showIndicator]) ifTrue:[
   922             icon := node isCollapsable ifTrue:[openIndicator] ifFalse:[closeIndicator].
   994             icon := node isCollapsable ifTrue:[openIndicator] ifFalse:[closeIndicator].
   923             self displayForm:icon x:xIndc y:(yCtr - offIndcY)
   995             self displayForm:icon x:xIndc y:(yCtr - offIndcY)
   924         ].
   996         ].
   925         prevNode := node.
   997         prevNode := node.
   926     ]
   998     ]
   927 !
   999 !
   928 
  1000 
   929 redrawSelFrameForYs:aList fromX:x0 toX:x1
  1001 redrawSelFrameAtX:x0 y:y0 toX:x1
   930     "redraw selection frames for each line starting at an absolute 
  1002     "redraw selection frame for a line
   931      y derived from the argument a list.
  1003     "
   932     "
  1004     |
   933     | 
       
   934      spc "{ Class: SmallInteger }"
       
   935      dY  "{ Class: SmallInteger }"
       
   936      w   "{ Class: SmallInteger }"
  1005      w   "{ Class: SmallInteger }"
   937      y   "{ Class: SmallInteger }" 
  1006      y   "{ Class: SmallInteger }" 
   938      x   "{ Class: SmallInteger }" 
  1007      x   "{ Class: SmallInteger }" 
   939     |
  1008     |
   940     aList isNil ifTrue:[
       
   941         ^ self
       
   942     ].
       
   943     strikeOut ifTrue:[
       
   944         y := fontHeight // 2.
       
   945         self paint:bgColor.
       
   946         aList do:[:sY| self displayLineFromX:x0 y:(sY + y) toX:x1 y:(sY + y) ].
       
   947         ^ self
       
   948     ].
       
   949     spc := lineSpacing // 2.
       
   950 
  1009 
   951     hilightFrameColor notNil ifTrue:[
  1010     hilightFrameColor notNil ifTrue:[
   952         hilightLevel == 0 ifTrue:[
  1011         hilightLevel == 0 ifTrue:[
   953             dY := fontHeight - 1.
       
   954             self paint:hilightFrameColor.
  1012             self paint:hilightFrameColor.
   955 
  1013             self displayLineFromX:x0 y:y0 toX:x1 y:y0.
   956             aList do:[:sY|
  1014             y := y0 + fontHeight - 1.
   957                 y := sY - spc. self displayLineFromX:x0 y:y toX:x1 y:y.
  1015           ^ self displayLineFromX:x0 y:y toX:x1 y:y.
   958                 y := y  + dY.  self displayLineFromX:x0 y:y toX:x1 y:y.
       
   959             ].
       
   960         ]
  1016         ]
   961     ] ifFalse:[
  1017     ] ifFalse:[
   962         hilightStyle == #motif ifTrue:[
  1018         hilightStyle == #motif ifTrue:[
   963             dY := fontHeight - spc - 2.
       
   964             self paint:bgColor.
  1019             self paint:bgColor.
   965 
  1020 
   966             aList do:[:sY|
  1021             y := y0 + 1.
   967                 y := sY - spc + 1. self displayLineFromX:x0 y:y toX:x1 y:y.
  1022             self displayLineFromX:x0 y:y toX:x1 y:y.
   968                 y := sY + dY.      self displayLineFromX:x0 y:y toX:x1 y:y.
  1023             y := y0 + fontHeight - 2.
       
  1024             self displayLineFromX:x0 y:y toX:x1 y:y.
       
  1025         ]
       
  1026     ].
       
  1027 
       
  1028     hilightLevel ~~ 0 ifTrue:[
       
  1029         "/ draw edge
       
  1030 
       
  1031         highlightMode == #line ifTrue:[
       
  1032             w := ((width - (2 * margin)) max:(self widthOfContents)) + leftOffset.
       
  1033             x := margin - leftOffset.
       
  1034         ] ifFalse:[
       
  1035             w := x1 - x0.
       
  1036             x := x0.
       
  1037         ].
       
  1038         self drawEdgesForX:x y:y0 width:w height:fontHeight level:hilightLevel.
       
  1039     ]
       
  1040 
       
  1041 
       
  1042 
       
  1043 !
       
  1044 
       
  1045 redrawX:x y:y width:w height:h
       
  1046     "a region must be redrawn"
       
  1047 
       
  1048     |savClip startLn sel
       
  1049      y0       "{ Class:SmallInteger }"
       
  1050      y1       "{ Class:SmallInteger }"
       
  1051      visStart "{ Class:SmallInteger }"
       
  1052      visEnd   "{ Class:SmallInteger }"
       
  1053      stopLn   "{ Class:SmallInteger }"
       
  1054      maxY     "{ Class:SmallInteger }"
       
  1055      maxX     "{ Class:SmallInteger }"
       
  1056      dltLine  "{ Class:SmallInteger }"
       
  1057      startY   "{ Class:SmallInteger }"|
       
  1058 
       
  1059     shown ifFalse:[^ self].
       
  1060 
       
  1061     visStart := self visibleLineOfY:(y + 1).
       
  1062     startLn  := self visibleLineToAbsoluteLine:visStart.
       
  1063 
       
  1064     self paint:bgColor.
       
  1065     self fillRectangleX:x y:y width:w height:h.
       
  1066     startLn isNil ifTrue:[ ^ self ].
       
  1067 
       
  1068     sel     := nil.
       
  1069     maxX    := x + w.
       
  1070     maxY    := y + h.
       
  1071     visEnd  := self visibleLineOfY:maxY.
       
  1072     startY  := self yOfVisibleLine:visStart.
       
  1073     dltLine := startLn - visStart.
       
  1074     stopLn  := dltLine + visEnd.
       
  1075     savClip := clipRect.
       
  1076 
       
  1077     self clippingRectangle:(Rectangle left:x top:y width:w height:h).
       
  1078 
       
  1079     (highlightMode == #line and:[self hasSelection]) ifTrue:[
       
  1080         "/ redraw the background for all selected lines in the invalid range
       
  1081 
       
  1082         self selectionDo:[:lnNr|
       
  1083             (lnNr between:startLn and:stopLn) ifTrue:[
       
  1084                 sel isNil ifTrue:[
       
  1085                     sel := OrderedCollection new.
       
  1086                     self paint:hilightBgColor.
       
  1087                 ].
       
  1088                 sel add:(y0 := self yOfVisibleLine:(lnNr - dltLine)).
       
  1089                 y1 := y0 + fontHeight min:maxY.
       
  1090                 y0 := y0 max:y.
       
  1091                 self fillRectangleX:x y:y0 width:w height:y1 - y0.
   969             ]
  1092             ]
   970         ]
  1093         ]
   971     ].
  1094     ].
   972 
  1095     self redrawLinesX:x y:startY toX:maxX start:startLn stop:stopLn.
   973     hilightLevel ~~ 0 ifTrue:[
  1096 
   974         "/ draw edge
  1097     "/ draw selection frames
   975 
  1098     sel notNil ifTrue:[
   976         w := ((width - (2 * margin)) max:(self widthOfContents)) + leftOffset.
  1099         sel do:[:y0| self redrawSelFrameAtX:x y:y0 toX:maxX]
   977         x := margin - leftOffset.
  1100     ].
   978 
  1101 
   979         aList do:[:sY|
  1102     self clippingRectangle:savClip.
   980             self drawEdgesForX:x y:(sY - spc) width:w height:fontHeight level:hilightLevel.
       
   981         ]
       
   982     ]
       
   983 
       
   984 
       
   985 
       
   986 ! !
  1103 ! !
   987 
  1104 
   988 !SelectionInTreeView methodsFor:'enumerating'!
  1105 !SelectionInTreeView methodsFor:'enumerating'!
   989 
  1106 
   990 detectNode:aOneArgBlock
  1107 detectNode:aOneArgBlock
  1176     ^ super keyPress:key x:x y:y
  1293     ^ super keyPress:key x:x y:y
  1177 
  1294 
  1178 
  1295 
  1179 
  1296 
  1180 
  1297 
  1181 !
       
  1182 
       
  1183 redrawX:x y:y width:w height:h
       
  1184     "a region must be redrawn"
       
  1185 
       
  1186     |savClip startLn sel
       
  1187      lnSpace  "{ Class:SmallInteger }"
       
  1188      y0       "{ Class:SmallInteger }"
       
  1189      y1       "{ Class:SmallInteger }"
       
  1190      visStart "{ Class:SmallInteger }"
       
  1191      visEnd   "{ Class:SmallInteger }"
       
  1192      stopLn   "{ Class:SmallInteger }"
       
  1193      maxY     "{ Class:SmallInteger }"
       
  1194      maxX     "{ Class:SmallInteger }"
       
  1195      dltLine  "{ Class:SmallInteger }"
       
  1196      startY   "{ Class:SmallInteger }"|
       
  1197 
       
  1198     shown ifFalse:[^ self].
       
  1199 
       
  1200     visStart := self visibleLineOfY:(y + 1).
       
  1201     startLn  := self visibleLineToAbsoluteLine:visStart.
       
  1202 
       
  1203     self paint:bgColor.
       
  1204     self fillRectangleX:x y:y width:w height:h.
       
  1205     startLn isNil ifTrue:[ ^ self ].
       
  1206 
       
  1207     sel     := nil.
       
  1208     maxX    := x + w.
       
  1209     maxY    := y + h.
       
  1210     lnSpace := lineSpacing // 2.
       
  1211     visEnd  := self visibleLineOfY:maxY.
       
  1212     startY  := self yOfVisibleLine:visStart.
       
  1213     dltLine := startLn - visStart.
       
  1214     stopLn  := dltLine + visEnd.
       
  1215     savClip := clipRect.
       
  1216 
       
  1217     self clippingRectangle:(Rectangle left:x top:y width:w height:h).
       
  1218 
       
  1219     self hasSelection ifTrue:[
       
  1220         "/ redraw the background for all selected lines in the invalid range
       
  1221 
       
  1222         self selectionDo:[:lnNr|
       
  1223             (lnNr between:startLn and:stopLn) ifTrue:[
       
  1224                 sel isNil ifTrue:[
       
  1225                     sel := OrderedCollection new.
       
  1226                     self paint:hilightBgColor.
       
  1227                 ].
       
  1228                 sel add:(y0 := self yOfVisibleLine:(lnNr - dltLine)).
       
  1229                 y0 := y0 - lnSpace.
       
  1230                 y1 := y0 + fontHeight min:maxY.
       
  1231                 y0 := y0 max:y.
       
  1232                 self fillRectangleX:x y:y0 width:w height:y1 - y0.
       
  1233             ]
       
  1234         ]
       
  1235     ].
       
  1236 
       
  1237     self redrawLinesX:x y:startY - lnSpace toX:maxX start:startLn stop:stopLn.
       
  1238 
       
  1239     "/ draw selection frames
       
  1240     self redrawSelFrameForYs:sel fromX:x toX:maxX.
       
  1241 
       
  1242     self clippingRectangle:savClip.
       
  1243 ! !
  1298 ! !
  1244 
  1299 
  1245 !SelectionInTreeView methodsFor:'initialization'!
  1300 !SelectionInTreeView methodsFor:'initialization'!
  1246 
  1301 
  1247 create
  1302 create
  1337         fontHeight := lineHeight
  1392         fontHeight := lineHeight
  1338     ].
  1393     ].
  1339     fontHeight odd ifTrue:[
  1394     fontHeight odd ifTrue:[
  1340         fontHeight := fontHeight + 1
  1395         fontHeight := fontHeight + 1
  1341     ]
  1396     ]
       
  1397 !
       
  1398 
       
  1399 initStyle
       
  1400     "setup viewStyle specifics"
       
  1401 
       
  1402     super initStyle.
       
  1403     highlightMode := DefaultHilightMode ? #line.
       
  1404 
  1342 !
  1405 !
  1343 
  1406 
  1344 initialize
  1407 initialize
  1345     "setup instance attributes
  1408     "setup instance attributes
  1346     "
  1409     "
  1358 
  1421 
  1359     buildInArray := Array new:50.       "/ used for temporary calculation
  1422     buildInArray := Array new:50.       "/ used for temporary calculation
  1360                                         "/ suppress garbage collection
  1423                                         "/ suppress garbage collection
  1361 
  1424 
  1362     self model:nil.     "/ creates a default model.
  1425     self model:nil.     "/ creates a default model.
  1363 
  1426     highlightMode := #line.
  1364 !
  1427 !
  1365 
  1428 
  1366 realize
  1429 realize
  1367     super realize.
  1430     super realize.
  1368     self  refetchDeviceResources.
  1431     self  refetchDeviceResources.
  1998 ! !
  2061 ! !
  1999 
  2062 
  2000 !SelectionInTreeView class methodsFor:'documentation'!
  2063 !SelectionInTreeView class methodsFor:'documentation'!
  2001 
  2064 
  2002 version
  2065 version
  2003     ^ '$Header: /cvs/stx/stx/libwidg2/SelectionInTreeView.st,v 1.59 1998-04-16 10:59:40 ca Exp $'
  2066     ^ '$Header: /cvs/stx/stx/libwidg2/SelectionInTreeView.st,v 1.60 1998-05-28 11:17:22 ca Exp $'
  2004 ! !
  2067 ! !