LabelAndIcon.st
author Claus Gittinger <cg@exept.de>
Mon, 21 Aug 2000 23:54:15 +0200
changeset 1817 e639d2a9d605
parent 1814 a7697ca7f34f
child 1860 b4c0e45ad336
permissions -rw-r--r--
tuned compare
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
1814
a7697ca7f34f added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents: 1604
diff changeset
    14
"{ Package: 'stx:libwidg2' }"
a7697ca7f34f added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents: 1604
diff changeset
    15
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
ListEntry subclass:#LabelAndIcon
981
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
    17
	instanceVariableNames:'icon gap string image offset'
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	classVariableNames:''
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	poolDictionaries:''
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	category:'Views-Support'
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!LabelAndIcon class methodsFor:'documentation'!
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
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
"
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
 COPYRIGHT (c) 1996 by Claus Gittinger
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
              All Rights Reserved
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
 This software is furnished under a license and may be used
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
 only in accordance with the terms of that license and with the
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
 be provided or otherwise made available to, or used by, any
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
 other person.  No title to or ownership of the software is
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 hereby transferred.
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
!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
documentation
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
"
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
    an icon and a string, side by side.
178
ba4f86aaa203 example
Claus Gittinger <cg@exept.de>
parents: 177
diff changeset
    43
    Usable as list entries in a listView (a fileList), as
179
fccdac863996 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
    44
    popUpMenuItems or as Label/Button image.
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
    This is an example class - currently not used by the system.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
179
fccdac863996 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
    48
    Notice:
fccdac863996 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
    49
        This is different from ST-80's LabelAndIcon class, which
fccdac863996 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
    50
        inherits from Label. Therefore, things may change in the future.
fccdac863996 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 178
diff changeset
    51
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
    [author:]
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
        Claus Gittinger
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
    [see also:]
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
        ListEntry Text String Icon
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
        ListView SelectionInListView
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
"
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
examples
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
"
175
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
    63
  in a listView:
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
                                                                        [exBegin]
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
    |top slv wrapper l fileImage dirImage|
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
    fileImage := Image 
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
                   width:16 
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
                   height:16
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
                   depth:1
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
                   fromArray:#[2r00000000 2r00000000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
                               2r00000000 2r00000000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
                               2r00011111 2r11100000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
                               2r00010000 2r00100000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
                               2r00010000 2r00011000
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
                               2r00010000 2r00001000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
                               2r00010000 2r00001000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
                               2r00011111 2r11111000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
                               2r00000000 2r00000000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
                               2r00000000 2r00000000].
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
    fileImage photometric:#whiteIs0.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
    dirImage := Image 
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
                   width:16 
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
                   height:16
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
                   depth:1
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
                   fromArray:#[2r00000000 2r00000000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
                               2r00000000 2r00000000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
                               2r00000000 2r00000000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
                               2r01111111 2r11110000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    97
                               2r01000000 2r00001000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
                               2r01000000 2r00000100
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
                               2r01000000 2r00000010
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
                               2r01000000 2r00000010
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
                               2r01111111 2r11111110
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
                               2r00000000 2r00000000
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   108
                               2r00000000 2r00000000].
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   109
    dirImage photometric:#whiteIs0.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   110
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   111
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   112
    l := OrderedCollection new.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   113
    Filename currentDirectory directoryContents do:[:s |
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   114
        s asFilename isDirectory ifTrue:[
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   115
            l add:(LabelAndIcon icon:dirImage string:s)
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
        ] ifFalse:[
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   117
            l add:(LabelAndIcon icon:fileImage string:s)
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   118
        ]
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   119
    ].
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   120
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   121
    slv := SelectionInListView new.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   122
    slv list:l.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   123
    wrapper := HVScrollableView forView:slv miniScrollerH:true.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   124
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   125
    top := StandardSystemView extent:150@200.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   126
    top add:wrapper in:(0.0@0.0 corner:1.0@1.0).
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   127
    top open.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   128
                                                                        [exEnd]
