"
COPYRIGHT (c) 1997 by Claus Gittinger / eXept Software AG
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
"
SimpleView subclass:#DSVLabelView
instanceVariableNames:'isVisible dataSet lineDrag columns selection enabled
preferredHeight handleCursor tabSpacing'
classVariableNames:''
poolDictionaries:''
category:'Views-DataSet'
!
Object subclass:#LineDrag
instanceVariableNames:'rootView topX topY botY column minX startX transX'
classVariableNames:''
poolDictionaries:''
privateIn:DSVLabelView
!
!DSVLabelView class methodsFor:'documentation'!
copyright
"
COPYRIGHT (c) 1997 by Claus Gittinger / eXept Software AG
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
"
!
documentation
"
shows the labels assigned to the column descriptions. Used by the
DataSetView
[Instance variables:]
dataSet <DSVColumnView> column view which shows the columns
selection <Integer or nil> current selected index or nil.
enabled <Boolean> if a press action exists on a column
entry, this action could be enabled or
disabled.
isVisible <Boolean> true if the labelView is shown
preferredHeight <Integer> the preferred height of the labelView
[author:]
Claus Atzkern
[see also:]
DSVColumnView
DataSetColumnSpec
DataSetColumn
DataSetView
"
! !
!DSVLabelView methodsFor:'accessing'!
columns:aListOfColumns
"the list of columns changed
"
|layout|
columns := aListOfColumns.
preferredHeight := nil.
selection := nil.
isVisible ifTrue:[
dataSet layout:layout.
].
!
level:aLevel
"ignorre; alway 0 relative to superView
"
!
preferredHeight
preferredHeight isNil ifTrue:[
preferredHeight := 0.
columns do:[:c|preferredHeight := (c label preferredHeight) max:preferredHeight ].
preferredHeight := preferredHeight
+ (margin + margin + dataSet horizontalSpacing * 2)
].
^ preferredHeight
! !
!DSVLabelView methodsFor:'drawing'!
invalidate
(shown and:[isVisible]) ifTrue:[
super invalidate
]
!
invalidateItemAt:anIndex
"invalidate rectangle assigned to an item at an index
"
|cL xL xR hg|
(isVisible and:[shown]) ifTrue:[
cL := columns at:anIndex ifAbsent:[^ nil].
xL := dataSet xVisibleOfColNr:anIndex.
xR := xL + cL width.
(xL < width and:[xR > 0]) ifTrue:[
xL := xL max:0.
xR := xR min:width.
hg := height - margin - margin.
self invalidate:(Rectangle left:xL top:margin width:(xR - xL) height:hg)
]
]
!
redrawX:x y:y width:w height:h
"redraw a rectangle
"
|items savClip bg fg fgColor bgColor
inset "{ Class:SmallInteger }"
maxX "{ Class:SmallInteger }"
lblH "{ Class:SmallInteger }"
wt "{ Class:SmallInteger }"
x1 "{ Class:SmallInteger }"
x0 "{ Class:SmallInteger }"
|
(isVisible and:[shown]) ifFalse:[^ self].
bgColor := dataSet backgroundColor.
self paint:bgColor.
self fillRectangleX:x y:y width:w height:h.
columns isEmpty ifTrue:[^ self].
fgColor := dataSet foregroundColor.
inset := dataSet horizontalSpacing + 1.
maxX := (x + w) min:(width - margin).
lblH := height - margin - margin.
savClip := clipRect.
self clippingRectangle:(Rectangle left:x top:y width:w height:h).
x1 := dataSet xVisibleOfColNr:1.
columns keysAndValuesDo:[:aKey :aCol| |anItem|
anItem := aCol label.
wt := aCol width.
x0 := x1.
x1 := x1 + wt.
(x1 > x and:[x0 < maxX]) ifTrue:[
fg := (anItem foregroundColor) ? fgColor.
(bg := anItem backgroundColor) notNil ifTrue:[
bg ~= bgColor ifTrue:[
self paint:bg.
self fillRectangleX:x0 y:margin width:wt height:lblH.
]
] ifFalse:[
bg := bgColor
].
self paint:fg on:bg.
anItem redrawX:x0 w:wt h:height inset:inset on:self.
selection == aKey ifTrue:[
dataSet drawEdgesAtX:x0 y:margin width:wt height:lblH level:-1 on:self
] ifFalse:[
anItem labelIsButton ifTrue:[
dataSet drawEdgesAtX:x0 y:margin width:wt height:lblH level:1 on:self
]
]
]
].
self clippingRectangle:savClip.
! !
!DSVLabelView methodsFor:'event handling'!
buttonMotion:state x:x y:y
"mouse-button was moved;
redraw thumb at its new position and, if scroll-mode is asynchronous,
the scroll action is performed
"
|idx x1|
lineDrag notNil ifTrue:[
^ lineDrag moveToX:x
].
"/ in the resize area ?
idx := self xVisibleToColNr:(x-tabSpacing).
idx ~~ 0 ifTrue:[
x1 := dataSet xVisibleOfColNr:(idx + 1).
(x between:(x1-tabSpacing) and:(x1+tabSpacing))
"/ x + tabSpacing > x1
ifTrue:[
^ self cursor:handleCursor
].
].
self cursor:(Cursor normal)
!
buttonPress:button x:x y:y
"handle a button press event; checks whether the item under the mouse
is selectable. If true, the selection is set to the item.
"
|x1 idx col|
(isVisible and:[enabled and:[shown]]) ifFalse:[
^ self
].
"/ in the resize area ?
idx := self xVisibleToColNr:(x-tabSpacing).
idx ~~ 0 ifTrue:[
x1 := dataSet xVisibleOfColNr:(idx + 1).
(x between:(x1-tabSpacing) and:(x1+tabSpacing))
ifTrue:[
col := columns at:idx ifAbsent:nil.
self cursor:handleCursor.
lineDrag := LineDrag new.
lineDrag column:col
x:x
y:margin
h:(self height + dataSet height)
minX:(x1 - col width + col minimumRequiredWidth)
on:self.
^ self
]
].
idx := self xVisibleToColNr:x.
col := columns at:idx ifAbsent:nil.
col notNil ifTrue:[
col label isSelectable ifTrue:[
self invalidateItemAt:(selection := idx)
]
].
self cursor:(Cursor normal).
!
buttonRelease:button x:x y:y
"handle a button press event; checks whether the item under the mouse
is the selected item. If true, the application is informed.
"
|selected index column deltaX|
self cursor:(Cursor normal).
selection isNil ifTrue:[
lineDrag notNil ifTrue:[
lineDrag invertLine.
column := lineDrag column.
deltaX := lineDrag deltaX.
lineDrag := nil.
deltaX abs > 2 ifTrue:[
dataSet changeWidthOfColumn:column deltaX:deltaX
]
].
^ self
].
index := self xVisibleToSelectionIndex:x.
selected := index == selection.
index := selection.
selection := nil.
self invalidateItemAt:index.
selected ifTrue:[
(columns at:index) label sendClickMsgTo:(self application)
]
!
pointerLeave:state
"mouse left view - restore cursor.
"
self sensor anyButtonPressed ifFalse:[
self cursor:(Cursor normal)
].
!
xVisibleToColNr:x
"returns the column number assigned to a physical x or nil
"
|x0 x1|
x1 := dataSet xVisibleOfColNr:1.
columns keysAndValuesDo:[:index :aCol|
x0 := x1.
x1 := x0 + aCol width.
(x1 > x and:[x0 < x]) ifTrue:[
^ index
]
].
^ 0
! !
!DSVLabelView methodsFor:'instance creation'!
for:aColumnView
"initialization
"
dataSet := aColumnView.
self level:(dataSet level).
self borderWidth:(dataSet borderWidth).
!
initStyle
super initStyle.
handleCursor := (VariablePanel cursorForOrientation:#horizontal onDevice:device) onDevice:device.
!
initialize
super initialize.
super level:0.
enabled := true.
isVisible := true.
columns := #().
tabSpacing := 6.
self enableMotionEvents.
!
realize
"recompute contents and fit columns to view
"
self bitGravity:#NorthWest.
super realize.
! !
!DSVLabelView methodsFor:'queries'!
enabled
"true, if widget is enabled
"
^ enabled
!
enabled:aState
"true, if widget is enabled
"
enabled := aState.
!
isVisible
^ isVisible
!
isVisible:aBool
aBool ~~ isVisible ifTrue:[
isVisible := aBool.
dataSet layout:nil.
].
!
xVisibleToSelectionIndex:x
"returns the column number assigned to a physical x or nil. If
the column exists but is not selectable nil is returned.
"
|index column|
(isVisible and:[enabled]) ifTrue:[
( (index := dataSet xVisibleToColNr:x) notNil
and:[(column := columns at:index ifAbsent:nil) notNil
and:[column label isSelectable]]
) ifTrue:[
^ index
]
].
^ nil
! !
!DSVLabelView methodsFor:'scrolling'!
copyFromX:x0 y:y0 toX:x1 y:y1 width:w invalidateX:leftX
(shown and:[isVisible]) ifFalse:[^ self].
(self sensor hasDamageFor:self) ifTrue:[
self invalidate
] ifFalse:[
self copyFrom:self x:x0 y:y0 toX:x1 y:y1 width:w height:height async:false.
self invalidate:(Rectangle left:leftX top:0 width:(width - w) height:height)
repairNow:true
]
! !
!DSVLabelView::LineDrag methodsFor:'accessing'!
column
"return the value of the instance variable 'column' (automatically generated)"
^ column!
deltaX
"returns the distance x between the start and end action
"
^ topX - startX
! !
!DSVLabelView::LineDrag methodsFor:'dragging'!
invertLine
"invert for a line
"
rootView clippedByChildren:false.
rootView xoring:[
rootView lineWidth:2.
rootView displayLineFromX:topX y:topY toX:topX y:botY.
rootView flush
]
!
moveToX:viewX
|x|
x := (minX max:viewX) + transX.
x == topX ifFalse:[
self invertLine.
topX := x.
self invertLine.
]
! !
!DSVLabelView::LineDrag methodsFor:'setup'!
column:aColumn x:x y:y h:h minX:aMinX on:aView
|device point|
column := aColumn.
device := aView device.
rootView := device rootView.
point := device translatePoint:(x@y) from:(aView id) to:(rootView id).
topX := point x.
topY := point y.
botY := topY + h.
minX := aMinX.
startX := topX.
transX := topX - x.
self invertLine.
! !
!DSVLabelView class methodsFor:'documentation'!
version
^ '$Header: /cvs/stx/stx/libwidg2/DSVLabelView.st,v 1.30 1999-10-13 21:27:11 cg Exp $'
! !