DSVLabelView.st
changeset 1491 d6133cb2f3c9
parent 1487 fd003e2156cc
child 1494 096845be5d75
equal deleted inserted replaced
1490:9c418c3aaf49 1491:d6133cb2f3c9
    13 
    13 
    14 
    14 
    15 
    15 
    16 
    16 
    17 SimpleView subclass:#DSVLabelView
    17 SimpleView subclass:#DSVLabelView
    18 	instanceVariableNames:'isVisible dataSet columns selection enabled preferredHeight'
    18 	instanceVariableNames:'isVisible dataSet tabulator columns selection enabled
       
    19 		preferredHeight'
    19 	classVariableNames:''
    20 	classVariableNames:''
    20 	poolDictionaries:''
    21 	poolDictionaries:''
    21 	category:'Views-DataSet'
    22 	category:'Views-DataSet'
       
    23 !
       
    24 
       
    25 SimpleView subclass:#Tabulator
       
    26 	instanceVariableNames:'column colRight startX transX minRqX'
       
    27 	classVariableNames:''
       
    28 	poolDictionaries:''
       
    29 	privateIn:DSVLabelView
    22 !
    30 !
    23 
    31 
    24 !DSVLabelView class methodsFor:'documentation'!
    32 !DSVLabelView class methodsFor:'documentation'!
    25 
    33 
    26 copyright
    34 copyright
   198 
   206 
   199 ! !
   207 ! !
   200 
   208 
   201 !DSVLabelView methodsFor:'event handling'!
   209 !DSVLabelView methodsFor:'event handling'!
   202 
   210 
       
   211 buttonMotion:state x:x y:y
       
   212     "mouse-button was moved while pressed;
       
   213      redraw thumb at its new position and, if scroll-mode is asynchronous, 
       
   214      the scroll action is performed
       
   215     "
       
   216     tabulator notNil ifTrue:[tabulator moveToX:x]
       
   217 
       
   218 
       
   219 !
       
   220 
   203 buttonPress:button x:x y:y
   221 buttonPress:button x:x y:y
   204     "handle a button press event; checks whether the item under the mouse
   222     "handle a button press event; checks whether the item under the mouse
   205      is selectable. If true, the selection is set to the item.
   223      is selectable. If true, the selection is set to the item.
   206     "
   224     "
   207     (selection := self xVisibleToSelectionIndex:x) notNil ifTrue:[
   225     |x0 x1|
   208         self invalidateItemAt:selection
   226 
   209     ]
   227     (isVisible and:[enabled and:[shown]]) ifFalse:[
       
   228         ^ self
       
   229     ].
       
   230     x1 := dataSet xVisibleOfColNr:1.
       
   231 
       
   232     columns keysAndValuesDo:[:index :aCol|
       
   233         x0 := x1.
       
   234         x1 := x0 + aCol width.
       
   235 
       
   236         (x1 > x and:[x0 < x]) ifTrue:[
       
   237             x + 6 > x1  ifFalse:[
       
   238                 aCol label isSelectable ifTrue:[
       
   239                     self invalidateItemAt:(selection := index)
       
   240                 ]
       
   241             ] ifTrue:[
       
   242                 tabulator := Tabulator new. 
       
   243                 tabulator column:aCol colRight:x1.
       
   244                 tabulator openFor:self x:x y:0 h:(self superView height)
       
   245             ].
       
   246             ^ self
       
   247         ].
       
   248     ].
       
   249 
   210 !
   250 !
   211 
   251 
   212 buttonRelease:button x:x y:y
   252 buttonRelease:button x:x y:y
   213     "handle a button press event; checks whether the item under the mouse
   253     "handle a button press event; checks whether the item under the mouse
   214      is the selected item. If true, the application is informed.
   254      is the selected item. If true, the application is informed.
   215     "
   255     "
   216     |selected index|
   256     |selected index column deltaX|
   217 
   257 
   218     selection isNil ifTrue:[
   258     selection isNil ifTrue:[
       
   259         tabulator notNil ifTrue:[
       
   260             column := tabulator column.
       
   261             deltaX := tabulator deltaX.
       
   262             tabulator destroy.
       
   263             tabulator := nil.
       
   264 
       
   265             deltaX abs > 2 ifTrue:[
       
   266                 dataSet changeWidthOfColumn:column deltaX:deltaX
       
   267             ]
       
   268         ].
   219         ^ self
   269         ^ self
   220     ].
   270     ].
   221     index     := self xVisibleToSelectionIndex:x.
   271     index     := self xVisibleToSelectionIndex:x.
   222     selected  := index == selection.
   272     selected  := index == selection.
       
   273     index     := selection.
   223     selection := nil.
   274     selection := nil.
   224 
   275 
   225     self invalidateItemAt:index.
   276     self invalidateItemAt:index.
   226 
   277 
   227     selected ifTrue:[
   278     selected ifTrue:[
   232 !DSVLabelView methodsFor:'instance creation'!
   283 !DSVLabelView methodsFor:'instance creation'!
   233 
   284 
   234 for:aColumnView
   285 for:aColumnView
   235     "initialization
   286     "initialization
   236     "
   287     "
       
   288     dataSet   := aColumnView.
       
   289     self level:(dataSet level).
       
   290     self borderWidth:(dataSet borderWidth).
       
   291 !
       
   292 
       
   293 initialize
       
   294     super initialize.
       
   295 
   237     enabled   := true.
   296     enabled   := true.
   238     isVisible := true.
   297     isVisible := true.
   239     dataSet   := aColumnView.
       
   240     columns   := #().
   298     columns   := #().
   241     self level:(dataSet level).
   299 
   242     self borderWidth:(dataSet borderWidth).
   300     self enableMotionEvents.
       
   301 
       
   302 
   243 !
   303 !
   244 
   304 
   245 realize
   305 realize
   246     "recompute contents and fit columns to view
   306     "recompute contents and fit columns to view
   247     "
   307     "
   306         self invalidate:(Rectangle left:leftX top:0 width:(width - w) height:height)
   366         self invalidate:(Rectangle left:leftX top:0 width:(width - w) height:height)
   307               repairNow:true
   367               repairNow:true
   308     ]
   368     ]
   309 ! !
   369 ! !
   310 
   370 
       
   371 !DSVLabelView::Tabulator methodsFor:'accessing'!
       
   372 
       
   373 column
       
   374     "return the value of the instance variable 'column' (automatically generated)"
       
   375 
       
   376     ^ column!
       
   377 
       
   378 deltaX
       
   379     "returns the distance x between the start and end action
       
   380     "
       
   381     ^ self origin x - startX
       
   382 ! !
       
   383 
       
   384 !DSVLabelView::Tabulator methodsFor:'dimension'!
       
   385 
       
   386 moveToX:x
       
   387     |ogX org|
       
   388 
       
   389     ogX := (minRqX max:x) + transX.
       
   390     org := self origin.
       
   391 
       
   392     org x ~~ ogX ifTrue:[
       
   393         org x:ogX.
       
   394         self origin:org.
       
   395     ]
       
   396 
       
   397 !
       
   398 
       
   399 openFor:aView x:x y:y h:h
       
   400     |pnt dev w|
       
   401 
       
   402     dev := aView device.
       
   403     pnt := dev translatePoint:(x@y)
       
   404                          from:(aView id)
       
   405                            to:(dev rootView id).
       
   406 
       
   407     minRqX := colRight - column width + column minimumRequiredWidth.
       
   408     transX := pnt x - x.
       
   409     startX := pnt x.
       
   410 
       
   411     self origin:pnt extent:(2 @ h).
       
   412     self backgroundColor:(Color black).
       
   413     self openAndWait.
       
   414 ! !
       
   415 
       
   416 !DSVLabelView::Tabulator methodsFor:'initialization'!
       
   417 
       
   418 column:aColumn colRight:x
       
   419     colRight := x.
       
   420     column   := aColumn.
       
   421 !
       
   422 
       
   423 isPopUpView
       
   424     "return true if view is a popup view; without decoration
       
   425      and popUp to top immediately
       
   426     "
       
   427     ^ true
       
   428 
       
   429 ! !
       
   430 
   311 !DSVLabelView class methodsFor:'documentation'!
   431 !DSVLabelView class methodsFor:'documentation'!
   312 
   432 
   313 version
   433 version
   314     ^ '$Header: /cvs/stx/stx/libwidg2/DSVLabelView.st,v 1.25 1999-08-24 15:29:02 cg Exp $'
   434     ^ '$Header: /cvs/stx/stx/libwidg2/DSVLabelView.st,v 1.26 1999-08-28 16:50:27 cg Exp $'
   315 ! !
   435 ! !