SelectionInTreeView.st
changeset 478 d7286b946764
parent 471 6fe41e3caca1
child 480 982c2ad4f6a2
equal deleted inserted replaced
477:37f12d35c359 478:d7286b946764
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
    12 
    12 
    13 
    13 
    14 SelectionInListView subclass:#SelectionInTreeView
    14 SelectionInListView subclass:#SelectionInTreeView
    15 	instanceVariableNames:'figuresWidth leftIndent figuresWidthDiv2 figuresInset showLines
    15 	instanceVariableNames:'doubleClickSelectionBlock figuresWidth leftIndent
    16 		listOfNodes dblClickEvt imageOpened imageClosed imageItem'
    16 		figuresWidthDiv2 figuresInset showLines listOfNodes dblClickEvt
       
    17 		imageOpened imageClosed imageItem'
    17 	classVariableNames:'ImageOpened ImageClosed ImageItem'
    18 	classVariableNames:'ImageOpened ImageClosed ImageItem'
    18 	poolDictionaries:''
    19 	poolDictionaries:''
    19 	category:'Views-Text'
    20 	category:'Views-Text'
    20 !
    21 !
    21 
    22 
   207     super list:list keepSelection:keepSelection
   208     super list:list keepSelection:keepSelection
   208 ! !
   209 ! !
   209 
   210 
   210 !SelectionInTreeView methodsFor:'accessing-behavior'!
   211 !SelectionInTreeView methodsFor:'accessing-behavior'!
   211 
   212 
       
   213 doubleClickSelectionBlock
       
   214     "get the conditionBlock; this block is evaluated before a doubleClick action
       
   215      on a node containg children will be performed. In case of returning false, the
       
   216      doubleClick will not be handled.
       
   217    "
       
   218    ^ doubleClickSelectionBlock
       
   219 
       
   220 
       
   221 !
       
   222 
       
   223 doubleClickSelectionBlock:aBlock
       
   224     "set the conditionBlock; this block is evaluated before a doubleClick action
       
   225      on a node containg children will be performed. In case of returning false, the
       
   226      doubleClick will not be handled.
       
   227    "
       
   228    doubleClickSelectionBlock := aBlock
       
   229 
       
   230 
       
   231 !
       
   232 
   212 showLines
   233 showLines
   213     "returns true if lines are shown
   234     "returns true if lines are shown
   214     "
   235     "
   215   ^ showLines
   236   ^ showLines
   216 !
   237 !
   354 fetchDeviceResources
   375 fetchDeviceResources
   355     "initialize heavily used device resources - to avoid rendering
   376     "initialize heavily used device resources - to avoid rendering
   356      images again and again later"
   377      images again and again later"
   357 
   378 
   358     super fetchDeviceResources.
   379     super fetchDeviceResources.
   359 
   380     self refetchDeviceResources
   360     figuresInset := self class figuresInset.
   381 !
       
   382 
       
   383 fetchImageResources
       
   384     "initialize heavily used device resources - to avoid rendering
       
   385      images again and again later; returns maximum extent of the images used.
       
   386      Could be redefined by subclass
       
   387     "
       
   388     |y x t|
       
   389 
   361     imageOpened  := (self class imageOpened) onDevice:device.
   390     imageOpened  := (self class imageOpened) onDevice:device.
   362     imageClosed  := (self class imageClosed) onDevice:device.
   391     imageClosed  := (self class imageClosed) onDevice:device.
   363     imageItem    := (self class imageItem) onDevice:device.
   392     imageItem    := (self class imageItem)   onDevice:device.
   364 !
       
   365 
       
   366 getFontParameters
       
   367     "get some info of the used font and figures. They are cached since we use them
       
   368      often ..
       
   369     "
       
   370     |extent|
       
   371 
       
   372     super getFontParameters.
       
   373 
       
   374     imageClosed isNil ifTrue:[
       
   375         self fetchDeviceResources
       
   376     ].
       
   377     extent := self getMaxFiguresExtent.
       
   378 
       
   379     extent y > fontHeight ifTrue:[
       
   380         fontHeight := extent y
       
   381     ].
       
   382     figuresWidth     := extent x.
       
   383     leftIndent       := figuresInset + figuresWidth.
       
   384     figuresWidthDiv2 := figuresWidth // 2.
       
   385 !
       
   386 
       
   387 getMaxFiguresExtent
       
   388     "returns maximum extent of the figures used
       
   389     "
       
   390     |y x t|
       
   391 
   393 
   392     y := imageClosed heightOn:self.
   394     y := imageClosed heightOn:self.
   393     x := imageClosed widthOn:self.
   395     x := imageClosed widthOn:self.
   394 
   396 
   395     (t := imageOpened heightOn:self) > y ifTrue:[y := t].
   397     (t := imageOpened heightOn:self) > y ifTrue:[y := t].
   396     (t := imageOpened widthOn:self)  > x ifTrue:[x := t].
   398     (t := imageOpened widthOn:self)  > x ifTrue:[x := t].
   397     (t := imageItem   heightOn:self) > y ifTrue:[y := t].
   399     (t := imageItem   heightOn:self) > y ifTrue:[y := t].
   398     (t := imageItem   widthOn:self)  > x ifTrue:[x := t].
   400     (t := imageItem   widthOn:self)  > x ifTrue:[x := t].
   399 
   401 
   400   ^ x @ y
   402   ^ x @ y
       
   403 
   401 !
   404 !
   402 
   405 
   403 initialize
   406 initialize
   404     "setup instance attributes
   407     "setup instance attributes
   405     "
   408     "
   406     super initialize.
   409     super initialize.
   407     showLines    := true.
   410     showLines    := true.
   408     dblClickEvt  := false.
   411     dblClickEvt  := false.
       
   412     figuresWidth     := 18.                             "/ default: will change during startup
       
   413     figuresInset     := 2.                              "/ default: will change during startup
       
   414     leftIndent       := figuresWidth + figuresInset.    "/ default: will change during startup
       
   415     figuresWidthDiv2 := figuresWidth // 2.              "/ default: will change during startup
       
   416 !
       
   417 
       
   418 refetchDeviceResources
       
   419     "reinitialize heavily used device resources - to avoid rendering
       
   420      images again and again later
       
   421     "
       
   422     |extent|
       
   423 
       
   424     figuresInset := self class figuresInset.
       
   425     extent       := self fetchImageResources.
       
   426 
       
   427     extent y > fontHeight ifTrue:[
       
   428         fontHeight := extent y
       
   429     ].
       
   430     figuresWidth     := extent x.
       
   431     leftIndent       := figuresInset + figuresWidth.
       
   432     figuresWidthDiv2 := figuresWidth // 2.
   409 
   433 
   410 ! !
   434 ! !
   411 
   435 
   412 !SelectionInTreeView methodsFor:'private'!
   436 !SelectionInTreeView methodsFor:'private'!
   413 
   437 
   556 
   580 
   557     (node := self selectedNode) notNil ifTrue:[
   581     (node := self selectedNode) notNil ifTrue:[
   558         node hasChildren ifTrue:[
   582         node hasChildren ifTrue:[
   559          "/ node is a children container
   583          "/ node is a children container
   560 
   584 
       
   585             doubleClickSelectionBlock notNil ifTrue:[
       
   586                 (doubleClickSelectionBlock value:(self selectedIndex)) ifFalse:[
       
   587                     ^ self
       
   588                 ]
       
   589             ].
   561             node numberOfChildren == 0 ifTrue:[
   590             node numberOfChildren == 0 ifTrue:[
   562              "/ but without any children, thus redraw
   591              "/ but without any children, thus redraw
   563              "/ only selected line; figure may changed
   592              "/ only selected line; figure may changed
   564                 node isExpandable ifTrue:[node expand]
   593                 node isExpandable ifTrue:[node expand]
   565                                  ifFalse:[node collapse].
   594                                  ifFalse:[node collapse].
   576                 dblClickEvt := false.
   605                 dblClickEvt := false.
   577             ]
   606             ]
   578         ].
   607         ].
   579         super doubleClicked.
   608         super doubleClicked.
   580     ]
   609     ]
       
   610 
   581 !
   611 !
   582 
   612 
   583 selectNode:aNode
   613 selectNode:aNode
   584     "change selection to a node
   614     "change selection to a node
   585     "
   615     "
   612 ! !
   642 ! !
   613 
   643 
   614 !SelectionInTreeView class methodsFor:'documentation'!
   644 !SelectionInTreeView class methodsFor:'documentation'!
   615 
   645 
   616 version
   646 version
   617     ^ '$Header: /cvs/stx/stx/libwidg2/SelectionInTreeView.st,v 1.7 1997-07-23 07:43:16 ca Exp $'
   647     ^ '$Header: /cvs/stx/stx/libwidg2/SelectionInTreeView.st,v 1.8 1997-08-01 08:52:54 ca Exp $'
   618 ! !
   648 ! !