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