author | Claus Gittinger <cg@exept.de> |
Fri, 20 Jun 2008 11:54:07 +0200 | |
changeset 3633 | c9eacbe73abb |
parent 3615 | a99127b32e61 |
child 3649 | 36c3b9d8bef3 |
permissions | -rw-r--r-- |
0 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
59 | 3 |
All Rights Reserved |
0 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
2192
e9068416fd41
foreground-, backgroundChannel moved to superclass (#destroy)
Stefan Vogel <sv@exept.de>
parents:
2098
diff
changeset
|
12 |
"{ Package: 'stx:libwidg' }" |
e9068416fd41
foreground-, backgroundChannel moved to superclass (#destroy)
Stefan Vogel <sv@exept.de>
parents:
2098
diff
changeset
|
13 |
|
0 | 14 |
View subclass:#Label |
254
aa15cac0670f
oops - foregroundColor was overwritten by backgroundColor (if defined in styleSheet)
Claus Gittinger <cg@exept.de>
parents:
250
diff
changeset
|
15 |
instanceVariableNames:'logo labelWidth labelHeight labelOriginX labelOriginY adjust |
2496 | 16 |
hSpace vSpace bgColor fgColor etchedFgColor fixSize labelMsg |
17 |
converter labelChannel' |
|
392
81343306d796
eliminated all DefaultFont classVars (are now classINSTvars)
Claus Gittinger <cg@exept.de>
parents:
391
diff
changeset
|
18 |
classVariableNames:'DefaultForegroundColor DefaultBackgroundColor' |
254
aa15cac0670f
oops - foregroundColor was overwritten by backgroundColor (if defined in styleSheet)
Claus Gittinger <cg@exept.de>
parents:
250
diff
changeset
|
19 |
poolDictionaries:'' |
aa15cac0670f
oops - foregroundColor was overwritten by backgroundColor (if defined in styleSheet)
Claus Gittinger <cg@exept.de>
parents:
250
diff
changeset
|
20 |
category:'Views-Layout' |
0 | 21 |
! |
22 |
||
935 | 23 |
!Label class methodsFor:'documentation'! |
3 | 24 |
|
38 | 25 |
copyright |
26 |
" |
|
27 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
59 | 28 |
All Rights Reserved |
38 | 29 |
|
30 |
This software is furnished under a license and may be used |
|
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
38 |
||
3 | 39 |
documentation |
40 |
" |
|
38 | 41 |
This class implements labels, which are views to display a string or image. |
42 |
The Label will try to do its best to make its contents fit into the |
|
43 |
view. The contents can be a String, a collection of Strings (i.e. |
|
118 | 44 |
a StringCollection) or a Form/Image. |
63 | 45 |
|
46 |
The contents is drawn in fgColor/bgColor, which can be changed using: |
|
47 |
||
585 | 48 |
aLabel foregroundColor:aColor |
49 |
aLabel backgroundColor:aColor |
|
3 | 50 |
|
38 | 51 |
When a label is assigned a contents, it will resize itself to fit |
52 |
the required size. This resizing can be suppressed by setting the |
|
53 |
fixsize attribute to true using: |
|
63 | 54 |
|
585 | 55 |
aLabel sizeFixed:true |
3 | 56 |
|
38 | 57 |
This can be used, if resizing of the label is not wanted. |
63 | 58 |
However, in this case you have to make certain that the size is big enough |
118 | 59 |
to hold any changed logos later. (usually, you create the label first with |
60 |
the longest string first to have it compute its size, then set the fixSize |
|
61 |
attribute to avoid resizing later). |
|
125 | 62 |
Be careful when placing self-resizing labels into panels - by default, |
63 |
panels do not react on the size change - leading to ugly looking geometry. |
|
64 |
(but you can tell the panel to watch for changes with #elementsCHangeSize:) |
|
38 | 65 |
|
66 |
The placement of the contents within the label is controlled by |
|
63 | 67 |
the adjust attribute, it can be set with: |
68 |
||
585 | 69 |
aLabel adjust:how |
3 | 70 |
|
1946 | 71 |
where how is one of the symbols left, #right, #center, #centerEach, |
72 |
#centerLeft, #centerRight, #leftRight or #rightLeft |
|
73 |
(see the comment in Label>>adjust:). The default is #center. |
|
3 | 74 |
|
145 | 75 |
model-less operation (ok for static labels): |
118 | 76 |
if no model is set, the labels contents is set with: |
77 |
||
585 | 78 |
aLabel label:aStringOrImage |
118 | 79 |
|
80 |
and stays constant unless changed by new calls to #label:. |
|
81 |
||
82 |
||
145 | 83 |
model operation (ST-80 style): |
118 | 84 |
labels with a model, aspectMsg and labelMsg react to |
85 |
changes of the aspect, and send a labelMsg-message |
|
86 |
to the model in order to aquire a new labelString or image. |
|
87 |
The model should send 'self changed:aspectMsg' if it thinks the label |
|
88 |
should change and return a string or image from the labelMsg-message. |
|
89 |
||
585 | 90 |
label model:aModel. |
91 |
label aspect:aspectSymbol. |
|
92 |
label labelMessage:labelSymbol. |
|
118 | 93 |
|
585 | 94 |
model sends #changed:aspectSymbol |
95 |
---> label will redraw its label from value of model perform:labelSymbol |
|
118 | 96 |
|
97 |
Having a labelSymbol different from the aspectSymbol allows for two labels |
|
98 |
to react on the same aspect-change, but use different messages when asking |
|
99 |
the model for a new label contents. By default, the labelMsg is nil, |
|
100 |
so the label does NOT update its shown contents. |
|
101 |
The aspectMsg defaults to #value. |
|
102 |
||
125 | 103 |
|
145 | 104 |
|
105 |
channel operation (new ST/X style): |
|
106 |
||
107 |
the label will react on changes of the token found in the |
|
108 |
channels: foregroundChannel, backgroundChannel and labelChannel. |
|
109 |
These are valueHolders and can be shared between labels. |
|
110 |
||
111 |
||
112 |
||
585 | 113 |
[Instance variables:] |
3 | 114 |
|
585 | 115 |
logo <Object> the logo, can be a Form, String or Text |
116 |
labelWidth <Integer> the width of the logo in device units |
|
117 |
labelHeight <Integer> the height of the logo in device units |
|
118 |
labelOriginX <Integer> the x-position of the logo withing the Label |
|
119 |
labelOriginY <Integer> the y-position of the logo withing the Label |
|
120 |
adjust <Symbol> controls how the logo is positioned within the |
|
121 |
label. Can be one of:#left,#right,#center, |
|
122 |
#centerLeft or #centerRight (see comment in adjust:) |
|
123 |
hSpace <Integer> number of horizontal pixels around logo |
|
124 |
vSpace <Integer> number of vertical pixels around logo |
|
3 | 125 |
|
585 | 126 |
bgColor <Color> background color |
127 |
fgColor <Color> foreground color |
|
38 | 128 |
|
585 | 129 |
fixSize <Boolean> if true, a change of the logo change will not |
130 |
resize the label; otherwise, its size is adjusted. |
|
131 |
default:false. |
|
50 | 132 |
|
585 | 133 |
labelMsg <Symbol> if non-nil, this is sent to the model to |
134 |
aquire the labelString or labelImage. |
|
135 |
If nil, the label stays as is |
|
113 | 136 |
|
585 | 137 |
[styleSheet parameters:] |
50 | 138 |
|
118 | 139 |
labelForegroundColor <Color> color to draw foreground pixels (i.e. the string) |
140 |
labelBackgroundColor <Color> color to draw background pixels |
|
141 |
labelFont <Font> font to use for textual labels |
|
585 | 142 |
|
143 |
[author:] |
|
144 |
Claus Gittinger |
|
593 | 145 |
|
146 |
[see also:] |
|
147 |
Panel HorizontalPanel VerticalPanel |
|
148 |
TextView EditTextView |
|
149 |
Button |
|
150 |
InfoBox WarningBox |
|
3 | 151 |
" |
63 | 152 |
! |
153 |
||
154 |
examples |
|
155 |
" |
|
156 |
Notice, that Buttons and others inherit from Label; |
|
157 |
therefore, the following geometry examples apply to all subclasses too. |
|
158 |
||
159 |
||
113 | 160 |
simple (default position is 0@0): |
593 | 161 |
[exBegin] |
162 |
|top l| |
|
63 | 163 |
|
593 | 164 |
top := StandardSystemView new. |
165 |
top extent:(200 @ 200). |
|
63 | 166 |
|
593 | 167 |
l := Label in:top. |
168 |
l label:'hello world'. |
|
63 | 169 |
|
593 | 170 |
top open |
171 |
[exEnd] |
|
63 | 172 |
|
113 | 173 |
|
626 | 174 |
simple with emphasis: |
175 |
[exBegin] |
|
176 |
|top l| |
|
177 |
||
178 |
top := StandardSystemView new. |
|
179 |
top extent:(300 @ 100). |
|
180 |
||
181 |
l := Label in:top. |
|
182 |
l level:-1. |
|
183 |
l label:('hello world - this is text in a label ' asText |
|
184 |
emphasizeFrom:7 to:11 with:#italic; |
|
185 |
emphasizeFrom:23 to:26 with:#bold). |
|
186 |
top open |
|
187 |
[exEnd] |
|
188 |
||
189 |
||
113 | 190 |
there is also a creation message which sets the label: |
593 | 191 |
[exBegin] |
192 |
|top l| |
|
113 | 193 |
|
593 | 194 |
top := StandardSystemView new. |
195 |
top extent:(200 @ 200). |
|
113 | 196 |
|
593 | 197 |
l := Label label:'hello world' in:top. |
113 | 198 |
|
593 | 199 |
top open |
200 |
[exEnd] |
|
113 | 201 |
|
202 |
||
63 | 203 |
placement: |
593 | 204 |
[exBegin] |
205 |
|top l| |
|
63 | 206 |
|
593 | 207 |
top := StandardSystemView new. |
208 |
top extent:(200 @ 200). |
|
63 | 209 |
|
593 | 210 |
l := Label in:top. |
211 |
l label:'hello world'. |
|
212 |
l origin:50@100. |
|
63 | 213 |
|
593 | 214 |
top open |
215 |
[exEnd] |
|
63 | 216 |
|
113 | 217 |
|
63 | 218 |
level: |
593 | 219 |
[exBegin] |
220 |
|top l| |
|
63 | 221 |
|
593 | 222 |
top := StandardSystemView new. |
223 |
top extent:(200 @ 200). |
|
63 | 224 |
|
593 | 225 |
l := Label in:top. |
226 |
l level:5. |
|
227 |
l label:'hello world'. |
|
228 |
l origin:50@100. |
|
63 | 229 |
|
593 | 230 |
top open |
231 |
[exEnd] |
|
63 | 232 |
|
113 | 233 |
|
63 | 234 |
another level: |
593 | 235 |
[exBegin] |
236 |
|top l| |
|
63 | 237 |
|
593 | 238 |
top := StandardSystemView new. |
239 |
top extent:(200 @ 200). |
|
63 | 240 |
|
593 | 241 |
l := Label in:top. |
242 |
l level:-1. |
|
243 |
l label:'hello world'. |
|
244 |
l origin:50@100. |
|
63 | 245 |
|
593 | 246 |
top open |
247 |
[exEnd] |
|
63 | 248 |
|
113 | 249 |
|
118 | 250 |
colors & font: |
593 | 251 |
[exBegin] |
252 |
|top l| |
|
118 | 253 |
|
593 | 254 |
top := StandardSystemView new. |
255 |
top extent:(200 @ 200). |
|
118 | 256 |
|
593 | 257 |
l := Label in:top. |
258 |
l level:-1. |
|
259 |
l font:(Font family:'Times' size:18). |
|
260 |
l foregroundColor:Color yellow. |
|
261 |
l backgroundColor:Color red. |
|
262 |
l label:'hello world'. |
|
263 |
l origin:50@100. |
|
118 | 264 |
|
593 | 265 |
top open |
266 |
[exEnd] |
|
118 | 267 |
|
268 |
||
63 | 269 |
border & colors: |
593 | 270 |
[exBegin] |
271 |
|top l| |
|
63 | 272 |
|
593 | 273 |
top := StandardSystemView new. |
274 |
top extent:(200 @ 200). |
|
63 | 275 |
|
593 | 276 |
l := Label in:top. |
277 |
l level:0. |
|
278 |
l borderWidth:1. |
|
279 |
l borderColor:Color red. |
|
280 |
l foregroundColor:Color green darkened. |
|
281 |
l backgroundColor:Color green lightened. |
|
282 |
l label:'hello world'. |
|
283 |
l origin:50@100. |
|
63 | 284 |
|
593 | 285 |
top open |
286 |
[exEnd] |
|
63 | 287 |
|
113 | 288 |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
289 |
different adjusts (resize to see): |
593 | 290 |
[exBegin] |
291 |
|top l| |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
292 |
|
593 | 293 |
top := StandardSystemView new. |
294 |
top extent:(300 @ 250). |
|
295 |
top label:'make me smaller'. |
|
296 |
||
297 |
l := Label in:top. |
|
298 |
l borderWidth:1. |
|
299 |
l label:'default - #centered'. |
|
300 |
l origin:0.1@40. |
|
301 |
l width:0.8. |
|
63 | 302 |
|
593 | 303 |
l := Label in:top. |
304 |
l borderWidth:1. |
|
305 |
l adjust:#left. |
|
306 |
l label:'#left adjust'. |
|
307 |
l origin:0.1@70. |
|
308 |
l width:0.8. |
|
63 | 309 |
|
593 | 310 |
l := Label in:top. |
311 |
l borderWidth:1. |
|
312 |
l adjust:#right. |
|
313 |
l label:'#right adjust'. |
|
314 |
l origin:0.1@100. |
|
315 |
l width:0.8. |
|
118 | 316 |
|
593 | 317 |
l := Label in:top. |
318 |
l borderWidth:1. |
|
319 |
l adjust:#centerLeft. |
|
320 |
l label:'#centerLeft adjust with a long text'. |
|
321 |
l origin:0.1@130. |
|
322 |
l width:0.8. |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
323 |
|
593 | 324 |
l := Label in:top. |
325 |
l borderWidth:1. |
|
326 |
l adjust:#centerRight. |
|
327 |
l label:'#centerRight adjust with a long text'. |
|
328 |
l origin:0.1@160. |
|
329 |
l width:0.8. |
|
63 | 330 |
|
593 | 331 |
l := Label in:top. |
332 |
l borderWidth:1. |
|
333 |
l adjust:#leftRight. |
|
334 |
l label:'#leftRight adjust with a long text'. |
|
335 |
l origin:0.1@190. |
|
336 |
l width:0.8. |
|
63 | 337 |
|
593 | 338 |
l := Label in:top. |
339 |
l borderWidth:1. |
|
340 |
l adjust:#rightLeft. |
|
341 |
l label:'#rightLeft adjust with a long text'. |
|
342 |
l origin:0.1@220. |
|
343 |
l width:0.8. |
|
118 | 344 |
|
593 | 345 |
top open |
346 |
[exEnd] |
|
63 | 347 |
|
113 | 348 |
|
1945 | 349 |
center vs. centerEach adjust (only with multiline labels): |
350 |
[exBegin] |
|
351 |
|top l| |
|
352 |
||
353 |
top := StandardSystemView new. |
|
354 |
top extent:(300 @ 250). |
|
355 |
top label:'resize me'. |
|
356 |
||
357 |
l := Label in:top. |
|
358 |
l borderWidth:1. |
|
359 |
l label:'this labels logo |
|
1946 | 360 |
consists of multiple lines |
361 |
with #center adjust'. |
|
1945 | 362 |
l origin:0.1@0.1. |
363 |
l corner:0.9@0.9. |
|
364 |
l adjust:#center. |
|
365 |
||
366 |
top open. |
|
367 |
||
368 |
top := StandardSystemView new. |
|
369 |
top extent:(300 @ 250). |
|
370 |
top label:'resize me'. |
|
371 |
||
372 |
l := Label in:top. |
|
373 |
l borderWidth:1. |
|
374 |
l label:'this labels logo |
|
1946 | 375 |
consists of multiple lines |
376 |
with #centerEach adjust'. |
|
1945 | 377 |
l origin:0.1@0.1. |
378 |
l corner:0.9@0.9. |
|
379 |
l adjust:#centerEach. |
|
380 |
||
381 |
top open |
|
382 |
||
383 |
[exEnd] |
|
384 |
||
131 | 385 |
fitting-adjust (resize to see): |
386 |
Warning: #fit is experimental and should not be used. |
|
593 | 387 |
[exBegin] |
388 |
|top l| |
|
131 | 389 |
|
593 | 390 |
top := StandardSystemView new. |
391 |
top extent:(200 @ 200). |
|
131 | 392 |
|
593 | 393 |
l := Label origin:0.25 @ 0.25 corner:0.75@0.75 in:top. |
394 |
l label:'stretch'. |
|
395 |
l level:-1. |
|
396 |
l adjust:#fit. |
|
131 | 397 |
|
593 | 398 |
top open |
399 |
[exEnd] |
|
131 | 400 |
|
401 |
or: |
|
402 |
Warning: #fit is experimental and should not be used. |
|
593 | 403 |
[exBegin] |
404 |
|top l| |
|
131 | 405 |
|
593 | 406 |
top := StandardSystemView new. |
407 |
top extent:(200 @ 200). |
|
131 | 408 |
|
593 | 409 |
l := Label origin:0.25 @ 0.25 corner:0.75@0.75 in:top. |
410 |
l label:(Image fromFile:'bitmaps/SBrowser.xbm'). |
|
411 |
l level:-1. |
|
412 |
l adjust:#fit. |
|
131 | 413 |
|
593 | 414 |
top open |
415 |
[exEnd] |
|
131 | 416 |
|
417 |
||
63 | 418 |
just a reminder, that instead of doing placement manually |
113 | 419 |
as in ...: |
593 | 420 |
[exBegin] |
421 |
|top l| |
|
63 | 422 |
|
593 | 423 |
top := StandardSystemView new. |
424 |
top extent:(200 @ 200). |
|
63 | 425 |
|
593 | 426 |
l := Label in:top. |
427 |
l borderWidth:1. |
|
428 |
l label:'default - centered'. |
|
429 |
l origin:0.1@70. |
|
430 |
l width:0.8. |
|
63 | 431 |
|
593 | 432 |
l := Label in:top. |
433 |
l borderWidth:1. |
|
434 |
l adjust:#left. |
|
435 |
l label:'left adjust'. |
|
436 |
l origin:0.1@100. |
|
437 |
l width:0.8. |
|
63 | 438 |
|
593 | 439 |
l := Label in:top. |
440 |
l borderWidth:1. |
|
441 |
l adjust:#right. |
|
442 |
l label:'right adjust'. |
|
443 |
l origin:0.1@130. |
|
444 |
l width:0.8. |
|
63 | 445 |
|
593 | 446 |
top open |
447 |
[exEnd] |
|
63 | 448 |
|
113 | 449 |
|
450 |
... it is much easier, to use a geometry handler, such as |
|
63 | 451 |
a VerticalPanel. Try: |
593 | 452 |
[exBegin] |
453 |
|top panel l| |
|
63 | 454 |
|
593 | 455 |
top := StandardSystemView new. |
456 |
top extent:(200 @ 200). |
|
63 | 457 |
|
593 | 458 |
panel := VerticalPanelView |
459 |
origin:0.1 @ 0.0 |
|
460 |
corner:0.9 @ 1.0 |
|
461 |
in:top. |
|
63 | 462 |
|
593 | 463 |
panel horizontalLayout:#fit. |
464 |
panel verticalLayout:#center. |
|
63 | 465 |
|
593 | 466 |
l := Label in:panel. |
467 |
l borderWidth:1. |
|
468 |
l label:'default - centered'. |
|
63 | 469 |
|
593 | 470 |
l := Label in:panel. |
471 |
l borderWidth:1. |
|
472 |
l adjust:#left. |
|
473 |
l label:'left adjust'. |
|
63 | 474 |
|
593 | 475 |
l := Label in:panel. |
476 |
l borderWidth:1. |
|
477 |
l adjust:#right. |
|
478 |
l label:'right adjust'. |
|
63 | 479 |
|
593 | 480 |
top open |
481 |
[exEnd] |
|
63 | 482 |
|
113 | 483 |
|
63 | 484 |
labels with bitmaps or images: |
593 | 485 |
[exBegin] |
486 |
|top l| |
|
63 | 487 |
|
593 | 488 |
top := StandardSystemView new. |
489 |
top extent:(200 @ 200). |
|
63 | 490 |
|
593 | 491 |
l := Label in:top. |
492 |
l level:-1. |
|
493 |
l label:((Image fromFile:'bitmaps/garfield.gif') magnifyBy:0.2 @ 0.2). |
|
494 |
l origin:50@100. |
|
63 | 495 |
|
593 | 496 |
top open |
497 |
[exEnd] |
|
113 | 498 |
|
499 |
||
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
500 |
that even works with #fit: |
593 | 501 |
[exBegin] |
502 |
|top l| |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
503 |
|
593 | 504 |
top := StandardSystemView new. |
505 |
top extent:(200 @ 200). |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
506 |
|
593 | 507 |
l := Label in:top. |
508 |
l adjust:#fit. |
|
509 |
l level:-1. |
|
510 |
l label:(Image fromFile:'bitmaps/garfield.gif'). |
|
511 |
l origin:0.2@0.2 corner:0.8@0.8. |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
512 |
|
593 | 513 |
top open |
514 |
[exEnd] |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
515 |
|
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
516 |
|
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
517 |
notice, that Buttons inherit from Label; thus: |
593 | 518 |
[exBegin] |
519 |
|top b| |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
520 |
|
593 | 521 |
top := StandardSystemView new. |
522 |
top extent:(200 @ 200). |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
523 |
|
593 | 524 |
b := Button in:top. |
525 |
b adjust:#fit. |
|
526 |
b label:(Image fromFile:'bitmaps/garfield.gif'). |
|
527 |
b origin:0.2@0.2 corner:0.8@0.8. |
|
655 | 528 |
b action:[Transcript showCR:'wow']. |
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
529 |
|
593 | 530 |
top open |
531 |
[exEnd] |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
532 |
|
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
533 |
|
1374 | 534 |
Channel operation (controlling fg, bg and labelText via ValueHolders) |
145 | 535 |
----------------- |
593 | 536 |
[exBegin] |
537 |
|top panel logoChannel fgChannel bgChannel l b| |
|
145 | 538 |
|
593 | 539 |
top := StandardSystemView new. |
540 |
top extent:(450 @ 200). |
|
145 | 541 |
|
593 | 542 |
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
145 | 543 |
|
593 | 544 |
l := Label in:panel. |
545 |
l level:-1. |
|
546 |
l label:'change my colors'. |
|
547 |
l origin:50@100. |
|
548 |
l sizeFixed:true. |
|
145 | 549 |
|
593 | 550 |
fgChannel := Color blue asValue. |
551 |
bgChannel := Color grey asValue. |
|
552 |
logoChannel := 'change me' asValue. |
|
145 | 553 |
|
593 | 554 |
b := Toggle label:'change fg' in:panel. b showLamp:false; onLevel:-2. |
555 |
b pressAction:[fgChannel value:Color red]. |
|
556 |
b releaseAction:[fgChannel value:Color blue]. |
|
145 | 557 |
|
593 | 558 |
b := Toggle label:'change bg' in:panel. |
559 |
b pressAction:[bgChannel value:Color yellow]. |
|
560 |
b releaseAction:[bgChannel value:Color grey]. |
|
145 | 561 |
|
593 | 562 |
b := Toggle label:'change text' in:panel. |
563 |
b pressAction:[logoChannel value:'wow']. |
|
564 |
b releaseAction:[logoChannel value:'not bad' ]. |
|
145 | 565 |
|
593 | 566 |
l labelChannel:logoChannel. |
567 |
l foregroundChannel:fgChannel. |
|
568 |
l backgroundChannel:bgChannel. |
|
145 | 569 |
|
593 | 570 |
top open |
571 |
[exEnd] |
|
145 | 572 |
|
573 |
||
146 | 574 |
multiple labels on one channel: |
593 | 575 |
[exBegin] |
576 |
|l1 l2 b conv| |
|
146 | 577 |
|
593 | 578 |
l1 := Label label:'label1'. |
146 | 579 |
|
593 | 580 |
l2 := Label label:'label2'. |
146 | 581 |
|
593 | 582 |
b := Button label:'change'. |
583 |
conv := (ConvertedValue new |
|
584 |
conversion:[:input | |
|
585 |
input ifTrue:[ |
|
586 |
Color red |
|
587 |
] ifFalse:[ |
|
588 |
Color blue |
|
589 |
]]). |
|
590 |
conv value:false. |
|
146 | 591 |
|
593 | 592 |
b controller pressChannel:conv. |
593 |
l1 foregroundChannel:conv. |
|
594 |
l2 foregroundColor:Color white; backgroundChannel:conv. |
|
146 | 595 |
|
593 | 596 |
b open. |
597 |
l1 open. |
|
598 |
l2 open. |
|
599 |
[exEnd] |
|
146 | 600 |
|
601 |
||
125 | 602 |
MVC operation |
145 | 603 |
------------- |
604 |
||
125 | 605 |
model provides the label): |
606 |
(have to use a plug to simulate a model which responds to |
|
593 | 607 |
the #someAspect message): |
608 |
|top l model| |
|
113 | 609 |
|
593 | 610 |
model := Plug new. |
611 |
model respondTo:#someAspect with:['models labelString']. |
|
113 | 612 |
|
593 | 613 |
top := StandardSystemView new. |
614 |
top extent:(200 @ 200). |
|
113 | 615 |
|
593 | 616 |
l := Label in:top. |
617 |
l model:model; labelMessage:#someAspect. |
|
113 | 618 |
|
593 | 619 |
top open |
620 |
... |
|
118 | 621 |
|
593 | 622 |
model changed:#someAspect |
623 |
... |
|
113 | 624 |
|
625 |
||
118 | 626 |
concrete example (track a counters value): |
125 | 627 |
(here, the default aspect #value is used both to notify the label about |
628 |
changes and to aquire a new value from the model). |
|
593 | 629 |
[exBegin] |
630 |
|top l model| |
|
113 | 631 |
|
593 | 632 |
model := ValueHolder new. |
633 |
model value:'0'. |
|
634 |
[ |
|
635 |
1 to:20 do:[:i | |
|
636 |
(Delay forSeconds:1) wait. |
|
637 |
model value:i printString |
|
638 |
]. |
|
639 |
top destroy |
|
640 |
] fork. |
|
113 | 641 |
|
593 | 642 |
top := StandardSystemView new. |
643 |
top extent:(200 @ 200). |
|
113 | 644 |
|
593 | 645 |
l := Label in:top. |
646 |
l level:-1. |
|
647 |
l model:model; labelMessage:#value. |
|
118 | 648 |
|
593 | 649 |
top open |
650 |
[exEnd] |
|
118 | 651 |
|
652 |
||
133 | 653 |
with a printConverter: |
593 | 654 |
[exBegin] |
655 |
|top l model| |
|
133 | 656 |
|
593 | 657 |
model := Date today asValue. |
658 |
[ |
|
659 |
1 to:50 do:[:i | |
|
660 |
(Delay forSeconds:1) wait. |
|
661 |
model value:(model value addDays:1) |
|
662 |
]. |
|
663 |
top destroy |
|
664 |
] fork. |
|
133 | 665 |
|
593 | 666 |
top := StandardSystemView new. |
667 |
top extent:(200 @ 200). |
|
133 | 668 |
|
593 | 669 |
l := Label in:top. |
670 |
l level:-1. |
|
671 |
l converter:(PrintConverter new initForDate). |
|
672 |
l model:model; labelMessage:#value. |
|
133 | 673 |
|
593 | 674 |
top open |
675 |
[exEnd] |
|
133 | 676 |
|
677 |
||
125 | 678 |
model changes aspect after a while; two labels on the same model: |
593 | 679 |
[exBegin] |
680 |
|top l model| |
|
118 | 681 |
|
593 | 682 |
model := Plug new. |
683 |
model respondTo:#labelValue1 with:['models labelString1']. |
|
684 |
model respondTo:#labelValue2 with:['models labelString2']. |
|
118 | 685 |
|
593 | 686 |
top := StandardSystemView new. |
687 |
top extent:(200 @ 200). |
|
118 | 688 |
|
593 | 689 |
l := Label origin:0.0@0.0 corner:1.0@0.5 in:top. |
690 |
l model:model; aspect:#someAspect; labelMessage:#labelValue1. |
|
691 |
l := Label origin:0.0@0.5 corner:1.0@1.0 in:top. |
|
692 |
l model:model; aspect:#someAspect; labelMessage:#labelValue2. |
|
693 |
||
694 |
top open. |
|
113 | 695 |
|
593 | 696 |
(Delay forSeconds:5) wait. |
697 |
model respondTo:#labelValue1 with:['new string1']. |
|
698 |
model respondTo:#labelValue2 with:['new string2']. |
|
118 | 699 |
|
593 | 700 |
model changed:#someAspect |
701 |
[exEnd] |
|
118 | 702 |
|
703 |
||
125 | 704 |
plugged MVC operation (getBlock returns the label): |
593 | 705 |
[exBegin] |
706 |
|top l model| |
|
118 | 707 |
|
593 | 708 |
model := PluggableAdaptor new |
709 |
getBlock:[:m | 'hello'] |
|
710 |
putBlock:nil |
|
711 |
updateBlock:nil. |
|
118 | 712 |
|
593 | 713 |
top := StandardSystemView new. |
714 |
top extent:(200 @ 200). |
|
118 | 715 |
|
593 | 716 |
l := Label origin:0.0@0.0 corner:1.0@0.5 in:top. |
717 |
l model:model; labelMessage:#value. |
|
118 | 718 |
|
593 | 719 |
top open. |
720 |
[exEnd] |
|
125 | 721 |
|
722 |
||
723 |
use different label-selectors to access fields of a complex model: |
|
593 | 724 |
[exBegin] |
725 |
|top panel model| |
|
125 | 726 |
|
593 | 727 |
model := Plug new. |
728 |
model respondTo:#field1 with:['value1']. |
|
729 |
model respondTo:#field2 with:['value2']. |
|
730 |
model respondTo:#field3 with:['value3']. |
|
731 |
model respondTo:#field4 with:['value4']. |
|
125 | 732 |
|
593 | 733 |
top := StandardSystemView new. |
734 |
||
735 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
736 |
panel elementsChangeSize:true. |
|
125 | 737 |
|
593 | 738 |
panel addSubView:((Label on:model) labelMessage:#field1). |
739 |
panel addSubView:((Label on:model) labelMessage:#field2). |
|
740 |
panel addSubView:((Label on:model) labelMessage:#field3). |
|
741 |
panel addSubView:((Label on:model) labelMessage:#field4). |
|
125 | 742 |
|
593 | 743 |
top extent:(200 @ 200). |
744 |
top open. |
|
125 | 745 |
|
593 | 746 |
(Delay forSeconds:5) wait. |
125 | 747 |
|
593 | 748 |
model respondTo:#field2 with:['new value2']. |
749 |
model changed:#value |
|
750 |
[exEnd] |
|
125 | 751 |
|
752 |
||
753 |
same as above, using default aspects in the label, and an adaptor |
|
754 |
to translate aspects: |
|
593 | 755 |
[exBegin] |
756 |
|top panel model v1| |
|
125 | 757 |
|
593 | 758 |
model := Plug new. |
759 |
model respondTo:#field1 with:[v1]. |
|
760 |
model respondTo:#field1: with:[:arg | v1 := arg. model changed:#field1]. |
|
761 |
model respondTo:#field2 with:['value2']. |
|
762 |
model respondTo:#field2: with:[:arg |]. |
|
763 |
model respondTo:#field3 with:['value3']. |
|
764 |
model respondTo:#field3: with:[:arg |]. |
|
765 |
model respondTo:#field4 with:['value4']. |
|
766 |
model respondTo:#field4: with:[:arg |]. |
|
125 | 767 |
|
593 | 768 |
top := StandardSystemView new. |
125 | 769 |
|
593 | 770 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
771 |
panel elementsChangeSize:true. |
|
772 |
||
773 |
panel addSubView:((Label on:((AspectAdaptor subject:model) forAspect:#field1)) labelMessage:#value). |
|
774 |
panel addSubView:((Label on:((AspectAdaptor subject:model) forAspect:#field2)) labelMessage:#value). |
|
775 |
panel addSubView:((Label on:((AspectAdaptor subject:model) forAspect:#field3)) labelMessage:#value). |
|
776 |
panel addSubView:((Label on:((AspectAdaptor subject:model) forAspect:#field4)) labelMessage:#value). |
|
125 | 777 |
|
593 | 778 |
top extent:(200 @ 200). |
779 |
top open. |
|
125 | 780 |
|
593 | 781 |
(Delay forSeconds:5) wait. |
125 | 782 |
|
593 | 783 |
model field1:'new value1'. |
784 |
[exEnd] |
|
125 | 785 |
|
786 |
||
787 |
use an adapter to access fields of a complex model: |
|
593 | 788 |
[exBegin] |
789 |
|top l panel model| |
|
125 | 790 |
|
593 | 791 |
model := #('one' 'two' 'three') asValue. |
125 | 792 |
|
593 | 793 |
top := StandardSystemView new. |
125 | 794 |
|
593 | 795 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
796 |
panel elementsChangeSize:true. |
|
125 | 797 |
|
593 | 798 |
panel addSubView:((Label on:(ProtocolAdaptor |
799 |
subjectChannel:model |
|
800 |
accessPath:#(1))) labelMessage:#value). |
|
801 |
panel addSubView:((Label on:(ProtocolAdaptor |
|
802 |
subjectChannel:model |
|
803 |
accessPath:#(2))) labelMessage:#value). |
|
804 |
panel addSubView:((Label on:(ProtocolAdaptor |
|
805 |
subjectChannel:model |
|
806 |
accessPath:#(3))) labelMessage:#value). |
|
125 | 807 |
|
593 | 808 |
top extent:(200 @ 200). |
809 |
top open. |
|
125 | 810 |
|
593 | 811 |
(Delay forSeconds:5) wait. |
125 | 812 |
|
593 | 813 |
model value:#('oneone' 'twotwo' 'threethree'). |
814 |
[exEnd] |
|
63 | 815 |
" |
3 | 816 |
! ! |
817 |
||
935 | 818 |
!Label class methodsFor:'instance creation'! |
105 | 819 |
|
820 |
form:aForm |
|
118 | 821 |
"return a new Label showing a form. |
822 |
OBSOLETE: you should now use #label: for both text and bitmap labels." |
|
105 | 823 |
|
2366 | 824 |
<resource:#obsolete> |
825 |
||
1246
9033af51413c
obsolete: #form: / #form:in:
Claus Gittinger <cg@exept.de>
parents:
1242
diff
changeset
|
826 |
self obsoleteMethodWarning:'use #label:'. |
2969
eb87f1aedd6c
Do not use obsolete methods with #form:
Stefan Vogel <sv@exept.de>
parents:
2968
diff
changeset
|
827 |
^ (self onDevice:Screen current) label:aForm |
1246
9033af51413c
obsolete: #form: / #form:in:
Claus Gittinger <cg@exept.de>
parents:
1242
diff
changeset
|
828 |
|
9033af51413c
obsolete: #form: / #form:in:
Claus Gittinger <cg@exept.de>
parents:
1242
diff
changeset
|
829 |
"Modified: 16.6.1997 / 11:47:38 / cg" |
105 | 830 |
! |
831 |
||
832 |
form:aForm in:aView |
|
118 | 833 |
"return a new Label showing a form. |
834 |
OBSOLETE: you should now use #label:in: for both text and bitmap labels." |
|
105 | 835 |
|
2366 | 836 |
<resource:#obsolete> |
837 |
||
1246
9033af51413c
obsolete: #form: / #form:in:
Claus Gittinger <cg@exept.de>
parents:
1242
diff
changeset
|
838 |
self obsoleteMethodWarning:'use #label:in:'. |
2969
eb87f1aedd6c
Do not use obsolete methods with #form:
Stefan Vogel <sv@exept.de>
parents:
2968
diff
changeset
|
839 |
^ (self in:aView) label:aForm |
1246
9033af51413c
obsolete: #form: / #form:in:
Claus Gittinger <cg@exept.de>
parents:
1242
diff
changeset
|
840 |
|
9033af51413c
obsolete: #form: / #form:in:
Claus Gittinger <cg@exept.de>
parents:
1242
diff
changeset
|
841 |
"Modified: 16.6.1997 / 11:47:57 / cg" |
105 | 842 |
! ! |
843 |
||
935 | 844 |
!Label class methodsFor:'defaults'! |
0 | 845 |
|
846 |
defaultExtent |
|
571 | 847 |
"return the default extent of my instances. |
848 |
The value returned here is usually ignored, and |
|
849 |
the value from preferredExtent taken instead." |
|
0 | 850 |
|
851 |
^ 16 @ 16 |
|
571 | 852 |
|
853 |
"Modified: 22.4.1996 / 23:36:11 / cg" |
|
59 | 854 |
! |
855 |
||
2098
22fcc05794eb
accessor for defaultForegroundColor
Claus Gittinger <cg@exept.de>
parents:
1991
diff
changeset
|
856 |
defaultForegroundColor |
22fcc05794eb
accessor for defaultForegroundColor
Claus Gittinger <cg@exept.de>
parents:
1991
diff
changeset
|
857 |
"return the default foregroundColor of my instances." |
22fcc05794eb
accessor for defaultForegroundColor
Claus Gittinger <cg@exept.de>
parents:
1991
diff
changeset
|
858 |
|
22fcc05794eb
accessor for defaultForegroundColor
Claus Gittinger <cg@exept.de>
parents:
1991
diff
changeset
|
859 |
^ DefaultForegroundColor |
22fcc05794eb
accessor for defaultForegroundColor
Claus Gittinger <cg@exept.de>
parents:
1991
diff
changeset
|
860 |
|
22fcc05794eb
accessor for defaultForegroundColor
Claus Gittinger <cg@exept.de>
parents:
1991
diff
changeset
|
861 |
! |
22fcc05794eb
accessor for defaultForegroundColor
Claus Gittinger <cg@exept.de>
parents:
1991
diff
changeset
|
862 |
|
59 | 863 |
updateStyleCache |
440
2beb33cb0146
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
416
diff
changeset
|
864 |
"extract values from the styleSheet and cache them in class variables" |
2beb33cb0146
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
416
diff
changeset
|
865 |
|
1356 | 866 |
<resource: #style (#'label.foregroundColor' #'label.backgroundColor' |
442 | 867 |
#foregroundColor #backgroundColor |
1356 | 868 |
#'label.font')> |
440
2beb33cb0146
added style resource directive
Claus Gittinger <cg@exept.de>
parents:
416
diff
changeset
|
869 |
|
1872 | 870 |
DefaultForegroundColor := StyleSheet colorAt:#'label.foregroundColor'. |
77 | 871 |
DefaultForegroundColor isNil ifTrue:[ |
1374 | 872 |
"/ fallBack: comon value |
1872 | 873 |
DefaultForegroundColor := StyleSheet colorAt:#'foregroundColor' default:Black. |
77 | 874 |
]. |
1872 | 875 |
DefaultBackgroundColor := StyleSheet colorAt:#'label.backgroundColor'. |
77 | 876 |
DefaultBackgroundColor isNil ifTrue:[ |
1374 | 877 |
"/ fallBack: comon value |
1872 | 878 |
DefaultBackgroundColor := StyleSheet colorAt:#'backgroundColor'. |
77 | 879 |
]. |
1872 | 880 |
DefaultFont := StyleSheet fontAt:#'label.font'. |
60 | 881 |
|
882 |
" |
|
883 |
self updateStyleCache |
|
884 |
" |
|
254
aa15cac0670f
oops - foregroundColor was overwritten by backgroundColor (if defined in styleSheet)
Claus Gittinger <cg@exept.de>
parents:
250
diff
changeset
|
885 |
|
1374 | 886 |
"Modified: / 31.10.1997 / 14:53:48 / cg" |
0 | 887 |
! ! |
888 |
||
202 | 889 |
!Label methodsFor:'accessing-channels'! |
105 | 890 |
|
260 | 891 |
labelChannel |
1374 | 892 |
"return the labelChannel - or nil" |
893 |
||
260 | 894 |
^ labelChannel. |
895 |
||
1374 | 896 |
"Created: / 16.12.1995 / 15:50:18 / cg" |
897 |
"Modified: / 31.10.1997 / 14:43:14 / cg" |
|
260 | 898 |
! |
899 |
||
145 | 900 |
labelChannel:aValueHolder |
1374 | 901 |
"set the labelChannel - a valueHolder holding a string or image |
902 |
which is shown as my logo" |
|
903 |
||
146 | 904 |
|prev| |
905 |
||
906 |
prev := labelChannel. |
|
145 | 907 |
labelChannel := aValueHolder. |
1374 | 908 |
self setupChannel:aValueHolder for:nil withOld:prev |
909 |
||
910 |
"Modified: / 31.10.1997 / 14:37:02 / cg" |
|
145 | 911 |
! ! |
912 |
||
202 | 913 |
!Label methodsFor:'accessing-colors'! |
125 | 914 |
|
202 | 915 |
backgroundColor |
916 |
"return the background color" |
|
125 | 917 |
|
202 | 918 |
^ bgColor |
125 | 919 |
! |
920 |
||
202 | 921 |
backgroundColor:aColor |
922 |
"set the background color" |
|
125 | 923 |
|
263 | 924 |
aColor ~~ bgColor ifTrue:[ |
3582 | 925 |
bgColor := aColor. |
926 |
bgColor notNil ifTrue:[ |
|
927 |
bgColor := bgColor onDevice:device. |
|
3597 | 928 |
self class == Label ifTrue:[ |
929 |
super viewBackground:bgColor |
|
930 |
]. |
|
1218 | 931 |
]. |
2913
bdf4fb09cfc0
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2751
diff
changeset
|
932 |
self invalidateRepairNow:true |
263 | 933 |
] |
934 |
||
1414
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
935 |
"Modified: / 15.1.1998 / 00:14:10 / stefan" |
1554
b05a50854c76
redrawNow for visible changes.
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
936 |
"Modified: / 6.6.1998 / 20:01:56 / cg" |
105 | 937 |
! |
938 |
||
2496 | 939 |
etchedForegroundColor |
940 |
"return the etched foreground color (or nil)" |
|
941 |
||
942 |
^ etchedFgColor |
|
943 |
! |
|
944 |
||
945 |
etchedForegroundColor:aColor |
|
946 |
"set the etched foreground color" |
|
947 |
||
948 |
aColor ~~ etchedFgColor ifTrue:[ |
|
949 |
etchedFgColor := aColor. |
|
950 |
etchedFgColor notNil ifTrue:[ |
|
951 |
etchedFgColor := etchedFgColor onDevice:device. |
|
952 |
]. |
|
2913
bdf4fb09cfc0
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2751
diff
changeset
|
953 |
self invalidateRepairNow:true |
2496 | 954 |
]. |
955 |
! |
|
956 |
||
105 | 957 |
foregroundColor |
958 |
"return the foreground color" |
|
959 |
||
960 |
^ fgColor |
|
961 |
! |
|
962 |
||
202 | 963 |
foregroundColor:aColor |
964 |
"set the foreground color" |
|
105 | 965 |
|
263 | 966 |
aColor ~~ fgColor ifTrue:[ |
1414
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
967 |
fgColor := aColor onDevice:device. |
2913
bdf4fb09cfc0
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2751
diff
changeset
|
968 |
self invalidateRepairNow:true |
263 | 969 |
]. |
970 |
||
1414
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
971 |
"Modified: / 15.1.1998 / 00:14:22 / stefan" |
1554
b05a50854c76
redrawNow for visible changes.
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
972 |
"Modified: / 6.6.1998 / 20:02:02 / cg" |
105 | 973 |
! |
974 |
||
975 |
foregroundColor:fg backgroundColor:bg |
|
976 |
"set the colors to be used for drawing" |
|
977 |
||
993 | 978 |
(fgColor ~~ fg or:[bgColor ~~ bg]) ifTrue:[ |
1414
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
979 |
fgColor := fg onDevice:device. |
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
980 |
bgColor := bg onDevice:device. |
1218 | 981 |
self class == Label ifTrue:[ |
1414
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
982 |
super viewBackground:bgColor |
1218 | 983 |
]. |
2913
bdf4fb09cfc0
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2751
diff
changeset
|
984 |
self invalidateRepairNow:true |
993 | 985 |
]. |
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
986 |
|
1414
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
987 |
"Modified: / 15.1.1998 / 00:14:36 / stefan" |
1554
b05a50854c76
redrawNow for visible changes.
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
988 |
"Modified: / 6.6.1998 / 20:02:07 / cg" |
1218 | 989 |
! |
990 |
||
991 |
viewBackground:aColor |
|
992 |
"for labels, the viewBackground is forced to be the same as |
|
993 |
the backgroundColor" |
|
994 |
||
1554
b05a50854c76
redrawNow for visible changes.
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
995 |
super viewBackground:aColor. |
1218 | 996 |
self class == Label ifTrue:[ |
1554
b05a50854c76
redrawNow for visible changes.
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
997 |
self backgroundColor:aColor |
1218 | 998 |
]. |
1554
b05a50854c76
redrawNow for visible changes.
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
999 |
|
b05a50854c76
redrawNow for visible changes.
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
1000 |
"Modified: / 6.6.1998 / 20:02:22 / cg" |
133 | 1001 |
! ! |
1002 |
||
1003 |
!Label methodsFor:'accessing-contents'! |
|
0 | 1004 |
|
202 | 1005 |
form:aForm |
1006 |
"set the labels form; adjust extent if not already realized. |
|
1007 |
OBSOLETE: you should now use #label: for both strings and images" |
|
118 | 1008 |
|
2969
eb87f1aedd6c
Do not use obsolete methods with #form:
Stefan Vogel <sv@exept.de>
parents:
2968
diff
changeset
|
1009 |
<resource:#obsolete> |
eb87f1aedd6c
Do not use obsolete methods with #form:
Stefan Vogel <sv@exept.de>
parents:
2968
diff
changeset
|
1010 |
|
202 | 1011 |
self label:aForm |
1012 |
! |
|
1013 |
||
1014 |
label |
|
1015 |
"return the labels string or image" |
|
1016 |
||
1017 |
^ logo |
|
118 | 1018 |
! |
105 | 1019 |
|
118 | 1020 |
label:aStringOrFormOrImage |
1021 |
"set the labelString or image; adjust extent if not already realized and |
|
1022 |
not fixedSize" |
|
1023 |
||
2639 | 1024 |
|newLogo| |
1025 |
||
1026 |
newLogo := aStringOrFormOrImage. |
|
118 | 1027 |
(aStringOrFormOrImage ~~ logo) ifTrue:[ |
616
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1028 |
"/ |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1029 |
"/ avoid recompute of size, if its an image with |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1030 |
"/ the same size |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1031 |
"/ |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1032 |
aStringOrFormOrImage isImageOrForm ifTrue:[ |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1033 |
logo notNil ifTrue:[ |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1034 |
logo isImageOrForm ifTrue:[ |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1035 |
logo extent = aStringOrFormOrImage extent ifTrue:[ |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1036 |
logo := aStringOrFormOrImage. |
2913
bdf4fb09cfc0
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2751
diff
changeset
|
1037 |
self invalidateRepairNow:true. |
616
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1038 |
^ self |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1039 |
] |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1040 |
] |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1041 |
] |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1042 |
] ifFalse:[ |
2690 | 1043 |
"/ aStringOrFormOrImage notNil ifTrue:[ |
1044 |
"/ newLogo := aStringOrFormOrImage asString. |
|
1045 |
"/ ]. |
|
806
a641ed42df70
dont ignore new label setting, if the emphasis changed
Claus Gittinger <cg@exept.de>
parents:
799
diff
changeset
|
1046 |
"/ any change ? |
2639 | 1047 |
(logo = newLogo) ifTrue:[ |
2706 | 1048 |
(logo isString not |
1049 |
or:[logo emphasis = newLogo emphasis]) ifTrue:[ |
|
2639 | 1050 |
^ self |
806
a641ed42df70
dont ignore new label setting, if the emphasis changed
Claus Gittinger <cg@exept.de>
parents:
799
diff
changeset
|
1051 |
] |
616
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1052 |
] |
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1053 |
]. |
3557
e57daeff04be
changed #label: - fix typo in comment
Stefan Vogel <sv@exept.de>
parents:
3531
diff
changeset
|
1054 |
"/ do not check using #isString here; |
3531 | 1055 |
"/ we allow for non-strings to be used as logo as well (it must understand displayOn:). |
1056 |
newLogo isNumber ifTrue:[ |
|
1057 |
logo := newLogo asString |
|
1058 |
] ifFalse:[ |
|
1059 |
logo := newLogo. |
|
1060 |
]. |
|
1917 | 1061 |
self newLayout. |
1062 |
self repairDamage. |
|
105 | 1063 |
] |
616
f6d4c90abaec
redraw if image-label changes
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
1064 |
|
1554
b05a50854c76
redrawNow for visible changes.
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
1065 |
"Modified: / 6.6.1998 / 19:23:43 / cg" |
105 | 1066 |
! |
0 | 1067 |
|
1367 | 1068 |
label:newLabel suppressResize:suppress |
1069 |
"change the label and optionally suppress a resize operation" |
|
1070 |
||
1071 |
|wasFix| |
|
1072 |
||
1073 |
wasFix := fixSize. |
|
1074 |
suppress ifTrue:[ |
|
1075 |
fixSize := true. |
|
1076 |
]. |
|
1077 |
here label:newLabel. |
|
1078 |
fixSize := wasFix |
|
1079 |
||
1080 |
"Modified: / 29.10.1997 / 15:50:01 / cg" |
|
1081 |
! |
|
1082 |
||
202 | 1083 |
labelString:aString |
1084 |
"for ST-80 compatibility: same as #label: |
|
1085 |
set the label-string; adjust extent if not already realized and not fixedSize" |
|
118 | 1086 |
|
202 | 1087 |
self label:aString |
1088 |
! |
|
1089 |
||
1090 |
labelWidth |
|
1091 |
"return the logos width in pixels" |
|
1092 |
||
1093 |
^ labelWidth |
|
118 | 1094 |
! |
1095 |
||
1096 |
logo:something |
|
1097 |
"set the labels form or string. |
|
1098 |
OBSOLETE: the old version used #form: for images and #label: for strings. |
|
2969
eb87f1aedd6c
Do not use obsolete methods with #form:
Stefan Vogel <sv@exept.de>
parents:
2968
diff
changeset
|
1099 |
you should now use #label: for any." |
eb87f1aedd6c
Do not use obsolete methods with #form:
Stefan Vogel <sv@exept.de>
parents:
2968
diff
changeset
|
1100 |
|
eb87f1aedd6c
Do not use obsolete methods with #form:
Stefan Vogel <sv@exept.de>
parents:
2968
diff
changeset
|
1101 |
<resource:#obsolete> |
118 | 1102 |
|
1103 |
self label:something |
|
133 | 1104 |
! ! |
1105 |
||
1106 |
!Label methodsFor:'accessing-layout'! |
|
1107 |
||
202 | 1108 |
adjust |
1921 | 1109 |
"return the adjust symbol. See #adjust: for an explanation." |
0 | 1110 |
|
202 | 1111 |
^ adjust |
125 | 1112 |
! |
1113 |
||
105 | 1114 |
adjust:how |
1115 |
"set the adjust, how which must be one of |
|
0 | 1116 |
|
105 | 1117 |
#left -> left adjust logo |
1118 |
#right -> right adjust logo |
|
1119 |
#center -> center logo |
|
1945 | 1120 |
#centerEach -> like #center, but if its a multiline logo, |
1121 |
center each line individually. |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1122 |
|
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1123 |
#centerRight -> center logo if it fits; |
533 | 1124 |
BUT, if it does not fit, right adjust the logo |
1125 |
(use with filenames, where the interesting part is |
|
1126 |
at the right if the label is too small) |
|
1127 |
||
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1128 |
#centerLeft -> center logo if it fits; |
533 | 1129 |
BUT, if it does not fit, left adjust the logo |
1130 |
(use with strings where the interesting part is at the |
|
1131 |
left if the label is too small) |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1132 |
|
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1133 |
#leftRight -> left adjust logo if it fits |
533 | 1134 |
BUT, if it does not fit, right adjust the logo |
1135 |
(use with filenames, where the interesting part is |
|
1136 |
at the right if the label is too small) |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1137 |
|
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1138 |
#rightLeft -> right adjust logo if it fits |
533 | 1139 |
BUT, if it does not fit, left adjust the logo |
1140 |
(use with strings where the interesting part is at the |
|
1141 |
left if the label is too small) |
|
1142 |
||
1143 |
See examples in the documentation category. |
|
105 | 1144 |
" |
118 | 1145 |
|
105 | 1146 |
(adjust ~~ how) ifTrue:[ |
533 | 1147 |
adjust := how. |
1148 |
self newLayout |
|
105 | 1149 |
] |
533 | 1150 |
|
1151 |
"Modified: 13.4.1996 / 11:17:58 / cg" |
|
105 | 1152 |
! |
1153 |
||
202 | 1154 |
font:aFont |
665 | 1155 |
"set the font - if I'm not realized and not fixedSize, adjust my size. |
1156 |
CAVEAT: with the addition of Text objects, |
|
1157 |
this method is going to be obsoleted by a textStyle |
|
1158 |
method, which allows specific control over |
|
1159 |
normalFont/boldFont/italicFont parameters." |
|
125 | 1160 |
|
416 | 1161 |
(aFont notNil and:[aFont ~~ font]) ifTrue:[ |
1991 | 1162 |
super font:(aFont onDevice:device). |
416 | 1163 |
self newLayout |
202 | 1164 |
] |
416 | 1165 |
|
665 | 1166 |
"Modified: 22.5.1996 / 12:36:29 / cg" |
133 | 1167 |
! |
1168 |
||
1169 |
horizontalSpace:aNumber |
|
1170 |
"set the number of pixels by which the logo |
|
1171 |
is horizontally inset from the border" |
|
1172 |
||
162 | 1173 |
hSpace := aNumber. |
1174 |
self newLayout |
|
133 | 1175 |
! |
1176 |
||
202 | 1177 |
layout:something |
1178 |
"OBSOLETE compatibility interface. Will vanish. |
|
1179 |
for protocol compatibility: alias for #adjust:. |
|
1180 |
Please use #adjust:, since #layout: conflicts with a method |
|
1181 |
in VW (which has a completely different meaning). |
|
1182 |
In future versions of ST/X, #layout: will behave the VW way. |
|
1183 |
In the meantime, try to figure out what is meant ... a kludge" |
|
1184 |
||
2366 | 1185 |
<resource:#obsolete> |
1186 |
||
3215 | 1187 |
something isSymbol ifFalse:[^ super layout:something]. |
202 | 1188 |
|
1189 |
self obsoleteMethodWarning:'use #adjust:'. |
|
1190 |
self adjust:something |
|
1191 |
||
1192 |
"Modified: 31.8.1995 / 23:08:13 / claus" |
|
1193 |
! |
|
1194 |
||
1195 |
sizeFixed |
|
1196 |
"return the fix-size attribute" |
|
1197 |
||
1198 |
^ fixSize |
|
1199 |
! |
|
1200 |
||
1201 |
sizeFixed:aBoolean |
|
1202 |
"set/clear the fix-size attribute. |
|
1203 |
If true, the receiver will not change its size when the labelString/logo |
|
1204 |
changes. If false (the default), it will resize itself to make the logo |
|
1205 |
fit." |
|
1206 |
||
1207 |
fixSize := aBoolean |
|
1208 |
! |
|
1209 |
||
1210 |
verticalSpace:aNumber |
|
1211 |
"set the number of pixels by which the logo |
|
1212 |
is vertically inset from the border" |
|
1213 |
||
1214 |
vSpace := aNumber. |
|
1215 |
self newLayout |
|
1216 |
! ! |
|
1217 |
||
1218 |
!Label methodsFor:'accessing-mvc'! |
|
1219 |
||
1220 |
addModelInterfaceTo:aDictionary |
|
1221 |
"see comment in View>>modelInterface" |
|
1222 |
||
1223 |
super addModelInterfaceTo:aDictionary. |
|
1224 |
aDictionary at:#labelMessage put:labelMsg |
|
1225 |
! |
|
1226 |
||
1227 |
converter:aConverter |
|
1228 |
"set the printConverter; |
|
1229 |
that one is asked to convert the models value to a printed |
|
1230 |
representation (if non-nil). If nil, the model is supposed to |
|
1231 |
return a string or bitmap image." |
|
1232 |
||
1233 |
converter := aConverter |
|
1234 |
! |
|
105 | 1235 |
|
202 | 1236 |
labelMessage |
1237 |
"return the symbol used to aquire the labelString/image from the model |
|
1238 |
when the aspect changes. |
|
1239 |
The default is nil, which means: leave the label unchanged." |
|
1240 |
||
1241 |
^ labelMsg |
|
1242 |
! |
|
1243 |
||
1244 |
labelMessage:aSymbol |
|
1245 |
"set the symbol used to aquire the labelString/image from the model. |
|
1246 |
The default is nil, which means: leave the label unchanged." |
|
1247 |
||
1248 |
labelMsg ~~ aSymbol ifTrue:[ |
|
1249 |
labelMsg := aSymbol. |
|
1250 |
self getLabelFromModel |
|
1251 |
] |
|
1252 |
! |
|
1253 |
||
1254 |
model:aModel |
|
1255 |
super model:aModel. |
|
1039 | 1256 |
labelMsg notNil ifTrue:[ |
1257 |
self getLabelFromModel. |
|
1258 |
] |
|
202 | 1259 |
! ! |
1260 |
||
1261 |
!Label methodsFor:'change & update'! |
|
1262 |
||
1263 |
update:something with:aParameter from:changedObject |
|
1264 |
"the MVC way of changing the label ..." |
|
1265 |
||
1374 | 1266 |
changedObject notNil ifTrue:[ |
1267 |
changedObject == labelChannel ifTrue:[ |
|
1268 |
self label:(labelChannel value). |
|
1269 |
^ self |
|
1270 |
]. |
|
1271 |
||
1272 |
changedObject == model ifTrue:[ |
|
1273 |
something == aspectMsg ifTrue:[ |
|
1274 |
self getLabelFromModel. |
|
1275 |
^ self. |
|
1276 |
] |
|
1277 |
]. |
|
202 | 1278 |
]. |
1279 |
^ super update:something with:aParameter from:changedObject |
|
1374 | 1280 |
|
1281 |
"Modified: / 31.10.1997 / 14:32:02 / cg" |
|
1828 | 1282 |
"Modified: / 30.3.1999 / 13:57:26 / stefan" |
202 | 1283 |
! ! |
1284 |
||
1285 |
!Label methodsFor:'event handling'! |
|
1286 |
||
1287 |
sizeChanged:how |
|
1288 |
"sent whenever size is changed by someone else - recompute the |
|
1289 |
logos position within the View." |
|
1290 |
||
1508
15d1b3e7e92a
oops - resize in Y must redraw
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
1291 |
|prevX prevY| |
202 | 1292 |
|
1293 |
super sizeChanged:how. |
|
1508
15d1b3e7e92a
oops - resize in Y must redraw
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
1294 |
|
15d1b3e7e92a
oops - resize in Y must redraw
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
1295 |
prevX := labelOriginX. |
15d1b3e7e92a
oops - resize in Y must redraw
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
1296 |
prevY := labelOriginY. |
1392 | 1297 |
self computeLabelOrigin. |
202 | 1298 |
shown ifTrue:[ |
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1299 |
(adjust == #fit |
1508
15d1b3e7e92a
oops - resize in Y must redraw
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
1300 |
or:[labelOriginX ~~ prevX |
15d1b3e7e92a
oops - resize in Y must redraw
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
1301 |
or:[labelOriginY ~~ prevY |
15d1b3e7e92a
oops - resize in Y must redraw
Claus Gittinger <cg@exept.de>
parents:
1428
diff
changeset
|
1302 |
or:[how ~~ #smaller]]]) ifTrue:[ |
1509 | 1303 |
"/ self clear. |
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1304 |
self invalidate. |
1509 | 1305 |
"/ self redrawEdges |
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1306 |
] |
105 | 1307 |
] |
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1308 |
|
1509 | 1309 |
"Modified: / 28.4.1998 / 17:07:57 / cg" |
0 | 1310 |
! ! |
1311 |
||
1867
d27de2b0705c
dont take the focus on click
Claus Gittinger <cg@exept.de>
parents:
1857
diff
changeset
|
1312 |
!Label methodsFor:'focus handling'! |
d27de2b0705c
dont take the focus on click
Claus Gittinger <cg@exept.de>
parents:
1857
diff
changeset
|
1313 |
|
d27de2b0705c
dont take the focus on click
Claus Gittinger <cg@exept.de>
parents:
1857
diff
changeset
|
1314 |
wantsFocusWithButtonPress |
d27de2b0705c
dont take the focus on click
Claus Gittinger <cg@exept.de>
parents:
1857
diff
changeset
|
1315 |
self class == Label ifTrue:[^ false]. |
d27de2b0705c
dont take the focus on click
Claus Gittinger <cg@exept.de>
parents:
1857
diff
changeset
|
1316 |
^ super wantsFocusWithButtonPress |
d27de2b0705c
dont take the focus on click
Claus Gittinger <cg@exept.de>
parents:
1857
diff
changeset
|
1317 |
|
d27de2b0705c
dont take the focus on click
Claus Gittinger <cg@exept.de>
parents:
1857
diff
changeset
|
1318 |
|
d27de2b0705c
dont take the focus on click
Claus Gittinger <cg@exept.de>
parents:
1857
diff
changeset
|
1319 |
! ! |
d27de2b0705c
dont take the focus on click
Claus Gittinger <cg@exept.de>
parents:
1857
diff
changeset
|
1320 |
|
2751 | 1321 |
!Label methodsFor:'initialization & release'! |
0 | 1322 |
|
935 | 1323 |
fetchDeviceResources |
1324 |
"fetch device colors, to avoid reallocation at redraw time" |
|
1325 |
||
1326 |
super fetchDeviceResources. |
|
1327 |
||
1414
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
1328 |
fgColor := fgColor onDevice:device. |
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
1329 |
bgColor := bgColor onDevice:device. |
935 | 1330 |
|
1414
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
1331 |
"Created: / 13.1.1997 / 23:34:30 / cg" |
b86d8f36f3a9
Use Color>>onDevice: instead of obsolete Color>>on:
Stefan Vogel <sv@exept.de>
parents:
1398
diff
changeset
|
1332 |
"Modified: / 15.1.1998 / 00:13:46 / stefan" |
935 | 1333 |
! |
1334 |
||
0 | 1335 |
initStyle |
967 | 1336 |
"setup viewStyle specifics" |
1337 |
||
0 | 1338 |
super initStyle. |
1339 |
||
392
81343306d796
eliminated all DefaultFont classVars (are now classINSTvars)
Claus Gittinger <cg@exept.de>
parents:
391
diff
changeset
|
1340 |
"/ DefaultFont notNil ifTrue:[font := DefaultFont on:device]. |
81343306d796
eliminated all DefaultFont classVars (are now classINSTvars)
Claus Gittinger <cg@exept.de>
parents:
391
diff
changeset
|
1341 |
|
59 | 1342 |
DefaultBackgroundColor notNil ifTrue:[ |
935 | 1343 |
bgColor := DefaultBackgroundColor |
38 | 1344 |
] ifFalse:[ |
935 | 1345 |
bgColor := viewBackground. |
59 | 1346 |
]. |
1347 |
DefaultForegroundColor notNil ifTrue:[ |
|
935 | 1348 |
fgColor := DefaultForegroundColor |
59 | 1349 |
] ifFalse:[ |
935 | 1350 |
fgColor := Black. |
1374 | 1351 |
]. |
1352 |
self class == Label ifTrue:[ |
|
1353 |
borderWidth := 0. |
|
38 | 1354 |
] |
935 | 1355 |
|
1374 | 1356 |
"Modified: / 31.10.1997 / 14:57:23 / cg" |
0 | 1357 |
! |
1358 |
||
105 | 1359 |
initialize |
1360 |
super initialize. |
|
1361 |
||
1991 | 1362 |
font := font onDevice:device. |
832 | 1363 |
self initialHeight:(font height + font descent). |
105 | 1364 |
adjust := #center. |
118 | 1365 |
labelOriginX := labelOriginY := 0. |
1366 |
labelWidth := labelHeight := 0. |
|
105 | 1367 |
logo := nil. |
1368 |
fixSize := false. |
|
1369 |
hSpace := (self horizontalPixelPerMillimeter:0.5) rounded. |
|
131 | 1370 |
vSpace := (self verticalPixelPerMillimeter:0.25) rounded |
105 | 1371 |
! |
1372 |
||
0 | 1373 |
recreate |
2258 | 1374 |
"after snapin or a migration, labels dimensions may have changed due to |
0 | 1375 |
different font parameters" |
1376 |
||
1377 |
super recreate. |
|
1991 | 1378 |
font := font onDevice:device. |
0 | 1379 |
self computeLabelSize. |
1380 |
self computeLabelOrigin |
|
2592 | 1381 |
! |
1382 |
||
1383 |
release |
|
1384 |
labelChannel notNil ifTrue:[ |
|
1385 |
labelChannel removeDependent:self. |
|
1386 |
labelChannel := nil. |
|
1387 |
]. |
|
1388 |
super release |
|
0 | 1389 |
! ! |
1390 |
||
202 | 1391 |
!Label methodsFor:'private'! |
1392 |
||
1393 |
computeLabelOrigin |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1394 |
"(re)compute the origin of the label whenever label, font or view-size changes" |
202 | 1395 |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1396 |
|x y a| |
202 | 1397 |
|
1398 |
labelHeight isNil ifTrue:[^ self]. |
|
1399 |
||
1400 |
adjust == #fit ifTrue:[ |
|
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1401 |
labelOriginX := labelOriginY := margin. |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1402 |
^ self |
202 | 1403 |
]. |
1404 |
||
1405 |
"if it does not fit, should we make the origin visible, |
|
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1406 |
or the center ? |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1407 |
(for text, the center seems better. |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1408 |
For images, I dont really know ...) |
202 | 1409 |
The commented code below makes the origin visible |
1410 |
" |
|
1411 |
"/ (labelHeight < height) ifTrue:[ |
|
1412 |
"/ y := (height - labelHeight) // 2 |
|
1413 |
"/ ] ifFalse:[ |
|
1414 |
"/ y := 0 |
|
1415 |
"/ ]. |
|
1416 |
||
1417 |
"always center vertically" |
|
1418 |
y := (height - labelHeight) // 2. |
|
1419 |
||
1420 |
labelOriginY := y. |
|
1421 |
||
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1422 |
a := adjust. |
1945 | 1423 |
a == #centerEach ifTrue:[a := #center]. |
1424 |
||
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1425 |
(width < labelWidth) ifTrue:[ |
1921 | 1426 |
((a == #centerRight) or:[a == #leftRight]) ifTrue:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1427 |
a := #right |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1428 |
] ifFalse:[ |
1921 | 1429 |
((a == #centerLeft) or:[a == #rightLeft]) ifTrue:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1430 |
a := #left |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1431 |
]. |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1432 |
] |
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1433 |
] ifFalse:[ |
1921 | 1434 |
((a == #centerRight) or:[a == #centerLeft]) ifTrue:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1435 |
a := #center |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1436 |
] ifFalse:[ |
1921 | 1437 |
a == #leftRight ifTrue:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1438 |
a := #left |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1439 |
] ifFalse:[ |
1921 | 1440 |
a == #rightLeft ifTrue:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1441 |
a := #right |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1442 |
] |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1443 |
] |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1444 |
] |
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1445 |
]. |
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1446 |
|
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1447 |
(a == #center) ifTrue:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1448 |
" center text/form in button " |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1449 |
x := (width - labelWidth) // 2. |
202 | 1450 |
] ifFalse:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1451 |
(a == #left) ifTrue:[ |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1452 |
x := margin |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1453 |
] ifFalse:[ |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1454 |
"/ #right |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1455 |
x := width - labelWidth - margin |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1456 |
] |
202 | 1457 |
]. |
1458 |
labelOriginX := x |
|
318
73ea409232c0
new adjusts: #leftRight and #rightLeft (sounds wierd - mhmh)
Claus Gittinger <cg@exept.de>
parents:
304
diff
changeset
|
1459 |
|
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1460 |
"Modified: 13.5.1996 / 10:55:17 / cg" |
202 | 1461 |
! |
1462 |
||
1463 |
computeLabelSize |
|
1464 |
"compute the extent needed to hold the label; aForm or aString" |
|
1465 |
||
1284 | 1466 |
|numberOfLines textHeight textWidth b| |
202 | 1467 |
|
1468 |
logo isNil ifTrue:[^ self]. |
|
1469 |
||
1470 |
logo isString ifTrue:[ |
|
626 | 1471 |
numberOfLines := 1 + (logo occurrencesOf:(Character cr)). |
1472 |
(numberOfLines ~~ 1) ifTrue:[ |
|
1473 |
logo := logo asStringCollection |
|
1474 |
] |
|
202 | 1475 |
] ifFalse:[ |
1754
e93ca7cf9d17
eliminated some #isKindOf: calls.
Claus Gittinger <cg@exept.de>
parents:
1679
diff
changeset
|
1476 |
(logo isStringCollection) ifTrue:[ |
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1477 |
numberOfLines := logo size. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1478 |
(numberOfLines <= 1) ifTrue:[ |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1479 |
logo := logo asString |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1480 |
] |
626 | 1481 |
] |
202 | 1482 |
]. |
1483 |
||
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1484 |
numberOfLines isNil ifTrue:[ |
3490 | 1485 |
"logo is neither a String nor a StringCollection" |
756 | 1486 |
(logo respondsTo:#preferredBounds) ifTrue:[ |
1487 |
b := logo preferredBounds. |
|
1488 |
labelWidth := b width. |
|
1489 |
labelHeight := b height. |
|
1490 |
] ifFalse:[ |
|
2704
9cd14ade263d
reset have to ask the device for fonts in computeLabelSize
penk
parents:
2703
diff
changeset
|
1491 |
labelWidth := logo widthOn:self. |
9cd14ade263d
reset have to ask the device for fonts in computeLabelSize
penk
parents:
2703
diff
changeset
|
1492 |
labelHeight := logo heightOn:self. |
756 | 1493 |
]. |
640 | 1494 |
|
1495 |
"/ b := logo bounds. |
|
1496 |
"/ labelWidth := b right. |
|
1497 |
"/ labelHeight := b bottom. |
|
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1498 |
logo isImageOrForm ifFalse:[ |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1499 |
labelWidth := labelWidth + (hSpace * 2). |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1500 |
labelHeight := labelHeight + (vSpace * 2). |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1501 |
]. |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1502 |
|
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1503 |
^ self |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1504 |
]. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1505 |
|
202 | 1506 |
"/ textHeight := font height * numberOfLines + font descent. |
626 | 1507 |
|
640 | 1508 |
logo isString ifTrue:[ |
1509 |
"/ a string or Text |
|
1510 |
textHeight := logo heightOn:self. |
|
1511 |
textWidth := logo widthOn:self. |
|
1512 |
] ifFalse:[ |
|
1513 |
"/ a StringCollection |
|
1514 |
textHeight := font height * numberOfLines. |
|
794 | 1515 |
"/ textWidth := font widthOf:logo. |
1516 |
||
1517 |
textWidth := 0. |
|
1518 |
logo do:[:line | |
|
1519 |
|this| |
|
1520 |
||
1521 |
line notNil ifTrue:[ |
|
1522 |
this := line asString widthOn:self. |
|
1523 |
(this > textWidth) ifTrue:[textWidth := this] |
|
1524 |
] |
|
1525 |
]. |
|
640 | 1526 |
]. |
1527 |
||
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1528 |
labelWidth := textWidth + (hSpace * 2). |
202 | 1529 |
labelHeight := textHeight + (vSpace * 2) |
626 | 1530 |
|
794 | 1531 |
"Modified: 17.7.1996 / 14:33:10 / cg" |
202 | 1532 |
! |
1533 |
||
1534 |
getLabelFromModel |
|
1535 |
"ask my model for the label to show. |
|
1536 |
Here, we use labelMsg (instead of aspectMsg). |
|
1537 |
This allows multiple labels to react on the same aspect, |
|
1538 |
but show different labels when changed |
|
1539 |
(also, since labelMsg defaults to nil, constant labels |
|
1540 |
which have a nil labelMsg will not try to aquire a labelString)." |
|
1541 |
||
1542 |
|val| |
|
1543 |
||
1544 |
(model notNil |
|
1545 |
and:[labelMsg notNil]) ifTrue:[ |
|
1546 |
val := model perform:labelMsg. |
|
1547 |
converter notNil ifTrue:[ |
|
1548 |
val := converter printStringFor:val |
|
1549 |
]. |
|
1550 |
self label:val. |
|
1551 |
]. |
|
1552 |
! |
|
1553 |
||
1554 |
newLayout |
|
1555 |
"recompute position/size after a change |
|
1556 |
- helper for form:/font: etc." |
|
1557 |
||
1558 |
self computeLabelSize. |
|
3499 | 1559 |
|
202 | 1560 |
fixSize ifFalse:[ |
3499 | 1561 |
self resize. |
1562 |
] ifTrue:[ |
|
1563 |
self computeLabelOrigin. |
|
202 | 1564 |
]. |
2913
bdf4fb09cfc0
invalidate checks itself for shown-flag
Claus Gittinger <cg@exept.de>
parents:
2751
diff
changeset
|
1565 |
self invalidate |
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
665
diff
changeset
|
1566 |
|
1554
b05a50854c76
redrawNow for visible changes.
Claus Gittinger <cg@exept.de>
parents:
1509
diff
changeset
|
1567 |
"Modified: / 6.6.1998 / 19:23:45 / cg" |
202 | 1568 |
! ! |
1569 |
||
1570 |
!Label methodsFor:'queries'! |
|
1571 |
||
1572 |
preferredExtent |
|
1573 |
"return my preferred extent - this is the minimum size I would like to have" |
|
1574 |
||
1575 |
|extra| |
|
1576 |
||
799 | 1577 |
"/ If I have an explicit preferredExtent .. |
1578 |
||
713
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
1579 |
preferredExtent notNil ifTrue:[ |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
1580 |
^ preferredExtent |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
1581 |
]. |
0c38ad51016d
care for preSet preferredExtent
Claus Gittinger <cg@exept.de>
parents:
711
diff
changeset
|
1582 |
|
361
b5cb40f55316
if size is fixed, return my actual size in #preferredExtent
ca
parents:
318
diff
changeset
|
1583 |
fixSize ifTrue:[^ self extent]. |
b5cb40f55316
if size is fixed, return my actual size in #preferredExtent
ca
parents:
318
diff
changeset
|
1584 |
|
303
8408cec09472
if undefined, set label to empty string when asked for preferredExtent (would otherwise return 0@0)
ah
parents:
275
diff
changeset
|
1585 |
logo isNil ifTrue:[ |
361
b5cb40f55316
if size is fixed, return my actual size in #preferredExtent
ca
parents:
318
diff
changeset
|
1586 |
self label:'' |
202 | 1587 |
]. |
1588 |
||
303
8408cec09472
if undefined, set label to empty string when asked for preferredExtent (would otherwise return 0@0)
ah
parents:
275
diff
changeset
|
1589 |
logo notNil ifTrue:[ |
361
b5cb40f55316
if size is fixed, return my actual size in #preferredExtent
ca
parents:
318
diff
changeset
|
1590 |
extra := margin * 2. |
b5cb40f55316
if size is fixed, return my actual size in #preferredExtent
ca
parents:
318
diff
changeset
|
1591 |
^ (labelWidth + extra + hSpace) @ (labelHeight + extra + vSpace) |
303
8408cec09472
if undefined, set label to empty string when asked for preferredExtent (would otherwise return 0@0)
ah
parents:
275
diff
changeset
|
1592 |
]. |
8408cec09472
if undefined, set label to empty string when asked for preferredExtent (would otherwise return 0@0)
ah
parents:
275
diff
changeset
|
1593 |
|
202 | 1594 |
^ super preferredExtent |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1595 |
|
799 | 1596 |
"Modified: 19.7.1996 / 20:44:41 / cg" |
993 | 1597 |
! |
1598 |
||
1599 |
redrawsFull |
|
1600 |
^ true |
|
1601 |
||
1602 |
"Created: 7.2.1997 / 16:41:41 / cg" |
|
202 | 1603 |
! ! |
1604 |
||
0 | 1605 |
!Label methodsFor:'redrawing'! |
1606 |
||
77 | 1607 |
clearInsideWith:bg |
1608 |
|cutOff mustClear| |
|
0 | 1609 |
|
1610 |
cutOff := margin * 2. |
|
1611 |
||
3 | 1612 |
mustClear := true. |
1613 |
||
87 | 1614 |
(logo notNil and:[logo isImageOrForm]) ifTrue:[ |
59 | 1615 |
(labelOriginX == 0 and:[labelOriginY == 0]) ifTrue:[ |
1616 |
logo width >= (width - cutOff) ifTrue:[ |
|
1617 |
logo height >= (height - cutOff) ifTrue:[ |
|
1618 |
"no need to clear before - avoid flicker" |
|
1619 |
mustClear := false |
|
1620 |
] |
|
1621 |
] |
|
1622 |
]. |
|
3 | 1623 |
]. |
1624 |
||
1625 |
mustClear ifTrue:[ |
|
59 | 1626 |
self paint:bg. |
1627 |
self fillRectangleX:margin y:margin |
|
1628 |
width:(width - cutOff) |
|
1629 |
height:(height - cutOff). |
|
3 | 1630 |
]. |
77 | 1631 |
! |
1632 |
||
1679 | 1633 |
drawWin95FocusFrame |
1891 | 1634 |
|m1 m2| |
1635 |
||
1636 |
m1 := margin + 1. |
|
1637 |
m2 := margin + margin + 2. |
|
1679 | 1638 |
self |
1891 | 1639 |
displayDottedRectangleX:m1 |
1640 |
y:m1 |
|
1641 |
width:(width - m2) |
|
1642 |
height:(height - m2). |
|
1679 | 1643 |
|
1644 |
"Created: / 17.9.1998 / 14:16:46 / cg" |
|
1891 | 1645 |
"Modified: / 29.4.1999 / 21:49:22 / cg" |
1679 | 1646 |
! |
1647 |
||
77 | 1648 |
drawWith:fg and:bg |
1649 |
"redraw my label with fg/bg - this generic method is also used by subclasses |
|
1650 |
(especially Button) to redraw the logo in different colors." |
|
1651 |
||
2496 | 1652 |
self drawWith:fg and:bg clearInside:true etchedFg:etchedFgColor. |
1653 |
! |
|
1654 |
||
1655 |
drawWith:fg and:bg clearInside:doClear etchedFg:etchedFg |
|
1656 |
"redraw my label with fg/bg - this generic method is also used by subclasses |
|
1657 |
(especially Button) to redraw the logo in different colors." |
|
1658 |
||
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1659 |
|x y scaleH scaleV nW nH hSep vSep m2 stringLogo| |
77 | 1660 |
|
2496 | 1661 |
doClear ifTrue:[self clearInsideWith:bg]. |
0 | 1662 |
|
3633
c9eacbe73abb
fg/bg setting is needed as a sideeffect in order
Claus Gittinger <cg@exept.de>
parents:
3615
diff
changeset
|
1663 |
self paint:fg on:bg. |
0 | 1664 |
logo notNil ifTrue:[ |
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1665 |
m2 := margin * 2. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1666 |
hSep := (hSpace*2). |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1667 |
vSep := (vSpace*2). |
133 | 1668 |
|
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1669 |
x := labelOriginX. |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1670 |
y := labelOriginY. |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1671 |
|
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1672 |
logo isImageOrForm ifTrue:[ |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1673 |
adjust == #fit ifTrue:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1674 |
"/ |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1675 |
"/ change scale to make the logo fit exactly |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1676 |
"/ |
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1677 |
scaleH := ((width - hSep) / (logo width)) asFloat. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1678 |
scaleV := ((height - vSep) / (logo height)) asFloat. |
2968 | 1679 |
scaleH <= 0 ifTrue:[scaleH := Float epsilon]. |
1680 |
scaleV <= 0 ifTrue:[scaleV := Float epsilon]. |
|
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1681 |
self scale:(scaleH @ scaleV). |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1682 |
x := transformation applyInverseScaleX:x. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1683 |
y := transformation applyInverseScaleY:y. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1684 |
]. |
131 | 1685 |
|
1242 | 1686 |
logo := logo onDevice:device. |
59 | 1687 |
"/ self background:bg. |
2496 | 1688 |
(doClear not or:[logo mask notNil]) ifTrue:[ |
1089
abb0c3d4b5f4
masked images must be drawn different.
Claus Gittinger <cg@exept.de>
parents:
1039
diff
changeset
|
1689 |
self displayForm:logo x:x y:y |
abb0c3d4b5f4
masked images must be drawn different.
Claus Gittinger <cg@exept.de>
parents:
1039
diff
changeset
|
1690 |
] ifFalse:[ |
abb0c3d4b5f4
masked images must be drawn different.
Claus Gittinger <cg@exept.de>
parents:
1039
diff
changeset
|
1691 |
self displayOpaqueForm:logo x:x y:y |
abb0c3d4b5f4
masked images must be drawn different.
Claus Gittinger <cg@exept.de>
parents:
1039
diff
changeset
|
1692 |
] |
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1693 |
] ifFalse:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1694 |
x := x + hSpace. |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1695 |
y := y + vSpace. |
0 | 1696 |
|
1665 | 1697 |
level < 0 ifTrue:[ |
1698 |
x := x + 1. |
|
1699 |
y := y + 1 |
|
1659
9b2b15f77813
with positive level, draw string label offset by one pixel.
Claus Gittinger <cg@exept.de>
parents:
1650
diff
changeset
|
1700 |
]. |
9b2b15f77813
with positive level, draw string label offset by one pixel.
Claus Gittinger <cg@exept.de>
parents:
1650
diff
changeset
|
1701 |
|
1428 | 1702 |
(logo isString |
1703 |
or:[logo species == String |
|
1754
e93ca7cf9d17
eliminated some #isKindOf: calls.
Claus Gittinger <cg@exept.de>
parents:
1679
diff
changeset
|
1704 |
or:[logo isStringCollection]]) ifTrue:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1705 |
stringLogo := true. |
3049 | 1706 |
y := y + (font ascentOn:device). |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1707 |
] ifFalse:[ |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1708 |
stringLogo := false. |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1709 |
]. |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1710 |
|
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1711 |
adjust == #fit ifTrue:[ |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1712 |
"/ |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1713 |
"/ change scale to make the logo fit exactly |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1714 |
"/ |
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1715 |
scaleH := ((width - m2 - hSep) / (labelWidth - hSpace)) asFloat. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1716 |
scaleV := ((height - m2 - vSep) / (labelHeight - vSpace)) asFloat. |
2968 | 1717 |
scaleH <= 0 ifTrue:[scaleH := Float epsilon]. |
1718 |
scaleV <= 0 ifTrue:[scaleV := Float epsilon]. |
|
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1719 |
|
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1720 |
self scale:(scaleH min:scaleV). |
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1721 |
x := transformation applyInverseScaleX:x. |
639
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1722 |
stringLogo ifTrue:[ |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1723 |
y := y - font ascent + (transformation applyScaleY:font ascent). |
26c56f23fa19
fixed to have VisualComponents usable as label
Claus Gittinger <cg@exept.de>
parents:
636
diff
changeset
|
1724 |
]. |
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1725 |
y := transformation applyInverseScaleY:y. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1726 |
scaleH < scaleV ifTrue:[ |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1727 |
nH := labelHeight * scaleH. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1728 |
"/ now, center vertically |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1729 |
y := y + ((height - nH - m2 - vSep) / scaleH / 2). |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1730 |
]. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1731 |
scaleV < scaleH ifTrue:[ |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1732 |
"/ now, center horizontally |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1733 |
nW := labelWidth * scaleV. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1734 |
x := x + ((width - nW - m2 - hSep) / scaleV / 2) |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1735 |
]. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1736 |
]. |
131 | 1737 |
|
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1738 |
logo isString ifTrue:[ |
2496 | 1739 |
"/ doClear ifTrue:[ |
1740 |
"/ self displayOpaqueString:logo x:x y:y |
|
1741 |
"/ ] ifFalse:[ |
|
1742 |
"/ self displayString:logo x:x y:y |
|
1743 |
"/ ] |
|
1744 |
etchedFg notNil ifTrue:[ |
|
1745 |
self paint:etchedFg. |
|
1746 |
self displayString:logo x:x+1 y:y+1. |
|
1747 |
self paint:fg. |
|
1748 |
]. |
|
1749 |
self displayString:logo x:x y:y |
|
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1750 |
] ifFalse:[ |
1754
e93ca7cf9d17
eliminated some #isKindOf: calls.
Claus Gittinger <cg@exept.de>
parents:
1679
diff
changeset
|
1751 |
(logo isStringCollection) ifTrue:[ |
2496 | 1752 |
logo do:[ :line | |
1753 |
|wThis str| |
|
1754 |
||
1945 | 1755 |
adjust == #centerEach ifTrue:[ |
1756 |
wThis := line asString widthOn:self. |
|
1757 |
x := (width - wThis) // 2. |
|
1758 |
]. |
|
2496 | 1759 |
str := line printString. |
1760 |
"/ doClear ifTrue:[ |
|
1761 |
"/ self displayOpaqueString:str x:x y:y. |
|
1762 |
"/ ] ifFalse:[ |
|
1763 |
"/ self displayString:str x:x y:y. |
|
1764 |
"/ ]. |
|
1765 |
etchedFg notNil ifTrue:[ |
|
1766 |
self paint:etchedFg. |
|
1767 |
self displayString:str x:x+1 y:y+1. |
|
1768 |
self paint:fg. |
|
1769 |
]. |
|
1770 |
self displayString:str x:x y:y. |
|
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1771 |
y := y + (font height) |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1772 |
] |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1773 |
] ifFalse:[ |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1774 |
"/ anything |
2496 | 1775 |
logo displayOn:self x:x y:y opaque:doClear |
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1776 |
] |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1777 |
]. |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1778 |
]. |
131 | 1779 |
|
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1780 |
adjust == #fit ifTrue:[ |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1781 |
self scale:1 |
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1782 |
]. |
0 | 1783 |
] |
636
02b141814b92
unified widthOn/heightOn protocol
Claus Gittinger <cg@exept.de>
parents:
626
diff
changeset
|
1784 |
|
1659
9b2b15f77813
with positive level, draw string label offset by one pixel.
Claus Gittinger <cg@exept.de>
parents:
1650
diff
changeset
|
1785 |
"Modified: / 6.9.1998 / 22:35:53 / cg" |
0 | 1786 |
! |
1787 |
||
1788 |
redraw |
|
1789 |
"redraw my label" |
|
1790 |
||
1791 |
shown ifTrue:[ |
|
59 | 1792 |
self drawWith:fgColor and:bgColor |
0 | 1793 |
] |
1794 |
! ! |
|
105 | 1795 |
|
110 | 1796 |
!Label methodsFor:'resizing'! |
1797 |
||
1798 |
forceResize |
|
118 | 1799 |
"resize myself to make text fit into myself. Here, this is done even if |
1800 |
fixSize is set." |
|
110 | 1801 |
|
2664 | 1802 |
|prevFixSize| |
1803 |
||
110 | 1804 |
logo notNil ifTrue:[ |
2664 | 1805 |
prevFixSize := fixSize. |
1806 |
fixSize := false. |
|
1807 |
self extent:self preferredExtent. |
|
1808 |
self computeLabelOrigin. |
|
3499 | 1809 |
"/ this seems the only one which might depend on my contents. |
1810 |
layout isLayout ifTrue:[ |
|
1811 |
layout isAlignmentOrigin ifTrue:[ |
|
1812 |
self containerChangedSize. |
|
1813 |
] |
|
1814 |
]. |
|
2664 | 1815 |
fixSize := prevFixSize. |
1816 |
] |
|
1817 |
! |
|
1818 |
||
1819 |
forceResizeHorizontally |
|
1820 |
"resize myself horizontally to make text fit into myself. |
|
1821 |
Here, this is done even if fixSize is set." |
|
1822 |
||
1823 |
|prevFixSize| |
|
1824 |
||
1825 |
logo notNil ifTrue:[ |
|
1826 |
prevFixSize := fixSize. |
|
1827 |
fixSize := false. |
|
3615
a99127b32e61
added preferredWidth & preferredHeight
Claus Gittinger <cg@exept.de>
parents:
3597
diff
changeset
|
1828 |
self width:self preferredWidth. |
2664 | 1829 |
self computeLabelOrigin. |
1830 |
fixSize := prevFixSize. |
|
110 | 1831 |
] |
105 | 1832 |
! |
1833 |
||
1834 |
resize |
|
1835 |
"resize myself to make text fit into myself. |
|
118 | 1836 |
but only do so, if I am not fixedSize and I have NOT been |
1837 |
given a relative extent or an extend computation block." |
|
105 | 1838 |
|
110 | 1839 |
(logo notNil |
1840 |
and:[fixSize not |
|
1841 |
and:[relativeExtent isNil |
|
1842 |
and:[extentRule isNil |
|
1843 |
and:[relativeCorner isNil |
|
1844 |
and:[cornerRule isNil]]]]]) ifTrue:[ |
|
1845 |
self forceResize |
|
1846 |
] ifFalse:[ |
|
105 | 1847 |
self computeLabelOrigin |
1848 |
] |
|
1849 |
! ! |
|
1850 |
||
935 | 1851 |
!Label class methodsFor:'documentation'! |
205 | 1852 |
|
1853 |
version |
|
3633
c9eacbe73abb
fg/bg setting is needed as a sideeffect in order
Claus Gittinger <cg@exept.de>
parents:
3615
diff
changeset
|
1854 |
^ '$Header: /cvs/stx/stx/libwidg/Label.st,v 1.135 2008-06-20 09:54:07 cg Exp $' |
205 | 1855 |
! ! |