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