DataSetLabel.st
author Claus Gittinger <cg@exept.de>
Tue, 22 Jul 2008 14:49:03 +0200
changeset 3490 f46a3c50dc15
parent 3468 075b137a1e67
child 3553 9387938a3c07
permissions -rw-r--r--
preferredExtent changes & fixes (ubs)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1716
0e31e721d4ab copyrights
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
     1
"
0e31e721d4ab copyrights
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
     2
 COPYRIGHT (c) 1997 by eXept Software AG
0e31e721d4ab copyrights
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
     3
              All Rights Reserved
0e31e721d4ab copyrights
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
     4
0e31e721d4ab copyrights
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
     5
 This software is furnished under a license and may be used
0e31e721d4ab copyrights
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
     6
 only in accordance with the terms of that license and with the
0e31e721d4ab copyrights
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
0e31e721d4ab copyrights
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
     8
 be provided or otherwise made available to, or used by, any
0e31e721d4ab copyrights
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
     9
 other person.  No title to or ownership of the software is
0e31e721d4ab copyrights
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
    10
 hereby transferred.
0e31e721d4ab copyrights
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
    11
"
1818
fe99c5c721e9 category changes
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
    12
"{ Package: 'stx:libwidg2' }"
fe99c5c721e9 category changes
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
    13
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
Object subclass:#DataSetLabel
1487
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
    15
	instanceVariableNames:'label selector argument adjust font fgColor bgColor
1605
3eb7d3e78e08 checkin from browser
ca
parents: 1591
diff changeset
    16
		preferredHeight preferredWidth'
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	classVariableNames:''
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	poolDictionaries:''
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	category:'Views-DataSet'
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
!
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
1716
0e31e721d4ab copyrights
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
    22
!DataSetLabel class methodsFor:'documentation'!
0e31e721d4ab copyrights
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
    23
0e31e721d4ab copyrights
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
    24
copyright
0e31e721d4ab copyrights
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
    25
"
0e31e721d4ab copyrights
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
    26
 COPYRIGHT (c) 1997 by eXept Software AG
0e31e721d4ab copyrights
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
    27
              All Rights Reserved
0e31e721d4ab copyrights
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
    28
0e31e721d4ab copyrights
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
    29
 This software is furnished under a license and may be used
0e31e721d4ab copyrights
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
    30
 only in accordance with the terms of that license and with the
0e31e721d4ab copyrights
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
0e31e721d4ab copyrights
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
    32
 be provided or otherwise made available to, or used by, any
0e31e721d4ab copyrights
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
    33
 other person.  No title to or ownership of the software is
0e31e721d4ab copyrights
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
    34
 hereby transferred.
0e31e721d4ab copyrights
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
    35
"
0e31e721d4ab copyrights
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
    36
0e31e721d4ab copyrights
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
    37
0e31e721d4ab copyrights
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
    38
0e31e721d4ab copyrights
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
    39
0e31e721d4ab copyrights
Claus Gittinger <cg@exept.de>
parents: 1605
diff changeset
    40
! !
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
1818
fe99c5c721e9 category changes
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
    42
!DataSetLabel methodsFor:'accessing-colors'!
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
backgroundColor
1487
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
    45
    "returns the background color or nil
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
    "
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
    ^ bgColor
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
!
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
2699
ffc569afbb18 WOs accessors
werner
parents: 2451
diff changeset
    52
backgroundColor:aColor
ffc569afbb18 WOs accessors
werner
parents: 2451
diff changeset
    53
    "set the background color or nil
ffc569afbb18 WOs accessors
werner
parents: 2451
diff changeset
    54
    "
ffc569afbb18 WOs accessors
werner
parents: 2451
diff changeset
    55
    bgColor := aColor
ffc569afbb18 WOs accessors
werner
parents: 2451
diff changeset
    56
!
ffc569afbb18 WOs accessors
werner
parents: 2451
diff changeset
    57
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
foregroundColor
1487
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
    59
    "returns the foreground color or nil
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
    "
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
    ^ fgColor
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
2699
ffc569afbb18 WOs accessors
werner
parents: 2451
diff changeset
    63
!
ffc569afbb18 WOs accessors
werner
parents: 2451
diff changeset
    64
ffc569afbb18 WOs accessors
werner
parents: 2451
diff changeset
    65
