343
|
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 |
|
|
14 |
View subclass:#TabView
|
550
|
15 |
instanceVariableNames:'list listHolder selection enabled action tabStyle useIndex
|
|
16 |
maxRawNr direction fitLastRow moveSelectedRow enableChannel
|
697
|
17 |
selectConditionBlock oldExtent oneTabPerLine fontAscent
|
|
18 |
fontDescent'
|
550
|
19 |
classVariableNames:''
|
|
20 |
poolDictionaries:''
|
|
21 |
category:'Views-Interactors'
|
343
|
22 |
!
|
|
23 |
|
|
24 |
!TabView class methodsFor:'documentation'!
|
|
25 |
|
|
26 |
copyright
|
|
27 |
"
|
|
28 |
COPYRIGHT (c) 1997 by eXept Software AG
|
|
29 |
All Rights Reserved
|
|
30 |
|
|
31 |
This software is furnished under a license and may be used
|
|
32 |
only in accordance with the terms of that license and with the
|
|
33 |
inclusion of the above copyright notice. This software may not
|
|
34 |
be provided or otherwise made available to, or used by, any
|
|
35 |
other person. No title to or ownership of the software is
|
|
36 |
hereby transferred.
|
|
37 |
"
|
|
38 |
|
|
39 |
!
|
|
40 |
|
|
41 |
documentation
|
|
42 |
"
|
|
43 |
implements the tabs-view component of a noteBook.
|
|
44 |
May also be used on its own (without a surrounding noteBook).
|
|
45 |
|
|
46 |
The functionality is basically the same as provided by a
|
|
47 |
PopUpList or SelectionInListView, in that a valueHolder
|
|
48 |
gets a value assigned corresponding to the selected tab
|
|
49 |
from a list of possible tabs.
|
|
50 |
|
|
51 |
[author:]
|
|
52 |
Claus Atzkern
|
|
53 |
|
|
54 |
[see also:]
|
|
55 |
NoteBookView
|
369
|
56 |
SelectionInListView PopUpList ValueHolder TabWidget
|
343
|
57 |
"
|
|
58 |
|
|
59 |
!
|
|
60 |
|
|
61 |
examples
|
|
62 |
"
|
367
|
63 |
tabs at top of a view
|
343
|
64 |
[exBegin]
|
367
|
65 |
|top tab view inset|
|
|
66 |
|
|
67 |
top := StandardSystemView new label:'tabs at top'; extent:250@100.
|
499
|
68 |
tab := TabView origin:0.0 @ 0.0 corner:1.0 @ 0.0 in:top.
|
|
69 |
view := View origin:0.0 @ 0.0 corner:1.0 @ 1.0 in:top.
|
367
|
70 |
|
|
71 |
view viewBackground:(tab styleAt:#selectedColor).
|
|
72 |
tab direction:#top.
|
|
73 |
tab list:#( 'Foo' 'Bar' 'Baz' ).
|
|
74 |
inset := tab preferredSizeXorY.
|
|
75 |
tab bottomInset:(inset negated).
|
|
76 |
view topInset:inset.
|
|
77 |
tab action:[:aName|Transcript showCR:aName].
|
|
78 |
top open.
|
|
79 |
[exEnd]
|
343
|
80 |
|
367
|
81 |
tabs at bottom of a view; changing widget to MAC style
|
|
82 |
[exBegin]
|
|
83 |
|top tab view inset|
|
|
84 |
|
|
85 |
top := StandardSystemView new label:'tabs at bottom'; extent:250@100.
|
499
|
86 |
view := View origin:0.0 @ 0.0 corner:1.0 @ 1.0 in:top.
|
|
87 |
tab := TabView origin:0.0 @ 1.0 corner:1.0 @ 1.0 in:top.
|
343
|
88 |
|
367
|
89 |
view viewBackground:(tab styleAt:#selectedColor).
|
|
90 |
tab direction:#bottom.
|
|
91 |
tab tabWidget:#Mac.
|
343
|
92 |
|
367
|
93 |
tab list:#( 'Foo' 'Bar' 'Baz' ).
|
|
94 |
inset := tab preferredSizeXorY.
|
|
95 |
tab topInset:(inset negated).
|
|
96 |
view bottomInset:inset.
|
|
97 |
tab action:[:aName|Transcript showCR:aName].
|
|
98 |
top open.
|
|
99 |
[exEnd]
|
343
|
100 |
|
367
|
101 |
tabs at right of a view
|
|
102 |
[exBegin]
|
|
103 |
|top tab view inset|
|
|
104 |
|
|
105 |
top := StandardSystemView new label:'tabs at right'; extent:100@250.
|
499
|
106 |
view := View origin:0.0 @ 0.0 corner:1.0 @ 1.0 in:top.
|
|
107 |
tab := TabView origin:1.0 @ 0.0 corner:1.0 @ 1.0 in:top.
|
367
|
108 |
|
|
109 |
view viewBackground:(tab styleAt:#selectedColor).
|
|
110 |
tab direction:#right.
|
|
111 |
tab list:#( 'Foo' 'Bar' 'Baz' ).
|
|
112 |
inset := tab preferredSizeXorY.
|
|
113 |
tab leftInset:(inset negated).
|
|
114 |
view rightInset:inset.
|
|
115 |
tab action:[:aName|Transcript showCR:aName].
|
343
|
116 |
top open.
|
367
|
117 |
[exEnd]
|
343
|
118 |
|
367
|
119 |
tabs at left of a view
|
343
|
120 |
[exBegin]
|
367
|
121 |
|top tab view inset|
|
|
122 |
|
|
123 |
top := StandardSystemView new label:'tabs at left'; extent:100@250.
|
499
|
124 |
tab := TabView origin:0.0 @ 0.0 corner:0.0 @ 1.0 in:top.
|
|
125 |
view := View origin:0.0 @ 0.0 corner:1.0 @ 1.0 in:top.
|
343
|
126 |
|
367
|
127 |
view viewBackground:(tab styleAt:#selectedColor).
|
|
128 |
tab direction:#left.
|
|
129 |
tab list:#( 'Foo' 'Bar' 'Baz' ).
|
|
130 |
inset := tab preferredSizeXorY.
|
|
131 |
tab rightInset:(inset negated).
|
|
132 |
view leftInset:inset.
|
|
133 |
tab action:[:aName|Transcript showCR:aName].
|
|
134 |
top open.
|
|
135 |
[exEnd]
|
343
|
136 |
|
367
|
137 |
changing default style( see TabWidget class ); useing index
|
|
138 |
[exBegin]
|
|
139 |
|top tab view|
|
|
140 |
|
|
141 |
top := StandardSystemView new label:'example'; extent:450@300.
|
499
|
142 |
tab := TabView origin:0.0 @ 0.0 corner:1.0 @ 40 in:top.
|
367
|
143 |
tab horizontalInset:10.
|
|
144 |
view := NoteBookFrameView origin:0.0 @ 40 corner:1.0 @ 1.0 in:top.
|
343
|
145 |
view horizontalInset:10.
|
|
146 |
view bottomInset:10.
|
|
147 |
view level:2.
|
|
148 |
view viewBackground:(Image fromFile:'bitmaps/gifImages/garfield.gif').
|
|
149 |
|
367
|
150 |
tab styleAt:#selectedColor put:(view viewBackground).
|
|
151 |
tab styleAt:#unselectedColor put:(Color grey:60).
|
|
152 |
tab styleAt:#expandSelection put:9@7.
|
343
|
153 |
|
367
|
154 |
tab list:#( 'Foo' 'Bar' 'Baz').
|
|
155 |
tab useIndex:true.
|
|
156 |
tab action:[:aName| Transcript showCR:aName ].
|
352
|
157 |
|
343
|
158 |
top open.
|
367
|
159 |
[exEnd]
|
343
|
160 |
|
|
161 |
|
367
|
162 |
using images and text
|
|
163 |
[exBegin]
|
|
164 |
|top tab view list|
|
|
165 |
|
|
166 |
top := StandardSystemView new label:'example'.
|
499
|
167 |
tab := TabView origin:0.0 @ 0.0 corner:1.0 @ 1.0 in:top.
|
367
|
168 |
list := #( 'SBrowser' 'FBrowser' 'Debugger' ).
|
|
169 |
list := list collect:[:n | Image fromFile:'bitmaps/' , n , '.xbm'].
|
|
170 |
list add:'A Text'.
|
|
171 |
tab list:list.
|
|
172 |
tab action:[:indexOrNil| Transcript showCR:indexOrNil ].
|
|
173 |
top extent:(tab preferredExtent).
|
|
174 |
top open.
|
|
175 |
[exEnd]
|
343
|
176 |
|
367
|
177 |
using images and text; MAC style
|
|
178 |
[exBegin]
|
|
179 |
|top tab view list|
|
|
180 |
|
|
181 |
top := StandardSystemView new label:'example'.
|
499
|
182 |
tab := TabView origin:0.0 @ 0.0 corner:1.0 @ 1.0 in:top.
|
367
|
183 |
tab tabWidget:#Mac.
|
|
184 |
list := #( 'SBrowser' 'FBrowser' 'Debugger' ).
|
|
185 |
list := list collect:[:n | Image fromFile:'bitmaps/' , n , '.xbm'].
|
|
186 |
list add:'A Text'.
|
|
187 |
tab list:list.
|
|
188 |
tab action:[:indexOrNil| Transcript showCR:indexOrNil ].
|
|
189 |
top extent:(tab preferredExtent).
|
343
|
190 |
top open.
|
367
|
191 |
[exEnd]
|
343
|
192 |
|
367
|
193 |
tabs at top of view dealing with other models
|
|
194 |
|
|
195 |
[exBegin]
|
352
|
196 |
|top sel view l top2 s top3 p|
|
343
|
197 |
|
|
198 |
l := SelectionInList new.
|
|
199 |
l list:#('foo' 'bar' 'baz').
|
|
200 |
l selectionIndex:1.
|
|
201 |
|
|
202 |
top2 := StandardSystemView new.
|
367
|
203 |
top2 extent:100@100.
|
343
|
204 |
s := SelectionInListView origin:0.0@0.0 corner:1.0@1.0 in:top2.
|
|
205 |
s model:l.
|
|
206 |
top2 open.
|
|
207 |
|
|
208 |
top3 := StandardSystemView new.
|
367
|
209 |
top3 extent:100@100.
|
343
|
210 |
s := PopUpList in:top3.
|
|
211 |
s model:l.
|
|
212 |
top3 open.
|
|
213 |
|
499
|
214 |
top := StandardSystemView new label:'example'; extent:200@50.
|
|
215 |
sel := TabView origin:0.0 @ 0.0 corner:1.0 @ 1.0 in:top.
|
367
|
216 |
sel useIndex:true.
|
343
|
217 |
sel model:(l selectionIndexHolder).
|
|
218 |
sel listHolder:(l listHolder).
|
367
|
219 |
sel action:[:indexOrNil|Transcript showCR:indexOrNil].
|
343
|
220 |
top open.
|
|
221 |
[exEnd]
|
|
222 |
"
|
|
223 |
! !
|
|
224 |
|
|
225 |
!TabView class methodsFor:'defaults'!
|
|
226 |
|
|
227 |
defaultTabWidget
|
367
|
228 |
^ #Window
|
343
|
229 |
! !
|
|
230 |
|
|
231 |
!TabView methodsFor:'accessing'!
|
|
232 |
|
|
233 |
action:oneArgBlock
|
|
234 |
"set the action block to be performed on select; the argument to
|
|
235 |
the block is the selected index or nil in case of no selection.
|
|
236 |
"
|
|
237 |
action := oneArgBlock.
|
|
238 |
|
|
239 |
!
|
|
240 |
|
418
|
241 |
backgroundColor
|
|
242 |
^ viewBackground
|
|
243 |
!
|
|
244 |
|
697
|
245 |
fontAscent
|
|
246 |
fontAscent isNil ifTrue:[
|
|
247 |
fontAscent := self font ascent
|
|
248 |
].
|
|
249 |
^ fontAscent
|
|
250 |
!
|
|
251 |
|
|
252 |
fontDescent
|
|
253 |
fontDescent isNil ifTrue:[
|
|
254 |
fontDescent := self font descent
|
|
255 |
].
|
|
256 |
^ fontDescent
|
|
257 |
!
|
|
258 |
|
343
|
259 |
list
|
|
260 |
"return the list
|
|
261 |
"
|
|
262 |
^ list
|
|
263 |
!
|
|
264 |
|
|
265 |
list:aList
|
|
266 |
"set the list
|
|
267 |
"
|
697
|
268 |
|hasChanged newSel model|
|
376
|
269 |
|
|
270 |
aList size == list size ifTrue:[
|
|
271 |
list notNil ifTrue:[
|
|
272 |
list keysAndValuesDo:[:aKey :aTab|
|
|
273 |
(aTab label) = (aList at:aKey) ifFalse:[
|
499
|
274 |
hasChanged := true
|
376
|
275 |
]
|
|
276 |
]
|
|
277 |
].
|
499
|
278 |
hasChanged == true ifFalse:[^ self ].
|
376
|
279 |
].
|
343
|
280 |
|
697
|
281 |
self removeListDependencies.
|
|
282 |
|
343
|
283 |
aList size ~~ 0 ifTrue:[
|
697
|
284 |
(newSel := self tabAt:selection) notNil ifTrue:[
|
|
285 |
newSel := newSel printableLabel
|
|
286 |
].
|
499
|
287 |
list := (tabStyle at:#widget) labels:aList for:self.
|
|
288 |
|
697
|
289 |
list do:[:aTab|
|
|
290 |
(model := aTab model) notNil ifTrue:[
|
|
291 |
model addDependent:self
|
|
292 |
]
|
|
293 |
].
|
|
294 |
|
499
|
295 |
newSel notNil ifTrue:[
|
697
|
296 |
(newSel := list findFirst:[:aTab| aTab printableLabel = newSel]) == 0 ifTrue:[
|
499
|
297 |
newSel := nil
|
|
298 |
]
|
|
299 |
].
|
|
300 |
] ifFalse:[
|
|
301 |
list := nil.
|
343
|
302 |
].
|
499
|
303 |
selection := newSel.
|
|
304 |
|
343
|
305 |
self shown ifTrue:[
|
|
306 |
self recomputeList.
|
793
|
307 |
self invalidateRepairNow:true.
|
376
|
308 |
self changed:#preferredExtent
|
|
309 |
].
|
343
|
310 |
!
|
|
311 |
|
508
|
312 |
oneTabPerLine
|
|
313 |
^ oneTabPerLine
|
|
314 |
!
|
|
315 |
|
|
316 |
oneTabPerLine:aBool
|
|
317 |
oneTabPerLine := aBool.
|
|
318 |
!
|
|
319 |
|
387
|
320 |
useIndex
|
|
321 |
"use index instead of name
|
|
322 |
"
|
|
323 |
^ useIndex
|
|
324 |
|
|
325 |
|
|
326 |
!
|
|
327 |
|
|
328 |
useIndex:aBoolean
|
|
329 |
"set/clear the useIndex flag. If set, both actionBlock and change-messages
|
|
330 |
are passed the index(indices) of the selection as argument.
|
|
331 |
If clear, the value(s) (i.e. the selected string) is passed.
|
|
332 |
Default is false."
|
|
333 |
|
|
334 |
useIndex := aBoolean
|
|
335 |
|
|
336 |
|
418
|
337 |
!
|
|
338 |
|
|
339 |
viewBackground:aColor
|
|
340 |
"update colors
|
|
341 |
"
|
|
342 |
super viewBackground:aColor.
|
|
343 |
TabWidget computeColorsOn:self style:tabStyle.
|
|
344 |
self invalidate.
|
387
|
345 |
! !
|
|
346 |
|
391
|
347 |
!TabView methodsFor:'accessing behavior'!
|
|
348 |
|
|
349 |
enabled
|
|
350 |
"returns true if tabs are enabled
|
|
351 |
"
|
|
352 |
^ enabled
|
|
353 |
!
|
|
354 |
|
|
355 |
enabled:aState
|
|
356 |
"set enabled state
|
|
357 |
"
|
|
358 |
|state|
|
|
359 |
|
|
360 |
state := aState ? true.
|
|
361 |
|
|
362 |
enabled ~~ state ifTrue:[
|
|
363 |
enabled := state.
|
499
|
364 |
self redrawLabels.
|
391
|
365 |
]
|
397
|
366 |
!
|
|
367 |
|
|
368 |
isEnabled:aState
|
|
369 |
"ST-80 compatibility; set enabled state
|
|
370 |
"
|
|
371 |
self enabled:aState
|
|
372 |
|
|
373 |
|
670
|
374 |
!
|
|
375 |
|
|
376 |
selectConditionBlock
|
|
377 |
"get the conditionBlock; this block is evaluated before a selection
|
|
378 |
change is performed; the change will not be done, if the evaluation
|
|
379 |
returns false. The argument to the block is the selection index
|
|
380 |
"
|
|
381 |
^ selectConditionBlock
|
|
382 |
!
|
|
383 |
|
|
384 |
selectConditionBlock:aOneArgBlock
|
|
385 |
"get the conditionBlock; this block is evaluated before a selection
|
|
386 |
change is performed; the change will not be done, if the evaluation
|
|
387 |
returns false. The argument to the block is the selection index
|
|
388 |
"
|
|
389 |
selectConditionBlock := aOneArgBlock
|
391
|
390 |
! !
|
|
391 |
|
387
|
392 |
!TabView methodsFor:'accessing channels/holders'!
|
|
393 |
|
|
394 |
enableChannel
|
|
395 |
"return a valueHolder for enable/disable
|
|
396 |
"
|
|
397 |
^ enableChannel
|
|
398 |
!
|
|
399 |
|
|
400 |
enableChannel:aValueHolderForBoolean
|
|
401 |
"set the valueHolder used for enable/disable
|
|
402 |
"
|
603
|
403 |
|
|
404 |
|prev|
|
387
|
405 |
|
603
|
406 |
prev := enableChannel.
|
|
407 |
enableChannel := aValueHolderForBoolean.
|
|
408 |
self setupChannel:aValueHolderForBoolean for:nil withOld:prev
|
387
|
409 |
|
603
|
410 |
"Modified: / 31.10.1997 / 14:48:59 / cg"
|
387
|
411 |
!
|
|
412 |
|
343
|
413 |
listHolder
|
|
414 |
"returns the list holder
|
|
415 |
"
|
|
416 |
^ listHolder
|
|
417 |
!
|
|
418 |
|
|
419 |
listHolder:aValueHolder
|
|
420 |
"change the list holder
|
|
421 |
"
|
|
422 |
listHolder notNil ifTrue:[
|
|
423 |
listHolder removeDependent:self.
|
|
424 |
].
|
387
|
425 |
|
343
|
426 |
listHolder := aValueHolder.
|
|
427 |
listHolder notNil ifTrue:[
|
|
428 |
listHolder addDependent:self.
|
|
429 |
self list:listHolder value.
|
|
430 |
self selection:model value.
|
|
431 |
].
|
|
432 |
!
|
|
433 |
|
|
434 |
model:aValueHolder
|
|
435 |
super model:aValueHolder.
|
500
|
436 |
|
343
|
437 |
model notNil ifTrue:[
|
|
438 |
self selection:(model value)
|
|
439 |
]
|
|
440 |
! !
|
|
441 |
|
367
|
442 |
!TabView methodsFor:'accessing dimension'!
|
|
443 |
|
|
444 |
preferredExtent
|
|
445 |
"compute max extent x/y based on one line
|
|
446 |
"
|
508
|
447 |
|x y ovl size maxY|
|
|
448 |
|
|
449 |
(size := list size) == 0 ifTrue:[^ 0 @ 0 ].
|
367
|
450 |
|
508
|
451 |
maxY := tabStyle at:#maxY.
|
|
452 |
y := maxY + self viewSpacing.
|
367
|
453 |
|
508
|
454 |
oneTabPerLine ifTrue:[
|
|
455 |
y := y + ((size - 1) * maxY).
|
367
|
456 |
|
508
|
457 |
(self isHorizontalDirection) ifTrue:[x := super extent x]
|
|
458 |
ifFalse:[x := super extent y]
|
|
459 |
] ifFalse:[
|
|
460 |
x := ovl := tabStyle at:#rightCovered.
|
|
461 |
list do:[:aTab|x := x - ovl + aTab preferredExtentX]
|
367
|
462 |
].
|
|
463 |
|
508
|
464 |
(self isHorizontalDirection) ifTrue:[^ x @ y]
|
|
465 |
ifFalse:[^ y @ x]
|
367
|
466 |
!
|
|
467 |
|
|
468 |
preferredSizeXorY
|
|
469 |
"returns preferred size dependant on the current view layout and
|
|
470 |
the direction of the tabs
|
|
471 |
"
|
|
472 |
list size == 0 ifFalse:[
|
369
|
473 |
maxRawNr isNil ifTrue:[self recomputeList].
|
367
|
474 |
|
508
|
475 |
oneTabPerLine ifTrue:[
|
|
476 |
self isHorizontalDirection ifTrue:[^ super extent y]
|
|
477 |
ifFalse:[^ super extent x]
|
|
478 |
].
|
|
479 |
^ ((maxRawNr * (tabStyle at:#maxY)) + self viewSpacing).
|
367
|
480 |
].
|
|
481 |
^ 0
|
508
|
482 |
!
|
|
483 |
|
|
484 |
viewSpacing
|
|
485 |
"returns my view spacing
|
|
486 |
"
|
|
487 |
^ ((tabStyle at:#expandSelection) y) + (self class viewSpacing)
|
367
|
488 |
! !
|
|
489 |
|
343
|
490 |
!TabView methodsFor:'accessing style'!
|
|
491 |
|
367
|
492 |
direction
|
369
|
493 |
"returns the direction of tabs as symbol. On default the value is
|
|
494 |
set to #top. Valid symbols are:
|
|
495 |
#top arrange tabs to be on top of a view
|
|
496 |
#bottom arrange tabs to be on bottom of a view
|
|
497 |
#left arrange tabs to be on left of a view
|
|
498 |
#right arrange tabs to be on right of a view
|
367
|
499 |
"
|
|
500 |
^ direction
|
|
501 |
|
|
502 |
!
|
|
503 |
|
|
504 |
direction:aDirection
|
369
|
505 |
"change the direction of tabs. On default the value is set to #top.
|
|
506 |
Valid symbols are:
|
|
507 |
#top arrange tabs to be on top of a view
|
|
508 |
#bottom arrange tabs to be on bottom of a view
|
|
509 |
#left arrange tabs to be on left of a view
|
|
510 |
#right arrange tabs to be on right of a view
|
367
|
511 |
"
|
374
|
512 |
direction ~~ aDirection ifTrue:[
|
|
513 |
direction := aDirection.
|
|
514 |
self changed:#direction
|
|
515 |
].
|
367
|
516 |
!
|
|
517 |
|
369
|
518 |
fitLastRow
|
|
519 |
"in case of true, the last row is expanded to the view size like all
|
|
520 |
other raws. In case of false all the tabs in the last raw keep their
|
|
521 |
preferred extent (x or y) dependant on the direction.
|
|
522 |
"
|
|
523 |
^ fitLastRow
|
|
524 |
!
|
|
525 |
|
|
526 |
fitLastRow:aBool
|
|
527 |
"in case of true, the last row is expanded to the view size like all
|
|
528 |
other raws. In case of false all the tabs in the last raw keep their
|
|
529 |
preferred extent (x or y) dependant on the direction.
|
|
530 |
"
|
|
531 |
fitLastRow := aBool
|
|
532 |
!
|
|
533 |
|
697
|
534 |
font:aFont
|
|
535 |
(aFont ~= font) ifTrue:[
|
|
536 |
super font:aFont.
|
|
537 |
fontAscent := fontDescent := nil
|
|
538 |
]
|
|
539 |
|
|
540 |
!
|
|
541 |
|
369
|
542 |
moveSelectedRow
|
|
543 |
"in case of true, the raw assigned to the tab will be moved
|
|
544 |
to the first line (to the view). Otherwise the position of
|
|
545 |
the view will be kept.
|
|
546 |
"
|
|
547 |
^ moveSelectedRow
|
|
548 |
!
|
|
549 |
|
|
550 |
moveSelectedRow:aBool
|
|
551 |
"in case of true, the raw assigned to the tab will be moved
|
|
552 |
to the first line (to the view). Otherwise the position of
|
|
553 |
the view will be kept.
|
|
554 |
"
|
|
555 |
moveSelectedRow := aBool
|
|
556 |
!
|
|
557 |
|
367
|
558 |
style
|
369
|
559 |
"returns the style sheet derived from the current widget class
|
367
|
560 |
"
|
|
561 |
^ tabStyle
|
|
562 |
!
|
|
563 |
|
343
|
564 |
styleAt:anIdentifier
|
369
|
565 |
"returns a specific entry into the widget description. For more information
|
|
566 |
see the specific widget class ( TabWidget ... ).
|
343
|
567 |
"
|
|
568 |
^ tabStyle at:anIdentifier
|
|
569 |
!
|
|
570 |
|
|
571 |
styleAt:anIdentifier put:something
|
369
|
572 |
"change a specific entry from the widget description. For more information
|
|
573 |
see the specific widget class ( TabWidget ... ).
|
343
|
574 |
"
|
352
|
575 |
tabStyle at:anIdentifier put:something.
|
343
|
576 |
!
|
|
577 |
|
352
|
578 |
tabWidget
|
369
|
579 |
"returns the current widget class as symbol
|
352
|
580 |
"
|
|
581 |
|widget|
|
|
582 |
|
|
583 |
widget := tabStyle at:#widget.
|
|
584 |
widget := widget nameWithoutPrefix asSymbol.
|
|
585 |
^ widget
|
|
586 |
!
|
|
587 |
|
343
|
588 |
tabWidget:aWidget
|
369
|
589 |
"change the current widget class. An existing list will be
|
|
590 |
recomputed and redrawn
|
343
|
591 |
"
|
369
|
592 |
|widget labels|
|
|
593 |
|
|
594 |
(self tabWidget) ~~ aWidget ifTrue:[
|
|
595 |
widget := TabWidget widgetClass:aWidget.
|
343
|
596 |
|
367
|
597 |
widget notNil ifTrue:[
|
369
|
598 |
tabStyle := widget tabStyleOn:self.
|
|
599 |
|
|
600 |
list notNil ifTrue:[
|
|
601 |
labels := list collect:[:aTab| aTab label].
|
|
602 |
list := widget labels:labels for:self.
|
|
603 |
|
|
604 |
self shown ifTrue:[
|
|
605 |
self recomputeList.
|
418
|
606 |
self invalidate.
|
369
|
607 |
]
|
|
608 |
]
|
343
|
609 |
]
|
367
|
610 |
]
|
343
|
611 |
! !
|
|
612 |
|
418
|
613 |
!TabView methodsFor:'accessing tabs'!
|
|
614 |
|
|
615 |
tabAt:anIndex
|
|
616 |
"get tab at an index or nil
|
|
617 |
"
|
697
|
618 |
^ anIndex notNil ifTrue:[list at:anIndex ifAbsent:nil] ifFalse:[nil]
|
418
|
619 |
! !
|
|
620 |
|
343
|
621 |
!TabView methodsFor:'change & update'!
|
|
622 |
|
|
623 |
update:something with:aParameter from:changedObject
|
369
|
624 |
"one of my models changed its value
|
343
|
625 |
"
|
697
|
626 |
|idx tab|
|
|
627 |
|
391
|
628 |
changedObject == model ifTrue:[^ self selection:model value].
|
|
629 |
changedObject == listHolder ifTrue:[^ self list:(listHolder value)].
|
|
630 |
changedObject == enableChannel ifTrue:[^ self enabled:(enableChannel value)].
|
697
|
631 |
|
|
632 |
( list isNil
|
|
633 |
or:[(idx := list findFirst:[:aTab| aTab model == changedObject]) == 0]
|
|
634 |
) ifTrue:[
|
|
635 |
^ self
|
|
636 |
].
|
|
637 |
|
|
638 |
self shown ifTrue:[
|
|
639 |
tab := list at:idx.
|
|
640 |
|
|
641 |
something == #foregroundColor ifTrue:[
|
|
642 |
^ self redrawLabelOfTab:tab
|
|
643 |
].
|
|
644 |
|
|
645 |
something == #enabled ifTrue:[
|
|
646 |
idx == selection ifTrue:[
|
|
647 |
^ self selection:nil
|
|
648 |
].
|
|
649 |
^ self redrawLabelOfTab:tab
|
|
650 |
].
|
|
651 |
tab labelChanged.
|
|
652 |
self recomputeList.
|
|
653 |
self invalidate.
|
|
654 |
self changed:#preferredExtent
|
|
655 |
]
|
|
656 |
|
343
|
657 |
! !
|
|
658 |
|
|
659 |
!TabView methodsFor:'drawing'!
|
|
660 |
|
|
661 |
paintColor:aColorSymbol
|
369
|
662 |
"set the paint color derived from the symbol used as key into the current
|
|
663 |
style sheet to access the color
|
343
|
664 |
"
|
|
665 |
self paint:(tabStyle at:aColorSymbol)
|
|
666 |
!
|
|
667 |
|
550
|
668 |
redraw
|
|
669 |
"redraw"
|
|
670 |
|
|
671 |
self redrawX:0 y:0 width:width height:height.
|
|
672 |
|
|
673 |
!
|
|
674 |
|
697
|
675 |
redrawLabelOfTab:aTab
|
|
676 |
"redraw only the label of the tab
|
|
677 |
"
|
|
678 |
shown ifTrue:[
|
|
679 |
aTab == (self tabAt:selection) ifTrue:[
|
|
680 |
self selectedTab:aTab redrawBlock:[aTab redrawLabel]
|
|
681 |
] ifFalse:[
|
|
682 |
aTab redrawLabel
|
|
683 |
]
|
|
684 |
].
|
|
685 |
!
|
|
686 |
|
499
|
687 |
redrawLabels
|
|
688 |
"redraw all the labels
|
|
689 |
"
|
|
690 |
|selectedTab|
|
|
691 |
|
697
|
692 |
(shown and:[list size ~~ 0]) ifTrue:[
|
|
693 |
selectedTab := self tabAt:selection.
|
499
|
694 |
|
|
695 |
list reverseDo:[:aTab|
|
|
696 |
aTab ~~ selectedTab ifTrue:[
|
|
697 |
aTab redrawLabel
|
|
698 |
] ifFalse:[
|
|
699 |
self selectedTab:aTab redrawBlock:[aTab redrawLabel]
|
|
700 |
]
|
|
701 |
]
|
|
702 |
].
|
|
703 |
!
|
|
704 |
|
369
|
705 |
redrawRawAt:aRawNr
|
|
706 |
"redraw raw at a number; all contained tabs are drawn unselected
|
367
|
707 |
"
|
372
|
708 |
list reverseDo:[:aTab|aTab lineNr == aRawNr ifTrue:[aTab redraw:false]].
|
367
|
709 |
!
|
|
710 |
|
548
|
711 |
redrawRawAt:aRawNr in:aRectangle
|
|
712 |
"redraw raw at a number; all contained tabs are drawn unselected
|
|
713 |
"
|
|
714 |
list reverseDo:[:aTab|
|
|
715 |
aTab lineNr == aRawNr ifTrue:[
|
|
716 |
(aTab intersects:aRectangle) ifTrue:[
|
|
717 |
aTab redraw:false
|
|
718 |
]
|
|
719 |
]
|
|
720 |
].
|
|
721 |
!
|
|
722 |
|
367
|
723 |
redrawSelection
|
|
724 |
"redraw current selection
|
|
725 |
"
|
499
|
726 |
|tab idx|
|
343
|
727 |
|
499
|
728 |
(selection notNil and:[self shown and:[list size ~~ 0]]) ifTrue:[
|
|
729 |
tab := list at:selection.
|
|
730 |
idx := tab lineNr.
|
|
731 |
self selectedTab:tab redrawBlock:[tab redraw:true].
|
|
732 |
[(idx := idx - 1) ~~ 0] whileTrue:[self redrawRawAt:idx].
|
|
733 |
].
|
|
734 |
!
|
|
735 |
|
|
736 |
redrawX:x y:y width:w height:h
|
|
737 |
"a region must be redrawn
|
|
738 |
"
|
548
|
739 |
|rectangle oldSelect prevClipArea|
|
|
740 |
|
|
741 |
self shown ifFalse:[
|
|
742 |
^ self
|
|
743 |
].
|
499
|
744 |
|
548
|
745 |
self paint:(self viewBackground).
|
|
746 |
self clearRectangleX:x y:y width:w height:h.
|
|
747 |
|
|
748 |
list size == 0 ifTrue:[^ self].
|
|
749 |
|
|
750 |
prevClipArea := clipRect.
|
|
751 |
clipRect := nil.
|
|
752 |
device setClipX:x y:y width:w height:h in:drawableId gc:gcId.
|
|
753 |
rectangle := Rectangle left:x top:y width:w height:h.
|
|
754 |
|
|
755 |
maxRawNr to:1 by:-1 do:[:i| self redrawRawAt:i in:rectangle].
|
499
|
756 |
|
548
|
757 |
selection notNil ifTrue:[
|
|
758 |
oldSelect := selection.
|
|
759 |
selection := nil.
|
|
760 |
self setSelection:oldSelect.
|
|
761 |
].
|
|
762 |
|
|
763 |
prevClipArea isNil ifTrue:[device noClipIn:drawableId gc:gcId]
|
|
764 |
ifFalse:[self clippingRectangle:prevClipArea].
|
499
|
765 |
|
867
|
766 |
"Modified: / 18.4.1998 / 16:19:58 / cg"
|
499
|
767 |
!
|
|
768 |
|
|
769 |
selectedTab:aTab redrawBlock:aRedrawBlock
|
|
770 |
"calculate extent of selection and evaluate the block which will
|
|
771 |
perform a redraw action
|
|
772 |
"
|
545
|
773 |
|tab oldAnc newAnc oldExt newExt expSel expDlt x y|
|
343
|
774 |
|
367
|
775 |
tab := list at:selection.
|
|
776 |
oldAnc := tab anchor.
|
|
777 |
oldExt := tab extent.
|
|
778 |
expSel := tabStyle at:#expandSelection.
|
|
779 |
expDlt := expSel x.
|
|
780 |
|
369
|
781 |
(self isHorizontalDirection) ifTrue:[
|
367
|
782 |
newExt := oldExt + ( expDlt @ 0 ).
|
|
783 |
newAnc := oldAnc - ((expDlt//2) @ ((expSel y) negated)).
|
343
|
784 |
|
367
|
785 |
(x := newAnc x) < 0 ifTrue:[
|
|
786 |
newExt x:(newExt x + x).
|
|
787 |
newAnc x:0.
|
|
788 |
x := 0.
|
|
789 |
].
|
369
|
790 |
(x + newExt x) > (super extent x) ifTrue:[newExt x:((super extent x) - x)].
|
367
|
791 |
] ifFalse:[
|
|
792 |
newExt := oldExt + ( 0 @ expDlt ).
|
|
793 |
newAnc := oldAnc - (((expSel y) negated) @ (expDlt//2)).
|
343
|
794 |
|
367
|
795 |
(y := newAnc y) < 0 ifTrue:[
|
|
796 |
newExt y:(newExt y + y).
|
|
797 |
newAnc y:0.
|
|
798 |
y := 0.
|
|
799 |
].
|
369
|
800 |
(y + newExt y) > (super extent y) ifTrue:[newExt y:((super extent y) - y)].
|
343
|
801 |
].
|
|
802 |
|
367
|
803 |
tab anchor:newAnc extent:newExt.
|
499
|
804 |
aRedrawBlock value.
|
367
|
805 |
tab anchor:oldAnc extent:oldExt.
|
352
|
806 |
|
343
|
807 |
! !
|
|
808 |
|
|
809 |
!TabView methodsFor:'event handling'!
|
|
810 |
|
|
811 |
buttonPress:button x:x y:y
|
369
|
812 |
"a button is pressed; find tab under point and set the selection
|
343
|
813 |
"
|
499
|
814 |
|idx|
|
|
815 |
|
|
816 |
( self isEnabled
|
|
817 |
and:[list notNil
|
|
818 |
and:[(idx := list findFirst:[:aTab|aTab containsPoint:(x@y)]) ~~ 0]]
|
|
819 |
) ifTrue:[
|
|
820 |
self selection:idx
|
|
821 |
].
|
343
|
822 |
!
|
|
823 |
|
346
|
824 |
keyPress:aKey x:x y:y
|
|
825 |
"selection might change; look for corresponding list entry
|
|
826 |
"
|
670
|
827 |
|size index n|
|
|
828 |
|
|
829 |
(self isEnabled and:[(size := list size) > 1]) ifFalse:[
|
|
830 |
^ self
|
|
831 |
].
|
346
|
832 |
|
670
|
833 |
(aKey == #CursorRight or:[aKey == #CursorDown]) ifTrue:[
|
|
834 |
n := selection ? 0.
|
697
|
835 |
|
670
|
836 |
(size - 1) timesRepeat:[
|
|
837 |
(n := n + 1) > size ifTrue:[n := 1].
|
|
838 |
|
697
|
839 |
(self canSelectTabAtIndex:n) ifTrue:[
|
670
|
840 |
^ self selection:n
|
346
|
841 |
]
|
670
|
842 |
].
|
|
843 |
^ self
|
|
844 |
].
|
|
845 |
|
|
846 |
(aKey == #CursorLeft or:[aKey == #CursorUp]) ifTrue:[
|
|
847 |
n := selection ? size.
|
697
|
848 |
|
670
|
849 |
(size - 1) timesRepeat:[
|
|
850 |
(n := n - 1) < 1 ifTrue:[n := size].
|
|
851 |
|
697
|
852 |
(self canSelectTabAtIndex:n) ifTrue:[
|
670
|
853 |
^ self selection:n
|
|
854 |
]
|
|
855 |
].
|
|
856 |
^ self
|
|
857 |
].
|
|
858 |
|
|
859 |
aKey isCharacter ifTrue:[
|
|
860 |
(selection isNil or:[selection == size]) ifTrue:[index := 1]
|
|
861 |
ifFalse:[index := selection + 1].
|
|
862 |
|
|
863 |
n := index - 1.
|
|
864 |
[
|
|
865 |
n := self findTabStartingWithKey:aKey startingAt:n + 1.
|
|
866 |
|
697
|
867 |
(n ~~ 0 and:[self canSelectTabAtIndex:n]) ifTrue:[
|
|
868 |
^ self selection:n
|
670
|
869 |
].
|
|
870 |
n ~~ 0
|
418
|
871 |
|
670
|
872 |
] whileTrue.
|
|
873 |
|
|
874 |
index ~~ 1 ifTrue:[
|
|
875 |
(n := self findTabStartingWithKey:aKey startingAt:1) ~~ 0 ifTrue:[
|
|
876 |
^ self selection:n
|
346
|
877 |
]
|
|
878 |
]
|
|
879 |
].
|
|
880 |
|
670
|
881 |
super keyPress:aKey x:x y:y
|
867
|
882 |
!
|
|
883 |
|
|
884 |
sizeChanged:how
|
|
885 |
"size of view changed
|
|
886 |
"
|
|
887 |
|extent delta dX dY|
|
|
888 |
|
|
889 |
list size ~~ 0 ifTrue:[
|
|
890 |
extent := super extent.
|
|
891 |
delta := oldExtent - extent.
|
|
892 |
|
|
893 |
((dX := delta x) > 1 or:[dX < -1
|
|
894 |
or:[(dY := delta y) > 1 or:[dY < -1]]]) ifTrue:[
|
|
895 |
oldExtent := extent.
|
|
896 |
self recomputeList.
|
|
897 |
self changed:#preferredExtent.
|
|
898 |
].
|
|
899 |
shown ifTrue:[
|
|
900 |
self invalidate
|
|
901 |
]
|
|
902 |
].
|
|
903 |
super sizeChanged:how
|
|
904 |
|
|
905 |
"Modified: / 18.4.1998 / 16:25:30 / cg"
|
343
|
906 |
! !
|
|
907 |
|
|
908 |
!TabView methodsFor:'initialization'!
|
|
909 |
|
387
|
910 |
destroy
|
|
911 |
listHolder notNil ifTrue:[
|
|
912 |
listHolder removeDependent:self.
|
|
913 |
].
|
|
914 |
enableChannel notNil ifTrue:[
|
|
915 |
enableChannel removeDependent:self.
|
|
916 |
].
|
697
|
917 |
self removeListDependencies.
|
387
|
918 |
super destroy.
|
|
919 |
!
|
|
920 |
|
343
|
921 |
initialize
|
|
922 |
"setup default attributes
|
|
923 |
"
|
|
924 |
|widget|
|
|
925 |
|
|
926 |
super initialize.
|
369
|
927 |
|
576
|
928 |
self cursor:Cursor hand.
|
|
929 |
|
369
|
930 |
widget := TabWidget widgetClass:(self class defaultTabWidget).
|
|
931 |
tabStyle := widget tabStyleOn:self.
|
|
932 |
useIndex := false.
|
508
|
933 |
oneTabPerLine := false.
|
369
|
934 |
direction := #top.
|
|
935 |
fitLastRow := true.
|
|
936 |
moveSelectedRow := true.
|
391
|
937 |
enabled := true.
|
410
|
938 |
super font:(Label defaultFont on:device).
|
418
|
939 |
oldExtent := 0@0.
|
576
|
940 |
|
|
941 |
"Modified: 23.10.1997 / 03:28:02 / cg"
|
343
|
942 |
! !
|
|
943 |
|
|
944 |
!TabView methodsFor:'layout'!
|
|
945 |
|
369
|
946 |
changeRaw:aRawA with:aRawB
|
|
947 |
"exchange positions of two raws
|
|
948 |
"
|
|
949 |
|tabB tabA ancA ancB hrz|
|
|
950 |
|
372
|
951 |
tabA := list at:(list findFirst:[:aTab|aTab lineNr == aRawA]).
|
|
952 |
tabB := list at:(list findFirst:[:aTab|aTab lineNr == aRawB]).
|
369
|
953 |
hrz := (self isHorizontalDirection).
|
|
954 |
|
|
955 |
hrz ifTrue:[
|
|
956 |
ancA := tabA anchor y.
|
|
957 |
ancB := tabB anchor y.
|
|
958 |
] ifFalse:[
|
|
959 |
ancA := tabA anchor x.
|
|
960 |
ancB := tabB anchor x.
|
|
961 |
].
|
|
962 |
|
|
963 |
list do:[:aTab||ln|
|
|
964 |
(ln := aTab lineNr) == aRawB ifTrue:[
|
|
965 |
aTab lineNr:aRawA.
|
|
966 |
hrz ifTrue:[aTab anchor y:ancA]
|
|
967 |
ifFalse:[aTab anchor x:ancA]
|
|
968 |
] ifFalse:[
|
|
969 |
ln == aRawA ifTrue:[
|
|
970 |
aTab lineNr:aRawB.
|
|
971 |
hrz ifTrue:[aTab anchor y:ancB]
|
|
972 |
ifFalse:[aTab anchor x:ancB]
|
|
973 |
]
|
|
974 |
]
|
|
975 |
].
|
|
976 |
|
508
|
977 |
oneTabPerLine ifFalse:[
|
|
978 |
aRawB == maxRawNr ifTrue:[
|
|
979 |
self fitRawAt:aRawA.
|
369
|
980 |
self unfitLastRaw.
|
508
|
981 |
] ifFalse:[
|
|
982 |
aRawA == maxRawNr ifTrue:[
|
|
983 |
self fitRawAt:aRawB.
|
|
984 |
self unfitLastRaw.
|
|
985 |
]
|
369
|
986 |
]
|
|
987 |
]
|
|
988 |
!
|
|
989 |
|
|
990 |
fitRawAt:aRawNr
|
|
991 |
"fit raw to view's size
|
|
992 |
"
|
|
993 |
|last first tab ext org max size|
|
|
994 |
|
508
|
995 |
(aRawNr ~~ maxRawNr or:[fitLastRow]) ifFalse:[
|
|
996 |
^ self
|
|
997 |
].
|
369
|
998 |
|
|
999 |
last := list findLast:[:aTab| aTab lineNr == aRawNr ].
|
|
1000 |
first := list findFirst:[:aTab| aTab lineNr == aRawNr ].
|
372
|
1001 |
tab := list at:last.
|
369
|
1002 |
size := last - first + 1.
|
|
1003 |
org := 0.
|
|
1004 |
|
|
1005 |
(self isHorizontalDirection) ifTrue:[
|
|
1006 |
max := super extent x.
|
|
1007 |
ext := (max - ((tab anchor x) + (tab extent x))) // size.
|
|
1008 |
|
|
1009 |
ext > 1 ifTrue:[
|
372
|
1010 |
first to:last do:[:i|
|
369
|
1011 |
tab := list at:i.
|
|
1012 |
tab extent x:((tab extent x) + ext).
|
|
1013 |
tab anchor x:((tab anchor x) + org).
|
|
1014 |
org := org + ext.
|
|
1015 |
].
|
372
|
1016 |
tab := list at:last.
|
369
|
1017 |
].
|
|
1018 |
tab extent x:(max - tab anchor x).
|
|
1019 |
] ifFalse:[
|
|
1020 |
max := super extent y.
|
|
1021 |
ext := (max - ((tab anchor y) + (tab extent y))) // size.
|
|
1022 |
|
|
1023 |
ext > 1 ifTrue:[
|
372
|
1024 |
first to:last do:[:i|
|
369
|
1025 |
tab := list at:i.
|
|
1026 |
tab extent y:((tab extent y) + ext).
|
|
1027 |
tab anchor y:((tab anchor y) + org).
|
|
1028 |
org := org + ext.
|
|
1029 |
].
|
372
|
1030 |
tab := list at:last.
|
369
|
1031 |
].
|
|
1032 |
tab extent y:(max - tab anchor y).
|
|
1033 |
]
|
|
1034 |
!
|
|
1035 |
|
343
|
1036 |
recomputeList
|
369
|
1037 |
"recompute list
|
343
|
1038 |
"
|
545
|
1039 |
|maxY x y maxSz ovl|
|
343
|
1040 |
|
508
|
1041 |
list size == 0 ifTrue:[
|
|
1042 |
^ self
|
|
1043 |
].
|
369
|
1044 |
|
508
|
1045 |
maxY := tabStyle at:#maxY.
|
|
1046 |
ovl := tabStyle at:#rightCovered.
|
|
1047 |
maxRawNr := 1.
|
369
|
1048 |
|
508
|
1049 |
(self isHorizontalDirection) ifTrue:[
|
|
1050 |
maxSz := super extent x.
|
|
1051 |
x := 0.
|
|
1052 |
y := maxY.
|
|
1053 |
|
|
1054 |
oneTabPerLine ifTrue:[
|
|
1055 |
list do:[:aTab|
|
369
|
1056 |
aTab lineNr:maxRawNr.
|
508
|
1057 |
aTab anchor:x@y extent:(maxSz @ maxY).
|
|
1058 |
maxRawNr := maxRawNr + 1.
|
|
1059 |
y := y + maxY.
|
|
1060 |
].
|
|
1061 |
^ self
|
|
1062 |
].
|
|
1063 |
list do:[:aTab||eX n|
|
|
1064 |
eX := aTab preferredExtentX.
|
|
1065 |
n := eX + x - ovl.
|
369
|
1066 |
|
508
|
1067 |
(n > maxSz and:[x ~~ 0]) ifTrue:[
|
|
1068 |
maxRawNr := maxRawNr + 1.
|
|
1069 |
x := 0.
|
|
1070 |
y := y + maxY.
|
|
1071 |
n := eX - ovl.
|
|
1072 |
].
|
|
1073 |
aTab lineNr:maxRawNr.
|
|
1074 |
aTab anchor:x@y extent:(eX @ maxY).
|
|
1075 |
x := n.
|
|
1076 |
]
|
|
1077 |
] ifFalse:[
|
|
1078 |
maxSz := super extent y.
|
|
1079 |
x := maxY.
|
|
1080 |
y := 0.
|
369
|
1081 |
|
508
|
1082 |
oneTabPerLine ifTrue:[
|
|
1083 |
list do:[:aTab|
|
369
|
1084 |
aTab lineNr:maxRawNr.
|
508
|
1085 |
aTab anchor:x@y extent:(maxY @ maxSz).
|
|
1086 |
maxRawNr := maxRawNr + 1.
|
|
1087 |
x := x + maxY.
|
|
1088 |
].
|
|
1089 |
^ self
|
369
|
1090 |
].
|
508
|
1091 |
list do:[:aTab||eY n|
|
|
1092 |
eY := aTab preferredExtentX.
|
|
1093 |
n := eY + y - ovl.
|
|
1094 |
|
|
1095 |
(n > maxSz and:[y ~~ 0]) ifTrue:[
|
|
1096 |
maxRawNr := maxRawNr + 1.
|
|
1097 |
y := 0.
|
|
1098 |
x := x + maxY.
|
|
1099 |
n := eY - ovl.
|
|
1100 |
].
|
|
1101 |
aTab lineNr:maxRawNr.
|
|
1102 |
aTab anchor:x@y extent:(maxY @ eY).
|
|
1103 |
y := n.
|
|
1104 |
]
|
367
|
1105 |
].
|
508
|
1106 |
"/ fit raws to view
|
|
1107 |
1 to:maxRawNr do:[:aLnNr|self fitRawAt:aLnNr].
|
367
|
1108 |
!
|
|
1109 |
|
369
|
1110 |
unfitLastRaw
|
|
1111 |
"use the preferred extent for all tabs in the last raw
|
367
|
1112 |
"
|
369
|
1113 |
|last first tab ovl anchor extent pos offset hrz|
|
343
|
1114 |
|
508
|
1115 |
fitLastRow ifTrue:[
|
|
1116 |
^ self
|
|
1117 |
].
|
369
|
1118 |
last := list findLast:[:aTab| aTab lineNr == maxRawNr ].
|
|
1119 |
first := list findFirst:[:aTab| aTab lineNr == maxRawNr ].
|
367
|
1120 |
ovl := tabStyle at:#rightCovered.
|
369
|
1121 |
pos := 0.
|
|
1122 |
hrz := (self isHorizontalDirection).
|
367
|
1123 |
|
372
|
1124 |
first to:last do:[:i|
|
369
|
1125 |
tab := list at:i.
|
|
1126 |
anchor := tab anchor.
|
|
1127 |
extent := tab extent.
|
|
1128 |
offset := tab preferredExtentX.
|
367
|
1129 |
|
369
|
1130 |
hrz ifTrue:[
|
|
1131 |
extent x:offset.
|
|
1132 |
anchor x:pos
|
|
1133 |
] ifFalse:[
|
|
1134 |
extent y:offset.
|
|
1135 |
anchor y:pos.
|
367
|
1136 |
].
|
369
|
1137 |
tab anchor:anchor extent:extent.
|
|
1138 |
pos := pos + offset - ovl.
|
349
|
1139 |
].
|
369
|
1140 |
! !
|
343
|
1141 |
|
373
|
1142 |
!TabView methodsFor:'private'!
|
|
1143 |
|
418
|
1144 |
findTabStartingWithKey:aKey startingAt:anIndex
|
697
|
1145 |
"get index of tab starting its printableLabel with a key or 0
|
418
|
1146 |
"
|
697
|
1147 |
|upper lower|
|
418
|
1148 |
|
|
1149 |
(aKey isCharacter and:[anIndex <= list size]) ifFalse:[ ^ 0 ].
|
|
1150 |
|
|
1151 |
upper := aKey asUppercase.
|
|
1152 |
lower := aKey asLowercase.
|
|
1153 |
|
697
|
1154 |
^ list findFirst:[:aTab||l c|
|
|
1155 |
( (l := aTab printableLabel) isString
|
|
1156 |
and:[((c := l first) == lower or:[c == upper])]
|
|
1157 |
)
|
418
|
1158 |
] startingAt:anIndex
|
|
1159 |
!
|
|
1160 |
|
373
|
1161 |
listIndexOf:something
|
|
1162 |
"convert something to an index into list or nil.
|
|
1163 |
"
|
|
1164 |
|index|
|
|
1165 |
|
697
|
1166 |
something isNil ifTrue:[^ nil ].
|
|
1167 |
|
|
1168 |
something isNumber ifTrue:[
|
373
|
1169 |
index := something
|
697
|
1170 |
] ifFalse:[
|
|
1171 |
index := list findFirst:[:aTab|aTab label = something].
|
|
1172 |
|
|
1173 |
index == 0 ifTrue:[
|
|
1174 |
index := list findFirst:[:aTab|aTab printableLabel = something].
|
|
1175 |
]
|
373
|
1176 |
].
|
697
|
1177 |
^ index ~~ 0 ifTrue:[index] ifFalse:[nil]
|
|
1178 |
!
|
|
1179 |
|
|
1180 |
removeListDependencies
|
|
1181 |
|model|
|
|
1182 |
|
|
1183 |
list notNil ifTrue:[
|
|
1184 |
list do:[:aTab|
|
|
1185 |
(model := aTab model) notNil ifTrue:[
|
|
1186 |
model removeDependent:self
|
|
1187 |
]
|
|
1188 |
]
|
|
1189 |
]
|
373
|
1190 |
! !
|
|
1191 |
|
369
|
1192 |
!TabView methodsFor:'queries'!
|
343
|
1193 |
|
697
|
1194 |
canSelectTabAtIndex:anIndex
|
|
1195 |
"returns true if tab at an index is selectable
|
|
1196 |
"
|
|
1197 |
(list at:anIndex) isEnabled ifTrue:[
|
|
1198 |
^ selectConditionBlock isNil ifTrue:[true]
|
|
1199 |
ifFalse:[selectConditionBlock value:anIndex]
|
|
1200 |
].
|
|
1201 |
^ false
|
|
1202 |
!
|
|
1203 |
|
703
|
1204 |
getBackgroundPaintForTab:aTab
|
|
1205 |
"returns background color of the tab
|
|
1206 |
"
|
|
1207 |
|key|
|
|
1208 |
|
|
1209 |
key := aTab == (self tabAt:selection) ifFalse:[#unselectedColor]
|
|
1210 |
ifTrue:[#selectedColor].
|
|
1211 |
|
|
1212 |
^ tabStyle at:key
|
|
1213 |
!
|
|
1214 |
|
387
|
1215 |
isEnabled
|
391
|
1216 |
"returns enabled state
|
|
1217 |
"
|
|
1218 |
^ enabled
|
387
|
1219 |
!
|
|
1220 |
|
369
|
1221 |
isHorizontalDirection
|
|
1222 |
"returns true in case of direction is #top or #bottom
|
|
1223 |
"
|
|
1224 |
^ (direction == #top or:[direction == #bottom])
|
|
1225 |
|
367
|
1226 |
!
|
343
|
1227 |
|
369
|
1228 |
isVerticalDirection
|
|
1229 |
"returns true in case of direction is #left or #right
|
367
|
1230 |
"
|
369
|
1231 |
^ (direction == #left or:[direction == #right])
|
367
|
1232 |
|
343
|
1233 |
! !
|
|
1234 |
|
|
1235 |
!TabView methodsFor:'selection'!
|
|
1236 |
|
703
|
1237 |
isTabSelected:aTab
|
|
1238 |
"returns true if tab is selected
|
|
1239 |
"
|
|
1240 |
^ aTab == (self tabAt:selection)
|
|
1241 |
!
|
|
1242 |
|
343
|
1243 |
selection
|
|
1244 |
"return the selection index or nil
|
|
1245 |
"
|
697
|
1246 |
|tab|
|
|
1247 |
|
352
|
1248 |
useIndex ifTrue:[
|
500
|
1249 |
^ selection ? 0
|
352
|
1250 |
].
|
697
|
1251 |
tab := self tabAt:selection.
|
|
1252 |
^ tab notNil ifTrue:[tab label] ifFalse:[nil]
|
343
|
1253 |
!
|
|
1254 |
|
|
1255 |
selection:anIndexOrNil
|
|
1256 |
"change the selection to index or nil. The model and/or actionBlock is notified
|
|
1257 |
"
|
499
|
1258 |
|oldSel|
|
|
1259 |
|
|
1260 |
oldSel := selection.
|
|
1261 |
self setSelection:anIndexOrNil.
|
|
1262 |
oldSel ~~ selection ifTrue:[self selectionHasChanged].
|
|
1263 |
!
|
|
1264 |
|
|
1265 |
selectionHasChanged
|
|
1266 |
"selection might change; raise notification
|
|
1267 |
"
|
352
|
1268 |
|sel|
|
343
|
1269 |
|
499
|
1270 |
sel := self selection.
|
343
|
1271 |
|
499
|
1272 |
model notNil ifTrue:[model value:sel].
|
|
1273 |
action notNil ifTrue:[action value:sel]
|
343
|
1274 |
|
|
1275 |
!
|
|
1276 |
|
373
|
1277 |
setSelection:something
|
343
|
1278 |
"change the selection to index or nil. No notifications are raised
|
|
1279 |
"
|
373
|
1280 |
|newSel lnNr tab last first exp x y w h|
|
343
|
1281 |
|
418
|
1282 |
list size == 0 ifTrue:[^ self].
|
373
|
1283 |
newSel := self listIndexOf:something.
|
|
1284 |
selection == newSel ifTrue:[^ self].
|
670
|
1285 |
|
591
|
1286 |
newSel notNil ifTrue:[
|
697
|
1287 |
(self tabAt:newSel) isNil ifTrue:[
|
670
|
1288 |
newSel := nil
|
697
|
1289 |
] ifFalse:[
|
|
1290 |
(self canSelectTabAtIndex:newSel) ifFalse:[^ self ].
|
670
|
1291 |
]
|
591
|
1292 |
].
|
372
|
1293 |
|
352
|
1294 |
self shown ifFalse:[
|
373
|
1295 |
selection := newSel.
|
352
|
1296 |
^ self
|
|
1297 |
].
|
|
1298 |
|
445
|
1299 |
maxRawNr isNil ifTrue:[
|
|
1300 |
selection := newSel.
|
|
1301 |
self recomputeList.
|
|
1302 |
^ self invalidate.
|
|
1303 |
].
|
|
1304 |
|
591
|
1305 |
(newSel notNil
|
|
1306 |
and:[moveSelectedRow
|
|
1307 |
and:[(lnNr := (list at:newSel) lineNr) > 1]]
|
|
1308 |
) ifTrue:[
|
369
|
1309 |
self changeRaw:1 with:lnNr.
|
418
|
1310 |
selection := 1. "/ force a redraw
|
352
|
1311 |
].
|
|
1312 |
|
|
1313 |
selection notNil ifTrue:[
|
373
|
1314 |
maxRawNr > 1 ifTrue:[
|
418
|
1315 |
self paint:(self viewBackground). "/ total redraw
|
|
1316 |
self clear.
|
373
|
1317 |
selection := nil.
|
418
|
1318 |
maxRawNr to:1 by:-1 do:[:i| self redrawRawAt:i ].
|
373
|
1319 |
] ifFalse:[
|
|
1320 |
first := 1.
|
|
1321 |
|
499
|
1322 |
(selection ~~ 1 and:[(tabStyle at:#rightCovered) == 0]) ifTrue:[
|
373
|
1323 |
first := selection - 1
|
|
1324 |
].
|
|
1325 |
|
|
1326 |
(last := selection + 1) > list size ifTrue:[
|
|
1327 |
last := selection
|
|
1328 |
].
|
|
1329 |
exp := (tabStyle at:#expandSelection) x.
|
|
1330 |
tab := list at:selection.
|
|
1331 |
|
|
1332 |
self isHorizontalDirection ifTrue:[
|
|
1333 |
(x := tab anchor x - (exp // 2)) < 0 ifTrue:[x := 0].
|
|
1334 |
w := tab extent x + exp.
|
|
1335 |
h := super extent y.
|
|
1336 |
y := 0.
|
|
1337 |
] ifFalse:[
|
|
1338 |
(y := tab anchor y - (exp // 2)) < 0 ifTrue:[y := 0].
|
|
1339 |
h := tab extent y + exp.
|
|
1340 |
w := super extent x.
|
|
1341 |
x := 0.
|
|
1342 |
].
|
|
1343 |
self paint:(self viewBackground).
|
|
1344 |
self clearRectangleX:x y:y width:w height:h.
|
|
1345 |
|
|
1346 |
last to:first by:-1 do:[:i|
|
|
1347 |
tab := list at:i.
|
|
1348 |
tab redraw:false
|
|
1349 |
]
|
|
1350 |
]
|
352
|
1351 |
].
|
373
|
1352 |
selection := newSel.
|
367
|
1353 |
self redrawSelection.
|
591
|
1354 |
|
|
1355 |
"Modified: / 29.10.1997 / 15:50:13 / cg"
|
343
|
1356 |
! !
|
|
1357 |
|
|
1358 |
!TabView class methodsFor:'documentation'!
|
|
1359 |
|
|
1360 |
version
|
867
|
1361 |
^ '$Header: /cvs/stx/stx/libwidg2/TabView.st,v 1.34 1998-04-18 14:25:56 cg Exp $'
|
343
|
1362 |
! !
|