LabelAndIcon.st
author Claus Gittinger <cg@exept.de>
Tue, 24 Jun 2008 13:02:06 +0200
changeset 3450 b0ce6b6fa2c6
parent 3132 9ee61ede263a
child 3453 ed5454e9bbd1
permissions -rw-r--r--
comments and examples
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     1
"
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     2
 COPYRIGHT (c) 1996 by Claus Gittinger
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
              All Rights Reserved
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
 This software is furnished under a license and may be used
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 hereby transferred.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
"
1814
a7697ca7f34f added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents: 1604
diff changeset
    12
"{ Package: 'stx:libwidg2' }"
a7697ca7f34f added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents: 1604
diff changeset
    13
2197
7ad026a1ae93 Make subclass of ModelListEntry
Stefan Vogel <sv@exept.de>
parents: 1977
diff changeset
    14
ModelListEntry subclass:#LabelAndIcon
7ad026a1ae93 Make subclass of ModelListEntry
Stefan Vogel <sv@exept.de>
parents: 1977
diff changeset
    15
	instanceVariableNames:'icon gap image offset'
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
	classVariableNames:''
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	poolDictionaries:''
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	category:'Views-Support'
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!LabelAndIcon class methodsFor:'documentation'!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
copyright
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
"
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
 COPYRIGHT (c) 1996 by Claus Gittinger
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
              All Rights Reserved
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
 This software is furnished under a license and may be used
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
 only in accordance with the terms of that license and with the
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 be provided or otherwise made available to, or used by, any
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 other person.  No title to or ownership of the software is
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 hereby transferred.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
"
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
documentation
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
"
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
    an icon and a string, side by side.
178
ba4f86aaa203 example
Claus Gittinger <cg@exept.de>
parents: 177
diff changeset
    41
    Usable as list entries in a listView (a fileList), as
179
fccdac863996 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
    42
    popUpMenuItems or as Label/Button image.
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
    This is an example class - currently not used by the system.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
179
fccdac863996 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
    46
    Notice:
fccdac863996 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
    47
        This is different from ST-80's LabelAndIcon class, which
fccdac863996 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
    48
        inherits from Label. Therefore, things may change in the future.
fccdac863996 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
    49
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
    [author:]
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
        Claus Gittinger
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
    [see also:]
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
        ListEntry Text String Icon
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
        ListView SelectionInListView
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
"
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
examples
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
"
175
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    61
  in a listView:
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
                                                                        [exBegin]
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
    |top slv wrapper l fileImage dirImage|
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
    fileImage := Image 
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
                   width:16 
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
                   height:16
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
                   depth:1
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
                   fromArray:#[2r00000000 2r00000000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
                               2r00000000 2r00000000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
                               2r00011111 2r11100000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
                               2r00010000 2r00100000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
                               2r00010000 2r00011000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
                               2r00010000 2r00001000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
                               2r00010000 2r00001000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
                               2r00010000 2r00001000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
                               2r00010000 2r00001000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
                               2r00010000 2r00001000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
                               2r00010000 2r00001000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
                               2r00010000 2r00001000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
                               2r00010000 2r00001000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
                               2r00011111 2r11111000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
                               2r00000000 2r00000000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
                               2r00000000 2r00000000].
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
    fileImage photometric:#whiteIs0.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
    dirImage := Image 
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
                   width:16 
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
                   height:16
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
                   depth:1
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
                   fromArray:#[2r00000000 2r00000000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
                               2r00000000 2r00000000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
                               2r00000000 2r00000000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
                               2r01111111 2r11110000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
                               2r01000000 2r00001000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
                               2r01000000 2r00000100
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
                               2r01000000 2r00000010
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
                               2r01000000 2r00000010
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
                               2r01000000 2r00000010
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   100
                               2r01000000 2r00000010
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   101
                               2r01000000 2r00000010
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   102
                               2r01000000 2r00000010
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
                               2r01111111 2r11111110
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
                               2r00000000 2r00000000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
                               2r00000000 2r00000000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   106
                               2r00000000 2r00000000].
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   107
    dirImage photometric:#whiteIs0.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
    l := OrderedCollection new.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
    Filename currentDirectory directoryContents do:[:s |
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
        s asFilename isDirectory ifTrue:[
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
            l add:(LabelAndIcon icon:dirImage string:s)
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
        ] ifFalse:[
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
            l add:(LabelAndIcon icon:fileImage string:s)
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
        ]
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
    ].
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
    slv := SelectionInListView new.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
    slv list:l.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
    wrapper := HVScrollableView forView:slv miniScrollerH:true.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
    top := StandardSystemView extent:150@200.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
    top add:wrapper in:(0.0@0.0 corner:1.0@1.0).
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
    top open.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
                                                                        [exEnd]