foregroundColor:aColor
ffc569afbb18 WOs accessors
werner
parents: 2451
diff changeset
    66
    "set the foreground color or nil
ffc569afbb18 WOs accessors
werner
parents: 2451
diff changeset
    67
    "
ffc569afbb18 WOs accessors
werner
parents: 2451
diff changeset
    68
    fgColor := aColor
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
! !
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
1818
fe99c5c721e9 category changes
Claus Gittinger <cg@exept.de>
parents: 1716
diff changeset
    71
!DataSetLabel methodsFor:'accessing-dimensions'!
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
1487
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
    73
preferredHeight
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
    74
    "returns my preferred height
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
    "
1487
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
    76
    ^ preferredHeight
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
!
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
1487
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
    79
preferredWidth
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
    80
    "returns my preferred width
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
    "
1487
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
    82
    ^ preferredWidth
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
! !
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
!DataSetLabel methodsFor:'actions'!
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
sendClickMsgTo:aReceiver
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
    "inform the receiver of a button release notification
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
    "
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
    (aReceiver notNil and:[selector notNil]) ifTrue:[
2068
3fcbf2422c5a use new #perform:withOptionalArg
Claus Gittinger <cg@exept.de>
parents: 1818
diff changeset
    91
        aReceiver perform:selector withOptionalArgument:argument
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92
    ]
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    93
! !
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    94
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    95
!DataSetLabel methodsFor:'drawing'!
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    96
1487
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
    97
redrawX:xLeft w:width h:height inset:inset on:aGC
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    98
    "redraw the label; the background is cleared and the paint is set
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    99
    "
2144
29820901d223 shortened label, if it does not fit (i.e. O..)
penk
parents: 2068
diff changeset
   100
    |y0 x y ascent gcFont labelWidth 
2154
cb22be939082 split strings; some refactoring
Claus Gittinger <cg@exept.de>
parents: 2144
diff changeset
   101
     shownLabel prevClip mustUndoClip
3490
f46a3c50dc15 preferredExtent changes & fixes (ubs)
Claus Gittinger <cg@exept.de>
parents: 3468
diff changeset
   102
     netWidth goodLookingVerticalSpacing|
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   103
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   104
    label isNil ifTrue:[ ^ self ].
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   105
1487
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   106
    gcFont := aGC font.
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   107
    font notNil ifTrue:[
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   108
        aGC font:font.
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   109
        ascent := font ascent
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   110
    ] ifFalse:[
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   111
        ascent := gcFont ascent
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   112
    ].
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   113
    y0 := height - preferredHeight // 2.
3490
f46a3c50dc15 preferredExtent changes & fixes (ubs)
Claus Gittinger <cg@exept.de>
parents: 3468
diff changeset
   114
    goodLookingVerticalSpacing := aGC font descent.
f46a3c50dc15 preferredExtent changes & fixes (ubs)
Claus Gittinger <cg@exept.de>
parents: 3468
diff changeset
   115
    y0 := y0 + goodLookingVerticalSpacing.
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   116
2144
29820901d223 shortened label, if it does not fit (i.e. O..)
penk
parents: 2068
diff changeset
   117
    netWidth := width-inset-inset.
29820901d223 shortened label, if it does not fit (i.e. O..)
penk
parents: 2068
diff changeset
   118
