author | Claus Gittinger <cg@exept.de> |
Fri, 28 Feb 1997 22:51:30 +0100 | |
changeset 465 | 5df2fbe7275a |
parent 344 | 42ae71c13eef |
child 596 | a184f2e4dbbb |
permissions | -rw-r--r-- |
59 | 1 |
" |
2 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
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 |
" |
|
12 |
||
13 |
||
14 |
EventListener subclass:#ActiveHelp |
|
216 | 15 |
instanceVariableNames:'currentView currentHelpView currentFrame showProcess closeProcess' |
16 |
classVariableNames:'DelayTime ShowTime TheOneAndOnlyHelpListener' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Interface-Help' |
|
59 | 19 |
! |
20 |
||
338
071f92621e3b
oops - catching the terminateSignal is no good idea
Claus Gittinger <cg@exept.de>
parents:
330
diff
changeset
|
21 |
!ActiveHelp class methodsFor:'documentation'! |
59 | 22 |
|
138 | 23 |
copyright |
24 |
" |
|
25 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
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 |
" |
|
35 |
||
59 | 36 |
! |
37 |
||
38 |
documentation |
|
39 |
" |
|
98 | 40 |
The active help listener. |
41 |
The one and only instance of myself intercepts incoming mouse & keyboard |
|
42 |
events for the display device, being especially interested in view-enter/ |
|
100 | 43 |
leave enents. When such an event arrives, it asks the corresponding view |
98 | 44 |
or its model for a help message and display it via an ActiveHelpView. |
100 | 45 |
This query is repeated along the views superView chain, until any model or |
46 |
view returns a nonNil answer for the #helpTextFor:at or #helpTextFor |
|
47 |
message. |
|
48 |
||
98 | 49 |
All I need for automatic help is some model/view/applicationModel along |
50 |
the superview chain of the entered component, which responds to the |
|
51 |
#helpTextFor: message with a non-nil (string-) answer. |
|
52 |
I close down the help view after a while, if a key is pressed or the mouse |
|
53 |
moved to another view. |
|
100 | 54 |
|
55 |
Who should provide the helpText: |
|
56 |
||
221 | 57 |
the best place is the application object (an instance of ApplicationModel) |
58 |
or the topView, if its a derived class of StandardSystemView. |
|
59 |
This should know about its components and return the string |
|
60 |
when asked via #helpTextFor:aComponent. |
|
330
d7ce98930ad3
Rename Launcher-->OldLauncher, NewLauncher-->Launcher.
Stefan Vogel <sv@exept.de>
parents:
297
diff
changeset
|
61 |
See examples in FileBrowser, Launcher etc. |
100 | 62 |
|
63 |
Be aware, that for applicationModels, there must be a link from the |
|
64 |
topView to this applicationModel |
|
65 |
(set via: aTopView application:anApplicationModel) |
|
66 |
otherwise, the helpManager has no means of finding the application which |
|
67 |
corresponds to a view. |
|
68 |
||
69 |
Who should display the helpText: |
|
70 |
||
221 | 71 |
by default, the helpListener opens a little popup view, which displays the |
72 |
returned help message. However, a nice trick which can be used by applications |
|
73 |
is to create an infoLabel as a subview of the topFrame (a la windows) |
|
74 |
and display the text right in the #helpTextFor: method. To cheat the |
|
75 |
help listener, this method should then return nil, to keep it silent. |
|
76 |
||
77 |
||
78 |
[author:] |
|
79 |
Claus Gittinger |
|
80 |
||
233 | 81 |
[start with:] |
82 |
ActiveHelp start |
|
83 |
ActiveHelp stop |
|
84 |
||
221 | 85 |
[See also:] |
233 | 86 |
ActiveHelpView |
87 |
WindowGroup WindowEvent |
|
88 |
ApplicationModel StandardSystemView |
|
100 | 89 |
" |
90 |
! |
|
91 |
||
92 |
examples |
|
93 |
" |
|
233 | 94 |
(make certain that activeHelp is turned on ... |
95 |
... otherwise, you will see nothing) |
|
100 | 96 |
|
97 |
the following example uses a Plug as a model replacement. |
|
98 |
In concrete application, you would create a method to implement the helpText |
|
99 |
query message. |
|
227 | 100 |
[exBegin] |
101 |
|app top button1 button2| |
|
100 | 102 |
|
227 | 103 |
app := Plug new. |
104 |
app respondTo:#helpTextFor: |
|
105 |
with:[:view | |
|
106 |
view == button1 ifTrue:[ |
|
107 |
'this is button1' |
|
108 |
] ifFalse:[ |
|
109 |
view == button2 ifTrue:[ |
|
110 |
'some help for button2' |
|
111 |
] ifFalse:[ |
|
112 |
nil |
|
113 |
] |
|
114 |
] |
|
115 |
]. |
|
100 | 116 |
|
227 | 117 |
top := StandardSystemView new. |
118 |
top extent:300@100. |
|
119 |
button1 := Button label:'b1' in:top. |
|
120 |
button1 origin:0.0@0.0 corner:0.5@30. |
|
121 |
button2 := Button label:'b2' in:top. |
|
122 |
button2 origin:0.5@0.0 corner:1.0@30. |
|
123 |
top model:app. '<-- normally this would be: top application:app'. |
|
124 |
top open |
|
125 |
[exEnd] |
|
100 | 126 |
|
233 | 127 |
(make certain that activeHelp is turned on ... |
128 |
... otherwise, you will see nothing) |
|
129 |
||
227 | 130 |
alternatively, display of the helpMessage in a local, private view: |
131 |
[exBegin] |
|
132 |
|app top button1 button2 infoView| |
|
100 | 133 |
|
227 | 134 |
app := Plug new. |
135 |
app respondTo:#helpTextFor: |
|
136 |
with:[:view | infoView label:'info ...'. |
|
137 |
view == button1 ifTrue:[ |
|
138 |
infoView label:'this is button1' |
|
139 |
]. |
|
140 |
view == button2 ifTrue:[ |
|
141 |
infoView label:'some help for button2' |
|
142 |
]. |
|
143 |
nil |
|
144 |
]. |
|
100 | 145 |
|
227 | 146 |
top := StandardSystemView new. |
147 |
top extent:300@100. |
|
148 |
button1 := Button label:'b1' in:top. |
|
149 |
button1 origin:0.0@0.0 corner:0.5@30. |
|
150 |
button2 := Button label:'b2' in:top. |
|
151 |
button2 origin:0.5@0.0 corner:1.0@30. |
|
152 |
infoView := Label label:'info ...' in:top. |
|
153 |
infoView level:-1; origin:0.0@1.0 corner:1.0@1.0. |
|
154 |
infoView topInset:(infoView preferredExtent y negated - 3); |
|
155 |
leftInset:3; |
|
156 |
rightInset:3; |
|
157 |
bottomInset:3; |
|
158 |
adjust:#left. |
|
159 |
top model:app. '<-- normally this would be: top application:app'. |
|
160 |
top open |
|
161 |
[exEnd] |
|
59 | 162 |
" |
163 |
! ! |
|
164 |
||
338
071f92621e3b
oops - catching the terminateSignal is no good idea
Claus Gittinger <cg@exept.de>
parents:
330
diff
changeset
|
165 |
!ActiveHelp class methodsFor:'initialization'! |
59 | 166 |
|
167 |
initialize |
|
233 | 168 |
"set default delay & help-display times" |
169 |
||
92 | 170 |
ShowTime := 15. |
100 | 171 |
DelayTime := 2. |
92 | 172 |
|
173 |
" |
|
174 |
ActiveHelp initialize |
|
175 |
" |
|
233 | 176 |
|
177 |
"Modified: 27.4.1996 / 15:07:27 / cg" |
|
59 | 178 |
! ! |
179 |
||
338
071f92621e3b
oops - catching the terminateSignal is no good idea
Claus Gittinger <cg@exept.de>
parents:
330
diff
changeset
|
180 |
!ActiveHelp class methodsFor:'startup'! |
100 | 181 |
|
233 | 182 |
isActive |
183 |
"return true, if activeHelp is turned on" |
|
184 |
||
138 | 185 |
^ TheOneAndOnlyHelpListener notNil |
233 | 186 |
|
187 |
"Modified: 27.4.1996 / 15:07:57 / cg" |
|
138 | 188 |
! |
59 | 189 |
|
190 |
start |
|
233 | 191 |
"start activeHelp" |
192 |
||
59 | 193 |
TheOneAndOnlyHelpListener isNil ifTrue:[ |
233 | 194 |
TheOneAndOnlyHelpListener := self new. |
59 | 195 |
]. |
196 |
TheOneAndOnlyHelpListener listen |
|
197 |
||
198 |
" |
|
199 |
ActiveHelp start |
|
200 |
" |
|
233 | 201 |
|
202 |
"Modified: 27.4.1996 / 15:08:05 / cg" |
|
59 | 203 |
! |
204 |
||
205 |
stop |
|
233 | 206 |
"stop activeHelp" |
207 |
||
59 | 208 |
TheOneAndOnlyHelpListener notNil ifTrue:[ |
233 | 209 |
TheOneAndOnlyHelpListener unlisten. |
59 | 210 |
]. |
92 | 211 |
TheOneAndOnlyHelpListener := nil |
59 | 212 |
|
213 |
" |
|
214 |
ActiveHelp stop |
|
215 |
" |
|
233 | 216 |
|
217 |
"Modified: 27.4.1996 / 15:08:11 / cg" |
|
138 | 218 |
! ! |
219 |
||
338
071f92621e3b
oops - catching the terminateSignal is no good idea
Claus Gittinger <cg@exept.de>
parents:
330
diff
changeset
|
220 |
!ActiveHelp class methodsFor:'times'! |
138 | 221 |
|
222 |
delayTime:numberOfSeconds |
|
223 |
"set the delay (the time, the cursor has to be in the view |
|
224 |
before help is shown). The default is 2 seconds." |
|
225 |
||
226 |
DelayTime := numberOfSeconds |
|
227 |
||
228 |
" |
|
229 |
ActiveHelp delayTime:0.5 |
|
230 |
ActiveHelp delayTime:2 |
|
231 |
ActiveHelp delayTime:10 |
|
232 |
" |
|
59 | 233 |
! |
234 |
||
138 | 235 |
showTime:numberOfSeconds |
236 |
"set the number of seconds, a help messages is to be shown. |
|
237 |
The default is 15 seconds." |
|
238 |
||
239 |
ShowTime := numberOfSeconds |
|
240 |
||
241 |
" |
|
242 |
ActiveHelp showTime:10 |
|
243 |
ActiveHelp showTime:99999 |
|
244 |
ActiveHelp showTime:30 |
|
245 |
" |
|
246 |
! ! |
|
247 |
||
248 |
!ActiveHelp methodsFor:'listening'! |
|
249 |
||
250 |
buttonMotion:state x:x y:y view:view |
|
233 | 251 |
"handle motion events - if the mousepointer left the |
252 |
previous helped view, hide the help" |
|
253 |
||
138 | 254 |
self hideIfPointerLeft:view. |
255 |
^ false |
|
233 | 256 |
|
257 |
"Modified: 27.4.1996 / 15:09:48 / cg" |
|
138 | 258 |
! |
259 |
||
260 |
buttonPress:state x:x y:y view:view |
|
233 | 261 |
"handle button press - unconditionally hide the help" |
262 |
||
138 | 263 |
self hideHelp. |
264 |
^ false |
|
233 | 265 |
|
266 |
"Modified: 27.4.1996 / 15:09:45 / cg" |
|
138 | 267 |
! |
268 |
||
269 |
keyPress:state x:x y:y view:view |
|
233 | 270 |
"handle key press - unconditionally hide the help" |
271 |
||
138 | 272 |
self hideHelp. |
273 |
^ false |
|
233 | 274 |
|
275 |
"Modified: 27.4.1996 / 15:09:57 / cg" |
|
138 | 276 |
! |
277 |
||
278 |
pointerEnter:state x:x y:y view:aView |
|
233 | 279 |
"handle pointer entering a view; setup timeOut to show help" |
280 |
||
344 | 281 |
|p| |
138 | 282 |
|
283 |
showProcess notNil ifTrue:[ |
|
233 | 284 |
p := showProcess. showProcess := nil. |
285 |
p terminate. |
|
138 | 286 |
]. |
287 |
self hideIfPointerLeft:aView. |
|
288 |
aView topView == currentHelpView ifTrue:[ |
|
233 | 289 |
^ true |
138 | 290 |
]. |
291 |
||
292 |
self initiateHelpFor:aView atX:x y:y. |
|
293 |
^ false |
|
233 | 294 |
|
295 |
"Modified: 27.4.1996 / 15:10:27 / cg" |
|
138 | 296 |
! |
297 |
||
298 |
pointerLeave:state view:view |
|
233 | 299 |
"handle pointer leaving a view; hide help text" |
300 |
||
138 | 301 |
self hideIfPointerLeft:view. |
302 |
^ false |
|
233 | 303 |
|
304 |
"Modified: 27.4.1996 / 15:10:41 / cg" |
|
59 | 305 |
! ! |
306 |
||
307 |
!ActiveHelp methodsFor:'private'! |
|
308 |
||
309 |
helpTextFor:aView atX:x y:y |
|
233 | 310 |
"retrieve helptext for aView as a string; |
100 | 311 |
walk along the views superView chain, |
312 |
asking models and views encountered while walking. |
|
313 |
The first one who understands and returns a nonNil answer to the |
|
233 | 314 |
#helpTextFor:at: or #helpTextFor: message ends this search and the |
100 | 315 |
returned string is returned." |
316 |
||
344 | 317 |
|model text view v sv| |
59 | 318 |
|
319 |
view := aView. |
|
320 |
(model := aView model) notNil ifTrue:[ |
|
233 | 321 |
(model respondsTo:#helpTextFor:at:) ifTrue:[ |
322 |
text := model helpTextFor:aView at:x@y. |
|
323 |
text notNil ifTrue:[^ text]. |
|
324 |
]. |
|
325 |
(model respondsTo:#helpTextFor:) ifTrue:[ |
|
326 |
text := model helpTextFor:aView. |
|
327 |
text notNil ifTrue:[^ text]. |
|
328 |
] |
|
59 | 329 |
]. |
330 |
||
331 |
(aView respondsTo:#helpText) ifTrue:[ |
|
233 | 332 |
text := aView helpText. |
333 |
text notNil ifTrue:[^ text]. |
|
59 | 334 |
]. |
335 |
||
336 |
"walk up the chain - maybe someone knows about its subview ..." |
|
337 |
v := aView. |
|
338 |
||
296 | 339 |
[(sv := v container) notNil] whileTrue:[ |
233 | 340 |
(model := sv model) notNil ifTrue:[ |
341 |
(model respondsTo:#helpTextFor:at:) ifTrue:[ |
|
342 |
text := model helpTextFor:aView at:x@y. |
|
343 |
text notNil ifTrue:[^ text]. |
|
344 |
]. |
|
345 |
(model respondsTo:#helpTextFor:) ifTrue:[ |
|
346 |
text := model helpTextFor:aView. |
|
347 |
text notNil ifTrue:[^ text]. |
|
348 |
] |
|
349 |
]. |
|
59 | 350 |
|
233 | 351 |
(sv respondsTo:#helpTextFor:) ifTrue:[ |
352 |
text := sv helpTextFor:aView. |
|
353 |
text notNil ifTrue:[^ text]. |
|
354 |
text := sv helpTextFor:v. |
|
355 |
text notNil ifTrue:[^ text]. |
|
356 |
]. |
|
357 |
v := sv. |
|
59 | 358 |
]. |
359 |
||
100 | 360 |
(v notNil and:[v respondsTo:#application]) ifTrue:[ |
233 | 361 |
(model := v application) notNil ifTrue:[ |
362 |
(model respondsTo:#helpTextFor:at:) ifTrue:[ |
|
363 |
text := model helpTextFor:aView at:x@y. |
|
364 |
text notNil ifTrue:[^ text]. |
|
365 |
]. |
|
366 |
(model respondsTo:#helpTextFor:) ifTrue:[ |
|
367 |
text := model helpTextFor:aView. |
|
368 |
text notNil ifTrue:[^ text]. |
|
369 |
] |
|
370 |
] |
|
100 | 371 |
]. |
372 |
(v notNil and:[v respondsTo:#model]) ifTrue:[ |
|
233 | 373 |
(model := v model) notNil ifTrue:[ |
374 |
(model respondsTo:#helpTextFor:at:) ifTrue:[ |
|
375 |
text := model helpTextFor:aView at:x@y. |
|
376 |
text notNil ifTrue:[^ text]. |
|
377 |
]. |
|
378 |
(model respondsTo:#helpTextFor:) ifTrue:[ |
|
379 |
text := model helpTextFor:aView. |
|
380 |
text notNil ifTrue:[^ text]. |
|
381 |
] |
|
382 |
] |
|
100 | 383 |
]. |
384 |
||
59 | 385 |
(view class respondsTo:#helpText) ifTrue:[ |
233 | 386 |
text := view class helpText. |
387 |
text notNil ifTrue:[^ text]. |
|
59 | 388 |
]. |
389 |
||
390 |
^ nil |
|
100 | 391 |
|
392 |
"Modified: 31.8.1995 / 20:38:00 / claus" |
|
296 | 393 |
"Modified: 5.6.1996 / 14:18:23 / cg" |
100 | 394 |
! |
395 |
||
138 | 396 |
hideIfPointerLeft:aView |
233 | 397 |
"hide help, if the pointer is not in aView" |
398 |
||
138 | 399 |
|whereOnScreen p| |
400 |
||
401 |
"/ showProcess notNil ifTrue:[ |
|
402 |
"/ p := showProcess. showProcess := nil. |
|
403 |
"/ p terminate. |
|
404 |
"/ ]. |
|
405 |
||
276 | 406 |
whereOnScreen := aView graphicsDevice pointerPosition. |
138 | 407 |
|
408 |
(currentFrame notNil |
|
409 |
and:[(currentFrame insetBy:1@1) containsPoint:whereOnScreen]) ifFalse:[ |
|
233 | 410 |
self hideHelp. |
411 |
currentView := nil |
|
138 | 412 |
]. |
233 | 413 |
|
276 | 414 |
"Modified: 28.5.1996 / 20:18:28 / cg" |
138 | 415 |
! |
416 |
||
100 | 417 |
initiateHelpFor:aView atX:x y:y |
233 | 418 |
"start a timeout process to display help for aView after some delay" |
419 |
||
100 | 420 |
|text p| |
421 |
||
422 |
text := self helpTextFor:aView atX:x y:y. |
|
423 |
||
424 |
text notNil ifTrue:[ |
|
233 | 425 |
DelayTime > 0 ifTrue:[ |
426 |
showProcess notNil ifTrue:[ |
|
427 |
p := showProcess. showProcess := nil. |
|
428 |
p terminate. |
|
429 |
]. |
|
430 |
showProcess := [ |
|
297 | 431 |
Delay waitForSeconds:DelayTime. |
233 | 432 |
showProcess := nil. |
433 |
self showHelp:text for:aView |
|
434 |
] forkAt:(Processor userSchedulingPriority + 1). |
|
435 |
] ifFalse:[ |
|
436 |
self showHelp:text for:aView |
|
437 |
] |
|
100 | 438 |
]. |
233 | 439 |
|
297 | 440 |
"Modified: 7.6.1996 / 10:02:19 / cg" |
59 | 441 |
! ! |
442 |
||
443 |
!ActiveHelp methodsFor:'show / hide help'! |
|
444 |
||
445 |
hideHelp |
|
233 | 446 |
"hide the help text" |
447 |
||
98 | 448 |
|p| |
449 |
||
92 | 450 |
showProcess notNil ifTrue:[ |
233 | 451 |
p := showProcess. showProcess := nil. |
452 |
p terminate. |
|
92 | 453 |
]. |
59 | 454 |
currentHelpView notNil ifTrue:[ |
233 | 455 |
[ |
456 |
currentHelpView destroy. |
|
457 |
currentHelpView := nil. |
|
458 |
currentView := nil. |
|
459 |
] valueUninterruptably |
|
59 | 460 |
]. |
461 |
currentFrame := nil. |
|
462 |
closeProcess notNil ifTrue:[ |
|
233 | 463 |
p := closeProcess. closeProcess := nil. |
464 |
p terminate. |
|
59 | 465 |
] |
233 | 466 |
|
467 |
"Modified: 27.4.1996 / 15:12:13 / cg" |
|
59 | 468 |
! |
469 |
||
470 |
showHelp:aHelpText for:view |
|
233 | 471 |
"show the help text for aView" |
472 |
||
276 | 473 |
|org p v dev| |
59 | 474 |
|
475 |
view == currentView ifTrue:[^ self]. |
|
476 |
||
92 | 477 |
closeProcess notNil ifTrue:[ |
233 | 478 |
p := closeProcess. closeProcess := nil. |
479 |
p terminate. |
|
92 | 480 |
]. |
59 | 481 |
currentHelpView notNil ifTrue:[ |
233 | 482 |
self hideHelp |
59 | 483 |
]. |
484 |
||
485 |
org := view originRelativeTo:nil. |
|
486 |
currentFrame := org extent:view extent. |
|
487 |
org :=org + (view extent // 2). |
|
488 |
||
100 | 489 |
v := ActiveHelpView for:aHelpText withCRs. |
59 | 490 |
|
276 | 491 |
dev := view graphicsDevice. |
492 |
org := dev pointerPosition. |
|
100 | 493 |
org := org + (10@10). |
276 | 494 |
(org x + v width) > dev width ifTrue:[ |
233 | 495 |
org := (org x - v width) @ org y |
92 | 496 |
]. |
276 | 497 |
(org y + v height) > dev height ifTrue:[ |
233 | 498 |
org := org x @ (org y - v height). |
92 | 499 |
]. |
500 |
||
100 | 501 |
v origin:org. |
59 | 502 |
"/ currentHelpView open. |
100 | 503 |
v realize. |
504 |
v enableButtonMotionEvents. |
|
505 |
v enableMotionEvents. |
|
506 |
currentHelpView := v. |
|
59 | 507 |
|
508 |
currentView := view. |
|
509 |
closeProcess := [ |
|
338
071f92621e3b
oops - catching the terminateSignal is no good idea
Claus Gittinger <cg@exept.de>
parents:
330
diff
changeset
|
510 |
[ |
233 | 511 |
(Delay forSeconds:ShowTime) wait. |
512 |
[ |
|
513 |
currentHelpView notNil ifTrue:[ |
|
514 |
currentHelpView destroy. |
|
515 |
currentHelpView := nil. |
|
516 |
] |
|
517 |
] valueUninterruptably |
|
338
071f92621e3b
oops - catching the terminateSignal is no good idea
Claus Gittinger <cg@exept.de>
parents:
330
diff
changeset
|
518 |
] valueOnUnwindDo:[ |
071f92621e3b
oops - catching the terminateSignal is no good idea
Claus Gittinger <cg@exept.de>
parents:
330
diff
changeset
|
519 |
closeProcess := nil. |
233 | 520 |
]. |
59 | 521 |
] forkAt:(Processor userSchedulingPriority + 1). |
100 | 522 |
|
523 |
"Modified: 31.8.1995 / 19:20:45 / claus" |
|
338
071f92621e3b
oops - catching the terminateSignal is no good idea
Claus Gittinger <cg@exept.de>
parents:
330
diff
changeset
|
524 |
"Modified: 16.10.1996 / 00:36:22 / cg" |
59 | 525 |
! ! |
526 |
||
338
071f92621e3b
oops - catching the terminateSignal is no good idea
Claus Gittinger <cg@exept.de>
parents:
330
diff
changeset
|
527 |
!ActiveHelp class methodsFor:'documentation'! |
138 | 528 |
|
529 |
version |
|
344 | 530 |
^ '$Header: /cvs/stx/stx/libview2/ActiveHelp.st,v 1.18 1996-10-26 16:56:48 cg Exp $' |
138 | 531 |
! ! |
59 | 532 |
ActiveHelp initialize! |