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