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