author | Claus Gittinger <cg@exept.de> |
Fri, 04 Dec 1998 15:11:51 +0100 | |
changeset 2412 | 3065f9e362dc |
parent 2387 | cfd8fa32799b |
child 2574 | ab434bf2439e |
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 |
||
2412 | 185 |
!PopUpView methodsFor:'defaults'! |
186 |
||
187 |
defaultShadow |
|
188 |
^ DefaultShadow |
|
189 |
||
190 |
"Created: / 4.12.1998 / 15:11:20 / cg" |
|
191 |
! ! |
|
192 |
||
269 | 193 |
!PopUpView methodsFor:'dispatching'! |
194 |
||
195 |
modalLoop |
|
677
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
196 |
"obsolete support for small configuration without threads. |
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
197 |
This is no longer used" |
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
198 |
|
269 | 199 |
haveControl := true. |
200 |
||
677
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
201 |
"this is a kludge - if we do not have multiple processes, therefore |
269 | 202 |
we start another dispatch loop, which exits when control is lost" |
203 |
||
204 |
device dispatchFor:nil while:[haveControl] |
|
677
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
205 |
|
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
206 |
"Modified: 12.5.1996 / 22:03:52 / cg" |
0 | 207 |
! ! |
208 |
||
89 | 209 |
!PopUpView methodsFor:'initialize / release'! |
0 | 210 |
|
269 | 211 |
create |
212 |
super create. |
|
1732 | 213 |
|
269 | 214 |
shadowView isNil ifTrue:[ |
1732 | 215 |
self saveUnder:true |
269 | 216 |
] |
217 |
! |
|
218 |
||
219 |
destroy |
|
141 | 220 |
haveControl := false. |
269 | 221 |
super destroy. |
222 |
shadowView notNil ifTrue:[shadowView destroy. shadowView := nil] |
|
81 | 223 |
! |
224 |
||
225 |
initStyle |
|
1263 | 226 |
"setup viewStyle specifics" |
227 |
||
81 | 228 |
super initStyle. |
229 |
||
151 | 230 |
styleSheet is3D == true ifTrue:[ |
1263 | 231 |
borderWidth := 0. |
232 |
level := 2 |
|
0 | 233 |
] ifFalse:[ |
1263 | 234 |
borderWidth := 1. |
235 |
level := 0 |
|
0 | 236 |
]. |
237 |
||
81 | 238 |
DefaultBorderColor notNil ifTrue:[ |
1263 | 239 |
self borderColor:(DefaultBorderColor on:device). |
81 | 240 |
]. |
241 |
DefaultBorderWidth notNil ifTrue:[ |
|
1263 | 242 |
borderWidth := DefaultBorderWidth. |
81 | 243 |
]. |
244 |
"/ DefaultEdgeStyle notNil ifTrue:[ |
|
245 |
"/ edgeStyle := DefaultEdgeStyle. |
|
246 |
"/ ]. |
|
247 |
DefaultLevel notNil ifTrue:[ |
|
1263 | 248 |
self level:DefaultLevel. |
81 | 249 |
]. |
250 |
||
2412 | 251 |
self defaultShadow ifTrue:[ |
1263 | 252 |
shadowView := (ShadowView onDevice:device) for:self. |
0 | 253 |
]. |
1263 | 254 |
|
2412 | 255 |
"Modified: / 4.12.1998 / 15:11:28 / cg" |
0 | 256 |
! |
257 |
||
269 | 258 |
initialize |
259 |
super initialize. |
|
260 |
exclusivePointer := true. |
|
0 | 261 |
haveControl := false. |
269 | 262 |
type := #popup |
162 | 263 |
! |
264 |
||
265 |
releasePointer |
|
677
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
266 |
"release the mouse pointer" |
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
267 |
|
162 | 268 |
device activePointerGrab == self ifTrue:[ |
677
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
269 |
device ungrabPointer. |
162 | 270 |
]. |
677
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
271 |
|
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
272 |
"Modified: 12.5.1996 / 22:04:09 / cg" |
2387
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
273 |
! |
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
274 |
|
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
275 |
releasePointerAndKeyboard |
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
276 |
"release the pointer and keyboard" |
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
277 |
|
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
278 |
device activePointerGrab == self ifTrue:[ |
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
279 |
device ungrabPointer. |
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
280 |
]. |
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
281 |
device activeKeyboardGrab == self ifTrue:[ |
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
282 |
device ungrabKeyboard. |
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
283 |
]. |
0 | 284 |
! ! |
285 |
||
269 | 286 |
!PopUpView methodsFor:'private'! |
0 | 287 |
|
677
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
288 |
regainControl |
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
289 |
"get exclusive access to pointer and keyboard" |
0 | 290 |
|
1732 | 291 |
|sensor| |
292 |
||
648 | 293 |
shown ifTrue:[ |
1732 | 294 |
device grabPointerInView:self. |
648 | 295 |
device grabKeyboardInView:self. |
1732 | 296 |
|
297 |
self sensor flushMotionEventsFor:nil. |
|
298 |
self sensor flushKeyboardFor:nil. |
|
648 | 299 |
]. |
493 | 300 |
|
648 | 301 |
"Modified: 6.5.1996 / 22:33:39 / stefan" |
677
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
302 |
"Modified: 12.5.1996 / 22:04:42 / cg" |
89 | 303 |
! ! |
304 |
||
269 | 305 |
!PopUpView methodsFor:'queries'! |
89 | 306 |
|
269 | 307 |
isPopUpView |
677
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
308 |
"return true, since I want to come up without decoration |
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
309 |
and popUp to top immediately." |
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
310 |
|
269 | 311 |
^ true |
677
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
312 |
|
069dd8cd00d1
removed obsolete stuff & commentary
Claus Gittinger <cg@exept.de>
parents:
648
diff
changeset
|
313 |
"Modified: 12.5.1996 / 21:57:51 / cg" |
0 | 314 |
! ! |
315 |
||
316 |
!PopUpView methodsFor:'realize / unrealize'! |
|
317 |
||
318 |
mapped |
|
162 | 319 |
"grab the pointer here, when visible (but not control is already lost). |
643 | 320 |
If the grab fails, try again and unmap myself if that fails too." |
0 | 321 |
|
523 | 322 |
mapTime := Time millisecondClockValue. |
323 |
||
0 | 324 |
super mapped. |
162 | 325 |
|
157 | 326 |
(haveControl |
162 | 327 |
and:[true "/ exclusivePointer |
157 | 328 |
and:[realized]]) ifTrue:[ |
493 | 329 |
(device grabPointerInView:self) ifFalse:[ |
330 |
"wait a little bit and try again" |
|
157 | 331 |
"/ 'grab pointer failed' errorPrintNL. |
493 | 332 |
Delay waitForSeconds:0.1. |
333 |
(device grabPointerInView:self) ifFalse:[ |
|
334 |
"give up" |
|
1174
6889dc61d701
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
335 |
'PopUpView [warning]: could not grab pointer' errorPrintCR. |
643 | 336 |
self unmap |
493 | 337 |
] |
338 |
]. |
|
339 |
exclusivePointer ifFalse:[ |
|
340 |
self releasePointer |
|
341 |
]. |
|
1174
6889dc61d701
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
342 |
device grabKeyboardInView:self. |
493 | 343 |
self getKeyboardFocus |
81 | 344 |
] |
493 | 345 |
|
643 | 346 |
"Modified: 3.5.1996 / 23:48:37 / stefan" |
1174
6889dc61d701
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
347 |
"Modified: 10.1.1997 / 18:00:31 / cg" |
0 | 348 |
! |
349 |
||
350 |
realize |
|
351 |
shadowView notNil ifTrue:[shadowView realize]. |
|
352 |
self raise. |
|
81 | 353 |
haveControl := true. |
0 | 354 |
super realize. |
355 |
! |
|
356 |
||
269 | 357 |
restarted |
358 |
^ self |
|
359 |
! |
|
360 |
||
643 | 361 |
unmap |
0 | 362 |
haveControl := false. |
1732 | 363 |
|
2387
cfd8fa32799b
also release keyboard when unmapped
Claus Gittinger <cg@exept.de>
parents:
2335
diff
changeset
|
364 |
self releasePointerAndKeyboard. |
643 | 365 |
super unmap. |
366 |
shadowView notNil ifTrue:[shadowView unmap]. |
|
367 |
||
368 |
"Modified: 3.5.1996 / 23:46:06 / stefan" |
|
0 | 369 |
! ! |
370 |
||
1174
6889dc61d701
newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents:
922
diff
changeset
|
371 |
!PopUpView class methodsFor:'documentation'! |
0 | 372 |
|
269 | 373 |
version |
2412 | 374 |
^ '$Header: /cvs/stx/stx/libview/PopUpView.st,v 1.38 1998-12-04 14:11:51 cg Exp $' |
157 | 375 |
! ! |