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