1487
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   119
    label do:[:aLabel|
2144
29820901d223 shortened label, if it does not fit (i.e. O..)
penk
parents: 2068
diff changeset
   120
        shownLabel := aLabel.
29820901d223 shortened label, if it does not fit (i.e. O..)
penk
parents: 2068
diff changeset
   121
1588
e6039e46cae2 clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
   122
        mustUndoClip := false.
2144
29820901d223 shortened label, if it does not fit (i.e. O..)
penk
parents: 2068
diff changeset
   123
        labelWidth := shownLabel widthOn:aGC.
29820901d223 shortened label, if it does not fit (i.e. O..)
penk
parents: 2068
diff changeset
   124
        labelWidth > netWidth ifTrue:[
2154
cb22be939082 split strings; some refactoring
Claus Gittinger <cg@exept.de>
parents: 2144
diff changeset
   125
            shownLabel := DataSetColumn shortenedStringFor:aLabel on:aGC maxWidth:netWidth.
cb22be939082 split strings; some refactoring
Claus Gittinger <cg@exept.de>
parents: 2144
diff changeset
   126
            labelWidth := shownLabel widthOn:aGC.
2144
29820901d223 shortened label, if it does not fit (i.e. O..)
penk
parents: 2068
diff changeset
   127
        ].
29820901d223 shortened label, if it does not fit (i.e. O..)
penk
parents: 2068
diff changeset
   128
1487
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   129
        adjust == #left ifTrue:[
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   130
            x := xLeft + inset.
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   131
        ] ifFalse:[
2144
29820901d223 shortened label, if it does not fit (i.e. O..)
penk
parents: 2068
diff changeset
   132
            x := width - labelWidth.
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   133
1487
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   134
            adjust == #right ifTrue:[x := x - inset]
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   135
                            ifFalse:[x := x // 2].
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   136
            x := xLeft + x.
1588
e6039e46cae2 clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
   137
e6039e46cae2 clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
   138
           "/ cg: must clip left, if string is too large
e6039e46cae2 clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
   139
            x < xLeft ifTrue:[
e6039e46cae2 clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
   140
                "/ must clip ...
e6039e46cae2 clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
   141
                prevClip := aGC clippingRectangleOrNil.
e6039e46cae2 clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
   142
                mustUndoClip := true.
1591
6996391ee3ba Avoid obsolete method. (stefan)
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   143
                aGC clippingRectangle:(Rectangle 
1588
e6039e46cae2 clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
   144
                                    left:xLeft top:y0 
e6039e46cae2 clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
   145
                                    width:width height:height).
e6039e46cae2 clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
   146
            ].
1487
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   147
        ].
2443
e88b4123061a changes to allow for Object>>displayOn:x:y: to work correctly
Claus Gittinger <cg@exept.de>
parents: 2291
diff changeset
   148
        "/ y := shownLabel isImageOrForm ifTrue:[y0] ifFalse:[y0 + ascent].
2451
383fdea243d0 use new aspectOn: query
Claus Gittinger <cg@exept.de>
parents: 2443
diff changeset
   149
        "/ y := shownLabel isString ifTrue:[y0 + ascent] ifFalse:[y0].
383fdea243d0 use new aspectOn: query
Claus Gittinger <cg@exept.de>
parents: 2443
diff changeset
   150
        shownLabel displayOn:aGC x:x y:y0 + (shownLabel ascentOn:aGC).
3490
f46a3c50dc15 preferredExtent changes & fixes (ubs)
Claus Gittinger <cg@exept.de>
parents: 3468
diff changeset
   151
        y0 := y0 + (shownLabel heightOn:aGC) + goodLookingVerticalSpacing.
1588
e6039e46cae2 clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
   152
e6039e46cae2 clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
   153
        mustUndoClip == true ifTrue:[
1591
6996391ee3ba Avoid obsolete method. (stefan)
Claus Gittinger <cg@exept.de>
parents: 1588
diff changeset
   154
            aGC clippingRectangle:prevClip
1588
e6039e46cae2 clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
   155
        ].
1487
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   156
    ].
2451
383fdea243d0 use new aspectOn: query
Claus Gittinger <cg@exept.de>
parents: 2443
diff changeset
   157
    font notNil ifTrue:[
383fdea243d0 use new aspectOn: query
Claus Gittinger <cg@exept.de>
parents: 2443
diff changeset
   158
        aGC font:gcFont     "/ restore font
383fdea243d0 use new aspectOn: query
Claus Gittinger <cg@exept.de>
parents: 2443
diff changeset
   159
    ].       
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
! !
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
!DataSetLabel methodsFor:'instance creation'!
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
1487
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   164
description:aDescription builder:aBuilder on:aGC
3490
f46a3c50dc15 preferredExtent changes & fixes (ubs)
Claus Gittinger <cg@exept.de>
parents: 3468
diff changeset
   165
    |device gcFont verticalSpace|
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
1605
3eb7d3e78e08 checkin from browser
ca
parents: 1591
diff changeset
   167
    label           := self resolveLabelFromDescription:aDescription withBuilder:aBuilder.
3eb7d3e78e08 checkin from browser
ca
parents: 1591
diff changeset
   168
    selector        := aDescription  labelActionSelector.
