author | ca |
Wed, 20 Nov 2002 16:20:26 +0100 | |
changeset 2385 | 8113112e2184 |
parent 2384 | 44fbf84cfb22 |
child 2408 | 8b0d11537dc0 |
permissions | -rw-r--r-- |
1431 | 1 |
" |
2 |
COPYRIGHT (c) 1999 by eXept Software AG |
|
2265 | 3 |
All Rights Reserved |
1431 | 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 |
||
1752 | 14 |
"{ Package: 'stx:libwidg2' }" |
15 |
||
1390 | 16 |
View subclass:#ListModelView |
17 |
instanceVariableNames:'list listHolder textStartLeft viewOrigin enabled fgColor bgColor |
|
1399 | 18 |
lineSpacing widthOfContents computeWidthInRange startOfLinesY |
2329 | 19 |
autoScroll autoScrollBlock scrollWhenUpdating hasConstantHeight |
2352 | 20 |
constantHeight previousExtent renderer' |
1390 | 21 |
classVariableNames:'DefaultForegroundColor DefaultBackgroundColor DefaultShadowColor |
22 |
DefaultLightColor StopRedrawSignal' |
|
23 |
poolDictionaries:'' |
|
1430 | 24 |
category:'Views-Lists' |
1390 | 25 |
! |
26 |
||
2352 | 27 |
Object subclass:#Renderer |
28 |
instanceVariableNames:'view' |
|
29 |
classVariableNames:'' |
|
30 |
poolDictionaries:'' |
|
31 |
privateIn:ListModelView |
|
32 |
! |
|
33 |
||
1390 | 34 |
!ListModelView class methodsFor:'documentation'! |
35 |
||
1431 | 36 |
copyright |
37 |
" |
|
38 |
COPYRIGHT (c) 1999 by eXept Software AG |
|
2265 | 39 |
All Rights Reserved |
1431 | 40 |
|
41 |
This software is furnished under a license and may be used |
|
42 |
only in accordance with the terms of that license and with the |
|
43 |
inclusion of the above copyright notice. This software may not |
|
44 |
be provided or otherwise made available to, or used by, any |
|
45 |
other person. No title to or ownership of the software is |
|
46 |
hereby transferred. |
|
47 |
" |
|
48 |
||
49 |
! |
|
50 |
||
1390 | 51 |
documentation |
52 |
" |
|
1431 | 53 |
This widget is a new improved revision of the good-old ListView. |
54 |
In contrast to ListView, this one reacts on changes of the |
|
55 |
underlying model and performs optimized redraws. |
|
56 |
It requires a List (or alike) as model. |
|
57 |
||
1390 | 58 |
This class can only passively display collections of elements. |
59 |
The class doesn't keep its own list, it works directly on |
|
60 |
the model( List or HierarchicalList ). |
|
61 |
||
62 |
Each list item is obligated to provide 3 services: |
|
2302
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
63 |
- heightOn:aGC |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
64 |
- widthOn:aGC |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
65 |
- displayOn:aGC x:x y:y |
1390 | 66 |
|
67 |
[Instance variables:] |
|
2302
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
68 |
list <List-Model> List or HierarchicalList ... |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
69 |
listHolder <Model> Model, which keeps a List |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
70 |
textStartLeft <Number> left inset of text |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
71 |
viewOrigin <Point> the current origin |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
72 |
enabled <Boolean> widget is enabled/disabeled |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
73 |
fgColor <Color> color to draw characters |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
74 |
bgColor <Color> the background |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
75 |
lineSpacing <Number> pixels between lines |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
76 |
widthOfContents <Number> cached width of widest line |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
77 |
computeWidthInRange <Point> used for recompute width of contents |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
78 |
startOfLinesY <Collection> keeps all the absolute Y-start positions |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
79 |
for each line in the list. The first |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
80 |
entry into the list is the top Y inset. |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
81 |
supportsDisplayInRange <Boolean> set to true if the list elements |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
82 |
supports the service: |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
83 |
#displayOn:x:y:h: |
1535
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
84 |
|
2302
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
85 |
hasConstantHeight <Boolean> true, than each line has the same height |
1554 | 86 |
|
2302
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
87 |
constantHeight <SmallInteger> hasConstantHeight is turned on, this |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
88 |
is the used line height |
2264 | 89 |
|
1390 | 90 |
[author:] |
2302
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
91 |
Claus Atzkern |
1390 | 92 |
|
93 |
[see also:] |
|
94 |
||
2302
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
95 |
SelectionInListModelView |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
96 |
HierarchicalListView |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
97 |
List |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
98 |
HierarchicalList |
1390 | 99 |
" |
100 |
! |
|
101 |
||
102 |
examples |
|
103 |
" |
|
2265 | 104 |
[exBegin] |
1390 | 105 |
|top list view up index| |
106 |
||
107 |
list := List new. |
|
108 |
||
109 |
top := StandardSystemView new; extent:300@300. |
|
110 |
view := ScrollableView for:ListModelView miniScroller:true |
|
2265 | 111 |
origin:0.0@0.0 corner:1.0@1.0 in:top. |
1827 | 112 |
|
1390 | 113 |
view list:list. |
114 |
top openAndWait. |
|
115 |
up := true. |
|
116 |
||
117 |
[top shown] whileTrue:[ |
|
2265 | 118 |
Delay waitForSeconds:0.2. |
1390 | 119 |
|
2265 | 120 |
up ifTrue:[ |
121 |
index := 1 + (list size). |
|
122 |
list add:('element: ', index printString). |
|
123 |
up := index < 20 |
|
124 |
] ifFalse:[ |
|
125 |
list removeIndex:1. |
|
126 |
up := list isEmpty. |
|
127 |
] |
|
1390 | 128 |
]. |
2265 | 129 |
[exEnd] |
1390 | 130 |
|
131 |
" |
|
132 |
||
133 |
! ! |
|
134 |
||
135 |
!ListModelView class methodsFor:'initialization'! |
|
136 |
||
137 |
initialize |
|
1409 | 138 |
"setup the signals |
139 |
" |
|
140 |
super initialize. |
|
1390 | 141 |
|
1736
eda99db343be
StopRedrawSignal is a Notification, not an Error.
Stefan Vogel <sv@exept.de>
parents:
1732
diff
changeset
|
142 |
StopRedrawSignal := Notification newSignalMayProceed:false. |
1390 | 143 |
! ! |
144 |
||
145 |
!ListModelView class methodsFor:'Signal constants'! |
|
146 |
||
147 |
stopRedrawSignal |
|
148 |
^ StopRedrawSignal |
|
149 |
! ! |
|
150 |
||
151 |
!ListModelView class methodsFor:'defaults'! |
|
152 |
||
2352 | 153 |
defaultRenderer |
154 |
^ Renderer |
|
155 |
! |
|
156 |
||
1390 | 157 |
updateStyleCache |
158 |
"extract values from the styleSheet and cache them in class variables" |
|
159 |
||
160 |
<resource: #style ( |
|
2265 | 161 |
#'text.backgroundColor' #'text.foregroundColor' |
162 |
#'selection.shadowColor' #'selection.lightColor' |
|
163 |
#'text.font' |
|
164 |
)> |
|
1390 | 165 |
|
166 |
DefaultForegroundColor := StyleSheet colorAt:'text.foregroundColor' default:Black. |
|
167 |
DefaultBackgroundColor := StyleSheet colorAt:'text.backgroundColor'. |
|
168 |
DefaultShadowColor := StyleSheet colorAt:'selection.shadowColor'. |
|
169 |
DefaultLightColor := StyleSheet colorAt:'selection.lightColor'. |
|
170 |
DefaultFont := StyleSheet fontAt:'text.font'. |
|
171 |
||
172 |
" |
|
173 |
self updateStyleCache |
|
174 |
" |
|
175 |
||
176 |
||
177 |
! ! |
|
178 |
||
179 |
!ListModelView methodsFor:'accessing'! |
|
180 |
||
181 |
list |
|
182 |
"get the list of items |
|
183 |
" |
|
184 |
^ list |
|
185 |
||
186 |
||
187 |
! |
|
188 |
||
189 |
list:aList |
|
190 |
"set the list of items |
|
191 |
" |
|
2264 | 192 |
|negatedOrg| |
1443 | 193 |
|
1452 | 194 |
list ~~ aList ifTrue:[ |
2302
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
195 |
list removeDependent:self. |
1390 | 196 |
]. |
1452 | 197 |
(list := aList) notNil ifTrue:[ |
2302
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
198 |
list addDependent:self |
1452 | 199 |
]. |
2264 | 200 |
preferredExtent := nil. |
201 |
widthOfContents := nil. |
|
202 |
||
203 |
self realized ifFalse:[^ self]. |
|
204 |
||
1390 | 205 |
self recomputeHeightOfContents. |
206 |
||
207 |
||
1827 | 208 |
scrollWhenUpdating == #beginOfText ifTrue:[ |
2302
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
209 |
viewOrigin = (0@0) ifFalse:[ |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
210 |
self originWillChange. |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
211 |
negatedOrg := viewOrigin negated. |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
212 |
viewOrigin := (0@0). |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
213 |
self originChanged:negatedOrg. |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
214 |
]. |
1827 | 215 |
] ifFalse:[ |
2302
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
216 |
scrollWhenUpdating == #endOfText ifTrue:[ |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
217 |
self scrollTo:(0 @ self heightOfContents - self innerHeight) redraw:false |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
218 |
] |
1422 | 219 |
]. |
1827 | 220 |
|
1422 | 221 |
self invalidate. |
1457 | 222 |
self contentsChanged |
1390 | 223 |
! ! |
224 |
||
1818 | 225 |
!ListModelView methodsFor:'accessing-behavior'! |
1390 | 226 |
|
1748 | 227 |
autoScroll |
228 |
"returns true if auto scrolling is enabled |
|
229 |
" |
|
230 |
^ autoScroll |
|
231 |
! |
|
232 |
||
233 |
autoScroll:aBool |
|
234 |
"returns true if auto scrolling is enabled |
|
235 |
" |
|
236 |
autoScroll := aBool ? true. |
|
237 |
! |
|
238 |
||
1390 | 239 |
enabled |
240 |
"returns the enabled state |
|
241 |
" |
|
242 |
^ enabled |
|
243 |
||
244 |
||
245 |
! |
|
246 |
||
247 |
enabled:aBoolean |
|
248 |
"set the enabled state |
|
249 |
" |
|
250 |
enabled := aBoolean |
|
251 |
||
252 |
||
1742 | 253 |
! |
254 |
||
2261 | 255 |
hasConstantHeight |
256 |
"user configured; true if each line has the same lineHeight |
|
257 |
optimize for scroller update |
|
258 |
" |
|
259 |
^ hasConstantHeight |
|
260 |
! |
|
261 |
||
262 |
hasConstantHeight:aBool |
|
263 |
"user configured; true if each line has the same lineHeight |
|
264 |
optimize for scroller update |
|
265 |
" |
|
266 |
aBool == hasConstantHeight ifTrue:[ |
|
2265 | 267 |
^ self |
2261 | 268 |
]. |
2264 | 269 |
constantHeight := nil. |
2261 | 270 |
hasConstantHeight := aBool. |
271 |
||
272 |
self lostSynchronisation. |
|
273 |
! |
|
274 |
||
1742 | 275 |
scrollWhenUpdating:aSymbolOrNil |
276 |
"define how to scroll, when I get a new text |
|
277 |
(via the model or the #contents/#list) |
|
278 |
Allowed arguments are: |
|
2265 | 279 |
#keep / nil -> no change |
280 |
#endOfText -> scroll to the end |
|
281 |
#beginOfText -> scroll to the top |
|
1742 | 282 |
The default is #beginOfText. |
283 |
This may be useful for fields which get new values assigned from |
|
284 |
the program (i.e. not from the user) |
|
285 |
" |
|
286 |
||
1827 | 287 |
scrollWhenUpdating := aSymbolOrNil |
1742 | 288 |
|
289 |
||
1390 | 290 |
! ! |
291 |
||
1818 | 292 |
!ListModelView methodsFor:'accessing-items'! |
1390 | 293 |
|
294 |
at:anIndex |
|
295 |
"return the list element at an index |
|
296 |
" |
|
297 |
^ list at:anIndex |
|
298 |
! |
|
299 |
||
300 |
at:anIndex ifAbsent:exceptionBlock |
|
301 |
"return the list element at an index if valid. |
|
302 |
If the index is invalid, return the result of evaluating |
|
303 |
the exceptionblock. |
|
304 |
" |
|
305 |
list notNil ifTrue:[ |
|
2265 | 306 |
^ list at:anIndex ifAbsent:exceptionBlock |
1390 | 307 |
]. |
308 |
^ nil. |
|
309 |
! |
|
310 |
||
311 |
identityIndexOf:anElement |
|
312 |
"returns the index of an element or nil |
|
313 |
" |
|
314 |
^ list notNil ifTrue:[list identityIndexOf:anElement] |
|
2265 | 315 |
ifFalse:[0] |
1390 | 316 |
|
317 |
||
318 |
! ! |
|
319 |
||
1818 | 320 |
!ListModelView methodsFor:'accessing-look'! |
1390 | 321 |
|
322 |
backgroundColor |
|
323 |
"get the background color |
|
324 |
" |
|
325 |
^ bgColor |
|
326 |
||
327 |
||
328 |
! |
|
329 |
||
330 |
backgroundColor:aColor |
|
331 |
"set the background color |
|
332 |
" |
|
333 |
(aColor notNil and:[bgColor ~~ aColor]) ifTrue:[ |
|
2265 | 334 |
super viewBackground:bgColor. |
1390 | 335 |
|
2265 | 336 |
self realized ifTrue:[ |
337 |
bgColor := aColor onDevice:device. |
|
338 |
self invalidate |
|
339 |
] ifFalse:[ |
|
340 |
bgColor := aColor |
|
341 |
] |
|
1390 | 342 |
] |
343 |
! |
|
344 |
||
345 |
font:aFont |
|
346 |
"set a new font |
|
347 |
" |
|
348 |
|oldWidth oldHeight| |
|
349 |
||
350 |
(aFont isNil or:[aFont = font]) ifFalse:[ |
|
2265 | 351 |
oldWidth := font width. |
352 |
oldHeight := font height. |
|
1390 | 353 |
|
2265 | 354 |
super font:aFont. |
1390 | 355 |
|
2265 | 356 |
(font widthOn:device) ~~ oldWidth ifTrue:[ "/ force a recomputation |
357 |
preferredExtent := nil. |
|
358 |
widthOfContents := nil. |
|
359 |
]. |
|
360 |
oldHeight ~~ (font heightOn:device) ifTrue:[ |
|
361 |
self recomputeHeightOfContents. |
|
362 |
]. |
|
363 |
shown ifTrue:[ self invalidate ] |
|
1390 | 364 |
]. |
365 |
! |
|
366 |
||
367 |
foregroundColor |
|
368 |
"get the foreground color |
|
369 |
" |
|
370 |
^ fgColor |
|
371 |
||
372 |
! |
|
373 |
||
374 |
foregroundColor:aColor |
|
375 |
"set the foreground color |
|
376 |
" |
|
377 |
(aColor notNil and:[fgColor ~~ aColor]) ifTrue:[ |
|
2265 | 378 |
self realized ifTrue:[ |
379 |
fgColor := aColor onDevice:device. |
|
380 |
self invalidate |
|
381 |
] ifFalse:[ |
|
382 |
fgColor := aColor |
|
383 |
] |
|
1390 | 384 |
] |
1945 | 385 |
! |
386 |
||
387 |
lineSpacing |
|
388 |
"get the lineSpacing - thats an additional number of pixels, |
|
389 |
by which lines are vertically separated. |
|
390 |
" |
|
391 |
^ lineSpacing |
|
392 |
! |
|
393 |
||
394 |
lineSpacing:aNumber |
|
395 |
"set the lineSpacing - thats an additional number of pixels, |
|
396 |
by which lines are vertically separated. |
|
397 |
" |
|
398 |
lineSpacing ~= aNumber ifTrue:[ |
|
2265 | 399 |
lineSpacing := aNumber. |
1945 | 400 |
|
2265 | 401 |
self recomputeHeightOfContents. |
1945 | 402 |
|
2265 | 403 |
shown ifTrue:[ |
404 |
self invalidate |
|
405 |
] |
|
1945 | 406 |
] |
1390 | 407 |
! ! |
408 |
||
1818 | 409 |
!ListModelView methodsFor:'accessing-mvc'! |
1390 | 410 |
|
411 |
listHolder |
|
412 |
"returns the listHolder or nil |
|
413 |
" |
|
414 |
^ listHolder |
|
415 |
! |
|
416 |
||
417 |
listHolder:aListHolder |
|
418 |
"set a new listHolder |
|
419 |
" |
|
420 |
listHolder removeDependent:self. |
|
421 |
||
422 |
(listHolder := aListHolder) notNil ifTrue:[ |
|
2265 | 423 |
listHolder addDependent:self. |
1390 | 424 |
]. |
425 |
self list:(listHolder value). |
|
426 |
! ! |
|
427 |
||
428 |
!ListModelView methodsFor:'change & update'! |
|
429 |
||
430 |
lineChangedAt:aLnNr with:arg |
|
431 |
"line changed at position; check whether line height changed |
|
432 |
" |
|
2385 | 433 |
|cash |
1390 | 434 |
oldHeight "{ Class:SmallInteger }" |
435 |
dltHeight "{ Class:SmallInteger }" |
|
436 |
| |
|
437 |
(arg notNil and:[(arg == #icon or:[arg == #hierarchy])]) ifTrue:[ |
|
2385 | 438 |
^ self |
1390 | 439 |
]. |
2264 | 440 |
hasConstantHeight ifTrue:[ |
2385 | 441 |
self invalidateLineAt:aLnNr. |
442 |
^ self |
|
2264 | 443 |
]. |
444 |
||
1390 | 445 |
oldHeight := (self yVisibleOfLine:(aLnNr + 1)) - (self yVisibleOfLine:aLnNr). |
446 |
dltHeight := (self heightOfLineAt:aLnNr) - oldHeight. |
|
447 |
||
448 |
dltHeight == 0 ifTrue:[ |
|
2385 | 449 |
self invalidateLineAt:aLnNr. |
450 |
^ self |
|
1390 | 451 |
]. |
2385 | 452 |
cash := startOfLinesY. |
1390 | 453 |
|
2385 | 454 |
aLnNr + 1 to:cash size do:[:i| |
455 |
cash at:i put:((cash at:i) + dltHeight) |
|
1390 | 456 |
]. |
457 |
self invalidate. |
|
458 |
! |
|
459 |
||
460 |
listChangedInsert:start nItems:nLines |
|
461 |
"list changed; items are added |
|
462 |
" |
|
2385 | 463 |
|newLines |
1390 | 464 |
run "{ Class: SmallInteger }" |
1457 | 465 |
newSz "{ Class: SmallInteger }" |
1390 | 466 |
cpyHg "{ Class: SmallInteger }" |
467 |
absY0 "{ Class: SmallInteger }" |
|
468 |
absY1 "{ Class: SmallInteger }" |
|
469 |
visY0 "{ Class: SmallInteger }" |
|
470 |
visY1 "{ Class: SmallInteger }" |
|
471 |
orgY "{ Class: SmallInteger }" |
|
472 |
dltY "{ Class: SmallInteger }" |
|
473 |
maxHg "{ Class: SmallInteger }" |
|
474 |
| |
|
475 |
||
476 |
nLines == 0 ifTrue:[^ self ]. |
|
477 |
self listSizeChanged:start nLines:nLines. |
|
478 |
shown not ifTrue:[^ self]. |
|
479 |
||
1457 | 480 |
newSz := startOfLinesY size + nLines. |
481 |
||
482 |
(newSz - 1) ~~ list size ifTrue:[ |
|
2385 | 483 |
"/ |
484 |
"/ no longer synchrounous |
|
485 |
"/ |
|
486 |
^ self lostSynchronisation |
|
1451 | 487 |
]. |
2385 | 488 |
newLines := startOfLinesY copy. |
489 |
newLines addAll:(Array new:nLines) beforeIndex:start + 1. |
|
490 |
absY0 := newLines at:start. |
|
1390 | 491 |
absY1 := absY0. |
492 |
run := start. |
|
493 |
||
494 |
nLines timesRepeat:[ |
|
2385 | 495 |
absY1 := absY1 + (self heightOfLineAt:run). |
496 |
run := run + 1. |
|
497 |
newLines at:run put:absY1. |
|
1390 | 498 |
]. |
499 |
dltY := absY1 - absY0. |
|
1457 | 500 |
|
501 |
run + 1 to:newSz do:[:i||v| |
|
2385 | 502 |
newLines at:i put:((newLines at:i) + dltY) |
1390 | 503 |
]. |
2385 | 504 |
startOfLinesY := newLines. |
1390 | 505 |
|
506 |
orgY := viewOrigin y. |
|
507 |
absY1 := absY0 + dltY. |
|
508 |
visY0 := absY0 - orgY. |
|
509 |
visY1 := absY1 - orgY. |
|
510 |
maxHg := height - margin. |
|
511 |
||
512 |
absY0 < orgY ifTrue:[ |
|
2385 | 513 |
self originWillChange. |
514 |
viewOrigin y:(dltY + orgY). |
|
515 |
self originChanged:(0 @ dltY). |
|
1390 | 516 |
]. |
1457 | 517 |
|
1390 | 518 |
(visY0 >= maxHg or:[visY1 <= margin]) ifTrue:[ |
2385 | 519 |
^ self contentsChanged |
1390 | 520 |
]. |
521 |
visY0 := visY0 max:margin. |
|
522 |
visY1 := visY1 min:maxHg. |
|
523 |
||
1773
9dba0f0dda0e
invalidate uptoend not all if a damage exists (insert/remove)
ca
parents:
1753
diff
changeset
|
524 |
self hasDamage ifTrue:[ |
2385 | 525 |
self invalidate:(Rectangle left:0 |
526 |
top:visY0 |
|
527 |
width:width |
|
528 |
height:height - visY0). |
|
1773
9dba0f0dda0e
invalidate uptoend not all if a damage exists (insert/remove)
ca
parents:
1753
diff
changeset
|
529 |
|
2385 | 530 |
^ self contentsChanged. |
1773
9dba0f0dda0e
invalidate uptoend not all if a damage exists (insert/remove)
ca
parents:
1753
diff
changeset
|
531 |
]. |
9dba0f0dda0e
invalidate uptoend not all if a damage exists (insert/remove)
ca
parents:
1753
diff
changeset
|
532 |
|
1390 | 533 |
(start == list size or:[(cpyHg := maxHg - visY1) < 20]) ifTrue:[ |
2385 | 534 |
visY1 := maxHg |
1390 | 535 |
] ifFalse:[ |
2385 | 536 |
self catchExpose. |
1390 | 537 |
|
2385 | 538 |
self copyFrom:self x:0 y:visY0 |
539 |
toX:0 y:visY1 |
|
540 |
width:width height:cpyHg async:true. |
|
1390 | 541 |
|
2385 | 542 |
self waitForExpose |
1390 | 543 |
]. |
544 |
||
1457 | 545 |
self invalidateX:margin |
2385 | 546 |
y:visY0 |
547 |
width:width - margin - margin |
|
548 |
height:(visY1 - visY0). |
|
1457 | 549 |
|
1390 | 550 |
self contentsChanged. |
551 |
! |
|
552 |
||
1446
fb46beba2d0c
startOfLines can have nil at end; lookup the first not nil
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
553 |
listChangedRemove:aStart toIndex:aStop |
1390 | 554 |
"list changed; items are removed |
555 |
" |
|
2385 | 556 |
|noRedraw newLines |
1390 | 557 |
size "{ Class: SmallInteger }" |
558 |
absY0 "{ Class: SmallInteger }" |
|
559 |
absY1 "{ Class: SmallInteger }" |
|
560 |
visY0 "{ Class: SmallInteger }" |
|
561 |
visY1 "{ Class: SmallInteger }" |
|
562 |
orgY "{ Class: SmallInteger }" |
|
563 |
orgX "{ Class: SmallInteger }" |
|
564 |
dltY "{ Class: SmallInteger }" |
|
565 |
cpyHg "{ Class: SmallInteger }" |
|
566 |
maxHg "{ Class: SmallInteger }" |
|
1444
0b7cd00e2537
check range before delete lines
Claus Gittinger <cg@exept.de>
parents:
1443
diff
changeset
|
567 |
stop "{ Class: SmallInteger }" |
1446
fb46beba2d0c
startOfLines can have nil at end; lookup the first not nil
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
568 |
start "{ Class: SmallInteger }" |
1457 | 569 |
newSz "{ Class: SmallInteger }" |
1390 | 570 |
| |
1446
fb46beba2d0c
startOfLines can have nil at end; lookup the first not nil
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
571 |
stop := aStop. |
fb46beba2d0c
startOfLines can have nil at end; lookup the first not nil
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
572 |
start := aStart. |
1390 | 573 |
|
1446
fb46beba2d0c
startOfLines can have nil at end; lookup the first not nil
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
574 |
(size := stop - start + 1) == 0 ifTrue:[ |
2385 | 575 |
^ self |
1390 | 576 |
]. |
1446
fb46beba2d0c
startOfLines can have nil at end; lookup the first not nil
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
577 |
|
1390 | 578 |
self listSizeChanged:start nLines:(size negated). |
579 |
shown not ifTrue:[^ self]. |
|
1451 | 580 |
|
1457 | 581 |
newSz := startOfLinesY size - size. |
582 |
||
583 |
(newSz - 1) ~~ list size ifTrue:[ |
|
2385 | 584 |
"/ |
585 |
"/ no longer synchrounous |
|
586 |
"/ |
|
587 |
^ self lostSynchronisation |
|
1451 | 588 |
]. |
589 |
||
1390 | 590 |
absY0 := self yAbsoluteOfLine:start. |
1457 | 591 |
absY1 := self yAbsoluteOfLine:stop + 1. |
1390 | 592 |
dltY := absY1 - absY0. |
593 |
||
2385 | 594 |
newLines := startOfLinesY copy. |
595 |
newLines removeFromIndex:(start + 1) toIndex:(stop + 1). |
|
1390 | 596 |
|
1457 | 597 |
(start + 1) to:newSz do:[:i| |
2385 | 598 |
absY0 := newLines at:i. |
599 |
newLines at:i put:(absY0 - dltY). |
|
1390 | 600 |
]. |
2385 | 601 |
startOfLinesY := newLines. |
1390 | 602 |
|
603 |
orgY := viewOrigin y. |
|
604 |
orgX := viewOrigin x. |
|
605 |
||
606 |
absY0 := self yAbsoluteOfLine:start. |
|
607 |
absY1 := absY0 + dltY. |
|
608 |
visY0 := absY0 - orgY. |
|
609 |
visY1 := absY1 - orgY. |
|
610 |
maxHg := height - margin. |
|
611 |
||
612 |
(list size == 0 or:[(orgY ~~ 0 and:[self maxViewOriginY == 0])]) ifTrue:[ |
|
2385 | 613 |
(orgX ~~ 0 or:[orgY ~~ 0]) ifTrue:[ |
614 |
self originWillChange. |
|
615 |
viewOrigin := 0@0. |
|
616 |
self originChanged:((orgX @ orgY) negated). |
|
617 |
]. |
|
618 |
self invalidate. |
|
619 |
^ self contentsChanged |
|
1390 | 620 |
]. |
621 |
||
622 |
visY0 < margin ifTrue:[ |
|
2385 | 623 |
noRedraw := visY1 <= margin. |
624 |
noRedraw ifTrue:[dltY := dltY negated] ifFalse:[dltY := visY0]. |
|
1390 | 625 |
|
2385 | 626 |
self originWillChange. |
627 |
viewOrigin y:(dltY + orgY). |
|
628 |
self originChanged:(0 @ dltY). |
|
1390 | 629 |
] ifFalse:[ |
2385 | 630 |
noRedraw := visY0 >= maxHg |
1390 | 631 |
]. |
1773
9dba0f0dda0e
invalidate uptoend not all if a damage exists (insert/remove)
ca
parents:
1753
diff
changeset
|
632 |
visY0 := visY0 max:margin. |
9dba0f0dda0e
invalidate uptoend not all if a damage exists (insert/remove)
ca
parents:
1753
diff
changeset
|
633 |
|
1457 | 634 |
self hasDamage ifTrue:[ |
2385 | 635 |
self invalidate:(Rectangle left:0 |
636 |
top:visY0 |
|
637 |
width:width |
|
638 |
height:height - visY0). |
|
1773
9dba0f0dda0e
invalidate uptoend not all if a damage exists (insert/remove)
ca
parents:
1753
diff
changeset
|
639 |
|
2385 | 640 |
noRedraw := true |
1457 | 641 |
]. |
1390 | 642 |
|
1457 | 643 |
noRedraw ifFalse:[ |
2385 | 644 |
cpyHg := maxHg - visY1. |
1390 | 645 |
|
2385 | 646 |
cpyHg > 20 ifTrue:[ |
647 |
self catchExpose. |
|
648 |
self copyFrom:self x:0 y:visY1 toX:0 y:visY0 |
|
649 |
width:width height:cpyHg async:true. |
|
650 |
self waitForExpose. |
|
651 |
visY0 := visY0 + cpyHg. |
|
652 |
]. |
|
1390 | 653 |
|
2385 | 654 |
self invalidateX:margin |
655 |
y:visY0 |
|
656 |
width:width - margin - margin |
|
657 |
height:(maxHg - visY0). |
|
1390 | 658 |
]. |
659 |
self contentsChanged. |
|
660 |
! |
|
661 |
||
2302
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
662 |
update:what with:aPara from:chgObj |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
663 |
"catch and handle any notification raised from the list model |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
664 |
or list holder |
1390 | 665 |
" |
1443 | 666 |
|a1 a2| |
1390 | 667 |
|
2302
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
668 |
chgObj ~~ list ifTrue:[ |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
669 |
chgObj == listHolder ifTrue:[ |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
670 |
self list:(listHolder value). |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
671 |
] ifFalse:[ |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
672 |
super update:what with:aPara from:chgObj |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
673 |
]. |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
674 |
^ self |
1995 | 675 |
]. |
1390 | 676 |
|
2302
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
677 |
aPara isCollection ifFalse:[ |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
678 |
what == #at: ifTrue:[self lineChangedAt:aPara with:nil. ^ self]. |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
679 |
what == #insert: ifTrue:[self listChangedInsert:aPara nItems:1. ^ self]. |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
680 |
what == #remove: ifTrue:[self listChangedRemove:aPara toIndex:aPara. ^ self]. |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
681 |
^ self. |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
682 |
]. |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
683 |
|
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
684 |
a1 := aPara at:1. |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
685 |
a2 := aPara at:2. |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
686 |
|
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
687 |
(a1 == 1 and:[a2 == list size]) ifTrue:[ |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
688 |
self list:list. "/ reload full list |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
689 |
^ self |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
690 |
]. |
1390 | 691 |
|
1995 | 692 |
what == #at: ifTrue:[self lineChangedAt:a1 with:a2. ^ self]. |
693 |
what == #insertCollection: ifTrue:[self listChangedInsert:a1 nItems:a2. ^ self]. |
|
694 |
what == #removeFrom: ifTrue:[self listChangedRemove:a1 toIndex:a2. ^ self]. |
|
2302
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
695 |
|
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
696 |
what == #replace: ifTrue:[ |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
697 |
a1 to:a2 do:[:i|self lineChangedAt:i with:nil]. |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
698 |
^ self |
1995 | 699 |
]. |
1390 | 700 |
! ! |
701 |
||
702 |
!ListModelView methodsFor:'drawing'! |
|
703 |
||
2304 | 704 |
drawFrom:start to:stop x:x y:y w:w |
705 |
"draw lines from start to stop. |
|
706 |
clipping and clearing the background is already done |
|
1399 | 707 |
" |
2304 | 708 |
|item |
709 |
y0 "{ Class:SmallInteger }" |
|
710 |
y1 "{ Class:SmallInteger }" |
|
711 |
x0 "{ Class:SmallInteger }" |
|
712 |
| |
|
713 |
self paint:fgColor on:bgColor. |
|
714 |
||
715 |
x0 := textStartLeft - viewOrigin x. |
|
716 |
y1 := y. |
|
717 |
||
718 |
start to:stop do:[:i| |
|
719 |
item := list at:i ifAbsent:self. "/ list changed during draw |
|
720 |
item == self ifTrue:[^ self]. |
|
721 |
||
722 |
y0 := y1. |
|
723 |
y1 := self yVisibleOfLine:(i + 1). |
|
724 |
||
725 |
item notNil ifTrue:[ |
|
2352 | 726 |
renderer display:item atX:x0 y:y0 lineHeight:(y1 - y0). |
2304 | 727 |
] |
728 |
] |
|
1390 | 729 |
! |
730 |
||
2304 | 731 |
invalidateLineAt:aLineNr |
732 |
"add a damage to redraw a line specified by its line number to the |
|
733 |
input event queue. |
|
1390 | 734 |
" |
2322 | 735 |
^ self invalidateLineAt:aLineNr fromX:0. |
736 |
! |
|
737 |
||
738 |
invalidateLineAt:aLineNr fromX:x |
|
739 |
"add a damage to redraw a line specified by its line number to the |
|
740 |
input event queue. |
|
741 |
" |
|
1390 | 742 |
|y0 "{ Class:SmallInteger }" |
743 |
y1 "{ Class:SmallInteger }" |
|
744 |
yB "{ Class:SmallInteger }" |
|
2322 | 745 |
x0 "{ Class:SmallInteger }" |
746 |
xR "{ Class:SmallInteger }" |
|
1390 | 747 |
| |
748 |
||
2244
c9a195d28e72
change #redrawLineAt: to #invalidateLineAt: (because is a invalidate)
ca
parents:
2188
diff
changeset
|
749 |
(shown and:[aLineNr notNil and:[aLineNr > 0]]) ifFalse:[ |
2304 | 750 |
^ self |
2244
c9a195d28e72
change #redrawLineAt: to #invalidateLineAt: (because is a invalidate)
ca
parents:
2188
diff
changeset
|
751 |
]. |
1390 | 752 |
|
2322 | 753 |
xR := width - margin. |
754 |
x0 := x max:margin. |
|
755 |
x0 < xR ifFalse:[ ^ self]. |
|
756 |
||
2244
c9a195d28e72
change #redrawLineAt: to #invalidateLineAt: (because is a invalidate)
ca
parents:
2188
diff
changeset
|
757 |
yB := height - margin. |
c9a195d28e72
change #redrawLineAt: to #invalidateLineAt: (because is a invalidate)
ca
parents:
2188
diff
changeset
|
758 |
y0 := (self yVisibleOfLine:aLineNr) max:margin. |
c9a195d28e72
change #redrawLineAt: to #invalidateLineAt: (because is a invalidate)
ca
parents:
2188
diff
changeset
|
759 |
|
c9a195d28e72
change #redrawLineAt: to #invalidateLineAt: (because is a invalidate)
ca
parents:
2188
diff
changeset
|
760 |
y0 < yB ifTrue:[ |
2304 | 761 |
y1 := (self yVisibleOfLine:(aLineNr + 1)) min:yB. |
2244
c9a195d28e72
change #redrawLineAt: to #invalidateLineAt: (because is a invalidate)
ca
parents:
2188
diff
changeset
|
762 |
|
2304 | 763 |
y1 > y0 ifTrue:[ |
2322 | 764 |
self invalidateX:x0 y:y0 width:(xR - x0) height:(y1 - y0) repairNow:false. |
2304 | 765 |
] |
766 |
]. |
|
2244
c9a195d28e72
change #redrawLineAt: to #invalidateLineAt: (because is a invalidate)
ca
parents:
2188
diff
changeset
|
767 |
! |
c9a195d28e72
change #redrawLineAt: to #invalidateLineAt: (because is a invalidate)
ca
parents:
2188
diff
changeset
|
768 |
|
c9a195d28e72
change #redrawLineAt: to #invalidateLineAt: (because is a invalidate)
ca
parents:
2188
diff
changeset
|
769 |
redraw |
c9a195d28e72
change #redrawLineAt: to #invalidateLineAt: (because is a invalidate)
ca
parents:
2188
diff
changeset
|
770 |
"redraw complete view |
c9a195d28e72
change #redrawLineAt: to #invalidateLineAt: (because is a invalidate)
ca
parents:
2188
diff
changeset
|
771 |
" |
c9a195d28e72
change #redrawLineAt: to #invalidateLineAt: (because is a invalidate)
ca
parents:
2188
diff
changeset
|
772 |
self redrawX:0 y:0 width:width height:height. |
c9a195d28e72
change #redrawLineAt: to #invalidateLineAt: (because is a invalidate)
ca
parents:
2188
diff
changeset
|
773 |
|
1390 | 774 |
|
775 |
! |
|
776 |
||
777 |
redrawX:x y:y width:w height:h |
|
778 |
"redraw part of myself immediately, given logical coordinates |
|
779 |
" |
|
2304 | 780 |
|start stop yAbs drawFailed| |
1390 | 781 |
|
782 |
shown ifFalse:[^ self]. |
|
783 |
||
784 |
self paint:bgColor. |
|
785 |
self fillRectangleX:x y:y width:w height:h. |
|
786 |
||
2304 | 787 |
widthOfContents isNil ifTrue:[ |
788 |
self preferredExtent |
|
2188 | 789 |
]. |
1390 | 790 |
|
2304 | 791 |
start := self yVisibleToLineNr:y. |
792 |
start isNil ifTrue:[ ^ self ]. |
|
793 |
||
794 |
yAbs := y + h. |
|
795 |
stop := self yVisibleToLineNr:yAbs. |
|
796 |
||
797 |
stop isNil ifTrue:[ |
|
798 |
stop := list size. |
|
799 |
] ifFalse:[ |
|
800 |
yAbs == (startOfLinesY at:stop) ifTrue:[ |
|
801 |
stop := (stop - 1) max:start |
|
802 |
]. |
|
803 |
]. |
|
1390 | 804 |
|
2304 | 805 |
drawFailed := true. |
1390 | 806 |
|
2304 | 807 |
"/ test whether list changed during redraw |
808 |
stop >= start ifTrue:[ |
|
809 |
StopRedrawSignal handle:[:ex| ] |
|
810 |
do:[ self drawFrom:start to:stop x:x |
|
811 |
y:(self yVisibleOfLine:start) w:w. |
|
812 |
||
813 |
drawFailed := false. "/ success drawn |
|
814 |
] |
|
815 |
]. |
|
816 |
||
817 |
drawFailed ifTrue:[ self invalidate ]. |
|
1390 | 818 |
! ! |
819 |
||
820 |
!ListModelView methodsFor:'event handling'! |
|
821 |
||
822 |
keyPress:aKey x:x y:y |
|
823 |
"a key was pressed - handle page-keys here |
|
824 |
" |
|
825 |
<resource: #keyboard( #PreviousPage #NextPage #HalfPageUp #HalfPageDown |
|
2265 | 826 |
#BeginOfText #EndOfText #ScrollUp #ScrollDown |
827 |
)> |
|
1390 | 828 |
|
829 |
|n sensor| |
|
830 |
||
831 |
list size ~~ 0 ifTrue:[ |
|
2265 | 832 |
(aKey == #PreviousPage) ifTrue:[^ self pageUp]. |
833 |
(aKey == #NextPage) ifTrue:[^ self pageDown]. |
|
834 |
(aKey == #HalfPageUp) ifTrue:[^ self halfPageUp]. |
|
835 |
(aKey == #HalfPageDown) ifTrue:[^ self halfPageDown]. |
|
836 |
(aKey == #BeginOfText) ifTrue:[^ self scrollToTop]. |
|
837 |
(aKey == #EndOfText) ifTrue:[^ self scrollToBottom]. |
|
1390 | 838 |
|
2265 | 839 |
(aKey == #ScrollUp or:[aKey == #ScrollDown]) ifTrue:[ |
840 |
sensor := self sensor. |
|
1390 | 841 |
|
2265 | 842 |
n := sensor notNil ifTrue:[1 + (sensor compressKeyPressEventsWithKey:aKey)] |
843 |
ifFalse:[1]. |
|
1390 | 844 |
|
2265 | 845 |
n := n * self verticalScrollStep. |
1390 | 846 |
|
2265 | 847 |
aKey == #ScrollUp ifTrue:[self scrollUp:n] |
848 |
ifFalse:[self scrollDown:n]. |
|
849 |
^ self |
|
850 |
]. |
|
1390 | 851 |
]. |
852 |
super keyPress:aKey x:x y:y |
|
2274
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2265
diff
changeset
|
853 |
! |
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2265
diff
changeset
|
854 |
|
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2265
diff
changeset
|
855 |
sizeChanged:how |
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2265
diff
changeset
|
856 |
previousExtent := self extent. |
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2265
diff
changeset
|
857 |
super sizeChanged:how. |
1390 | 858 |
! ! |
859 |
||
1554 | 860 |
!ListModelView methodsFor:'event simulation'! |
861 |
||
862 |
syncronizeEvents |
|
2302
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
863 |
self obsoleteMethodWarning:'no longer supported'. |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
864 |
^ false |
1554 | 865 |
! |
866 |
||
867 |
syncronizeEvents:aBoolean |
|
2302
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
868 |
self obsoleteMethodWarning:'no longer supported'. |
1554 | 869 |
! ! |
870 |
||
1390 | 871 |
!ListModelView methodsFor:'fetch resources'! |
872 |
||
873 |
colorOnDevice:aColor |
|
874 |
"fetch a device colors |
|
875 |
" |
|
2097 | 876 |
^ aColor notNil ifTrue:[aColor onDevice:device] ifFalse:[nil] |
1390 | 877 |
! |
878 |
||
879 |
imageOnDevice:anImage |
|
880 |
"associate image to device and clear pixel mask |
|
881 |
returns the new image. |
|
882 |
" |
|
883 |
|image| |
|
884 |
||
885 |
(image := anImage) notNil ifTrue:[ |
|
2265 | 886 |
image device ~~ device ifTrue:[ |
887 |
image := image copy. |
|
888 |
]. |
|
889 |
image := image onDevice:device. |
|
890 |
image := image clearMaskedPixels. |
|
1390 | 891 |
]. |
892 |
^ image |
|
893 |
! ! |
|
894 |
||
1417 | 895 |
!ListModelView methodsFor:'focus handling'! |
896 |
||
897 |
wantsFocusWithButtonPress |
|
898 |
"catch the keyboard focus on button click |
|
899 |
" |
|
900 |
^ true |
|
901 |
||
902 |
||
903 |
! |
|
904 |
||
905 |
wantsFocusWithPointerEnter |
|
906 |
"views which like to take the keyboard focus |
|
907 |
when the pointer enters can do so by redefining this |
|
908 |
to return true" |
|
909 |
||
910 |
^ true |
|
911 |
||
912 |
! ! |
|
913 |
||
1390 | 914 |
!ListModelView methodsFor:'initialize / release'! |
915 |
||
916 |
create |
|
917 |
"fetch device dependent resources |
|
918 |
" |
|
919 |
super create. |
|
920 |
self fetchResources. |
|
921 |
! |
|
922 |
||
923 |
initStyle |
|
924 |
"setup viewStyle specifics |
|
925 |
" |
|
926 |
super initStyle. |
|
927 |
||
1595 | 928 |
DefaultForegroundColor isNil ifTrue:[ |
2265 | 929 |
self updateStyleCache |
1595 | 930 |
]. |
931 |
||
1390 | 932 |
DefaultBackgroundColor notNil ifTrue:[ |
2265 | 933 |
viewBackground := DefaultBackgroundColor |
1390 | 934 |
]. |
935 |
lineSpacing := 0. |
|
936 |
textStartLeft := 2. |
|
937 |
fgColor := DefaultForegroundColor. |
|
938 |
bgColor := viewBackground. |
|
939 |
startOfLinesY := OrderedCollection new. |
|
940 |
||
941 |
startOfLinesY add:(2 + margin). "/ top inset of first line |
|
942 |
||
943 |
DefaultShadowColor notNil ifTrue:[ |
|
2265 | 944 |
shadowColor := DefaultShadowColor |
1390 | 945 |
]. |
946 |
||
947 |
DefaultLightColor notNil ifTrue:[ |
|
2265 | 948 |
lightColor := DefaultLightColor |
1390 | 949 |
]. |
950 |
! |
|
951 |
||
952 |
initialize |
|
953 |
"setup default attributes |
|
954 |
" |
|
955 |
super initialize. |
|
956 |
||
2261 | 957 |
viewOrigin := 0@0. |
958 |
bitGravity := #NorthWest. |
|
959 |
enabled := true. |
|
960 |
autoScroll := true. |
|
1827 | 961 |
scrollWhenUpdating := #beginOfText. |
2261 | 962 |
hasConstantHeight := false. |
2352 | 963 |
|
964 |
renderer isNil ifTrue:[ |
|
965 |
renderer := self class defaultRenderer forView:self. |
|
966 |
]. |
|
1390 | 967 |
! |
968 |
||
1562 | 969 |
mapped |
970 |
"recompute list |
|
971 |
" |
|
972 |
shown ifFalse:[ |
|
2265 | 973 |
self recomputeHeightOfContents. |
974 |
self contentsChanged. |
|
1562 | 975 |
]. |
976 |
super mapped |
|
977 |
||
978 |
! |
|
979 |
||
1390 | 980 |
recreate |
1832 | 981 |
"sent after a snapin or a migration, reinit for new device" |
1828 | 982 |
|
1390 | 983 |
super recreate. |
984 |
self fetchResources. |
|
1796
c9d801c011f7
recompute layout after snapIn (font geometry could be different)
Claus Gittinger <cg@exept.de>
parents:
1773
diff
changeset
|
985 |
! |
c9d801c011f7
recompute layout after snapIn (font geometry could be different)
Claus Gittinger <cg@exept.de>
parents:
1773
diff
changeset
|
986 |
|
c9d801c011f7
recompute layout after snapIn (font geometry could be different)
Claus Gittinger <cg@exept.de>
parents:
1773
diff
changeset
|
987 |
reinitialize |
c9d801c011f7
recompute layout after snapIn (font geometry could be different)
Claus Gittinger <cg@exept.de>
parents:
1773
diff
changeset
|
988 |
"reinit after snapIn (font geometry might be different) |
c9d801c011f7
recompute layout after snapIn (font geometry could be different)
Claus Gittinger <cg@exept.de>
parents:
1773
diff
changeset
|
989 |
" |
c9d801c011f7
recompute layout after snapIn (font geometry could be different)
Claus Gittinger <cg@exept.de>
parents:
1773
diff
changeset
|
990 |
super reinitialize. |
c9d801c011f7
recompute layout after snapIn (font geometry could be different)
Claus Gittinger <cg@exept.de>
parents:
1773
diff
changeset
|
991 |
self recomputeHeightOfContents. |
c9d801c011f7
recompute layout after snapIn (font geometry could be different)
Claus Gittinger <cg@exept.de>
parents:
1773
diff
changeset
|
992 |
self contentsChanged. |
c9d801c011f7
recompute layout after snapIn (font geometry could be different)
Claus Gittinger <cg@exept.de>
parents:
1773
diff
changeset
|
993 |
|
2156 | 994 |
! |
995 |
||
996 |
release |
|
997 |
"remove dependencies |
|
998 |
" |
|
999 |
listHolder removeDependent:self. |
|
1000 |
list removeDependent:self. |
|
1001 |
||
1002 |
super release |
|
1390 | 1003 |
! ! |
1004 |
||
1005 |
!ListModelView methodsFor:'private'! |
|
1006 |
||
1457 | 1007 |
hasDamage |
1008 |
"return true, if any damage events (i.e. expose or resize) are pending. |
|
1009 |
" |
|
1010 |
|sensor| |
|
1011 |
||
1012 |
^ (sensor := self sensor) isNil or:[sensor hasDamageFor:self] |
|
1013 |
! |
|
1014 |
||
1390 | 1015 |
yAbsoluteOfLine:aLineNr |
1016 |
"given a lineNr, return y-coordinate absolute |
|
1017 |
" |
|
1744 | 1018 |
|y y2 y1 cash| |
1446
fb46beba2d0c
startOfLines can have nil at end; lookup the first not nil
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
1019 |
|
1744 | 1020 |
cash := startOfLinesY. |
1446
fb46beba2d0c
startOfLines can have nil at end; lookup the first not nil
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
1021 |
|
1744 | 1022 |
(y := cash at:aLineNr ifAbsent:nil) notNil ifTrue:[ |
2265 | 1023 |
^ y |
1446
fb46beba2d0c
startOfLines can have nil at end; lookup the first not nil
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
1024 |
]. |
1744 | 1025 |
|
1026 |
"/ recompute a y position |
|
1027 |
y1 := startOfLinesY at:1 ifAbsent:2. |
|
1028 |
y2 := startOfLinesY at:2 ifAbsent:10. |
|
1029 |
^ aLineNr * (y2 - y1) + y1 |
|
1390 | 1030 |
! |
1031 |
||
1032 |
yVisibleOfLine:aLineNr |
|
1033 |
"given a lineNr, return y-coordinate in view |
|
1034 |
" |
|
1744 | 1035 |
^ (self yAbsoluteOfLine:aLineNr) - viewOrigin y |
1390 | 1036 |
|
1037 |
||
1038 |
! |
|
1039 |
||
1040 |
yVisibleToLineNr:yVisible |
|
2301 | 1041 |
"returns the line number assigned to a physical y or nil if out of list |
1390 | 1042 |
" |
2301 | 1043 |
|cash |
1044 |
yAbs "{ Class: SmallInteger}" |
|
1045 |
size "{ Class: SmallInteger}" |
|
1046 |
ictr "{ Class: SmallInteger}" |
|
1047 |
yRun "{ Class: SmallInteger}" |
|
1390 | 1048 |
| |
1643 | 1049 |
cash := startOfLinesY. |
1390 | 1050 |
|
2301 | 1051 |
(size := cash size) < 2 ifTrue:[^ nil]. "/ empty list |
1390 | 1052 |
|
2301 | 1053 |
yAbs := yVisible + viewOrigin y. |
1054 |
yRun := cash at:size. |
|
1390 | 1055 |
|
2301 | 1056 |
yAbs >= yRun ifTrue:[ |
1057 |
yAbs == yRun ifTrue:[ ^ size - 1]. |
|
1058 |
^ nil "/ out of list |
|
1059 |
]. |
|
1390 | 1060 |
|
2301 | 1061 |
constantHeight notNil ifTrue:[ |
1062 |
yAbs := yAbs - (cash at:1). |
|
1063 |
yAbs < constantHeight ifTrue:[ ^ 1 ]. |
|
1064 |
^ yAbs // constantHeight + 1 |
|
1390 | 1065 |
]. |
1066 |
||
2301 | 1067 |
ictr := yAbs // (cash at:2). |
1068 |
ictr < 1 ifTrue:[ ictr := 1 ] |
|
1069 |
ifFalse:[ ictr := ictr min:size ]. |
|
1070 |
||
1071 |
yRun := cash at:ictr. |
|
1072 |
||
1073 |
yRun > yAbs ifTrue:[ |
|
1074 |
[(ictr := ictr - 1) > 0 ] whileTrue:[ |
|
1075 |
yRun := cash at:ictr. |
|
1076 |
yRun <= yAbs ifTrue:[ ^ ictr ]. |
|
1077 |
]. |
|
1078 |
^ 1 |
|
1390 | 1079 |
]. |
2301 | 1080 |
|
1081 |
[ yRun ~~ yAbs ] whileTrue:[ |
|
1082 |
ictr := ictr + 1. |
|
1083 |
yRun := cash at:ictr. |
|
1084 |
yRun > yAbs ifTrue:[ ^ ictr - 1 ]. |
|
1390 | 1085 |
]. |
2301 | 1086 |
^ ictr |
1390 | 1087 |
! ! |
1088 |
||
1089 |
!ListModelView methodsFor:'protocol'! |
|
1090 |
||
1091 |
fetchResources |
|
1092 |
"fetch device colors and ..., to avoid reallocation at redraw time; |
|
1093 |
*** called after a create or snapin to fetch all device resources |
|
1094 |
" |
|
1095 |
fgColor := self colorOnDevice:fgColor. |
|
1096 |
bgColor := self colorOnDevice:bgColor. |
|
2097 | 1097 |
font := font onDevice:device. |
1390 | 1098 |
! |
1099 |
||
2352 | 1100 |
lineHeightFor:anItem |
1101 |
"returns the computed line height for an item |
|
1390 | 1102 |
" |
2352 | 1103 |
^ lineSpacing + (renderer heightFor:anItem) |
1390 | 1104 |
! |
1105 |
||
1106 |
listSizeChanged:anIndex nLines:noLines |
|
1107 |
"list size changed; information is stored to recompute the |
|
1108 |
width if required( preferredExtent, horizontal scroller ... ). |
|
1109 |
see: widthOfContents |
|
1110 |
*** if nLines is negative, lines are removed otherwise added. |
|
1111 |
" |
|
1112 |
|start "{ Class:SmallInteger }" |
|
1113 |
stop "{ Class:SmallInteger }" |
|
1114 |
size "{ Class:SmallInteger }" |
|
1115 |
| |
|
1116 |
preferredExtent := nil. |
|
1117 |
||
1118 |
widthOfContents isNil ifTrue:[ "/ recompute whole list |
|
2265 | 1119 |
^ self |
1390 | 1120 |
]. |
1121 |
||
1122 |
(noLines < 0 or:[(size := list size) <= noLines]) ifTrue:[ |
|
2265 | 1123 |
widthOfContents := nil. "/ force recompute whole list |
1124 |
^ self |
|
1390 | 1125 |
]. |
1126 |
||
1127 |
stop := anIndex + noLines - 1. "/ recompute a range |
|
1128 |
start := anIndex. |
|
1129 |
||
1130 |
computeWidthInRange notNil ifTrue:[ |
|
2265 | 1131 |
start := computeWidthInRange y. |
1132 |
stop < start ifTrue:[stop := start min:size]. |
|
1133 |
start := (computeWidthInRange x) min:anIndex. |
|
1390 | 1134 |
]. |
1135 |
computeWidthInRange := start@stop |
|
1136 |
! |
|
1137 |
||
1457 | 1138 |
lostSynchronisation |
1139 |
"called when the changes derived from the model are faster than the handling |
|
1140 |
" |
|
1141 |
shown ifTrue:[ |
|
2302
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
1142 |
self recomputeHeightOfContents. |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
1143 |
self invalidate. |
5a2a1d5d09f8
remove asynchronous handling of changes; always disabled because doesn't work
ca
parents:
2301
diff
changeset
|
1144 |
self contentsChanged |
1457 | 1145 |
]. |
1146 |
! |
|
1147 |
||
1390 | 1148 |
widthOfWidestLineBetween:firstLine and:lastLine |
1149 |
"return the width in pixels of the widest line in a range |
|
1150 |
" |
|
2265 | 1151 |
|item |
1390 | 1152 |
width "{ Class: SmallInteger }" |
1153 |
| |
|
1154 |
width := textStartLeft. |
|
1155 |
||
1156 |
firstLine to:lastLine do:[:anIndex| |
|
2352 | 1157 |
item := list at:anIndex ifAbsent:nil. |
1508
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1457
diff
changeset
|
1158 |
|
2352 | 1159 |
item isNil ifTrue:[^ width + textStartLeft]. |
1508
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1457
diff
changeset
|
1160 |
|
2352 | 1161 |
width := (renderer widthFor:item) max:width |
1390 | 1162 |
]. |
1163 |
^ width + textStartLeft |
|
1164 |
! ! |
|
1165 |
||
1820 | 1166 |
!ListModelView methodsFor:'queries'! |
1167 |
||
2274
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2265
diff
changeset
|
1168 |
isLineVisible:aLineNr |
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2265
diff
changeset
|
1169 |
"returns true if the line is visible" |
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2265
diff
changeset
|
1170 |
|
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2265
diff
changeset
|
1171 |
^ self isLineVisible:aLineNr in:self extent |
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2265
diff
changeset
|
1172 |
! |
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2265
diff
changeset
|
1173 |
|
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2265
diff
changeset
|
1174 |
isLineVisible:aLineNr in:anExtentPoint |
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2265
diff
changeset
|
1175 |
"returns true if the line is visible" |
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2265
diff
changeset
|
1176 |
|
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2265
diff
changeset
|
1177 |
|y| |
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2265
diff
changeset
|
1178 |
y := self yVisibleOfLine:aLineNr. |
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2265
diff
changeset
|
1179 |
|
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2265
diff
changeset
|
1180 |
^ (y between:margin and:(anExtentPoint y - margin)) |
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2265
diff
changeset
|
1181 |
! |
c973acbc021d
only make selection visible after a resize, if it was visible before
ca
parents:
2265
diff
changeset
|
1182 |
|
1820 | 1183 |
size |
1184 |
"returns number of raws |
|
1185 |
" |
|
1186 |
^ list size |
|
1187 |
||
1188 |
||
1189 |
! ! |
|
1190 |
||
1390 | 1191 |
!ListModelView methodsFor:'recomputation'! |
1192 |
||
1193 |
preferredExtent |
|
1194 |
"returns the preferred extent |
|
1195 |
" |
|
1196 |
|x y| |
|
1197 |
||
1198 |
preferredExtent isNil ifTrue:[ |
|
2265 | 1199 |
y := self heightOfContents. |
1200 |
x := self widthOfContents. |
|
1201 |
preferredExtent := x@y |
|
1390 | 1202 |
]. |
1203 |
^ preferredExtent |
|
1204 |
||
1205 |
||
1206 |
! |
|
1207 |
||
1208 |
recomputeHeightOfContents |
|
1209 |
"recompute all the y positions |
|
1210 |
" |
|
1643 | 1211 |
|newList |
1212 |
yAbs "{ Class: SmallInteger }" |
|
1390 | 1213 |
lnHg "{ Class: SmallInteger }" |
1643 | 1214 |
size "{ Class: SmallInteger }" |
1390 | 1215 |
| |
1216 |
||
1643 | 1217 |
yAbs := startOfLinesY at:1. "/ top inset of first line |
1218 |
size := list size. |
|
1219 |
newList := OrderedCollection new:(size + 1). |
|
1220 |
||
1221 |
newList add:yAbs. |
|
1390 | 1222 |
|
2264 | 1223 |
size == 0 ifTrue:[ |
2265 | 1224 |
startOfLinesY := newList. |
2264 | 1225 |
^ self |
1226 |
]. |
|
1227 |
||
1228 |
hasConstantHeight ifTrue:[ |
|
2265 | 1229 |
constantHeight notNil ifTrue:[ lnHg := constantHeight ] |
1230 |
ifFalse:[ lnHg := self heightOfLineAt:1 ]. |
|
1231 |
||
1232 |
1 to:size do:[:anIndex| |
|
1233 |
newList add:(yAbs := yAbs + lnHg) |
|
1234 |
]. |
|
1235 |
startOfLinesY := newList. |
|
2264 | 1236 |
^ self |
1237 |
]. |
|
1238 |
||
1643 | 1239 |
1 to:size do:[:anIndex| |
2265 | 1240 |
lnHg := self heightOfLineAt:anIndex. |
1241 |
newList add:(yAbs := yAbs + lnHg) |
|
1390 | 1242 |
]. |
1643 | 1243 |
startOfLinesY := newList. |
1390 | 1244 |
! ! |
1245 |
||
1246 |
!ListModelView methodsFor:'scroller interface'! |
|
1247 |
||
1248 |
heightOfContents |
|
1249 |
"return the height of the contents in pixels |
|
1250 |
" |
|
2257
6d59932d078d
avoid returning nil heightOfContents
Claus Gittinger <cg@exept.de>
parents:
2244
diff
changeset
|
1251 |
^ startOfLinesY last ? 0 |
1390 | 1252 |
! |
1253 |
||
2261 | 1254 |
heightOfLineAt:aLineNr |
1255 |
"returns the total height for a line at an index( including lineSpacing ... ) |
|
1256 |
" |
|
1257 |
|item| |
|
1258 |
||
1259 |
hasConstantHeight ifTrue:[ |
|
2352 | 1260 |
constantHeight notNil ifTrue:[ ^ constantHeight ]. |
1261 |
item := list at:1 ifAbsent:nil. |
|
2264 | 1262 |
|
2352 | 1263 |
item notNil ifTrue:[ |
1264 |
constantHeight := self lineHeightFor:item. |
|
1265 |
^ constantHeight |
|
1266 |
] |
|
2264 | 1267 |
] ifFalse:[ |
2352 | 1268 |
item := list at:aLineNr ifAbsent:nil. |
2264 | 1269 |
|
2352 | 1270 |
item notNil ifTrue:[ |
1271 |
^ self lineHeightFor:item |
|
1272 |
] |
|
2261 | 1273 |
]. |
2264 | 1274 |
^ 4 |
2261 | 1275 |
! |
1276 |
||
1390 | 1277 |
innerHeight |
1278 |
"returns the inner height of the contents shown |
|
1279 |
" |
|
1280 |
^ height - margin - margin |
|
1281 |
||
1282 |
! |
|
1283 |
||
1284 |
innerWidth |
|
1285 |
"returns the inner width of the contents shown |
|
1286 |
" |
|
1287 |
^ width - margin - margin |
|
1288 |
||
1289 |
! |
|
1290 |
||
1291 |
maxViewOriginY |
|
1292 |
"returns the maximum possible y of the view origin |
|
1293 |
" |
|
1294 |
^ (self heightOfContents - self innerHeight) max:0 |
|
1295 |
||
1296 |
||
1297 |
! |
|
1298 |
||
1299 |
verticalScrollStep |
|
1300 |
"return the amount to scroll when stepping up/down. |
|
1301 |
" |
|
1302 |
^ 10 |
|
1303 |
||
1304 |
! |
|
1305 |
||
1306 |
viewOrigin |
|
1307 |
"return the viewOrigin; thats the coordinate of the contents |
|
1308 |
which is shown topLeft in the view. |
|
1309 |
" |
|
1310 |
^ viewOrigin |
|
1311 |
||
1312 |
! |
|
1313 |
||
1314 |
widthOfContents |
|
1315 |
"return the width of the contents in pixels |
|
1316 |
" |
|
1317 |
|range |
|
1318 |
size "{ Class:SmallInteger }" |
|
1319 |
start "{ Class:SmallInteger }" |
|
1320 |
stop "{ Class:SmallInteger }" |
|
1321 |
| |
|
1322 |
(widthOfContents notNil and:[computeWidthInRange isNil]) ifTrue:[ |
|
2384 | 1323 |
^ widthOfContents + textStartLeft |
1390 | 1324 |
]. |
1325 |
range := computeWidthInRange. |
|
1326 |
computeWidthInRange := nil. |
|
1327 |
preferredExtent := nil. |
|
2384 | 1328 |
|
1329 |
shown ifFalse:[ ^ 60 ]. |
|
1330 |
||
1331 |
size := list size. |
|
1390 | 1332 |
|
1333 |
size == 0 ifTrue:[ |
|
2384 | 1334 |
widthOfContents := 20. |
1390 | 1335 |
] ifFalse:[ |
2384 | 1336 |
widthOfContents isNil ifTrue:[ |
1337 |
widthOfContents := self widthOfWidestLineBetween:1 and:size |
|
1338 |
] ifFalse:[ |
|
1339 |
start := range x. |
|
1340 |
stop := range y min:size. |
|
1390 | 1341 |
|
2384 | 1342 |
start > stop ifFalse:[ |
1343 |
size := self widthOfWidestLineBetween:start and:stop. |
|
1390 | 1344 |
|
2384 | 1345 |
widthOfContents < size ifTrue:[ |
1346 |
widthOfContents := size |
|
1347 |
] |
|
1348 |
] |
|
1349 |
] |
|
1390 | 1350 |
]. |
1351 |
^ widthOfContents + textStartLeft |
|
1352 |
! |
|
1353 |
||
1354 |
xOriginOfContents |
|
1355 |
"return the horizontal origin of the contents in pixels |
|
1356 |
" |
|
1357 |
^ viewOrigin x |
|
1358 |
||
1359 |
! |
|
1360 |
||
1361 |
yOriginOfContents |
|
1362 |
"return the vertical origin of the contents in pixels |
|
1363 |
" |
|
1364 |
^ viewOrigin y |
|
1365 |
||
1366 |
! ! |
|
1367 |
||
1368 |
!ListModelView methodsFor:'scrolling'! |
|
1369 |
||
1370 |
halfPageDown |
|
1371 |
"scroll down half a page |
|
1372 |
" |
|
1827 | 1373 |
self scrollDown:(height // 2). |
1390 | 1374 |
|
1375 |
! |
|
1376 |
||
1377 |
halfPageUp |
|
1378 |
"scroll up half a page |
|
1379 |
" |
|
1827 | 1380 |
self scrollUp:(height // 2). |
1390 | 1381 |
|
1382 |
! |
|
1383 |
||
2367 | 1384 |
makeLineVisible:aLnNr |
1385 |
"make the line visible |
|
1386 |
" |
|
1387 |
aLnNr notNil ifTrue:[ |
|
1388 |
self scrollToLine:aLnNr |
|
1389 |
]. |
|
1390 |
! |
|
1391 |
||
1390 | 1392 |
scrollTo:anOrigin redraw:doRedraw |
1393 |
"change origin to have newOrigin be visible at the top-left. |
|
1394 |
" |
|
1538 | 1395 |
|newOrg dltOrg winGrp |
1390 | 1396 |
innerWT "{ Class:SmallInteger }" |
1397 |
innerHG "{ Class:SmallInteger }" |
|
1398 |
h "{ Class:SmallInteger }" |
|
1399 |
x "{ Class:SmallInteger }" |
|
1400 |
x0 "{ Class:SmallInteger }" |
|
1401 |
x1 "{ Class:SmallInteger }" |
|
1402 |
y "{ Class:SmallInteger }" |
|
1403 |
w "{ Class:SmallInteger }" |
|
1404 |
y0 "{ Class:SmallInteger }" |
|
1405 |
y1 "{ Class:SmallInteger }" |
|
1406 |
dX "{ Class:SmallInteger }" |
|
1407 |
dY "{ Class:SmallInteger }" |
|
1408 |
| |
|
1531 | 1409 |
|
1580 | 1410 |
realized ifFalse:[ |
2265 | 1411 |
^ self |
1390 | 1412 |
]. |
1580 | 1413 |
|
1390 | 1414 |
innerWT := self innerWidth. |
1415 |
innerHG := self innerHeight. |
|
1416 |
||
1417 |
h := viewOrigin y. |
|
1418 |
||
1419 |
(y := anOrigin y) > h ifTrue:[ "/ end of contents |
|
2265 | 1420 |
y > (dY := self maxViewOriginY) ifTrue:[ |
1421 |
y := dY max:h |
|
1422 |
] |
|
1390 | 1423 |
] ifFalse:[ |
2265 | 1424 |
y := y max:0. |
1390 | 1425 |
]. |
1426 |
||
1427 |
(x := anOrigin x) > 0 ifTrue:[ |
|
2265 | 1428 |
x := x min:(self widthOfContents - innerWT). |
1390 | 1429 |
]. |
1430 |
x := x max:0. |
|
1431 |
newOrg := (x @ y). |
|
1432 |
dltOrg := newOrg - viewOrigin. |
|
1433 |
dX := dltOrg x. |
|
1434 |
dY := dltOrg y. |
|
1435 |
||
1436 |
(dX == 0 and:[dY == 0]) ifTrue:[ |
|
2265 | 1437 |
^ self |
1390 | 1438 |
]. |
1534 | 1439 |
dY := dY abs. |
1440 |
dX := dX abs. |
|
1390 | 1441 |
|
1534 | 1442 |
( (dX ~~ 0 and:[dY ~~ 0]) "/ scroll vertical & horizontal |
1443 |
or:[(innerHG - dY < 20 or:[innerWT - dX < 20])] "/ faster to invalidate screen |
|
1444 |
) ifTrue:[ |
|
2265 | 1445 |
viewOrigin := newOrg. |
1446 |
self originChanged:dltOrg. |
|
1534 | 1447 |
^ self invalidate |
1448 |
]. |
|
1753
17769f8df493
#scrollTo:redraw: first check whether full invalidate otherwise processRealExposeEventsFor:
ca
parents:
1752
diff
changeset
|
1449 |
|
17769f8df493
#scrollTo:redraw: first check whether full invalidate otherwise processRealExposeEventsFor:
ca
parents:
1752
diff
changeset
|
1450 |
(winGrp := self windowGroup) notNil ifTrue:[ |
2265 | 1451 |
winGrp processRealExposeEventsFor:self. |
1753
17769f8df493
#scrollTo:redraw: first check whether full invalidate otherwise processRealExposeEventsFor:
ca
parents:
1752
diff
changeset
|
1452 |
]. |
17769f8df493
#scrollTo:redraw: first check whether full invalidate otherwise processRealExposeEventsFor:
ca
parents:
1752
diff
changeset
|
1453 |
|
17769f8df493
#scrollTo:redraw: first check whether full invalidate otherwise processRealExposeEventsFor:
ca
parents:
1752
diff
changeset
|
1454 |
self originWillChange. |
17769f8df493
#scrollTo:redraw: first check whether full invalidate otherwise processRealExposeEventsFor:
ca
parents:
1752
diff
changeset
|
1455 |
|
17769f8df493
#scrollTo:redraw: first check whether full invalidate otherwise processRealExposeEventsFor:
ca
parents:
1752
diff
changeset
|
1456 |
doRedraw ifFalse:[ |
2265 | 1457 |
viewOrigin := newOrg. |
1458 |
^ self originChanged:dltOrg |
|
1753
17769f8df493
#scrollTo:redraw: first check whether full invalidate otherwise processRealExposeEventsFor:
ca
parents:
1752
diff
changeset
|
1459 |
]. |
17769f8df493
#scrollTo:redraw: first check whether full invalidate otherwise processRealExposeEventsFor:
ca
parents:
1752
diff
changeset
|
1460 |
|
1531 | 1461 |
self catchExpose. |
1462 |
viewOrigin := newOrg. |
|
1463 |
||
1390 | 1464 |
dY ~~ 0 ifTrue:[ "/ SCROLL VERTICAL |
2265 | 1465 |
y0 := y1 := margin + dY. |
1466 |
h := innerHG - dY. |
|
1390 | 1467 |
|
2265 | 1468 |
dltOrg y < 0 ifTrue:[y0 := margin. y := y0] |
1469 |
ifFalse:[y1 := margin. y := y1 + h]. |
|
1390 | 1470 |
|
2265 | 1471 |
self copyFrom:self x:margin y:y0 toX:margin y:y1 width:innerWT height:h async:true. |
1472 |
self invalidateX:margin y:y width:innerWT height:(innerHG - h). |
|
1390 | 1473 |
|
1474 |
] ifFalse:[ "/ SCROLL HORIZONTAL |
|
2265 | 1475 |
x0 := x1 := dX + margin. |
1476 |
w := innerWT - dX. |
|
1390 | 1477 |
|
2265 | 1478 |
dltOrg x < 0 ifTrue:[x0 := x := margin ] |
1479 |
ifFalse:[x1 := margin. x := w]. |
|
1390 | 1480 |
|
2265 | 1481 |
self copyFrom:self x:x0 y:margin toX:x1 y:margin width:w height:innerHG async:true. |
1482 |
self invalidateX:x y:margin width:(width - w) height:innerHG. |
|
1390 | 1483 |
]. |
1484 |
self originChanged:dltOrg. |
|
1531 | 1485 |
self waitForExpose. |
1486 |
||
1390 | 1487 |
! |
1488 |
||
1489 |
scrollToLine:aLineNumber |
|
1490 |
"make line visible |
|
1491 |
" |
|
1744 | 1492 |
|inHg "{ Class:SmallInteger }" |
1493 |
yTop "{ Class:SmallInteger }" |
|
1494 |
orgY "{ Class:SmallInteger }" |
|
1495 |
yBot "{ Class:SmallInteger }" |
|
1390 | 1496 |
| |
1744 | 1497 |
(shown and:[aLineNumber notNil and:[aLineNumber between:1 and:list size]]) ifFalse:[ |
2265 | 1498 |
^ self |
1390 | 1499 |
]. |
1500 |
||
1744 | 1501 |
yTop := self yAbsoluteOfLine:aLineNumber. |
1502 |
inHg := self innerHeight. |
|
1503 |
orgY := viewOrigin y. |
|
1504 |
||
1505 |
yTop > orgY ifTrue:[ |
|
2265 | 1506 |
yBot := self yAbsoluteOfLine:(aLineNumber + 1). |
1390 | 1507 |
|
2265 | 1508 |
yBot <= (orgY + inHg) ifTrue:[ |
1509 |
^ self |
|
1510 |
]. |
|
1390 | 1511 |
]. |
1744 | 1512 |
yTop := (yTop - (inHg // 2)) max:0. |
1513 |
self scrollTo:(viewOrigin x @ yTop). |
|
1390 | 1514 |
|
1515 |
||
1516 |
! ! |
|
1517 |
||
1748 | 1518 |
!ListModelView methodsFor:'scrolling auto'! |
1519 |
||
1520 |
startAutoScroll:aBlock distance:aDistance |
|
1521 |
"setup for auto-scroll (when button-press-moving below view); |
|
1522 |
- timeDelta for scroll is computed from distance |
|
1523 |
" |
|
1524 |
|timeDelta| |
|
1525 |
||
1526 |
(autoScroll and:[aBlock notNil]) ifFalse:[ |
|
2265 | 1527 |
^ self stopAutoScroll |
1748 | 1528 |
]. |
1529 |
autoScrollBlock notNil ifTrue:[ |
|
2265 | 1530 |
Processor removeTimedBlock:autoScrollBlock. |
1748 | 1531 |
] ifFalse:[ |
2265 | 1532 |
self compressMotionEvents:false. |
1748 | 1533 |
]. |
1534 |
||
1535 |
timeDelta := 0.5 / (aDistance abs). |
|
1536 |
||
1537 |
autoScrollBlock := [ |
|
2265 | 1538 |
aBlock value. |
1539 |
Processor addTimedBlock:autoScrollBlock afterSeconds:timeDelta. |
|
1748 | 1540 |
]. |
1541 |
Processor addTimedBlock:autoScrollBlock afterSeconds:timeDelta. |
|
1542 |
||
1543 |
! |
|
1544 |
||
1545 |
stopAutoScroll |
|
1546 |
"stop any autoScroll |
|
1547 |
" |
|
1548 |
autoScrollBlock notNil ifTrue:[ |
|
2265 | 1549 |
Processor removeTimedBlock:autoScrollBlock. |
1550 |
autoScrollBlock := nil. |
|
1551 |
self compressMotionEvents:true. |
|
1748 | 1552 |
]. |
1553 |
! ! |
|
1554 |
||
2352 | 1555 |
!ListModelView::Renderer class methodsFor:'documentation'! |
1556 |
||
1557 |
documentation |
|
1558 |
" |
|
1559 |
prepared for ListItemRenderer |
|
1560 |
.... SelectionItemRenderer ... |
|
1561 |
||
1562 |
goal: |
|
1563 |
allow the user to redefine the display operation and the dimesion queries |
|
1564 |
" |
|
1565 |
! ! |
|
1566 |
||
1567 |
!ListModelView::Renderer class methodsFor:'instance creation'! |
|
1568 |
||
1569 |
forView:aView |
|
1570 |
|renderer| |
|
1571 |
||
1572 |
renderer := self basicNew initialize. |
|
1573 |
renderer forView:aView. |
|
1574 |
^ renderer |
|
1575 |
! ! |
|
1576 |
||
1577 |
!ListModelView::Renderer methodsFor:'displaying'! |
|
1578 |
||
1579 |
display:anItem atX:xLeft y:yTop lineHeight:h |
|
1580 |
"display the item on the view |
|
1581 |
" |
|
1582 |
|x0 y0 label| |
|
1583 |
||
1584 |
x0 := xLeft. |
|
1585 |
y0 := yTop. |
|
1586 |
||
1587 |
anItem isHierarchicalItem ifTrue:[ |
|
1588 |
anItem displayOn:view x:x0 y:y0 h:h |
|
1589 |
] ifFalse:[ |
|
1590 |
anItem isNil ifTrue:[^ self]. |
|
1591 |
||
1592 |
y0 := y0 - ((self heightFor:anItem) + 1 - h // 2). |
|
1593 |
label := anItem. |
|
1594 |
||
1595 |
label isImageOrForm ifFalse:[ |
|
1596 |
label isNumber ifTrue:[ |
|
1597 |
label := label printString |
|
1598 |
]. |
|
1599 |
y0 := y0 + view font ascent |
|
1600 |
]. |
|
1601 |
label displayOn:view x:x0 y:y0 |
|
1602 |
]. |
|
1603 |
! ! |
|
1604 |
||
1605 |
!ListModelView::Renderer methodsFor:'instance creation'! |
|
1606 |
||
1607 |
forView:aView |
|
1608 |
view := aView. |
|
1609 |
! ! |
|
1610 |
||
1611 |
!ListModelView::Renderer methodsFor:'queries-dimensions'! |
|
1612 |
||
1613 |
heightFor:anItem |
|
1614 |
"returns the height of an item on the view |
|
1615 |
" |
|
1616 |
^ anItem heightOn:view |
|
1617 |
! |
|
1618 |
||
1619 |
widthFor:anItem |
|
1620 |
"returns the width of an item on the view |
|
1621 |
" |
|
1622 |
^ anItem widthOn:view |
|
1623 |
! ! |
|
1624 |
||
1390 | 1625 |
!ListModelView class methodsFor:'documentation'! |
1626 |
||
1627 |
version |
|
2385 | 1628 |
^ '$Header: /cvs/stx/stx/libwidg2/ListModelView.st,v 1.72 2002-11-20 15:20:26 ca Exp $' |
1390 | 1629 |
! ! |
2244
c9a195d28e72
change #redrawLineAt: to #invalidateLineAt: (because is a invalidate)
ca
parents:
2188
diff
changeset
|
1630 |
|
1390 | 1631 |
ListModelView initialize! |