0
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
3 |
All Rights Reserved
|
0
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
View subclass:#ListView
|
|
14 |
instanceVariableNames:'list
|
59
|
15 |
attributes
|
|
16 |
firstLineShown leftOffset
|
|
17 |
nFullLinesShown nLinesShown
|
|
18 |
fgColor bgColor
|
|
19 |
partialLines
|
|
20 |
leftMargin topMargin
|
|
21 |
textStartLeft textStartTop innerWidth
|
|
22 |
tabPositions lineSpacing
|
|
23 |
fontHeight fontAscent
|
|
24 |
fontIsFixedWidth fontWidth
|
|
25 |
normalFont boldFont italicFont
|
|
26 |
autoScrollBlock autoScrollDeltaT
|
|
27 |
searchPattern wordCheck
|
|
28 |
includesNonStrings'
|
|
29 |
classVariableNames:'DefaultForegroundColor DefaultBackgroundColor
|
|
30 |
DefaultFont'
|
0
|
31 |
poolDictionaries:''
|
|
32 |
category:'Views-Text'
|
|
33 |
!
|
|
34 |
|
|
35 |
ListView comment:'
|
5
|
36 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
37 |
All Rights Reserved
|
0
|
38 |
|
60
|
39 |
$Header: /cvs/stx/stx/libwidg/ListView.st,v 1.11 1994-10-28 03:25:07 claus Exp $
|
0
|
40 |
'!
|
|
41 |
|
|
42 |
!ListView class methodsFor:'documentation'!
|
|
43 |
|
38
|
44 |
copyright
|
|
45 |
"
|
|
46 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
47 |
All Rights Reserved
|
38
|
48 |
|
|
49 |
This software is furnished under a license and may be used
|
|
50 |
only in accordance with the terms of that license and with the
|
|
51 |
inclusion of the above copyright notice. This software may not
|
|
52 |
be provided or otherwise made available to, or used by, any
|
|
53 |
other person. No title to or ownership of the software is
|
|
54 |
hereby transferred.
|
|
55 |
"
|
|
56 |
!
|
|
57 |
|
|
58 |
version
|
|
59 |
"
|
60
|
60 |
$Header: /cvs/stx/stx/libwidg/ListView.st,v 1.11 1994-10-28 03:25:07 claus Exp $
|
38
|
61 |
"
|
|
62 |
!
|
|
63 |
|
0
|
64 |
documentation
|
|
65 |
"
|
38
|
66 |
a View for (string-)lists.
|
|
67 |
|
|
68 |
This class can only passively display collections of strings-
|
|
69 |
selections, editing, cursors etc. must be done in subclasses.
|
|
70 |
see SelectionInListView, TextView etc.
|
|
71 |
|
|
72 |
This code currently handles only fixed-height fonts correctly -
|
|
73 |
should be rewritten in some places ...
|
0
|
74 |
|
38
|
75 |
It can only scroll by full lines vertically (i.e. setting firstLineShown to ~~ 1)
|
|
76 |
which should be changed to have this behavior optionally for smooth scroll.
|
|
77 |
|
|
78 |
This is being totally rewritten ... so dont depend on the internals.
|
|
79 |
|
0
|
80 |
|
38
|
81 |
Instance variables:
|
0
|
82 |
|
38
|
83 |
list <aCollection> the text strings
|
|
84 |
attributes <aCollection> corresponding attributes (if any)
|
|
85 |
firstLineShown <Number> the index of the 1st visible line (1 ..)
|
|
86 |
leftOffset <Number> left offset for horizontal scroll
|
0
|
87 |
|
38
|
88 |
nFullLinesShown <Number> the number of unclipped lines in visible
|
|
89 |
nLinesShown <Number> the number of lines in visible
|
|
90 |
fgColor <Color> color to draw characters
|
|
91 |
bgColor <Color> the background
|
|
92 |
partialLines <Boolean> allow last line to be partial displayed
|
|
93 |
leftMargin <Number> margin at left in pixels
|
|
94 |
topMargin <Number> margin at top in pixels
|
|
95 |
textStartLeft <Number> margin + leftMargin
|
|
96 |
textStartTop <Number> margin + topMargin
|
|
97 |
innerWidth <Number> width - margins
|
|
98 |
tabPositions <aCollection> tab stops (cols)
|
|
99 |
fontHeight <Number> font height in pixels
|
|
100 |
fontAscent <Number> font ascent in pixels
|
|
101 |
fontIsFixed <Boolean> true if its a fixed font
|
|
102 |
fontWidth <Number> width of space
|
|
103 |
lineSpacing <Number> pixels between lines
|
|
104 |
normalFont <Font> font for normal characters
|
|
105 |
boldFont <Font> font for bold characters
|
|
106 |
italicFont <Font> font for italic characters
|
|
107 |
searchPattern <String> last pattern for searching
|
|
108 |
wordCheck <Block> rule used for check in word select
|
0
|
109 |
"
|
|
110 |
! !
|
|
111 |
|
|
112 |
!ListView class methodsFor:'defaults'!
|
|
113 |
|
59
|
114 |
updateStyleCache
|
60
|
115 |
DefaultForegroundColor := StyleSheet colorAt:'textForegroundColor' default:Black.
|
|
116 |
DefaultBackgroundColor := StyleSheet colorAt:'textBackgroundColor' default:White.
|
|
117 |
DefaultFont := StyleSheet fontAt:'textFont'.
|
59
|
118 |
!
|
|
119 |
|
7
|
120 |
tab4Positions
|
|
121 |
^ #(1 5 9 13 17 21 25 29 33 37 41 45 49 53 57 61 65 69 73 77 81
|
59
|
122 |
85 89 93 97 101 105 109 113 114 121 125 129 133 137 141 145)
|
7
|
123 |
!
|
|
124 |
|
|
125 |
tab8Positions
|
|
126 |
^ #(1 9 17 25 33 41 49 57 65 73 81 89 97 105 113 121 129 137 145)
|
|
127 |
!
|
|
128 |
|
0
|
129 |
defaultTabPositions
|
7
|
130 |
^ self tab8Positions
|
0
|
131 |
! !
|
|
132 |
|
|
133 |
!ListView methodsFor:'initialization'!
|
|
134 |
|
|
135 |
initialize
|
59
|
136 |
device width <= 800 ifTrue:[
|
|
137 |
"
|
|
138 |
some more pixels of real estate ...
|
|
139 |
"
|
|
140 |
leftMargin := topMargin := 1
|
|
141 |
] ifFalse:[
|
|
142 |
leftMargin := (self horizontalPixelPerMillimeter:0.5) rounded.
|
|
143 |
topMargin := (self verticalPixelPerMillimeter:0.5) rounded.
|
|
144 |
].
|
38
|
145 |
|
0
|
146 |
super initialize.
|
|
147 |
|
|
148 |
bitGravity := #NorthWest.
|
|
149 |
list := nil.
|
|
150 |
firstLineShown := 1.
|
38
|
151 |
nFullLinesShown := 1. "just any value ..."
|
|
152 |
nLinesShown := 1. "just any value"
|
0
|
153 |
leftOffset := 0.
|
|
154 |
partialLines := true.
|
|
155 |
tabPositions := self class defaultTabPositions.
|
|
156 |
textStartLeft := leftMargin + margin.
|
|
157 |
textStartTop := topMargin + margin.
|
38
|
158 |
innerWidth := width - textStartLeft - (margin * 2).
|
|
159 |
self getFontParameters.
|
51
|
160 |
wordCheck := [:char | char isNationalAlphaNumeric].
|
|
161 |
includesNonStrings := false
|
0
|
162 |
!
|
|
163 |
|
|
164 |
initStyle
|
|
165 |
super initStyle.
|
38
|
166 |
|
0
|
167 |
lineSpacing := 0.
|
59
|
168 |
fgColor := DefaultForegroundColor on:device.
|
|
169 |
bgColor := DefaultBackgroundColor on:device.
|
|
170 |
DefaultFont notNil ifTrue:[font := DefaultFont on:device]
|
0
|
171 |
!
|
|
172 |
|
|
173 |
create
|
|
174 |
super create.
|
|
175 |
|
|
176 |
"I cache font parameters here - they are used so often ..."
|
|
177 |
self getFontParameters.
|
|
178 |
self computeNumberOfLinesShown.
|
|
179 |
fgColor := fgColor on:device.
|
|
180 |
bgColor := bgColor on:device
|
|
181 |
!
|
|
182 |
|
|
183 |
recreate
|
|
184 |
"recreate after a snapin"
|
|
185 |
|
|
186 |
super recreate.
|
|
187 |
|
|
188 |
"recompute margins and font parameters
|
|
189 |
- display may have different resolution."
|
|
190 |
|
|
191 |
leftMargin := (self horizontalPixelPerMillimeter:0.5) rounded.
|
|
192 |
topMargin := (self verticalPixelPerMillimeter:0.5) rounded.
|
|
193 |
textStartLeft := leftMargin + margin.
|
|
194 |
textStartTop := topMargin + margin.
|
|
195 |
innerWidth := width - textStartLeft - margin.
|
|
196 |
self getFontParameters
|
|
197 |
! !
|
|
198 |
|
|
199 |
!ListView methodsFor:'accessing'!
|
|
200 |
|
59
|
201 |
backgroundColor
|
|
202 |
"return the background color"
|
|
203 |
|
|
204 |
^ bgColor
|
|
205 |
!
|
|
206 |
|
0
|
207 |
backgroundColor:aColor
|
|
208 |
"set the background color"
|
|
209 |
|
38
|
210 |
bgColor ~~ aColor ifTrue:[
|
59
|
211 |
bgColor := aColor.
|
|
212 |
self viewBackground:bgColor.
|
|
213 |
shown ifTrue:[
|
|
214 |
self clear.
|
|
215 |
self redraw
|
|
216 |
]
|
0
|
217 |
]
|
|
218 |
!
|
|
219 |
|
59
|
220 |
foregroundColor
|
|
221 |
"return the foreground color"
|
|
222 |
|
|
223 |
^ fgColor
|
|
224 |
!
|
|
225 |
|
0
|
226 |
foregroundColor:aColor
|
|
227 |
"set the foreground color"
|
|
228 |
|
38
|
229 |
fgColor ~~ aColor ifTrue:[
|
59
|
230 |
fgColor := aColor.
|
|
231 |
shown ifTrue:[
|
|
232 |
self redraw
|
|
233 |
]
|
0
|
234 |
]
|
|
235 |
!
|
|
236 |
|
|
237 |
foregroundColor:color1 backgroundColor:color2
|
|
238 |
"set both foreground and background colors"
|
|
239 |
|
38
|
240 |
((fgColor ~~ color1) or:[bgColor ~~ color2]) ifTrue:[
|
59
|
241 |
fgColor := color1.
|
|
242 |
bgColor := color2.
|
|
243 |
shown ifTrue:[
|
|
244 |
self redraw
|
|
245 |
]
|
0
|
246 |
]
|
|
247 |
!
|
|
248 |
|
|
249 |
partialLines:aBoolean
|
|
250 |
"allow/disallow display of a last partial line"
|
|
251 |
|
|
252 |
partialLines := aBoolean.
|
|
253 |
self computeNumberOfLinesShown
|
|
254 |
!
|
|
255 |
|
|
256 |
leftMargin:aNumber
|
|
257 |
"set the margin to left of 1st col"
|
|
258 |
|
|
259 |
leftMargin := aNumber.
|
|
260 |
textStartLeft := leftMargin + margin.
|
|
261 |
innerWidth := width - textStartLeft - margin
|
|
262 |
!
|
|
263 |
|
|
264 |
leftMargin
|
|
265 |
"return the margin to left of 1st col"
|
|
266 |
|
|
267 |
^ leftMargin
|
|
268 |
!
|
|
269 |
|
51
|
270 |
setList:aCollection expandTabs:expandTabs
|
38
|
271 |
"set the contents (a collection of strings);
|
|
272 |
dont change position (i.e. do not scroll).
|
|
273 |
This can be used to update a self-changing list
|
|
274 |
(for example: a file list being shown, without disturbing user too much)"
|
0
|
275 |
|
|
276 |
(aCollection isNil and:[list isNil]) ifTrue:[
|
59
|
277 |
"no change"
|
|
278 |
^ self
|
0
|
279 |
].
|
|
280 |
list := aCollection.
|
|
281 |
|
|
282 |
list notNil ifTrue:[
|
59
|
283 |
expandTabs ifTrue:[
|
|
284 |
self expandTabs
|
|
285 |
] ifFalse:[
|
|
286 |
includesNonStrings := (list findFirst:[:l | l notNil and:[l isString not]]) ~~ 0.
|
|
287 |
]
|
0
|
288 |
].
|
|
289 |
self contentsChanged.
|
|
290 |
shown ifTrue:[
|
59
|
291 |
self redrawFromVisibleLine:1 to:nLinesShown
|
0
|
292 |
]
|
|
293 |
!
|
|
294 |
|
51
|
295 |
setList:aCollection
|
|
296 |
"set the contents (a collection of strings);
|
|
297 |
dont change position (i.e. do not scroll).
|
|
298 |
This can be used to update a self-changing list
|
|
299 |
(for example: a file list being shown, without disturbing user too much)"
|
|
300 |
|
|
301 |
^ self setList:aCollection expandTabs:true
|
|
302 |
!
|
|
303 |
|
0
|
304 |
list:aCollection
|
38
|
305 |
"set the contents (a collection of strings) and scroll to top-left"
|
0
|
306 |
|
38
|
307 |
|oldFirst oldLeft|
|
0
|
308 |
|
|
309 |
(aCollection isNil and:[list isNil]) ifTrue:[
|
59
|
310 |
"no change"
|
|
311 |
self scrollToTop.
|
|
312 |
self scrollToLeft.
|
|
313 |
^ self
|
0
|
314 |
].
|
|
315 |
list := aCollection.
|
|
316 |
|
|
317 |
list notNil ifTrue:[
|
59
|
318 |
self expandTabs
|
0
|
319 |
].
|
|
320 |
oldFirst := firstLineShown.
|
38
|
321 |
oldLeft := leftOffset.
|
0
|
322 |
firstLineShown := 1.
|
38
|
323 |
leftOffset := 0.
|
|
324 |
realized ifTrue:[
|
59
|
325 |
self contentsChanged.
|
|
326 |
"
|
|
327 |
dont use scroll here to avoid the redraw
|
|
328 |
"
|
|
329 |
self originChanged:(oldFirst - 1) negated.
|
|
330 |
shown ifTrue:[
|
|
331 |
self redrawFromVisibleLine:1 to:nLinesShown
|
|
332 |
]
|
0
|
333 |
]
|
|
334 |
!
|
|
335 |
|
|
336 |
list
|
|
337 |
"return the contents as a collection of strings"
|
|
338 |
|
|
339 |
^ list
|
|
340 |
!
|
|
341 |
|
|
342 |
setContents:something
|
|
343 |
"set the contents (either a string or a Collection of strings)
|
38
|
344 |
dont change position (i.e. do not scroll).
|
|
345 |
This can be used to update a self-changing list
|
|
346 |
(for example: a file list being shown, without disturbing user too much)."
|
0
|
347 |
|
51
|
348 |
|l|
|
|
349 |
|
|
350 |
l := something.
|
|
351 |
l notNil ifTrue:[
|
|
352 |
l isString ifTrue:[
|
|
353 |
l := l asText
|
|
354 |
]
|
|
355 |
].
|
|
356 |
self setList:l
|
0
|
357 |
!
|
|
358 |
|
|
359 |
contents:something
|
|
360 |
"set the contents (either a string or a Collection of strings)
|
38
|
361 |
also scroll to top-left"
|
0
|
362 |
|
51
|
363 |
|l|
|
|
364 |
|
|
365 |
l := something.
|
|
366 |
l notNil ifTrue:[
|
59
|
367 |
l isString ifTrue:[
|
|
368 |
l := l asText
|
|
369 |
]
|
51
|
370 |
].
|
|
371 |
self list:l
|
0
|
372 |
!
|
|
373 |
|
|
374 |
contents
|
|
375 |
"return the contents as a string"
|
|
376 |
|
|
377 |
list isNil ifTrue:[^ ''].
|
|
378 |
^ list asString
|
|
379 |
!
|
|
380 |
|
|
381 |
at:index put:aString
|
|
382 |
"change a line and redisplay"
|
|
383 |
|
|
384 |
self checkForExistingLine:index.
|
|
385 |
list at:index put:aString.
|
60
|
386 |
includesNonStrings ifFalse:[
|
|
387 |
includesNonStrings := (aString notNil and:[aString isString not]).
|
|
388 |
] ifTrue:[
|
|
389 |
(aString isNil or:[aString isString]) ifTrue:[
|
|
390 |
includesNonStrings := (list findFirst:[:l | l notNil and:[l isString not]]) ~~ 0.
|
|
391 |
]
|
|
392 |
].
|
0
|
393 |
shown ifTrue:[
|
59
|
394 |
self redrawLine:index
|
0
|
395 |
]
|
|
396 |
!
|
|
397 |
|
|
398 |
at:index
|
|
399 |
"retrieve a line; return nil if behond end-of-text"
|
|
400 |
|
|
401 |
^ self listAt:index
|
|
402 |
!
|
|
403 |
|
|
404 |
removeIndexWithoutRedraw:lineNr
|
|
405 |
"delete line - no redraw;
|
3
|
406 |
return true, if something was really deleted"
|
0
|
407 |
|
|
408 |
(list isNil or:[lineNr > list size]) ifTrue:[^ false].
|
|
409 |
list removeIndex:lineNr.
|
38
|
410 |
(attributes notNil and:[lineNr <= attributes size]) ifTrue:[attributes removeIndex:lineNr].
|
|
411 |
|
7
|
412 |
lineNr < firstLineShown ifTrue:[
|
59
|
413 |
firstLineShown := firstLineShown - 1
|
0
|
414 |
].
|
|
415 |
self contentsChanged.
|
|
416 |
^ true
|
|
417 |
!
|
|
418 |
|
|
419 |
removeIndex:lineNr
|
|
420 |
"delete line"
|
|
421 |
|
|
422 |
|visLine w
|
|
423 |
srcY "{ Class: SmallInteger }" |
|
|
424 |
|
|
425 |
(self removeIndexWithoutRedraw:lineNr) ifFalse:[^ self].
|
38
|
426 |
"
|
|
427 |
is there a need to redraw ?
|
|
428 |
"
|
0
|
429 |
visLine := self listLineToVisibleLine:lineNr.
|
|
430 |
visLine notNil ifTrue:[
|
59
|
431 |
w := self widthForScrollBetween:lineNr and:(firstLineShown + nLinesShown).
|
|
432 |
srcY := topMargin + (visLine * fontHeight).
|
|
433 |
self catchExpose.
|
|
434 |
self copyFrom:self x:textStartLeft y:srcY
|
|
435 |
toX:textStartLeft y:(srcY - fontHeight)
|
|
436 |
width:w height:((nLinesShown - visLine) * fontHeight).
|
|
437 |
self redrawVisibleLine:nFullLinesShown.
|
|
438 |
(nFullLinesShown ~~ nLinesShown) ifTrue:[
|
|
439 |
self redrawVisibleLine:nLinesShown
|
|
440 |
].
|
|
441 |
self waitForExpose
|
0
|
442 |
]
|
|
443 |
!
|
|
444 |
|
|
445 |
font:aFont
|
|
446 |
"set the font"
|
|
447 |
|
|
448 |
aFont isNil ifTrue:[
|
59
|
449 |
^ self error:'nil font'
|
0
|
450 |
].
|
38
|
451 |
font ~~ aFont ifTrue:[
|
59
|
452 |
super font:aFont.
|
|
453 |
realized ifTrue:[
|
|
454 |
(font device == device) ifTrue:[
|
|
455 |
self getFontParameters.
|
|
456 |
self computeNumberOfLinesShown.
|
|
457 |
shown ifTrue:[
|
|
458 |
self redrawFromVisibleLine:1 to:nLinesShown
|
|
459 |
]
|
|
460 |
].
|
|
461 |
self contentsChanged
|
|
462 |
]
|
38
|
463 |
]
|
0
|
464 |
!
|
|
465 |
|
|
466 |
level:aNumber
|
|
467 |
"set the level - cought here to update text-position variables
|
38
|
468 |
(which avoids many computations later)"
|
0
|
469 |
|
|
470 |
super level:aNumber.
|
|
471 |
|
|
472 |
textStartLeft := leftMargin + margin.
|
|
473 |
textStartTop := topMargin + margin.
|
|
474 |
" textStartLeft := leftMargin. "
|
|
475 |
innerWidth := width - textStartLeft - margin
|
|
476 |
!
|
|
477 |
|
|
478 |
innerHeight
|
|
479 |
"return the number of pixels visible of the contents
|
|
480 |
- redefined since ListView adds a margin"
|
|
481 |
|
|
482 |
^ height - (2 * margin) - (2 * topMargin)
|
|
483 |
! !
|
|
484 |
|
|
485 |
!ListView methodsFor:'queries'!
|
|
486 |
|
3
|
487 |
firstLineShown
|
|
488 |
"return the index of the first (possibly partial) visible line"
|
|
489 |
|
|
490 |
^ firstLineShown
|
|
491 |
!
|
|
492 |
|
|
493 |
lastLineShown
|
38
|
494 |
"return the index of the last (possibly partial) visible line"
|
3
|
495 |
|
|
496 |
^ firstLineShown + nLinesShown
|
|
497 |
!
|
|
498 |
|
0
|
499 |
numberOfLines
|
3
|
500 |
"return the number of lines the text has"
|
0
|
501 |
|
|
502 |
^ list size
|
|
503 |
!
|
|
504 |
|
|
505 |
lengthOfLongestLine
|
3
|
506 |
"return the length (in characters) of the longest line"
|
0
|
507 |
|
38
|
508 |
^ self lengthOfLongestLineBetween:1 and:list size
|
0
|
509 |
!
|
|
510 |
|
|
511 |
lengthOfLongestLineBetween:firstLine and:lastLine
|
3
|
512 |
"return the length (in characters) of the longest line in a line-range"
|
0
|
513 |
|
|
514 |
|max "{ Class: SmallInteger }"
|
|
515 |
thisLen "{ Class: SmallInteger }"
|
|
516 |
listSize "{ Class: SmallInteger }"
|
|
517 |
first "{ Class: SmallInteger }"
|
|
518 |
last "{ Class: SmallInteger }" |
|
|
519 |
|
38
|
520 |
list isNil ifTrue:[^ 0].
|
|
521 |
|
0
|
522 |
listSize := list size.
|
|
523 |
max := 0.
|
|
524 |
first := firstLine.
|
|
525 |
last := lastLine.
|
|
526 |
|
|
527 |
(first > listSize) ifTrue:[^ max].
|
|
528 |
(last > listSize) ifTrue:[
|
59
|
529 |
last := listSize
|
0
|
530 |
].
|
|
531 |
list from:first to:last do:[:lineString |
|
59
|
532 |
lineString notNil ifTrue:[
|
|
533 |
thisLen := lineString size.
|
|
534 |
(thisLen > max) ifTrue:[
|
|
535 |
max := thisLen
|
|
536 |
]
|
|
537 |
]
|
0
|
538 |
].
|
|
539 |
^ max
|
|
540 |
!
|
|
541 |
|
|
542 |
heightOfContents
|
|
543 |
"return the height of the contents in pixels
|
|
544 |
- used for scrollbar interface"
|
|
545 |
|
|
546 |
| numLines |
|
|
547 |
|
|
548 |
numLines := self numberOfLines.
|
38
|
549 |
numLines == 0 ifTrue:[^ 0].
|
|
550 |
"
|
|
551 |
need device-font for query
|
|
552 |
"
|
|
553 |
font := font on:device.
|
|
554 |
^ numLines * fontHeight + textStartTop
|
59
|
555 |
+ (font descent) "makes it look better".
|
38
|
556 |
"/ + (font descent * 2) "makes it look better".
|
0
|
557 |
|
38
|
558 |
"/ "it used to be that code - which is wrong"
|
|
559 |
"/ (nLinesShown == nFullLinesShown) ifTrue:[
|
|
560 |
"/ ^ numLines * fontHeight
|
|
561 |
"/ ].
|
|
562 |
"/ "add one - otherwise we cannot make last line
|
|
563 |
"/ fully visible since scrolling is done by full lines only"
|
|
564 |
"/
|
|
565 |
"/ ^ (numLines + 1) * fontHeight
|
0
|
566 |
!
|
|
567 |
|
|
568 |
widthOfContents
|
38
|
569 |
"return the width of the contents in pixels
|
|
570 |
- used for scrollbar interface"
|
0
|
571 |
|
|
572 |
|max|
|
|
573 |
|
38
|
574 |
list isNil ifTrue:[^ 0].
|
|
575 |
|
51
|
576 |
includesNonStrings ifTrue:[
|
59
|
577 |
max := list
|
|
578 |
inject:0
|
|
579 |
into:[:maxSoFar :entry |
|
|
580 |
(
|
|
581 |
entry isNil ifTrue:[
|
|
582 |
0
|
|
583 |
] ifFalse:[
|
|
584 |
entry isString ifTrue:[
|
|
585 |
font widthOf:entry
|
|
586 |
] ifFalse:[
|
|
587 |
entry widthIn:self
|
|
588 |
]
|
|
589 |
]
|
|
590 |
) max:maxSoFar.
|
|
591 |
]
|
38
|
592 |
] ifFalse:[
|
59
|
593 |
fontIsFixedWidth ifTrue:[
|
|
594 |
max := self lengthOfLongestLine * fontWidth
|
|
595 |
] ifFalse:[
|
|
596 |
max := 0.
|
|
597 |
list notNil ifTrue:[
|
|
598 |
max := max max:(font widthOf:list)
|
|
599 |
].
|
|
600 |
].
|
|
601 |
^ max + (leftMargin * 2)
|
51
|
602 |
]
|
0
|
603 |
!
|
|
604 |
|
|
605 |
yOriginOfContents
|
|
606 |
"return the vertical origin of the contents in pixels
|
|
607 |
- used for scrollbar interface"
|
|
608 |
|
|
609 |
^ (firstLineShown - 1) * fontHeight
|
|
610 |
!
|
|
611 |
|
|
612 |
xOriginOfContents
|
|
613 |
"return the horizontal origin of the contents in pixels
|
|
614 |
- used for scrollbar interface"
|
|
615 |
|
38
|
616 |
^ leftOffset
|
0
|
617 |
!
|
|
618 |
|
|
619 |
leftIndentOfLine:lineNr
|
7
|
620 |
"return the number of spaces at the left in line, lineNr.
|
|
621 |
returns 0 for empty lines."
|
0
|
622 |
|
|
623 |
|lineString index end|
|
|
624 |
|
|
625 |
lineString := self listAt:lineNr.
|
7
|
626 |
lineString notNil ifTrue:[
|
59
|
627 |
index := 1.
|
|
628 |
end := lineString size.
|
|
629 |
[index <= end] whileTrue:[
|
|
630 |
(lineString at:index) isSeparator ifFalse:[^ index - 1].
|
|
631 |
index := index + 1
|
|
632 |
]
|
0
|
633 |
].
|
|
634 |
^ 0
|
|
635 |
! !
|
|
636 |
|
|
637 |
!ListView methodsFor:'private'!
|
|
638 |
|
|
639 |
getFontParameters
|
|
640 |
"get some info of the used font. They are cached since we use them often .."
|
|
641 |
|
|
642 |
font := font on:device.
|
|
643 |
normalFont := font.
|
|
644 |
fontHeight := font height + lineSpacing.
|
|
645 |
fontAscent := font ascent.
|
|
646 |
fontWidth := font width.
|
|
647 |
fontIsFixedWidth := font isFixedWidth.
|
|
648 |
!
|
|
649 |
|
|
650 |
checkForExistingLine:lineNr
|
|
651 |
"check if a line for lineNr exists; if not, expand text"
|
|
652 |
|
|
653 |
list isNil ifTrue: [
|
59
|
654 |
list := Text new:lineNr.
|
|
655 |
self contentsChanged
|
0
|
656 |
] ifFalse: [
|
59
|
657 |
lineNr > (list size) ifTrue:[
|
|
658 |
list grow:lineNr.
|
|
659 |
self contentsChanged
|
|
660 |
]
|
0
|
661 |
]
|
|
662 |
!
|
|
663 |
|
|
664 |
getBoldFont
|
|
665 |
"get a bold-font corresponding to font"
|
|
666 |
|
|
667 |
font style notNil ifTrue:[
|
59
|
668 |
boldFont := Font family:(font family) face:'bold'
|
|
669 |
style:'roman' size:(font size)
|
0
|
670 |
].
|
|
671 |
boldFont isNil ifTrue:[
|
59
|
672 |
boldFont := font
|
0
|
673 |
]
|
|
674 |
!
|
|
675 |
|
|
676 |
getItalicFont
|
|
677 |
"get an italic-font corresponding to font"
|
|
678 |
|
|
679 |
font style notNil ifTrue:[
|
59
|
680 |
italicFont := Font family:(font family) face:'medium'
|
|
681 |
style:'oblique' size:(font size)
|
0
|
682 |
].
|
|
683 |
italicFont isNil ifTrue:[
|
59
|
684 |
italicFont := font
|
0
|
685 |
]
|
|
686 |
!
|
|
687 |
|
|
688 |
convertRTF:aList
|
|
689 |
"this is a q&d RTF to poor-text converter which removes any rich stuff.
|
|
690 |
- a first shot 'til DocumentView is finished ..."
|
|
691 |
|
|
692 |
|newList newLine charIndex inEscape char special|
|
|
693 |
|
|
694 |
newList := Text new:200.
|
|
695 |
newList grow:0.
|
|
696 |
|
|
697 |
newLine := ''.
|
|
698 |
aList do:[:line |
|
59
|
699 |
((line size == 0) or:[line isBlank]) ifTrue:[
|
|
700 |
newList add:newLine.
|
|
701 |
newLine := ''
|
|
702 |
] ifFalse:[
|
|
703 |
special := ((line at:1) == ${) or:[(line includes:$\)].
|
|
704 |
special := special or:[(line at:1) == $}].
|
|
705 |
special ifFalse:[
|
|
706 |
newList add:(newLine , line)
|
|
707 |
] ifTrue:[
|
|
708 |
charIndex := 1.
|
|
709 |
[charIndex <= line size] whileTrue:[
|
|
710 |
char := line at:charIndex.
|
|
711 |
((char == ${ ) or:[char == $} ]) ifTrue:[
|
|
712 |
"left-brace: ignore rest of line"
|
|
713 |
charIndex := line size + 1
|
|
714 |
] ifFalse:[
|
|
715 |
(char == $\) ifTrue:[
|
|
716 |
inEscape := true
|
|
717 |
] ifFalse:[
|
|
718 |
inEscape ifTrue:[
|
|
719 |
(char == Character space) ifTrue:[
|
|
720 |
inEscape := false
|
|
721 |
]
|
|
722 |
] ifFalse:[
|
|
723 |
newLine := newLine copyWith:char
|
|
724 |
]
|
|
725 |
].
|
|
726 |
charIndex := charIndex + 1
|
|
727 |
]
|
|
728 |
]
|
|
729 |
]
|
|
730 |
]
|
0
|
731 |
].
|
|
732 |
^ newList
|
|
733 |
!
|
|
734 |
|
|
735 |
computeNumberOfLinesShown
|
|
736 |
"recompute the number of visible lines"
|
|
737 |
|
|
738 |
nFullLinesShown := self innerHeight // fontHeight.
|
|
739 |
nLinesShown := nFullLinesShown.
|
|
740 |
|
|
741 |
partialLines ifTrue:[
|
59
|
742 |
((nLinesShown * fontHeight) == height) ifFalse:[
|
|
743 |
nLinesShown := nLinesShown + 1
|
|
744 |
]
|
0
|
745 |
]
|
|
746 |
!
|
|
747 |
|
|
748 |
widthOfWidestLineBetween:firstLine and:lastLine
|
38
|
749 |
"return the width in pixels of the widest line in a range
|
|
750 |
- used to optimize scrolling, by limiting the scrolled area"
|
0
|
751 |
|
|
752 |
|max "{ Class: SmallInteger }"
|
|
753 |
first "{ Class: SmallInteger }"
|
|
754 |
last "{ Class: SmallInteger }"
|
|
755 |
thisLen "{ Class: SmallInteger }"
|
|
756 |
listSize "{ Class: SmallInteger }" |
|
|
757 |
|
51
|
758 |
includesNonStrings ifTrue:[
|
59
|
759 |
^ width
|
51
|
760 |
].
|
|
761 |
|
0
|
762 |
fontIsFixedWidth ifTrue:[
|
59
|
763 |
^ (self lengthOfLongestLineBetween:firstLine and:lastLine) * fontWidth
|
0
|
764 |
].
|
|
765 |
listSize := list size.
|
|
766 |
max := 0.
|
|
767 |
first := firstLine.
|
|
768 |
last := lastLine.
|
|
769 |
|
|
770 |
(first > listSize) ifTrue:[^ max].
|
|
771 |
(last > listSize) ifTrue:[
|
59
|
772 |
last := listSize
|
0
|
773 |
].
|
|
774 |
|
|
775 |
list from:first to:last do:[:line |
|
59
|
776 |
line notNil ifTrue:[
|
|
777 |
thisLen := font widthOf:line.
|
|
778 |
(thisLen > max) ifTrue:[
|
|
779 |
max := thisLen
|
|
780 |
]
|
|
781 |
]
|
0
|
782 |
].
|
|
783 |
^ max
|
|
784 |
!
|
|
785 |
|
|
786 |
widthForScrollBetween:firstLine and:lastLine
|
38
|
787 |
"return the width in pixels for a scroll between firstLine and lastLine.
|
|
788 |
- used to optimize scrolling, by limiting the scrolled area.
|
|
789 |
Subclasses with selections or other additional visible stuff should redefine
|
|
790 |
this method."
|
0
|
791 |
|
|
792 |
|w|
|
|
793 |
|
|
794 |
"for small width, its not worth searching for
|
59
|
795 |
longest line ...
|
|
796 |
"
|
0
|
797 |
(width < 300) ifTrue:[^ innerWidth].
|
|
798 |
|
59
|
799 |
"for large lists, search may take longer than scrolling full
|
|
800 |
"
|
|
801 |
list size > 2000 ifTrue:[^ innerWidth].
|
38
|
802 |
|
59
|
803 |
"
|
|
804 |
if there is a pattern-background, we have to scroll everything
|
|
805 |
"
|
|
806 |
(viewBackground isColor not
|
|
807 |
or:[viewBackground colorId notNil]) ifTrue:[
|
|
808 |
^ width
|
|
809 |
].
|
38
|
810 |
|
|
811 |
w := self widthOfWidestLineBetween:firstLine and:lastLine.
|
0
|
812 |
(w > innerWidth) ifTrue:[^ innerWidth].
|
|
813 |
^ w
|
|
814 |
!
|
|
815 |
|
|
816 |
listAt:lineNr
|
3
|
817 |
"given a lineNumber, return the corresponding string"
|
0
|
818 |
|
|
819 |
list isNil ifTrue:[^ nil].
|
|
820 |
(lineNr between:1 and:list size) ifFalse:[^ nil].
|
|
821 |
^ list at:lineNr
|
|
822 |
!
|
|
823 |
|
|
824 |
listAt:lineNr from:startCol to:endCol
|
3
|
825 |
"return substring from startCol to endCol of a line"
|
0
|
826 |
|
|
827 |
|line stop lineLen|
|
|
828 |
|
|
829 |
line := self listAt:lineNr.
|
|
830 |
line isNil ifTrue:[^ nil].
|
|
831 |
lineLen := line size.
|
|
832 |
(startCol > lineLen) ifTrue:[^ nil].
|
|
833 |
stop := endCol.
|
|
834 |
(stop > lineLen) ifTrue:[stop := lineLen].
|
|
835 |
^ line copyFrom:startCol to:stop
|
|
836 |
!
|
|
837 |
|
|
838 |
listAt:lineNr from:startCol
|
3
|
839 |
"return right substring from startCol to end of a line"
|
0
|
840 |
|
|
841 |
|line|
|
|
842 |
|
|
843 |
line := self listAt:lineNr.
|
|
844 |
line isNil ifTrue:[^ nil].
|
|
845 |
(startCol > line size) ifTrue:[^ nil].
|
38
|
846 |
^ line copyFrom:startCol
|
0
|
847 |
!
|
|
848 |
|
|
849 |
listAt:lineNr to:endCol
|
3
|
850 |
"return left substring from start to endCol of a line"
|
0
|
851 |
|
|
852 |
|line stop|
|
|
853 |
|
|
854 |
line := self listAt:lineNr.
|
|
855 |
line isNil ifTrue:[^ nil].
|
|
856 |
stop := endCol.
|
|
857 |
(stop > line size) ifTrue:[stop := line size].
|
38
|
858 |
^ line copyTo:stop
|
0
|
859 |
!
|
|
860 |
|
|
861 |
listLineToVisibleLine:listLineNr
|
|
862 |
"given a list line (1..) return visible linenr or nil"
|
|
863 |
|
|
864 |
|visibleLineNr "{ Class: SmallInteger }"|
|
|
865 |
|
|
866 |
shown ifFalse:[^ nil].
|
|
867 |
listLineNr isNil ifTrue:[^ nil].
|
|
868 |
visibleLineNr := listLineNr + 1 - firstLineShown.
|
|
869 |
(visibleLineNr between:1 and:nLinesShown) ifFalse:[^ nil].
|
|
870 |
^ visibleLineNr
|
|
871 |
!
|
|
872 |
|
|
873 |
visibleLineToListLine:visibleLineNr
|
|
874 |
"given a visible line (1..) return linenr in list or nil
|
|
875 |
(this one returns nil if the given visibleLineNr is one of the
|
|
876 |
separators)"
|
|
877 |
|
|
878 |
|listLineNr "{ Class: SmallInteger }"
|
|
879 |
listsize "{ Class: SmallInteger }" |
|
|
880 |
|
|
881 |
visibleLineNr isNil ifTrue:[^ nil].
|
|
882 |
listLineNr := visibleLineNr + firstLineShown - 1.
|
|
883 |
(listLineNr == 0) ifTrue:[^nil].
|
|
884 |
listsize := list size.
|
|
885 |
(listLineNr <= listsize) ifTrue:[^ listLineNr].
|
|
886 |
^ nil
|
|
887 |
!
|
|
888 |
|
|
889 |
absoluteLineToVisibleLine:absLineNr
|
|
890 |
"given an absolute line (1..) return visible linenr or nil"
|
|
891 |
|
|
892 |
absLineNr isNil ifTrue:[^ nil].
|
|
893 |
(absLineNr < firstLineShown) ifTrue:[^ nil].
|
|
894 |
(absLineNr >= (firstLineShown + nLinesShown)) ifTrue:[^ nil].
|
|
895 |
^ absLineNr - firstLineShown + 1
|
|
896 |
!
|
|
897 |
|
|
898 |
visibleLineToAbsoluteLine:visibleLineNr
|
|
899 |
"given a visible line (1..) return absolut linenr"
|
|
900 |
|
|
901 |
visibleLineNr isNil ifTrue:[^ nil].
|
|
902 |
^ visibleLineNr + firstLineShown - 1
|
|
903 |
!
|
|
904 |
|
59
|
905 |
yOfVisibleLine:visLineNr
|
0
|
906 |
"given a visible lineNr, return y-coordinate in view
|
|
907 |
- works for fix-height fonts only"
|
|
908 |
|
|
909 |
^ ((visLineNr - 1) * fontHeight) + textStartTop
|
|
910 |
!
|
|
911 |
|
59
|
912 |
xOfCol:col inVisibleLine:visLineNr
|
0
|
913 |
"given a visible line- and colNr, return x-coordinate in view"
|
|
914 |
|
|
915 |
|line lineSize tcol|
|
|
916 |
|
|
917 |
tcol := col - 1.
|
|
918 |
fontIsFixedWidth ifTrue:[
|
59
|
919 |
^ (tcol * fontWidth) + textStartLeft
|
0
|
920 |
].
|
|
921 |
line := self visibleAt:visLineNr.
|
|
922 |
line notNil ifTrue:[
|
59
|
923 |
lineSize := line size
|
0
|
924 |
] ifFalse:[
|
59
|
925 |
lineSize := 0
|
0
|
926 |
].
|
|
927 |
(lineSize == 0) ifTrue:[
|
59
|
928 |
^ (tcol * fontWidth) + textStartLeft
|
0
|
929 |
].
|
|
930 |
(lineSize < col) ifTrue:[
|
59
|
931 |
^ (font widthOf:line)
|
|
932 |
+ (fontWidth * (tcol - lineSize))
|
|
933 |
+ textStartLeft
|
0
|
934 |
].
|
|
935 |
^ (font widthOf:line from:1 to:tcol) + textStartLeft
|
|
936 |
!
|
|
937 |
|
|
938 |
colOfX:x inVisibleLine:visLineNr
|
|
939 |
"given a visible lineNr and x-coordinate, return colNr"
|
|
940 |
|
|
941 |
|lineString linePixelWidth xRel runCol posLeft posRight done|
|
|
942 |
|
38
|
943 |
xRel := x - textStartLeft + leftOffset.
|
0
|
944 |
fontIsFixedWidth ifTrue:[
|
59
|
945 |
^ (xRel // fontWidth) + 1
|
0
|
946 |
].
|
|
947 |
lineString := self visibleAt:visLineNr.
|
|
948 |
lineString notNil ifTrue:[
|
59
|
949 |
linePixelWidth := font widthOf:lineString
|
0
|
950 |
] ifFalse:[
|
59
|
951 |
linePixelWidth := 0
|
0
|
952 |
].
|
|
953 |
(xRel <= 0) ifTrue:[^ 1].
|
|
954 |
(linePixelWidth <= xRel) ifTrue:[
|
59
|
955 |
^ lineString size + ((xRel - linePixelWidth) // fontWidth) + 1
|
0
|
956 |
].
|
|
957 |
runCol := lineString size // 2.
|
|
958 |
(runCol == 0) ifTrue:[runCol := 1].
|
|
959 |
posLeft := font widthOf:lineString from:1 to:(runCol - 1).
|
|
960 |
posRight := font widthOf:lineString from:1 to:runCol.
|
|
961 |
done := (posLeft <= xRel) and:[posRight > xRel].
|
|
962 |
[done] whileFalse:[
|
59
|
963 |
(posRight <= xRel) ifTrue:[
|
|
964 |
runCol := runCol + 1.
|
|
965 |
posLeft := posRight.
|
|
966 |
posRight := font widthOf:lineString from:1 to:runCol
|
|
967 |
] ifFalse:[
|
|
968 |
(posLeft > xRel) ifTrue:[
|
|
969 |
runCol := runCol - 1.
|
|
970 |
(runCol == 0) ifTrue:[^ 0].
|
|
971 |
posRight := posLeft.
|
|
972 |
posLeft := font widthOf:lineString from:1 to:(runCol - 1)
|
|
973 |
]
|
|
974 |
].
|
|
975 |
done := (posLeft <= xRel) and:[posRight > xRel]
|
0
|
976 |
].
|
|
977 |
^ runCol
|
|
978 |
!
|
|
979 |
|
|
980 |
visibleLineOfY:y
|
|
981 |
"given a y-coordinate, return lineNr
|
|
982 |
- works for fix-height fonts only"
|
|
983 |
|
|
984 |
^ ((y - textStartTop) // fontHeight) + 1
|
|
985 |
!
|
|
986 |
|
3
|
987 |
visibleAttributeAt:visibleLineNr
|
|
988 |
"return the attributes of what is visible at line (numbers start at 1)"
|
0
|
989 |
|
|
990 |
|listLineNr listsize|
|
|
991 |
|
|
992 |
listLineNr := visibleLineNr + firstLineShown - 1.
|
|
993 |
(listLineNr == 0) ifTrue:[^ nil].
|
|
994 |
(attributes notNil) ifTrue:[
|
59
|
995 |
listsize := attributes size
|
0
|
996 |
] ifFalse:[
|
59
|
997 |
listsize := 0
|
0
|
998 |
].
|
|
999 |
(listLineNr <= listsize) ifTrue:[^ attributes at:listLineNr].
|
|
1000 |
^ nil
|
|
1001 |
!
|
|
1002 |
|
|
1003 |
visibleAt:visibleLineNr
|
3
|
1004 |
"return what is visible at line (numbers start at 1)"
|
0
|
1005 |
|
|
1006 |
|listLineNr listsize|
|
|
1007 |
|
|
1008 |
listLineNr := visibleLineNr + firstLineShown - 1.
|
|
1009 |
(listLineNr == 0) ifTrue:[^ nil].
|
|
1010 |
(list notNil) ifTrue:[
|
59
|
1011 |
listsize := list size
|
0
|
1012 |
] ifFalse:[
|
59
|
1013 |
listsize := 0
|
0
|
1014 |
].
|
|
1015 |
(listLineNr <= listsize) ifTrue:[^ list at:listLineNr].
|
|
1016 |
^ ''
|
|
1017 |
!
|
|
1018 |
|
|
1019 |
lineOfCharacterPosition:charPos
|
|
1020 |
"given a character index within the contents-string,
|
|
1021 |
return the lineNumber where the character is
|
|
1022 |
- used to find line to hilight from Compilers error-position"
|
|
1023 |
|
|
1024 |
|lineNr sum lastLine|
|
|
1025 |
|
|
1026 |
lineNr := 1.
|
|
1027 |
sum := 0.
|
|
1028 |
lastLine := list size.
|
|
1029 |
[sum < charPos] whileTrue:[
|
59
|
1030 |
(lineNr > lastLine) ifTrue:[^ lineNr - 1].
|
|
1031 |
sum := sum + (list at:lineNr) size + 1.
|
|
1032 |
lineNr := lineNr + 1
|
0
|
1033 |
].
|
|
1034 |
^ lineNr - 1
|
|
1035 |
!
|
|
1036 |
|
|
1037 |
characterPositionOfLine:lineNr col:col
|
|
1038 |
"given a line/col position, return the character index within the contents-string,
|
|
1039 |
- used with Compilers error-positioning"
|
|
1040 |
|
|
1041 |
|lineString pos|
|
|
1042 |
|
|
1043 |
pos := 1.
|
|
1044 |
1 to:(lineNr - 1) do:[:lnr |
|
59
|
1045 |
lineString := list at:lnr.
|
|
1046 |
lineString notNil ifTrue:[
|
|
1047 |
pos := pos + lineString size
|
|
1048 |
].
|
|
1049 |
pos := pos + 1 "the return-character"
|
0
|
1050 |
].
|
|
1051 |
^ pos + col - 1
|
|
1052 |
! !
|
|
1053 |
|
7
|
1054 |
!ListView methodsFor:'tabulators'!
|
|
1055 |
|
|
1056 |
setTab4
|
38
|
1057 |
"set 4-character tab stops"
|
|
1058 |
|
7
|
1059 |
tabPositions := self class tab4Positions.
|
|
1060 |
!
|
|
1061 |
|
|
1062 |
setTab8
|
38
|
1063 |
"set 8-character tab stops"
|
|
1064 |
|
7
|
1065 |
tabPositions := self class tab8Positions.
|
|
1066 |
!
|
|
1067 |
|
|
1068 |
expandTabs
|
|
1069 |
"go through whole text expanding tabs into spaces"
|
|
1070 |
|
|
1071 |
|line newLine nLines "{ Class: SmallInteger }"|
|
|
1072 |
|
|
1073 |
list notNil ifTrue:[
|
59
|
1074 |
nLines := list size.
|
|
1075 |
1 to:nLines do:[:index |
|
|
1076 |
line := list at:index.
|
|
1077 |
line notNil ifTrue:[
|
|
1078 |
line isString ifFalse:[
|
|
1079 |
newLine := line printString
|
|
1080 |
] ifTrue:[
|
|
1081 |
newLine := line
|
|
1082 |
].
|
|
1083 |
(newLine occurrencesOf:(Character tab)) == 0 ifFalse:[
|
|
1084 |
newLine := self withTabsExpanded:newLine
|
|
1085 |
].
|
|
1086 |
(newLine ~~ line) ifTrue:[
|
|
1087 |
list at:index put:newLine
|
|
1088 |
]
|
|
1089 |
]
|
|
1090 |
]
|
7
|
1091 |
]
|
|
1092 |
!
|
|
1093 |
|
|
1094 |
nextTabAfter:colNr
|
|
1095 |
"return the next tab position after col"
|
|
1096 |
|
|
1097 |
|col "{ Class: SmallInteger }"
|
|
1098 |
tabIndex "{ Class: SmallInteger }"
|
|
1099 |
thisTab "{ Class: SmallInteger }"
|
|
1100 |
nTabs "{ Class: SmallInteger }" |
|
|
1101 |
|
|
1102 |
tabIndex := 1.
|
|
1103 |
col := colNr.
|
|
1104 |
thisTab := tabPositions at:tabIndex.
|
|
1105 |
nTabs := tabPositions size.
|
|
1106 |
[thisTab <= col] whileTrue:[
|
59
|
1107 |
(tabIndex == nTabs) ifTrue:[^ thisTab].
|
|
1108 |
tabIndex := tabIndex + 1.
|
|
1109 |
thisTab := tabPositions at:tabIndex
|
7
|
1110 |
].
|
|
1111 |
^ thisTab
|
|
1112 |
!
|
|
1113 |
|
|
1114 |
prevTabBefore:colNr
|
|
1115 |
"return the prev tab position before col"
|
|
1116 |
|
|
1117 |
|col "{ Class: SmallInteger }"
|
|
1118 |
tabIndex "{ Class: SmallInteger }"
|
|
1119 |
thisTab "{ Class: SmallInteger }"
|
|
1120 |
nTabs "{ Class: SmallInteger }" |
|
|
1121 |
|
|
1122 |
tabIndex := 1.
|
|
1123 |
col := colNr.
|
|
1124 |
thisTab := tabPositions at:tabIndex.
|
|
1125 |
nTabs := tabPositions size.
|
|
1126 |
[thisTab < col] whileTrue:[
|
59
|
1127 |
(tabIndex == nTabs) ifTrue:[^ thisTab].
|
|
1128 |
tabIndex := tabIndex + 1.
|
|
1129 |
thisTab := tabPositions at:tabIndex
|
7
|
1130 |
].
|
|
1131 |
(tabIndex == 1) ifTrue:[
|
59
|
1132 |
^ 1
|
7
|
1133 |
].
|
|
1134 |
^ tabPositions at:(tabIndex - 1)
|
|
1135 |
!
|
|
1136 |
|
|
1137 |
withTabsExpanded:line
|
38
|
1138 |
"expand tabs into spaces, return a new line string,
|
|
1139 |
or original line, if no tabs are included.
|
|
1140 |
good idea, to make this one a primitive"
|
7
|
1141 |
|
38
|
1142 |
|tmpString nString nTabs
|
7
|
1143 |
currentMax "{ Class: SmallInteger }"
|
|
1144 |
dstIndex "{ Class: SmallInteger }"
|
|
1145 |
nextTab "{ Class: SmallInteger }" |
|
|
1146 |
|
38
|
1147 |
line isNil ifTrue:[^ line].
|
|
1148 |
nTabs := line occurrencesOf:(Character tab).
|
|
1149 |
nTabs == 0 ifTrue:[^ line].
|
|
1150 |
|
60
|
1151 |
currentMax := line size + (nTabs * 7).
|
7
|
1152 |
tmpString := String new:currentMax.
|
|
1153 |
dstIndex := 1.
|
|
1154 |
line do:[:character |
|
59
|
1155 |
(character == (Character tab)) ifTrue:[
|
|
1156 |
nextTab := self nextTabAfter:dstIndex.
|
|
1157 |
[dstIndex < nextTab] whileTrue:[
|
|
1158 |
tmpString at:dstIndex put:(Character space).
|
|
1159 |
dstIndex := dstIndex + 1
|
|
1160 |
]
|
|
1161 |
] ifFalse:[
|
|
1162 |
tmpString at:dstIndex put:character.
|
|
1163 |
dstIndex := dstIndex + 1
|
|
1164 |
].
|
|
1165 |
(dstIndex > currentMax) ifTrue:[
|
60
|
1166 |
"
|
|
1167 |
this cannot happen with <= 8 tabs
|
|
1168 |
"
|
59
|
1169 |
currentMax := currentMax + currentMax.
|
|
1170 |
nString := String new:currentMax.
|
|
1171 |
nString replaceFrom:1 to:(dstIndex - 1)
|
|
1172 |
with:tmpString startingAt:1.
|
|
1173 |
tmpString := nString.
|
|
1174 |
nString := nil
|
|
1175 |
].
|
7
|
1176 |
|
59
|
1177 |
"make stc-optimizer happy
|
|
1178 |
- no need to return value of ifTrue:/ifFalse above"
|
|
1179 |
0
|
7
|
1180 |
].
|
60
|
1181 |
dstIndex := dstIndex - 1.
|
|
1182 |
dstIndex == currentMax ifTrue:[
|
|
1183 |
^ tmpString
|
|
1184 |
].
|
|
1185 |
^ tmpString copyTo:dstIndex
|
38
|
1186 |
!
|
|
1187 |
|
|
1188 |
withTabs:line
|
|
1189 |
"Assuming an 8-character tab,
|
|
1190 |
compress multiple spaces to tabs, return a new line string
|
|
1191 |
or original line, if no tabs where created.
|
|
1192 |
good idea, to make this one a primitive"
|
|
1193 |
|
|
1194 |
|newLine|
|
|
1195 |
|
|
1196 |
line isNil ifTrue:[^ line].
|
|
1197 |
(line startsWith:' ') ifFalse:[^ line].
|
|
1198 |
|
|
1199 |
newLine := line copyFrom:9.
|
|
1200 |
[newLine startsWith:' '] whileTrue:[
|
59
|
1201 |
newLine := Character tab asString , (newLine copyFrom:9)
|
38
|
1202 |
].
|
|
1203 |
^ newLine
|
7
|
1204 |
! !
|
|
1205 |
|
0
|
1206 |
!ListView methodsFor:'searching'!
|
|
1207 |
|
|
1208 |
setSearchPattern:aString
|
|
1209 |
"set the searchpattern"
|
|
1210 |
|
|
1211 |
searchPattern := aString withoutSeparators
|
|
1212 |
!
|
|
1213 |
|
|
1214 |
searchForwardFor:pattern startingAtLine:startLine col:startCol ifFound:block1 else:block2
|
|
1215 |
"search for a pattern, if found evaluate block1 with row/col as arguments, if not
|
38
|
1216 |
found evaluate block2.
|
|
1217 |
Sorry, but pattern is no regular expression pattern (yet)"
|
0
|
1218 |
|
59
|
1219 |
|lineString col savedCursor patternSize
|
|
1220 |
line1 "{Class: SmallInteger}"
|
|
1221 |
line2 "{Class: SmallInteger}"|
|
0
|
1222 |
|
|
1223 |
patternSize := pattern size.
|
59
|
1224 |
(list notNil and:[patternSize ~~ 0]) ifTrue:[
|
|
1225 |
savedCursor := cursor.
|
|
1226 |
self cursor:(Cursor questionMark).
|
|
1227 |
searchPattern := pattern.
|
|
1228 |
col := startCol + 1.
|
|
1229 |
line1 := startLine.
|
|
1230 |
line2 := list size.
|
|
1231 |
line1 to:line2 do:[:lnr |
|
|
1232 |
lineString := list at:lnr.
|
|
1233 |
lineString notNil ifTrue:[
|
|
1234 |
col := lineString findString:pattern startingAt:col ifAbsent:[0].
|
|
1235 |
col ~~ 0 ifTrue:[
|
|
1236 |
self cursor:savedCursor.
|
|
1237 |
^ block1 value:lnr value:col.
|
|
1238 |
]
|
|
1239 |
].
|
|
1240 |
col := 1
|
|
1241 |
]
|
0
|
1242 |
].
|
|
1243 |
"not found"
|
|
1244 |
|
|
1245 |
self cursor:savedCursor.
|
|
1246 |
^ block2 value
|
|
1247 |
!
|
|
1248 |
|
|
1249 |
searchBackwardFor:pattern startingAtLine:startLine col:startCol ifFound:block1 else:block2
|
|
1250 |
"search for a pattern, if found evaluate block1 with row/col as arguments, if not
|
38
|
1251 |
found evaluate block2.
|
|
1252 |
Sorry, but pattern is no regular expression pattern (yet)"
|
0
|
1253 |
|
59
|
1254 |
|lineString col cc found firstChar savedCursor patternSize
|
|
1255 |
line1 "{Class: SmallInteger}"|
|
0
|
1256 |
|
|
1257 |
patternSize := pattern size.
|
59
|
1258 |
(list notNil and:[patternSize ~~ 0]) ifTrue:[
|
|
1259 |
savedCursor := cursor.
|
|
1260 |
self cursor:(Cursor questionMark).
|
|
1261 |
searchPattern := pattern.
|
|
1262 |
col := startCol - 1.
|
|
1263 |
firstChar := pattern at:1.
|
|
1264 |
col > (list at:startLine) size ifTrue:[
|
|
1265 |
col := nil
|
|
1266 |
].
|
|
1267 |
line1 := startLine.
|
|
1268 |
line1 to:1 by:-1 do:[:lnr |
|
|
1269 |
lineString := list at:lnr.
|
|
1270 |
lineString notNil ifTrue:[
|
|
1271 |
col isNil ifTrue:[col := lineString size - patternSize + 1].
|
|
1272 |
[(col > 0) and:[(lineString at:col) ~~ firstChar]] whileTrue:[
|
|
1273 |
col := col - 1
|
|
1274 |
].
|
|
1275 |
[col > 0] whileTrue:[
|
|
1276 |
cc := col.
|
|
1277 |
found := true.
|
|
1278 |
1 to:patternSize do:[:cnr |
|
|
1279 |
cc > lineString size ifTrue:[
|
|
1280 |
found := false
|
|
1281 |
] ifFalse:[
|
|
1282 |
(pattern at:cnr) ~~ (lineString at:cc) ifTrue:[
|
|
1283 |
found := false
|
|
1284 |
]
|
|
1285 |
].
|
|
1286 |
cc := cc + 1
|
|
1287 |
].
|
|
1288 |
found ifTrue:[
|
|
1289 |
self cursor:savedCursor.
|
|
1290 |
^ block1 value:lnr value:col.
|
|
1291 |
].
|
|
1292 |
col := col - 1.
|
|
1293 |
[(col > 0) and:[(lineString at:col) ~~ firstChar]] whileTrue:[
|
|
1294 |
col := col - 1
|
|
1295 |
]
|
|
1296 |
]
|
|
1297 |
].
|
|
1298 |
col := nil
|
|
1299 |
]
|
0
|
1300 |
].
|
|
1301 |
"not found"
|
|
1302 |
|
|
1303 |
self cursor:savedCursor.
|
|
1304 |
^ block2 value
|
38
|
1305 |
!
|
|
1306 |
|
|
1307 |
findBeginOfWordAtLine:selectLine col:selectCol
|
|
1308 |
"return the col of first character of the word at given line/col.
|
|
1309 |
If the character under the initial col is a space character, return
|
|
1310 |
the first col of the blank-block."
|
|
1311 |
|
|
1312 |
|beginCol thisCharacter|
|
|
1313 |
|
|
1314 |
beginCol := selectCol.
|
|
1315 |
thisCharacter := self characterAtLine:selectLine col:beginCol.
|
|
1316 |
|
|
1317 |
"is this acharacter within a word ?"
|
|
1318 |
(wordCheck value:thisCharacter) ifTrue:[
|
59
|
1319 |
[wordCheck value:thisCharacter] whileTrue:[
|
|
1320 |
beginCol := beginCol - 1.
|
|
1321 |
beginCol < 1 ifTrue:[
|
|
1322 |
thisCharacter := Character space
|
|
1323 |
] ifFalse:[
|
|
1324 |
thisCharacter := self characterAtLine:selectLine col:beginCol
|
|
1325 |
]
|
|
1326 |
].
|
|
1327 |
beginCol := beginCol + 1.
|
38
|
1328 |
] ifFalse:[
|
59
|
1329 |
"nope - maybe its a space"
|
|
1330 |
thisCharacter == Character space ifTrue:[
|
|
1331 |
[beginCol > 1 and:[thisCharacter == Character space]] whileTrue:[
|
|
1332 |
beginCol := beginCol - 1.
|
|
1333 |
thisCharacter := self characterAtLine:selectLine col:beginCol
|
|
1334 |
].
|
|
1335 |
thisCharacter ~~ Character space ifTrue:[
|
|
1336 |
beginCol := beginCol + 1.
|
|
1337 |
].
|
|
1338 |
] ifFalse:[
|
|
1339 |
"select single character"
|
|
1340 |
]
|
38
|
1341 |
].
|
|
1342 |
^ beginCol
|
|
1343 |
!
|
|
1344 |
|
|
1345 |
findEndOfWordAtLine:selectLine col:selectCol
|
|
1346 |
"return the col of last character of the word at given line/col.
|
|
1347 |
If the character under the initial col is a space character, return
|
|
1348 |
the last col of the blank-block.
|
|
1349 |
Return 0 if we should wrap to next line (for spaces)"
|
|
1350 |
|
|
1351 |
|endCol thisCharacter len|
|
|
1352 |
|
|
1353 |
endCol := selectCol.
|
|
1354 |
endCol == 0 ifTrue:[endCol := 1].
|
|
1355 |
thisCharacter := self characterAtLine:selectLine col:endCol.
|
|
1356 |
|
|
1357 |
"is this acharacter within a word ?"
|
|
1358 |
(wordCheck value:thisCharacter) ifTrue:[
|
59
|
1359 |
thisCharacter := self characterAtLine:selectLine col:endCol.
|
|
1360 |
[wordCheck value:thisCharacter] whileTrue:[
|
|
1361 |
endCol := endCol + 1.
|
|
1362 |
thisCharacter := self characterAtLine:selectLine col:endCol
|
|
1363 |
].
|
|
1364 |
endCol := endCol - 1.
|
38
|
1365 |
] ifFalse:[
|
59
|
1366 |
"nope - maybe its a space"
|
|
1367 |
thisCharacter == Character space ifTrue:[
|
|
1368 |
len := (self listAt:selectLine) size.
|
|
1369 |
endCol > len ifTrue:[
|
|
1370 |
"select rest to end"
|
|
1371 |
endCol := 0
|
|
1372 |
] ifFalse:[
|
|
1373 |
thisCharacter := self characterAtLine:selectLine col:endCol.
|
|
1374 |
[endCol <= len and:[thisCharacter == Character space]] whileTrue:[
|
|
1375 |
endCol := endCol + 1.
|
|
1376 |
thisCharacter := self characterAtLine:selectLine col:endCol
|
|
1377 |
].
|
|
1378 |
endCol := endCol - 1.
|
|
1379 |
]
|
|
1380 |
] ifFalse:[
|
|
1381 |
"select single character"
|
|
1382 |
]
|
38
|
1383 |
].
|
|
1384 |
^ endCol.
|
0
|
1385 |
! !
|
|
1386 |
|
|
1387 |
!ListView methodsFor:'scrolling'!
|
|
1388 |
|
|
1389 |
gotoLine:aLineNumber
|
|
1390 |
"position to line aLineNumber; this may be redefined
|
|
1391 |
in subclasses (for example to move the cursor also)"
|
|
1392 |
|
|
1393 |
^ self scrollToLine:aLineNumber
|
|
1394 |
!
|
|
1395 |
|
|
1396 |
pageDown
|
|
1397 |
"change origin to display next page"
|
|
1398 |
|
38
|
1399 |
|nLines|
|
|
1400 |
|
|
1401 |
nLines := nFullLinesShown.
|
|
1402 |
(firstLineShown + nLines + nFullLinesShown > list size) ifTrue:[
|
59
|
1403 |
nLines := list size - firstLineShown - nFullLinesShown + 1
|
38
|
1404 |
].
|
|
1405 |
nLines <= 0 ifTrue:[^ self].
|
|
1406 |
|
0
|
1407 |
self originWillChange.
|
38
|
1408 |
firstLineShown := firstLineShown + nLines.
|
|
1409 |
self originChanged:nLines.
|
0
|
1410 |
self redrawFromVisibleLine:1 to:nLinesShown
|
|
1411 |
!
|
|
1412 |
|
|
1413 |
pageUp
|
|
1414 |
"change origin to display previous page"
|
|
1415 |
|
|
1416 |
|oldOrg|
|
|
1417 |
|
|
1418 |
(firstLineShown == 1) ifFalse:[
|
59
|
1419 |
self originWillChange.
|
|
1420 |
oldOrg := firstLineShown.
|
|
1421 |
firstLineShown := firstLineShown - nFullLinesShown.
|
|
1422 |
(firstLineShown < 1) ifTrue:[
|
|
1423 |
firstLineShown := 1
|
|
1424 |
].
|
|
1425 |
self originChanged:(firstLineShown - oldOrg).
|
|
1426 |
self redrawFromVisibleLine:1 to:nLinesShown
|
0
|
1427 |
]
|
|
1428 |
!
|
|
1429 |
|
|
1430 |
halfPageDown
|
|
1431 |
"scroll down half a page"
|
|
1432 |
|
|
1433 |
self scrollDown:(nFullLinesShown // 2)
|
|
1434 |
!
|
|
1435 |
|
|
1436 |
halfPageUp
|
|
1437 |
"scroll up half a page"
|
|
1438 |
|
|
1439 |
self scrollUp:(nFullLinesShown // 2)
|
|
1440 |
!
|
|
1441 |
|
38
|
1442 |
makeLineVisible:aListLineNr
|
|
1443 |
"if aListLineNr is not visible, scroll to make it visible.
|
|
1444 |
Numbering starts with 1 for the very first line of the text."
|
|
1445 |
|
|
1446 |
|bott|
|
|
1447 |
|
|
1448 |
(aListLineNr isNil "or:[shown not]") ifTrue:[^ self].
|
|
1449 |
|
|
1450 |
(aListLineNr >= firstLineShown) ifTrue:[
|
59
|
1451 |
(aListLineNr < (firstLineShown + nFullLinesShown)) ifTrue:[
|
|
1452 |
^ self
|
|
1453 |
]
|
38
|
1454 |
].
|
|
1455 |
(aListLineNr < nFullLinesShown) ifTrue:[
|
59
|
1456 |
^ self scrollToLine:1
|
38
|
1457 |
].
|
|
1458 |
(nFullLinesShown < 3) ifTrue:[
|
59
|
1459 |
^ self scrollToLine:aListLineNr
|
38
|
1460 |
].
|
|
1461 |
bott := self numberOfLines - (nFullLinesShown - 1).
|
|
1462 |
(aListLineNr > bott) ifTrue:[
|
59
|
1463 |
^ self scrollToLine:bott
|
38
|
1464 |
].
|
|
1465 |
self scrollToLine:(aListLineNr - (nFullLinesShown // 2) + 1)
|
|
1466 |
!
|
|
1467 |
|
|
1468 |
makeColVisible:aCol inLine:aLineNr
|
|
1469 |
"if column aCol is not visible, scroll horizontal to make it visible"
|
|
1470 |
|
|
1471 |
|xWant xVis visLnr oldLeft|
|
|
1472 |
|
|
1473 |
(aCol isNil or:[shown not]) ifTrue:[^ self].
|
|
1474 |
|
|
1475 |
visLnr := self absoluteLineToVisibleLine:aLineNr.
|
|
1476 |
visLnr isNil ifTrue:[^ self].
|
|
1477 |
|
59
|
1478 |
xWant := self xOfCol:aCol inVisibleLine:visLnr.
|
|
1479 |
xVis := xWant - leftOffset.
|
|
1480 |
|
38
|
1481 |
"
|
|
1482 |
dont scroll, if already visible
|
|
1483 |
(but scroll, if not in inner 20%..80% of visible area)
|
|
1484 |
"
|
59
|
1485 |
"/ ((xVis >= (width // 5)) and:[xVis <= (width * 4 // 5)]) ifTrue:[
|
|
1486 |
"/ ^ self
|
|
1487 |
"/ ].
|
38
|
1488 |
|
59
|
1489 |
"
|
|
1490 |
no, the above does not look good, if you click / select at the
|
|
1491 |
far right - makes selecting so difficult ...
|
|
1492 |
"
|
|
1493 |
(xVis >= 0 and:[xVis < (width - font width)]) ifTrue:[^ self].
|
38
|
1494 |
|
59
|
1495 |
"/ oldLeft := leftOffset.
|
38
|
1496 |
self scrollHorizontalTo:(xWant - (width // 2)).
|
59
|
1497 |
"/ self originChanged:((oldLeft - leftOffset) @ 0)
|
38
|
1498 |
!
|
|
1499 |
|
0
|
1500 |
scrollDown:nLines
|
|
1501 |
"change origin to scroll down some lines"
|
|
1502 |
|
|
1503 |
|w "{ Class:SmallInteger }"
|
|
1504 |
h "{ Class:SmallInteger }"
|
|
1505 |
m2 "{ Class:SmallInteger }"
|
51
|
1506 |
count "{ Class:SmallInteger }"
|
|
1507 |
prevFirst|
|
0
|
1508 |
|
|
1509 |
count := nLines.
|
|
1510 |
(firstLineShown + nLines + nFullLinesShown > list size) ifTrue:[
|
59
|
1511 |
count := list size - firstLineShown - nFullLinesShown + 1
|
0
|
1512 |
].
|
|
1513 |
count <= 0 ifTrue:[^ self].
|
|
1514 |
|
|
1515 |
self originWillChange.
|
51
|
1516 |
prevFirst := firstLineShown.
|
|
1517 |
firstLineShown := firstLineShown + count.
|
59
|
1518 |
shown ifFalse:[
|
|
1519 |
viewOrigin := viewOrigin x @ (viewOrigin y + (fontHeight * count)).
|
|
1520 |
] ifTrue:[
|
|
1521 |
(count >= nLinesShown) ifTrue:[
|
|
1522 |
viewOrigin := viewOrigin x @ (viewOrigin y + (fontHeight * count)).
|
|
1523 |
self redrawFromVisibleLine:1 to:nLinesShown.
|
|
1524 |
] ifFalse:[
|
|
1525 |
m2 := margin * 2.
|
|
1526 |
w := self widthForScrollBetween:prevFirst
|
|
1527 |
and:(prevFirst + nLinesShown).
|
|
1528 |
w := w + leftMargin.
|
0
|
1529 |
|
59
|
1530 |
h := (fontHeight * count) + textStartTop.
|
|
1531 |
self catchExpose.
|
|
1532 |
self copyFrom:self x:margin y:h
|
|
1533 |
toX:margin y:textStartTop
|
|
1534 |
width:w height:(height - m2 - h).
|
0
|
1535 |
|
59
|
1536 |
viewOrigin := viewOrigin x @ (viewOrigin y + (fontHeight * count)).
|
|
1537 |
self redrawFromVisibleLine:(nFullLinesShown - count + 1)
|
|
1538 |
to:nLinesShown.
|
|
1539 |
self waitForExpose.
|
|
1540 |
].
|
51
|
1541 |
].
|
|
1542 |
self originChanged:count.
|
0
|
1543 |
!
|
|
1544 |
|
|
1545 |
scrollDown
|
|
1546 |
"change origin to scroll down one line"
|
|
1547 |
|
|
1548 |
self scrollDown:1
|
|
1549 |
!
|
|
1550 |
|
|
1551 |
scrollUp:nLines
|
|
1552 |
"change origin to scroll up some lines"
|
|
1553 |
|
|
1554 |
|w "{ Class:SmallInteger }"
|
|
1555 |
h "{ Class:SmallInteger }"
|
51
|
1556 |
count "{ Class:SmallInteger }"
|
|
1557 |
prevFirst|
|
0
|
1558 |
|
|
1559 |
count := nLines.
|
|
1560 |
count >= firstLineShown ifTrue:[
|
59
|
1561 |
count := firstLineShown - 1
|
0
|
1562 |
].
|
|
1563 |
(count == 0) ifTrue:[^ self].
|
|
1564 |
|
|
1565 |
self originWillChange.
|
51
|
1566 |
prevFirst := firstLineShown.
|
|
1567 |
firstLineShown := firstLineShown - count.
|
59
|
1568 |
shown ifFalse:[
|
|
1569 |
viewOrigin := viewOrigin x @ (viewOrigin y - (fontHeight * count)).
|
|
1570 |
] ifTrue:[
|
|
1571 |
(count >= nLinesShown) ifTrue:[
|
|
1572 |
viewOrigin := viewOrigin x @ (viewOrigin y - (fontHeight * count)).
|
|
1573 |
self redrawFromVisibleLine:1 to:nLinesShown.
|
|
1574 |
] ifFalse:[
|
|
1575 |
w := self widthForScrollBetween:prevFirst
|
|
1576 |
and:(prevFirst + nLinesShown).
|
|
1577 |
w := w + leftMargin.
|
|
1578 |
h := (fontHeight * count) + topMargin.
|
|
1579 |
self catchExpose.
|
|
1580 |
self copyFrom:self x:margin y:topMargin
|
|
1581 |
toX:margin y:h
|
|
1582 |
width:w height:(height - h - margin).
|
|
1583 |
viewOrigin := viewOrigin x @ (viewOrigin y - (fontHeight * count)).
|
|
1584 |
self redrawFromVisibleLine:1 to:count.
|
|
1585 |
self waitForExpose.
|
|
1586 |
].
|
51
|
1587 |
].
|
|
1588 |
self originChanged:(count negated).
|
0
|
1589 |
!
|
|
1590 |
|
|
1591 |
scrollUp
|
|
1592 |
"change origin to scroll up one line"
|
|
1593 |
|
|
1594 |
self scrollUp:1
|
|
1595 |
!
|
|
1596 |
|
|
1597 |
scrollToTop
|
|
1598 |
"change origin to start of text"
|
|
1599 |
|
|
1600 |
self scrollToLine:1
|
|
1601 |
!
|
|
1602 |
|
38
|
1603 |
scrollToBottom
|
|
1604 |
"change origin to show end of text"
|
|
1605 |
|
|
1606 |
"scrolling to the end is not really correct (i.e. should scroll to list size - nFullLinesShown),
|
|
1607 |
but scrollDown: will adjust it ..."
|
|
1608 |
|
|
1609 |
self scrollToLine:(list size)
|
|
1610 |
!
|
|
1611 |
|
0
|
1612 |
scrollToLine:aLineNr
|
|
1613 |
"change origin to make aLineNr be the top line"
|
|
1614 |
|
|
1615 |
aLineNr < firstLineShown ifTrue:[
|
59
|
1616 |
self scrollUp:(firstLineShown - aLineNr)
|
0
|
1617 |
] ifFalse:[
|
59
|
1618 |
aLineNr > firstLineShown ifTrue:[
|
|
1619 |
self scrollDown:(aLineNr - firstLineShown)
|
|
1620 |
]
|
0
|
1621 |
]
|
|
1622 |
!
|
|
1623 |
|
38
|
1624 |
scrollToLeft
|
|
1625 |
"change origin to start (left) of text"
|
|
1626 |
|
|
1627 |
leftOffset ~~ 0 ifTrue:[
|
59
|
1628 |
self scrollToCol:1
|
38
|
1629 |
]
|
|
1630 |
!
|
|
1631 |
|
|
1632 |
scrollToCol:aColNr
|
|
1633 |
"change origin to make aColNr be the left col"
|
|
1634 |
|
|
1635 |
|pxlOffset|
|
|
1636 |
|
|
1637 |
aColNr == 1 ifTrue:[
|
59
|
1638 |
leftOffset ~~ 0 ifTrue:[
|
|
1639 |
self scrollLeft:leftOffset.
|
|
1640 |
].
|
|
1641 |
^ self
|
38
|
1642 |
].
|
|
1643 |
|
|
1644 |
pxlOffset := font width * (aColNr - 1).
|
|
1645 |
|
|
1646 |
pxlOffset < leftOffset ifTrue:[
|
59
|
1647 |
self scrollLeft:(leftOffset - pxlOffset)
|
38
|
1648 |
] ifFalse:[
|
59
|
1649 |
pxlOffset > leftOffset ifTrue:[
|
|
1650 |
self scrollRight:(pxlOffset - leftOffset)
|
|
1651 |
]
|
38
|
1652 |
]
|
|
1653 |
!
|
|
1654 |
|
0
|
1655 |
scrollVerticalToPercent:percent
|
|
1656 |
"scroll to a position given in percent of total"
|
|
1657 |
|
|
1658 |
|lineNr|
|
|
1659 |
|
|
1660 |
lineNr := (((self numberOfLines * percent) asFloat / 100.0) + 0.5) asInteger + 1.
|
|
1661 |
self scrollToLine:lineNr
|
|
1662 |
!
|
|
1663 |
|
|
1664 |
scrollSelectUp
|
|
1665 |
"just a template - I do not know anything about selections"
|
|
1666 |
|
|
1667 |
^ self subclassResponsibility
|
|
1668 |
!
|
|
1669 |
|
|
1670 |
scrollSelectDown
|
|
1671 |
"just a template - I do not know anything about selections"
|
|
1672 |
|
|
1673 |
^ self subclassResponsibility
|
|
1674 |
!
|
|
1675 |
|
59
|
1676 |
startAutoScrollDown:yDistance
|
0
|
1677 |
"setup for auto-scroll down (when button-press-moving below view)
|
|
1678 |
- timeDelta for scroll is computed from distance"
|
|
1679 |
|
|
1680 |
|deltaT mm|
|
|
1681 |
|
|
1682 |
mm := yDistance // self verticalIntegerPixelPerMillimeter + 1.
|
|
1683 |
deltaT := 0.5 / mm.
|
|
1684 |
|
|
1685 |
(deltaT = autoScrollDeltaT) ifFalse:[
|
59
|
1686 |
autoScrollDeltaT := deltaT.
|
|
1687 |
autoScrollBlock isNil ifTrue:[
|
|
1688 |
autoScrollBlock := [self scrollSelectDown].
|
|
1689 |
Processor addTimedBlock:autoScrollBlock afterSeconds:deltaT
|
|
1690 |
]
|
0
|
1691 |
]
|
|
1692 |
!
|
|
1693 |
|
59
|
1694 |
startAutoScrollUp:yDistance
|
0
|
1695 |
"setup for auto-scroll up (when button-press-moving below view)
|
|
1696 |
- timeDelta for scroll is computed from distance"
|
|
1697 |
|
|
1698 |
|deltaT mm|
|
|
1699 |
|
|
1700 |
mm := yDistance negated // self verticalIntegerPixelPerMillimeter + 1.
|
|
1701 |
deltaT := 0.5 / mm.
|
|
1702 |
|
|
1703 |
(deltaT = autoScrollDeltaT) ifFalse:[
|
59
|
1704 |
autoScrollDeltaT := deltaT.
|
|
1705 |
autoScrollBlock isNil ifTrue:[
|
|
1706 |
autoScrollBlock := [self scrollSelectUp].
|
|
1707 |
Processor addTimedBlock:autoScrollBlock afterSeconds:deltaT
|
|
1708 |
]
|
|
1709 |
]
|
|
1710 |
!
|
|
1711 |
|
|
1712 |
startAutoScrollRight:xDistance
|
|
1713 |
"setup for auto-scroll down (when button-press-moving to the right of the view)
|
|
1714 |
- timeDelta for scroll is computed from distance"
|
|
1715 |
|
|
1716 |
|deltaT mm|
|
|
1717 |
|
|
1718 |
mm := xDistance // self horizontalIntegerPixelPerMillimeter + 1.
|
|
1719 |
deltaT := 0.5 / mm.
|
|
1720 |
|
|
1721 |
(deltaT = autoScrollDeltaT) ifFalse:[
|
|
1722 |
autoScrollDeltaT := deltaT.
|
|
1723 |
autoScrollBlock isNil ifTrue:[
|
|
1724 |
autoScrollBlock := [self scrollSelectRight].
|
|
1725 |
Processor addTimedBlock:autoScrollBlock afterSeconds:deltaT
|
|
1726 |
]
|
|
1727 |
]
|
|
1728 |
!
|
|
1729 |
|
|
1730 |
startAutoScrollLeft:xDistance
|
|
1731 |
"setup for auto-scroll up (when button-press-moving to the left of the view)
|
|
1732 |
- timeDelta for scroll is computed from distance"
|
|
1733 |
|
|
1734 |
|deltaT mm|
|
|
1735 |
|
|
1736 |
mm := xDistance negated // self horizontalIntegerPixelPerMillimeter + 1.
|
|
1737 |
deltaT := 0.5 / mm.
|
|
1738 |
|
|
1739 |
(deltaT = autoScrollDeltaT) ifFalse:[
|
|
1740 |
autoScrollDeltaT := deltaT.
|
|
1741 |
autoScrollBlock isNil ifTrue:[
|
|
1742 |
autoScrollBlock := [self scrollSelectLeft].
|
|
1743 |
Processor addTimedBlock:autoScrollBlock afterSeconds:deltaT
|
|
1744 |
]
|
0
|
1745 |
]
|
|
1746 |
!
|
|
1747 |
|
|
1748 |
stopAutoScroll
|
|
1749 |
"stop any auto-scroll"
|
|
1750 |
|
|
1751 |
autoScrollBlock notNil ifTrue:[
|
59
|
1752 |
self compressMotionEvents:true.
|
|
1753 |
Processor removeTimedBlock:autoScrollBlock.
|
|
1754 |
autoScrollBlock := nil.
|
|
1755 |
autoScrollDeltaT := nil
|
0
|
1756 |
].
|
38
|
1757 |
!
|
|
1758 |
|
|
1759 |
scrollRight
|
|
1760 |
"scroll right by one character
|
|
1761 |
- question is how much is a good for variable fonts"
|
|
1762 |
|
|
1763 |
self scrollRight:font width
|
|
1764 |
!
|
|
1765 |
|
|
1766 |
scrollRight:nPixel
|
|
1767 |
"change origin to scroll right some cols"
|
|
1768 |
|
|
1769 |
|wMax cnt|
|
|
1770 |
|
|
1771 |
|
|
1772 |
cnt := nPixel.
|
|
1773 |
|
|
1774 |
"
|
|
1775 |
commenting out the block below allows scrolling to the right of
|
|
1776 |
the widest line
|
|
1777 |
"
|
|
1778 |
" "
|
|
1779 |
"
|
|
1780 |
the 10 below allows scrolling somewhat behind the end of the line
|
|
1781 |
"
|
|
1782 |
wMax := self widthOfContents + 10.
|
|
1783 |
(leftOffset + nPixel + width > wMax) ifTrue:[
|
59
|
1784 |
cnt := wMax - leftOffset - width
|
38
|
1785 |
].
|
59
|
1786 |
" "
|
38
|
1787 |
cnt <= 0 ifTrue:[^ self].
|
|
1788 |
self originWillChange.
|
|
1789 |
leftOffset:= leftOffset + cnt.
|
59
|
1790 |
viewOrigin := leftOffset @ viewOrigin y.
|
38
|
1791 |
self redrawFromVisibleLine:1 to:nLinesShown.
|
|
1792 |
self originChanged:(cnt @ 0)
|
|
1793 |
!
|
|
1794 |
|
|
1795 |
scrollLeft
|
|
1796 |
"scroll left by one character
|
|
1797 |
- question is how much is a good for variable fonts"
|
|
1798 |
|
|
1799 |
self scrollLeft:font width
|
|
1800 |
!
|
|
1801 |
|
|
1802 |
scrollLeft:nPixel
|
|
1803 |
"change origin to scroll left some cols"
|
|
1804 |
|
|
1805 |
|newLeftOffset|
|
|
1806 |
|
|
1807 |
nPixel <= 0 ifTrue:[^ self].
|
|
1808 |
|
|
1809 |
newLeftOffset := leftOffset - nPixel.
|
|
1810 |
newLeftOffset <= 0 ifTrue:[
|
59
|
1811 |
leftOffset == 0 ifTrue:[^ self].
|
|
1812 |
newLeftOffset := 0
|
38
|
1813 |
].
|
|
1814 |
|
|
1815 |
self originWillChange.
|
|
1816 |
leftOffset := newLeftOffset.
|
59
|
1817 |
viewOrigin := newLeftOffset @ viewOrigin y.
|
38
|
1818 |
self redrawFromVisibleLine:1 to:nLinesShown.
|
|
1819 |
self originChanged:(0 @ nPixel)
|
|
1820 |
!
|
|
1821 |
|
|
1822 |
scrollHorizontalTo:aPixelOffset
|
|
1823 |
"change origin to make aPixelOffset be the left col"
|
|
1824 |
|
|
1825 |
|orgX|
|
|
1826 |
|
|
1827 |
orgX := leftOffset.
|
|
1828 |
|
|
1829 |
(aPixelOffset < orgX) ifTrue:[
|
59
|
1830 |
self scrollLeft:(orgX - aPixelOffset)
|
38
|
1831 |
] ifFalse:[
|
59
|
1832 |
(aPixelOffset > orgX) ifTrue:[
|
|
1833 |
self scrollRight:(aPixelOffset - orgX)
|
|
1834 |
]
|
38
|
1835 |
]
|
0
|
1836 |
! !
|
|
1837 |
|
|
1838 |
!ListView methodsFor:'drawing'!
|
|
1839 |
|
|
1840 |
drawVisibleLine:visLineNr col:col with:fg and:bg
|
|
1841 |
"draw single character at col index of visible line in fg/bg"
|
|
1842 |
|
|
1843 |
|y x lineString characterString|
|
|
1844 |
|
|
1845 |
lineString := self visibleAt:visLineNr.
|
59
|
1846 |
x := (self xOfCol:col inVisibleLine:visLineNr) - leftOffset.
|
|
1847 |
y := self yOfVisibleLine:visLineNr.
|
0
|
1848 |
|
|
1849 |
self paint:bg.
|
|
1850 |
|
51
|
1851 |
(lineString notNil and:[lineString isString not]) ifTrue:[
|
59
|
1852 |
self drawVisibleLine:visLineNr with:fg and:bg
|
0
|
1853 |
] ifFalse:[
|
59
|
1854 |
col > lineString size ifTrue:[
|
|
1855 |
self fillRectangleX:x y:y width:(font width) height:fontHeight.
|
|
1856 |
self paint:fg
|
|
1857 |
] ifFalse:[
|
|
1858 |
characterString := (lineString at:col) asString.
|
|
1859 |
self fillRectangleX:x y:y
|
|
1860 |
width:(font widthOf:characterString)
|
|
1861 |
height:fontHeight.
|
|
1862 |
self paint:fg.
|
|
1863 |
self displayString:characterString x:x y:(y + fontAscent)
|
|
1864 |
]
|
0
|
1865 |
]
|
|
1866 |
!
|
|
1867 |
|
|
1868 |
drawVisibleLine:visLineNr from:startCol to:endCol with:fg and:bg
|
|
1869 |
"draw part of a visible line in fg/bg"
|
|
1870 |
|
|
1871 |
|y x lineString len characterString|
|
|
1872 |
|
|
1873 |
(endCol >= startCol) ifTrue:[
|
59
|
1874 |
lineString := self visibleAt:visLineNr.
|
51
|
1875 |
|
59
|
1876 |
(lineString notNil and:[lineString isString not]) ifTrue:[
|
|
1877 |
self drawVisibleLine:visLineNr with:fg and:bg.
|
|
1878 |
] ifFalse:[
|
|
1879 |
x := (self xOfCol:startCol inVisibleLine:visLineNr) - leftOffset.
|
|
1880 |
y := (self yOfVisibleLine:visLineNr).
|
|
1881 |
len := lineString size.
|
|
1882 |
(startCol > len) ifTrue:[
|
|
1883 |
len := endCol - startCol + 1.
|
|
1884 |
self paint:bg.
|
|
1885 |
self fillRectangleX:x y:y
|
|
1886 |
width:(fontWidth * len)
|
|
1887 |
height:fontHeight
|
|
1888 |
] ifFalse:[
|
|
1889 |
(endCol > len) ifTrue:[
|
|
1890 |
characterString := String new:endCol.
|
|
1891 |
characterString replaceFrom:1 to:len with:lineString startingAt:1.
|
|
1892 |
lineString := characterString
|
|
1893 |
].
|
|
1894 |
self paint:bg.
|
|
1895 |
self fillRectangleX:x y:y width:(font widthOf:lineString from:startCol to:endCol)
|
|
1896 |
height:fontHeight.
|
|
1897 |
self paint:fg.
|
|
1898 |
self displayString:lineString from:startCol to:endCol x:x y:(y + fontAscent)
|
|
1899 |
]
|
|
1900 |
]
|
0
|
1901 |
]
|
|
1902 |
!
|
|
1903 |
|
|
1904 |
drawVisibleLine:visLineNr from:startCol with:fg and:bg
|
|
1905 |
"draw right part of a visible line from startCol to end of line in fg/bg"
|
|
1906 |
|
|
1907 |
|y x lineString index1 index2|
|
|
1908 |
|
|
1909 |
(startCol < 1) ifTrue:[
|
59
|
1910 |
index1 := 1
|
0
|
1911 |
] ifFalse:[
|
59
|
1912 |
index1 := startCol
|
0
|
1913 |
].
|
59
|
1914 |
y := self yOfVisibleLine:visLineNr.
|
|
1915 |
x := (self xOfCol:index1 inVisibleLine:visLineNr) - leftOffset.
|
0
|
1916 |
self paint:bg.
|
|
1917 |
self fillRectangleX:x y:y
|
59
|
1918 |
width:(width + leftOffset - x)
|
|
1919 |
height:fontHeight.
|
51
|
1920 |
|
0
|
1921 |
lineString := self visibleAt:visLineNr.
|
|
1922 |
lineString notNil ifTrue:[
|
59
|
1923 |
lineString isString ifFalse:[
|
|
1924 |
self drawVisibleLine:visLineNr with:fg and:bg.
|
|
1925 |
] ifTrue:[
|
|
1926 |
index2 := lineString size.
|
|
1927 |
(index2 < index1) ifTrue:[^ self].
|
|
1928 |
(index1 <= index2) ifTrue:[
|
|
1929 |
self paint:fg.
|
|
1930 |
self displayString:lineString from:index1 to:index2 x:x y:(y + fontAscent)
|
|
1931 |
]
|
|
1932 |
]
|
0
|
1933 |
]
|
|
1934 |
!
|
|
1935 |
|
|
1936 |
drawFromVisibleLine:startVisLineNr to:endVisLineNr with:fg and:bg
|
|
1937 |
"draw a visible line range in fg/bg"
|
|
1938 |
|
|
1939 |
|y "{ Class: SmallInteger }"
|
|
1940 |
x "{ Class: SmallInteger }"
|
|
1941 |
startLine "{ Class: SmallInteger }"
|
|
1942 |
endLine "{ Class: SmallInteger }"
|
|
1943 |
listSize e|
|
|
1944 |
|
59
|
1945 |
y := self yOfVisibleLine:startVisLineNr.
|
0
|
1946 |
self paint:bg.
|
|
1947 |
self fillRectangleX:margin y:y
|
59
|
1948 |
width:(width - (margin * 2))
|
|
1949 |
height:(endVisLineNr - startVisLineNr + 1) * fontHeight.
|
38
|
1950 |
list isNil ifTrue:[^ self].
|
0
|
1951 |
|
|
1952 |
y := y + fontAscent.
|
|
1953 |
listSize := list size.
|
|
1954 |
|
|
1955 |
startLine := startVisLineNr + firstLineShown - 1.
|
|
1956 |
endLine := endVisLineNr + firstLineShown - 1.
|
|
1957 |
(startLine == 0) ifTrue:[
|
59
|
1958 |
y := y + fontHeight.
|
|
1959 |
startLine := startLine + 1
|
0
|
1960 |
].
|
|
1961 |
|
|
1962 |
(endLine > listSize) ifTrue:[
|
59
|
1963 |
e := listSize
|
0
|
1964 |
] ifFalse:[
|
59
|
1965 |
e := endLine
|
0
|
1966 |
].
|
|
1967 |
|
|
1968 |
(startLine <= e) ifTrue:[
|
59
|
1969 |
x := textStartLeft - leftOffset.
|
|
1970 |
self paint:fg.
|
|
1971 |
list from:startLine to:e do:[:line |
|
|
1972 |
line notNil ifTrue:[
|
|
1973 |
self displayString:line x:x y:y
|
|
1974 |
].
|
|
1975 |
y := y + fontHeight
|
|
1976 |
]
|
0
|
1977 |
]
|
|
1978 |
!
|
|
1979 |
|
|
1980 |
drawVisibleLine:visLineNr with:fg and:bg
|
|
1981 |
"draw a visible line in fg/bg"
|
|
1982 |
|
|
1983 |
|y line|
|
|
1984 |
|
59
|
1985 |
y := self yOfVisibleLine:visLineNr.
|
0
|
1986 |
line := self visibleAt:visLineNr.
|
|
1987 |
self paint:bg.
|
|
1988 |
self fillRectangleX:margin y:y
|
59
|
1989 |
width:(width - (margin * 2))
|
|
1990 |
height:fontHeight.
|
0
|
1991 |
line notNil ifTrue:[
|
59
|
1992 |
self paint:fg.
|
|
1993 |
self displayString:line x:(textStartLeft - leftOffset) y:(y + fontAscent)
|
0
|
1994 |
]
|
|
1995 |
! !
|
|
1996 |
|
|
1997 |
!ListView methodsFor:'redrawing'!
|
|
1998 |
|
60
|
1999 |
flash
|
|
2000 |
"show contents in reverse colors for a moment - to wakeup the user :-)"
|
|
2001 |
|
|
2002 |
|savFg savBg|
|
|
2003 |
|
|
2004 |
savFg := fgColor.
|
|
2005 |
savBg := bgColor.
|
|
2006 |
fgColor := savBg.
|
|
2007 |
bgColor := savFg.
|
|
2008 |
self redraw.
|
|
2009 |
(Delay forSeconds:0.1) wait.
|
|
2010 |
fgColor := savFg.
|
|
2011 |
bgColor := savBg.
|
|
2012 |
self redraw
|
|
2013 |
!
|
|
2014 |
|
0
|
2015 |
redrawVisibleLine:visLineNr col:col
|
|
2016 |
"redraw single character at col index of visible line"
|
|
2017 |
|
|
2018 |
shown ifTrue:[
|
59
|
2019 |
self drawVisibleLine:visLineNr col:col with:fgColor and:bgColor
|
0
|
2020 |
]
|
|
2021 |
!
|
|
2022 |
|
|
2023 |
redrawVisibleLine:visLineNr from:startCol to:endCol
|
|
2024 |
"redraw part of a visible line"
|
|
2025 |
|
|
2026 |
shown ifTrue:[
|
59
|
2027 |
self drawVisibleLine:visLineNr from:startCol to:endCol with:fgColor and:bgColor
|
0
|
2028 |
]
|
|
2029 |
!
|
|
2030 |
|
|
2031 |
redrawVisibleLine:visLineNr from:startCol
|
|
2032 |
"redraw right part of a visible line from startCol to end of line"
|
|
2033 |
|
|
2034 |
shown ifTrue:[
|
59
|
2035 |
self drawVisibleLine:visLineNr from:startCol with:fgColor and:bgColor
|
0
|
2036 |
]
|
|
2037 |
!
|
|
2038 |
|
|
2039 |
redrawFromVisibleLine:startVisLineNr to:endVisLineNr
|
|
2040 |
"redraw a visible line range"
|
|
2041 |
|
|
2042 |
shown ifTrue:[
|
59
|
2043 |
self drawFromVisibleLine:startVisLineNr to:endVisLineNr with:fgColor and:bgColor
|
0
|
2044 |
]
|
|
2045 |
!
|
|
2046 |
|
|
2047 |
redrawVisibleLine:visLineNr
|
|
2048 |
"redraw a visible line"
|
|
2049 |
|
|
2050 |
shown ifTrue:[
|
59
|
2051 |
self drawVisibleLine:visLineNr with:fgColor and:bgColor
|
0
|
2052 |
]
|
|
2053 |
!
|
|
2054 |
|
|
2055 |
redrawLine:lineNr col:col
|
|
2056 |
"redraw a single character"
|
|
2057 |
|
|
2058 |
|visibleLine|
|
|
2059 |
|
|
2060 |
visibleLine := self listLineToVisibleLine:lineNr.
|
|
2061 |
visibleLine notNil ifTrue:[
|
59
|
2062 |
self redrawVisibleLine:visibleLine col:col
|
0
|
2063 |
]
|
|
2064 |
!
|
|
2065 |
|
|
2066 |
redrawLine:lineNr
|
|
2067 |
"redraw a list line"
|
|
2068 |
|
|
2069 |
|visibleLine|
|
|
2070 |
|
|
2071 |
visibleLine := self listLineToVisibleLine:lineNr.
|
|
2072 |
visibleLine notNil ifTrue:[
|
59
|
2073 |
self redrawVisibleLine:visibleLine
|
0
|
2074 |
]
|
|
2075 |
!
|
|
2076 |
|
|
2077 |
redrawLine:lineNr from:startCol
|
|
2078 |
"redraw a list line from startCol to end of line"
|
|
2079 |
|
|
2080 |
|visibleLine|
|
|
2081 |
|
|
2082 |
visibleLine := self listLineToVisibleLine:lineNr.
|
|
2083 |
visibleLine notNil ifTrue:[
|
59
|
2084 |
self redrawVisibleLine:visibleLine from:startCol
|
0
|
2085 |
]
|
|
2086 |
!
|
|
2087 |
|
|
2088 |
redrawLine:lineNr from:startCol to:endCol
|
|
2089 |
"redraw a list line from startCol to endCol"
|
|
2090 |
|
|
2091 |
|visibleLine|
|
|
2092 |
|
|
2093 |
visibleLine := self listLineToVisibleLine:lineNr.
|
|
2094 |
visibleLine notNil ifTrue:[
|
59
|
2095 |
self redrawVisibleLine:visibleLine from:startCol to:endCol
|
0
|
2096 |
]
|
|
2097 |
!
|
|
2098 |
|
|
2099 |
redrawFromLine:lineNr
|
|
2100 |
"redraw starting at linrNr"
|
|
2101 |
|
|
2102 |
|visibleLine first|
|
|
2103 |
|
|
2104 |
shown ifTrue:[
|
59
|
2105 |
"if first line to redraw is above 1st visible line,
|
|
2106 |
start redraw at 1st visible line"
|
|
2107 |
(lineNr < firstLineShown) ifTrue:[
|
|
2108 |
first := firstLineShown
|
|
2109 |
] ifFalse:[
|
|
2110 |
first := lineNr
|
|
2111 |
].
|
|
2112 |
visibleLine := self listLineToVisibleLine:first.
|
|
2113 |
visibleLine notNil ifTrue:[
|
|
2114 |
self redrawFromVisibleLine:visibleLine to:nLinesShown
|
|
2115 |
]
|
0
|
2116 |
]
|
|
2117 |
!
|
|
2118 |
|
|
2119 |
redrawFromLine:start to:end
|
|
2120 |
"redraw lines from start to end"
|
|
2121 |
|
|
2122 |
|visibleFirst visibleLast first last lastLineShown|
|
|
2123 |
|
|
2124 |
shown ifTrue:[
|
59
|
2125 |
lastLineShown := firstLineShown + nLinesShown - 1.
|
|
2126 |
(start <= lastLineShown) ifTrue:[
|
|
2127 |
(end >= firstLineShown) ifTrue:[
|
0
|
2128 |
|
59
|
2129 |
"if first line to redraw is above 1st visible line,
|
|
2130 |
start redraw at 1st visible line"
|
0
|
2131 |
|
59
|
2132 |
(start < firstLineShown) ifTrue:[
|
|
2133 |
first := firstLineShown
|
|
2134 |
] ifFalse:[
|
|
2135 |
first := start
|
|
2136 |
].
|
|
2137 |
(end > lastLineShown) ifTrue:[
|
|
2138 |
last := lastLineShown
|
|
2139 |
] ifFalse:[
|
|
2140 |
last := end
|
|
2141 |
].
|
|
2142 |
visibleFirst := self listLineToVisibleLine:first.
|
|
2143 |
visibleLast := self listLineToVisibleLine:last.
|
|
2144 |
self redrawFromVisibleLine:visibleFirst to:visibleLast
|
|
2145 |
]
|
|
2146 |
]
|
0
|
2147 |
]
|
|
2148 |
!
|
|
2149 |
|
|
2150 |
redraw
|
|
2151 |
"redraw complete view"
|
|
2152 |
|
|
2153 |
shown ifTrue:[
|
59
|
2154 |
self redrawFromVisibleLine:1 to:nLinesShown
|
0
|
2155 |
]
|
|
2156 |
! !
|
|
2157 |
|
|
2158 |
!ListView methodsFor:'event processing'!
|
|
2159 |
|
|
2160 |
sizeChanged:how
|
|
2161 |
"size changed - move origin up if possible"
|
|
2162 |
|
|
2163 |
|listSize newOrigin|
|
|
2164 |
|
|
2165 |
self computeNumberOfLinesShown.
|
|
2166 |
innerWidth := width - textStartLeft - margin.
|
|
2167 |
shown ifTrue:[
|
59
|
2168 |
list notNil ifTrue:[
|
|
2169 |
listSize := self numberOfLines.
|
|
2170 |
((firstLineShown + nFullLinesShown) > listSize) ifTrue:[
|
|
2171 |
newOrigin := listSize - nFullLinesShown + 1.
|
|
2172 |
newOrigin < 1 ifTrue:[
|
|
2173 |
newOrigin := 1
|
|
2174 |
].
|
|
2175 |
self scrollToLine: newOrigin
|
|
2176 |
]
|
|
2177 |
]
|
0
|
2178 |
]
|
|
2179 |
!
|
|
2180 |
|
|
2181 |
redrawX:x y:y width:w height:h
|
|
2182 |
"a region must be redrawn"
|
|
2183 |
|
|
2184 |
|startLine stopLine startCol endCol|
|
|
2185 |
|
|
2186 |
startLine := self visibleLineOfY:y.
|
|
2187 |
stopLine := self visibleLineOfY:(y + h).
|
|
2188 |
|
|
2189 |
"if text-margin is affected"
|
|
2190 |
x < textStartLeft ifTrue:[
|
59
|
2191 |
self paint:bgColor.
|
|
2192 |
self fillRectangleX:margin y:margin width:(textStartLeft - margin)
|
|
2193 |
height:(height - margin - margin)
|
0
|
2194 |
].
|
|
2195 |
y < textStartTop ifTrue:[
|
59
|
2196 |
self paint:bgColor.
|
|
2197 |
self fillRectangleX:margin y:margin width:(width - margin - margin)
|
|
2198 |
height:(textStartTop - margin)
|
0
|
2199 |
].
|
|
2200 |
(w > (width // 4 * 3)) ifTrue:[
|
59
|
2201 |
"if area is big enough redraw whole lines"
|
|
2202 |
self redrawFromVisibleLine:startLine to:stopLine
|
0
|
2203 |
] ifFalse:[
|
59
|
2204 |
includesNonStrings ifTrue:[
|
|
2205 |
startLine to:stopLine do:[:i |
|
|
2206 |
self redrawVisibleLine:i
|
|
2207 |
]
|
|
2208 |
] ifFalse:[
|
|
2209 |
fontIsFixedWidth ifFalse:[
|
|
2210 |
"start/end col has to be computed for each line"
|
51
|
2211 |
|
59
|
2212 |
startLine to:stopLine do:[:i |
|
|
2213 |
startCol := self colOfX:x inVisibleLine:i.
|
|
2214 |
endCol := self colOfX:(x + w) inVisibleLine:i.
|
|
2215 |
startCol > 0 ifTrue:[
|
|
2216 |
endCol > 0 ifTrue:[
|
|
2217 |
self redrawVisibleLine:i from:startCol to:endCol
|
|
2218 |
]
|
|
2219 |
]
|
|
2220 |
]
|
|
2221 |
] ifTrue:[
|
|
2222 |
"start/end col is the same for all lines"
|
0
|
2223 |
|
59
|
2224 |
startCol := self colOfX:x inVisibleLine:startLine.
|
|
2225 |
endCol := self colOfX:(x + w) inVisibleLine:startLine.
|
|
2226 |
startCol > 0 ifTrue:[
|
|
2227 |
endCol > 0 ifTrue:[
|
|
2228 |
startLine to:stopLine do:[:i |
|
|
2229 |
self redrawVisibleLine:i from:startCol to:endCol
|
|
2230 |
]
|
|
2231 |
]
|
|
2232 |
]
|
|
2233 |
]
|
|
2234 |
]
|
0
|
2235 |
]
|
|
2236 |
!
|
|
2237 |
|
|
2238 |
keyPress:key x:x y:y
|
|
2239 |
"a key was pressed - handle page-keys here"
|
|
2240 |
|
|
2241 |
(key == #Prior) ifTrue: [^ self pageUp].
|
|
2242 |
(key == #Next) ifTrue: [^ self pageDown].
|
|
2243 |
|
|
2244 |
(key == #Ctrlb) ifTrue:[^ self pageUp].
|
|
2245 |
(key == #Ctrlf) ifTrue:[^ self pageDown].
|
|
2246 |
(key == #Ctrld) ifTrue:[^ self halfPageDown].
|
|
2247 |
(key == #Ctrlu) ifTrue:[^ self halfPageUp].
|
|
2248 |
|
|
2249 |
super keyPress:key x:x y:y
|
|
2250 |
! !
|