3eb7d3e78e08 checkin from browser
ca
parents: 1591
diff changeset
   169
    argument        := (aDescription labelActionArgument) ? label.
3eb7d3e78e08 checkin from browser
ca
parents: 1591
diff changeset
   170
    adjust          := (aDescription labelAlignment) ? #left.
3eb7d3e78e08 checkin from browser
ca
parents: 1591
diff changeset
   171
    device          := aGC device.
3eb7d3e78e08 checkin from browser
ca
parents: 1591
diff changeset
   172
    fgColor         := aDescription labelForegroundColor.
3eb7d3e78e08 checkin from browser
ca
parents: 1591
diff changeset
   173
    bgColor         := aDescription labelBackgroundColor.
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
1480
51dd0cc6ea11 #on: -> #onDevice:
Claus Gittinger <cg@exept.de>
parents: 1269
diff changeset
   175
    fgColor notNil ifTrue:[ fgColor := fgColor onDevice:device ].
51dd0cc6ea11 #on: -> #onDevice:
Claus Gittinger <cg@exept.de>
parents: 1269
diff changeset
   176
    bgColor notNil ifTrue:[ bgColor := bgColor onDevice:device ].
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   177
1487
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   178
    preferredHeight := preferredWidth := 0.
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   179
3490
f46a3c50dc15 preferredExtent changes & fixes (ubs)
Claus Gittinger <cg@exept.de>
parents: 3468
diff changeset
   180
    (label isEmptyOrNil) ifTrue:[
1487
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   181
        label := nil.
3490
f46a3c50dc15 preferredExtent changes & fixes (ubs)
Claus Gittinger <cg@exept.de>
parents: 3468
diff changeset
   182
        ^ self
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   183
    ].
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   184
1487
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   185
    (font := aDescription labelFont) notNil ifTrue:[
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   186
        (gcFont := aGC font) = font ifTrue:[
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   187
            font := nil
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   188
        ] ifFalse:[
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   189
            aGC font:(font := font onDevice:device)
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   190
        ]
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   191
    ].
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
3490
f46a3c50dc15 preferredExtent changes & fixes (ubs)
Claus Gittinger <cg@exept.de>
parents: 3468
diff changeset
   193
    label isString ifTrue:[
f46a3c50dc15 preferredExtent changes & fixes (ubs)
Claus Gittinger <cg@exept.de>
parents: 3468
diff changeset
   194
        label := Array with:label.
f46a3c50dc15 preferredExtent changes & fixes (ubs)
Claus Gittinger <cg@exept.de>
parents: 3468
diff changeset
   195
    ] ifFalse:[
f46a3c50dc15 preferredExtent changes & fixes (ubs)
Claus Gittinger <cg@exept.de>
parents: 3468
diff changeset
   196
        (label isSequenceable not) ifTrue:[
f46a3c50dc15 preferredExtent changes & fixes (ubs)
Claus Gittinger <cg@exept.de>
parents: 3468
diff changeset
   197
            label := Array with:label.
f46a3c50dc15 preferredExtent changes & fixes (ubs)
Claus Gittinger <cg@exept.de>
parents: 3468
diff changeset
   198
        ]
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   199
    ].
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   200
3490
f46a3c50dc15 preferredExtent changes & fixes (ubs)
Claus Gittinger <cg@exept.de>
parents: 3468
diff changeset
   201
    verticalSpace := aGC font descent. "/ goodLookingVerticalSpacing
f46a3c50dc15 preferredExtent changes & fixes (ubs)
Claus Gittinger <cg@exept.de>
parents: 3468
diff changeset
   202
    label := label 
