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