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