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