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
|
12
|
14 |
instanceVariableNames:'haveControl shadowView exclusiveKeyboard'
|
0
|
15 |
classVariableNames:'PopShadow'
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Views-Basic'
|
|
18 |
!
|
|
19 |
|
|
20 |
ModalBox comment:'
|
|
21 |
|
6
|
22 |
COPYRIGHT (c) 1990 by Claus Gittinger
|
0
|
23 |
All Rights Reserved
|
|
24 |
|
17
|
25 |
$Header: /cvs/stx/stx/libview/ModalBox.st,v 1.6 1993-12-13 17:10:15 claus Exp $
|
2
|
26 |
|
|
27 |
written Jan 90 by claus
|
|
28 |
'!
|
|
29 |
|
|
30 |
!ModalBox class methodsFor:'documentation'!
|
|
31 |
|
|
32 |
documentation
|
|
33 |
"
|
|
34 |
this class implements modal boxes; ModalBoxes are different from
|
|
35 |
others, in that they take complete control over the display, until
|
|
36 |
all processing is done (i.e. other views will not get any events
|
|
37 |
while the box is active).
|
0
|
38 |
|
|
39 |
class variables:
|
|
40 |
|
|
41 |
PopShadow <Boolean> if true, modalBoxes will show a shadow
|
|
42 |
|
2
|
43 |
"
|
|
44 |
! !
|
|
45 |
|
|
46 |
!ModalBox class methodsFor:'initialization'!
|
0
|
47 |
|
2
|
48 |
initialize
|
|
49 |
super initialize.
|
12
|
50 |
Display notNil ifTrue:[
|
|
51 |
PopShadow := self classResources name:'POPUP_SHADOW' default:false
|
|
52 |
]
|
2
|
53 |
! !
|
0
|
54 |
|
|
55 |
!ModalBox class methodsFor:'instance creation'!
|
|
56 |
|
|
57 |
new
|
|
58 |
^ super on:ModalDisplay
|
|
59 |
! !
|
|
60 |
|
|
61 |
!ModalBox methodsFor:'initialize / release'!
|
|
62 |
|
|
63 |
initialize
|
|
64 |
super initialize.
|
|
65 |
|
|
66 |
haveControl := false.
|
12
|
67 |
exclusiveKeyboard := false.
|
|
68 |
|
|
69 |
PopShadow ifTrue:[
|
|
70 |
shadowView := (ShadowView on:device) for:self
|
|
71 |
]
|
|
72 |
!
|
|
73 |
|
|
74 |
initStyle
|
|
75 |
super initStyle.
|
0
|
76 |
self is3D ifTrue:[
|
|
77 |
borderWidth := 0.
|
|
78 |
self level:2
|
|
79 |
]
|
|
80 |
!
|
|
81 |
|
|
82 |
initEvents
|
|
83 |
super initEvents.
|
|
84 |
self enableKeyEvents
|
|
85 |
!
|
|
86 |
|
|
87 |
addToCurrentProject
|
|
88 |
"ignored here"
|
|
89 |
|
|
90 |
^ self
|
|
91 |
!
|
|
92 |
|
|
93 |
destroy
|
12
|
94 |
shadowView notNil ifTrue:[
|
|
95 |
shadowView destroy.
|
|
96 |
shadowView := nil
|
|
97 |
].
|
|
98 |
self leaveControl. "just to make sure"
|
0
|
99 |
super destroy.
|
|
100 |
!
|
|
101 |
|
|
102 |
create
|
|
103 |
super create.
|
2
|
104 |
PopShadow ifFalse:[
|
|
105 |
self saveUnder:true
|
|
106 |
]
|
0
|
107 |
!
|
|
108 |
|
|
109 |
createOnTop
|
|
110 |
^ true
|
|
111 |
! !
|
|
112 |
|
|
113 |
!ModalBox methodsFor:'show / hide'!
|
|
114 |
|
|
115 |
mapped
|
|
116 |
"wait till visible for grabbing"
|
|
117 |
|
|
118 |
super mapped.
|
12
|
119 |
|
|
120 |
"take it away from any popup menu possibly still active"
|
|
121 |
|
|
122 |
device ungrabKeyboard.
|
|
123 |
ActiveGrab := nil.
|
|
124 |
device grabPointerIn:drawableId.
|
|
125 |
device ungrabPointer.
|
|
126 |
|
|
127 |
exclusiveKeyboard ifTrue:[
|
|
128 |
device grabKeyboardIn:drawableId.
|
|
129 |
].
|
|
130 |
|
|
131 |
"this will be changed as soon as I find out, where the
|
|
132 |
timing problem is .... close your eyes please"
|
|
133 |
|
|
134 |
ActiveGrab := nil.
|
|
135 |
ModalDisplay ungrabPointer.
|
|
136 |
ModalDisplay synchronizeOutput.
|
|
137 |
Display ungrabPointer.
|
|
138 |
Display synchronizeOutput.
|
|
139 |
|
0
|
140 |
device setInputFocusTo:drawableId.
|
|
141 |
!
|
|
142 |
|
12
|
143 |
fixPosition:aPoint
|
|
144 |
"make sure, that the box is visible by shifting it
|
17
|
145 |
into the visible screen area if nescessary"
|
0
|
146 |
|
|
147 |
self origin:aPoint.
|
|
148 |
((top + height) > (device height)) ifTrue:[
|
|
149 |
self top:(device height - height)
|
|
150 |
].
|
|
151 |
((left + width) > (device width)) ifTrue:[
|
|
152 |
self left:(device width - width)
|
|
153 |
].
|
|
154 |
(top < 0) ifTrue:[
|
|
155 |
self top:0
|
|
156 |
].
|
|
157 |
(left < 0) ifTrue:[
|
|
158 |
self left:0
|
|
159 |
].
|
12
|
160 |
!
|
|
161 |
|
|
162 |
positionOffset
|
|
163 |
"return the delta, by which the box should be
|
|
164 |
displaced from the mouse pointer. Usually redefined in
|
|
165 |
subclasses to have some ok-button appear under
|
|
166 |
the pointer."
|
|
167 |
|
|
168 |
^ (width // 2) @ (height // 2)
|
|
169 |
!
|
|
170 |
|
|
171 |
show
|
|
172 |
"make myself visible (at the last position) and take control"
|
|
173 |
|
|
174 |
self fixSize.
|
|
175 |
self makeVisible
|
|
176 |
!
|
|
177 |
|
|
178 |
showAt:aPoint
|
|
179 |
"make myself visible at aPoint.
|
|
180 |
Fix position to make box fully visible"
|
|
181 |
|
|
182 |
self fixSize.
|
|
183 |
self fixPosition:aPoint.
|
|
184 |
self makeVisible
|
0
|
185 |
!
|
|
186 |
|
|
187 |
showAtPointer
|
12
|
188 |
"make myself visible at mouse pointer shifted to have
|
|
189 |
convenient button under cursor.
|
|
190 |
Fix position to make box fully visible"
|
|
191 |
|
|
192 |
self fixSize.
|
|
193 |
self showAt:(device pointerPosition - self positionOffset).
|
0
|
194 |
!
|
|
195 |
|
|
196 |
showAtPointerNotCovering:aView
|
12
|
197 |
"make myself visible at mouse pointer shifted to have
|
|
198 |
convenient button under cursor.
|
|
199 |
Fix position to make box fully visible or to make sure that
|
|
200 |
aView is not covered."
|
|
201 |
|
|
202 |
|pos|
|
0
|
203 |
|
12
|
204 |
pos := device pointerPosition - self positionOffset.
|
|
205 |
((Rectangle origin:pos extent:self extent) intersects:
|
0
|
206 |
(aView origin corner: aView corner)) ifTrue:[
|
12
|
207 |
pos x:(aView origin x + aView width)
|
0
|
208 |
].
|
12
|
209 |
self showAt:pos
|
0
|
210 |
!
|
|
211 |
|
|
212 |
hide
|
|
213 |
"make myself invisible and leave control"
|
|
214 |
|
12
|
215 |
shadowView notNil ifTrue:[shadowView unrealize].
|
0
|
216 |
self unrealize.
|
12
|
217 |
device synchronizeOutput.
|
2
|
218 |
self leaveControl.
|
0
|
219 |
! !
|
|
220 |
|
|
221 |
!ModalBox methodsFor:'private'!
|
|
222 |
|
12
|
223 |
makeVisible
|
|
224 |
"make myself visible (at the last position) and take control"
|
|
225 |
|
|
226 |
Display synchronizeOutput. "show all buffered drawing"
|
|
227 |
shadowView notNil ifTrue:[shadowView realize].
|
|
228 |
self raise.
|
|
229 |
self realize.
|
|
230 |
self takeControl
|
|
231 |
!
|
|
232 |
|
0
|
233 |
takeControl
|
|
234 |
haveControl := true.
|
|
235 |
|
|
236 |
"
|
12
|
237 |
exclusiveKeyboard ifTrue:[
|
|
238 |
device grabKeyboardIn:drawableId.
|
|
239 |
].
|
0
|
240 |
device setInputFocusTo:drawableId.
|
|
241 |
"
|
|
242 |
|
12
|
243 |
"this will be changed as soon as I find out, where the
|
|
244 |
timing problem is .... close your eyes please"
|
|
245 |
|
|
246 |
ActiveGrab := nil.
|
|
247 |
device ungrabKeyboard.
|
|
248 |
device grabPointerIn:drawableId.
|
|
249 |
device ungrabPointer.
|
|
250 |
|
|
251 |
|
0
|
252 |
"this is a kludge - we do not have multiple processes, therefore
|
|
253 |
we start another dispatch loop, which exits when control is lost"
|
|
254 |
|
|
255 |
device dispatchWhile:[haveControl]
|
|
256 |
!
|
|
257 |
|
|
258 |
leaveControl
|
|
259 |
haveControl := false.
|
12
|
260 |
exclusiveKeyboard ifTrue:[
|
|
261 |
device ungrabKeyboard
|
|
262 |
]
|
0
|
263 |
! !
|