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