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