home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 16 / CD_ASCQ_16_0994.iso / news / 4611 / fw16d.ins / SOURCE / CLASSES / SCRLLBAR.PRG < prev    next >
Text File  |  1994-06-10  |  8KB  |  245 lines

  1. #include "FiveWin.ch"
  2. #include "Constant.ch"
  3.  
  4. #define SB_HORZ 0
  5. #define SB_VERT 1
  6. #define SB_CTL  2
  7.  
  8. #define COLOR_SCROLLBAR 0
  9. #define COLOR_WINDOW    5
  10.  
  11. //----------------------------------------------------------------------------//
  12.  
  13. CLASS TScrollBar FROM TControl
  14.  
  15.    DATA   lVertical, lReDraw, lIsChild, nMin, nMax, nPgStep
  16.    DATA   bGoUp, bGoDown, bGoTop, bGoBottom, bPageUp, bPageDown, bPos
  17.  
  18.    METHOD New( nRow, nCol, nMin, nMax, nPgStep, lVertical, oWnd, nWidth,;
  19.                nHeight, bUpAction, bDownAction, bPgUp, bPgDown,;
  20.                bPos, lPixel, nClrText, nClrBack, cMsg, lUpdate ) CONSTRUCTOR
  21.  
  22.    METHOD WinNew( nMin, nMax, nPgStep, lVertical, oWnd, bUpAction,;
  23.                   bDownAction, bPgUp, bPgDown, bPos, nClrText, nClrBack,;
  24.                   lUpdate ) CONSTRUCTOR
  25.  
  26.    METHOD Redefine( nID, nMin, nMax, nPgStep, oWnd, bUpAction, bDownAction, ;
  27.                     bPgUp, bPgDown, bPos, nClrText, nClrBack, cMsg,;
  28.                     lUpdate ) CONSTRUCTOR
  29.  
  30.    METHOD cToChar() INLINE Super:cToChar( "SCROLLBAR" )
  31.  
  32.    METHOD GetPos() INLINE GetScrollPos( if( ::lIsChild, ::oWnd:hWnd, ::hWnd ),;
  33.             if( ::lIsChild, If( ::lVertical, SB_VERT, SB_HORZ ), SB_CTL ) )
  34.  
  35.    METHOD GetRange() INLINE GetScrollRange( if( ::lIsChild, ::oWnd:hWnd, ::hWnd ),;
  36.             if( ::lIsChild, If( ::lVertical, SB_VERT, SB_HORZ ), SB_CTL ) )
  37.  
  38.    METHOD HandleEvent( nMsg, nWParam, nLParam )
  39.  
  40.    METHOD Init( hDlg ) INLINE  Super:Init( hDlg ), ;
  41.                                ::SetRange( ::nMin, ::nMax ),;
  42.                                ::SetPos( ::nMin )
  43.  
  44.    // These two have to be BLOCK
  45.  
  46.    METHOD GoUp()   BLOCK { | Self, nPos | nPos := ::GetPos(),;
  47.                                           if( nPos > ::GetRange()[ 1 ],;
  48.                                               ::SetPos( --nPos ), ),;
  49.                           If( ::bGoUp != nil, Eval( ::bGoUp ),) }
  50.  
  51.    METHOD GoDown() BLOCK { | Self, nPos | nPos := ::GetPos(),;
  52.                                           if( nPos < ::nMax,;
  53.                                               ::SetPos( ++nPos ), ),;
  54.                           If( ::bGoDown != nil, Eval( ::bGoDown ),) }
  55.  
  56.  
  57.    METHOD GoTop() INLINE  ::SetPos( ::nMin ),;
  58.                           If( ::bGoTop != nil, Eval( ::bGoTop ),)
  59.  
  60.    METHOD GoBottom() INLINE  ::SetPos( ::nMax ),;
  61.                              If( ::bGoBottom != nil, Eval( ::bGoBottom ),)
  62.  
  63.    METHOD PageUp() INLINE  If( ::bPageUp != nil, Eval( ::bPageUp ),),;
  64.                            ::SetPos( ::GetPos() - ::nPgStep )
  65.  
  66.    METHOD PageDown() INLINE  If( ::bPageDown != nil, Eval( ::bPageDown ),),;
  67.                                  ::SetPos( ::GetPos() + ::nPgStep )
  68.  
  69.    METHOD SetPos( nPos ) INLINE ;
  70.                  SetScrollPos( if( ::lIsChild, ::oWnd:hWnd, ::hWnd ),;
  71.                  If( ::lIsChild, If( ::lVertical, SB_VERT, SB_HORZ ), SB_CTL ),;
  72.                  nPos, ::lReDraw )
  73.  
  74.    METHOD SetRange( nMin, nMax ) INLINE ;
  75.                                   ::nMin := nMin, ::nMax := nMax, ;
  76.            SetScrollRange( if( ::lIsChild, ::oWnd:hWnd, ::hWnd ), ;
  77.                if( ::lIsChild, If( ::lVertical, SB_VERT, SB_HORZ ), SB_CTL ), ;
  78.                     nMin, nMax, ::lReDraw )
  79.  
  80.    METHOD ThumbPos( nPos ) INLINE  If( ::bPos != nil, Eval( ::bPos, nPos ),)
  81.  
  82.    METHOD MouseMove( nRow, nCol, nKeyFlags )
  83.  
  84. ENDCLASS
  85.  
  86. //----------------------------------------------------------------------------//
  87.  
  88. METHOD New( nRow, nCol, nMin, nMax, nPgStep, lVertical, oWnd, nWidth, nHeight,;
  89.             bUpAct, bDownAct, bPgUp, bPgDown, bPos, lPixel, nClrText,;
  90.             nClrBack, cMsg, lUpdate ) CLASS TScrollBar
  91.  
  92.    DEFAULT nMin := 0, nMax := 0, nPgStep := 1,;
  93.            lVertical := .t., nWidth := If( lVertical, 16, 200 ),;
  94.            nHeight   := If( lVertical, 200, 17 ),;
  95.            lPixel    := .f.,;
  96.            nClrText  := GetSysColor( COLOR_WINDOW ),;
  97.            nClrBack  := GetSysColor( COLOR_SCROLLBAR ),;
  98.            lUpdate   := .f.
  99.  
  100.    ::cCaption   = ""
  101.    ::nTop       = nRow * If( lPixel, 1, SCRL_CHARPIX_H ) //14
  102.    ::nLeft      = nCol * If( lPixel, 1, SCRL_CHARPIX_W )    // 8
  103.    ::nBottom    = ::nTop + nHeight - 1
  104.    ::nRight     = ::nLeft + nWidth - 1
  105.    ::nMin       = nMin
  106.    ::nMax       = nMax
  107.    ::nPgStep    = nPgStep
  108.    ::lVertical  = lVertical
  109.    ::lReDraw    = .t.
  110.    ::nStyle     = nOR( WS_CHILD, WS_VISIBLE, WS_TABSTOP,;
  111.                        If( lVertical, SBS_VERT, SBS_HORZ ) )
  112.    ::bGoUp      = bUpAct
  113.    ::bGoDown    = bDownAct
  114.    ::bPageUp    = bPgUp
  115.    ::bPageDown  = bPgDown
  116.    ::bPos       = bPos
  117.    ::oWnd       = oWnd
  118.    ::lIsChild   = .f.
  119.    ::lDrag      = .f.
  120.    ::lCaptured  = .f.
  121.    ::cMsg       = cMsg
  122.    ::lUpdate    = lUpdate
  123.  
  124.    ::SetColor( nClrText, nClrBack )
  125.  
  126.    if oWnd:lVisible
  127.       ::Create( "SCROLLBAR" )
  128.       ::SetRange( ::nMin, ::nMax )
  129.       ::SetPos( ::nMin )
  130.    else
  131.       oWnd:DefControl( Self )
  132.    endif
  133.  
  134. return nil
  135.  
  136.  
  137. //---------------------------------------------------------------------------//
  138.  
  139. // Constructor for non-true ScrollBar Controls
  140. // ( when using WS_VSCROLL, WS_HSCROLL styles in a Window )
  141. // They are NOT controls but we consider them as real Objects!
  142.  
  143. METHOD WinNew( nMin, nMax, nPgStep, lVertical, oWnd, bUpAction,;
  144.                bDownAction, bPgUp, bPgDown, bPos, nClrText, nClrBack,;
  145.                lUpdate ) CLASS TScrollBar
  146.  
  147.    DEFAULT nMin := 1, nMax := 2, nPgStep := 1, lVertical := .t.,;
  148.            nClrText  := GetSysColor( COLOR_WINDOW ),;
  149.            nClrBack  := GetSysColor( COLOR_SCROLLBAR ),;
  150.            lUpdate   := .f.
  151.  
  152.    ::oWnd      = oWnd
  153.    ::lVertical = lVertical
  154.    ::lReDraw   = .t.
  155.    ::lIsChild  = .t.
  156.    ::nMin      = nMin
  157.    ::nMax      = nMax
  158.    ::nPgStep   = nPgStep
  159.    ::bGoUp     = bUpAction
  160.    ::bGoDown   = bDownAction
  161.    ::bPageUp   = bPgUp
  162.    ::bPageDown = bPgDown
  163.    ::bPos      = bPos
  164.    ::lUpdate   = lUpdate
  165.  
  166.    ::SetColor( nClrText, nClrBack )
  167.    ::SetRange( nMin, nMax )
  168.    ::SetPos( nMin )
  169.  
  170. return nil
  171.  
  172. //----------------------------------------------------------------------------//
  173.  
  174. METHOD Redefine( nID, nMin, nMax, nPgStep, oWnd, bUpAction, bDownAction, ;
  175.                  bPgUp, bPgDown, bPos, nClrText, nClrBack, cMsg,;
  176.                  lUpdate ) CLASS TScrollbar
  177.  
  178.    DEFAULT nMin := 0, nMax := 0, nPgStep := 1,;
  179.            nClrText  := GetSysColor( COLOR_WINDOW ),;
  180.            nClrBack  := GetSysColor( COLOR_SCROLLBAR ),;
  181.            lUpdate   := .f.
  182.  
  183.    ::nID        = nID
  184.    ::nMin       = nMin
  185.    ::nMax       = nMax
  186.    ::nPgStep    = nPgStep
  187.    ::lVertical  = .f.
  188.    ::lReDraw    = .t.
  189.    ::bGoUp      = bUpAction
  190.    ::bGoDown    = bDownAction
  191.    ::bPageUp    = bPgUp
  192.    ::bPageDown  = bPgDown
  193.    ::bPos       = bPos
  194.    ::oWnd       = oWnd
  195.    ::lIsChild   = .f. // .t. only for Windows with WS_HSCROLL ó WS_VSCROLL style
  196.    ::lRedraw    = .t.
  197.    ::oWnd       = oWnd
  198.    ::lDrag      = .f.
  199.    ::lCaptured  = .f.
  200.    ::cMsg       = cMsg
  201.    ::lUpdate    = lUpdate
  202.  
  203.    ::SetColor( nClrText, nClrBack )
  204.    oWnd:DefControl( Self )
  205.  
  206. return nil
  207.  
  208. //----------------------------------------------------------------------------//
  209.  
  210. METHOD HandleEvent( nMsg, nWParam, nLParam ) CLASS TScrollBar
  211.  
  212.    do case
  213.       case nMsg == WM_SCROLLUP
  214.            ::GoUp()
  215.            return 0
  216.  
  217.       case nMsg == WM_SCROLLDOWN
  218.            ::GoDown()
  219.            return 0
  220.  
  221.       case nMsg == WM_SCROLLPGUP
  222.            ::PageUp()
  223.            return 0
  224.  
  225.       case nMsg == WM_SCROLLPGDN
  226.            ::PageDown()
  227.            return 0
  228.  
  229.       case nMsg == FW_THUMBPOS
  230.            ::ThumbPos( nWParam )
  231.            return 0
  232.    endcase
  233.  
  234. return Super:HandleEvent( nMsg, nWParam, nLParam )
  235.  
  236. //----------------------------------------------------------------------------//
  237.  
  238. METHOD MouseMove( nRow, nCol, nKeyFlags ) CLASS TScrollBar
  239.  
  240.    local nResult := Super:MouseMove( nRow, nCol, nKeyFlags )
  241.  
  242. return If( ::lDrag, nResult, nil )    // We want standard behavior !!!
  243.  
  244. //----------------------------------------------------------------------------//
  245.