LinkButton.st
author Stefan Vogel <sv@exept.de>
Mon, 23 Mar 2009 08:23:06 +0100
changeset 3671 a43da2ee728e
parent 3670 ccfd04be9736
child 4071 d056c9f9b595
permissions -rw-r--r--
changed #drawStringLogo:x:y: - remove halt
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3650
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"{ Package: 'stx:libwidg2' }"
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
Button subclass:#LinkButton
3670
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
     4
	instanceVariableNames:'labelsAndActions'
3662
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
     5
	classVariableNames:'DefaultLinkColor'
3650
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
	poolDictionaries:''
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
	category:'Views-Layout'
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
!
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
!LinkButton class methodsFor:'documentation'!
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
documentation
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
"
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
    Looks like a Label, but behaves like a button with individually clickable text components.
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
    Can be used to create htmp-page-look-alike links in a view.
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
    [author:]
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
        cg (cg@CG-VOSTRO)
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
    [instance variables:]
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
    [class variables:]
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
    [see also:]
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
"
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
!
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
examples
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
"
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
    |v l|
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
    v := StandardSystemView new.
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
    l := LinkButton in:v.
3670
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
    35
    l label:
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
    36
        (('Hello' actionForAll:[ Transcript showCR:'Hello Clicked']) 
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
    37
        , '    '
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
    38
        , ('World' actionForAll:[ Transcript showCR:'World Clicked'])).
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
    39
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
    40
    l foregroundColor:Color blue.
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
    41
    v open
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
    42
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
    43
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
    44
    |v l|
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
    45
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
    46
    v := StandardSystemView new.
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
    47
    l := LinkButton in:v.
3650
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
    l labelsAndActions:{ 
3662
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
    49
                        'Hello' -> [ Transcript showCR:'Hello Clicked'].
3650
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
                        ' ' -> nil.
3662
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
    51
                        'World' -> [ Transcript showCR:'World Clicked'].
3650
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
                       }.
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
    l foregroundColor:Color blue.
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
    v open
3668
e1888e938d68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
    55
e1888e938d68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
    56
e1888e938d68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
    57
    |v l|
e1888e938d68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
    58
e1888e938d68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
    59
    v := StandardSystemView new.
e1888e938d68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
    60
    l := LinkButton in:v.
e1888e938d68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
    61
    l labelsAndActions:{ 
e1888e938d68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
    62
                        'Hello' -> nil.
e1888e938d68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
    63
                        ' ' -> nil.
e1888e938d68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
    64
                        'World' -> [ Transcript showCR:'World Clicked'].
e1888e938d68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
    65
                       }.
e1888e938d68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
    66
    l foregroundColor:Color blue.
e1888e938d68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
    67
    v open
3650
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
"
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
! !
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
3662
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
    71
!LinkButton class methodsFor:'defaults'!
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
    72
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
    73
updateStyleCache
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
    74
    "extract values from the styleSheet and cache them in class variables"
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
    75
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
    76
    <resource: #style ( #'linkButton.linkColor' )>
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
    77
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
    78
    DefaultLinkColor := StyleSheet colorAt:#'linkButton.linkColor' default:Color blue.
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
    79
! !
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
    80
3650
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
!LinkButton methodsFor:'accessing'!
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
labelsAndActions
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
    "returns the collection of label->action associations. 
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
     For display, the label strings are drawn as one concatenated string (add separating spaces, if you have to).
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
     When clicked on a string, the corresponding action is called"
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
    ^ labelsAndActions
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
!
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
labelsAndActions:aCollectionOfAssociations
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
    "set the collection of label->action associations. 
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
     For display, the label strings are drawn as one concatenated string (add separating spaces, if you have to).
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
     When clicked on a string, the corresponding action is called"
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
    labelsAndActions := aCollectionOfAssociations.
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
    self label:((aCollectionOfAssociations collect:[:assoc | assoc key]) asStringWith:'')
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
! !
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
!LinkButton methodsFor:'initialization'!
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
defaultControllerClass
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
    ^ LinkButtonController
