author | Claus Gittinger <cg@exept.de> |
Mon, 09 Mar 2020 14:19:10 +0100 | |
changeset 6238 | 1f70ed3090a4 |
parent 6115 | 48230a24846a |
permissions | -rw-r--r-- |
5838 | 1 |
"{ Encoding: utf8 }" |
2 |
||
1716 | 3 |
" |
4 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
5 |
All Rights Reserved |
|
6 |
||
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
1818 | 14 |
"{ Package: 'stx:libwidg2' }" |
15 |
||
5055 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
1150 | 18 |
Object subclass:#DataSetLabel |
3772 | 19 |
instanceVariableNames:'label selector argument adjust font fgColor bgColor |
20 |
preferredHeight preferredWidth description' |
|
21 |
classVariableNames:'' |
|
22 |
poolDictionaries:'' |
|
23 |
category:'Views-DataSet' |
|
1150 | 24 |
! |
25 |
||
1716 | 26 |
!DataSetLabel class methodsFor:'documentation'! |
27 |
||
28 |
copyright |
|
29 |
" |
|
30 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
31 |
All Rights Reserved |
|
32 |
||
33 |
This software is furnished under a license and may be used |
|
34 |
only in accordance with the terms of that license and with the |
|
35 |
inclusion of the above copyright notice. This software may not |
|
36 |
be provided or otherwise made available to, or used by, any |
|
37 |
other person. No title to or ownership of the software is |
|
38 |
hereby transferred. |
|
39 |
" |
|
40 |
||
41 |
||
42 |
||
43 |
||
3649 | 44 |
! |
45 |
||
46 |
documentation |
|
47 |
" |
|
48 |
This class keeps some info about a label. |
|
49 |
||
50 |
[author:] |
|
51 |
Claus Atzkern |
|
52 |
" |
|
53 |
! ! |
|
54 |
||
55 |
!DataSetLabel class methodsFor:'image specs'! |
|
56 |
||
57 |
sortIndicator |
|
6115 | 58 |
<resource: #obsolete> |
59 |
<resource: #programImage> |
|
4588
7aebb93f46c6
Use ImageMask instead of Depth1Image for masks
Stefan Vogel <sv@exept.de>
parents:
4549
diff
changeset
|
60 |
|
6115 | 61 |
^ ToolbarIconLibrary sortIndicatorIcon |
3649 | 62 |
! |
63 |
||
3763 | 64 |
sortIndicatorGrey |
6115 | 65 |
<resource: #obsolete> |
5838 | 66 |
<resource: #programImage> |
67 |
||
6115 | 68 |
^ ToolbarIconLibrary sortIndicatorGreyIcon |
3768 | 69 |
! |
70 |
||
71 |
sortIndicatorIcon |
|
6115 | 72 |
<resource: #obsolete> |
73 |
<resource: #programImage> |
|
74 |
||
75 |
^ ToolbarIconLibrary sortIndicatorIcon |
|
3768 | 76 |
! |
77 |
||
3649 | 78 |
sortReverseIndicator |
6115 | 79 |
<resource: #obsolete> |
80 |
<resource: #programImage> |
|
4588
7aebb93f46c6
Use ImageMask instead of Depth1Image for masks
Stefan Vogel <sv@exept.de>
parents:
4549
diff
changeset
|
81 |
|
6115 | 82 |
^ ToolbarIconLibrary sortReverseIndicatorIcon |
83 |
||
3763 | 84 |
! |
85 |
||
86 |
sortReverseIndicatorGrey |
|
6115 | 87 |
<resource: #obsolete> |
88 |
<resource: #programImage> |
|
3768 | 89 |
|
6115 | 90 |
^ ToolbarIconLibrary sortReverseIndicatorGrey |
3768 | 91 |
! |
92 |
||
93 |
sortReverseIndicatorIcon |
|
6115 | 94 |
<resource: #obsolete> |
95 |
<resource: #programImage> |
|
96 |
||
97 |
^ ToolbarIconLibrary sortReverseIndicatorIcon |
|
1716 | 98 |
! ! |
1150 | 99 |
|
5641 | 100 |
!DataSetLabel methodsFor:'accessing-color & font'! |
1150 | 101 |
|
102 |
backgroundColor |
|
1487 | 103 |
"returns the background color or nil |
1150 | 104 |
" |
105 |
^ bgColor |
|
106 |
||
107 |
||
108 |
! |
|
109 |
||
2699 | 110 |
backgroundColor:aColor |
111 |
"set the background color or nil |
|
112 |
" |
|
113 |
bgColor := aColor |
|
114 |
! |
|
115 |
||
1150 | 116 |
foregroundColor |
1487 | 117 |
"returns the foreground color or nil |
1150 | 118 |
" |
119 |
^ fgColor |
|
120 |
||
2699 | 121 |
! |
122 |
||
123 |
foregroundColor:aColor |
|
124 |
"set the foreground color or nil |
|
125 |
" |
|
126 |
fgColor := aColor |
|
1150 | 127 |
! ! |
128 |
||
1818 | 129 |
!DataSetLabel methodsFor:'accessing-dimensions'! |
1150 | 130 |
|
1487 | 131 |
preferredHeight |
132 |
"returns my preferred height |
|
1150 | 133 |
" |
1487 | 134 |
^ preferredHeight |
1150 | 135 |
! |
136 |
||
1487 | 137 |
preferredWidth |
138 |
"returns my preferred width |
|
1150 | 139 |
" |
1487 | 140 |
^ preferredWidth |
1150 | 141 |
! ! |
142 |
||
143 |
!DataSetLabel methodsFor:'drawing'! |
|
144 |
||
3649 | 145 |
redrawX:xLeft w:width h:height inset:inset on:aLabelView |
1150 | 146 |
"redraw the label; the background is cleared and the paint is set |
147 |
" |
|
3763 | 148 |
|y0 x iconOffset gcFont labelWidth |
3768 | 149 |
netWidth goodLookingVerticalSpacing colNr sortIcon| |
1150 | 150 |
|
151 |
label isNil ifTrue:[ ^ self ]. |
|
152 |
||
1487 | 153 |
font notNil ifTrue:[ |
3649 | 154 |
gcFont := aLabelView font. "save original font" |
155 |
aLabelView font:font. |
|
1487 | 156 |
]. |
3582
2927b1b12e8f
Get the label from a value holder
Stefan Vogel <sv@exept.de>
parents:
3553
diff
changeset
|
157 |
|
2927b1b12e8f
Get the label from a value holder
Stefan Vogel <sv@exept.de>
parents:
3553
diff
changeset
|
158 |
y0 := (height - preferredHeight) // 2. |
4622 | 159 |
goodLookingVerticalSpacing := ((aLabelView font descent) - 2) max:2. |
3490
f46a3c50dc15
preferredExtent changes & fixes (ubs)
Claus Gittinger <cg@exept.de>
parents:
3468
diff
changeset
|
160 |
y0 := y0 + goodLookingVerticalSpacing. |
1150 | 161 |
|
2144 | 162 |
netWidth := width-inset-inset. |
163 |
||
3763 | 164 |
iconOffset := 0. |
3768 | 165 |
description isSortable ifTrue:[ |
166 |
iconOffset := 12. |
|
167 |
colNr := aLabelView columnIndexOfDescription:description. |
|
168 |
colNr == aLabelView indexOfSortColumn ifTrue:[ |
|
169 |
aLabelView reverseSort ifTrue:[ |
|
170 |
sortIcon := ToolbarIconLibrary sortIndicatorGreyIcon |
|
171 |
] ifFalse:[ |
|
172 |
sortIcon := ToolbarIconLibrary sortReverseIndicatorGreyIcon |
|
173 |
]. |
|
174 |
sortIcon displayOn:aLabelView x:xLeft+inset y:y0. |
|
3765 | 175 |
]. |
176 |
]. |
|
177 |
||
178 |
label do:[:eachLabelLine| |
|
3763 | 179 |
|restWidth xOffset shownLabel mustUndoClip prevClip| |
180 |
||
3765 | 181 |
shownLabel := eachLabelLine. |
2144 | 182 |
|
1588
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
183 |
mustUndoClip := false. |
3649 | 184 |
labelWidth := shownLabel widthOn:aLabelView. |
2144 | 185 |
labelWidth > netWidth ifTrue:[ |
3765 | 186 |
shownLabel := DataSetColumn shortenedStringFor:eachLabelLine on:aLabelView maxWidth:netWidth. |
3649 | 187 |
labelWidth := shownLabel widthOn:aLabelView. |
2144 | 188 |
]. |
189 |
||
1487 | 190 |
adjust == #left ifTrue:[ |
3763 | 191 |
x := xLeft + iconOffset + inset. |
1487 | 192 |
] ifFalse:[ |
3763 | 193 |
restWidth := width - labelWidth - iconOffset. |
1150 | 194 |
|
3649 | 195 |
adjust == #right ifTrue:[ |
3763 | 196 |
xOffset := restWidth - inset |
3649 | 197 |
] ifFalse:[ |
3763 | 198 |
xOffset := restWidth // 2. "/ center |
3649 | 199 |
]. |
3763 | 200 |
x := xLeft + xOffset. |
1588
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
201 |
|
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
202 |
"/ 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
|
203 |
x < xLeft ifTrue:[ |
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
204 |
"/ must clip ... |
3649 | 205 |
prevClip := aLabelView clippingRectangleOrNil. |
1588
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
206 |
mustUndoClip := true. |
5409 | 207 |
aLabelView clippingBounds:(Rectangle |
1588
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
208 |
left:xLeft top:y0 |
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
209 |
width:width height:height). |
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
210 |
]. |
1487 | 211 |
]. |
3582
2927b1b12e8f
Get the label from a value holder
Stefan Vogel <sv@exept.de>
parents:
3553
diff
changeset
|
212 |
|
3649 | 213 |
shownLabel displayOn:aLabelView x:x y:y0 + (shownLabel ascentOn:aLabelView). |
214 |
y0 := y0 + (shownLabel heightOn:aLabelView) + goodLookingVerticalSpacing. |
|
1588
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
215 |
|
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
216 |
mustUndoClip == true ifTrue:[ |
5409 | 217 |
aLabelView clippingBounds:prevClip |
1588
e6039e46cae2
clip label on the left, if larger than columns width,
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
218 |
]. |
1487 | 219 |
]. |
3649 | 220 |
|
3582
2927b1b12e8f
Get the label from a value holder
Stefan Vogel <sv@exept.de>
parents:
3553
diff
changeset
|
221 |
gcFont notNil ifTrue:[ |
3649 | 222 |
aLabelView font:gcFont "/ restore font |
2451 | 223 |
]. |
1150 | 224 |
! ! |
225 |
||
226 |
!DataSetLabel methodsFor:'instance creation'! |
|
227 |
||
1487 | 228 |
description:aDescription builder:aBuilder on:aGC |
5560 | 229 |
|device| |
1150 | 230 |
|
3649 | 231 |
description := aDescription. |
232 |
||
233 |
"/ stupid code - could simply access things via the description. |
|
234 |
"/ I leave it here for subclasses which depend on it (for a while). |
|
1605 | 235 |
label := self resolveLabelFromDescription:aDescription withBuilder:aBuilder. |
236 |
selector := aDescription labelActionSelector. |
|
237 |
argument := (aDescription labelActionArgument) ? label. |
|
238 |
adjust := (aDescription labelAlignment) ? #left. |
|
4549 | 239 |
device := aGC graphicsDevice. |
1605 | 240 |
fgColor := aDescription labelForegroundColor. |
241 |
bgColor := aDescription labelBackgroundColor. |
|
1150 | 242 |
|
1480 | 243 |
fgColor notNil ifTrue:[ fgColor := fgColor onDevice:device ]. |
244 |
bgColor notNil ifTrue:[ bgColor := bgColor onDevice:device ]. |
|
1150 | 245 |
|
5560 | 246 |
label isEmptyOrNil ifTrue:[ |
247 |
label := nil. |
|
248 |
] ifFalse:[ |
|
249 |
font := aDescription labelFont. |
|
250 |
font notNil ifTrue:[ |
|
251 |
font := aBuilder resolveFont:font. |
|
252 |
font notNil ifTrue:[ |
|
253 |
aGC font = font |
|
254 |
ifTrue:[font := nil] |
|
255 |
ifFalse:[font := font onDevice:device]. |
|
256 |
]. |
|
257 |
]. |
|
258 |
label isNonByteCollection |
|
259 |
ifFalse:[label := Array with:label]. |
|
260 |
||
261 |
label := label collect:[:el| self label:el on:device ]. |
|
262 |
]. |
|
263 |
self fontChangedOn:aGC. "/ initial setup font relevant attributes |
|
264 |
! |
|
1487 | 265 |
|
5560 | 266 |
font |
267 |
"answer my font or nil (default)" |
|
268 |
^ font |
|
269 |
! |
|
270 |
||
271 |
font:aFont |
|
272 |
"set my font or nil (default)" |
|
273 |
font := aFont. |
|
274 |
! |
|
275 |
||
276 |
fontChangedOn:aGC |
|
277 |
"invoked after the font has changed" |
|
278 |
|gcFont verticalSpace| |
|
279 |
||
280 |
preferredWidth := preferredHeight := 0. |
|
281 |
label isEmptyOrNil |
|
282 |
ifTrue:[ ^ self ]. |
|
283 |
||
284 |
gcFont := aGC font. |
|
285 |
verticalSpace := gcFont descent. "/ goodLookingVerticalSpacing |
|
286 |
||
287 |
font isNil ifTrue:[ |
|
288 |
gcFont := nil. |
|
289 |
] ifFalse:[ |
|
290 |
font = gcFont |
|
291 |
ifTrue:[gcFont := nil] |
|
292 |
ifFalse:[aGC font:font]. |
|
1150 | 293 |
]. |
294 |
||
5560 | 295 |
label do:[:each| |
296 |
preferredWidth := preferredWidth max:(each widthOn:aGC). |
|
297 |
preferredHeight := preferredHeight + verticalSpace + (each heightOn:aGC). |
|
1487 | 298 |
]. |
5560 | 299 |
gcFont notNil ifTrue:[aGC font:gcFont]. |
1150 | 300 |
! ! |
301 |
||
302 |
!DataSetLabel methodsFor:'private'! |
|
303 |
||
304 |
label:aLabel on:aDevice |
|
5201 | 305 |
"returns registered label on a device" |
1150 | 306 |
|
1487 | 307 |
aLabel isNil ifTrue:[^ '']. |
308 |
||
5201 | 309 |
(aLabel isImageOrForm or:[aLabel isLabelAndIcon]) ifTrue:[ |
310 |
^ aLabel onDevice:aDevice |
|
1150 | 311 |
]. |
312 |
^ aLabel |
|
313 |
! |
|
314 |
||
315 |
resolveLabelFromDescription:aDescription withBuilder:aBuilder |
|
3763 | 316 |
"the rawLabel can be a string, icon, labelAndIcon or collection of strings. |
317 |
if labelIsImage is true, the string is actually the appModel-labelFor-access key" |
|
318 |
||
3468 | 319 |
|rawLabel appl resources lbl| |
1150 | 320 |
|
321 |
aBuilder isNil ifTrue:[ |
|
3468 | 322 |
rawLabel := aDescription rawLabel. |
3763 | 323 |
] ifFalse:[ |
324 |
rawLabel := aDescription label. |
|
325 |
rawLabel isNil ifTrue:[^ nil ]. |
|
326 |
||
327 |
aBuilder isEditing ifFalse:[ |
|
328 |
appl := aBuilder application. |
|
329 |
appl notNil ifTrue:[ resources := appl resources ]. |
|
330 |
]. |
|
3468 | 331 |
|
332 |
rawLabel isString ifTrue:[ |
|
3763 | 333 |
aDescription labelIsImage ifTrue:[ |
334 |
(aBuilder isEditing or:[(rawLabel := aBuilder labelFor:(rawLabel asSymbol)) isNil]) ifTrue:[ |
|
335 |
rawLabel := aDescription class defaultIcon |
|
336 |
]. |
|
337 |
^ rawLabel |
|
338 |
] ifFalse:[ |
|
339 |
aDescription translateLabel == true ifTrue:[ |
|
340 |
lbl := (aBuilder labelAt:(rawLabel asSymbol)) value. |
|
341 |
lbl isNil ifTrue:[ |
|
342 |
lbl := (aBuilder aspectAt:(rawLabel asSymbol)) value. |
|
343 |
]. |
|
344 |
(lbl isNil and:[resources notNil]) ifTrue:[ |
|
345 |
lbl := resources string:rawLabel default:nil. |
|
346 |
]. |
|
347 |
lbl notNil ifTrue:[ rawLabel := lbl ]. |
|
348 |
]. |
|
349 |
]. |
|
3468 | 350 |
] ifFalse:[ |
5445 | 351 |
(rawLabel isLabelAndIcon) ifTrue:[ |
3763 | 352 |
rawLabel := rawLabel copy string:(resources string:rawLabel string). |
1150 | 353 |
]. |
3468 | 354 |
|
3763 | 355 |
rawLabel isSequenceable ifFalse:[^ rawLabel]. |
356 |
rawLabel isEmptyOrNil ifTrue:[^ nil ]. |
|
357 |
||
358 |
resources notNil ifTrue:[ |
|
359 |
lbl := resources string:rawLabel default:nil. |
|
3468 | 360 |
|
3763 | 361 |
lbl notNil ifTrue:[ |
362 |
rawLabel := lbl. |
|
363 |
] ifFalse:[ |
|
364 |
lbl := resources array:rawLabel. |
|
365 |
lbl notEmptyOrNil ifTrue:[ |
|
366 |
lbl size == 1 ifTrue:[ rawLabel := lbl first ] |
|
367 |
ifFalse:[ rawLabel := lbl ]. |
|
368 |
]. |
|
3468 | 369 |
]. |
370 |
]. |
|
1150 | 371 |
]. |
372 |
]. |
|
3763 | 373 |
|
3468 | 374 |
rawLabel isString ifTrue:[ |
375 |
rawLabel isEmpty ifTrue:[ ^ nil ]. |
|
376 |
lbl := rawLabel asStringCollection. |
|
377 |
lbl size > 1 ifTrue:[^ lbl ]. |
|
378 |
]. |
|
379 |
^ rawLabel |
|
5445 | 380 |
|
381 |
"Modified: / 04-02-2017 / 22:10:42 / cg" |
|
1150 | 382 |
! ! |
383 |
||
384 |
!DataSetLabel methodsFor:'queries'! |
|
385 |
||
1605 | 386 |
hasSeparator |
387 |
label size == 1 ifTrue:[ |
|
388 |
"/ ^ (label at:1) ~= 'Alarm' |
|
389 |
^ (label at:1) ~= 'Area' |
|
390 |
]. |
|
391 |
^ true |
|
5570 | 392 |
|
393 |
"Modified (format): / 03-08-2017 / 14:37:12 / cg" |
|
1605 | 394 |
! |
395 |
||
1150 | 396 |
isSelectable |
397 |
"returns true if the item is selectable; a valid selector |
|
398 |
to notify the receiver for a release button event exists |
|
399 |
" |
|
400 |
^ selector notNil |
|
401 |
||
402 |
||
3765 | 403 |
! |
404 |
||
3768 | 405 |
isSortable |
3765 | 406 |
^ description isSortable |
1150 | 407 |
! ! |
408 |
||
409 |
!DataSetLabel class methodsFor:'documentation'! |
|
410 |
||
411 |
version |
|
5055 | 412 |
^ '$Header$' |
3763 | 413 |
! |
414 |
||
415 |
version_CVS |
|
5055 | 416 |
^ '$Header$' |
1150 | 417 |
! ! |
4549 | 418 |