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