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