ListView.st
changeset 1700 3538310c2724
parent 1699 b10682bac6f9
child 1712 cb753ba02fb4
equal deleted inserted replaced
1699:b10682bac6f9 1700:3538310c2724
  1186      listSize e sH|
  1186      listSize e sH|
  1187 
  1187 
  1188     y := self yOfVisibleLine:startVisLineNr.
  1188     y := self yOfVisibleLine:startVisLineNr.
  1189     sH := lineSpacing // 2.
  1189     sH := lineSpacing // 2.
  1190 
  1190 
  1191     self paint:bg.
  1191     backgroundAlreadyClearedColor == bg ifFalse:[
  1192     self fillRectangleX:margin 
  1192         self paint:bg.
  1193 		      y:y-sH
  1193         self fillRectangleX:margin 
  1194 		  width:(width - (margin * 2))
  1194                           y:y-sH
  1195 		 height:(endVisLineNr - startVisLineNr + 1) * fontHeight + (lineSpacing - sH).
  1195                       width:(width - (margin * 2))
       
  1196                      height:(endVisLineNr - startVisLineNr + 1) * fontHeight + (lineSpacing - sH).
       
  1197     ].
  1196     list isNil ifTrue:[^ self].
  1198     list isNil ifTrue:[^ self].
  1197 
  1199 
  1198     y := y + fontAscent.
  1200     y := y + fontAscent.
  1199     listSize := self size.
  1201     listSize := self size.
  1200 
  1202 
  1201     startLine := startVisLineNr + firstLineShown - 1.
  1203     startLine := startVisLineNr + firstLineShown - 1.
  1202     endLine := endVisLineNr + firstLineShown - 1.
  1204     endLine := endVisLineNr + firstLineShown - 1.
  1203     (startLine == 0) ifTrue:[
  1205     (startLine == 0) ifTrue:[
  1204 	y := y + fontHeight.
  1206         y := y + fontHeight.
  1205 	startLine := startLine + 1
  1207         startLine := startLine + 1
  1206     ].
  1208     ].
  1207 
  1209 
  1208     (endLine > listSize) ifTrue:[
  1210     (endLine > listSize) ifTrue:[
  1209 	e := listSize
  1211         e := listSize
  1210     ] ifFalse:[
  1212     ] ifFalse:[
  1211 	e := endLine
  1213         e := endLine
  1212     ].
  1214     ].
  1213 
  1215 
  1214     (startLine <= e) ifTrue:[
  1216     (startLine <= e) ifTrue:[
  1215 	x := textStartLeft - leftOffset.
  1217         x := textStartLeft - leftOffset.
  1216 	self paint:fg on:bg.
  1218         self paint:fg on:bg.
  1217 	self from:startLine to:e do:[:line |
  1219         self from:startLine to:e do:[:line |
  1218 	    line notNil ifTrue:[
  1220             line notNil ifTrue:[
  1219 		self displayOpaqueString:line x:x y:y
  1221                 self displayOpaqueString:line x:x y:y
  1220 	    ].
  1222             ].
  1221 	    y := y + fontHeight
  1223             y := y + fontHeight
  1222 	]
  1224         ]
  1223     ]
  1225     ]
  1224 
  1226 
  1225     "Modified: 24.2.1996 / 16:41:48 / cg"
  1227     "Modified: / 3.10.1998 / 23:06:41 / cg"
  1226 !
  1228 !
  1227 
  1229 
  1228 drawLine:line atX:x inVisible:visLineNr with:fg and:bg
  1230 drawLine:line atX:x inVisible:visLineNr with:fg and:bg
  1229     "draw a given string at visible lines position with
  1231     "draw a given string at visible lines position with
  1230      given x position in fg/bg. Clears the whole line before drawing the string.
  1232      given x position in fg/bg. Clears the whole line before drawing the string.
  1231      Low level entry; not meant for public use."
  1233      Low level entry; not meant for public use."
  1232 
  1234 
  1233     |y|
  1235     |y|
  1234 
  1236 
  1235     y := self yOfVisibleLine:visLineNr.
  1237     y := self yOfVisibleLine:visLineNr.
  1236     self paint:bg.
  1238     backgroundAlreadyClearedColor == bg ifFalse:[
  1237     self fillRectangleX:margin y:y - (lineSpacing//2)
  1239         self paint:bg.
  1238 		  width:(width - (2 * margin)) 
  1240         self fillRectangleX:margin y:y - (lineSpacing//2)
  1239 		 height:fontHeight.
  1241                       width:(width - (2 * margin)) 
       
  1242                      height:fontHeight.
       
  1243     ].
  1240     line notNil ifTrue:[
  1244     line notNil ifTrue:[
  1241 	self paint:fg on:bg.
  1245         self paint:fg on:bg.
  1242 	self displayOpaqueString:line x:x y:(y + fontAscent)
  1246         self displayOpaqueString:line x:x y:(y + fontAscent)
  1243     ]
  1247     ]
  1244 
  1248 
  1245     "Modified: 28.2.1996 / 14:46:07 / cg"
  1249     "Modified: / 3.10.1998 / 23:05:17 / cg"
  1246 !
  1250 !
  1247 
  1251 
  1248 drawLine:line fromX:x inVisible:visLineNr with:fg and:bg
  1252 drawLine:line fromX:x inVisible:visLineNr with:fg and:bg
  1249     "draw a given string at visible lines position with
  1253     "draw a given string at visible lines position with
  1250      given x position in fg/bg. Clears partial line before drawing the string.
  1254      given x position in fg/bg. Clears partial line before drawing the string.
  1313 !
  1317 !
  1314 
  1318 
  1315 drawVisibleLine:visLineNr from:startCol to:endCol with:fg and:bg
  1319 drawVisibleLine:visLineNr from:startCol to:endCol with:fg and:bg
  1316     "draw part of a visible line in fg/bg"
  1320     "draw part of a visible line in fg/bg"
  1317 
  1321 
  1318     |y yf x lineString len characterString w sCol|
  1322     |y yf x lineString len characterString w sCol eCol|
  1319 
  1323 
  1320     (endCol >= startCol) ifTrue:[
  1324     (endCol >= startCol) ifTrue:[
  1321 	sCol := startCol max:1.
  1325         sCol := startCol max:1.
  1322 
  1326 
  1323 	lineString := self visibleAt:visLineNr.
  1327         lineString := self visibleAt:visLineNr.
  1324 
  1328 
  1325 	(lineString notNil and:[lineString isString not])
  1329         (lineString notNil and:[lineString isString not])
  1326 	ifTrue:[
  1330         ifTrue:[
  1327 	    self drawVisibleLine:visLineNr with:fg and:bg.
  1331             self drawVisibleLine:visLineNr with:fg and:bg.
  1328 	] ifFalse:[
  1332         ] ifFalse:[
  1329 	    x := (self xOfCol:sCol inVisibleLine:visLineNr) - leftOffset.
  1333             x := (self xOfCol:sCol inVisibleLine:visLineNr) - leftOffset.
  1330 	    y := (self yOfVisibleLine:visLineNr).
  1334             y := (self yOfVisibleLine:visLineNr).
  1331 	    yf := y - (lineSpacing // 2).
  1335             yf := y - (lineSpacing // 2).
  1332 	    len := lineString size.
  1336             len := lineString size.
  1333 	    (sCol > len) ifTrue:[
  1337             (sCol > len) ifTrue:[
  1334 		len := endCol - sCol + 1.
  1338                 len := endCol - sCol + 1.
  1335 		self paint:bg.
  1339                 backgroundAlreadyClearedColor == bg ifFalse:[
  1336 		self fillRectangleX:x y:yf 
  1340                     self paint:bg.
  1337 			      width:(fontWidth * len) 
  1341                     self fillRectangleX:x y:yf 
  1338 			     height:fontHeight
  1342                                    width:(fontWidth * len) 
  1339 	    ] ifFalse:[
  1343                                   height:fontHeight
  1340 		(endCol > len) ifTrue:[
  1344                 ]
  1341 		    characterString := lineString species new:endCol.
  1345             ] ifFalse:[
  1342 		    characterString replaceFrom:1 to:len with:lineString startingAt:1.
  1346                 eCol := endCol.
  1343 		    lineString := characterString
  1347                 (endCol > len) ifTrue:[
  1344 		].
  1348                     backgroundAlreadyClearedColor == bg ifFalse:[
  1345 		self paint:bg.
  1349                         characterString := lineString species new:endCol.
  1346 		(lineString isMemberOf:String) ifTrue:[
  1350                         characterString replaceFrom:1 to:len with:lineString startingAt:1.
  1347 		    fontIsFixedWidth ifTrue:[
  1351                         lineString := characterString.
  1348 			w := (endCol - sCol + 1) * fontWidth
  1352                     ] ifTrue:[
  1349 		    ] ifFalse:[
  1353                         eCol := len.
  1350 			w := font widthOf:lineString from:sCol to:endCol
  1354                     ].
  1351 		    ]
  1355                 ].
  1352 		] ifFalse:[
  1356                 (lineString isMemberOf:String) ifTrue:[
  1353 		    w := (lineString copyFrom:sCol to:endCol) widthOn:self
  1357                     fontIsFixedWidth ifTrue:[
  1354 		].
  1358                         w := (eCol - sCol + 1) * fontWidth
  1355 		self fillRectangleX:x y:yf 
  1359                     ] ifFalse:[
  1356 			      width:w
  1360                         w := font widthOf:lineString from:sCol to:eCol
  1357 			      height:fontHeight.
  1361                     ]
  1358 		self paint:fg on:bg.
  1362                 ] ifFalse:[
  1359 		self displayOpaqueString:lineString from:sCol to:endCol x:x y:(y + fontAscent)
  1363                     w := (lineString copyFrom:sCol to:eCol) widthOn:self
  1360 	    ]
  1364                 ].
  1361 	]
  1365                 backgroundAlreadyClearedColor == bg ifFalse:[
  1362     ]
  1366                     self paint:bg.
  1363 
  1367                     self fillRectangleX:x y:yf 
  1364     "Modified: / 3.9.1998 / 21:54:01 / cg"
  1368                                   width:w
       
  1369                                   height:fontHeight.
       
  1370                 ].
       
  1371                 self paint:fg on:bg.
       
  1372                 self displayOpaqueString:lineString from:sCol to:eCol x:x y:(y + fontAscent)
       
  1373             ]
       
  1374         ]
       
  1375     ]
       
  1376 
       
  1377     "Modified: / 3.10.1998 / 22:59:41 / cg"
  1365 !
  1378 !
  1366 
  1379 
  1367 drawVisibleLine:visLineNr from:startCol with:fg and:bg
  1380 drawVisibleLine:visLineNr from:startCol with:fg and:bg
  1368     "draw right part of a visible line from startCol to end of line in fg/bg"
  1381     "draw right part of a visible line from startCol to end of line in fg/bg"
  1369 
  1382 
  1370     |y x lineString index1 index2|
  1383     |y x lineString index1 index2|
  1371 
  1384 
  1372     (startCol < 1) ifTrue:[
  1385     (startCol < 1) ifTrue:[
  1373 	index1 := 1
  1386         index1 := 1
  1374     ] ifFalse:[
  1387     ] ifFalse:[
  1375 	index1 := startCol
  1388         index1 := startCol
  1376     ].
  1389     ].
  1377     y := self yOfVisibleLine:visLineNr.
  1390     y := self yOfVisibleLine:visLineNr.
  1378     x := (self xOfCol:index1 inVisibleLine:visLineNr) - leftOffset.
  1391     x := (self xOfCol:index1 inVisibleLine:visLineNr) - leftOffset.
  1379     self paint:bg.
  1392     backgroundAlreadyClearedColor == bg ifFalse:[
  1380     self fillRectangleX:x y:y - (lineSpacing // 2)
  1393         self paint:bg.
  1381 		  width:(width + leftOffset - x)
  1394         self fillRectangleX:x y:y - (lineSpacing // 2)
  1382 		 height:fontHeight.
  1395                       width:(width + leftOffset - x)
  1383 
  1396                      height:fontHeight.
       
  1397     ].
  1384     lineString := self visibleAt:visLineNr.
  1398     lineString := self visibleAt:visLineNr.
  1385     lineString notNil ifTrue:[
  1399     lineString notNil ifTrue:[
  1386 	lineString isString ifFalse:[
  1400         lineString isString ifFalse:[
  1387 	    self drawVisibleLine:visLineNr with:fg and:bg.
  1401             self drawVisibleLine:visLineNr with:fg and:bg.
  1388 	] ifTrue:[
  1402         ] ifTrue:[
  1389 	    index2 := lineString size.
  1403             index2 := lineString size.
  1390 	    (index2 < index1) ifTrue:[^ self].
  1404             (index2 < index1) ifTrue:[^ self].
  1391 	    (index1 <= index2) ifTrue:[
  1405             (index1 <= index2) ifTrue:[
  1392 		self paint:fg on:bg.
  1406                 self paint:fg on:bg.
  1393 		self displayOpaqueString:lineString from:index1 to:index2 x:x y:(y + fontAscent)
  1407                 self displayOpaqueString:lineString from:index1 to:index2 x:x y:(y + fontAscent)
  1394 	    ]
  1408             ]
  1395 	]
  1409         ]
  1396     ]
  1410     ]
  1397 
  1411 
  1398     "Modified: 12.5.1996 / 12:47:49 / cg"
  1412     "Modified: / 3.10.1998 / 23:07:56 / cg"
  1399 !
  1413 !
  1400 
  1414 
  1401 drawVisibleLine:visLineNr with:fg and:bg
  1415 drawVisibleLine:visLineNr with:fg and:bg
  1402     "draw a visible line in fg/bg"
  1416     "draw a visible line in fg/bg"
  1403 
  1417 
  2508 
  2522 
  2509     list isNil ifTrue:[^ 0].
  2523     list isNil ifTrue:[^ 0].
  2510     widthOfWidestLine notNil ifTrue:[^ widthOfWidestLine + (leftMargin * 2)].
  2524     widthOfWidestLine notNil ifTrue:[^ widthOfWidestLine + (leftMargin * 2)].
  2511 
  2525 
  2512     device isNil ifTrue:[
  2526     device isNil ifTrue:[
  2513 	"/ mhmh - really dont know yet
  2527         "/ mhmh - really dont know yet
  2514 	f := font on:Screen current
  2528         f := font on:Screen current
  2515     ] ifFalse:[
  2529     ] ifFalse:[
  2516 	f := font := font on:device.
  2530         f := font := font on:device.
  2517     ].
  2531     ].
  2518 
  2532 
  2519     includesNonStrings ifTrue:[
  2533     includesNonStrings ifTrue:[
  2520 	max := list 
  2534         max := list 
  2521 		   inject:0 
  2535                    inject:0 
  2522 		   into:[:maxSoFar :entry |
  2536                    into:[:maxSoFar :entry |
  2523 			     (
  2537                              (
  2524 				 entry isNil ifTrue:[
  2538                                  entry isNil ifTrue:[
  2525 				     0
  2539                                      0
  2526 				 ] ifFalse:[
  2540                                  ] ifFalse:[
  2527 				    entry isString ifTrue:[
  2541                                     entry isString ifTrue:[
  2528 					f widthOf:entry
  2542                                         f widthOf:entry
  2529 				    ] ifFalse:[
  2543                                     ] ifFalse:[
  2530 					entry widthOn:self
  2544                                         entry widthOn:self
  2531 				    ]
  2545                                     ]
  2532 				 ]
  2546                                  ]
  2533 			     ) max:maxSoFar.
  2547                              ) max:maxSoFar.
  2534 			]
  2548                         ]
  2535     ] ifFalse:[
  2549     ] ifFalse:[
  2536 	fontIsFixedWidth ifTrue:[
  2550         false "fontIsFixedWidth" ifTrue:[
  2537 	    max := self lengthOfLongestLine * fontWidth
  2551             max := self lengthOfLongestLine * fontWidth
  2538 	] ifFalse:[
  2552         ] ifFalse:[
  2539 	    max := 0.
  2553             max := 0.
  2540 	    list notNil ifTrue:[
  2554             list notNil ifTrue:[
  2541 		list do:[:line |
  2555                 list do:[:line |
  2542 		    line notNil ifTrue:[
  2556                     line notNil ifTrue:[
  2543 			max := max max:(line widthOn:self)
  2557                         max := max max:(line widthOn:self)
  2544 		    ]
  2558                     ]
  2545 		].
  2559                 ].
  2546 "/                max := max max:(f widthOf:list)
  2560 "/                max := max max:(f widthOf:list)
  2547 	    ].
  2561             ].
  2548 	].
  2562         ].
  2549     ].
  2563     ].
  2550     widthOfWidestLine := max.
  2564     widthOfWidestLine := max.
  2551     ^ max + (leftMargin * 2)
  2565     ^ max + (leftMargin * 2)
  2552 
  2566 
  2553     "Modified: 5.7.1996 / 13:54:01 / cg"
  2567     "Modified: / 24.9.1998 / 18:21:08 / cg"
  2554 !
  2568 !
  2555 
  2569 
  2556 xOriginOfContents
  2570 xOriginOfContents
  2557     "return the horizontal origin of the contents in pixels
  2571     "return the horizontal origin of the contents in pixels
  2558      - used for scrollbar interface"
  2572      - used for scrollbar interface"
  3819 ! !
  3833 ! !
  3820 
  3834 
  3821 !ListView class methodsFor:'documentation'!
  3835 !ListView class methodsFor:'documentation'!
  3822 
  3836 
  3823 version
  3837 version
  3824     ^ '$Header: /cvs/stx/stx/libwidg/ListView.st,v 1.175 1998-10-02 17:52:40 cg Exp $'
  3838     ^ '$Header: /cvs/stx/stx/libwidg/ListView.st,v 1.176 1998-10-03 21:54:14 cg Exp $'
  3825 ! !
  3839 ! !