0
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
3 |
All Rights Reserved
|
0
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
71
|
13 |
'From Smalltalk/X, Version:2.10.4 on 30-nov-1994 at 3:38:24 pm'!
|
63
|
14 |
|
0
|
15 |
View subclass:#ObjectView
|
77
|
16 |
instanceVariableNames:'contents sorted lastButt pressAction
|
63
|
17 |
releaseAction shiftPressAction doublePressAction motionAction
|
71
|
18 |
keyPressAction selection gridShown gridPixmap scaleMetric
|
77
|
19 |
dragObject leftHandCursor oldCursor movedObject
|
|
20 |
moveStartPoint moveDelta documentFormat canDragOutOfView
|
71
|
21 |
rootMotion rootView aligning gridAlign'
|
63
|
22 |
classVariableNames:''
|
|
23 |
poolDictionaries:''
|
|
24 |
category:'Views-Basic'
|
0
|
25 |
!
|
|
26 |
|
|
27 |
ObjectView comment:'
|
59
|
28 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
|
29 |
All Rights Reserved
|
|
30 |
'!
|
0
|
31 |
|
59
|
32 |
!ObjectView class methodsFor:'documentation'!
|
|
33 |
|
|
34 |
copyright
|
|
35 |
"
|
|
36 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
|
37 |
All Rights Reserved
|
0
|
38 |
|
59
|
39 |
This software is furnished under a license and may be used
|
|
40 |
only in accordance with the terms of that license and with the
|
|
41 |
inclusion of the above copyright notice. This software may not
|
|
42 |
be provided or otherwise made available to, or used by, any
|
|
43 |
other person. No title to or ownership of the software is
|
|
44 |
hereby transferred.
|
|
45 |
"
|
|
46 |
!
|
0
|
47 |
|
59
|
48 |
version
|
|
49 |
"
|
102
|
50 |
$Header: /cvs/stx/stx/libwidg/ObjectView.st,v 1.22 1995-03-09 03:22:23 claus Exp $
|
59
|
51 |
"
|
|
52 |
!
|
|
53 |
|
|
54 |
documentation
|
|
55 |
"
|
|
56 |
a View which can hold DisplayObjects, can make selections, move them around etc.
|
|
57 |
this is an abstract class providing common mechanisms - actual instances are
|
|
58 |
DrawView, DirectoryView, LogicView or DocumentView.
|
|
59 |
|
77
|
60 |
Instance variables:
|
|
61 |
|
|
62 |
contents <Collection> the objects. The order in which
|
|
63 |
these are in that collection defines
|
|
64 |
their appearance in the z-plane:
|
|
65 |
an object located after another one
|
|
66 |
here will be drawn ABOVE the other.
|
|
67 |
|
|
68 |
sorted <Boolean> if set, redraw and picking methods
|
|
69 |
assume that the objects are sorted by
|
|
70 |
>= y-coordinates. These operations are
|
|
71 |
a bit faster then, since a binary search
|
|
72 |
can be done. (use with care).
|
|
73 |
|
|
74 |
lastButt <Point> last pointer press position
|
|
75 |
(internal)
|
|
76 |
|
|
77 |
pressAction <Block> action to perform when mouse pointer
|
|
78 |
is pressed. Can be set to something like
|
|
79 |
[self startCreate], [self startSelectOrMove]
|
|
80 |
etc.
|
|
81 |
|
|
82 |
releaseAction <Block> action to perform when mouse pointer is
|
|
83 |
released. Typically set in one of the
|
|
84 |
startXXX methods.
|
|
85 |
|
|
86 |
shiftPressAction <Block> like pressAction, if shift key is
|
|
87 |
pressed.
|
|
88 |
|
|
89 |
doublePressAction <Block> same for double-clicks
|
|
90 |
|
|
91 |
motionAction <Block> action to perform on mouse-pointer
|
|
92 |
motion.
|
|
93 |
|
|
94 |
keyPressAction <Block> action for keyboard events
|
|
95 |
|
|
96 |
selection <any> the current selection; either a single
|
|
97 |
object or a collection of objects.
|
|
98 |
|
|
99 |
gridShown <Boolean> internal
|
|
100 |
|
|
101 |
gridPixmap <Form> internal
|
|
102 |
|
|
103 |
scaleMetric <Symbol> either #mm or #inch; used to
|
|
104 |
decide how the grid is defined
|
|
105 |
|
|
106 |
dragObject internal
|
|
107 |
|
|
108 |
leftHandCursor cursor shown while dragging a rectangle
|
|
109 |
|
|
110 |
oldCursor saved original cursor while dragging a rectangle
|
|
111 |
|
|
112 |
movedObject internal
|
|
113 |
moveStartPoint internal
|
|
114 |
moveDelta internal
|
|
115 |
|
|
116 |
documentFormat <Symbol> defines the size and layout of the
|
|
117 |
document. Can be any of
|
|
118 |
#letter, #a4, #a3 etc.
|
|
119 |
|
|
120 |
canDragOutOfView <Boolean> if true, objects can be dragged out of the
|
|
121 |
view. If false, dragging is restricted to within
|
|
122 |
this view.
|
|
123 |
|
|
124 |
rootMotion internal
|
|
125 |
rootView internal
|
|
126 |
|
|
127 |
aligning <Boolean> if true, pointer positions are
|
|
128 |
aligned (snapped) to the point
|
|
129 |
specified in gridAlign
|
|
130 |
|
|
131 |
gridAlign <Point> if aligning is true, this point
|
|
132 |
defines the snapping. For example,
|
|
133 |
12@12 defines snap to the nearest
|
|
134 |
12-point grid.
|
|
135 |
|
59
|
136 |
written spring/summer 89 by claus
|
|
137 |
"
|
77
|
138 |
!
|
|
139 |
|
|
140 |
examples
|
|
141 |
"
|
|
142 |
typically, ObjectViews are not used on their own, but instead
|
|
143 |
subclassed and thereby provide the common functionality for
|
|
144 |
views which show (possibly overlapping) objects.
|
|
145 |
The methods here provide all mechanisms to handle redraws, picking
|
|
146 |
(i.e. finding an object by position), gridding, moving objects with
|
|
147 |
minimum redraw etc.
|
|
148 |
Also, zooming and scrolling is handled.
|
|
149 |
All objects which respond to the DisplayObject protocol can be handled
|
|
150 |
by ObjectView - therefore, you can add almost any object and have it
|
|
151 |
displayed and handled here. (as an example, try to copy a LogicGate
|
|
152 |
from a LogicView and paste it into a DrawTool - it will work).
|
|
153 |
|
|
154 |
Reminder: ObjectViews are not to be used as below, but instead to be
|
|
155 |
subclassed. Therefore, the examples below are somewhat untypical.
|
|
156 |
|
|
157 |
simple example:
|
|
158 |
|
|
159 |
|v o|
|
|
160 |
|
|
161 |
v := ObjectView new.
|
|
162 |
v extent:200@200.
|
|
163 |
|
|
164 |
o := DrawRectangle new.
|
|
165 |
o origin:10@10 corner:100@100.
|
|
166 |
v add:o.
|
|
167 |
|
|
168 |
o := DrawText new.
|
|
169 |
o text:'hello there'; origin:50@50; foreground:Color red.
|
|
170 |
v add:o.
|
|
171 |
|
|
172 |
v open
|
|
173 |
|
|
174 |
add scrolling:
|
|
175 |
|
|
176 |
|v top o|
|
|
177 |
|
|
178 |
top := HVScrollableView for:ObjectView.
|
|
179 |
top extent:200@200.
|
|
180 |
v := top scrolledView.
|
|
181 |
|
|
182 |
o := DrawRectangle new.
|
|
183 |
o origin:10@10 corner:100@100.
|
|
184 |
v add:o.
|
|
185 |
|
|
186 |
o := DrawText new.
|
|
187 |
o text:'hello there'; origin:50@50; foreground:Color red.
|
|
188 |
v add:o.
|
|
189 |
|
|
190 |
top open
|
|
191 |
|
|
192 |
or, using miniscrollers:
|
|
193 |
|
|
194 |
|v top o|
|
|
195 |
|
|
196 |
top := HVScrollableView for:ObjectView
|
|
197 |
miniScrollerH:true miniScrollerV:true.
|
|
198 |
top extent:200@200.
|
|
199 |
v := top scrolledView.
|
|
200 |
|
|
201 |
o := DrawRectangle new.
|
|
202 |
o origin:10@10 corner:100@100.
|
|
203 |
v add:o.
|
|
204 |
|
|
205 |
o := DrawText new.
|
|
206 |
o text:'hello there'; origin:50@50; foreground:Color red.
|
|
207 |
v add:o.
|
|
208 |
|
|
209 |
top open
|
|
210 |
|
|
211 |
grid:
|
|
212 |
|
|
213 |
|v top o|
|
|
214 |
|
|
215 |
top := HVScrollableView for:ObjectView
|
|
216 |
miniScrollerH:true miniScrollerV:true.
|
|
217 |
top extent:200@200.
|
|
218 |
v := top scrolledView.
|
|
219 |
v showGrid.
|
|
220 |
|
|
221 |
o := DrawRectangle new.
|
|
222 |
o origin:10@10 corner:100@100.
|
|
223 |
v add:o.
|
|
224 |
|
|
225 |
o := DrawText new.
|
|
226 |
o text:'hello there'; origin:50@50; foreground:Color red.
|
|
227 |
v add:o.
|
|
228 |
|
|
229 |
top open
|
|
230 |
"
|
59
|
231 |
! !
|
0
|
232 |
|
|
233 |
!ObjectView class methodsFor:'defaults'!
|
|
234 |
|
|
235 |
hitDelta
|
|
236 |
"when clicking an object, allow for hitDelta pixels around object;
|
|
237 |
0 is exact; 1*pixelPerMillimeter is good for draw programs"
|
63
|
238 |
|
0
|
239 |
^ 0
|
|
240 |
! !
|
|
241 |
|
71
|
242 |
!ObjectView methodsFor:'scrolling'!
|
|
243 |
|
|
244 |
verticalScrollStep
|
77
|
245 |
"return the amount to scroll when stepping left/right.
|
|
246 |
Redefined to scroll by inches or centimeters."
|
71
|
247 |
|
|
248 |
scaleMetric == #inch ifTrue:[
|
|
249 |
^ (device verticalPixelPerInch * (1/2)) asInteger
|
|
250 |
].
|
|
251 |
^ (device verticalPixelPerMillimeter * 20) asInteger
|
|
252 |
!
|
|
253 |
|
|
254 |
horizontalScrollStep
|
77
|
255 |
"return the amount to scroll when stepping left/right.
|
|
256 |
Redefined to scroll by inches or centimeters."
|
71
|
257 |
|
|
258 |
scaleMetric == #inch ifTrue:[
|
|
259 |
^ (device horizontalPixelPerInch * (1/2)) asInteger
|
|
260 |
].
|
|
261 |
^ (device horizontalPixelPerMillimeter * 20) asInteger
|
|
262 |
! !
|
|
263 |
|
|
264 |
!ObjectView methodsFor:'misc'!
|
|
265 |
|
77
|
266 |
hitDelta
|
|
267 |
"when clicking an object, allow for hitDelta pixels around object.
|
|
268 |
We compensate for any scaling here, to get a constant physical
|
|
269 |
hitDelta (i.e. the value returned here is inverse scaled)."
|
|
270 |
|
|
271 |
|delta|
|
|
272 |
|
|
273 |
delta := self class hitDelta.
|
|
274 |
transformation notNil ifTrue:[
|
|
275 |
delta := delta / transformation scale x
|
|
276 |
].
|
|
277 |
^ delta
|
|
278 |
!
|
|
279 |
|
71
|
280 |
objectsIntersecting:aRectangle do:aBlock
|
|
281 |
"do something to every object which intersects a rectangle"
|
|
282 |
|
|
283 |
|f top bot
|
|
284 |
firstIndex "{ Class: SmallInteger }"
|
|
285 |
delta "{ Class: SmallInteger }"
|
|
286 |
theObject
|
|
287 |
nObjects "{ Class: SmallInteger }"|
|
|
288 |
|
|
289 |
nObjects := contents size.
|
|
290 |
(nObjects == 0) ifTrue:[^ self].
|
|
291 |
|
|
292 |
sorted ifFalse:[
|
|
293 |
"
|
|
294 |
have to check every object
|
|
295 |
"
|
|
296 |
contents do:[:theObject |
|
|
297 |
(theObject frame intersects:aRectangle) ifTrue:[
|
|
298 |
aBlock value:theObject
|
|
299 |
]
|
|
300 |
].
|
|
301 |
^ self
|
|
302 |
].
|
|
303 |
|
|
304 |
"
|
|
305 |
contents is sorted by y; can do a fast (binary) search for the first
|
|
306 |
object which intersects aRectangle and
|
|
307 |
break from the draw loop, when the 1st object below aRectangle is reached.
|
|
308 |
"
|
|
309 |
bot := aRectangle bottom.
|
|
310 |
top := aRectangle top.
|
|
311 |
|
|
312 |
"
|
|
313 |
binary search for an object in aRectangle ...
|
|
314 |
"
|
|
315 |
delta := nObjects // 2.
|
|
316 |
firstIndex := delta.
|
|
317 |
(firstIndex == 0) ifTrue:[
|
|
318 |
firstIndex := 1
|
|
319 |
].
|
|
320 |
theObject := contents at:firstIndex.
|
|
321 |
(theObject frame bottom < top) ifTrue:[
|
|
322 |
[theObject frame bottom < top and:[delta > 1]] whileTrue:[
|
|
323 |
delta := delta // 2.
|
|
324 |
firstIndex := firstIndex + delta.
|
|
325 |
theObject := contents at:firstIndex
|
|
326 |
]
|
|
327 |
] ifFalse:[
|
|
328 |
[theObject frame top > bot and:[delta > 1]] whileTrue:[
|
|
329 |
delta := delta // 2.
|
|
330 |
firstIndex := firstIndex - delta.
|
|
331 |
theObject := contents at:firstIndex
|
|
332 |
]
|
|
333 |
].
|
|
334 |
|
|
335 |
"
|
|
336 |
now, theObject at:firstIndex is in aRectangle; go backward to the object
|
|
337 |
following first non-visible
|
|
338 |
"
|
|
339 |
[theObject frame bottom > top and:[firstIndex > 1]] whileTrue:[
|
|
340 |
firstIndex := firstIndex - 1.
|
|
341 |
theObject := contents at:firstIndex
|
|
342 |
].
|
|
343 |
|
|
344 |
firstIndex to:nObjects do:[:index |
|
|
345 |
theObject := contents at:index.
|
|
346 |
f := theObject frame.
|
|
347 |
(f intersects:aRectangle) ifTrue:[
|
|
348 |
aBlock value:theObject
|
|
349 |
] ifFalse:[
|
|
350 |
(f top > bot) ifTrue:[^ self]
|
|
351 |
]
|
|
352 |
]
|
|
353 |
!
|
|
354 |
|
|
355 |
forEach:aCollection do:aBlock
|
|
356 |
"apply block to every object in a collectioni;
|
|
357 |
(adds a check for non-collection)"
|
|
358 |
|
|
359 |
aCollection isNil ifTrue:[^self].
|
87
|
360 |
aCollection isCollection ifTrue:[
|
71
|
361 |
aCollection do:[:object |
|
|
362 |
object notNil ifTrue:[
|
|
363 |
aBlock value:object
|
|
364 |
]
|
|
365 |
]
|
|
366 |
] ifFalse: [
|
|
367 |
aBlock value:aCollection
|
|
368 |
]
|
|
369 |
!
|
|
370 |
|
|
371 |
objectsIntersectingVisible:aRectangle do:aBlock
|
102
|
372 |
"do something to every object which intersects a visible rectangle.
|
|
373 |
This is a leftOver from times when scrolling was not transparent.
|
|
374 |
Please use objectsIntersecting:do:, since this will vanish."
|
|
375 |
|
|
376 |
self objectsIntersecting:aRectangle do:aBlock
|
71
|
377 |
!
|
|
378 |
|
|
379 |
setDefaultActions
|
|
380 |
motionAction := [:movePoint | nil].
|
|
381 |
releaseAction := [nil]
|
|
382 |
!
|
|
383 |
|
|
384 |
objectsIntersecting:aRectangle
|
|
385 |
"answer a Collection of objects intersecting the argument, aRectangle"
|
|
386 |
|
|
387 |
|newCollection|
|
|
388 |
|
|
389 |
newCollection := OrderedCollection new.
|
|
390 |
self objectsIntersecting:aRectangle do:[:theObject |
|
|
391 |
newCollection add:theObject
|
|
392 |
].
|
|
393 |
(newCollection size == 0) ifTrue:[^ nil].
|
|
394 |
^ newCollection
|
|
395 |
!
|
|
396 |
|
|
397 |
objectsIn:aRectangle do:aBlock
|
|
398 |
"do something to every object which is completely in a rectangle"
|
|
399 |
|
|
400 |
|bot|
|
|
401 |
|
|
402 |
sorted ifTrue:[
|
|
403 |
bot := aRectangle bottom.
|
|
404 |
contents do:[:theObject |
|
|
405 |
(theObject isContainedIn:aRectangle) ifTrue:[
|
|
406 |
aBlock value:theObject
|
|
407 |
] ifFalse:[
|
|
408 |
theObject frame top > bot ifTrue:[^ self]
|
|
409 |
]
|
|
410 |
].
|
|
411 |
^ self
|
|
412 |
].
|
|
413 |
|
|
414 |
contents do:[:theObject |
|
|
415 |
(theObject isContainedIn:aRectangle) ifTrue:[
|
|
416 |
aBlock value:theObject
|
|
417 |
]
|
|
418 |
]
|
|
419 |
!
|
|
420 |
|
|
421 |
documentFormat:aFormatString
|
|
422 |
"set the document format (mostly used by scrollbars).
|
|
423 |
The argument should be a string such as 'a4', 'a5'
|
|
424 |
or 'letter'. See widthOfContentsInMM for supported formats."
|
|
425 |
|
|
426 |
aFormatString ~= documentFormat ifTrue:[
|
|
427 |
documentFormat := aFormatString.
|
|
428 |
self contentsChanged.
|
|
429 |
self defineGrid.
|
|
430 |
gridShown ifTrue:[
|
|
431 |
self clear.
|
|
432 |
self redraw
|
|
433 |
]
|
|
434 |
]
|
|
435 |
!
|
|
436 |
|
|
437 |
objectsInVisible:aRectangle do:aBlock
|
|
438 |
"do something to every object which is completely in a
|
102
|
439 |
visible rectangle.
|
|
440 |
This is a leftOver from times when scrolling was not transparent.
|
|
441 |
Please use objectsIn:do:, since this will vanish."
|
|
442 |
|
|
443 |
self objectsIn:aRectangle do:aBlock
|
71
|
444 |
!
|
|
445 |
|
|
446 |
visibleObjectsDo:aBlock
|
|
447 |
"do something to every visible object"
|
|
448 |
|
102
|
449 |
|absRect|
|
|
450 |
|
|
451 |
absRect := Rectangle left:0 top:0 width:width height:height.
|
71
|
452 |
self objectsIntersecting:absRect do:aBlock
|
|
453 |
!
|
|
454 |
|
|
455 |
numberOfObjectsIntersectingVisible:aRectangle
|
102
|
456 |
"answer the number of objects intersecting the argument, aRectangle.
|
|
457 |
This is a leftOver from times when scrolling was not transparent.
|
|
458 |
Please use numberOfObjectsIntersecting:, since this will vanish."
|
71
|
459 |
|
|
460 |
^ self numberOfObjectsIntersecting:aRectangle
|
|
461 |
!
|
|
462 |
|
|
463 |
numberOfObjectsIntersecting:aRectangle
|
|
464 |
"answer the number of objects intersecting the argument, aRectangle"
|
|
465 |
|
|
466 |
|tally|
|
|
467 |
|
|
468 |
tally := 0.
|
|
469 |
contents do:[:theObject |
|
|
470 |
(theObject frame intersects:aRectangle) ifTrue:[
|
|
471 |
tally := tally + 1
|
|
472 |
]
|
|
473 |
].
|
|
474 |
^ tally
|
|
475 |
!
|
|
476 |
|
|
477 |
objectsIntersectingVisible:aRectangle
|
102
|
478 |
"answer a Collection of objects intersecting a visible aRectangle.
|
|
479 |
This is a leftOver from times when scrolling was not transparent.
|
|
480 |
Please use objectsIntersecting:, since this will vanish."
|
|
481 |
|
|
482 |
^ self objectsIntersecting:aRectangle
|
71
|
483 |
!
|
|
484 |
|
|
485 |
objectsBelow:objectToBeTested do:aBlock
|
|
486 |
"do something to every object below objectToBeTested
|
|
487 |
(does not mean obscured by - simply below in hierarchy)"
|
|
488 |
|
|
489 |
|endIndex|
|
|
490 |
|
|
491 |
endIndex := contents identityIndexOf:objectToBeTested ifAbsent:[self error].
|
|
492 |
contents from:1 to:(endIndex - 1) do:aBlock
|
|
493 |
!
|
|
494 |
|
|
495 |
objectsAbove:objectToBeTested do:aBlock
|
|
496 |
"do something to every object above objectToBeTested
|
|
497 |
(does not mean obscured - simply above in hierarchy)"
|
|
498 |
|
|
499 |
|startIndex|
|
|
500 |
|
|
501 |
startIndex := contents identityIndexOf:objectToBeTested
|
|
502 |
ifAbsent:[self error].
|
|
503 |
contents from:startIndex to:(contents size) do:aBlock
|
|
504 |
!
|
|
505 |
|
|
506 |
objectsAbove:anObject intersecting:aRectangle do:aBlock
|
|
507 |
"do something to every object above objectToBeTested
|
|
508 |
and intersecting aRectangle"
|
|
509 |
|
|
510 |
self objectsAbove:anObject do:[:theObject |
|
|
511 |
(theObject frame intersects:aRectangle) ifTrue:[
|
|
512 |
aBlock value:theObject
|
|
513 |
]
|
|
514 |
]
|
|
515 |
!
|
|
516 |
|
|
517 |
rectangleForScroll
|
|
518 |
"find the area occupied by visible objects"
|
|
519 |
|
|
520 |
|left right top bottom frame oLeft oRight oTop oBottom orgX orgY viewOrigin|
|
|
521 |
|
|
522 |
viewOrigin := 0@0. "/self viewOrigin.
|
|
523 |
orgX := 0 . "/viewOrigin x.
|
|
524 |
orgY := 0 . "/viewOrigin y.
|
|
525 |
left := 9999.
|
|
526 |
right := 0.
|
|
527 |
top := 9999.
|
|
528 |
bottom := 0.
|
|
529 |
self visibleObjectsDo:[:anObject |
|
|
530 |
frame := anObject frame.
|
|
531 |
oLeft := frame left - orgX.
|
|
532 |
oRight := frame right - orgX.
|
|
533 |
oTop := frame top - orgY.
|
|
534 |
oBottom := frame bottom - orgY.
|
|
535 |
(oLeft < left) ifTrue:[left := oLeft].
|
|
536 |
(oRight > right) ifTrue:[right := oRight].
|
|
537 |
(oTop < top) ifTrue:[top := oTop].
|
|
538 |
(oBottom > bottom) ifTrue:[bottom := oBottom]
|
|
539 |
].
|
|
540 |
(left < margin) ifTrue:[left := margin].
|
|
541 |
(top < margin) ifTrue:[top := margin].
|
|
542 |
(right > (width - margin)) ifTrue:[right := width - margin].
|
|
543 |
(bottom > (height - margin)) ifTrue:[bottom := height - margin].
|
|
544 |
|
|
545 |
((left > right) or:[top > bottom]) ifTrue:[^ nil].
|
|
546 |
|
|
547 |
^ Rectangle left:left right:right top:top bottom:bottom
|
|
548 |
! !
|
|
549 |
|
70
|
550 |
!ObjectView methodsFor:'event handling'!
|
0
|
551 |
|
63
|
552 |
redrawX:x y:y width:w height:h
|
77
|
553 |
|redrawFrame |
|
0
|
554 |
|
69
|
555 |
((contents size ~~ 0) or:[gridShown]) ifTrue:[
|
77
|
556 |
redrawFrame := Rectangle left:x top:y
|
|
557 |
width:w height:h.
|
63
|
558 |
self redrawObjectsInVisible:redrawFrame
|
|
559 |
]
|
0
|
560 |
!
|
|
561 |
|
71
|
562 |
buttonPress:button x:x y:y
|
|
563 |
"user pressed left button"
|
|
564 |
|
|
565 |
((button == 1) or:[button == #select]) ifTrue:[
|
|
566 |
pressAction notNil ifTrue:[
|
|
567 |
lastButt := x @ y.
|
|
568 |
pressAction value:lastButt
|
|
569 |
]
|
|
570 |
] ifFalse:[
|
|
571 |
super buttonPress:button x:x y:y
|
|
572 |
]
|
|
573 |
!
|
|
574 |
|
|
575 |
buttonRelease:button x:x y:y
|
|
576 |
((button == 1) or:[button == #select]) ifTrue:[
|
|
577 |
releaseAction notNil ifTrue:[releaseAction value]
|
|
578 |
] ifFalse:[
|
|
579 |
super buttonRelease:button x:x y:y
|
|
580 |
]
|
|
581 |
!
|
|
582 |
|
63
|
583 |
buttonMotion:buttonMask x:buttX y:buttY
|
|
584 |
"user moved mouse while button pressed"
|
|
585 |
|
|
586 |
|xpos ypos movePoint limitW limitH|
|
|
587 |
|
|
588 |
"is it the select or 1-button ?"
|
|
589 |
(device buttonMotionMask:buttonMask includesButton:#select) ifFalse:[
|
|
590 |
(device buttonMotionMask:buttonMask includesButton:1) ifFalse:[
|
|
591 |
^ self
|
|
592 |
].
|
|
593 |
].
|
|
594 |
|
|
595 |
lastButt notNil ifTrue:[
|
|
596 |
xpos := buttX.
|
|
597 |
ypos := buttY.
|
|
598 |
|
|
599 |
"check against visible limits if move outside is not allowed"
|
|
600 |
rootMotion ifFalse:[
|
|
601 |
limitW := width.
|
|
602 |
limitH := height.
|
|
603 |
transformation notNil ifTrue:[
|
|
604 |
limitW := transformation applyInverseToX:width.
|
|
605 |
limitH := transformation applyInverseToY:height.
|
|
606 |
].
|
|
607 |
|
|
608 |
(xpos < 0) ifTrue:[
|
|
609 |
xpos := 0
|
|
610 |
] ifFalse: [
|
|
611 |
(xpos > limitW) ifTrue:[xpos := limitW]
|
|
612 |
].
|
|
613 |
(ypos < 0) ifTrue:[
|
|
614 |
ypos := 0
|
|
615 |
] ifFalse: [
|
|
616 |
(ypos > limitH) ifTrue:[ypos := limitH]
|
|
617 |
]
|
|
618 |
].
|
|
619 |
movePoint := xpos @ ypos.
|
|
620 |
|
|
621 |
(xpos == (lastButt x)) ifTrue:[
|
|
622 |
(ypos == (lastButt y)) ifTrue:[
|
|
623 |
^ self "no move"
|
|
624 |
]
|
|
625 |
].
|
|
626 |
|
|
627 |
motionAction notNil ifTrue:[
|
|
628 |
motionAction value:movePoint
|
|
629 |
].
|
|
630 |
lastButt := movePoint
|
|
631 |
]
|
|
632 |
!
|
|
633 |
|
71
|
634 |
buttonMultiPress:button x:x y:y
|
|
635 |
"user pressed left button twice (or more)"
|
63
|
636 |
|
|
637 |
((button == 1) or:[button == #select]) ifTrue:[
|
71
|
638 |
doublePressAction notNil ifTrue:[
|
|
639 |
doublePressAction value:(x @ y)
|
63
|
640 |
]
|
|
641 |
] ifFalse:[
|
71
|
642 |
super buttonMultiPress:button x:x y:y
|
63
|
643 |
]
|
|
644 |
!
|
|
645 |
|
|
646 |
buttonShiftPress:button x:x y:y
|
|
647 |
"user pressed left button with shift"
|
|
648 |
|
|
649 |
((button == 1) or:[button == #select]) ifTrue:[
|
|
650 |
shiftPressAction notNil ifTrue:[
|
|
651 |
lastButt := x @ y.
|
|
652 |
shiftPressAction value:lastButt
|
|
653 |
]
|
|
654 |
] ifFalse:[
|
|
655 |
super buttonShiftPress:button x:x y:y
|
|
656 |
]
|
|
657 |
!
|
|
658 |
|
|
659 |
keyPress:key x:x y:y
|
|
660 |
keyPressAction notNil ifTrue:[
|
|
661 |
selection notNil ifTrue:[
|
|
662 |
self selectionDo: [:obj |
|
|
663 |
obj keyInput:key
|
|
664 |
]
|
|
665 |
]
|
|
666 |
]
|
0
|
667 |
! !
|
|
668 |
|
71
|
669 |
!ObjectView methodsFor:'dragging object move'!
|
|
670 |
|
|
671 |
doObjectMove:aPoint
|
77
|
672 |
"do an object move - this is called for every motion
|
|
673 |
when moving objects."
|
|
674 |
|
102
|
675 |
|d org nOrg|
|
77
|
676 |
|
71
|
677 |
movedObject isNil ifTrue:[
|
|
678 |
movedObject := selection.
|
|
679 |
"
|
|
680 |
draw first outline
|
|
681 |
"
|
|
682 |
movedObject notNil ifTrue:[
|
|
683 |
moveDelta := 0@0.
|
|
684 |
|
77
|
685 |
"tricky, the moved object may not currently be aligned.
|
|
686 |
if so, simulate a frame move of the delta"
|
|
687 |
|
|
688 |
aligning ifTrue:[
|
102
|
689 |
org := movedObject origin.
|
|
690 |
d := org - (self alignToGrid:(org)).
|
77
|
691 |
moveDelta := d negated.
|
|
692 |
].
|
|
693 |
self invertDragObject:movedObject delta:moveDelta
|
71
|
694 |
]
|
|
695 |
].
|
|
696 |
movedObject notNil ifTrue:[
|
83
|
697 |
d := aPoint - moveStartPoint.
|
77
|
698 |
aligning ifTrue:[
|
102
|
699 |
org := movedObject origin.
|
|
700 |
nOrg := org + d.
|
|
701 |
d := (self alignToGrid:(nOrg)) - org.
|
77
|
702 |
].
|
83
|
703 |
d ~= moveDelta ifTrue:[
|
|
704 |
"
|
|
705 |
clear prev outline,
|
|
706 |
draw new outline
|
|
707 |
"
|
|
708 |
self invertDragObject:movedObject delta:moveDelta.
|
|
709 |
moveDelta := d.
|
|
710 |
self invertDragObject:movedObject delta:moveDelta
|
|
711 |
]
|
71
|
712 |
]
|
|
713 |
!
|
|
714 |
|
|
715 |
endObjectMove
|
77
|
716 |
"cleanup after object move - called when the object move ends.
|
|
717 |
Find the destination view and position and dispatch to
|
|
718 |
one of the moveObjectXXX-methods which should do the real move.
|
|
719 |
These can be redefined in subclasses."
|
|
720 |
|
|
721 |
|inMySelf rootPoint destinationPoint p
|
71
|
722 |
viewId destinationView destinationId lastViewId|
|
|
723 |
|
|
724 |
movedObject notNil ifTrue:[
|
77
|
725 |
self invertDragObject:movedObject delta:moveDelta.
|
71
|
726 |
|
|
727 |
"check if object is to be put into another view"
|
|
728 |
rootMotion ifTrue:[
|
77
|
729 |
p := lastButt.
|
|
730 |
"
|
|
731 |
get device coordinates
|
|
732 |
"
|
|
733 |
transformation notNil ifTrue:[
|
|
734 |
p := transformation applyTo:p.
|
|
735 |
].
|
|
736 |
"
|
|
737 |
translate to screen
|
|
738 |
"
|
|
739 |
rootPoint := p + (device translatePoint:0@0 from:(self id) to:(rootView id)).
|
|
740 |
|
71
|
741 |
"search view the drop is in"
|
|
742 |
viewId := rootView id.
|
|
743 |
[viewId notNil] whileTrue:[
|
|
744 |
destinationId := device viewIdFromPoint:rootPoint in:viewId.
|
|
745 |
lastViewId := viewId.
|
|
746 |
viewId := destinationId
|
|
747 |
].
|
|
748 |
destinationView := device viewFromId:lastViewId.
|
|
749 |
destinationId := lastViewId.
|
|
750 |
inMySelf := (destinationView == self).
|
|
751 |
rootMotion := false
|
|
752 |
] ifFalse:[
|
|
753 |
inMySelf := true
|
|
754 |
].
|
77
|
755 |
|
71
|
756 |
inMySelf ifTrue:[
|
|
757 |
"simple move"
|
|
758 |
self move:movedObject by:moveDelta
|
|
759 |
] ifFalse:[
|
|
760 |
destinationPoint := device translatePoint:rootPoint
|
|
761 |
from:(rootView id)
|
|
762 |
to:destinationId.
|
|
763 |
destinationView notNil ifTrue:[
|
83
|
764 |
destinationView transformation notNil ifTrue:[
|
|
765 |
destinationPoint := destinationView transformation applyInverseTo:destinationPoint
|
|
766 |
].
|
71
|
767 |
"
|
|
768 |
move into another smalltalk view
|
|
769 |
"
|
|
770 |
self move:movedObject to:destinationPoint in:destinationView
|
|
771 |
] ifFalse:[
|
|
772 |
"
|
|
773 |
not one of my views
|
|
774 |
"
|
|
775 |
self move:movedObject to:destinationPoint inAlienViewId:destinationId
|
|
776 |
]
|
|
777 |
].
|
|
778 |
self setDefaultActions.
|
|
779 |
movedObject := nil
|
|
780 |
]
|
|
781 |
!
|
|
782 |
|
|
783 |
startObjectMove:something at:aPoint
|
|
784 |
"start an object move"
|
|
785 |
|
77
|
786 |
self startObjectMove:something at:aPoint inRoot:canDragOutOfView
|
|
787 |
!
|
|
788 |
|
|
789 |
startRootObjectMove:something at:aPoint
|
|
790 |
"start an object move, possibly crossing view boundaries"
|
|
791 |
|
|
792 |
self startObjectMove:something at:aPoint inRoot:true
|
|
793 |
!
|
|
794 |
|
|
795 |
startObjectMove:something at:aPoint inRoot:inRoot
|
|
796 |
"start an object move; if inRoot is true, view
|
|
797 |
boundaries may be crossed."
|
|
798 |
|
71
|
799 |
something notNil ifTrue:[
|
|
800 |
self select:something.
|
|
801 |
(self canMove:something) ifTrue:[
|
|
802 |
self setMoveActions.
|
|
803 |
moveStartPoint := aPoint.
|
77
|
804 |
rootMotion := inRoot.
|
71
|
805 |
] ifFalse:[
|
|
806 |
self setDefaultActions
|
|
807 |
]
|
|
808 |
]
|
77
|
809 |
!
|
|
810 |
|
|
811 |
setMoveActions
|
|
812 |
"setup to drag an object. Call this (for example) from your buttonPress
|
|
813 |
method, to make the view start to drag some object.
|
|
814 |
See startObjectMove and startRootObjectMove."
|
|
815 |
|
|
816 |
motionAction := [:movePoint | self doObjectMove:movePoint].
|
|
817 |
releaseAction := [self endObjectMove]
|
|
818 |
!
|
|
819 |
|
|
820 |
invertDragObject:movedObject delta:moveDelta
|
|
821 |
"draw inverting for an object move"
|
|
822 |
|
|
823 |
|dragger offs p d scale oldTrans|
|
|
824 |
|
|
825 |
rootMotion ifTrue:[
|
|
826 |
p := movedObject origin + moveDelta.
|
|
827 |
dragger := rootView.
|
|
828 |
"
|
|
829 |
get device coordinates
|
|
830 |
"
|
|
831 |
"/ 'logical ' print. p printNL.
|
|
832 |
transformation notNil ifTrue:[
|
|
833 |
scale := transformation scale.
|
|
834 |
p := transformation applyTo:p.
|
|
835 |
"/ 'device ' print. p printNL.
|
|
836 |
].
|
|
837 |
"
|
|
838 |
translate to screen
|
|
839 |
"
|
|
840 |
offs := device translatePoint:0@0 from:(self id) to:(rootView id).
|
|
841 |
"/ 'offs' print. offs printNL.
|
|
842 |
p := p + offs.
|
|
843 |
"/ 'screen ' print. p printNL.
|
|
844 |
"
|
|
845 |
p is where we want it ...
|
|
846 |
have to adust slightly, since showDragging shows the object
|
|
847 |
at its origin plus some offset; here we want it to be drawn
|
|
848 |
at absolute p.
|
|
849 |
To do so, we set the draggers translation to p and
|
|
850 |
draw the object scaled at 0@0 (by setting offset to its negative org)
|
|
851 |
"
|
|
852 |
|
|
853 |
oldTrans := dragger transformation.
|
|
854 |
dragger transformation:(WindowingTransformation
|
|
855 |
scale:scale
|
|
856 |
translation:p).
|
|
857 |
d := movedObject origin negated.
|
|
858 |
|
|
859 |
dragger xoring:[
|
|
860 |
self showDragging:movedObject offset:d.
|
|
861 |
].
|
|
862 |
|
|
863 |
dragger transformation:oldTrans.
|
|
864 |
dragger device synchronizeOutput.
|
|
865 |
] ifFalse:[
|
|
866 |
self xoring:[
|
|
867 |
self showDragging:movedObject offset:moveDelta.
|
|
868 |
].
|
|
869 |
self device synchronizeOutput
|
|
870 |
].
|
71
|
871 |
! !
|
|
872 |
|
|
873 |
!ObjectView methodsFor:'drawing'!
|
|
874 |
|
|
875 |
showDragging:something offset:anOffset
|
|
876 |
"show an object while dragging"
|
|
877 |
|
77
|
878 |
|drawer|
|
71
|
879 |
|
|
880 |
rootMotion ifTrue:[
|
|
881 |
"drag in root-window"
|
|
882 |
|
|
883 |
drawer := rootView
|
|
884 |
] ifFalse:[
|
|
885 |
drawer := self
|
65
|
886 |
].
|
71
|
887 |
self forEach:something do:[:anObject |
|
77
|
888 |
anObject drawDragIn:drawer offset:anOffset
|
71
|
889 |
]
|
|
890 |
!
|
|
891 |
|
102
|
892 |
redrawObjectsIntersecting:aRectangle
|
|
893 |
"redraw all objects which have part of themself in aRectangle"
|
|
894 |
|
|
895 |
self objectsIntersecting:aRectangle do:[:theObject |
|
71
|
896 |
self show:theObject
|
|
897 |
]
|
102
|
898 |
!
|
|
899 |
|
|
900 |
redrawObjectsIntersectingVisible:aRectangle
|
|
901 |
"redraw all objects which have part of themself in a vis rectangle
|
|
902 |
This is a leftOver from times when scrolling was not transparent.
|
|
903 |
Please use redrawObjectsIntersecting:, since this will vanish."
|
|
904 |
|
|
905 |
self redrawObjectsIntersecting:aRectangle
|
71
|
906 |
!
|
|
907 |
|
|
908 |
redrawObjectsInVisible:visRect
|
|
909 |
"redraw all objects which have part of themselfes in a vis rectangle
|
|
910 |
draw only in (i.e. clip output to) aRectangle"
|
|
911 |
|
|
912 |
|vis|
|
|
913 |
|
|
914 |
shown ifTrue:[
|
|
915 |
vis := visRect.
|
|
916 |
clipRect notNil ifTrue:[
|
|
917 |
vis := vis intersect:clipRect
|
|
918 |
].
|
77
|
919 |
|
71
|
920 |
transformation notNil ifTrue:[
|
77
|
921 |
transformation scale ~~ 1 ifTrue:[
|
|
922 |
vis := vis origin truncated
|
|
923 |
corner:(vis corner + (1@1)) truncated.
|
|
924 |
]
|
71
|
925 |
].
|
|
926 |
|
|
927 |
self clippedTo:vis do:[
|
|
928 |
self clearRectangle:vis.
|
102
|
929 |
self redrawObjectsIntersecting:vis
|
71
|
930 |
]
|
|
931 |
]
|
|
932 |
!
|
|
933 |
|
|
934 |
redraw
|
|
935 |
"redraw complete View"
|
|
936 |
|
|
937 |
shown ifTrue:[
|
|
938 |
self clear.
|
|
939 |
self redrawObjects
|
|
940 |
]
|
|
941 |
!
|
|
942 |
|
|
943 |
redrawObjectsOn:aGC
|
|
944 |
"redraw all objects on a graphic context"
|
|
945 |
|
|
946 |
|vFrame org viewOrigin|
|
|
947 |
|
|
948 |
(aGC == self) ifTrue:[
|
|
949 |
shown ifFalse:[^ self].
|
|
950 |
viewOrigin := 0@0. "/self viewOrigin.
|
|
951 |
org := viewOrigin.
|
|
952 |
vFrame := Rectangle origin:org
|
|
953 |
corner:(viewOrigin + (width @ height)).
|
|
954 |
|
|
955 |
transformation notNil ifTrue:[
|
|
956 |
vFrame := transformation applyInverseTo:vFrame.
|
|
957 |
].
|
|
958 |
self redrawObjectsIntersecting:vFrame
|
|
959 |
] ifFalse:[
|
|
960 |
"loop over pages"
|
|
961 |
|
|
962 |
"
|
|
963 |
org := 0 @ 0.
|
|
964 |
vFrame := Rectangle origin:org
|
|
965 |
corner:(org + (width @ height)).
|
|
966 |
|
|
967 |
self redrawObjectsIntersecting:vFrame
|
|
968 |
"
|
|
969 |
self objectsIntersecting:vFrame do:[:theObject |
|
|
970 |
theObject drawIn:aGC
|
|
971 |
]
|
|
972 |
]
|
|
973 |
!
|
|
974 |
|
|
975 |
redrawObjects
|
|
976 |
"redraw all objects"
|
|
977 |
|
|
978 |
self redrawObjectsOn:self
|
|
979 |
!
|
|
980 |
|
|
981 |
show:anObject
|
|
982 |
"show the object, either selected or not"
|
|
983 |
|
|
984 |
(self isSelected:anObject) ifTrue:[
|
|
985 |
self showSelected:anObject
|
|
986 |
] ifFalse:[
|
|
987 |
self showUnselected:anObject
|
|
988 |
]
|
65
|
989 |
!
|
|
990 |
|
71
|
991 |
showUnselected:anObject
|
|
992 |
"show an object as unselected"
|
|
993 |
|
|
994 |
anObject drawIn:self
|
|
995 |
!
|
|
996 |
|
|
997 |
redrawObjectsIn:aRectangle
|
|
998 |
"redraw all objects which have part of themselfes in aRectangle
|
|
999 |
draw only in (i.e. clip output to) aRectangle"
|
|
1000 |
|
102
|
1001 |
|visRect|
|
71
|
1002 |
|
|
1003 |
shown ifTrue:[
|
102
|
1004 |
visRect := Rectangle origin:(aRectangle origin)
|
71
|
1005 |
extent:(aRectangle extent).
|
|
1006 |
transformation notNil ifTrue:[
|
|
1007 |
visRect := visRect origin truncated
|
|
1008 |
corner:(visRect corner + (1@1)) truncated.
|
|
1009 |
].
|
|
1010 |
clipRect notNil ifTrue:[
|
|
1011 |
visRect := visRect intersect:clipRect
|
|
1012 |
].
|
|
1013 |
self clippedTo:visRect do:[
|
|
1014 |
self clearRectangle:visRect.
|
102
|
1015 |
self redrawObjectsIntersecting:visRect
|
71
|
1016 |
]
|
|
1017 |
]
|
|
1018 |
!
|
|
1019 |
|
|
1020 |
redrawScale
|
|
1021 |
"redraw the scales"
|
|
1022 |
|
|
1023 |
self redrawHorizontalScale.
|
|
1024 |
self redrawVerticalScale
|
|
1025 |
!
|
|
1026 |
|
|
1027 |
redrawObjectsAbove:anObject intersecting:aRectangle
|
|
1028 |
"redraw all objects which have part of themself in aRectangle
|
|
1029 |
and are above (in front of) anObject"
|
|
1030 |
|
|
1031 |
self objectsAbove:anObject intersecting:aRectangle do:[:theObject |
|
|
1032 |
self show:theObject
|
|
1033 |
]
|
|
1034 |
!
|
|
1035 |
|
|
1036 |
redrawObjectsAbove:anObject intersectingVisible:aRectangle
|
|
1037 |
"redraw all objects which have part of themself in a vis rectangle
|
|
1038 |
and are above (in front of) anObject"
|
|
1039 |
|
|
1040 |
self objectsAbove:anObject intersectingVisible:aRectangle do:[:theObject |
|
|
1041 |
self show:theObject
|
|
1042 |
]
|
|
1043 |
!
|
|
1044 |
|
|
1045 |
showSelected:anObject
|
|
1046 |
"show an object as selected"
|
|
1047 |
|
|
1048 |
anObject drawSelectedIn:self
|
|
1049 |
!
|
|
1050 |
|
|
1051 |
redrawObjectsAbove:anObject in:aRectangle
|
|
1052 |
"redraw all objects which have part of themselfes in aRectangle
|
|
1053 |
and are above (in front of) anObject.
|
|
1054 |
draw only in (i.e. clip output to) aRectangle"
|
|
1055 |
|
|
1056 |
|vis|
|
|
1057 |
|
|
1058 |
shown ifTrue:[
|
|
1059 |
vis := aRectangle.
|
|
1060 |
clipRect notNil ifTrue:[
|
|
1061 |
vis := vis intersect:clipRect
|
|
1062 |
].
|
|
1063 |
self clippedTo:vis do:[
|
|
1064 |
self redrawObjectsAbove:anObject intersecting:vis
|
|
1065 |
]
|
|
1066 |
]
|
|
1067 |
!
|
|
1068 |
|
|
1069 |
redrawObjectsAbove:anObject inVisible:aRectangle
|
|
1070 |
"redraw all objects which have part of themselfes in a vis rectangle
|
|
1071 |
and are above (in front of) anObject.
|
|
1072 |
draw only in (i.e. clip output to) aRectangle"
|
|
1073 |
|
|
1074 |
|vis|
|
|
1075 |
|
|
1076 |
shown ifTrue:[
|
|
1077 |
vis := aRectangle.
|
|
1078 |
clipRect notNil ifTrue:[
|
|
1079 |
vis := vis intersect:clipRect
|
|
1080 |
].
|
|
1081 |
self clippedTo:vis do:[
|
|
1082 |
self redrawObjectsAbove:anObject intersectingVisible:vis
|
|
1083 |
]
|
|
1084 |
]
|
65
|
1085 |
! !
|
|
1086 |
|
0
|
1087 |
!ObjectView methodsFor:'queries'!
|
|
1088 |
|
63
|
1089 |
heightOfContents
|
|
1090 |
"answer the height of the document in pixels"
|
0
|
1091 |
|
63
|
1092 |
|h|
|
59
|
1093 |
|
63
|
1094 |
h := self heightOfContentsInMM * (self verticalPixelPerMillimeter:1).
|
77
|
1095 |
^ h rounded
|
0
|
1096 |
!
|
|
1097 |
|
71
|
1098 |
widthOfContents
|
|
1099 |
"answer the width of the document in pixels"
|
|
1100 |
|
|
1101 |
|w|
|
|
1102 |
|
|
1103 |
w := self widthOfContentsInMM * (self horizontalPixelPerMillimeter:1).
|
77
|
1104 |
^ w rounded
|
0
|
1105 |
!
|
|
1106 |
|
63
|
1107 |
heightOfContentsInMM
|
|
1108 |
"answer the height of the document in millimeters"
|
|
1109 |
|
|
1110 |
"landscape"
|
|
1111 |
(documentFormat = 'a1l') ifTrue:[
|
|
1112 |
^ 592
|
|
1113 |
].
|
|
1114 |
(documentFormat = 'a2l') ifTrue:[
|
|
1115 |
^ 420
|
|
1116 |
].
|
|
1117 |
(documentFormat = 'a3l') ifTrue:[
|
|
1118 |
^ 296
|
|
1119 |
].
|
|
1120 |
(documentFormat = 'a4l') ifTrue:[
|
|
1121 |
^ 210
|
|
1122 |
].
|
|
1123 |
(documentFormat = 'a5l') ifTrue:[
|
|
1124 |
^ 148
|
|
1125 |
].
|
|
1126 |
(documentFormat = 'a6l') ifTrue:[
|
|
1127 |
^ 105
|
|
1128 |
].
|
|
1129 |
(documentFormat = 'letterl') ifTrue:[
|
|
1130 |
^ 8.5 * 25.4
|
|
1131 |
].
|
0
|
1132 |
|
63
|
1133 |
(documentFormat = 'a1') ifTrue:[
|
|
1134 |
^ 840
|
|
1135 |
].
|
|
1136 |
(documentFormat = 'a2') ifTrue:[
|
|
1137 |
^ 592
|
|
1138 |
].
|
|
1139 |
(documentFormat = 'a3') ifTrue:[
|
|
1140 |
^ 420
|
|
1141 |
].
|
|
1142 |
(documentFormat = 'a4') ifTrue:[
|
|
1143 |
^ 296
|
|
1144 |
].
|
|
1145 |
(documentFormat = 'a5') ifTrue:[
|
|
1146 |
^ 210
|
|
1147 |
].
|
|
1148 |
(documentFormat = 'a6') ifTrue:[
|
|
1149 |
^ 148
|
|
1150 |
].
|
|
1151 |
(documentFormat = 'letter') ifTrue:[
|
|
1152 |
^ 11 * 25.4
|
|
1153 |
].
|
|
1154 |
"*** more formats needed here ...***"
|
|
1155 |
|
|
1156 |
"assuming window size is document size"
|
|
1157 |
^ (height / self verticalPixelPerMillimeter:1) asInteger
|
0
|
1158 |
!
|
|
1159 |
|
71
|
1160 |
widthOfContentsInMM
|
|
1161 |
"answer the width of the document in millimeters"
|
|
1162 |
|
|
1163 |
"landscape"
|
|
1164 |
(documentFormat = 'a1l') ifTrue:[
|
|
1165 |
^ 840
|
|
1166 |
].
|
|
1167 |
(documentFormat = 'a2l') ifTrue:[
|
|
1168 |
^ 592
|
|
1169 |
].
|
|
1170 |
(documentFormat = 'a3l') ifTrue:[
|
|
1171 |
^ 420
|
|
1172 |
].
|
|
1173 |
(documentFormat = 'a4l') ifTrue:[
|
|
1174 |
^ 296
|
|
1175 |
].
|
|
1176 |
(documentFormat = 'a5l') ifTrue:[
|
|
1177 |
^ 210
|
|
1178 |
].
|
|
1179 |
(documentFormat = 'a6l') ifTrue:[
|
|
1180 |
^ 148
|
|
1181 |
].
|
|
1182 |
(documentFormat = 'letterl') ifTrue:[
|
|
1183 |
^ 11 * 25.4
|
|
1184 |
].
|
|
1185 |
|
|
1186 |
(documentFormat = 'a1') ifTrue:[
|
|
1187 |
^ 592
|
|
1188 |
].
|
|
1189 |
(documentFormat = 'a2') ifTrue:[
|
|
1190 |
^ 420
|
|
1191 |
].
|
|
1192 |
(documentFormat = 'a3') ifTrue:[
|
|
1193 |
^ 296
|
|
1194 |
].
|
|
1195 |
(documentFormat = 'a4') ifTrue:[
|
|
1196 |
^ 210
|
|
1197 |
].
|
|
1198 |
(documentFormat = 'a5') ifTrue:[
|
|
1199 |
^ 148
|
|
1200 |
].
|
|
1201 |
(documentFormat = 'a6') ifTrue:[
|
|
1202 |
^ 105
|
|
1203 |
].
|
|
1204 |
(documentFormat = 'letter') ifTrue:[
|
|
1205 |
^ 8.5 * 25.4
|
|
1206 |
].
|
|
1207 |
"*** more formats needed here ...***"
|
|
1208 |
|
|
1209 |
"assuming window size is document size"
|
|
1210 |
^ (width / self horizontalPixelPerMillimeter:1) asInteger
|
|
1211 |
! !
|
|
1212 |
|
|
1213 |
!ObjectView methodsFor:'testing objects'!
|
|
1214 |
|
|
1215 |
frameOf:anObjectOrCollection
|
|
1216 |
"answer the maximum extent defined by the argument, anObject or a
|
|
1217 |
collection of objects"
|
|
1218 |
|
|
1219 |
|first frameAll|
|
|
1220 |
|
|
1221 |
anObjectOrCollection isNil ifTrue:[^ nil ].
|
|
1222 |
first := true.
|
|
1223 |
self forEach:anObjectOrCollection do:[:theObject |
|
|
1224 |
first ifTrue:[
|
|
1225 |
frameAll := theObject frame.
|
|
1226 |
first := false
|
|
1227 |
] ifFalse:[
|
|
1228 |
frameAll := frameAll merge:(theObject frame)
|
|
1229 |
]
|
|
1230 |
].
|
|
1231 |
^ frameAll
|
|
1232 |
!
|
|
1233 |
|
|
1234 |
isObscured:something
|
|
1235 |
"return true, if the argument something, anObject or a collection of
|
|
1236 |
objects is obscured (partially or whole) by any other object"
|
|
1237 |
|
|
1238 |
self forEach:something do:[:anObject |
|
|
1239 |
(self objectIsObscured:anObject) ifTrue:[
|
|
1240 |
^ true
|
|
1241 |
]
|
63
|
1242 |
].
|
71
|
1243 |
^ false
|
|
1244 |
!
|
|
1245 |
|
|
1246 |
findObjectAt:aPoint
|
|
1247 |
"find the last object (by looking from back to front) which is hit by
|
|
1248 |
the argument, aPoint - this is the topmost object hit"
|
|
1249 |
|
|
1250 |
|hdelta|
|
|
1251 |
|
77
|
1252 |
hdelta := self hitDelta.
|
71
|
1253 |
contents reverseDo:[:object |
|
|
1254 |
(object isHitBy:aPoint withDelta:hdelta) ifTrue:[^ object]
|
|
1255 |
].
|
|
1256 |
^ nil
|
|
1257 |
!
|
|
1258 |
|
|
1259 |
findObjectAtVisible:aPoint
|
|
1260 |
"find the last object (by looking from back to front) which is hit by
|
102
|
1261 |
a visible point - this is the topmost object hit.
|
|
1262 |
This is a leftOver from times when scrolling was not transparent.
|
|
1263 |
Please use findObjectAt:, since this will vanish."
|
|
1264 |
|
|
1265 |
^ self findObjectAt:aPoint
|
71
|
1266 |
!
|
|
1267 |
|
|
1268 |
isSelected:anObject
|
|
1269 |
"return true, if the argument, anObject is in the selection"
|
|
1270 |
|
|
1271 |
selection isNil ifTrue:[^ false].
|
|
1272 |
(selection == anObject) ifTrue:[^ true].
|
87
|
1273 |
selection isCollection ifTrue:[
|
71
|
1274 |
^ (selection identityIndexOf:anObject startingAt:1) ~~ 0
|
|
1275 |
].
|
|
1276 |
^ false
|
|
1277 |
!
|
|
1278 |
|
|
1279 |
canMove:something
|
|
1280 |
"return true, if the argument, anObject or a collection can be moved"
|
|
1281 |
|
87
|
1282 |
something isCollection ifTrue:[
|
71
|
1283 |
self forEach:something do:[:theObject |
|
|
1284 |
(theObject canBeMoved) ifFalse:[^ false]
|
|
1285 |
].
|
|
1286 |
^ true
|
|
1287 |
].
|
|
1288 |
^ something canBeMoved
|
|
1289 |
!
|
|
1290 |
|
|
1291 |
objectIsObscured:objectToBeTested
|
|
1292 |
"return true, if the argument, anObject is obscured (partially or whole)
|
|
1293 |
by any other object"
|
|
1294 |
|
|
1295 |
|frameToBeTested frameleft frameright frametop framebot
|
|
1296 |
objectsFrame startIndex|
|
|
1297 |
|
|
1298 |
(objectToBeTested == (contents last)) ifTrue:[
|
|
1299 |
"quick return if object is on top"
|
|
1300 |
^ false
|
|
1301 |
].
|
|
1302 |
|
|
1303 |
frameToBeTested := self frameOf:objectToBeTested.
|
|
1304 |
frameleft := frameToBeTested left.
|
|
1305 |
frameright := frameToBeTested right.
|
|
1306 |
frametop := frameToBeTested top.
|
|
1307 |
framebot := frameToBeTested bottom.
|
|
1308 |
|
|
1309 |
"check objects after the one to check"
|
|
1310 |
|
|
1311 |
startIndex := contents identityIndexOf:objectToBeTested ifAbsent:[self error].
|
|
1312 |
contents from:(startIndex + 1) to:(contents size) do:[:object |
|
|
1313 |
objectsFrame := self frameOf:object.
|
|
1314 |
(objectsFrame right < frameleft) ifFalse:[
|
|
1315 |
(objectsFrame left > frameright) ifFalse:[
|
|
1316 |
(objectsFrame bottom < frametop) ifFalse:[
|
|
1317 |
(objectsFrame top > framebot) ifFalse:[
|
|
1318 |
^ true
|
|
1319 |
]
|
|
1320 |
]
|
|
1321 |
]
|
|
1322 |
]
|
|
1323 |
].
|
|
1324 |
^ false
|
|
1325 |
!
|
|
1326 |
|
|
1327 |
findObjectAt:aPoint suchThat:aBlock
|
|
1328 |
"find the last object (back to front ) which is hit by
|
|
1329 |
the argument, aPoint and for which the testBlock, aBlock evaluates to
|
|
1330 |
true"
|
|
1331 |
|
|
1332 |
|hdelta|
|
|
1333 |
|
77
|
1334 |
hdelta := self hitDelta.
|
71
|
1335 |
contents reverseDo:[:object |
|
|
1336 |
(object isHitBy:aPoint withDelta:hdelta) ifTrue:[
|
|
1337 |
(aBlock value:object) ifTrue:[^ object]
|
|
1338 |
]
|
|
1339 |
].
|
|
1340 |
^ nil
|
|
1341 |
!
|
|
1342 |
|
|
1343 |
findObjectAtVisible:aPoint suchThat:aBlock
|
|
1344 |
"find the last object (back to front ) which is hit by
|
|
1345 |
the argument, aPoint and for which the testBlock, aBlock evaluates to
|
102
|
1346 |
true.
|
|
1347 |
This is a leftOver from times when scrolling was not transparent.
|
|
1348 |
Please use findObjectAt:suchThat:, since this will vanish."
|
|
1349 |
|
|
1350 |
^ self findObjectAt:aPoint suchThat:aBlock
|
63
|
1351 |
! !
|
|
1352 |
|
|
1353 |
!ObjectView methodsFor:'user interface'!
|
|
1354 |
|
|
1355 |
alignToGrid:aPoint
|
|
1356 |
"round aPoint to the next nearest point on the grid"
|
|
1357 |
|
|
1358 |
aligning ifFalse:[
|
|
1359 |
^ aPoint
|
|
1360 |
].
|
|
1361 |
|
|
1362 |
^ (aPoint grid:gridAlign) rounded
|
|
1363 |
!
|
|
1364 |
|
|
1365 |
startSelectOrMove:aPoint
|
|
1366 |
"start a rectangleDrag or objectMove - if aPoint hits an object,
|
|
1367 |
an object move is started, otherwise a rectangleDrag.
|
|
1368 |
This is typically the button pressAction."
|
|
1369 |
|
|
1370 |
|anObject|
|
|
1371 |
|
102
|
1372 |
anObject := self findObjectAt:aPoint.
|
63
|
1373 |
anObject notNil ifTrue:[
|
|
1374 |
(self isSelected:anObject) ifFalse:[self unselect].
|
|
1375 |
self startObjectMove:anObject at:aPoint.
|
|
1376 |
^ self
|
|
1377 |
].
|
|
1378 |
"nothing was hit by this click - this starts a group select"
|
|
1379 |
self unselect.
|
|
1380 |
self startRectangleDrag:aPoint
|
|
1381 |
!
|
|
1382 |
|
|
1383 |
selectMore:aPoint
|
|
1384 |
"add/remove an object from the selection"
|
|
1385 |
|
|
1386 |
|anObject|
|
|
1387 |
|
102
|
1388 |
anObject := self findObjectAt:aPoint.
|
63
|
1389 |
anObject notNil ifTrue:[
|
|
1390 |
(self isSelected:anObject) ifTrue:[
|
|
1391 |
"remove from selection"
|
|
1392 |
self removeFromSelection:anObject
|
|
1393 |
] ifFalse:[
|
|
1394 |
"add to selection"
|
|
1395 |
self addToSelection:anObject
|
|
1396 |
]
|
|
1397 |
].
|
|
1398 |
^ self
|
|
1399 |
!
|
|
1400 |
|
|
1401 |
startSelectMoreOrMove:aPoint
|
|
1402 |
"add/remove object hit by aPoint, then start a rectangleDrag or move
|
|
1403 |
- if aPoint hits an object, a move is started, otherwise a rectangleDrag.
|
|
1404 |
This is typically the button shiftPressAction."
|
|
1405 |
|
|
1406 |
|anObject|
|
|
1407 |
|
102
|
1408 |
anObject := self findObjectAt:aPoint.
|
63
|
1409 |
anObject notNil ifTrue:[
|
|
1410 |
(self isSelected:anObject) ifTrue:[
|
|
1411 |
"remove from selection"
|
|
1412 |
self removeFromSelection:anObject
|
|
1413 |
] ifFalse:[
|
|
1414 |
"add to selection"
|
|
1415 |
self addToSelection:anObject
|
|
1416 |
].
|
|
1417 |
self startObjectMove:selection at:aPoint.
|
|
1418 |
^ self
|
|
1419 |
].
|
|
1420 |
self unselect.
|
|
1421 |
self startRectangleDrag:aPoint
|
|
1422 |
! !
|
|
1423 |
|
0
|
1424 |
!ObjectView methodsFor:'selections'!
|
|
1425 |
|
63
|
1426 |
unselect
|
77
|
1427 |
"unselect - hide selection; clear selection"
|
63
|
1428 |
|
|
1429 |
self hideSelection.
|
|
1430 |
selection := nil
|
|
1431 |
!
|
|
1432 |
|
71
|
1433 |
selectAllIn:aRectangle
|
|
1434 |
"select all objects fully in aRectangle"
|
|
1435 |
|
|
1436 |
self hideSelection.
|
|
1437 |
selection := OrderedCollection new.
|
|
1438 |
self objectsIn:aRectangle do:[:theObject |
|
|
1439 |
selection add:theObject
|
|
1440 |
].
|
|
1441 |
(selection size == 0) ifTrue:[
|
|
1442 |
selection := nil
|
|
1443 |
] ifFalse:[
|
|
1444 |
(selection size == 1) ifTrue:[selection := selection first]
|
|
1445 |
].
|
|
1446 |
self showSelection
|
63
|
1447 |
!
|
|
1448 |
|
|
1449 |
withSelectionHiddenDo:aBlock
|
|
1450 |
"evaluate aBlock while selection is hidden"
|
|
1451 |
|
|
1452 |
|sel|
|
|
1453 |
|
|
1454 |
sel := selection.
|
|
1455 |
self unselect.
|
|
1456 |
aBlock value.
|
|
1457 |
self select:sel
|
|
1458 |
!
|
|
1459 |
|
71
|
1460 |
select:something
|
|
1461 |
"select something - hide previouse selection, set to something and hilight"
|
|
1462 |
|
|
1463 |
(selection == something) ifFalse:[
|
|
1464 |
self hideSelection.
|
|
1465 |
selection := something.
|
|
1466 |
self showSelection
|
|
1467 |
]
|
|
1468 |
!
|
|
1469 |
|
0
|
1470 |
selectionDo:aBlock
|
|
1471 |
"apply block to every object in selection"
|
|
1472 |
|
|
1473 |
self forEach:selection do:aBlock
|
|
1474 |
!
|
|
1475 |
|
71
|
1476 |
hideSelection
|
|
1477 |
"hide the selection - undraw hilights - whatever that is"
|
|
1478 |
|
|
1479 |
self selectionDo:[:object |
|
|
1480 |
self showUnselected:object
|
|
1481 |
]
|
|
1482 |
!
|
|
1483 |
|
0
|
1484 |
showSelection
|
|
1485 |
"show the selection - draw hilights - whatever that is"
|
|
1486 |
|
|
1487 |
self selectionDo:[:object |
|
59
|
1488 |
self showSelected:object
|
0
|
1489 |
]
|
|
1490 |
!
|
|
1491 |
|
|
1492 |
selectAll
|
|
1493 |
"select all objects"
|
|
1494 |
|
|
1495 |
self hideSelection.
|
7
|
1496 |
selection := contents copy.
|
0
|
1497 |
self showSelection
|
|
1498 |
!
|
|
1499 |
|
|
1500 |
addToSelection:anObject
|
|
1501 |
"add anObject to the selection"
|
|
1502 |
|
87
|
1503 |
selection isCollection ifFalse:[
|
59
|
1504 |
selection := OrderedCollection with:selection
|
0
|
1505 |
].
|
|
1506 |
selection add:anObject.
|
|
1507 |
self showSelected:anObject
|
|
1508 |
!
|
|
1509 |
|
|
1510 |
removeFromSelection:anObject
|
|
1511 |
"remove anObject from the selection"
|
|
1512 |
|
87
|
1513 |
selection isCollection ifTrue:[
|
59
|
1514 |
selection remove:anObject ifAbsent:[nil].
|
|
1515 |
(selection size == 1) ifTrue:[
|
|
1516 |
selection := selection first
|
|
1517 |
]
|
0
|
1518 |
] ifFalse:[
|
59
|
1519 |
(selection == anObject) ifTrue:[
|
|
1520 |
selection := nil
|
|
1521 |
]
|
0
|
1522 |
].
|
|
1523 |
self showUnselected:anObject
|
|
1524 |
!
|
|
1525 |
|
63
|
1526 |
selectAllIntersecting:aRectangle
|
|
1527 |
"select all objects touched by aRectangle"
|
0
|
1528 |
|
63
|
1529 |
self hideSelection.
|
|
1530 |
selection := OrderedCollection new.
|
0
|
1531 |
|
63
|
1532 |
self objectsIntersecting:aRectangle do:[:theObject |
|
|
1533 |
selection add:theObject
|
|
1534 |
].
|
|
1535 |
(selection size == 0) ifTrue:[
|
|
1536 |
selection := nil
|
|
1537 |
] ifFalse:[
|
|
1538 |
(selection size == 1) ifTrue:[selection := selection first]
|
|
1539 |
].
|
|
1540 |
self showSelection
|
0
|
1541 |
! !
|
|
1542 |
|
71
|
1543 |
!ObjectView methodsFor:'initialization'!
|
|
1544 |
|
|
1545 |
setInitialDocumentFormat
|
|
1546 |
(Smalltalk language == #english) ifTrue:[
|
|
1547 |
documentFormat := 'letter'.
|
|
1548 |
scaleMetric := #inch
|
|
1549 |
] ifFalse:[
|
|
1550 |
documentFormat := 'a4'.
|
|
1551 |
scaleMetric := #mm
|
63
|
1552 |
].
|
71
|
1553 |
!
|
|
1554 |
|
|
1555 |
initEvents
|
83
|
1556 |
"/ self backingStore:true.
|
63
|
1557 |
!
|
|
1558 |
|
71
|
1559 |
initialize
|
|
1560 |
super initialize.
|
|
1561 |
|
|
1562 |
viewBackground := White.
|
|
1563 |
|
|
1564 |
bitGravity := #NorthWest.
|
|
1565 |
contents := OrderedCollection new.
|
|
1566 |
gridShown := false.
|
|
1567 |
|
|
1568 |
canDragOutOfView := false.
|
|
1569 |
rootView := DisplayRootView new.
|
|
1570 |
rootView noClipByChildren.
|
|
1571 |
rootMotion := false.
|
|
1572 |
self setInitialDocumentFormat.
|
|
1573 |
|
|
1574 |
leftHandCursor := Cursor leftHand.
|
|
1575 |
sorted := false.
|
|
1576 |
aligning := false
|
|
1577 |
! !
|
|
1578 |
|
77
|
1579 |
!ObjectView methodsFor:'cut & paste '!
|
|
1580 |
|
|
1581 |
deleteSelection
|
|
1582 |
"delete the selection into the cut&paste buffer"
|
|
1583 |
|
|
1584 |
|tmp|
|
|
1585 |
|
|
1586 |
tmp := selection.
|
|
1587 |
self unselect.
|
|
1588 |
self remove:tmp.
|
|
1589 |
self setSelection:tmp
|
|
1590 |
!
|
|
1591 |
|
|
1592 |
pasteBuffer
|
|
1593 |
"add the objects in the paste-buffer"
|
|
1594 |
|
|
1595 |
|sel|
|
|
1596 |
|
|
1597 |
sel := self getSelection.
|
|
1598 |
(device getSelectionOwnerOf:(device atomIDOf:'PRIMARY')) == drawableId
|
|
1599 |
ifTrue:[
|
|
1600 |
"
|
|
1601 |
a local selection - paste with some offset
|
|
1602 |
"
|
|
1603 |
sel size > 0 ifTrue:[
|
|
1604 |
sel := sel collect:[:element |
|
|
1605 |
element copy moveTo:(element origin + (8 @ 8))
|
|
1606 |
]
|
|
1607 |
] ifFalse:[
|
|
1608 |
sel := sel copy moveTo:(sel origin + (8 @ 8))
|
|
1609 |
]
|
|
1610 |
].
|
|
1611 |
self paste:sel
|
|
1612 |
!
|
|
1613 |
|
|
1614 |
convertForPaste:anObject
|
|
1615 |
"return a converted version of anObject to be pasted, or nil if
|
|
1616 |
the object is not compatible with me.
|
|
1617 |
Return nil here; concrete subclasses should try to convert.
|
|
1618 |
Notice: anObject may be a collection of to-be-pasted objects."
|
|
1619 |
|
|
1620 |
"in concrete subclasses, you can use:"
|
|
1621 |
"
|
|
1622 |
|s|
|
|
1623 |
|
|
1624 |
(anObject respondsTo:#asDisplayObject) ifTrue:[
|
|
1625 |
^ anObject asDisplayObject
|
|
1626 |
].
|
|
1627 |
(anObject isString or:[anObject isMemberOf:Text]) ifTrue:[
|
|
1628 |
].
|
|
1629 |
anObject size > 0 ifTrue:[
|
|
1630 |
(anObject inject:true into:[:okSoFar :element |
|
|
1631 |
okSoFar and:[element respondsTo:#asDisplayObject]
|
|
1632 |
]) ifFalse:[
|
|
1633 |
self warn:'selection not convertable to DisplayObject'.
|
|
1634 |
^ nil
|
|
1635 |
].
|
|
1636 |
^ anObject collect:[:element | element asDisplayObject].
|
|
1637 |
].
|
|
1638 |
"
|
|
1639 |
^ nil.
|
|
1640 |
!
|
|
1641 |
|
|
1642 |
paste:something
|
|
1643 |
"add the objects in the cut&paste-buffer"
|
|
1644 |
|
|
1645 |
|s|
|
|
1646 |
|
|
1647 |
self unselect.
|
|
1648 |
s := self convertForPaste:something .
|
|
1649 |
s isNil ifTrue:[
|
|
1650 |
self warn:'selection not convertable'.
|
|
1651 |
^ self
|
|
1652 |
].
|
|
1653 |
self addSelected:s
|
|
1654 |
!
|
|
1655 |
|
|
1656 |
copySelection
|
|
1657 |
"copy the selection into the cut&paste-buffer"
|
|
1658 |
|
|
1659 |
|tmp|
|
|
1660 |
|
|
1661 |
tmp := OrderedCollection new.
|
|
1662 |
self selectionDo:[:object |
|
|
1663 |
tmp add:(object copy)
|
|
1664 |
].
|
|
1665 |
"/ self forEach:tmp do:[:anObject |
|
|
1666 |
"/ anObject moveTo:(anObject origin + (8 @ 8))
|
|
1667 |
"/ ].
|
|
1668 |
self setSelection:tmp
|
|
1669 |
! !
|
|
1670 |
|
71
|
1671 |
!ObjectView methodsFor:'adding / removing'!
|
|
1672 |
|
|
1673 |
addWithoutRedraw:something
|
|
1674 |
"add something, anObject or a collection of objects to the contents
|
|
1675 |
do not redraw"
|
63
|
1676 |
|
|
1677 |
self forEach:something do:[:anObject |
|
71
|
1678 |
self addObjectWithoutRedraw:anObject
|
|
1679 |
]
|
0
|
1680 |
!
|
|
1681 |
|
71
|
1682 |
addObjectWithoutRedraw:anObject
|
|
1683 |
"add the argument, anObject to the contents - no redraw"
|
|
1684 |
|
|
1685 |
anObject notNil ifTrue:[
|
|
1686 |
contents addLast:anObject
|
63
|
1687 |
]
|
|
1688 |
!
|
|
1689 |
|
71
|
1690 |
addSelected:something
|
|
1691 |
"add something, anObject or a collection of objects to the contents
|
|
1692 |
and select it"
|
|
1693 |
|
|
1694 |
self add:something.
|
|
1695 |
self select:something
|
|
1696 |
!
|
|
1697 |
|
|
1698 |
remove:something
|
|
1699 |
"remove something, anObject or a collection of objects from the contents
|
|
1700 |
do redraw"
|
|
1701 |
|
77
|
1702 |
something size > (contents size / 4) ifTrue:[
|
|
1703 |
"
|
|
1704 |
better to remove first, then redraw rest
|
|
1705 |
"
|
|
1706 |
self forEach:something do:[:anObject |
|
|
1707 |
self removeFromSelection:anObject.
|
|
1708 |
contents remove:anObject.
|
|
1709 |
].
|
|
1710 |
self redraw.
|
|
1711 |
^ self
|
|
1712 |
].
|
|
1713 |
|
71
|
1714 |
self forEach:something do:[:anObject |
|
|
1715 |
self removeObject:anObject
|
|
1716 |
]
|
|
1717 |
!
|
|
1718 |
|
|
1719 |
removeObject:anObject
|
|
1720 |
"remove the argument, anObject from the contents - no redraw"
|
|
1721 |
|
|
1722 |
anObject notNil ifTrue:[
|
|
1723 |
self removeFromSelection:anObject.
|
|
1724 |
contents remove:anObject.
|
|
1725 |
shown "realized" ifTrue:[
|
|
1726 |
self redrawObjectsIn:(anObject frame)
|
63
|
1727 |
]
|
|
1728 |
]
|
|
1729 |
!
|
|
1730 |
|
71
|
1731 |
addObject:anObject
|
|
1732 |
"add the argument, anObject to the contents - with redraw"
|
|
1733 |
|
|
1734 |
anObject notNil ifTrue:[
|
|
1735 |
contents addLast:anObject.
|
|
1736 |
"its on top - only draw this one"
|
|
1737 |
shown "realized" ifTrue:[
|
|
1738 |
self showUnselected:anObject
|
63
|
1739 |
]
|
|
1740 |
]
|
|
1741 |
!
|
|
1742 |
|
71
|
1743 |
add:something
|
|
1744 |
"add something, anObject or a collection of objects to the contents
|
|
1745 |
with redraw"
|
|
1746 |
|
|
1747 |
self forEach:something do:[:anObject |
|
|
1748 |
self addObject:anObject
|
|
1749 |
]
|
63
|
1750 |
!
|
|
1751 |
|
71
|
1752 |
removeWithoutRedraw:something
|
|
1753 |
"remove something, anObject or a collection of objects from the contents
|
|
1754 |
do not redraw"
|
|
1755 |
|
|
1756 |
self forEach:something do:[:anObject |
|
|
1757 |
self removeObjectWithoutRedraw:anObject
|
63
|
1758 |
]
|
|
1759 |
!
|
|
1760 |
|
71
|
1761 |
removeObjectWithoutRedraw:anObject
|
|
1762 |
"remove the argument, anObject from the contents - no redraw"
|
|
1763 |
|
|
1764 |
anObject notNil ifTrue:[
|
|
1765 |
self removeFromSelection:anObject.
|
|
1766 |
contents remove:anObject
|
|
1767 |
]
|
|
1768 |
!
|
|
1769 |
|
|
1770 |
removeAllWithoutRedraw
|
|
1771 |
"remove all - no redraw"
|
|
1772 |
|
|
1773 |
selection := nil.
|
|
1774 |
contents := OrderedCollection new
|
|
1775 |
!
|
|
1776 |
|
|
1777 |
removeAll
|
|
1778 |
"remove all - redraw"
|
|
1779 |
|
|
1780 |
self removeAllWithoutRedraw.
|
|
1781 |
self redraw
|
0
|
1782 |
! !
|
|
1783 |
|
|
1784 |
!ObjectView methodsFor:'layout manipulation'!
|
|
1785 |
|
|
1786 |
moveObject:anObject to:newOrigin
|
|
1787 |
"move anObject to newOrigin, aPoint"
|
|
1788 |
|
|
1789 |
|oldOrigin oldFrame newFrame
|
|
1790 |
objectsIntersectingOldFrame objectsIntersectingNewFrame
|
|
1791 |
wasObscured isObscured intersects
|
69
|
1792 |
vx vy oldLeft oldTop w h newLeft newTop griddedNewOrigin viewOrigin|
|
0
|
1793 |
|
|
1794 |
anObject isNil ifTrue:[^ self].
|
|
1795 |
anObject canBeMoved ifFalse:[^ self].
|
|
1796 |
|
38
|
1797 |
griddedNewOrigin := self alignToGrid:newOrigin.
|
0
|
1798 |
oldOrigin := anObject origin.
|
38
|
1799 |
(oldOrigin = griddedNewOrigin) ifTrue:[^ self].
|
0
|
1800 |
|
|
1801 |
oldFrame := self frameOf:anObject.
|
|
1802 |
objectsIntersectingOldFrame := self objectsIntersecting:oldFrame.
|
|
1803 |
wasObscured := self isObscured:anObject.
|
|
1804 |
|
38
|
1805 |
anObject moveTo:griddedNewOrigin.
|
0
|
1806 |
|
|
1807 |
newFrame := self frameOf:anObject.
|
|
1808 |
objectsIntersectingNewFrame := self objectsIntersecting:newFrame.
|
|
1809 |
|
|
1810 |
"try to redraw the minimum possible"
|
|
1811 |
|
|
1812 |
"if no other object intersects both frames we can do a copy:"
|
|
1813 |
|
71
|
1814 |
viewOrigin := 0@0 "self viewOrigin".
|
0
|
1815 |
intersects := oldFrame intersects:newFrame.
|
|
1816 |
intersects ifFalse:[
|
59
|
1817 |
gridShown ifFalse:[
|
60
|
1818 |
transformation isNil ifTrue:[
|
|
1819 |
(objectsIntersectingOldFrame size == 1) ifTrue:[
|
|
1820 |
(objectsIntersectingNewFrame size == 1) ifTrue:[
|
|
1821 |
(oldFrame isContainedIn:self clipRect) ifTrue:[
|
|
1822 |
vx := viewOrigin x.
|
|
1823 |
vy := viewOrigin y.
|
|
1824 |
oldLeft := oldFrame left - vx.
|
|
1825 |
oldTop := oldFrame top - vy.
|
|
1826 |
newLeft := newFrame left - vx.
|
|
1827 |
newTop := newFrame top - vy.
|
|
1828 |
w := oldFrame width.
|
|
1829 |
h := oldFrame height.
|
|
1830 |
((newLeft < width) and:[newTop < height]) ifTrue:[
|
|
1831 |
((newLeft >= 0) and:[newTop >= 0]) ifTrue:[
|
71
|
1832 |
self catchExpose.
|
60
|
1833 |
self copyFrom:self x:oldLeft y:oldTop
|
|
1834 |
toX:newLeft y:newTop
|
|
1835 |
width:w height:h.
|
|
1836 |
self waitForExpose
|
|
1837 |
]
|
|
1838 |
].
|
|
1839 |
((oldLeft < width) and:[oldTop < height]) ifTrue:[
|
|
1840 |
((oldLeft >= 0) and:[oldTop >= 0]) ifTrue:[
|
63
|
1841 |
self clearRectangleX:oldLeft y:oldTop width:w height:h.
|
|
1842 |
|
|
1843 |
"/ self fillRectangleX:oldLeft y:oldTop width:w height:h
|
|
1844 |
"/ with:viewBackground
|
60
|
1845 |
]
|
|
1846 |
].
|
|
1847 |
^ self
|
|
1848 |
]
|
59
|
1849 |
]
|
|
1850 |
]
|
|
1851 |
]
|
|
1852 |
]
|
0
|
1853 |
].
|
|
1854 |
isObscured := self isObscured:anObject.
|
|
1855 |
(oldFrame intersects:newFrame) ifTrue:[
|
59
|
1856 |
isObscured ifFalse:[
|
|
1857 |
self redrawObjectsIn:oldFrame.
|
|
1858 |
self show: anObject
|
|
1859 |
] ifTrue:[
|
|
1860 |
self redrawObjectsIn:(oldFrame merge:newFrame)
|
|
1861 |
]
|
0
|
1862 |
] ifFalse:[
|
59
|
1863 |
self redrawObjectsIn:oldFrame.
|
|
1864 |
isObscured ifFalse:[
|
|
1865 |
self show: anObject
|
|
1866 |
] ifTrue:[
|
|
1867 |
self redrawObjectsIn:newFrame
|
|
1868 |
]
|
0
|
1869 |
]
|
|
1870 |
!
|
|
1871 |
|
71
|
1872 |
move:something by:delta
|
|
1873 |
"change the position of something, an Object or Collection
|
|
1874 |
by delta, aPoint"
|
|
1875 |
|
|
1876 |
(delta x == 0) ifTrue:[
|
|
1877 |
(delta y == 0) ifTrue:[^ self]
|
|
1878 |
].
|
|
1879 |
|
|
1880 |
self forEach:something do:[:anObject |
|
|
1881 |
self moveObject:anObject by:delta
|
|
1882 |
]
|
|
1883 |
!
|
|
1884 |
|
|
1885 |
moveObject:anObject by:delta
|
|
1886 |
"change the position of anObject by delta, aPoint"
|
|
1887 |
|
|
1888 |
self moveObject:anObject to:(anObject origin + delta)
|
|
1889 |
!
|
|
1890 |
|
63
|
1891 |
move:something to:aPoint in:aView
|
|
1892 |
"can only happen when dragOutOfView is true
|
|
1893 |
- should be redefined in subclasses"
|
|
1894 |
|
|
1895 |
self notify:'cannot move object(s) out of view'
|
|
1896 |
!
|
|
1897 |
|
|
1898 |
move:something to:aPoint inAlienViewId:aViewId
|
|
1899 |
"can only happen when dragOutOfView is true
|
|
1900 |
- should be redefined in subclasses"
|
|
1901 |
|
|
1902 |
self notify:'cannot move object(s) to alien views'
|
|
1903 |
!
|
|
1904 |
|
0
|
1905 |
objectToFront:anObject
|
|
1906 |
"bring the argument, anObject to front"
|
|
1907 |
|
|
1908 |
|wasObscured|
|
|
1909 |
|
|
1910 |
anObject notNil ifTrue:[
|
59
|
1911 |
wasObscured := self isObscured:anObject.
|
|
1912 |
contents remove:anObject.
|
|
1913 |
contents addLast:anObject.
|
|
1914 |
wasObscured ifTrue:[
|
7
|
1915 |
"old:
|
59
|
1916 |
self redrawObjectsIn:(anObject frame)
|
7
|
1917 |
"
|
59
|
1918 |
self hideSelection.
|
|
1919 |
self show:anObject.
|
|
1920 |
self showSelection
|
|
1921 |
]
|
0
|
1922 |
]
|
|
1923 |
!
|
|
1924 |
|
|
1925 |
toFront:something
|
|
1926 |
"bring the argument, anObject or a collection of objects to front"
|
|
1927 |
|
|
1928 |
self forEach:something do:[:anObject |
|
59
|
1929 |
self objectToFront:anObject
|
0
|
1930 |
]
|
|
1931 |
!
|
|
1932 |
|
|
1933 |
selectionToFront
|
|
1934 |
"bring the selection to front"
|
|
1935 |
|
|
1936 |
self toFront:selection
|
|
1937 |
!
|
|
1938 |
|
|
1939 |
objectToBack:anObject
|
|
1940 |
"bring the argument, anObject to back"
|
|
1941 |
|
|
1942 |
anObject notNil ifTrue:[
|
59
|
1943 |
contents remove:anObject.
|
|
1944 |
contents addFirst:anObject.
|
|
1945 |
(self isObscured:anObject) ifTrue:[
|
|
1946 |
self redrawObjectsIn:(anObject frame)
|
|
1947 |
]
|
0
|
1948 |
]
|
|
1949 |
!
|
|
1950 |
|
|
1951 |
toBack:something
|
|
1952 |
"bring the argument, anObject or a collection of objects to back"
|
|
1953 |
|
|
1954 |
self forEach:something do:[:anObject |
|
59
|
1955 |
self objectToBack:anObject
|
0
|
1956 |
]
|
|
1957 |
!
|
|
1958 |
|
|
1959 |
selectionToBack
|
|
1960 |
"bring the selection to back"
|
|
1961 |
|
|
1962 |
self toBack:selection
|
|
1963 |
!
|
|
1964 |
|
|
1965 |
alignLeft:something
|
|
1966 |
|leftMost|
|
|
1967 |
|
|
1968 |
leftMost := 999999.
|
|
1969 |
self forEach:something do:[:anObject |
|
59
|
1970 |
leftMost := leftMost min:(anObject frame left)
|
0
|
1971 |
].
|
|
1972 |
self withSelectionHiddenDo:[
|
59
|
1973 |
self forEach:something do:[:anObject |
|
|
1974 |
self moveObject:anObject to:(leftMost @ (anObject frame top))
|
|
1975 |
]
|
0
|
1976 |
]
|
|
1977 |
!
|
|
1978 |
|
|
1979 |
alignRight:something
|
|
1980 |
|rightMost|
|
|
1981 |
|
|
1982 |
rightMost := -999999.
|
|
1983 |
self forEach:something do:[:anObject |
|
59
|
1984 |
rightMost := rightMost max:(anObject frame right)
|
0
|
1985 |
].
|
|
1986 |
self withSelectionHiddenDo:[
|
59
|
1987 |
self forEach:something do:[:anObject |
|
|
1988 |
self moveObject:anObject to:(rightMost - (anObject frame width))
|
|
1989 |
@ (anObject frame top)
|
|
1990 |
]
|
0
|
1991 |
]
|
|
1992 |
!
|
|
1993 |
|
|
1994 |
alignTop:something
|
|
1995 |
|topMost|
|
|
1996 |
|
|
1997 |
topMost := 999999.
|
|
1998 |
self forEach:something do:[:anObject |
|
59
|
1999 |
topMost := topMost min:(anObject frame top)
|
0
|
2000 |
].
|
|
2001 |
self withSelectionHiddenDo:[
|
59
|
2002 |
self forEach:something do:[:anObject |
|
|
2003 |
self moveObject:anObject to:((anObject frame left) @ topMost)
|
|
2004 |
]
|
0
|
2005 |
]
|
|
2006 |
!
|
|
2007 |
|
|
2008 |
alignBottom:something
|
|
2009 |
|botMost|
|
|
2010 |
|
|
2011 |
botMost := -999999.
|
|
2012 |
self forEach:something do:[:anObject |
|
59
|
2013 |
botMost := botMost max:(anObject frame bottom)
|
0
|
2014 |
].
|
|
2015 |
self withSelectionHiddenDo:[
|
59
|
2016 |
self forEach:something do:[:anObject |
|
|
2017 |
self moveObject:anObject to:(anObject frame left)
|
|
2018 |
@
|
|
2019 |
(botMost - (anObject frame height))
|
|
2020 |
]
|
0
|
2021 |
]
|
|
2022 |
!
|
|
2023 |
|
|
2024 |
selectionAlignLeft
|
|
2025 |
"align selected objects left"
|
|
2026 |
|
|
2027 |
self alignLeft:selection
|
|
2028 |
!
|
|
2029 |
|
|
2030 |
selectionAlignRight
|
|
2031 |
"align selected objects right"
|
|
2032 |
|
|
2033 |
self alignRight:selection
|
|
2034 |
!
|
|
2035 |
|
|
2036 |
selectionAlignTop
|
|
2037 |
"align selected objects at top"
|
|
2038 |
|
|
2039 |
self alignTop:selection
|
|
2040 |
!
|
|
2041 |
|
|
2042 |
selectionAlignBottom
|
|
2043 |
"align selected objects at bottom"
|
|
2044 |
|
|
2045 |
self alignBottom:selection
|
|
2046 |
! !
|
|
2047 |
|
71
|
2048 |
!ObjectView methodsFor:'dragging rectangle'!
|
|
2049 |
|
77
|
2050 |
setRectangleDragActions
|
|
2051 |
"setup to drag a rectangle. Call this (for example) from your buttonPress
|
|
2052 |
method, to make the view start the drag.
|
|
2053 |
See startRectangleDrag:."
|
|
2054 |
|
|
2055 |
motionAction := [:movePoint | self doRectangleDrag:movePoint].
|
|
2056 |
releaseAction := [self endRectangleDrag]
|
|
2057 |
!
|
|
2058 |
|
71
|
2059 |
endRectangleDrag
|
|
2060 |
"cleanup after rectangle drag; select them"
|
|
2061 |
|
|
2062 |
self invertDragRectangle.
|
|
2063 |
self cursor:oldCursor.
|
|
2064 |
self selectAllIn:(dragObject "+ self viewOrigin")
|
0
|
2065 |
!
|
|
2066 |
|
71
|
2067 |
invertDragRectangle
|
|
2068 |
"helper for rectangle drag - invert the dragRectangle.
|
|
2069 |
Extracted into a separate method to allow easier redefinition
|
|
2070 |
(different lineWidth etc)"
|
|
2071 |
|
|
2072 |
self xoring:[self lineWidth:0. self displayRectangle:dragObject].
|
63
|
2073 |
!
|
|
2074 |
|
71
|
2075 |
startRectangleDrag:startPoint
|
|
2076 |
"start a rectangle drag"
|
|
2077 |
|
|
2078 |
self setRectangleDragActions.
|
|
2079 |
dragObject := Rectangle origin:startPoint corner:startPoint.
|
|
2080 |
self invertDragRectangle.
|
|
2081 |
oldCursor := cursor.
|
|
2082 |
self cursor:leftHandCursor
|
0
|
2083 |
!
|
|
2084 |
|
71
|
2085 |
doRectangleDrag:aPoint
|
|
2086 |
"do drag a rectangle"
|
|
2087 |
|
|
2088 |
self invertDragRectangle.
|
|
2089 |
dragObject corner:aPoint.
|
|
2090 |
self invertDragRectangle.
|
0
|
2091 |
! !
|
|
2092 |
|
|
2093 |
!ObjectView methodsFor:'view manipulation'!
|
|
2094 |
|
71
|
2095 |
zoom:factor
|
|
2096 |
"set a zoom factor; nil or 1 is identity; 2 is magnify by 2;
|
|
2097 |
0.5 is shrink by 2"
|
|
2098 |
|
|
2099 |
|current|
|
|
2100 |
|
|
2101 |
transformation isNil ifTrue:[
|
|
2102 |
current := 1@1
|
|
2103 |
] ifFalse:[
|
|
2104 |
current := transformation scale
|
|
2105 |
].
|
|
2106 |
factor asPoint = current asPoint ifTrue:[
|
|
2107 |
^ self
|
|
2108 |
].
|
|
2109 |
current := factor.
|
|
2110 |
current isNil ifTrue:[
|
|
2111 |
current := 1
|
|
2112 |
].
|
|
2113 |
|
|
2114 |
(current = 1) ifTrue:[
|
|
2115 |
transformation := nil
|
|
2116 |
] ifFalse:[
|
|
2117 |
transformation := WindowingTransformation scale:current translation:0.
|
|
2118 |
].
|
|
2119 |
self contentsChanged.
|
|
2120 |
self setInnerClip.
|
|
2121 |
gridShown ifTrue:[
|
|
2122 |
self newGrid
|
|
2123 |
].
|
|
2124 |
shown ifTrue:[
|
|
2125 |
self clear.
|
|
2126 |
self redraw
|
|
2127 |
].
|
|
2128 |
!
|
|
2129 |
|
69
|
2130 |
zoomIn
|
|
2131 |
transformation isNil ifTrue:[
|
|
2132 |
transformation := WindowingTransformation scale:1 translation:0
|
|
2133 |
].
|
|
2134 |
transformation := WindowingTransformation scale:(transformation scale / 2)
|
|
2135 |
translation:0.
|
71
|
2136 |
self contentsChanged.
|
|
2137 |
self setInnerClip.
|
|
2138 |
self redraw.
|
69
|
2139 |
!
|
|
2140 |
|
|
2141 |
zoomOut
|
|
2142 |
transformation isNil ifTrue:[
|
|
2143 |
transformation := WindowingTransformation scale:1 translation:0
|
|
2144 |
].
|
|
2145 |
transformation := WindowingTransformation scale:(transformation scale * 2)
|
|
2146 |
translation:0.
|
71
|
2147 |
self contentsChanged.
|
|
2148 |
self setInnerClip.
|
69
|
2149 |
self redraw
|
|
2150 |
!
|
|
2151 |
|
0
|
2152 |
millimeterMetric
|
63
|
2153 |
(scaleMetric ~~ #mm) ifTrue:[
|
59
|
2154 |
scaleMetric := #mm.
|
63
|
2155 |
self newGrid
|
0
|
2156 |
]
|
|
2157 |
!
|
|
2158 |
|
|
2159 |
inchMetric
|
63
|
2160 |
(scaleMetric ~~ #inch) ifTrue:[
|
59
|
2161 |
scaleMetric := #inch.
|
63
|
2162 |
self newGrid
|
0
|
2163 |
]
|
63
|
2164 |
! !
|
|
2165 |
|
|
2166 |
!ObjectView methodsFor:'grid manipulation'!
|
|
2167 |
|
71
|
2168 |
newGrid
|
77
|
2169 |
"define a new grid - this is a private helper which has to be
|
|
2170 |
called after any change in the grid. It (re)creates the gridPixmap,
|
|
2171 |
clears the view and redraws all visible objects."
|
71
|
2172 |
|
|
2173 |
gridPixmap := nil.
|
|
2174 |
shown ifTrue:[
|
|
2175 |
self viewBackground:White.
|
|
2176 |
self clear.
|
|
2177 |
].
|
|
2178 |
|
|
2179 |
gridShown ifTrue:[
|
|
2180 |
self defineGrid.
|
|
2181 |
self viewBackground:gridPixmap.
|
|
2182 |
].
|
|
2183 |
shown ifTrue:[
|
|
2184 |
self redraw
|
|
2185 |
].
|
|
2186 |
!
|
|
2187 |
|
63
|
2188 |
gridParameters
|
|
2189 |
"used by defineGrid, and in a separate method for
|
|
2190 |
easier redefinition in subclasses.
|
77
|
2191 |
Returns the grid parameters in an array of 7 elements,
|
63
|
2192 |
which control the appearance of the grid-pattern.
|
77
|
2193 |
the elements are:
|
0
|
2194 |
|
63
|
2195 |
bigStepH number of pixels horizontally between 2 major steps
|
|
2196 |
bigStepV number of pixels vertically between 2 major steps
|
|
2197 |
littleStepH number of pixels horizontally between 2 minor steps
|
|
2198 |
littleStepV number of pixels vertically between 2 minor steps
|
77
|
2199 |
gridAlignH number of pixels for horizontal grid align (pointer snap)
|
|
2200 |
gridAlignV number of pixels for vertical grid align (pointer snap)
|
|
2201 |
docBounds true, if document boundary should be shown
|
|
2202 |
|
|
2203 |
if littleStepH/V are nil, only bigSteps are drawn.
|
63
|
2204 |
"
|
0
|
2205 |
|
63
|
2206 |
|mmH mmV bigStepH bigStepV littleStepH littleStepV arr|
|
|
2207 |
|
|
2208 |
"example: 12grid & 12snapIn"
|
|
2209 |
"/ ^ #(12 12 nil nil 12 12 false).
|
|
2210 |
|
|
2211 |
"example: 12grid & 24snapIn"
|
|
2212 |
"/ ^ #(12 12 nil nil 24 24 false).
|
|
2213 |
|
|
2214 |
"default: cm/mm grid & mm snapIn for metric,
|
|
2215 |
1inch , 1/8inch grid & 1/8 inch snapIn"
|
0
|
2216 |
|
|
2217 |
mmH := self horizontalPixelPerMillimeter.
|
|
2218 |
mmV := self verticalPixelPerMillimeter.
|
60
|
2219 |
|
77
|
2220 |
"
|
|
2221 |
metric grid: small steps every millimeter, big step every
|
|
2222 |
centimeter. If the transformation is shrinking, turn off little
|
|
2223 |
steps.
|
|
2224 |
"
|
0
|
2225 |
(scaleMetric == #mm) ifTrue:[
|
59
|
2226 |
"dots every mm; lines every cm"
|
|
2227 |
bigStepH := mmH * 10.0.
|
|
2228 |
bigStepV := mmV * 10.0.
|
69
|
2229 |
(transformation notNil
|
|
2230 |
and:[transformation scale <= 0.5]) ifFalse:[
|
|
2231 |
littleStepH := mmH.
|
|
2232 |
littleStepV := mmV
|
|
2233 |
]
|
0
|
2234 |
].
|
77
|
2235 |
"
|
|
2236 |
inch grid: small steps every 1/8th inch, big step every half inch
|
|
2237 |
If the transformation is shrinking, change little steps to 1/th inch
|
|
2238 |
or even turn them off completely.
|
|
2239 |
"
|
0
|
2240 |
(scaleMetric == #inch) ifTrue:[
|
59
|
2241 |
"dots every eights inch; lines every half inch"
|
|
2242 |
bigStepH := mmH * (25.4 / 2).
|
|
2243 |
bigStepV := mmV * (25.4 / 2).
|
69
|
2244 |
(transformation notNil
|
|
2245 |
and:[transformation scale <= 0.5]) ifTrue:[
|
77
|
2246 |
transformation scale > 0.2 ifTrue:[
|
|
2247 |
littleStepH := mmH * (25.4 / 4).
|
|
2248 |
littleStepV := mmV * (25.4 / 4)
|
|
2249 |
]
|
69
|
2250 |
] ifFalse:[
|
|
2251 |
littleStepH := mmH * (25.4 / 8).
|
|
2252 |
littleStepV := mmV * (25.4 / 8)
|
|
2253 |
]
|
0
|
2254 |
].
|
63
|
2255 |
|
|
2256 |
arr := Array new:8.
|
|
2257 |
arr at:1 put:bigStepH.
|
|
2258 |
arr at:2 put:bigStepV.
|
|
2259 |
arr at:3 put:littleStepH.
|
|
2260 |
arr at:4 put:littleStepV.
|
|
2261 |
arr at:5 put:littleStepH.
|
|
2262 |
arr at:6 put:littleStepV.
|
|
2263 |
arr at:7 put:false.
|
0
|
2264 |
|
63
|
2265 |
^ arr
|
|
2266 |
!
|
|
2267 |
|
|
2268 |
defineGrid
|
77
|
2269 |
"define the grid pattern - this creates the gridPixmap, which is
|
|
2270 |
used as viewBackground when a grid is to be shown.
|
|
2271 |
The grid is specified by the value returned from gridParameters,
|
|
2272 |
which can be redefined in subclasses. See the comment there on how
|
|
2273 |
the numbers are interpreted."
|
63
|
2274 |
|
|
2275 |
|mmH mmV params showDocumentBoundary gridW gridH
|
|
2276 |
bigStepH bigStepV littleStepH littleStepV hires|
|
|
2277 |
|
|
2278 |
mmH := self horizontalPixelPerMillimeter.
|
|
2279 |
mmV := self verticalPixelPerMillimeter.
|
|
2280 |
hires := self horizontalPixelPerInch > 120.
|
0
|
2281 |
|
63
|
2282 |
gridW := (self widthOfContentsInMM * mmH).
|
|
2283 |
gridH := (self heightOfContentsInMM * mmV).
|
|
2284 |
|
|
2285 |
params := self gridParameters.
|
|
2286 |
|
|
2287 |
bigStepH := params at:1.
|
|
2288 |
bigStepV := params at:2.
|
|
2289 |
littleStepH := params at:3.
|
|
2290 |
littleStepV := params at:4.
|
|
2291 |
showDocumentBoundary := params at:7.
|
0
|
2292 |
|
63
|
2293 |
transformation notNil ifTrue:[
|
|
2294 |
mmH := mmH * transformation scale x.
|
|
2295 |
mmV := mmV * transformation scale y.
|
|
2296 |
bigStepH := bigStepH * transformation scale x.
|
|
2297 |
bigStepV := bigStepV * transformation scale y.
|
|
2298 |
littleStepH notNil ifTrue:[
|
|
2299 |
littleStepH := littleStepH * transformation scale x.
|
59
|
2300 |
].
|
63
|
2301 |
littleStepV notNil ifTrue:[
|
|
2302 |
littleStepV := littleStepV * transformation scale y.
|
|
2303 |
].
|
0
|
2304 |
].
|
|
2305 |
|
63
|
2306 |
bigStepH isNil ifTrue:[^ self].
|
|
2307 |
|
|
2308 |
self withCursor:(Cursor wait) do:[
|
|
2309 |
|xp yp y x|
|
|
2310 |
|
|
2311 |
"
|
|
2312 |
up to next full unit
|
|
2313 |
"
|
|
2314 |
gridW := ((gridW // bigStepH) + 1 * bigStepH) asInteger.
|
|
2315 |
gridH := ((gridH // bigStepV) + 1 * bigStepV) asInteger.
|
|
2316 |
|
|
2317 |
gridPixmap := Form width:gridW height:gridH depth:1.
|
|
2318 |
gridPixmap colorMap:(Array with:White with:Black).
|
|
2319 |
gridPixmap clear.
|
|
2320 |
gridPixmap paint:(Color colorId:1).
|
|
2321 |
|
|
2322 |
"draw first row point-by-point"
|
|
2323 |
yp := 0.0.
|
|
2324 |
xp := 0.0.
|
|
2325 |
y := yp asInteger.
|
|
2326 |
[xp <= gridW] whileTrue:[
|
|
2327 |
x := xp rounded.
|
|
2328 |
hires ifTrue:[
|
|
2329 |
gridPixmap displayPointX:(x + 1) y:y.
|
|
2330 |
gridPixmap displayPointX:(x + 2) y:y
|
|
2331 |
].
|
|
2332 |
gridPixmap displayPointX:x y:y.
|
|
2333 |
littleStepH notNil ifTrue:[
|
|
2334 |
xp := xp + littleStepH
|
|
2335 |
] ifFalse:[
|
|
2336 |
xp := xp + bigStepH
|
|
2337 |
]
|
|
2338 |
].
|
|
2339 |
|
|
2340 |
"copy rest from what has been drawn already"
|
|
2341 |
yp := yp + bigStepV.
|
|
2342 |
[yp <= gridH] whileTrue:[
|
|
2343 |
y := yp rounded.
|
|
2344 |
hires ifTrue:[
|
|
2345 |
gridPixmap copyFrom:gridPixmap x:0 y:0
|
|
2346 |
toX:0 y:(y + 1)
|
|
2347 |
width:gridW height:1.
|
|
2348 |
gridPixmap copyFrom:gridPixmap x:0 y:0
|
|
2349 |
toX:0 y:(y + 2)
|
|
2350 |
width:gridW height:1
|
|
2351 |
].
|
59
|
2352 |
gridPixmap copyFrom:gridPixmap x:0 y:0
|
63
|
2353 |
toX:0 y:y
|
59
|
2354 |
width:gridW height:1.
|
63
|
2355 |
yp := yp + bigStepV
|
|
2356 |
].
|
|
2357 |
|
|
2358 |
"draw first col point-by-point"
|
|
2359 |
xp := 0.0.
|
|
2360 |
yp := 0.0.
|
|
2361 |
x := xp asInteger.
|
|
2362 |
[yp <= gridH] whileTrue:[
|
|
2363 |
y := yp rounded.
|
|
2364 |
hires ifTrue:[
|
|
2365 |
gridPixmap displayPointX:x y:(y + 1).
|
|
2366 |
gridPixmap displayPointX:x y:(y + 2)
|
|
2367 |
].
|
|
2368 |
gridPixmap displayPointX:x y:y.
|
|
2369 |
littleStepV notNil ifTrue:[
|
|
2370 |
yp := yp + littleStepV
|
|
2371 |
] ifFalse:[
|
|
2372 |
yp := yp + bigStepV
|
|
2373 |
]
|
59
|
2374 |
].
|
63
|
2375 |
|
|
2376 |
"copy rest from what has been drawn already"
|
|
2377 |
xp := xp + bigStepH.
|
|
2378 |
[xp <= gridW] whileTrue:[
|
|
2379 |
x := xp rounded.
|
|
2380 |
hires ifTrue:[
|
|
2381 |
gridPixmap copyFrom:gridPixmap x:0 y:0
|
|
2382 |
toX:(x + 1) y:0
|
|
2383 |
width:1 height:gridH.
|
|
2384 |
gridPixmap copyFrom:gridPixmap x:0 y:0
|
|
2385 |
toX:(x + 2) y:0
|
|
2386 |
width:1 height:gridH
|
|
2387 |
].
|
|
2388 |
gridPixmap copyFrom:gridPixmap x:0 y:0
|
|
2389 |
toX:x y:0
|
|
2390 |
width:1 height:gridH.
|
|
2391 |
xp := xp + bigStepH
|
|
2392 |
].
|
|
2393 |
|
|
2394 |
showDocumentBoundary ifTrue:[
|
|
2395 |
"
|
|
2396 |
mark the right-end and bottom of the document
|
|
2397 |
"
|
|
2398 |
gridPixmap displayLineFromX:gridW-1 y:0 toX:gridW-1 y:gridH-1.
|
|
2399 |
gridPixmap displayLineFromX:0 y:gridH-1 toX:gridW-1 y:gridH-1.
|
|
2400 |
].
|
|
2401 |
]
|
|
2402 |
!
|
|
2403 |
|
0
|
2404 |
showGrid
|
77
|
2405 |
"show the grid. The grid is defined by the return value of
|
|
2406 |
gridParameters, which can be redefined in concrete subclasses."
|
0
|
2407 |
|
|
2408 |
gridShown := true.
|
63
|
2409 |
self newGrid
|
0
|
2410 |
!
|
|
2411 |
|
|
2412 |
hideGrid
|
|
2413 |
"hide the grid"
|
|
2414 |
|
|
2415 |
gridShown := false.
|
63
|
2416 |
self newGrid
|
|
2417 |
!
|
|
2418 |
|
|
2419 |
getAlignParameters
|
|
2420 |
|params|
|
|
2421 |
|
|
2422 |
params := self gridParameters.
|
|
2423 |
gridAlign := (params at:5) @ (params at:6)
|
0
|
2424 |
!
|
|
2425 |
|
|
2426 |
alignOn
|
|
2427 |
"align points to grid"
|
|
2428 |
|
63
|
2429 |
aligning := true.
|
|
2430 |
self getAlignParameters
|
0
|
2431 |
!
|
|
2432 |
|
|
2433 |
alignOff
|
|
2434 |
"do no align point to grid"
|
|
2435 |
|
|
2436 |
aligning := false
|
|
2437 |
! !
|
|
2438 |
|
63
|
2439 |
!ObjectView methodsFor:'dragging line'!
|
59
|
2440 |
|
77
|
2441 |
setLineDragActions
|
|
2442 |
"setup to drag a line. Call this (for example) from your buttonPress
|
|
2443 |
method, to make the view start to drag a line.
|
|
2444 |
See startLineDrag and startRootLineDrag."
|
|
2445 |
|
|
2446 |
motionAction := [:movePoint | self doLineDrag:movePoint].
|
|
2447 |
releaseAction := [self endLineDrag]
|
|
2448 |
!
|
|
2449 |
|
59
|
2450 |
startLineDrag:startPoint
|
77
|
2451 |
"start a line drag within the view"
|
59
|
2452 |
|
|
2453 |
self setLineDragActions.
|
|
2454 |
dragObject := Rectangle origin:startPoint corner:startPoint.
|
63
|
2455 |
self invertDragLine.
|
59
|
2456 |
oldCursor := cursor.
|
|
2457 |
self cursor:leftHandCursor
|
|
2458 |
!
|
|
2459 |
|
|
2460 |
startRootLineDrag:startPoint
|
|
2461 |
"start a line drag possibly crossing my view boundaries"
|
|
2462 |
|
|
2463 |
self setLineDragActions.
|
|
2464 |
rootMotion := true.
|
|
2465 |
dragObject := Rectangle origin:startPoint corner:startPoint.
|
63
|
2466 |
self invertDragLine.
|
59
|
2467 |
oldCursor := cursor.
|
|
2468 |
self cursor:leftHandCursor
|
|
2469 |
!
|
|
2470 |
|
|
2471 |
doLineDrag:aPoint
|
|
2472 |
"do drag a line"
|
|
2473 |
|
63
|
2474 |
self invertDragLine.
|
|
2475 |
dragObject corner:aPoint.
|
|
2476 |
self invertDragLine.
|
59
|
2477 |
!
|
|
2478 |
|
|
2479 |
endLineDrag
|
60
|
2480 |
"cleanup after line drag; select them. Find the origin and destination
|
|
2481 |
views and relative offsets, then dispatch to one of the endLineDrag methods.
|
|
2482 |
These can be redefined in subclasses to allow connect between views."
|
59
|
2483 |
|
77
|
2484 |
|rootPoint viewId offs
|
60
|
2485 |
lastViewId destinationId destinationView destinationPoint inMySelf|
|
59
|
2486 |
|
77
|
2487 |
self invertDragLine.
|
|
2488 |
|
59
|
2489 |
self cursor:oldCursor.
|
60
|
2490 |
|
|
2491 |
"check if line drag is into another view"
|
|
2492 |
rootMotion ifTrue:[
|
77
|
2493 |
rootPoint := lastButt.
|
|
2494 |
"
|
|
2495 |
get device coordinates
|
|
2496 |
"
|
83
|
2497 |
"/ 'logical ' print. rootPoint printNL.
|
77
|
2498 |
transformation notNil ifTrue:[
|
|
2499 |
rootPoint := transformation applyTo:rootPoint.
|
83
|
2500 |
"/ 'device ' print. rootPoint printNL.
|
77
|
2501 |
].
|
|
2502 |
"
|
|
2503 |
translate to screen
|
|
2504 |
"
|
|
2505 |
offs := device translatePoint:0@0 from:(self id) to:(rootView id).
|
83
|
2506 |
"/ 'offs' print. offs printNL.
|
77
|
2507 |
rootPoint := rootPoint + offs.
|
83
|
2508 |
"/ 'screen ' print. rootPoint printNL.
|
77
|
2509 |
|
|
2510 |
"/ rootPoint := device translatePoint:lastButt
|
|
2511 |
"/ from:(self id)
|
|
2512 |
"/ to:(rootView id).
|
60
|
2513 |
"search view the drop is in"
|
|
2514 |
|
|
2515 |
viewId := rootView id.
|
|
2516 |
[viewId notNil] whileTrue:[
|
|
2517 |
destinationId := device viewIdFromPoint:rootPoint in:viewId.
|
|
2518 |
lastViewId := viewId.
|
|
2519 |
viewId := destinationId
|
|
2520 |
].
|
|
2521 |
destinationView := device viewFromId:lastViewId.
|
|
2522 |
destinationId := lastViewId.
|
|
2523 |
inMySelf := (destinationView == self).
|
|
2524 |
rootMotion := false
|
|
2525 |
] ifFalse:[
|
|
2526 |
inMySelf := true
|
|
2527 |
].
|
87
|
2528 |
|
60
|
2529 |
inMySelf ifTrue:[
|
|
2530 |
"a simple line within myself"
|
87
|
2531 |
self lineDragFrom:dragObject origin to:dragObject corner
|
60
|
2532 |
] ifFalse:[
|
|
2533 |
"into another one"
|
|
2534 |
destinationView notNil ifTrue:[
|
77
|
2535 |
destinationPoint := device translatePoint:rootPoint
|
|
2536 |
from:(rootView id)
|
|
2537 |
to:(destinationView id).
|
83
|
2538 |
destinationView transformation notNil ifTrue:[
|
|
2539 |
destinationPoint := destinationView transformation applyInverseTo:destinationPoint
|
|
2540 |
].
|
60
|
2541 |
"
|
|
2542 |
move into another smalltalk view
|
|
2543 |
"
|
|
2544 |
self lineDragFrom:dragObject origin to:destinationPoint in:destinationView
|
|
2545 |
] ifFalse:[
|
|
2546 |
"
|
|
2547 |
not one of my views
|
|
2548 |
"
|
|
2549 |
self lineDragFrom:dragObject origin
|
|
2550 |
to:destinationPoint
|
|
2551 |
inAlienViewId:destinationId
|
|
2552 |
]
|
|
2553 |
].
|
|
2554 |
self setDefaultActions.
|
|
2555 |
dragObject := nil
|
|
2556 |
!
|
|
2557 |
|
|
2558 |
lineDragFrom:startPoint to:endPoint inAlienViewId:destinationId
|
|
2559 |
"this is called after a line-drag with rootmotion set
|
|
2560 |
to true, IFF the endpoint is in an alien view
|
|
2561 |
- should be redefined in subclasses"
|
|
2562 |
|
|
2563 |
self notify:'cannot connect object in alien view'
|
|
2564 |
!
|
|
2565 |
|
|
2566 |
lineDragFrom:startPoint to:endPoint
|
|
2567 |
"this is called after a line-drag. Nothing is done here.
|
|
2568 |
- should be redefined in subclasses"
|
|
2569 |
|
|
2570 |
^ self
|
|
2571 |
!
|
|
2572 |
|
|
2573 |
lineDragFrom:startPoint to:endPoint in:destinationView
|
|
2574 |
"this is called after a line-drag crossing view boundaries.
|
|
2575 |
- should be redefined in subclasses"
|
|
2576 |
|
|
2577 |
^ self notify:'dont know how to connect to external views'
|
0
|
2578 |
!
|
|
2579 |
|
63
|
2580 |
invertDragLine
|
|
2581 |
"helper for line dragging - invert the dragged line.
|
|
2582 |
Extracted for easier redefinition in subclasses
|
|
2583 |
(different line width etc.)"
|
0
|
2584 |
|
77
|
2585 |
|dragger offs p1 p2|
|
|
2586 |
|
|
2587 |
p1 := dragObject origin.
|
|
2588 |
p2 := dragObject corner.
|
|
2589 |
rootMotion ifTrue:[
|
|
2590 |
dragger := rootView.
|
|
2591 |
"
|
|
2592 |
get device coordinates
|
|
2593 |
"
|
|
2594 |
"/ 'logical ' print. p1 print. ' ' print. p2 printNL.
|
|
2595 |
transformation notNil ifTrue:[
|
|
2596 |
p1 := transformation applyTo:p1.
|
|
2597 |
p2 := transformation applyTo:p2.
|
|
2598 |
"/ 'device ' print. p1 print. ' ' print. p2 printNL.
|
|
2599 |
].
|
|
2600 |
"
|
|
2601 |
translate to screen
|
|
2602 |
"
|
|
2603 |
offs := device translatePoint:0@0 from:(self id) to:(rootView id).
|
|
2604 |
"/ 'offs' print. offs printNL.
|
|
2605 |
p1 := p1 + offs.
|
|
2606 |
p2 := p2 + offs.
|
|
2607 |
"/ 'screen ' print. p1 print. ' ' print. p2 printNL.
|
|
2608 |
] ifFalse:[
|
|
2609 |
dragger := self.
|
|
2610 |
].
|
|
2611 |
|
|
2612 |
dragger xoring:[
|
|
2613 |
dragger lineWidth:0.
|
|
2614 |
dragger displayLineFrom:p1 to:p2.
|
|
2615 |
dragger device synchronizeOutput
|
|
2616 |
].
|
0
|
2617 |
! !
|
|
2618 |
|
|
2619 |
!ObjectView methodsFor:'saving / restoring'!
|
|
2620 |
|
63
|
2621 |
initializeFileInObject:anObject
|
|
2622 |
"each object may be processed here after its being filed-in
|
|
2623 |
- subclasses may do whatever they want here ...
|
|
2624 |
(see LogicView for example)"
|
|
2625 |
|
|
2626 |
^ self
|
|
2627 |
!
|
|
2628 |
|
0
|
2629 |
storeContentsOn:aStream
|
59
|
2630 |
"store the contents in textual representation on aStream.
|
|
2631 |
Notice, that for huge objects (such as DrawImages) this ascii output
|
|
2632 |
can become quite large, and the time to save and reload can become
|
|
2633 |
long."
|
|
2634 |
|
0
|
2635 |
|excla|
|
|
2636 |
|
59
|
2637 |
self topView withCursor:Cursor write do:[
|
|
2638 |
excla := aStream class chunkSeparator.
|
|
2639 |
self forEach:contents do:[:theObject |
|
|
2640 |
theObject storeOn:aStream.
|
|
2641 |
aStream nextPut:excla.
|
|
2642 |
aStream cr
|
|
2643 |
].
|
|
2644 |
aStream nextPut:excla
|
|
2645 |
]
|
0
|
2646 |
!
|
|
2647 |
|
77
|
2648 |
storeBinaryContentsOn:aStream
|
|
2649 |
"store the contents in binary representation on aStream."
|
|
2650 |
|
|
2651 |
aStream binary.
|
|
2652 |
self topView withCursor:Cursor write do:[
|
|
2653 |
self forEach:contents do:[:theObject |
|
|
2654 |
theObject storeBinaryOn:aStream.
|
|
2655 |
].
|
|
2656 |
]
|
|
2657 |
!
|
|
2658 |
|
0
|
2659 |
withoutRedrawFileInContentsFrom:aStream
|
77
|
2660 |
"remove all objects, load new contents from aStream without any redraw"
|
|
2661 |
|
|
2662 |
self fileInContentsFrom:aStream redraw:false new:true binary:false
|
0
|
2663 |
!
|
|
2664 |
|
|
2665 |
fileInContentsFrom:aStream
|
59
|
2666 |
"remove all objects, load new contents from aStream and redraw"
|
|
2667 |
|
77
|
2668 |
self fileInContentsFrom:aStream redraw:true new:true binary:false
|
63
|
2669 |
!
|
|
2670 |
|
|
2671 |
fileInContentsFrom:aStream redraw:redraw
|
|
2672 |
"remove all objects, load new contents from aStream
|
|
2673 |
and redraw if the redraw argument is true"
|
|
2674 |
|
77
|
2675 |
self fileInContentsFrom:aStream redraw:redraw new:true binary:false
|
|
2676 |
!
|
|
2677 |
|
|
2678 |
fileInContentsFrom:aStream redraw:redraw new:new
|
|
2679 |
"remove all objects, load new contents from aStream
|
|
2680 |
and redraw if the redraw argument is true"
|
|
2681 |
|
|
2682 |
self fileInContentsFrom:aStream redraw:redraw new:new binary:false
|
|
2683 |
!
|
|
2684 |
|
|
2685 |
fileInContentsFrom:aStream redraw:redraw new:new binary:binary
|
|
2686 |
"if the new argument is true, remove all objects.
|
|
2687 |
Then load objects from aStream. If redraw is false, no redraw
|
|
2688 |
is done
|
|
2689 |
(allows fileIn of multiple files doing a single redraw at the end)."
|
|
2690 |
|
|
2691 |
binary ifTrue:[
|
|
2692 |
aStream binary
|
|
2693 |
].
|
|
2694 |
self topView withCursor:(Cursor read) do:[
|
|
2695 |
|newObject chunk individualRedraw|
|
|
2696 |
|
|
2697 |
self unselect.
|
|
2698 |
individualRedraw := redraw.
|
|
2699 |
new ifTrue:[
|
|
2700 |
self removeAll.
|
|
2701 |
individualRedraw := false.
|
|
2702 |
].
|
|
2703 |
[aStream atEnd] whileFalse:[
|
|
2704 |
binary ifTrue:[
|
|
2705 |
newObject := Object readBinaryFrom:aStream
|
|
2706 |
] ifFalse:[
|
|
2707 |
chunk := aStream nextChunk.
|
|
2708 |
(chunk notNil and:[chunk isEmpty not]) ifTrue:[
|
|
2709 |
newObject := Compiler evaluate:chunk.
|
|
2710 |
] ifFalse:[
|
|
2711 |
newObject := nil
|
|
2712 |
]
|
|
2713 |
].
|
|
2714 |
newObject notNil ifTrue:[
|
|
2715 |
self initializeFileInObject:newObject.
|
|
2716 |
individualRedraw ifFalse:[
|
|
2717 |
self addObjectWithoutRedraw:newObject
|
|
2718 |
] ifTrue:[
|
|
2719 |
self addObject:newObject
|
|
2720 |
]
|
|
2721 |
]
|
|
2722 |
].
|
|
2723 |
(new and:[redraw]) ifTrue:[
|
|
2724 |
self redraw
|
|
2725 |
]
|
|
2726 |
]
|
0
|
2727 |
! !
|
63
|
2728 |
|