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