44
|
1 |
ObjectView subclass:#UIObjectView
|
|
2 |
instanceVariableNames:'inputView testMode undoHistory copiedExtent resizedObject
|
|
3 |
resizeSelector createInWidget createFrame createdObject
|
|
4 |
createClass'
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'Interface-UIPainter'
|
|
8 |
!
|
|
9 |
|
47
|
10 |
Object subclass:#UndoHistory
|
|
11 |
instanceVariableNames:'history transaction enabled modifiedAction'
|
|
12 |
classVariableNames:''
|
|
13 |
poolDictionaries:''
|
|
14 |
privateIn:UIObjectView
|
|
15 |
!
|
|
16 |
|
44
|
17 |
|
|
18 |
!UIObjectView class methodsFor:'defaults'!
|
|
19 |
|
|
20 |
defaultGrid
|
|
21 |
^ 4 @ 4
|
|
22 |
|
|
23 |
!
|
|
24 |
|
|
25 |
gridShown
|
|
26 |
^ false
|
|
27 |
|
|
28 |
!
|
|
29 |
|
|
30 |
handleSize
|
|
31 |
"size of blob drawn for handles"
|
|
32 |
^ 4
|
|
33 |
|
|
34 |
!
|
|
35 |
|
|
36 |
hitDelta
|
|
37 |
^ 4
|
|
38 |
|
|
39 |
! !
|
|
40 |
|
|
41 |
!UIObjectView methodsFor:'accessing'!
|
|
42 |
|
|
43 |
gridParameters
|
|
44 |
"used by defineGrid, and in a separate method for
|
|
45 |
easier redefinition in subclasses.
|
|
46 |
Returns the grid parameters in an array of 7 elements,
|
|
47 |
which control the appearance of the grid-pattern.
|
|
48 |
the elements are:
|
|
49 |
|
|
50 |
bigStepH number of pixels horizontally between 2 major steps
|
|
51 |
bigStepV number of pixels vertically between 2 major steps
|
|
52 |
littleStepH number of pixels horizontally between 2 minor steps
|
|
53 |
littleStepV number of pixels vertically between 2 minor steps
|
|
54 |
gridAlignH number of pixels for horizontal grid align (pointer snap)
|
|
55 |
gridAlignV number of pixels for vertical grid align (pointer snap)
|
|
56 |
docBounds true, if document boundary should be shown
|
|
57 |
|
|
58 |
if littleStepH/V are nil, only bigSteps are drawn.
|
|
59 |
"
|
|
60 |
|
|
61 |
^ #(10 10 nil nil 10 10 false)
|
|
62 |
|
|
63 |
|
|
64 |
!
|
|
65 |
|
|
66 |
hideGrid
|
|
67 |
gridShown ifTrue:[
|
|
68 |
self withSelectionHiddenDo:[
|
|
69 |
super hideGrid
|
|
70 |
]
|
|
71 |
]
|
|
72 |
|
|
73 |
|
|
74 |
!
|
|
75 |
|
|
76 |
showGrid
|
|
77 |
self withSelectionHiddenDo:[
|
|
78 |
super showGrid
|
|
79 |
]
|
|
80 |
|
|
81 |
"Modified: 5.9.1995 / 12:47:46 / claus"
|
|
82 |
|
|
83 |
|
|
84 |
!
|
|
85 |
|
|
86 |
testMode
|
|
87 |
"returns testMode
|
|
88 |
"
|
|
89 |
^ testMode
|
|
90 |
|
|
91 |
|
|
92 |
!
|
|
93 |
|
|
94 |
testMode:aBoolean
|
|
95 |
"change testMode
|
|
96 |
"
|
|
97 |
(aBoolean == testMode) ifFalse:[
|
|
98 |
testMode := aBoolean.
|
|
99 |
|
|
100 |
testMode ifTrue:[
|
|
101 |
self unselect.
|
|
102 |
inputView unrealize
|
|
103 |
] ifFalse:[
|
|
104 |
inputView raise.
|
|
105 |
inputView realize
|
|
106 |
]
|
|
107 |
]
|
|
108 |
|
|
109 |
|
|
110 |
! !
|
|
111 |
|
|
112 |
!UIObjectView methodsFor:'cut & paste'!
|
|
113 |
|
|
114 |
convertForPaste:something
|
|
115 |
Transcript showCR:'convertForPaste'.
|
|
116 |
^ nil
|
|
117 |
|
|
118 |
|
|
119 |
!
|
|
120 |
|
|
121 |
deleteSelection
|
|
122 |
"delete the selection
|
|
123 |
"
|
|
124 |
undoHistory transactionNamed:'delete' do:[
|
|
125 |
super deleteSelection
|
|
126 |
].
|
|
127 |
|
|
128 |
! !
|
|
129 |
|
|
130 |
!UIObjectView methodsFor:'dragging object move'!
|
|
131 |
|
|
132 |
doObjectMove:aPoint
|
|
133 |
"move selection
|
|
134 |
"
|
|
135 |
|
|
136 |
selection isCollection ifTrue:[^ self].
|
|
137 |
|
|
138 |
movedObject isNil ifTrue:[
|
|
139 |
(movedObject := selection) isNil ifTrue:[
|
|
140 |
^ self
|
|
141 |
].
|
|
142 |
super unselect.
|
|
143 |
moveDelta := aPoint - movedObject computeOrigin.
|
|
144 |
self invertOutlineOf:movedObject
|
|
145 |
].
|
|
146 |
|
|
147 |
self moveObject:movedObject to:(aPoint - moveDelta)
|
|
148 |
|
|
149 |
|
|
150 |
!
|
|
151 |
|
|
152 |
endObjectMove
|
|
153 |
"cleanup after object move"
|
|
154 |
|
|
155 |
movedObject notNil ifTrue:[
|
|
156 |
self invertOutlineOf:movedObject.
|
|
157 |
self setDefaultActions.
|
|
158 |
self select:movedObject.
|
|
159 |
movedObject := nil
|
|
160 |
].
|
|
161 |
|
|
162 |
"Modified: 5.9.1995 / 12:20:31 / claus"
|
|
163 |
|
|
164 |
|
|
165 |
!
|
|
166 |
|
|
167 |
startObjectMove:aView at:aPoint
|
|
168 |
|
|
169 |
super startObjectMove:aView at:aPoint.
|
|
170 |
|
|
171 |
aView notNil ifTrue:[
|
|
172 |
undoHistory transactionNamed:'move' do:[
|
|
173 |
self undoBlockPositionChanged:aView
|
|
174 |
]
|
|
175 |
]
|
|
176 |
|
|
177 |
|
|
178 |
!
|
|
179 |
|
|
180 |
startSelectMoreOrMove:aPoint
|
|
181 |
"add/remove to/from selection"
|
|
182 |
|
|
183 |
|anObject|
|
|
184 |
|
|
185 |
testMode ifTrue:[^ self].
|
|
186 |
|
|
187 |
anObject := self findObjectAtVisible:aPoint.
|
|
188 |
anObject notNil ifTrue:[
|
|
189 |
(self isSelected:anObject) ifTrue:[
|
|
190 |
self removeFromSelection:anObject
|
|
191 |
] ifFalse:[
|
|
192 |
self addToSelection:anObject
|
|
193 |
]
|
|
194 |
]
|
|
195 |
!
|
|
196 |
|
|
197 |
startSelectOrMove:aPoint
|
|
198 |
"a button is pressed at a point
|
|
199 |
"
|
|
200 |
|anObject b|
|
|
201 |
|
|
202 |
testMode ifTrue:[^ self].
|
|
203 |
|
|
204 |
"if there is one selection and point hits handle, start a resize
|
|
205 |
"
|
|
206 |
self singleSelection notNil ifTrue:[
|
|
207 |
b := self whichHandleOf:selection isHitBy:aPoint.
|
|
208 |
|
|
209 |
(b notNil and:[b ~~ #view]) ifTrue:[
|
|
210 |
^ self startResizeBorder:b of:selection at:aPoint.
|
|
211 |
]
|
|
212 |
].
|
|
213 |
|
|
214 |
anObject := self findObjectAtVisible:aPoint.
|
|
215 |
|
|
216 |
"nothing is selected
|
|
217 |
"
|
|
218 |
anObject isNil ifTrue:[
|
|
219 |
^ self unselect
|
|
220 |
].
|
|
221 |
|
|
222 |
"object not in selection; clear selection and add anObject to selection
|
|
223 |
"
|
|
224 |
(self isSelected:anObject) ifFalse:[
|
|
225 |
super unselect.
|
|
226 |
self select:anObject.
|
|
227 |
] ifTrue:[
|
|
228 |
selection isCollection ifTrue:[
|
|
229 |
^ self removeFromSelection:anObject.
|
|
230 |
]
|
|
231 |
].
|
|
232 |
|
|
233 |
"prepare move operation for an object
|
|
234 |
"
|
|
235 |
motionAction := [:movePoint|
|
|
236 |
(aPoint dist:movePoint) > 2.0 ifTrue:[
|
|
237 |
self startObjectMove:anObject at:aPoint
|
|
238 |
]
|
|
239 |
].
|
|
240 |
releaseAction := [self setDefaultActions].
|
|
241 |
|
|
242 |
|
|
243 |
! !
|
|
244 |
|
|
245 |
!UIObjectView methodsFor:'event handling'!
|
|
246 |
|
|
247 |
doKeyInput:key
|
|
248 |
^ self
|
|
249 |
|
|
250 |
|
|
251 |
!
|
|
252 |
|
|
253 |
elementChanged:aView
|
|
254 |
"some element has been changed - kludge to force a resizing
|
|
255 |
operation (for child layout recomputation) in its superView"
|
|
256 |
|
|
257 |
aView superView sizeChanged:nil.
|
|
258 |
self changed:#any.
|
|
259 |
|
|
260 |
|
|
261 |
!
|
|
262 |
|
|
263 |
elementChangedLayout:aView
|
|
264 |
"some element has been changed - kludge to force a resizing
|
|
265 |
operation (for child layout recomputation) in its superView"
|
|
266 |
|
|
267 |
aView superView sizeChanged:nil.
|
|
268 |
self changed:#layout.
|
|
269 |
|
|
270 |
|
|
271 |
!
|
|
272 |
|
|
273 |
exposeX:x y:y width:w height:h
|
|
274 |
"handle an expose event from device; redraw selection
|
|
275 |
"
|
|
276 |
super exposeX:x y:y width:w height:h.
|
|
277 |
|
|
278 |
selection notNil ifTrue:[
|
|
279 |
self selectionDo:[:v | self showSelected:v]
|
|
280 |
]
|
|
281 |
|
|
282 |
|
|
283 |
!
|
|
284 |
|
|
285 |
keyPress:key x:x y:y
|
|
286 |
|
|
287 |
key == #InspectIt ifTrue:[
|
|
288 |
^ self inspectSelection
|
|
289 |
].
|
|
290 |
|
|
291 |
(key == #Delete or:[key == #BackSpace]) ifTrue: [
|
|
292 |
selection notNil ifTrue:[
|
|
293 |
self deleteSelection
|
|
294 |
]
|
|
295 |
] ifFalse:[
|
|
296 |
keyPressAction notNil ifTrue:[
|
|
297 |
keyPressAction value:key
|
|
298 |
]
|
|
299 |
]
|
|
300 |
|
|
301 |
|
|
302 |
!
|
|
303 |
|
|
304 |
processEvent:anEvent
|
|
305 |
"catch expose events for components, and redraw its handles after
|
|
306 |
the redraw when this happens
|
|
307 |
"
|
|
308 |
|view|
|
|
309 |
|
|
310 |
selection notNil ifTrue:[
|
|
311 |
anEvent type == #damage ifTrue:[
|
|
312 |
view := anEvent view.
|
|
313 |
(selection == view
|
|
314 |
or:[selection isCollection
|
|
315 |
and:[selection includes:view]]) ifTrue:[
|
|
316 |
self showSelected:view
|
|
317 |
]
|
|
318 |
]
|
|
319 |
].
|
|
320 |
^ false.
|
|
321 |
|
|
322 |
|
|
323 |
!
|
|
324 |
|
|
325 |
sizeChanged:how
|
|
326 |
self withSelectionHiddenDo:[
|
|
327 |
super sizeChanged:how
|
|
328 |
]
|
|
329 |
|
|
330 |
|
|
331 |
! !
|
|
332 |
|
|
333 |
!UIObjectView methodsFor:'initialization'!
|
|
334 |
|
|
335 |
initialize
|
|
336 |
super initialize.
|
|
337 |
|
|
338 |
"funny: since I do not want the created widgets to get pointer
|
|
339 |
events, I put an InputView on top of them, which catches those events
|
|
340 |
and passes them back to me - have to take care, that this inputView
|
|
341 |
is always on top
|
|
342 |
"
|
|
343 |
inputView := InputView origin:0.0@0.0 extent:1.0@1.0 in:self.
|
|
344 |
|
|
345 |
inputView eventReceiver:self.
|
|
346 |
inputView enableButtonEvents.
|
|
347 |
inputView enableButtonMotionEvents.
|
|
348 |
|
|
349 |
undoHistory := UndoHistory new.
|
|
350 |
|
|
351 |
undoHistory modifiedAction:[:what|
|
|
352 |
self changed:#undoHistory with:what
|
|
353 |
].
|
|
354 |
|
|
355 |
testMode := false.
|
|
356 |
|
|
357 |
(self class gridShown) ifTrue:[
|
|
358 |
super showGrid
|
|
359 |
].
|
|
360 |
|
|
361 |
!
|
|
362 |
|
|
363 |
realize
|
|
364 |
super realize.
|
|
365 |
self windowGroup postEventHook:self
|
|
366 |
|
|
367 |
! !
|
|
368 |
|
|
369 |
!UIObjectView methodsFor:'misc'!
|
|
370 |
|
|
371 |
cursor:aCursor
|
|
372 |
inputView realized ifTrue:[
|
|
373 |
inputView cursor:aCursor
|
|
374 |
].
|
|
375 |
super cursor:aCursor
|
|
376 |
|
|
377 |
|
|
378 |
!
|
|
379 |
|
|
380 |
invertOutlineOf:anObject
|
|
381 |
|delta|
|
|
382 |
|
|
383 |
self clippedByChildren:false.
|
|
384 |
delta := (anObject originRelativeTo:self) - anObject origin.
|
|
385 |
self xoring:[
|
|
386 |
self displayRectangle:((anObject origin + delta) extent:anObject extent).
|
|
387 |
].
|
|
388 |
self clippedByChildren:true.
|
|
389 |
|
|
390 |
"Modified: 5.9.1995 / 12:25:25 / claus"
|
|
391 |
|
|
392 |
|
|
393 |
!
|
|
394 |
|
|
395 |
showDragging:something offset:anOffset
|
|
396 |
"drag around a View"
|
|
397 |
|
|
398 |
|top|
|
|
399 |
|
|
400 |
self forEach:something do:[:anObject |
|
|
401 |
self drawRectangle:((anObject origin + anOffset) extent:(anObject extent))
|
|
402 |
]
|
|
403 |
|
|
404 |
! !
|
|
405 |
|
|
406 |
!UIObjectView methodsFor:'object creation'!
|
|
407 |
|
|
408 |
doDragCreate:aPoint
|
|
409 |
"do a widget create drag
|
|
410 |
"
|
|
411 |
|p|
|
|
412 |
|
|
413 |
p := self alignToGrid:aPoint.
|
|
414 |
createFrame corner:(p - (createInWidget originRelativeTo:self)).
|
|
415 |
|
|
416 |
(createFrame extent x < 10) ifTrue:[
|
|
417 |
createFrame extent x:10
|
|
418 |
].
|
|
419 |
|
|
420 |
(createFrame extent y < 10) ifTrue:[
|
|
421 |
createFrame extent y:10
|
|
422 |
].
|
|
423 |
|
|
424 |
self invertOutlineOf:createdObject.
|
|
425 |
createdObject origin:(createFrame origin) extent:(createFrame extent).
|
|
426 |
self invertOutlineOf:createdObject.
|
|
427 |
!
|
|
428 |
|
|
429 |
endCreate
|
|
430 |
"end a widget create drag
|
|
431 |
"
|
|
432 |
self invertOutlineOf:createdObject.
|
|
433 |
self cursor:oldCursor.
|
|
434 |
inputView raise.
|
|
435 |
|
|
436 |
createdObject geometryLayout:(createdObject bounds asLayout).
|
|
437 |
|
|
438 |
self changed:#tree.
|
|
439 |
self select:createdObject.
|
|
440 |
createdObject := nil.
|
|
441 |
|
|
442 |
pressAction := [:pressPoint | self startSelectOrMove:pressPoint].
|
|
443 |
motionAction := [:movePoint | true].
|
|
444 |
releaseAction := [ true ].
|
|
445 |
|
|
446 |
self cursor:Cursor normal.
|
|
447 |
|
|
448 |
|
|
449 |
!
|
|
450 |
|
|
451 |
initializeCreatedObject:anObject
|
|
452 |
self subclassResponsibility
|
|
453 |
!
|
|
454 |
|
|
455 |
startCreate:aPoint
|
|
456 |
"start a widget create
|
|
457 |
"
|
|
458 |
|props index startPoint|
|
|
459 |
|
|
460 |
createClass isNil ifTrue:[
|
|
461 |
^ self
|
|
462 |
].
|
|
463 |
|
|
464 |
startPoint := self alignToGrid:aPoint.
|
|
465 |
motionAction := [:movePoint | self doDragCreate:movePoint].
|
|
466 |
releaseAction := [self endCreate].
|
|
467 |
|
|
468 |
(selection isNil or:[selection isKindOf:Collection]) ifTrue:[
|
|
469 |
createInWidget := self findObjectIn:self at:aPoint
|
|
470 |
] ifFalse:[
|
|
471 |
createInWidget := self findObjectIn:selection at:aPoint
|
|
472 |
].
|
|
473 |
super unselect.
|
|
474 |
self select:createInWidget.
|
|
475 |
|
|
476 |
oldCursor := cursor.
|
|
477 |
self cursor:(Cursor leftHand).
|
|
478 |
|
|
479 |
createInWidget isNil ifTrue:[
|
|
480 |
createdObject := createClass in:self.
|
|
481 |
createInWidget := self.
|
|
482 |
] ifFalse:[
|
|
483 |
createdObject := createClass new.
|
|
484 |
createInWidget addSubView:createdObject.
|
|
485 |
].
|
|
486 |
|
|
487 |
createFrame := Rectangle origin:(startPoint - (createInWidget originRelativeTo:self))
|
|
488 |
corner:startPoint.
|
|
489 |
|
|
490 |
createdObject origin:(createFrame origin).
|
|
491 |
|
|
492 |
undoHistory transactionNamed:'create' do:[
|
|
493 |
self initializeCreatedObject:createdObject.
|
|
494 |
].
|
|
495 |
createdObject realize.
|
|
496 |
self invertOutlineOf:createdObject.
|
|
497 |
! !
|
|
498 |
|
|
499 |
!UIObjectView methodsFor:'private handles'!
|
|
500 |
|
|
501 |
handlesOf:aComponent do:aBlock
|
|
502 |
|delta layout vertical horizontal|
|
|
503 |
|
|
504 |
layout := aComponent geometryLayout.
|
|
505 |
delta := (aComponent originRelativeTo:self) - aComponent origin.
|
|
506 |
|
|
507 |
(layout isLayout not or:[layout isLayoutFrame]) ifTrue:[
|
|
508 |
vertical := self isVerticalResizable:aComponent.
|
|
509 |
horizontal := self isHorizontalResizable:aComponent.
|
|
510 |
] ifFalse:[
|
|
511 |
vertical := false.
|
|
512 |
horizontal := false.
|
|
513 |
].
|
|
514 |
|
|
515 |
horizontal ifTrue:[
|
|
516 |
aBlock value:(aComponent leftCenter + delta) value:#left.
|
|
517 |
aBlock value:(aComponent rightCenter + delta) value:#right.
|
|
518 |
].
|
|
519 |
|
|
520 |
vertical ifTrue:[
|
|
521 |
aBlock value:(aComponent topCenter + delta) value:#top.
|
|
522 |
aBlock value:(aComponent bottomCenter + delta) value:#bottom.
|
|
523 |
].
|
|
524 |
|
|
525 |
(horizontal and:[vertical]) ifTrue:[
|
|
526 |
aBlock value:(aComponent origin + delta) value:#origin.
|
|
527 |
aBlock value:(aComponent corner + delta) value:#corner.
|
|
528 |
aBlock value:(aComponent topRight + delta) value:#topRight.
|
|
529 |
aBlock value:(aComponent bottomLeft + delta) value:#bottomLeft.
|
|
530 |
] ifFalse:[
|
|
531 |
aBlock value:(aComponent origin + delta) value:#view.
|
|
532 |
aBlock value:(aComponent corner + delta) value:#view.
|
|
533 |
aBlock value:(aComponent topRight + delta) value:#view.
|
|
534 |
aBlock value:(aComponent bottomLeft + delta) value:#view.
|
|
535 |
].
|
|
536 |
|
|
537 |
|
|
538 |
!
|
|
539 |
|
|
540 |
showSelected:aComponent
|
|
541 |
|delta oldPaint|
|
|
542 |
|
|
543 |
self paint:Color black.
|
|
544 |
self clippedByChildren:false.
|
|
545 |
|
|
546 |
self handlesOf:aComponent do:[:pnt :what |
|
|
547 |
what == #view ifTrue:[self displayRectangle:(pnt - (4@4) extent:7@7)]
|
|
548 |
ifFalse:[self fillRectangle:(pnt - (4@4) extent:7@7)]
|
|
549 |
].
|
|
550 |
|
|
551 |
self clippedByChildren:true.
|
|
552 |
self paint:oldPaint.
|
|
553 |
!
|
|
554 |
|
|
555 |
showUnselected:aComponent
|
|
556 |
|delta r oldPaint|
|
|
557 |
|
|
558 |
r := aComponent origin extent:8@8.
|
|
559 |
|
|
560 |
self clippedByChildren:false.
|
|
561 |
|
|
562 |
self handlesOf:aComponent do:[:pnt :what |
|
|
563 |
self clearRectangle:(pnt - (4@4) extent:7@7).
|
|
564 |
].
|
|
565 |
|
|
566 |
self clippedByChildren:true.
|
|
567 |
|
|
568 |
"/ must redraw all components which are affected b the handles
|
|
569 |
|
|
570 |
r := (aComponent originRelativeTo:self) - (4@4)
|
|
571 |
extent:(aComponent extent + (4@4)).
|
|
572 |
|
|
573 |
subViews do:[:anotherComponent |
|
|
574 |
|absOrg absFrame|
|
|
575 |
|
|
576 |
anotherComponent ~~ inputView ifTrue:[
|
|
577 |
absOrg := anotherComponent originRelativeTo:self.
|
|
578 |
absFrame := absOrg extent:(anotherComponent extent).
|
|
579 |
(absFrame intersects:r) ifTrue:[
|
|
580 |
anotherComponent withAllSubViewsDo:[:v |
|
|
581 |
v clear.
|
|
582 |
v exposeX:0 y:0 width:9999 height:9999.
|
|
583 |
]
|
|
584 |
]
|
|
585 |
]
|
|
586 |
]
|
|
587 |
|
|
588 |
!
|
|
589 |
|
|
590 |
whichHandleOf:aView isHitBy:aPoint
|
|
591 |
|bounds|
|
|
592 |
|
|
593 |
self handlesOf:aView do:[:pnt :what |
|
|
594 |
((pnt - (4@4) extent:7@7) containsPoint:aPoint) ifTrue:[
|
|
595 |
^ what
|
|
596 |
].
|
|
597 |
].
|
|
598 |
|
|
599 |
^ #view
|
|
600 |
|
|
601 |
"Modified: 5.9.1995 / 14:39:34 / claus"
|
|
602 |
|
|
603 |
! !
|
|
604 |
|
|
605 |
!UIObjectView methodsFor:'private resizing-subviews'!
|
|
606 |
|
|
607 |
resize:aView bottom:aPoint
|
|
608 |
|
|
609 |
undoHistory disabledTransitionDo:[
|
|
610 |
self shifLayout:aView top:0 bottom:((aPoint y) - (aView computeCorner y))
|
|
611 |
]
|
|
612 |
!
|
|
613 |
|
|
614 |
resize:aView corner:aPoint
|
|
615 |
|delta|
|
|
616 |
|
|
617 |
delta := aPoint - aView computeCorner.
|
|
618 |
|
|
619 |
undoHistory disabledTransitionDo:[
|
|
620 |
self shifLayout:aView top:0 bottom:(delta y) left:0 right:(delta x)
|
|
621 |
]
|
|
622 |
!
|
|
623 |
|
|
624 |
resize:aView left:aPoint
|
|
625 |
|
|
626 |
undoHistory disabledTransitionDo:[
|
|
627 |
self shifLayout:aView left:((aPoint x) - (aView computeOrigin x)) right:0
|
|
628 |
]
|
|
629 |
|
|
630 |
!
|
|
631 |
|
|
632 |
resize:aView right:aPoint
|
|
633 |
|
|
634 |
undoHistory disabledTransitionDo:[
|
|
635 |
self shifLayout:aView left:0 right:((aPoint x) - (aView computeCorner x))
|
|
636 |
]
|
|
637 |
!
|
|
638 |
|
|
639 |
resize:aView top:aPoint
|
|
640 |
|
|
641 |
undoHistory disabledTransitionDo:[
|
|
642 |
self shifLayout:aView top:((aPoint y) - (aView computeOrigin y)) bottom:0
|
|
643 |
]
|
|
644 |
! !
|
|
645 |
|
|
646 |
!UIObjectView methodsFor:'private shift-layout'!
|
|
647 |
|
|
648 |
shifLayout:aView left:l right:r
|
|
649 |
"shift layout for a view; in case of an open transaction, the
|
|
650 |
undoAction will be defined
|
|
651 |
"
|
|
652 |
self shifLayout:aView top:0 bottom:0 left:l right:r
|
|
653 |
|
|
654 |
!
|
|
655 |
|
|
656 |
shifLayout:aView top:t bottom:b
|
|
657 |
"shift layout for a view; in case of an open transaction, the
|
|
658 |
undoAction will be defined
|
|
659 |
"
|
|
660 |
self shifLayout:aView top:t bottom:b left:0 right:0
|
|
661 |
|
|
662 |
|
|
663 |
!
|
|
664 |
|
|
665 |
shifLayout:aView top:t bottom:b left:l right:r
|
|
666 |
"shift layout for a view; in case of an open transaction, the
|
|
667 |
undoAction will be defined
|
|
668 |
"
|
|
669 |
|layout|
|
|
670 |
|
|
671 |
self undoBlockPositionChanged:aView.
|
|
672 |
|
|
673 |
layout := aView geometryLayout.
|
|
674 |
|
|
675 |
layout leftOffset:(layout leftOffset + l)
|
|
676 |
topOffset:(layout topOffset + t).
|
|
677 |
|
|
678 |
layout isLayoutFrame ifTrue:[
|
|
679 |
layout bottomOffset:(layout bottomOffset + b).
|
|
680 |
layout rightOffset:(layout rightOffset + r).
|
|
681 |
].
|
|
682 |
|
|
683 |
aView geometryLayout:layout.
|
|
684 |
|
|
685 |
|
|
686 |
|
|
687 |
! !
|
|
688 |
|
|
689 |
!UIObjectView methodsFor:'private undo-actions'!
|
|
690 |
|
|
691 |
undoBlockDimensionChanged:aView
|
|
692 |
|
|
693 |
undoHistory isTransactionOpen ifTrue:[
|
|
694 |
|layout|
|
|
695 |
|
|
696 |
layout := aView geometryLayout copy.
|
|
697 |
|
|
698 |
undoHistory addUndoBlock:[
|
|
699 |
aView geometryLayout:layout.
|
|
700 |
aView superView sizeChanged:nil.
|
|
701 |
]
|
|
702 |
]
|
|
703 |
|
|
704 |
!
|
|
705 |
|
|
706 |
undoBlockPositionChanged:aView
|
|
707 |
|
|
708 |
undoHistory isTransactionOpen ifTrue:[
|
|
709 |
|layout|
|
|
710 |
|
|
711 |
layout := aView geometryLayout copy.
|
|
712 |
undoHistory addUndoBlock:[aView geometryLayout:layout]
|
|
713 |
]
|
|
714 |
|
|
715 |
! !
|
|
716 |
|
|
717 |
!UIObjectView methodsFor:'searching'!
|
|
718 |
|
|
719 |
findObjectAt:aPoint
|
|
720 |
"find the origin/corner of the currentWidget"
|
|
721 |
|
|
722 |
selection notNil ifTrue:[
|
|
723 |
(selection isKindOf:Collection) ifTrue:[
|
|
724 |
^ self findObjectIn:(selection first) at:aPoint
|
|
725 |
].
|
|
726 |
^ self findObjectIn:selection at:aPoint
|
|
727 |
].
|
|
728 |
^ self findObjectIn:self at:aPoint
|
|
729 |
|
|
730 |
|
|
731 |
|
|
732 |
!
|
|
733 |
|
|
734 |
findObjectIn:aView at:aPoint
|
|
735 |
"find the origin/corner of the currentWidget
|
|
736 |
"
|
|
737 |
|relPoint|
|
|
738 |
|
|
739 |
aView isNil ifTrue:[^ nil].
|
|
740 |
aView subViews notNil ifTrue:[
|
|
741 |
relPoint := aPoint - (aView originRelativeTo:self).
|
|
742 |
self subviewsOf:aView do:[:aView |
|
|
743 |
|org ext|
|
|
744 |
|
|
745 |
(aView isKindOf:InputView) ifFalse:[
|
|
746 |
org := aView computeOrigin.
|
|
747 |
ext := aView computeExtent.
|
|
748 |
((org extent:ext) containsPoint:relPoint) ifTrue:[
|
|
749 |
^ aView
|
|
750 |
]
|
|
751 |
]
|
|
752 |
]
|
|
753 |
].
|
|
754 |
(aView == self) ifTrue:[^ nil].
|
|
755 |
|
|
756 |
^ self findObjectIn:(aView superView) at:aPoint
|
|
757 |
!
|
|
758 |
|
|
759 |
whichBorderOf:aView isHitBy:aPoint
|
|
760 |
|p r bw org|
|
|
761 |
|
|
762 |
bw := aView borderWidth.
|
|
763 |
p := aPoint - (aView superView originRelativeTo:self).
|
|
764 |
|
|
765 |
r := Rectangle origin:(aView origin)
|
|
766 |
extent:(aView width @ bw).
|
|
767 |
(r containsPoint:p) ifTrue:[^ #top:].
|
|
768 |
|
|
769 |
r origin:(aView left @ (aView bottom + bw)) extent:(aView width @ bw).
|
|
770 |
(r containsPoint:p) ifTrue:[^ #bottom:].
|
|
771 |
|
|
772 |
r top:(aView top).
|
|
773 |
r extent:(bw @ aView height).
|
|
774 |
(r containsPoint:p) ifTrue:[^ #left:].
|
|
775 |
|
|
776 |
r origin:((aView right + bw) @ aView top).
|
|
777 |
(r containsPoint:p) ifTrue:[^ #right:].
|
|
778 |
|
|
779 |
^ nil
|
|
780 |
|
|
781 |
|
|
782 |
! !
|
|
783 |
|
|
784 |
!UIObjectView methodsFor:'selections'!
|
|
785 |
|
|
786 |
addToSelection:something
|
|
787 |
(testMode or:[something == selection]) ifFalse:[
|
|
788 |
selection ~~ something ifTrue:[
|
|
789 |
super addToSelection:something.
|
|
790 |
self changed:#selection.
|
|
791 |
]
|
|
792 |
]
|
|
793 |
!
|
|
794 |
|
|
795 |
inspectSelection
|
|
796 |
self singleSelectionDo:[:aView |
|
|
797 |
aView inspect
|
|
798 |
]
|
|
799 |
!
|
|
800 |
|
|
801 |
removeFromSelection:something
|
|
802 |
super removeFromSelection:something.
|
|
803 |
self changed:#selection
|
|
804 |
|
|
805 |
!
|
|
806 |
|
|
807 |
select:something
|
|
808 |
(testMode or:[something == selection]) ifFalse:[
|
|
809 |
super select:something.
|
|
810 |
self changed:#selection
|
|
811 |
]
|
|
812 |
|
|
813 |
!
|
|
814 |
|
|
815 |
selection
|
|
816 |
^ selection
|
|
817 |
|
|
818 |
|
|
819 |
!
|
|
820 |
|
|
821 |
selectionFindMinimum:aOneArgBlock
|
|
822 |
"returns the minimum value from the block evaluated on each view
|
|
823 |
in the selection
|
|
824 |
"
|
|
825 |
|min val|
|
|
826 |
|
|
827 |
self selectionDo:[:aView|
|
|
828 |
val := aOneArgBlock value:aView.
|
|
829 |
|
|
830 |
min isNil ifTrue:[min := val]
|
|
831 |
ifFalse:[min := min min:val]
|
|
832 |
].
|
|
833 |
^ min
|
|
834 |
!
|
|
835 |
|
|
836 |
selectionHiddenDo:aBlock
|
|
837 |
"apply block to every object in selection"
|
|
838 |
|
|
839 |
self selectionDo:[:aView |
|
|
840 |
self showUnselected:aView.
|
|
841 |
].
|
|
842 |
device flush.
|
|
843 |
aBlock value.
|
|
844 |
self selectionDo:[:aView |
|
|
845 |
self showSelected:aView
|
|
846 |
]
|
|
847 |
|
|
848 |
|
|
849 |
!
|
|
850 |
|
|
851 |
singleSelection
|
|
852 |
"returns single selection or nil
|
|
853 |
"
|
|
854 |
(selection isKindOf:SimpleView) ifTrue:[^ selection]
|
|
855 |
ifFalse:[^ nil]
|
|
856 |
!
|
|
857 |
|
|
858 |
singleSelectionDo:aBlock
|
|
859 |
|
|
860 |
self singleSelection notNil ifTrue:[
|
|
861 |
aBlock value:selection
|
|
862 |
]
|
|
863 |
!
|
|
864 |
|
|
865 |
unselect
|
|
866 |
selection notNil ifTrue:[
|
|
867 |
super unselect.
|
|
868 |
self changed:#selection
|
|
869 |
]
|
|
870 |
|
|
871 |
!
|
|
872 |
|
|
873 |
withSelectionHiddenDo:aBlock
|
|
874 |
"evaluate aBlock while selection is hidden"
|
|
875 |
|
|
876 |
|sel|
|
|
877 |
|
|
878 |
selection isNil ifTrue:[
|
|
879 |
aBlock value
|
|
880 |
] ifFalse:[
|
|
881 |
sel := selection.
|
|
882 |
super unselect.
|
|
883 |
aBlock value.
|
|
884 |
super select:sel
|
|
885 |
]
|
|
886 |
|
|
887 |
"Modified: 6.9.1995 / 01:46:16 / claus"
|
|
888 |
|
|
889 |
|
|
890 |
! !
|
|
891 |
|
|
892 |
!UIObjectView methodsFor:'testing'!
|
|
893 |
|
|
894 |
canMove:something
|
|
895 |
^ true
|
|
896 |
|
|
897 |
|
|
898 |
!
|
|
899 |
|
|
900 |
isHorizontalResizable:aComponent
|
|
901 |
^ self subclassResponsibility
|
|
902 |
|
|
903 |
|
|
904 |
!
|
|
905 |
|
|
906 |
isVerticalResizable:aComponent
|
|
907 |
^ self subclassResponsibility
|
|
908 |
|
|
909 |
|
|
910 |
! !
|
|
911 |
|
|
912 |
!UIObjectView methodsFor:'user actions'!
|
|
913 |
|
|
914 |
createWidgetWithClass:aClass
|
|
915 |
"prepare to create new widgets
|
|
916 |
"
|
|
917 |
createClass := aClass.
|
|
918 |
pressAction := [:pressPoint | self startCreate:pressPoint].
|
|
919 |
self cursor:Cursor origin.
|
|
920 |
|
|
921 |
|
|
922 |
!
|
|
923 |
|
|
924 |
undoAction
|
|
925 |
undoHistory notEmpty ifTrue:[
|
|
926 |
self unselect.
|
|
927 |
undoHistory undoLast
|
|
928 |
]
|
|
929 |
|
|
930 |
|
|
931 |
! !
|
|
932 |
|
|
933 |
!UIObjectView methodsFor:'user actions - dimension'!
|
|
934 |
|
|
935 |
copyExtent
|
|
936 |
(selection isNil or:[selection isKindOf:Collection]) ifTrue:[
|
|
937 |
^ self warn:'exactly one element must be selected'.
|
|
938 |
].
|
|
939 |
copiedExtent := selection computeExtent
|
|
940 |
|
|
941 |
|
|
942 |
|
|
943 |
!
|
|
944 |
|
|
945 |
pasteExtent
|
|
946 |
copiedExtent notNil ifTrue:[
|
|
947 |
self transition:'paste extent' dimensionDo:[:v|
|
|
948 |
self resize:v corner:(v computeOrigin + copiedExtent)
|
|
949 |
]
|
|
950 |
]
|
|
951 |
!
|
|
952 |
|
|
953 |
pasteHeight
|
|
954 |
copiedExtent notNil ifTrue:[
|
|
955 |
self transition:'paste height' dimensionDo:[:v|
|
|
956 |
self resize:v bottom:(v computeOrigin + copiedExtent)
|
|
957 |
]
|
|
958 |
]
|
|
959 |
|
|
960 |
!
|
|
961 |
|
|
962 |
pasteWidth
|
|
963 |
copiedExtent notNil ifTrue:[
|
|
964 |
self transition:'paste width' dimensionDo:[:v|
|
|
965 |
self resize:v right:(v computeOrigin + copiedExtent)
|
|
966 |
]
|
|
967 |
]
|
|
968 |
|
|
969 |
!
|
|
970 |
|
|
971 |
setDimension:aLayout
|
|
972 |
|undoText|
|
|
973 |
|
|
974 |
undoText := 'change layout'.
|
|
975 |
aLayout isLayout ifTrue:[
|
|
976 |
undoText := 'change to layout frame'.
|
|
977 |
aLayout isAlignmentOrigin ifTrue:[
|
|
978 |
undoText := 'change to layout alignOrigin'.
|
|
979 |
] ifFalse:[
|
|
980 |
aLayout isAlignmentOrigin ifTrue:[
|
|
981 |
undoText := 'change to layout origin'.
|
|
982 |
]
|
|
983 |
]
|
|
984 |
].
|
|
985 |
|
|
986 |
self transition:undoText dimensionDo:[:v| v geometryLayout:(aLayout copy)]
|
|
987 |
|
|
988 |
!
|
|
989 |
|
|
990 |
setToDefaultExtent
|
|
991 |
self transition:'default extent' dimensionDo:[:v|
|
|
992 |
self resize:v corner:(v computeOrigin + (v preferredExtent))
|
|
993 |
]
|
|
994 |
|
|
995 |
!
|
|
996 |
|
|
997 |
setToDefaultHeight
|
|
998 |
self transition:'default height' dimensionDo:[:v|
|
|
999 |
self resize:v bottom:(v computeOrigin + (v preferredExtent))
|
|
1000 |
]
|
|
1001 |
|
|
1002 |
!
|
|
1003 |
|
|
1004 |
setToDefaultWidth
|
|
1005 |
self transition:'default width' dimensionDo:[:v|
|
|
1006 |
self resize:v right:(v computeOrigin + (v preferredExtent))
|
|
1007 |
]
|
|
1008 |
|
|
1009 |
!
|
|
1010 |
|
|
1011 |
transition:what dimensionDo:aOneArgBlock
|
|
1012 |
"change dimension within a transaction for the selected elements by evaluating
|
|
1013 |
the block with the argument a view.
|
|
1014 |
"
|
|
1015 |
self selectionHiddenDo:[
|
|
1016 |
undoHistory transactionNamed:what do:[
|
|
1017 |
self selectionDo:[:aView|
|
|
1018 |
self undoBlockDimensionChanged:aView.
|
|
1019 |
aOneArgBlock value:aView.
|
|
1020 |
self elementChangedLayout:aView.
|
|
1021 |
]
|
|
1022 |
]
|
|
1023 |
]
|
|
1024 |
! !
|
|
1025 |
|
|
1026 |
!UIObjectView methodsFor:'user actions - move'!
|
|
1027 |
|
|
1028 |
basicMoveSelectionHorizontal:n
|
|
1029 |
"move left: n < 0
|
|
1030 |
move right: n > 0
|
|
1031 |
"
|
|
1032 |
self selectionHiddenDo:[
|
|
1033 |
undoHistory transactionNamed:'move' do:[
|
|
1034 |
self selectionDo:[:aView|self shifLayout:aView left:n right:n]
|
|
1035 |
].
|
|
1036 |
self changed:#layout
|
|
1037 |
]
|
|
1038 |
|
|
1039 |
|
|
1040 |
!
|
|
1041 |
|
|
1042 |
basicMoveSelectionVertical:n
|
|
1043 |
"move up: n < 0
|
|
1044 |
move down: n > 0
|
|
1045 |
"
|
|
1046 |
self selectionHiddenDo:[
|
|
1047 |
undoHistory transactionNamed:'move' do:[
|
|
1048 |
self selectionDo:[:aView| self shifLayout:aView top:n bottom:n ]
|
|
1049 |
].
|
|
1050 |
self changed:#layout
|
|
1051 |
]
|
|
1052 |
|
|
1053 |
|
|
1054 |
|
|
1055 |
!
|
|
1056 |
|
|
1057 |
moveObject:anObject to:aPoint
|
|
1058 |
"move anObject to newOrigin, aPoint
|
|
1059 |
"
|
|
1060 |
|dX dY org delta|
|
|
1061 |
|
|
1062 |
anObject notNil ifTrue:[
|
|
1063 |
self invertOutlineOf:anObject.
|
|
1064 |
|
|
1065 |
org := anObject computeOrigin.
|
|
1066 |
|
|
1067 |
delta := aPoint - org.
|
|
1068 |
delta := (self alignToGrid:aPoint) - org.
|
|
1069 |
dX := delta x.
|
|
1070 |
dY := delta y.
|
|
1071 |
|
|
1072 |
undoHistory disabledTransitionDo:[
|
|
1073 |
self shifLayout:anObject top:dY bottom:dY left:dX right:dX
|
|
1074 |
].
|
|
1075 |
self elementChangedLayout:anObject.
|
|
1076 |
self invertOutlineOf:anObject.
|
|
1077 |
]
|
|
1078 |
|
|
1079 |
!
|
|
1080 |
|
|
1081 |
moveSelectionDown
|
|
1082 |
self moveSelectionDown:1
|
|
1083 |
|
|
1084 |
|
|
1085 |
!
|
|
1086 |
|
|
1087 |
moveSelectionDown10
|
|
1088 |
self moveSelectionDown:10
|
|
1089 |
|
|
1090 |
|
|
1091 |
!
|
|
1092 |
|
|
1093 |
moveSelectionDown:n
|
|
1094 |
self basicMoveSelectionVertical:n
|
|
1095 |
|
|
1096 |
|
|
1097 |
!
|
|
1098 |
|
|
1099 |
moveSelectionLeft
|
|
1100 |
self moveSelectionLeft:1
|
|
1101 |
|
|
1102 |
|
|
1103 |
!
|
|
1104 |
|
|
1105 |
moveSelectionLeft10
|
|
1106 |
self moveSelectionLeft:10
|
|
1107 |
|
|
1108 |
|
|
1109 |
!
|
|
1110 |
|
|
1111 |
moveSelectionLeft:n
|
|
1112 |
self basicMoveSelectionHorizontal:(n negated)
|
|
1113 |
|
|
1114 |
|
|
1115 |
!
|
|
1116 |
|
|
1117 |
moveSelectionRight
|
|
1118 |
self moveSelectionRight:1
|
|
1119 |
|
|
1120 |
|
|
1121 |
!
|
|
1122 |
|
|
1123 |
moveSelectionRight10
|
|
1124 |
self moveSelectionRight:10
|
|
1125 |
|
|
1126 |
|
|
1127 |
!
|
|
1128 |
|
|
1129 |
moveSelectionRight:n
|
|
1130 |
self basicMoveSelectionHorizontal:n
|
|
1131 |
|
|
1132 |
|
|
1133 |
!
|
|
1134 |
|
|
1135 |
moveSelectionUp
|
|
1136 |
self moveSelectionUp:1
|
|
1137 |
|
|
1138 |
|
|
1139 |
!
|
|
1140 |
|
|
1141 |
moveSelectionUp10
|
|
1142 |
self moveSelectionUp:10
|
|
1143 |
|
|
1144 |
|
|
1145 |
!
|
|
1146 |
|
|
1147 |
moveSelectionUp:n
|
|
1148 |
self basicMoveSelectionVertical:(n negated)
|
|
1149 |
|
|
1150 |
|
|
1151 |
! !
|
|
1152 |
|
|
1153 |
!UIObjectView methodsFor:'user actions - position'!
|
|
1154 |
|
|
1155 |
alignSelectionBottom
|
|
1156 |
|bmost delta|
|
|
1157 |
|
|
1158 |
self selectionHiddenDo:[
|
|
1159 |
bmost := 0.
|
|
1160 |
self selectionDo:[:v| bmost := bmost max:(v computeCorner y)].
|
|
1161 |
|
|
1162 |
undoHistory transactionNamed:'align' do:[
|
|
1163 |
self selectionDo:[:v|
|
|
1164 |
(delta := bmost - (v computeCorner y)) ~~ 0 ifTrue:[
|
|
1165 |
self shifLayout:v top:delta bottom:delta
|
|
1166 |
]
|
|
1167 |
]
|
|
1168 |
].
|
|
1169 |
self changed:#layout
|
|
1170 |
]
|
|
1171 |
|
|
1172 |
|
|
1173 |
|
|
1174 |
!
|
|
1175 |
|
|
1176 |
alignSelectionCenterHor
|
|
1177 |
|counter centerX|
|
|
1178 |
|
|
1179 |
self selectionHiddenDo:[
|
|
1180 |
counter := 0.
|
|
1181 |
centerX := 0.
|
|
1182 |
|
|
1183 |
self selectionDo:[:v |
|
|
1184 |
centerX := centerX + (v computeCorner x + v computeOrigin x).
|
|
1185 |
counter := counter + 1.
|
|
1186 |
].
|
|
1187 |
centerX := centerX // (counter * 2).
|
|
1188 |
|
|
1189 |
undoHistory transactionNamed:'align' do:[
|
|
1190 |
|newX oldX delta|
|
|
1191 |
|
|
1192 |
self selectionDo:[:v|
|
|
1193 |
oldX := v computeOrigin x.
|
|
1194 |
newX := centerX - ((v computeCorner x - oldX) // 2).
|
|
1195 |
delta := newX - oldX.
|
|
1196 |
|
|
1197 |
self shifLayout:v left:delta right:delta
|
|
1198 |
]
|
|
1199 |
].
|
|
1200 |
self changed:#layout
|
|
1201 |
]
|
|
1202 |
|
|
1203 |
|
|
1204 |
|
|
1205 |
!
|
|
1206 |
|
|
1207 |
alignSelectionCenterVer
|
|
1208 |
|counter centerY|
|
|
1209 |
|
|
1210 |
self selectionHiddenDo:[
|
|
1211 |
counter := 0.
|
|
1212 |
centerY := 0.
|
|
1213 |
|
|
1214 |
self selectionDo:[:v |
|
|
1215 |
centerY := centerY + (v computeCorner y + v computeOrigin y).
|
|
1216 |
counter := counter + 1.
|
|
1217 |
].
|
|
1218 |
centerY := centerY // (counter * 2).
|
|
1219 |
|
|
1220 |
undoHistory transactionNamed:'align' do:[
|
|
1221 |
|newY oldY delta|
|
|
1222 |
|
|
1223 |
self selectionDo:[:v|
|
|
1224 |
oldY := v computeOrigin y.
|
|
1225 |
newY := centerY - ((v computeCorner y - oldY) // 2).
|
|
1226 |
delta := newY - oldY.
|
|
1227 |
|
|
1228 |
self shifLayout:v top:delta bottom:delta
|
|
1229 |
]
|
|
1230 |
].
|
|
1231 |
self changed:#layout
|
|
1232 |
]
|
|
1233 |
!
|
|
1234 |
|
|
1235 |
alignSelectionLeft
|
|
1236 |
|lmost delta|
|
|
1237 |
|
|
1238 |
self selectionHiddenDo:[
|
|
1239 |
lmost := self selectionFindMinimum:[:v| v computeOrigin x].
|
|
1240 |
|
|
1241 |
undoHistory transactionNamed:'align' do:[
|
|
1242 |
self selectionDo:[:v|
|
|
1243 |
(delta := lmost - (v computeOrigin x)) ~~ 0 ifTrue:[
|
|
1244 |
self shifLayout:v left:delta right:delta
|
|
1245 |
]
|
|
1246 |
]
|
|
1247 |
].
|
|
1248 |
self changed:#layout
|
|
1249 |
]
|
|
1250 |
|
|
1251 |
!
|
|
1252 |
|
|
1253 |
alignSelectionLeftAndRight
|
|
1254 |
|lmost rmost|
|
|
1255 |
|
|
1256 |
self selectionHiddenDo:[
|
|
1257 |
lmost := self selectionFindMinimum:[:v| v computeOrigin x].
|
|
1258 |
rmost := 0.
|
|
1259 |
self selectionDo:[:v | rmost := rmost max:(v computeCorner x)].
|
|
1260 |
|
|
1261 |
undoHistory transactionNamed:'align' do:[
|
|
1262 |
self selectionDo:[:v|
|
|
1263 |
self shifLayout:v left:(lmost - (v computeOrigin x))
|
|
1264 |
right:(rmost - (v computeCorner x))
|
|
1265 |
]
|
|
1266 |
].
|
|
1267 |
self changed:#layout
|
|
1268 |
]
|
|
1269 |
!
|
|
1270 |
|
|
1271 |
alignSelectionRight
|
|
1272 |
|rmost delta|
|
|
1273 |
|
|
1274 |
self selectionHiddenDo:[
|
|
1275 |
rmost := 0.
|
|
1276 |
self selectionDo:[:v| rmost := rmost max:(v computeCorner x)].
|
|
1277 |
|
|
1278 |
undoHistory transactionNamed:'align' do:[
|
|
1279 |
self selectionDo:[:v|
|
|
1280 |
(delta := rmost - (v computeCorner x)) ~~ 0 ifTrue:[
|
|
1281 |
self shifLayout:v left:delta right:delta
|
|
1282 |
]
|
|
1283 |
]
|
|
1284 |
].
|
|
1285 |
self changed:#layout
|
|
1286 |
]
|
|
1287 |
|
|
1288 |
!
|
|
1289 |
|
|
1290 |
alignSelectionTop
|
|
1291 |
|tmost delta|
|
|
1292 |
|
|
1293 |
self selectionHiddenDo:[
|
|
1294 |
tmost := self selectionFindMinimum:[:v| v computeOrigin y].
|
|
1295 |
|
|
1296 |
undoHistory transactionNamed:'align' do:[
|
|
1297 |
self selectionDo:[:v||delta|
|
|
1298 |
(delta := tmost - (v computeOrigin y)) ~~ 0 ifTrue:[
|
|
1299 |
self shifLayout:v top:delta bottom:delta
|
|
1300 |
]
|
|
1301 |
]
|
|
1302 |
].
|
|
1303 |
self changed:#layout
|
|
1304 |
]
|
|
1305 |
|
|
1306 |
!
|
|
1307 |
|
|
1308 |
alignSelectionTopAndBottom
|
|
1309 |
|tmost bmost|
|
|
1310 |
|
|
1311 |
self selectionHiddenDo:[
|
|
1312 |
tmost := self selectionFindMinimum:[:v| v computeOrigin y].
|
|
1313 |
bmost := 0.
|
|
1314 |
self selectionDo:[:v| bmost := bmost max:(v computeCorner y)].
|
|
1315 |
|
|
1316 |
undoHistory transactionNamed:'align' do:[
|
|
1317 |
self selectionDo:[:v|
|
|
1318 |
self shifLayout:v top:(tmost - (v computeOrigin y))
|
|
1319 |
bottom:(bmost - (v computeCorner y))
|
|
1320 |
]
|
|
1321 |
].
|
|
1322 |
self changed:#layout
|
|
1323 |
]
|
|
1324 |
!
|
|
1325 |
|
|
1326 |
centerSelection:aOneArgBlockXorY
|
|
1327 |
"center selection horizontal or vertical dependant on the block result( x or y).
|
|
1328 |
The argument to the block is the point.
|
|
1329 |
"
|
|
1330 |
|superview min max delta val|
|
|
1331 |
|
|
1332 |
self selectionHiddenDo:[
|
|
1333 |
max := 0.
|
|
1334 |
|
|
1335 |
self selectionDo:[:aView |
|
|
1336 |
superview isNil ifTrue:[
|
|
1337 |
superview := aView superView
|
|
1338 |
] ifFalse:[
|
|
1339 |
(aView superView == superview) ifFalse:[
|
|
1340 |
^ self notify:'views must have same superview'.
|
|
1341 |
]
|
|
1342 |
].
|
|
1343 |
val := aOneArgBlockXorY value:(aView computeOrigin).
|
|
1344 |
|
|
1345 |
min isNil ifTrue:[min := val]
|
|
1346 |
ifFalse:[min := min min:val].
|
|
1347 |
|
|
1348 |
val := aOneArgBlockXorY value:(aView computeCorner).
|
|
1349 |
max := max max:val.
|
|
1350 |
].
|
|
1351 |
|
|
1352 |
val := aOneArgBlockXorY value:(superview computeExtent).
|
|
1353 |
max := (min + val - max) // 2.
|
|
1354 |
|
|
1355 |
max == min ifFalse:[
|
|
1356 |
delta := max - min.
|
|
1357 |
|
|
1358 |
undoHistory transactionNamed:'center' do:[
|
|
1359 |
self selectionDo:[:aView|
|
|
1360 |
self shifLayout:aView top:delta bottom:delta]
|
|
1361 |
]
|
|
1362 |
].
|
|
1363 |
self changed:#layout
|
|
1364 |
]
|
|
1365 |
|
|
1366 |
|
|
1367 |
!
|
|
1368 |
|
|
1369 |
centerSelectionHor
|
|
1370 |
"center selection horizontal
|
|
1371 |
"
|
|
1372 |
self centerSelection:[:aPoint| aPoint x]
|
|
1373 |
|
|
1374 |
|
|
1375 |
!
|
|
1376 |
|
|
1377 |
centerSelectionVer
|
|
1378 |
"center selection vertical
|
|
1379 |
"
|
|
1380 |
self centerSelection:[:aPoint| aPoint y]
|
|
1381 |
!
|
|
1382 |
|
|
1383 |
spreadSelectionHor
|
|
1384 |
|sumWidths min max viewsInOrder topsInOrder count space|
|
|
1385 |
|
|
1386 |
(selection isKindOf:Collection) ifFalse:[^ self].
|
|
1387 |
|
|
1388 |
self selectionHiddenDo:[
|
|
1389 |
count := 0.
|
|
1390 |
sumWidths := 0.
|
|
1391 |
max := 0.
|
|
1392 |
|
|
1393 |
self selectionDo:[:aView |
|
|
1394 |
sumWidths := sumWidths + aView width.
|
|
1395 |
|
|
1396 |
min isNil ifTrue:[min := aView left]
|
|
1397 |
ifFalse:[min := min min:(aView left)].
|
|
1398 |
|
|
1399 |
max := max max:(aView right).
|
|
1400 |
count := count + 1
|
|
1401 |
].
|
|
1402 |
viewsInOrder := Array withAll:selection.
|
|
1403 |
topsInOrder := viewsInOrder collect:[:aView | aView left].
|
|
1404 |
topsInOrder sortWith:viewsInOrder.
|
|
1405 |
|
|
1406 |
space := (((max - min) - sumWidths) / (count - 1)) rounded asInteger.
|
|
1407 |
|
|
1408 |
undoHistory transactionNamed:'spread' do:[
|
|
1409 |
viewsInOrder do:[:aView |
|
|
1410 |
|delta|
|
|
1411 |
|
|
1412 |
delta := min - aView computeOrigin x.
|
|
1413 |
self shifLayout:aView left:delta right:delta.
|
|
1414 |
min := min + aView computeExtent x + space
|
|
1415 |
]
|
|
1416 |
].
|
|
1417 |
self changed:#layout
|
|
1418 |
]
|
|
1419 |
|
|
1420 |
!
|
|
1421 |
|
|
1422 |
spreadSelectionVer
|
|
1423 |
|sumHeights min max viewsInOrder topsInOrder count space|
|
|
1424 |
|
|
1425 |
(selection isKindOf:Collection) ifFalse:[^ self].
|
|
1426 |
|
|
1427 |
self selectionHiddenDo:[
|
|
1428 |
count := 0.
|
|
1429 |
sumHeights := 0.
|
|
1430 |
max := 0.
|
|
1431 |
|
|
1432 |
self selectionDo:[:aView |
|
|
1433 |
sumHeights := sumHeights + aView height.
|
|
1434 |
|
|
1435 |
min isNil ifTrue:[min := aView top]
|
|
1436 |
ifFalse:[min := min min:(aView top)].
|
|
1437 |
|
|
1438 |
max := max max:(aView bottom).
|
|
1439 |
count := count + 1
|
|
1440 |
].
|
|
1441 |
viewsInOrder := Array withAll:selection.
|
|
1442 |
topsInOrder := viewsInOrder collect:[:aView|aView top].
|
|
1443 |
topsInOrder sortWith:viewsInOrder.
|
|
1444 |
|
|
1445 |
space := (((max - min) - sumHeights) / (count - 1)) rounded asInteger.
|
|
1446 |
|
|
1447 |
undoHistory transactionNamed:'spread' do:[
|
|
1448 |
viewsInOrder do:[:aView||delta|
|
|
1449 |
delta := min - aView computeOrigin y.
|
|
1450 |
self shifLayout:aView top:delta bottom:delta.
|
|
1451 |
min := min + aView height + space
|
|
1452 |
]
|
|
1453 |
].
|
|
1454 |
self changed:#layout
|
|
1455 |
]
|
|
1456 |
! !
|
|
1457 |
|
|
1458 |
!UIObjectView methodsFor:'user actions - resize'!
|
|
1459 |
|
|
1460 |
doDragResize:aPoint
|
|
1461 |
"do a widget resize drag"
|
|
1462 |
|
|
1463 |
|p|
|
|
1464 |
|
|
1465 |
self invertOutlineOf:resizedObject.
|
|
1466 |
p := (self alignToGrid:aPoint) - (resizedObject container originRelativeTo:self).
|
|
1467 |
self perform:('x' , resizeSelector , ':') asSymbol with:p.
|
|
1468 |
resizedObject geometryLayout:(resizedObject geometryLayout).
|
|
1469 |
self invertOutlineOf:resizedObject
|
|
1470 |
|
|
1471 |
"Modified: 5.9.1995 / 17:11:46 / claus"
|
|
1472 |
|
|
1473 |
!
|
|
1474 |
|
|
1475 |
endResize
|
|
1476 |
"cleanup after object resize"
|
|
1477 |
|
|
1478 |
self invertOutlineOf:resizedObject.
|
|
1479 |
self setDefaultActions.
|
|
1480 |
self select:resizedObject.
|
|
1481 |
resizedObject := nil
|
|
1482 |
|
|
1483 |
"Modified: 5.9.1995 / 17:11:17 / claus"
|
|
1484 |
|
|
1485 |
!
|
|
1486 |
|
|
1487 |
startResizeBorder:b of:selection at:aPoint
|
|
1488 |
"resize selected view
|
|
1489 |
"
|
|
1490 |
resizedObject := self singleSelection.
|
|
1491 |
|
|
1492 |
resizedObject notNil ifTrue:[
|
|
1493 |
resizeSelector := b.
|
|
1494 |
super unselect.
|
|
1495 |
|
|
1496 |
undoHistory transactionNamed:'extent' do:[
|
|
1497 |
self undoBlockDimensionChanged:resizedObject.
|
|
1498 |
].
|
|
1499 |
|
|
1500 |
motionAction := [:movePoint | self doDragResize:movePoint].
|
|
1501 |
releaseAction := [self endResize].
|
|
1502 |
self invertOutlineOf:resizedObject
|
|
1503 |
]
|
|
1504 |
!
|
|
1505 |
|
|
1506 |
xbottom:aPoint
|
|
1507 |
self resize:resizedObject bottom:aPoint
|
|
1508 |
|
|
1509 |
!
|
|
1510 |
|
|
1511 |
xbottomLeft:aPoint
|
|
1512 |
self resize:resizedObject left:aPoint.
|
|
1513 |
self resize:resizedObject bottom:aPoint.
|
|
1514 |
|
|
1515 |
!
|
|
1516 |
|
|
1517 |
xcorner:aPoint
|
|
1518 |
self resize:resizedObject corner:aPoint.
|
|
1519 |
|
|
1520 |
!
|
|
1521 |
|
|
1522 |
xleft:aPoint
|
|
1523 |
self resize:resizedObject left:aPoint
|
|
1524 |
|
|
1525 |
!
|
|
1526 |
|
|
1527 |
xorigin:aPoint
|
|
1528 |
self resize:resizedObject left:aPoint.
|
|
1529 |
self resize:resizedObject top:aPoint.
|
|
1530 |
|
|
1531 |
!
|
|
1532 |
|
|
1533 |
xright:aPoint
|
|
1534 |
self resize:resizedObject right:aPoint
|
|
1535 |
|
|
1536 |
!
|
|
1537 |
|
|
1538 |
xtop:aPoint
|
|
1539 |
self resize:resizedObject top:aPoint
|
|
1540 |
|
|
1541 |
!
|
|
1542 |
|
|
1543 |
xtopRight:aPoint
|
|
1544 |
self resize:resizedObject right:aPoint.
|
|
1545 |
self resize:resizedObject top:aPoint.
|
|
1546 |
|
|
1547 |
! !
|
|
1548 |
|
47
|
1549 |
!UIObjectView::UndoHistory class methodsFor:'constants'!
|
|
1550 |
|
|
1551 |
maxHistorySize
|
|
1552 |
"returns maximum size of history before removing oldest
|
|
1553 |
record
|
|
1554 |
"
|
|
1555 |
^ 50
|
|
1556 |
|
|
1557 |
|
|
1558 |
! !
|
|
1559 |
|
|
1560 |
!UIObjectView::UndoHistory class methodsFor:'instance creation'!
|
|
1561 |
|
|
1562 |
new
|
|
1563 |
^ self basicNew initialize
|
|
1564 |
|
|
1565 |
|
|
1566 |
! !
|
|
1567 |
|
|
1568 |
!UIObjectView::UndoHistory methodsFor:'accessing'!
|
|
1569 |
|
|
1570 |
modifiedAction:aBlockWithOneArg
|
|
1571 |
"the block is evaluated whenever the history changed; the argument to the
|
|
1572 |
block is the newest transaction identifier retrived from 'openTransaction'
|
|
1573 |
"
|
|
1574 |
modifiedAction := aBlockWithOneArg
|
|
1575 |
|
|
1576 |
|
|
1577 |
! !
|
|
1578 |
|
|
1579 |
!UIObjectView::UndoHistory methodsFor:'initialization'!
|
|
1580 |
|
|
1581 |
initialize
|
|
1582 |
super initialize.
|
|
1583 |
self reinitialize.
|
|
1584 |
|
|
1585 |
|
|
1586 |
!
|
|
1587 |
|
|
1588 |
reinitialize
|
|
1589 |
"reinitialize all attributes
|
|
1590 |
"
|
|
1591 |
history := OrderedCollection new.
|
|
1592 |
transaction := nil.
|
|
1593 |
enabled := true.
|
|
1594 |
|
|
1595 |
|
|
1596 |
! !
|
|
1597 |
|
|
1598 |
!UIObjectView::UndoHistory methodsFor:'notifications'!
|
|
1599 |
|
|
1600 |
modified
|
|
1601 |
"raise notification; history changed
|
|
1602 |
"
|
|
1603 |
modifiedAction notNil ifTrue:[
|
|
1604 |
|what|
|
|
1605 |
|
|
1606 |
history isEmpty ifTrue:[what := nil]
|
|
1607 |
ifFalse:[what := history last first].
|
|
1608 |
|
|
1609 |
modifiedAction value:what
|
|
1610 |
]
|
|
1611 |
|
|
1612 |
|
|
1613 |
! !
|
|
1614 |
|
|
1615 |
!UIObjectView::UndoHistory methodsFor:'testing'!
|
|
1616 |
|
|
1617 |
isEmpty
|
|
1618 |
"returns true if undo history is empty
|
|
1619 |
"
|
|
1620 |
^ history isEmpty
|
|
1621 |
|
|
1622 |
|
|
1623 |
!
|
|
1624 |
|
|
1625 |
isTransactionOpen
|
|
1626 |
^ (enabled and:[transaction notNil])
|
|
1627 |
!
|
|
1628 |
|
|
1629 |
notEmpty
|
|
1630 |
"returns true if undo history is not empty
|
|
1631 |
"
|
|
1632 |
^ history notEmpty
|
|
1633 |
|
|
1634 |
|
|
1635 |
! !
|
|
1636 |
|
|
1637 |
!UIObjectView::UndoHistory methodsFor:'transaction'!
|
|
1638 |
|
|
1639 |
addUndoBlock:anUndoBlock
|
|
1640 |
"undo block to restore changes; add block to current transaction
|
|
1641 |
"
|
|
1642 |
enabled ifTrue:[
|
|
1643 |
transaction isNil ifTrue:[
|
|
1644 |
"no existing transaction
|
|
1645 |
"
|
|
1646 |
self halt
|
|
1647 |
] ifFalse:[
|
|
1648 |
(transaction at:2) add:anUndoBlock
|
|
1649 |
]
|
|
1650 |
]
|
|
1651 |
|
|
1652 |
|
|
1653 |
!
|
|
1654 |
|
|
1655 |
closeTransaction
|
|
1656 |
"close current transaction
|
|
1657 |
"
|
|
1658 |
self isTransactionOpen ifTrue:[
|
|
1659 |
transaction last isEmpty ifTrue:[
|
|
1660 |
"empty undo transaction
|
|
1661 |
"
|
|
1662 |
transaction := nil
|
|
1663 |
] ifFalse:[
|
|
1664 |
history addLast:transaction.
|
|
1665 |
transaction := nil.
|
|
1666 |
|
|
1667 |
history size > (self class maxHistorySize) ifTrue:[
|
|
1668 |
history removeFirst
|
|
1669 |
].
|
|
1670 |
self modified
|
|
1671 |
]
|
|
1672 |
]
|
|
1673 |
|
|
1674 |
|
|
1675 |
!
|
|
1676 |
|
|
1677 |
disabledTransitionDo:aBlock
|
|
1678 |
"disable transitions during evaluating the block
|
|
1679 |
"
|
|
1680 |
|oldState|
|
|
1681 |
|
|
1682 |
oldState := enabled.
|
|
1683 |
enabled := false.
|
|
1684 |
aBlock value.
|
|
1685 |
enabled := oldState.
|
|
1686 |
!
|
|
1687 |
|
|
1688 |
openTransaction:what
|
|
1689 |
"open a new transaction
|
|
1690 |
"
|
|
1691 |
enabled ifTrue:[
|
|
1692 |
transaction notNil ifTrue:[
|
|
1693 |
"transaction within transaction
|
|
1694 |
"
|
|
1695 |
self halt.
|
|
1696 |
] ifFalse:[
|
|
1697 |
transaction := Array with:what with:OrderedCollection new
|
|
1698 |
]
|
|
1699 |
]
|
|
1700 |
|
|
1701 |
!
|
|
1702 |
|
|
1703 |
transactionNamed:what do:aBlock
|
|
1704 |
"open a transaction; perform the block; at least close the transaction
|
|
1705 |
"
|
|
1706 |
self isTransactionOpen ifFalse:[
|
|
1707 |
self openTransaction:what.
|
|
1708 |
aBlock value.
|
|
1709 |
self closeTransaction
|
|
1710 |
] ifTrue:[
|
|
1711 |
aBlock value
|
|
1712 |
]
|
|
1713 |
! !
|
|
1714 |
|
|
1715 |
!UIObjectView::UndoHistory methodsFor:'undo'!
|
|
1716 |
|
|
1717 |
undoLast
|
|
1718 |
"undo last transactions; an open transaction will be closed;
|
|
1719 |
transactions during undo are disabled
|
|
1720 |
"
|
|
1721 |
self undoLast:1
|
|
1722 |
|
|
1723 |
|
|
1724 |
!
|
|
1725 |
|
|
1726 |
undoLast:nTransactions
|
|
1727 |
"undo last n transactions; an open transaction will be closed;
|
|
1728 |
transactions during undo are disabled
|
|
1729 |
"
|
|
1730 |
|actions n|
|
|
1731 |
|
|
1732 |
transaction := nil.
|
|
1733 |
n := nTransactions min:(history size).
|
|
1734 |
|
|
1735 |
n ~~ 0 ifTrue:[
|
|
1736 |
enabled := false.
|
|
1737 |
|
|
1738 |
n timesRepeat:[
|
|
1739 |
actions := (history removeLast) last.
|
|
1740 |
|
|
1741 |
actions reverseDo:[:aUndoBlock|
|
|
1742 |
aUndoBlock value
|
|
1743 |
]
|
|
1744 |
].
|
|
1745 |
enabled := true.
|
|
1746 |
self modified.
|
|
1747 |
]
|
|
1748 |
|
|
1749 |
|
|
1750 |
! !
|
|
1751 |
|
44
|
1752 |
!UIObjectView class methodsFor:'documentation'!
|
|
1753 |
|
|
1754 |
version
|
|
1755 |
^ '$Header$'
|
|
1756 |
! !
|