author | Claus Gittinger <cg@exept.de> |
Fri, 02 Oct 1998 12:55:34 +0200 | |
changeset 2387 | cfd8fa32799b |
parent 2335 | 73978e370059 |
child 2412 | 3065f9e362dc |
permissions | -rw-r--r-- |
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 |
506 | 14 |
instanceVariableNames:'shadowView haveControl exclusivePointer mapTime' |
485 | 15 |
classVariableNames:'DefaultShadow DefaultLevel DefaultBorderWidth DefaultBorderColor' |
16 |
poolDictionaries:'' |
|
17 |
category:'Views-Basic' |
|
0 | 18 |
! |
19 |
||
1174
6889dc61d701
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
20 |
!PopUpView class methodsFor:'documentation'! |
2 | 21 |
|
46 | 22 |
copyright |
23 |
" |
|
24 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
72 | 25 |
All Rights Reserved |
46 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
2 | 36 |
documentation |
37 |
" |
|
46 | 38 |
this class implements an abstract superclass for all views which bypass the |
89 | 39 |
window manager and pop up on top of the screen. A typical example is |
40 |
a PopUpMenu. PopUpView itself is abstract, providing basic mechanisms. |
|
41 |
They are not decorated by window managers. |
|
2 | 42 |
|
616 | 43 |
[styleSheet parameters:] |
2 | 44 |
|
616 | 45 |
popupShadow <Boolean> if true, popupViews show a shadow below |
46 |
popupLevel <nil | Integer> 3D level |
|
47 |
popupBorderWidth <nil | Integer> borderWidth |
|
48 |
||
49 |
[author:] |
|
50 |
Claus Gittinger |
|
2 | 51 |
" |
52 |
! ! |
|
53 |
||
1174
6889dc61d701
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
54 |
!PopUpView class methodsFor:'defaults'! |
0 | 55 |
|
56 |
defaultExtent |
|
587 | 57 |
"return the default extent of my instances. |
58 |
The value returned here is usually ignored, and |
|
59 |
the value from preferredExtent taken instead." |
|
60 |
||
922
52c1d0d22c0e
dont ask Display for defaultExtent - ask current screen
Claus Gittinger <cg@exept.de>
parents:
677
diff
changeset
|
61 |
|screen| |
587 | 62 |
|
922
52c1d0d22c0e
dont ask Display for defaultExtent - ask current screen
Claus Gittinger <cg@exept.de>
parents:
677
diff
changeset
|
63 |
screen := Screen current. |
52c1d0d22c0e
dont ask Display for defaultExtent - ask current screen
Claus Gittinger <cg@exept.de>
parents:
677
diff
changeset
|
64 |
^ (screen width // 3) @ (screen height // 3) |
52c1d0d22c0e
dont ask Display for defaultExtent - ask current screen
Claus Gittinger <cg@exept.de>
parents:
677
diff
changeset
|
65 |
|
52c1d0d22c0e
dont ask Display for defaultExtent - ask current screen
Claus Gittinger <cg@exept.de>
parents:
677
diff
changeset
|
66 |
"Modified: 5.7.1996 / 13:55:08 / cg" |
81 | 67 |
! |
0 | 68 |
|
269 | 69 |
shadows |
70 |
"return the shadows-flag. False means: turned off." |
|
71 |
||
72 |
^ DefaultShadow |
|
144 | 73 |
! |
74 |
||
75 |
shadows:aBoolean |
|
76 |
"turn on/off shadows under popUpViews. |
|
77 |
On slow displays, turning them off makes menus appear a bit snappier. |
|
78 |
The default is set via the styleSheet and changes when the viewStyle |
|
79 |
is changed." |
|
80 |
||
81 |
DefaultShadow := aBoolean |
|
82 |
! |
|
83 |
||
269 | 84 |
updateStyleCache |
485 | 85 |
"extract values from the styleSheet and cache them in class variables" |
86 |
||
1930 | 87 |
<resource: #style (#'popup.shadow' #'popup.level' |
88 |
#'popup.borderWidth' |
|
89 |
#'popup.borderColor')> |
|
485 | 90 |
|
269 | 91 |
ShadowView isNil ifTrue:[ |
485 | 92 |
DefaultShadow := false |
269 | 93 |
] ifFalse:[ |
1930 | 94 |
DefaultShadow := StyleSheet at:'popup.shadow' default:false. |
269 | 95 |
]. |
1930 | 96 |
DefaultLevel := StyleSheet at:'popup.level'. |
97 |
DefaultBorderWidth := StyleSheet at:'popup.borderWidth'. |
|
98 |
DefaultBorderColor := StyleSheet colorAt:'popup.borderColor'. |
|
485 | 99 |
|
1930 | 100 |
"Modified: 20.10.1997 / 15:10:07 / cg" |
269 | 101 |
! ! |
102 |
||
103 |
!PopUpView methodsFor:'accessing'! |
|
104 |
||
105 |
exclusivePointer:aBoolean |
|
677
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
106 |
"set/clear the exclusive pointer flag; |
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
107 |
DANGER: if set, no interaction with other views is possible, |
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
108 |
while the popUp is active" |
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
109 |
|
269 | 110 |
exclusivePointer := aBoolean |
677
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
111 |
|
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
112 |
"Modified: 12.5.1996 / 22:02:52 / cg" |
269 | 113 |
! |
114 |
||
115 |
noShadow |
|
116 |
"turn off the shadow" |
|
117 |
||
118 |
shadowView := nil |
|
119 |
! ! |
|
120 |
||
121 |
!PopUpView methodsFor:'activation'! |
|
122 |
||
123 |
hide |
|
124 |
"hide the view, leave its modal event loop" |
|
125 |
||
126 |
windowGroup notNil ifTrue:[ |
|
643 | 127 |
windowGroup removeView:self. |
128 |
windowGroup := nil. |
|
269 | 129 |
]. |
643 | 130 |
self unmap. |
131 |
||
2335
73978e370059
delay a bit when closing a popupVuew, to allow for expose
Claus Gittinger <cg@exept.de>
parents:
1930
diff
changeset
|
132 |
"/ allow for redraw events to arrive |
73978e370059
delay a bit when closing a popupVuew, to allow for expose
Claus Gittinger <cg@exept.de>
parents:
1930
diff
changeset
|
133 |
"/ (actually, only req'd for win32 systems, |
73978e370059
delay a bit when closing a popupVuew, to allow for expose
Claus Gittinger <cg@exept.de>
parents:
1930
diff
changeset
|
134 |
"/ but that short delay does not hurt on others) |
73978e370059
delay a bit when closing a popupVuew, to allow for expose
Claus Gittinger <cg@exept.de>
parents:
1930
diff
changeset
|
135 |
|
73978e370059
delay a bit when closing a popupVuew, to allow for expose
Claus Gittinger <cg@exept.de>
parents:
1930
diff
changeset
|
136 |
Delay waitForSeconds:0.05. |
73978e370059
delay a bit when closing a popupVuew, to allow for expose
Claus Gittinger <cg@exept.de>
parents:
1930
diff
changeset
|
137 |
|
73978e370059
delay a bit when closing a popupVuew, to allow for expose
Claus Gittinger <cg@exept.de>
parents:
1930
diff
changeset
|
138 |
"Modified: / 3.5.1996 / 23:48:22 / stefan" |
73978e370059
delay a bit when closing a popupVuew, to allow for expose
Claus Gittinger <cg@exept.de>
parents:
1930
diff
changeset
|
139 |
"Modified: / 12.9.1998 / 14:58:33 / cg" |
269 | 140 |
! |
141 |
||
142 |
show |
|
143 |
"realize the view at its last position" |
|
144 |
||
145 |
self fixSize. |
|
146 |
self openModal:[true] "realize " |
|
147 |
! |
|
144 | 148 |
|
269 | 149 |
showAt:aPoint |
150 |
"realize the view at aPoint" |
|
151 |
||
152 |
self showAt:aPoint resizing:true |
|
153 |
! |
|
154 |
||
155 |
showAt:aPoint resizing:aBoolean |
|
156 |
"realize the view at aPoint" |
|
157 |
||
158 |
aBoolean ifTrue:[ |
|
1732 | 159 |
self fixSize. |
269 | 160 |
]. |
161 |
self origin:aPoint. |
|
162 |
self makeFullyVisible. |
|
163 |
self openModal:[true] "realize " |
|
164 |
! |
|
165 |
||
166 |
showAtPointer |
|
167 |
"realize the view at the current pointer position" |
|
168 |
||
169 |
self showAt:(device pointerPosition) resizing:true |
|
170 |
! |
|
171 |
||
172 |
showCenteredIn:aView |
|
173 |
"make myself visible at the screen center." |
|
174 |
||
175 |
|top| |
|
176 |
||
177 |
top := aView topView. |
|
178 |
top raise. |
|
179 |
self showAt:(top origin |
|
180 |
+ (aView originRelativeTo:top) |
|
181 |
+ (aView extent // 2) |
|
182 |
- (self extent // 2)) |
|
183 |
! ! |
|
184 |
||
185 |
!PopUpView methodsFor:'dispatching'! |
|
186 |
||
187 |
modalLoop |
|
677
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
188 |
"obsolete support for small configuration without threads. |
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
189 |
This is no longer used" |
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
190 |
|
269 | 191 |
haveControl := true. |
192 |
||
677
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
193 |
"this is a kludge - if we do not have multiple processes, therefore |
269 | 194 |
we start another dispatch loop, which exits when control is lost" |
195 |
||
196 |
device dispatchFor:nil while:[haveControl] |
|
677
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
197 |
|
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
198 |
"Modified: 12.5.1996 / 22:03:52 / cg" |
0 | 199 |
! ! |
200 |
||
89 | 201 |
!PopUpView methodsFor:'initialize / release'! |
0 | 202 |
|
269 | 203 |
create |
204 |
super create. |
|
1732 | 205 |
|
269 | 206 |
shadowView isNil ifTrue:[ |
1732 | 207 |
self saveUnder:true |
269 | 208 |
] |
209 |
! |
|
210 |
||
211 |
destroy |
|
141 | 212 |
haveControl := false. |
269 | 213 |
super destroy. |
214 |
shadowView notNil ifTrue:[shadowView destroy. shadowView := nil] |
|
81 | 215 |
! |
216 |
||
217 |
initStyle |
|
1263 | 218 |
"setup viewStyle specifics" |
219 |
||
81 | 220 |
super initStyle. |
221 |
||
151 | 222 |
styleSheet is3D == true ifTrue:[ |
1263 | 223 |
borderWidth := 0. |
224 |
level := 2 |
|
0 | 225 |
] ifFalse:[ |
1263 | 226 |
borderWidth := 1. |
227 |
level := 0 |
|
0 | 228 |
]. |
229 |
||
81 | 230 |
DefaultBorderColor notNil ifTrue:[ |
1263 | 231 |
self borderColor:(DefaultBorderColor on:device). |
81 | 232 |
]. |
233 |
DefaultBorderWidth notNil ifTrue:[ |
|
1263 | 234 |
borderWidth := DefaultBorderWidth. |
81 | 235 |
]. |
236 |
"/ DefaultEdgeStyle notNil ifTrue:[ |
|
237 |
"/ edgeStyle := DefaultEdgeStyle. |
|
238 |
"/ ]. |
|
239 |
DefaultLevel notNil ifTrue:[ |
|
1263 | 240 |
self level:DefaultLevel. |
81 | 241 |
]. |
242 |
||
243 |
DefaultShadow ifTrue:[ |
|
1263 | 244 |
shadowView := (ShadowView onDevice:device) for:self. |
0 | 245 |
]. |
1263 | 246 |
|
247 |
"Modified: 22.1.1997 / 11:57:38 / cg" |
|
0 | 248 |
! |
249 |
||
269 | 250 |
initialize |
251 |
super initialize. |
|
252 |
exclusivePointer := true. |
|
0 | 253 |
haveControl := false. |
269 | 254 |
type := #popup |
162 | 255 |
! |
256 |
||
257 |
releasePointer |
|
677
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
258 |
"release the mouse pointer" |
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
259 |
|
162 | 260 |
device activePointerGrab == self ifTrue:[ |
677
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
261 |
device ungrabPointer. |
162 | 262 |
]. |
677
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
263 |
|
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
264 |
"Modified: 12.5.1996 / 22:04:09 / cg" |
2387
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
265 |
! |
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
266 |
|
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
267 |
releasePointerAndKeyboard |
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
268 |
"release the pointer and keyboard" |
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
269 |
|
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
270 |
device activePointerGrab == self ifTrue:[ |
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
271 |
device ungrabPointer. |
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
272 |
]. |
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
273 |
device activeKeyboardGrab == self ifTrue:[ |
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
274 |
device ungrabKeyboard. |
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
275 |
]. |
0 | 276 |
! ! |
277 |
||
269 | 278 |
!PopUpView methodsFor:'private'! |
0 | 279 |
|
677
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
280 |
regainControl |
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
281 |
"get exclusive access to pointer and keyboard" |
0 | 282 |
|
1732 | 283 |
|sensor| |
284 |
||
648 | 285 |
shown ifTrue:[ |
1732 | 286 |
device grabPointerInView:self. |
648 | 287 |
device grabKeyboardInView:self. |
1732 | 288 |
|
289 |
self sensor flushMotionEventsFor:nil. |
|
290 |
self sensor flushKeyboardFor:nil. |
|
648 | 291 |
]. |
493 | 292 |
|
648 | 293 |
"Modified: 6.5.1996 / 22:33:39 / stefan" |
677
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
294 |
"Modified: 12.5.1996 / 22:04:42 / cg" |
89 | 295 |
! ! |
296 |
||
269 | 297 |
!PopUpView methodsFor:'queries'! |
89 | 298 |
|
269 | 299 |
isPopUpView |
677
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
300 |
"return true, since I want to come up without decoration |
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
301 |
and popUp to top immediately." |
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
302 |
|
269 | 303 |
^ true |
677
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
304 |
|
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
305 |
"Modified: 12.5.1996 / 21:57:51 / cg" |
0 | 306 |
! ! |
307 |
||
308 |
!PopUpView methodsFor:'realize / unrealize'! |
|
309 |
||
310 |
mapped |
|
162 | 311 |
"grab the pointer here, when visible (but not control is already lost). |
643 | 312 |
If the grab fails, try again and unmap myself if that fails too." |
0 | 313 |
|
523 | 314 |
mapTime := Time millisecondClockValue. |
315 |
||
0 | 316 |
super mapped. |
162 | 317 |
|
157 | 318 |
(haveControl |
162 | 319 |
and:[true "/ exclusivePointer |
157 | 320 |
and:[realized]]) ifTrue:[ |
493 | 321 |
(device grabPointerInView:self) ifFalse:[ |
322 |
"wait a little bit and try again" |
|
157 | 323 |
"/ 'grab pointer failed' errorPrintNL. |
493 | 324 |
Delay waitForSeconds:0.1. |
325 |
(device grabPointerInView:self) ifFalse:[ |
|
326 |
"give up" |
|
1174
6889dc61d701
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
327 |
'PopUpView [warning]: could not grab pointer' errorPrintCR. |
643 | 328 |
self unmap |
493 | 329 |
] |
330 |
]. |
|
331 |
exclusivePointer ifFalse:[ |
|
332 |
self releasePointer |
|
333 |
]. |
|
1174
6889dc61d701
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
334 |
device grabKeyboardInView:self. |
493 | 335 |
self getKeyboardFocus |
81 | 336 |
] |
493 | 337 |
|
643 | 338 |
"Modified: 3.5.1996 / 23:48:37 / stefan" |
1174
6889dc61d701
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
339 |
"Modified: 10.1.1997 / 18:00:31 / cg" |
0 | 340 |
! |
341 |
||
342 |
realize |
|
343 |
shadowView notNil ifTrue:[shadowView realize]. |
|
344 |
self raise. |
|
81 | 345 |
haveControl := true. |
0 | 346 |
super realize. |
347 |
! |
|
348 |
||
269 | 349 |
restarted |
350 |
^ self |
|
351 |
! |
|
352 |
||
643 | 353 |
unmap |
0 | 354 |
haveControl := false. |
1732 | 355 |
|
2387
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
356 |
self releasePointerAndKeyboard. |
643 | 357 |
super unmap. |
358 |
shadowView notNil ifTrue:[shadowView unmap]. |
|
359 |
||
360 |
"Modified: 3.5.1996 / 23:46:06 / stefan" |
|
0 | 361 |
! ! |
362 |
||
1174
6889dc61d701
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
363 |
!PopUpView class methodsFor:'documentation'! |
0 | 364 |
|
269 | 365 |
version |
2387
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
366 |
^ '$Header: /cvs/stx/stx/libview/PopUpView.st,v 1.37 1998-10-02 10:55:34 cg Exp $' |
157 | 367 |
! ! |