f46a3c50dc15 preferredExtent changes & fixes (ubs)
Claus Gittinger <cg@exept.de>
parents: 3468
diff changeset
   203
                collect:[:el|
f46a3c50dc15 preferredExtent changes & fixes (ubs)
Claus Gittinger <cg@exept.de>
parents: 3468
diff changeset
   204
                    |lbl|
f46a3c50dc15 preferredExtent changes & fixes (ubs)
Claus Gittinger <cg@exept.de>
parents: 3468
diff changeset
   205
f46a3c50dc15 preferredExtent changes & fixes (ubs)
Claus Gittinger <cg@exept.de>
parents: 3468
diff changeset
   206
                    lbl := self label:el on:device.
f46a3c50dc15 preferredExtent changes & fixes (ubs)
Claus Gittinger <cg@exept.de>
parents: 3468
diff changeset
   207
                    preferredWidth  := (lbl widthOn:aGC) max:preferredWidth.
f46a3c50dc15 preferredExtent changes & fixes (ubs)
Claus Gittinger <cg@exept.de>
parents: 3468
diff changeset
   208
                    preferredHeight := preferredHeight + verticalSpace + (lbl heightOn:aGC) + verticalSpace.
f46a3c50dc15 preferredExtent changes & fixes (ubs)
Claus Gittinger <cg@exept.de>
parents: 3468
diff changeset
   209
                    lbl
f46a3c50dc15 preferredExtent changes & fixes (ubs)
Claus Gittinger <cg@exept.de>
parents: 3468
diff changeset
   210
                ].
1487
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   211
    font notNil ifTrue:[aGC font:gcFont].       "/ restore font
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   212
! !
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   213
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
!DataSetLabel methodsFor:'private'!
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   215
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   216
label:aLabel on:aDevice
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   217
    "returns registered label on a device
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   218
    "
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   219
    |lbl img|
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   220
1487
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   221
    aLabel isNil ifTrue:[^ ''].
fd003e2156cc bug fixes + rework
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   222
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   223
    aLabel isString ifFalse:[
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   224
        aLabel isImageOrForm ifTrue:[
2291
c5e8140dd6ba #on: -> #onDevice:
Claus Gittinger <cg@exept.de>
parents: 2154
diff changeset
   225
            aLabel device ~~ aDevice ifTrue:[
c5e8140dd6ba #on: -> #onDevice:
Claus Gittinger <cg@exept.de>
parents: 2154
diff changeset
   226
                lbl := aLabel copy onDevice:aDevice
c5e8140dd6ba #on: -> #onDevice:
Claus Gittinger <cg@exept.de>
parents: 2154
diff changeset
   227
            ] ifFalse:[
c5e8140dd6ba #on: -> #onDevice:
Claus Gittinger <cg@exept.de>
parents: 2154
diff changeset
   228
                lbl := aLabel
c5e8140dd6ba #on: -> #onDevice:
Claus Gittinger <cg@exept.de>
parents: 2154
diff changeset
   229
            ].
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
            lbl isImage ifTrue:[
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   231
                lbl clearMaskedPixels
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   232
            ].
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   233
            ^ lbl
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   234
        ].
1588
e6039e46cae2 clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
   235
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   236
        aLabel class == LabelAndIcon ifTrue:[
2291
c5e8140dd6ba #on: -> #onDevice:
Claus Gittinger <cg@exept.de>
parents: 2154
diff changeset
   237
            lbl := aLabel onDevice:aDevice.
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   238
            (img := lbl image) isImage ifTrue:[img clearMaskedPixels].
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   239
            (img := lbl icon)  isImage ifTrue:[img clearMaskedPixels].
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   240
            ^ lbl
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   241
        ]
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   242
    ].
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   243
    ^ aLabel
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   244
!
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   245
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   246
resolveLabelFromDescription:aDescription withBuilder:aBuilder
3468
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   247
    |rawLabel appl resources lbl|
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   248
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   249
    aBuilder isNil ifTrue:[
3468
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   250
        rawLabel := aDescription rawLabel.
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   251
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   252
        rawLabel isString ifTrue:[
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   253
            rawLabel isEmpty ifTrue:[^ nil ].
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   254
            lbl := rawLabel asStringCollection.
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   255
            lbl size > 1 ifTrue:[^ lbl ].
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   256
        ].
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   257
        ^ rawLabel        
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   258
    ].
3468
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   259
    rawLabel := aDescription label.
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   260
    rawLabel isNil ifTrue:[^ nil ].
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   261
2779
e5b0570c2c32 also translate multi-line labels
Claus Gittinger <cg@exept.de>
parents: 2699
diff changeset
   262
    aBuilder isEditing ifFalse:[
e5b0570c2c32 also translate multi-line labels
Claus Gittinger <cg@exept.de>
parents: 2699
diff changeset
   263
        appl := aBuilder application.
3468
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   264
        appl notNil ifTrue:[ resources := appl resources ].
2779
e5b0570c2c32 also translate multi-line labels
Claus Gittinger <cg@exept.de>
parents: 2699
diff changeset
   265
    ].
