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