author | Claus Gittinger <cg@exept.de> |
Fri, 28 Jun 2019 09:21:50 +0200 | |
changeset 6078 | 08c9e2a47dc5 |
parent 5945 | fdf3c398a30f |
permissions | -rw-r--r-- |
5945 | 1 |
"{ Encoding: utf8 }" |
2 |
||
542 | 3 |
" |
4 |
COPYRIGHT (c) 1997 by Claus Gittinger / eXept Software AG |
|
5 |
All Rights Reserved |
|
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 |
" |
|
2090
af478f964ac0
avoid overhead in scrollbar creation.
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
14 |
"{ Package: 'stx:libwidg2' }" |
af478f964ac0
avoid overhead in scrollbar creation.
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
15 |
|
5326 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
1487 | 18 |
ScrollableView subclass:#DataSetView |
2146 | 19 |
instanceVariableNames:'labelView rememberedTopOffsetOfScrolledView' |
542 | 20 |
classVariableNames:'' |
21 |
poolDictionaries:'' |
|
22 |
category:'Views-DataSet' |
|
23 |
! |
|
24 |
||
25 |
!DataSetView class methodsFor:'documentation'! |
|
26 |
||
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 1997 by Claus Gittinger / eXept Software AG |
|
30 |
All Rights Reserved |
|
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 |
! |
|
43 |
||
44 |
documentation |
|
45 |
" |
|
46 |
This class implements a selection list view based on rows and columns. |
|
5735 | 47 |
Instances are wrapping a DSVLabelView and a DSVColumnView. |
542 | 48 |
It allows for the dynamic editing of this information. |
49 |
||
2901 | 50 |
This is a replacement for the obsolete TableView. |
51 |
||
542 | 52 |
[author:] |
53 |
Claus Atzkern |
|
54 |
||
55 |
[see also:] |
|
56 |
DataSetColumnSpec |
|
57 |
DataSetColumn |
|
58 |
DSVColumnView |
|
59 |
" |
|
60 |
! |
|
61 |
||
62 |
examples |
|
63 |
" |
|
2901 | 64 |
example 1: list with valid rows of type Array |
611 | 65 |
[exBegin] |
66 |
|top scr columns rows bool rdWtSel| |
|
542 | 67 |
|
1495 | 68 |
top := StandardSystemView new label:'Simple Test'; extent:700@440. |
611 | 69 |
scr := DataSetView origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
70 |
||
71 |
columns := OrderedCollection new. |
|
72 |
rows := OrderedCollection new. |
|
73 |
bool := true. |
|
74 |
rdWtSel := #( #at: #at:put: ). |
|
75 |
||
76 |
1 to:1000 do:[:i||n| |
|
77 |
n := i printString. |
|
3506 | 78 |
rows add:(Array with:('text: ', n) with:('input: ', n) with:bool with:(i==20)). |
611 | 79 |
bool := bool not. |
80 |
]. |
|
81 |
||
82 |
columns add:(DataSetColumnSpec label:'Text' editorType:#None selector:rdWtSel). |
|
83 |
columns add:(DataSetColumnSpec label:'Input' editorType:#InputField selector:rdWtSel). |
|
84 |
columns add:(DataSetColumnSpec label:'Toggle' editorType:#CheckToggle selector:rdWtSel). |
|
3506 | 85 |
columns add:(DataSetColumnSpec label:'Radio' editorType:#RadioButton selector:rdWtSel). |
611 | 86 |
|
87 |
scr columnDescriptors:columns. |
|
88 |
scr list:rows. |
|
89 |
top open. |
|
90 |
[exEnd] |
|
91 |
||
92 |
||
619 | 93 |
|
2901 | 94 |
example 2: list with none valid rows; defining #rowIfAbsent: block |
619 | 95 |
[exBegin] |
96 |
|top scr columns bool rdWtSel| |
|
97 |
||
1495 | 98 |
top := StandardSystemView new label:'Row Is Absent'; extent:700@440. |
619 | 99 |
scr := DataSetView origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
100 |
||
101 |
columns := OrderedCollection new. |
|
102 |
bool := true. |
|
103 |
rdWtSel := #( #at: #at:put: ). |
|
104 |
||
105 |
columns add:(DataSetColumnSpec label:'Text' editorType:#None selector:rdWtSel). |
|
106 |
columns add:(DataSetColumnSpec label:'Input' editorType:#InputField selector:rdWtSel). |
|
107 |
columns add:(DataSetColumnSpec label:'Toggle' editorType:#CheckToggle selector:rdWtSel). |
|
108 |
||
109 |
scr rowIfAbsent:[:i| |
|
110 |
bool := bool not. |
|
111 |
Array with:('text: ', i printString) with:('input: ') with:bool |
|
112 |
]. |
|
113 |
||
114 |
scr columnDescriptors:columns. |
|
115 |
scr list:(Array new:1000). |
|
116 |
top open. |
|
117 |
[exEnd] |
|
118 |
||
119 |
||
120 |
||
2901 | 121 |
example 3: list with valid rows of type Structure |
542 | 122 |
[exBegin] |
123 |
|top scr clDc rows slct list idx bool| |
|
124 |
||
1495 | 125 |
top := StandardSystemView new label:'Editors'; extent:700@440. |
542 | 126 |
scr := DataSetView origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
127 |
||
128 |
clDc := OrderedCollection new. |
|
129 |
rows := OrderedCollection new. |
|
130 |
list := #( 'Text ' 'Field ' 'C-Box ' 'C-List ' true #( 'foo' 'bar' 'baz' ) ). |
|
131 |
slct := #( #text #field #cbox #clist #toggle #choices ). |
|
132 |
idx := 11. |
|
133 |
bool := true. |
|
134 |
||
135 |
20 timesRepeat:[ |values| |
|
136 |
values := list collect:[:n| |
|
137 |
n isString ifTrue:[n, idx printString] |
|
138 |
ifFalse:[n == true ifTrue:[bool] ifFalse:[n]] |
|
139 |
]. |
|
140 |
rows add:(Structure newWith:slct values:values). |
|
141 |
bool := bool not. |
|
142 |
idx := idx + 1. |
|
143 |
]. |
|
144 |
clDc add:( DataSetColumnSpec label:'Text' editorType:#None selector:#text ). |
|
145 |
clDc add:( DataSetColumnSpec label:'Text' editorType:#None selector:#text ). |
|
146 |
clDc add:( DataSetColumnSpec label:'Field' editorType:#InputField selector:#field ). |
|
147 |
clDc add:( DataSetColumnSpec label:'C-Box' editorType:#ComboBox selector:#cbox ). |
|
148 |
clDc last choices:#choices. |
|
149 |
clDc add:( DataSetColumnSpec label:'C-List' editorType:#ComboList selector:#clist ). |
|
150 |
clDc last choices:#choices. |
|
151 |
clDc add:( DataSetColumnSpec label:'Toggle' editorType:#CheckToggle selector:#toggle ). |
|
152 |
||
607 | 153 |
scr has3Dseparators:true. |
542 | 154 |
scr columnDescriptors:clDc. |
155 |
scr list:rows. |
|
156 |
top open. |
|
157 |
[exEnd] |
|
158 |
||
159 |
||
160 |
||
161 |
||
2901 | 162 |
example 4: table includes a row selector and multiple select is enabled |
542 | 163 |
[exBegin] |
164 |
|top scr clDc rows slct list idx bool| |
|
165 |
||
1495 | 166 |
top := StandardSystemView new label:'Multiple Select'; extent:700@440. |
542 | 167 |
scr := DataSetView origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
168 |
||
169 |
clDc := OrderedCollection new. |
|
170 |
rows := OrderedCollection new. |
|
171 |
list := #( 'Text ' 'Field ' 'C-Box ' 'C-List ' true #( 'foo' 'bar' 'baz' ) ). |
|
172 |
slct := #( #text #field #cbox #clist #toggle #choices ). |
|
173 |
idx := 11. |
|
174 |
bool := true. |
|
175 |
||
176 |
20 timesRepeat:[ |values| |
|
177 |
values := list collect:[:n| |
|
178 |
n isString ifTrue:[n, idx printString] |
|
179 |
ifFalse:[n == true ifTrue:[bool] ifFalse:[n]] |
|
180 |
]. |
|
181 |
rows add:(Structure newWith:slct values:values). |
|
182 |
bool := bool not. |
|
183 |
idx := idx + 1. |
|
184 |
]. |
|
185 |
clDc add:( DataSetColumnSpec rowSelector ). |
|
186 |
clDc add:( DataSetColumnSpec label:'Text' editorType:#None selector:#text ). |
|
187 |
clDc add:( DataSetColumnSpec label:'Text' editorType:#None selector:#text ). |
|
188 |
clDc add:( DataSetColumnSpec label:'Field' editorType:#InputField selector:#field ). |
|
189 |
clDc add:( DataSetColumnSpec label:'C-Box' editorType:#ComboBox selector:#cbox ). |
|
190 |
clDc last choices:#choices. |
|
191 |
clDc add:( DataSetColumnSpec label:'C-List' editorType:#ComboList selector:#clist ). |
|
192 |
clDc last choices:#choices. |
|
193 |
clDc add:( DataSetColumnSpec label:'Toggle' editorType:#CheckToggle selector:#toggle ). |
|
194 |
||
607 | 195 |
scr has3Dseparators:true. |
542 | 196 |
scr columnDescriptors:clDc. |
619 | 197 |
scr multipleSelectOk:true. |
542 | 198 |
scr list:rows. |
199 |
top open. |
|
200 |
[exEnd] |
|
201 |
||
202 |
||
2901 | 203 |
example 5: Images and Layout |
542 | 204 |
[exBegin] |
1495 | 205 |
|top scr columns rows colDesc image text| |
542 | 206 |
|
1495 | 207 |
text := 'Text'. |
208 |
rows := Array new:1000. |
|
542 | 209 |
|
1495 | 210 |
1 to:(rows size) do:[:i| |
211 |
rows at:i put:(Array with:('Id: ', i printString) with:text with:text) |
|
212 |
]. |
|
542 | 213 |
|
1495 | 214 |
columns := OrderedCollection new. |
215 |
image := Image fromFile:('xpmBitmaps/misc_tools/box_full.xpm' ). |
|
216 |
||
217 |
colDesc := DataSetColumnSpec label:(LabelAndIcon icon:image string:'Left') selector:#at:. |
|
218 |
colDesc labelAlignment:#left. |
|
219 |
colDesc columnAlignment:#left. |
|
220 |
columns add:colDesc. |
|
542 | 221 |
|
1495 | 222 |
colDesc := DataSetColumnSpec label:(LabelAndIcon icon:image string:'Right') selector:#at:. |
223 |
colDesc labelAlignment:#right. |
|
224 |
colDesc columnAlignment:#right. |
|
225 |
columns add:colDesc. |
|
226 |
||
227 |
colDesc := DataSetColumnSpec label:(LabelAndIcon icon:image string:'Center') selector:#at:. |
|
228 |
colDesc labelAlignment:#center. |
|
229 |
colDesc columnAlignment:#center. |
|
230 |
columns add:colDesc. |
|
542 | 231 |
|
1495 | 232 |
columns do:[:el|el labelActionSelector:#dummy]. |
542 | 233 |
|
1495 | 234 |
top := StandardSystemView new label:'Layout'; extent:500@500. |
235 |
scr := DataSetView origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
|
236 |
scr has3Dseparators:true. |
|
237 |
scr columnDescriptors:columns. |
|
238 |
scr list:rows. |
|
542 | 239 |
|
1495 | 240 |
top open |
542 | 241 |
[exEnd] |
242 |
||
243 |
||
244 |
||
2901 | 245 |
example 6: adding and removing |
1487 | 246 |
[exBegin] |
247 |
|top scr list| |
|
248 |
||
1495 | 249 |
top := StandardSystemView new label:'Adding & Removing'; extent:600@440. |
1487 | 250 |
scr := DataSetView origin:(0.0 @ 0.0) corner:(1.0 @ 1.0) in:top. |
251 |
||
252 |
scr columnDescriptors:( Array with:(DataSetColumnSpec label:'FOO' selector:#at:) |
|
253 |
with:(DataSetColumnSpec label:'BAR' selector:#at:) |
|
254 |
with:(DataSetColumnSpec label:'BAZ' selector:#at:) |
|
255 |
). |
|
256 |
||
257 |
scr has3Dseparators:true. |
|
258 |
scr listHolder:(list := List new). |
|
259 |
top openAndWait. |
|
260 |
||
261 |
1 to:32 do:[:i| |pid| |
|
262 |
pid := i printString. |
|
263 |
list add:(Array with:('foo: ', pid) with:('bar: ', pid) with:('baz: ', pid)). |
|
264 |
i even ifTrue:[ |
|
265 |
list removeFirst |
|
266 |
]. |
|
267 |
Delay waitForSeconds:0.1. |
|
268 |
]. |
|
269 |
[exEnd] |
|
270 |
||
271 |
||
542 | 272 |
" |
273 |
! ! |
|
274 |
||
2829 | 275 |
!DataSetView methodsFor:'accessing'! |
276 |
||
277 |
columnView |
|
278 |
^ scrolledView |
|
279 |
! |
|
280 |
||
5665 | 281 |
ignoreReselect:aBoolean |
282 |
"controls if clicking on an already selected item should |
|
283 |
be ignored or should perform the select action again. |
|
284 |
By default, these are ignored" |
|
4259 | 285 |
|
5665 | 286 |
self columnView ignoreReselect:aBoolean |
4259 | 287 |
! |
288 |
||
2829 | 289 |
labelView |
290 |
^ labelView |
|
291 |
! ! |
|
292 |
||
2146 | 293 |
!DataSetView methodsFor:'change & update'! |
294 |
||
295 |
update:something with:aParameter from:changedObject |
|
296 |
changedObject == labelView ifTrue:[ |
|
2153 | 297 |
((something == #columnLayout) |
298 |
or:[something == #visibility]) ifTrue:[ |
|
2146 | 299 |
self recomputeLayouts. |
300 |
^ self |
|
301 |
]. |
|
302 |
]. |
|
303 |
||
304 |
super update:something with:aParameter from:changedObject |
|
305 |
! ! |
|
306 |
||
2500 | 307 |
!DataSetView methodsFor:'initialization & release'! |
542 | 308 |
|
309 |
initialize |
|
310 |
"set column area |
|
311 |
" |
|
2146 | 312 |
|columnView| |
313 |
||
2090
af478f964ac0
avoid overhead in scrollbar creation.
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
314 |
"/ preset flags to avoid creation and later destruction of scrollBars ... |
af478f964ac0
avoid overhead in scrollbar creation.
Claus Gittinger <cg@exept.de>
parents:
1495
diff
changeset
|
315 |
self setVertical:true mini:false horizontal:true mini:true. |
542 | 316 |
super initialize. |
317 |
||
1487 | 318 |
self setupVertical:true mini:false horizontal:true mini:true. |
2146 | 319 |
|
320 |
labelView := DSVLabelView in:self. |
|
321 |
columnView := DSVColumnView new. |
|
322 |
columnView labelView:labelView. |
|
323 |
||
2150 | 324 |
"/ columnView addDependent:self. |
2146 | 325 |
labelView addDependent:self. |
326 |
||
327 |
self scrolledView:columnView. |
|
328 |
! ! |
|
329 |
||
330 |
!DataSetView methodsFor:'layout computation'! |
|
331 |
||
332 |
recomputeLayouts |
|
333 |
|columnView columnViewLayout newOffset| |
|
334 |
||
335 |
columnView := self scrolledView. |
|
336 |
columnView isNil ifTrue:[^ self]. |
|
337 |
(columnViewLayout := columnView layout) isNil ifTrue:[^ self]. |
|
338 |
||
339 |
labelView isVisible ifFalse:[ |
|
340 |
newOffset := scrolledViewLayout topOffset. |
|
341 |
] ifTrue:[ |
|
342 |
newOffset := scrolledViewLayout topOffset + (columnView preferredLabelViewHeight). |
|
343 |
]. |
|
344 |
||
345 |
newOffset ~~ columnViewLayout topOffset ifTrue:[ |
|
346 |
columnViewLayout topOffset:newOffset. |
|
2721
5d00500ffc3e
do not ignore sizechange while being invisible
Claus Gittinger <cg@exept.de>
parents:
2720
diff
changeset
|
347 |
"/ columnView realized ifTrue:[ |
2146 | 348 |
columnView containerChangedSize. |
2721
5d00500ffc3e
do not ignore sizechange while being invisible
Claus Gittinger <cg@exept.de>
parents:
2720
diff
changeset
|
349 |
"/ ] |
2146 | 350 |
]. |
2153 | 351 |
labelView containerChangedSize. |
2146 | 352 |
! |
353 |
||
354 |
scrolledViewLayout:aLayout |
|
355 |
"invoked by superclasses setLayout method, whenever the scrolled views |
|
356 |
layout changes (due to added/removed scrollbars)." |
|
357 |
||
2150 | 358 |
|modifiedLayout originalTopOffset labelViewLayout newLeft newRight| |
2146 | 359 |
|
360 |
"/ always copy - since layout it destructively modified in #recomputeLayouts |
|
361 |
modifiedLayout := aLayout copy. |
|
2153 | 362 |
|
363 |
originalTopOffset := scrolledViewLayout topOffset. |
|
2146 | 364 |
labelView isVisible ifTrue:[ |
365 |
modifiedLayout topOffset:(originalTopOffset + labelView height). |
|
2153 | 366 |
]. |
2150 | 367 |
|
2153 | 368 |
newLeft := aLayout leftOffset. |
369 |
newRight := aLayout rightOffset. |
|
2151
50f8723054e7
selected row is highlighted over the full width;
Claus Gittinger <cg@exept.de>
parents:
2150
diff
changeset
|
370 |
|
2153 | 371 |
(scrolledView level == 0 |
372 |
and:[self level < 0 |
|
373 |
and:[labelView level == 0]]) ifTrue:[ |
|
374 |
newRight := (newRight + 1) min:0. |
|
375 |
modifiedLayout rightOffset:newRight. |
|
376 |
]. |
|
2150 | 377 |
|
2153 | 378 |
labelViewLayout := labelView layout. |
379 |
labelViewLayout topOffset:originalTopOffset. |
|
380 |
labelViewLayout |
|
381 |
leftOffset:newLeft |
|
382 |
rightOffset:newRight. |
|
383 |
||
384 |
labelView isVisible ifTrue:[ |
|
2150 | 385 |
labelView containerChangedSize. |
2146 | 386 |
]. |
387 |
super scrolledViewLayout:modifiedLayout |
|
5326 | 388 |
! |
389 |
||
390 |
verticalScrollBarLayout:aLayout |
|
391 |
"redefined to care for the label view, |
|
392 |
which is at the top and NOT scrolled. |
|
393 |
It covers the top areay of myself, so we have to make the vertical |
|
394 |
scrollbar a little smaller." |
|
395 |
||
396 |
labelView notNil ifTrue:[ |
|
397 |
aLayout topOffset:(aLayout topOffset + labelView height). |
|
398 |
]. |
|
399 |
super verticalScrollBarLayout:aLayout |
|
542 | 400 |
! ! |
401 |
||
402 |
!DataSetView methodsFor:'queries'! |
|
403 |
||
4177 | 404 |
canTab |
405 |
^ labelView notNil and:[labelView enabled] |
|
406 |
! |
|
407 |
||
5945 | 408 |
computePreferredExtent |
3677
bffaafb77e62
#preferredExtent - consider label view
Stefan Vogel <sv@exept.de>
parents:
3506
diff
changeset
|
409 |
"return my preferredExtent from the scrolledViews prefExtent |
bffaafb77e62
#preferredExtent - consider label view
Stefan Vogel <sv@exept.de>
parents:
3506
diff
changeset
|
410 |
plus the size of the scrollBar" |
bffaafb77e62
#preferredExtent - consider label view
Stefan Vogel <sv@exept.de>
parents:
3506
diff
changeset
|
411 |
|
bffaafb77e62
#preferredExtent - consider label view
Stefan Vogel <sv@exept.de>
parents:
3506
diff
changeset
|
412 |
|preferred| |
bffaafb77e62
#preferredExtent - consider label view
Stefan Vogel <sv@exept.de>
parents:
3506
diff
changeset
|
413 |
|
5945 | 414 |
preferred := super computePreferredExtent. |
3677
bffaafb77e62
#preferredExtent - consider label view
Stefan Vogel <sv@exept.de>
parents:
3506
diff
changeset
|
415 |
^ (preferred x) @ (preferred y + labelView preferredHeight). |
bffaafb77e62
#preferredExtent - consider label view
Stefan Vogel <sv@exept.de>
parents:
3506
diff
changeset
|
416 |
|
5945 | 417 |
"Created: / 09-11-2018 / 19:50:35 / Claus Gittinger" |
3677
bffaafb77e62
#preferredExtent - consider label view
Stefan Vogel <sv@exept.de>
parents:
3506
diff
changeset
|
418 |
! |
bffaafb77e62
#preferredExtent - consider label view
Stefan Vogel <sv@exept.de>
parents:
3506
diff
changeset
|
419 |
|
542 | 420 |
specClass |
637 | 421 |
"returns my spec class |
422 |
" |
|
542 | 423 |
^ DataSetSpec |
424 |
! ! |
|
425 |
||
426 |
!DataSetView class methodsFor:'documentation'! |
|
427 |
||
428 |
version |
|
5326 | 429 |
^ '$Header$' |
542 | 430 |
! ! |
4177 | 431 |