22 tabPositions lineSpacing |
22 tabPositions lineSpacing |
23 fontHeight fontAscent |
23 fontHeight fontAscent |
24 fontIsFixedWidth fontWidth |
24 fontIsFixedWidth fontWidth |
25 normalFont boldFont italicFont |
25 normalFont boldFont italicFont |
26 autoScrollBlock autoScrollDeltaT |
26 autoScrollBlock autoScrollDeltaT |
27 searchPattern wordCheck' |
27 searchPattern wordCheck |
|
28 includesNonStrings' |
28 classVariableNames:'' |
29 classVariableNames:'' |
29 poolDictionaries:'' |
30 poolDictionaries:'' |
30 category:'Views-Text' |
31 category:'Views-Text' |
31 ! |
32 ! |
32 |
33 |
33 ListView comment:' |
34 ListView comment:' |
34 COPYRIGHT (c) 1989 by Claus Gittinger |
35 COPYRIGHT (c) 1989 by Claus Gittinger |
35 All Rights Reserved |
36 All Rights Reserved |
36 |
37 |
37 $Header: /cvs/stx/stx/libwidg/ListView.st,v 1.8 1994-08-07 13:22:46 claus Exp $ |
38 $Header: /cvs/stx/stx/libwidg/ListView.st,v 1.9 1994-08-23 23:38:21 claus Exp $ |
38 '! |
39 '! |
39 |
40 |
40 !ListView class methodsFor:'documentation'! |
41 !ListView class methodsFor:'documentation'! |
41 |
42 |
42 copyright |
43 copyright |
140 topMargin := (self verticalPixelPerMillimeter:0.5) rounded. |
141 topMargin := (self verticalPixelPerMillimeter:0.5) rounded. |
141 textStartLeft := leftMargin + margin. |
142 textStartLeft := leftMargin + margin. |
142 textStartTop := topMargin + margin. |
143 textStartTop := topMargin + margin. |
143 innerWidth := width - textStartLeft - (margin * 2). |
144 innerWidth := width - textStartLeft - (margin * 2). |
144 self getFontParameters. |
145 self getFontParameters. |
145 wordCheck := [:char | char isNationalAlphaNumeric] |
146 wordCheck := [:char | char isNationalAlphaNumeric]. |
|
147 includesNonStrings := false |
146 ! |
148 ! |
147 |
149 |
148 initStyle |
150 initStyle |
149 super initStyle. |
151 super initStyle. |
150 |
152 |
237 "return the margin to left of 1st col" |
239 "return the margin to left of 1st col" |
238 |
240 |
239 ^ leftMargin |
241 ^ leftMargin |
240 ! |
242 ! |
241 |
243 |
|
244 setList:aCollection expandTabs:expandTabs |
|
245 "set the contents (a collection of strings); |
|
246 dont change position (i.e. do not scroll). |
|
247 This can be used to update a self-changing list |
|
248 (for example: a file list being shown, without disturbing user too much)" |
|
249 |
|
250 (aCollection isNil and:[list isNil]) ifTrue:[ |
|
251 "no change" |
|
252 ^ self |
|
253 ]. |
|
254 list := aCollection. |
|
255 |
|
256 list notNil ifTrue:[ |
|
257 expandTabs ifTrue:[ |
|
258 self expandTabs |
|
259 ] ifFalse:[ |
|
260 includesNonStrings := (list findFirst:[:l | l notNil and:[l isString not]]) ~~ 0. |
|
261 ] |
|
262 ]. |
|
263 self contentsChanged. |
|
264 shown ifTrue:[ |
|
265 self redrawFromVisibleLine:1 to:nLinesShown |
|
266 ] |
|
267 ! |
|
268 |
242 setList:aCollection |
269 setList:aCollection |
243 "set the contents (a collection of strings); |
270 "set the contents (a collection of strings); |
244 dont change position (i.e. do not scroll). |
271 dont change position (i.e. do not scroll). |
245 This can be used to update a self-changing list |
272 This can be used to update a self-changing list |
246 (for example: a file list being shown, without disturbing user too much)" |
273 (for example: a file list being shown, without disturbing user too much)" |
247 |
274 |
248 (aCollection isNil and:[list isNil]) ifTrue:[ |
275 ^ self setList:aCollection expandTabs:true |
249 "no change" |
|
250 ^ self |
|
251 ]. |
|
252 list := aCollection. |
|
253 |
|
254 list notNil ifTrue:[ |
|
255 self expandTabs |
|
256 ]. |
|
257 self contentsChanged. |
|
258 shown ifTrue:[ |
|
259 self redrawFromVisibleLine:1 to:nLinesShown |
|
260 ] |
|
261 ! |
276 ! |
262 |
277 |
263 list:aCollection |
278 list:aCollection |
264 "set the contents (a collection of strings) and scroll to top-left" |
279 "set the contents (a collection of strings) and scroll to top-left" |
265 |
280 |
302 "set the contents (either a string or a Collection of strings) |
317 "set the contents (either a string or a Collection of strings) |
303 dont change position (i.e. do not scroll). |
318 dont change position (i.e. do not scroll). |
304 This can be used to update a self-changing list |
319 This can be used to update a self-changing list |
305 (for example: a file list being shown, without disturbing user too much)." |
320 (for example: a file list being shown, without disturbing user too much)." |
306 |
321 |
307 something isNil ifTrue:[ |
322 |l| |
308 self setList:nil |
323 |
309 ] ifFalse:[ |
324 l := something. |
310 self setList:(something asText) |
325 l notNil ifTrue:[ |
311 ] |
326 l isString ifTrue:[ |
|
327 l := l asText |
|
328 ] |
|
329 ]. |
|
330 self setList:l |
312 ! |
331 ! |
313 |
332 |
314 contents:something |
333 contents:something |
315 "set the contents (either a string or a Collection of strings) |
334 "set the contents (either a string or a Collection of strings) |
316 also scroll to top-left" |
335 also scroll to top-left" |
317 |
336 |
318 something isNil ifTrue:[ |
337 |l| |
319 self list:nil |
338 |
320 ] ifFalse:[ |
339 l := something. |
321 self list:(something asText) |
340 l notNil ifTrue:[ |
322 ] |
341 l isString ifTrue:[ |
|
342 l := l asText |
|
343 ] |
|
344 ]. |
|
345 self list:l |
323 ! |
346 ! |
324 |
347 |
325 contents |
348 contents |
326 "return the contents as a string" |
349 "return the contents as a string" |
327 |
350 |
515 |
538 |
516 |max| |
539 |max| |
517 |
540 |
518 list isNil ifTrue:[^ 0]. |
541 list isNil ifTrue:[^ 0]. |
519 |
542 |
520 fontIsFixedWidth ifTrue:[ |
543 includesNonStrings ifTrue:[ |
521 max := self lengthOfLongestLine * fontWidth |
544 max := list |
|
545 inject:0 |
|
546 into:[:maxSoFar :entry | |
|
547 ( |
|
548 entry isNil ifTrue:[ |
|
549 0 |
|
550 ] ifFalse:[ |
|
551 entry isString ifTrue:[ |
|
552 font widthOf:entry |
|
553 ] ifFalse:[ |
|
554 entry widthIn:self |
|
555 ] |
|
556 ] |
|
557 ) max:maxSoFar. |
|
558 ] |
522 ] ifFalse:[ |
559 ] ifFalse:[ |
523 max := 0. |
560 fontIsFixedWidth ifTrue:[ |
524 list notNil ifTrue:[ |
561 max := self lengthOfLongestLine * fontWidth |
525 max := max max:(font widthOf:list) |
562 ] ifFalse:[ |
|
563 max := 0. |
|
564 list notNil ifTrue:[ |
|
565 max := max max:(font widthOf:list) |
|
566 ]. |
526 ]. |
567 ]. |
527 ]. |
568 ^ max + (leftMargin * 2) |
528 ^ max + (leftMargin * 2) |
569 ] |
529 ! |
570 ! |
530 |
571 |
531 yOriginOfContents |
572 yOriginOfContents |
532 "return the vertical origin of the contents in pixels |
573 "return the vertical origin of the contents in pixels |
533 - used for scrollbar interface" |
574 - used for scrollbar interface" |
678 |max "{ Class: SmallInteger }" |
719 |max "{ Class: SmallInteger }" |
679 first "{ Class: SmallInteger }" |
720 first "{ Class: SmallInteger }" |
680 last "{ Class: SmallInteger }" |
721 last "{ Class: SmallInteger }" |
681 thisLen "{ Class: SmallInteger }" |
722 thisLen "{ Class: SmallInteger }" |
682 listSize "{ Class: SmallInteger }" | |
723 listSize "{ Class: SmallInteger }" | |
|
724 |
|
725 includesNonStrings ifTrue:[ |
|
726 ^ width |
|
727 ]. |
683 |
728 |
684 fontIsFixedWidth ifTrue:[ |
729 fontIsFixedWidth ifTrue:[ |
685 ^ (self lengthOfLongestLineBetween:firstLine and:lastLine) * fontWidth |
730 ^ (self lengthOfLongestLineBetween:firstLine and:lastLine) * fontWidth |
686 ]. |
731 ]. |
687 listSize := list size. |
732 listSize := list size. |
1396 "change origin to scroll down some lines" |
1441 "change origin to scroll down some lines" |
1397 |
1442 |
1398 |w "{ Class:SmallInteger }" |
1443 |w "{ Class:SmallInteger }" |
1399 h "{ Class:SmallInteger }" |
1444 h "{ Class:SmallInteger }" |
1400 m2 "{ Class:SmallInteger }" |
1445 m2 "{ Class:SmallInteger }" |
1401 count "{ Class:SmallInteger }"| |
1446 count "{ Class:SmallInteger }" |
|
1447 prevFirst| |
1402 |
1448 |
1403 count := nLines. |
1449 count := nLines. |
1404 (firstLineShown + nLines + nFullLinesShown > list size) ifTrue:[ |
1450 (firstLineShown + nLines + nFullLinesShown > list size) ifTrue:[ |
1405 count := list size - firstLineShown - nFullLinesShown + 1 |
1451 count := list size - firstLineShown - nFullLinesShown + 1 |
1406 ]. |
1452 ]. |
1407 count <= 0 ifTrue:[^ self]. |
1453 count <= 0 ifTrue:[^ self]. |
1408 |
1454 |
1409 self originWillChange. |
1455 self originWillChange. |
1410 (count >= nLinesShown) ifTrue:[ |
1456 prevFirst := firstLineShown. |
1411 firstLineShown := firstLineShown + count. |
1457 firstLineShown := firstLineShown + count. |
1412 self redrawFromVisibleLine:1 to:nLinesShown. |
1458 shown ifTrue:[ |
1413 self originChanged:(count negated) |
1459 (count >= nLinesShown) ifTrue:[ |
1414 ] ifFalse:[ |
1460 self redrawFromVisibleLine:1 to:nLinesShown. |
1415 m2 := margin * 2. |
1461 ] ifFalse:[ |
1416 w := self widthForScrollBetween:firstLineShown |
1462 m2 := margin * 2. |
1417 and:(firstLineShown + nLinesShown). |
1463 w := self widthForScrollBetween:prevFirst |
1418 w := w + leftMargin. |
1464 and:(prevFirst + nLinesShown). |
1419 |
1465 w := w + leftMargin. |
1420 firstLineShown := firstLineShown + count. |
1466 |
1421 h := (fontHeight * count) + textStartTop. |
1467 h := (fontHeight * count) + textStartTop. |
1422 self catchExpose. |
1468 self catchExpose. |
1423 self copyFrom:self x:margin y:h |
1469 self copyFrom:self x:margin y:h |
1424 toX:margin y:textStartTop |
1470 toX:margin y:textStartTop |
1425 width:w height:(height - m2 - h). |
1471 width:w height:(height - m2 - h). |
1426 |
1472 |
1427 self redrawFromVisibleLine:(nFullLinesShown - count + 1) |
1473 self redrawFromVisibleLine:(nFullLinesShown - count + 1) |
1428 to:nLinesShown. |
1474 to:nLinesShown. |
1429 self waitForExpose. |
1475 self waitForExpose. |
1430 self originChanged:(count negated). |
1476 ]. |
1431 ] |
1477 ]. |
|
1478 self originChanged:count. |
1432 ! |
1479 ! |
1433 |
1480 |
1434 scrollDown |
1481 scrollDown |
1435 "change origin to scroll down one line" |
1482 "change origin to scroll down one line" |
1436 |
1483 |
1440 scrollUp:nLines |
1487 scrollUp:nLines |
1441 "change origin to scroll up some lines" |
1488 "change origin to scroll up some lines" |
1442 |
1489 |
1443 |w "{ Class:SmallInteger }" |
1490 |w "{ Class:SmallInteger }" |
1444 h "{ Class:SmallInteger }" |
1491 h "{ Class:SmallInteger }" |
1445 count "{ Class:SmallInteger }"| |
1492 count "{ Class:SmallInteger }" |
|
1493 prevFirst| |
1446 |
1494 |
1447 count := nLines. |
1495 count := nLines. |
1448 count >= firstLineShown ifTrue:[ |
1496 count >= firstLineShown ifTrue:[ |
1449 count := firstLineShown - 1 |
1497 count := firstLineShown - 1 |
1450 ]. |
1498 ]. |
1451 (count == 0) ifTrue:[^ self]. |
1499 (count == 0) ifTrue:[^ self]. |
1452 |
1500 |
1453 self originWillChange. |
1501 self originWillChange. |
1454 (count >= nLinesShown) ifTrue:[ |
1502 prevFirst := firstLineShown. |
1455 firstLineShown := firstLineShown - count. |
1503 firstLineShown := firstLineShown - count. |
1456 self redrawFromVisibleLine:1 to:nLinesShown. |
1504 shown ifTrue:[ |
1457 self originChanged:(count negated) |
1505 (count >= nLinesShown) ifTrue:[ |
1458 ] ifFalse:[ |
1506 self redrawFromVisibleLine:1 to:nLinesShown. |
1459 w := self widthForScrollBetween:firstLineShown |
1507 ] ifFalse:[ |
1460 and:(firstLineShown + nLinesShown). |
1508 w := self widthForScrollBetween:prevFirst |
1461 w := w + leftMargin. |
1509 and:(prevFirst + nLinesShown). |
1462 firstLineShown := firstLineShown - count. |
1510 w := w + leftMargin. |
1463 h := (fontHeight * count) + topMargin. |
1511 h := (fontHeight * count) + topMargin. |
1464 self catchExpose. |
1512 self catchExpose. |
1465 self copyFrom:self x:margin y:topMargin |
1513 self copyFrom:self x:margin y:topMargin |
1466 toX:margin y:h |
1514 toX:margin y:h |
1467 width:w height:(height - h - margin). |
1515 width:w height:(height - h - margin). |
1468 self redrawFromVisibleLine:1 to:count. |
1516 self redrawFromVisibleLine:1 to:count. |
1469 self waitForExpose. |
1517 self waitForExpose. |
1470 self originChanged:(count negated). |
1518 ]. |
1471 ] |
1519 ]. |
|
1520 self originChanged:(count negated). |
1472 ! |
1521 ! |
1473 |
1522 |
1474 scrollUp |
1523 scrollUp |
1475 "change origin to scroll up one line" |
1524 "change origin to scroll up one line" |
1476 |
1525 |
1691 x := (self xOfCol:col inLine:visLineNr) - leftOffset. |
1740 x := (self xOfCol:col inLine:visLineNr) - leftOffset. |
1692 y := self yOfLine:visLineNr. |
1741 y := self yOfLine:visLineNr. |
1693 |
1742 |
1694 self paint:bg. |
1743 self paint:bg. |
1695 |
1744 |
1696 (lineString isNil or:[col > lineString size]) ifTrue:[ |
1745 (lineString notNil and:[lineString isString not]) ifTrue:[ |
1697 self fillRectangleX:x y:y width:(font widthOf:' ') |
1746 self drawVisibleLine:visLineNr with:fg and:bg |
1698 height:fontHeight. |
|
1699 self paint:fg |
|
1700 ] ifFalse:[ |
1747 ] ifFalse:[ |
1701 characterString := (lineString at:col) asString. |
1748 col > lineString size ifTrue:[ |
1702 self fillRectangleX:x y:y width:(font widthOf:characterString) |
1749 self fillRectangleX:x y:y width:(font width) height:fontHeight. |
1703 height:fontHeight. |
1750 self paint:fg |
1704 self paint:fg. |
1751 ] ifFalse:[ |
1705 self displayString:characterString x:x y:(y + fontAscent) |
1752 characterString := (lineString at:col) asString. |
|
1753 self fillRectangleX:x y:y |
|
1754 width:(font widthOf:characterString) |
|
1755 height:fontHeight. |
|
1756 self paint:fg. |
|
1757 self displayString:characterString x:x y:(y + fontAscent) |
|
1758 ] |
1706 ] |
1759 ] |
1707 ! |
1760 ! |
1708 |
1761 |
1709 drawVisibleLine:visLineNr from:startCol to:endCol with:fg and:bg |
1762 drawVisibleLine:visLineNr from:startCol to:endCol with:fg and:bg |
1710 "draw part of a visible line in fg/bg" |
1763 "draw part of a visible line in fg/bg" |
1711 |
1764 |
1712 |y x lineString len characterString| |
1765 |y x lineString len characterString| |
1713 |
1766 |
1714 (endCol >= startCol) ifTrue:[ |
1767 (endCol >= startCol) ifTrue:[ |
1715 lineString := self visibleAt:visLineNr. |
1768 lineString := self visibleAt:visLineNr. |
1716 x := (self xOfCol:startCol inLine:visLineNr) - leftOffset. |
1769 |
1717 y := (self yOfLine:visLineNr). |
1770 (lineString notNil and:[lineString isString not]) ifTrue:[ |
1718 |
1771 self drawVisibleLine:visLineNr with:fg and:bg. |
1719 len := lineString size. |
|
1720 (startCol > len) ifTrue:[ |
|
1721 len := endCol - startCol + 1. |
|
1722 self paint:bg. |
|
1723 self fillRectangleX:x y:y |
|
1724 width:(fontWidth * len) |
|
1725 height:fontHeight |
|
1726 ] ifFalse:[ |
1772 ] ifFalse:[ |
1727 (endCol > len) ifTrue:[ |
1773 x := (self xOfCol:startCol inLine:visLineNr) - leftOffset. |
1728 characterString := String new:endCol. |
1774 y := (self yOfLine:visLineNr). |
1729 characterString replaceFrom:1 to:len with:lineString startingAt:1. |
1775 len := lineString size. |
1730 lineString := characterString |
1776 (startCol > len) ifTrue:[ |
1731 ]. |
1777 len := endCol - startCol + 1. |
1732 self paint:bg. |
1778 self paint:bg. |
1733 self fillRectangleX:x y:y width:(font widthOf:lineString from:startCol to:endCol) |
1779 self fillRectangleX:x y:y |
1734 height:fontHeight. |
1780 width:(fontWidth * len) |
1735 self paint:fg. |
1781 height:fontHeight |
1736 self displayString:lineString from:startCol to:endCol x:x y:(y + fontAscent) |
1782 ] ifFalse:[ |
|
1783 (endCol > len) ifTrue:[ |
|
1784 characterString := String new:endCol. |
|
1785 characterString replaceFrom:1 to:len with:lineString startingAt:1. |
|
1786 lineString := characterString |
|
1787 ]. |
|
1788 self paint:bg. |
|
1789 self fillRectangleX:x y:y width:(font widthOf:lineString from:startCol to:endCol) |
|
1790 height:fontHeight. |
|
1791 self paint:fg. |
|
1792 self displayString:lineString from:startCol to:endCol x:x y:(y + fontAscent) |
|
1793 ] |
1737 ] |
1794 ] |
1738 ] |
1795 ] |
1739 ! |
1796 ! |
1740 |
1797 |
1741 drawVisibleLine:visLineNr from:startCol with:fg and:bg |
1798 drawVisibleLine:visLineNr from:startCol with:fg and:bg |
1752 x := (self xOfCol:index1 inLine:visLineNr) - leftOffset. |
1809 x := (self xOfCol:index1 inLine:visLineNr) - leftOffset. |
1753 self paint:bg. |
1810 self paint:bg. |
1754 self fillRectangleX:x y:y |
1811 self fillRectangleX:x y:y |
1755 width:(width + leftOffset - x) |
1812 width:(width + leftOffset - x) |
1756 height:fontHeight. |
1813 height:fontHeight. |
1757 |
1814 |
1758 lineString := self visibleAt:visLineNr. |
1815 lineString := self visibleAt:visLineNr. |
1759 lineString notNil ifTrue:[ |
1816 lineString notNil ifTrue:[ |
1760 index2 := lineString size. |
1817 lineString isString ifFalse:[ |
1761 (index2 < index1) ifTrue:[^ self]. |
1818 self drawVisibleLine:visLineNr with:fg and:bg. |
1762 (index1 <= index2) ifTrue:[ |
1819 ] ifTrue:[ |
1763 self paint:fg. |
1820 index2 := lineString size. |
1764 self displayString:lineString from:index1 to:index2 x:x y:(y + fontAscent) |
1821 (index2 < index1) ifTrue:[^ self]. |
|
1822 (index1 <= index2) ifTrue:[ |
|
1823 self paint:fg. |
|
1824 self displayString:lineString from:index1 to:index2 x:x y:(y + fontAscent) |
|
1825 ] |
1765 ] |
1826 ] |
1766 ] |
1827 ] |
1767 ! |
1828 ! |
1768 |
1829 |
1769 drawFromVisibleLine:startVisLineNr to:endVisLineNr with:fg and:bg |
1830 drawFromVisibleLine:startVisLineNr to:endVisLineNr with:fg and:bg |
2016 ]. |
2077 ]. |
2017 (w > (width // 4 * 3)) ifTrue:[ |
2078 (w > (width // 4 * 3)) ifTrue:[ |
2018 "if area is big enough redraw whole lines" |
2079 "if area is big enough redraw whole lines" |
2019 self redrawFromVisibleLine:startLine to:stopLine |
2080 self redrawFromVisibleLine:startLine to:stopLine |
2020 ] ifFalse:[ |
2081 ] ifFalse:[ |
2021 fontIsFixedWidth ifFalse:[ |
2082 includesNonStrings ifTrue:[ |
2022 "start/end col has to be computed for each line" |
|
2023 |
|
2024 startLine to:stopLine do:[:i | |
2083 startLine to:stopLine do:[:i | |
2025 startCol := self colOfX:x inVisibleLine:i. |
2084 self redrawVisibleLine:i |
2026 endCol := self colOfX:(x + w) inVisibleLine:i. |
2085 ] |
|
2086 ] ifFalse:[ |
|
2087 fontIsFixedWidth ifFalse:[ |
|
2088 "start/end col has to be computed for each line" |
|
2089 |
|
2090 startLine to:stopLine do:[:i | |
|
2091 startCol := self colOfX:x inVisibleLine:i. |
|
2092 endCol := self colOfX:(x + w) inVisibleLine:i. |
|
2093 startCol > 0 ifTrue:[ |
|
2094 endCol > 0 ifTrue:[ |
|
2095 self redrawVisibleLine:i from:startCol to:endCol |
|
2096 ] |
|
2097 ] |
|
2098 ] |
|
2099 ] ifTrue:[ |
|
2100 "start/end col is the same for all lines" |
|
2101 |
|
2102 startCol := self colOfX:x inVisibleLine:startLine. |
|
2103 endCol := self colOfX:(x + w) inVisibleLine:startLine. |
2027 startCol > 0 ifTrue:[ |
2104 startCol > 0 ifTrue:[ |
2028 endCol > 0 ifTrue:[ |
2105 endCol > 0 ifTrue:[ |
2029 self redrawVisibleLine:i from:startCol to:endCol |
2106 startLine to:stopLine do:[:i | |
2030 ] |
2107 self redrawVisibleLine:i from:startCol to:endCol |
2031 ] |
2108 ] |
2032 ] |
|
2033 ] ifTrue:[ |
|
2034 "start/end col is the same for all lines" |
|
2035 |
|
2036 startCol := self colOfX:x inVisibleLine:startLine. |
|
2037 endCol := self colOfX:(x + w) inVisibleLine:startLine. |
|
2038 startCol > 0 ifTrue:[ |
|
2039 endCol > 0 ifTrue:[ |
|
2040 startLine to:stopLine do:[:i | |
|
2041 self redrawVisibleLine:i from:startCol to:endCol |
|
2042 ] |
2109 ] |
2043 ] |
2110 ] |
2044 ] |
2111 ] |
2045 ] |
2112 ] |
2046 ] |
2113 ] |