author | Stefan Vogel <sv@exept.de> |
Fri, 13 Mar 2009 14:57:48 +0100 | |
changeset 3666 | 4a4e9dae4017 |
parent 3664 | b49c21d9aac4 |
child 3668 | e1888e938d68 |
permissions | -rw-r--r-- |
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 |
|
42 |
" |
|
43 |
! ! |
|
44 |
||
3662 | 45 |
!LinkButton class methodsFor:'defaults'! |
46 |
||
47 |
updateStyleCache |
|
48 |
"extract values from the styleSheet and cache them in class variables" |
|
49 |
||
50 |
<resource: #style ( #'linkButton.linkColor' )> |
|
51 |
||
52 |
DefaultLinkColor := StyleSheet colorAt:#'linkButton.linkColor' default:Color blue. |
|
53 |
! ! |
|
54 |
||
3650 | 55 |
!LinkButton methodsFor:'accessing'! |
56 |
||
57 |
labelsAndActions |
|
58 |
"returns the collection of label->action associations. |
|
59 |
For display, the label strings are drawn as one concatenated string (add separating spaces, if you have to). |
|
60 |
When clicked on a string, the corresponding action is called" |
|
61 |
||
62 |
^ labelsAndActions |
|
63 |
! |
|
64 |
||
65 |
labelsAndActions:aCollectionOfAssociations |
|
66 |
"set the collection of label->action associations. |
|
67 |
For display, the label strings are drawn as one concatenated string (add separating spaces, if you have to). |
|
68 |
When clicked on a string, the corresponding action is called" |
|
69 |
||
70 |
labelsAndActions := aCollectionOfAssociations. |
|
71 |
self label:((aCollectionOfAssociations collect:[:assoc | assoc key]) asStringWith:'') |
|
72 |
! ! |
|
73 |
||
74 |
!LinkButton methodsFor:'initialization'! |
|
75 |
||
76 |
defaultControllerClass |
|
77 |
^ LinkButtonController |
|
3662 | 78 |
! |
79 |
||
80 |
initStyle |
|
81 |
super initStyle. |
|
82 |
||
83 |
level := enterLevel := leaveLevel := onLevel := offLevel := 0. |
|
84 |
DefaultLinkColor notNil ifTrue:[ |
|
85 |
foreground := DefaultLinkColor onDevice:device. |
|
86 |
]. |
|
87 |
activeFgColor := enteredFgColor := foreground. |
|
88 |
activeBgColor := enteredBgColor := viewBackground. |
|
89 |
! |
|
90 |
||
91 |
initialize |
|
92 |
super initialize. |
|
3666
4a4e9dae4017
changed #initialize - link is left-aligned by default
Stefan Vogel <sv@exept.de>
parents:
3664
diff
changeset
|
93 |
adjust := #left. |
3662 | 94 |
self enableMotionEvents |
95 |
! ! |
|
96 |
||
97 |
!LinkButton methodsFor:'redrawing'! |
|
98 |
||
99 |
actionAt:aPoint |
|
3664 | 100 |
|pressAction| |
101 |
||
102 |
pressAction := self pressAction ? self releaseAction. |
|
3662 | 103 |
self labelsAndActionsWithPositionsDo:[:lbl :action :leftX :rightX | |
104 |
(aPoint x between:leftX and:rightX) ifTrue:[ |
|
3664 | 105 |
^ labelsAndActions notNil ifTrue:action ifFalse:pressAction |
3662 | 106 |
]. |
107 |
]. |
|
108 |
^ nil |
|
109 |
! |
|
110 |
||
111 |
drawStringLogo:aString x:x y:y |
|
112 |
"redefined to draw the part under the mouse pointer with an underined emphasis" |
|
113 |
||
114 |
|entered mousePoint| |
|
115 |
||
116 |
mousePoint := controller lastMousePoint. |
|
117 |
entered := controller entered. |
|
118 |
||
119 |
self labelsAndActionsWithPositionsDo:[:lbl :action :leftX :rightX | |
|
120 |
|l| |
|
121 |
l := lbl. |
|
122 |
(entered and:[mousePoint notNil and:[mousePoint x between:leftX and:rightX]]) ifTrue:[ |
|
123 |
l := l allUnderlined |
|
124 |
]. |
|
125 |
self displayString:l x:leftX y:y. |
|
126 |
]. |
|
127 |
! |
|
128 |
||
129 |
labelsAndActionsWithPositionsDo:aFourArgBlock |
|
3664 | 130 |
|leftX rightX w| |
3662 | 131 |
|
132 |
leftX := labelOriginX. |
|
3664 | 133 |
labelsAndActions isNil ifTrue:[ |
134 |
w := (self font widthOf:logo on:device). |
|
135 |
rightX := leftX + w-1. |
|
136 |
aFourArgBlock |
|
137 |
value:logo |
|
138 |
value:self pressAction |
|
139 |
value:leftX |
|
140 |
value:rightX. |
|
141 |
^ self |
|
142 |
]. |
|
143 |
||
3662 | 144 |
labelsAndActions do:[:assoc | |
145 |
|lbl wEach| |
|
146 |
||
147 |
lbl := assoc key. |
|
148 |
wEach := (self font widthOf:lbl on:device). |
|
149 |
rightX := leftX + wEach-1. |
|
150 |
aFourArgBlock |
|
151 |
value:assoc key |
|
152 |
value:assoc value |
|
153 |
value:leftX |
|
154 |
value:rightX. |
|
155 |
||
156 |
leftX := rightX+1. |
|
157 |
]. |
|
158 |
^ nil |
|
3650 | 159 |
! ! |
160 |
||
161 |
!LinkButton class methodsFor:'documentation'! |
|
162 |
||
163 |
version |
|
3666
4a4e9dae4017
changed #initialize - link is left-aligned by default
Stefan Vogel <sv@exept.de>
parents:
3664
diff
changeset
|
164 |
^ '$Header: /cvs/stx/stx/libwidg2/LinkButton.st,v 1.4 2009-03-13 13:57:48 stefan Exp $' |
3650 | 165 |
! ! |