home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / CLIPPER / OBJECTS / VIEW.PRG < prev    next >
Text File  |  1992-11-10  |  5KB  |  213 lines

  1. #include "Objects.ch"
  2.  
  3. //----------------------------------------------------------------------------//
  4.  
  5. CLASS TView
  6.  
  7.    DATA nTop, nLeft, nBottom, nRight
  8.    DATA cMessage, cBackImage, cMsgBack
  9.    DATA cClrNormal, cClrFocus
  10.    DATA lEndExec, lFocused, lVisible, lShadow
  11.    DATA oParent
  12.  
  13.    METHOD New( nTop, nLeft, nBottom, nRight )
  14.    METHOD Show()
  15.    METHOD Display() VIRTUAL
  16.    METHOD Hide()
  17.    METHOD SetFocus( lOnOff )
  18.    METHOD lIsOver()
  19.    METHOD Move( nRow, nCol )
  20.    METHOD Size( nHeigh, nWidth )
  21.    METHOD KeyApply( nKey ) VIRTUAL
  22.    METHOD Exec()
  23.    METHOD EndExec()
  24.    METHOD Init() VIRTUAL
  25.    METHOD nAbsTop()
  26.    METHOD nAbsLeft()
  27.  
  28. ENDCLASS
  29.  
  30. //----------------------------------------------------------------------------//
  31.  
  32. METHOD TView::New( nTop, nLeft, nBottom, nRight )
  33.  
  34.    ::nTop       = If( nTop == nil, 0, nTop )
  35.    ::nLeft      = If( nLeft == nil, 0, nLeft )
  36.    ::nBottom    = If( nBottom == nil, 0, nBottom )
  37.    ::nRight     = If( nRight == nil, 0, nRight )
  38.    ::cBackImage = ""
  39.    ::cMsgBack   = ""
  40.    ::cClrNormal = "N/W"
  41.    ::cClrFocus  = "W/N"
  42.    ::lEndExec   = .f.
  43.    ::lFocused   = .f.
  44.    ::lVisible   = .f.
  45.    ::lShadow    = .f.
  46.  
  47. return Self
  48.  
  49. //----------------------------------------------------------------------------//
  50.  
  51. METHOD TView::Show()
  52.  
  53.    local nMCrsOld := SetMCursor( 0 )
  54.  
  55.    if ! ::lVisible
  56.       ::lVisible = .t.
  57.       ::cBackImage = SaveScreen( ::nTop, ::nLeft,;
  58.                                  ::nBottom + If( ::lShadow, 1, 0 ),;
  59.                                  ::nRight + If( ::lShadow, 2, 0 ) )
  60.       ::Display()
  61.    endif
  62.    SetMCursor( nMCrsOld )
  63.  
  64. return
  65.  
  66. //----------------------------------------------------------------------------//
  67.  
  68. METHOD TView::Hide()
  69.  
  70.    local nMCrsOld := SetMCursor( 0 )
  71.  
  72.    if ::lVisible
  73.       ::lVisible = .f.
  74.       RestScreen( ::nTop, ::nLeft,;
  75.                   ::nBottom + If( ::lShadow, 1, 0 ),;
  76.                   ::nRight + If( ::lShadow, 2, 0 ), ::cBackImage )
  77.       ::cBackImage = ""
  78.    endif
  79.  
  80.    SetMCursor( nMCrsOld )
  81.  
  82. return
  83.  
  84. //----------------------------------------------------------------------------//
  85.  
  86. METHOD TView::SetFocus( lOnOff )
  87.  
  88.    ::lFocused = lOnOff
  89.    if ::cMessage != nil
  90.       @ Set( _SET_MESSAGE ), 0 SAY If( Set( _SET_MCENTER ),;
  91.         PadC( ::cMessage, MaxCol() + 1 ), PadR( ::cMessage, MaxCol() + 1 ) ) ;
  92.         COLOR ::cClrNormal
  93.    endif
  94.  
  95. return
  96.  
  97. //----------------------------------------------------------------------------//
  98.  
  99. METHOD TView::lIsOver( nRow, nCol )
  100.  
  101. return nRow >= ::nTop .and. nRow <= ::nBottom .and. ;
  102.        nCol >= ::nLeft .and. nCol <= ::nRight
  103.  
  104. //----------------------------------------------------------------------------//
  105.  
  106. METHOD TView::Move( nRow, nCol )
  107.  
  108.    local nMCrsOld    := SetMCursor()
  109.    local nWidth      := ::nRight - ::nLeft
  110.    local nHeigh      := ::nBottom - ::nTop
  111.    local lWasVisible := ::lVisible
  112.  
  113.    if nRow != ::nTop .or. nCol != ::nLeft
  114.       SetMCursor( 0 )
  115.       DispBegin()
  116.       if ::lVisible
  117.          ::Hide()
  118.       endif
  119.       ::nTop    = nRow
  120.       ::nLeft   = nCol
  121.       ::nBottom = nRow + nHeigh
  122.       ::nRight  = nCol + nWidth
  123.       if lWasVisible
  124.          ::Show()
  125.       endif
  126.       DispEnd()
  127.       SetMcursor( nMCrsOld )
  128.    endif
  129.  
  130. return
  131.  
  132. //----------------------------------------------------------------------------//
  133.  
  134. METHOD TView::Size( nHeigh, nWidth )
  135.  
  136.    local nMCrsOld    := SetMCursor()
  137.    local lWasVisible := ::lVisible
  138.  
  139.    if ( nHeigh > 1 .and. nWidth > 1 ) .and. ;
  140.       ( ( nHeigh != ::nBottom - ::nTop + 1 ) .or. ;
  141.       ( nWidth != ::nRight - ::nLeft + 1 ) )
  142.       SetMCursor( 0 )
  143.       DispBegin()
  144.       if ::lVisible
  145.          ::Hide()
  146.       endif
  147.       ::nBottom = ::nTop + nHeigh - 1
  148.       ::nRight  = ::nLeft + nWidth - 1
  149.       if lWasVisible
  150.          ::Show()
  151.       endif
  152.       DispEnd()
  153.       SetMCursor( nMCrsOld )
  154.    endif
  155.  
  156. return
  157.  
  158. //----------------------------------------------------------------------------//
  159.  
  160. METHOD TView::Exec()
  161.  
  162.    local nCrsOld := SetCursor( 0 )
  163.    local nKey
  164.  
  165.    ::lEndExec = .f.
  166.    ::Show()
  167.    ::SetFocus( .t. )
  168.  
  169.    do while ! ::lEndExec
  170.  
  171.       nKey = nMKeyWait()
  172.  
  173.       if nKey == 0
  174.          ::Click( nMRow(), nMCol() )
  175.          do while lMPressed()
  176.             MUpdate()
  177.          enddo
  178.       else
  179.          if SetKey( nKey ) != nil
  180.             Eval( SetKey( nKey ) )
  181.          else
  182.             ::KeyApply( nKey )
  183.          endif
  184.       endif
  185.    enddo
  186.  
  187.    ::Hide()
  188.    SetCursor( nCrsOld )
  189.  
  190. return
  191.  
  192. //----------------------------------------------------------------------------//
  193.  
  194. METHOD TView::EndExec()
  195.  
  196.    ::lEndExec = .t.
  197.  
  198. return
  199.  
  200. //----------------------------------------------------------------------------//
  201.  
  202. METHOD TView::nAbsTop()
  203.  
  204. return ::nTop + If( ::oParent != nil, ::oParent:nAbsTop(), 0 )
  205.  
  206. //----------------------------------------------------------------------------//
  207.  
  208. METHOD TView::nAbsLeft()
  209.  
  210. return ::nLeft + If( ::oParent != nil, ::oParent:nAbsLeft(), 0 )
  211.  
  212. //----------------------------------------------------------------------------//
  213.