author | Claus Gittinger <cg@exept.de> |
Thu, 01 Oct 2009 09:53:07 +0200 | |
changeset 2754 | 4c3b40eba71b |
parent 2692 | 5fe75b7fb83a |
child 2774 | 7894ba397774 |
permissions | -rw-r--r-- |
1802 | 1 |
" |
2 |
COPYRIGHT (c) 2001 by eXept Software AG |
|
3 |
All Rights Reserved |
|
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 |
" |
|
1536 | 12 |
"{ Package: 'stx:libview2' }" |
13 |
||
14 |
ActiveHelp subclass:#FlyByHelp |
|
2680 | 15 |
instanceVariableNames:'currentFrame currentView currentHelpView showProcess closeProcess' |
1892 | 16 |
classVariableNames:'' |
1536 | 17 |
poolDictionaries:'' |
18 |
category:'Interface-Help' |
|
19 |
! |
|
20 |
||
1802 | 21 |
!FlyByHelp class methodsFor:'documentation'! |
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 2001 by eXept Software AG |
|
26 |
All Rights Reserved |
|
27 |
||
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
1893 | 35 |
! |
36 |
||
37 |
examples |
|
38 |
" |
|
39 |
FlyByHelp isActive |
|
40 |
||
41 |
FlyByHelp stop |
|
42 |
FlyByHelp start |
|
43 |
" |
|
1802 | 44 |
! ! |
1536 | 45 |
|
46 |
!FlyByHelp class methodsFor:'initialization'! |
|
47 |
||
48 |
initialize |
|
49 |
"set default delay & help-display times" |
|
50 |
||
1657 | 51 |
ShowTime := 10. |
52 |
DelayTime := 0.4. |
|
1536 | 53 |
|
54 |
" |
|
55 |
FlyByHelp initialize |
|
56 |
" |
|
57 |
||
58 |
"Modified: 27.4.1996 / 15:07:27 / cg" |
|
59 |
! ! |
|
60 |
||
2692 | 61 |
!FlyByHelp class methodsFor:'accessing'! |
62 |
||
63 |
currentlyShownView |
|
64 |
^ TheOneAndOnlyHelpListener currentlyShownView |
|
65 |
! ! |
|
66 |
||
2684 | 67 |
!FlyByHelp methodsFor:'defaults'! |
68 |
||
69 |
flyByHelpTimeoutMillis |
|
70 |
"abort flyby help text generation, if no text can be generated within that |
|
71 |
time delta. This is used to abort long-lasting parsing/scanning/analysis in |
|
72 |
large methods when the mouse is moved over some syntactic constructs, and |
|
73 |
it takes too long to parse... |
|
74 |
The returned time is given in ms" |
|
75 |
||
76 |
^ 300 |
|
77 |
! ! |
|
78 |
||
2392 | 79 |
!FlyByHelp methodsFor:'event handling'! |
1540 | 80 |
|
2474 | 81 |
buttonMotion:buttonAndModifierState x:x y:y view:aView |
2519 | 82 |
aView == currentHelpView ifTrue:[ |
83 |
"/ the help-bubble itself |
|
84 |
^ false |
|
85 |
]. |
|
86 |
||
2518 | 87 |
"/ don't start tooltip, if this view is not active |
88 |
"/ aView topView isActive ifFalse:[^ false]. |
|
2477
b009e0b51999
suppress tooltip for inactive (lower) windows
Claus Gittinger <cg@exept.de>
parents:
2474
diff
changeset
|
89 |
|
2474 | 90 |
^ super buttonMotion:buttonAndModifierState x:x y:y view:aView |
1540 | 91 |
! |
92 |
||
2611
f578b9c43a6f
handle escape key to close flyByHelp
Claus Gittinger <cg@exept.de>
parents:
2521
diff
changeset
|
93 |
buttonPress:button x:x y:y view:aView |
f578b9c43a6f
handle escape key to close flyByHelp
Claus Gittinger <cg@exept.de>
parents:
2521
diff
changeset
|
94 |
aView == currentHelpView ifTrue:[ |
f578b9c43a6f
handle escape key to close flyByHelp
Claus Gittinger <cg@exept.de>
parents:
2521
diff
changeset
|
95 |
self hideHelp. |
f578b9c43a6f
handle escape key to close flyByHelp
Claus Gittinger <cg@exept.de>
parents:
2521
diff
changeset
|
96 |
^ true |
f578b9c43a6f
handle escape key to close flyByHelp
Claus Gittinger <cg@exept.de>
parents:
2521
diff
changeset
|
97 |
]. |
f578b9c43a6f
handle escape key to close flyByHelp
Claus Gittinger <cg@exept.de>
parents:
2521
diff
changeset
|
98 |
|
f578b9c43a6f
handle escape key to close flyByHelp
Claus Gittinger <cg@exept.de>
parents:
2521
diff
changeset
|
99 |
^ super buttonPress:button x:x y:y view:aView |
f578b9c43a6f
handle escape key to close flyByHelp
Claus Gittinger <cg@exept.de>
parents:
2521
diff
changeset
|
100 |
! |
f578b9c43a6f
handle escape key to close flyByHelp
Claus Gittinger <cg@exept.de>
parents:
2521
diff
changeset
|
101 |
|
f578b9c43a6f
handle escape key to close flyByHelp
Claus Gittinger <cg@exept.de>
parents:
2521
diff
changeset
|
102 |
keyPress:key x:x y:y view:aView |
2612 | 103 |
aView == currentHelpView ifTrue:[ |
104 |
key == #Escape ifTrue:[ |
|
105 |
self hideHelp. |
|
106 |
^ true |
|
107 |
]. |
|
2611
f578b9c43a6f
handle escape key to close flyByHelp
Claus Gittinger <cg@exept.de>
parents:
2521
diff
changeset
|
108 |
]. |
f578b9c43a6f
handle escape key to close flyByHelp
Claus Gittinger <cg@exept.de>
parents:
2521
diff
changeset
|
109 |
^ false |
f578b9c43a6f
handle escape key to close flyByHelp
Claus Gittinger <cg@exept.de>
parents:
2521
diff
changeset
|
110 |
! |
f578b9c43a6f
handle escape key to close flyByHelp
Claus Gittinger <cg@exept.de>
parents:
2521
diff
changeset
|
111 |
|
2521
7e51aa294156
care for mousewheel while showing help
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
112 |
mouseWheelMotion:state x:x y:y amount:amount deltaTime:dTime view:aView |
7e51aa294156
care for mousewheel while showing help
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
113 |
currentHelpView notNil ifTrue:[ |
7e51aa294156
care for mousewheel while showing help
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
114 |
self handleMouseIn:aView x:x y:y. |
7e51aa294156
care for mousewheel while showing help
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
115 |
]. |
7e51aa294156
care for mousewheel while showing help
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
116 |
^ false |
7e51aa294156
care for mousewheel while showing help
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
117 |
! |
7e51aa294156
care for mousewheel while showing help
Claus Gittinger <cg@exept.de>
parents:
2519
diff
changeset
|
118 |
|
1540 | 119 |
pointerLeave:state view:aView |
2611
f578b9c43a6f
handle escape key to close flyByHelp
Claus Gittinger <cg@exept.de>
parents:
2521
diff
changeset
|
120 |
aView == currentHelpView ifTrue:[^ true]. |
f578b9c43a6f
handle escape key to close flyByHelp
Claus Gittinger <cg@exept.de>
parents:
2521
diff
changeset
|
121 |
^ super pointerLeave:state view:aView |
1540 | 122 |
! ! |
123 |
||
2392 | 124 |
!FlyByHelp methodsFor:'help texts'! |
1536 | 125 |
|
126 |
helpTextFromModel:aModel view:aView at:aPointOrNil |
|
127 |
"helper: ask aModel for its helpText." |
|
128 |
||
129 |
|text| |
|
130 |
||
131 |
aPointOrNil notNil ifTrue:[ |
|
132 |
(aModel respondsTo:#flyByHelpTextFor:at:) ifTrue:[ |
|
133 |
text := aModel flyByHelpTextFor:aView at:aPointOrNil. |
|
2754 | 134 |
text notNil ifTrue:[^ text]. |
1536 | 135 |
]. |
136 |
]. |
|
2754 | 137 |
(aModel respondsTo:#flyByHelpTextFor:) ifTrue:[ |
138 |
text := aModel flyByHelpTextFor:aView. |
|
139 |
text notNil ifTrue:[^ text]. |
|
1536 | 140 |
]. |
2754 | 141 |
^ nil |
1536 | 142 |
! |
143 |
||
144 |
helpTextFromView:aView at:aPointOrNil |
|
145 |
"helper: ask aView for its helpText." |
|
146 |
||
2754 | 147 |
|text key app| |
1536 | 148 |
|
149 |
aPointOrNil notNil ifTrue:[ |
|
150 |
(aView respondsTo:#flyByHelpTextAt:) ifTrue:[ |
|
151 |
text := aView flyByHelpTextAt:aPointOrNil. |
|
2754 | 152 |
text notNil ifTrue:[^ text]. |
1536 | 153 |
]. |
154 |
]. |
|
2754 | 155 |
(aView respondsTo:#flyByHelpText) ifTrue:[ |
156 |
text := aView flyByHelpText. |
|
157 |
text notNil ifTrue:[^ text]. |
|
158 |
]. |
|
159 |
(aView respondsTo:#helpKey) ifTrue:[ |
|
160 |
key := aView helpKey. |
|
161 |
key notNil ifTrue:[ |
|
162 |
app := aView application. |
|
163 |
app isNil ifTrue:[ |
|
164 |
app := Error handle:[:ex | nil] do:[ aView windowGroup mainGroup application ]. |
|
165 |
]. |
|
166 |
app notNil ifTrue:[ |
|
167 |
^ app flyByHelpTextForKey:key |
|
168 |
]. |
|
169 |
^ aView resources string:key |
|
1536 | 170 |
]. |
171 |
]. |
|
2754 | 172 |
^ nil. |
2392 | 173 |
! ! |
174 |
||
175 |
!FlyByHelp methodsFor:'private'! |
|
1536 | 176 |
|
177 |
hideIfPointerLeft:aView |
|
178 |
"hide help, if the pointer is not in aView" |
|
179 |
||
180 |
|whereOnScreen| |
|
181 |
||
182 |
currentFrame notNil ifTrue:[ |
|
183 |
whereOnScreen := aView graphicsDevice pointerPosition. |
|
184 |
||
185 |
(currentFrame notNil |
|
186 |
and:[(currentFrame insetBy:1@1) containsPoint:whereOnScreen]) ifFalse:[ |
|
187 |
self hideHelp. |
|
188 |
]. |
|
189 |
]. |
|
190 |
||
191 |
"Modified: 28.5.1996 / 20:18:28 / cg" |
|
192 |
! |
|
193 |
||
194 |
initiateHelpFor:aView at:aPointOrNil now:showItNow |
|
195 |
"ask aView for helpText, passing x/y coordinates; |
|
196 |
start a timeout process to display this helpText after some delay; |
|
197 |
Normally used internally, but can also be used by widgets to force |
|
198 |
re-negotiation of the displayed helpText |
|
199 |
(for example in a menu, when the selection changes)" |
|
200 |
||
2679
552847065fb3
car not to hog the cpu by flyByHelp processing
Claus Gittinger <cg@exept.de>
parents:
2651
diff
changeset
|
201 |
|text delayTime now| |
1536 | 202 |
|
203 |
(self interestedIn:aView) ifFalse:[ |
|
204 |
^ self |
|
205 |
]. |
|
206 |
||
2679
552847065fb3
car not to hog the cpu by flyByHelp processing
Claus Gittinger <cg@exept.de>
parents:
2651
diff
changeset
|
207 |
now := Timestamp now. |
552847065fb3
car not to hog the cpu by flyByHelp processing
Claus Gittinger <cg@exept.de>
parents:
2651
diff
changeset
|
208 |
|
2680 | 209 |
"/ do not allow for more than 200 ms to be spent in the |
2679
552847065fb3
car not to hog the cpu by flyByHelp processing
Claus Gittinger <cg@exept.de>
parents:
2651
diff
changeset
|
210 |
"/ helpText gatherer (the codeView parses the code for the variable under the cursor) |
552847065fb3
car not to hog the cpu by flyByHelp processing
Claus Gittinger <cg@exept.de>
parents:
2651
diff
changeset
|
211 |
[ |
552847065fb3
car not to hog the cpu by flyByHelp processing
Claus Gittinger <cg@exept.de>
parents:
2651
diff
changeset
|
212 |
text := self helpTextFor:aView at:aPointOrNil. |
2684 | 213 |
] valueWithWatchDog:[ ^ self ] afterMilliseconds:(self flyByHelpTimeoutMillis). |
2679
552847065fb3
car not to hog the cpu by flyByHelp processing
Claus Gittinger <cg@exept.de>
parents:
2651
diff
changeset
|
214 |
|
1536 | 215 |
lastHelpText = text ifTrue:[ |
2392 | 216 |
self toolTipFollowsMouse ifFalse:[ |
217 |
^ self |
|
218 |
] |
|
1536 | 219 |
]. |
220 |
||
221 |
text size > 0 ifTrue:[ |
|
2392 | 222 |
delayTime := self delayTime. |
223 |
(showItNow not and:[delayTime > 0]) ifTrue:[ |
|
1536 | 224 |
self stopHelpDisplayProcess. |
2392 | 225 |
showProcess := |
226 |
[ |
|
2680 | 227 |
Delay waitForSeconds:delayTime. |
228 |
showProcess := nil. |
|
229 |
aView device anyButtonPressed ifFalse:[ |
|
230 |
self showHelp:text for:aView |
|
231 |
] |
|
2392 | 232 |
] forkAt:(Processor userSchedulingPriority + 1). |
1536 | 233 |
] ifFalse:[ |
234 |
self showHelp:text for:aView |
|
235 |
] |
|
1542 | 236 |
] ifFalse:[ |
237 |
self hideHelp |
|
1536 | 238 |
]. |
239 |
! |
|
240 |
||
241 |
interestedIn:aView |
|
242 |
"return true, if I am interested in aView (either listeningForAll, |
|
243 |
or in my list of apps)" |
|
244 |
||
245 |
aView isNil ifTrue:[^ false]. |
|
2495
728d6935dc5b
also interestedIn: help, if a pointer moves
Claus Gittinger <cg@exept.de>
parents:
2478
diff
changeset
|
246 |
"/ aView topView == currentHelpView ifTrue:[^ false]. |
1536 | 247 |
|
248 |
^ super interestedIn:aView |
|
249 |
! ! |
|
250 |
||
2392 | 251 |
!FlyByHelp methodsFor:'queries'! |
252 |
||
2692 | 253 |
currentlyShownView |
254 |
^ currentHelpView |
|
255 |
! |
|
256 |
||
2392 | 257 |
toolTipFollowsMouse |
258 |
^ false |
|
259 |
! ! |
|
260 |
||
1768 | 261 |
!FlyByHelp methodsFor:'show & hide help'! |
1536 | 262 |
|
263 |
hideHelp |
|
264 |
"hide the help text" |
|
265 |
||
266 |
|p| |
|
267 |
||
1540 | 268 |
lastHelpText := nil. |
1536 | 269 |
self stopHelpDisplayProcess. |
270 |
||
271 |
currentHelpView notNil ifTrue:[ |
|
272 |
[ |
|
273 |
currentHelpView destroy. |
|
274 |
currentHelpView := nil. |
|
275 |
currentView := nil. |
|
276 |
] valueUninterruptably |
|
277 |
]. |
|
278 |
currentFrame := nil. |
|
279 |
closeProcess notNil ifTrue:[ |
|
280 |
p := closeProcess. closeProcess := nil. |
|
281 |
p terminate. |
|
282 |
] |
|
283 |
||
284 |
"Modified: 28.6.1997 / 14:03:50 / cg" |
|
285 |
! |
|
286 |
||
287 |
showHelp:aHelpText for:view |
|
288 |
"show the help text for aView" |
|
289 |
||
2651 | 290 |
|wg org p v dev| |
1536 | 291 |
|
2651 | 292 |
(wg := view windowGroup) notNil ifTrue:[ |
293 |
wg isInModalLoop ifTrue:[ |
|
2628
03a41945fb37
do not show flyBy help for a view,
Claus Gittinger <cg@exept.de>
parents:
2612
diff
changeset
|
294 |
"/ Transcript showCR:'1'. |
2651 | 295 |
wg isModal ifFalse:[ |
2628
03a41945fb37
do not show flyBy help for a view,
Claus Gittinger <cg@exept.de>
parents:
2612
diff
changeset
|
296 |
"/ Transcript showCR:'2'. |
2651 | 297 |
^ self |
298 |
]. |
|
2628
03a41945fb37
do not show flyBy help for a view,
Claus Gittinger <cg@exept.de>
parents:
2612
diff
changeset
|
299 |
]. |
03a41945fb37
do not show flyBy help for a view,
Claus Gittinger <cg@exept.de>
parents:
2612
diff
changeset
|
300 |
]. |
03a41945fb37
do not show flyBy help for a view,
Claus Gittinger <cg@exept.de>
parents:
2612
diff
changeset
|
301 |
|
1536 | 302 |
view == currentView ifTrue:[ |
303 |
lastHelpText = aHelpText ifTrue:[ |
|
304 |
^ self |
|
305 |
] |
|
306 |
]. |
|
307 |
||
308 |
lastHelpText := aHelpText. |
|
309 |
||
310 |
closeProcess notNil ifTrue:[ |
|
311 |
p := closeProcess. closeProcess := nil. |
|
312 |
p terminate. |
|
313 |
]. |
|
314 |
currentHelpView notNil ifTrue:[ |
|
315 |
self hideHelp |
|
316 |
]. |
|
317 |
||
318 |
org := view originRelativeTo:nil. |
|
319 |
currentFrame := org extent:view extent. |
|
320 |
org :=org + (view extent // 2). |
|
321 |
||
1677
dc49ab70b762
open helpView on the correcdt device
Claus Gittinger <cg@exept.de>
parents:
1657
diff
changeset
|
322 |
dev := view graphicsDevice. |
1536 | 323 |
|
1963
fb6663696d20
removed withCRs in showHelp:
Claus Gittinger <cg@exept.de>
parents:
1893
diff
changeset
|
324 |
v := ActiveHelpView for:aHelpText onDevice:dev. |
1677
dc49ab70b762
open helpView on the correcdt device
Claus Gittinger <cg@exept.de>
parents:
1657
diff
changeset
|
325 |
|
1536 | 326 |
org := dev pointerPosition. |
1657 | 327 |
org := org + (0@18"24"). |
1536 | 328 |
(org x + v width) > dev width ifTrue:[ |
329 |
org := (org x - v width) @ org y |
|
330 |
]. |
|
331 |
(org y + v height) > dev height ifTrue:[ |
|
332 |
org := org x @ (org y - v height). |
|
333 |
]. |
|
334 |
||
335 |
v origin:org. |
|
336 |
v realize. |
|
337 |
v enableButtonMotionEvents. |
|
338 |
v enableMotionEvents. |
|
339 |
currentHelpView := v. |
|
2392 | 340 |
currentView := view. |
1536 | 341 |
|
2392 | 342 |
self showTime notNil ifTrue:[ |
343 |
closeProcess := [ |
|
1546 | 344 |
[ |
2392 | 345 |
(Delay forSeconds:self showTime) wait. |
346 |
[ |
|
347 |
currentHelpView notNil ifTrue:[ |
|
348 |
currentHelpView destroy. |
|
349 |
currentHelpView := nil. |
|
350 |
] |
|
351 |
] valueUninterruptably |
|
352 |
] ifCurtailed:[ |
|
353 |
closeProcess := nil. |
|
354 |
]. |
|
355 |
] newProcess. |
|
356 |
closeProcess priority:(Processor userSchedulingPriority + 1). |
|
357 |
closeProcess resume. |
|
358 |
]. |
|
1536 | 359 |
|
1963
fb6663696d20
removed withCRs in showHelp:
Claus Gittinger <cg@exept.de>
parents:
1893
diff
changeset
|
360 |
"Modified: / 31-08-1995 / 19:20:45 / claus" |
fb6663696d20
removed withCRs in showHelp:
Claus Gittinger <cg@exept.de>
parents:
1893
diff
changeset
|
361 |
"Modified: / 16-03-2004 / 15:27:50 / cg" |
1536 | 362 |
! |
363 |
||
364 |
stopHelpDisplayProcess |
|
365 |
|p| |
|
366 |
||
2680 | 367 |
(p := showProcess) notNil ifTrue:[ |
368 |
showProcess := nil. |
|
1536 | 369 |
p terminate. |
370 |
]. |
|
371 |
||
372 |
"Created: 28.6.1997 / 14:03:17 / cg" |
|
373 |
! ! |
|
374 |
||
375 |
!FlyByHelp class methodsFor:'documentation'! |
|
376 |
||
377 |
version |
|
2754 | 378 |
^ '$Header: /cvs/stx/stx/libview2/FlyByHelp.st,v 1.32 2009-10-01 07:53:07 cg Exp $' |
379 |
! |
|
380 |
||
381 |
version_CVS |
|
382 |
^ '$Header: /cvs/stx/stx/libview2/FlyByHelp.st,v 1.32 2009-10-01 07:53:07 cg Exp $' |
|
1536 | 383 |
! ! |
1657 | 384 |
|
1536 | 385 |
FlyByHelp initialize! |