3650
|
1 |
"{ Package: 'stx:libwidg2' }"
|
|
2 |
|
|
3 |
Button subclass:#LinkButton
|
3662
|
4 |
instanceVariableNames:'labelsAndActions mouseOverLabelIndex'
|
|
5 |
classVariableNames:'DefaultLinkColor'
|
3650
|
6 |
poolDictionaries:''
|
|
7 |
category:'Views-Layout'
|
|
8 |
!
|
|
9 |
|
|
10 |
!LinkButton class methodsFor:'documentation'!
|
|
11 |
|
|
12 |
documentation
|
|
13 |
"
|
|
14 |
Looks like a Label, but behaves like a button with individually clickable text components.
|
|
15 |
Can be used to create htmp-page-look-alike links in a view.
|
|
16 |
|
|
17 |
[author:]
|
|
18 |
cg (cg@CG-VOSTRO)
|
|
19 |
|
|
20 |
[instance variables:]
|
|
21 |
|
|
22 |
[class variables:]
|
|
23 |
|
|
24 |
[see also:]
|
|
25 |
|
|
26 |
"
|
|
27 |
!
|
|
28 |
|
|
29 |
examples
|
|
30 |
"
|
|
31 |
|v l|
|
|
32 |
|
|
33 |
v := StandardSystemView new.
|
|
34 |
l := LinkButton in:v.
|
|
35 |
l labelsAndActions:{
|
3662
|
36 |
'Hello' -> [ Transcript showCR:'Hello Clicked'].
|
3650
|
37 |
' ' -> nil.
|
3662
|
38 |
'World' -> [ Transcript showCR:'World Clicked'].
|
3650
|
39 |
}.
|
|
40 |
l foregroundColor:Color blue.
|
|
41 |
v open
|
3668
|
42 |
|
|
43 |
|
|
44 |
|v l|
|
|
45 |
|
|
46 |
v := StandardSystemView new.
|
|
47 |
l := LinkButton in:v.
|
|
48 |
l labelsAndActions:{
|
|
49 |
'Hello' -> nil.
|
|
50 |
' ' -> nil.
|
|
51 |
'World' -> [ Transcript showCR:'World Clicked'].
|
|
52 |
}.
|
|
53 |
l foregroundColor:Color blue.
|
|
54 |
v open
|
3650
|
55 |
"
|
|
56 |
! !
|
|
57 |
|
3662
|
58 |
!LinkButton class methodsFor:'defaults'!
|
|
59 |
|
|
60 |
updateStyleCache
|
|
61 |
"extract values from the styleSheet and cache them in class variables"
|
|
62 |
|
|
63 |
<resource: #style ( #'linkButton.linkColor' )>
|
|
64 |
|
|
65 |
DefaultLinkColor := StyleSheet colorAt:#'linkButton.linkColor' default:Color blue.
|
|
66 |
! !
|
|
67 |
|
3650
|
68 |
!LinkButton methodsFor:'accessing'!
|
|
69 |
|
|
70 |
labelsAndActions
|
|
71 |
"returns the collection of label->action associations.
|
|
72 |
For display, the label strings are drawn as one concatenated string (add separating spaces, if you have to).
|
|
73 |
When clicked on a string, the corresponding action is called"
|
|
74 |
|
|
75 |
^ labelsAndActions
|
|
76 |
!
|
|
77 |
|
|
78 |
labelsAndActions:aCollectionOfAssociations
|
|
79 |
"set the collection of label->action associations.
|
|
80 |
For display, the label strings are drawn as one concatenated string (add separating spaces, if you have to).
|
|
81 |
When clicked on a string, the corresponding action is called"
|
|
82 |
|
|
83 |
labelsAndActions := aCollectionOfAssociations.
|
|
84 |
self label:((aCollectionOfAssociations collect:[:assoc | assoc key]) asStringWith:'')
|
|
85 |
! !
|
|
86 |
|
|
87 |
!LinkButton methodsFor:'initialization'!
|
|
88 |
|
|
89 |
defaultControllerClass
|
|
90 |
^ LinkButtonController
|
3662
|
91 |
!
|
|
92 |
|
|
93 |
initStyle
|
|
94 |
super initStyle.
|
|
95 |
|
|
96 |
level := enterLevel := leaveLevel := onLevel := offLevel := 0.
|
|
97 |
DefaultLinkColor notNil ifTrue:[
|
|
98 |
foreground := DefaultLinkColor onDevice:device.
|
|
99 |
].
|
|
100 |
activeFgColor := enteredFgColor := foreground.
|
|
101 |
activeBgColor := enteredBgColor := viewBackground.
|
|
102 |
!
|
|
103 |
|
|
104 |
initialize
|
|
105 |
super initialize.
|
3668
|
106 |
"/ adjust := #left.
|
3662
|
107 |
self enableMotionEvents
|
|
108 |
! !
|
|
109 |
|
|
110 |
!LinkButton methodsFor:'redrawing'!
|
|
111 |
|
|
112 |
actionAt:aPoint
|
3664
|
113 |
|pressAction|
|
|
114 |
|
|
115 |
pressAction := self pressAction ? self releaseAction.
|
3662
|
116 |
self labelsAndActionsWithPositionsDo:[:lbl :action :leftX :rightX |
|
|
117 |
(aPoint x between:leftX and:rightX) ifTrue:[
|
3664
|
118 |
^ labelsAndActions notNil ifTrue:action ifFalse:pressAction
|
3662
|
119 |
].
|
|
120 |
].
|
|
121 |
^ nil
|
|
122 |
!
|
|
123 |
|
|
124 |
drawStringLogo:aString x:x y:y
|
|
125 |
"redefined to draw the part under the mouse pointer with an underined emphasis"
|
|
126 |
|
|
127 |
|entered mousePoint|
|
|
128 |
|
|
129 |
mousePoint := controller lastMousePoint.
|
|
130 |
entered := controller entered.
|
|
131 |
|
|
132 |
self labelsAndActionsWithPositionsDo:[:lbl :action :leftX :rightX |
|
|
133 |
|l|
|
3668
|
134 |
|
3662
|
135 |
l := lbl.
|
3668
|
136 |
action notNil ifTrue:[
|
|
137 |
(entered and:[mousePoint notNil and:[mousePoint x between:leftX and:rightX]]) ifTrue:[
|
|
138 |
l := l allUnderlined
|
|
139 |
].
|
3662
|
140 |
].
|
|
141 |
self displayString:l x:leftX y:y.
|
|
142 |
].
|
|
143 |
!
|
|
144 |
|
|
145 |
labelsAndActionsWithPositionsDo:aFourArgBlock
|
3664
|
146 |
|leftX rightX w|
|
3662
|
147 |
|
|
148 |
leftX := labelOriginX.
|
3664
|
149 |
labelsAndActions isNil ifTrue:[
|
|
150 |
w := (self font widthOf:logo on:device).
|
|
151 |
rightX := leftX + w-1.
|
|
152 |
aFourArgBlock
|
|
153 |
value:logo
|
|
154 |
value:self pressAction
|
|
155 |
value:leftX
|
|
156 |
value:rightX.
|
|
157 |
^ self
|
|
158 |
].
|
|
159 |
|
3662
|
160 |
labelsAndActions do:[:assoc |
|
|
161 |
|lbl wEach|
|
|
162 |
|
|
163 |
lbl := assoc key.
|
|
164 |
wEach := (self font widthOf:lbl on:device).
|
|
165 |
rightX := leftX + wEach-1.
|
|
166 |
aFourArgBlock
|
|
167 |
value:assoc key
|
|
168 |
value:assoc value
|
|
169 |
value:leftX
|
|
170 |
value:rightX.
|
|
171 |
|
|
172 |
leftX := rightX+1.
|
|
173 |
].
|
|
174 |
^ nil
|
3650
|
175 |
! !
|
|
176 |
|
|
177 |
!LinkButton class methodsFor:'documentation'!
|
|
178 |
|
|
179 |
version
|
3668
|
180 |
^ '$Header: /cvs/stx/stx/libwidg2/LinkButton.st,v 1.5 2009-03-13 18:15:27 cg Exp $'
|
3650
|
181 |
! !
|