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