home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 16 / CD_ASCQ_16_0994.iso / news / 4611 / fw16d.ins / SOURCE / CLASSES / TREEITEM.PRG < prev    next >
Text File  |  1994-04-24  |  4KB  |  166 lines

  1. #include "FiveWin.ch"
  2.  
  3. #define ID_EMPTY      Chr( 0 )
  4. #define ID_VERTLINE   Chr( 1 )
  5. #define ID_VERTHORZ   Chr( 2 )
  6. #define ID_CORNLINE   Chr( 3 )
  7.  
  8. static aLines
  9.  
  10. //----------------------------------------------------------------------------//
  11.  
  12. CLASS TTreeItem
  13.  
  14.    DATA   cDraw, cLabel
  15.    DATA   oPrev, oNext
  16.    DATA   oTree
  17.    DATA   lOpened
  18.    DATA   nLevel
  19.    DATA   hBmpOpen, hBmpClose
  20.  
  21.    METHOD New( cLabel, nLevel, hBmpOpen, hBmpClose ) CONSTRUCTOR
  22.  
  23.    METHOD Open() INLINE ;
  24.                   If( ! ::lOpened .and. ::oTree != nil, ::lOpened := .t.,)
  25.  
  26.    METHOD Close() INLINE  If( ::lOpened, ::lOpened := .f.,)
  27.  
  28.    METHOD Skip( @n )
  29.  
  30.    METHOD GetNext() INLINE If( ::lOpened, ::oTree:oFirst, ::oNext )
  31.    METHOD GetPrev()
  32.  
  33.    METHOD GetText() INLINE If( ::oTree != nil .and. ::lOpened, " - ", ;
  34.                            If( ::oTree != nil, " + ", "   " ) ) + ::cDraw + ::cLabel
  35.  
  36.    METHOD GetLabel()
  37.  
  38.    METHOD Draw( cPrevDraw )
  39.  
  40.    METHOD SetNext( oItem ) INLINE ::oNext := oItem,;
  41.           If( ::oTree != nil, ::oTree:oLast:SetNext( oItem ),)
  42.  
  43.    METHOD Toggle() INLINE If( ::lOpened, ::Close(), ::Open() )
  44.  
  45.    METHOD ColSizes()
  46.  
  47. ENDCLASS
  48.  
  49. //----------------------------------------------------------------------------//
  50.  
  51. METHOD New( cLabel, nLevel, hBmpOpen, hBmpClose ) CLASS TTreeItem
  52.  
  53.    ::cDraw     = ""
  54.    ::cLabel    = cLabel
  55.    ::lOpened   = .f.
  56.    ::nLevel    = nLevel
  57.    ::hBmpOpen  = hBmpOpen
  58.    ::hBmpClose = hBmpClose
  59.  
  60.    if aLines == nil
  61.       aLines = { LoadBitmap( GetResources(), "VertLine" ),;
  62.                  LoadBitmap( GetResources(), "VertHorz" ),;
  63.                  LoadBitmap( GetResources(), "CornLine" ) }
  64.    endif
  65.  
  66. return nil
  67.  
  68. //----------------------------------------------------------------------------//
  69.  
  70. METHOD Skip( n ) CLASS TTreeItem
  71.  
  72.    local nCount := 0
  73.    local oItem  := Self
  74.  
  75.    if n > 0
  76.       while nCount < n .and. oItem:GetNext() != nil
  77.           oItem = oItem:GetNext()
  78.           nCount++
  79.       end
  80.       n = nCount
  81.    endif
  82.  
  83.    if n < 0
  84.       while nCount < -n .and. oItem:GetPrev() != nil
  85.          oItem = oItem:GetPrev()
  86.          nCount++
  87.       end
  88.       n = -nCount
  89.    endif
  90.  
  91. return oItem
  92.  
  93. //----------------------------------------------------------------------------//
  94.  
  95. METHOD GetPrev() CLASS TTreeItem
  96.  
  97.    if ::oPrev != nil
  98.       if ::oPrev:nLevel < ::nLevel
  99.          return ::oPrev
  100.       else
  101.          if ::oPrev:lOpened
  102.             return ::oPrev:oTree:GetLast()
  103.          else
  104.             return ::oPrev
  105.          endif
  106.       endif
  107.    endif
  108.  
  109. return nil
  110.  
  111. //----------------------------------------------------------------------------//
  112.  
  113. METHOD Draw( cPrevDraw ) CLASS TTreeItem
  114.  
  115.    DEFAULT cPrevDraw := ""
  116.  
  117.    ::cDraw = cPrevDraw + ;
  118.              If( ::oPrev != nil,;
  119.              If( ::oNext != nil .and. ::oNext:nLevel == ::nLevel,;
  120.                  ID_VERTHORZ, ID_CORNLINE ), ID_EMPTY )
  121.  
  122.    If ::oTree != nil
  123.       ::oTree:Draw( cPrevDraw + ;
  124.                     If( ::oNext != nil,;
  125.                     If( ::oNext:nLevel < ::nLevel, ID_VERTHORZ, ID_VERTLINE ),;
  126.                         ID_EMPTY ) )
  127.    endif
  128.  
  129. return nil
  130.  
  131. //----------------------------------------------------------------------------//
  132.  
  133. METHOD GetLabel() CLASS TTreeItem
  134.  
  135.    local aLabel := Array( ::nLevel + 1 )
  136.    local n, nLine
  137.  
  138.    AFill( aLabel, 0 )
  139.    AAdd( aLabel, ::cLabel )
  140.  
  141.    for n = 1 to Len( ::cDraw )
  142.        nLine = Asc( SubStr( ::cDraw, n, 1 ) )
  143.        if nLine != 0
  144.           aLabel[ n ] = aLines[ nLine ]
  145.        endif
  146.    next
  147.  
  148.  
  149.    aLabel[ ::nLevel + 1 ] = If( ::oTree != nil,;
  150.                             If( ::lOpened, ::hBmpClose, ::hBmpOpen ), 0 )
  151.  
  152. return aLabel
  153.  
  154. //----------------------------------------------------------------------------//
  155.  
  156. METHOD ColSizes() CLASS TTreeItem
  157.  
  158.    local aCols := Array( ::nLevel + 1 )
  159.  
  160.    AFill( aCols, 16 )
  161.    AAdd( aCols, 300 )
  162.  
  163. return aCols
  164.  
  165. //----------------------------------------------------------------------------//
  166.