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