3662
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   104
!
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   105
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   106
initStyle
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   107
    super initStyle.
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   108
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   109
    level := enterLevel := leaveLevel := onLevel := offLevel := 0.
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   110
    DefaultLinkColor notNil ifTrue:[
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   111
        foreground := DefaultLinkColor onDevice:device.
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   112
    ].
3670
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   113
"/    activeFgColor := enteredFgColor := foreground.
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   114
"/    activeBgColor := enteredBgColor := viewBackground.
3662
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   115
!
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   116
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   117
initialize
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   118
    super initialize.
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   119
    self enableMotionEvents
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   120
! !
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   121
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   122
!LinkButton methodsFor:'redrawing'!
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   123
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   124
actionAt:aPoint
3670
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   125
    |pressAction emphasis|
3664
b49c21d9aac4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3662
diff changeset
   126
b49c21d9aac4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3662
diff changeset
   127
    pressAction := self pressAction ? self releaseAction.
3670
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   128
    labelsAndActions isNil ifTrue:[
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   129
        "take action from logo, which is normally a text"
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   130
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   131
        emphasis := logo emphasisAtPoint:aPoint on:self.
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   132
        (emphasis isNil or:[emphasis isSymbol]) ifTrue:[
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   133
            ^ pressAction.
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   134
        ].
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   135
        emphasis isAssociation ifTrue:[
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   136
            emphasis key == #actionBlock ifTrue:[
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   137
                ^ emphasis value.
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   138
            ].
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   139
            ^ pressAction.
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   140
        ].
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   141
        emphasis do:[:eachElement|
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   142
            eachElement isAssociation ifTrue:[
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   143
                eachElement key == #actionBlock ifTrue:[
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   144
                    ^ eachElement value.
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   145
                ].
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   146
            ].
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   147
        ].
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   148
        ^ pressAction.
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   149
    ].
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   150
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   151
3662
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   152
    self labelsAndActionsWithPositionsDo:[:lbl :action :leftX :rightX |
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   153
        (aPoint x between:leftX and:rightX) ifTrue:[
3664
b49c21d9aac4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3662
diff changeset
   154
            ^ labelsAndActions notNil ifTrue:action ifFalse:pressAction
3662
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   155
        ].
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   156
    ].
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   157
    ^ nil
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   158
!
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   159
3670
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   160
actionEmphasisIn:aText atPoint:aPoint
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   161
    "check for a actionBlock emphasis in aString at aPoint.
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   162
     Answer an Array with the whole emphasis and the actionBlock,
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   163
     or nil"
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   164
    
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   165
    |emphasis|
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   166
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   167
    emphasis := aText emphasisAtPoint:aPoint on:self.
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   168
    (emphasis isNil or:[emphasis isSymbol]) ifTrue:[
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   169
        ^ #(nil nil).
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   170
    ].
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   171
    emphasis isAssociation ifTrue:[
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   172
        emphasis key == #actionBlock ifTrue:[
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   173
            ^ Array with:emphasis with:emphasis value.
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   174
        ].
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   175
        ^ #(nil nil).
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   176
    ].
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   177
    emphasis detect:[:eachElement|
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   178
        eachElement isAssociation ifTrue:[
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   179
            eachElement key == #actionBlock ifTrue:[
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   180
                ^ Array with:emphasis with:eachElement value.
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   181
            ].
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   182
        ].
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   183
    ] ifNone:[].
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   184
    ^ #(nil nil).
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   185
!
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   186
3662
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   187
drawStringLogo:aString x:x y:y
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   188
    "redefined to draw the part under the mouse pointer with an underined emphasis"
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   189
3670
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   190
    |str entered mousePoint start len emphasis|
