0
|
1 |
"
|
6
|
2 |
COPYRIGHT (c) 1990 by Claus Gittinger
|
72
|
3 |
All Rights Reserved
|
0
|
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 |
StandardSystemView subclass:#ModalBox
|
54
|
14 |
instanceVariableNames:'haveControl shadowView exclusiveKeyboard '
|
72
|
15 |
classVariableNames:'UseTransientViews'
|
0
|
16 |
poolDictionaries:''
|
|
17 |
category:'Views-Basic'
|
|
18 |
!
|
|
19 |
|
|
20 |
ModalBox comment:'
|
6
|
21 |
COPYRIGHT (c) 1990 by Claus Gittinger
|
72
|
22 |
All Rights Reserved
|
54
|
23 |
|
72
|
24 |
$Header: /cvs/stx/stx/libview/ModalBox.st,v 1.12 1994-10-10 02:32:40 claus Exp $
|
2
|
25 |
'!
|
|
26 |
|
|
27 |
!ModalBox class methodsFor:'documentation'!
|
|
28 |
|
46
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1990 by Claus Gittinger
|
72
|
32 |
All Rights Reserved
|
46
|
33 |
|
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
|
42 |
|
|
43 |
version
|
|
44 |
"
|
72
|
45 |
$Header: /cvs/stx/stx/libview/ModalBox.st,v 1.12 1994-10-10 02:32:40 claus Exp $
|
46
|
46 |
"
|
|
47 |
!
|
|
48 |
|
2
|
49 |
documentation
|
|
50 |
"
|
46
|
51 |
this class implements modal boxes; ModalBoxes are different from
|
|
52 |
others, in that they take complete control over the display, until
|
|
53 |
all processing is done (i.e. other views will not get any events
|
|
54 |
while the box is active).
|
2
|
55 |
"
|
|
56 |
! !
|
|
57 |
|
|
58 |
!ModalBox class methodsFor:'initialization'!
|
0
|
59 |
|
2
|
60 |
initialize
|
72
|
61 |
UseTransient := false.
|
2
|
62 |
! !
|
0
|
63 |
|
|
64 |
!ModalBox methodsFor:'initialize / release'!
|
|
65 |
|
|
66 |
initialize
|
|
67 |
super initialize.
|
|
68 |
|
|
69 |
haveControl := false.
|
12
|
70 |
exclusiveKeyboard := false.
|
72
|
71 |
label := ' '.
|
12
|
72 |
|
72
|
73 |
UseTransient ifFalse:[
|
|
74 |
(StyleSheet at:#popupShadow default:false) ifTrue:[
|
|
75 |
shadowView := (ShadowView on:device) for:self
|
|
76 |
]
|
12
|
77 |
]
|
|
78 |
!
|
|
79 |
|
72
|
80 |
initEvents
|
|
81 |
self enableEvent:#visibilityChange
|
|
82 |
!
|
|
83 |
|
12
|
84 |
initStyle
|
|
85 |
super initStyle.
|
46
|
86 |
((style ~~ #normal) and:[style ~~ #mswindows]) ifTrue:[
|
72
|
87 |
borderWidth := 0.
|
|
88 |
self level:2
|
0
|
89 |
]
|
|
90 |
!
|
|
91 |
|
72
|
92 |
reinitialize
|
|
93 |
super reinitialize.
|
|
94 |
self unrealize.
|
|
95 |
!
|
|
96 |
|
0
|
97 |
addToCurrentProject
|
|
98 |
"ignored here"
|
|
99 |
|
|
100 |
^ self
|
|
101 |
!
|
|
102 |
|
|
103 |
destroy
|
12
|
104 |
shadowView notNil ifTrue:[
|
72
|
105 |
shadowView destroy.
|
|
106 |
shadowView := nil
|
12
|
107 |
].
|
|
108 |
self leaveControl. "just to make sure"
|
0
|
109 |
super destroy.
|
|
110 |
!
|
|
111 |
|
|
112 |
create
|
|
113 |
super create.
|
72
|
114 |
shadowView notNil ifTrue:[
|
|
115 |
self saveUnder:true
|
2
|
116 |
]
|
0
|
117 |
!
|
|
118 |
|
|
119 |
createOnTop
|
72
|
120 |
^ UseTransient not
|
0
|
121 |
! !
|
|
122 |
|
54
|
123 |
!ModalBox methodsFor:'accessing'!
|
|
124 |
|
|
125 |
exclusiveKeyboard:aBoolean
|
|
126 |
"set/clear exclusive locking of the keyboard;
|
|
127 |
If set, the box will take total control over the
|
|
128 |
keyboard, not allowing input to other views/boxes
|
|
129 |
while active.
|
|
130 |
Danger: only use this for very very urgent boxes, since
|
|
131 |
no interaction with any view on the screen is possible then."
|
|
132 |
|
|
133 |
exclusiveKeyboard := aBoolean
|
|
134 |
! !
|
|
135 |
|
0
|
136 |
!ModalBox methodsFor:'show / hide'!
|
|
137 |
|
|
138 |
mapped
|
|
139 |
"wait till visible for grabbing"
|
|
140 |
|
|
141 |
super mapped.
|
12
|
142 |
|
|
143 |
"take it away from any popup menu possibly still active"
|
|
144 |
|
46
|
145 |
ActiveGrab notNil ifTrue:[
|
72
|
146 |
device ungrabKeyboard.
|
|
147 |
ActiveGrab := nil.
|
46
|
148 |
].
|
12
|
149 |
|
54
|
150 |
"
|
|
151 |
if I am a super-modal box, take the keyboard
|
|
152 |
"
|
12
|
153 |
exclusiveKeyboard ifTrue:[
|
72
|
154 |
device grabKeyboardIn:drawableId.
|
12
|
155 |
].
|
|
156 |
|
54
|
157 |
"
|
|
158 |
get the focus
|
|
159 |
"
|
0
|
160 |
device setInputFocusTo:drawableId.
|
54
|
161 |
self enableEnterLeaveEvents
|
0
|
162 |
!
|
|
163 |
|
12
|
164 |
fixPosition:aPoint
|
72
|
165 |
"set origin to aPoint, but make sure, that the box is fully visible
|
|
166 |
by shifting it into the visible screen area if nescessary.
|
|
167 |
This prevents invisible modalBoxes (which you could never close)."
|
0
|
168 |
|
|
169 |
self origin:aPoint.
|
54
|
170 |
self makeFullyVisible
|
12
|
171 |
!
|
|
172 |
|
|
173 |
positionOffset
|
|
174 |
"return the delta, by which the box should be
|
72
|
175 |
displaced from the mouse pointer.
|
|
176 |
Usually redefined in subclasses to have the most convenient
|
|
177 |
ok-button appear under the pointer."
|
12
|
178 |
|
|
179 |
^ (width // 2) @ (height // 2)
|
|
180 |
!
|
|
181 |
|
46
|
182 |
open
|
72
|
183 |
"default for modalboxes is to come up modal at the pointer position"
|
46
|
184 |
|
72
|
185 |
^ self showAtPointer
|
46
|
186 |
!
|
|
187 |
|
72
|
188 |
openModal:aBlock
|
54
|
189 |
"open the box modal;
|
|
190 |
In addition to the basic (inherited) modalloop, change
|
72
|
191 |
the current active windowgroups cursors to the busy-stop cursor, show
|
54
|
192 |
a shadow, and raise the box."
|
|
193 |
|
72
|
194 |
|mainGroup mainView useTransient|
|
|
195 |
|
|
196 |
useTransient := UseTransient.
|
|
197 |
|
|
198 |
"
|
|
199 |
show a stop-cursor in the current group
|
|
200 |
"
|
|
201 |
mainGroup := WindowGroup activeGroup.
|
|
202 |
mainGroup notNil ifTrue:[
|
|
203 |
mainGroup := mainGroup mainGroup.
|
|
204 |
mainGroup notNil ifTrue:[
|
|
205 |
mainGroup showCursor:(Cursor stop).
|
|
206 |
]
|
|
207 |
].
|
|
208 |
|
|
209 |
mainGroup isNil ifTrue:[
|
|
210 |
useTransient := false
|
|
211 |
].
|
|
212 |
|
|
213 |
useTransient ifTrue:[
|
|
214 |
mainGroup topViews notNil ifTrue:[
|
|
215 |
mainView := mainGroup topViews first.
|
|
216 |
].
|
|
217 |
mainView isNil ifTrue:[
|
|
218 |
useTransient := false.
|
|
219 |
]
|
|
220 |
].
|
54
|
221 |
|
72
|
222 |
useTransient ifTrue:[
|
|
223 |
shadowView := nil.
|
|
224 |
] ifFalse:[
|
|
225 |
shadowView notNil ifTrue:[shadowView realize].
|
54
|
226 |
].
|
|
227 |
self raise.
|
72
|
228 |
|
54
|
229 |
haveControl := true.
|
72
|
230 |
mainGroup notNil ifTrue:[
|
|
231 |
"
|
|
232 |
flush pending key & mouse events.
|
|
233 |
this avoids pre-characters
|
|
234 |
to be put into the view ...
|
|
235 |
"
|
|
236 |
"/ mainGroup sensor flushUserEvents.
|
|
237 |
].
|
|
238 |
|
|
239 |
useTransient ifTrue:[
|
|
240 |
device setTransient:drawableId for:(mainView id).
|
|
241 |
].
|
|
242 |
super openModal:aBlock.
|
|
243 |
mainGroup notNil ifTrue:[
|
|
244 |
"
|
|
245 |
flush any key & mouse events which arrived
|
|
246 |
while the box was open (avoids stray input).
|
|
247 |
"
|
|
248 |
mainGroup sensor flushUserEvents.
|
|
249 |
].
|
54
|
250 |
!
|
|
251 |
|
12
|
252 |
show
|
72
|
253 |
"make myself visible (at the last or default position) and take control"
|
12
|
254 |
|
|
255 |
self fixSize.
|
72
|
256 |
self makeFullyVisible.
|
54
|
257 |
self openModal
|
72
|
258 |
|
|
259 |
"
|
|
260 |
|b|
|
|
261 |
|
|
262 |
b := InfoBox title:'hello'.
|
|
263 |
b show.
|
|
264 |
"
|
12
|
265 |
!
|
|
266 |
|
|
267 |
showAt:aPoint
|
|
268 |
"make myself visible at aPoint.
|
|
269 |
Fix position to make box fully visible"
|
|
270 |
|
|
271 |
self fixSize.
|
|
272 |
self fixPosition:aPoint.
|
54
|
273 |
self openModal
|
72
|
274 |
|
|
275 |
"
|
|
276 |
|b|
|
|
277 |
|
|
278 |
b := InfoBox title:'hello'.
|
|
279 |
b showAt:(0 @ 0).
|
|
280 |
b showAt:(400 @ 400).
|
|
281 |
"
|
|
282 |
!
|
|
283 |
|
|
284 |
showAt:aPoint center:center
|
|
285 |
"make myself visible at aPoint. center specifies
|
|
286 |
if the view should show up centered around aPoint."
|
|
287 |
|
|
288 |
self showAt:aPoint centerX:center centerY:center
|
|
289 |
|
|
290 |
"
|
|
291 |
|b|
|
|
292 |
|
|
293 |
b := InfoBox title:'hello'.
|
|
294 |
b showAt:(100 @ 100) center:true.
|
|
295 |
b showAt:(100 @ 100) center:false.
|
|
296 |
"
|
|
297 |
!
|
|
298 |
|
|
299 |
showAt:aPoint centerX:centerX centerY:centerY
|
|
300 |
"make myself visible at aPoint. centerX/centerY specify
|
|
301 |
if the view should show up centered around aPoint.
|
|
302 |
Fix position to make box fully visible"
|
|
303 |
|
|
304 |
|dx dy|
|
|
305 |
|
|
306 |
self fixSize.
|
|
307 |
centerX ifTrue:[
|
|
308 |
dx := self width // 2.
|
|
309 |
] ifFalse:[
|
|
310 |
dx := 0
|
|
311 |
].
|
|
312 |
centerY ifTrue:[
|
|
313 |
dy := self height // 2.
|
|
314 |
] ifFalse:[
|
|
315 |
dy := 0
|
|
316 |
].
|
|
317 |
self origin:(aPoint - (dx @ dy)).
|
|
318 |
self makeFullyVisible.
|
|
319 |
self openModal
|
|
320 |
|
|
321 |
"
|
|
322 |
|b|
|
|
323 |
|
|
324 |
b := InfoBox title:'hello'.
|
|
325 |
b showAt:(100 @ 100).
|
|
326 |
b showAt:(100 @ 100) centerX:true centerY:false.
|
|
327 |
"
|
54
|
328 |
!
|
|
329 |
|
|
330 |
showAtCenter
|
|
331 |
"make myself visible at the screen center."
|
|
332 |
|
72
|
333 |
self showAt:(device center) center:true
|
|
334 |
|
|
335 |
"
|
|
336 |
|b|
|
|
337 |
|
|
338 |
b := InfoBox title:'hello'.
|
|
339 |
b showAtCenter.
|
|
340 |
"
|
|
341 |
!
|
|
342 |
|
|
343 |
showCenteredIn:aView
|
|
344 |
"make myself visible at the screen center."
|
|
345 |
|
|
346 |
|top|
|
|
347 |
|
|
348 |
top := aView topView.
|
|
349 |
top raise.
|
|
350 |
self showAt:(top center + (aView originRelativeTo:top)) center:true
|
|
351 |
|
|
352 |
"
|
|
353 |
|b|
|
|
354 |
|
|
355 |
b := InfoBox title:'hello'.
|
|
356 |
b showCenteredIn:Transcript.
|
|
357 |
"
|
0
|
358 |
!
|
|
359 |
|
|
360 |
showAtPointer
|
12
|
361 |
"make myself visible at mouse pointer shifted to have
|
66
|
362 |
convenient button under cursor. self positionOffset should
|
|
363 |
return that offset (usually redefined, since we dont know here,
|
|
364 |
which button should be under cursor)."
|
12
|
365 |
|
|
366 |
self fixSize.
|
66
|
367 |
self fixPosition:(device pointerPosition - self positionOffset).
|
|
368 |
self openModal
|
72
|
369 |
|
|
370 |
"
|
|
371 |
|b|
|
|
372 |
|
|
373 |
b := InfoBox title:'hello'.
|
|
374 |
b showAtPointer.
|
|
375 |
"
|
0
|
376 |
!
|
|
377 |
|
|
378 |
showAtPointerNotCovering:aView
|
12
|
379 |
"make myself visible at mouse pointer shifted to have
|
|
380 |
convenient button under cursor.
|
54
|
381 |
Fix position to make box fully visible and to make sure that
|
12
|
382 |
aView is not covered."
|
|
383 |
|
54
|
384 |
|pos newX|
|
0
|
385 |
|
12
|
386 |
pos := device pointerPosition - self positionOffset.
|
54
|
387 |
|
|
388 |
((Rectangle origin:pos extent:self extent)
|
72
|
389 |
intersects: (aView origin corner: aView corner))
|
54
|
390 |
ifTrue:[
|
72
|
391 |
"
|
|
392 |
try to the right of the untouchable view
|
|
393 |
"
|
|
394 |
newX := (aView origin x + aView width).
|
|
395 |
newX + width > device width ifTrue:[
|
|
396 |
newX := device width - width
|
|
397 |
].
|
|
398 |
pos x:newX.
|
54
|
399 |
|
|
400 |
|
72
|
401 |
((Rectangle origin:pos extent:self extent)
|
|
402 |
intersects: (aView origin corner: aView corner))
|
|
403 |
ifTrue:[
|
|
404 |
"
|
|
405 |
try to the left of the untouchable view
|
|
406 |
"
|
|
407 |
newX := aView origin x - width.
|
|
408 |
"
|
|
409 |
should look for vertical possibilities too ...
|
|
410 |
"
|
|
411 |
pos x:newX.
|
|
412 |
]
|
54
|
413 |
|
0
|
414 |
].
|
12
|
415 |
self showAt:pos
|
0
|
416 |
!
|
|
417 |
|
|
418 |
hide
|
54
|
419 |
"make the receiver invisible and leave control"
|
0
|
420 |
|
59
|
421 |
|p|
|
|
422 |
|
12
|
423 |
shadowView notNil ifTrue:[shadowView unrealize].
|
0
|
424 |
self unrealize.
|
12
|
425 |
device synchronizeOutput.
|
59
|
426 |
|
|
427 |
(windowGroup notNil and:[(p := windowGroup previousGroup) notNil]) ifTrue:[
|
72
|
428 |
"
|
|
429 |
this is a kludge for IRIS which does not provide backingstore:
|
|
430 |
when we hide a modalbox (such as a searchbox) which covered
|
|
431 |
a scrollbar, the scrollbars bitblt-method will copy from the
|
|
432 |
not-yet redrawn area - effectively clearing the scroller.
|
|
433 |
We need a short delay here, since at this sime, the expose event has
|
|
434 |
not yet arrived.
|
|
435 |
"
|
|
436 |
(Delay forSeconds:0.1) wait.
|
|
437 |
p processExposeEvents
|
59
|
438 |
].
|
2
|
439 |
self leaveControl.
|
54
|
440 |
!
|
|
441 |
|
|
442 |
autoHideAfter:seconds with:anAction
|
|
443 |
"install a background process, which hides the box
|
|
444 |
after some time. Also, if non-nil, anAction will be
|
72
|
445 |
evaluated then. The action will not be evaluated if
|
|
446 |
the box is closed by the user pressing a button."
|
54
|
447 |
|
72
|
448 |
"the implementation is simple: just fork of a process
|
|
449 |
to hide me."
|
54
|
450 |
[
|
72
|
451 |
(Delay forSeconds:seconds) wait.
|
|
452 |
self shown ifTrue:[
|
|
453 |
self hide.
|
|
454 |
anAction notNil ifTrue:[anAction value]
|
|
455 |
]
|
54
|
456 |
] forkAt:4.
|
|
457 |
|
|
458 |
"
|
|
459 |
|b|
|
|
460 |
|
|
461 |
b := InfoBox title:'hello there'.
|
|
462 |
b autoHideAfter:5 with:[].
|
|
463 |
b showAtCenter.
|
|
464 |
"
|
|
465 |
! !
|
|
466 |
|
|
467 |
!ModalBox methodsFor:'events'!
|
|
468 |
|
72
|
469 |
visibilityChange:how
|
|
470 |
"raise when covered - this should not be needed, since we
|
|
471 |
have been created as override-redirect window (which should
|
|
472 |
stay on top - but some window managers (fvwm) seem to ignore
|
|
473 |
this ..."
|
|
474 |
|
|
475 |
"code below is not good, since it will lead to
|
|
476 |
oscillating raises when two modalBoxes are going to cover
|
|
477 |
each other - see coveredBy:-handling ..."
|
|
478 |
|
|
479 |
"/ how ~~ #fullyVisible ifTrue:[
|
|
480 |
"/ self raise
|
|
481 |
"/ ]
|
|
482 |
!
|
|
483 |
|
|
484 |
coveredBy:aView
|
|
485 |
"the receiver has been covered by another view.
|
|
486 |
If the other view is a non-modal one, raise"
|
|
487 |
|
|
488 |
|mainGroup topViews|
|
|
489 |
|
|
490 |
"
|
|
491 |
if the other view is not a modal- (or shadow-, or popup-) -view,
|
|
492 |
bring myself to the front again.
|
|
493 |
"
|
|
494 |
aView createOnTop ifFalse:[
|
|
495 |
"
|
|
496 |
if I have a mainGroup,
|
|
497 |
only raise if its one of my maingroup-views
|
|
498 |
"
|
|
499 |
windowGroup notNil ifTrue:[
|
|
500 |
mainGroup := windowGroup mainGroup.
|
|
501 |
mainGroup notNil ifTrue:[
|
|
502 |
topViews := mainGroup topViews.
|
|
503 |
topViews notNil ifTrue:[
|
|
504 |
topViews do:[:aTopView |
|
|
505 |
aView == aTopView ifTrue:[
|
|
506 |
self raise.
|
|
507 |
^ self
|
|
508 |
]
|
|
509 |
]
|
|
510 |
].
|
|
511 |
^ self
|
|
512 |
]
|
|
513 |
].
|
|
514 |
self raise
|
|
515 |
]
|
|
516 |
!
|
|
517 |
|
54
|
518 |
pointerEnter:state x:x y:y
|
|
519 |
"
|
|
520 |
mhmh: this seems to be a special X kludge;
|
|
521 |
without the following, we will not regain input focus after
|
|
522 |
pointer is reentered"
|
|
523 |
|
|
524 |
device setInputFocusTo:drawableId.
|
|
525 |
super pointerEnter:state x:x y:y
|
0
|
526 |
! !
|
|
527 |
|
|
528 |
!ModalBox methodsFor:'private'!
|
|
529 |
|
54
|
530 |
leaveControl
|
|
531 |
|g|
|
12
|
532 |
|
54
|
533 |
windowGroup notNil ifTrue:[
|
72
|
534 |
g := windowGroup mainGroup.
|
|
535 |
g notNil ifTrue:[
|
|
536 |
g restoreCursors
|
|
537 |
]
|
12
|
538 |
].
|
0
|
539 |
haveControl := false.
|
12
|
540 |
exclusiveKeyboard ifTrue:[
|
72
|
541 |
device ungrabKeyboard
|
12
|
542 |
]
|
0
|
543 |
! !
|