author | Claus Gittinger <cg@exept.de> |
Wed, 06 Sep 2000 15:48:37 +0200 | |
changeset 1832 | f6e6640e99a3 |
parent 1828 | ea1f39c639f8 |
child 1845 | 3eedddfdfc54 |
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 |
||
335 |
(font width) ~~ oldWidth ifTrue:[ "/ force a recomputation |
|
336 |
preferredExtent := nil. |
|
337 |
widthOfContents := nil. |
|
338 |
]. |
|
339 |
oldHeight ~~ font height ifTrue:[ |
|
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 |
||
365 |
! ! |
|
366 |
||
1818 | 367 |
!ListModelView methodsFor:'accessing-mvc'! |
1390 | 368 |
|
369 |
listHolder |
|
370 |
"returns the listHolder or nil |
|
371 |
" |
|
372 |
^ listHolder |
|
373 |
! |
|
374 |
||
375 |
listHolder:aListHolder |
|
376 |
"set a new listHolder |
|
377 |
" |
|
378 |
|newList| |
|
379 |
||
380 |
listHolder removeDependent:self. |
|
381 |
||
382 |
(listHolder := aListHolder) notNil ifTrue:[ |
|
383 |
listHolder addDependent:self. |
|
384 |
]. |
|
385 |
self list:(listHolder value). |
|
386 |
! ! |
|
387 |
||
1818 | 388 |
!ListModelView methodsFor:'accessing-views'! |
1535
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
389 |
|
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
390 |
destroyFrame:aFrame |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
391 |
"destroy a frame |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
392 |
" |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
393 |
aFrame notNil ifTrue:[ |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
394 |
displayedFrames removeKey:aFrame ifAbsent:nil. |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
395 |
aFrame destroy. |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
396 |
]. |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
397 |
! |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
398 |
|
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
399 |
registerFrame:aView atLine:aLineNr x:logX width:w |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
400 |
"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
|
401 |
" |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
402 |
|x y h item index| |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
403 |
|
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
404 |
(item := list at:aLineNr ifAbsent:nil) isNil ifTrue:[ |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
405 |
^ self |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
406 |
]. |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
407 |
y := self yVisibleOfLine:aLineNr. |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
408 |
x := logX - viewOrigin x. |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
409 |
h := (startOfLinesY at:(aLineNr + 1)) - (startOfLinesY at:aLineNr). |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
410 |
|
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
411 |
aView origin:(x@y) extent:(w@h). |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
412 |
self addSubView:aView. |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
413 |
displayedFrames at:aView put:item. |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
414 |
realized ifTrue:[aView realize]. |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
415 |
! ! |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
416 |
|
1390 | 417 |
!ListModelView methodsFor:'change & update'! |
418 |
||
1535
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
419 |
contentsChanged |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
420 |
"contents changed; recompute origin Y of registered views |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
421 |
" |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
422 |
|idx y x| |
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 |
displayedFrames keysAndValuesDo:[:aFrame :anItem| |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
425 |
(idx := list identityIndexOf:anItem) == 0 ifTrue:[ |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
426 |
aFrame beInvisible. |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
427 |
] ifFalse:[ |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
428 |
y := self yVisibleOfLine:idx. |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
429 |
x := aFrame origin x. |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
430 |
aFrame origin:(x @ y). |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
431 |
aFrame beVisible. |
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 |
]. |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
434 |
super contentsChanged. |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
435 |
|
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
436 |
! |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
437 |
|
1390 | 438 |
lineChangedAt:aLnNr with:arg |
439 |
"line changed at position; check whether line height changed |
|
440 |
" |
|
441 |
| |
|
442 |
oldHeight "{ Class:SmallInteger }" |
|
443 |
dltHeight "{ Class:SmallInteger }" |
|
444 |
| |
|
445 |
||
446 |
||
447 |
(arg notNil and:[(arg == #icon or:[arg == #hierarchy])]) ifTrue:[ |
|
448 |
^ self |
|
449 |
]. |
|
450 |
oldHeight := (self yVisibleOfLine:(aLnNr + 1)) - (self yVisibleOfLine:aLnNr). |
|
451 |
dltHeight := (self heightOfLineAt:aLnNr) - oldHeight. |
|
452 |
||
453 |
dltHeight == 0 ifTrue:[ |
|
454 |
^ self redrawLineAt:aLnNr |
|
455 |
]. |
|
456 |
||
457 |
aLnNr + 1 to:startOfLinesY size do:[:i| |
|
458 |
startOfLinesY at:i put:((startOfLinesY at:i) + dltHeight) |
|
459 |
]. |
|
460 |
self invalidate. |
|
461 |
||
462 |
||
463 |
! |
|
464 |
||
465 |
listChangedInsert:start nItems:nLines |
|
466 |
"list changed; items are added |
|
467 |
" |
|
1457 | 468 |
| |
1390 | 469 |
run "{ Class: SmallInteger }" |
1457 | 470 |
newSz "{ Class: SmallInteger }" |
1390 | 471 |
cpyHg "{ Class: SmallInteger }" |
472 |
absY0 "{ Class: SmallInteger }" |
|
473 |
absY1 "{ Class: SmallInteger }" |
|
474 |
visY0 "{ Class: SmallInteger }" |
|
475 |
visY1 "{ Class: SmallInteger }" |
|
476 |
orgY "{ Class: SmallInteger }" |
|
477 |
dltY "{ Class: SmallInteger }" |
|
478 |
maxHg "{ Class: SmallInteger }" |
|
479 |
| |
|
480 |
||
481 |
nLines == 0 ifTrue:[^ self ]. |
|
482 |
self listSizeChanged:start nLines:nLines. |
|
483 |
shown not ifTrue:[^ self]. |
|
484 |
||
1457 | 485 |
newSz := startOfLinesY size + nLines. |
486 |
||
487 |
(newSz - 1) ~~ list size ifTrue:[ |
|
488 |
"/ |
|
489 |
"/ no longer synchrounous |
|
490 |
"/ |
|
491 |
^ self lostSynchronisation |
|
1451 | 492 |
]. |
493 |
||
1390 | 494 |
startOfLinesY addAll:(Array new:nLines) beforeIndex:start + 1. |
495 |
absY0 := startOfLinesY at:start. |
|
496 |
absY1 := absY0. |
|
497 |
run := start. |
|
498 |
||
499 |
nLines timesRepeat:[ |
|
500 |
absY1 := absY1 + (self heightOfLineAt:run). |
|
501 |
run := run + 1. |
|
502 |
startOfLinesY at:run put:absY1. |
|
503 |
]. |
|
504 |
dltY := absY1 - absY0. |
|
1457 | 505 |
|
506 |
run + 1 to:newSz do:[:i||v| |
|
1390 | 507 |
startOfLinesY at:i put:((startOfLinesY at:i) + dltY) |
508 |
]. |
|
509 |
||
510 |
orgY := viewOrigin y. |
|
511 |
absY1 := absY0 + dltY. |
|
512 |
visY0 := absY0 - orgY. |
|
513 |
visY1 := absY1 - orgY. |
|
514 |
maxHg := height - margin. |
|
515 |
||
516 |
absY0 < orgY ifTrue:[ |
|
517 |
self originWillChange. |
|
518 |
viewOrigin y:(dltY + orgY). |
|
519 |
self originChanged:(0 @ dltY). |
|
520 |
]. |
|
1457 | 521 |
|
1390 | 522 |
(visY0 >= maxHg or:[visY1 <= margin]) ifTrue:[ |
523 |
^ self contentsChanged |
|
524 |
]. |
|
525 |
visY0 := visY0 max:margin. |
|
526 |
visY1 := visY1 min:maxHg. |
|
527 |
||
1773
9dba0f0dda0e
invalidate uptoend not all if a damage exists (insert/remove)
ca
parents:
1753
diff
changeset
|
528 |
self hasDamage ifTrue:[ |
9dba0f0dda0e
invalidate uptoend not all if a damage exists (insert/remove)
ca
parents:
1753
diff
changeset
|
529 |
self invalidate:(Rectangle left:0 |
9dba0f0dda0e
invalidate uptoend not all if a damage exists (insert/remove)
ca
parents:
1753
diff
changeset
|
530 |
top:visY0 |
9dba0f0dda0e
invalidate uptoend not all if a damage exists (insert/remove)
ca
parents:
1753
diff
changeset
|
531 |
width:width |
9dba0f0dda0e
invalidate uptoend not all if a damage exists (insert/remove)
ca
parents:
1753
diff
changeset
|
532 |
height:height - visY0). |
9dba0f0dda0e
invalidate uptoend not all if a damage exists (insert/remove)
ca
parents:
1753
diff
changeset
|
533 |
|
9dba0f0dda0e
invalidate uptoend not all if a damage exists (insert/remove)
ca
parents:
1753
diff
changeset
|
534 |
^ self contentsChanged. |
9dba0f0dda0e
invalidate uptoend not all if a damage exists (insert/remove)
ca
parents:
1753
diff
changeset
|
535 |
]. |
9dba0f0dda0e
invalidate uptoend not all if a damage exists (insert/remove)
ca
parents:
1753
diff
changeset
|
536 |
|
1390 | 537 |
(start == list size or:[(cpyHg := maxHg - visY1) < 20]) ifTrue:[ |
538 |
visY1 := maxHg |
|
539 |
] ifFalse:[ |
|
540 |
self catchExpose. |
|
541 |
||
542 |
self copyFrom:self x:0 y:visY0 |
|
543 |
toX:0 y:visY1 |
|
544 |
width:width height:cpyHg async:true. |
|
545 |
||
546 |
self waitForExpose |
|
547 |
]. |
|
548 |
||
1457 | 549 |
self invalidateX:margin |
550 |
y:visY0 |
|
551 |
width:width - margin - margin |
|
552 |
height:(visY1 - visY0). |
|
553 |
||
1390 | 554 |
self contentsChanged. |
555 |
||
556 |
||
1457 | 557 |
|
1390 | 558 |
! |
559 |
||
1446
fb46beba2d0c
startOfLines can have nil at end; lookup the first not nil
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
560 |
listChangedRemove:aStart toIndex:aStop |
1390 | 561 |
"list changed; items are removed |
562 |
" |
|
563 |
|noRedraw |
|
564 |
size "{ Class: SmallInteger }" |
|
565 |
absY0 "{ Class: SmallInteger }" |
|
566 |
absY1 "{ Class: SmallInteger }" |
|
567 |
visY0 "{ Class: SmallInteger }" |
|
568 |
visY1 "{ Class: SmallInteger }" |
|
569 |
orgY "{ Class: SmallInteger }" |
|
570 |
orgX "{ Class: SmallInteger }" |
|
571 |
dltY "{ Class: SmallInteger }" |
|
572 |
cpyHg "{ Class: SmallInteger }" |
|
573 |
maxHg "{ Class: SmallInteger }" |
|
1444
0b7cd00e2537
check range before delete lines
Claus Gittinger <cg@exept.de>
parents:
1443
diff
changeset
|
574 |
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
|
575 |
start "{ Class: SmallInteger }" |
1457 | 576 |
newSz "{ Class: SmallInteger }" |
1390 | 577 |
| |
1446
fb46beba2d0c
startOfLines can have nil at end; lookup the first not nil
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
578 |
stop := aStop. |
fb46beba2d0c
startOfLines can have nil at end; lookup the first not nil
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
579 |
start := aStart. |
1390 | 580 |
|
1446
fb46beba2d0c
startOfLines can have nil at end; lookup the first not nil
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
581 |
(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
|
582 |
^ self |
1390 | 583 |
]. |
1446
fb46beba2d0c
startOfLines can have nil at end; lookup the first not nil
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
584 |
|
1390 | 585 |
self listSizeChanged:start nLines:(size negated). |
586 |
shown not ifTrue:[^ self]. |
|
1451 | 587 |
|
1457 | 588 |
newSz := startOfLinesY size - size. |
589 |
||
590 |
(newSz - 1) ~~ list size ifTrue:[ |
|
591 |
"/ |
|
592 |
"/ no longer synchrounous |
|
593 |
"/ |
|
594 |
^ self lostSynchronisation |
|
1451 | 595 |
]. |
596 |
||
1390 | 597 |
absY0 := self yAbsoluteOfLine:start. |
1457 | 598 |
absY1 := self yAbsoluteOfLine:stop + 1. |
1390 | 599 |
dltY := absY1 - absY0. |
600 |
||
1457 | 601 |
startOfLinesY removeFromIndex:(start + 1) toIndex:(stop + 1). |
1390 | 602 |
|
1457 | 603 |
(start + 1) to:newSz do:[:i| |
1390 | 604 |
absY0 := startOfLinesY at:i. |
605 |
startOfLinesY at:i put:(absY0 - dltY). |
|
606 |
]. |
|
607 |
||
608 |
orgY := viewOrigin y. |
|
609 |
orgX := viewOrigin x. |
|
610 |
||
611 |
absY0 := self yAbsoluteOfLine:start. |
|
612 |
absY1 := absY0 + dltY. |
|
613 |
visY0 := absY0 - orgY. |
|
614 |
visY1 := absY1 - orgY. |
|
615 |
maxHg := height - margin. |
|
616 |
||
617 |
(list size == 0 or:[(orgY ~~ 0 and:[self maxViewOriginY == 0])]) ifTrue:[ |
|
618 |
(orgX ~~ 0 or:[orgY ~~ 0]) ifTrue:[ |
|
619 |
self originWillChange. |
|
620 |
viewOrigin := 0@0. |
|
621 |
self originChanged:((orgX @ orgY) negated). |
|
622 |
]. |
|
623 |
self invalidate. |
|
624 |
^ self contentsChanged |
|
625 |
]. |
|
626 |
||
627 |
visY0 < margin ifTrue:[ |
|
628 |
noRedraw := visY1 <= margin. |
|
629 |
noRedraw ifTrue:[dltY := dltY negated] ifFalse:[dltY := visY0]. |
|
630 |
||
631 |
self originWillChange. |
|
632 |
viewOrigin y:(dltY + orgY). |
|
633 |
self originChanged:(0 @ dltY). |
|
634 |
] ifFalse:[ |
|
635 |
noRedraw := visY0 >= maxHg |
|
636 |
]. |
|
1773
9dba0f0dda0e
invalidate uptoend not all if a damage exists (insert/remove)
ca
parents:
1753
diff
changeset
|
637 |
visY0 := visY0 max:margin. |
9dba0f0dda0e
invalidate uptoend not all if a damage exists (insert/remove)
ca
parents:
1753
diff
changeset
|
638 |
|
1457 | 639 |
self hasDamage ifTrue:[ |
1773
9dba0f0dda0e
invalidate uptoend not all if a damage exists (insert/remove)
ca
parents:
1753
diff
changeset
|
640 |
self invalidate:(Rectangle left:0 |
9dba0f0dda0e
invalidate uptoend not all if a damage exists (insert/remove)
ca
parents:
1753
diff
changeset
|
641 |
top:visY0 |
9dba0f0dda0e
invalidate uptoend not all if a damage exists (insert/remove)
ca
parents:
1753
diff
changeset
|
642 |
width:width |
9dba0f0dda0e
invalidate uptoend not all if a damage exists (insert/remove)
ca
parents:
1753
diff
changeset
|
643 |
height:height - visY0). |
9dba0f0dda0e
invalidate uptoend not all if a damage exists (insert/remove)
ca
parents:
1753
diff
changeset
|
644 |
|
1457 | 645 |
noRedraw := true |
646 |
]. |
|
1390 | 647 |
|
1457 | 648 |
noRedraw ifFalse:[ |
1390 | 649 |
cpyHg := maxHg - visY1. |
650 |
||
651 |
cpyHg > 20 ifTrue:[ |
|
652 |
self catchExpose. |
|
653 |
self copyFrom:self x:0 y:visY1 toX:0 y:visY0 |
|
654 |
width:width height:cpyHg async:true. |
|
655 |
self waitForExpose. |
|
656 |
visY0 := visY0 + cpyHg. |
|
657 |
]. |
|
658 |
||
1457 | 659 |
self invalidateX:margin |
660 |
y:visY0 |
|
661 |
width:width - margin - margin |
|
662 |
height:(maxHg - visY0). |
|
1390 | 663 |
]. |
664 |
self contentsChanged. |
|
665 |
! |
|
666 |
||
1535
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
667 |
originChanged:aDelta |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
668 |
"change origin of registered views |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
669 |
" |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
670 |
displayedFrames keys do:[:aFrame| |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
671 |
aFrame origin:(aFrame origin - aDelta) |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
672 |
]. |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
673 |
super originChanged:aDelta. |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
674 |
|
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
675 |
! |
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
676 |
|
1443 | 677 |
syncUpdate:what with:args |
678 |
"handle synchronous change |
|
1390 | 679 |
" |
1443 | 680 |
|a1 a2| |
1390 | 681 |
|
1443 | 682 |
args isCollection ifFalse:[ |
683 |
what == #at: ifTrue:[self lineChangedAt:args with:nil] |
|
684 |
ifFalse:[what == #insert: ifTrue:[self listChangedInsert:args nItems:1] |
|
685 |
ifFalse:[what == #remove: ifTrue:[self listChangedRemove:args toIndex:args]]] |
|
686 |
] ifTrue:[ |
|
687 |
a1 := args at:1. |
|
688 |
a2 := args at:2. |
|
1390 | 689 |
|
1443 | 690 |
what == #at: ifTrue:[self lineChangedAt:a1 with:a2] |
691 |
ifFalse:[what == #insertCollection: ifTrue:[self listChangedInsert:a1 nItems:a2] |
|
692 |
ifFalse:[what == #removeFrom: ifTrue:[self listChangedRemove:a1 toIndex:a2] |
|
693 |
ifFalse:[what == #replace: ifTrue:[ |
|
694 |
a1 to:a2 do:[:i|self lineChangedAt:i with:nil] |
|
695 |
]]]] |
|
1390 | 696 |
] |
697 |
||
698 |
||
699 |
||
700 |
||
701 |
||
1443 | 702 |
! |
703 |
||
704 |
update:what with:aPara from:chgObj |
|
705 |
"catch and handle any notification raised from the list model |
|
706 |
or list holder |
|
707 |
" |
|
1773
9dba0f0dda0e
invalidate uptoend not all if a damage exists (insert/remove)
ca
parents:
1753
diff
changeset
|
708 |
|
1443 | 709 |
chgObj ~~ list ifTrue:[ |
710 |
chgObj == listHolder ifTrue:[ |
|
1554 | 711 |
self syncPushEvent:#list: with:(listHolder value) |
1443 | 712 |
] ifFalse:[ |
713 |
super update:what with:aPara from:chgObj |
|
714 |
]. |
|
715 |
^ self |
|
716 |
]. |
|
717 |
||
718 |
( #( insert: |
|
719 |
remove: |
|
720 |
removeFrom: |
|
721 |
insertCollection: |
|
722 |
at: |
|
723 |
replace: |
|
724 |
) includes:what |
|
725 |
) ifTrue:[ |
|
1456 | 726 |
(aPara isCollection and:[(aPara at:1) == 1 and:[(aPara at:2) == list size]]) ifTrue:[ |
1451 | 727 |
self list:list |
1443 | 728 |
] ifFalse:[ |
1554 | 729 |
self syncPushEvent:#syncUpdate:with: with:what with:aPara |
1443 | 730 |
] |
731 |
] |
|
1390 | 732 |
! ! |
733 |
||
734 |
!ListModelView methodsFor:'drawing'! |
|
735 |
||
1532
56e0fafc4349
change display protocol for item
Claus Gittinger <cg@exept.de>
parents:
1531
diff
changeset
|
736 |
displayElement:anItem x:x y:y h:h |
56e0fafc4349
change display protocol for item
Claus Gittinger <cg@exept.de>
parents:
1531
diff
changeset
|
737 |
"draw a label at x/y; fg/bg colors are already set |
1390 | 738 |
" |
1634 | 739 |
|ok label |
1532
56e0fafc4349
change display protocol for item
Claus Gittinger <cg@exept.de>
parents:
1531
diff
changeset
|
740 |
y0 "{ Class: SmallInteger }" |
1390 | 741 |
| |
1752 | 742 |
anItem isHierarchicalItem ifTrue:[ |
1532
56e0fafc4349
change display protocol for item
Claus Gittinger <cg@exept.de>
parents:
1531
diff
changeset
|
743 |
anItem displayOn:self x:x y:y h:h |
1399 | 744 |
] ifFalse:[ |
1634 | 745 |
y0 := y - ((anItem heightOn:self) + 1 - h // 2). |
746 |
label := anItem. |
|
1390 | 747 |
|
1634 | 748 |
label isImageOrForm ifFalse:[ |
749 |
label isNumber ifTrue:[ |
|
750 |
label := label printString |
|
751 |
]. |
|
752 |
y0 := y0 + font ascent |
|
1390 | 753 |
]. |
1634 | 754 |
label displayOn:self x:x y:y0 |
1390 | 755 |
] |
756 |
||
757 |
||
758 |
! |
|
759 |
||
1391 | 760 |
invalidateX:x y:y width:w height:h |
761 |
"add a damage to redraw part of the view |
|
1390 | 762 |
" |
1399 | 763 |
shown ifTrue:[ |
764 |
self invalidate:(Rectangle left:x top:y width:w height:h) |
|
765 |
repairNow:false |
|
766 |
] |
|
767 |
! |
|
768 |
||
769 |
redraw |
|
770 |
"redraw complete view |
|
771 |
" |
|
772 |
self redrawX:0 y:0 width:width height:height. |
|
773 |
||
774 |
||
1390 | 775 |
! |
776 |
||
777 |
redrawLineAt:aLineNr |
|
778 |
"redraw a specific line |
|
779 |
" |
|
780 |
|y0 "{ Class:SmallInteger }" |
|
781 |
y1 "{ Class:SmallInteger }" |
|
782 |
yB "{ Class:SmallInteger }" |
|
783 |
| |
|
784 |
||
785 |
(shown and:[aLineNr notNil]) ifTrue:[ |
|
786 |
yB := height - margin. |
|
787 |
y0 := (self yVisibleOfLine:aLineNr) max:margin. |
|
788 |
||
789 |
y0 < yB ifTrue:[ |
|
790 |
y1 := (self yVisibleOfLine:(aLineNr + 1)) min:yB. |
|
791 |
y1 > margin ifTrue:[ |
|
1566 | 792 |
self invalidateX:0 y:y0 width:width height:(y1 - y0) |
1390 | 793 |
] |
794 |
] |
|
795 |
] |
|
796 |
||
797 |
! |
|
798 |
||
799 |
redrawX:x y:y width:w height:h |
|
800 |
"redraw part of myself immediately, given logical coordinates |
|
801 |
" |
|
802 |
|savClip start stop yAbs| |
|
803 |
||
804 |
shown ifFalse:[^ self]. |
|
805 |
||
806 |
self paint:bgColor. |
|
807 |
self fillRectangleX:x y:y width:w height:h. |
|
808 |
||
1615 | 809 |
widthOfContents isNil ifTrue:[self preferredExtent]. |
810 |
||
1390 | 811 |
(start := self yVisibleToLineNr:y) isNil ifTrue:[ |
812 |
^ self |
|
813 |
]. |
|
814 |
yAbs := y + h. |
|
815 |
||
816 |
(stop := self yVisibleToLineNr:yAbs) isNil ifTrue:[ |
|
817 |
stop := list size. |
|
818 |
] ifFalse:[ |
|
819 |
yAbs == (startOfLinesY at:stop) ifTrue:[ |
|
1531 | 820 |
stop := (stop - 1) max:start |
1390 | 821 |
]. |
822 |
]. |
|
823 |
||
824 |
savClip := clipRect. |
|
825 |
self clippingRectangle:(Rectangle left:x top:y width:w height:h). |
|
826 |
||
827 |
StopRedrawSignal handle:[:ex| self invalidate. |
|
828 |
ex return |
|
829 |
] do:[ self drawFrom:start |
|
830 |
to:stop |
|
831 |
x:x |
|
832 |
y:(self yVisibleOfLine:start) |
|
1532
56e0fafc4349
change display protocol for item
Claus Gittinger <cg@exept.de>
parents:
1531
diff
changeset
|
833 |
w:w |
1390 | 834 |
]. |
835 |
||
836 |
self clippingRectangle:savClip. |
|
837 |
||
838 |
||
839 |
||
840 |
||
841 |
! ! |
|
842 |
||
843 |
!ListModelView methodsFor:'event handling'! |
|
844 |
||
845 |
keyPress:aKey x:x y:y |
|
846 |
"a key was pressed - handle page-keys here |
|
847 |
" |
|
848 |
<resource: #keyboard( #PreviousPage #NextPage #HalfPageUp #HalfPageDown |
|
849 |
#BeginOfText #EndOfText #ScrollUp #ScrollDown |
|
850 |
)> |
|
851 |
||
852 |
|n sensor| |
|
853 |
||
854 |
list size ~~ 0 ifTrue:[ |
|
855 |
(aKey == #PreviousPage) ifTrue:[^ self pageUp]. |
|
856 |
(aKey == #NextPage) ifTrue:[^ self pageDown]. |
|
857 |
(aKey == #HalfPageUp) ifTrue:[^ self halfPageUp]. |
|
858 |
(aKey == #HalfPageDown) ifTrue:[^ self halfPageDown]. |
|
859 |
(aKey == #BeginOfText) ifTrue:[^ self scrollToTop]. |
|
860 |
(aKey == #EndOfText) ifTrue:[^ self scrollToBottom]. |
|
861 |
||
862 |
(aKey == #ScrollUp or:[aKey == #ScrollDown]) ifTrue:[ |
|
863 |
sensor := self sensor. |
|
864 |
||
865 |
n := sensor notNil ifTrue:[1 + (sensor compressKeyPressEventsWithKey:aKey)] |
|
866 |
ifFalse:[1]. |
|
867 |
||
868 |
n := n * self verticalScrollStep. |
|
869 |
||
870 |
aKey == #ScrollUp ifTrue:[self scrollUp:n] |
|
871 |
ifFalse:[self scrollDown:n]. |
|
872 |
^ self |
|
873 |
]. |
|
874 |
]. |
|
875 |
super keyPress:aKey x:x y:y |
|
876 |
! ! |
|
877 |
||
1554 | 878 |
!ListModelView methodsFor:'event simulation'! |
879 |
||
880 |
syncFlushEvent:aSelector |
|
881 |
"throw away all pending syncronization events for a specific selector |
|
882 |
" |
|
883 |
|sensor| |
|
884 |
||
885 |
(syncronizeEvents and:[(sensor := self sensor) notNil]) ifTrue:[ |
|
886 |
sensor flushUserEventsFor:self withType:aSelector |
|
887 |
] |
|
888 |
||
889 |
! |
|
890 |
||
891 |
syncPushEvent:aSelector |
|
892 |
"if events are synchronized, the message send is pushed into my |
|
893 |
event queue and will be performed when its time to handle events. |
|
894 |
Otherwise the event is handled immediately |
|
895 |
" |
|
896 |
|sensor| |
|
897 |
||
898 |
(syncronizeEvents and:[(sensor := self sensor) notNil]) ifTrue:[ |
|
899 |
sensor pushUserEvent:aSelector for:self withArguments:#() |
|
900 |
] ifFalse:[ |
|
901 |
self perform:aSelector |
|
902 |
] |
|
903 |
||
904 |
||
905 |
! |
|
906 |
||
907 |
syncPushEvent:aSelector with:arg |
|
908 |
"if events are synchronized, the message send is pushed into my |
|
909 |
event queue and will be performed when its time to handle events. |
|
910 |
Otherwise the event is handled immediately |
|
911 |
" |
|
912 |
|sensor| |
|
913 |
||
914 |
(syncronizeEvents and:[(sensor := self sensor) notNil]) ifTrue:[ |
|
915 |
sensor pushUserEvent:aSelector for:self withArguments:(Array with:arg) |
|
916 |
] ifFalse:[ |
|
917 |
self perform:aSelector with:arg |
|
918 |
] |
|
919 |
||
920 |
! |
|
921 |
||
922 |
syncPushEvent:aSelector with:arg1 with:arg2 |
|
923 |
"if events are synchronized, the message send is pushed into my |
|
924 |
event queue and will be performed when its time to handle events. |
|
925 |
Otherwise the event is handled immediately |
|
926 |
" |
|
927 |
|sensor| |
|
928 |
||
929 |
(syncronizeEvents and:[(sensor := self sensor) notNil]) ifTrue:[ |
|
930 |
sensor pushUserEvent:aSelector for:self withArguments:(Array with:arg1 with:arg2) |
|
931 |
] ifFalse:[ |
|
932 |
self perform:aSelector with:arg1 with:arg2 |
|
933 |
] |
|
934 |
||
935 |
! |
|
936 |
||
937 |
syncronizeEvents |
|
938 |
"if true, all asynchronous events are pushed into my event queue |
|
939 |
and will be performed when its time to handle the events. |
|
940 |
Otherwise these events are handled immediately. On default disabled. |
|
941 |
" |
|
942 |
^ syncronizeEvents |
|
943 |
! |
|
944 |
||
945 |
syncronizeEvents:aBoolean |
|
946 |
"if true, all asynchronous events are pushed into my event queue |
|
947 |
and will be performed when its time to handle the events. |
|
948 |
Otherwise these events are handled immediately. On default disabled. |
|
949 |
" |
|
950 |
syncronizeEvents := aBoolean ? false. |
|
951 |
! ! |
|
952 |
||
1390 | 953 |
!ListModelView methodsFor:'fetch resources'! |
954 |
||
955 |
colorOnDevice:aColor |
|
956 |
"fetch a device colors |
|
957 |
" |
|
958 |
^ aColor notNil ifTrue:[aColor on:device] ifFalse:[nil] |
|
959 |
||
960 |
! |
|
961 |
||
962 |
imageOnDevice:anImage |
|
963 |
"associate image to device and clear pixel mask |
|
964 |
returns the new image. |
|
965 |
" |
|
966 |
|image| |
|
967 |
||
968 |
(image := anImage) notNil ifTrue:[ |
|
969 |
image device ~~ device ifTrue:[ |
|
970 |
image := image copy. |
|
971 |
]. |
|
972 |
image := image on:device. |
|
973 |
image := image clearMaskedPixels. |
|
974 |
]. |
|
975 |
^ image |
|
976 |
||
977 |
! ! |
|
978 |
||
1417 | 979 |
!ListModelView methodsFor:'focus handling'! |
980 |
||
981 |
wantsFocusWithButtonPress |
|
982 |
"catch the keyboard focus on button click |
|
983 |
" |
|
984 |
^ true |
|
985 |
||
986 |
||
987 |
! |
|
988 |
||
989 |
wantsFocusWithPointerEnter |
|
990 |
"views which like to take the keyboard focus |
|
991 |
when the pointer enters can do so by redefining this |
|
992 |
to return true" |
|
993 |
||
994 |
^ true |
|
995 |
||
996 |
! ! |
|
997 |
||
1390 | 998 |
!ListModelView methodsFor:'initialize / release'! |
999 |
||
1000 |
create |
|
1001 |
"fetch device dependent resources |
|
1002 |
" |
|
1003 |
super create. |
|
1004 |
self fetchResources. |
|
1005 |
self recomputeHeightOfContents. |
|
1006 |
! |
|
1007 |
||
1008 |
destroy |
|
1009 |
"remove dependencies |
|
1010 |
" |
|
1011 |
listHolder removeDependent:self. |
|
1012 |
list removeDependent:self. |
|
1535
872422bc0e81
support frames (views) within the list
Claus Gittinger <cg@exept.de>
parents:
1534
diff
changeset
|
1013 |
|
1390 | 1014 |
super destroy |
1015 |
||
1016 |
! |
|
1017 |
||
1018 |
initStyle |
|
1019 |
"setup viewStyle specifics |
|
1020 |
" |
|
1021 |
super initStyle. |
|
1022 |
||
1595 | 1023 |
DefaultForegroundColor isNil ifTrue:[ |
1024 |
self updateStyleCache |
|
1025 |
]. |
|
1026 |
||
1390 | 1027 |
DefaultBackgroundColor notNil ifTrue:[ |
1028 |
viewBackground := DefaultBackgroundColor |
|
1029 |
]. |
|
1030 |
lineSpacing := 0. |
|
1031 |
textStartLeft := 2. |
|
1032 |
fgColor := DefaultForegroundColor. |
|
1033 |
bgColor := viewBackground. |
|
1034 |
startOfLinesY := OrderedCollection new. |
|
1035 |
||
1036 |
startOfLinesY add:(2 + margin). "/ top inset of first line |
|
1037 |
||
1038 |
DefaultShadowColor notNil ifTrue:[ |
|
1039 |
shadowColor := DefaultShadowColor |
|
1040 |
]. |
|
1041 |
||
1042 |
DefaultLightColor notNil ifTrue:[ |
|
1043 |
lightColor := DefaultLightColor |
|
1044 |
]. |
|
1045 |
! |
|
1046 |
||
1047 |
initialize |
|
1048 |
"setup default attributes |
|
1049 |
" |
|
1050 |
super initialize. |
|
1051 |
||
1554 | 1052 |
viewOrigin := 0@0. |
1053 |
bitGravity := #NorthWest. |
|
1054 |
enabled := true. |
|
1055 |
displayedFrames := WeakIdentityDictionary new. |
|
1056 |
syncronizeEvents := false. |
|
1748 | 1057 |
autoScroll := true. |
1827 | 1058 |
scrollWhenUpdating := #beginOfText. |
1390 | 1059 |
! |
1060 |
||
1562 | 1061 |
mapped |
1062 |
"recompute list |
|
1063 |
" |
|
1064 |
shown ifFalse:[ |
|
1065 |
self recomputeHeightOfContents. |
|
1066 |
self contentsChanged. |
|
1067 |
]. |
|
1068 |
super mapped |
|
1069 |
||
1070 |
! |
|
1071 |
||
1390 | 1072 |
recreate |
1832 | 1073 |
"sent after a snapin or a migration, reinit for new device" |
1828 | 1074 |
|
1390 | 1075 |
super recreate. |
1076 |
self fetchResources. |
|
1796
c9d801c011f7
recompute layout after snapIn (font geometry could be different)
Claus Gittinger <cg@exept.de>
parents:
1773
diff
changeset
|
1077 |
! |
c9d801c011f7
recompute layout after snapIn (font geometry could be different)
Claus Gittinger <cg@exept.de>
parents:
1773
diff
changeset
|
1078 |
|
c9d801c011f7
recompute layout after snapIn (font geometry could be different)
Claus Gittinger <cg@exept.de>
parents:
1773
diff
changeset
|
1079 |
reinitialize |
c9d801c011f7
recompute layout after snapIn (font geometry could be different)
Claus Gittinger <cg@exept.de>
parents:
1773
diff
changeset
|
1080 |
"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
|
1081 |
" |
c9d801c011f7
recompute layout after snapIn (font geometry could be different)
Claus Gittinger <cg@exept.de>
parents:
1773
diff
changeset
|
1082 |
super reinitialize. |
c9d801c011f7
recompute layout after snapIn (font geometry could be different)
Claus Gittinger <cg@exept.de>
parents:
1773
diff
changeset
|
1083 |
self recomputeHeightOfContents. |
c9d801c011f7
recompute layout after snapIn (font geometry could be different)
Claus Gittinger <cg@exept.de>
parents:
1773
diff
changeset
|
1084 |
self contentsChanged. |
c9d801c011f7
recompute layout after snapIn (font geometry could be different)
Claus Gittinger <cg@exept.de>
parents:
1773
diff
changeset
|
1085 |
|
1390 | 1086 |
! ! |
1087 |
||
1088 |
!ListModelView methodsFor:'private'! |
|
1089 |
||
1457 | 1090 |
hasDamage |
1091 |
"return true, if any damage events (i.e. expose or resize) are pending. |
|
1092 |
" |
|
1093 |
|sensor| |
|
1094 |
||
1095 |
^ (sensor := self sensor) isNil or:[sensor hasDamageFor:self] |
|
1096 |
! |
|
1097 |
||
1390 | 1098 |
yAbsoluteOfLine:aLineNr |
1099 |
"given a lineNr, return y-coordinate absolute |
|
1100 |
" |
|
1744 | 1101 |
|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
|
1102 |
|
1744 | 1103 |
cash := startOfLinesY. |
1446
fb46beba2d0c
startOfLines can have nil at end; lookup the first not nil
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
1104 |
|
1744 | 1105 |
(y := cash at:aLineNr ifAbsent:nil) notNil ifTrue:[ |
1106 |
^ y |
|
1446
fb46beba2d0c
startOfLines can have nil at end; lookup the first not nil
Claus Gittinger <cg@exept.de>
parents:
1444
diff
changeset
|
1107 |
]. |
1744 | 1108 |
|
1109 |
"/ recompute a y position |
|
1110 |
y1 := startOfLinesY at:1 ifAbsent:2. |
|
1111 |
y2 := startOfLinesY at:2 ifAbsent:10. |
|
1112 |
^ aLineNr * (y2 - y1) + y1 |
|
1390 | 1113 |
! |
1114 |
||
1115 |
yVisibleOfLine:aLineNr |
|
1116 |
"given a lineNr, return y-coordinate in view |
|
1117 |
" |
|
1744 | 1118 |
^ (self yAbsoluteOfLine:aLineNr) - viewOrigin y |
1390 | 1119 |
|
1120 |
||
1121 |
! |
|
1122 |
||
1123 |
yVisibleToLineNr:yVisible |
|
1124 |
"returns the line number assigned to a physical y or nil |
|
1125 |
" |
|
1643 | 1126 |
|eol cash |
1390 | 1127 |
yAbs "{ Class: SmallInteger}" |
1128 |
yMid "{ Class: SmallInteger}" |
|
1129 |
size "{ Class: SmallInteger}" |
|
1130 |
next "{ Class: SmallInteger}" |
|
1131 |
low "{ Class: SmallInteger}" |
|
1132 |
high "{ Class: SmallInteger}" |
|
1133 |
middle "{ Class: SmallInteger}" |
|
1134 |
| |
|
1643 | 1135 |
cash := startOfLinesY. |
1390 | 1136 |
|
1643 | 1137 |
(size := cash size) == 1 ifTrue:[^ nil]. "/ EMPTY LIST |
1390 | 1138 |
yAbs := yVisible + viewOrigin y. |
1643 | 1139 |
eol := cash at:size ifAbsent:nil. |
1642 | 1140 |
(eol isNil or:[yAbs > eol]) ifTrue:[^ nil]. "/ END OF LIST |
1390 | 1141 |
|
1142 |
middle := size. |
|
1143 |
size := size - 1. |
|
1144 |
high := size. |
|
1145 |
low := 1. |
|
1146 |
||
1147 |
[(next := low + high // 2) ~~ middle] whileTrue:[ |
|
1643 | 1148 |
(eol := cash at:next ifAbsent:nil) isNil ifTrue:[ |
1149 |
^ nil "/ LIST CHANGED |
|
1150 |
]. |
|
1151 |
middle := next. |
|
1152 |
yMid := eol. |
|
1390 | 1153 |
|
1154 |
yMid < yAbs ifTrue:[low := middle] |
|
1155 |
ifFalse:[high := middle] |
|
1156 |
]. |
|
1157 |
||
1158 |
yAbs < yMid ifTrue:[ |
|
1159 |
^ (middle - 1) max:1. |
|
1160 |
]. |
|
1161 |
middle < size ifTrue:[ |
|
1162 |
next := middle + 1. |
|
1643 | 1163 |
(eol := cash at:next ifAbsent:nil) isNil ifTrue:[ |
1164 |
^ nil "/ LIST CHANGED |
|
1165 |
]. |
|
1166 |
^ eol > yAbs ifTrue:[middle] ifFalse:[next] |
|
1390 | 1167 |
]. |
1168 |
^ size |
|
1169 |
! ! |
|
1170 |
||
1171 |
!ListModelView methodsFor:'protocol'! |
|
1172 |
||
1532
56e0fafc4349
change display protocol for item
Claus Gittinger <cg@exept.de>
parents:
1531
diff
changeset
|
1173 |
drawFrom:start to:stop x:x y:y w:w |
1390 | 1174 |
"draw lines from start to stop. |
1175 |
clipping and clearing the background is already done |
|
1176 |
" |
|
1399 | 1177 |
|item |
1178 |
y0 "{ Class:SmallInteger }" |
|
1390 | 1179 |
y1 "{ Class:SmallInteger }" |
1180 |
x0 "{ Class:SmallInteger }" |
|
1181 |
| |
|
1182 |
self paint:fgColor on:bgColor. |
|
1183 |
||
1184 |
x0 := textStartLeft - viewOrigin x. |
|
1532
56e0fafc4349
change display protocol for item
Claus Gittinger <cg@exept.de>
parents:
1531
diff
changeset
|
1185 |
y1 := y. |
1390 | 1186 |
|
1187 |
start to:stop do:[:i| |
|
1188 |
y0 := y1. |
|
1189 |
y1 := self yVisibleOfLine:(i + 1). |
|
1399 | 1190 |
|
1191 |
(item := list at:i ifAbsent:nil) notNil ifTrue:[ |
|
1532
56e0fafc4349
change display protocol for item
Claus Gittinger <cg@exept.de>
parents:
1531
diff
changeset
|
1192 |
self displayElement:item x:x0 y:y0 h:(y1 - y0) |
1399 | 1193 |
] |
1194 |
] |
|
1390 | 1195 |
|
1196 |
! |
|
1197 |
||
1198 |
fetchResources |
|
1199 |
"fetch device colors and ..., to avoid reallocation at redraw time; |
|
1200 |
*** called after a create or snapin to fetch all device resources |
|
1201 |
" |
|
1202 |
fgColor := self colorOnDevice:fgColor. |
|
1203 |
bgColor := self colorOnDevice:bgColor. |
|
1204 |
font := font on:device. |
|
1205 |
||
1206 |
! |
|
1207 |
||
1208 |
heightOfLineAt:aLineNr |
|
1209 |
"returns the total height for a line at an index( including lineSpacing ... ) |
|
1210 |
" |
|
1211 |
|item| |
|
1212 |
||
1508
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1457
diff
changeset
|
1213 |
item := list at:aLineNr ifAbsent:nil. |
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1457
diff
changeset
|
1214 |
|
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1457
diff
changeset
|
1215 |
^ item notNil ifTrue:[lineSpacing + (item heightOn:self)] |
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1457
diff
changeset
|
1216 |
ifFalse:[4] |
1390 | 1217 |
! |
1218 |
||
1219 |
listSizeChanged:anIndex nLines:noLines |
|
1220 |
"list size changed; information is stored to recompute the |
|
1221 |
width if required( preferredExtent, horizontal scroller ... ). |
|
1222 |
see: widthOfContents |
|
1223 |
*** if nLines is negative, lines are removed otherwise added. |
|
1224 |
" |
|
1225 |
|start "{ Class:SmallInteger }" |
|
1226 |
stop "{ Class:SmallInteger }" |
|
1227 |
size "{ Class:SmallInteger }" |
|
1228 |
| |
|
1229 |
preferredExtent := nil. |
|
1230 |
||
1231 |
widthOfContents isNil ifTrue:[ "/ recompute whole list |
|
1232 |
^ self |
|
1233 |
]. |
|
1234 |
||
1235 |
(noLines < 0 or:[(size := list size) <= noLines]) ifTrue:[ |
|
1236 |
widthOfContents := nil. "/ force recompute whole list |
|
1237 |
^ self |
|
1238 |
]. |
|
1239 |
||
1240 |
stop := anIndex + noLines - 1. "/ recompute a range |
|
1241 |
start := anIndex. |
|
1242 |
||
1243 |
computeWidthInRange notNil ifTrue:[ |
|
1244 |
start := computeWidthInRange y. |
|
1245 |
stop < start ifTrue:[stop := start min:size]. |
|
1246 |
start := (computeWidthInRange x) min:anIndex. |
|
1247 |
]. |
|
1248 |
computeWidthInRange := start@stop |
|
1249 |
! |
|
1250 |
||
1457 | 1251 |
lostSynchronisation |
1252 |
"called when the changes derived from the model are faster than the handling |
|
1253 |
" |
|
1254 |
shown ifTrue:[ |
|
1554 | 1255 |
self syncFlushEvent:#syncUpdate:with:. |
1457 | 1256 |
self recomputeHeightOfContents. |
1257 |
self invalidate. |
|
1258 |
self contentsChanged |
|
1259 |
]. |
|
1260 |
||
1261 |
||
1262 |
||
1263 |
||
1264 |
! |
|
1265 |
||
1390 | 1266 |
widthOfWidestLineBetween:firstLine and:lastLine |
1267 |
"return the width in pixels of the widest line in a range |
|
1268 |
" |
|
1269 |
|lbl item |
|
1270 |
width "{ Class: SmallInteger }" |
|
1271 |
| |
|
1272 |
width := textStartLeft. |
|
1273 |
||
1274 |
firstLine to:lastLine do:[:anIndex| |
|
1508
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1457
diff
changeset
|
1275 |
item := list at:anIndex ifAbsent:nil. |
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1457
diff
changeset
|
1276 |
|
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1457
diff
changeset
|
1277 |
item isNil ifTrue:[^ width + textStartLeft]. |
9c54f2e53da1
check whether #at:ifAbsent returns nil.
Claus Gittinger <cg@exept.de>
parents:
1457
diff
changeset
|
1278 |
|
1390 | 1279 |
width := (item widthOn:self) max:width |
1280 |
]. |
|
1281 |
^ width + textStartLeft |
|
1282 |
||
1283 |
||
1284 |
||
1285 |
||
1286 |
! ! |
|
1287 |
||
1820 | 1288 |
!ListModelView methodsFor:'queries'! |
1289 |
||
1290 |
size |
|
1291 |
"returns number of raws |
|
1292 |
" |
|
1293 |
^ list size |
|
1294 |
||
1295 |
||
1296 |
! ! |
|
1297 |
||
1390 | 1298 |
!ListModelView methodsFor:'recomputation'! |
1299 |
||
1300 |
preferredExtent |
|
1301 |
"returns the preferred extent |
|
1302 |
" |
|
1303 |
|x y| |
|
1304 |
||
1305 |
preferredExtent isNil ifTrue:[ |
|
1306 |
y := self heightOfContents. |
|
1307 |
x := self widthOfContents. |
|
1308 |
preferredExtent := x@y |
|
1309 |
]. |
|
1310 |
^ preferredExtent |
|
1311 |
||
1312 |
||
1313 |
! |
|
1314 |
||
1315 |
recomputeHeightOfContents |
|
1316 |
"recompute all the y positions |
|
1317 |
" |
|
1643 | 1318 |
|newList |
1319 |
yAbs "{ Class: SmallInteger }" |
|
1390 | 1320 |
lnHg "{ Class: SmallInteger }" |
1643 | 1321 |
size "{ Class: SmallInteger }" |
1390 | 1322 |
| |
1323 |
||
1643 | 1324 |
yAbs := startOfLinesY at:1. "/ top inset of first line |
1325 |
size := list size. |
|
1326 |
newList := OrderedCollection new:(size + 1). |
|
1327 |
||
1328 |
newList add:yAbs. |
|
1390 | 1329 |
|
1643 | 1330 |
1 to:size do:[:anIndex| |
1390 | 1331 |
lnHg := self heightOfLineAt:anIndex. |
1643 | 1332 |
newList add:(yAbs := yAbs + lnHg) |
1390 | 1333 |
]. |
1643 | 1334 |
startOfLinesY := newList. |
1390 | 1335 |
! ! |
1336 |
||
1337 |
!ListModelView methodsFor:'scroller interface'! |
|
1338 |
||
1339 |
heightOfContents |
|
1340 |
"return the height of the contents in pixels |
|
1341 |
" |
|
1342 |
^ startOfLinesY last |
|
1343 |
! |
|
1344 |
||
1345 |
innerHeight |
|
1346 |
"returns the inner height of the contents shown |
|
1347 |
" |
|
1348 |
^ height - margin - margin |
|
1349 |
||
1350 |
! |
|
1351 |
||
1352 |
innerWidth |
|
1353 |
"returns the inner width of the contents shown |
|
1354 |
" |
|
1355 |
^ width - margin - margin |
|
1356 |
||
1357 |
! |
|
1358 |
||
1359 |
maxViewOriginY |
|
1360 |
"returns the maximum possible y of the view origin |
|
1361 |
" |
|
1362 |
^ (self heightOfContents - self innerHeight) max:0 |
|
1363 |
||
1364 |
||
1365 |
! |
|
1366 |
||
1367 |
verticalScrollStep |
|
1368 |
"return the amount to scroll when stepping up/down. |
|
1369 |
" |
|
1370 |
^ 10 |
|
1371 |
||
1372 |
! |
|
1373 |
||
1374 |
viewOrigin |
|
1375 |
"return the viewOrigin; thats the coordinate of the contents |
|
1376 |
which is shown topLeft in the view. |
|
1377 |
" |
|
1378 |
^ viewOrigin |
|
1379 |
||
1380 |
! |
|
1381 |
||
1382 |
widthOfContents |
|
1383 |
"return the width of the contents in pixels |
|
1384 |
" |
|
1385 |
|range |
|
1386 |
size "{ Class:SmallInteger }" |
|
1387 |
start "{ Class:SmallInteger }" |
|
1388 |
stop "{ Class:SmallInteger }" |
|
1389 |
| |
|
1390 |
(widthOfContents notNil and:[computeWidthInRange isNil]) ifTrue:[ |
|
1391 |
^ widthOfContents + textStartLeft |
|
1392 |
]. |
|
1393 |
range := computeWidthInRange. |
|
1394 |
computeWidthInRange := nil. |
|
1395 |
preferredExtent := nil. |
|
1396 |
size := list size. |
|
1397 |
||
1398 |
size == 0 ifTrue:[ |
|
1399 |
widthOfContents := 20. |
|
1400 |
] ifFalse:[ |
|
1401 |
widthOfContents isNil ifTrue:[ |
|
1402 |
widthOfContents := self widthOfWidestLineBetween:1 and:size |
|
1403 |
] ifFalse:[ |
|
1404 |
start := range x. |
|
1405 |
stop := range y min:size. |
|
1406 |
||
1407 |
start > stop ifFalse:[ |
|
1408 |
size := self widthOfWidestLineBetween:start and:stop. |
|
1409 |
||
1410 |
widthOfContents < size ifTrue:[ |
|
1411 |
widthOfContents := size |
|
1412 |
] |
|
1413 |
] |
|
1414 |
] |
|
1415 |
]. |
|
1416 |
^ widthOfContents + textStartLeft |
|
1417 |
! |
|
1418 |
||
1419 |
xOriginOfContents |
|
1420 |
"return the horizontal origin of the contents in pixels |
|
1421 |
" |
|
1422 |
^ viewOrigin x |
|
1423 |
||
1424 |
! |
|
1425 |
||
1426 |
yOriginOfContents |
|
1427 |
"return the vertical origin of the contents in pixels |
|
1428 |
" |
|
1429 |
^ viewOrigin y |
|
1430 |
||
1431 |
! ! |
|
1432 |
||
1433 |
!ListModelView methodsFor:'scrolling'! |
|
1434 |
||
1435 |
halfPageDown |
|
1436 |
"scroll down half a page |
|
1437 |
" |
|
1827 | 1438 |
self scrollDown:(height // 2). |
1390 | 1439 |
|
1440 |
! |
|
1441 |
||
1442 |
halfPageUp |
|
1443 |
"scroll up half a page |
|
1444 |
" |
|
1827 | 1445 |
self scrollUp:(height // 2). |
1390 | 1446 |
|
1447 |
! |
|
1448 |
||
1449 |
scrollTo:anOrigin redraw:doRedraw |
|
1450 |
"change origin to have newOrigin be visible at the top-left. |
|
1451 |
" |
|
1538 | 1452 |
|newOrg dltOrg winGrp |
1390 | 1453 |
innerWT "{ Class:SmallInteger }" |
1454 |
innerHG "{ Class:SmallInteger }" |
|
1455 |
h "{ Class:SmallInteger }" |
|
1456 |
x "{ Class:SmallInteger }" |
|
1457 |
x0 "{ Class:SmallInteger }" |
|
1458 |
x1 "{ Class:SmallInteger }" |
|
1459 |
y "{ Class:SmallInteger }" |
|
1460 |
w "{ Class:SmallInteger }" |
|
1461 |
y0 "{ Class:SmallInteger }" |
|
1462 |
y1 "{ Class:SmallInteger }" |
|
1463 |
dX "{ Class:SmallInteger }" |
|
1464 |
dY "{ Class:SmallInteger }" |
|
1465 |
| |
|
1531 | 1466 |
|
1580 | 1467 |
realized ifFalse:[ |
1390 | 1468 |
^ self |
1469 |
]. |
|
1580 | 1470 |
|
1390 | 1471 |
innerWT := self innerWidth. |
1472 |
innerHG := self innerHeight. |
|
1473 |
||
1474 |
h := viewOrigin y. |
|
1475 |
||
1476 |
(y := anOrigin y) > h ifTrue:[ "/ end of contents |
|
1477 |
y > (dY := self maxViewOriginY) ifTrue:[ |
|
1478 |
y := dY max:h |
|
1479 |
] |
|
1480 |
] ifFalse:[ |
|
1481 |
y := y max:0. |
|
1482 |
]. |
|
1483 |
||
1484 |
(x := anOrigin x) > 0 ifTrue:[ |
|
1485 |
x := x min:(self widthOfContents - innerWT). |
|
1486 |
]. |
|
1487 |
x := x max:0. |
|
1488 |
newOrg := (x @ y). |
|
1489 |
dltOrg := newOrg - viewOrigin. |
|
1490 |
dX := dltOrg x. |
|
1491 |
dY := dltOrg y. |
|
1492 |
||
1493 |
(dX == 0 and:[dY == 0]) ifTrue:[ |
|
1494 |
^ self |
|
1495 |
]. |
|
1534 | 1496 |
dY := dY abs. |
1497 |
dX := dX abs. |
|
1390 | 1498 |
|
1534 | 1499 |
( (dX ~~ 0 and:[dY ~~ 0]) "/ scroll vertical & horizontal |
1500 |
or:[(innerHG - dY < 20 or:[innerWT - dX < 20])] "/ faster to invalidate screen |
|
1501 |
) ifTrue:[ |
|
1502 |
viewOrigin := newOrg. |
|
1503 |
self originChanged:dltOrg. |
|
1504 |
^ self invalidate |
|
1505 |
]. |
|
1753
17769f8df493
#scrollTo:redraw: first check whether full invalidate otherwise processRealExposeEventsFor:
ca
parents:
1752
diff
changeset
|
1506 |
|
17769f8df493
#scrollTo:redraw: first check whether full invalidate otherwise processRealExposeEventsFor:
ca
parents:
1752
diff
changeset
|
1507 |
(winGrp := self windowGroup) notNil ifTrue:[ |
17769f8df493
#scrollTo:redraw: first check whether full invalidate otherwise processRealExposeEventsFor:
ca
parents:
1752
diff
changeset
|
1508 |
winGrp processRealExposeEventsFor:self. |
17769f8df493
#scrollTo:redraw: first check whether full invalidate otherwise processRealExposeEventsFor:
ca
parents:
1752
diff
changeset
|
1509 |
]. |
17769f8df493
#scrollTo:redraw: first check whether full invalidate otherwise processRealExposeEventsFor:
ca
parents:
1752
diff
changeset
|
1510 |
|
17769f8df493
#scrollTo:redraw: first check whether full invalidate otherwise processRealExposeEventsFor:
ca
parents:
1752
diff
changeset
|
1511 |
self originWillChange. |
17769f8df493
#scrollTo:redraw: first check whether full invalidate otherwise processRealExposeEventsFor:
ca
parents:
1752
diff
changeset
|
1512 |
|
17769f8df493
#scrollTo:redraw: first check whether full invalidate otherwise processRealExposeEventsFor:
ca
parents:
1752
diff
changeset
|
1513 |
doRedraw ifFalse:[ |
17769f8df493
#scrollTo:redraw: first check whether full invalidate otherwise processRealExposeEventsFor:
ca
parents:
1752
diff
changeset
|
1514 |
viewOrigin := newOrg. |
17769f8df493
#scrollTo:redraw: first check whether full invalidate otherwise processRealExposeEventsFor:
ca
parents:
1752
diff
changeset
|
1515 |
^ self originChanged:dltOrg |
17769f8df493
#scrollTo:redraw: first check whether full invalidate otherwise processRealExposeEventsFor:
ca
parents:
1752
diff
changeset
|
1516 |
]. |
17769f8df493
#scrollTo:redraw: first check whether full invalidate otherwise processRealExposeEventsFor:
ca
parents:
1752
diff
changeset
|
1517 |
|
1531 | 1518 |
self catchExpose. |
1519 |
viewOrigin := newOrg. |
|
1520 |
||
1390 | 1521 |
dY ~~ 0 ifTrue:[ "/ SCROLL VERTICAL |
1534 | 1522 |
y0 := y1 := margin + dY. |
1523 |
h := innerHG - dY. |
|
1390 | 1524 |
|
1534 | 1525 |
dltOrg y < 0 ifTrue:[y0 := margin. y := y0] |
1526 |
ifFalse:[y1 := margin. y := y1 + h]. |
|
1390 | 1527 |
|
1534 | 1528 |
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
|
1529 |
self invalidateX:margin y:y width:innerWT height:(innerHG - h). |
1390 | 1530 |
|
1531 |
] ifFalse:[ "/ SCROLL HORIZONTAL |
|
1534 | 1532 |
x0 := x1 := dX + margin. |
1533 |
w := innerWT - dX. |
|
1390 | 1534 |
|
1534 | 1535 |
dltOrg x < 0 ifTrue:[x0 := x := margin ] |
1536 |
ifFalse:[x1 := margin. x := w]. |
|
1390 | 1537 |
|
1534 | 1538 |
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
|
1539 |
self invalidateX:x y:margin width:(width - w) height:innerHG. |
1390 | 1540 |
]. |
1541 |
self originChanged:dltOrg. |
|
1531 | 1542 |
self waitForExpose. |
1543 |
||
1390 | 1544 |
! |
1545 |
||
1546 |
scrollToLine:aLineNumber |
|
1547 |
"make line visible |
|
1548 |
" |
|
1744 | 1549 |
|inHg "{ Class:SmallInteger }" |
1550 |
yTop "{ Class:SmallInteger }" |
|
1551 |
orgY "{ Class:SmallInteger }" |
|
1552 |
yBot "{ Class:SmallInteger }" |
|
1390 | 1553 |
| |
1744 | 1554 |
(shown and:[aLineNumber notNil and:[aLineNumber between:1 and:list size]]) ifFalse:[ |
1390 | 1555 |
^ self |
1556 |
]. |
|
1557 |
||
1744 | 1558 |
yTop := self yAbsoluteOfLine:aLineNumber. |
1559 |
inHg := self innerHeight. |
|
1560 |
orgY := viewOrigin y. |
|
1561 |
||
1562 |
yTop > orgY ifTrue:[ |
|
1563 |
yBot := self yAbsoluteOfLine:(aLineNumber + 1). |
|
1390 | 1564 |
|
1744 | 1565 |
yBot <= (orgY + inHg) ifTrue:[ |
1566 |
^ self |
|
1567 |
]. |
|
1390 | 1568 |
]. |
1744 | 1569 |
yTop := (yTop - (inHg // 2)) max:0. |
1570 |
self scrollTo:(viewOrigin x @ yTop). |
|
1390 | 1571 |
|
1572 |
||
1573 |
! ! |
|
1574 |
||
1748 | 1575 |
!ListModelView methodsFor:'scrolling auto'! |
1576 |
||
1577 |
startAutoScroll:aBlock distance:aDistance |
|
1578 |
"setup for auto-scroll (when button-press-moving below view); |
|
1579 |
- timeDelta for scroll is computed from distance |
|
1580 |
" |
|
1581 |
|timeDelta| |
|
1582 |
||
1583 |
(autoScroll and:[aBlock notNil]) ifFalse:[ |
|
1584 |
^ self stopAutoScroll |
|
1585 |
]. |
|
1586 |
autoScrollBlock notNil ifTrue:[ |
|
1587 |
Processor removeTimedBlock:autoScrollBlock. |
|
1588 |
] ifFalse:[ |
|
1589 |
self compressMotionEvents:false. |
|
1590 |
]. |
|
1591 |
||
1592 |
timeDelta := 0.5 / (aDistance abs). |
|
1593 |
||
1594 |
autoScrollBlock := [ |
|
1595 |
aBlock value. |
|
1596 |
Processor addTimedBlock:autoScrollBlock afterSeconds:timeDelta. |
|
1597 |
]. |
|
1598 |
Processor addTimedBlock:autoScrollBlock afterSeconds:timeDelta. |
|
1599 |
||
1600 |
! |
|
1601 |
||
1602 |
stopAutoScroll |
|
1603 |
"stop any autoScroll |
|
1604 |
" |
|
1605 |
autoScrollBlock notNil ifTrue:[ |
|
1606 |
Processor removeTimedBlock:autoScrollBlock. |
|
1607 |
autoScrollBlock := nil. |
|
1608 |
self compressMotionEvents:true. |
|
1609 |
]. |
|
1610 |
! ! |
|
1611 |
||
1390 | 1612 |
!ListModelView class methodsFor:'documentation'! |
1613 |
||
1614 |
version |
|
1832 | 1615 |
^ '$Header: /cvs/stx/stx/libwidg2/ListModelView.st,v 1.49 2000-09-06 13:48:04 cg Exp $' |
1390 | 1616 |
! ! |
1617 |
ListModelView initialize! |