0
|
1 |
"
|
6
|
2 |
COPYRIGHT (c) 1989 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 |
|
135
|
13 |
TopView subclass:#PopUpView
|
157
|
14 |
instanceVariableNames:'shadowView haveControl exclusivePointer'
|
81
|
15 |
classVariableNames:'DefaultShadow DefaultLevel DefaultBorderWidth
|
|
16 |
DefaultBorderColor'
|
0
|
17 |
poolDictionaries:''
|
|
18 |
category:'Views-Basic'
|
|
19 |
!
|
|
20 |
|
|
21 |
PopUpView comment:'
|
6
|
22 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
72
|
23 |
All Rights Reserved
|
54
|
24 |
|
157
|
25 |
$Header: /cvs/stx/stx/libview/PopUpView.st,v 1.15 1995-07-23 02:28:02 claus Exp $
|
0
|
26 |
'!
|
|
27 |
|
2
|
28 |
!PopUpView class methodsFor:'documentation'!
|
|
29 |
|
46
|
30 |
copyright
|
|
31 |
"
|
|
32 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
72
|
33 |
All Rights Reserved
|
46
|
34 |
|
|
35 |
This software is furnished under a license and may be used
|
|
36 |
only in accordance with the terms of that license and with the
|
|
37 |
inclusion of the above copyright notice. This software may not
|
|
38 |
be provided or otherwise made available to, or used by, any
|
|
39 |
other person. No title to or ownership of the software is
|
|
40 |
hereby transferred.
|
|
41 |
"
|
|
42 |
!
|
|
43 |
|
|
44 |
version
|
|
45 |
"
|
157
|
46 |
$Header: /cvs/stx/stx/libview/PopUpView.st,v 1.15 1995-07-23 02:28:02 claus Exp $
|
46
|
47 |
"
|
|
48 |
!
|
|
49 |
|
2
|
50 |
documentation
|
|
51 |
"
|
46
|
52 |
this class implements an abstract superclass for all views which bypass the
|
89
|
53 |
window manager and pop up on top of the screen. A typical example is
|
|
54 |
a PopUpMenu. PopUpView itself is abstract, providing basic mechanisms.
|
|
55 |
They are not decorated by window managers.
|
2
|
56 |
|
81
|
57 |
styleSheet parameters:
|
2
|
58 |
|
81
|
59 |
popupShadow <Boolean> if true, popupViews show a shadow below
|
|
60 |
popupLevel <nil | Integer> 3D level
|
|
61 |
popupBorderWidth <nil | Integer> borderWidth
|
2
|
62 |
"
|
|
63 |
! !
|
|
64 |
|
0
|
65 |
!PopUpView class methodsFor:'defaults'!
|
|
66 |
|
|
67 |
defaultExtent
|
135
|
68 |
^ (Display width // 3) @ (Display height // 3)
|
81
|
69 |
!
|
0
|
70 |
|
81
|
71 |
updateStyleCache
|
135
|
72 |
ShadowView isNil ifTrue:[
|
|
73 |
DefaultShadow := false
|
|
74 |
] ifFalse:[
|
|
75 |
DefaultShadow := StyleSheet at:'popupShadow' default:false.
|
|
76 |
].
|
81
|
77 |
DefaultLevel := StyleSheet at:'popupLevel'.
|
|
78 |
DefaultBorderWidth := StyleSheet at:'popupBorderWidth'.
|
|
79 |
DefaultBorderColor := StyleSheet colorAt:'popupBorderColor'.
|
144
|
80 |
!
|
|
81 |
|
|
82 |
shadows:aBoolean
|
|
83 |
"turn on/off shadows under popUpViews.
|
|
84 |
On slow displays, turning them off makes menus appear a bit snappier.
|
|
85 |
The default is set via the styleSheet and changes when the viewStyle
|
|
86 |
is changed."
|
|
87 |
|
|
88 |
DefaultShadow := aBoolean
|
|
89 |
!
|
|
90 |
|
|
91 |
shadows
|
|
92 |
"return the shadows-flag. False means: turned off."
|
|
93 |
|
|
94 |
^ DefaultShadow
|
0
|
95 |
! !
|
|
96 |
|
89
|
97 |
!PopUpView methodsFor:'initialize / release'!
|
0
|
98 |
|
|
99 |
initialize
|
|
100 |
super initialize.
|
157
|
101 |
exclusivePointer := true.
|
141
|
102 |
haveControl := false.
|
|
103 |
type := #popup
|
81
|
104 |
!
|
|
105 |
|
|
106 |
initStyle
|
|
107 |
super initStyle.
|
|
108 |
|
151
|
109 |
styleSheet is3D == true ifTrue:[
|
72
|
110 |
borderWidth := 0.
|
81
|
111 |
level := 2
|
0
|
112 |
] ifFalse:[
|
81
|
113 |
borderWidth := 1.
|
|
114 |
level := 0
|
0
|
115 |
].
|
|
116 |
|
81
|
117 |
DefaultBorderColor notNil ifTrue:[
|
|
118 |
self borderColor:(DefaultBorderColor on:device).
|
|
119 |
].
|
|
120 |
DefaultBorderWidth notNil ifTrue:[
|
|
121 |
borderWidth := DefaultBorderWidth.
|
|
122 |
].
|
|
123 |
"/ DefaultEdgeStyle notNil ifTrue:[
|
|
124 |
"/ edgeStyle := DefaultEdgeStyle.
|
|
125 |
"/ ].
|
|
126 |
DefaultLevel notNil ifTrue:[
|
|
127 |
self level:DefaultLevel.
|
|
128 |
].
|
|
129 |
|
|
130 |
DefaultShadow ifTrue:[
|
135
|
131 |
shadowView := (ShadowView onDevice:device) for:self.
|
0
|
132 |
].
|
|
133 |
!
|
|
134 |
|
|
135 |
destroy
|
|
136 |
haveControl := false.
|
|
137 |
super destroy.
|
12
|
138 |
shadowView notNil ifTrue:[shadowView destroy. shadowView := nil]
|
0
|
139 |
!
|
|
140 |
|
|
141 |
create
|
|
142 |
super create.
|
12
|
143 |
shadowView isNil ifTrue:[
|
72
|
144 |
self saveUnder:true
|
2
|
145 |
]
|
0
|
146 |
! !
|
|
147 |
|
|
148 |
!PopUpView methodsFor:'dispatching'!
|
|
149 |
|
|
150 |
modalLoop
|
|
151 |
haveControl := true.
|
|
152 |
|
|
153 |
"this is a kludge - we do not have multiple processes, therefore
|
|
154 |
we start another dispatch loop, which exits when control is lost"
|
|
155 |
|
12
|
156 |
device dispatchFor:nil while:[haveControl]
|
0
|
157 |
! !
|
|
158 |
|
|
159 |
!PopUpView methodsFor:'private'!
|
|
160 |
|
|
161 |
takeControl
|
|
162 |
^ self.
|
|
163 |
haveControl := true.
|
|
164 |
|
|
165 |
"this is a kludge - we do not have multiple processes, therefore
|
|
166 |
we start another dispatch loop, which exits when control is lost"
|
|
167 |
|
|
168 |
device dispatchFor:drawableId while:[haveControl]
|
|
169 |
!
|
|
170 |
|
|
171 |
leaveControl
|
|
172 |
haveControl := false
|
89
|
173 |
!
|
|
174 |
|
|
175 |
regainControl
|
|
176 |
device grabPointerInView:self
|
|
177 |
! !
|
|
178 |
|
|
179 |
!PopUpView methodsFor:'activation'!
|
|
180 |
|
|
181 |
show
|
|
182 |
"realize the view at its last position"
|
|
183 |
|
|
184 |
self fixSize.
|
|
185 |
self openModal:[true] "realize "
|
|
186 |
!
|
|
187 |
|
|
188 |
showAt:aPoint resizing:aBoolean
|
|
189 |
"realize the view at aPoint"
|
|
190 |
|
|
191 |
aBoolean ifTrue:[
|
|
192 |
self fixSize.
|
|
193 |
].
|
|
194 |
self origin:aPoint.
|
|
195 |
self makeFullyVisible.
|
|
196 |
self openModal:[true] "realize "
|
|
197 |
!
|
|
198 |
|
|
199 |
showAt:aPoint
|
|
200 |
"realize the view at aPoint"
|
|
201 |
|
|
202 |
self showAt:aPoint resizing:true
|
|
203 |
!
|
|
204 |
|
|
205 |
showCenteredIn:aView
|
|
206 |
"make myself visible at the screen center."
|
|
207 |
|
|
208 |
|top|
|
|
209 |
|
|
210 |
top := aView topView.
|
|
211 |
top raise.
|
|
212 |
self showAt:(top origin
|
|
213 |
+ (aView originRelativeTo:top)
|
|
214 |
+ (aView extent // 2)
|
|
215 |
- (self extent // 2))
|
|
216 |
!
|
|
217 |
|
|
218 |
showAtPointer
|
|
219 |
"realize the view at the current pointer position"
|
|
220 |
|
|
221 |
self showAt:(device pointerPosition) resizing:true
|
|
222 |
!
|
|
223 |
|
|
224 |
hide
|
|
225 |
"hide the view, leave its modal event loop"
|
|
226 |
|
|
227 |
windowGroup notNil ifTrue:[
|
|
228 |
windowGroup removeView:self.
|
|
229 |
windowGroup := nil.
|
|
230 |
].
|
|
231 |
self unrealize.
|
0
|
232 |
! !
|
|
233 |
|
|
234 |
!PopUpView methodsFor:'realize / unrealize'!
|
|
235 |
|
|
236 |
mapped
|
141
|
237 |
"wait till visible for grabbing. If the grab fails,
|
|
238 |
try again and unrealize myself if that fails too."
|
0
|
239 |
|
|
240 |
super mapped.
|
157
|
241 |
(haveControl
|
|
242 |
and:[exclusivePointer
|
|
243 |
and:[realized]]) ifTrue:[
|
141
|
244 |
(device grabPointerInView:self) ifFalse:[
|
|
245 |
"wait a little bit and try again"
|
157
|
246 |
"/ 'grab pointer failed' errorPrintNL.
|
141
|
247 |
(Delay forSeconds:0.1) wait.
|
|
248 |
(device grabPointerInView:self) ifFalse:[
|
|
249 |
"give up"
|
|
250 |
'could not grab pointer' errorPrintNL.
|
|
251 |
self unrealize
|
|
252 |
]
|
|
253 |
]
|
81
|
254 |
]
|
0
|
255 |
!
|
|
256 |
|
|
257 |
realize
|
|
258 |
shadowView notNil ifTrue:[shadowView realize].
|
|
259 |
self raise.
|
81
|
260 |
haveControl := true.
|
0
|
261 |
super realize.
|
|
262 |
!
|
|
263 |
|
|
264 |
unrealize
|
|
265 |
haveControl := false.
|
81
|
266 |
device activePointerGrab == self ifTrue:[
|
72
|
267 |
device ungrabPointer.
|
12
|
268 |
].
|
2
|
269 |
super unrealize.
|
|
270 |
shadowView notNil ifTrue:[shadowView unrealize].
|
0
|
271 |
! !
|
|
272 |
|
|
273 |
!PopUpView methodsFor:'accessing'!
|
|
274 |
|
135
|
275 |
noShadow
|
|
276 |
"turn off the shadow"
|
0
|
277 |
|
135
|
278 |
shadowView := nil
|
0
|
279 |
!
|
|
280 |
|
157
|
281 |
exclusivePointer:aBoolean
|
|
282 |
exclusivePointer := aBoolean
|
|
283 |
! !
|
|
284 |
|
|
285 |
!PopUpView methodsFor:'queries'!
|
|
286 |
|
|
287 |
isPopUpView
|
0
|
288 |
^ true
|
|
289 |
! !
|