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
|
391
|
15 |
instanceVariableNames:'list listHolder selection enabled action tabStyle sizeChanged
|
|
16 |
useIndex maxRawNr direction fitLastRow moveSelectedRow
|
|
17 |
enableChannel'
|
343
|
18 |
classVariableNames:''
|
|
19 |
poolDictionaries:''
|
|
20 |
category:'Views-Interactors'
|
|
21 |
!
|
|
22 |
|
|
23 |
!TabView 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 |
implements the tabs-view component of a noteBook.
|
|
43 |
May also be used on its own (without a surrounding noteBook).
|
|
44 |
|
|
45 |
The functionality is basically the same as provided by a
|
|
46 |
PopUpList or SelectionInListView, in that a valueHolder
|
|
47 |
gets a value assigned corresponding to the selected tab
|
|
48 |
from a list of possible tabs.
|
|
49 |
|
|
50 |
[author:]
|
|
51 |
Claus Atzkern
|
|
52 |
|
|
53 |
[see also:]
|
|
54 |
NoteBookView
|
369
|
55 |
SelectionInListView PopUpList ValueHolder TabWidget
|
343
|
56 |
"
|
|
57 |
|
|
58 |
!
|
|
59 |
|
|
60 |
examples
|
|
61 |
"
|
367
|
62 |
tabs at top of a view
|
343
|
63 |
[exBegin]
|
367
|
64 |
|top tab view inset|
|
|
65 |
|
|
66 |
top := StandardSystemView new label:'tabs at top'; extent:250@100.
|
|
67 |
tab := self origin:0.0 @ 0.0 corner:1.0 @ 0.0 in:top.
|
|
68 |
view := View origin:0.0 @ 0.0 corner:1.0 @ 1.0 in:top.
|
|
69 |
|
|
70 |
view viewBackground:(tab styleAt:#selectedColor).
|
|
71 |
tab direction:#top.
|
|
72 |
tab list:#( 'Foo' 'Bar' 'Baz' ).
|
|
73 |
inset := tab preferredSizeXorY.
|
|
74 |
tab bottomInset:(inset negated).
|
|
75 |
view topInset:inset.
|
|
76 |
tab action:[:aName|Transcript showCR:aName].
|
|
77 |
top open.
|
|
78 |
[exEnd]
|
343
|
79 |
|
367
|
80 |
tabs at bottom of a view; changing widget to MAC style
|
|
81 |
[exBegin]
|
|
82 |
|top tab view inset|
|
|
83 |
|
|
84 |
top := StandardSystemView new label:'tabs at bottom'; extent:250@100.
|
|
85 |
view := View origin:0.0 @ 0.0 corner:1.0 @ 1.0 in:top.
|
|
86 |
tab := self origin:0.0 @ 1.0 corner:1.0 @ 1.0 in:top.
|
343
|
87 |
|
367
|
88 |
view viewBackground:(tab styleAt:#selectedColor).
|
|
89 |
tab direction:#bottom.
|
|
90 |
tab tabWidget:#Mac.
|
343
|
91 |
|
367
|
92 |
tab list:#( 'Foo' 'Bar' 'Baz' ).
|
|
93 |
inset := tab preferredSizeXorY.
|
|
94 |
tab topInset:(inset negated).
|
|
95 |
view bottomInset:inset.
|
|
96 |
tab action:[:aName|Transcript showCR:aName].
|
|
97 |
top open.
|
|
98 |
[exEnd]
|
343
|
99 |
|
367
|
100 |
tabs at right of a view
|
|
101 |
[exBegin]
|
|
102 |
|top tab view inset|
|
|
103 |
|
|
104 |
top := StandardSystemView new label:'tabs at right'; extent:100@250.
|
|
105 |
view := View origin:0.0 @ 0.0 corner:1.0 @ 1.0 in:top.
|
|
106 |
tab := self origin:1.0 @ 0.0 corner:1.0 @ 1.0 in:top.
|
|
107 |
|
|
108 |
view viewBackground:(tab styleAt:#selectedColor).
|
|
109 |
tab direction:#right.
|
|
110 |
tab list:#( 'Foo' 'Bar' 'Baz' ).
|
|
111 |
inset := tab preferredSizeXorY.
|
|
112 |
tab leftInset:(inset negated).
|
|
113 |
view rightInset:inset.
|
|
114 |
tab action:[:aName|Transcript showCR:aName].
|
343
|
115 |
top open.
|
367
|
116 |
[exEnd]
|
343
|
117 |
|
367
|
118 |
tabs at left of a view
|
343
|
119 |
[exBegin]
|
367
|
120 |
|top tab view inset|
|
|
121 |
|
|
122 |
top := StandardSystemView new label:'tabs at left'; extent:100@250.
|
|
123 |
tab := self origin:0.0 @ 0.0 corner:0.0 @ 1.0 in:top.
|
|
124 |
view := View origin:0.0 @ 0.0 corner:1.0 @ 1.0 in:top.
|
343
|
125 |
|
367
|
126 |
view viewBackground:(tab styleAt:#selectedColor).
|
|
127 |
tab direction:#left.
|
|
128 |
tab list:#( 'Foo' 'Bar' 'Baz' ).
|
|
129 |
inset := tab preferredSizeXorY.
|
|
130 |
tab rightInset:(inset negated).
|
|
131 |
view leftInset:inset.
|
|
132 |
tab action:[:aName|Transcript showCR:aName].
|
|
133 |
top open.
|
|
134 |
[exEnd]
|
343
|
135 |
|
367
|
136 |
changing default style( see TabWidget class ); useing index
|
|
137 |
[exBegin]
|
|
138 |
|top tab view|
|
|
139 |
|
|
140 |
top := StandardSystemView new label:'example'; extent:450@300.
|
|
141 |
tab := self origin:0.0 @ 0.0 corner:1.0 @ 40 in:top.
|
|
142 |
tab horizontalInset:10.
|
|
143 |
view := NoteBookFrameView origin:0.0 @ 40 corner:1.0 @ 1.0 in:top.
|
343
|
144 |
view horizontalInset:10.
|
|
145 |
view bottomInset:10.
|
|
146 |
view level:2.
|
|
147 |
view viewBackground:(Image fromFile:'bitmaps/gifImages/garfield.gif').
|
|
148 |
|
367
|
149 |
tab styleAt:#selectedColor put:(view viewBackground).
|
|
150 |
tab styleAt:#unselectedColor put:(Color grey:60).
|
|
151 |
tab styleAt:#expandSelection put:9@7.
|
343
|
152 |
|
367
|
153 |
tab list:#( 'Foo' 'Bar' 'Baz').
|
|
154 |
tab useIndex:true.
|
|
155 |
tab action:[:aName| Transcript showCR:aName ].
|
352
|
156 |
|
343
|
157 |
top open.
|
367
|
158 |
[exEnd]
|
343
|
159 |
|
|
160 |
|
367
|
161 |
using images and text
|
|
162 |
[exBegin]
|
|
163 |
|top tab view list|
|
|
164 |
|
|
165 |
top := StandardSystemView new label:'example'.
|
343
|
166 |
|
367
|
167 |
tab := self origin:0.0 @ 0.0 corner:1.0 @ 1.0 in:top.
|
|
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'.
|
343
|
182 |
|
367
|
183 |
tab := self origin:0.0 @ 0.0 corner:1.0 @ 1.0 in:top.
|
|
184 |
tab tabWidget:#Mac.
|
|
185 |
list := #( 'SBrowser' 'FBrowser' 'Debugger' ).
|
|
186 |
list := list collect:[:n | Image fromFile:'bitmaps/' , n , '.xbm'].
|
|
187 |
list add:'A Text'.
|
|
188 |
tab list:list.
|
|
189 |
tab action:[:indexOrNil| Transcript showCR:indexOrNil ].
|
|
190 |
top extent:(tab preferredExtent).
|
343
|
191 |
top open.
|
367
|
192 |
[exEnd]
|
343
|
193 |
|
367
|
194 |
tabs at top of view dealing with other models
|
|
195 |
|
|
196 |
[exBegin]
|
352
|
197 |
|top sel view l top2 s top3 p|
|
343
|
198 |
|
|
199 |
l := SelectionInList new.
|
|
200 |
l list:#('foo' 'bar' 'baz').
|
|
201 |
l selectionIndex:1.
|
|
202 |
|
|
203 |
top2 := StandardSystemView new.
|
367
|
204 |
top2 extent:100@100.
|
343
|
205 |
s := SelectionInListView origin:0.0@0.0 corner:1.0@1.0 in:top2.
|
|
206 |
s model:l.
|
|
207 |
top2 open.
|
|
208 |
|
|
209 |
top3 := StandardSystemView new.
|
367
|
210 |
top3 extent:100@100.
|
343
|
211 |
s := PopUpList in:top3.
|
|
212 |
s model:l.
|
|
213 |
top3 open.
|
|
214 |
|
|
215 |
top := StandardSystemView new
|
367
|
216 |
label:'example';
|
|
217 |
extent:200@50.
|
343
|
218 |
|
|
219 |
sel := self origin:0.0 @ 0.0 corner:1.0 @ 1.0 in:top.
|
367
|
220 |
sel useIndex:true.
|
343
|
221 |
sel model:(l selectionIndexHolder).
|
|
222 |
sel listHolder:(l listHolder).
|
367
|
223 |
sel action:[:indexOrNil|Transcript showCR:indexOrNil].
|
343
|
224 |
top open.
|
|
225 |
[exEnd]
|
|
226 |
"
|
|
227 |
! !
|
|
228 |
|
|
229 |
!TabView class methodsFor:'defaults'!
|
|
230 |
|
|
231 |
defaultTabWidget
|
367
|
232 |
^ #Window
|
343
|
233 |
! !
|
|
234 |
|
|
235 |
!TabView methodsFor:'accessing'!
|
|
236 |
|
|
237 |
action:oneArgBlock
|
|
238 |
"set the action block to be performed on select; the argument to
|
|
239 |
the block is the selected index or nil in case of no selection.
|
|
240 |
"
|
|
241 |
action := oneArgBlock.
|
|
242 |
|
|
243 |
!
|
|
244 |
|
|
245 |
list
|
|
246 |
"return the list
|
|
247 |
"
|
|
248 |
^ list
|
|
249 |
!
|
|
250 |
|
|
251 |
list:aList
|
|
252 |
"set the list
|
|
253 |
"
|
376
|
254 |
|widget redraw|
|
|
255 |
|
|
256 |
aList size == list size ifTrue:[
|
|
257 |
redraw := false.
|
343
|
258 |
|
376
|
259 |
list notNil ifTrue:[
|
|
260 |
list keysAndValuesDo:[:aKey :aTab|
|
|
261 |
(aTab label) = (aList at:aKey) ifFalse:[
|
|
262 |
redraw := true
|
|
263 |
]
|
|
264 |
]
|
|
265 |
].
|
|
266 |
redraw ifFalse:[^ self ].
|
|
267 |
].
|
387
|
268 |
self selection:nil.
|
343
|
269 |
list := nil.
|
|
270 |
|
|
271 |
aList size ~~ 0 ifTrue:[
|
|
272 |
widget := tabStyle at:#widget.
|
367
|
273 |
list := widget labels:aList for:self.
|
343
|
274 |
].
|
|
275 |
self shown ifTrue:[
|
|
276 |
self recomputeList.
|
|
277 |
self redrawFull.
|
376
|
278 |
self changed:#preferredExtent
|
|
279 |
].
|
343
|
280 |
!
|
|
281 |
|
387
|
282 |
useIndex
|
|
283 |
"use index instead of name
|
|
284 |
"
|
|
285 |
^ useIndex
|
|
286 |
|
|
287 |
|
|
288 |
!
|
|
289 |
|
|
290 |
useIndex:aBoolean
|
|
291 |
"set/clear the useIndex flag. If set, both actionBlock and change-messages
|
|
292 |
are passed the index(indices) of the selection as argument.
|
|
293 |
If clear, the value(s) (i.e. the selected string) is passed.
|
|
294 |
Default is false."
|
|
295 |
|
|
296 |
useIndex := aBoolean
|
|
297 |
|
|
298 |
|
|
299 |
! !
|
|
300 |
|
391
|
301 |
!TabView methodsFor:'accessing behavior'!
|
|
302 |
|
|
303 |
enabled
|
|
304 |
"returns true if tabs are enabled
|
|
305 |
"
|
|
306 |
^ enabled
|
|
307 |
!
|
|
308 |
|
|
309 |
enabled:aState
|
|
310 |
"set enabled state
|
|
311 |
"
|
|
312 |
|state|
|
|
313 |
|
|
314 |
state := aState ? true.
|
|
315 |
|
|
316 |
enabled ~~ state ifTrue:[
|
|
317 |
enabled := state.
|
|
318 |
self redrawFull
|
|
319 |
]
|
397
|
320 |
!
|
|
321 |
|
|
322 |
isEnabled:aState
|
|
323 |
"ST-80 compatibility; set enabled state
|
|
324 |
"
|
|
325 |
self enabled:aState
|
|
326 |
|
|
327 |
|
391
|
328 |
! !
|
|
329 |
|
387
|
330 |
!TabView methodsFor:'accessing channels/holders'!
|
|
331 |
|
|
332 |
enableChannel
|
|
333 |
"return a valueHolder for enable/disable
|
|
334 |
"
|
|
335 |
^ enableChannel
|
|
336 |
!
|
|
337 |
|
|
338 |
enableChannel:aValueHolderForBoolean
|
|
339 |
"set the valueHolder used for enable/disable
|
|
340 |
"
|
|
341 |
enableChannel notNil ifTrue:[
|
|
342 |
enableChannel removeDependent:self.
|
|
343 |
].
|
|
344 |
enableChannel := aValueHolderForBoolean.
|
|
345 |
|
|
346 |
enableChannel notNil ifTrue:[
|
|
347 |
enableChannel addDependent:self.
|
|
348 |
].
|
391
|
349 |
self enabled:(enableChannel value).
|
387
|
350 |
|
|
351 |
|
|
352 |
|
|
353 |
!
|
|
354 |
|
343
|
355 |
listHolder
|
|
356 |
"returns the list holder
|
|
357 |
"
|
|
358 |
^ listHolder
|
|
359 |
!
|
|
360 |
|
|
361 |
listHolder:aValueHolder
|
|
362 |
"change the list holder
|
|
363 |
"
|
|
364 |
listHolder notNil ifTrue:[
|
|
365 |
listHolder removeDependent:self.
|
|
366 |
].
|
387
|
367 |
|
343
|
368 |
listHolder := aValueHolder.
|
|
369 |
listHolder notNil ifTrue:[
|
|
370 |
listHolder addDependent:self.
|
|
371 |
self list:listHolder value.
|
|
372 |
self selection:model value.
|
|
373 |
].
|
|
374 |
!
|
|
375 |
|
|
376 |
model:aValueHolder
|
|
377 |
super model:aValueHolder.
|
|
378 |
model notNil ifTrue:[
|
|
379 |
self selection:(model value)
|
|
380 |
]
|
|
381 |
! !
|
|
382 |
|
367
|
383 |
!TabView methodsFor:'accessing dimension'!
|
|
384 |
|
|
385 |
preferredExtent
|
|
386 |
"compute max extent x/y based on one line
|
|
387 |
"
|
|
388 |
|x y ovl ext|
|
|
389 |
|
|
390 |
list size == 0 ifTrue:[^ 0 @ 0 ].
|
|
391 |
|
|
392 |
ovl := tabStyle at:#rightCovered.
|
|
393 |
x := ovl.
|
|
394 |
|
|
395 |
list do:[:aTab|
|
|
396 |
x := x - ovl + aTab preferredExtentX
|
|
397 |
].
|
|
398 |
y := (tabStyle at:#maxY)
|
|
399 |
+ ((tabStyle at:#expandSelection) y)
|
|
400 |
+ (self class viewSpacing).
|
|
401 |
|
369
|
402 |
(self isHorizontalDirection) ifTrue:[
|
367
|
403 |
^ x @ y
|
|
404 |
].
|
369
|
405 |
^ y @ x
|
367
|
406 |
!
|
|
407 |
|
|
408 |
preferredSizeXorY
|
|
409 |
"returns preferred size dependant on the current view layout and
|
|
410 |
the direction of the tabs
|
|
411 |
"
|
|
412 |
|y|
|
|
413 |
|
|
414 |
list size == 0 ifFalse:[
|
369
|
415 |
maxRawNr isNil ifTrue:[self recomputeList].
|
367
|
416 |
|
369
|
417 |
y := (maxRawNr * (tabStyle at:#maxY))
|
367
|
418 |
+ ((tabStyle at:#expandSelection) y)
|
|
419 |
+ (self class viewSpacing).
|
|
420 |
|
|
421 |
^ y
|
|
422 |
].
|
|
423 |
^ 0
|
|
424 |
! !
|
|
425 |
|
343
|
426 |
!TabView methodsFor:'accessing style'!
|
|
427 |
|
367
|
428 |
direction
|
369
|
429 |
"returns the direction of tabs as symbol. On default the value is
|
|
430 |
set to #top. Valid symbols are:
|
|
431 |
#top arrange tabs to be on top of a view
|
|
432 |
#bottom arrange tabs to be on bottom of a view
|
|
433 |
#left arrange tabs to be on left of a view
|
|
434 |
#right arrange tabs to be on right of a view
|
367
|
435 |
"
|
|
436 |
^ direction
|
|
437 |
|
|
438 |
!
|
|
439 |
|
|
440 |
direction:aDirection
|
369
|
441 |
"change the direction of tabs. On default the value is set to #top.
|
|
442 |
Valid symbols are:
|
|
443 |
#top arrange tabs to be on top of a view
|
|
444 |
#bottom arrange tabs to be on bottom of a view
|
|
445 |
#left arrange tabs to be on left of a view
|
|
446 |
#right arrange tabs to be on right of a view
|
367
|
447 |
"
|
374
|
448 |
direction ~~ aDirection ifTrue:[
|
|
449 |
direction := aDirection.
|
|
450 |
self changed:#direction
|
|
451 |
].
|
367
|
452 |
!
|
|
453 |
|
369
|
454 |
fitLastRow
|
|
455 |
"in case of true, the last row is expanded to the view size like all
|
|
456 |
other raws. In case of false all the tabs in the last raw keep their
|
|
457 |
preferred extent (x or y) dependant on the direction.
|
|
458 |
"
|
|
459 |
^ fitLastRow
|
|
460 |
!
|
|
461 |
|
|
462 |
fitLastRow:aBool
|
|
463 |
"in case of true, the last row is expanded to the view size like all
|
|
464 |
other raws. In case of false all the tabs in the last raw keep their
|
|
465 |
preferred extent (x or y) dependant on the direction.
|
|
466 |
"
|
|
467 |
fitLastRow := aBool
|
|
468 |
!
|
|
469 |
|
|
470 |
moveSelectedRow
|
|
471 |
"in case of true, the raw assigned to the tab will be moved
|
|
472 |
to the first line (to the view). Otherwise the position of
|
|
473 |
the view will be kept.
|
|
474 |
"
|
|
475 |
^ moveSelectedRow
|
|
476 |
!
|
|
477 |
|
|
478 |
moveSelectedRow:aBool
|
|
479 |
"in case of true, the raw assigned to the tab will be moved
|
|
480 |
to the first line (to the view). Otherwise the position of
|
|
481 |
the view will be kept.
|
|
482 |
"
|
|
483 |
moveSelectedRow := aBool
|
|
484 |
!
|
|
485 |
|
367
|
486 |
style
|
369
|
487 |
"returns the style sheet derived from the current widget class
|
367
|
488 |
"
|
|
489 |
^ tabStyle
|
|
490 |
!
|
|
491 |
|
343
|
492 |
styleAt:anIdentifier
|
369
|
493 |
"returns a specific entry into the widget description. For more information
|
|
494 |
see the specific widget class ( TabWidget ... ).
|
343
|
495 |
"
|
|
496 |
^ tabStyle at:anIdentifier
|
|
497 |
!
|
|
498 |
|
|
499 |
styleAt:anIdentifier put:something
|
369
|
500 |
"change a specific entry from the widget description. For more information
|
|
501 |
see the specific widget class ( TabWidget ... ).
|
343
|
502 |
"
|
352
|
503 |
tabStyle at:anIdentifier put:something.
|
343
|
504 |
!
|
|
505 |
|
352
|
506 |
tabWidget
|
369
|
507 |
"returns the current widget class as symbol
|
352
|
508 |
"
|
|
509 |
|widget|
|
|
510 |
|
|
511 |
widget := tabStyle at:#widget.
|
|
512 |
widget := widget nameWithoutPrefix asSymbol.
|
|
513 |
^ widget
|
|
514 |
!
|
|
515 |
|
343
|
516 |
tabWidget:aWidget
|
369
|
517 |
"change the current widget class. An existing list will be
|
|
518 |
recomputed and redrawn
|
343
|
519 |
"
|
369
|
520 |
|widget labels|
|
|
521 |
|
|
522 |
(self tabWidget) ~~ aWidget ifTrue:[
|
|
523 |
widget := TabWidget widgetClass:aWidget.
|
343
|
524 |
|
367
|
525 |
widget notNil ifTrue:[
|
369
|
526 |
tabStyle := widget tabStyleOn:self.
|
|
527 |
|
|
528 |
list notNil ifTrue:[
|
|
529 |
labels := list collect:[:aTab| aTab label].
|
|
530 |
list := widget labels:labels for:self.
|
|
531 |
|
|
532 |
self shown ifTrue:[
|
|
533 |
self recomputeList.
|
|
534 |
self redrawFull
|
|
535 |
]
|
|
536 |
]
|
343
|
537 |
]
|
367
|
538 |
]
|
343
|
539 |
! !
|
|
540 |
|
|
541 |
!TabView methodsFor:'change & update'!
|
|
542 |
|
387
|
543 |
sizeChanged:how
|
|
544 |
"size of view changed
|
|
545 |
"
|
|
546 |
list notNil ifTrue:[
|
|
547 |
self recomputeList.
|
|
548 |
|
|
549 |
sizeChanged ifFalse:[
|
|
550 |
sizeChanged := true.
|
|
551 |
self changed:#preferredExtent.
|
|
552 |
sizeChanged := false.
|
|
553 |
]
|
|
554 |
].
|
|
555 |
|
|
556 |
|
|
557 |
!
|
|
558 |
|
343
|
559 |
update:something with:aParameter from:changedObject
|
369
|
560 |
"one of my models changed its value
|
343
|
561 |
"
|
391
|
562 |
changedObject == model ifTrue:[^ self selection:model value].
|
|
563 |
changedObject == listHolder ifTrue:[^ self list:(listHolder value)].
|
|
564 |
changedObject == enableChannel ifTrue:[^ self enabled:(enableChannel value)].
|
343
|
565 |
! !
|
|
566 |
|
|
567 |
!TabView methodsFor:'drawing'!
|
|
568 |
|
|
569 |
paintColor:aColorSymbol
|
369
|
570 |
"set the paint color derived from the symbol used as key into the current
|
|
571 |
style sheet to access the color
|
343
|
572 |
"
|
|
573 |
self paint:(tabStyle at:aColorSymbol)
|
|
574 |
!
|
|
575 |
|
|
576 |
redrawFull
|
369
|
577 |
"full redraw
|
343
|
578 |
"
|
367
|
579 |
|oldSelect|
|
|
580 |
|
|
581 |
(list size ~~ 0 and:[self shown]) ifTrue:[
|
|
582 |
self paint:(self viewBackground).
|
|
583 |
self clear.
|
|
584 |
|
369
|
585 |
maxRawNr to:1 by:-1 do:[:i|self redrawRawAt:i].
|
367
|
586 |
selection notNil ifTrue:[
|
|
587 |
oldSelect := selection.
|
|
588 |
selection := nil.
|
|
589 |
self setSelection:oldSelect.
|
|
590 |
]
|
|
591 |
]
|
|
592 |
!
|
|
593 |
|
369
|
594 |
redrawRawAt:aRawNr
|
|
595 |
"redraw raw at a number; all contained tabs are drawn unselected
|
367
|
596 |
"
|
372
|
597 |
list reverseDo:[:aTab|aTab lineNr == aRawNr ifTrue:[aTab redraw:false]].
|
367
|
598 |
!
|
|
599 |
|
|
600 |
redrawSelection
|
|
601 |
"redraw current selection
|
|
602 |
"
|
|
603 |
|tab size oldAnc newAnc oldExt newExt expSel expDlt x y|
|
343
|
604 |
|
|
605 |
size := list size.
|
|
606 |
|
367
|
607 |
(selection notNil and:[self shown and:[size ~~ 0]]) ifFalse:[
|
343
|
608 |
^ self
|
|
609 |
].
|
|
610 |
|
367
|
611 |
tab := list at:selection.
|
|
612 |
oldAnc := tab anchor.
|
|
613 |
oldExt := tab extent.
|
|
614 |
expSel := tabStyle at:#expandSelection.
|
|
615 |
expDlt := expSel x.
|
|
616 |
|
369
|
617 |
(self isHorizontalDirection) ifTrue:[
|
367
|
618 |
newExt := oldExt + ( expDlt @ 0 ).
|
|
619 |
newAnc := oldAnc - ((expDlt//2) @ ((expSel y) negated)).
|
343
|
620 |
|
367
|
621 |
(x := newAnc x) < 0 ifTrue:[
|
|
622 |
newExt x:(newExt x + x).
|
|
623 |
newAnc x:0.
|
|
624 |
x := 0.
|
|
625 |
].
|
369
|
626 |
(x + newExt x) > (super extent x) ifTrue:[newExt x:((super extent x) - x)].
|
367
|
627 |
] ifFalse:[
|
|
628 |
newExt := oldExt + ( 0 @ expDlt ).
|
|
629 |
newAnc := oldAnc - (((expSel y) negated) @ (expDlt//2)).
|
343
|
630 |
|
367
|
631 |
(y := newAnc y) < 0 ifTrue:[
|
|
632 |
newExt y:(newExt y + y).
|
|
633 |
newAnc y:0.
|
|
634 |
y := 0.
|
|
635 |
].
|
369
|
636 |
(y + newExt y) > (super extent y) ifTrue:[newExt y:((super extent y) - y)].
|
343
|
637 |
].
|
|
638 |
|
367
|
639 |
tab anchor:newAnc extent:newExt.
|
|
640 |
tab redraw:true.
|
|
641 |
tab anchor:oldAnc extent:oldExt.
|
352
|
642 |
|
367
|
643 |
size := tab lineNr.
|
369
|
644 |
[(size := size - 1) ~~ 0] whileTrue:[self redrawRawAt:size].
|
367
|
645 |
|
343
|
646 |
!
|
|
647 |
|
|
648 |
redrawX:x y:y width:w height:h
|
|
649 |
"a region must be redrawn
|
|
650 |
"
|
|
651 |
self redrawFull
|
|
652 |
! !
|
|
653 |
|
|
654 |
!TabView methodsFor:'event handling'!
|
|
655 |
|
|
656 |
buttonPress:button x:x y:y
|
369
|
657 |
"a button is pressed; find tab under point and set the selection
|
343
|
658 |
"
|
387
|
659 |
(self isEnabled and:[list notNil]) ifTrue:[
|
372
|
660 |
self selection:(list findFirst:[:aTab|aTab containsPoint:(x@y)])
|
352
|
661 |
]
|
343
|
662 |
!
|
|
663 |
|
346
|
664 |
keyPress:aKey x:x y:y
|
|
665 |
"selection might change; look for corresponding list entry
|
|
666 |
"
|
352
|
667 |
|size newSel|
|
346
|
668 |
|
391
|
669 |
(self isEnabled and:[(size := list size) ~~ 0]) ifTrue:[
|
372
|
670 |
(aKey == #CursorRight or:[aKey == #CursorDown]) ifTrue:[
|
346
|
671 |
(selection isNil or:[selection == size]) ifTrue:[
|
|
672 |
newSel := 1
|
|
673 |
] ifFalse:[
|
|
674 |
newSel := (selection + 1)
|
|
675 |
]
|
|
676 |
] ifFalse:[
|
372
|
677 |
(aKey == #CursorLeft or:[aKey == #CursorUp]) ifTrue:[
|
346
|
678 |
(selection isNil or:[selection == 1]) ifTrue:[
|
|
679 |
newSel := size
|
|
680 |
] ifFalse:[
|
|
681 |
newSel := (selection - 1)
|
|
682 |
]
|
|
683 |
]
|
|
684 |
].
|
|
685 |
newSel notNil ifTrue:[
|
|
686 |
self selection:newSel
|
|
687 |
]
|
|
688 |
|
|
689 |
].
|
|
690 |
|
343
|
691 |
! !
|
|
692 |
|
|
693 |
!TabView methodsFor:'initialization'!
|
|
694 |
|
387
|
695 |
destroy
|
|
696 |
listHolder notNil ifTrue:[
|
|
697 |
listHolder removeDependent:self.
|
|
698 |
].
|
|
699 |
enableChannel notNil ifTrue:[
|
|
700 |
enableChannel removeDependent:self.
|
|
701 |
].
|
|
702 |
super destroy.
|
|
703 |
!
|
|
704 |
|
343
|
705 |
initialize
|
|
706 |
"setup default attributes
|
|
707 |
"
|
|
708 |
|widget|
|
|
709 |
|
|
710 |
super initialize.
|
369
|
711 |
|
|
712 |
widget := TabWidget widgetClass:(self class defaultTabWidget).
|
|
713 |
tabStyle := widget tabStyleOn:self.
|
|
714 |
useIndex := false.
|
|
715 |
direction := #top.
|
|
716 |
sizeChanged := false.
|
|
717 |
fitLastRow := true.
|
|
718 |
moveSelectedRow := true.
|
391
|
719 |
enabled := true.
|
410
|
720 |
super font:(Label defaultFont on:device).
|
374
|
721 |
|
343
|
722 |
! !
|
|
723 |
|
|
724 |
!TabView methodsFor:'layout'!
|
|
725 |
|
369
|
726 |
changeRaw:aRawA with:aRawB
|
|
727 |
"exchange positions of two raws
|
|
728 |
"
|
|
729 |
|tabB tabA ancA ancB hrz|
|
|
730 |
|
372
|
731 |
tabA := list at:(list findFirst:[:aTab|aTab lineNr == aRawA]).
|
|
732 |
tabB := list at:(list findFirst:[:aTab|aTab lineNr == aRawB]).
|
369
|
733 |
hrz := (self isHorizontalDirection).
|
|
734 |
|
|
735 |
hrz ifTrue:[
|
|
736 |
ancA := tabA anchor y.
|
|
737 |
ancB := tabB anchor y.
|
|
738 |
] ifFalse:[
|
|
739 |
ancA := tabA anchor x.
|
|
740 |
ancB := tabB anchor x.
|
|
741 |
].
|
|
742 |
|
|
743 |
list do:[:aTab||ln|
|
|
744 |
(ln := aTab lineNr) == aRawB ifTrue:[
|
|
745 |
aTab lineNr:aRawA.
|
|
746 |
hrz ifTrue:[aTab anchor y:ancA]
|
|
747 |
ifFalse:[aTab anchor x:ancA]
|
|
748 |
] ifFalse:[
|
|
749 |
ln == aRawA ifTrue:[
|
|
750 |
aTab lineNr:aRawB.
|
|
751 |
hrz ifTrue:[aTab anchor y:ancB]
|
|
752 |
ifFalse:[aTab anchor x:ancB]
|
|
753 |
]
|
|
754 |
]
|
|
755 |
].
|
|
756 |
|
|
757 |
aRawB == maxRawNr ifTrue:[
|
|
758 |
self fitRawAt:aRawA.
|
|
759 |
self unfitLastRaw.
|
|
760 |
] ifFalse:[
|
|
761 |
aRawA == maxRawNr ifTrue:[
|
|
762 |
self fitRawAt:aRawB.
|
|
763 |
self unfitLastRaw.
|
|
764 |
]
|
|
765 |
]
|
|
766 |
!
|
|
767 |
|
|
768 |
fitRawAt:aRawNr
|
|
769 |
"fit raw to view's size
|
|
770 |
"
|
|
771 |
|last first tab ext org max size|
|
|
772 |
|
|
773 |
(aRawNr ~~ maxRawNr or:[fitLastRow]) ifFalse:[^ self].
|
|
774 |
|
|
775 |
last := list findLast:[:aTab| aTab lineNr == aRawNr ].
|
|
776 |
first := list findFirst:[:aTab| aTab lineNr == aRawNr ].
|
372
|
777 |
tab := list at:last.
|
369
|
778 |
size := last - first + 1.
|
|
779 |
org := 0.
|
|
780 |
|
|
781 |
(self isHorizontalDirection) ifTrue:[
|
|
782 |
max := super extent x.
|
|
783 |
ext := (max - ((tab anchor x) + (tab extent x))) // size.
|
|
784 |
|
|
785 |
ext > 1 ifTrue:[
|
372
|
786 |
first to:last do:[:i|
|
369
|
787 |
tab := list at:i.
|
|
788 |
tab extent x:((tab extent x) + ext).
|
|
789 |
tab anchor x:((tab anchor x) + org).
|
|
790 |
org := org + ext.
|
|
791 |
].
|
372
|
792 |
tab := list at:last.
|
369
|
793 |
].
|
|
794 |
tab extent x:(max - tab anchor x).
|
|
795 |
] ifFalse:[
|
|
796 |
max := super extent y.
|
|
797 |
ext := (max - ((tab anchor y) + (tab extent y))) // size.
|
|
798 |
|
|
799 |
ext > 1 ifTrue:[
|
372
|
800 |
first to:last do:[:i|
|
369
|
801 |
tab := list at:i.
|
|
802 |
tab extent y:((tab extent y) + ext).
|
|
803 |
tab anchor y:((tab anchor y) + org).
|
|
804 |
org := org + ext.
|
|
805 |
].
|
372
|
806 |
tab := list at:last.
|
369
|
807 |
].
|
|
808 |
tab extent y:(max - tab anchor y).
|
|
809 |
]
|
|
810 |
!
|
|
811 |
|
343
|
812 |
recomputeList
|
369
|
813 |
"recompute list
|
343
|
814 |
"
|
369
|
815 |
|tab maxY x y maxSz ovl|
|
343
|
816 |
|
367
|
817 |
list size ~~ 0 ifTrue:[
|
369
|
818 |
maxY := tabStyle at:#maxY.
|
|
819 |
ovl := tabStyle at:#rightCovered.
|
|
820 |
maxRawNr := 1.
|
|
821 |
|
|
822 |
(self isHorizontalDirection) ifTrue:[
|
|
823 |
maxSz := super extent x.
|
|
824 |
x := 0.
|
|
825 |
y := maxY.
|
|
826 |
|
372
|
827 |
list do:[:aTab||eX n|
|
369
|
828 |
eX := aTab preferredExtentX.
|
|
829 |
n := eX + x - ovl.
|
|
830 |
|
371
|
831 |
(n > maxSz and:[x ~~ 0]) ifTrue:[
|
369
|
832 |
maxRawNr := maxRawNr + 1.
|
|
833 |
x := 0.
|
|
834 |
y := y + maxY.
|
|
835 |
n := eX - ovl.
|
|
836 |
].
|
|
837 |
aTab lineNr:maxRawNr.
|
|
838 |
aTab anchor:x@y extent:(eX @ maxY).
|
|
839 |
x := n.
|
|
840 |
]
|
367
|
841 |
] ifFalse:[
|
369
|
842 |
maxSz := super extent y.
|
|
843 |
x := maxY.
|
|
844 |
y := 0.
|
|
845 |
|
372
|
846 |
list do:[:aTab||eY n|
|
369
|
847 |
eY := aTab preferredExtentX.
|
|
848 |
n := eY + y - ovl.
|
|
849 |
|
371
|
850 |
(n > maxSz and:[y ~~ 0]) ifTrue:[
|
369
|
851 |
maxRawNr := maxRawNr + 1.
|
|
852 |
y := 0.
|
|
853 |
x := x + maxY.
|
|
854 |
n := eY - ovl.
|
|
855 |
].
|
|
856 |
aTab lineNr:maxRawNr.
|
|
857 |
aTab anchor:x@y extent:(maxY @ eY).
|
|
858 |
y := n.
|
|
859 |
]
|
|
860 |
].
|
|
861 |
"/ fit raws to view
|
|
862 |
1 to:maxRawNr do:[:aLnNr|self fitRawAt:aLnNr].
|
367
|
863 |
].
|
|
864 |
!
|
|
865 |
|
369
|
866 |
unfitLastRaw
|
|
867 |
"use the preferred extent for all tabs in the last raw
|
367
|
868 |
"
|
369
|
869 |
|last first tab ovl anchor extent pos offset hrz|
|
343
|
870 |
|
369
|
871 |
fitLastRow ifTrue:[^ self].
|
|
872 |
|
|
873 |
last := list findLast:[:aTab| aTab lineNr == maxRawNr ].
|
|
874 |
first := list findFirst:[:aTab| aTab lineNr == maxRawNr ].
|
367
|
875 |
ovl := tabStyle at:#rightCovered.
|
369
|
876 |
pos := 0.
|
|
877 |
hrz := (self isHorizontalDirection).
|
367
|
878 |
|
372
|
879 |
first to:last do:[:i|
|
369
|
880 |
tab := list at:i.
|
|
881 |
anchor := tab anchor.
|
|
882 |
extent := tab extent.
|
|
883 |
offset := tab preferredExtentX.
|
367
|
884 |
|
369
|
885 |
hrz ifTrue:[
|
|
886 |
extent x:offset.
|
|
887 |
anchor x:pos
|
|
888 |
] ifFalse:[
|
|
889 |
extent y:offset.
|
|
890 |
anchor y:pos.
|
367
|
891 |
].
|
369
|
892 |
tab anchor:anchor extent:extent.
|
|
893 |
pos := pos + offset - ovl.
|
349
|
894 |
].
|
369
|
895 |
! !
|
343
|
896 |
|
373
|
897 |
!TabView methodsFor:'private'!
|
|
898 |
|
|
899 |
listIndexOf:something
|
|
900 |
"convert something to an index into list or nil.
|
|
901 |
"
|
|
902 |
|index|
|
|
903 |
|
|
904 |
something isString ifTrue:[
|
|
905 |
index := list findFirst:[:aTab|aTab label = something].
|
|
906 |
] ifFalse:[
|
|
907 |
index := something
|
|
908 |
].
|
|
909 |
index ~~ 0 ifTrue:[^ index]
|
|
910 |
ifFalse:[^ nil]
|
|
911 |
! !
|
|
912 |
|
369
|
913 |
!TabView methodsFor:'queries'!
|
343
|
914 |
|
387
|
915 |
isEnabled
|
391
|
916 |
"returns enabled state
|
|
917 |
"
|
|
918 |
^ enabled
|
387
|
919 |
!
|
|
920 |
|
369
|
921 |
isHorizontalDirection
|
|
922 |
"returns true in case of direction is #top or #bottom
|
|
923 |
"
|
|
924 |
^ (direction == #top or:[direction == #bottom])
|
|
925 |
|
367
|
926 |
!
|
343
|
927 |
|
369
|
928 |
isVerticalDirection
|
|
929 |
"returns true in case of direction is #left or #right
|
367
|
930 |
"
|
369
|
931 |
^ (direction == #left or:[direction == #right])
|
367
|
932 |
|
343
|
933 |
! !
|
|
934 |
|
|
935 |
!TabView methodsFor:'selection'!
|
|
936 |
|
|
937 |
selection
|
|
938 |
"return the selection index or nil
|
|
939 |
"
|
352
|
940 |
useIndex ifTrue:[
|
|
941 |
^ selection
|
|
942 |
].
|
|
943 |
|
|
944 |
(selection notNil and:[list size >= selection]) ifTrue:[
|
|
945 |
^ (list at:selection) label
|
|
946 |
].
|
|
947 |
^ nil
|
343
|
948 |
!
|
|
949 |
|
|
950 |
selection:anIndexOrNil
|
|
951 |
"change the selection to index or nil. The model and/or actionBlock is notified
|
|
952 |
"
|
352
|
953 |
|sel|
|
343
|
954 |
|
352
|
955 |
sel := selection.
|
343
|
956 |
self setSelection:anIndexOrNil.
|
|
957 |
|
352
|
958 |
(sel ~~ selection) ifTrue:[
|
|
959 |
sel := self selection.
|
|
960 |
|
367
|
961 |
model notNil ifTrue:[model value:sel].
|
|
962 |
action notNil ifTrue:[action value:sel]
|
343
|
963 |
]
|
|
964 |
|
|
965 |
!
|
|
966 |
|
373
|
967 |
setSelection:something
|
343
|
968 |
"change the selection to index or nil. No notifications are raised
|
|
969 |
"
|
373
|
970 |
|newSel lnNr tab last first exp x y w h|
|
343
|
971 |
|
373
|
972 |
list isNil ifTrue:[^ self].
|
|
973 |
newSel := self listIndexOf:something.
|
|
974 |
selection == newSel ifTrue:[^ self].
|
372
|
975 |
|
352
|
976 |
self shown ifFalse:[
|
373
|
977 |
selection := newSel.
|
352
|
978 |
^ self
|
|
979 |
].
|
|
980 |
|
373
|
981 |
(newSel notNil and:[moveSelectedRow and:[(lnNr := (list at:newSel) lineNr) > 1]]) ifTrue:[
|
369
|
982 |
self changeRaw:1 with:lnNr.
|
373
|
983 |
selection := 1. "/ force a redraw
|
352
|
984 |
].
|
|
985 |
|
|
986 |
selection notNil ifTrue:[
|
373
|
987 |
maxRawNr > 1 ifTrue:[
|
|
988 |
selection := nil.
|
|
989 |
self redrawFull.
|
|
990 |
] ifFalse:[
|
|
991 |
first := 1.
|
|
992 |
|
394
|
993 |
(selection > 2 and:[(tabStyle at:#rightCovered) ~~ 0]) ifTrue:[
|
373
|
994 |
first := selection - 1
|
|
995 |
].
|
|
996 |
|
|
997 |
(last := selection + 1) > list size ifTrue:[
|
|
998 |
last := selection
|
|
999 |
].
|
|
1000 |
exp := (tabStyle at:#expandSelection) x.
|
|
1001 |
tab := list at:selection.
|
|
1002 |
|
|
1003 |
self isHorizontalDirection ifTrue:[
|
|
1004 |
(x := tab anchor x - (exp // 2)) < 0 ifTrue:[x := 0].
|
|
1005 |
w := tab extent x + exp.
|
|
1006 |
h := super extent y.
|
|
1007 |
y := 0.
|
|
1008 |
] ifFalse:[
|
|
1009 |
(y := tab anchor y - (exp // 2)) < 0 ifTrue:[y := 0].
|
|
1010 |
h := tab extent y + exp.
|
|
1011 |
w := super extent x.
|
|
1012 |
x := 0.
|
|
1013 |
].
|
|
1014 |
self paint:(self viewBackground).
|
|
1015 |
self clearRectangleX:x y:y width:w height:h.
|
|
1016 |
|
|
1017 |
last to:first by:-1 do:[:i|
|
|
1018 |
tab := list at:i.
|
|
1019 |
tab redraw:false
|
|
1020 |
]
|
|
1021 |
]
|
352
|
1022 |
].
|
373
|
1023 |
selection := newSel.
|
367
|
1024 |
self redrawSelection.
|
343
|
1025 |
! !
|
|
1026 |
|
|
1027 |
!TabView class methodsFor:'documentation'!
|
|
1028 |
|
|
1029 |
version
|
410
|
1030 |
^ '$Header: /cvs/stx/stx/libwidg2/TabView.st,v 1.17 1997-06-04 11:19:26 ca Exp $'
|
343
|
1031 |
! !
|