author | Stefan Vogel <sv@exept.de> |
Tue, 18 Feb 2003 15:16:32 +0100 | |
changeset 2439 | 5bc545c13f51 |
parent 2438 | 3c77e12a63d6 |
child 2491 | 10f86a3c5342 |
permissions | -rw-r--r-- |
696 | 1 |
" |
2 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
||
1777
1c09f7e0a18a
set masterApplication ... in case of an ApplicationModel
tm
parents:
1761
diff
changeset
|
14 |
"{ Package: 'stx:libwidg2' }" |
1759 | 15 |
|
696 | 16 |
Model subclass:#TabItem |
1759 | 17 |
instanceVariableNames:'rawLabel label enabled argument canvas adornments activeHelpText' |
696 | 18 |
classVariableNames:'' |
19 |
poolDictionaries:'' |
|
20 |
category:'Views-Support' |
|
21 |
! |
|
22 |
||
23 |
!TabItem class methodsFor:'documentation'! |
|
24 |
||
25 |
copyright |
|
26 |
" |
|
27 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
28 |
All Rights Reserved |
|
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 |
! |
|
39 |
||
40 |
documentation |
|
41 |
" |
|
42 |
describes one tab entry; could be used for tabs instead of a string. Whenever |
|
43 |
a value changed, a change notification is raised |
|
44 |
||
45 |
[see also:] |
|
46 |
TabItemEditor |
|
47 |
TabView |
|
48 |
NoteBookView |
|
49 |
UIPainter |
|
50 |
||
51 |
[author:] |
|
52 |
Claus Atzkern |
|
53 |
" |
|
54 |
||
55 |
||
56 |
! |
|
57 |
||
58 |
examples |
|
59 |
" |
|
60 |
labels derived from item |
|
61 |
[exBegin] |
|
62 |
|top tab| |
|
63 |
||
64 |
top := StandardSystemView new label:'tabs at top'; extent:250@100. |
|
65 |
tab := TabView origin:0.0 @ 0.0 corner:1.0 @ 0.5 in:top. |
|
66 |
||
67 |
tab direction:#top. |
|
68 |
tab list:(#( 'Foo' 'Bar' 'Baz' ) collect:[:l| TabItem label:l ]). |
|
69 |
tab action:[:aName|Transcript showCR:aName]. |
|
70 |
top open. |
|
71 |
[exEnd] |
|
72 |
||
73 |
||
74 |
testing tab configuration and change notifications |
|
75 |
[exBegin] |
|
76 |
|top tab list idx label| |
|
77 |
||
78 |
top := StandardSystemView new label:'tabs at top'; extent:250@100. |
|
79 |
tab := TabView origin:0.0 @ 0.0 corner:1.0 @ 0.5 in:top. |
|
80 |
||
81 |
tab direction:#top. |
|
82 |
list := (#( 'Foo' 'Bar' 'Baz' ) collect:[:l| TabItem label:l ]). |
|
83 |
tab list:list. |
|
84 |
tab action:[:aName|Transcript showCR:aName]. |
|
85 |
top openAndWait. |
|
86 |
||
87 |
[ |
|
88 |
idx := 0. |
|
89 |
label := LabelAndIcon icon:(Image fromFile:('xpmBitmaps/document_images/tiny_yellow_dir.xpm' )) |
|
90 |
string:'Test Tab'. |
|
91 |
||
92 |
[top shown] whileTrue:[ |
|
93 |
|aTab lbl| |
|
94 |
||
95 |
(idx := idx + 1) > list size ifTrue:[idx := 1]. |
|
96 |
||
97 |
aTab := list at:idx. |
|
98 |
lbl := aTab label. |
|
99 |
||
100 |
Delay waitForSeconds:0.5. aTab label:label. |
|
101 |
Delay waitForSeconds:0.5. aTab enabled:false. |
|
102 |
Delay waitForSeconds:0.5. aTab enabled:true. |
|
103 |
Delay waitForSeconds:0.5. aTab foregroundColor:(Color red). |
|
104 |
Delay waitForSeconds:0.5. aTab foregroundColor:nil. |
|
105 |
aTab label:lbl. |
|
106 |
] |
|
107 |
] forkAt:1. |
|
108 |
[exEnd] |
|
109 |
||
110 |
" |
|
111 |
! ! |
|
112 |
||
113 |
!TabItem class methodsFor:'instance creation'! |
|
114 |
||
115 |
label:aLabel |
|
116 |
^ self new label:aLabel |
|
117 |
! |
|
118 |
||
119 |
new |
|
120 |
^ self basicNew initialize |
|
121 |
! ! |
|
122 |
||
1759 | 123 |
!TabItem class methodsFor:'tests'! |
124 |
||
125 |
test |
|
126 |
|top tab list item| |
|
127 |
||
128 |
top := StandardSystemView new label:'tabs at top'; extent:400@400. |
|
129 |
tab := NoteBookView origin:0.0 @ 0.0 corner:1.0 @ 1.0 in:top. |
|
130 |
||
131 |
tab direction:#top. |
|
132 |
list := #( 'Foo' 'Bar' 'Baz' ) collect:[:l| TabItem label:l ]. |
|
133 |
item := list at:1. |
|
134 |
item majorKey:ClockView. |
|
135 |
item := list at:2. |
|
136 |
item majorKey:CodingExamples_GUI::GUIDemoNoteBook. |
|
137 |
||
138 |
item := list at:3. |
|
139 |
item majorKey:CodingExamples_GUI::GUIDemoMenu. |
|
140 |
||
141 |
tab list:list. |
|
142 |
top open. |
|
143 |
! ! |
|
144 |
||
696 | 145 |
!TabItem methodsFor:'accessing'! |
146 |
||
1671 | 147 |
accessCharacterPosition |
148 |
"get the index of the access character in the label text or string, or 0 if none |
|
149 |
" |
|
1759 | 150 |
^ self adornmentAt:#accessCharacterPosition ifAbsent:0 |
1671 | 151 |
! |
152 |
||
1759 | 153 |
accessCharacterPosition:anIndex |
1671 | 154 |
"get the index of the access character in the label text or string, or 0 if none |
155 |
" |
|
1759 | 156 |
|idx| |
157 |
||
158 |
anIndex ~~ 0 ifTrue:[ |
|
159 |
idx := anIndex |
|
160 |
]. |
|
161 |
self adornmentAt:#accessCharacterPosition put:idx |
|
1671 | 162 |
! |
163 |
||
716 | 164 |
argument |
165 |
"returns a user defined argument or nil |
|
166 |
" |
|
167 |
^ argument |
|
168 |
! |
|
169 |
||
170 |
argument:anArgument |
|
171 |
"set a user defined argument |
|
172 |
" |
|
1674 | 173 |
(anArgument isString and:[anArgument isEmpty]) ifTrue:[ |
174 |
argument := nil |
|
175 |
] ifFalse:[ |
|
176 |
argument := anArgument |
|
177 |
]. |
|
716 | 178 |
argument := anArgument |
179 |
! |
|
180 |
||
1759 | 181 |
createNewBuilder |
182 |
"returns true if a new builder is used to create the canvas; |
|
183 |
the default is true |
|
184 |
" |
|
185 |
^ self adornmentAt:#createNewBuilder ifAbsent:true |
|
186 |
||
187 |
! |
|
188 |
||
189 |
createNewBuilder:aBool |
|
190 |
"returns true if a new builder is used to create the canvas; |
|
191 |
the default is true |
|
192 |
" |
|
193 |
|flag| |
|
194 |
||
195 |
aBool == false ifTrue:[ |
|
196 |
flag := false |
|
197 |
]. |
|
198 |
^ self adornmentAt:#createNewBuilder put:flag |
|
199 |
||
200 |
! |
|
201 |
||
696 | 202 |
enabled |
203 |
"get the enabled state of the tab |
|
204 |
" |
|
205 |
^ enabled ? true |
|
206 |
! |
|
207 |
||
208 |
enabled:aState |
|
209 |
"set the enabled state of the tab |
|
210 |
" |
|
211 |
|s| |
|
212 |
||
213 |
s := aState ? true. |
|
214 |
||
215 |
self enabled ~~ s ifTrue:[ |
|
216 |
enabled := s. |
|
217 |
self changed:#enabled |
|
218 |
] |
|
219 |
! |
|
220 |
||
221 |
foregroundColor |
|
222 |
"get the label color or nil |
|
223 |
" |
|
1759 | 224 |
^ self adornmentAt:#foregroundColor |
696 | 225 |
! |
226 |
||
227 |
foregroundColor:aColor |
|
228 |
"set the label color or nil |
|
229 |
" |
|
1759 | 230 |
self foregroundColor ~= aColor ifTrue:[ |
231 |
self adornmentAt:#foregroundColor put:aColor. |
|
696 | 232 |
self changed:#foregroundColor |
1759 | 233 |
]. |
696 | 234 |
! |
235 |
||
236 |
label |
|
237 |
"get the label or selector to access a label/bitmap. To get the label to be shown |
|
238 |
use: #rawLabel |
|
239 |
" |
|
240 |
^ label |
|
241 |
! |
|
242 |
||
243 |
label:aLabel |
|
244 |
"set the label or selector to access the label/bitmap |
|
245 |
" |
|
246 |
label := aLabel. |
|
247 |
||
1936
ce9aa6069889
in #label: treat label as different, if emphasis is.
Claus Gittinger <cg@exept.de>
parents:
1891
diff
changeset
|
248 |
(aLabel ~= rawLabel |
ce9aa6069889
in #label: treat label as different, if emphasis is.
Claus Gittinger <cg@exept.de>
parents:
1891
diff
changeset
|
249 |
or:[aLabel isString |
ce9aa6069889
in #label: treat label as different, if emphasis is.
Claus Gittinger <cg@exept.de>
parents:
1891
diff
changeset
|
250 |
and:[rawLabel isString |
ce9aa6069889
in #label: treat label as different, if emphasis is.
Claus Gittinger <cg@exept.de>
parents:
1891
diff
changeset
|
251 |
and:[(aLabel sameStringAndEmphasisAs:rawLabel) not]]]) |
ce9aa6069889
in #label: treat label as different, if emphasis is.
Claus Gittinger <cg@exept.de>
parents:
1891
diff
changeset
|
252 |
|
ce9aa6069889
in #label: treat label as different, if emphasis is.
Claus Gittinger <cg@exept.de>
parents:
1891
diff
changeset
|
253 |
ifTrue:[ |
696 | 254 |
rawLabel := aLabel. |
255 |
self changed |
|
256 |
] |
|
257 |
! |
|
258 |
||
259 |
labelForegroundColor |
|
260 |
"get the label color or nil |
|
261 |
" |
|
262 |
^ self foregroundColor |
|
263 |
! |
|
264 |
||
265 |
labelForegroundColor:aColor |
|
266 |
"set the label color or nil |
|
267 |
" |
|
268 |
self foregroundColor:aColor |
|
1671 | 269 |
! |
270 |
||
271 |
shortcutKey |
|
272 |
"get the key to press to select the tab item from the keyboard; a symbol or nil |
|
273 |
" |
|
1759 | 274 |
^ self adornmentAt:#shortcutKey |
1671 | 275 |
! |
276 |
||
277 |
shortcutKey:aKeyOrNil |
|
278 |
"set the key to press to select the tab item from the keyboard; a symbol or nil |
|
279 |
" |
|
1759 | 280 |
|key| |
281 |
||
282 |
aKeyOrNil size ~~ 0 ifTrue:[ |
|
283 |
key := aKeyOrNil asSymbol |
|
284 |
]. |
|
285 |
self adornmentAt:#shortcutKey put:key |
|
286 |
||
287 |
||
288 |
! ! |
|
289 |
||
2404 | 290 |
!TabItem methodsFor:'accessing-canvas'! |
1759 | 291 |
|
292 |
canvas |
|
293 |
"returns the application or nil |
|
294 |
" |
|
1777
1c09f7e0a18a
set masterApplication ... in case of an ApplicationModel
tm
parents:
1761
diff
changeset
|
295 |
|view cls wsel ckey builder appl| |
1759 | 296 |
|
297 |
canvas notNil ifTrue:[ |
|
298 |
^ canvas |
|
299 |
]. |
|
300 |
||
301 |
(ckey := self majorKey) notNil ifTrue:[ |
|
1891
ab8801a1c22d
subapps always got a new builder (even if one was already present)
tm
parents:
1777
diff
changeset
|
302 |
builder := self adornmentAt:#builder. |
ab8801a1c22d
subapps always got a new builder (even if one was already present)
tm
parents:
1777
diff
changeset
|
303 |
|
1777
1c09f7e0a18a
set masterApplication ... in case of an ApplicationModel
tm
parents:
1761
diff
changeset
|
304 |
(appl := builder application) notNil ifTrue:[ |
1c09f7e0a18a
set masterApplication ... in case of an ApplicationModel
tm
parents:
1761
diff
changeset
|
305 |
(cls := appl resolveName:ckey) isNil ifTrue:[ |
1c09f7e0a18a
set masterApplication ... in case of an ApplicationModel
tm
parents:
1761
diff
changeset
|
306 |
canvas := appl perform:ckey ifNotUnderstood:nil |
1c09f7e0a18a
set masterApplication ... in case of an ApplicationModel
tm
parents:
1761
diff
changeset
|
307 |
] |
1c09f7e0a18a
set masterApplication ... in case of an ApplicationModel
tm
parents:
1761
diff
changeset
|
308 |
] ifFalse:[ |
1c09f7e0a18a
set masterApplication ... in case of an ApplicationModel
tm
parents:
1761
diff
changeset
|
309 |
cls := Smalltalk resolveName:ckey inClass:self class. |
1759 | 310 |
]. |
1777
1c09f7e0a18a
set masterApplication ... in case of an ApplicationModel
tm
parents:
1761
diff
changeset
|
311 |
|
1c09f7e0a18a
set masterApplication ... in case of an ApplicationModel
tm
parents:
1761
diff
changeset
|
312 |
canvas isNil ifTrue:[ |
1c09f7e0a18a
set masterApplication ... in case of an ApplicationModel
tm
parents:
1761
diff
changeset
|
313 |
cls isNil ifTrue:[ |
1c09f7e0a18a
set masterApplication ... in case of an ApplicationModel
tm
parents:
1761
diff
changeset
|
314 |
self majorKey:nil. |
1c09f7e0a18a
set masterApplication ... in case of an ApplicationModel
tm
parents:
1761
diff
changeset
|
315 |
^ nil |
1c09f7e0a18a
set masterApplication ... in case of an ApplicationModel
tm
parents:
1761
diff
changeset
|
316 |
]. |
1c09f7e0a18a
set masterApplication ... in case of an ApplicationModel
tm
parents:
1761
diff
changeset
|
317 |
canvas := cls new. |
1c09f7e0a18a
set masterApplication ... in case of an ApplicationModel
tm
parents:
1761
diff
changeset
|
318 |
]. |
1759 | 319 |
|
320 |
(canvas isKindOf:ApplicationModel) ifTrue:[ |
|
321 |
view := SimpleView new. |
|
322 |
wsel := self minorKey ? #windowSpec. |
|
1777
1c09f7e0a18a
set masterApplication ... in case of an ApplicationModel
tm
parents:
1761
diff
changeset
|
323 |
|
1c09f7e0a18a
set masterApplication ... in case of an ApplicationModel
tm
parents:
1761
diff
changeset
|
324 |
canvas builder notNil ifTrue:[ |
1c09f7e0a18a
set masterApplication ... in case of an ApplicationModel
tm
parents:
1761
diff
changeset
|
325 |
builder := canvas builder |
1891
ab8801a1c22d
subapps always got a new builder (even if one was already present)
tm
parents:
1777
diff
changeset
|
326 |
] ifFalse:[ |
ab8801a1c22d
subapps always got a new builder (even if one was already present)
tm
parents:
1777
diff
changeset
|
327 |
builder isNil ifTrue:[ |
ab8801a1c22d
subapps always got a new builder (even if one was already present)
tm
parents:
1777
diff
changeset
|
328 |
builder := canvas createBuilder. |
ab8801a1c22d
subapps always got a new builder (even if one was already present)
tm
parents:
1777
diff
changeset
|
329 |
] ifFalse:[ |
ab8801a1c22d
subapps always got a new builder (even if one was already present)
tm
parents:
1777
diff
changeset
|
330 |
canvas builder:builder. |
ab8801a1c22d
subapps always got a new builder (even if one was already present)
tm
parents:
1777
diff
changeset
|
331 |
]. |
1777
1c09f7e0a18a
set masterApplication ... in case of an ApplicationModel
tm
parents:
1761
diff
changeset
|
332 |
]. |
1c09f7e0a18a
set masterApplication ... in case of an ApplicationModel
tm
parents:
1761
diff
changeset
|
333 |
|
1c09f7e0a18a
set masterApplication ... in case of an ApplicationModel
tm
parents:
1761
diff
changeset
|
334 |
(appl notNil and:[canvas masterApplication isNil]) ifTrue:[ |
1c09f7e0a18a
set masterApplication ... in case of an ApplicationModel
tm
parents:
1761
diff
changeset
|
335 |
canvas masterApplication:appl |
1c09f7e0a18a
set masterApplication ... in case of an ApplicationModel
tm
parents:
1761
diff
changeset
|
336 |
]. |
1943
c90153998d43
set new application in builder if builder is created
martin
parents:
1936
diff
changeset
|
337 |
self createNewBuilder ifTrue:[ |
c90153998d43
set new application in builder if builder is created
martin
parents:
1936
diff
changeset
|
338 |
"/ set the application to the new application |
c90153998d43
set new application in builder if builder is created
martin
parents:
1936
diff
changeset
|
339 |
builder application:canvas |
c90153998d43
set new application in builder if builder is created
martin
parents:
1936
diff
changeset
|
340 |
]. |
1759 | 341 |
view client:canvas spec:wsel builder:builder. |
342 |
canvas window:(self setupCanvasView:view). |
|
343 |
] ifFalse:[ |
|
344 |
canvas := self setupCanvasView:canvas |
|
1943
c90153998d43
set new application in builder if builder is created
martin
parents:
1936
diff
changeset
|
345 |
] |
1759 | 346 |
]. |
347 |
^ canvas |
|
348 |
! |
|
349 |
||
350 |
canvasView |
|
351 |
"returns the view the canvas is running in or nil if no canvas |
|
352 |
specified or not yet created |
|
353 |
" |
|
354 |
|canvas| |
|
355 |
||
356 |
(canvas := self canvas) notNil ifTrue:[ |
|
357 |
^ canvas perform:#window ifNotUnderstood:[canvas] |
|
358 |
]. |
|
359 |
^ nil |
|
360 |
! |
|
361 |
||
362 |
destroyCanvas |
|
363 |
||
364 |
canvas notNil ifTrue:[ |
|
365 |
self canvasView destroy. |
|
366 |
canvas := nil |
|
367 |
]. |
|
368 |
! |
|
369 |
||
370 |
majorKey |
|
371 |
^ self adornmentAt:#majorKey |
|
372 |
! |
|
373 |
||
374 |
majorKey:aMajorKey |
|
375 |
|key| |
|
376 |
||
377 |
aMajorKey notNil ifTrue:[ |
|
378 |
aMajorKey isBehavior ifTrue:[ |
|
379 |
key := aMajorKey name asSymbol |
|
380 |
] ifFalse:[ |
|
381 |
aMajorKey size ~~ 0 ifTrue:[ |
|
382 |
key := aMajorKey asSymbol |
|
383 |
] |
|
384 |
] |
|
385 |
]. |
|
386 |
||
387 |
self majorKey ~~ key ifTrue:[ |
|
388 |
self destroyCanvas |
|
389 |
]. |
|
390 |
self adornmentAt:#majorKey put:key. |
|
391 |
! |
|
392 |
||
393 |
minorKey |
|
394 |
^ self adornmentAt:#minorKey |
|
395 |
! |
|
396 |
||
397 |
minorKey:aMinorKey |
|
398 |
self adornmentAt:#minorKey put:aMinorKey. |
|
399 |
! |
|
1671 | 400 |
|
1759 | 401 |
setupCanvasView:aView |
402 |
|frame isV isH auto| |
|
403 |
||
404 |
isH := self hasHorizontalScrollBar. |
|
405 |
isV := self hasVerticalScrollBar. |
|
406 |
||
407 |
(isH or:[isV]) ifFalse:[ |
|
408 |
frame := aView |
|
409 |
] ifTrue:[ |
|
410 |
frame := ScrollableView for:ViewScroller. |
|
411 |
||
412 |
frame horizontalScrollable:isH. |
|
413 |
frame verticalScrollable:isV. |
|
414 |
||
415 |
isH ifTrue:[frame horizontalMini:(self miniScrollerHorizontal)]. |
|
416 |
isV ifTrue:[frame verticalMini:(self miniScrollerVertical)]. |
|
417 |
||
418 |
(auto := self autoHideScrollBars) notNil ifTrue:[ |
|
419 |
frame autoHideScrollBars:auto |
|
420 |
]. |
|
421 |
frame scrolledView scrolledView:aView. |
|
422 |
]. |
|
423 |
frame objectAttributeAt:#isTabItem put:true. |
|
424 |
^ frame |
|
425 |
! ! |
|
426 |
||
2404 | 427 |
!TabItem methodsFor:'accessing-scrollbars'! |
1759 | 428 |
|
429 |
autoHideScrollBars |
|
430 |
^ self adornmentAt:#autoHideScrollBars |
|
431 |
! |
|
432 |
||
433 |
autoHideScrollBars:aBoolOrNil |
|
434 |
self adornmentAt:#autoHideScrollBars put:aBoolOrNil |
|
435 |
||
436 |
! |
|
437 |
||
438 |
hasHorizontalScrollBar |
|
439 |
^ self adornmentAt:#hasHorizontalScrollBar ifAbsent:false |
|
440 |
||
441 |
! |
|
442 |
||
443 |
hasHorizontalScrollBar:aBool |
|
444 |
|flag| |
|
445 |
||
446 |
aBool == true ifTrue:[flag := true] |
|
447 |
ifFalse:[self miniScrollerHorizontal:false]. |
|
448 |
||
449 |
self adornmentAt:#hasHorizontalScrollBar put:flag |
|
450 |
||
451 |
! |
|
452 |
||
453 |
hasVerticalScrollBar |
|
454 |
^ self adornmentAt:#hasVerticalScrollBar ifAbsent:false |
|
455 |
||
456 |
! |
|
457 |
||
458 |
hasVerticalScrollBar:aBool |
|
459 |
|flag| |
|
460 |
||
461 |
aBool == true ifTrue:[flag := true] |
|
462 |
ifFalse:[self miniScrollerVertical:false]. |
|
463 |
||
464 |
self adornmentAt:#hasVerticalScrollBar put:flag |
|
465 |
||
466 |
! |
|
467 |
||
468 |
miniScrollerHorizontal |
|
469 |
^ self adornmentAt:#miniScrollerHorizontal ifAbsent:false |
|
470 |
||
471 |
! |
|
472 |
||
473 |
miniScrollerHorizontal:aBool |
|
474 |
|flag| |
|
475 |
||
476 |
aBool == true ifTrue:[ |
|
477 |
flag := true |
|
478 |
]. |
|
479 |
self adornmentAt:#miniScrollerHorizontal put:flag |
|
480 |
||
481 |
! |
|
482 |
||
483 |
miniScrollerVertical |
|
484 |
^ self adornmentAt:#miniScrollerVertical ifAbsent:false |
|
485 |
||
486 |
! |
|
487 |
||
488 |
miniScrollerVertical:aBool |
|
489 |
|flag| |
|
490 |
||
491 |
aBool == true ifTrue:[ |
|
492 |
flag := true |
|
493 |
]. |
|
494 |
self adornmentAt:#miniScrollerVertical put:flag |
|
1671 | 495 |
|
696 | 496 |
! ! |
497 |
||
498 |
!TabItem methodsFor:'building'! |
|
499 |
||
716 | 500 |
editAgument |
501 |
"used by TabItemEditor to get the argument |
|
502 |
" |
|
503 |
^ argument isSymbol ifTrue:['#', argument] ifFalse:[argument] |
|
504 |
! |
|
505 |
||
506 |
editAgument:anArgument |
|
507 |
"used by TabItemEditor to set the argument |
|
508 |
" |
|
2439 | 509 |
|size| |
716 | 510 |
|
511 |
anArgument size ~~ 0 ifTrue:[ |
|
512 |
argument := anArgument withoutSeparators. |
|
513 |
||
514 |
(size := argument size) == 0 ifTrue:[ |
|
515 |
argument := nil |
|
516 |
] ifFalse:[ |
|
517 |
(argument startsWith:$#) ifTrue:[ |
|
518 |
size > 1 ifTrue:[ |
|
519 |
argument := (argument copyFrom:2) asSymbol |
|
520 |
] ifFalse:[ |
|
521 |
argument := nil |
|
522 |
] |
|
523 |
] |
|
524 |
] |
|
525 |
] ifFalse:[ |
|
526 |
argument := nil |
|
527 |
] |
|
528 |
! |
|
529 |
||
696 | 530 |
rawLabel |
531 |
"returns the label to be shown |
|
532 |
" |
|
533 |
^ rawLabel ? ' ' |
|
534 |
||
535 |
||
536 |
! |
|
537 |
||
702 | 538 |
setAttributesFromClass:aClass |
539 |
"setup attributes from class |
|
540 |
" |
|
1761 | 541 |
|key spec cls| |
542 |
||
543 |
rawLabel := nil. |
|
544 |
||
545 |
(aClass notNil and:[(cls := Smalltalk resolveName:aClass inClass:self class) notNil]) ifTrue:[ |
|
546 |
(self translateLabel and:[label isString]) ifTrue:[ |
|
547 |
rawLabel := cls perform:(label asSymbol) ifNotUnderstood:nil |
|
702 | 548 |
]. |
1761 | 549 |
(self majorKey isNil and:[(key := self minorKey) notNil]) ifTrue:[ |
2438
3c77e12a63d6
Replace referneces to Exception.
Stefan Vogel <sv@exept.de>
parents:
2404
diff
changeset
|
550 |
Error handle:[:ex| |
1761 | 551 |
] do:[ |
552 |
spec := cls perform:(key asSymbol) ifNotUnderstood:nil. |
|
553 |
||
554 |
spec notNil ifTrue:[ |
|
555 |
canvas := SimpleView new. |
|
556 |
canvas client:nil spec:spec builder:(UIBuilder new). |
|
557 |
canvas := self setupCanvasView:canvas. |
|
558 |
]. |
|
559 |
] |
|
560 |
] |
|
702 | 561 |
]. |
1761 | 562 |
|
563 |
rawLabel isNil ifTrue:[ |
|
564 |
rawLabel := label isNil ifTrue:[''] ifFalse:[label printString] |
|
565 |
]. |
|
702 | 566 |
! |
567 |
||
696 | 568 |
setAttributesWithBuilder:aBuilder |
569 |
"setup attributes dependent on the builder |
|
570 |
" |
|
1759 | 571 |
|appl key builder | |
572 |
||
1777
1c09f7e0a18a
set masterApplication ... in case of an ApplicationModel
tm
parents:
1761
diff
changeset
|
573 |
builder := self createNewBuilder ifTrue:[UIBuilder new] ifFalse:[aBuilder]. |
1759 | 574 |
self adornmentAt:#builder put:builder. |
575 |
||
696 | 576 |
(self translateLabel and:[label isString]) ifTrue:[ |
577 |
rawLabel := aBuilder labelFor:(label asSymbol). |
|
1759 | 578 |
]. |
696 | 579 |
|
1759 | 580 |
rawLabel isNil ifTrue:[ |
581 |
rawLabel := label printString. |
|
696 | 582 |
]. |
1759 | 583 |
|
584 |
(aBuilder isEditing or:[(appl := aBuilder application) isNil]) ifFalse:[ |
|
585 |
(key := self activeHelpKey) notNil ifTrue:[ |
|
586 |
activeHelpText := appl helpTextForKey:key. |
|
587 |
]. |
|
1777
1c09f7e0a18a
set masterApplication ... in case of an ApplicationModel
tm
parents:
1761
diff
changeset
|
588 |
builder application isNil ifTrue:[ |
1c09f7e0a18a
set masterApplication ... in case of an ApplicationModel
tm
parents:
1761
diff
changeset
|
589 |
builder application:appl |
1c09f7e0a18a
set masterApplication ... in case of an ApplicationModel
tm
parents:
1761
diff
changeset
|
590 |
]. |
1c09f7e0a18a
set masterApplication ... in case of an ApplicationModel
tm
parents:
1761
diff
changeset
|
591 |
|
1759 | 592 |
(self majorKey isNil and:[(key := self minorKey) notNil]) ifTrue:[ |
593 |
canvas := SimpleView new. |
|
1777
1c09f7e0a18a
set masterApplication ... in case of an ApplicationModel
tm
parents:
1761
diff
changeset
|
594 |
canvas client:appl spec:key builder:builder. |
1759 | 595 |
canvas := self setupCanvasView:canvas. |
596 |
] |
|
1891
ab8801a1c22d
subapps always got a new builder (even if one was already present)
tm
parents:
1777
diff
changeset
|
597 |
]. |
696 | 598 |
! |
599 |
||
600 |
translateLabel |
|
601 |
"returns true if the label derives from the application |
|
602 |
" |
|
1759 | 603 |
^ self adornmentAt:#translateLabel ifAbsent:false |
696 | 604 |
! |
605 |
||
606 |
translateLabel:aBool |
|
607 |
"returns true if the label derives from the application |
|
608 |
" |
|
1759 | 609 |
|flag| |
610 |
||
611 |
aBool == true ifTrue:[ |
|
612 |
flag := true. |
|
613 |
]. |
|
1760 | 614 |
^ self adornmentAt:#translateLabel put:flag |
696 | 615 |
! ! |
616 |
||
617 |
!TabItem methodsFor:'converting'! |
|
618 |
||
619 |
fromLiteralArrayEncoding:aLiteralEncodedArray |
|
620 |
"read my contents from a aLiteralEncodedArray |
|
621 |
" |
|
622 |
2 to:aLiteralEncodedArray size by:2 do:[:i | |
|
623 |
|selector value| |
|
624 |
||
625 |
selector := aLiteralEncodedArray at:i. |
|
1759 | 626 |
|
696 | 627 |
(self respondsTo:selector) ifTrue:[ |
1759 | 628 |
value := (aLiteralEncodedArray at:i+1) decodeAsLiteralArray. |
696 | 629 |
self perform:selector with:value |
630 |
] |
|
631 |
]. |
|
632 |
||
633 |
||
634 |
" |
|
635 |
||
636 |
#(#TabItem |
|
637 |
#label: 'claus' |
|
638 |
#foregroundColor: #(#Color 0.0 0.0 100.0) |
|
639 |
#enabled: false |
|
640 |
||
641 |
) decodeAsLiteralArray |
|
642 |
||
643 |
||
644 |
" |
|
645 |
||
646 |
||
647 |
! |
|
648 |
||
649 |
literalArrayEncoding |
|
650 |
"return myself encoded as a literal array |
|
651 |
" |
|
2439 | 652 |
|coll| |
696 | 653 |
|
654 |
coll := OrderedCollection new. |
|
655 |
coll add:#TabItem. |
|
656 |
coll add:#label: ; add:(label literalArrayEncoding). |
|
657 |
||
658 |
self enabled ifFalse:[ |
|
1671 | 659 |
coll add:#enabled: ; add:false. |
696 | 660 |
]. |
661 |
||
716 | 662 |
argument notNil ifTrue:[ |
663 |
coll add:#argument: ; add:(argument literalArrayEncoding). |
|
664 |
]. |
|
665 |
||
1759 | 666 |
adornments size ~~ 0 ifTrue:[ |
667 |
adornments keysAndValuesDo:[:key :val| |
|
668 |
key ~~ #builder ifTrue:[ |
|
669 |
coll add:((key, ':') asSymbol). |
|
670 |
coll add:(val literalArrayEncoding). |
|
671 |
] |
|
672 |
] |
|
673 |
]. |
|
674 |
||
675 |
^ coll asArray |
|
696 | 676 |
" |
677 |
||
678 |
#(#TabItem |
|
679 |
#label: 'claus' |
|
680 |
#translateLabel: true |
|
681 |
#foregroundColor: #(#Color 0.0 0.0 100.0) |
|
682 |
#enabled: false |
|
683 |
||
684 |
) decodeAsLiteralArray literalArrayEncoding |
|
685 |
||
686 |
" |
|
687 |
! ! |
|
688 |
||
1759 | 689 |
!TabItem methodsFor:'displaying'! |
690 |
||
691 |
displayOn:aGC x:x y:y |
|
692 |
|s| |
|
693 |
||
694 |
(s := rawLabel ? label) isNil ifTrue:[ |
|
695 |
^ self |
|
696 |
]. |
|
697 |
s isNumber ifTrue:[ |
|
698 |
s := s printString |
|
699 |
]. |
|
700 |
s displayOn:aGC x:x y:y |
|
701 |
! |
|
702 |
||
703 |
heightOn:aGC |
|
704 |
|s| |
|
705 |
||
706 |
(s := rawLabel ? label) isNil ifTrue:[ |
|
707 |
^ aGC font height |
|
708 |
]. |
|
709 |
^ s heightOn:aGC |
|
710 |
! |
|
711 |
||
712 |
widthOn:aGC |
|
713 |
|s| |
|
714 |
||
715 |
(s := rawLabel ? label) isNil ifTrue:[ |
|
716 |
^ 4 |
|
717 |
]. |
|
718 |
^ s widthOn:aGC |
|
719 |
! ! |
|
720 |
||
721 |
!TabItem methodsFor:'help'! |
|
722 |
||
723 |
activeHelpKey |
|
724 |
^ self adornmentAt:#activeHelpKey |
|
725 |
! |
|
726 |
||
727 |
activeHelpKey:aKey |
|
728 |
|key| |
|
729 |
||
730 |
aKey size > 0 ifTrue:[key := aKey asSymbol]. |
|
731 |
self adornmentAt:#activeHelpKey put:key |
|
732 |
! |
|
733 |
||
734 |
activeHelpText |
|
735 |
^ activeHelpText |
|
736 |
! ! |
|
737 |
||
738 |
!TabItem methodsFor:'private'! |
|
739 |
||
740 |
adornmentAt:aKey |
|
741 |
^ self adornmentAt:aKey ifAbsent:nil |
|
742 |
! |
|
743 |
||
744 |
adornmentAt:aKey ifAbsent:exceptionBlock |
|
745 |
adornments isNil ifTrue:[ |
|
746 |
^ exceptionBlock value |
|
747 |
]. |
|
748 |
^ adornments at:aKey ifAbsent:exceptionBlock |
|
749 |
! |
|
750 |
||
751 |
adornmentAt:aKey put:something |
|
752 |
||
753 |
something isNil ifTrue:[ |
|
754 |
adornments notNil ifTrue:[ |
|
755 |
adornments removeKey:aKey ifAbsent:nil. |
|
756 |
] |
|
757 |
] ifFalse:[ |
|
758 |
adornments isNil ifTrue:[ |
|
759 |
adornments := IdentityDictionary new. |
|
760 |
]. |
|
761 |
adornments at:aKey put:something. |
|
762 |
]. |
|
763 |
^ something |
|
764 |
! ! |
|
765 |
||
766 |
!TabItem methodsFor:'queries'! |
|
696 | 767 |
|
768 |
isEnabled |
|
769 |
^ self enabled |
|
770 |
! ! |
|
771 |
||
772 |
!TabItem class methodsFor:'documentation'! |
|
773 |
||
774 |
version |
|
2439 | 775 |
^ '$Header: /cvs/stx/stx/libwidg2/TabItem.st,v 1.16 2003-02-18 14:16:32 stefan Exp $' |
696 | 776 |
! ! |