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