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

  1. #include "FiveWin.ch"
  2. #include "Constant.ch"
  3.  
  4. #define LTGRAY_BRUSH 1
  5.  
  6. static lRegistered := .f.
  7.  
  8. //----------------------------------------------------------------------------//
  9.  
  10. CLASS TMeter FROM TControl
  11.  
  12.    DATA   nTotal
  13.  
  14.    METHOD New( nRow, nCol, bSetGet, nTotal, oWnd, nWidth, nHeight,;
  15.                lUpdate ) CONSTRUCTOR
  16.  
  17.    METHOD ReDefine( nId, bSetGet, nTotal, oWnd, lUpdate ) CONSTRUCTOR
  18.  
  19.    METHOD Default()
  20.  
  21.    METHOD Init( hDlg ) INLINE Super:Init( hDlg ), ::Default()
  22.  
  23.    METHOD HandleEvent( nMsg, nWParam, nLParam )
  24.  
  25.    METHOD Paint() BLOCK ;
  26.       { | Self, nActual | MeterPaint( ::hWnd, ::hDC,;
  27.                           nActual := Eval( ::bSetGet ), ::nTotal,;
  28.                           nActual * 100 / ::nTotal ) }
  29.  
  30.    METHOD Set( nActual )
  31.  
  32. ENDCLASS
  33.  
  34. //----------------------------------------------------------------------------//
  35.  
  36. METHOD New( nRow, nCol, bSetGet, nTotal, oWnd, nWidth, nHeight,;
  37.             lUpdate ) CLASS TMeter
  38.  
  39.    DEFAULT nTotal  := 10, nWidth := 300, nHeight := 20,;
  40.            lUpdate := .f.
  41.  
  42.    ::nTop      = nRow * MTR_CHARPIX_H    //14
  43.    ::nLeft     = nCol *  MTR_CHARPIX_W    //8
  44.    ::nBottom   = ::nTop  + nHeight
  45.    ::nRight    = ::nLeft + nWidth
  46.    ::oWnd      = oWnd
  47.    ::nStyle    = nOR( WS_CHILD, WS_VISIBLE, WS_BORDER )
  48.    ::nId       = ::GetNewId()
  49.    ::bSetGet   = bSetGet
  50.    ::nTotal    = nTotal
  51.    ::lDrag     = .f.
  52.    ::lCaptured = .f.
  53.    ::lUpdate   = .f.
  54.  
  55.    if ! lRegistered
  56.       ::Register( nOR( CS_VREDRAW, CS_HREDRAW, CS_GLOBALCLASS ) )
  57.       lRegistered = .t.
  58.    endif
  59.  
  60.    if oWnd:lVisible
  61.       ::Create()
  62.       ::Default()
  63.       oWnd:AddControl( Self )
  64.    else
  65.       oWnd:DefControl( Self )
  66.    endif
  67.  
  68. return nil
  69.  
  70. //----------------------------------------------------------------------------//
  71.  
  72. METHOD ReDefine( nId, bSetGet, nTotal, oWnd, lUpdate ) CLASS TMeter
  73.  
  74.    DEFAULT nTotal := 10, lUpdate := .f.
  75.  
  76.    ::nId       = nId
  77.    ::bSetGet   = bSetGet
  78.    ::nTotal    = nTotal
  79.    ::oWnd      = oWnd
  80.    ::lDrag     = .f.
  81.    ::lCaptured = .f.
  82.    ::lUpdate   = lUpdate
  83.  
  84.    if ! lRegistered
  85.       ::Register( nOR( CS_VREDRAW, CS_HREDRAW, CS_GLOBALCLASS ) )
  86.       lRegistered = .t.
  87.    endif
  88.  
  89.    if oWnd != nil
  90.       oWnd:DefControl( Self )
  91.    endif
  92.  
  93. return nil
  94.  
  95. //----------------------------------------------------------------------------//
  96.  
  97. METHOD HandleEvent( nMsg, nWParam, nLParam ) CLASS TMeter
  98.  
  99.    if nMsg == WM_PAINT
  100.       ::BeginPaint()
  101.       ::Paint()
  102.       ::EndPaint()
  103.       return 0
  104.    endif
  105.  
  106. return Super:HandleEvent( nMsg, nWParam, nLParam )
  107.  
  108. //----------------------------------------------------------------------------//
  109.  
  110. METHOD Set( nActual ) CLASS TMeter
  111.  
  112.    DEFAULT nActual := Eval( ::bSetGet )
  113.  
  114.    if nActual > ::nTotal
  115.       nActual = ::nTotal
  116.    endif
  117.  
  118.    if nActual < 0
  119.       nActual = 0
  120.    endif
  121.  
  122.    Eval( ::bSetGet, nActual )
  123.  
  124.    ::Refresh( .f. )
  125.  
  126. return nil
  127.  
  128. //----------------------------------------------------------------------------//
  129.  
  130. METHOD Default() CLASS TMeter
  131.  
  132.    if ValType( Eval( ::bSetGet ) ) == "U"
  133.       Eval( ::bSetGet, 0 )
  134.    endif
  135.  
  136. return nil
  137.  
  138. //----------------------------------------------------------------------------//
  139.