home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 16 / CD_ASCQ_16_0994.iso / news / 4611 / fw16d.ins / SOURCE / CLASSES / BAR.PRG next >
Text File  |  1994-06-12  |  6KB  |  205 lines

  1. #include "FiveWin.ch"
  2.  
  3. static lRegistered := .f.
  4.  
  5. #define BAR_HEIGHT  28
  6. #define GRAY_BRUSH   2
  7.  
  8. #define BAR_TOP      1
  9. #define BAR_LEFT     2
  10. #define BAR_RIGHT    3
  11. #define BAR_ADJUST   4
  12.  
  13. //----------------------------------------------------------------------------//
  14.  
  15. CLASS TBar FROM TControl
  16.  
  17.    DATA   aButtons, nGroups, nMode
  18.    DATA   nBtnWidth, nBtnHeight
  19.    DATA   l3D
  20.  
  21.    METHOD New( oWnd, nBtnWidth, nBtnHeight, l3D, cMode, oCursor ) CONSTRUCTOR
  22.  
  23.    METHOD Add( oBtnBmp ) INLINE  AAdd( ::aButtons, oBtnBmp )
  24.  
  25.    METHOD Adjust() INLINE  BarAdjust( ::hWnd, ::nMode, ::oWnd:oMsgBar != nil )
  26.  
  27.    METHOD AdjMode() INLINE ::nMode := BAR_ADJUST,;
  28.                             ::SetCoors( TRect():New( -1, -1,;
  29.                             ::oWnd:nBottom + 1, ::oWnd:nRight + 1 ) )
  30.  
  31.    METHOD Click( hCtrl )
  32.  
  33.    METHOD cGenPRG()
  34.    METHOD GetBtnTop( lNewGroup )
  35.    METHOD GetBtnLeft( lNewGroup )
  36.    METHOD HandleEvent( nMsg, nWParam, nLParam )
  37.  
  38.    METHOD LeftMode() INLINE ::nMode := BAR_LEFT,;
  39.                             ::SetCoors( TRect():New( -1, -1,;
  40.                             ::oWnd:nBottom + 1, ::nBtnWidth - 1 ) )
  41.  
  42.    METHOD MouseMove( nRow, nCol, nKeyFlags ) INLINE ;
  43.                      Super:MouseMove( nRow, nCol, nKeyFlags ),;
  44.                      ::oWnd:SetMsg(), 0
  45.  
  46.    METHOD Paint()
  47.  
  48.    METHOD RightMode() INLINE ::nMode := BAR_RIGHT,;
  49.                              ::SetCoors( TRect():New( -1,;
  50.                              ::oWnd:nRight - ::nBtnWidth - 1,;
  51.                              ::oWnd:nBottom + 1, ::oWnd:nRight ) )
  52.  
  53.    METHOD TopMode() INLINE ::nMode := BAR_TOP,;
  54.                            ::SetCoors( TRect():New( -1, -1,;
  55.                            ::nBtnHeight + 1, ::oWnd:nRight + 1 ) )
  56.  
  57. ENDCLASS
  58.  
  59. //----------------------------------------------------------------------------//
  60.  
  61. METHOD New( oWnd, nBtnWidth, nBtnHeight, l3D, cMode, oCursor ) CLASS TBar
  62.  
  63.    local oRect := oWnd:GetCliRect()
  64.  
  65.    DEFAULT nBtnWidth := BAR_HEIGHT, nBtnHeight := BAR_HEIGHT,;
  66.            l3D := .f., cMode := "TOP"
  67.  
  68.    ::nStyle     = nOR( WS_BORDER, WS_CHILD, WS_VISIBLE )
  69.    ::aButtons   = {}
  70.    ::nGroups    = 0
  71.    ::oWnd       = oWnd
  72.    ::nTop       = -1
  73.    ::nLeft      = If( cMode == "RIGHT", oRect:nRight - nBtnWidth, -1 )
  74.    ::nBottom    = If( cMode == "TOP", nBtnHeight, oRect:nBottom + 1 )
  75.    ::nRight     = If( cMode == "TOP" .or. cMode == "ADJUST",;
  76.                       oRect:nRight,;
  77.                   If( cMode == "LEFT", nBtnWidth - 1, oRect:nRight + 1 ) )
  78.    ::nBtnWidth  = nBtnWidth
  79.    ::nBtnHeight = nBtnHeight
  80.    ::nId       = ::GetNewId()
  81.    ::lDrag     = .f.
  82.    ::lCaptured = .f.
  83.    ::nClrPane  = If( l3D, CLR_LIGHTGRAY, CLR_GRAY )
  84.    ::lVisible  = .t.
  85.    ::l3D       = l3D
  86.    ::nMode     = AScan( { "TOP", "LEFT", "RIGHT", "ADJUST" }, cMode )
  87.  
  88.    ::oBrush    = TBrush():New( ,::nClrPane, )
  89.    ::oCursor   = oCursor
  90.  
  91.    if ! lRegistered
  92.       ::Register( nOR( CS_VREDRAW, CS_HREDRAW, CS_GLOBALCLASS ) )
  93.       lRegistered = .t.
  94.    endif
  95.  
  96.    ::Create()
  97.  
  98.    if oWnd != nil
  99.       oWnd:oBar = Self
  100.    endif
  101.  
  102. return Self
  103.  
  104. //----------------------------------------------------------------------------//
  105.  
  106. METHOD Click( hCtrl ) CLASS TBar
  107.  
  108.    AEval( ::aButtons, { | oBtn | If( oBtn:hWnd == hCtrl, oBtn:Click(),) } )
  109.  
  110. return nil
  111.  
  112. //----------------------------------------------------------------------------//
  113.  
  114. METHOD cGenPRG() CLASS TBar
  115.  
  116.    local cPrg := ""
  117.    local n
  118.  
  119.    cPrg += CRLF + CRLF + "   DEFINE BUTTONBAR oBar OF oWnd"
  120.  
  121.    for n = 1 to Len( ::aButtons )
  122.       cPrg += ::aButtons[ n ]:cGenPRG()
  123.    next
  124.  
  125. return cPrg
  126.  
  127. //----------------------------------------------------------------------------//
  128.  
  129. METHOD GetBtnLeft( lNewGroup ) CLASS TBar
  130.  
  131.    local nPos := 0
  132.  
  133.    do case
  134.       case ::nMode == BAR_TOP
  135.            nPos = ( Len( ::aButtons ) * ::nBtnWidth ) - 1 + ;
  136.                   If( lNewGroup, ++::nGroups, ::nGroups ) * 15 + ;
  137.                   If( ::l3D, 2, 0 )
  138.  
  139.       case ::nMode == BAR_LEFT
  140.            nPos = -1 + If( ::l3D, 2, 0 )
  141.  
  142.       case ::nMode == BAR_RIGHT
  143.            nPos = ::nLeft - If( ::l3D, 2, 0 )
  144.  
  145.       case ::nMode == BAR_ADJUST
  146.            nPos = If( Len( ::aButtons ) > 0,;
  147.                   If( ATail( ::aButtons ):nRight + ::nBtnWidth > ::nRight,;
  148.                       -1, ( Len( ::aButtons ) * ::nBtnWidth ) - 1 ), -1 )
  149.    endcase
  150.  
  151. return nPos
  152.  
  153. //----------------------------------------------------------------------------//
  154.  
  155. METHOD GetBtnTop( lNewGroup ) CLASS TBar
  156.  
  157.    local nPos := 0
  158.  
  159.    do case
  160.       case ::nMode == BAR_TOP
  161.            nPos = If( ::l3D, 2, -1 )
  162.  
  163.       case ::nMode == BAR_LEFT .or. ::nMode == BAR_RIGHT
  164.            nPos = ( Len( ::aButtons ) * ( ::nBtnHeight + 1 ) ) - 1 + ;
  165.                   If( lNewGroup, ++::nGroups, ::nGroups ) * 15 + ;
  166.                   If( ::l3D, 3, 0 )
  167.    endcase
  168.  
  169. return nPos
  170.  
  171. //----------------------------------------------------------------------------//
  172.  
  173. METHOD HandleEvent( nMsg, nWParam, nLParam ) CLASS TBar
  174.  
  175.      do case
  176.         case nMsg == WM_LBUTTONDOWN
  177.              return ::Click( nWParam )
  178.  
  179.         case nMsg == WM_PAINT
  180.              ::BeginPaint()
  181.              ::Paint()
  182.              ::EndPaint()
  183.              return 0
  184.  
  185.         otherwise
  186.              return Super:HandleEvent( nMsg, nWParam, nLParam )
  187.      endcase
  188.  
  189. return nil
  190.  
  191. //----------------------------------------------------------------------------//
  192.  
  193. METHOD Paint() CLASS TBar
  194.  
  195.    if ! ::l3D
  196.       Super:Paint()
  197.    else
  198.       WndRaised( ::hWnd, ::GetDC() )
  199.       ::ReleaseDC()
  200.    endif
  201.  
  202. return nil
  203.  
  204. //----------------------------------------------------------------------------//
  205.