175
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   127
  in a selectionInListView:
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
                                                                        [exBegin]
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   129
    |top slv wrapper l fileImage dirImage|
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
    dirImage := Image fromFile:'DirObj.xbm'.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
    fileImage := Image fromFile:'FileObj.xbm'.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
    l := OrderedCollection new.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
    Filename currentDirectory directoryContents do:[:s |
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
        s asFilename isDirectory ifTrue:[
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
            l add:(LabelAndIcon icon:dirImage string:s)
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
        ] ifFalse:[
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
            l add:(LabelAndIcon icon:fileImage string:s)
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
        ]
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
    ].
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
    slv := SelectionInListView new.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
    slv list:l.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
    wrapper := HVScrollableView forView:slv miniScrollerH:true.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
    top := StandardSystemView extent:150@200.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
    top add:wrapper in:(0.0@0.0 corner:1.0@1.0).
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
    top open.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
                                                                        [exEnd]
175
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   152
  in a menu:
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   153
                                                                        [exBegin]
3450
b0ce6b6fa2c6 comments and examples
Claus Gittinger <cg@exept.de>
parents: 3132
diff changeset
   154
    |top l image1 image2|
175
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   155
3450
b0ce6b6fa2c6 comments and examples
Claus Gittinger <cg@exept.de>
parents: 3132
diff changeset
   156
    image1 := Image fromFile:'../../goodies/bitmaps/xpmBitmaps/countries/brazil.xpm'.
b0ce6b6fa2c6 comments and examples
Claus Gittinger <cg@exept.de>
parents: 3132
diff changeset
   157
    image2 := Image fromFile:'../../goodies/bitmaps/xpmBitmaps/countries/germany.xpm'.
175
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   158
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   159
    l := OrderedCollection new.
3450
b0ce6b6fa2c6 comments and examples
Claus Gittinger <cg@exept.de>
parents: 3132
diff changeset
   160
    l add:(LabelAndIcon icon:image1 string:'brazil').
b0ce6b6fa2c6 comments and examples
Claus Gittinger <cg@exept.de>
parents: 3132
diff changeset
   161
    l add:(LabelAndIcon icon:image2 string:'germany').
175
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   162
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   163
    top := View new.
