542
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1997 by Claus Gittinger / 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 |
|
|
15 |
|
|
16 |
|
824
|
17 |
SimpleView subclass:#DSVLabelView
|
884
|
18 |
instanceVariableNames:'items columnView selection enabled'
|
542
|
19 |
classVariableNames:''
|
|
20 |
poolDictionaries:''
|
|
21 |
category:'Views-DataSet'
|
|
22 |
!
|
|
23 |
|
824
|
24 |
Object subclass:#Item
|
907
|
25 |
instanceVariableNames:'label selector argument adjust font fgColor bgColor layout
|
|
26 |
preferredExtent'
|
824
|
27 |
classVariableNames:'DefaultLayout'
|
|
28 |
poolDictionaries:''
|
|
29 |
privateIn:DSVLabelView
|
|
30 |
!
|
|
31 |
|
542
|
32 |
!DSVLabelView class methodsFor:'documentation'!
|
|
33 |
|
|
34 |
copyright
|
|
35 |
"
|
|
36 |
COPYRIGHT (c) 1997 by Claus Gittinger / eXept Software AG
|
|
37 |
All Rights Reserved
|
|
38 |
|
|
39 |
This software is furnished under a license and may be used
|
|
40 |
only in accordance with the terms of that license and with the
|
|
41 |
inclusion of the above copyright notice. This software may not
|
|
42 |
be provided or otherwise made available to, or used by, any
|
|
43 |
other person. No title to or ownership of the software is
|
|
44 |
hereby transferred.
|
|
45 |
"
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
!
|
|
51 |
|
|
52 |
documentation
|
|
53 |
"
|
|
54 |
shows the labels assigned to the column descriptions. Used by the
|
|
55 |
DataSetView
|
|
56 |
|
|
57 |
[Instance variables:]
|
|
58 |
|
824
|
59 |
columnView <DSVColumnView> column view which shows the columns
|
|
60 |
|
|
61 |
items <OrderedCollection> list of items; each item describes
|
|
62 |
one column.
|
|
63 |
|
|
64 |
selection <Item or nil> current selected item or nil. An none
|
|
65 |
empty selection exists during pressing
|
|
66 |
a button.
|
|
67 |
|
542
|
68 |
|
|
69 |
[author:]
|
|
70 |
Claus Atzkern
|
|
71 |
|
|
72 |
[see also:]
|
|
73 |
DSVColumnView
|
|
74 |
DataSetColumnSpec
|
|
75 |
DataSetColumn
|
|
76 |
DataSetView
|
|
77 |
"
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
! !
|
|
82 |
|
824
|
83 |
!DSVLabelView class methodsFor:'constants'!
|
|
84 |
|
|
85 |
activeLevel
|
|
86 |
"returns the active level; item is pressed
|
|
87 |
"
|
|
88 |
^ -2
|
|
89 |
!
|
542
|
90 |
|
824
|
91 |
passiveLevel
|
|
92 |
"returns the passive level; item not pressed
|
|
93 |
"
|
|
94 |
^ 1
|
|
95 |
!
|
|
96 |
|
|
97 |
verticalInset
|
|
98 |
"returns the vertical inset added to the maximum label height
|
637
|
99 |
"
|
824
|
100 |
^ 8
|
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
! !
|
|
105 |
|
884
|
106 |
!DSVLabelView methodsFor:'accessing'!
|
|
107 |
|
|
108 |
columnView
|
|
109 |
^ columnView
|
|
110 |
!
|
|
111 |
|
|
112 |
enabled
|
|
113 |
^ enabled
|
|
114 |
!
|
|
115 |
|
|
116 |
enabled:aState
|
|
117 |
enabled := aState.
|
|
118 |
! !
|
|
119 |
|
824
|
120 |
!DSVLabelView methodsFor:'drawing'!
|
|
121 |
|
|
122 |
redraw
|
|
123 |
"redraw complete view
|
|
124 |
"
|
|
125 |
self redrawX:0 y:0 width:(self width) height:(self height).
|
562
|
126 |
|
824
|
127 |
!
|
|
128 |
|
|
129 |
redrawItem:anItem
|
|
130 |
"redraw rectangle assigned to an item
|
|
131 |
"
|
|
132 |
|layout|
|
|
133 |
|
|
134 |
layout := anItem layout.
|
|
135 |
|
|
136 |
self redrawX:(layout left)
|
|
137 |
y:(layout top)
|
|
138 |
width:(layout width)
|
|
139 |
height:(layout height).
|
|
140 |
|
637
|
141 |
! !
|
562
|
142 |
|
824
|
143 |
!DSVLabelView methodsFor:'drawing basics'!
|
562
|
144 |
|
824
|
145 |
redrawX:x y:y width:w height:h
|
|
146 |
"redraw a rectangle
|
637
|
147 |
"
|
824
|
148 |
|inset savClip bg fg fgColor bgColor maxX layout left width actLvl pasLvl lv|
|
|
149 |
|
|
150 |
shown ifFalse:[
|
|
151 |
^ self
|
|
152 |
].
|
|
153 |
|
|
154 |
bgColor := columnView backgroundColor.
|
|
155 |
fgColor := columnView foregroundColor.
|
|
156 |
inset := columnView horizontalSpacing.
|
|
157 |
actLvl := self class activeLevel.
|
|
158 |
pasLvl := self class passiveLevel.
|
|
159 |
maxX := x + w.
|
|
160 |
|
|
161 |
self paint:bgColor.
|
|
162 |
self fillRectangleX:x y:y width:w height:h.
|
|
163 |
|
859
|
164 |
items isEmpty ifTrue:[
|
|
165 |
^ self
|
|
166 |
].
|
824
|
167 |
savClip := clipRect.
|
859
|
168 |
|
824
|
169 |
self clippingRectangle:(Rectangle left:x top:y width:w height:h).
|
|
170 |
|
|
171 |
items do:[:anItem|
|
907
|
172 |
layout := anItem layout.
|
|
173 |
left := layout left.
|
|
174 |
width := layout width.
|
824
|
175 |
|
907
|
176 |
(left < maxX and:[layout right > x]) ifTrue:[
|
|
177 |
(bg := anItem backgroundColor) notNil ifTrue:[
|
|
178 |
bg ~= bgColor ifTrue:[
|
|
179 |
self paint:bg.
|
|
180 |
self fillRectangleX:left y:y width:width height:h.
|
|
181 |
]
|
|
182 |
] ifFalse:[
|
|
183 |
bg := bgColor
|
|
184 |
].
|
824
|
185 |
|
907
|
186 |
fg := (anItem foregroundColor) ? fgColor.
|
|
187 |
lv := selection == anItem ifTrue:[actLvl] ifFalse:[pasLvl].
|
|
188 |
self paint:fg on:bg.
|
|
189 |
anItem redrawLabelOn:self hInset:inset + (lv abs).
|
|
190 |
columnView drawEdgesAtX:left y:0 width:width height:height level:lv on:self
|
824
|
191 |
]
|
|
192 |
].
|
859
|
193 |
self clippingRectangle:savClip.
|
824
|
194 |
|
637
|
195 |
|
562
|
196 |
|
637
|
197 |
! !
|
|
198 |
|
|
199 |
!DSVLabelView methodsFor:'event handling'!
|
542
|
200 |
|
637
|
201 |
buttonPress:button x:x y:y
|
824
|
202 |
"handle a button press event; checks whether the item under the mouse
|
|
203 |
is selectable. If true, the selection is set to the item.
|
637
|
204 |
"
|
824
|
205 |
|item|
|
|
206 |
|
884
|
207 |
enabled ifTrue:[
|
|
208 |
( button == 1
|
|
209 |
and:[selection isNil
|
|
210 |
and:[(item := self detectItemAtX:x y:y) notNil
|
|
211 |
and:[item isSelectable]]]
|
|
212 |
) ifTrue:[
|
|
213 |
self redrawItem:(selection := item)
|
|
214 |
]
|
824
|
215 |
].
|
|
216 |
super buttonPress:button x:x y:y
|
|
217 |
|
542
|
218 |
|
|
219 |
!
|
|
220 |
|
637
|
221 |
buttonRelease:button x:x y:y
|
824
|
222 |
"handle a button press event; checks whether the item under the mouse
|
|
223 |
is the selected item. If true, the application is informed.
|
|
224 |
"
|
|
225 |
|item same layout arg appl|
|
|
226 |
|
|
227 |
( button == 1 and:[selection notNil]) ifTrue:[
|
|
228 |
same := (self detectItemAtX:x y:y) == selection.
|
|
229 |
item := selection.
|
|
230 |
layout := item layout.
|
|
231 |
selection := nil.
|
|
232 |
|
|
233 |
self redrawItem:item.
|
|
234 |
|
|
235 |
same ifTrue:[
|
|
236 |
item sendClickMsgTo:(self application)
|
|
237 |
]
|
|
238 |
].
|
|
239 |
super buttonRelease:button x:x y:y.
|
|
240 |
|
|
241 |
! !
|
|
242 |
|
|
243 |
!DSVLabelView methodsFor:'instance creation'!
|
|
244 |
|
|
245 |
for:aColumnView
|
|
246 |
"initialization
|
|
247 |
"
|
884
|
248 |
enabled := true.
|
824
|
249 |
items := OrderedCollection new.
|
|
250 |
columnView := aColumnView.
|
|
251 |
|
|
252 |
! !
|
|
253 |
|
|
254 |
!DSVLabelView methodsFor:'notifications'!
|
|
255 |
|
|
256 |
columnsLayoutChanged
|
|
257 |
"layout of columns changed and thus the layout of
|
|
258 |
all items.
|
542
|
259 |
"
|
824
|
260 |
items size == columnView numberOfColumns ifFalse:[
|
|
261 |
self columnsSizeChanged
|
|
262 |
] ifTrue:[
|
|
263 |
self updateLayoutsHeight:(self height).
|
|
264 |
self redraw.
|
|
265 |
].
|
|
266 |
|
|
267 |
|
|
268 |
!
|
|
269 |
|
|
270 |
columnsOriginChanged:aPoint
|
|
271 |
"the origin of the columnView changed caused by a scroll operation
|
|
272 |
"
|
|
273 |
|point pX x w h|
|
|
274 |
|
|
275 |
(pX := aPoint x) == 0 ifTrue:[
|
|
276 |
^ self
|
|
277 |
].
|
|
278 |
|
|
279 |
point := Point x:(aPoint x) y:0.
|
|
280 |
items do:[:anItem| anItem originChanged:point].
|
542
|
281 |
|
824
|
282 |
(self sensor hasExposeEventFor:self) ifTrue:[
|
|
283 |
^ self invalidateRepairNow:true
|
|
284 |
].
|
|
285 |
|
|
286 |
x := pX abs.
|
|
287 |
w := self width - x.
|
|
288 |
h := self height.
|
|
289 |
|
|
290 |
w < 20 ifTrue:[
|
|
291 |
^ self redraw
|
|
292 |
].
|
|
293 |
|
|
294 |
self catchExpose.
|
|
295 |
|
|
296 |
pX < 0 ifTrue:[
|
|
297 |
self copyFrom:self x:0 y:0 toX:x y:0 width:w height:h async:true.
|
|
298 |
w := 0.
|
|
299 |
] ifFalse:[
|
|
300 |
self copyFrom:self x:x y:0 toX:0 y:0 width:w height:h async:true.
|
|
301 |
].
|
|
302 |
self redrawX:w y:0 width:x height:h.
|
|
303 |
self waitForExpose.
|
|
304 |
|
542
|
305 |
|
824
|
306 |
!
|
|
307 |
|
|
308 |
columnsSizeChanged
|
|
309 |
"the list of columns changed; recreate all items
|
|
310 |
"
|
907
|
311 |
|height font|
|
824
|
312 |
|
907
|
313 |
items := OrderedCollection new.
|
824
|
314 |
|
907
|
315 |
columnView numberOfColumns ~~ 0 ifTrue:[
|
|
316 |
font := columnView font.
|
|
317 |
height := 0.
|
824
|
318 |
|
907
|
319 |
columnView columnsDo:[:aColumn||item|
|
|
320 |
items add:(item := Item column:aColumn font:font on:self).
|
|
321 |
height := (item preferredExtent y) max:height.
|
|
322 |
].
|
|
323 |
height := height + self class verticalInset.
|
|
324 |
self updateLayoutsHeight:height.
|
|
325 |
self bottomInset:height negated.
|
824
|
326 |
].
|
|
327 |
self redraw.
|
|
328 |
|
|
329 |
! !
|
|
330 |
|
|
331 |
!DSVLabelView methodsFor:'private'!
|
|
332 |
|
|
333 |
detectItemAtX:x y:y
|
|
334 |
"returns item at point x@y or nil
|
|
335 |
"
|
|
336 |
items do:[:anItem|
|
|
337 |
(anItem layout containsPointX:x y:y) ifTrue:[ ^ anItem ]
|
|
338 |
].
|
|
339 |
^ nil
|
|
340 |
|
|
341 |
!
|
|
342 |
|
|
343 |
updateLayoutsHeight:h
|
|
344 |
"update the rectangle layout for each item based on a height
|
|
345 |
"
|
907
|
346 |
|i x w|
|
824
|
347 |
|
907
|
348 |
i := 1.
|
|
349 |
x := columnView margin - columnView xOriginOfContents.
|
|
350 |
columnView has3Dseparators ifFalse:[ x := x + 1].
|
824
|
351 |
|
907
|
352 |
columnView columnsDo:[:aCol|
|
|
353 |
w := aCol width.
|
|
354 |
(items at:i) layout:(Rectangle origin:(x @ 0) extent:(w @ h)).
|
|
355 |
i := i + 1.
|
|
356 |
x := x + w.
|
542
|
357 |
].
|
824
|
358 |
! !
|
|
359 |
|
|
360 |
!DSVLabelView::Item class methodsFor:'constants'!
|
|
361 |
|
|
362 |
defaultLayout
|
|
363 |
"returns the default layout used for initialization
|
|
364 |
"
|
|
365 |
DefaultLayout isNil ifTrue:[
|
|
366 |
DefaultLayout := Rectangle left:0 right:0 top:0 bottom:0
|
|
367 |
].
|
|
368 |
^ DefaultLayout
|
|
369 |
|
|
370 |
|
|
371 |
! !
|
|
372 |
|
|
373 |
!DSVLabelView::Item class methodsFor:'documentation'!
|
|
374 |
|
|
375 |
documentation
|
|
376 |
"
|
|
377 |
describes the label of one column entry.
|
|
378 |
|
|
379 |
[Instance variables:]
|
|
380 |
|
|
381 |
label <Object> the label of the column
|
|
382 |
|
|
383 |
selector <Symbol> a selector, which is evaluated with the argument
|
|
384 |
if the item is selected and the button is released.
|
|
385 |
|
|
386 |
argument <Object> user defined argument for the selector.
|
|
387 |
|
|
388 |
adjust <Symbol> align label left, right or center; default is center
|
|
389 |
|
|
390 |
font <Font> font used to dispaly the label; if the font is
|
|
391 |
undefined, the default font is used.
|
|
392 |
|
|
393 |
fgColor <Color> foreground color for the label; if the fgColor is
|
|
394 |
undefined, the default foreground color is used.
|
|
395 |
|
|
396 |
bgColor <Color> background color for the label; if the bgColor is
|
|
397 |
undefined, the default background color is used.
|
|
398 |
|
|
399 |
layout <Rectangle> the layout of the item
|
|
400 |
|
|
401 |
preferredExtent <Point> preferred extent of the label
|
|
402 |
|
|
403 |
|
|
404 |
[author:]
|
|
405 |
Claus Atzkern
|
|
406 |
"
|
|
407 |
! !
|
|
408 |
|
|
409 |
!DSVLabelView::Item class methodsFor:'instance creation'!
|
|
410 |
|
|
411 |
column:aColumn font:aFont on:aGC
|
|
412 |
"create a new item for a column
|
|
413 |
"
|
|
414 |
^ (self new) column:aColumn font:aFont on:aGC
|
|
415 |
|
|
416 |
|
|
417 |
! !
|
|
418 |
|
|
419 |
!DSVLabelView::Item methodsFor:'accessing'!
|
|
420 |
|
|
421 |
backgroundColor
|
|
422 |
"returns the background color of the column or nil
|
|
423 |
"
|
|
424 |
^ bgColor
|
|
425 |
|
|
426 |
|
|
427 |
!
|
|
428 |
|
|
429 |
foregroundColor
|
|
430 |
"returns the foreground color of the column or nil
|
|
431 |
"
|
|
432 |
^ fgColor
|
|
433 |
|
|
434 |
|
|
435 |
!
|
|
436 |
|
|
437 |
label
|
|
438 |
"returns the label of the column or nil
|
|
439 |
"
|
|
440 |
^ label
|
|
441 |
|
|
442 |
|
542
|
443 |
! !
|
|
444 |
|
824
|
445 |
!DSVLabelView::Item methodsFor:'accessing dimensions'!
|
|
446 |
|
|
447 |
layout
|
|
448 |
"returns the item's layout, a Rectangle
|
|
449 |
"
|
|
450 |
^ layout
|
|
451 |
|
|
452 |
|
|
453 |
!
|
|
454 |
|
|
455 |
layout:aLayout
|
|
456 |
"set the item's layout, a Rectangle
|
|
457 |
"
|
|
458 |
layout := aLayout
|
|
459 |
|
|
460 |
|
|
461 |
!
|
|
462 |
|
|
463 |
preferredExtent
|
|
464 |
"returns the preferred extent of the label
|
|
465 |
"
|
|
466 |
^ preferredExtent
|
|
467 |
|
|
468 |
|
|
469 |
! !
|
|
470 |
|
|
471 |
!DSVLabelView::Item methodsFor:'actions'!
|
542
|
472 |
|
824
|
473 |
sendClickMsgTo:aReceiver
|
|
474 |
"inform the receiver of a button release notification
|
|
475 |
"
|
|
476 |
(aReceiver notNil and:[selector notNil]) ifTrue:[
|
|
477 |
selector numArgs ~~ 0 ifTrue:[
|
|
478 |
aReceiver perform:selector with:argument
|
|
479 |
] ifFalse:[
|
|
480 |
aReceiver perform:selector
|
|
481 |
]
|
|
482 |
]
|
|
483 |
|
|
484 |
! !
|
|
485 |
|
|
486 |
!DSVLabelView::Item methodsFor:'drawing'!
|
|
487 |
|
|
488 |
redrawLabelOn:aGC hInset:hInset
|
|
489 |
"redraw the label; the background is cleared and the paint is set
|
|
490 |
"
|
|
491 |
|x y|
|
|
492 |
|
|
493 |
label isNil ifTrue:[
|
|
494 |
^ self
|
|
495 |
].
|
542
|
496 |
|
824
|
497 |
adjust == #left ifTrue:[
|
|
498 |
x := layout left + hInset.
|
|
499 |
] ifFalse:[
|
|
500 |
adjust == #right ifTrue:[
|
|
501 |
x := layout right - preferredExtent x - hInset
|
|
502 |
] ifFalse:[
|
|
503 |
x := layout left + (((layout width - preferredExtent x) // 2) max:0)
|
|
504 |
]
|
|
505 |
].
|
|
506 |
y := layout top + (layout height - preferredExtent y // 2).
|
|
507 |
|
|
508 |
font notNil ifTrue:[
|
|
509 |
aGC font:font.
|
|
510 |
y := y + font ascent.
|
|
511 |
].
|
|
512 |
|
|
513 |
label displayOn:aGC x:x y:y.
|
|
514 |
|
|
515 |
|
|
516 |
! !
|
|
517 |
|
|
518 |
!DSVLabelView::Item methodsFor:'instance creation'!
|
|
519 |
|
|
520 |
column:aColumn font:aFont on:aGC
|
|
521 |
"create instance for a column
|
|
522 |
"
|
|
523 |
|img|
|
|
524 |
|
893
|
525 |
label := aColumn label.
|
824
|
526 |
selector := aColumn description labelActionSelector.
|
|
527 |
argument := (aColumn description labelActionArgument) ? label.
|
542
|
528 |
|
824
|
529 |
adjust := aColumn labelAlignment.
|
|
530 |
layout := self class defaultLayout.
|
|
531 |
|
|
532 |
(fgColor := aColumn labelForegroundColor) notNil ifTrue:[
|
|
533 |
fgColor := fgColor on:(aGC device)
|
|
534 |
].
|
|
535 |
|
|
536 |
(bgColor := aColumn labelBackgroundColor) notNil ifTrue:[
|
|
537 |
bgColor := bgColor on:(aGC device)
|
|
538 |
].
|
|
539 |
|
|
540 |
label notNil ifTrue:[
|
|
541 |
label isString ifFalse:[
|
|
542 |
label := label on:aGC device.
|
|
543 |
|
|
544 |
label isImage ifTrue:[
|
|
545 |
label clearMaskedPixels
|
|
546 |
]
|
|
547 |
] ifTrue:[
|
|
548 |
label withoutSeparators isEmpty ifTrue:[
|
|
549 |
label := nil
|
|
550 |
]
|
|
551 |
].
|
|
552 |
|
|
553 |
(label respondsTo:#string) ifTrue:[
|
|
554 |
font := aColumn labelFont.
|
|
555 |
|
|
556 |
font notNil ifTrue:[ font := font on:(aGC device) ]
|
|
557 |
ifFalse:[ font := aFont ].
|
|
558 |
|
|
559 |
aGC font:font.
|
|
560 |
|
|
561 |
label class == LabelAndIcon ifTrue:[
|
|
562 |
label := label on:(aGC device).
|
|
563 |
(img := label image) isImage ifTrue:[img clearMaskedPixels].
|
|
564 |
(img := label icon) isImage ifTrue:[img clearMaskedPixels].
|
637
|
565 |
]
|
|
566 |
]
|
560
|
567 |
].
|
542
|
568 |
|
907
|
569 |
preferredExtent := label notNil ifTrue:[ Point x:(label widthOn:aGC) y:(label heightOn:aGC) ]
|
|
570 |
ifFalse:[ 0 @ 0 ].
|
824
|
571 |
|
|
572 |
! !
|
|
573 |
|
|
574 |
!DSVLabelView::Item methodsFor:'notification'!
|
|
575 |
|
|
576 |
originChanged:aDeltaPoint
|
|
577 |
"called when the origin of the layout changed; scrolling left or right
|
|
578 |
"
|
|
579 |
|origin extent|
|
|
580 |
|
|
581 |
origin := layout origin.
|
|
582 |
extent := layout extent.
|
|
583 |
|
|
584 |
layout origin:(origin - aDeltaPoint) extent:extent
|
|
585 |
|
|
586 |
|
|
587 |
! !
|
|
588 |
|
|
589 |
!DSVLabelView::Item methodsFor:'queries'!
|
|
590 |
|
|
591 |
isSelectable
|
|
592 |
"returns true if the item is selectable; a valid selector
|
|
593 |
to notify the receiver for a release button event exists
|
|
594 |
"
|
|
595 |
^ selector notNil
|
|
596 |
|
|
597 |
|
542
|
598 |
! !
|
|
599 |
|
|
600 |
!DSVLabelView class methodsFor:'documentation'!
|
|
601 |
|
|
602 |
version
|
907
|
603 |
^ '$Header: /cvs/stx/stx/libwidg2/DSVLabelView.st,v 1.16 1998-06-03 14:30:36 ca Exp $'
|
542
|
604 |
! !
|