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