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