--- a/LinkButton.st Fri Mar 13 19:16:01 2009 +0100
+++ b/LinkButton.st Mon Mar 16 16:20:16 2009 +0100
@@ -1,7 +1,7 @@
"{ Package: 'stx:libwidg2' }"
Button subclass:#LinkButton
- instanceVariableNames:'labelsAndActions mouseOverLabelIndex'
+ instanceVariableNames:'labelsAndActions'
classVariableNames:'DefaultLinkColor'
poolDictionaries:''
category:'Views-Layout'
@@ -32,6 +32,19 @@
v := StandardSystemView new.
l := LinkButton in:v.
+ l label:
+ (('Hello' actionForAll:[ Transcript showCR:'Hello Clicked'])
+ , ' '
+ , ('World' actionForAll:[ Transcript showCR:'World Clicked'])).
+
+ l foregroundColor:Color blue.
+ v open
+
+
+ |v l|
+
+ v := StandardSystemView new.
+ l := LinkButton in:v.
l labelsAndActions:{
'Hello' -> [ Transcript showCR:'Hello Clicked'].
' ' -> nil.
@@ -97,22 +110,45 @@
DefaultLinkColor notNil ifTrue:[
foreground := DefaultLinkColor onDevice:device.
].
- activeFgColor := enteredFgColor := foreground.
- activeBgColor := enteredBgColor := viewBackground.
+"/ activeFgColor := enteredFgColor := foreground.
+"/ activeBgColor := enteredBgColor := viewBackground.
!
initialize
super initialize.
- "/ adjust := #left.
self enableMotionEvents
! !
!LinkButton methodsFor:'redrawing'!
actionAt:aPoint
- |pressAction|
+ |pressAction emphasis|
pressAction := self pressAction ? self releaseAction.
+ labelsAndActions isNil ifTrue:[
+ "take action from logo, which is normally a text"
+
+ emphasis := logo emphasisAtPoint:aPoint on:self.
+ (emphasis isNil or:[emphasis isSymbol]) ifTrue:[
+ ^ pressAction.
+ ].
+ emphasis isAssociation ifTrue:[
+ emphasis key == #actionBlock ifTrue:[
+ ^ emphasis value.
+ ].
+ ^ pressAction.
+ ].
+ emphasis do:[:eachElement|
+ eachElement isAssociation ifTrue:[
+ eachElement key == #actionBlock ifTrue:[
+ ^ eachElement value.
+ ].
+ ].
+ ].
+ ^ pressAction.
+ ].
+
+
self labelsAndActionsWithPositionsDo:[:lbl :action :leftX :rightX |
(aPoint x between:leftX and:rightX) ifTrue:[
^ labelsAndActions notNil ifTrue:action ifFalse:pressAction
@@ -121,14 +157,71 @@
^ nil
!
+actionEmphasisIn:aText atPoint:aPoint
+ "check for a actionBlock emphasis in aString at aPoint.
+ Answer an Array with the whole emphasis and the actionBlock,
+ or nil"
+
+ |emphasis|
+
+ emphasis := aText emphasisAtPoint:aPoint on:self.
+ (emphasis isNil or:[emphasis isSymbol]) ifTrue:[
+ ^ #(nil nil).
+ ].
+ emphasis isAssociation ifTrue:[
+ emphasis key == #actionBlock ifTrue:[
+ ^ Array with:emphasis with:emphasis value.
+ ].
+ ^ #(nil nil).
+ ].
+ emphasis detect:[:eachElement|
+ eachElement isAssociation ifTrue:[
+ eachElement key == #actionBlock ifTrue:[
+ ^ Array with:emphasis with:eachElement value.
+ ].
+ ].
+ ] ifNone:[].
+ ^ #(nil nil).
+!
+
drawStringLogo:aString x:x y:y
"redefined to draw the part under the mouse pointer with an underined emphasis"
- |entered mousePoint|
+ |str entered mousePoint start len emphasis|
mousePoint := controller lastMousePoint.
entered := controller entered.
+ labelsAndActions isNil ifTrue:[
+ (entered not or:[mousePoint isNil]) ifTrue:[
+ self displayString:aString x:x y:y.
+ ^ self.
+ ].
+
+ str := aString.
+ emphasis := (self actionEmphasisIn:aString atPoint:mousePoint) first.
+ emphasis notNil ifTrue:[
+ start := 1.
+ aString emphasisCollection runsDo:[:eachLen :eachEmphasis|
+ len isNil ifTrue:[
+ eachEmphasis == emphasis ifTrue:[
+ len := eachLen.
+ ] ifFalse:[
+ start := start + eachLen.
+ ].
+ ].
+ ].
+ len notNil ifTrue:[
+ str := str deepCopy.
+ str emphasisFrom:start to:start+len-1 add:#underline.
+ str emphasisFrom:start to:start+len-1 add:(#color -> foreground).
+self halt.
+ ].
+ ].
+ self displayString:str x:x y:y.
+ ^ self.
+ ].
+
self labelsAndActionsWithPositionsDo:[:lbl :action :leftX :rightX |
|l|
@@ -177,5 +270,5 @@
!LinkButton class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libwidg2/LinkButton.st,v 1.5 2009-03-13 18:15:27 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libwidg2/LinkButton.st,v 1.6 2009-03-16 15:20:16 stefan Exp $'
! !