author | Claus Gittinger <cg@exept.de> |
Wed, 18 Aug 1999 16:39:00 +0200 | |
changeset 2831 | 62b8abcdf5f2 |
parent 2579 | 774e6fb33dde |
child 2876 | dbe1454f8539 |
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 |
show |
|
124 |
"realize the view at its last position" |
|
125 |
||
126 |
self fixSize. |
|
127 |
self openModal:[true] "realize " |
|
128 |
! |
|
144 | 129 |
|
269 | 130 |
showAt:aPoint |
131 |
"realize the view at aPoint" |
|
132 |
||
133 |
self showAt:aPoint resizing:true |
|
134 |
! |
|
135 |
||
136 |
showAt:aPoint resizing:aBoolean |
|
137 |
"realize the view at aPoint" |
|
138 |
||
139 |
aBoolean ifTrue:[ |
|
1732 | 140 |
self fixSize. |
269 | 141 |
]. |
142 |
self origin:aPoint. |
|
143 |
self makeFullyVisible. |
|
144 |
self openModal:[true] "realize " |
|
145 |
! |
|
146 |
||
147 |
showAtPointer |
|
148 |
"realize the view at the current pointer position" |
|
149 |
||
150 |
self showAt:(device pointerPosition) resizing:true |
|
151 |
! |
|
152 |
||
153 |
showCenteredIn:aView |
|
154 |
"make myself visible at the screen center." |
|
155 |
||
156 |
|top| |
|
157 |
||
158 |
top := aView topView. |
|
159 |
top raise. |
|
160 |
self showAt:(top origin |
|
161 |
+ (aView originRelativeTo:top) |
|
162 |
+ (aView extent // 2) |
|
163 |
- (self extent // 2)) |
|
164 |
! ! |
|
165 |
||
2412 | 166 |
!PopUpView methodsFor:'defaults'! |
167 |
||
168 |
defaultShadow |
|
169 |
^ DefaultShadow |
|
170 |
||
171 |
"Created: / 4.12.1998 / 15:11:20 / cg" |
|
172 |
! ! |
|
173 |
||
89 | 174 |
!PopUpView methodsFor:'initialize / release'! |
0 | 175 |
|
269 | 176 |
create |
177 |
super create. |
|
1732 | 178 |
|
269 | 179 |
shadowView isNil ifTrue:[ |
1732 | 180 |
self saveUnder:true |
269 | 181 |
] |
182 |
! |
|
183 |
||
184 |
destroy |
|
141 | 185 |
haveControl := false. |
269 | 186 |
super destroy. |
187 |
shadowView notNil ifTrue:[shadowView destroy. shadowView := nil] |
|
81 | 188 |
! |
189 |
||
190 |
initStyle |
|
1263 | 191 |
"setup viewStyle specifics" |
192 |
||
2574 | 193 |
|l| |
81 | 194 |
|
2574 | 195 |
super initStyle. |
0 | 196 |
|
81 | 197 |
DefaultBorderColor notNil ifTrue:[ |
2831 | 198 |
self borderColor:(DefaultBorderColor onDevice:device). |
81 | 199 |
]. |
2574 | 200 |
DefaultBorderWidth isNil ifTrue:[ |
201 |
borderWidth := styleSheet is3D ifTrue:[0] ifFalse:[1]. |
|
202 |
] ifFalse:[ |
|
1263 | 203 |
borderWidth := DefaultBorderWidth. |
81 | 204 |
]. |
2574 | 205 |
DefaultLevel isNil ifTrue:[ |
206 |
l := styleSheet is3D ifTrue:[1] ifFalse:[0]. |
|
207 |
] ifFalse:[ |
|
208 |
l := DefaultLevel. |
|
81 | 209 |
]. |
2574 | 210 |
self level:l. |
81 | 211 |
|
2412 | 212 |
self defaultShadow ifTrue:[ |
1263 | 213 |
shadowView := (ShadowView onDevice:device) for:self. |
0 | 214 |
]. |
1263 | 215 |
|
2412 | 216 |
"Modified: / 4.12.1998 / 15:11:28 / cg" |
0 | 217 |
! |
218 |
||
269 | 219 |
initialize |
220 |
super initialize. |
|
221 |
exclusivePointer := true. |
|
0 | 222 |
haveControl := false. |
269 | 223 |
type := #popup |
162 | 224 |
! |
225 |
||
226 |
releasePointer |
|
677
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
227 |
"release the mouse pointer" |
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
228 |
|
162 | 229 |
device activePointerGrab == self ifTrue:[ |
677
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
230 |
device ungrabPointer. |
162 | 231 |
]. |
677
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
232 |
|
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
233 |
"Modified: 12.5.1996 / 22:04:09 / cg" |
2387
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
234 |
! |
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
235 |
|
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
236 |
releasePointerAndKeyboard |
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
237 |
"release the pointer and keyboard" |
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
238 |
|
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
239 |
device activePointerGrab == self ifTrue:[ |
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
240 |
device ungrabPointer. |
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
241 |
]. |
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
242 |
device activeKeyboardGrab == self ifTrue:[ |
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
243 |
device ungrabKeyboard. |
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
244 |
]. |
0 | 245 |
! ! |
246 |
||
269 | 247 |
!PopUpView methodsFor:'private'! |
0 | 248 |
|
677
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
249 |
regainControl |
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
250 |
"get exclusive access to pointer and keyboard" |
0 | 251 |
|
1732 | 252 |
|sensor| |
253 |
||
648 | 254 |
shown ifTrue:[ |
1732 | 255 |
device grabPointerInView:self. |
648 | 256 |
device grabKeyboardInView:self. |
1732 | 257 |
|
258 |
self sensor flushMotionEventsFor:nil. |
|
259 |
self sensor flushKeyboardFor:nil. |
|
648 | 260 |
]. |
493 | 261 |
|
648 | 262 |
"Modified: 6.5.1996 / 22:33:39 / stefan" |
677
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
263 |
"Modified: 12.5.1996 / 22:04:42 / cg" |
89 | 264 |
! ! |
265 |
||
269 | 266 |
!PopUpView methodsFor:'queries'! |
89 | 267 |
|
269 | 268 |
isPopUpView |
677
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
269 |
"return true, since I want to come up without decoration |
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
270 |
and popUp to top immediately." |
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
271 |
|
269 | 272 |
^ true |
677
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
273 |
|
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
274 |
"Modified: 12.5.1996 / 21:57:51 / cg" |
0 | 275 |
! ! |
276 |
||
277 |
!PopUpView methodsFor:'realize / unrealize'! |
|
278 |
||
2574 | 279 |
hide |
280 |
"hide the view, leave its modal event loop" |
|
281 |
||
2579 | 282 |
|masterGroup| |
283 |
||
2574 | 284 |
windowGroup notNil ifTrue:[ |
2579 | 285 |
masterGroup := windowGroup previousGroup. |
2574 | 286 |
windowGroup removeView:self. |
287 |
windowGroup := nil. |
|
288 |
]. |
|
289 |
self unmap. |
|
290 |
||
291 |
"/ allow for redraw events to arrive |
|
292 |
"/ (actually, only req'd for win32 systems, |
|
293 |
"/ but that short delay does not hurt on others) |
|
294 |
||
2579 | 295 |
"/ Delay waitForSeconds:0.05. |
296 |
masterGroup notNil ifTrue:[ |
|
297 |
" |
|
298 |
this is a kludge for IRIS and others which do not provide backingstore: |
|
299 |
when we hide a modalbox (such as a searchbox) which covered |
|
300 |
a scrollbar, the scrollbars bitblt-method will copy from the |
|
301 |
not-yet redrawn area - effectively clearing the scroller. |
|
302 |
We need a short delay here, since at this time, the expose event has |
|
303 |
not yet arrived. |
|
304 |
" |
|
305 |
Delay waitForSeconds:0.05. |
|
306 |
masterGroup processExposeEvents |
|
307 |
]. |
|
2574 | 308 |
|
309 |
"Modified: / 3.5.1996 / 23:48:22 / stefan" |
|
310 |
"Modified: / 12.9.1998 / 14:58:33 / cg" |
|
311 |
! |
|
312 |
||
0 | 313 |
mapped |
162 | 314 |
"grab the pointer here, when visible (but not control is already lost). |
643 | 315 |
If the grab fails, try again and unmap myself if that fails too." |
0 | 316 |
|
523 | 317 |
mapTime := Time millisecondClockValue. |
318 |
||
0 | 319 |
super mapped. |
162 | 320 |
|
157 | 321 |
(haveControl |
162 | 322 |
and:[true "/ exclusivePointer |
157 | 323 |
and:[realized]]) ifTrue:[ |
493 | 324 |
(device grabPointerInView:self) ifFalse:[ |
325 |
"wait a little bit and try again" |
|
157 | 326 |
"/ 'grab pointer failed' errorPrintNL. |
493 | 327 |
Delay waitForSeconds:0.1. |
328 |
(device grabPointerInView:self) ifFalse:[ |
|
329 |
"give up" |
|
1174
6889dc61d701
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
330 |
'PopUpView [warning]: could not grab pointer' errorPrintCR. |
643 | 331 |
self unmap |
493 | 332 |
] |
333 |
]. |
|
334 |
exclusivePointer ifFalse:[ |
|
335 |
self releasePointer |
|
336 |
]. |
|
1174
6889dc61d701
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
337 |
device grabKeyboardInView:self. |
493 | 338 |
self getKeyboardFocus |
81 | 339 |
] |
493 | 340 |
|
643 | 341 |
"Modified: 3.5.1996 / 23:48:37 / stefan" |
1174
6889dc61d701
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
342 |
"Modified: 10.1.1997 / 18:00:31 / cg" |
0 | 343 |
! |
344 |
||
345 |
realize |
|
346 |
shadowView notNil ifTrue:[shadowView realize]. |
|
347 |
self raise. |
|
81 | 348 |
haveControl := true. |
0 | 349 |
super realize. |
350 |
! |
|
351 |
||
269 | 352 |
restarted |
353 |
^ self |
|
354 |
! |
|
355 |
||
643 | 356 |
unmap |
0 | 357 |
haveControl := false. |
1732 | 358 |
|
2387
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
359 |
self releasePointerAndKeyboard. |
643 | 360 |
super unmap. |
361 |
shadowView notNil ifTrue:[shadowView unmap]. |
|
362 |
||
363 |
"Modified: 3.5.1996 / 23:46:06 / stefan" |
|
0 | 364 |
! ! |
365 |
||
1174
6889dc61d701
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
366 |
!PopUpView class methodsFor:'documentation'! |
0 | 367 |
|
269 | 368 |
version |
2831 | 369 |
^ '$Header: /cvs/stx/stx/libview/PopUpView.st,v 1.41 1999-08-18 14:39:00 cg Exp $' |
157 | 370 |
! ! |