author | ca |
Wed, 08 Apr 1998 13:16:21 +0200 | |
changeset 768 | 2ef5b8bed914 |
parent 624 | 26e7978936fc |
child 777 | ce2a772e73fa |
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 |
||
768 | 880 |
handleAffectedViews:aViewOrSeqOfViews |
881 |
"update affected views |
|
882 |
" |
|
883 |
|bw| |
|
884 |
||
885 |
self forEach:aViewOrSeqOfViews do:[:v| |
|
886 |
v shown ifTrue:[ |
|
887 |
v fill:v viewBackground. |
|
888 |
bw := v borderWidth. |
|
889 |
bw ~~ 0 ifTrue:[ |
|
890 |
v borderWidth:(bw - 1). |
|
891 |
v borderWidth:bw. |
|
892 |
]. |
|
893 |
v exposeX:0 y:0 width:9999 height:9999 |
|
894 |
] |
|
895 |
] |
|
896 |
! |
|
897 |
||
175 | 898 |
handlesOf:aComponent do:aTwoArgAction |
899 |
"perform action on each handle of a component |
|
900 |
" |
|
901 |
|dlt ext| |
|
902 |
||
903 |
dlt := (aComponent originRelativeTo:self) - aComponent origin. |
|
904 |
dlt := dlt - (3@3). |
|
905 |
ext := 6@6. |
|
906 |
||
907 |
self class handlesOf:aComponent do:[:pnt :wht | |
|
908 |
aTwoArgAction value:(pnt + dlt extent:ext) value:wht |
|
909 |
] |
|
60 | 910 |
! |
911 |
||
912 |
showSelected:aComponent |
|
61 | 913 |
"show object selected |
914 |
" |
|
175 | 915 |
|wasClipped| |
916 |
||
917 |
selectionHiddenLevel == 0 ifTrue:[ |
|
918 |
self paint:Color black. |
|
919 |
||
920 |
(wasClipped := clipChildren) ifTrue:[ |
|
921 |
self clippedByChildren:(clipChildren := false). |
|
922 |
]. |
|
923 |
||
924 |
self handlesOf:aComponent do:[:rectangle :what| |
|
925 |
what == #view ifTrue:[self displayRectangle:rectangle] |
|
926 |
ifFalse:[self fillRectangle:rectangle] |
|
927 |
]. |
|
928 |
||
929 |
wasClipped ifTrue:[ |
|
930 |
self clippedByChildren:(clipChildren := true). |
|
931 |
] |
|
932 |
] |
|
60 | 933 |
! |
934 |
||
935 |
showUnselected:aComponent |
|
61 | 936 |
"show object unselected |
937 |
" |
|
768 | 938 |
self showUnselected:aComponent addAffectedViewsTo:nil |
939 |
! |
|
940 |
||
941 |
showUnselected:aComponent addAffectedViewsTo:aSet |
|
942 |
"show object unselected. If the set, an IdentitySet, is not nil, the |
|
943 |
affected subviews are added into the set, otherwise an expose event |
|
944 |
to each affected cpomponent is raised. |
|
945 |
" |
|
251 | 946 |
|wasClipped r| |
60 | 947 |
|
138 | 948 |
selectionHiddenLevel ~~ 0 ifTrue:[^ self]. |
949 |
||
60 | 950 |
(wasClipped := clipChildren) ifTrue:[ |
951 |
self clippedByChildren:(clipChildren := false). |
|
952 |
]. |
|
953 |
||
175 | 954 |
self handlesOf:aComponent do:[:rec :wht| self clearRectangle:rec ]. |
60 | 955 |
|
956 |
wasClipped ifTrue:[ |
|
957 |
self clippedByChildren:(clipChildren := true). |
|
958 |
]. |
|
959 |
||
960 |
"/ must redraw all components which are affected b the handles |
|
175 | 961 |
r := (aComponent originRelativeTo:self) - (3@3) extent:(aComponent extent + (6@6)). |
60 | 962 |
|
963 |
subViews do:[:anotherComponent | |
|
964 |
|absOrg absFrame| |
|
965 |
||
966 |
anotherComponent ~~ inputView ifTrue:[ |
|
967 |
absOrg := anotherComponent originRelativeTo:self. |
|
968 |
absFrame := absOrg extent:(anotherComponent extent). |
|
969 |
(absFrame intersects:r) ifTrue:[ |
|
970 |
anotherComponent withAllSubViewsDo:[:v | |
|
95 | 971 |
v shown ifTrue:[ |
768 | 972 |
aSet notNil ifTrue:[ |
973 |
aSet add:v |
|
974 |
] ifFalse:[ |
|
975 |
self handleAffectedViews:v |
|
976 |
] |
|
95 | 977 |
] |
60 | 978 |
] |
979 |
] |
|
980 |
] |
|
768 | 981 |
]. |
982 |
||
60 | 983 |
! |
984 |
||
175 | 985 |
whichHandleOf:aComponent isHitBy:aPoint |
61 | 986 |
"returns kind of handle or nil |
987 |
" |
|
175 | 988 |
self handlesOf:aComponent do:[:rectangle :what| |
989 |
(rectangle containsPoint:aPoint) ifTrue:[^ what] |
|
60 | 990 |
]. |
175 | 991 |
^ nil |
60 | 992 |
! ! |
993 |
||
994 |
!UIObjectView methodsFor:'private resizing-subviews'! |
|
995 |
||
996 |
resize:aView bottom:aPoint |
|
61 | 997 |
"resize a views bottom |
998 |
" |
|
134 | 999 |
undoHistory withoutTransactionDo:[ |
60 | 1000 |
self shiftLayout:aView top:0 bottom:((aPoint y) - (aView computeCorner y)) |
1001 |
] |
|
1002 |
! |
|
1003 |
||
1004 |
resize:aView bottomLeft:aPoint |
|
61 | 1005 |
"resize a views bottom and left |
1006 |
" |
|
134 | 1007 |
undoHistory withoutTransactionDo:[ |
60 | 1008 |
self shiftLayout:aView top:0 |
1009 |
bottom:((aPoint y) - (aView computeCorner y)) |
|
1010 |
left:((aPoint x) - (aView computeOrigin x)) |
|
1011 |
right:0 |
|
1012 |
||
1013 |
] |
|
1014 |
||
1015 |
||
1016 |
! |
|
1017 |
||
1018 |
resize:aView corner:aPoint |
|
61 | 1019 |
"resize a views corner |
1020 |
" |
|
60 | 1021 |
|delta| |
1022 |
||
1023 |
delta := aPoint - aView computeCorner. |
|
1024 |
||
134 | 1025 |
undoHistory withoutTransactionDo:[ |
60 | 1026 |
self shiftLayout:aView top:0 bottom:(delta y) left:0 right:(delta x) |
1027 |
] |
|
1028 |
! |
|
1029 |
||
1030 |
resize:aView left:aPoint |
|
61 | 1031 |
"resize a views left |
1032 |
" |
|
134 | 1033 |
undoHistory withoutTransactionDo:[ |
60 | 1034 |
self shiftLayout:aView left:((aPoint x) - (aView computeOrigin x)) right:0 |
1035 |
] |
|
1036 |
||
1037 |
! |
|
1038 |
||
1039 |
resize:aView origin:aPoint |
|
61 | 1040 |
"resize a views origin |
1041 |
" |
|
60 | 1042 |
|delta| |
1043 |
||
1044 |
delta := aPoint - aView computeOrigin. |
|
1045 |
||
134 | 1046 |
undoHistory withoutTransactionDo:[ |
60 | 1047 |
self shiftLayout:aView top:(delta y) bottom:0 left:(delta x) right:0 |
1048 |
] |
|
1049 |
||
1050 |
! |
|
1051 |
||
1052 |
resize:aView right:aPoint |
|
61 | 1053 |
"resize a views right |
1054 |
" |
|
134 | 1055 |
undoHistory withoutTransactionDo:[ |
60 | 1056 |
self shiftLayout:aView left:0 right:((aPoint x) - (aView computeCorner x)) |
1057 |
] |
|
1058 |
! |
|
1059 |
||
1060 |
resize:aView top:aPoint |
|
61 | 1061 |
"resize a views top |
1062 |
" |
|
134 | 1063 |
undoHistory withoutTransactionDo:[ |
60 | 1064 |
self shiftLayout:aView top:((aPoint y) - (aView computeOrigin y)) bottom:0 |
1065 |
] |
|
1066 |
! |
|
1067 |
||
1068 |
resize:aView topRight:aPoint |
|
61 | 1069 |
"resize a views top and right |
1070 |
" |
|
134 | 1071 |
undoHistory withoutTransactionDo:[ |
60 | 1072 |
self shiftLayout:aView top:((aPoint y) - (aView computeOrigin y)) |
1073 |
bottom:0 |
|
1074 |
left:0 |
|
1075 |
right:((aPoint x) - (aView computeCorner x)) |
|
1076 |
||
1077 |
] |
|
1078 |
||
1079 |
! ! |
|
1080 |
||
1081 |
!UIObjectView methodsFor:'private shift-layout'! |
|
1082 |
||
1083 |
shiftLayout:aView left:l right:r |
|
1084 |
"shift layout for a view; in case of an open transaction, the undo |
|
1085 |
action is registered |
|
1086 |
" |
|
1087 |
self shiftLayout:aView top:0 bottom:0 left:l right:r |
|
1088 |
||
1089 |
! |
|
1090 |
||
1091 |
shiftLayout:aView top:t bottom:b |
|
1092 |
"shift layout for a view; in case of an open transaction, the undo |
|
1093 |
action is registered |
|
1094 |
" |
|
1095 |
self shiftLayout:aView top:t bottom:b left:0 right:0 |
|
1096 |
||
1097 |
||
1098 |
! |
|
1099 |
||
1100 |
shiftLayout:aView top:t bottom:b left:l right:r |
|
1101 |
"shift layout for a view; in case of an open transaction, the undo |
|
1102 |
action is registered |
|
1103 |
" |
|
79 | 1104 |
|type layout oldExt| |
61 | 1105 |
|
1106 |
type := self class layoutType:aView. |
|
1107 |
||
1108 |
type notNil ifTrue:[ |
|
134 | 1109 |
self createUndoLayout:aView. |
61 | 1110 |
|
1111 |
type == #Extent ifTrue:[ |
|
79 | 1112 |
oldExt := aView extent. |
1113 |
aView extent:(oldExt + ((r-l) @ (b-t))). |
|
1114 |
^ self |
|
60 | 1115 |
]. |
61 | 1116 |
|
78 | 1117 |
layout := aView geometryLayout copy. |
61 | 1118 |
|
1119 |
layout isLayout ifTrue:[ |
|
1120 |
layout leftOffset:(layout leftOffset + l) |
|
1121 |
topOffset:(layout topOffset + t). |
|
1122 |
||
1123 |
type == #LayoutFrame ifTrue:[ |
|
1124 |
layout bottomOffset:(layout bottomOffset + b). |
|
1125 |
layout rightOffset:(layout rightOffset + r). |
|
1126 |
] |
|
1127 |
] ifFalse:[ |
|
1128 |
type == #Rectangle ifTrue:[ |
|
1129 |
layout left:(layout left + l) |
|
1130 |
right:(layout right + r) |
|
1131 |
top:(layout top + t) |
|
1132 |
bottom:(layout bottom + b). |
|
1133 |
] ifFalse:[ "POINT" |
|
1134 |
layout x:(layout x + l) y:(layout y + t). |
|
1135 |
] |
|
1136 |
]. |
|
1137 |
aView geometryLayout:layout |
|
60 | 1138 |
] |
1139 |
! ! |
|
1140 |
||
1141 |
!UIObjectView methodsFor:'searching'! |
|
1142 |
||
1143 |
findObjectAt:aPoint |
|
1144 |
"find the origin/corner of the currentWidget |
|
1145 |
" |
|
1146 |
|view viewId lastId point listOfViews| |
|
1147 |
||
1148 |
viewId := rootView id. |
|
1149 |
point := aPoint + (device translatePoint:0@0 from:(self id) to:viewId). |
|
1150 |
||
1151 |
inputView lower. |
|
1152 |
||
1153 |
[viewId notNil] whileTrue:[ |
|
1154 |
lastId := viewId. |
|
1155 |
viewId := device viewIdFromPoint:point in:lastId |
|
1156 |
]. |
|
1157 |
||
1158 |
inputView raise. |
|
1159 |
||
1160 |
view := device viewFromId:lastId. |
|
1161 |
||
1162 |
view ~~ inputView ifTrue:[^ view]. |
|
1163 |
||
1164 |
"/ look for 'hidden' views ... |
|
1165 |
||
1166 |
listOfViews := OrderedCollection new. |
|
1167 |
self allSubViewsDo:[:aView | |
|
1168 |
|org| |
|
1169 |
||
1170 |
aView ~~ inputView ifTrue:[ |
|
1171 |
org := device translatePoint:0@0 from:(aView id) to:self id. |
|
1172 |
((org extent:aView extent) containsPoint:aPoint) ifTrue:[ |
|
1173 |
listOfViews add:aView. |
|
1174 |
] |
|
1175 |
] |
|
1176 |
]. |
|
1177 |
||
1178 |
listOfViews size > 0 ifTrue:[ |
|
1179 |
^ listOfViews last |
|
1180 |
]. |
|
1181 |
^ nil |
|
1182 |
||
1183 |
||
1184 |
! ! |
|
1185 |
||
1186 |
!UIObjectView methodsFor:'selections'! |
|
1187 |
||
768 | 1188 |
hideSelection |
1189 |
"hide the selection - undraw hilights - whatever that is" |
|
1190 |
||
1191 |
|aSet| |
|
1192 |
||
1193 |
self selectionDo:[:object| |
|
1194 |
aSet isNil ifTrue:[ |
|
1195 |
aSet := IdentitySet new |
|
1196 |
]. |
|
1197 |
self showUnselected:object addAffectedViewsTo:aSet. |
|
1198 |
]. |
|
1199 |
self handleAffectedViews:aSet. |
|
1200 |
||
1201 |
||
1202 |
! |
|
1203 |
||
128 | 1204 |
moveableSelection |
131 | 1205 |
"checks whether the selection is not empty and all selected instances |
1206 |
can be moved. If true the selection is returned otherwise nil |
|
128 | 1207 |
" |
1208 |
|coll| |
|
1209 |
||
1210 |
self hasSelection ifTrue:[ |
|
1211 |
(self canMove:(coll := self selection)) ifTrue:[ |
|
1212 |
^ coll |
|
1213 |
] |
|
1214 |
]. |
|
1215 |
^ nil |
|
1216 |
! |
|
1217 |
||
60 | 1218 |
numberOfSelections |
131 | 1219 |
"return the number of selected instances |
61 | 1220 |
" |
128 | 1221 |
|coll size| |
1222 |
||
1223 |
coll := self selection. |
|
1224 |
size := coll size. |
|
1225 |
||
1226 |
(size ~~ 0 or:[coll isNil]) ifTrue:[^ size]. |
|
1227 |
^ 1 |
|
60 | 1228 |
! |
1229 |
||
149 | 1230 |
selection:something |
1231 |
"change selection to something |
|
1232 |
" |
|
1233 |
self select:something |
|
1234 |
! |
|
1235 |
||
128 | 1236 |
selectionDo:aBlock |
1237 |
"apply block to every selected object |
|
1238 |
" |
|
1239 |
self forEach:(self selection) do:aBlock |
|
1240 |
||
1241 |
||
1242 |
! |
|
1243 |
||
61 | 1244 |
showSelection |
128 | 1245 |
"show the selection - draw handles |
1246 |
" |
|
61 | 1247 |
selectionHiddenLevel == 0 ifTrue:[ |
128 | 1248 |
self selectionDo:[:el| self showSelected:el ] |
60 | 1249 |
]. |
1250 |
! |
|
1251 |
||
1252 |
singleSelection |
|
131 | 1253 |
"checks whether one element is selected; in this case the element is |
1254 |
returned otherwise nil |
|
60 | 1255 |
" |
128 | 1256 |
|coll| |
1257 |
||
1258 |
(coll := self selection) isCollection ifFalse:[ |
|
1259 |
^ coll |
|
60 | 1260 |
]. |
128 | 1261 |
|
1262 |
coll size == 1 ifTrue:[ ^ coll first]. |
|
1263 |
^ nil |
|
60 | 1264 |
! |
1265 |
||
1266 |
singleSelectionDo:aBlock |
|
131 | 1267 |
"checks whether one element is selected; in this case the block |
1268 |
with argument the selected instance will be processed |
|
61 | 1269 |
" |
60 | 1270 |
|view| |
1271 |
||
1272 |
(view := self singleSelection) notNil ifTrue:[ |
|
1273 |
aBlock value:view |
|
1274 |
] |
|
1275 |
! |
|
1276 |
||
1277 |
unselect |
|
61 | 1278 |
"clear selection |
1279 |
" |
|
128 | 1280 |
self select:nil |
60 | 1281 |
! |
1282 |
||
1283 |
withSelectionHiddenDo:aBlock |
|
61 | 1284 |
"apply block with selection hidden (no handles) |
1285 |
" |
|
78 | 1286 |
|coll| |
1287 |
||
138 | 1288 |
selectionHiddenLevel == 0 ifTrue:[ |
768 | 1289 |
self hideSelection. |
61 | 1290 |
device flush. |
1291 |
]. |
|
138 | 1292 |
selectionHiddenLevel := selectionHiddenLevel + 1. |
61 | 1293 |
|
1294 |
aBlock valueNowOrOnUnwindDo:[ |
|
1295 |
selectionHiddenLevel == 1 ifTrue:[ |
|
1296 |
setOfSuperViewsSizeChanged notEmpty ifTrue:[ |
|
78 | 1297 |
coll := self minSetOfSuperViews:setOfSuperViewsSizeChanged. |
1298 |
coll do:[:aView| aView sizeChanged:nil]. |
|
61 | 1299 |
setOfSuperViewsSizeChanged := IdentitySet new |
1300 |
]. |
|
138 | 1301 |
selectionHiddenLevel := 0. |
61 | 1302 |
self selectionDo:[:aView| self showSelected:aView]. |
138 | 1303 |
] ifFalse:[ |
1304 |
selectionHiddenLevel := selectionHiddenLevel - 1. |
|
1305 |
] |
|
61 | 1306 |
] |
1307 |
||
1308 |
! |
|
1309 |
||
1310 |
withoutSelectionDo:aBlock |
|
1311 |
"evaluate aBlock while selection is nilled |
|
1312 |
" |
|
60 | 1313 |
|sel| |
1314 |
||
128 | 1315 |
self hasSelection ifFalse:[ |
60 | 1316 |
aBlock value |
128 | 1317 |
] ifTrue:[ |
1318 |
sel := self selection. |
|
1319 |
self setSelection:nil withRedraw:true. |
|
60 | 1320 |
aBlock value. |
128 | 1321 |
self setSelection:sel withRedraw:true. |
60 | 1322 |
] |
1323 |
||
1324 |
||
1325 |
! ! |
|
1326 |
||
131 | 1327 |
!UIObjectView methodsFor:'selections basic'! |
1328 |
||
1329 |
selection |
|
1330 |
"returns the current selection |
|
1331 |
" |
|
1332 |
^ selection |
|
1333 |
||
1334 |
||
1335 |
! |
|
1336 |
||
1337 |
setSelection:aNewSelection withRedraw:doRedraw |
|
1338 |
"set a new selection without change notifications |
|
1339 |
" |
|
225 | 1340 |
|sel| |
1341 |
||
1342 |
(sel := aNewSelection) == self ifTrue:[ |
|
1343 |
sel := nil |
|
1344 |
]. |
|
1345 |
||
131 | 1346 |
doRedraw ifTrue:[ |
1347 |
self hideSelection. |
|
225 | 1348 |
selection := sel. |
131 | 1349 |
self showSelection |
1350 |
] ifFalse:[ |
|
225 | 1351 |
selection := sel |
131 | 1352 |
] |
1353 |
! ! |
|
1354 |
||
60 | 1355 |
!UIObjectView methodsFor:'testing'! |
1356 |
||
284 | 1357 |
hasSelection |
1358 |
"returns true if any widget is selected |
|
61 | 1359 |
" |
284 | 1360 |
^ self numberOfSelections ~~ 0 |
60 | 1361 |
|
1362 |
! |
|
1363 |
||
284 | 1364 |
hasSingleSelection |
1365 |
"returns true if one widget is selected |
|
61 | 1366 |
" |
284 | 1367 |
^ self numberOfSelections == 1 |
1368 |
||
1369 |
! |
|
1370 |
||
1371 |
hasUndoHistory |
|
1372 |
"returns true if undos exists |
|
1373 |
" |
|
1374 |
^ undoHistory isEmpty not |
|
60 | 1375 |
! |
1376 |
||
134 | 1377 |
isModified |
1378 |
"returns true if painter is modified |
|
1379 |
" |
|
1380 |
^ undoHistory isModified |
|
1381 |
! |
|
1382 |
||
128 | 1383 |
isSelected:anObject |
1384 |
"return true, if the argument, anObject is selected |
|
1385 |
" |
|
1386 |
anObject notNil ifTrue:[ |
|
1387 |
self selectionDo:[:el| el == anObject ifTrue:[^ true]] |
|
1388 |
]. |
|
1389 |
^ false |
|
1390 |
||
60 | 1391 |
! ! |
1392 |
||
1393 |
!UIObjectView methodsFor:'transaction'! |
|
1394 |
||
134 | 1395 |
createUndoLayout:aView |
1396 |
"prepare undo action for a view changing its layout |
|
1397 |
" |
|
1398 |
self subclassResponsibility |
|
1399 |
||
1400 |
! |
|
1401 |
||
60 | 1402 |
transaction:aType objects:something do:aOneArgBlock |
1403 |
"opens a transaction and evaluates a block within the transaction; the |
|
1404 |
argument to the block is a view from derived from something |
|
1405 |
" |
|
1406 |
self subclassResponsibility |
|
1407 |
||
1408 |
||
1409 |
! |
|
1410 |
||
1411 |
transaction:aType selectionDo:aOneArgBlock |
|
1412 |
"opens a transaction and evaluates a block within the transaction; the |
|
1413 |
argument to the block is a view from the selection |
|
1414 |
" |
|
128 | 1415 |
self transaction:aType objects:(self selection) do:aOneArgBlock |
60 | 1416 |
|
1417 |
||
1418 |
! ! |
|
1419 |
||
1420 |
!UIObjectView methodsFor:'user actions - dimension'! |
|
1421 |
||
1422 |
copyExtent |
|
61 | 1423 |
"copy the extent from the selected object |
1424 |
" |
|
60 | 1425 |
|object| |
1426 |
||
1427 |
object := self singleSelection. |
|
1428 |
||
1429 |
object notNil ifTrue:[ |
|
1430 |
copiedExtent := object computeExtent |
|
1431 |
] ifFalse:[ |
|
1432 |
self warn:'exactly one element must be selected'. |
|
1433 |
] |
|
1434 |
||
1435 |
||
1436 |
||
1437 |
! |
|
1438 |
||
89 | 1439 |
copyLayout |
1440 |
"copy the layout from the selected object |
|
1441 |
" |
|
1442 |
|object| |
|
1443 |
||
1444 |
object := self singleSelection. |
|
1445 |
||
1446 |
object notNil ifTrue:[ |
|
1447 |
copiedLayout := object geometryLayout copy |
|
1448 |
] ifFalse:[ |
|
1449 |
self warn:'exactly one element must be selected'. |
|
1450 |
] |
|
1451 |
||
1452 |
||
1453 |
||
1454 |
! |
|
1455 |
||
60 | 1456 |
pasteExtent |
61 | 1457 |
"paste the copied extent to all objects in the selection |
1458 |
" |
|
60 | 1459 |
copiedExtent notNil ifTrue:[ |
134 | 1460 |
self transaction:#pasteExtent dimensionDo:[:v| |
60 | 1461 |
self resize:v corner:(v computeOrigin + copiedExtent) |
1462 |
] |
|
1463 |
] |
|
1464 |
! |
|
1465 |
||
1466 |
pasteHeight |
|
61 | 1467 |
"paste the copied extent height to all objects in the selection |
1468 |
" |
|
60 | 1469 |
copiedExtent notNil ifTrue:[ |
134 | 1470 |
self transaction:#pasteHeight dimensionDo:[:v| |
60 | 1471 |
self resize:v bottom:(v computeOrigin + copiedExtent) |
1472 |
] |
|
1473 |
] |
|
1474 |
||
1475 |
! |
|
1476 |
||
89 | 1477 |
pasteLayout |
1478 |
"paste layout to all objects in the selection |
|
1479 |
" |
|
1480 |
copiedLayout notNil ifTrue:[ |
|
134 | 1481 |
self transaction:#pasteLayout dimensionDo:[:v| |
89 | 1482 |
v geometryLayout:(copiedLayout copy) |
1483 |
] |
|
1484 |
] |
|
1485 |
! |
|
1486 |
||
60 | 1487 |
pasteWidth |
61 | 1488 |
"paste the copied extent width to all objects in the selection |
1489 |
" |
|
60 | 1490 |
copiedExtent notNil ifTrue:[ |
134 | 1491 |
self transaction:#pasteWidth dimensionDo:[:v| |
60 | 1492 |
self resize:v right:(v computeOrigin + copiedExtent) |
1493 |
] |
|
1494 |
] |
|
1495 |
||
1496 |
! |
|
1497 |
||
61 | 1498 |
setExtent:anExtent |
1499 |
"change extent for all selected objects |
|
1500 |
" |
|
134 | 1501 |
self transaction:#extent dimensionDo:[:v| |
67 | 1502 |
v geometryLayout:nil. |
61 | 1503 |
v extent:anExtent. |
67 | 1504 |
]. |
1505 |
||
1506 |
"Modified: 28.2.1997 / 12:49:00 / cg" |
|
60 | 1507 |
! |
1508 |
||
149 | 1509 |
setLayout:aLayout |
1510 |
"change layout for all selected objects |
|
1511 |
" |
|
1512 |
self transaction:#layout dimensionDo:[:v| |
|
1513 |
v geometryLayout:(aLayout copy) |
|
1514 |
]. |
|
1515 |
||
1516 |
! |
|
1517 |
||
353 | 1518 |
setMaxExtent |
1519 |
"set the topViews maxExtent to its current extent |
|
1520 |
" |
|
1521 |
self halt |
|
1522 |
||
1523 |
"Modified: / 27.10.1997 / 03:26:16 / cg" |
|
1524 |
! |
|
1525 |
||
1526 |
setMinExtent |
|
1527 |
"set the topViews minExtent to its current extent |
|
1528 |
" |
|
1529 |
self halt |
|
1530 |
||
1531 |
"Created: / 27.10.1997 / 03:24:02 / cg" |
|
1532 |
"Modified: / 27.10.1997 / 03:26:34 / cg" |
|
1533 |
! |
|
1534 |
||
60 | 1535 |
setToDefaultExtent |
61 | 1536 |
"change extent of all selected views to their default extent |
1537 |
" |
|
134 | 1538 |
self transaction:#defaultExtent dimensionDo:[:v| |
149 | 1539 |
self resize:v corner:(v computeOrigin + (v preferredExtent)). |
60 | 1540 |
] |
1541 |
||
1542 |
! |
|
1543 |
||
1544 |
setToDefaultHeight |
|
61 | 1545 |
"change height of all selected views to their default height |
1546 |
" |
|
134 | 1547 |
self transaction:#defaultHeight dimensionDo:[:v| |
60 | 1548 |
self resize:v bottom:(v computeOrigin + (v preferredExtent)) |
1549 |
] |
|
1550 |
||
1551 |
! |
|
1552 |
||
1553 |
setToDefaultWidth |
|
61 | 1554 |
"change width of all selected views to their default width |
1555 |
" |
|
134 | 1556 |
self transaction:#defaultWidth dimensionDo:[:v| |
60 | 1557 |
self resize:v right:(v computeOrigin + (v preferredExtent)) |
1558 |
] |
|
1559 |
||
1560 |
! |
|
1561 |
||
134 | 1562 |
transaction:aType dimensionDo:aOneArgBlock |
60 | 1563 |
"change dimension within a transaction for the selected elements by evaluating |
1564 |
the block with the argument a view. |
|
1565 |
" |
|
61 | 1566 |
self withSelectionHiddenDo:[ |
60 | 1567 |
self transaction:aType selectionDo:[:aView| |
61 | 1568 |
(self class layoutType:aView) notNil ifTrue:[ |
134 | 1569 |
self createUndoLayout:aView. |
61 | 1570 |
aOneArgBlock value:aView. |
1571 |
self elementChangedSize:aView. |
|
1572 |
] |
|
1573 |
] |
|
1574 |
]. |
|
225 | 1575 |
self layoutChanged |
61 | 1576 |
|
60 | 1577 |
! ! |
1578 |
||
1579 |
!UIObjectView methodsFor:'user actions - move'! |
|
1580 |
||
138 | 1581 |
moveDo:aOneArgBlock |
1582 |
"perform a move operation |
|
1583 |
" |
|
1584 |
|sensor tm| |
|
1585 |
||
1586 |
self moveableSelection isNil ifTrue:[ |
|
1587 |
^ self |
|
1588 |
]. |
|
1589 |
sensor := self sensor. |
|
1590 |
||
1591 |
tm := 0.15. |
|
1592 |
||
1593 |
self withSelectionHiddenDo:[ |
|
1594 |
self transaction:#move selectionDo:[:aView|self createUndoLayout:aView]. |
|
1595 |
||
1596 |
[ |
|
1597 |
self selectionDo:[:aView| aOneArgBlock value:aView ]. |
|
1598 |
Delay waitForSeconds:tm. |
|
1599 |
tm := 0.02. |
|
225 | 1600 |
self layoutChanged. |
138 | 1601 |
sensor leftButtonPressed. |
1602 |
] whileTrue. |
|
1603 |
||
1604 |
"/ handle any expose events (for subcomponents) before |
|
1605 |
"/ redrawing the handles. |
|
1606 |
Delay waitForSeconds:0.05. |
|
1607 |
[self sensor hasExposeEventFor:nil] whileTrue:[ |
|
1608 |
self windowGroup processExposeEvents |
|
1609 |
] |
|
1610 |
]. |
|
1611 |
! |
|
1612 |
||
113 | 1613 |
moveSelectionDown |
61 | 1614 |
"move selection down |
1615 |
" |
|
138 | 1616 |
|gridY n| |
1617 |
||
1618 |
gridAlign notNil ifTrue:[gridY := gridAlign y] |
|
1619 |
ifFalse:[gridY := 1]. |
|
1620 |
||
1621 |
self moveDo:[:aView| |
|
1622 |
aligning ifTrue:[ |
|
1623 |
n := ((aView computeCorner y) \\ gridY). |
|
1624 |
||
1625 |
n ~~ 0 ifTrue:[ |
|
1626 |
n := gridY - n + 1. |
|
1627 |
] ifFalse:[ |
|
1628 |
n := gridY |
|
61 | 1629 |
] |
138 | 1630 |
] ifFalse:[ |
1631 |
n := 1 |
|
60 | 1632 |
]. |
138 | 1633 |
self shiftLayout:aView top:n bottom:n |
60 | 1634 |
] |
1635 |
! |
|
1636 |
||
113 | 1637 |
moveSelectionLeft |
60 | 1638 |
"move selection left |
1639 |
" |
|
113 | 1640 |
|gridX n| |
60 | 1641 |
|
138 | 1642 |
gridAlign notNil ifTrue:[gridX := gridAlign x] |
1643 |
ifFalse:[gridX := 1]. |
|
1644 |
||
1645 |
self moveDo:[:aView| |
|
1646 |
aligning ifTrue:[ |
|
1647 |
n := ((aView computeOrigin x) \\ gridX). |
|
1648 |
n == 0 ifTrue:[n := gridX]. |
|
1649 |
n := n negated. |
|
1650 |
] ifFalse:[ |
|
1651 |
n := -1 |
|
60 | 1652 |
]. |
138 | 1653 |
self shiftLayout:aView left:n right:n |
60 | 1654 |
] |
1655 |
! |
|
1656 |
||
113 | 1657 |
moveSelectionRight |
1658 |
"move selection right |
|
1659 |
" |
|
1660 |
|gridX n| |
|
1661 |
||
138 | 1662 |
gridAlign notNil ifTrue:[gridX := gridAlign x] |
1663 |
ifFalse:[gridX := 1]. |
|
1664 |
||
1665 |
self moveDo:[:aView| |
|
1666 |
aligning ifTrue:[ |
|
1667 |
n := ((aView computeCorner x) \\ gridX). |
|
1668 |
||
1669 |
n ~~ 0 ifTrue:[n := n negated] |
|
1670 |
ifFalse:[n := gridX] |
|
1671 |
] ifFalse:[ |
|
1672 |
n := 1 |
|
113 | 1673 |
]. |
138 | 1674 |
self shiftLayout:aView left:n right:n |
113 | 1675 |
] |
1676 |
! |
|
1677 |
||
1678 |
moveSelectionUp |
|
60 | 1679 |
"move selection up |
1680 |
" |
|
113 | 1681 |
|gridY n| |
60 | 1682 |
|
138 | 1683 |
gridAlign notNil ifTrue:[gridY := gridAlign y] |
1684 |
ifFalse:[gridY := 1]. |
|
1685 |
||
1686 |
self moveDo:[:aView| |
|
1687 |
aligning ifTrue:[ |
|
1688 |
n := ((aView computeOrigin x) \\ gridY). |
|
1689 |
n == 0 ifTrue:[n := gridY]. |
|
1690 |
n := n negated. |
|
1691 |
] ifFalse:[ |
|
1692 |
n := -1 |
|
60 | 1693 |
]. |
138 | 1694 |
self shiftLayout:aView top:n bottom:n |
60 | 1695 |
] |
1696 |
||
1697 |
! ! |
|
1698 |
||
1699 |
!UIObjectView methodsFor:'user actions - position'! |
|
1700 |
||
1701 |
alignSelectionBottom |
|
61 | 1702 |
"align selection to the bottom of the first object in the selection; in case |
1703 |
of one selection the object is aligned to the bottom of its superview |
|
1704 |
" |
|
128 | 1705 |
|bmost delta sel| |
1706 |
||
1707 |
(sel := self moveableSelection) notNil ifTrue:[ |
|
61 | 1708 |
self withSelectionHiddenDo:[ |
60 | 1709 |
self numberOfSelections > 1 ifTrue:[ |
128 | 1710 |
bmost := (sel first) computeCorner y. |
60 | 1711 |
|
72 | 1712 |
self transaction:#alignBottom selectionDo:[:v| |
60 | 1713 |
(delta := bmost - (v computeCorner y)) ~~ 0 ifTrue:[ |
1714 |
self shiftLayout:v top:delta bottom:delta. |
|
1715 |
] |
|
1716 |
] |
|
1717 |
] ifFalse:[ |
|
72 | 1718 |
self extentToFrame:#Bottom do:[:aLayout| |
63 | 1719 |
aLayout bottomOffset:0. |
1720 |
aLayout bottomFraction:1.0 |
|
60 | 1721 |
] |
1722 |
] |
|
1723 |
]. |
|
225 | 1724 |
self layoutChanged |
60 | 1725 |
] |
1726 |
||
1727 |
||
1728 |
||
1729 |
! |
|
1730 |
||
1731 |
alignSelectionCenterHor |
|
61 | 1732 |
"align selection to the center/horizontal of the first object in the selection; in case |
1733 |
of one selection the object is aligned to the center/horizontal of its superview |
|
1734 |
" |
|
128 | 1735 |
|view center sel| |
1736 |
||
1737 |
(sel := self moveableSelection) notNil ifTrue:[ |
|
61 | 1738 |
self withSelectionHiddenDo:[ |
60 | 1739 |
view := self singleSelection. |
1740 |
||
1741 |
view notNil ifTrue:[ |
|
284 | 1742 |
|
1743 |
view := self findContainerOfView:view. |
|
60 | 1744 |
center := view computeExtent |
1745 |
] ifFalse:[ |
|
128 | 1746 |
view := sel first. |
60 | 1747 |
center := view computeCorner + view computeOrigin. |
1748 |
]. |
|
1749 |
center := center x // 2. |
|
1750 |
||
72 | 1751 |
self transaction:#alignCenterHorizontal selectionDo:[:v| |
60 | 1752 |
|newX oldX delta| |
1753 |
||
1754 |
oldX := v computeOrigin x. |
|
1755 |
newX := center - ((v computeCorner x - oldX) // 2). |
|
1756 |
delta := newX - oldX. |
|
1757 |
||
1758 |
self shiftLayout:v left:delta right:delta |
|
61 | 1759 |
] |
1760 |
]. |
|
225 | 1761 |
self layoutChanged |
60 | 1762 |
] |
1763 |
||
1764 |
||
1765 |
||
1766 |
! |
|
1767 |
||
1768 |
alignSelectionCenterVer |
|
61 | 1769 |
"align selection to the center/vertical of the first object in the selection; in case |
1770 |
of one selection the object is aligned to the center/vertical of its superview |
|
1771 |
" |
|
128 | 1772 |
|view center sel| |
1773 |
||
1774 |
(sel := self moveableSelection) notNil ifTrue:[ |
|
61 | 1775 |
self withSelectionHiddenDo:[ |
60 | 1776 |
view := self singleSelection. |
1777 |
||
1778 |
view notNil ifTrue:[ |
|
284 | 1779 |
view := self findContainerOfView:view. |
60 | 1780 |
center := view computeExtent |
1781 |
] ifFalse:[ |
|
128 | 1782 |
view := sel first. |
60 | 1783 |
center := view computeCorner + view computeOrigin. |
1784 |
]. |
|
1785 |
center := center y // 2. |
|
1786 |
||
72 | 1787 |
self transaction:#alignCenterVertical selectionDo:[:v| |
60 | 1788 |
|newY oldY delta| |
1789 |
||
1790 |
oldY := v computeOrigin y. |
|
1791 |
newY := center - ((v computeCorner y - oldY) // 2). |
|
1792 |
delta := newY - oldY. |
|
1793 |
||
1794 |
self shiftLayout:v top:delta bottom:delta |
|
61 | 1795 |
] |
1796 |
]. |
|
225 | 1797 |
self layoutChanged |
60 | 1798 |
] |
1799 |
! |
|
1800 |
||
1801 |
alignSelectionLeft |
|
61 | 1802 |
"align selection to the left of the first object in the selection; in case |
1803 |
of one selection the object is aligned to the left of its superview |
|
1804 |
" |
|
128 | 1805 |
|lmost delta sel| |
1806 |
||
1807 |
(sel := self moveableSelection) notNil ifTrue:[ |
|
61 | 1808 |
self withSelectionHiddenDo:[ |
60 | 1809 |
self numberOfSelections > 1 ifTrue:[ |
128 | 1810 |
lmost := (sel first) computeOrigin x. |
60 | 1811 |
|
72 | 1812 |
self transaction:#alignLeft selectionDo:[:v| |
60 | 1813 |
(delta := lmost - (v computeOrigin x)) ~~ 0 ifTrue:[ |
1814 |
self shiftLayout:v left:delta right:delta |
|
1815 |
] |
|
1816 |
] |
|
1817 |
] ifFalse:[ |
|
72 | 1818 |
self extentToFrame:#Left do:[:aLayout| |
63 | 1819 |
aLayout leftOffset:0. |
1820 |
aLayout leftFraction:0.0. |
|
60 | 1821 |
] |
1822 |
] |
|
1823 |
]. |
|
225 | 1824 |
self layoutChanged |
60 | 1825 |
] |
1826 |
! |
|
1827 |
||
1828 |
alignSelectionLeftAndRight |
|
61 | 1829 |
"align selection to the left/right of the first object in the selection; in case |
1830 |
of one selection the object is aligned to the left/right of its superview |
|
1831 |
" |
|
128 | 1832 |
|lmost rmost sel| |
1833 |
||
1834 |
(sel := self moveableSelection) notNil ifTrue:[ |
|
61 | 1835 |
self withSelectionHiddenDo:[ |
60 | 1836 |
self numberOfSelections > 1 ifTrue:[ |
128 | 1837 |
lmost := (sel first) computeOrigin x. |
1838 |
rmost := (sel first) computeCorner x. |
|
60 | 1839 |
|
72 | 1840 |
self transaction:#alignLeftRight selectionDo:[:aView| |
1841 |
|layout| |
|
1842 |
layout := self class asLayoutFrameFromView:aView. |
|
1843 |
||
1844 |
layout notNil ifTrue:[ |
|
134 | 1845 |
self createUndoLayout:aView. |
72 | 1846 |
aView geometryLayout:layout. |
1847 |
||
134 | 1848 |
undoHistory withoutTransactionDo:[ |
72 | 1849 |
self shiftLayout:aView left:(lmost - (aView computeOrigin x)) |
1850 |
right:(rmost - (aView computeCorner x)). |
|
1851 |
]. |
|
1852 |
self elementChangedSize:aView |
|
1853 |
] |
|
60 | 1854 |
] |
1855 |
] ifFalse:[ |
|
72 | 1856 |
self extentToFrame:#LeftRight do:[:aLayout| |
63 | 1857 |
aLayout leftOffset:0. |
1858 |
aLayout leftFraction:0.0. |
|
1859 |
aLayout rightOffset:0. |
|
1860 |
aLayout rightFraction:1.0. |
|
60 | 1861 |
] |
1862 |
] |
|
1863 |
]. |
|
225 | 1864 |
self layoutChanged |
61 | 1865 |
]. |
1866 |
||
60 | 1867 |
! |
1868 |
||
1869 |
alignSelectionRight |
|
61 | 1870 |
"align selection to the right of the first object in the selection; in case |
1871 |
of one selection the object is aligned to the right of its superview |
|
1872 |
" |
|
128 | 1873 |
|rmost delta sel| |
1874 |
||
1875 |
(sel := self moveableSelection) notNil ifTrue:[ |
|
61 | 1876 |
self withSelectionHiddenDo:[ |
60 | 1877 |
self numberOfSelections > 1 ifTrue:[ |
128 | 1878 |
rmost := (sel first) computeCorner x. |
60 | 1879 |
|
72 | 1880 |
self transaction:#alignRight selectionDo:[:v| |
60 | 1881 |
(delta := rmost - (v computeCorner x)) ~~ 0 ifTrue:[ |
1882 |
self shiftLayout:v left:delta right:delta |
|
1883 |
] |
|
1884 |
] |
|
1885 |
] ifFalse:[ |
|
72 | 1886 |
self extentToFrame:#Right do:[:aLayout| |
63 | 1887 |
aLayout rightOffset:0. |
1888 |
aLayout rightFraction:1.0. |
|
60 | 1889 |
] |
1890 |
] |
|
1891 |
]. |
|
225 | 1892 |
self layoutChanged |
60 | 1893 |
] |
1894 |
! |
|
1895 |
||
1896 |
alignSelectionTop |
|
61 | 1897 |
"align selection to the top of the first object in the selection; in case |
1898 |
of one selection the object is aligned to the top of its superview |
|
1899 |
" |
|
128 | 1900 |
|tmost delta sel| |
1901 |
||
1902 |
(sel := self moveableSelection) notNil ifTrue:[ |
|
61 | 1903 |
self withSelectionHiddenDo:[ |
60 | 1904 |
self numberOfSelections > 1 ifTrue:[ |
128 | 1905 |
tmost := (sel first) computeOrigin y. |
60 | 1906 |
|
72 | 1907 |
self transaction:#alignTop selectionDo:[:v| |
60 | 1908 |
(delta := tmost - (v computeOrigin y)) ~~ 0 ifTrue:[ |
1909 |
self shiftLayout:v top:delta bottom:delta |
|
1910 |
] |
|
1911 |
] |
|
1912 |
] ifFalse:[ |
|
72 | 1913 |
self extentToFrame:#Top do:[:aLayout| |
63 | 1914 |
aLayout topOffset:0. |
1915 |
aLayout topFraction:0.0. |
|
60 | 1916 |
] |
1917 |
] |
|
1918 |
]. |
|
225 | 1919 |
self layoutChanged |
60 | 1920 |
] |
1921 |
||
1922 |
! |
|
1923 |
||
1924 |
alignSelectionTopAndBottom |
|
61 | 1925 |
"align selection to the top/bottom of the first object in the selection; in case |
1926 |
of one selection the object is aligned to the top/bottom of its superview |
|
1927 |
" |
|
128 | 1928 |
|tmost bmost sel| |
1929 |
||
1930 |
(sel := self moveableSelection) notNil ifTrue:[ |
|
61 | 1931 |
self withSelectionHiddenDo:[ |
60 | 1932 |
self numberOfSelections > 1 ifTrue:[ |
128 | 1933 |
tmost := (sel first) computeOrigin y. |
1934 |
bmost := (sel first) computeCorner y. |
|
60 | 1935 |
|
72 | 1936 |
self transaction:#alignTopBottom selectionDo:[:aView| |
1937 |
|layout| |
|
1938 |
layout := self class asLayoutFrameFromView:aView. |
|
1939 |
||
1940 |
layout notNil ifTrue:[ |
|
134 | 1941 |
self createUndoLayout:aView. |
72 | 1942 |
aView geometryLayout:layout. |
1943 |
||
134 | 1944 |
undoHistory withoutTransactionDo:[ |
72 | 1945 |
self shiftLayout:aView top:(tmost - (aView computeOrigin y)) |
1946 |
bottom:(bmost - (aView computeCorner y)). |
|
1947 |
]. |
|
1948 |
self elementChangedSize:aView |
|
1949 |
] |
|
60 | 1950 |
] |
1951 |
] ifFalse:[ |
|
72 | 1952 |
self extentToFrame:#TopBottom do:[:aLayout| |
63 | 1953 |
aLayout topOffset:0. |
1954 |
aLayout topFraction:0.0. |
|
1955 |
aLayout bottomOffset:0. |
|
1956 |
aLayout bottomFraction:1.0. |
|
60 | 1957 |
] |
1958 |
] |
|
1959 |
]. |
|
225 | 1960 |
self layoutChanged |
60 | 1961 |
] |
1962 |
! |
|
1963 |
||
1964 |
centerSelection:aOneArgBlockXorY orientation:orientation |
|
1965 |
"center selection horizontal or vertical dependant on the block result( x or y). |
|
1966 |
The argument to the block is the point. |
|
1967 |
" |
|
1968 |
|superview min max delta val| |
|
1969 |
||
128 | 1970 |
(self moveableSelection) isNil ifTrue:[ |
61 | 1971 |
^ self |
1972 |
]. |
|
1973 |
||
1974 |
self withSelectionHiddenDo:[ |
|
60 | 1975 |
max := 0. |
1976 |
||
1977 |
self selectionDo:[:aView | |
|
1978 |
superview isNil ifTrue:[ |
|
284 | 1979 |
superview := self findContainerOfView:aView |
60 | 1980 |
] ifFalse:[ |
284 | 1981 |
(self findContainerOfView:aView) == superview ifFalse:[ |
60 | 1982 |
^ self notify:'views must have same superview'. |
1983 |
] |
|
1984 |
]. |
|
1985 |
val := aOneArgBlockXorY value:(aView computeOrigin). |
|
1986 |
||
1987 |
min isNil ifTrue:[min := val] |
|
1988 |
ifFalse:[min := min min:val]. |
|
1989 |
||
1990 |
val := aOneArgBlockXorY value:(aView computeCorner). |
|
1991 |
max := max max:val. |
|
1992 |
]. |
|
1993 |
||
1994 |
val := aOneArgBlockXorY value:(superview computeExtent). |
|
1995 |
max := (min + val - max) // 2. |
|
1996 |
||
1997 |
max == min ifFalse:[ |
|
72 | 1998 |
|type| |
1999 |
(orientation == #y) ifTrue:[type := #centerVertical] |
|
2000 |
ifFalse:[type := #centerHorizontal]. |
|
60 | 2001 |
delta := max - min. |
2002 |
||
72 | 2003 |
self transaction:type selectionDo:[:v| |
60 | 2004 |
orientation == #y ifTrue:[ |
2005 |
self shiftLayout:v top:delta bottom:delta |
|
2006 |
] ifFalse:[ |
|
2007 |
self shiftLayout:v left:delta right:delta |
|
2008 |
] |
|
61 | 2009 |
] |
2010 |
]. |
|
225 | 2011 |
self layoutChanged |
60 | 2012 |
] |
2013 |
||
2014 |
||
2015 |
! |
|
2016 |
||
2017 |
centerSelectionHor |
|
2018 |
"center selection horizontal |
|
2019 |
" |
|
2020 |
self centerSelection:[:aPoint| aPoint x] orientation:#x |
|
2021 |
||
2022 |
||
2023 |
! |
|
2024 |
||
2025 |
centerSelectionVer |
|
2026 |
"center selection vertical |
|
2027 |
" |
|
2028 |
self centerSelection:[:aPoint| aPoint y] orientation:#y |
|
2029 |
! |
|
2030 |
||
72 | 2031 |
extentToFrame:toWhat do:aBlock |
2032 |
"align to frame (Left Right ...) and perform the block on a frameLayout |
|
2033 |
" |
|
2034 |
|layout type| |
|
2035 |
||
2036 |
type := ('extent', toWhat asString) asSymbol. |
|
2037 |
||
2038 |
self transaction:type selectionDo:[:aView| |
|
2039 |
layout := self class asLayoutFrameFromView:aView. |
|
2040 |
||
2041 |
layout notNil ifTrue:[ |
|
134 | 2042 |
self createUndoLayout:aView. |
72 | 2043 |
aBlock value:layout. |
2044 |
aView geometryLayout:layout. |
|
2045 |
self elementChangedSize:aView. |
|
2046 |
] |
|
2047 |
] |
|
2048 |
! |
|
2049 |
||
60 | 2050 |
spreadSelectionHor |
61 | 2051 |
"spread multiple selection horizontal |
2052 |
" |
|
128 | 2053 |
|sumWidths 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 |
sumWidths := 0. |
|
2064 |
max := 0. |
|
2065 |
||
2066 |
self selectionDo:[:aView | |
|
2067 |
sumWidths := sumWidths + aView width. |
|
2068 |
||
2069 |
min isNil ifTrue:[min := aView left] |
|
2070 |
ifFalse:[min := min min:(aView left)]. |
|
2071 |
||
2072 |
max := max max:(aView right). |
|
2073 |
count := count + 1 |
|
2074 |
]. |
|
128 | 2075 |
viewsInOrder := Array withAll:sel. |
60 | 2076 |
topsInOrder := viewsInOrder collect:[:aView | aView left]. |
2077 |
topsInOrder sortWith:viewsInOrder. |
|
2078 |
||
2079 |
space := (((max - min) - sumWidths) / (count - 1)) rounded asInteger. |
|
2080 |
||
72 | 2081 |
self transaction:#spreadHorizontal objects:viewsInOrder do:[:aView| |
60 | 2082 |
|delta| |
2083 |
||
2084 |
delta := min - aView computeOrigin x. |
|
2085 |
self shiftLayout:aView left:delta right:delta. |
|
2086 |
min := min + aView computeExtent x + space |
|
61 | 2087 |
] |
2088 |
]. |
|
225 | 2089 |
self layoutChanged |
60 | 2090 |
|
2091 |
! |
|
2092 |
||
2093 |
spreadSelectionVer |
|
61 | 2094 |
"spread multiple selection vertical |
2095 |
" |
|
128 | 2096 |
|sumHeights min max viewsInOrder topsInOrder count space sel| |
2097 |
||
2098 |
sel := self moveableSelection. |
|
2099 |
||
2100 |
(sel notNil and:[self numberOfSelections > 1]) ifFalse:[ |
|
60 | 2101 |
^ self |
2102 |
]. |
|
2103 |
||
61 | 2104 |
self withSelectionHiddenDo:[ |
60 | 2105 |
count := 0. |
2106 |
sumHeights := 0. |
|
2107 |
max := 0. |
|
2108 |
||
2109 |
self selectionDo:[:aView | |
|
2110 |
sumHeights := sumHeights + aView height. |
|
2111 |
||
2112 |
min isNil ifTrue:[min := aView top] |
|
2113 |
ifFalse:[min := min min:(aView top)]. |
|
2114 |
||
2115 |
max := max max:(aView bottom). |
|
2116 |
count := count + 1 |
|
2117 |
]. |
|
128 | 2118 |
viewsInOrder := Array withAll:sel. |
60 | 2119 |
topsInOrder := viewsInOrder collect:[:aView|aView top]. |
2120 |
topsInOrder sortWith:viewsInOrder. |
|
2121 |
||
2122 |
space := (((max - min) - sumHeights) / (count - 1)) rounded asInteger. |
|
2123 |
||
72 | 2124 |
self transaction:#spreadVertical objects:viewsInOrder do:[:aView| |
60 | 2125 |
|delta| |
2126 |
||
2127 |
delta := min - aView computeOrigin y. |
|
2128 |
self shiftLayout:aView top:delta bottom:delta. |
|
2129 |
min := min + aView height + space |
|
61 | 2130 |
] |
2131 |
]. |
|
225 | 2132 |
self layoutChanged |
60 | 2133 |
! ! |
2134 |
||
2135 |
!UIObjectView methodsFor:'user actions - undo history'! |
|
2136 |
||
72 | 2137 |
enableUndoHistory:aState |
2138 |
"enable or disable undo history |
|
2139 |
" |
|
2140 |
undoHistory enabled:aState |
|
2141 |
! |
|
2142 |
||
60 | 2143 |
openUndoMenu |
61 | 2144 |
"open undo menu |
2145 |
" |
|
149 | 2146 |
self select:nil. |
138 | 2147 |
undoHistory openUndoMenu |
60 | 2148 |
! |
2149 |
||
2150 |
removeUndoHistory |
|
2151 |
"delete total undo history |
|
2152 |
" |
|
134 | 2153 |
undoHistory on:self |
60 | 2154 |
! |
2155 |
||
2156 |
undoLast |
|
61 | 2157 |
"undo last action |
2158 |
" |
|
138 | 2159 |
|newSel oldSel| |
2160 |
||
134 | 2161 |
undoHistory isEmpty ifFalse:[ |
138 | 2162 |
self hasSelection ifTrue:[ |
2163 |
oldSel := OrderedCollection new. |
|
2164 |
newSel := OrderedCollection new. |
|
2165 |
||
2166 |
self selectionDo:[:aView||p| |
|
2167 |
(p := self propertyOfView:aView) notNil ifTrue:[ |
|
2168 |
oldSel add:(p identifier) |
|
2169 |
] |
|
2170 |
]. |
|
2171 |
self setSelection:nil withRedraw:true. |
|
2172 |
]. |
|
2173 |
||
2174 |
self withSelectionHiddenDo:[undoHistory undoLast:1]. |
|
2175 |
||
2176 |
oldSel notNil ifTrue:[ |
|
2177 |
oldSel do:[:id||v| |
|
145 | 2178 |
(v := self findViewWithId:id) notNil ifTrue:[newSel add:v] |
138 | 2179 |
]. |
2180 |
self select:newSel. |
|
134 | 2181 |
] |
61 | 2182 |
]. |
60 | 2183 |
! ! |
2184 |
||
543
e3f2bf2dfb59
eliminated use of Structure - added private ResizeData class instead
Claus Gittinger <cg@exept.de>
parents:
374
diff
changeset
|
2185 |
!UIObjectView::ResizeData methodsFor:'accessing'! |
e3f2bf2dfb59
eliminated use of Structure - added private ResizeData class instead
Claus Gittinger <cg@exept.de>
parents:
374
diff
changeset
|
2186 |
|
e3f2bf2dfb59
eliminated use of Structure - added private ResizeData class instead
Claus Gittinger <cg@exept.de>
parents:
374
diff
changeset
|
2187 |
delta |
e3f2bf2dfb59
eliminated use of Structure - added private ResizeData class instead
Claus Gittinger <cg@exept.de>
parents:
374
diff
changeset
|
2188 |
^ delta |
e3f2bf2dfb59
eliminated use of Structure - added private ResizeData class instead
Claus Gittinger <cg@exept.de>
parents:
374
diff
changeset
|
2189 |
|
e3f2bf2dfb59
eliminated use of Structure - added private ResizeData class instead
Claus Gittinger <cg@exept.de>
parents:
374
diff
changeset
|
2190 |
"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
|
2191 |
! |
e3f2bf2dfb59
eliminated use of Structure - added private ResizeData class instead
Claus Gittinger <cg@exept.de>
parents:
374
diff
changeset
|
2192 |
|
e3f2bf2dfb59
eliminated use of Structure - added private ResizeData class instead
Claus Gittinger <cg@exept.de>
parents:
374
diff
changeset
|
2193 |
object |
e3f2bf2dfb59
eliminated use of Structure - added private ResizeData class instead
Claus Gittinger <cg@exept.de>
parents:
374
diff
changeset
|
2194 |
^ object |
e3f2bf2dfb59
eliminated use of Structure - added private ResizeData class instead
Claus Gittinger <cg@exept.de>
parents:
374
diff
changeset
|
2195 |
|
e3f2bf2dfb59
eliminated use of Structure - added private ResizeData class instead
Claus Gittinger <cg@exept.de>
parents:
374
diff
changeset
|
2196 |
"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
|
2197 |
! |
e3f2bf2dfb59
eliminated use of Structure - added private ResizeData class instead
Claus Gittinger <cg@exept.de>
parents:
374
diff
changeset
|
2198 |
|
e3f2bf2dfb59
eliminated use of Structure - added private ResizeData class instead
Claus Gittinger <cg@exept.de>
parents:
374
diff
changeset
|
2199 |
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
|
2200 |
object := anObject. |
e3f2bf2dfb59
eliminated use of Structure - added private ResizeData class instead
Claus Gittinger <cg@exept.de>
parents:
374
diff
changeset
|
2201 |
selector := aSymbol. |
e3f2bf2dfb59
eliminated use of Structure - added private ResizeData class instead
Claus Gittinger <cg@exept.de>
parents:
374
diff
changeset
|
2202 |
delta := anInteger. |
e3f2bf2dfb59
eliminated use of Structure - added private ResizeData class instead
Claus Gittinger <cg@exept.de>
parents:
374
diff
changeset
|
2203 |
|
e3f2bf2dfb59
eliminated use of Structure - added private ResizeData class instead
Claus Gittinger <cg@exept.de>
parents:
374
diff
changeset
|
2204 |
"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
|
2205 |
! |
e3f2bf2dfb59
eliminated use of Structure - added private ResizeData class instead
Claus Gittinger <cg@exept.de>
parents:
374
diff
changeset
|
2206 |
|
e3f2bf2dfb59
eliminated use of Structure - added private ResizeData class instead
Claus Gittinger <cg@exept.de>
parents:
374
diff
changeset
|
2207 |
selector |
e3f2bf2dfb59
eliminated use of Structure - added private ResizeData class instead
Claus Gittinger <cg@exept.de>
parents:
374
diff
changeset
|
2208 |
^ selector |
e3f2bf2dfb59
eliminated use of Structure - added private ResizeData class instead
Claus Gittinger <cg@exept.de>
parents:
374
diff
changeset
|
2209 |
|
e3f2bf2dfb59
eliminated use of Structure - added private ResizeData class instead
Claus Gittinger <cg@exept.de>
parents:
374
diff
changeset
|
2210 |
"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
|
2211 |
! ! |
e3f2bf2dfb59
eliminated use of Structure - added private ResizeData class instead
Claus Gittinger <cg@exept.de>
parents:
374
diff
changeset
|
2212 |
|
60 | 2213 |
!UIObjectView::UndoHistory class methodsFor:'constants'! |
2214 |
||
2215 |
maxHistorySize |
|
2216 |
"returns maximum size of history before removing oldest |
|
2217 |
record |
|
2218 |
" |
|
134 | 2219 |
^ 100 |
60 | 2220 |
|
2221 |
||
2222 |
! ! |
|
2223 |
||
131 | 2224 |
!UIObjectView::UndoHistory class methodsFor:'documentation'! |
2225 |
||
2226 |
documentation |
|
2227 |
" |
|
2228 |
undo history used by the UIPainter-Tool; to each operation, an undo block |
|
2229 |
and some text is stored. In case of a required undo, the corresponding |
|
2230 |
undo block will be performed. |
|
2231 |
||
2232 |
[see also:] |
|
2233 |
UIObjectView |
|
2234 |
UIPainterView |
|
156 | 2235 |
|
2236 |
[author:] |
|
2237 |
Claus Atzkern |
|
131 | 2238 |
" |
2239 |
||
2240 |
||
2241 |
! ! |
|
2242 |
||
60 | 2243 |
!UIObjectView::UndoHistory class methodsFor:'instance creation'! |
2244 |
||
134 | 2245 |
on:aPainter |
2246 |
|history| |
|
2247 |
||
2248 |
history := self new. |
|
2249 |
history on:aPainter. |
|
2250 |
^ history |
|
60 | 2251 |
|
2252 |
||
2253 |
! ! |
|
2254 |
||
2255 |
!UIObjectView::UndoHistory methodsFor:'accessing'! |
|
2256 |
||
134 | 2257 |
addUndoSelector:aSelector withArgs:anArray |
2258 |
"add a selector with arguments to the current opened transaction; in case that no |
|
2259 |
transaction is opened or disabled the block will not be kept in the history. |
|
2260 |
" |
|
2261 |
self isTransactionOpen ifTrue:[ |
|
2262 |
transaction add:(Association key:aSelector value:anArray) |
|
2263 |
] |
|
2264 |
||
2265 |
||
2266 |
! ! |
|
2267 |
||
2268 |
!UIObjectView::UndoHistory methodsFor:'accessing behavior'! |
|
2269 |
||
72 | 2270 |
enabled |
2271 |
^ enabled |
|
2272 |
! |
|
2273 |
||
2274 |
enabled:aState |
|
2275 |
enabled := aState |
|
2276 |
! |
|
2277 |
||
134 | 2278 |
resetModification |
2279 |
"set modification state to false |
|
2280 |
" |
|
2281 |
startIdentifier := identifier |
|
2282 |
! ! |
|
2283 |
||
2284 |
!UIObjectView::UndoHistory methodsFor:'activation'! |
|
2285 |
||
2286 |
withinTransaction:aType text:aTextOrNil do:aBlock |
|
2287 |
"open a transaction; perform the block; at least close the transaction |
|
72 | 2288 |
" |
134 | 2289 |
(enabled and:[transaction isNil]) ifTrue:[ |
2290 |
transaction := Transaction type:aType text:aTextOrNil. |
|
2291 |
||
2292 |
aBlock value. |
|
2293 |
||
2294 |
transaction isEmpty ifFalse:[ |
|
2295 |
identifier := identifier + 1. |
|
2296 |
transaction identifier:identifier. |
|
2297 |
history addLast:transaction. |
|
2298 |
history size > (self class maxHistorySize) ifTrue:[history removeFirst] |
|
2299 |
]. |
|
2300 |
transaction := nil |
|
2301 |
||
2302 |
] ifFalse:[ |
|
2303 |
aBlock value |
|
2304 |
] |
|
2305 |
! |
|
2306 |
||
2307 |
withoutTransactionDo:aNoneArgBlock |
|
2308 |
"evaluate the block without opening a transaction or keeping changes |
|
2309 |
within a still opened transaction |
|
2310 |
" |
|
2311 |
|oldState| |
|
2312 |
||
2313 |
oldState := enabled. |
|
2314 |
enabled := false. |
|
2315 |
aNoneArgBlock value. |
|
2316 |
enabled := oldState. |
|
60 | 2317 |
! ! |
2318 |
||
2319 |
!UIObjectView::UndoHistory methodsFor:'initialization'! |
|
2320 |
||
134 | 2321 |
on:aPainter |
2322 |
"setup for a painter and delete all existing history records |
|
60 | 2323 |
" |
134 | 2324 |
identifier := 0. |
2325 |
startIdentifier := 0. |
|
2326 |
||
2327 |
painter := aPainter. |
|
60 | 2328 |
history := OrderedCollection new. |
2329 |
transaction := nil. |
|
2330 |
enabled := true. |
|
2331 |
||
2332 |
||
2333 |
! ! |
|
2334 |
||
2335 |
!UIObjectView::UndoHistory methodsFor:'menu'! |
|
2336 |
||
2337 |
openUndoMenu |
|
72 | 2338 |
|list tabs top slv hzp inset selection okButton| |
60 | 2339 |
|
2340 |
history isEmpty ifTrue:[ |
|
2341 |
^ self |
|
2342 |
]. |
|
2343 |
||
2344 |
top := StandardSystemView new label:'undo history'; extent:250@350. |
|
2345 |
slv := ScrollableView for:SelectionInListView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
2346 |
hzp := HorizontalPanelView origin:0.0@1.0 corner:1.0@1.0 in:top. |
|
2347 |
hzp horizontalLayout:#fitSpace. |
|
2348 |
||
2349 |
(Button abortButtonIn:hzp) action:[ selection := nil. top destroy ]. |
|
2350 |
okButton := Button okButtonIn:hzp. |
|
2351 |
okButton label:'undo to end'. |
|
2352 |
okButton action:[ top destroy ]. |
|
2353 |
||
2354 |
inset := hzp preferredExtent y. |
|
2355 |
hzp topInset:(inset negated). |
|
2356 |
slv bottomInset:inset. |
|
2357 |
slv := slv scrolledView. |
|
2358 |
||
72 | 2359 |
tabs := TabulatorSpecification new. |
2360 |
tabs unit:#cm. |
|
2361 |
tabs positions:#(0 5). |
|
208 | 2362 |
tabs align:#(#left #left). |
72 | 2363 |
|
60 | 2364 |
list := history collect:[:aTrans||e| |
2365 |
e := MultiColListEntry new. |
|
72 | 2366 |
e colAt:1 put:(aTrans typeAsString). |
60 | 2367 |
e colAt:2 put:(aTrans text ? ''). |
72 | 2368 |
e tabulatorSpecification:tabs. |
60 | 2369 |
e |
2370 |
]. |
|
2371 |
||
2372 |
slv list:list. |
|
2373 |
slv action:[:index | selection := index ]. |
|
2374 |
top openModal. |
|
2375 |
||
2376 |
selection notNil ifTrue:[ |
|
2377 |
self undoLast:(history size - selection + 1). |
|
2378 |
] |
|
2379 |
! ! |
|
2380 |
||
2381 |
!UIObjectView::UndoHistory methodsFor:'testing'! |
|
2382 |
||
2383 |
isEmpty |
|
2384 |
"returns true if undo history is empty |
|
2385 |
" |
|
2386 |
^ history isEmpty |
|
2387 |
||
2388 |
||
2389 |
! |
|
2390 |
||
134 | 2391 |
isModified |
2392 |
"returns true if history is modified |
|
2393 |
" |
|
2394 |
self isEmpty ifTrue:[ |
|
2395 |
^ false |
|
2396 |
]. |
|
2397 |
^ history last identifier ~~ startIdentifier |
|
2398 |
! |
|
2399 |
||
60 | 2400 |
isTransactionOpen |
2401 |
^ (enabled and:[transaction notNil]) |
|
2402 |
! ! |
|
2403 |
||
2404 |
!UIObjectView::UndoHistory methodsFor:'undo'! |
|
2405 |
||
2406 |
undoLast:nTransactions |
|
2407 |
"undo last n transactions; an open transaction will be closed; |
|
2408 |
transactions during undo are disabled |
|
2409 |
" |
|
134 | 2410 |
|repeatTimes transaction actions| |
60 | 2411 |
|
2412 |
transaction := nil. |
|
134 | 2413 |
enabled := false. |
2414 |
repeatTimes := nTransactions min:(history size). |
|
2415 |
||
2416 |
repeatTimes timesRepeat:[ |
|
2417 |
transaction := history removeLast. |
|
2418 |
actions := transaction actions. |
|
2419 |
||
2420 |
actions isCollection ifTrue:[ |
|
2421 |
actions reverseDo:[:aBlock| |
|
2422 |
painter perform:(aBlock key) with:(aBlock value) |
|
2423 |
] |
|
2424 |
] ifFalse:[ |
|
2425 |
painter perform:(actions key) with:(actions value) |
|
2426 |
] |
|
2427 |
]. |
|
2428 |
enabled := true. |
|
60 | 2429 |
! ! |
2430 |
||
2431 |
!UIObjectView::UndoHistory::Transaction class methodsFor:'documentation'! |
|
2432 |
||
131 | 2433 |
documentation |
2434 |
" |
|
2435 |
represents one undo record, keeping the associated type and printable text |
|
2436 |
and the undo action performed on an undo request |
|
2437 |
||
2438 |
[see also:] |
|
2439 |
UndoHistory |
|
156 | 2440 |
|
2441 |
[author:] |
|
2442 |
Claus Atzkern |
|
131 | 2443 |
" |
2444 |
||
60 | 2445 |
! ! |
2446 |
||
54 | 2447 |
!UIObjectView::UndoHistory::Transaction class methodsFor:'instance creation'! |
2448 |
||
2449 |
type:aType text:aTextOrNil |
|
2450 |
^ self new type:aType text:aTextOrNil |
|
2451 |
||
2452 |
||
2453 |
! ! |
|
2454 |
||
2455 |
!UIObjectView::UndoHistory::Transaction methodsFor:'accessing'! |
|
2456 |
||
134 | 2457 |
actions |
2458 |
"returns actions associated with transaction |
|
2459 |
" |
|
2460 |
^ actions |
|
2461 |
! |
|
2462 |
||
2463 |
identifier |
|
2464 |
"gets my identifier |
|
2465 |
" |
|
2466 |
^ identifier |
|
2467 |
! |
|
2468 |
||
2469 |
identifier:anIdentifier |
|
2470 |
"sets my identifier |
|
2471 |
" |
|
2472 |
identifier := anIdentifier |
|
2473 |
! |
|
2474 |
||
54 | 2475 |
text |
134 | 2476 |
"returns text or nil assigned to transaction |
54 | 2477 |
" |
2478 |
^ text |
|
2479 |
! |
|
2480 |
||
2481 |
type |
|
134 | 2482 |
"returns type assigned to transaction |
54 | 2483 |
" |
2484 |
^ type |
|
2485 |
! |
|
2486 |
||
2487 |
type:aType |
|
134 | 2488 |
"change type assigned to transaction |
54 | 2489 |
" |
2490 |
type := aType |
|
72 | 2491 |
! |
2492 |
||
2493 |
typeAsString |
|
2494 |
"returns type as printable string |
|
2495 |
" |
|
2496 |
|line name size sep| |
|
2497 |
||
2498 |
line := type asString. |
|
2499 |
size := 0. |
|
2500 |
line do:[:c| (c isUppercase) ifTrue:[size := size+1] ]. |
|
2501 |
name := String new:(line size + size). |
|
2502 |
size := 1. |
|
2503 |
sep := Character space. |
|
2504 |
||
2505 |
line do:[:c| |
|
2506 |
(c isUppercase) ifFalse:[ |
|
2507 |
name at:size put:c |
|
2508 |
] ifTrue:[ |
|
2509 |
name at:size put:sep. |
|
2510 |
sep := $&. |
|
2511 |
size := size + 1. |
|
2512 |
name at:size put:(c asLowercase) |
|
2513 |
]. |
|
2514 |
size := size + 1 |
|
2515 |
]. |
|
2516 |
^ name |
|
54 | 2517 |
! ! |
2518 |
||
134 | 2519 |
!UIObjectView::UndoHistory::Transaction methodsFor:'adding'! |
54 | 2520 |
|
2521 |
add:anUndoBlock |
|
134 | 2522 |
"add an undo action to the current transaction |
54 | 2523 |
" |
2524 |
actions isNil ifTrue:[ |
|
2525 |
actions := anUndoBlock |
|
2526 |
] ifFalse:[ |
|
2527 |
actions isCollection ifFalse:[ |
|
134 | 2528 |
actions := OrderedCollection with:actions |
47 | 2529 |
]. |
54 | 2530 |
actions add:anUndoBlock. |
2531 |
] |
|
2532 |
! ! |
|
2533 |
||
2534 |
!UIObjectView::UndoHistory::Transaction methodsFor:'initialization'! |
|
2535 |
||
2536 |
type:aType text:aTextOrNil |
|
134 | 2537 |
"initialize transaction |
54 | 2538 |
" |
2539 |
type := aType. |
|
2540 |
text := aTextOrNil. |
|
2541 |
! ! |
|
2542 |
||
2543 |
!UIObjectView::UndoHistory::Transaction methodsFor:'testing'! |
|
2544 |
||
2545 |
isEmpty |
|
2546 |
"returns true if no undo action is registered |
|
2547 |
" |
|
2548 |
^ actions isNil |
|
47 | 2549 |
! ! |
2550 |
||
60 | 2551 |
!UIObjectView class methodsFor:'documentation'! |
2552 |
||
2553 |
version |
|
2554 |
^ '$Header$' |
|
2555 |
! ! |