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 |
"
|
98
|
27 |
$Header: /cvs/stx/stx/libview2/ActiveHelp.st,v 1.4 1995-08-29 23:42:57 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/
|
|
36 |
leave ebents. When such an event arrives, it asks the corresponding view
|
|
37 |
or its model for a help message and display it via an ActiveHelpView.
|
|
38 |
All I need for automatic help is some model/view/applicationModel along
|
|
39 |
the superview chain of the entered component, which responds to the
|
|
40 |
#helpTextFor: message with a non-nil (string-) answer.
|
|
41 |
I close down the help view after a while, if a key is pressed or the mouse
|
|
42 |
moved to another view.
|
59
|
43 |
"
|
|
44 |
!
|
|
45 |
|
|
46 |
copyright
|
|
47 |
"
|
|
48 |
COPYRIGHT (c) 1995 by Claus Gittinger
|
|
49 |
All Rights Reserved
|
|
50 |
|
|
51 |
This software is furnished under a license and may be used
|
|
52 |
only in accordance with the terms of that license and with the
|
|
53 |
inclusion of the above copyright notice. This software may not
|
|
54 |
be provided or otherwise made available to, or used by, any
|
|
55 |
other person. No title to or ownership of the software is
|
|
56 |
hereby transferred.
|
|
57 |
"
|
|
58 |
|
|
59 |
! !
|
|
60 |
|
|
61 |
!ActiveHelp class methodsFor:'initialization'!
|
|
62 |
|
|
63 |
initialize
|
92
|
64 |
ShowTime := 15.
|
|
65 |
DelayTime := 1.
|
|
66 |
|
|
67 |
"
|
|
68 |
ActiveHelp initialize
|
|
69 |
"
|
59
|
70 |
! !
|
|
71 |
|
|
72 |
!ActiveHelp class methodsFor:'startup'!
|
|
73 |
|
|
74 |
start
|
|
75 |
TheOneAndOnlyHelpListener isNil ifTrue:[
|
|
76 |
TheOneAndOnlyHelpListener := self new.
|
|
77 |
].
|
|
78 |
TheOneAndOnlyHelpListener listen
|
|
79 |
|
|
80 |
"
|
|
81 |
ActiveHelp start
|
|
82 |
"
|
|
83 |
!
|
|
84 |
|
|
85 |
stop
|
|
86 |
TheOneAndOnlyHelpListener notNil ifTrue:[
|
|
87 |
TheOneAndOnlyHelpListener unlisten.
|
|
88 |
].
|
92
|
89 |
TheOneAndOnlyHelpListener := nil
|
59
|
90 |
|
|
91 |
"
|
|
92 |
ActiveHelp stop
|
|
93 |
"
|
|
94 |
!
|
|
95 |
|
92
|
96 |
isActive
|
|
97 |
^ TheOneAndOnlyHelpListener notNil
|
59
|
98 |
! !
|
|
99 |
|
|
100 |
!ActiveHelp methodsFor:'private'!
|
|
101 |
|
|
102 |
helpTextFor:aView atX:x y:y
|
|
103 |
|model text view org found v sv|
|
|
104 |
|
|
105 |
view := aView.
|
|
106 |
|
|
107 |
(model := aView model) notNil ifTrue:[
|
|
108 |
"/ model printNL.
|
|
109 |
(model respondsTo:#helpTextFor:at:) ifTrue:[
|
|
110 |
text := model helpTextFor:aView at:x@y.
|
|
111 |
text notNil ifTrue:[^ text].
|
|
112 |
].
|
|
113 |
(model respondsTo:#helpTextFor:) ifTrue:[
|
|
114 |
text := model helpTextFor:aView.
|
|
115 |
text notNil ifTrue:[^ text].
|
|
116 |
]
|
|
117 |
].
|
|
118 |
|
|
119 |
(aView respondsTo:#helpText) ifTrue:[
|
|
120 |
text := aView helpText.
|
|
121 |
text notNil ifTrue:[^ text].
|
|
122 |
].
|
|
123 |
|
|
124 |
"walk up the chain - maybe someone knows about its subview ..."
|
|
125 |
v := aView.
|
|
126 |
|
|
127 |
[(sv := v superView) notNil] whileTrue:[
|
|
128 |
(model := sv model) notNil ifTrue:[
|
|
129 |
(model respondsTo:#helpTextFor:at:) ifTrue:[
|
|
130 |
text := model helpTextFor:aView at:x@y.
|
|
131 |
text notNil ifTrue:[^ text].
|
|
132 |
].
|
|
133 |
(model respondsTo:#helpTextFor:) ifTrue:[
|
|
134 |
text := model helpTextFor:aView.
|
|
135 |
text notNil ifTrue:[^ text].
|
|
136 |
]
|
|
137 |
].
|
|
138 |
|
|
139 |
(sv respondsTo:#helpTextFor:) ifTrue:[
|
|
140 |
text := sv helpTextFor:aView.
|
|
141 |
text notNil ifTrue:[^ text].
|
|
142 |
text := sv helpTextFor:v.
|
|
143 |
text notNil ifTrue:[^ text].
|
|
144 |
].
|
|
145 |
v := sv.
|
|
146 |
].
|
|
147 |
|
|
148 |
(view class respondsTo:#helpText) ifTrue:[
|
|
149 |
text := view class helpText.
|
|
150 |
text notNil ifTrue:[^ text].
|
|
151 |
].
|
|
152 |
|
|
153 |
^ nil
|
|
154 |
!
|
|
155 |
|
|
156 |
hideIfPointerLeft:aView
|
98
|
157 |
|whereOnScreen p|
|
59
|
158 |
|
92
|
159 |
showProcess notNil ifTrue:[
|
98
|
160 |
p := showProcess. showProcess := nil.
|
|
161 |
p terminate.
|
92
|
162 |
].
|
|
163 |
|
59
|
164 |
whereOnScreen := aView device pointerPosition.
|
|
165 |
|
|
166 |
(currentFrame notNil
|
|
167 |
and:[(currentFrame insetBy:1@1) containsPoint:whereOnScreen]) ifFalse:[
|
|
168 |
self hideHelp.
|
|
169 |
currentView := nil
|
|
170 |
].
|
|
171 |
! !
|
|
172 |
|
|
173 |
!ActiveHelp methodsFor:'listening'!
|
|
174 |
|
|
175 |
buttonPress:state x:x y:y view:view
|
|
176 |
self hideHelp.
|
|
177 |
^ false
|
|
178 |
!
|
|
179 |
|
|
180 |
pointerEnter:state x:x y:y view:aView
|
98
|
181 |
|text p|
|
59
|
182 |
|
92
|
183 |
showProcess notNil ifTrue:[
|
98
|
184 |
p := showProcess. showProcess := nil.
|
|
185 |
p terminate.
|
92
|
186 |
].
|
59
|
187 |
self hideIfPointerLeft:aView.
|
|
188 |
aView topView == currentHelpView ifTrue:[
|
|
189 |
^ true
|
|
190 |
].
|
|
191 |
|
|
192 |
text := self helpTextFor:aView atX:x y:y.
|
|
193 |
|
|
194 |
text notNil ifTrue:[
|
92
|
195 |
DelayTime > 0 ifTrue:[
|
|
196 |
showProcess notNil ifTrue:[
|
98
|
197 |
p := showProcess. showProcess := nil.
|
|
198 |
p terminate.
|
92
|
199 |
].
|
|
200 |
showProcess := [
|
|
201 |
(Delay forSeconds:DelayTime) wait.
|
|
202 |
showProcess := nil.
|
|
203 |
self showHelp:text for:aView
|
|
204 |
] forkAt:(Processor userSchedulingPriority + 1).
|
|
205 |
] ifFalse:[
|
|
206 |
self showHelp:text for:aView
|
|
207 |
]
|
59
|
208 |
].
|
|
209 |
|
|
210 |
^ false
|
|
211 |
!
|
|
212 |
|
|
213 |
pointerLeave:state view:view
|
|
214 |
self hideIfPointerLeft:view.
|
|
215 |
^ false
|
|
216 |
!
|
|
217 |
|
|
218 |
keyPress:state x:x y:y view:view
|
|
219 |
self hideHelp.
|
|
220 |
^ false
|
|
221 |
!
|
|
222 |
|
|
223 |
buttonMotion:state x:x y:y view:view
|
|
224 |
self hideIfPointerLeft:view.
|
|
225 |
^ false
|
|
226 |
! !
|
|
227 |
|
|
228 |
!ActiveHelp methodsFor:'show / hide help'!
|
|
229 |
|
|
230 |
hideHelp
|
98
|
231 |
|p|
|
|
232 |
|
92
|
233 |
showProcess notNil ifTrue:[
|
98
|
234 |
p := showProcess. showProcess := nil.
|
|
235 |
p terminate.
|
92
|
236 |
].
|
59
|
237 |
currentHelpView notNil ifTrue:[
|
|
238 |
[
|
|
239 |
currentHelpView destroy.
|
|
240 |
currentHelpView := nil.
|
|
241 |
currentView := nil.
|
|
242 |
] valueUninterruptably
|
|
243 |
].
|
|
244 |
currentFrame := nil.
|
|
245 |
closeProcess notNil ifTrue:[
|
98
|
246 |
p := closeProcess. closeProcess := nil.
|
|
247 |
p terminate.
|
59
|
248 |
]
|
|
249 |
!
|
|
250 |
|
|
251 |
showHelp:aHelpText for:view
|
98
|
252 |
|org p|
|
59
|
253 |
|
|
254 |
view == currentView ifTrue:[^ self].
|
|
255 |
|
92
|
256 |
closeProcess notNil ifTrue:[
|
98
|
257 |
p := closeProcess. closeProcess := nil.
|
|
258 |
p terminate.
|
92
|
259 |
].
|
59
|
260 |
currentHelpView notNil ifTrue:[
|
|
261 |
self hideHelp
|
|
262 |
].
|
|
263 |
|
|
264 |
org := view originRelativeTo:nil.
|
|
265 |
currentFrame := org extent:view extent.
|
|
266 |
org :=org + (view extent // 2).
|
|
267 |
|
92
|
268 |
currentHelpView := ActiveHelpView for:aHelpText withCRs.
|
59
|
269 |
|
92
|
270 |
org := view device pointerPosition.
|
|
271 |
org := org + (20@20).
|
|
272 |
(org x + currentHelpView width) > view device width ifTrue:[
|
|
273 |
org := (org x - currentHelpView width) @ org y
|
|
274 |
].
|
|
275 |
(org y + currentHelpView height) > view device height ifTrue:[
|
|
276 |
org := org x @ (org y - currentHelpView height).
|
|
277 |
].
|
|
278 |
|
59
|
279 |
currentHelpView origin:org.
|
|
280 |
"/ currentHelpView open.
|
|
281 |
currentHelpView realize.
|
|
282 |
currentHelpView enableButtonMotionEvents.
|
|
283 |
currentHelpView enableMotionEvents.
|
|
284 |
|
|
285 |
currentView := view.
|
|
286 |
closeProcess := [
|
|
287 |
Process terminateSignal handle:[:ex |
|
|
288 |
closeProcess := nil.
|
|
289 |
] do:[
|
|
290 |
(Delay forSeconds:ShowTime) wait.
|
|
291 |
[
|
|
292 |
currentHelpView notNil ifTrue:[
|
|
293 |
currentHelpView destroy.
|
|
294 |
currentHelpView := nil.
|
|
295 |
]
|
|
296 |
] valueUninterruptably
|
|
297 |
].
|
|
298 |
] forkAt:(Processor userSchedulingPriority + 1).
|
|
299 |
! !
|
|
300 |
|
|
301 |
ActiveHelp initialize!
|