author | Claus Gittinger <cg@exept.de> |
Thu, 24 Oct 2002 21:16:06 +0200 | |
changeset 1646 | da8d044c7c0d |
parent 1596 | bc7a430e6e41 |
child 1657 | 447db4aae998 |
permissions | -rw-r--r-- |
1536 | 1 |
"{ Package: 'stx:libview2' }" |
2 |
||
3 |
ActiveHelp subclass:#FlyByHelp |
|
4 |
instanceVariableNames:'currentFrame currentView currentHelpView showProcess closeProcess' |
|
5 |
classVariableNames:'DelayTime ShowTime TheOneAndOnlyHelpListener' |
|
6 |
poolDictionaries:'' |
|
7 |
category:'Interface-Help' |
|
8 |
! |
|
9 |
||
10 |
||
11 |
!FlyByHelp class methodsFor:'initialization'! |
|
12 |
||
13 |
initialize |
|
14 |
"set default delay & help-display times" |
|
15 |
||
16 |
ShowTime := 15. |
|
1596 | 17 |
DelayTime := 0.5. |
1536 | 18 |
|
19 |
" |
|
20 |
FlyByHelp initialize |
|
21 |
" |
|
22 |
||
23 |
"Modified: 27.4.1996 / 15:07:27 / cg" |
|
24 |
! ! |
|
25 |
||
26 |
!FlyByHelp class methodsFor:'start & stop'! |
|
27 |
||
28 |
start |
|
29 |
"start activeHelp for all apps" |
|
30 |
||
31 |
TheOneAndOnlyHelpListener isNil ifTrue:[ |
|
32 |
TheOneAndOnlyHelpListener := self new. |
|
33 |
]. |
|
34 |
TheOneAndOnlyHelpListener listenForAll |
|
35 |
||
36 |
" |
|
1542 | 37 |
FlyByHelp start |
38 |
FlyByHelp stop |
|
39 |
" |
|
40 |
! |
|
41 |
||
42 |
stop |
|
43 |
"stop activeHelp for all (except for individual apps)" |
|
44 |
||
45 |
TheOneAndOnlyHelpListener notNil ifTrue:[ |
|
46 |
TheOneAndOnlyHelpListener unlistenAll. |
|
47 |
TheOneAndOnlyHelpListener := nil. |
|
48 |
]. |
|
49 |
||
50 |
" |
|
51 |
FlyByHelp start |
|
52 |
FlyByHelp stop |
|
1536 | 53 |
" |
54 |
! ! |
|
55 |
||
1540 | 56 |
!FlyByHelp methodsFor:'listening'! |
57 |
||
58 |
buttonMotion:state x:x y:y view:aView |
|
59 |
aView == currentHelpView ifTrue:[^ self]. |
|
60 |
super buttonMotion:state x:x y:y view:aView |
|
61 |
! |
|
62 |
||
63 |
pointerLeave:state view:aView |
|
64 |
aView == currentHelpView ifTrue:[^ self]. |
|
65 |
super pointerLeave:state view:aView |
|
66 |
! ! |
|
67 |
||
1536 | 68 |
!FlyByHelp methodsFor:'private'! |
69 |
||
70 |
helpTextFromModel:aModel view:aView at:aPointOrNil |
|
71 |
"helper: ask aModel for its helpText." |
|
72 |
||
73 |
|text| |
|
74 |
||
75 |
aPointOrNil notNil ifTrue:[ |
|
76 |
(aModel respondsTo:#flyByHelpTextFor:at:) ifTrue:[ |
|
77 |
text := aModel flyByHelpTextFor:aView at:aPointOrNil. |
|
78 |
]. |
|
79 |
]. |
|
80 |
text isNil ifTrue:[ |
|
81 |
(aModel respondsTo:#flyByHelpTextFor:) ifTrue:[ |
|
82 |
text := aModel flyByHelpTextFor:aView. |
|
83 |
]. |
|
84 |
]. |
|
85 |
^ text |
|
86 |
! |
|
87 |
||
88 |
helpTextFromView:aView at:aPointOrNil |
|
89 |
"helper: ask aView for its helpText." |
|
90 |
||
91 |
|text| |
|
92 |
||
93 |
aPointOrNil notNil ifTrue:[ |
|
94 |
(aView respondsTo:#flyByHelpTextAt:) ifTrue:[ |
|
95 |
text := aView flyByHelpTextAt:aPointOrNil. |
|
96 |
]. |
|
97 |
]. |
|
98 |
text isNil ifTrue:[ |
|
99 |
(aView respondsTo:#flyByHelpText) ifTrue:[ |
|
100 |
text := aView flyByHelpText. |
|
101 |
]. |
|
102 |
]. |
|
103 |
^ text. |
|
104 |
! |
|
105 |
||
106 |
hideIfPointerLeft:aView |
|
107 |
"hide help, if the pointer is not in aView" |
|
108 |
||
109 |
|whereOnScreen| |
|
110 |
||
111 |
currentFrame notNil ifTrue:[ |
|
112 |
whereOnScreen := aView graphicsDevice pointerPosition. |
|
113 |
||
114 |
(currentFrame notNil |
|
115 |
and:[(currentFrame insetBy:1@1) containsPoint:whereOnScreen]) ifFalse:[ |
|
116 |
self hideHelp. |
|
117 |
]. |
|
118 |
]. |
|
119 |
||
120 |
"Modified: 28.5.1996 / 20:18:28 / cg" |
|
121 |
! |
|
122 |
||
123 |
initiateHelpFor:aView at:aPointOrNil now:showItNow |
|
124 |
"ask aView for helpText, passing x/y coordinates; |
|
125 |
start a timeout process to display this helpText after some delay; |
|
126 |
Normally used internally, but can also be used by widgets to force |
|
127 |
re-negotiation of the displayed helpText |
|
128 |
(for example in a menu, when the selection changes)" |
|
129 |
||
130 |
|text| |
|
131 |
||
132 |
(self interestedIn:aView) ifFalse:[ |
|
133 |
^ self |
|
134 |
]. |
|
135 |
||
136 |
text := self helpTextFor:aView at:aPointOrNil. |
|
137 |
lastHelpText = text ifTrue:[ |
|
138 |
^ self |
|
139 |
]. |
|
140 |
||
141 |
text size > 0 ifTrue:[ |
|
142 |
(showItNow not and:[DelayTime > 0]) ifTrue:[ |
|
143 |
self stopHelpDisplayProcess. |
|
144 |
showProcess := [ |
|
145 |
Delay waitForSeconds:DelayTime. |
|
146 |
showProcess := nil. |
|
147 |
self showHelp:text for:aView |
|
148 |
] forkAt:(Processor userSchedulingPriority + 1). |
|
149 |
] ifFalse:[ |
|
150 |
self showHelp:text for:aView |
|
151 |
] |
|
1542 | 152 |
] ifFalse:[ |
153 |
self hideHelp |
|
1536 | 154 |
]. |
155 |
! |
|
156 |
||
157 |
interestedIn:aView |
|
158 |
"return true, if I am interested in aView (either listeningForAll, |
|
159 |
or in my list of apps)" |
|
160 |
||
161 |
aView isNil ifTrue:[^ false]. |
|
162 |
aView topView == currentHelpView ifTrue:[^ false]. |
|
163 |
||
164 |
^ super interestedIn:aView |
|
165 |
! ! |
|
166 |
||
167 |
!FlyByHelp methodsFor:'show / hide help'! |
|
168 |
||
169 |
hideHelp |
|
170 |
"hide the help text" |
|
171 |
||
172 |
|p| |
|
173 |
||
1540 | 174 |
lastHelpText := nil. |
1536 | 175 |
self stopHelpDisplayProcess. |
176 |
||
177 |
currentHelpView notNil ifTrue:[ |
|
178 |
[ |
|
179 |
currentHelpView destroy. |
|
180 |
currentHelpView := nil. |
|
181 |
currentView := nil. |
|
182 |
] valueUninterruptably |
|
183 |
]. |
|
184 |
currentFrame := nil. |
|
185 |
closeProcess notNil ifTrue:[ |
|
186 |
p := closeProcess. closeProcess := nil. |
|
187 |
p terminate. |
|
188 |
] |
|
189 |
||
190 |
"Modified: 28.6.1997 / 14:03:50 / cg" |
|
191 |
! |
|
192 |
||
193 |
showHelp:aHelpText for:view |
|
194 |
"show the help text for aView" |
|
195 |
||
196 |
|org p v dev| |
|
197 |
||
198 |
view == currentView ifTrue:[ |
|
199 |
lastHelpText = aHelpText ifTrue:[ |
|
200 |
^ self |
|
201 |
] |
|
202 |
]. |
|
203 |
||
204 |
lastHelpText := aHelpText. |
|
205 |
||
206 |
closeProcess notNil ifTrue:[ |
|
207 |
p := closeProcess. closeProcess := nil. |
|
208 |
p terminate. |
|
209 |
]. |
|
210 |
currentHelpView notNil ifTrue:[ |
|
211 |
self hideHelp |
|
212 |
]. |
|
213 |
||
214 |
org := view originRelativeTo:nil. |
|
215 |
currentFrame := org extent:view extent. |
|
216 |
org :=org + (view extent // 2). |
|
217 |
||
218 |
v := ActiveHelpView for:aHelpText withCRs. |
|
219 |
||
220 |
dev := view graphicsDevice. |
|
221 |
org := dev pointerPosition. |
|
1540 | 222 |
org := org + (0@24). |
1536 | 223 |
(org x + v width) > dev width ifTrue:[ |
224 |
org := (org x - v width) @ org y |
|
225 |
]. |
|
226 |
(org y + v height) > dev height ifTrue:[ |
|
227 |
org := org x @ (org y - v height). |
|
228 |
]. |
|
229 |
||
230 |
v origin:org. |
|
231 |
"/ currentHelpView open. |
|
232 |
v realize. |
|
233 |
v enableButtonMotionEvents. |
|
234 |
v enableMotionEvents. |
|
235 |
currentHelpView := v. |
|
236 |
||
237 |
currentView := view. |
|
238 |
closeProcess := [ |
|
239 |
[ |
|
1546 | 240 |
(Delay forSeconds:ShowTime) wait. |
241 |
[ |
|
242 |
currentHelpView notNil ifTrue:[ |
|
243 |
currentHelpView destroy. |
|
244 |
currentHelpView := nil. |
|
245 |
] |
|
246 |
] valueUninterruptably |
|
1576
ff6cb0701733
Use #ifCurtailed: instead of #valueOnUnwindDo:
Stefan Vogel <sv@exept.de>
parents:
1546
diff
changeset
|
247 |
] ifCurtailed:[ |
1546 | 248 |
closeProcess := nil. |
249 |
]. |
|
250 |
] newProcess. |
|
251 |
closeProcess priority:(Processor userSchedulingPriority + 1). |
|
252 |
closeProcess resume. |
|
1536 | 253 |
|
1546 | 254 |
"Modified: / 31.8.1995 / 19:20:45 / claus" |
255 |
"Modified: / 10.12.2001 / 21:28:26 / cg" |
|
1536 | 256 |
! |
257 |
||
258 |
stopHelpDisplayProcess |
|
259 |
|p| |
|
260 |
||
261 |
showProcess notNil ifTrue:[ |
|
262 |
p := showProcess. showProcess := nil. |
|
263 |
p terminate. |
|
264 |
]. |
|
265 |
||
266 |
"Created: 28.6.1997 / 14:03:17 / cg" |
|
267 |
! ! |
|
268 |
||
269 |
!FlyByHelp class methodsFor:'documentation'! |
|
270 |
||
271 |
version |
|
1596 | 272 |
^ '$Header: /cvs/stx/stx/libview2/FlyByHelp.st,v 1.6 2002-08-20 14:12:55 cg Exp $' |
1536 | 273 |
! ! |
274 |
FlyByHelp initialize! |