author | Claus Gittinger <cg@exept.de> |
Wed, 26 Jun 2019 23:31:24 +0200 | |
changeset 6076 | e32451ae0577 |
parent 6045 | c1e2a95ac169 |
permissions | -rw-r--r-- |
6045 | 1 |
"{ Encoding: utf8 }" |
2 |
||
343 | 3 |
" |
4 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
1118
a49afa5a9f10
fixed font setup in initStyle.
Claus Gittinger <cg@exept.de>
parents:
913
diff
changeset
|
5 |
All Rights Reserved |
343 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
2531 | 14 |
"{ Package: 'stx:libwidg2' }" |
15 |
||
6045 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
1401 | 18 |
NoteBookView subclass:#TabView |
19 |
instanceVariableNames:'' |
|
550 | 20 |
classVariableNames:'' |
21 |
poolDictionaries:'' |
|
22 |
category:'Views-Interactors' |
|
343 | 23 |
! |
24 |
||
25 |
!TabView class methodsFor:'documentation'! |
|
26 |
||
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
1118
a49afa5a9f10
fixed font setup in initStyle.
Claus Gittinger <cg@exept.de>
parents:
913
diff
changeset
|
30 |
All Rights Reserved |
343 | 31 |
|
32 |
This software is furnished under a license and may be used |
|
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
" |
|
39 |
||
40 |
! |
|
41 |
||
42 |
documentation |
|
43 |
" |
|
44 |
implements the tabs-view component of a noteBook. |
|
45 |
May also be used on its own (without a surrounding noteBook). |
|
46 |
||
47 |
The functionality is basically the same as provided by a |
|
48 |
PopUpList or SelectionInListView, in that a valueHolder |
|
49 |
gets a value assigned corresponding to the selected tab |
|
50 |
from a list of possible tabs. |
|
51 |
||
52 |
[author:] |
|
1118
a49afa5a9f10
fixed font setup in initStyle.
Claus Gittinger <cg@exept.de>
parents:
913
diff
changeset
|
53 |
Claus Atzkern |
343 | 54 |
|
55 |
[see also:] |
|
1118
a49afa5a9f10
fixed font setup in initStyle.
Claus Gittinger <cg@exept.de>
parents:
913
diff
changeset
|
56 |
NoteBookView |
a49afa5a9f10
fixed font setup in initStyle.
Claus Gittinger <cg@exept.de>
parents:
913
diff
changeset
|
57 |
SelectionInListView PopUpList ValueHolder TabWidget |
343 | 58 |
" |
59 |
||
60 |
! |
|
61 |
||
62 |
examples |
|
63 |
" |
|
367 | 64 |
tabs at top of a view |
3902 | 65 |
[exBegin] |
66 |
|top tab| |
|
367 | 67 |
|
3902 | 68 |
top := StandardSystemView new label:'tabs at bottom'; extent:250@100. |
69 |
tab := TabView origin:(0.0 @ 0.0) corner:(1.0 @ 0.0)in:top. |
|
367 | 70 |
tab direction:#top. |
71 |
tab list:#( 'Foo' 'Bar' 'Baz' ). |
|
3902 | 72 |
tab action:[:anIndex| Transcript showCR:anIndex ]. |
73 |
tab bottomInset:(tab preferredExtent y negated). |
|
367 | 74 |
top open. |
2531 | 75 |
[exEnd] |
343 | 76 |
|
3902 | 77 |
tabs at bottom a view |
2531 | 78 |
[exBegin] |
3902 | 79 |
|top tab| |
367 | 80 |
|
81 |
top := StandardSystemView new label:'tabs at bottom'; extent:250@100. |
|
3902 | 82 |
tab := TabView origin:(0.0 @ 1.0) corner:(1.0 @ 1.0)in:top. |
367 | 83 |
tab direction:#bottom. |
84 |
tab list:#( 'Foo' 'Bar' 'Baz' ). |
|
3902 | 85 |
tab action:[:anIndex| Transcript showCR:anIndex ]. |
86 |
tab topInset:(tab preferredExtent y negated). |
|
367 | 87 |
top open. |
2531 | 88 |
[exEnd] |
343 | 89 |
|
367 | 90 |
tabs at right of a view |
2531 | 91 |
[exBegin] |
3902 | 92 |
|top tab| |
367 | 93 |
|
94 |
top := StandardSystemView new label:'tabs at right'; extent:100@250. |
|
3902 | 95 |
tab := TabView origin:1.0 @ 0.0 corner:1.0 @ 1.0 in:top. |
367 | 96 |
|
97 |
tab direction:#right. |
|
98 |
tab list:#( 'Foo' 'Bar' 'Baz' ). |
|
99 |
tab action:[:aName|Transcript showCR:aName]. |
|
3902 | 100 |
tab leftInset:(tab preferredExtent x negated). |
343 | 101 |
top open. |
2531 | 102 |
[exEnd] |
343 | 103 |
|
367 | 104 |
tabs at left of a view |
2531 | 105 |
[exBegin] |
367 | 106 |
|top tab view inset| |
107 |
||
108 |
top := StandardSystemView new label:'tabs at left'; extent:100@250. |
|
3902 | 109 |
tab := TabView origin:0.0 @ 0.0 corner:0.0 @ 1.0 in:top. |
343 | 110 |
|
367 | 111 |
tab direction:#left. |
112 |
tab list:#( 'Foo' 'Bar' 'Baz' ). |
|
113 |
tab action:[:aName|Transcript showCR:aName]. |
|
3902 | 114 |
tab rightInset:(tab preferredExtent x negated). |
367 | 115 |
top open. |
2531 | 116 |
[exEnd] |
343 | 117 |
|
3902 | 118 |
using icons and text |
2531 | 119 |
[exBegin] |
367 | 120 |
|top tab view list| |
121 |
||
3902 | 122 |
top := StandardSystemView new label:'using icons, text, ..'; extent:300@100. |
123 |
tab := TabView origin:0.0 @ 0.0 corner:1.0 @ 0.0 in:top. |
|
124 |
list := OrderedCollection new. |
|
125 |
list add:( LabelAndIcon icon:(ToolbarIconLibrary workspace24x24Icon2) string:'Workspace' ). |
|
126 |
list add:( ToolbarIconLibrary workspace24x24Icon2 ). |
|
127 |
list add:( 'Workspace' ). |
|
128 |
list add:( 'Workspace' allBold ). |
|
343 | 129 |
|
3902 | 130 |
tab list:list. |
131 |
tab hasScrollButtons:true. |
|
132 |
tab action:[:indexOrNil| Transcript showCR:indexOrNil ]. |
|
133 |
tab bottomInset:(tab preferredExtent y negated). |
|
343 | 134 |
top open. |
2531 | 135 |
[exEnd] |
343 | 136 |
" |
137 |
! ! |
|
138 |
||
6045 | 139 |
!TabView methodsFor:'accessing'! |
140 |
||
141 |
recomputeListHorizontal |
|
142 |
"compute layouts for all tabs" |
|
143 |
||
144 |
| borderLevel xLeft xRight yTop tabWidth tabHeight delta tabLvlAbs minLeft maxRight leftMargin rightMargin | |
|
145 |
||
146 |
maxRight := self width // list size. |
|
147 |
maxRight < 7 ifTrue:[ |
|
148 |
selectionInsetX := 0. |
|
149 |
maxRight > 5 ifTrue:[ selectionInsetX := 1 ]. |
|
150 |
] ifFalse:[ |
|
151 |
selectionInsetX := 2. |
|
152 |
maxRight > 8 ifTrue:[ selectionInsetX := 3 ]. |
|
153 |
]. |
|
154 |
tabLabelInset x: 0. |
|
155 |
||
156 |
tabLvlAbs := tabLevel abs. |
|
157 |
borderLevel := tabLvlAbs * 2. |
|
158 |
tabHeight := 0. |
|
159 |
leftMargin := self tabLeftMargin. |
|
160 |
rightMargin := self tabRightMargin. |
|
161 |
minLeft := leftMargin + selectionInsetX. |
|
162 |
maxRight := self width - rightMargin - selectionInsetX. |
|
163 |
xLeft := minLeft. |
|
164 |
||
165 |
addTabAction notNil |
|
166 |
ifTrue:[ maxRight := maxRight - self horizontalMarginForAddTabButton ]. |
|
167 |
||
168 |
list do:[:aTab| |tabExtent| |
|
169 |
tabExtent := self preferredExtentForTab:aTab. |
|
170 |
tabWidth := tabExtent x + borderLevel. |
|
171 |
tabHeight := tabExtent y max:tabHeight. |
|
172 |
xRight := xLeft + tabWidth. |
|
173 |
||
174 |
aTab destroyTabButtonShown ifTrue:[ |
|
175 |
xRight := xRight + self destroyButtonUsedWidth |
|
176 |
]. |
|
177 |
||
178 |
aTab lineNr: 1. |
|
179 |
aTab unselectedLayout:(Rectangle left:xLeft top:0 width:tabWidth height:tabHeight). |
|
180 |
xLeft := xRight. |
|
181 |
]. |
|
182 |
tabHeight := tabHeight + tabLvlAbs. |
|
183 |
yTop := selectionInsetY + tabTopMargin. |
|
184 |
delta := tabHeight. |
|
185 |
||
186 |
direction == #bottom ifTrue:[ |
|
187 |
yTop := self height - tabHeight - yTop. |
|
188 |
delta := tabHeight negated. |
|
189 |
]. |
|
190 |
||
191 |
list reverseDo:[:aTab| |
|
192 |
aTab unselectedLayout setTop:yTop. |
|
193 |
aTab unselectedLayout height:tabHeight. |
|
194 |
]. |
|
195 |
||
196 |
tabModus ifTrue:[ |
|
197 |
|firstTabLayout| |
|
198 |
||
199 |
firstTabLayout := list first unselectedLayout. |
|
200 |
delta := direction == #top |
|
201 |
ifTrue:[self height - firstTabLayout bottom] |
|
202 |
ifFalse:[firstTabLayout top negated]. |
|
203 |
||
204 |
list do:[:aTab | |l| |
|
205 |
l := aTab unselectedLayout. |
|
206 |
l setTop:(l top + delta). |
|
207 |
]. |
|
208 |
]. |
|
209 |
||
210 |
list isEmpty ifTrue:[ ^ self ]. |
|
211 |
||
212 |
delta := maxRight - list last unselectedLayout right. |
|
213 |
[ delta < 0 ] whileTrue:[ |tab wdt| |
|
214 |
tab := nil. |
|
215 |
wdt := 2. |
|
216 |
||
217 |
list do:[: each | |
|
218 |
each unselectedLayout width > wdt ifTrue:[ |
|
219 |
tab := each. |
|
220 |
wdt := each unselectedLayout width. |
|
221 |
]. |
|
222 |
]. |
|
223 |
tab isNil |
|
224 |
ifTrue:[ delta := 0 ] |
|
225 |
ifFalse:[ delta := delta + 1. tab unselectedLayout width: (tab unselectedLayout width - 1) ]. |
|
226 |
]. |
|
227 |
||
228 |
[ delta > 0 ] whileTrue:[ |tab wdt| |
|
229 |
tab := list first. |
|
230 |
wdt := tab unselectedLayout width - tab extent x. |
|
231 |
||
232 |
list from:2 to: list size do:[: each | |new| |
|
233 |
new := each unselectedLayout width - each extent x. |
|
234 |
wdt > new ifTrue:[ wdt := new. tab := each. ]. |
|
235 |
]. |
|
236 |
tab unselectedLayout width: (tab unselectedLayout width + 1). |
|
237 |
delta := delta - 1. |
|
238 |
]. |
|
239 |
||
240 |
2 to: list size do:[: i | |
|
241 |
(list at: i) unselectedLayout setLeft: ((list at: i -1) unselectedLayout right). |
|
242 |
]. |
|
243 |
||
244 |
list do:[:eachTab | eachTab layout:eachTab unselectedLayout; selectedLayout:nil ]. |
|
245 |
! ! |
|
246 |
||
1401 | 247 |
!TabView methodsFor:'initialization'! |
387 | 248 |
|
1118
a49afa5a9f10
fixed font setup in initStyle.
Claus Gittinger <cg@exept.de>
parents:
913
diff
changeset
|
249 |
initStyle |
a49afa5a9f10
fixed font setup in initStyle.
Claus Gittinger <cg@exept.de>
parents:
913
diff
changeset
|
250 |
"setup style attributes |
a49afa5a9f10
fixed font setup in initStyle.
Claus Gittinger <cg@exept.de>
parents:
913
diff
changeset
|
251 |
" |
a49afa5a9f10
fixed font setup in initStyle.
Claus Gittinger <cg@exept.de>
parents:
913
diff
changeset
|
252 |
|
a49afa5a9f10
fixed font setup in initStyle.
Claus Gittinger <cg@exept.de>
parents:
913
diff
changeset
|
253 |
super initStyle. |
1401 | 254 |
tabModus := true. |
367 | 255 |
|
343 | 256 |
|
257 |
! ! |
|
258 |
||
259 |
!TabView class methodsFor:'documentation'! |
|
260 |
||
261 |
version |
|
6045 | 262 |
^ '$Header$' |
3902 | 263 |
! |
264 |
||
265 |
version_CVS |
|
6045 | 266 |
^ '$Header$' |
343 | 267 |
! ! |
6045 | 268 |