home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / CLIPPER / OBJECTS / WINDOW.PRG < prev   
Text File  |  1992-12-04  |  4KB  |  144 lines

  1. #include "Objects.ch"
  2. #include "InKey.ch"
  3.  
  4. static cFrame
  5.  
  6. //----------------------------------------------------------------------------//
  7.  
  8. CLASS TWindow FROM TView
  9.  
  10.    DATA cTitle, cImage, cFrame
  11.    DATA cClrFocus, cClrFrame, cClrTitle
  12.    DATA lCloseable, lMaximizable, lGrow
  13.  
  14.    METHOD New( nTop, nLeft, nBottom, nRight, cTitle, cColors, lShadow )
  15.    METHOD NewCentered( nHeight, nWidth, cTitle, cColors, lShadow )
  16.    METHOD Display()
  17.    METHOD Click( nMRow, nMCol )
  18.    METHOD Say( nRow, nCol, cText, cColor )
  19.    METHOD SayCenter( nRow, cText, cColor )
  20.    METHOD KeyApply( nKey )
  21.  
  22. ENDCLASS
  23.  
  24. //----------------------------------------------------------------------------//
  25.  
  26. METHOD TWindow::New( nTop, nLeft, nBottom, nRight, cTitle, cColors, lShadow )
  27.  
  28.    local acColors := aStr2Array( If( cColors == nil, SetColor(), cColors ), "," )
  29.  
  30.    ::Parent:New( nTop, nLeft, nBottom, nRight )
  31.  
  32.    DEFAULT cTitle = ""
  33.  
  34.    ::cTitle       = cTitle
  35.    ::lShadow      = .t.
  36.    ::lCloseable   = .t.
  37.    ::lGrow        = .t.
  38.    ::lMaximizable = .f.
  39.    ::cClrFrame    = acColors[ 1 ]
  40.    ::cClrTitle    = acColors[ 4 ]
  41.    ::cImage       = ""
  42.  
  43.    if cFrame == nil
  44.       cFrame = If( lIsCua(), "   ▐╠═╚▌ ", "   │┘─└│ " )
  45.    endif
  46.  
  47. return Self
  48.  
  49. //----------------------------------------------------------------------------//
  50.  
  51. METHOD TWindow::NewCentered( nHeight, nWidth, cTitle, cColors, lShadow )
  52.  
  53.    local nTop    := ( MaxRow() / 2 ) - ( nHeight / 2 )
  54.    local nBottom := nTop + nHeight
  55.    local nLeft   := ( MaxCol() / 2 ) - ( nWidth / 2 )
  56.    local nRight  := nLeft + nWidth
  57.  
  58. return ::New( nTop, nLeft, nBottom, nRight, cTitle, cColors, lShadow )
  59.  
  60. //----------------------------------------------------------------------------//
  61.  
  62. METHOD TWindow::Display()
  63.  
  64.    local nMCrsOld := SetMCursor( 0 )
  65.  
  66.    DispBegin()
  67.    @ ::nTop, ::nLeft, ::nBottom, ::nRight BOX cFrame COLOR ::cClrFrame
  68.    if ! Empty( ::cTitle )
  69.       @ ::nTop, ::nLeft SAY PadC( ::cTitle, ::nRight - ::nLeft + 1 ) ;
  70.         COLOR ::cClrTitle
  71.    endif
  72.    if ::lCloseable
  73.       @ ::nTop, ::nLeft SAY If( lIsCua(), "╔╩", " ≡" ) COLOR ::cClrTitle
  74.    endif
  75.    if ::lShadow
  76.       if ::nRight <= MaxCol() - 1 .and. ::nTop <= MaxRow() - 1
  77.          ScrShadow( ::nTop + 1, ::nRight + 1, ::nBottom, ::nRight + 2 )
  78.       endif
  79.       if ::nBottom <= MaxRow() - 1 .and. ::nLeft <= MaxCol() - 2
  80.          ScrShadow( ::nBottom + 1, ::nLeft + 2, ::nBottom + 1, ::nRight + 2 )
  81.       endif
  82.    endif
  83.    DispEnd()
  84.  
  85.    SetMCursor( nMCrsOld )
  86.  
  87. return
  88.  
  89. //----------------------------------------------------------------------------//
  90.  
  91. METHOD TWindow::Click( nMRow, nMCol )
  92.  
  93.    do case
  94.       case nMRow == ::nTop .and. nMCol == ::nLeft
  95.            ::EndExec()
  96.  
  97.       case nMRow == ::nTop
  98.            do while lMPressed()
  99.               ::Move( nMRow(), nMCol() )
  100.               MUpdate()
  101.            enddo
  102.  
  103.       case nMRow == ::nBottom .and. nMCol == ::nRight
  104.            do while lMPressed()
  105.               ::Size( nMRow() - ::nTop + 1, nMCol() - ::nLeft + 1 )
  106.               MUpdate()
  107.            enddo
  108.    endcase
  109.  
  110. return
  111.  
  112. //----------------------------------------------------------------------------//
  113.  
  114. METHOD TWindow::Say( nRow, nCol, cText, cColor )
  115.  
  116.    DEFAULT cColor = ::cColor
  117.  
  118.    @ ::nTop + nRow, ::nLeft + nCol SAY cText COLOR cColor
  119.  
  120. return
  121.  
  122. //----------------------------------------------------------------------------//
  123.  
  124. METHOD TWindow::SayCenter( nRow, cText, cColor )
  125.  
  126.    local nCol := ( ( ::nRight - ::nLeft ) / 2 ) - ( Len( cText ) / 2 ) + 1
  127.  
  128.    ::Say( nRow, nCol, cText, cColor )
  129.  
  130. return
  131.  
  132. //----------------------------------------------------------------------------//
  133.  
  134. METHOD TWindow::KeyApply( nKey )
  135.  
  136.    do case
  137.       case nKey == K_ESC
  138.            ::EndExec()
  139.    endcase
  140.  
  141. return
  142.  
  143. //----------------------------------------------------------------------------//
  144.