author | ca |
Wed, 04 Jun 1997 13:31:50 +0200 | |
changeset 138 | 035c98964c38 |
parent 134 | d5ab85ec27fd |
child 140 | 1dde784a73d7 |
permissions | -rw-r--r-- |
60 | 1 |
ObjectView subclass:#UIObjectView |
123 | 2 |
instanceVariableNames:'saveSelection inputView enableChannel undoHistory copiedExtent |
3 |
copiedLayout actionData createClass clipChildren |
|
4 |
selectionHiddenLevel setOfSuperViewsSizeChanged' |
|
60 | 5 |
classVariableNames:'' |
6 |
poolDictionaries:'' |
|
7 |
category:'Interface-UIPainter' |
|
8 |
! |
|
9 |
||
10 |
Object subclass:#UndoHistory |
|
134 | 11 |
instanceVariableNames:'startIdentifier identifier painter history transaction enabled' |
60 | 12 |
classVariableNames:'' |
13 |
poolDictionaries:'' |
|
14 |
privateIn:UIObjectView |
|
15 |
! |
|
16 |
||
54 | 17 |
Object subclass:#Transaction |
134 | 18 |
instanceVariableNames:'identifier type text actions' |
54 | 19 |
classVariableNames:'' |
20 |
poolDictionaries:'' |
|
21 |
privateIn:UIObjectView::UndoHistory |
|
22 |
! |
|
23 |
||
128 | 24 |
!UIObjectView class methodsFor:'documentation'! |
25 |
||
26 |
documentation |
|
27 |
" |
|
131 | 28 |
buildIn view used by the UIPainter; it provides all services for creating, deleting |
29 |
moving and changing layouts of painted components on a canvas. |
|
128 | 30 |
|
31 |
[see also:] |
|
32 |
UIBuilder |
|
33 |
UIPainterView |
|
34 |
" |
|
35 |
||
36 |
! ! |
|
60 | 37 |
|
63 | 38 |
!UIObjectView class methodsFor:'conversion'! |
39 |
||
40 |
asLayoutFrameFromView:aView |
|
41 |
"convert layout from aView to a frameLayout. On success the frameLayout is |
|
42 |
returned otherwise nil |
|
43 |
" |
|
68 | 44 |
|lF lO rF rO tF tO bF bO type layout newLyt| |
45 |
||
46 |
type := self layoutType:aView. |
|
47 |
layout := aView geometryLayout. |
|
48 |
||
91 | 49 |
layout isNil ifTrue:[ |
50 |
type == #Extent ifTrue:[ |
|
51 |
layout := aView bounds asLayout |
|
52 |
] |
|
53 |
]. |
|
54 |
||
68 | 55 |
(type isNil or:[layout isNil]) ifTrue:[ |
63 | 56 |
^ nil |
57 |
]. |
|
58 |
||
68 | 59 |
type == #LayoutFrame ifTrue:[ |
60 |
^ layout copy |
|
61 |
]. |
|
62 |
||
63 |
layout isLayout ifFalse:[ |
|
64 |
type == #Rectangle ifTrue:[ |
|
63 | 65 |
lO := layout left. |
66 |
tO := layout top. |
|
67 |
rO := layout right. |
|
68 |
bO := layout bottom. |
|
69 |
] ifFalse:[ |
|
70 |
lO := layout x. |
|
71 |
tO := layout y. |
|
72 |
rO := lO + aView extent x. |
|
73 |
bO := tO + aView extent y. |
|
74 |
]. |
|
68 | 75 |
|
76 |
^ LayoutFrame leftFraction:0 offset:lO rightFraction:0 offset:rO |
|
77 |
topFraction:0 offset:tO bottomFraction:0 offset:bO |
|
63 | 78 |
]. |
79 |
||
68 | 80 |
lF := layout leftFraction. |
81 |
lO := layout leftOffset. |
|
82 |
tF := layout topFraction. |
|
83 |
tO := layout topOffset. |
|
84 |
bF := tF. |
|
85 |
bO := tO + aView extent y. |
|
86 |
rF := lF. |
|
87 |
rO := lO + aView extent x. |
|
88 |
||
89 |
newLyt := LayoutFrame leftFraction:lF offset:lO rightFraction:rF offset:rO |
|
90 |
topFraction:tF offset:tO bottomFraction:bF offset:bO. |
|
91 |
||
92 |
( (type == #AlignmentOrigin) |
|
93 |
and:[layout leftAlignmentFraction ~~ 0 |
|
94 |
or:[layout topAlignmentFraction ~~ 0]] |
|
95 |
) ifTrue:[ |
|
96 |
|svRc prBd dlta| |
|
97 |
||
98 |
svRc := aView superView viewRectangle. |
|
99 |
prBd := aView preferredBounds. |
|
100 |
dlta := ( ((layout rectangleRelativeTo:svRc preferred:prBd) corner) |
|
101 |
- ((newLyt rectangleRelativeTo:svRc preferred:prBd) corner) |
|
102 |
) rounded. |
|
103 |
||
104 |
newLyt leftOffset:(lO + dlta x). |
|
105 |
newLyt rightOffset:(rO + dlta x). |
|
106 |
newLyt topOffset:(tO + dlta y). |
|
107 |
newLyt bottomOffset:(bO + dlta y). |
|
108 |
]. |
|
109 |
^ newLyt. |
|
91 | 110 |
|
111 |
"Modified: 28.3.1997 / 19:52:48 / cg" |
|
63 | 112 |
! ! |
113 |
||
60 | 114 |
!UIObjectView class methodsFor:'defaults'! |
115 |
||
116 |
defaultGrid |
|
117 |
^ 4 @ 4 |
|
118 |
||
119 |
! |
|
120 |
||
121 |
gridShown |
|
122 |
^ false |
|
123 |
||
124 |
! |
|
125 |
||
126 |
handleSize |
|
127 |
"size of blob drawn for handles" |
|
128 |
^ 4 |
|
129 |
||
130 |
! |
|
131 |
||
132 |
hitDelta |
|
133 |
^ 4 |
|
134 |
||
135 |
! ! |
|
136 |
||
61 | 137 |
!UIObjectView class methodsFor:'queries'! |
138 |
||
139 |
layoutType:aView |
|
140 |
"returns layout type of aView or nil |
|
141 |
" |
|
113 | 142 |
|layout spec superView| |
143 |
||
144 |
aView notNil ifTrue:[ |
|
145 |
layout := aView geometryLayout. |
|
146 |
layout notNil ifTrue:[ |
|
147 |
layout isLayout ifTrue:[ |
|
148 |
layout isLayoutFrame ifTrue:[ ^ #LayoutFrame ]. |
|
149 |
layout isAlignmentOrigin ifTrue:[ ^ #AlignmentOrigin ]. |
|
150 |
layout isLayoutOrigin ifTrue:[ ^ #LayoutOrigin ]. |
|
151 |
] ifFalse:[ |
|
152 |
layout isRectangle ifTrue:[ ^ #Rectangle ]. |
|
153 |
layout isPoint ifTrue:[ ^ #Point ]. |
|
154 |
] |
|
61 | 155 |
] ifFalse:[ |
113 | 156 |
(superView := aView superView) notNil ifTrue:[ |
157 |
spec := superView specClass. |
|
158 |
spec canResizeSubComponents ifTrue:[ |
|
159 |
^ #Extent |
|
160 |
] |
|
161 |
] |
|
61 | 162 |
] |
163 |
]. |
|
164 |
^ nil |
|
165 |
||
67 | 166 |
"Modified: 28.2.1997 / 13:02:16 / cg" |
61 | 167 |
! ! |
168 |
||
60 | 169 |
!UIObjectView methodsFor:'accessing'! |
170 |
||
119 | 171 |
enableChannel |
172 |
"returns the channel which keeps false if running test otherwise true |
|
173 |
" |
|
174 |
^ enableChannel |
|
113 | 175 |
! |
176 |
||
60 | 177 |
gridAlign |
61 | 178 |
"returns state of aligning to grid |
179 |
" |
|
60 | 180 |
^ aligning |
181 |
||
182 |
! |
|
183 |
||
184 |
gridAlign:aBool |
|
61 | 185 |
"change state of aligning to grid |
186 |
" |
|
60 | 187 |
aBool ifTrue:[self alignOn] |
188 |
ifFalse:[self alignOff] |
|
189 |
||
190 |
! |
|
191 |
||
192 |
gridParameters |
|
193 |
"used by defineGrid, and in a separate method for |
|
194 |
easier redefinition in subclasses. |
|
195 |
Returns the grid parameters in an array of 7 elements, |
|
196 |
which control the appearance of the grid-pattern. |
|
197 |
the elements are: |
|
198 |
||
199 |
bigStepH number of pixels horizontally between 2 major steps |
|
200 |
bigStepV number of pixels vertically between 2 major steps |
|
201 |
littleStepH number of pixels horizontally between 2 minor steps |
|
202 |
littleStepV number of pixels vertically between 2 minor steps |
|
203 |
gridAlignH number of pixels for horizontal grid align (pointer snap) |
|
204 |
gridAlignV number of pixels for vertical grid align (pointer snap) |
|
205 |
docBounds true, if document boundary should be shown |
|
206 |
||
207 |
if littleStepH/V are nil, only bigSteps are drawn. |
|
208 |
" |
|
209 |
||
210 |
^ #(10 10 nil nil 10 10 false) |
|
211 |
||
212 |
||
213 |
! |
|
214 |
||
215 |
gridShown:aBool |
|
61 | 216 |
"change visibility of grid |
217 |
" |
|
60 | 218 |
aBool ifTrue:[self showGrid] |
219 |
ifFalse:[self hideGrid] |
|
220 |
! |
|
221 |
||
222 |
hideGrid |
|
61 | 223 |
"hide grid |
224 |
" |
|
60 | 225 |
gridShown ifTrue:[ |
61 | 226 |
self withSelectionHiddenDo:[super hideGrid] |
60 | 227 |
] |
228 |
||
229 |
||
230 |
! |
|
231 |
||
232 |
showGrid |
|
61 | 233 |
"show grid |
234 |
" |
|
235 |
self withSelectionHiddenDo:[super showGrid] |
|
119 | 236 |
! ! |
237 |
||
238 |
!UIObjectView methodsFor:'accessing behavior'! |
|
239 |
||
240 |
enabled |
|
241 |
^ enableChannel value |
|
242 |
! |
|
243 |
||
244 |
enabled:aState |
|
245 |
"set the modification / test mode |
|
246 |
" |
|
247 |
(aState == enableChannel value) ifFalse:[ |
|
123 | 248 |
aState ifFalse:[ |
131 | 249 |
saveSelection := self selection. |
250 |
self select:nil. |
|
128 | 251 |
enableChannel value:aState. |
252 |
inputView unrealize. |
|
119 | 253 |
] ifTrue:[ |
254 |
inputView raise. |
|
123 | 255 |
inputView realize. |
128 | 256 |
enableChannel value:aState. |
123 | 257 |
self select:saveSelection. |
258 |
] |
|
119 | 259 |
] |
260 |
||
261 |
||
262 |
||
60 | 263 |
! |
264 |
||
134 | 265 |
resetModification |
266 |
"set modification state to false |
|
267 |
" |
|
268 |
undoHistory resetModification |
|
269 |
! |
|
270 |
||
60 | 271 |
testMode |
61 | 272 |
"returns true if running test |
60 | 273 |
" |
119 | 274 |
^ enableChannel value not |
60 | 275 |
|
276 |
||
277 |
! |
|
278 |
||
279 |
testMode:aBoolean |
|
61 | 280 |
"change test mode |
60 | 281 |
" |
119 | 282 |
self enabled:(aBoolean not) |
60 | 283 |
! ! |
284 |
||
285 |
!UIObjectView methodsFor:'blocked'! |
|
286 |
||
287 |
addObject:anObject |
|
61 | 288 |
"add the argument, anObject to the contents - with redraw |
289 |
" |
|
60 | 290 |
self halt |
291 |
||
292 |
! |
|
293 |
||
294 |
addObjectWithoutRedraw:anObject |
|
61 | 295 |
"add the argument, anObject to the contents - with redraw |
296 |
" |
|
60 | 297 |
self halt |
298 |
||
299 |
! ! |
|
300 |
||
301 |
!UIObjectView methodsFor:'event handling'! |
|
302 |
||
61 | 303 |
elementChangedSize:aView |
304 |
"some element has changed its size; collect them during selectionHiddenLevel |
|
305 |
is on |
|
306 |
" |
|
307 |
selectionHiddenLevel ~~ 0 ifTrue:[ |
|
308 |
setOfSuperViewsSizeChanged add:aView superView |
|
309 |
] ifFalse:[ |
|
310 |
aView superView sizeChanged:nil |
|
311 |
] |
|
60 | 312 |
! |
313 |
||
314 |
exposeX:x y:y width:w height:h |
|
315 |
"handle an expose event from device; redraw selection |
|
316 |
" |
|
317 |
super exposeX:x y:y width:w height:h. |
|
132 | 318 |
|
319 |
" |
|
320 |
catch expose events for all subviews associated with |
|
321 |
a selected instance |
|
322 |
" |
|
323 |
||
138 | 324 |
"/ handle any expose events (for subcomponents) before |
325 |
"/ redrawing the handles. |
|
326 |
(self sensor hasExposeEventFor:nil) ifTrue:[^ self]. |
|
327 |
||
132 | 328 |
self selectionDo:[:aComponent | |
329 |
aComponent withAllSubViewsDo:[:v | |
|
330 |
self sensor flushExposeEventsFor:v. |
|
331 |
v exposeX:0 y:0 width:9999 height:9999. |
|
332 |
]. |
|
333 |
||
334 |
self showSelected:aComponent |
|
335 |
] |
|
60 | 336 |
|
337 |
! |
|
338 |
||
339 |
keyPress:key x:x y:y |
|
61 | 340 |
"any key pressed |
341 |
" |
|
78 | 342 |
<resource: #keyboard ( #Delete #BackSpace #Cut #Copy #Paste ) > |
60 | 343 |
|
344 |
(key == #Cut or:[key == #Delete or:[key == #BackSpace]]) ifTrue: [ |
|
345 |
^ self deleteSelection |
|
346 |
]. |
|
347 |
||
78 | 348 |
key == #Copy ifTrue:[ ^ self copySelection]. |
349 |
key == #Paste ifTrue:[ ^ self pasteBuffer]. |
|
60 | 350 |
! |
351 |
||
352 |
processEvent:anEvent |
|
353 |
"catch expose events for components, and redraw its handles after |
|
354 |
the redraw when this happens |
|
355 |
" |
|
128 | 356 |
(anEvent type == #damage and:[self isSelected:(anEvent view)]) ifTrue:[ |
357 |
self showSelected:(anEvent view) |
|
60 | 358 |
]. |
359 |
^ false. |
|
360 |
||
361 |
||
362 |
! |
|
363 |
||
364 |
sizeChanged:how |
|
61 | 365 |
"size of a view(s) changed |
366 |
" |
|
60 | 367 |
self withSelectionHiddenDo:[ |
368 |
super sizeChanged:how |
|
369 |
] |
|
370 |
||
371 |
||
372 |
! ! |
|
373 |
||
374 |
!UIObjectView methodsFor:'initialization'! |
|
375 |
||
376 |
initialize |
|
61 | 377 |
"setup attributes |
378 |
" |
|
60 | 379 |
super initialize. |
380 |
||
381 |
"funny: since I do not want the created widgets to get pointer |
|
382 |
events, I put an InputView on top of them, which catches those events |
|
383 |
and passes them back to me - have to take care, that this inputView |
|
384 |
is always on top |
|
385 |
" |
|
386 |
inputView := InputView origin:0.0@0.0 extent:1.0@1.0 in:self. |
|
61 | 387 |
setOfSuperViewsSizeChanged := IdentitySet new. |
60 | 388 |
|
389 |
inputView eventReceiver:self. |
|
390 |
inputView enableButtonEvents. |
|
391 |
inputView enableButtonMotionEvents. |
|
392 |
||
393 |
self setDefaultActions. |
|
394 |
||
134 | 395 |
undoHistory := UndoHistory on:self. |
119 | 396 |
enableChannel := true asValue. |
397 |
clipChildren := true. |
|
61 | 398 |
selectionHiddenLevel := 0. |
60 | 399 |
|
400 |
(self class gridShown) ifTrue:[ |
|
401 |
super showGrid |
|
402 |
]. |
|
403 |
||
404 |
! |
|
405 |
||
406 |
realize |
|
407 |
super realize. |
|
408 |
self windowGroup postEventHook:self |
|
409 |
||
410 |
! ! |
|
411 |
||
412 |
!UIObjectView methodsFor:'misc'! |
|
413 |
||
414 |
cursor:aCursor |
|
61 | 415 |
"set cursor |
416 |
" |
|
60 | 417 |
inputView realized ifTrue:[ |
418 |
inputView cursor:aCursor |
|
419 |
]. |
|
420 |
super cursor:aCursor |
|
421 |
||
422 |
||
423 |
! |
|
424 |
||
425 |
invertOutlineOf:anObject |
|
61 | 426 |
"invert outline of an object |
427 |
" |
|
60 | 428 |
|wasClipped delta| |
429 |
||
430 |
(wasClipped := clipChildren) ifTrue:[ |
|
431 |
self clippedByChildren:(clipChildren := false). |
|
432 |
]. |
|
433 |
delta := (anObject originRelativeTo:self) - anObject origin. |
|
434 |
||
435 |
self xoring:[ |
|
436 |
self displayRectangle:((anObject origin + delta) extent:anObject extent). |
|
437 |
]. |
|
438 |
||
439 |
wasClipped ifTrue:[ |
|
440 |
self clippedByChildren:(clipChildren := true). |
|
441 |
]. |
|
442 |
||
443 |
"Modified: 5.9.1995 / 12:25:25 / claus" |
|
444 |
||
445 |
||
446 |
! |
|
447 |
||
78 | 448 |
minSetOfSuperViews:setOfViews |
449 |
||
450 |
setOfViews isCollection ifFalse:[ |
|
451 |
setOfViews notNil ifTrue:[^ Array with:setOfViews] |
|
452 |
ifFalse:[^ nil] |
|
72 | 453 |
]. |
454 |
||
78 | 455 |
^ setOfViews select:[:aView| |
456 |
(setOfViews detect:[:v|aView isComponentOf:v] ifNone:nil) isNil |
|
457 |
] |
|
72 | 458 |
! |
459 |
||
60 | 460 |
setDefaultActions |
61 | 461 |
"set default actions |
462 |
" |
|
60 | 463 |
pressAction := [:pressPoint | self startSelectOrMove:pressPoint]. |
464 |
shiftPressAction := [:pressPoint | self startSelectMoreOrMove:pressPoint]. |
|
465 |
motionAction := [:movePoint | nil]. |
|
466 |
releaseAction := [nil]. |
|
467 |
keyPressAction := nil. |
|
468 |
||
469 |
self cursor:Cursor normal. |
|
470 |
||
471 |
! ! |
|
472 |
||
473 |
!UIObjectView methodsFor:'object creation'! |
|
474 |
||
475 |
actionCreate:anObject frame:aFrame delta:aDelta |
|
476 |
"create and initialize action data |
|
477 |
" |
|
478 |
|extent x y selectors values| |
|
479 |
||
480 |
"minimum extent |
|
481 |
" |
|
82 | 482 |
(anObject specClass supportsSubComponents) ifTrue:[ |
84 | 483 |
extent := 25@25 |
82 | 484 |
] ifFalse:[ |
485 |
extent := self extent. |
|
486 |
x := extent x // 3. |
|
487 |
y := extent y // 3. |
|
488 |
extent := anObject preferredExtent. |
|
489 |
||
490 |
(extent x > x) ifTrue:[extent x:x]. |
|
491 |
(extent y > y) ifTrue:[extent y:y]. |
|
492 |
]. |
|
60 | 493 |
|
494 |
"setup structure |
|
495 |
" |
|
496 |
selectors := #( object frame delta vertical horizontal minExtent ). |
|
497 |
values := Array new:(selectors size). |
|
498 |
||
499 |
values at:1 put:anObject. |
|
500 |
values at:2 put:aFrame. |
|
501 |
values at:3 put:aDelta. |
|
502 |
values at:4 put:(self isVerticalResizable:anObject). |
|
503 |
values at:5 put:(self isHorizontalResizable:anObject). |
|
504 |
values at:6 put:extent. |
|
505 |
||
506 |
actionData := Structure newWith:selectors values:values. |
|
507 |
||
508 |
||
509 |
"can change cursor dependent on vertical/horizontal resizing |
|
510 |
" |
|
511 |
oldCursor := cursor. |
|
512 |
self cursor:(Cursor leftHand). |
|
513 |
||
514 |
||
515 |
||
516 |
! |
|
517 |
||
518 |
createWidgetWithClass:aClass |
|
519 |
"prepare to create new widgets |
|
520 |
" |
|
89 | 521 |
aClass notNil ifTrue:[ |
522 |
createClass := aClass. |
|
523 |
pressAction := [:aPoint| self startCreate:aPoint]. |
|
524 |
self cursor:Cursor origin. |
|
525 |
] |
|
60 | 526 |
|
527 |
! |
|
528 |
||
529 |
doDragCreate:aPoint |
|
530 |
"do a widget create drag |
|
531 |
" |
|
532 |
|frame object extent minimum| |
|
533 |
||
534 |
frame := actionData frame. |
|
535 |
frame corner:((self alignToGrid:aPoint) - (actionData delta)). |
|
536 |
||
537 |
object := actionData object. |
|
538 |
minimum := actionData minExtent. |
|
539 |
extent := frame extent. |
|
540 |
||
541 |
((extent x < minimum x) or:[actionData horizontal not]) ifTrue:[ |
|
542 |
extent x:(minimum x) |
|
543 |
]. |
|
544 |
||
545 |
((extent y < minimum y) or:[actionData vertical not]) ifTrue:[ |
|
546 |
extent y:(minimum y) |
|
547 |
]. |
|
548 |
||
549 |
frame extent:extent. |
|
550 |
||
551 |
self invertOutlineOf:object. |
|
552 |
object origin:(frame origin) extent:(frame extent). |
|
553 |
self invertOutlineOf:object. |
|
554 |
! |
|
555 |
||
556 |
endCreate |
|
557 |
"end a widget create drag |
|
558 |
" |
|
89 | 559 |
|object specClass| |
60 | 560 |
|
561 |
object := actionData object. |
|
562 |
self invertOutlineOf:object. |
|
563 |
inputView raise. |
|
564 |
||
89 | 565 |
self setupInitialLayoutFor:object. |
60 | 566 |
self select:object. |
567 |
actionData := nil. |
|
568 |
||
569 |
self setDefaultActions. |
|
570 |
||
571 |
! |
|
572 |
||
78 | 573 |
initializeCreatedObject:anObject |
60 | 574 |
self subclassResponsibility |
575 |
! |
|
576 |
||
89 | 577 |
setupInitialLayoutFor:anObject |
578 |
"setup initial layout for an object; !!!! some kludge !!!! |
|
579 |
" |
|
580 |
|spec topSpec| |
|
581 |
||
582 |
topSpec := anObject superView specClass basicNew. |
|
583 |
||
584 |
topSpec class isLayoutContainer ifFalse:[ |
|
585 |
||
586 |
"/ ... KLUDGE .... |
|
587 |
||
588 |
spec := anObject specClass. |
|
589 |
||
590 |
( spec == ViewSpec |
|
591 |
or:[spec == SubCanvasSpec |
|
592 |
or:[spec == TextEditorSpec |
|
593 |
or:[spec == SequenceViewSpec]]] |
|
594 |
) ifTrue:[ |
|
595 |
anObject geometryLayout:(anObject bounds asLayout). |
|
596 |
^ self |
|
597 |
] |
|
598 |
]. |
|
599 |
topSpec setupInitialLayoutFor:anObject. |
|
600 |
||
601 |
! |
|
602 |
||
60 | 603 |
startCreate:aPoint |
604 |
"start a widget create |
|
605 |
" |
|
606 |
|widget object start frame delta| |
|
607 |
||
131 | 608 |
self select:nil. |
89 | 609 |
widget := self findContainerViewAt:aPoint. |
60 | 610 |
|
611 |
motionAction := [:movePoint| self doDragCreate:movePoint]. |
|
612 |
releaseAction := [ self endCreate]. |
|
613 |
||
614 |
object := createClass new. |
|
76 | 615 |
(widget isKindOf:ScrollableView) ifTrue:[ |
616 |
widget scrolledView:object |
|
617 |
] ifFalse:[ |
|
618 |
widget addSubView:object. |
|
619 |
]. |
|
60 | 620 |
|
621 |
start := self alignToGrid:aPoint. |
|
622 |
delta := widget originRelativeTo:self. |
|
623 |
frame := Rectangle origin:(start - delta) corner:start. |
|
624 |
||
625 |
object origin:(frame origin). |
|
78 | 626 |
self initializeCreatedObject:object. |
82 | 627 |
self actionCreate:object frame:frame delta:delta. |
628 |
object extent:(actionData minExtent). |
|
60 | 629 |
object realize. |
630 |
self invertOutlineOf:object. |
|
631 |
! ! |
|
632 |
||
633 |
!UIObjectView methodsFor:'object moving'! |
|
634 |
||
635 |
doObjectMove:aPoint |
|
636 |
"move selection |
|
637 |
" |
|
638 |
movedObject notNil ifTrue:[ |
|
639 |
movedObject keysAndValuesDo:[:nr :aView| |
|
640 |
self invertOutlineOf:aView. |
|
641 |
self moveObject:aView to:(aPoint - (moveDelta at:nr)). |
|
642 |
self invertOutlineOf:aView. |
|
643 |
] |
|
644 |
] |
|
645 |
||
646 |
! |
|
647 |
||
648 |
endObjectMove |
|
61 | 649 |
"cleanup after object(s) move |
650 |
" |
|
60 | 651 |
movedObject notNil ifTrue:[ |
128 | 652 |
movedObject do:[:aView|self invertOutlineOf:aView]. |
653 |
||
654 |
movedObject size == 1 ifTrue:[ |
|
655 |
movedObject := movedObject first |
|
60 | 656 |
]. |
128 | 657 |
|
658 |
self setSelection:movedObject withRedraw:true. |
|
60 | 659 |
movedObject := nil. |
660 |
self setDefaultActions. |
|
661 |
self changed:#layout. |
|
662 |
]. |
|
663 |
! |
|
664 |
||
665 |
moveObject:anObject to:aPoint |
|
666 |
"move anObject to newOrigin, aPoint |
|
667 |
" |
|
668 |
|dX dY org delta| |
|
669 |
||
670 |
anObject notNil ifTrue:[ |
|
671 |
org := anObject computeOrigin. |
|
672 |
||
673 |
delta := aPoint - org. |
|
674 |
delta := (self alignToGrid:aPoint) - org. |
|
675 |
dX := delta x. |
|
676 |
dY := delta y. |
|
677 |
||
134 | 678 |
undoHistory withoutTransactionDo:[ |
60 | 679 |
self shiftLayout:anObject top:dY bottom:dY left:dX right:dX |
680 |
] |
|
681 |
] |
|
682 |
||
683 |
! |
|
684 |
||
685 |
startObjectMoveAt:aPoint |
|
61 | 686 |
"start object(s) move at a point |
687 |
" |
|
128 | 688 |
self startObjectMove:(self selection) at:aPoint. |
689 |
movedObject := self selection. |
|
690 |
||
691 |
movedObject isCollection ifFalse:[ |
|
692 |
movedObject := Array with:movedObject |
|
60 | 693 |
]. |
128 | 694 |
self setSelection:nil withRedraw:true. |
60 | 695 |
|
696 |
moveDelta := movedObject collect:[:aView| |
|
697 |
aPoint - aView computeOrigin |
|
698 |
]. |
|
699 |
||
700 |
self transaction:#move objects:movedObject do:[:aView| |
|
701 |
self invertOutlineOf:aView. |
|
134 | 702 |
self createUndoLayout:aView |
60 | 703 |
]. |
704 |
||
705 |
! |
|
706 |
||
707 |
startSelectMoreOrMove:aPoint |
|
708 |
"add/remove to/from selection" |
|
709 |
||
710 |
|anObject| |
|
711 |
||
119 | 712 |
self enabled ifFalse:[^ self]. |
60 | 713 |
|
714 |
anObject := self findObjectAt:aPoint. |
|
715 |
anObject notNil ifTrue:[ |
|
716 |
(self isSelected:anObject) ifTrue:[ |
|
717 |
self removeFromSelection:anObject |
|
718 |
] ifFalse:[ |
|
719 |
self addToSelection:anObject |
|
720 |
] |
|
721 |
] |
|
722 |
! |
|
723 |
||
724 |
startSelectOrMove:aPoint |
|
61 | 725 |
"a button is pressed at a point; start moving or selection |
60 | 726 |
" |
61 | 727 |
|aView b| |
60 | 728 |
|
119 | 729 |
self enabled ifFalse:[^ self]. |
60 | 730 |
|
61 | 731 |
aView := self singleSelection. |
732 |
||
733 |
aView notNil ifTrue:[ |
|
734 |
(aView superView specClass canResizeSubComponents) ifTrue:[ |
|
735 |
b := self whichHandleOf:aView isHitBy:aPoint. |
|
736 |
||
737 |
(b notNil and:[b ~~ #view]) ifTrue:[ |
|
738 |
^ self startResizeBorder:b of:aView. |
|
739 |
] |
|
100 | 740 |
]. |
741 |
||
742 |
(self sensor ctrlDown and:[self canMove:aView]) ifFalse:[ |
|
743 |
aView := nil |
|
60 | 744 |
] |
745 |
]. |
|
746 |
||
100 | 747 |
aView isNil ifTrue:[ |
748 |
(aView := self findObjectAt:aPoint) isNil ifTrue:[ |
|
131 | 749 |
^ self select:nil |
100 | 750 |
]. |
751 |
||
752 |
(self canMove:aView) ifFalse:[ |
|
128 | 753 |
^ self select:aView |
100 | 754 |
] |
61 | 755 |
]. |
756 |
||
757 |
(self isSelected:aView) ifFalse:[ |
|
758 |
self select:aView. |
|
60 | 759 |
]. |
760 |
||
761 |
(self numberOfSelections ~~ 1) ifTrue:[ |
|
762 |
releaseAction := [ |
|
763 |
self setDefaultActions. |
|
61 | 764 |
self select:aView |
60 | 765 |
] |
766 |
] ifFalse:[ |
|
767 |
releaseAction := [self setDefaultActions] |
|
768 |
]. |
|
769 |
||
770 |
"prepare move operation for an object |
|
771 |
" |
|
61 | 772 |
|
60 | 773 |
motionAction := [:movePoint| |
72 | 774 |
(aPoint dist:movePoint) > 8.0 ifTrue:[ |
60 | 775 |
self startObjectMoveAt:aPoint |
776 |
] |
|
777 |
]. |
|
778 |
! ! |
|
779 |
||
780 |
!UIObjectView methodsFor:'object resize'! |
|
781 |
||
782 |
actionResize:anObject selector:aSelector |
|
783 |
"create and initialize action for resize |
|
784 |
" |
|
785 |
|selector delta| |
|
786 |
||
787 |
delta := anObject container originRelativeTo:self. |
|
788 |
selector := ('resize:', aSelector, ':') asSymbol. |
|
789 |
||
790 |
actionData := Structure with:(#object->anObject) |
|
791 |
with:(#selector->selector) |
|
792 |
with:(#delta->delta). |
|
793 |
||
794 |
"can change cursor dependent on vertical/horizontal resizing |
|
795 |
" |
|
796 |
oldCursor := cursor. |
|
797 |
self cursor:(Cursor leftHand). |
|
798 |
||
799 |
||
800 |
||
801 |
! |
|
802 |
||
803 |
doDragResize:aPoint |
|
61 | 804 |
"do a widget resize drag |
805 |
" |
|
60 | 806 |
|p object| |
807 |
||
808 |
object := actionData object. |
|
809 |
||
810 |
self invertOutlineOf:object. |
|
811 |
p := (self alignToGrid:aPoint) - (actionData delta). |
|
79 | 812 |
|
60 | 813 |
self perform:(actionData selector) with:object with:p. |
79 | 814 |
"/ object geometryLayout:(object geometryLayout). |
60 | 815 |
self invertOutlineOf:object |
816 |
||
817 |
! |
|
818 |
||
819 |
endResize |
|
61 | 820 |
"cleanup after object resize |
821 |
" |
|
822 |
|object| |
|
823 |
||
824 |
object := actionData object. |
|
825 |
actionData := nil. |
|
826 |
||
827 |
self invertOutlineOf:object. |
|
60 | 828 |
self setDefaultActions. |
61 | 829 |
self elementChangedSize:object. |
138 | 830 |
|
831 |
"/ handle any expose events (for subcomponents) before |
|
832 |
"/ redrawing the handles. |
|
833 |
Delay waitForSeconds:0.05. |
|
834 |
[self sensor hasExposeEventFor:nil] whileTrue:[ |
|
835 |
self windowGroup processExposeEvents |
|
836 |
]. |
|
837 |
||
128 | 838 |
self setSelection:object withRedraw:true. |
60 | 839 |
self changed:#layout. |
840 |
! |
|
841 |
||
842 |
startResizeBorder:b of:selection |
|
843 |
"resize selected view |
|
844 |
" |
|
845 |
|object| |
|
846 |
||
847 |
object := self singleSelection. |
|
848 |
self actionResize:object selector:b. |
|
849 |
||
72 | 850 |
self transaction:#resize selectionDo:[:aView| |
134 | 851 |
self createUndoLayout:aView |
60 | 852 |
]. |
128 | 853 |
self setSelection:nil withRedraw:true. |
60 | 854 |
|
855 |
motionAction := [:movePoint | self doDragResize:movePoint]. |
|
856 |
releaseAction := [self endResize]. |
|
857 |
self invertOutlineOf:object |
|
858 |
! ! |
|
859 |
||
860 |
!UIObjectView methodsFor:'private handles'! |
|
861 |
||
61 | 862 |
handlesOf:aView do:aBlock |
863 |
|dlta type v h| |
|
864 |
||
865 |
dlta := (aView originRelativeTo:self) - aView origin. |
|
866 |
type := self class layoutType:aView. |
|
867 |
||
868 |
(type == #LayoutFrame or:[type == #Rectangle]) ifTrue:[ |
|
869 |
v := self isVerticalResizable:aView. |
|
870 |
h := self isHorizontalResizable:aView. |
|
871 |
||
872 |
h ifTrue:[ aBlock value:(aView leftCenter + dlta) value:#left. |
|
873 |
aBlock value:(aView rightCenter + dlta) value:#right. |
|
874 |
]. |
|
875 |
v ifTrue:[ aBlock value:(aView topCenter + dlta) value:#top. |
|
876 |
aBlock value:(aView bottomCenter + dlta) value:#bottom. |
|
877 |
]. |
|
878 |
||
879 |
(h and:[v]) ifTrue:[ |
|
880 |
aBlock value:(aView origin + dlta) value:#origin. |
|
881 |
aBlock value:(aView topRight + dlta) value:#topRight. |
|
882 |
aBlock value:(aView bottomLeft + dlta) value:#bottomLeft. |
|
883 |
aBlock value:(aView corner + dlta) value:#corner. |
|
884 |
^ self |
|
885 |
] |
|
60 | 886 |
]. |
887 |
||
61 | 888 |
aBlock value:(aView origin + dlta) value:#view. |
889 |
aBlock value:(aView topRight + dlta) value:#view. |
|
890 |
aBlock value:(aView bottomLeft + dlta) value:#view. |
|
891 |
||
892 |
type == #Extent ifTrue:[ |
|
893 |
v := self isVerticalResizable:aView. |
|
894 |
h := self isHorizontalResizable:aView. |
|
895 |
||
896 |
v ifTrue:[aBlock value:(aView bottomCenter + dlta) value:#bottom]. |
|
897 |
h ifTrue:[aBlock value:(aView rightCenter + dlta) value:#right ]. |
|
898 |
||
899 |
(h and:[v]) ifTrue:[ |
|
900 |
aBlock value:(aView corner + dlta) value:#corner. |
|
901 |
^ self |
|
902 |
] |
|
60 | 903 |
]. |
61 | 904 |
aBlock value:(aView corner + dlta) value:#view. |
60 | 905 |
! |
906 |
||
907 |
showSelected:aComponent |
|
61 | 908 |
"show object selected |
909 |
" |
|
132 | 910 |
|wasClipped delta| |
60 | 911 |
|
138 | 912 |
selectionHiddenLevel ~~ 0 ifTrue:[^ self]. |
913 |
||
60 | 914 |
self paint:Color black. |
915 |
||
916 |
(wasClipped := clipChildren) ifTrue:[ |
|
917 |
self clippedByChildren:(clipChildren := false). |
|
918 |
]. |
|
919 |
||
920 |
self handlesOf:aComponent do:[:pnt :what | |
|
921 |
what == #view ifTrue:[self displayRectangle:(pnt - (4@4) extent:7@7)] |
|
922 |
ifFalse:[self fillRectangle:(pnt - (4@4) extent:7@7)] |
|
923 |
]. |
|
924 |
||
925 |
wasClipped ifTrue:[ |
|
926 |
self clippedByChildren:(clipChildren := true). |
|
927 |
]. |
|
132 | 928 |
|
60 | 929 |
! |
930 |
||
931 |
showUnselected:aComponent |
|
61 | 932 |
"show object unselected |
933 |
" |
|
132 | 934 |
|wasClipped delta r| |
60 | 935 |
|
138 | 936 |
selectionHiddenLevel ~~ 0 ifTrue:[^ self]. |
937 |
||
60 | 938 |
(wasClipped := clipChildren) ifTrue:[ |
939 |
self clippedByChildren:(clipChildren := false). |
|
940 |
]. |
|
941 |
||
942 |
self handlesOf:aComponent do:[:pnt :what | |
|
943 |
self clearRectangle:(pnt - (4@4) extent:7@7). |
|
944 |
]. |
|
945 |
||
946 |
wasClipped ifTrue:[ |
|
947 |
self clippedByChildren:(clipChildren := true). |
|
948 |
]. |
|
949 |
||
950 |
"/ must redraw all components which are affected b the handles |
|
951 |
||
952 |
r := (aComponent originRelativeTo:self) - (4@4) |
|
953 |
extent:(aComponent extent + (4@4)). |
|
954 |
||
955 |
subViews do:[:anotherComponent | |
|
956 |
|absOrg absFrame| |
|
957 |
||
958 |
anotherComponent ~~ inputView ifTrue:[ |
|
959 |
absOrg := anotherComponent originRelativeTo:self. |
|
960 |
absFrame := absOrg extent:(anotherComponent extent). |
|
961 |
(absFrame intersects:r) ifTrue:[ |
|
962 |
anotherComponent withAllSubViewsDo:[:v | |
|
95 | 963 |
v shown ifTrue:[ |
132 | 964 |
v fill:v viewBackground. |
95 | 965 |
v exposeX:0 y:0 width:9999 height:9999. |
966 |
] |
|
60 | 967 |
] |
968 |
] |
|
969 |
] |
|
970 |
] |
|
971 |
||
95 | 972 |
"Modified: 8.4.1997 / 00:32:26 / cg" |
60 | 973 |
! |
974 |
||
975 |
whichHandleOf:aView isHitBy:aPoint |
|
61 | 976 |
"returns kind of handle or nil |
977 |
" |
|
60 | 978 |
|bounds| |
979 |
||
980 |
self handlesOf:aView do:[:pnt :what | |
|
981 |
((pnt - (4@4) extent:7@7) containsPoint:aPoint) ifTrue:[ |
|
982 |
^ what |
|
983 |
]. |
|
984 |
]. |
|
985 |
||
986 |
^ nil |
|
987 |
||
988 |
"Modified: 5.9.1995 / 14:39:34 / claus" |
|
989 |
||
990 |
! ! |
|
991 |
||
992 |
!UIObjectView methodsFor:'private resizing-subviews'! |
|
993 |
||
994 |
resize:aView bottom:aPoint |
|
61 | 995 |
"resize a views bottom |
996 |
" |
|
134 | 997 |
undoHistory withoutTransactionDo:[ |
60 | 998 |
self shiftLayout:aView top:0 bottom:((aPoint y) - (aView computeCorner y)) |
999 |
] |
|
1000 |
! |
|
1001 |
||
1002 |
resize:aView bottomLeft:aPoint |
|
61 | 1003 |
"resize a views bottom and left |
1004 |
" |
|
134 | 1005 |
undoHistory withoutTransactionDo:[ |
60 | 1006 |
self shiftLayout:aView top:0 |
1007 |
bottom:((aPoint y) - (aView computeCorner y)) |
|
1008 |
left:((aPoint x) - (aView computeOrigin x)) |
|
1009 |
right:0 |
|
1010 |
||
1011 |
] |
|
1012 |
||
1013 |
||
1014 |
! |
|
1015 |
||
1016 |
resize:aView corner:aPoint |
|
61 | 1017 |
"resize a views corner |
1018 |
" |
|
60 | 1019 |
|delta| |
1020 |
||
1021 |
delta := aPoint - aView computeCorner. |
|
1022 |
||
134 | 1023 |
undoHistory withoutTransactionDo:[ |
60 | 1024 |
self shiftLayout:aView top:0 bottom:(delta y) left:0 right:(delta x) |
1025 |
] |
|
1026 |
! |
|
1027 |
||
1028 |
resize:aView left:aPoint |
|
61 | 1029 |
"resize a views left |
1030 |
" |
|
134 | 1031 |
undoHistory withoutTransactionDo:[ |
60 | 1032 |
self shiftLayout:aView left:((aPoint x) - (aView computeOrigin x)) right:0 |
1033 |
] |
|
1034 |
||
1035 |
! |
|
1036 |
||
1037 |
resize:aView origin:aPoint |
|
61 | 1038 |
"resize a views origin |
1039 |
" |
|
60 | 1040 |
|delta| |
1041 |
||
1042 |
delta := aPoint - aView computeOrigin. |
|
1043 |
||
134 | 1044 |
undoHistory withoutTransactionDo:[ |
60 | 1045 |
self shiftLayout:aView top:(delta y) bottom:0 left:(delta x) right:0 |
1046 |
] |
|
1047 |
||
1048 |
! |
|
1049 |
||
1050 |
resize:aView right:aPoint |
|
61 | 1051 |
"resize a views right |
1052 |
" |
|
134 | 1053 |
undoHistory withoutTransactionDo:[ |
60 | 1054 |
self shiftLayout:aView left:0 right:((aPoint x) - (aView computeCorner x)) |
1055 |
] |
|
1056 |
! |
|
1057 |
||
1058 |
resize:aView top:aPoint |
|
61 | 1059 |
"resize a views top |
1060 |
" |
|
134 | 1061 |
undoHistory withoutTransactionDo:[ |
60 | 1062 |
self shiftLayout:aView top:((aPoint y) - (aView computeOrigin y)) bottom:0 |
1063 |
] |
|
1064 |
! |
|
1065 |
||
1066 |
resize:aView topRight:aPoint |
|
61 | 1067 |
"resize a views top and right |
1068 |
" |
|
134 | 1069 |
undoHistory withoutTransactionDo:[ |
60 | 1070 |
self shiftLayout:aView top:((aPoint y) - (aView computeOrigin y)) |
1071 |
bottom:0 |
|
1072 |
left:0 |
|
1073 |
right:((aPoint x) - (aView computeCorner x)) |
|
1074 |
||
1075 |
] |
|
1076 |
||
1077 |
! ! |
|
1078 |
||
1079 |
!UIObjectView methodsFor:'private shift-layout'! |
|
1080 |
||
1081 |
shiftLayout:aView left:l right:r |
|
1082 |
"shift layout for a view; in case of an open transaction, the undo |
|
1083 |
action is registered |
|
1084 |
" |
|
1085 |
self shiftLayout:aView top:0 bottom:0 left:l right:r |
|
1086 |
||
1087 |
! |
|
1088 |
||
1089 |
shiftLayout:aView top:t bottom:b |
|
1090 |
"shift layout for a view; in case of an open transaction, the undo |
|
1091 |
action is registered |
|
1092 |
" |
|
1093 |
self shiftLayout:aView top:t bottom:b left:0 right:0 |
|
1094 |
||
1095 |
||
1096 |
! |
|
1097 |
||
1098 |
shiftLayout:aView top:t bottom:b left:l right:r |
|
1099 |
"shift layout for a view; in case of an open transaction, the undo |
|
1100 |
action is registered |
|
1101 |
" |
|
79 | 1102 |
|type layout oldExt| |
61 | 1103 |
|
1104 |
type := self class layoutType:aView. |
|
1105 |
||
1106 |
type notNil ifTrue:[ |
|
134 | 1107 |
self createUndoLayout:aView. |
61 | 1108 |
|
1109 |
type == #Extent ifTrue:[ |
|
79 | 1110 |
oldExt := aView extent. |
1111 |
aView extent:(oldExt + ((r-l) @ (b-t))). |
|
1112 |
^ self |
|
60 | 1113 |
]. |
61 | 1114 |
|
78 | 1115 |
layout := aView geometryLayout copy. |
61 | 1116 |
|
1117 |
layout isLayout ifTrue:[ |
|
1118 |
layout leftOffset:(layout leftOffset + l) |
|
1119 |
topOffset:(layout topOffset + t). |
|
1120 |
||
1121 |
type == #LayoutFrame ifTrue:[ |
|
1122 |
layout bottomOffset:(layout bottomOffset + b). |
|
1123 |
layout rightOffset:(layout rightOffset + r). |
|
1124 |
] |
|
1125 |
] ifFalse:[ |
|
1126 |
type == #Rectangle ifTrue:[ |
|
1127 |
layout left:(layout left + l) |
|
1128 |
right:(layout right + r) |
|
1129 |
top:(layout top + t) |
|
1130 |
bottom:(layout bottom + b). |
|
1131 |
] ifFalse:[ "POINT" |
|
1132 |
layout x:(layout x + l) y:(layout y + t). |
|
1133 |
] |
|
1134 |
]. |
|
1135 |
aView geometryLayout:layout |
|
60 | 1136 |
] |
1137 |
! ! |
|
1138 |
||
1139 |
!UIObjectView methodsFor:'searching'! |
|
1140 |
||
89 | 1141 |
findContainerViewAt:aPoint |
1142 |
"find container view responds to aPoint. |
|
1143 |
" |
|
1144 |
^ self subclassResponsibility |
|
1145 |
||
1146 |
||
1147 |
! |
|
1148 |
||
60 | 1149 |
findObjectAt:aPoint |
1150 |
"find the origin/corner of the currentWidget |
|
1151 |
" |
|
1152 |
|view viewId lastId point listOfViews| |
|
1153 |
||
1154 |
viewId := rootView id. |
|
1155 |
point := aPoint + (device translatePoint:0@0 from:(self id) to:viewId). |
|
1156 |
||
1157 |
inputView lower. |
|
1158 |
||
1159 |
[viewId notNil] whileTrue:[ |
|
1160 |
lastId := viewId. |
|
1161 |
viewId := device viewIdFromPoint:point in:lastId |
|
1162 |
]. |
|
1163 |
||
1164 |
inputView raise. |
|
1165 |
||
1166 |
view := device viewFromId:lastId. |
|
1167 |
||
1168 |
view ~~ inputView ifTrue:[^ view]. |
|
1169 |
||
1170 |
"/ look for 'hidden' views ... |
|
1171 |
||
1172 |
listOfViews := OrderedCollection new. |
|
1173 |
self allSubViewsDo:[:aView | |
|
1174 |
|org| |
|
1175 |
||
1176 |
aView ~~ inputView ifTrue:[ |
|
1177 |
org := device translatePoint:0@0 from:(aView id) to:self id. |
|
1178 |
((org extent:aView extent) containsPoint:aPoint) ifTrue:[ |
|
1179 |
listOfViews add:aView. |
|
1180 |
] |
|
1181 |
] |
|
1182 |
]. |
|
1183 |
||
1184 |
listOfViews size > 0 ifTrue:[ |
|
1185 |
^ listOfViews last |
|
1186 |
]. |
|
1187 |
^ nil |
|
1188 |
||
1189 |
||
1190 |
! |
|
1191 |
||
1192 |
isPoint:aPoint containedIn:aView |
|
1193 |
"checks whether a point is covered by a view. |
|
1194 |
" |
|
1195 |
|p| |
|
1196 |
||
1197 |
p := device translatePoint:aPoint from:inputView id to:aView id. |
|
1198 |
||
1199 |
(p x >= 0 and:[p y >= 0]) ifTrue:[ |
|
1200 |
p := aView extent - p. |
|
1201 |
||
1202 |
(p x >= 0 and:[p y >= 0]) ifTrue:[ |
|
1203 |
^ true |
|
1204 |
] |
|
1205 |
]. |
|
1206 |
^ false |
|
1207 |
! |
|
1208 |
||
1209 |
whichBorderOf:aView isHitBy:aPoint |
|
1210 |
|p r bw org| |
|
1211 |
||
1212 |
bw := aView borderWidth. |
|
1213 |
p := aPoint - (aView superView originRelativeTo:self). |
|
1214 |
||
1215 |
r := Rectangle origin:(aView origin) |
|
1216 |
extent:(aView width @ bw). |
|
1217 |
(r containsPoint:p) ifTrue:[^ #top:]. |
|
1218 |
||
1219 |
r origin:(aView left @ (aView bottom + bw)) extent:(aView width @ bw). |
|
1220 |
(r containsPoint:p) ifTrue:[^ #bottom:]. |
|
1221 |
||
1222 |
r top:(aView top). |
|
1223 |
r extent:(bw @ aView height). |
|
1224 |
(r containsPoint:p) ifTrue:[^ #left:]. |
|
1225 |
||
1226 |
r origin:((aView right + bw) @ aView top). |
|
1227 |
(r containsPoint:p) ifTrue:[^ #right:]. |
|
1228 |
||
1229 |
^ nil |
|
1230 |
||
1231 |
||
1232 |
! ! |
|
1233 |
||
1234 |
!UIObjectView methodsFor:'selections'! |
|
1235 |
||
128 | 1236 |
moveableSelection |
131 | 1237 |
"checks whether the selection is not empty and all selected instances |
1238 |
can be moved. If true the selection is returned otherwise nil |
|
128 | 1239 |
" |
1240 |
|coll| |
|
1241 |
||
1242 |
self hasSelection ifTrue:[ |
|
1243 |
(self canMove:(coll := self selection)) ifTrue:[ |
|
1244 |
^ coll |
|
1245 |
] |
|
1246 |
]. |
|
1247 |
^ nil |
|
1248 |
! |
|
1249 |
||
60 | 1250 |
numberOfSelections |
131 | 1251 |
"return the number of selected instances |
61 | 1252 |
" |
128 | 1253 |
|coll size| |
1254 |
||
1255 |
coll := self selection. |
|
1256 |
size := coll size. |
|
1257 |
||
1258 |
(size ~~ 0 or:[coll isNil]) ifTrue:[^ size]. |
|
1259 |
^ 1 |
|
60 | 1260 |
! |
1261 |
||
1262 |
select:something |
|
61 | 1263 |
"change selection to something |
1264 |
" |
|
128 | 1265 |
(self enabled and:[something ~= self selection]) ifTrue:[ |
1266 |
self setSelection:something withRedraw:true. |
|
113 | 1267 |
self selectionChanged |
60 | 1268 |
] |
1269 |
||
113 | 1270 |
|
1271 |
||
60 | 1272 |
! |
1273 |
||
113 | 1274 |
selectionChanged |
1275 |
"called whenever the selection changed |
|
1276 |
" |
|
1277 |
self subclassResponsibility |
|
1278 |
||
1279 |
! |
|
1280 |
||
128 | 1281 |
selectionDo:aBlock |
1282 |
"apply block to every selected object |
|
1283 |
" |
|
1284 |
self forEach:(self selection) do:aBlock |
|
1285 |
||
1286 |
||
1287 |
! |
|
1288 |
||
61 | 1289 |
showSelection |
128 | 1290 |
"show the selection - draw handles |
1291 |
" |
|
61 | 1292 |
selectionHiddenLevel == 0 ifTrue:[ |
128 | 1293 |
self selectionDo:[:el| self showSelected:el ] |
60 | 1294 |
]. |
1295 |
! |
|
1296 |
||
1297 |
singleSelection |
|
131 | 1298 |
"checks whether one element is selected; in this case the element is |
1299 |
returned otherwise nil |
|
60 | 1300 |
" |
128 | 1301 |
|coll| |
1302 |
||
1303 |
(coll := self selection) isCollection ifFalse:[ |
|
1304 |
^ coll |
|
60 | 1305 |
]. |
128 | 1306 |
|
1307 |
coll size == 1 ifTrue:[ ^ coll first]. |
|
1308 |
^ nil |
|
60 | 1309 |
! |
1310 |
||
1311 |
singleSelectionDo:aBlock |
|
131 | 1312 |
"checks whether one element is selected; in this case the block |
1313 |
with argument the selected instance will be processed |
|
61 | 1314 |
" |
60 | 1315 |
|view| |
1316 |
||
1317 |
(view := self singleSelection) notNil ifTrue:[ |
|
1318 |
aBlock value:view |
|
1319 |
] |
|
1320 |
! |
|
1321 |
||
1322 |
unselect |
|
61 | 1323 |
"clear selection |
1324 |
" |
|
128 | 1325 |
self select:nil |
60 | 1326 |
! |
1327 |
||
1328 |
withSelectionHiddenDo:aBlock |
|
61 | 1329 |
"apply block with selection hidden (no handles) |
1330 |
" |
|
78 | 1331 |
|coll| |
1332 |
||
138 | 1333 |
selectionHiddenLevel == 0 ifTrue:[ |
61 | 1334 |
self selectionDo:[:aView| self showUnselected:aView]. |
1335 |
device flush. |
|
1336 |
]. |
|
138 | 1337 |
selectionHiddenLevel := selectionHiddenLevel + 1. |
61 | 1338 |
|
1339 |
aBlock valueNowOrOnUnwindDo:[ |
|
1340 |
selectionHiddenLevel == 1 ifTrue:[ |
|
1341 |
setOfSuperViewsSizeChanged notEmpty ifTrue:[ |
|
78 | 1342 |
coll := self minSetOfSuperViews:setOfSuperViewsSizeChanged. |
1343 |
coll do:[:aView| aView sizeChanged:nil]. |
|
61 | 1344 |
setOfSuperViewsSizeChanged := IdentitySet new |
1345 |
]. |
|
138 | 1346 |
selectionHiddenLevel := 0. |
61 | 1347 |
self selectionDo:[:aView| self showSelected:aView]. |
138 | 1348 |
] ifFalse:[ |
1349 |
selectionHiddenLevel := selectionHiddenLevel - 1. |
|
1350 |
] |
|
61 | 1351 |
] |
1352 |
||
1353 |
! |
|
1354 |
||
1355 |
withoutSelectionDo:aBlock |
|
1356 |
"evaluate aBlock while selection is nilled |
|
1357 |
" |
|
60 | 1358 |
|sel| |
1359 |
||
128 | 1360 |
self hasSelection ifFalse:[ |
60 | 1361 |
aBlock value |
128 | 1362 |
] ifTrue:[ |
1363 |
sel := self selection. |
|
1364 |
self setSelection:nil withRedraw:true. |
|
60 | 1365 |
aBlock value. |
128 | 1366 |
self setSelection:sel withRedraw:true. |
60 | 1367 |
] |
1368 |
||
1369 |
||
1370 |
! ! |
|
1371 |
||
131 | 1372 |
!UIObjectView methodsFor:'selections basic'! |
1373 |
||
1374 |
addToSelection:anObject |
|
1375 |
"add an object to the selection |
|
1376 |
" |
|
1377 |
(self enabled and:[(self isSelected:anObject) not]) ifTrue:[ |
|
1378 |
selection isCollection ifFalse:[ |
|
1379 |
selection isNil ifTrue:[ |
|
1380 |
selection := anObject |
|
1381 |
] ifFalse:[ |
|
1382 |
selection := OrderedCollection with:selection with:anObject |
|
1383 |
] |
|
1384 |
] ifTrue:[ |
|
1385 |
selection add:anObject |
|
1386 |
]. |
|
1387 |
self showSelected:anObject. |
|
1388 |
self selectionChanged. |
|
1389 |
] |
|
1390 |
! |
|
1391 |
||
1392 |
removeFromSelection:anObject |
|
1393 |
"remove an object from the selection |
|
1394 |
" |
|
1395 |
(self isSelected:anObject) ifTrue:[ |
|
1396 |
self showUnselected:anObject. |
|
1397 |
||
1398 |
selection size > 1 ifTrue:[ |
|
1399 |
selection remove:anObject ifAbsent:nil. |
|
1400 |
self showSelection. |
|
1401 |
] ifFalse:[ |
|
1402 |
selection := nil |
|
1403 |
]. |
|
1404 |
self selectionChanged. |
|
1405 |
] |
|
1406 |
! |
|
1407 |
||
1408 |
selection |
|
1409 |
"returns the current selection |
|
1410 |
" |
|
1411 |
^ selection |
|
1412 |
||
1413 |
||
1414 |
! |
|
1415 |
||
1416 |
setSelection:aNewSelection withRedraw:doRedraw |
|
1417 |
"set a new selection without change notifications |
|
1418 |
" |
|
1419 |
doRedraw ifTrue:[ |
|
1420 |
self hideSelection. |
|
1421 |
selection := aNewSelection. |
|
1422 |
self showSelection |
|
1423 |
] ifFalse:[ |
|
1424 |
selection := aNewSelection |
|
1425 |
] |
|
1426 |
! ! |
|
1427 |
||
60 | 1428 |
!UIObjectView methodsFor:'testing'! |
1429 |
||
1430 |
canMove:something |
|
61 | 1431 |
"returns always true; all contained views can be moved |
1432 |
" |
|
1433 |
|sv| |
|
1434 |
||
1435 |
something notNil ifTrue:[ |
|
1436 |
self forEach:something do:[:v| |
|
1437 |
sv ~~ v superView ifTrue:[ |
|
1438 |
(sv notNil or:[v superView specClass isLayoutContainer]) ifTrue:[ |
|
1439 |
^ false |
|
1440 |
]. |
|
1441 |
sv := v superView |
|
1442 |
] |
|
1443 |
]. |
|
1444 |
^ true |
|
1445 |
]. |
|
1446 |
^ false |
|
60 | 1447 |
|
1448 |
! |
|
1449 |
||
1450 |
canPaste:something |
|
1451 |
"returns true if something could be paste |
|
1452 |
" |
|
1453 |
something notNil ifTrue:[ |
|
1454 |
something isCollection ifTrue:[ |
|
1455 |
something notEmpty ifTrue:[ |
|
1456 |
^ (something at:1) isKindOf:UISpecification |
|
1457 |
] |
|
1458 |
] ifFalse:[ |
|
1459 |
^ something isKindOf:UISpecification |
|
1460 |
] |
|
1461 |
]. |
|
1462 |
^ false |
|
1463 |
||
1464 |
! |
|
1465 |
||
61 | 1466 |
canPasteInto:something |
1467 |
"can paste into something ? |
|
1468 |
" |
|
96
73725336b4fe
dont paste into scrollable selectionInListViews ...
Claus Gittinger <cg@exept.de>
parents:
95
diff
changeset
|
1469 |
|
73725336b4fe
dont paste into scrollable selectionInListViews ...
Claus Gittinger <cg@exept.de>
parents:
95
diff
changeset
|
1470 |
|theView theSpec| |
73725336b4fe
dont paste into scrollable selectionInListViews ...
Claus Gittinger <cg@exept.de>
parents:
95
diff
changeset
|
1471 |
|
61 | 1472 |
something notNil ifTrue:[ |
1473 |
something isCollection ifFalse:[ |
|
96
73725336b4fe
dont paste into scrollable selectionInListViews ...
Claus Gittinger <cg@exept.de>
parents:
95
diff
changeset
|
1474 |
theView := something |
73725336b4fe
dont paste into scrollable selectionInListViews ...
Claus Gittinger <cg@exept.de>
parents:
95
diff
changeset
|
1475 |
] ifTrue:[ |
73725336b4fe
dont paste into scrollable selectionInListViews ...
Claus Gittinger <cg@exept.de>
parents:
95
diff
changeset
|
1476 |
something size == 1 ifTrue:[ |
73725336b4fe
dont paste into scrollable selectionInListViews ...
Claus Gittinger <cg@exept.de>
parents:
95
diff
changeset
|
1477 |
theView := (something at:1) |
73725336b4fe
dont paste into scrollable selectionInListViews ...
Claus Gittinger <cg@exept.de>
parents:
95
diff
changeset
|
1478 |
] |
61 | 1479 |
]. |
96
73725336b4fe
dont paste into scrollable selectionInListViews ...
Claus Gittinger <cg@exept.de>
parents:
95
diff
changeset
|
1480 |
theView notNil ifTrue:[ |
73725336b4fe
dont paste into scrollable selectionInListViews ...
Claus Gittinger <cg@exept.de>
parents:
95
diff
changeset
|
1481 |
theSpec := self specFor:theView. |
73725336b4fe
dont paste into scrollable selectionInListViews ...
Claus Gittinger <cg@exept.de>
parents:
95
diff
changeset
|
1482 |
theSpec isNil ifTrue:[ |
99 | 1483 |
^ theView specClass supportsSubComponents |
96
73725336b4fe
dont paste into scrollable selectionInListViews ...
Claus Gittinger <cg@exept.de>
parents:
95
diff
changeset
|
1484 |
]. |
73725336b4fe
dont paste into scrollable selectionInListViews ...
Claus Gittinger <cg@exept.de>
parents:
95
diff
changeset
|
1485 |
^ theSpec class supportsSubComponents |
61 | 1486 |
] |
1487 |
]. |
|
1488 |
^ false |
|
96
73725336b4fe
dont paste into scrollable selectionInListViews ...
Claus Gittinger <cg@exept.de>
parents:
95
diff
changeset
|
1489 |
|
99 | 1490 |
"Modified: 8.4.1997 / 01:19:14 / cg" |
61 | 1491 |
! |
1492 |
||
128 | 1493 |
hasSelection |
1494 |
"returns true if any selected object exists |
|
61 | 1495 |
" |
128 | 1496 |
^ self numberOfSelections ~~ 0 |
60 | 1497 |
|
1498 |
! |
|
1499 |
||
1500 |
isHorizontalResizable:aComponent |
|
61 | 1501 |
"returns true if instance is horizontal resizeable |
1502 |
" |
|
60 | 1503 |
^ self subclassResponsibility |
1504 |
||
1505 |
||
1506 |
! |
|
1507 |
||
134 | 1508 |
isModified |
1509 |
"returns true if painter is modified |
|
1510 |
" |
|
1511 |
^ undoHistory isModified |
|
1512 |
! |
|
1513 |
||
128 | 1514 |
isSelected:anObject |
1515 |
"return true, if the argument, anObject is selected |
|
1516 |
" |
|
1517 |
anObject notNil ifTrue:[ |
|
1518 |
self selectionDo:[:el| el == anObject ifTrue:[^ true]] |
|
1519 |
]. |
|
1520 |
^ false |
|
1521 |
||
1522 |
! |
|
1523 |
||
60 | 1524 |
isVerticalResizable:aComponent |
61 | 1525 |
"returns true if instance is vertical resizeable |
60 | 1526 |
" |
61 | 1527 |
^ self subclassResponsibility |
1528 |
||
1529 |
||
82 | 1530 |
! |
1531 |
||
1532 |
supportsLabel:aComponent |
|
1533 |
"returns true if component supports label |
|
1534 |
" |
|
1535 |
^ self subclassResponsibility |
|
1536 |
||
1537 |
||
60 | 1538 |
! ! |
1539 |
||
1540 |
!UIObjectView methodsFor:'transaction'! |
|
1541 |
||
134 | 1542 |
createUndoLayout:aView |
1543 |
"prepare undo action for a view changing its layout |
|
1544 |
" |
|
1545 |
self subclassResponsibility |
|
1546 |
||
1547 |
! |
|
1548 |
||
60 | 1549 |
transaction:aType objects:something do:aOneArgBlock |
1550 |
"opens a transaction and evaluates a block within the transaction; the |
|
1551 |
argument to the block is a view from derived from something |
|
1552 |
" |
|
1553 |
self subclassResponsibility |
|
1554 |
||
1555 |
||
1556 |
! |
|
1557 |
||
1558 |
transaction:aType selectionDo:aOneArgBlock |
|
1559 |
"opens a transaction and evaluates a block within the transaction; the |
|
1560 |
argument to the block is a view from the selection |
|
1561 |
" |
|
128 | 1562 |
self transaction:aType objects:(self selection) do:aOneArgBlock |
60 | 1563 |
|
1564 |
||
1565 |
! ! |
|
1566 |
||
1567 |
!UIObjectView methodsFor:'user actions - arrange'! |
|
1568 |
||
1569 |
lowerSelection |
|
61 | 1570 |
"lower all objects in the selection |
1571 |
" |
|
60 | 1572 |
self selectionDo:[:aView| aView lower ]. |
1573 |
||
1574 |
||
1575 |
! |
|
1576 |
||
1577 |
raiseSelection |
|
61 | 1578 |
"raise all objects in the selection |
1579 |
" |
|
60 | 1580 |
self selectionDo:[:aView| aView raise ]. |
1581 |
inputView raise. |
|
1582 |
||
1583 |
||
1584 |
! ! |
|
1585 |
||
1586 |
!UIObjectView methodsFor:'user actions - dimension'! |
|
1587 |
||
1588 |
copyExtent |
|
61 | 1589 |
"copy the extent from the selected object |
1590 |
" |
|
60 | 1591 |
|object| |
1592 |
||
1593 |
object := self singleSelection. |
|
1594 |
||
1595 |
object notNil ifTrue:[ |
|
1596 |
copiedExtent := object computeExtent |
|
1597 |
] ifFalse:[ |
|
1598 |
self warn:'exactly one element must be selected'. |
|
1599 |
] |
|
1600 |
||
1601 |
||
1602 |
||
1603 |
! |
|
1604 |
||
89 | 1605 |
copyLayout |
1606 |
"copy the layout from the selected object |
|
1607 |
" |
|
1608 |
|object| |
|
1609 |
||
1610 |
object := self singleSelection. |
|
1611 |
||
1612 |
object notNil ifTrue:[ |
|
1613 |
copiedLayout := object geometryLayout copy |
|
1614 |
] ifFalse:[ |
|
1615 |
self warn:'exactly one element must be selected'. |
|
1616 |
] |
|
1617 |
||
1618 |
||
1619 |
||
1620 |
! |
|
1621 |
||
60 | 1622 |
pasteExtent |
61 | 1623 |
"paste the copied extent to all objects in the selection |
1624 |
" |
|
60 | 1625 |
copiedExtent notNil ifTrue:[ |
134 | 1626 |
self transaction:#pasteExtent dimensionDo:[:v| |
60 | 1627 |
self resize:v corner:(v computeOrigin + copiedExtent) |
1628 |
] |
|
1629 |
] |
|
1630 |
! |
|
1631 |
||
1632 |
pasteHeight |
|
61 | 1633 |
"paste the copied extent height to all objects in the selection |
1634 |
" |
|
60 | 1635 |
copiedExtent notNil ifTrue:[ |
134 | 1636 |
self transaction:#pasteHeight dimensionDo:[:v| |
60 | 1637 |
self resize:v bottom:(v computeOrigin + copiedExtent) |
1638 |
] |
|
1639 |
] |
|
1640 |
||
1641 |
! |
|
1642 |
||
89 | 1643 |
pasteLayout |
1644 |
"paste layout to all objects in the selection |
|
1645 |
" |
|
1646 |
copiedLayout notNil ifTrue:[ |
|
134 | 1647 |
self transaction:#pasteLayout dimensionDo:[:v| |
89 | 1648 |
v geometryLayout:(copiedLayout copy) |
1649 |
] |
|
1650 |
] |
|
1651 |
! |
|
1652 |
||
60 | 1653 |
pasteWidth |
61 | 1654 |
"paste the copied extent width to all objects in the selection |
1655 |
" |
|
60 | 1656 |
copiedExtent notNil ifTrue:[ |
134 | 1657 |
self transaction:#pasteWidth dimensionDo:[:v| |
60 | 1658 |
self resize:v right:(v computeOrigin + copiedExtent) |
1659 |
] |
|
1660 |
] |
|
1661 |
||
1662 |
! |
|
1663 |
||
1664 |
setDimension:aLayout |
|
61 | 1665 |
"change layout for all selected objects |
1666 |
" |
|
134 | 1667 |
self transaction:#layout dimensionDo:[:v| |
61 | 1668 |
v geometryLayout:(aLayout copy) |
1669 |
]. |
|
1670 |
||
1671 |
! |
|
1672 |
||
1673 |
setExtent:anExtent |
|
1674 |
"change extent for all selected objects |
|
1675 |
" |
|
134 | 1676 |
self transaction:#extent dimensionDo:[:v| |
67 | 1677 |
v geometryLayout:nil. |
61 | 1678 |
v extent:anExtent. |
67 | 1679 |
]. |
1680 |
||
1681 |
"Modified: 28.2.1997 / 12:49:00 / cg" |
|
60 | 1682 |
! |
1683 |
||
1684 |
setToDefaultExtent |
|
61 | 1685 |
"change extent of all selected views to their default extent |
1686 |
" |
|
134 | 1687 |
self transaction:#defaultExtent dimensionDo:[:v| |
60 | 1688 |
self resize:v corner:(v computeOrigin + (v preferredExtent)) |
1689 |
] |
|
1690 |
||
1691 |
! |
|
1692 |
||
1693 |
setToDefaultHeight |
|
61 | 1694 |
"change height of all selected views to their default height |
1695 |
" |
|
134 | 1696 |
self transaction:#defaultHeight dimensionDo:[:v| |
60 | 1697 |
self resize:v bottom:(v computeOrigin + (v preferredExtent)) |
1698 |
] |
|
1699 |
||
1700 |
! |
|
1701 |
||
1702 |
setToDefaultWidth |
|
61 | 1703 |
"change width of all selected views to their default width |
1704 |
" |
|
134 | 1705 |
self transaction:#defaultWidth dimensionDo:[:v| |
60 | 1706 |
self resize:v right:(v computeOrigin + (v preferredExtent)) |
1707 |
] |
|
1708 |
||
1709 |
! |
|
1710 |
||
134 | 1711 |
transaction:aType dimensionDo:aOneArgBlock |
60 | 1712 |
"change dimension within a transaction for the selected elements by evaluating |
1713 |
the block with the argument a view. |
|
1714 |
" |
|
61 | 1715 |
self withSelectionHiddenDo:[ |
60 | 1716 |
self transaction:aType selectionDo:[:aView| |
61 | 1717 |
(self class layoutType:aView) notNil ifTrue:[ |
134 | 1718 |
self createUndoLayout:aView. |
61 | 1719 |
aOneArgBlock value:aView. |
1720 |
self elementChangedSize:aView. |
|
1721 |
] |
|
1722 |
] |
|
1723 |
]. |
|
1724 |
self changed:#layout |
|
1725 |
||
60 | 1726 |
! ! |
1727 |
||
1728 |
!UIObjectView methodsFor:'user actions - move'! |
|
1729 |
||
138 | 1730 |
moveDo:aOneArgBlock |
1731 |
"perform a move operation |
|
1732 |
" |
|
1733 |
|sensor tm| |
|
1734 |
||
1735 |
self moveableSelection isNil ifTrue:[ |
|
1736 |
^ self |
|
1737 |
]. |
|
1738 |
sensor := self sensor. |
|
1739 |
||
1740 |
tm := 0.15. |
|
1741 |
||
1742 |
self withSelectionHiddenDo:[ |
|
1743 |
self transaction:#move selectionDo:[:aView|self createUndoLayout:aView]. |
|
1744 |
||
1745 |
[ |
|
1746 |
self selectionDo:[:aView| aOneArgBlock value:aView ]. |
|
1747 |
Delay waitForSeconds:tm. |
|
1748 |
tm := 0.02. |
|
1749 |
self changed:#layout. |
|
1750 |
sensor leftButtonPressed. |
|
1751 |
] whileTrue. |
|
1752 |
||
1753 |
"/ handle any expose events (for subcomponents) before |
|
1754 |
"/ redrawing the handles. |
|
1755 |
Delay waitForSeconds:0.05. |
|
1756 |
[self sensor hasExposeEventFor:nil] whileTrue:[ |
|
1757 |
self windowGroup processExposeEvents |
|
1758 |
] |
|
1759 |
]. |
|
1760 |
! |
|
1761 |
||
113 | 1762 |
moveSelectionDown |
61 | 1763 |
"move selection down |
1764 |
" |
|
138 | 1765 |
|gridY n| |
1766 |
||
1767 |
gridAlign notNil ifTrue:[gridY := gridAlign y] |
|
1768 |
ifFalse:[gridY := 1]. |
|
1769 |
||
1770 |
self moveDo:[:aView| |
|
1771 |
aligning ifTrue:[ |
|
1772 |
n := ((aView computeCorner y) \\ gridY). |
|
1773 |
||
1774 |
n ~~ 0 ifTrue:[ |
|
1775 |
n := gridY - n + 1. |
|
1776 |
] ifFalse:[ |
|
1777 |
n := gridY |
|
61 | 1778 |
] |
138 | 1779 |
] ifFalse:[ |
1780 |
n := 1 |
|
60 | 1781 |
]. |
138 | 1782 |
self shiftLayout:aView top:n bottom:n |
60 | 1783 |
] |
1784 |
! |
|
1785 |
||
113 | 1786 |
moveSelectionLeft |
60 | 1787 |
"move selection left |
1788 |
" |
|
113 | 1789 |
|gridX n| |
60 | 1790 |
|
138 | 1791 |
gridAlign notNil ifTrue:[gridX := gridAlign x] |
1792 |
ifFalse:[gridX := 1]. |
|
1793 |
||
1794 |
self moveDo:[:aView| |
|
1795 |
aligning ifTrue:[ |
|
1796 |
n := ((aView computeOrigin x) \\ gridX). |
|
1797 |
n == 0 ifTrue:[n := gridX]. |
|
1798 |
n := n negated. |
|
1799 |
] ifFalse:[ |
|
1800 |
n := -1 |
|
60 | 1801 |
]. |
138 | 1802 |
self shiftLayout:aView left:n right:n |
60 | 1803 |
] |
1804 |
! |
|
1805 |
||
113 | 1806 |
moveSelectionRight |
1807 |
"move selection right |
|
1808 |
" |
|
1809 |
|gridX n| |
|
1810 |
||
138 | 1811 |
gridAlign notNil ifTrue:[gridX := gridAlign x] |
1812 |
ifFalse:[gridX := 1]. |
|
1813 |
||
1814 |
self moveDo:[:aView| |
|
1815 |
aligning ifTrue:[ |
|
1816 |
n := ((aView computeCorner x) \\ gridX). |
|
1817 |
||
1818 |
n ~~ 0 ifTrue:[n := n negated] |
|
1819 |
ifFalse:[n := gridX] |
|
1820 |
] ifFalse:[ |
|
1821 |
n := 1 |
|
113 | 1822 |
]. |
138 | 1823 |
self shiftLayout:aView left:n right:n |
113 | 1824 |
] |
1825 |
! |
|
1826 |
||
1827 |
moveSelectionUp |
|
60 | 1828 |
"move selection up |
1829 |
" |
|
113 | 1830 |
|gridY n| |
60 | 1831 |
|
138 | 1832 |
gridAlign notNil ifTrue:[gridY := gridAlign y] |
1833 |
ifFalse:[gridY := 1]. |
|
1834 |
||
1835 |
self moveDo:[:aView| |
|
1836 |
aligning ifTrue:[ |
|
1837 |
n := ((aView computeOrigin x) \\ gridY). |
|
1838 |
n == 0 ifTrue:[n := gridY]. |
|
1839 |
n := n negated. |
|
1840 |
] ifFalse:[ |
|
1841 |
n := -1 |
|
60 | 1842 |
]. |
138 | 1843 |
self shiftLayout:aView top:n bottom:n |
60 | 1844 |
] |
1845 |
||
1846 |
! ! |
|
1847 |
||
1848 |
!UIObjectView methodsFor:'user actions - position'! |
|
1849 |
||
1850 |
alignSelectionBottom |
|
61 | 1851 |
"align selection to the bottom of the first object in the selection; in case |
1852 |
of one selection the object is aligned to the bottom of its superview |
|
1853 |
" |
|
128 | 1854 |
|bmost delta sel| |
1855 |
||
1856 |
(sel := self moveableSelection) notNil ifTrue:[ |
|
61 | 1857 |
self withSelectionHiddenDo:[ |
60 | 1858 |
self numberOfSelections > 1 ifTrue:[ |
128 | 1859 |
bmost := (sel first) computeCorner y. |
60 | 1860 |
|
72 | 1861 |
self transaction:#alignBottom selectionDo:[:v| |
60 | 1862 |
(delta := bmost - (v computeCorner y)) ~~ 0 ifTrue:[ |
1863 |
self shiftLayout:v top:delta bottom:delta. |
|
1864 |
] |
|
1865 |
] |
|
1866 |
] ifFalse:[ |
|
72 | 1867 |
self extentToFrame:#Bottom do:[:aLayout| |
63 | 1868 |
aLayout bottomOffset:0. |
1869 |
aLayout bottomFraction:1.0 |
|
60 | 1870 |
] |
1871 |
] |
|
1872 |
]. |
|
1873 |
self changed:#layout |
|
1874 |
] |
|
1875 |
||
1876 |
||
1877 |
||
1878 |
! |
|
1879 |
||
1880 |
alignSelectionCenterHor |
|
61 | 1881 |
"align selection to the center/horizontal of the first object in the selection; in case |
1882 |
of one selection the object is aligned to the center/horizontal of its superview |
|
1883 |
" |
|
128 | 1884 |
|view center sel| |
1885 |
||
1886 |
(sel := self moveableSelection) notNil ifTrue:[ |
|
61 | 1887 |
self withSelectionHiddenDo:[ |
60 | 1888 |
view := self singleSelection. |
1889 |
||
1890 |
view notNil ifTrue:[ |
|
1891 |
view := view superView. |
|
1892 |
center := view computeExtent |
|
1893 |
] ifFalse:[ |
|
128 | 1894 |
view := sel first. |
60 | 1895 |
center := view computeCorner + view computeOrigin. |
1896 |
]. |
|
1897 |
center := center x // 2. |
|
1898 |
||
72 | 1899 |
self transaction:#alignCenterHorizontal selectionDo:[:v| |
60 | 1900 |
|newX oldX delta| |
1901 |
||
1902 |
oldX := v computeOrigin x. |
|
1903 |
newX := center - ((v computeCorner x - oldX) // 2). |
|
1904 |
delta := newX - oldX. |
|
1905 |
||
1906 |
self shiftLayout:v left:delta right:delta |
|
61 | 1907 |
] |
1908 |
]. |
|
1909 |
self changed:#layout |
|
60 | 1910 |
] |
1911 |
||
1912 |
||
1913 |
||
1914 |
! |
|
1915 |
||
1916 |
alignSelectionCenterVer |
|
61 | 1917 |
"align selection to the center/vertical of the first object in the selection; in case |
1918 |
of one selection the object is aligned to the center/vertical of its superview |
|
1919 |
" |
|
128 | 1920 |
|view center sel| |
1921 |
||
1922 |
(sel := self moveableSelection) notNil ifTrue:[ |
|
61 | 1923 |
self withSelectionHiddenDo:[ |
60 | 1924 |
view := self singleSelection. |
1925 |
||
1926 |
view notNil ifTrue:[ |
|
1927 |
view := view superView. |
|
1928 |
center := view computeExtent |
|
1929 |
] ifFalse:[ |
|
128 | 1930 |
view := sel first. |
60 | 1931 |
center := view computeCorner + view computeOrigin. |
1932 |
]. |
|
1933 |
center := center y // 2. |
|
1934 |
||
72 | 1935 |
self transaction:#alignCenterVertical selectionDo:[:v| |
60 | 1936 |
|newY oldY delta| |
1937 |
||
1938 |
oldY := v computeOrigin y. |
|
1939 |
newY := center - ((v computeCorner y - oldY) // 2). |
|
1940 |
delta := newY - oldY. |
|
1941 |
||
1942 |
self shiftLayout:v top:delta bottom:delta |
|
61 | 1943 |
] |
1944 |
]. |
|
1945 |
self changed:#layout |
|
60 | 1946 |
] |
1947 |
! |
|
1948 |
||
1949 |
alignSelectionLeft |
|
61 | 1950 |
"align selection to the left of the first object in the selection; in case |
1951 |
of one selection the object is aligned to the left of its superview |
|
1952 |
" |
|
128 | 1953 |
|lmost delta sel| |
1954 |
||
1955 |
(sel := self moveableSelection) notNil ifTrue:[ |
|
61 | 1956 |
self withSelectionHiddenDo:[ |
60 | 1957 |
self numberOfSelections > 1 ifTrue:[ |
128 | 1958 |
lmost := (sel first) computeOrigin x. |
60 | 1959 |
|
72 | 1960 |
self transaction:#alignLeft selectionDo:[:v| |
60 | 1961 |
(delta := lmost - (v computeOrigin x)) ~~ 0 ifTrue:[ |
1962 |
self shiftLayout:v left:delta right:delta |
|
1963 |
] |
|
1964 |
] |
|
1965 |
] ifFalse:[ |
|
72 | 1966 |
self extentToFrame:#Left do:[:aLayout| |
63 | 1967 |
aLayout leftOffset:0. |
1968 |
aLayout leftFraction:0.0. |
|
60 | 1969 |
] |
1970 |
] |
|
1971 |
]. |
|
1972 |
self changed:#layout |
|
1973 |
] |
|
1974 |
! |
|
1975 |
||
1976 |
alignSelectionLeftAndRight |
|
61 | 1977 |
"align selection to the left/right of the first object in the selection; in case |
1978 |
of one selection the object is aligned to the left/right of its superview |
|
1979 |
" |
|
128 | 1980 |
|lmost rmost sel| |
1981 |
||
1982 |
(sel := self moveableSelection) notNil ifTrue:[ |
|
61 | 1983 |
self withSelectionHiddenDo:[ |
60 | 1984 |
self numberOfSelections > 1 ifTrue:[ |
128 | 1985 |
lmost := (sel first) computeOrigin x. |
1986 |
rmost := (sel first) computeCorner x. |
|
60 | 1987 |
|
72 | 1988 |
self transaction:#alignLeftRight selectionDo:[:aView| |
1989 |
|layout| |
|
1990 |
layout := self class asLayoutFrameFromView:aView. |
|
1991 |
||
1992 |
layout notNil ifTrue:[ |
|
134 | 1993 |
self createUndoLayout:aView. |
72 | 1994 |
aView geometryLayout:layout. |
1995 |
||
134 | 1996 |
undoHistory withoutTransactionDo:[ |
72 | 1997 |
self shiftLayout:aView left:(lmost - (aView computeOrigin x)) |
1998 |
right:(rmost - (aView computeCorner x)). |
|
1999 |
]. |
|
2000 |
self elementChangedSize:aView |
|
2001 |
] |
|
60 | 2002 |
] |
2003 |
] ifFalse:[ |
|
72 | 2004 |
self extentToFrame:#LeftRight do:[:aLayout| |
63 | 2005 |
aLayout leftOffset:0. |
2006 |
aLayout leftFraction:0.0. |
|
2007 |
aLayout rightOffset:0. |
|
2008 |
aLayout rightFraction:1.0. |
|
60 | 2009 |
] |
2010 |
] |
|
2011 |
]. |
|
2012 |
self changed:#layout |
|
61 | 2013 |
]. |
2014 |
||
60 | 2015 |
! |
2016 |
||
2017 |
alignSelectionRight |
|
61 | 2018 |
"align selection to the right of the first object in the selection; in case |
2019 |
of one selection the object is aligned to the right of its superview |
|
2020 |
" |
|
128 | 2021 |
|rmost delta sel| |
2022 |
||
2023 |
(sel := self moveableSelection) notNil ifTrue:[ |
|
61 | 2024 |
self withSelectionHiddenDo:[ |
60 | 2025 |
self numberOfSelections > 1 ifTrue:[ |
128 | 2026 |
rmost := (sel first) computeCorner x. |
60 | 2027 |
|
72 | 2028 |
self transaction:#alignRight selectionDo:[:v| |
60 | 2029 |
(delta := rmost - (v computeCorner x)) ~~ 0 ifTrue:[ |
2030 |
self shiftLayout:v left:delta right:delta |
|
2031 |
] |
|
2032 |
] |
|
2033 |
] ifFalse:[ |
|
72 | 2034 |
self extentToFrame:#Right do:[:aLayout| |
63 | 2035 |
aLayout rightOffset:0. |
2036 |
aLayout rightFraction:1.0. |
|
60 | 2037 |
] |
2038 |
] |
|
2039 |
]. |
|
2040 |
self changed:#layout |
|
2041 |
] |
|
2042 |
! |
|
2043 |
||
2044 |
alignSelectionTop |
|
61 | 2045 |
"align selection to the top of the first object in the selection; in case |
2046 |
of one selection the object is aligned to the top of its superview |
|
2047 |
" |
|
128 | 2048 |
|tmost delta sel| |
2049 |
||
2050 |
(sel := self moveableSelection) notNil ifTrue:[ |
|
61 | 2051 |
self withSelectionHiddenDo:[ |
60 | 2052 |
self numberOfSelections > 1 ifTrue:[ |
128 | 2053 |
tmost := (sel first) computeOrigin y. |
60 | 2054 |
|
72 | 2055 |
self transaction:#alignTop selectionDo:[:v| |
60 | 2056 |
(delta := tmost - (v computeOrigin y)) ~~ 0 ifTrue:[ |
2057 |
self shiftLayout:v top:delta bottom:delta |
|
2058 |
] |
|
2059 |
] |
|
2060 |
] ifFalse:[ |
|
72 | 2061 |
self extentToFrame:#Top do:[:aLayout| |
63 | 2062 |
aLayout topOffset:0. |
2063 |
aLayout topFraction:0.0. |
|
60 | 2064 |
] |
2065 |
] |
|
2066 |
]. |
|
2067 |
self changed:#layout |
|
2068 |
] |
|
2069 |
||
2070 |
! |
|
2071 |
||
2072 |
alignSelectionTopAndBottom |
|
61 | 2073 |
"align selection to the top/bottom of the first object in the selection; in case |
2074 |
of one selection the object is aligned to the top/bottom of its superview |
|
2075 |
" |
|
128 | 2076 |
|tmost bmost sel| |
2077 |
||
2078 |
(sel := self moveableSelection) notNil ifTrue:[ |
|
61 | 2079 |
self withSelectionHiddenDo:[ |
60 | 2080 |
self numberOfSelections > 1 ifTrue:[ |
128 | 2081 |
tmost := (sel first) computeOrigin y. |
2082 |
bmost := (sel first) computeCorner y. |
|
60 | 2083 |
|
72 | 2084 |
self transaction:#alignTopBottom selectionDo:[:aView| |
2085 |
|layout| |
|
2086 |
layout := self class asLayoutFrameFromView:aView. |
|
2087 |
||
2088 |
layout notNil ifTrue:[ |
|
134 | 2089 |
self createUndoLayout:aView. |
72 | 2090 |
aView geometryLayout:layout. |
2091 |
||
134 | 2092 |
undoHistory withoutTransactionDo:[ |
72 | 2093 |
self shiftLayout:aView top:(tmost - (aView computeOrigin y)) |
2094 |
bottom:(bmost - (aView computeCorner y)). |
|
2095 |
]. |
|
2096 |
self elementChangedSize:aView |
|
2097 |
] |
|
60 | 2098 |
] |
2099 |
] ifFalse:[ |
|
72 | 2100 |
self extentToFrame:#TopBottom do:[:aLayout| |
63 | 2101 |
aLayout topOffset:0. |
2102 |
aLayout topFraction:0.0. |
|
2103 |
aLayout bottomOffset:0. |
|
2104 |
aLayout bottomFraction:1.0. |
|
60 | 2105 |
] |
2106 |
] |
|
2107 |
]. |
|
2108 |
self changed:#layout |
|
2109 |
] |
|
2110 |
! |
|
2111 |
||
2112 |
centerSelection:aOneArgBlockXorY orientation:orientation |
|
2113 |
"center selection horizontal or vertical dependant on the block result( x or y). |
|
2114 |
The argument to the block is the point. |
|
2115 |
" |
|
2116 |
|superview min max delta val| |
|
2117 |
||
128 | 2118 |
(self moveableSelection) isNil ifTrue:[ |
61 | 2119 |
^ self |
2120 |
]. |
|
2121 |
||
2122 |
self withSelectionHiddenDo:[ |
|
60 | 2123 |
max := 0. |
2124 |
||
2125 |
self selectionDo:[:aView | |
|
2126 |
superview isNil ifTrue:[ |
|
2127 |
superview := aView superView |
|
2128 |
] ifFalse:[ |
|
2129 |
(aView superView == superview) ifFalse:[ |
|
2130 |
^ self notify:'views must have same superview'. |
|
2131 |
] |
|
2132 |
]. |
|
2133 |
val := aOneArgBlockXorY value:(aView computeOrigin). |
|
2134 |
||
2135 |
min isNil ifTrue:[min := val] |
|
2136 |
ifFalse:[min := min min:val]. |
|
2137 |
||
2138 |
val := aOneArgBlockXorY value:(aView computeCorner). |
|
2139 |
max := max max:val. |
|
2140 |
]. |
|
2141 |
||
2142 |
val := aOneArgBlockXorY value:(superview computeExtent). |
|
2143 |
max := (min + val - max) // 2. |
|
2144 |
||
2145 |
max == min ifFalse:[ |
|
72 | 2146 |
|type| |
2147 |
(orientation == #y) ifTrue:[type := #centerVertical] |
|
2148 |
ifFalse:[type := #centerHorizontal]. |
|
60 | 2149 |
delta := max - min. |
2150 |
||
72 | 2151 |
self transaction:type selectionDo:[:v| |
60 | 2152 |
orientation == #y ifTrue:[ |
2153 |
self shiftLayout:v top:delta bottom:delta |
|
2154 |
] ifFalse:[ |
|
2155 |
self shiftLayout:v left:delta right:delta |
|
2156 |
] |
|
61 | 2157 |
] |
2158 |
]. |
|
2159 |
self changed:#layout |
|
60 | 2160 |
] |
2161 |
||
2162 |
||
2163 |
! |
|
2164 |
||
2165 |
centerSelectionHor |
|
2166 |
"center selection horizontal |
|
2167 |
" |
|
2168 |
self centerSelection:[:aPoint| aPoint x] orientation:#x |
|
2169 |
||
2170 |
||
2171 |
! |
|
2172 |
||
2173 |
centerSelectionVer |
|
2174 |
"center selection vertical |
|
2175 |
" |
|
2176 |
self centerSelection:[:aPoint| aPoint y] orientation:#y |
|
2177 |
! |
|
2178 |
||
72 | 2179 |
extentToFrame:toWhat do:aBlock |
2180 |
"align to frame (Left Right ...) and perform the block on a frameLayout |
|
2181 |
" |
|
2182 |
|layout type| |
|
2183 |
||
2184 |
type := ('extent', toWhat asString) asSymbol. |
|
2185 |
||
2186 |
self transaction:type selectionDo:[:aView| |
|
2187 |
layout := self class asLayoutFrameFromView:aView. |
|
2188 |
||
2189 |
layout notNil ifTrue:[ |
|
134 | 2190 |
self createUndoLayout:aView. |
72 | 2191 |
aBlock value:layout. |
2192 |
aView geometryLayout:layout. |
|
2193 |
self elementChangedSize:aView. |
|
2194 |
] |
|
2195 |
] |
|
2196 |
! |
|
2197 |
||
60 | 2198 |
spreadSelectionHor |
61 | 2199 |
"spread multiple selection horizontal |
2200 |
" |
|
128 | 2201 |
|sumWidths min max viewsInOrder topsInOrder count space sel| |
2202 |
||
2203 |
sel := self moveableSelection. |
|
2204 |
||
2205 |
(sel notNil and:[self numberOfSelections > 1]) ifFalse:[ |
|
60 | 2206 |
^ self |
2207 |
]. |
|
2208 |
||
61 | 2209 |
self withSelectionHiddenDo:[ |
60 | 2210 |
count := 0. |
2211 |
sumWidths := 0. |
|
2212 |
max := 0. |
|
2213 |
||
2214 |
self selectionDo:[:aView | |
|
2215 |
sumWidths := sumWidths + aView width. |
|
2216 |
||
2217 |
min isNil ifTrue:[min := aView left] |
|
2218 |
ifFalse:[min := min min:(aView left)]. |
|
2219 |
||
2220 |
max := max max:(aView right). |
|
2221 |
count := count + 1 |
|
2222 |
]. |
|
128 | 2223 |
viewsInOrder := Array withAll:sel. |
60 | 2224 |
topsInOrder := viewsInOrder collect:[:aView | aView left]. |
2225 |
topsInOrder sortWith:viewsInOrder. |
|
2226 |
||
2227 |
space := (((max - min) - sumWidths) / (count - 1)) rounded asInteger. |
|
2228 |
||
72 | 2229 |
self transaction:#spreadHorizontal objects:viewsInOrder do:[:aView| |
60 | 2230 |
|delta| |
2231 |
||
2232 |
delta := min - aView computeOrigin x. |
|
2233 |
self shiftLayout:aView left:delta right:delta. |
|
2234 |
min := min + aView computeExtent x + space |
|
61 | 2235 |
] |
2236 |
]. |
|
2237 |
self changed:#layout |
|
60 | 2238 |
|
2239 |
! |
|
2240 |
||
2241 |
spreadSelectionVer |
|
61 | 2242 |
"spread multiple selection vertical |
2243 |
" |
|
128 | 2244 |
|sumHeights min max viewsInOrder topsInOrder count space sel| |
2245 |
||
2246 |
sel := self moveableSelection. |
|
2247 |
||
2248 |
(sel notNil and:[self numberOfSelections > 1]) ifFalse:[ |
|
60 | 2249 |
^ self |
2250 |
]. |
|
2251 |
||
61 | 2252 |
self withSelectionHiddenDo:[ |
60 | 2253 |
count := 0. |
2254 |
sumHeights := 0. |
|
2255 |
max := 0. |
|
2256 |
||
2257 |
self selectionDo:[:aView | |
|
2258 |
sumHeights := sumHeights + aView height. |
|
2259 |
||
2260 |
min isNil ifTrue:[min := aView top] |
|
2261 |
ifFalse:[min := min min:(aView top)]. |
|
2262 |
||
2263 |
max := max max:(aView bottom). |
|
2264 |
count := count + 1 |
|
2265 |
]. |
|
128 | 2266 |
viewsInOrder := Array withAll:sel. |
60 | 2267 |
topsInOrder := viewsInOrder collect:[:aView|aView top]. |
2268 |
topsInOrder sortWith:viewsInOrder. |
|
2269 |
||
2270 |
space := (((max - min) - sumHeights) / (count - 1)) rounded asInteger. |
|
2271 |
||
72 | 2272 |
self transaction:#spreadVertical objects:viewsInOrder do:[:aView| |
60 | 2273 |
|delta| |
2274 |
||
2275 |
delta := min - aView computeOrigin y. |
|
2276 |
self shiftLayout:aView top:delta bottom:delta. |
|
2277 |
min := min + aView height + space |
|
61 | 2278 |
] |
2279 |
]. |
|
2280 |
self changed:#layout |
|
60 | 2281 |
! ! |
2282 |
||
2283 |
!UIObjectView methodsFor:'user actions - undo history'! |
|
2284 |
||
72 | 2285 |
enableUndoHistory:aState |
2286 |
"enable or disable undo history |
|
2287 |
" |
|
2288 |
undoHistory enabled:aState |
|
2289 |
! |
|
2290 |
||
60 | 2291 |
openUndoMenu |
61 | 2292 |
"open undo menu |
2293 |
" |
|
138 | 2294 |
self selection:nil. |
2295 |
undoHistory openUndoMenu |
|
60 | 2296 |
! |
2297 |
||
2298 |
removeUndoHistory |
|
2299 |
"delete total undo history |
|
2300 |
" |
|
134 | 2301 |
undoHistory on:self |
60 | 2302 |
! |
2303 |
||
2304 |
undoLast |
|
61 | 2305 |
"undo last action |
2306 |
" |
|
138 | 2307 |
|newSel oldSel| |
2308 |
||
134 | 2309 |
undoHistory isEmpty ifFalse:[ |
138 | 2310 |
self hasSelection ifTrue:[ |
2311 |
oldSel := OrderedCollection new. |
|
2312 |
newSel := OrderedCollection new. |
|
2313 |
||
2314 |
self selectionDo:[:aView||p| |
|
2315 |
(p := self propertyOfView:aView) notNil ifTrue:[ |
|
2316 |
oldSel add:(p identifier) |
|
2317 |
] |
|
2318 |
]. |
|
2319 |
self setSelection:nil withRedraw:true. |
|
2320 |
]. |
|
2321 |
||
2322 |
self withSelectionHiddenDo:[undoHistory undoLast:1]. |
|
2323 |
||
2324 |
oldSel notNil ifTrue:[ |
|
2325 |
oldSel do:[:id||v| |
|
2326 |
(v := self findViewWithId:id) notNil ifTrue:[ |
|
2327 |
newSel add:v |
|
2328 |
] |
|
2329 |
]. |
|
2330 |
self select:newSel. |
|
134 | 2331 |
] |
61 | 2332 |
]. |
60 | 2333 |
! ! |
2334 |
||
2335 |
!UIObjectView::UndoHistory class methodsFor:'constants'! |
|
2336 |
||
2337 |
maxHistorySize |
|
2338 |
"returns maximum size of history before removing oldest |
|
2339 |
record |
|
2340 |
" |
|
134 | 2341 |
^ 100 |
60 | 2342 |
|
2343 |
||
2344 |
! ! |
|
2345 |
||
131 | 2346 |
!UIObjectView::UndoHistory class methodsFor:'documentation'! |
2347 |
||
2348 |
documentation |
|
2349 |
" |
|
2350 |
undo history used by the UIPainter-Tool; to each operation, an undo block |
|
2351 |
and some text is stored. In case of a required undo, the corresponding |
|
2352 |
undo block will be performed. |
|
2353 |
||
2354 |
[see also:] |
|
2355 |
UIObjectView |
|
2356 |
UIPainterView |
|
2357 |
" |
|
2358 |
||
2359 |
||
2360 |
! ! |
|
2361 |
||
60 | 2362 |
!UIObjectView::UndoHistory class methodsFor:'instance creation'! |
2363 |
||
134 | 2364 |
on:aPainter |
2365 |
|history| |
|
2366 |
||
2367 |
history := self new. |
|
2368 |
history on:aPainter. |
|
2369 |
^ history |
|
60 | 2370 |
|
2371 |
||
2372 |
! ! |
|
2373 |
||
2374 |
!UIObjectView::UndoHistory methodsFor:'accessing'! |
|
2375 |
||
134 | 2376 |
addUndoSelector:aSelector withArgs:anArray |
2377 |
"add a selector with arguments to the current opened transaction; in case that no |
|
2378 |
transaction is opened or disabled the block will not be kept in the history. |
|
2379 |
" |
|
2380 |
self isTransactionOpen ifTrue:[ |
|
2381 |
transaction add:(Association key:aSelector value:anArray) |
|
2382 |
] |
|
2383 |
||
2384 |
||
2385 |
! ! |
|
2386 |
||
2387 |
!UIObjectView::UndoHistory methodsFor:'accessing behavior'! |
|
2388 |
||
72 | 2389 |
enabled |
2390 |
^ enabled |
|
2391 |
! |
|
2392 |
||
2393 |
enabled:aState |
|
2394 |
enabled := aState |
|
2395 |
! |
|
2396 |
||
134 | 2397 |
resetModification |
2398 |
"set modification state to false |
|
2399 |
" |
|
2400 |
startIdentifier := identifier |
|
2401 |
! ! |
|
2402 |
||
2403 |
!UIObjectView::UndoHistory methodsFor:'activation'! |
|
2404 |
||
2405 |
withinTransaction:aType text:aTextOrNil do:aBlock |
|
2406 |
"open a transaction; perform the block; at least close the transaction |
|
72 | 2407 |
" |
134 | 2408 |
(enabled and:[transaction isNil]) ifTrue:[ |
2409 |
transaction := Transaction type:aType text:aTextOrNil. |
|
2410 |
||
2411 |
aBlock value. |
|
2412 |
||
2413 |
transaction isEmpty ifFalse:[ |
|
2414 |
identifier := identifier + 1. |
|
2415 |
transaction identifier:identifier. |
|
2416 |
history addLast:transaction. |
|
2417 |
history size > (self class maxHistorySize) ifTrue:[history removeFirst] |
|
2418 |
]. |
|
2419 |
transaction := nil |
|
2420 |
||
2421 |
] ifFalse:[ |
|
2422 |
aBlock value |
|
2423 |
] |
|
2424 |
! |
|
2425 |
||
2426 |
withoutTransactionDo:aNoneArgBlock |
|
2427 |
"evaluate the block without opening a transaction or keeping changes |
|
2428 |
within a still opened transaction |
|
2429 |
" |
|
2430 |
|oldState| |
|
2431 |
||
2432 |
oldState := enabled. |
|
2433 |
enabled := false. |
|
2434 |
aNoneArgBlock value. |
|
2435 |
enabled := oldState. |
|
60 | 2436 |
! ! |
2437 |
||
2438 |
!UIObjectView::UndoHistory methodsFor:'initialization'! |
|
2439 |
||
134 | 2440 |
on:aPainter |
2441 |
"setup for a painter and delete all existing history records |
|
60 | 2442 |
" |
134 | 2443 |
identifier := 0. |
2444 |
startIdentifier := 0. |
|
2445 |
||
2446 |
painter := aPainter. |
|
60 | 2447 |
history := OrderedCollection new. |
2448 |
transaction := nil. |
|
2449 |
enabled := true. |
|
2450 |
||
2451 |
||
2452 |
! ! |
|
2453 |
||
2454 |
!UIObjectView::UndoHistory methodsFor:'menu'! |
|
2455 |
||
2456 |
openUndoMenu |
|
72 | 2457 |
|list tabs top slv hzp inset selection okButton| |
60 | 2458 |
|
2459 |
history isEmpty ifTrue:[ |
|
2460 |
^ self |
|
2461 |
]. |
|
2462 |
||
2463 |
top := StandardSystemView new label:'undo history'; extent:250@350. |
|
2464 |
slv := ScrollableView for:SelectionInListView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
2465 |
hzp := HorizontalPanelView origin:0.0@1.0 corner:1.0@1.0 in:top. |
|
2466 |
hzp horizontalLayout:#fitSpace. |
|
2467 |
||
2468 |
(Button abortButtonIn:hzp) action:[ selection := nil. top destroy ]. |
|
2469 |
okButton := Button okButtonIn:hzp. |
|
2470 |
okButton label:'undo to end'. |
|
2471 |
okButton action:[ top destroy ]. |
|
2472 |
||
2473 |
inset := hzp preferredExtent y. |
|
2474 |
hzp topInset:(inset negated). |
|
2475 |
slv bottomInset:inset. |
|
2476 |
slv := slv scrolledView. |
|
2477 |
||
72 | 2478 |
tabs := TabulatorSpecification new. |
2479 |
tabs unit:#cm. |
|
2480 |
tabs positions:#(0 5). |
|
2481 |
tabs align:#(#left ##left). |
|
2482 |
||
60 | 2483 |
list := history collect:[:aTrans||e| |
2484 |
e := MultiColListEntry new. |
|
72 | 2485 |
e colAt:1 put:(aTrans typeAsString). |
60 | 2486 |
e colAt:2 put:(aTrans text ? ''). |
72 | 2487 |
e tabulatorSpecification:tabs. |
60 | 2488 |
e |
2489 |
]. |
|
2490 |
||
2491 |
slv list:list. |
|
2492 |
slv action:[:index | selection := index ]. |
|
2493 |
top openModal. |
|
2494 |
||
2495 |
selection notNil ifTrue:[ |
|
2496 |
self undoLast:(history size - selection + 1). |
|
2497 |
] |
|
2498 |
! ! |
|
2499 |
||
2500 |
!UIObjectView::UndoHistory methodsFor:'testing'! |
|
2501 |
||
2502 |
isEmpty |
|
2503 |
"returns true if undo history is empty |
|
2504 |
" |
|
2505 |
^ history isEmpty |
|
2506 |
||
2507 |
||
2508 |
! |
|
2509 |
||
134 | 2510 |
isModified |
2511 |
"returns true if history is modified |
|
2512 |
" |
|
2513 |
self isEmpty ifTrue:[ |
|
2514 |
^ false |
|
2515 |
]. |
|
2516 |
^ history last identifier ~~ startIdentifier |
|
2517 |
! |
|
2518 |
||
60 | 2519 |
isTransactionOpen |
2520 |
^ (enabled and:[transaction notNil]) |
|
2521 |
! ! |
|
2522 |
||
2523 |
!UIObjectView::UndoHistory methodsFor:'undo'! |
|
2524 |
||
2525 |
undoLast:nTransactions |
|
2526 |
"undo last n transactions; an open transaction will be closed; |
|
2527 |
transactions during undo are disabled |
|
2528 |
" |
|
134 | 2529 |
|repeatTimes transaction actions| |
60 | 2530 |
|
2531 |
transaction := nil. |
|
134 | 2532 |
enabled := false. |
2533 |
repeatTimes := nTransactions min:(history size). |
|
2534 |
||
2535 |
repeatTimes timesRepeat:[ |
|
2536 |
transaction := history removeLast. |
|
2537 |
actions := transaction actions. |
|
2538 |
||
2539 |
actions isCollection ifTrue:[ |
|
2540 |
actions reverseDo:[:aBlock| |
|
2541 |
painter perform:(aBlock key) with:(aBlock value) |
|
2542 |
] |
|
2543 |
] ifFalse:[ |
|
2544 |
painter perform:(actions key) with:(actions value) |
|
2545 |
] |
|
2546 |
]. |
|
2547 |
enabled := true. |
|
60 | 2548 |
! ! |
2549 |
||
2550 |
!UIObjectView::UndoHistory::Transaction class methodsFor:'documentation'! |
|
2551 |
||
131 | 2552 |
documentation |
2553 |
" |
|
2554 |
represents one undo record, keeping the associated type and printable text |
|
2555 |
and the undo action performed on an undo request |
|
2556 |
||
2557 |
[see also:] |
|
2558 |
UndoHistory |
|
2559 |
" |
|
2560 |
||
60 | 2561 |
! ! |
2562 |
||
54 | 2563 |
!UIObjectView::UndoHistory::Transaction class methodsFor:'instance creation'! |
2564 |
||
2565 |
type:aType text:aTextOrNil |
|
2566 |
^ self new type:aType text:aTextOrNil |
|
2567 |
||
2568 |
||
2569 |
! ! |
|
2570 |
||
2571 |
!UIObjectView::UndoHistory::Transaction methodsFor:'accessing'! |
|
2572 |
||
134 | 2573 |
actions |
2574 |
"returns actions associated with transaction |
|
2575 |
" |
|
2576 |
^ actions |
|
2577 |
! |
|
2578 |
||
2579 |
identifier |
|
2580 |
"gets my identifier |
|
2581 |
" |
|
2582 |
^ identifier |
|
2583 |
! |
|
2584 |
||
2585 |
identifier:anIdentifier |
|
2586 |
"sets my identifier |
|
2587 |
" |
|
2588 |
identifier := anIdentifier |
|
2589 |
! |
|
2590 |
||
54 | 2591 |
text |
134 | 2592 |
"returns text or nil assigned to transaction |
54 | 2593 |
" |
2594 |
^ text |
|
2595 |
! |
|
2596 |
||
2597 |
type |
|
134 | 2598 |
"returns type assigned to transaction |
54 | 2599 |
" |
2600 |
^ type |
|
2601 |
! |
|
2602 |
||
2603 |
type:aType |
|
134 | 2604 |
"change type assigned to transaction |
54 | 2605 |
" |
2606 |
type := aType |
|
72 | 2607 |
! |
2608 |
||
2609 |
typeAsString |
|
2610 |
"returns type as printable string |
|
2611 |
" |
|
2612 |
|line name size sep| |
|
2613 |
||
2614 |
line := type asString. |
|
2615 |
size := 0. |
|
2616 |
line do:[:c| (c isUppercase) ifTrue:[size := size+1] ]. |
|
2617 |
name := String new:(line size + size). |
|
2618 |
size := 1. |
|
2619 |
sep := Character space. |
|
2620 |
||
2621 |
line do:[:c| |
|
2622 |
(c isUppercase) ifFalse:[ |
|
2623 |
name at:size put:c |
|
2624 |
] ifTrue:[ |
|
2625 |
name at:size put:sep. |
|
2626 |
sep := $&. |
|
2627 |
size := size + 1. |
|
2628 |
name at:size put:(c asLowercase) |
|
2629 |
]. |
|
2630 |
size := size + 1 |
|
2631 |
]. |
|
2632 |
^ name |
|
54 | 2633 |
! ! |
2634 |
||
134 | 2635 |
!UIObjectView::UndoHistory::Transaction methodsFor:'adding'! |
54 | 2636 |
|
2637 |
add:anUndoBlock |
|
134 | 2638 |
"add an undo action to the current transaction |
54 | 2639 |
" |
2640 |
actions isNil ifTrue:[ |
|
2641 |
actions := anUndoBlock |
|
2642 |
] ifFalse:[ |
|
2643 |
actions isCollection ifFalse:[ |
|
134 | 2644 |
actions := OrderedCollection with:actions |
47 | 2645 |
]. |
54 | 2646 |
actions add:anUndoBlock. |
2647 |
] |
|
2648 |
! ! |
|
2649 |
||
2650 |
!UIObjectView::UndoHistory::Transaction methodsFor:'initialization'! |
|
2651 |
||
2652 |
type:aType text:aTextOrNil |
|
134 | 2653 |
"initialize transaction |
54 | 2654 |
" |
2655 |
type := aType. |
|
2656 |
text := aTextOrNil. |
|
2657 |
! ! |
|
2658 |
||
2659 |
!UIObjectView::UndoHistory::Transaction methodsFor:'testing'! |
|
2660 |
||
2661 |
isEmpty |
|
2662 |
"returns true if no undo action is registered |
|
2663 |
" |
|
2664 |
^ actions isNil |
|
47 | 2665 |
! ! |
2666 |
||
60 | 2667 |
!UIObjectView class methodsFor:'documentation'! |
2668 |
||
2669 |
version |
|
2670 |
^ '$Header$' |
|
2671 |
! ! |