0
|
1 |
"
|
6
|
2 |
COPYRIGHT (c) 1990 by Claus Gittinger
|
0
|
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 |
StandardSystemView subclass:#ModalBox
|
54
|
14 |
instanceVariableNames:'haveControl shadowView exclusiveKeyboard '
|
0
|
15 |
classVariableNames:'PopShadow'
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Views-Basic'
|
|
18 |
!
|
|
19 |
|
|
20 |
ModalBox comment:'
|
6
|
21 |
COPYRIGHT (c) 1990 by Claus Gittinger
|
0
|
22 |
All Rights Reserved
|
54
|
23 |
|
|
24 |
$Header: /cvs/stx/stx/libview/ModalBox.st,v 1.9 1994-08-05 01:14:33 claus Exp $
|
2
|
25 |
'!
|
|
26 |
|
|
27 |
!ModalBox class methodsFor:'documentation'!
|
|
28 |
|
46
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1990 by Claus Gittinger
|
|
32 |
All Rights Reserved
|
|
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 |
"
|
54
|
45 |
$Header: /cvs/stx/stx/libview/ModalBox.st,v 1.9 1994-08-05 01:14:33 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).
|
0
|
55 |
|
46
|
56 |
class variables:
|
0
|
57 |
|
46
|
58 |
PopShadow <Boolean> if true, modalBoxes will show a shadow
|
2
|
59 |
"
|
|
60 |
! !
|
|
61 |
|
|
62 |
!ModalBox class methodsFor:'initialization'!
|
0
|
63 |
|
2
|
64 |
initialize
|
|
65 |
super initialize.
|
12
|
66 |
Display notNil ifTrue:[
|
|
67 |
PopShadow := self classResources name:'POPUP_SHADOW' default:false
|
|
68 |
]
|
2
|
69 |
! !
|
0
|
70 |
|
|
71 |
!ModalBox methodsFor:'initialize / release'!
|
|
72 |
|
|
73 |
initialize
|
|
74 |
super initialize.
|
|
75 |
|
|
76 |
haveControl := false.
|
12
|
77 |
exclusiveKeyboard := false.
|
|
78 |
|
|
79 |
PopShadow ifTrue:[
|
|
80 |
shadowView := (ShadowView on:device) for:self
|
|
81 |
]
|
|
82 |
!
|
|
83 |
|
|
84 |
initStyle
|
|
85 |
super initStyle.
|
46
|
86 |
((style ~~ #normal) and:[style ~~ #mswindows]) ifTrue:[
|
0
|
87 |
borderWidth := 0.
|
|
88 |
self level:2
|
|
89 |
]
|
|
90 |
!
|
|
91 |
|
|
92 |
addToCurrentProject
|
|
93 |
"ignored here"
|
|
94 |
|
|
95 |
^ self
|
|
96 |
!
|
|
97 |
|
|
98 |
destroy
|
12
|
99 |
shadowView notNil ifTrue:[
|
|
100 |
shadowView destroy.
|
|
101 |
shadowView := nil
|
|
102 |
].
|
|
103 |
self leaveControl. "just to make sure"
|
0
|
104 |
super destroy.
|
|
105 |
!
|
|
106 |
|
|
107 |
create
|
|
108 |
super create.
|
2
|
109 |
PopShadow ifFalse:[
|
|
110 |
self saveUnder:true
|
|
111 |
]
|
0
|
112 |
!
|
|
113 |
|
|
114 |
createOnTop
|
|
115 |
^ true
|
|
116 |
! !
|
|
117 |
|
54
|
118 |
!ModalBox methodsFor:'accessing'!
|
|
119 |
|
|
120 |
exclusiveKeyboard:aBoolean
|
|
121 |
"set/clear exclusive locking of the keyboard;
|
|
122 |
If set, the box will take total control over the
|
|
123 |
keyboard, not allowing input to other views/boxes
|
|
124 |
while active.
|
|
125 |
Danger: only use this for very very urgent boxes, since
|
|
126 |
no interaction with any view on the screen is possible then."
|
|
127 |
|
|
128 |
exclusiveKeyboard := aBoolean
|
|
129 |
! !
|
|
130 |
|
0
|
131 |
!ModalBox methodsFor:'show / hide'!
|
|
132 |
|
|
133 |
mapped
|
|
134 |
"wait till visible for grabbing"
|
|
135 |
|
|
136 |
super mapped.
|
12
|
137 |
|
|
138 |
"take it away from any popup menu possibly still active"
|
|
139 |
|
46
|
140 |
ActiveGrab notNil ifTrue:[
|
|
141 |
device ungrabKeyboard.
|
|
142 |
ActiveGrab := nil.
|
|
143 |
].
|
12
|
144 |
|
54
|
145 |
"
|
|
146 |
if I am a super-modal box, take the keyboard
|
|
147 |
"
|
12
|
148 |
exclusiveKeyboard ifTrue:[
|
|
149 |
device grabKeyboardIn:drawableId.
|
|
150 |
].
|
|
151 |
|
54
|
152 |
"
|
|
153 |
get the focus
|
|
154 |
"
|
0
|
155 |
device setInputFocusTo:drawableId.
|
54
|
156 |
self enableEnterLeaveEvents
|
0
|
157 |
!
|
|
158 |
|
12
|
159 |
fixPosition:aPoint
|
|
160 |
"make sure, that the box is visible by shifting it
|
17
|
161 |
into the visible screen area if nescessary"
|
0
|
162 |
|
|
163 |
self origin:aPoint.
|
54
|
164 |
self makeFullyVisible
|
12
|
165 |
!
|
|
166 |
|
|
167 |
positionOffset
|
|
168 |
"return the delta, by which the box should be
|
|
169 |
displaced from the mouse pointer. Usually redefined in
|
|
170 |
subclasses to have some ok-button appear under
|
|
171 |
the pointer."
|
|
172 |
|
|
173 |
^ (width // 2) @ (height // 2)
|
|
174 |
!
|
|
175 |
|
46
|
176 |
open
|
|
177 |
"default for modalboxes is to come up modal"
|
|
178 |
|
|
179 |
^ self openModal
|
|
180 |
!
|
|
181 |
|
54
|
182 |
openModal
|
|
183 |
"open the box modal;
|
|
184 |
In addition to the basic (inherited) modalloop, change
|
|
185 |
the current maingroups cursors to the busy-stop cursor, show
|
|
186 |
a shadow, and raise the box."
|
|
187 |
|
|
188 |
|g|
|
|
189 |
|
|
190 |
g := WindowGroup activeGroup.
|
|
191 |
g notNil ifTrue:[
|
|
192 |
g := g mainGroup.
|
|
193 |
g notNil ifTrue:[
|
|
194 |
g showCursor:(Cursor stop)
|
|
195 |
]
|
|
196 |
].
|
|
197 |
shadowView notNil ifTrue:[shadowView realize].
|
|
198 |
self raise.
|
|
199 |
haveControl := true.
|
|
200 |
super openModal.
|
|
201 |
!
|
|
202 |
|
12
|
203 |
show
|
|
204 |
"make myself visible (at the last position) and take control"
|
|
205 |
|
|
206 |
self fixSize.
|
54
|
207 |
self openModal
|
12
|
208 |
!
|
|
209 |
|
|
210 |
showAt:aPoint
|
|
211 |
"make myself visible at aPoint.
|
|
212 |
Fix position to make box fully visible"
|
|
213 |
|
|
214 |
self fixSize.
|
|
215 |
self fixPosition:aPoint.
|
54
|
216 |
self openModal
|
|
217 |
!
|
|
218 |
|
|
219 |
showAtCenter
|
|
220 |
"make myself visible at the screen center."
|
|
221 |
|
|
222 |
self fixSize.
|
|
223 |
self showAt:(device center - (self extent / 2))
|
0
|
224 |
!
|
|
225 |
|
|
226 |
showAtPointer
|
12
|
227 |
"make myself visible at mouse pointer shifted to have
|
|
228 |
convenient button under cursor.
|
|
229 |
Fix position to make box fully visible"
|
|
230 |
|
|
231 |
self fixSize.
|
|
232 |
self showAt:(device pointerPosition - self positionOffset).
|
0
|
233 |
!
|
|
234 |
|
|
235 |
showAtPointerNotCovering:aView
|
12
|
236 |
"make myself visible at mouse pointer shifted to have
|
|
237 |
convenient button under cursor.
|
54
|
238 |
Fix position to make box fully visible and to make sure that
|
12
|
239 |
aView is not covered."
|
|
240 |
|
54
|
241 |
|pos newX|
|
0
|
242 |
|
12
|
243 |
pos := device pointerPosition - self positionOffset.
|
54
|
244 |
|
|
245 |
((Rectangle origin:pos extent:self extent)
|
|
246 |
intersects: (aView origin corner: aView corner))
|
|
247 |
ifTrue:[
|
|
248 |
"
|
|
249 |
try to the right of the untouchable view
|
|
250 |
"
|
|
251 |
newX := (aView origin x + aView width).
|
|
252 |
newX + width > device width ifTrue:[
|
|
253 |
newX := device width - width
|
|
254 |
].
|
|
255 |
pos x:newX.
|
|
256 |
|
|
257 |
|
|
258 |
((Rectangle origin:pos extent:self extent)
|
|
259 |
intersects: (aView origin corner: aView corner))
|
|
260 |
ifTrue:[
|
|
261 |
"
|
|
262 |
try to the left of the untouchable view
|
|
263 |
"
|
|
264 |
newX := aView origin x - width.
|
|
265 |
"
|
|
266 |
should look for vertical possibilities too ...
|
|
267 |
"
|
|
268 |
pos x:newX.
|
|
269 |
]
|
|
270 |
|
0
|
271 |
].
|
12
|
272 |
self showAt:pos
|
0
|
273 |
!
|
|
274 |
|
|
275 |
hide
|
54
|
276 |
"make the receiver invisible and leave control"
|
0
|
277 |
|
12
|
278 |
shadowView notNil ifTrue:[shadowView unrealize].
|
0
|
279 |
self unrealize.
|
12
|
280 |
device synchronizeOutput.
|
2
|
281 |
self leaveControl.
|
54
|
282 |
!
|
|
283 |
|
|
284 |
autoHideAfter:seconds with:anAction
|
|
285 |
"install a background process, which hides the box
|
|
286 |
after some time. Also, if non-nil, anAction will be
|
|
287 |
evaluated then."
|
|
288 |
|
|
289 |
[
|
|
290 |
(Delay forSeconds:seconds) wait.
|
|
291 |
self shown ifTrue:[
|
|
292 |
self hide.
|
|
293 |
anAction notNil ifTrue:[anAction value]
|
|
294 |
]
|
|
295 |
] forkAt:4.
|
|
296 |
|
|
297 |
"
|
|
298 |
|b|
|
|
299 |
|
|
300 |
b := InfoBox title:'hello there'.
|
|
301 |
b autoHideAfter:5 with:[].
|
|
302 |
b showAtCenter.
|
|
303 |
"
|
|
304 |
! !
|
|
305 |
|
|
306 |
!ModalBox methodsFor:'events'!
|
|
307 |
|
|
308 |
pointerEnter:state x:x y:y
|
|
309 |
"
|
|
310 |
mhmh: this seems to be a special X kludge;
|
|
311 |
without the following, we will not regain input focus after
|
|
312 |
pointer is reentered"
|
|
313 |
|
|
314 |
device setInputFocusTo:drawableId.
|
|
315 |
super pointerEnter:state x:x y:y
|
0
|
316 |
! !
|
|
317 |
|
|
318 |
!ModalBox methodsFor:'private'!
|
|
319 |
|
54
|
320 |
leaveControl
|
|
321 |
|g|
|
12
|
322 |
|
54
|
323 |
windowGroup notNil ifTrue:[
|
|
324 |
g := windowGroup mainGroup.
|
|
325 |
g notNil ifTrue:[
|
|
326 |
g restoreCursors
|
|
327 |
]
|
12
|
328 |
].
|
0
|
329 |
haveControl := false.
|
12
|
330 |
exclusiveKeyboard ifTrue:[
|
|
331 |
device ungrabKeyboard
|
|
332 |
]
|
0
|
333 |
! !
|