LabelAndIcon.st
author tz
Wed, 04 Feb 1998 18:52:06 +0100
changeset 726 4b3a40124f6d
parent 719 3a833ca1c54a
child 810 847d7f52a2fd
permissions -rw-r--r--
center label, icon and image in the display routine
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
"
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
ListEntry subclass:#LabelAndIcon
629
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
    15
	instanceVariableNames:'icon gap string image'
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]
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   154
    |top l fileImage dirImage|
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   155
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   156
    dirImage := Image fromFile:'DirObj.xbm'.
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   157
    fileImage := Image fromFile:'FileObj.xbm'.
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   158
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   159
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   160
    l := OrderedCollection new.
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   161
    l add:(LabelAndIcon icon:dirImage string:'create directory').
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   162
    l add:(LabelAndIcon icon:fileImage string:'create file').
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   163
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   164
    top := View new.
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   165
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   166
    top middleButtonMenu:(PopUpMenu labels:l
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   167
                        selectors:#(foo bar)).
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   168
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   169
    top open.
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   170
                                                                        [exEnd]
178
ba4f86aaa203 example
Claus Gittinger <cg@exept.de>
parents: 177
diff changeset
   171
  in a button/label:
ba4f86aaa203 example
Claus Gittinger <cg@exept.de>
parents: 177
diff changeset
   172
                                                                        [exBegin]
ba4f86aaa203 example
Claus Gittinger <cg@exept.de>
parents: 177
diff changeset
   173
    |top l image|
ba4f86aaa203 example
Claus Gittinger <cg@exept.de>
parents: 177
diff changeset
   174
ba4f86aaa203 example
Claus Gittinger <cg@exept.de>
parents: 177
diff changeset
   175
    image := Image fromFile:'DirObj.xbm'.
ba4f86aaa203 example
Claus Gittinger <cg@exept.de>
parents: 177
diff changeset
   176
    l := (LabelAndIcon icon:image string:'directory').
ba4f86aaa203 example
Claus Gittinger <cg@exept.de>
parents: 177
diff changeset
   177
ba4f86aaa203 example
Claus Gittinger <cg@exept.de>
parents: 177
diff changeset
   178
    top := Button label:l.
ba4f86aaa203 example
Claus Gittinger <cg@exept.de>
parents: 177
diff changeset
   179
    top open.
ba4f86aaa203 example
Claus Gittinger <cg@exept.de>
parents: 177
diff changeset
   180
                                                                        [exEnd]
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   181
"
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   182
! !
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   184
!LabelAndIcon class methodsFor:'instance creation'!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
629
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   186
form:aForm image:anImage
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   187
629
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   188
    ^self new form:aForm image:anImage string:''
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   189
!
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   190
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   191
form:aForm image:anImage string:aString
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   192
629
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   193
    ^self new form:aForm image:anImage string:aString
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   194
!
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   195
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
icon:anIcon string:aString
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   197
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
    ^ self new icon:anIcon string:aString
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
    "Created: 12.5.1996 / 20:00:58 / cg"
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   201
!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   202
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   203
new
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   204
    ^ self basicNew initialize
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   205
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
    "Created: 12.5.1996 / 20:00:58 / cg"
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
! !
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
!LabelAndIcon methodsFor:'accessing'!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
629
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   211
form:aForm image:anImage string:aString
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   212
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   213
    icon := aForm.
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   214
    image:= anImage.
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   215
    string := aString. 
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   216
!
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   217
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
gap:pixels
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   219
    "set the spacing between the icon and the labelString.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
     The default is 4."
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   221
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
    gap := pixels.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
    "Created: 12.5.1996 / 20:00:52 / cg"
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   225
!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   226
286
89cced571c0f add accessing method to get the icon
ca
parents: 258
diff changeset
   227
icon
89cced571c0f add accessing method to get the icon
ca
parents: 258
diff changeset
   228
    "return my icon part"
89cced571c0f add accessing method to get the icon
ca
parents: 258
diff changeset
   229
89cced571c0f add accessing method to get the icon
ca
parents: 258
diff changeset
   230
    ^ icon
89cced571c0f add accessing method to get the icon
ca
parents: 258
diff changeset
   231
!
89cced571c0f add accessing method to get the icon
ca
parents: 258
diff changeset
   232
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   233
icon:anIcon
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   234
    "set the icon image"
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   235
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   236
    icon := anIcon.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
    "Created: 12.5.1996 / 20:00:52 / cg"
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   239
!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   240
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   241
icon:anIcon string:aString
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
    "set both iconImage and the labelString"
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   243
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   244
    icon := anIcon.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   245
    string := aString
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   247
    "Created: 12.5.1996 / 20:00:52 / cg"
175
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   248
!
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   249
719
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   250
image
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   251
    "return my image"
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   252
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   253
    ^ image
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   254
!
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   255
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   256
image:anImage
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   257
    "set the image"
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   258
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   259
    image := anImage
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   260
!
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   261
175
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   262
string
180
c63c079dea01 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 179
diff changeset
   263
    "return my string part"
c63c079dea01 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 179
diff changeset
   264
175
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   265
    ^ string
258
e46fadff344c added access to string
Claus Gittinger <cg@exept.de>
parents: 180
diff changeset
   266
!
e46fadff344c added access to string
Claus Gittinger <cg@exept.de>
parents: 180
diff changeset
   267
e46fadff344c added access to string
Claus Gittinger <cg@exept.de>
parents: 180
diff changeset
   268
string:aString
e46fadff344c added access to string
Claus Gittinger <cg@exept.de>
parents: 180
diff changeset
   269
    "set the labelString"
e46fadff344c added access to string
Claus Gittinger <cg@exept.de>
parents: 180
diff changeset
   270
e46fadff344c added access to string
Claus Gittinger <cg@exept.de>
parents: 180
diff changeset
   271
    string := aString
e46fadff344c added access to string
Claus Gittinger <cg@exept.de>
parents: 180
diff changeset
   272
e46fadff344c added access to string
Claus Gittinger <cg@exept.de>
parents: 180
diff changeset
   273
    "Created: 12.5.1996 / 20:00:52 / cg"
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   274
! !
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   275
177
5eb92a1ca41f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 176
diff changeset
   276
!LabelAndIcon methodsFor:'conversion'!
5eb92a1ca41f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 176
diff changeset
   277
5eb92a1ca41f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 176
diff changeset
   278
asString
180
c63c079dea01 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 179
diff changeset
   279
    "return my string part"
c63c079dea01 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 179
diff changeset
   280
177
5eb92a1ca41f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 176
diff changeset
   281
    ^ string
5eb92a1ca41f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 176
diff changeset
   282
5eb92a1ca41f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 176
diff changeset
   283
    "Created: 12.5.1996 / 21:26:47 / cg"
5eb92a1ca41f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 176
diff changeset
   284
! !
5eb92a1ca41f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 176
diff changeset
   285
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   286
!LabelAndIcon methodsFor:'displaying'!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   287
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   288
displayOn:aGC x:x y:y opaque:opaque
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   289
    "display the receiver on a GC"
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   290
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   291
    |y1 x1 iconHeight imageHeight stringHeight maxHeight gapY asc|
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   292
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   293
    gapY := (aGC device pixelPerMillimeter x) rounded.
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   294
    asc  := (aGC font on:aGC device) ascent.
180
c63c079dea01 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 179
diff changeset
   295
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   296
    iconHeight   := icon notNil     ifTrue:[icon   height]       ifFalse:[0].
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   297
    imageHeight  := image notNil    ifTrue:[image  height]       ifFalse:[0].
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   298
    stringHeight := string size > 0 ifTrue:[string heightOn:aGC] ifFalse:[0].
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   299
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   300
    maxHeight := ((iconHeight max: imageHeight) + gapY) max: stringHeight.
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   301
    x1 := x.
258
e46fadff344c added access to string
Claus Gittinger <cg@exept.de>
parents: 180
diff changeset
   302
306
f3954479c7e8 handle nil icons
Claus Gittinger <cg@exept.de>
parents: 287
diff changeset
   303
    icon notNil ifTrue:[
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   304
        y1 := y - asc + (maxHeight - iconHeight + 1 // 2).
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   305
        icon := icon onDevice:aGC device.
578
72916ad0a5f3 fixed centering of the image w.r.t. the fontHeight
Claus Gittinger <cg@exept.de>
parents: 423
diff changeset
   306
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   307
        (opaque and:[icon mask isNil]) ifTrue:[aGC displayOpaqueForm:icon x:x1 y:y1]
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   308
                                      ifFalse:[aGC displayForm:icon 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
   309
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   310
        x1 := x1 + icon width + gap
258
e46fadff344c added access to string
Claus Gittinger <cg@exept.de>
parents: 180
diff changeset
   311
    ].
e46fadff344c added access to string
Claus Gittinger <cg@exept.de>
parents: 180
diff changeset
   312
629
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   313
    image notNil ifTrue:[
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   314
        y1 := y - asc + (maxHeight - imageHeight + 1 // 2).
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   315
        image := image onDevice:aGC device.
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   316
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   317
        (opaque and:[image mask isNil]) ifTrue:[aGC displayOpaqueForm:image x:x1 y:y1]
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   318
                                       ifFalse:[aGC displayForm:image x:x1 y:y1].
629
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   319
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   320
        x1 := x1 + image width + gap
629
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   321
    ].
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   322
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   323
    stringHeight ~~ 0 ifTrue:[
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   324
        y1 := y + (maxHeight - stringHeight + 1 // 2).
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   325
        string displayOn:aGC x:x1 y:y1
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   326
    ]    
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   327
! !
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   328
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   329
!LabelAndIcon methodsFor:'initialization'!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   330
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   331
initialize
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   332
    gap := 4
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   333
! !
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   334
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   335
!LabelAndIcon methodsFor:'queries'!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   336
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   337
heightOn:aGC
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   338
    "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
   339
719
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   340
    |iconHeight imageHeight stringHeight oneMillimeter|
682
861e446e3b24 checkin from browser
ca
parents: 629
diff changeset
   341
861e446e3b24 checkin from browser
ca
parents: 629
diff changeset
   342
    oneMillimeter := aGC device pixelPerMillimeter x rounded.
306
f3954479c7e8 handle nil icons
Claus Gittinger <cg@exept.de>
parents: 287
diff changeset
   343
f3954479c7e8 handle nil icons
Claus Gittinger <cg@exept.de>
parents: 287
diff changeset
   344
    icon notNil ifTrue:[
682
861e446e3b24 checkin from browser
ca
parents: 629
diff changeset
   345
        iconHeight := icon height + oneMillimeter
306
f3954479c7e8 handle nil icons
Claus Gittinger <cg@exept.de>
parents: 287
diff changeset
   346
    ] ifFalse:[
f3954479c7e8 handle nil icons
Claus Gittinger <cg@exept.de>
parents: 287
diff changeset
   347
        iconHeight := 0
f3954479c7e8 handle nil icons
Claus Gittinger <cg@exept.de>
parents: 287
diff changeset
   348
    ].
629
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   349
    image notNil ifTrue:[
682
861e446e3b24 checkin from browser
ca
parents: 629
diff changeset
   350
        imageHeight := image height + oneMillimeter
629
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   351
    ] ifFalse:[
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   352
        imageHeight := 0   
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   353
    ].
719
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   354
    string size > 0 ifTrue:[
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   355
        stringHeight := string heightOn:aGC
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   356
    ] ifFalse:[
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   357
        stringHeight := 0   
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   358
    ].
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   359
    ^ ((iconHeight max: imageHeight) max: stringHeight)
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   360
!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   361
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   362
widthOn:aGC
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   363
    "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
   364
719
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   365
    |width|
306
f3954479c7e8 handle nil icons
Claus Gittinger <cg@exept.de>
parents: 287
diff changeset
   366
719
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   367
    width := 0.
306
f3954479c7e8 handle nil icons
Claus Gittinger <cg@exept.de>
parents: 287
diff changeset
   368
    icon notNil ifTrue:[
719
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   369
        width := width + icon width
306
f3954479c7e8 handle nil icons
Claus Gittinger <cg@exept.de>
parents: 287
diff changeset
   370
    ].
629
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   371
    image notNil ifTrue:[
719
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   372
        width := width + gap + image width
629
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   373
    ].
719
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   374
    string size > 0 ifTrue:[
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   375
        width := width + gap + (string widthOn:aGC)
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   376
    ].  
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   377
    ^width
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   378
   
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   379
! !
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   380
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   381
!LabelAndIcon class methodsFor:'documentation'!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   382
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   383
version
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   384
    ^ '$Header: /cvs/stx/stx/libwidg2/LabelAndIcon.st,v 1.20 1998-02-04 17:52:06 tz Exp $'
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   385
! !