3662
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   191
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   192
    mousePoint := controller lastMousePoint.
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   193
    entered := controller entered.
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   194
3670
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   195
    labelsAndActions isNil ifTrue:[
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   196
        (entered not or:[mousePoint isNil]) ifTrue:[
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   197
            self displayString:aString x:x y:y.
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   198
            ^ self.
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   199
        ].
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   200
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   201
        str := aString.
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   202
        emphasis := (self actionEmphasisIn:aString atPoint:mousePoint) first.
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   203
        emphasis notNil ifTrue:[
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   204
            start := 1.
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   205
            aString emphasisCollection runsDo:[:eachLen :eachEmphasis|
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   206
                len isNil ifTrue:[
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   207
                    eachEmphasis == emphasis ifTrue:[
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   208
                        len := eachLen.
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   209
                    ] ifFalse:[
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   210
                        start := start + eachLen.  
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   211
                    ].
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   212
                ].
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   213
            ].
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   214
            len notNil ifTrue:[
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   215
                str := str deepCopy.
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   216
                str emphasisFrom:start to:start+len-1 add:#underline.
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   217
                str emphasisFrom:start to:start+len-1 add:(#color -> foreground).
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   218
            ].
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   219
        ].
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   220
        self displayString:str x:x y:y.
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   221
        ^ self.
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   222
    ].
ccfd04be9736 Now works with Text/actionBlocks
Stefan Vogel <sv@exept.de>
parents: 3668
diff changeset
   223
3662
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   224
    self labelsAndActionsWithPositionsDo:[:lbl :action :leftX :rightX |
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   225
        |l|
3668
e1888e938d68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
   226
3662
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   227
        l := lbl.
3668
e1888e938d68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
   228
        action notNil ifTrue:[
e1888e938d68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
   229
            (entered and:[mousePoint notNil and:[mousePoint x between:leftX and:rightX]]) ifTrue:[
e1888e938d68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
   230
                l := l allUnderlined
e1888e938d68 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
   231
            ].
3662
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   232
        ].
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   233
        self displayString:l x:leftX y:y.
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   234
    ].
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   235
!
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   236
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   237
labelsAndActionsWithPositionsDo:aFourArgBlock
3664
b49c21d9aac4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3662
diff changeset
   238
    |leftX rightX w|
3662
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   239
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   240
    leftX := labelOriginX.
3664
b49c21d9aac4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3662
diff changeset
   241
    labelsAndActions isNil ifTrue:[
b49c21d9aac4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3662
diff changeset
   242
        w := (self font widthOf:logo on:device).
b49c21d9aac4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3662
diff changeset
   243
        rightX := leftX + w-1.
b49c21d9aac4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3662
diff changeset
   244
        aFourArgBlock 
b49c21d9aac4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3662
diff changeset
   245
            value:logo
b49c21d9aac4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3662
diff changeset
   246
            value:self pressAction
b49c21d9aac4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3662
diff changeset
   247
            value:leftX
b49c21d9aac4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3662
diff changeset
   248
            value:rightX.
b49c21d9aac4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3662
diff changeset
   249
        ^ self
b49c21d9aac4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3662
diff changeset
   250
    ].
b49c21d9aac4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3662
diff changeset
   251
3662
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   252
    labelsAndActions do:[:assoc | 
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   253
        |lbl wEach|
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   254
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   255
        lbl := assoc key.
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   256
        wEach := (self font widthOf:lbl on:device).
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   257
        rightX := leftX + wEach-1.
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   258
        aFourArgBlock 
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   259
            value:assoc key
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   260
            value:assoc value
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   261
            value:leftX
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   262
            value:rightX.
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   263
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   264
        leftX := rightX+1.
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   265
    ].
fb3778b66ce3 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3650
diff changeset
   266
    ^ nil
3650
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   267
! !
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   268
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   269
!LinkButton class methodsFor:'documentation'!
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   270
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   271
version
3671
a43da2ee728e changed #drawStringLogo:x:y: - remove halt
Stefan Vogel <sv@exept.de>
parents: 3670
diff changeset
   272
    ^ '$Header: /cvs/stx/stx/libwidg2/LinkButton.st,v 1.7 2009-03-23 07:23:06 stefan Exp $'
3650
60a95483b993 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   273
! !