e5b0570c2c32 also translate multi-line labels
Claus Gittinger <cg@exept.de>
parents: 2699
diff changeset
   266
3468
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   267
    rawLabel isString ifTrue:[
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   268
        aDescription labelIsImage ifTrue:[
3468
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   269
            (aBuilder isEditing or:[(rawLabel := aBuilder labelFor:(rawLabel asSymbol)) isNil]) ifTrue:[
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   270
                ^ aDescription class defaultIcon
3468
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   271
            ]
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   272
        ] ifFalse:[
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   273
            aDescription translateLabel == true ifTrue:[
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   274
                lbl := aBuilder aspectAt:(rawLabel asSymbol).
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   275
3468
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   276
                (lbl isNil and:[resources notNil]) ifTrue:[
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   277
                    lbl := resources string:rawLabel default:nil.
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   278
                ].
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   279
                lbl notNil ifTrue:[ rawLabel := lbl ].
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   280
            ].
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   281
        ].
3468
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   282
    ] ifFalse:[
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   283
        rawLabel isSequenceable ifFalse:[^ rawLabel].
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   284
        rawLabel isEmptyOrNil ifTrue:[^ nil ].
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   285
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   286
        resources notNil ifTrue:[
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   287
            lbl := resources string:rawLabel default:nil.
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   288
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   289
            lbl notNil ifTrue:[
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   290
                rawLabel := lbl.
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   291
            ] ifFalse:[
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   292
                lbl := resources array:rawLabel.
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   293
                lbl notEmptyOrNil ifTrue:[
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   294
                    lbl size == 1 ifTrue:[ rawLabel := lbl first ]
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   295
                                 ifFalse:[ rawLabel := lbl ].
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   296
                ].
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   297
            ].
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   298
        ].
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   299
    ].
3468
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   300
    rawLabel isString ifTrue:[
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   301
        rawLabel isEmpty ifTrue:[ ^ nil ].
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   302
        lbl := rawLabel asStringCollection.
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   303
        lbl size > 1 ifTrue:[^ lbl ].
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   304
    ].
075b137a1e67 support carriage return in title labels
ca
parents: 2932
diff changeset
   305
    ^ rawLabel
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   306
! !
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   307
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   308
!DataSetLabel methodsFor:'queries'!
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   309
1605
3eb7d3e78e08 checkin from browser
ca
parents: 1591
diff changeset
   310
hasSeparator
3eb7d3e78e08 checkin from browser
ca
parents: 1591
diff changeset
   311
    |l|
3eb7d3e78e08 checkin from browser
ca
parents: 1591
diff changeset
   312
3eb7d3e78e08 checkin from browser
ca
parents: 1591
diff changeset
   313
    label size == 1 ifTrue:[
3eb7d3e78e08 checkin from browser
ca
parents: 1591
diff changeset
   314
"/        ^ (label at:1) ~= 'Alarm'
3eb7d3e78e08 checkin from browser
ca
parents: 1591
diff changeset
   315
        ^ (label at:1) ~= 'Area'
3eb7d3e78e08 checkin from browser
ca
parents: 1591
diff changeset
   316
    ].
3eb7d3e78e08 checkin from browser
ca
parents: 1591
diff changeset
   317
    ^ true
3eb7d3e78e08 checkin from browser
ca
parents: 1591
diff changeset
   318
!
3eb7d3e78e08 checkin from browser
ca
parents: 1591
diff changeset
   319
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   320
isSelectable
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   321
    "returns true if the item is selectable; a valid selector
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   322
     to notify the receiver for a release button event exists
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   323
    "
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   324
    ^ selector notNil
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   325
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   326
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   327
! !
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   328
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   329
!DataSetLabel class methodsFor:'documentation'!
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   330
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   331
version
3490
f46a3c50dc15 preferredExtent changes & fixes (ubs)
Claus Gittinger <cg@exept.de>
parents: 3468
diff changeset
   332
    ^ '$Header: /cvs/stx/stx/libwidg2/DataSetLabel.st,v 1.21 2008-07-22 12:49:03 cg Exp $'
1150
d0530983c4f6 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   333
! !