author | Claus Gittinger <cg@exept.de> |
Wed, 14 Jul 1999 16:22:39 +0200 | |
changeset 1454 | 5d4303847148 |
parent 1426 | 9a067c26db45 |
child 1487 | fd003e2156cc |
permissions | -rw-r--r-- |
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 |
1085 | 18 |
instanceVariableNames:'items columnView selection enabled enteredItem' |
542 | 19 |
classVariableNames:'' |
20 |
poolDictionaries:'' |
|
21 |
category:'Views-DataSet' |
|
22 |
! |
|
23 |
||
24 |
!DSVLabelView class methodsFor:'documentation'! |
|
25 |
||
26 |
copyright |
|
27 |
" |
|
28 |
COPYRIGHT (c) 1997 by Claus Gittinger / 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 |
||
42 |
! |
|
43 |
||
44 |
documentation |
|
45 |
" |
|
46 |
shows the labels assigned to the column descriptions. Used by the |
|
47 |
DataSetView |
|
48 |
||
49 |
[Instance variables:] |
|
50 |
||
824 | 51 |
columnView <DSVColumnView> column view which shows the columns |
52 |
||
53 |
items <OrderedCollection> list of items; each item describes |
|
54 |
one column. |
|
55 |
||
56 |
selection <Item or nil> current selected item or nil. An none |
|
57 |
empty selection exists during pressing |
|
58 |
a button. |
|
59 |
||
1086 | 60 |
enabled <Boolean> if a press action exists on a column |
61 |
entry, this action could be enabled or |
|
62 |
disabled. |
|
63 |
||
64 |
enteredItem <Item> current entered item; if a press action |
|
65 |
is defined, this itenm is highlighted. |
|
66 |
Used to redraw the item not highlighted |
|
67 |
if the item is leaved. |
|
68 |
||
542 | 69 |
|
70 |
[author:] |
|
71 |
Claus Atzkern |
|
72 |
||
73 |
[see also:] |
|
74 |
DSVColumnView |
|
75 |
DataSetColumnSpec |
|
76 |
DataSetColumn |
|
77 |
DataSetView |
|
78 |
" |
|
79 |
||
80 |
||
81 |
||
82 |
! ! |
|
83 |
||
824 | 84 |
!DSVLabelView class methodsFor:'constants'! |
85 |
||
86 |
activeLevel |
|
87 |
"returns the active level; item is pressed |
|
88 |
" |
|
1085 | 89 |
^ -1 |
824 | 90 |
! |
542 | 91 |
|
824 | 92 |
passiveLevel |
93 |
"returns the passive level; item not pressed |
|
94 |
" |
|
95 |
^ 1 |
|
96 |
! |
|
97 |
||
98 |
verticalInset |
|
99 |
"returns the vertical inset added to the maximum label height |
|
637 | 100 |
" |
824 | 101 |
^ 8 |
102 |
||
103 |
||
104 |
||
105 |
! ! |
|
106 |
||
884 | 107 |
!DSVLabelView methodsFor:'accessing'! |
108 |
||
109 |
columnView |
|
110 |
^ columnView |
|
111 |
! |
|
112 |
||
113 |
enabled |
|
114 |
^ enabled |
|
115 |
! |
|
116 |
||
117 |
enabled:aState |
|
118 |
enabled := aState. |
|
119 |
! ! |
|
120 |
||
824 | 121 |
!DSVLabelView methodsFor:'drawing'! |
122 |
||
1408
1cda0a4fb566
use invalidate... insteat of redraw...
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
123 |
invalidateItem:anItem |
1cda0a4fb566
use invalidate... insteat of redraw...
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
124 |
"invalidate rectangle assigned to an item |
824 | 125 |
" |
1408
1cda0a4fb566
use invalidate... insteat of redraw...
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
126 |
shown ifTrue:[ |
1426
9a067c26db45
bug fix on highlighting label; copy the layout
Claus Gittinger <cg@exept.de>
parents:
1408
diff
changeset
|
127 |
self invalidate:(anItem layout copy) |
1408
1cda0a4fb566
use invalidate... insteat of redraw...
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
128 |
] |
824 | 129 |
! |
130 |
||
1408
1cda0a4fb566
use invalidate... insteat of redraw...
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
131 |
invalidateX:x y:y width:w height:h |
1cda0a4fb566
use invalidate... insteat of redraw...
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
132 |
"invalidate a rectangle |
824 | 133 |
" |
1408
1cda0a4fb566
use invalidate... insteat of redraw...
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
134 |
shown ifTrue:[ |
1cda0a4fb566
use invalidate... insteat of redraw...
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
135 |
self invalidate:(Rectangle left:x top:y width:w height:h) |
1cda0a4fb566
use invalidate... insteat of redraw...
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
136 |
]. |
1cda0a4fb566
use invalidate... insteat of redraw...
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
137 |
! |
562 | 138 |
|
824 | 139 |
redrawX:x y:y width:w height:h |
140 |
"redraw a rectangle |
|
637 | 141 |
" |
824 | 142 |
|inset savClip bg fg fgColor bgColor maxX layout left width actLvl pasLvl lv| |
143 |
||
144 |
shown ifFalse:[ |
|
145 |
^ self |
|
146 |
]. |
|
147 |
||
148 |
bgColor := columnView backgroundColor. |
|
149 |
fgColor := columnView foregroundColor. |
|
150 |
inset := columnView horizontalSpacing. |
|
151 |
actLvl := self class activeLevel. |
|
152 |
pasLvl := self class passiveLevel. |
|
153 |
maxX := x + w. |
|
154 |
||
155 |
self paint:bgColor. |
|
156 |
self fillRectangleX:x y:y width:w height:h. |
|
157 |
||
859 | 158 |
items isEmpty ifTrue:[ |
159 |
^ self |
|
160 |
]. |
|
824 | 161 |
savClip := clipRect. |
859 | 162 |
|
824 | 163 |
self clippingRectangle:(Rectangle left:x top:y width:w height:h). |
164 |
||
165 |
items do:[:anItem| |
|
907 | 166 |
layout := anItem layout. |
167 |
left := layout left. |
|
168 |
width := layout width. |
|
824 | 169 |
|
907 | 170 |
(left < maxX and:[layout right > x]) ifTrue:[ |
171 |
(bg := anItem backgroundColor) notNil ifTrue:[ |
|
172 |
bg ~= bgColor ifTrue:[ |
|
173 |
self paint:bg. |
|
174 |
self fillRectangleX:left y:y width:width height:h. |
|
175 |
] |
|
176 |
] ifFalse:[ |
|
177 |
bg := bgColor |
|
178 |
]. |
|
824 | 179 |
|
907 | 180 |
fg := (anItem foregroundColor) ? fgColor. |
181 |
lv := selection == anItem ifTrue:[actLvl] ifFalse:[pasLvl]. |
|
182 |
self paint:fg on:bg. |
|
183 |
anItem redrawLabelOn:self hInset:inset + (lv abs). |
|
1085 | 184 |
anItem == enteredItem ifTrue:[lv := lv + 1]. |
907 | 185 |
columnView drawEdgesAtX:left y:0 width:width height:height level:lv on:self |
824 | 186 |
] |
187 |
]. |
|
859 | 188 |
self clippingRectangle:savClip. |
824 | 189 |
|
637 | 190 |
|
562 | 191 |
|
637 | 192 |
! ! |
193 |
||
194 |
!DSVLabelView methodsFor:'event handling'! |
|
542 | 195 |
|
1085 | 196 |
buttonMotion:state x:x y:y |
197 |
|sensor| |
|
198 |
||
199 |
(selection isNil and:[(sensor := self sensor) notNil]) ifTrue:[ |
|
200 |
self itemEntered:(self detectItemAtX:x y:y) |
|
201 |
]. |
|
202 |
super buttonMotion:state x:x y:y |
|
203 |
! |
|
204 |
||
637 | 205 |
buttonPress:button x:x y:y |
824 | 206 |
"handle a button press event; checks whether the item under the mouse |
207 |
is selectable. If true, the selection is set to the item. |
|
637 | 208 |
" |
824 | 209 |
|item| |
210 |
||
1085 | 211 |
self itemEntered:nil. |
212 |
||
884 | 213 |
enabled ifTrue:[ |
214 |
( button == 1 |
|
215 |
and:[selection isNil |
|
216 |
and:[(item := self detectItemAtX:x y:y) notNil |
|
217 |
and:[item isSelectable]]] |
|
218 |
) ifTrue:[ |
|
1408
1cda0a4fb566
use invalidate... insteat of redraw...
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
219 |
self invalidateItem:(selection := item) |
884 | 220 |
] |
824 | 221 |
]. |
222 |
super buttonPress:button x:x y:y |
|
223 |
||
542 | 224 |
|
225 |
! |
|
226 |
||
637 | 227 |
buttonRelease:button x:x y:y |
824 | 228 |
"handle a button press event; checks whether the item under the mouse |
229 |
is the selected item. If true, the application is informed. |
|
230 |
" |
|
1269 | 231 |
|item same layout| |
824 | 232 |
|
1085 | 233 |
self itemEntered:nil. |
234 |
||
824 | 235 |
( button == 1 and:[selection notNil]) ifTrue:[ |
236 |
same := (self detectItemAtX:x y:y) == selection. |
|
237 |
item := selection. |
|
238 |
layout := item layout. |
|
239 |
selection := nil. |
|
240 |
||
1408
1cda0a4fb566
use invalidate... insteat of redraw...
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
241 |
self invalidateItem:item. |
824 | 242 |
|
243 |
same ifTrue:[ |
|
244 |
item sendClickMsgTo:(self application) |
|
245 |
] |
|
246 |
]. |
|
247 |
super buttonRelease:button x:x y:y. |
|
248 |
||
1085 | 249 |
! |
250 |
||
251 |
itemEntered:anItemOrNil |
|
252 |
|prevEntered| |
|
253 |
||
254 |
enteredItem == anItemOrNil ifTrue:[ |
|
255 |
^ self |
|
256 |
]. |
|
257 |
prevEntered := enteredItem. |
|
258 |
enteredItem := anItemOrNil. |
|
259 |
||
260 |
prevEntered notNil ifTrue:[ |
|
261 |
prevEntered isSelectable ifTrue:[ |
|
1408
1cda0a4fb566
use invalidate... insteat of redraw...
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
262 |
self invalidateItem:prevEntered |
1085 | 263 |
] |
264 |
]. |
|
265 |
||
266 |
enteredItem notNil ifTrue:[ |
|
267 |
enteredItem isSelectable ifTrue:[ |
|
1408
1cda0a4fb566
use invalidate... insteat of redraw...
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
268 |
self invalidateItem:enteredItem |
1085 | 269 |
] |
270 |
] |
|
271 |
! |
|
272 |
||
273 |
pointerLeave:state |
|
274 |
self itemEntered:nil. |
|
275 |
super pointerLeave:state |
|
824 | 276 |
! ! |
277 |
||
278 |
!DSVLabelView methodsFor:'instance creation'! |
|
279 |
||
280 |
for:aColumnView |
|
281 |
"initialization |
|
282 |
" |
|
884 | 283 |
enabled := true. |
824 | 284 |
items := OrderedCollection new. |
285 |
columnView := aColumnView. |
|
286 |
||
1085 | 287 |
! |
288 |
||
289 |
initialize |
|
290 |
super initialize. |
|
291 |
self enableMotionEvents. |
|
292 |
||
824 | 293 |
! ! |
294 |
||
295 |
!DSVLabelView methodsFor:'notifications'! |
|
296 |
||
297 |
columnsLayoutChanged |
|
298 |
"layout of columns changed and thus the layout of |
|
299 |
all items. |
|
542 | 300 |
" |
824 | 301 |
items size == columnView numberOfColumns ifFalse:[ |
302 |
self columnsSizeChanged |
|
303 |
] ifTrue:[ |
|
304 |
self updateLayoutsHeight:(self height). |
|
1408
1cda0a4fb566
use invalidate... insteat of redraw...
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
305 |
self invalidate. |
824 | 306 |
]. |
307 |
||
308 |
||
309 |
! |
|
310 |
||
311 |
columnsOriginChanged:aPoint |
|
312 |
"the origin of the columnView changed caused by a scroll operation |
|
313 |
" |
|
1454 | 314 |
|point pX x w h wg| |
824 | 315 |
|
316 |
(pX := aPoint x) == 0 ifTrue:[ |
|
317 |
^ self |
|
318 |
]. |
|
1454 | 319 |
|
320 |
(wg := self windowGroup) notNil ifTrue:[ |
|
321 |
wg processRealExposeEventsFor:self. |
|
1408
1cda0a4fb566
use invalidate... insteat of redraw...
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
322 |
]. |
1454 | 323 |
|
824 | 324 |
point := Point x:(aPoint x) y:0. |
325 |
items do:[:anItem| anItem originChanged:point]. |
|
542 | 326 |
|
1454 | 327 |
"/ (self sensor hasExposeEventFor:self) ifTrue:[ |
328 |
"/ ^ self invalidate |
|
329 |
"/ ]. |
|
330 |
||
1408
1cda0a4fb566
use invalidate... insteat of redraw...
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
331 |
x := pX abs. |
824 | 332 |
|
1408
1cda0a4fb566
use invalidate... insteat of redraw...
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
333 |
(w := self width - x) < 20 ifTrue:[ |
1cda0a4fb566
use invalidate... insteat of redraw...
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
334 |
^ self invalidate |
1cda0a4fb566
use invalidate... insteat of redraw...
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
335 |
]. |
824 | 336 |
h := self height. |
337 |
||
338 |
self catchExpose. |
|
339 |
||
340 |
pX < 0 ifTrue:[ |
|
341 |
self copyFrom:self x:0 y:0 toX:x y:0 width:w height:h async:true. |
|
342 |
w := 0. |
|
343 |
] ifFalse:[ |
|
344 |
self copyFrom:self x:x y:0 toX:0 y:0 width:w height:h async:true. |
|
345 |
]. |
|
346 |
self waitForExpose. |
|
1408
1cda0a4fb566
use invalidate... insteat of redraw...
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
347 |
self invalidateX:w y:0 width:x height:h. |
824 | 348 |
|
542 | 349 |
|
824 | 350 |
! |
351 |
||
352 |
columnsSizeChanged |
|
353 |
"the list of columns changed; recreate all items |
|
354 |
" |
|
907 | 355 |
|height font| |
824 | 356 |
|
1085 | 357 |
self itemEntered:nil. |
907 | 358 |
items := OrderedCollection new. |
824 | 359 |
|
907 | 360 |
columnView numberOfColumns ~~ 0 ifTrue:[ |
361 |
font := columnView font. |
|
362 |
height := 0. |
|
824 | 363 |
|
907 | 364 |
columnView columnsDo:[:aColumn||item| |
1148
893a2a5a640f
allow collection of strings or icons
Claus Gittinger <cg@exept.de>
parents:
1114
diff
changeset
|
365 |
items add:(item := aColumn label). |
907 | 366 |
height := (item preferredExtent y) max:height. |
367 |
]. |
|
368 |
height := height + self class verticalInset. |
|
369 |
self updateLayoutsHeight:height. |
|
370 |
self bottomInset:height negated. |
|
824 | 371 |
]. |
1408
1cda0a4fb566
use invalidate... insteat of redraw...
Claus Gittinger <cg@exept.de>
parents:
1269
diff
changeset
|
372 |
self invalidate. |
824 | 373 |
|
374 |
! ! |
|
375 |
||
376 |
!DSVLabelView methodsFor:'private'! |
|
377 |
||
378 |
detectItemAtX:x y:y |
|
379 |
"returns item at point x@y or nil |
|
380 |
" |
|
381 |
items do:[:anItem| |
|
1148
893a2a5a640f
allow collection of strings or icons
Claus Gittinger <cg@exept.de>
parents:
1114
diff
changeset
|
382 |
(anItem layout containsPointX:x y:y) ifTrue:[ ^ anItem ]. |
824 | 383 |
]. |
384 |
^ nil |
|
385 |
||
386 |
! |
|
387 |
||
388 |
updateLayoutsHeight:h |
|
389 |
"update the rectangle layout for each item based on a height |
|
390 |
" |
|
907 | 391 |
|i x w| |
824 | 392 |
|
907 | 393 |
i := 1. |
1114 | 394 |
x := columnView margin - columnView xOriginOfContents + 1. |
907 | 395 |
columnView has3Dseparators ifFalse:[ x := x + 1]. |
824 | 396 |
|
907 | 397 |
columnView columnsDo:[:aCol| |
398 |
w := aCol width. |
|
399 |
(items at:i) layout:(Rectangle origin:(x @ 0) extent:(w @ h)). |
|
400 |
i := i + 1. |
|
401 |
x := x + w. |
|
542 | 402 |
]. |
824 | 403 |
! ! |
404 |
||
542 | 405 |
!DSVLabelView class methodsFor:'documentation'! |
406 |
||
407 |
version |
|
1454 | 408 |
^ '$Header: /cvs/stx/stx/libwidg2/DSVLabelView.st,v 1.24 1999-07-14 14:22:39 cg Exp $' |
542 | 409 |
! ! |