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