3450
b0ce6b6fa2c6 comments and examples
Claus Gittinger <cg@exept.de>
parents: 3132
diff changeset
   164
    top middleButtonMenu:(PopUpMenu 
b0ce6b6fa2c6 comments and examples
Claus Gittinger <cg@exept.de>
parents: 3132
diff changeset
   165
                        labels:l
175
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   166
                        selectors:#(foo bar)).
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   167
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   168
    top open.
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   169
                                                                        [exEnd]
178
ba4f86aaa203 example
Claus Gittinger <cg@exept.de>
parents: 177
diff changeset
   170
  in a button/label:
ba4f86aaa203 example
Claus Gittinger <cg@exept.de>
parents: 177
diff changeset
   171
                                                                        [exBegin]
ba4f86aaa203 example
Claus Gittinger <cg@exept.de>
parents: 177
diff changeset
   172
    |top l image|
ba4f86aaa203 example
Claus Gittinger <cg@exept.de>
parents: 177
diff changeset
   173
3450
b0ce6b6fa2c6 comments and examples
Claus Gittinger <cg@exept.de>
parents: 3132
diff changeset
   174
    image := Image fromFile:'../../goodies/bitmaps/xpmBitmaps/countries/brazil.xpm'.
b0ce6b6fa2c6 comments and examples
Claus Gittinger <cg@exept.de>
parents: 3132
diff changeset
   175
    l := (LabelAndIcon icon:image string:'brazil').
b0ce6b6fa2c6 comments and examples
Claus Gittinger <cg@exept.de>
parents: 3132
diff changeset
   176
b0ce6b6fa2c6 comments and examples
Claus Gittinger <cg@exept.de>
parents: 3132
diff changeset
   177
    top := Button label:l.
b0ce6b6fa2c6 comments and examples
Claus Gittinger <cg@exept.de>
parents: 3132
diff changeset
   178
    top open.
b0ce6b6fa2c6 comments and examples
Claus Gittinger <cg@exept.de>
parents: 3132
diff changeset
   179
                                                                        [exEnd]
b0ce6b6fa2c6 comments and examples
Claus Gittinger <cg@exept.de>
parents: 3132
diff changeset
   180
  two images in a button/label:
b0ce6b6fa2c6 comments and examples
Claus Gittinger <cg@exept.de>
parents: 3132
diff changeset
   181
                                                                        [exBegin]
b0ce6b6fa2c6 comments and examples
Claus Gittinger <cg@exept.de>
parents: 3132
diff changeset
   182
    |top l image1 image2|
b0ce6b6fa2c6 comments and examples
Claus Gittinger <cg@exept.de>
parents: 3132
diff changeset
   183
b0ce6b6fa2c6 comments and examples
Claus Gittinger <cg@exept.de>
parents: 3132
diff changeset
   184
    image1 := Image fromFile:'../../goodies/bitmaps/xpmBitmaps/countries/brazil.xpm'.
b0ce6b6fa2c6 comments and examples
Claus Gittinger <cg@exept.de>
parents: 3132
diff changeset
   185
    image2 := Image fromFile:'../../goodies/bitmaps/xpmBitmaps/countries/germany.xpm'.
b0ce6b6fa2c6 comments and examples
Claus Gittinger <cg@exept.de>
parents: 3132
diff changeset
   186
    l := (LabelAndIcon form:image1 image:image2 string:'directory').
178
ba4f86aaa203 example
Claus Gittinger <cg@exept.de>
parents: 177
diff changeset
   187
ba4f86aaa203 example
Claus Gittinger <cg@exept.de>
parents: 177
diff changeset
   188
    top := Button label:l.
ba4f86aaa203 example
Claus Gittinger <cg@exept.de>
parents: 177
diff changeset
   189
    top open.
ba4f86aaa203 example
Claus Gittinger <cg@exept.de>
parents: 177
diff changeset
   190
                                                                        [exEnd]
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   191
"
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
! !
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   193
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
!LabelAndIcon class methodsFor:'instance creation'!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
629
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   196
form:aForm image:anImage
3450
b0ce6b6fa2c6 comments and examples
Claus Gittinger <cg@exept.de>
parents: 3132
diff changeset
   197
    "return an instance consisting of a form and an icon (on the left)"
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   198
629
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   199
    ^self new form:aForm image:anImage string:''
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   200
!
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   201
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   202
form:aForm image:anImage string:aString
3450
b0ce6b6fa2c6 comments and examples
Claus Gittinger <cg@exept.de>
parents: 3132
diff changeset
   203
    "return an instance consisting of two images (both on the left) and a string"
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   204
629
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   205
    ^self new form:aForm image:anImage string:aString
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   206
!
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   207
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
icon:anIcon string:aString
3450
b0ce6b6fa2c6 comments and examples
Claus Gittinger <cg@exept.de>
parents: 3132
diff changeset
   209
    "return an instance consisting of a label-string and an icon (on the left)"
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   210
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
    ^ self new icon:anIcon string:aString
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   212
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
    "Created: 12.5.1996 / 20:00:58 / cg"
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
1977
e658f77f88b2 checkin from browser
tm
parents: 1975
diff changeset
   216
label:aString icon:anIcon
3450
b0ce6b6fa2c6 comments and examples
Claus Gittinger <cg@exept.de>
parents: 3132
diff changeset
   217
    "return an instance consisting of a label-string and an icon (on the left)"
b0ce6b6fa2c6 comments and examples
Claus Gittinger <cg@exept.de>
parents: 3132
diff changeset
   218
1977
e658f77f88b2 checkin from browser
tm
parents: 1975
diff changeset
   219
    ^ self new icon:anIcon string:aString
e658f77f88b2 checkin from browser
tm
parents: 1975
diff changeset
   220
!
e658f77f88b2 checkin from browser
tm
parents: 1975
diff changeset
   221
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
new
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
    ^ self basicNew initialize
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   225
    "Created: 12.5.1996 / 20:00:58 / cg"
986
ed6b89c43416 added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 981
diff changeset
   226
!
ed6b89c43416 added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 981
diff changeset
   227
ed6b89c43416 added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 981
diff changeset
   228
string:aString
3450
b0ce6b6fa2c6 comments and examples
Claus Gittinger <cg@exept.de>
parents: 3132
diff changeset
   229
    "return an instance consisting of a string only"
986
ed6b89c43416 added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 981
diff changeset
   230
ed6b89c43416 added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 981
diff changeset
   231
    ^ self new icon:nil string:aString
ed6b89c43416 added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 981
diff changeset
   232
ed6b89c43416 added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 981
diff changeset
   233
    "Created: / 21.6.1998 / 04:57:28 / cg"
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   234
! !
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   235
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   236
!LabelAndIcon methodsFor:'accessing'!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
986
ed6b89c43416 added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 981
diff changeset
   238
beCheckMark
1860
b4c0e45ad336 use a smaller check-icon
Claus Gittinger <cg@exept.de>
parents: 1817
diff changeset
   239
    "/ self icon:(CheckToggle checkFormOn:Screen current)
b4c0e45ad336 use a smaller check-icon
Claus Gittinger <cg@exept.de>
parents: 1817
diff changeset
   240
    self icon:((CheckToggle smallCheckImageForStyle:#borderedFatcross) onDevice:Screen current)
986
ed6b89c43416 added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 981
diff changeset
   241
ed6b89c43416 added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 981
diff changeset
   242
    "Created: / 21.6.1998 / 05:01:01 / cg"
ed6b89c43416 added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 981
diff changeset
   243
    "Modified: / 21.6.1998 / 05:03:23 / cg"
ed6b89c43416 added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 981
diff changeset
   244
!
ed6b89c43416 added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 981
diff changeset
   245
629
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   246
form:aForm image:anImage string:aString
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   247
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   248
    icon := aForm.
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   249
    image:= anImage.
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   250
    string := aString. 
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   251
!
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   252
1975
bad9d0302b03 added #gap
martin
parents: 1860
diff changeset
   253
gap
bad9d0302b03 added #gap
martin
parents: 1860
diff changeset
   254
    "return the spacing between the icon and the labelString.
bad9d0302b03 added #gap
martin
parents: 1860
diff changeset
   255
     The default is 4"
bad9d0302b03 added #gap
martin
parents: 1860
diff changeset
   256
bad9d0302b03 added #gap
martin
parents: 1860
diff changeset
   257
    ^ gap
bad9d0302b03 added #gap
martin
parents: 1860
diff changeset
   258
!
bad9d0302b03 added #gap
martin
parents: 1860
diff changeset
   259
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   260
gap:pixels
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   261
    "set the spacing between the icon and the labelString.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   262
     The default is 4."
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   263
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   264
    gap := pixels.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   265
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   266
    "Created: 12.5.1996 / 20:00:52 / cg"
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   267
!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   268
286
89cced571c0f add accessing method to get the icon
ca
parents: 258
diff changeset
   269
icon
89cced571c0f add accessing method to get the icon
ca
parents: 258
diff changeset
   270
    "return my icon part"
89cced571c0f add accessing method to get the icon
ca
parents: 258
diff changeset
   271
89cced571c0f add accessing method to get the icon
ca
parents: 258
diff changeset
   272
    ^ icon
89cced571c0f add accessing method to get the icon
ca
parents: 258
diff changeset
   273
!
89cced571c0f add accessing method to get the icon
ca
parents: 258
diff changeset
   274
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   275
icon:anIcon
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   276
    "set the icon image"
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   277
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   278
    icon := anIcon.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   279
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   280
    "Created: 12.5.1996 / 20:00:52 / cg"
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   281
!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   282
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   283
icon:anIcon string:aString
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   284
    "set both iconImage and the labelString"
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   285
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   286
    icon := anIcon.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   287
    string := aString
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   288
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   289
    "Created: 12.5.1996 / 20:00:52 / cg"
175
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   290
!
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   291
719
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   292
image
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   293
    "return my image"
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   294
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   295
    ^ image
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   296
!
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   297
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   298
image:anImage
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   299
    "set the image"
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   300
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   301
    image := anImage
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   302
!
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   303
3132
9ee61ede263a *** empty log message ***
ca
parents: 2773
diff changeset
   304
offset
9ee61ede263a *** empty log message ***
ca
parents: 2773
diff changeset
   305
    "set the left offset (i.e. spacing to the left of the icon).
9ee61ede263a *** empty log message ***
ca
parents: 2773
diff changeset
   306
     The default is 0."
9ee61ede263a *** empty log message ***
ca
parents: 2773
diff changeset
   307
9ee61ede263a *** empty log message ***
ca
parents: 2773
diff changeset
   308
    ^ offset
9ee61ede263a *** empty log message ***
ca
parents: 2773
diff changeset
   309
!
9ee61ede263a *** empty log message ***
ca
parents: 2773
diff changeset
   310
981
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   311
offset:pixels
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   312
    "set the left offset (i.e. spacing to the left of the icon).
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   313
     The default is 0."
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   314
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   315
    offset := pixels.
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   316
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   317
    "Created: / 21.6.1998 / 03:11:03 / cg"
3132
9ee61ede263a *** empty log message ***
ca
parents: 2773
diff changeset
   318
!
9ee61ede263a *** empty log message ***
ca
parents: 2773
diff changeset
   319
9ee61ede263a *** empty log message ***
ca
parents: 2773
diff changeset
   320
xOfString
9ee61ede263a *** empty log message ***
ca
parents: 2773
diff changeset
   321
    "returns the x position of the string"
9ee61ede263a *** empty log message ***
ca
parents: 2773
diff changeset
   322
9ee61ede263a *** empty log message ***
ca
parents: 2773
diff changeset
   323
    |x img|
9ee61ede263a *** empty log message ***
ca
parents: 2773
diff changeset
   324
9ee61ede263a *** empty log message ***
ca
parents: 2773
diff changeset
   325
    x := offset.
9ee61ede263a *** empty log message ***
ca
parents: 2773
diff changeset
   326
9ee61ede263a *** empty log message ***
ca
parents: 2773
diff changeset
   327
    (img := icon value) notNil ifTrue:[
9ee61ede263a *** empty log message ***
ca
parents: 2773
diff changeset
   328
        x := x + img width + gap
9ee61ede263a *** empty log message ***
ca
parents: 2773
diff changeset
   329
    ].
9ee61ede263a *** empty log message ***
ca
parents: 2773
diff changeset
   330
    (img := image value) notNil ifTrue:[
9ee61ede263a *** empty log message ***
ca
parents: 2773
diff changeset
   331
        x := x + img width + gap
9ee61ede263a *** empty log message ***
ca
parents: 2773
diff changeset
   332
    ].
9ee61ede263a *** empty log message ***
ca
parents: 2773
diff changeset
   333
    ^ x
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   334
! !
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   335
1814
a7697ca7f34f added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents: 1604
diff changeset
   336
!LabelAndIcon methodsFor:'comparing'!
a7697ca7f34f added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents: 1604
diff changeset
   337
2657
20d7ed550989 also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents: 2454
diff changeset
   338
= aStringOrLabelAndIcon
2674
e877ecb7d8b7 Allow #= comparison against nil
Stefan Vogel <sv@exept.de>
parents: 2657
diff changeset
   339
e877ecb7d8b7 Allow #= comparison against nil
Stefan Vogel <sv@exept.de>
parents: 2657
diff changeset
   340
    aStringOrLabelAndIcon isNil ifTrue:[^ false].
e877ecb7d8b7 Allow #= comparison against nil
Stefan Vogel <sv@exept.de>
parents: 2657
diff changeset
   341
2657
20d7ed550989 also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents: 2454
diff changeset
   342
    self hasIcon == aStringOrLabelAndIcon hasIcon ifFalse:[^ false].
20d7ed550989 also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents: 2454
diff changeset
   343
    aStringOrLabelAndIcon hasIcon ifTrue:[
20d7ed550989 also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents: 2454
diff changeset
   344
        icon = aStringOrLabelAndIcon icon ifFalse:[^ false].
20d7ed550989 also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents: 2454
diff changeset
   345
    ].
20d7ed550989 also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents: 2454
diff changeset
   346
    self hasImage == aStringOrLabelAndIcon hasImage ifFalse:[^ false].
20d7ed550989 also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents: 2454
diff changeset
   347
    aStringOrLabelAndIcon hasImage ifTrue:[
20d7ed550989 also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents: 2454
diff changeset
   348
        image = aStringOrLabelAndIcon image ifFalse:[^ false].
20d7ed550989 also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents: 2454
diff changeset
   349
    ].
20d7ed550989 also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents: 2454
diff changeset
   350
    ^ super = aStringOrLabelAndIcon
20d7ed550989 also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents: 2454
diff changeset
   351
!
20d7ed550989 also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents: 2454
diff changeset
   352
1814
a7697ca7f34f added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents: 1604
diff changeset
   353
sameStringAndEmphasisAs:someStringOrLabelAndIcon
1817
e639d2a9d605 tuned compare
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   354
    someStringOrLabelAndIcon class == self class ifTrue:[
e639d2a9d605 tuned compare
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   355
        icon = someStringOrLabelAndIcon icon ifFalse:[^ false].
e639d2a9d605 tuned compare
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   356
        image = someStringOrLabelAndIcon image ifFalse:[^ false].
e639d2a9d605 tuned compare
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   357
        (string sameStringAndEmphasisAs:someStringOrLabelAndIcon string) ifFalse:[ ^ false].
e639d2a9d605 tuned compare
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   358
        ^ true.        
e639d2a9d605 tuned compare
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   359
    ].
e639d2a9d605 tuned compare
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   360
1814
a7697ca7f34f added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents: 1604
diff changeset
   361
    (string sameStringAndEmphasisAs:someStringOrLabelAndIcon) ifFalse:[ ^ false].
a7697ca7f34f added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents: 1604
diff changeset
   362
    (icon isNil and:[image isNil]) ifTrue:[^ true].
1817
e639d2a9d605 tuned compare
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   363
    ^ false
1814
a7697ca7f34f added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents: 1604
diff changeset
   364
! !
a7697ca7f34f added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents: 1604
diff changeset
   365
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   366
!LabelAndIcon methodsFor:'displaying'!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   367
2453
3dad4e5c2fbe ascentOn: (is this correct ?)
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   368
ascentOn:aGC
2454
aca5d29e6298 oops - ascent
Claus Gittinger <cg@exept.de>
parents: 2453
diff changeset
   369
    ^ aGC font ascentOn:aGC device.
2453
3dad4e5c2fbe ascentOn: (is this correct ?)
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   370
!
3dad4e5c2fbe ascentOn: (is this correct ?)
Claus Gittinger <cg@exept.de>
parents: 2197
diff changeset
   371
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   372
displayOn:aGC x:x y:y opaque:opaque
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   373
    "display the receiver on a GC"
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   374
2773
ba1b2f93afee care for icon-blocks
Claus Gittinger <cg@exept.de>
parents: 2674
diff changeset
   375
    |y1 x1 iconValue imageValue iconHeight imageHeight stringHeight maxHeight gapY asc|
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   376
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   377
    gapY := (aGC device pixelPerMillimeter x) rounded.
1860
b4c0e45ad336 use a smaller check-icon
Claus Gittinger <cg@exept.de>
parents: 1817
diff changeset
   378
    "/ gapY := 0.
1479
8511f61fe8fe #on: -> #onDevice:
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   379
    asc  := (aGC font onDevice:aGC device) ascent.
180
c63c079dea01 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 179
diff changeset
   380
2773
ba1b2f93afee care for icon-blocks
Claus Gittinger <cg@exept.de>
parents: 2674
diff changeset
   381
    iconValue := icon value.
ba1b2f93afee care for icon-blocks
Claus Gittinger <cg@exept.de>
parents: 2674
diff changeset
   382
    imageValue := image value.
ba1b2f93afee care for icon-blocks
Claus Gittinger <cg@exept.de>
parents: 2674
diff changeset
   383
ba1b2f93afee care for icon-blocks
Claus Gittinger <cg@exept.de>
parents: 2674
diff changeset
   384
    iconHeight   := iconValue notNil ifTrue:[iconValue height]   ifFalse:[0].
ba1b2f93afee care for icon-blocks
Claus Gittinger <cg@exept.de>
parents: 2674
diff changeset
   385
    imageHeight  := imageValue notNil ifTrue:[imageValue height]  ifFalse:[0].
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   386
    stringHeight := string size > 0 ifTrue:[string heightOn:aGC] ifFalse:[0].
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   387
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   388
    maxHeight := ((iconHeight max: imageHeight) + gapY) max: stringHeight.
981
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   389
    x1 := x + offset.
258
e46fadff344c added access to string
Claus Gittinger <cg@exept.de>
parents: 180
diff changeset
   390
2773
ba1b2f93afee care for icon-blocks
Claus Gittinger <cg@exept.de>
parents: 2674
diff changeset
   391
    iconValue notNil ifTrue:[
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   392
        y1 := y - asc + (maxHeight - iconHeight + 1 // 2).
1860
b4c0e45ad336 use a smaller check-icon
Claus Gittinger <cg@exept.de>
parents: 1817
diff changeset
   393
2773
ba1b2f93afee care for icon-blocks
Claus Gittinger <cg@exept.de>
parents: 2674
diff changeset
   394
        icon := iconValue onDevice:aGC device.
578
72916ad0a5f3 fixed centering of the image w.r.t. the fontHeight
Claus Gittinger <cg@exept.de>
parents: 423
diff changeset
   395
2773
ba1b2f93afee care for icon-blocks
Claus Gittinger <cg@exept.de>
parents: 2674
diff changeset
   396
        (opaque and:[iconValue mask isNil]) ifTrue:[aGC displayOpaqueForm:iconValue x:x1 y:y1]
ba1b2f93afee care for icon-blocks
Claus Gittinger <cg@exept.de>
parents: 2674
diff changeset
   397
                                            ifFalse:[aGC displayForm:iconValue x:x1 y:y1].
578
72916ad0a5f3 fixed centering of the image w.r.t. the fontHeight
Claus Gittinger <cg@exept.de>
parents: 423
diff changeset
   398
2773
ba1b2f93afee care for icon-blocks
Claus Gittinger <cg@exept.de>
parents: 2674
diff changeset
   399
        x1 := x1 + iconValue width + gap
258
e46fadff344c added access to string
Claus Gittinger <cg@exept.de>
parents: 180
diff changeset
   400
    ].
e46fadff344c added access to string
Claus Gittinger <cg@exept.de>
parents: 180
diff changeset
   401
2773
ba1b2f93afee care for icon-blocks
Claus Gittinger <cg@exept.de>
parents: 2674
diff changeset
   402
    imageValue notNil ifTrue:[
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   403
        y1 := y - asc + (maxHeight - imageHeight + 1 // 2).
2773
ba1b2f93afee care for icon-blocks
Claus Gittinger <cg@exept.de>
parents: 2674
diff changeset
   404
        image := imageValue onDevice:aGC device.
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   405
2773
ba1b2f93afee care for icon-blocks
Claus Gittinger <cg@exept.de>
parents: 2674
diff changeset
   406
        (opaque and:[imageValue mask isNil]) ifTrue:[aGC displayOpaqueForm:imageValue x:x1 y:y1]
ba1b2f93afee care for icon-blocks
Claus Gittinger <cg@exept.de>
parents: 2674
diff changeset
   407
                                             ifFalse:[aGC displayForm:imageValue x:x1 y:y1].
629
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   408
2773
ba1b2f93afee care for icon-blocks
Claus Gittinger <cg@exept.de>
parents: 2674
diff changeset
   409
        x1 := x1 + imageValue width + gap
629
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   410
    ].
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   411
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   412
    stringHeight ~~ 0 ifTrue:[
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   413
        y1 := y + (maxHeight - stringHeight + 1 // 2).
981
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   414
        string displayOn:aGC x:x1 y:y1 opaque:opaque
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   415
    ]
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   416
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   417
    "Modified: / 21.6.1998 / 03:52:12 / cg"
810
847d7f52a2fd new methods:
ca
parents: 726
diff changeset
   418
!
847d7f52a2fd new methods:
ca
parents: 726
diff changeset
   419
847d7f52a2fd new methods:
ca
parents: 726
diff changeset
   420
on:aDevice
847d7f52a2fd new methods:
ca
parents: 726
diff changeset
   421
    "return a new image on a device
847d7f52a2fd new methods:
ca
parents: 726
diff changeset
   422
    "
1604
2c15dd8fb3cf ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   423
    ^ self onDevice:aDevice
810
847d7f52a2fd new methods:
ca
parents: 726
diff changeset
   424
847d7f52a2fd new methods:
ca
parents: 726
diff changeset
   425
!
847d7f52a2fd new methods:
ca
parents: 726
diff changeset
   426
847d7f52a2fd new methods:
ca
parents: 726
diff changeset
   427
onDevice:aDevice
847d7f52a2fd new methods:
ca
parents: 726
diff changeset
   428
    "return a new image on a device
847d7f52a2fd new methods:
ca
parents: 726
diff changeset
   429
    "
1604
2c15dd8fb3cf ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   430
    |form img|
2c15dd8fb3cf ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   431
2c15dd8fb3cf ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   432
    aDevice isNil ifTrue:[^ self].
2c15dd8fb3cf ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   433
    icon  notNil ifTrue:[form := icon  onDevice:aDevice].
2c15dd8fb3cf ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   434
    image notNil ifTrue:[img  := image onDevice:aDevice].
2c15dd8fb3cf ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   435
2c15dd8fb3cf ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   436
    ^ LabelAndIcon form:form image:img string:string
2c15dd8fb3cf ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   437
2c15dd8fb3cf ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   438
2c15dd8fb3cf ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   439
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   440
! !
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   441
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   442
!LabelAndIcon methodsFor:'initialization'!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   443
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   444
initialize
981
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   445
    gap := 4.
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   446
    offset := 0.
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   447
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   448
    "Modified: / 21.6.1998 / 03:10:19 / cg"
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   449
! !
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   450
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   451
!LabelAndIcon methodsFor:'queries'!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   452
2657
20d7ed550989 also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents: 2454
diff changeset
   453
hasIcon
20d7ed550989 also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents: 2454
diff changeset
   454
    ^ icon notNil
20d7ed550989 also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents: 2454
diff changeset
   455
!
20d7ed550989 also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents: 2454
diff changeset
   456
20d7ed550989 also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents: 2454
diff changeset
   457
hasImage
20d7ed550989 also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents: 2454
diff changeset
   458
    ^ image notNil
20d7ed550989 also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents: 2454
diff changeset
   459
!
20d7ed550989 also coare for icon and image when comparing
Claus Gittinger <cg@exept.de>
parents: 2454
diff changeset
   460
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   461
heightOn:aGC
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   462
    "return the height of the receiver, if it is to be displayed on aGC"
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   463
719
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   464
    |iconHeight imageHeight stringHeight oneMillimeter|
682
861e446e3b24 checkin from browser
ca
parents: 629
diff changeset
   465
861e446e3b24 checkin from browser
ca
parents: 629
diff changeset
   466
    oneMillimeter := aGC device pixelPerMillimeter x rounded.
1860
b4c0e45ad336 use a smaller check-icon
Claus Gittinger <cg@exept.de>
parents: 1817
diff changeset
   467
    "/ oneMillimeter := 0.
306
f3954479c7e8 handle nil icons
Claus Gittinger <cg@exept.de>
parents: 287
diff changeset
   468
f3954479c7e8 handle nil icons
Claus Gittinger <cg@exept.de>
parents: 287
diff changeset
   469
    icon notNil ifTrue:[
2773
ba1b2f93afee care for icon-blocks
Claus Gittinger <cg@exept.de>
parents: 2674
diff changeset
   470
        iconHeight := icon value height + oneMillimeter
306
f3954479c7e8 handle nil icons
Claus Gittinger <cg@exept.de>
parents: 287
diff changeset
   471
    ] ifFalse:[
f3954479c7e8 handle nil icons
Claus Gittinger <cg@exept.de>
parents: 287
diff changeset
   472
        iconHeight := 0
f3954479c7e8 handle nil icons
Claus Gittinger <cg@exept.de>
parents: 287
diff changeset
   473
    ].
629
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   474
    image notNil ifTrue:[
2773
ba1b2f93afee care for icon-blocks
Claus Gittinger <cg@exept.de>
parents: 2674
diff changeset
   475
        imageHeight := image value height + oneMillimeter
629
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   476
    ] ifFalse:[
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   477
        imageHeight := 0   
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   478
    ].
719
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   479
    string size > 0 ifTrue:[
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   480
        stringHeight := string heightOn:aGC
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   481
    ] ifFalse:[
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   482
        stringHeight := 0   
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   483
    ].
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   484
    ^ ((iconHeight max: imageHeight) max: stringHeight)
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   485
!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   486
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   487
widthOn:aGC
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   488
    "return the width of the receiver, if it is to be displayed on aGC"
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   489
719
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   490
    |width|
306
f3954479c7e8 handle nil icons
Claus Gittinger <cg@exept.de>
parents: 287
diff changeset
   491
981
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   492
    width := offset.
306
f3954479c7e8 handle nil icons
Claus Gittinger <cg@exept.de>
parents: 287
diff changeset
   493
    icon notNil ifTrue:[
2773
ba1b2f93afee care for icon-blocks
Claus Gittinger <cg@exept.de>
parents: 2674
diff changeset
   494
        width := width + icon value width
306
f3954479c7e8 handle nil icons
Claus Gittinger <cg@exept.de>
parents: 287
diff changeset
   495
    ].
629
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   496
    image notNil ifTrue:[
2773
ba1b2f93afee care for icon-blocks
Claus Gittinger <cg@exept.de>
parents: 2674
diff changeset
   497
        width := width + gap + image value width
629
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   498
    ].
719
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   499
    string size > 0 ifTrue:[
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   500
        width := width + gap + (string widthOn:aGC)
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   501
    ].  
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   502
    ^width
981
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   503
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   504
    "Modified: / 21.6.1998 / 03:11:14 / cg"
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   505
! !
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   506
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   507
!LabelAndIcon class methodsFor:'documentation'!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   508
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   509
version
3450
b0ce6b6fa2c6 comments and examples
Claus Gittinger <cg@exept.de>
parents: 3132
diff changeset
   510
    ^ '$Header: /cvs/stx/stx/libwidg2/LabelAndIcon.st,v 1.38 2008-06-24 11:02:06 cg Exp $'
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   511
! !