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' |
27 searchPattern wordCheck' |
28 classVariableNames:'' |
28 classVariableNames:'' |
29 poolDictionaries:'' |
29 poolDictionaries:'' |
30 category:'Views-Text' |
30 category:'Views-Text' |
31 ! |
31 ! |
32 |
32 |
33 ListView comment:' |
33 ListView comment:' |
34 |
|
35 COPYRIGHT (c) 1989 by Claus Gittinger |
34 COPYRIGHT (c) 1989 by Claus Gittinger |
36 All Rights Reserved |
35 All Rights Reserved |
37 |
36 |
38 $Header: /cvs/stx/stx/libwidg/ListView.st,v 1.7 1994-01-13 00:17:08 claus Exp $ |
37 $Header: /cvs/stx/stx/libwidg/ListView.st,v 1.8 1994-08-07 13:22:46 claus Exp $ |
39 |
|
40 written spring 89 by claus |
|
41 '! |
38 '! |
42 |
39 |
43 !ListView class methodsFor:'documentation'! |
40 !ListView class methodsFor:'documentation'! |
|
41 |
|
42 copyright |
|
43 " |
|
44 COPYRIGHT (c) 1989 by Claus Gittinger |
|
45 All Rights Reserved |
|
46 |
|
47 This software is furnished under a license and may be used |
|
48 only in accordance with the terms of that license and with the |
|
49 inclusion of the above copyright notice. This software may not |
|
50 be provided or otherwise made available to, or used by, any |
|
51 other person. No title to or ownership of the software is |
|
52 hereby transferred. |
|
53 " |
|
54 ! |
|
55 |
|
56 version |
|
57 " |
|
58 $Header: /cvs/stx/stx/libwidg/ListView.st,v 1.8 1994-08-07 13:22:46 claus Exp $ |
|
59 " |
|
60 ! |
44 |
61 |
45 documentation |
62 documentation |
46 " |
63 " |
47 a simple View for lists - the elements must understand printString |
64 a View for (string-)lists. |
48 the list is changed - the elements are replaced by their printStrings |
65 |
49 (if this leads to problems - I will change it later) |
66 This class can only passively display collections of strings- |
50 |
67 selections, editing, cursors etc. must be done in subclasses. |
51 This class can only passively display - |
68 see SelectionInListView, TextView etc. |
52 selections, editing, cursors etc. must be done in subclasses. |
69 |
53 see SelectionInListView, TextView etc. |
70 This code currently handles only fixed-height fonts correctly - |
54 |
71 should be rewritten in some places ... |
55 This code currently handles only fixed-height fonts correctly - |
72 |
56 should be rewritten in some places ... |
73 It can only scroll by full lines vertically (i.e. setting firstLineShown to ~~ 1) |
57 |
74 which should be changed to have this behavior optionally for smooth scroll. |
58 Instance variables: |
75 |
59 |
76 This is being totally rewritten ... so dont depend on the internals. |
60 list <aCollection> the text strings |
77 |
61 attributes <aCollection> corresponding attributes |
78 |
62 firstLineShown <Number> the index of the 1st visible line (1 ..) |
79 Instance variables: |
63 leftOffset <Number> left offset for horizontal scroll |
80 |
64 nFullLinesShown <Number> the number of unclipped lines in visible |
81 list <aCollection> the text strings |
65 nLinesShown <Number> the number of lines in visible |
82 attributes <aCollection> corresponding attributes (if any) |
66 fgColor <Color> color to draw characters |
83 firstLineShown <Number> the index of the 1st visible line (1 ..) |
67 bgColor <Color> the background |
84 leftOffset <Number> left offset for horizontal scroll |
68 partialLines <Boolean> allow last line to be partial displayed |
85 |
69 leftMargin <Number> margin at left in pixels |
86 nFullLinesShown <Number> the number of unclipped lines in visible |
70 topMargin <Number> margin at top in pixels |
87 nLinesShown <Number> the number of lines in visible |
71 textStartLeft <Number> margin + leftMargin |
88 fgColor <Color> color to draw characters |
72 textStartTop <Number> margin + topMargin |
89 bgColor <Color> the background |
73 innerWidth <Number> width - margins |
90 partialLines <Boolean> allow last line to be partial displayed |
74 tabPositions <aCollection> tab stops (cols) |
91 leftMargin <Number> margin at left in pixels |
75 fontHeight <Number> font height in pixels |
92 topMargin <Number> margin at top in pixels |
76 fontAscent <Number> font ascent in pixels |
93 textStartLeft <Number> margin + leftMargin |
77 fontIsFixed <Boolean> true if its a fixed font |
94 textStartTop <Number> margin + topMargin |
78 fontWidth <Number> width of space |
95 innerWidth <Number> width - margins |
79 lineSpacing <Number> pixels between lines |
96 tabPositions <aCollection> tab stops (cols) |
80 normalFont <Font> font for normal characters |
97 fontHeight <Number> font height in pixels |
81 boldFont <Font> font for bold characters |
98 fontAscent <Number> font ascent in pixels |
82 italicFont <Font> font for italic characters |
99 fontIsFixed <Boolean> true if its a fixed font |
83 searchPattern <String> last pattern for searching |
100 fontWidth <Number> width of space |
|
101 lineSpacing <Number> pixels between lines |
|
102 normalFont <Font> font for normal characters |
|
103 boldFont <Font> font for bold characters |
|
104 italicFont <Font> font for italic characters |
|
105 searchPattern <String> last pattern for searching |
|
106 wordCheck <Block> rule used for check in word select |
84 " |
107 " |
85 ! ! |
108 ! ! |
86 |
109 |
87 !ListView class methodsFor:'defaults'! |
110 !ListView class methodsFor:'defaults'! |
88 |
111 |
100 ! ! |
123 ! ! |
101 |
124 |
102 !ListView methodsFor:'initialization'! |
125 !ListView methodsFor:'initialization'! |
103 |
126 |
104 initialize |
127 initialize |
|
128 leftMargin := (self horizontalPixelPerMillimeter:0.5) rounded. |
|
129 |
105 super initialize. |
130 super initialize. |
106 |
131 |
107 bitGravity := #NorthWest. |
132 bitGravity := #NorthWest. |
108 list := nil. |
133 list := nil. |
109 firstLineShown := 1. |
134 firstLineShown := 1. |
|
135 nFullLinesShown := 1. "just any value ..." |
|
136 nLinesShown := 1. "just any value" |
110 leftOffset := 0. |
137 leftOffset := 0. |
111 partialLines := true. |
138 partialLines := true. |
112 tabPositions := self class defaultTabPositions. |
139 tabPositions := self class defaultTabPositions. |
113 leftMargin := (self horizontalPixelPerMillimeter:0.5) rounded. |
|
114 topMargin := (self verticalPixelPerMillimeter:0.5) rounded. |
140 topMargin := (self verticalPixelPerMillimeter:0.5) rounded. |
115 textStartLeft := leftMargin + margin. |
141 textStartLeft := leftMargin + margin. |
116 textStartTop := topMargin + margin. |
142 textStartTop := topMargin + margin. |
117 innerWidth := width - textStartLeft - margin. |
143 innerWidth := width - textStartLeft - (margin * 2). |
118 self getFontParameters |
144 self getFontParameters. |
|
145 wordCheck := [:char | char isNationalAlphaNumeric] |
119 ! |
146 ! |
120 |
147 |
121 initStyle |
148 initStyle |
122 super initStyle. |
149 super initStyle. |
123 fgColor := Black. |
150 |
124 bgColor := White. |
151 fgColor := resources at:'FOREGROUND_COLOR' default:Black. |
|
152 bgColor := resources at:'BACKGROUND_COLOR' default:White. |
125 lineSpacing := 0. |
153 lineSpacing := 0. |
126 ! |
154 |
127 |
155 "Transcript class classResources at:'FOREGROUND_COLOR' put:Color red. |
128 initEvents |
156 Transcript class classResources at:'BACKGROUND_COLOR' put:Color white" |
129 self enableKeyEvents |
|
130 ! |
157 ! |
131 |
158 |
132 create |
159 create |
133 super create. |
160 super create. |
134 |
161 |
317 "delete line" |
364 "delete line" |
318 |
365 |
319 |visLine w |
366 |visLine w |
320 srcY "{ Class: SmallInteger }" | |
367 srcY "{ Class: SmallInteger }" | |
321 |
368 |
322 w := self widthForScrollBetween:lineNr |
|
323 and:(firstLineShown + nLinesShown). |
|
324 (self removeIndexWithoutRedraw:lineNr) ifFalse:[^ self]. |
369 (self removeIndexWithoutRedraw:lineNr) ifFalse:[^ self]. |
|
370 " |
|
371 is there a need to redraw ? |
|
372 " |
325 visLine := self listLineToVisibleLine:lineNr. |
373 visLine := self listLineToVisibleLine:lineNr. |
326 visLine notNil ifTrue:[ |
374 visLine notNil ifTrue:[ |
|
375 w := self widthForScrollBetween:lineNr and:(firstLineShown + nLinesShown). |
327 srcY := topMargin + (visLine * fontHeight). |
376 srcY := topMargin + (visLine * fontHeight). |
328 self catchExpose. |
377 self catchExpose. |
329 self copyFrom:self x:textStartLeft y:srcY |
378 self copyFrom:self x:textStartLeft y:srcY |
330 toX:textStartLeft y:(srcY - fontHeight) |
379 toX:textStartLeft y:(srcY - fontHeight) |
331 width:w height:((nLinesShown - visLine) * fontHeight). |
380 width:w height:((nLinesShown - visLine) * fontHeight). |
395 ! |
447 ! |
396 |
448 |
397 lengthOfLongestLine |
449 lengthOfLongestLine |
398 "return the length (in characters) of the longest line" |
450 "return the length (in characters) of the longest line" |
399 |
451 |
400 |max "{ Class: SmallInteger }" |
452 ^ self lengthOfLongestLineBetween:1 and:list size |
401 thisLen "{ Class: SmallInteger }" | |
|
402 |
|
403 max := 0. |
|
404 list notNil ifTrue:[ |
|
405 list do:[:lineString | |
|
406 lineString notNil ifTrue:[ |
|
407 thisLen := lineString size. |
|
408 (thisLen > max) ifTrue:[ |
|
409 max := thisLen |
|
410 ] |
|
411 ] |
|
412 ] |
|
413 ]. |
|
414 ^ max |
|
415 ! |
453 ! |
416 |
454 |
417 lengthOfLongestLineBetween:firstLine and:lastLine |
455 lengthOfLongestLineBetween:firstLine and:lastLine |
418 "return the length (in characters) of the longest line in a line-range" |
456 "return the length (in characters) of the longest line in a line-range" |
419 |
457 |
420 |max "{ Class: SmallInteger }" |
458 |max "{ Class: SmallInteger }" |
421 thisLen "{ Class: SmallInteger }" |
459 thisLen "{ Class: SmallInteger }" |
422 listSize "{ Class: SmallInteger }" |
460 listSize "{ Class: SmallInteger }" |
423 first "{ Class: SmallInteger }" |
461 first "{ Class: SmallInteger }" |
424 last "{ Class: SmallInteger }" | |
462 last "{ Class: SmallInteger }" | |
|
463 |
|
464 list isNil ifTrue:[^ 0]. |
425 |
465 |
426 listSize := list size. |
466 listSize := list size. |
427 max := 0. |
467 max := 0. |
428 first := firstLine. |
468 first := firstLine. |
429 last := lastLine. |
469 last := lastLine. |
448 - used for scrollbar interface" |
488 - used for scrollbar interface" |
449 |
489 |
450 | numLines | |
490 | numLines | |
451 |
491 |
452 numLines := self numberOfLines. |
492 numLines := self numberOfLines. |
453 ^ numLines * fontHeight + textStartTop. |
493 numLines == 0 ifTrue:[^ 0]. |
454 |
494 " |
455 "it used to be that code - which is wrong" |
495 need device-font for query |
456 (nLinesShown == nFullLinesShown) ifTrue:[ |
496 " |
457 ^ numLines * fontHeight |
497 font := font on:device. |
458 ]. |
498 ^ numLines * fontHeight + textStartTop |
459 "add one - otherwise we cannot make last line |
499 + (font descent) "makes it look better". |
460 fully visible since scrolling is done by full lines only" |
500 "/ + (font descent * 2) "makes it look better". |
461 |
501 |
462 ^ (numLines + 1) * fontHeight |
502 "/ "it used to be that code - which is wrong" |
|
503 "/ (nLinesShown == nFullLinesShown) ifTrue:[ |
|
504 "/ ^ numLines * fontHeight |
|
505 "/ ]. |
|
506 "/ "add one - otherwise we cannot make last line |
|
507 "/ fully visible since scrolling is done by full lines only" |
|
508 "/ |
|
509 "/ ^ (numLines + 1) * fontHeight |
463 ! |
510 ! |
464 |
511 |
465 widthOfContents |
512 widthOfContents |
466 "return the width of the contents in pixels" |
513 "return the width of the contents in pixels |
|
514 - used for scrollbar interface" |
467 |
515 |
468 |max| |
516 |max| |
469 |
517 |
|
518 list isNil ifTrue:[^ 0]. |
|
519 |
470 fontIsFixedWidth ifTrue:[ |
520 fontIsFixedWidth ifTrue:[ |
471 ^ self lengthOfLongestLine * fontWidth |
521 max := self lengthOfLongestLine * fontWidth |
472 ]. |
522 ] ifFalse:[ |
473 max := 0. |
523 max := 0. |
474 list notNil ifTrue:[ |
524 list notNil ifTrue:[ |
475 max := max max:(font widthOf:list) |
525 max := max max:(font widthOf:list) |
476 ]. |
526 ]. |
477 ^ max |
527 ]. |
|
528 ^ max + (leftMargin * 2) |
478 ! |
529 ! |
479 |
530 |
480 yOriginOfContents |
531 yOriginOfContents |
481 "return the vertical origin of the contents in pixels |
532 "return the vertical origin of the contents in pixels |
482 - used for scrollbar interface" |
533 - used for scrollbar interface" |
985 ]. |
1047 ]. |
986 ^ tabPositions at:(tabIndex - 1) |
1048 ^ tabPositions at:(tabIndex - 1) |
987 ! |
1049 ! |
988 |
1050 |
989 withTabsExpanded:line |
1051 withTabsExpanded:line |
990 "good idea, to make this one a primitive" |
1052 "expand tabs into spaces, return a new line string, |
991 |
1053 or original line, if no tabs are included. |
992 |tmpString nString |
1054 good idea, to make this one a primitive" |
|
1055 |
|
1056 |tmpString nString nTabs |
993 currentMax "{ Class: SmallInteger }" |
1057 currentMax "{ Class: SmallInteger }" |
994 dstIndex "{ Class: SmallInteger }" |
1058 dstIndex "{ Class: SmallInteger }" |
995 nextTab "{ Class: SmallInteger }" | |
1059 nextTab "{ Class: SmallInteger }" | |
|
1060 |
|
1061 line isNil ifTrue:[^ line]. |
|
1062 nTabs := line occurrencesOf:(Character tab). |
|
1063 nTabs == 0 ifTrue:[^ line]. |
996 |
1064 |
997 currentMax := 200. |
1065 currentMax := 200. |
998 tmpString := String new:currentMax. |
1066 tmpString := String new:currentMax. |
999 dstIndex := 1. |
1067 dstIndex := 1. |
1000 line do:[:character | |
1068 line do:[:character | |
1113 ]. |
1201 ]. |
1114 "not found" |
1202 "not found" |
1115 |
1203 |
1116 self cursor:savedCursor. |
1204 self cursor:savedCursor. |
1117 ^ block2 value |
1205 ^ block2 value |
|
1206 ! |
|
1207 |
|
1208 findBeginOfWordAtLine:selectLine col:selectCol |
|
1209 "return the col of first character of the word at given line/col. |
|
1210 If the character under the initial col is a space character, return |
|
1211 the first col of the blank-block." |
|
1212 |
|
1213 |beginCol thisCharacter| |
|
1214 |
|
1215 beginCol := selectCol. |
|
1216 thisCharacter := self characterAtLine:selectLine col:beginCol. |
|
1217 |
|
1218 "is this acharacter within a word ?" |
|
1219 (wordCheck value:thisCharacter) ifTrue:[ |
|
1220 [wordCheck value:thisCharacter] whileTrue:[ |
|
1221 beginCol := beginCol - 1. |
|
1222 beginCol < 1 ifTrue:[ |
|
1223 thisCharacter := Character space |
|
1224 ] ifFalse:[ |
|
1225 thisCharacter := self characterAtLine:selectLine col:beginCol |
|
1226 ] |
|
1227 ]. |
|
1228 beginCol := beginCol + 1. |
|
1229 ] ifFalse:[ |
|
1230 "nope - maybe its a space" |
|
1231 thisCharacter == Character space ifTrue:[ |
|
1232 [beginCol > 1 and:[thisCharacter == Character space]] whileTrue:[ |
|
1233 beginCol := beginCol - 1. |
|
1234 thisCharacter := self characterAtLine:selectLine col:beginCol |
|
1235 ]. |
|
1236 thisCharacter ~~ Character space ifTrue:[ |
|
1237 beginCol := beginCol + 1. |
|
1238 ]. |
|
1239 ] ifFalse:[ |
|
1240 "select single character" |
|
1241 ] |
|
1242 ]. |
|
1243 ^ beginCol |
|
1244 ! |
|
1245 |
|
1246 findEndOfWordAtLine:selectLine col:selectCol |
|
1247 "return the col of last character of the word at given line/col. |
|
1248 If the character under the initial col is a space character, return |
|
1249 the last col of the blank-block. |
|
1250 Return 0 if we should wrap to next line (for spaces)" |
|
1251 |
|
1252 |endCol thisCharacter len| |
|
1253 |
|
1254 endCol := selectCol. |
|
1255 endCol == 0 ifTrue:[endCol := 1]. |
|
1256 thisCharacter := self characterAtLine:selectLine col:endCol. |
|
1257 |
|
1258 "is this acharacter within a word ?" |
|
1259 (wordCheck value:thisCharacter) ifTrue:[ |
|
1260 thisCharacter := self characterAtLine:selectLine col:endCol. |
|
1261 [wordCheck value:thisCharacter] whileTrue:[ |
|
1262 endCol := endCol + 1. |
|
1263 thisCharacter := self characterAtLine:selectLine col:endCol |
|
1264 ]. |
|
1265 endCol := endCol - 1. |
|
1266 ] ifFalse:[ |
|
1267 "nope - maybe its a space" |
|
1268 thisCharacter == Character space ifTrue:[ |
|
1269 len := (self listAt:selectLine) size. |
|
1270 endCol > len ifTrue:[ |
|
1271 "select rest to end" |
|
1272 endCol := 0 |
|
1273 ] ifFalse:[ |
|
1274 thisCharacter := self characterAtLine:selectLine col:endCol. |
|
1275 [endCol <= len and:[thisCharacter == Character space]] whileTrue:[ |
|
1276 endCol := endCol + 1. |
|
1277 thisCharacter := self characterAtLine:selectLine col:endCol |
|
1278 ]. |
|
1279 endCol := endCol - 1. |
|
1280 ] |
|
1281 ] ifFalse:[ |
|
1282 "select single character" |
|
1283 ] |
|
1284 ]. |
|
1285 ^ endCol. |
1118 ! ! |
1286 ! ! |
1119 |
1287 |
1120 !ListView methodsFor:'scrolling'! |
1288 !ListView methodsFor:'scrolling'! |
1121 |
1289 |
1122 gotoLine:aLineNumber |
1290 gotoLine:aLineNumber |
1160 |
1336 |
1161 halfPageUp |
1337 halfPageUp |
1162 "scroll up half a page" |
1338 "scroll up half a page" |
1163 |
1339 |
1164 self scrollUp:(nFullLinesShown // 2) |
1340 self scrollUp:(nFullLinesShown // 2) |
|
1341 ! |
|
1342 |
|
1343 makeLineVisible:aListLineNr |
|
1344 "if aListLineNr is not visible, scroll to make it visible. |
|
1345 Numbering starts with 1 for the very first line of the text." |
|
1346 |
|
1347 |bott| |
|
1348 |
|
1349 (aListLineNr isNil "or:[shown not]") ifTrue:[^ self]. |
|
1350 |
|
1351 (aListLineNr >= firstLineShown) ifTrue:[ |
|
1352 (aListLineNr < (firstLineShown + nFullLinesShown)) ifTrue:[ |
|
1353 ^ self |
|
1354 ] |
|
1355 ]. |
|
1356 (aListLineNr < nFullLinesShown) ifTrue:[ |
|
1357 ^ self scrollToLine:1 |
|
1358 ]. |
|
1359 (nFullLinesShown < 3) ifTrue:[ |
|
1360 ^ self scrollToLine:aListLineNr |
|
1361 ]. |
|
1362 bott := self numberOfLines - (nFullLinesShown - 1). |
|
1363 (aListLineNr > bott) ifTrue:[ |
|
1364 ^ self scrollToLine:bott |
|
1365 ]. |
|
1366 self scrollToLine:(aListLineNr - (nFullLinesShown // 2) + 1) |
|
1367 ! |
|
1368 |
|
1369 makeColVisible:aCol inLine:aLineNr |
|
1370 "if column aCol is not visible, scroll horizontal to make it visible" |
|
1371 |
|
1372 |xWant xVis visLnr oldLeft| |
|
1373 |
|
1374 (aCol isNil or:[shown not]) ifTrue:[^ self]. |
|
1375 |
|
1376 visLnr := self absoluteLineToVisibleLine:aLineNr. |
|
1377 visLnr isNil ifTrue:[^ self]. |
|
1378 |
|
1379 xWant := self xOfCol:aCol inLine:visLnr. |
|
1380 " |
|
1381 dont scroll, if already visible |
|
1382 (but scroll, if not in inner 20%..80% of visible area) |
|
1383 " |
|
1384 xVis := xWant - leftOffset. |
|
1385 |
|
1386 ((xVis >= (width // 5)) and:[xVis <= (width * 4 // 5)]) ifTrue:[ |
|
1387 ^ self |
|
1388 ]. |
|
1389 |
|
1390 oldLeft := leftOffset. |
|
1391 self scrollHorizontalTo:(xWant - (width // 2)). |
|
1392 self originChanged:((oldLeft - leftOffset) @ 0) |
1165 ! |
1393 ! |
1166 |
1394 |
1167 scrollDown:nLines |
1395 scrollDown:nLines |
1168 "change origin to scroll down some lines" |
1396 "change origin to scroll down some lines" |
1169 |
1397 |
1265 self scrollDown:(aLineNr - firstLineShown) |
1502 self scrollDown:(aLineNr - firstLineShown) |
1266 ] |
1503 ] |
1267 ] |
1504 ] |
1268 ! |
1505 ! |
1269 |
1506 |
|
1507 scrollToLeft |
|
1508 "change origin to start (left) of text" |
|
1509 |
|
1510 leftOffset ~~ 0 ifTrue:[ |
|
1511 self scrollToCol:1 |
|
1512 ] |
|
1513 ! |
|
1514 |
|
1515 scrollToCol:aColNr |
|
1516 "change origin to make aColNr be the left col" |
|
1517 |
|
1518 |pxlOffset| |
|
1519 |
|
1520 aColNr == 1 ifTrue:[ |
|
1521 leftOffset ~~ 0 ifTrue:[ |
|
1522 self scrollLeft:leftOffset. |
|
1523 ]. |
|
1524 ^ self |
|
1525 ]. |
|
1526 |
|
1527 pxlOffset := font width * (aColNr - 1). |
|
1528 |
|
1529 pxlOffset < leftOffset ifTrue:[ |
|
1530 self scrollLeft:(leftOffset - pxlOffset) |
|
1531 ] ifFalse:[ |
|
1532 pxlOffset > leftOffset ifTrue:[ |
|
1533 self scrollRight:(pxlOffset - leftOffset) |
|
1534 ] |
|
1535 ] |
|
1536 ! |
|
1537 |
1270 scrollVerticalToPercent:percent |
1538 scrollVerticalToPercent:percent |
1271 "scroll to a position given in percent of total" |
1539 "scroll to a position given in percent of total" |
1272 |
1540 |
1273 |lineNr| |
1541 |lineNr| |
1274 |
1542 |
1275 lineNr := (((self numberOfLines * percent) asFloat / 100.0) + 0.5) asInteger + 1. |
1543 lineNr := (((self numberOfLines * percent) asFloat / 100.0) + 0.5) asInteger + 1. |
1276 self scrollToLine:lineNr |
1544 self scrollToLine:lineNr |
1277 ! |
|
1278 |
|
1279 makeLineVisible:aListLineNr |
|
1280 "if aListLineNr is not visible, scroll to make it visible" |
|
1281 |
|
1282 |bott| |
|
1283 |
|
1284 (aListLineNr isNil or:[shown not]) ifTrue:[^ self]. |
|
1285 |
|
1286 (aListLineNr >= firstLineShown) ifTrue:[ |
|
1287 (aListLineNr < (firstLineShown + nFullLinesShown)) ifTrue:[ |
|
1288 ^ self |
|
1289 ] |
|
1290 ]. |
|
1291 (aListLineNr < nFullLinesShown) ifTrue:[ |
|
1292 ^ self scrollToLine:1 |
|
1293 ]. |
|
1294 (nFullLinesShown < 3) ifTrue:[ |
|
1295 ^ self scrollToLine:aListLineNr |
|
1296 ]. |
|
1297 bott := self numberOfLines - (nFullLinesShown - 1). |
|
1298 (aListLineNr > bott) ifTrue:[ |
|
1299 ^ self scrollToLine:bott |
|
1300 ]. |
|
1301 self scrollToLine:(aListLineNr - (nFullLinesShown // 2) + 1) |
|
1302 ! |
1545 ! |
1303 |
1546 |
1304 scrollSelectUp |
1547 scrollSelectUp |
1305 "just a template - I do not know anything about selections" |
1548 "just a template - I do not know anything about selections" |
1306 |
1549 |
1356 self compressMotionEvents:true. |
1599 self compressMotionEvents:true. |
1357 Processor removeTimedBlock:autoScrollBlock. |
1600 Processor removeTimedBlock:autoScrollBlock. |
1358 autoScrollBlock := nil. |
1601 autoScrollBlock := nil. |
1359 autoScrollDeltaT := nil |
1602 autoScrollDeltaT := nil |
1360 ]. |
1603 ]. |
|
1604 ! |
|
1605 |
|
1606 scrollRight |
|
1607 "scroll right by one character |
|
1608 - question is how much is a good for variable fonts" |
|
1609 |
|
1610 self scrollRight:font width |
|
1611 ! |
|
1612 |
|
1613 scrollRight:nPixel |
|
1614 "change origin to scroll right some cols" |
|
1615 |
|
1616 |wMax cnt| |
|
1617 |
|
1618 |
|
1619 cnt := nPixel. |
|
1620 |
|
1621 " |
|
1622 commenting out the block below allows scrolling to the right of |
|
1623 the widest line |
|
1624 " |
|
1625 " " |
|
1626 " |
|
1627 the 10 below allows scrolling somewhat behind the end of the line |
|
1628 " |
|
1629 wMax := self widthOfContents + 10. |
|
1630 (leftOffset + nPixel + width > wMax) ifTrue:[ |
|
1631 cnt := wMax - leftOffset - width |
|
1632 ]. |
|
1633 cnt <= 0 ifTrue:[^ self]. |
|
1634 " " |
|
1635 self originWillChange. |
|
1636 leftOffset:= leftOffset + cnt. |
|
1637 self redrawFromVisibleLine:1 to:nLinesShown. |
|
1638 self originChanged:(cnt @ 0) |
|
1639 ! |
|
1640 |
|
1641 scrollLeft |
|
1642 "scroll left by one character |
|
1643 - question is how much is a good for variable fonts" |
|
1644 |
|
1645 self scrollLeft:font width |
|
1646 ! |
|
1647 |
|
1648 scrollLeft:nPixel |
|
1649 "change origin to scroll left some cols" |
|
1650 |
|
1651 |newLeftOffset| |
|
1652 |
|
1653 nPixel <= 0 ifTrue:[^ self]. |
|
1654 |
|
1655 newLeftOffset := leftOffset - nPixel. |
|
1656 newLeftOffset <= 0 ifTrue:[ |
|
1657 leftOffset == 0 ifTrue:[^ self]. |
|
1658 newLeftOffset := 0 |
|
1659 ]. |
|
1660 |
|
1661 self originWillChange. |
|
1662 leftOffset := newLeftOffset. |
|
1663 self redrawFromVisibleLine:1 to:nLinesShown. |
|
1664 self originChanged:(0 @ nPixel) |
|
1665 ! |
|
1666 |
|
1667 scrollHorizontalTo:aPixelOffset |
|
1668 "change origin to make aPixelOffset be the left col" |
|
1669 |
|
1670 |orgX| |
|
1671 |
|
1672 orgX := leftOffset. |
|
1673 |
|
1674 (aPixelOffset < orgX) ifTrue:[ |
|
1675 self scrollLeft:(orgX - aPixelOffset) |
|
1676 ] ifFalse:[ |
|
1677 (aPixelOffset > orgX) ifTrue:[ |
|
1678 self scrollRight:(aPixelOffset - orgX) |
|
1679 ] |
|
1680 ] |
1361 ! ! |
1681 ! ! |
1362 |
1682 |
1363 !ListView methodsFor:'drawing'! |
1683 !ListView methodsFor:'drawing'! |
1364 |
1684 |
1365 drawVisibleLine:visLineNr col:col with:fg and:bg |
1685 drawVisibleLine:visLineNr col:col with:fg and:bg |
1701 "start/end col has to be computed for each line" |
2022 "start/end col has to be computed for each line" |
1702 |
2023 |
1703 startLine to:stopLine do:[:i | |
2024 startLine to:stopLine do:[:i | |
1704 startCol := self colOfX:x inVisibleLine:i. |
2025 startCol := self colOfX:x inVisibleLine:i. |
1705 endCol := self colOfX:(x + w) inVisibleLine:i. |
2026 endCol := self colOfX:(x + w) inVisibleLine:i. |
1706 self redrawVisibleLine:i from:startCol to:endCol |
2027 startCol > 0 ifTrue:[ |
|
2028 endCol > 0 ifTrue:[ |
|
2029 self redrawVisibleLine:i from:startCol to:endCol |
|
2030 ] |
|
2031 ] |
1707 ] |
2032 ] |
1708 ] ifTrue:[ |
2033 ] ifTrue:[ |
1709 "start/end col is the same for all lines" |
2034 "start/end col is the same for all lines" |
1710 |
2035 |
1711 startCol := self colOfX:x inVisibleLine:startLine. |
2036 startCol := self colOfX:x inVisibleLine:startLine. |
1712 endCol := self colOfX:(x + w) inVisibleLine:startLine. |
2037 endCol := self colOfX:(x + w) inVisibleLine:startLine. |
1713 startLine to:stopLine do:[:i | |
2038 startCol > 0 ifTrue:[ |
1714 self redrawVisibleLine:i from:startCol to:endCol |
2039 endCol > 0 ifTrue:[ |
|
2040 startLine to:stopLine do:[:i | |
|
2041 self redrawVisibleLine:i from:startCol to:endCol |
|
2042 ] |
|
2043 ] |
1715 ] |
2044 ] |
1716 ] |
2045 ] |
1717 ] |
2046 ] |
1718 ! |
2047 ! |
1719 |
2048 |