175
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   129
  in a selectionInListView:
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   130
                                                                        [exBegin]
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   131
    |top slv wrapper l fileImage dirImage|
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   132
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
    dirImage := Image fromFile:'DirObj.xbm'.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   134
    fileImage := Image fromFile:'FileObj.xbm'.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   135
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   136
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   137
    l := OrderedCollection new.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   138
    Filename currentDirectory directoryContents do:[:s |
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   139
        s asFilename isDirectory ifTrue:[
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   140
            l add:(LabelAndIcon icon:dirImage string:s)
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   141
        ] ifFalse:[
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   142
            l add:(LabelAndIcon icon:fileImage string:s)
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
        ]
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
    ].
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
    slv := SelectionInListView new.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
    slv list:l.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
    wrapper := HVScrollableView forView:slv miniScrollerH:true.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
    top := StandardSystemView extent:150@200.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
    top add:wrapper in:(0.0@0.0 corner:1.0@1.0).
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
    top open.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
                                                                        [exEnd]
175
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   154
  in a menu:
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   155
                                                                        [exBegin]
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   156
    |top l fileImage dirImage|
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   157
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   158
    dirImage := Image fromFile:'DirObj.xbm'.
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   159
    fileImage := Image fromFile:'FileObj.xbm'.
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   160
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   161
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   162
    l := OrderedCollection new.
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   163
    l add:(LabelAndIcon icon:dirImage string:'create directory').
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   164
    l add:(LabelAndIcon icon:fileImage string:'create file').
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 := View new.
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 middleButtonMenu:(PopUpMenu labels:l
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   169
                        selectors:#(foo bar)).
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   170
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   171
    top open.
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   172
                                                                        [exEnd]
178
ba4f86aaa203 example
Claus Gittinger <cg@exept.de>
parents: 177
diff changeset
   173
  in a button/label:
ba4f86aaa203 example
Claus Gittinger <cg@exept.de>
parents: 177
diff changeset
   174
                                                                        [exBegin]
ba4f86aaa203 example
Claus Gittinger <cg@exept.de>
parents: 177
diff changeset
   175
    |top l image|
ba4f86aaa203 example
Claus Gittinger <cg@exept.de>
parents: 177
diff changeset
   176
ba4f86aaa203 example
Claus Gittinger <cg@exept.de>
parents: 177
diff changeset
   177
    image := Image fromFile:'DirObj.xbm'.
ba4f86aaa203 example
Claus Gittinger <cg@exept.de>
parents: 177
diff changeset
   178
    l := (LabelAndIcon icon:image string:'directory').
ba4f86aaa203 example
Claus Gittinger <cg@exept.de>
parents: 177
diff changeset
   179
ba4f86aaa203 example
Claus Gittinger <cg@exept.de>
parents: 177
diff changeset
   180
    top := Button label:l.
ba4f86aaa203 example
Claus Gittinger <cg@exept.de>
parents: 177
diff changeset
   181
    top open.
ba4f86aaa203 example
Claus Gittinger <cg@exept.de>
parents: 177
diff changeset
   182
                                                                        [exEnd]
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
"
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   184
! !
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   185
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   186
!LabelAndIcon class methodsFor:'instance creation'!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   187
629
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   188
form:aForm image:anImage
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   189
629
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   190
    ^self new form:aForm image:anImage string:''
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   191
!
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   192
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   193
form:aForm image:anImage string:aString
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   194
629
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   195
    ^self new form:aForm image:anImage string:aString
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   196
!
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   197
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
icon:anIcon string:aString
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   199
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
    ^ self new icon:anIcon string:aString
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   201
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   202
    "Created: 12.5.1996 / 20:00:58 / cg"
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   203
!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   204
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   205
new
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   206
    ^ self basicNew initialize
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   207
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
    "Created: 12.5.1996 / 20:00:58 / cg"
986
ed6b89c43416 added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 981
diff changeset
   209
!
ed6b89c43416 added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 981
diff changeset
   210
ed6b89c43416 added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 981
diff changeset
   211
string:aString
ed6b89c43416 added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 981
diff changeset
   212
ed6b89c43416 added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 981
diff changeset
   213
    ^ self new icon:nil string:aString
ed6b89c43416 added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 981
diff changeset
   214
ed6b89c43416 added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 981
diff changeset
   215
    "Created: / 21.6.1998 / 04:57:28 / cg"
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
! !
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
!LabelAndIcon methodsFor:'accessing'!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   219
986
ed6b89c43416 added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 981
diff changeset
   220
beCheckMark
ed6b89c43416 added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 981
diff changeset
   221
    self icon:(CheckToggle checkFormOn:Screen current)
ed6b89c43416 added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 981
diff changeset
   222
ed6b89c43416 added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 981
diff changeset
   223
    "Created: / 21.6.1998 / 05:01:01 / cg"
ed6b89c43416 added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 981
diff changeset
   224
    "Modified: / 21.6.1998 / 05:03:23 / cg"
ed6b89c43416 added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 981
diff changeset
   225
!
ed6b89c43416 added #beCheckMark for ST80 compatibility
Claus Gittinger <cg@exept.de>
parents: 981
diff changeset
   226
629
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   227
form:aForm image:anImage string:aString
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   228
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   229
    icon := aForm.
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   230
    image:= anImage.
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   231
    string := aString. 
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   232
!
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   233
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   234
gap:pixels
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   235
    "set the spacing between the icon and the labelString.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   236
     The default is 4."
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   237
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
    gap := pixels.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   239
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   240
    "Created: 12.5.1996 / 20:00:52 / cg"
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   241
!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
286
89cced571c0f add accessing method to get the icon
ca
parents: 258
diff changeset
   243
icon
89cced571c0f add accessing method to get the icon
ca
parents: 258
diff changeset
   244
    "return my icon part"
89cced571c0f add accessing method to get the icon
ca
parents: 258
diff changeset
   245
89cced571c0f add accessing method to get the icon
ca
parents: 258
diff changeset
   246
    ^ icon
89cced571c0f add accessing method to get the icon
ca
parents: 258
diff changeset
   247
!
89cced571c0f add accessing method to get the icon
ca
parents: 258
diff changeset
   248
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   249
icon:anIcon
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   250
    "set the icon image"
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   251
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   252
    icon := anIcon.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   253
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   254
    "Created: 12.5.1996 / 20:00:52 / cg"
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   255
!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   256
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   257
icon:anIcon string:aString
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   258
    "set both iconImage and the labelString"
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   259
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   260
    icon := anIcon.
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   261
    string := aString
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   262
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   263
    "Created: 12.5.1996 / 20:00:52 / cg"
175
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   264
!
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   265
719
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   266
image
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   267
    "return my image"
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   268
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   269
    ^ image
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   270
!
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   271
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   272
image:anImage
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   273
    "set the image"
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   274
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   275
    image := anImage
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   276
!
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   277
981
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   278
offset:pixels
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   279
    "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
   280
     The default is 0."
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   281
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   282
    offset := pixels.
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   283
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   284
    "Created: / 21.6.1998 / 03:11:03 / cg"
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   285
!
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   286
175
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   287
string
180
c63c079dea01 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 179
diff changeset
   288
    "return my string part"
c63c079dea01 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 179
diff changeset
   289
175
44a363de85f5 examples
Claus Gittinger <cg@exept.de>
parents: 172
diff changeset
   290
    ^ string
258
e46fadff344c added access to string
Claus Gittinger <cg@exept.de>
parents: 180
diff changeset
   291
!
e46fadff344c added access to string
Claus Gittinger <cg@exept.de>
parents: 180
diff changeset
   292
e46fadff344c added access to string
Claus Gittinger <cg@exept.de>
parents: 180
diff changeset
   293
string:aString
e46fadff344c added access to string
Claus Gittinger <cg@exept.de>
parents: 180
diff changeset
   294
    "set the labelString"
e46fadff344c added access to string
Claus Gittinger <cg@exept.de>
parents: 180
diff changeset
   295
e46fadff344c added access to string
Claus Gittinger <cg@exept.de>
parents: 180
diff changeset
   296
    string := aString
e46fadff344c added access to string
Claus Gittinger <cg@exept.de>
parents: 180
diff changeset
   297
e46fadff344c added access to string
Claus Gittinger <cg@exept.de>
parents: 180
diff changeset
   298
    "Created: 12.5.1996 / 20:00:52 / cg"
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   299
! !
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   300
1814
a7697ca7f34f added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents: 1604
diff changeset
   301
!LabelAndIcon methodsFor:'comparing'!
a7697ca7f34f added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents: 1604
diff changeset
   302
a7697ca7f34f added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents: 1604
diff changeset
   303
sameStringAndEmphasisAs:someStringOrLabelAndIcon
1817
e639d2a9d605 tuned compare
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   304
    someStringOrLabelAndIcon class == self class ifTrue:[
e639d2a9d605 tuned compare
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   305
        icon = someStringOrLabelAndIcon icon ifFalse:[^ false].
e639d2a9d605 tuned compare
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   306
        image = someStringOrLabelAndIcon image ifFalse:[^ false].
e639d2a9d605 tuned compare
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   307
        (string sameStringAndEmphasisAs:someStringOrLabelAndIcon string) ifFalse:[ ^ false].
e639d2a9d605 tuned compare
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   308
        ^ true.        
e639d2a9d605 tuned compare
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   309
    ].
e639d2a9d605 tuned compare
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   310
1814
a7697ca7f34f added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents: 1604
diff changeset
   311
    (string sameStringAndEmphasisAs:someStringOrLabelAndIcon) ifFalse:[ ^ false].
a7697ca7f34f added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents: 1604
diff changeset
   312
    (icon isNil and:[image isNil]) ifTrue:[^ true].
1817
e639d2a9d605 tuned compare
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   313
    ^ false
1814
a7697ca7f34f added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents: 1604
diff changeset
   314
! !
a7697ca7f34f added sameStringAndEmphasisAs
Claus Gittinger <cg@exept.de>
parents: 1604
diff changeset
   315
177
5eb92a1ca41f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 176
diff changeset
   316
!LabelAndIcon methodsFor:'conversion'!
5eb92a1ca41f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 176
diff changeset
   317
5eb92a1ca41f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 176
diff changeset
   318
asString
180
c63c079dea01 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 179
diff changeset
   319
    "return my string part"
c63c079dea01 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 179
diff changeset
   320
177
5eb92a1ca41f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 176
diff changeset
   321
    ^ string
5eb92a1ca41f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 176
diff changeset
   322
5eb92a1ca41f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 176
diff changeset
   323
    "Created: 12.5.1996 / 21:26:47 / cg"
5eb92a1ca41f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 176
diff changeset
   324
! !
5eb92a1ca41f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 176
diff changeset
   325
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   326
!LabelAndIcon methodsFor:'displaying'!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   327
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   328
displayOn:aGC x:x y:y opaque:opaque
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   329
    "display the receiver on a GC"
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   330
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   331
    |y1 x1 iconHeight imageHeight stringHeight maxHeight gapY asc|
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   332
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   333
    gapY := (aGC device pixelPerMillimeter x) rounded.
1479
8511f61fe8fe #on: -> #onDevice:
Claus Gittinger <cg@exept.de>
parents: 986
diff changeset
   334
    asc  := (aGC font onDevice:aGC device) ascent.
180
c63c079dea01 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 179
diff changeset
   335
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   336
    iconHeight   := icon notNil     ifTrue:[icon   height]       ifFalse:[0].
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   337
    imageHeight  := image notNil    ifTrue:[image  height]       ifFalse:[0].
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   338
    stringHeight := string size > 0 ifTrue:[string heightOn:aGC] ifFalse:[0].
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   339
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   340
    maxHeight := ((iconHeight max: imageHeight) + gapY) max: stringHeight.
981
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   341
    x1 := x + offset.
258
e46fadff344c added access to string
Claus Gittinger <cg@exept.de>
parents: 180
diff changeset
   342
306
f3954479c7e8 handle nil icons
Claus Gittinger <cg@exept.de>
parents: 287
diff changeset
   343
    icon notNil ifTrue:[
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   344
        y1 := y - asc + (maxHeight - iconHeight + 1 // 2).
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   345
        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
   346
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   347
        (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
   348
                                      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
   349
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   350
        x1 := x1 + icon width + gap
258
e46fadff344c added access to string
Claus Gittinger <cg@exept.de>
parents: 180
diff changeset
   351
    ].
e46fadff344c added access to string
Claus Gittinger <cg@exept.de>
parents: 180
diff changeset
   352
629
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   353
    image notNil ifTrue:[
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   354
        y1 := y - asc + (maxHeight - imageHeight + 1 // 2).
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   355
        image := image onDevice:aGC device.
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   356
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   357
        (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
   358
                                       ifFalse:[aGC displayForm:image x:x1 y:y1].
629
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   359
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   360
        x1 := x1 + image width + gap
629
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   361
    ].
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   362
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   363
    stringHeight ~~ 0 ifTrue:[
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   364
        y1 := y + (maxHeight - stringHeight + 1 // 2).
981
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   365
        string displayOn:aGC x:x1 y:y1 opaque:opaque
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   366
    ]
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   367
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   368
    "Modified: / 21.6.1998 / 03:52:12 / cg"
810
847d7f52a2fd new methods:
ca
parents: 726
diff changeset
   369
!
847d7f52a2fd new methods:
ca
parents: 726
diff changeset
   370
847d7f52a2fd new methods:
ca
parents: 726
diff changeset
   371
on:aDevice
847d7f52a2fd new methods:
ca
parents: 726
diff changeset
   372
    "return a new image on a device
847d7f52a2fd new methods:
ca
parents: 726
diff changeset
   373
    "
1604
2c15dd8fb3cf ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   374
    ^ self onDevice:aDevice
810
847d7f52a2fd new methods:
ca
parents: 726
diff changeset
   375
847d7f52a2fd new methods:
ca
parents: 726
diff changeset
   376
!
847d7f52a2fd new methods:
ca
parents: 726
diff changeset
   377
847d7f52a2fd new methods:
ca
parents: 726
diff changeset
   378
onDevice:aDevice
847d7f52a2fd new methods:
ca
parents: 726
diff changeset
   379
    "return a new image on a device
847d7f52a2fd new methods:
ca
parents: 726
diff changeset
   380
    "
1604
2c15dd8fb3cf ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   381
    |form img|
2c15dd8fb3cf ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   382
2c15dd8fb3cf ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   383
    aDevice isNil ifTrue:[^ self].
2c15dd8fb3cf ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   384
    icon  notNil ifTrue:[form := icon  onDevice:aDevice].
2c15dd8fb3cf ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   385
    image notNil ifTrue:[img  := image onDevice:aDevice].
2c15dd8fb3cf ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   386
2c15dd8fb3cf ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   387
    ^ LabelAndIcon form:form image:img string:string
2c15dd8fb3cf ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   388
2c15dd8fb3cf ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   389
2c15dd8fb3cf ignore nil device in #onDevice:
Claus Gittinger <cg@exept.de>
parents: 1479
diff changeset
   390
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   391
! !
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   392
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   393
!LabelAndIcon methodsFor:'initialization'!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   394
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   395
initialize
981
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   396
    gap := 4.
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   397
    offset := 0.
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   398
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   399
    "Modified: / 21.6.1998 / 03:10:19 / cg"
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   400
! !
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   401
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   402
!LabelAndIcon methodsFor:'queries'!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   403
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   404
heightOn:aGC
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   405
    "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
   406
719
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   407
    |iconHeight imageHeight stringHeight oneMillimeter|
682
861e446e3b24 checkin from browser
ca
parents: 629
diff changeset
   408
861e446e3b24 checkin from browser
ca
parents: 629
diff changeset
   409
    oneMillimeter := aGC device pixelPerMillimeter x rounded.
306
f3954479c7e8 handle nil icons
Claus Gittinger <cg@exept.de>
parents: 287
diff changeset
   410
f3954479c7e8 handle nil icons
Claus Gittinger <cg@exept.de>
parents: 287
diff changeset
   411
    icon notNil ifTrue:[
682
861e446e3b24 checkin from browser
ca
parents: 629
diff changeset
   412
        iconHeight := icon height + oneMillimeter
306
f3954479c7e8 handle nil icons
Claus Gittinger <cg@exept.de>
parents: 287
diff changeset
   413
    ] ifFalse:[
f3954479c7e8 handle nil icons
Claus Gittinger <cg@exept.de>
parents: 287
diff changeset
   414
        iconHeight := 0
f3954479c7e8 handle nil icons
Claus Gittinger <cg@exept.de>
parents: 287
diff changeset
   415
    ].
629
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   416
    image notNil ifTrue:[
682
861e446e3b24 checkin from browser
ca
parents: 629
diff changeset
   417
        imageHeight := image height + oneMillimeter
629
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   418
    ] ifFalse:[
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   419
        imageHeight := 0   
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   420
    ].
719
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   421
    string size > 0 ifTrue:[
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   422
        stringHeight := string heightOn:aGC
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   423
    ] ifFalse:[
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   424
        stringHeight := 0   
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   425
    ].
726
4b3a40124f6d center label, icon and image in the display routine
tz
parents: 719
diff changeset
   426
    ^ ((iconHeight max: imageHeight) max: stringHeight)
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   427
!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   428
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   429
widthOn:aGC
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   430
    "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
   431
719
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   432
    |width|
306
f3954479c7e8 handle nil icons
Claus Gittinger <cg@exept.de>
parents: 287
diff changeset
   433
981
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   434
    width := offset.
306
f3954479c7e8 handle nil icons
Claus Gittinger <cg@exept.de>
parents: 287
diff changeset
   435
    icon notNil ifTrue:[
719
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   436
        width := width + icon width
306
f3954479c7e8 handle nil icons
Claus Gittinger <cg@exept.de>
parents: 287
diff changeset
   437
    ].
629
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   438
    image notNil ifTrue:[
719
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   439
        width := width + gap + image width
629
4a2d83659f66 now with image support (-> menu builder)
tz
parents: 588
diff changeset
   440
    ].
719
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   441
    string size > 0 ifTrue:[
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   442
        width := width + gap + (string widthOn:aGC)
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   443
    ].  
3a833ca1c54a better #widthOn: method
tz
parents: 682
diff changeset
   444
    ^width
981
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   445
b7558ca52e20 added an optional left-offset
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   446
    "Modified: / 21.6.1998 / 03:11:14 / cg"
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   447
! !
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   448
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   449
!LabelAndIcon class methodsFor:'documentation'!
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   450
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   451
version
1817
e639d2a9d605 tuned compare
Claus Gittinger <cg@exept.de>
parents: 1814
diff changeset
   452
    ^ '$Header: /cvs/stx/stx/libwidg2/LabelAndIcon.st,v 1.27 2000-08-21 21:54:15 cg Exp $'
172
c30e1ff9f9dd intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   453
! !