author | Claus Gittinger <cg@exept.de> |
Tue, 18 Mar 2014 16:08:20 +0100 | |
changeset 3313 | 05f5ca07ddbf |
parent 3288 | 711749d5cfd5 |
child 3314 | 552383bb5952 |
permissions | -rw-r--r-- |
60 | 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 |
" |
|
1485 | 12 |
"{ Package: 'stx:libview2' }" |
13 |
||
60 | 14 |
View subclass:#ActiveHelpView |
3250
276f1af4583b
handle key press and close help.
Claus Gittinger <cg@exept.de>
parents:
3249
diff
changeset
|
15 |
instanceVariableNames:'myView shapeStyle controllingHelpListener' |
216 | 16 |
classVariableNames:'' |
17 |
poolDictionaries:'' |
|
18 |
category:'Interface-Help' |
|
60 | 19 |
! |
20 |
||
380 | 21 |
!ActiveHelpView class methodsFor:'documentation'! |
60 | 22 |
|
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 |
||
36 |
||
138 | 37 |
! |
38 |
||
39 |
documentation |
|
40 |
" |
|
635 | 41 |
a bubbleHelp view. |
233 | 42 |
|
138 | 43 |
Instances of myself show up either as a comics-like talking |
44 |
view, or as a simple square popup. This is configured via the |
|
233 | 45 |
styleSheet; the default is simple-square. |
46 |
To get the fancy comics style, add a resource 'activeHelpStyle' with |
|
47 |
a symbol-value of #cartoon. |
|
138 | 48 |
However, be aware that some servers have performance problems with |
49 |
these view-shapes (or do not support shapes at all). |
|
635 | 50 |
Therefore, the default style is a rectangular popupView. |
216 | 51 |
|
221 | 52 |
[author:] |
53 |
Claus Gittinger |
|
54 |
||
216 | 55 |
[See also:] |
56 |
ActiveHelp |
|
138 | 57 |
" |
60 | 58 |
! ! |
59 |
||
380 | 60 |
!ActiveHelpView class methodsFor:'instance creation'! |
60 | 61 |
|
62 |
for:someText |
|
635 | 63 |
"create a bubble-view for some text" |
233 | 64 |
|
1676 | 65 |
^ self for:someText onDevice:Screen current. |
66 |
||
67 |
" |
|
68 |
|v| |
|
69 |
||
70 |
v := (ActiveHelpView for:'hello world\this is an ActiveHelpView' withCRs) shapeStyle:nil. |
|
71 |
v realize. |
|
72 |
Delay waitForSeconds:2. |
|
73 |
v destroy |
|
74 |
" |
|
75 |
||
76 |
" |
|
77 |
|v| |
|
78 |
||
79 |
v := (ActiveHelpView for:'hello world\this is an ActiveHelpView' withCRs) shapeStyle:#cartoon. |
|
80 |
v realize. |
|
81 |
Delay waitForSeconds:2. |
|
82 |
v destroy |
|
83 |
" |
|
84 |
||
85 |
"Modified: 28.6.1997 / 14:24:23 / cg" |
|
86 |
! |
|
87 |
||
88 |
for:someText onDevice:aDevice |
|
89 |
"create a bubble-view for some text" |
|
90 |
||
60 | 91 |
|helpView textView| |
92 |
||
1714
85cd314f0916
Fix ActiveHelp for foreign displays
Stefan Vogel <sv@exept.de>
parents:
1676
diff
changeset
|
93 |
helpView := self onDevice:aDevice. |
3313 | 94 |
(someText startsWith:'<HTML>') ifTrue:[ |
95 |
textView := HTMLView onDevice:aDevice. |
|
96 |
textView level:0. |
|
97 |
textView contents:someText. |
|
98 |
textView preferredExtent:(textView extentOfContents + 20 min:(Display extent * 2 // 3)). |
|
99 |
^ helpView withView:textView |
|
100 |
] ifFalse:[ |
|
101 |
textView := Label onDevice:aDevice. |
|
102 |
textView font:(helpView font onDevice:aDevice). |
|
103 |
^ (helpView withView:textView) contents:someText |
|
104 |
]. |
|
60 | 105 |
|
106 |
" |
|
635 | 107 |
|v| |
285 | 108 |
|
635 | 109 |
v := (ActiveHelpView for:'hello world\this is an ActiveHelpView' withCRs) shapeStyle:nil. |
110 |
v realize. |
|
111 |
Delay waitForSeconds:2. |
|
112 |
v destroy |
|
60 | 113 |
" |
233 | 114 |
|
635 | 115 |
" |
116 |
|v| |
|
117 |
||
118 |
v := (ActiveHelpView for:'hello world\this is an ActiveHelpView' withCRs) shapeStyle:#cartoon. |
|
119 |
v realize. |
|
120 |
Delay waitForSeconds:2. |
|
121 |
v destroy |
|
122 |
" |
|
123 |
||
124 |
"Modified: 28.6.1997 / 14:24:23 / cg" |
|
60 | 125 |
! |
126 |
||
127 |
with:aView |
|
233 | 128 |
"create a talking-view wrapping some other view" |
129 |
||
60 | 130 |
^ self new withView:aView |
131 |
||
132 |
" |
|
133 |
(ActiveHelpView with:(TextView new)) realize |
|
134 |
(ActiveHelpView with:(TextView new)) open |
|
135 |
(ActiveHelpView with:(Button label:'ok')) open |
|
136 |
" |
|
233 | 137 |
|
138 |
"Modified: 27.4.1996 / 15:14:18 / cg" |
|
60 | 139 |
! ! |
140 |
||
138 | 141 |
!ActiveHelpView methodsFor:'accessing'! |
142 |
||
143 |
contents:someText |
|
233 | 144 |
"set the text" |
145 |
||
138 | 146 |
(myView isKindOf:Label) ifTrue:[ |
233 | 147 |
myView label:someText asString. |
148 |
myView extent:(myView preferredExtent). |
|
138 | 149 |
] ifFalse:[ |
233 | 150 |
myView contents:someText. |
138 | 151 |
]. |
152 |
self resizeToFit |
|
153 |
||
233 | 154 |
"Modified: 27.4.1996 / 15:14:56 / cg" |
138 | 155 |
! |
60 | 156 |
|
3250
276f1af4583b
handle key press and close help.
Claus Gittinger <cg@exept.de>
parents:
3249
diff
changeset
|
157 |
controllingHelpListener:something |
276f1af4583b
handle key press and close help.
Claus Gittinger <cg@exept.de>
parents:
3249
diff
changeset
|
158 |
controllingHelpListener := something. |
276f1af4583b
handle key press and close help.
Claus Gittinger <cg@exept.de>
parents:
3249
diff
changeset
|
159 |
! |
276f1af4583b
handle key press and close help.
Claus Gittinger <cg@exept.de>
parents:
3249
diff
changeset
|
160 |
|
285 | 161 |
shapeStyle:aStyleSymbol |
3218 | 162 |
"set the shapeStyle. |
163 |
Currently, only nil and #cartoon are supported" |
|
285 | 164 |
|
165 |
shapeStyle := aStyleSymbol. |
|
3246 | 166 |
Screen current supportsArbitraryShapedViews ifFalse:[ |
167 |
shapeStyle := nil |
|
168 |
]. |
|
285 | 169 |
self resizeToFit. |
170 |
self computeShape. |
|
171 |
||
172 |
"Created: 29.5.1996 / 15:39:41 / cg" |
|
635 | 173 |
"Modified: 28.6.1997 / 14:15:22 / cg" |
285 | 174 |
! |
175 |
||
138 | 176 |
withView:aView |
233 | 177 |
"set the component view" |
178 |
||
3118 | 179 |
|fg| |
180 |
||
138 | 181 |
(aView isKindOf:Label) ifTrue:[ |
233 | 182 |
aView viewBackground:viewBackground. |
183 |
aView backgroundColor:viewBackground. |
|
3118 | 184 |
(fg := styleSheet colorAt:#'activeHelp.foregroundColor' default:nil) notNil ifTrue:[ |
185 |
aView foregroundColor:fg. |
|
186 |
]. |
|
3313 | 187 |
] ifFalse:[ |
188 |
(aView isKindOf:HTMLView) ifTrue:[ |
|
189 |
aView style viewBGColor:viewBackground. |
|
190 |
]. |
|
138 | 191 |
]. |
192 |
self addSubView:aView. |
|
193 |
myView := aView. |
|
194 |
myView borderWidth:0 |
|
233 | 195 |
|
196 |
"Modified: 27.4.1996 / 15:16:46 / cg" |
|
138 | 197 |
! ! |
198 |
||
3250
276f1af4583b
handle key press and close help.
Claus Gittinger <cg@exept.de>
parents:
3249
diff
changeset
|
199 |
!ActiveHelpView methodsFor:'event handling'! |
276f1af4583b
handle key press and close help.
Claus Gittinger <cg@exept.de>
parents:
3249
diff
changeset
|
200 |
|
276f1af4583b
handle key press and close help.
Claus Gittinger <cg@exept.de>
parents:
3249
diff
changeset
|
201 |
keyPress:key x:x y:y |
276f1af4583b
handle key press and close help.
Claus Gittinger <cg@exept.de>
parents:
3249
diff
changeset
|
202 |
controllingHelpListener hideHelp |
276f1af4583b
handle key press and close help.
Claus Gittinger <cg@exept.de>
parents:
3249
diff
changeset
|
203 |
! ! |
276f1af4583b
handle key press and close help.
Claus Gittinger <cg@exept.de>
parents:
3249
diff
changeset
|
204 |
|
138 | 205 |
!ActiveHelpView methodsFor:'initialization'! |
206 |
||
92 | 207 |
initStyle |
380 | 208 |
"setup viewStyle specifics" |
209 |
||
725 | 210 |
<resource: #style (#'activeHelp.backgroundColor' |
211 |
#'activeHelp.borderWidth' |
|
1537 | 212 |
#'activeHelp.font' |
725 | 213 |
#'activeHelp.style')> |
285 | 214 |
|
2776
7181bb9659ae
comment/format in: #withView:
Claus Gittinger <cg@exept.de>
parents:
2773
diff
changeset
|
215 |
|bg defaultFont| |
236 | 216 |
|
92 | 217 |
super initStyle. |
218 |
||
3218 | 219 |
(shapeStyle := UserPreferences current toolTipShapeStyle) isNil ifTrue:[ |
220 |
shapeStyle := styleSheet at:#'activeHelp.style' default:nil. |
|
221 |
]. |
|
222 |
||
2776
7181bb9659ae
comment/format in: #withView:
Claus Gittinger <cg@exept.de>
parents:
2773
diff
changeset
|
223 |
defaultFont := styleSheet fontAt:#'activeHelp.font' default:nil. |
7181bb9659ae
comment/format in: #withView:
Claus Gittinger <cg@exept.de>
parents:
2773
diff
changeset
|
224 |
defaultFont notNil ifTrue:[ |
7181bb9659ae
comment/format in: #withView:
Claus Gittinger <cg@exept.de>
parents:
2773
diff
changeset
|
225 |
self font:defaultFont |
1537 | 226 |
]. |
227 |
||
1583
36d82eed6873
Use #isWindowsStyle instead of comparing to style name.
Stefan Vogel <sv@exept.de>
parents:
1537
diff
changeset
|
228 |
bg := styleSheet colorAt:#'activeHelp.backgroundColor' default:nil. |
285 | 229 |
bg notNil ifTrue:[ |
230 |
viewBackground := bg |
|
231 |
] ifFalse:[ |
|
232 |
shapeStyle == #cartoon ifTrue:[ |
|
3288 | 233 |
viewBackground := self whiteColor. |
285 | 234 |
] |
235 |
]. |
|
2773
eaec2e45bd8d
no more direct accesses to borderWidth and borderColor
Claus Gittinger <cg@exept.de>
parents:
2413
diff
changeset
|
236 |
self borderWidth:(styleSheet at:#'activeHelp.borderWidth' default:1). |
3288 | 237 |
self borderColor:(styleSheet at:#'activeHelp.borderColor' default:self blackColor). |
236 | 238 |
|
725 | 239 |
"Modified: / 26.10.1997 / 17:02:09 / cg" |
92 | 240 |
! |
241 |
||
138 | 242 |
realize |
243 |
self create. |
|
244 |
self computeShape. |
|
245 |
self enableMotionEvents. |
|
246 |
self enableButtonMotionEvents. |
|
1485 | 247 |
super realize |
60 | 248 |
! ! |
249 |
||
250 |
!ActiveHelpView methodsFor:'private'! |
|
251 |
||
252 |
computeShape |
|
233 | 253 |
"compute the shape, based upon the size of my component view" |
254 |
||
3224 | 255 |
|extent oldOrigin shapeForm borderForm y1 bw h w mirrorH mirrorV |
3218 | 256 |
p1 p2 p3 pB1 pB2 pB3 offs hEll h2 w2 w8 w78 mousePosition| |
60 | 257 |
|
3249
38845952e1d4
more control over the shape style
Claus Gittinger <cg@exept.de>
parents:
3246
diff
changeset
|
258 |
(shapeStyle == #cartoon) ifTrue:[ |
3285 | 259 |
self graphicsDevice supportsArbitraryShapedViews ifTrue:[ |
635 | 260 |
extent := self extent. |
3224 | 261 |
oldOrigin := self origin. |
635 | 262 |
h := extent y. |
263 |
w := extent x. |
|
264 |
bw := 4. |
|
265 |
offs := 0. |
|
3218 | 266 |
mousePosition := device pointerPosition. |
60 | 267 |
|
3218 | 268 |
((mousePosition > (device width * (2/3))) |
269 |
or:[ self corner x > device usableWidth ]) ifTrue:[ |
|
635 | 270 |
mirrorH := true. |
3224 | 271 |
self origin:((oldOrigin x - w) @ (self origin y)). |
635 | 272 |
offs := bw * 2. |
273 |
] ifFalse:[ |
|
274 |
mirrorH := false |
|
275 |
]. |
|
3218 | 276 |
((mousePosition > (device height * (2/3))) |
277 |
or:[ self corner y > device usableHeight ]) ifTrue:[ |
|
635 | 278 |
mirrorV := true. |
3224 | 279 |
self origin:(oldOrigin x @ (self origin y - h)). |
635 | 280 |
] ifFalse:[ |
281 |
mirrorV := false |
|
282 |
]. |
|
285 | 283 |
|
635 | 284 |
borderForm := Form width:w height:h. |
285 |
shapeForm := Form width:w height:h. |
|
286 |
borderForm fill:(Color noColor). |
|
287 |
shapeForm fill:(Color noColor). |
|
288 |
||
289 |
hEll := (h // 3 * 2). |
|
60 | 290 |
|
635 | 291 |
mirrorV ifTrue:[ |
292 |
y1 := 0. |
|
293 |
] ifFalse:[ |
|
294 |
y1 := h // 4. |
|
295 |
]. |
|
60 | 296 |
|
635 | 297 |
borderForm fillArcX:0 y:y1 |
3224 | 298 |
width:w height:hEll |
299 |
from:0 angle:360. |
|
635 | 300 |
|
301 |
myView origin:(width - myView width // 2) @ (y1 + ((hEll - myView height) // 2)). |
|
285 | 302 |
|
1182 | 303 |
h2 := h // 2. |
304 |
w2 := w // 2. |
|
305 |
w8 := w // 8. |
|
306 |
w78 := w * 7 // 8. |
|
307 |
||
635 | 308 |
mirrorH ifTrue:[ |
309 |
mirrorV ifTrue:[ |
|
310 |
p1 := w @ h. |
|
1182 | 311 |
p2 := (w78 @ h2). |
312 |
p3 := (w2 @ h2). |
|
635 | 313 |
pB1 := (w-bw) @ (h-bw). |
1182 | 314 |
pB2 := ((w78 - bw) @ (h2 - bw)). |
315 |
pB3 := ((w2 + bw) @ (h2 - bw)) |
|
635 | 316 |
] ifFalse:[ |
317 |
p1 := w @ 0. |
|
1182 | 318 |
p2 := (w78 @ h2). |
319 |
p3 := (w2 @ h2). |
|
635 | 320 |
pB1 := (w-bw) @ bw. |
1182 | 321 |
pB2 := ((w78 - bw) @ (h2 + bw)). |
322 |
pB3 := ((w2 + bw) @ (h2 + bw)) |
|
635 | 323 |
] |
324 |
] ifFalse:[ |
|
325 |
mirrorV ifTrue:[ |
|
326 |
p1 := 0@h. |
|
1182 | 327 |
p2 := (w8 @ h2). |
328 |
p3 := (w2 @ h2). |
|
635 | 329 |
pB1 := bw@(h-bw). |
1182 | 330 |
pB2 := ((w8 + bw) @ (h2 - bw)). |
331 |
pB3 := ((w2 - bw) @ (h2 - bw)). |
|
635 | 332 |
] ifFalse:[ |
333 |
p1 := 0@0. |
|
1182 | 334 |
p2 := (w8 @ h2). |
335 |
p3 := (w2 @ h2). |
|
635 | 336 |
pB1 := bw@bw. |
1182 | 337 |
pB2 := ((w8 + bw) @ (h2 + bw)). |
338 |
pB3 := ((w2 - bw) @ (h2 + bw)). |
|
635 | 339 |
] |
340 |
]. |
|
60 | 341 |
|
635 | 342 |
borderForm fillPolygon:(Array with:p1 with:p2 with:p3). |
343 |
shapeForm fillPolygon:(Array with:pB1 with:pB2 with:pB3). |
|
60 | 344 |
|
635 | 345 |
shapeForm lineWidth:bw. |
346 |
shapeForm paint:(Color noColor). |
|
347 |
shapeForm displayPolygon:(Array with:p3 with:p1 with:p2). |
|
60 | 348 |
|
635 | 349 |
shapeForm paint:(Color colorId:1). |
350 |
shapeForm fillArcX:bw y:y1 + bw |
|
3224 | 351 |
width:(w - (bw * 2)) height:(h // 3 * 2 - (bw * 2)) |
352 |
from:0 angle:360. |
|
635 | 353 |
]. |
354 |
borderForm notNil ifTrue:[ |
|
355 |
self borderShape:borderForm. |
|
356 |
self viewShape:shapeForm |
|
357 |
]. |
|
358 |
] |
|
60 | 359 |
|
1182 | 360 |
"Modified: / 5.6.1999 / 21:41:01 / cg" |
1261 | 361 |
"Modified: / 27.10.1999 / 13:45:45 / stefan" |
60 | 362 |
! |
363 |
||
364 |
resizeToFit |
|
233 | 365 |
"resize myself to make the component view fit" |
366 |
||
3223 | 367 |
|h w pref bw| |
60 | 368 |
|
285 | 369 |
pref := myView preferredExtent. |
370 |
shapeStyle == #cartoon ifTrue:[ |
|
371 |
h := pref y. |
|
372 |
w := pref x. |
|
3223 | 373 |
self extent:((w / 0.85) @ (h * 4)) rounded. |
92 | 374 |
] ifFalse:[ |
3223 | 375 |
bw := self borderWidth. |
376 |
self extent:(pref + (bw * 2)). |
|
377 |
myView origin:(bw asPoint). |
|
92 | 378 |
] |
233 | 379 |
|
635 | 380 |
"Modified: 28.6.1997 / 14:23:49 / cg" |
233 | 381 |
! ! |
382 |
||
383 |
!ActiveHelpView methodsFor:'queries'! |
|
384 |
||
385 |
isPopUpView |
|
261 | 386 |
"return true - I am a popUp type of view (no decoration, pop-to-top)" |
233 | 387 |
|
388 |
^ true |
|
389 |
||
261 | 390 |
"Modified: 12.5.1996 / 21:58:12 / cg" |
3250
276f1af4583b
handle key press and close help.
Claus Gittinger <cg@exept.de>
parents:
3249
diff
changeset
|
391 |
! |
276f1af4583b
handle key press and close help.
Claus Gittinger <cg@exept.de>
parents:
3249
diff
changeset
|
392 |
|
276f1af4583b
handle key press and close help.
Claus Gittinger <cg@exept.de>
parents:
3249
diff
changeset
|
393 |
wantsFocusWithButtonPress |
276f1af4583b
handle key press and close help.
Claus Gittinger <cg@exept.de>
parents:
3249
diff
changeset
|
394 |
^ false |
60 | 395 |
! ! |
396 |
||
380 | 397 |
!ActiveHelpView class methodsFor:'documentation'! |
60 | 398 |
|
138 | 399 |
version |
3313 | 400 |
^ '$Header: /cvs/stx/stx/libview2/ActiveHelpView.st,v 1.43 2014-03-18 15:08:20 cg Exp $' |
2773
eaec2e45bd8d
no more direct accesses to borderWidth and borderColor
Claus Gittinger <cg@exept.de>
parents:
2413
diff
changeset
|
401 |
! |
eaec2e45bd8d
no more direct accesses to borderWidth and borderColor
Claus Gittinger <cg@exept.de>
parents:
2413
diff
changeset
|
402 |
|
eaec2e45bd8d
no more direct accesses to borderWidth and borderColor
Claus Gittinger <cg@exept.de>
parents:
2413
diff
changeset
|
403 |
version_CVS |
3313 | 404 |
^ '$Header: /cvs/stx/stx/libview2/ActiveHelpView.st,v 1.43 2014-03-18 15:08:20 cg Exp $' |
60 | 405 |
! ! |
3118 | 406 |