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

  1. #include "FiveWin.ch"
  2. #include "Constant.ch"
  3.  
  4.  
  5. #define ES_WANTRETURN    4096  // 0x1000
  6.  
  7. #define EM_GETSEL  (WM_USER+0)
  8. #define EM_SETSEL  (WM_USER+1)
  9.  
  10. #define COLOR_WINDOW        5
  11. #define COLOR_WINDOWTEXT    8
  12.  
  13. //----------------------------------------------------------------------------//
  14.  
  15. CLASS TMultiGet FROM TControl
  16.  
  17.    METHOD New( nRow, nCol, bSetGet, oWnd, nWidth, nHeight, oFont,;
  18.                lHScroll, nClrFore, nClrBack, oCursor, lPixel, cMsg,;
  19.                lUpdate ) CONSTRUCTOR
  20.  
  21.    METHOD ReDefine( nId, bSetGet, oWnd, nHelpId, nClrFore, nClrBack, oFont,;
  22.                     oCursor, cMsg, lUpdate ) CONSTRUCTOR
  23.  
  24.    METHOD cToChar() INLINE  Super:cToChar( "EDIT" )
  25.  
  26.    METHOD GotFocus() INLINE Super:GotFocus(),;
  27.                             SetWindowText( ::hWnd, Eval( ::bSetGet ) )
  28.  
  29.    METHOD Init( hDlg )
  30.  
  31.    METHOD LostFocus() INLINE Super:LostFocus(),;
  32.                              Eval( ::bSetGet, GetWindowText( ::hWnd ) )
  33.  
  34.    METHOD MouseMove( nRow, nCol, nKeyFlags )
  35.  
  36.    METHOD cText( cText ) SETGET
  37.  
  38.    METHOD Refresh() INLINE ;
  39.                     SetWindowText( ::hWnd, cValToChar( Eval( ::bSetGet ) ) )
  40.  
  41.    METHOD Save() INLINE Eval( ::bSetGet, GetWindowText( ::hWnd ) )
  42.  
  43.    METHOD VScroll( nWParam, nLParam ) VIRTUAL
  44.  
  45.    METHOD GetSel()
  46.  
  47. ENDCLASS
  48.  
  49. //----------------------------------------------------------------------------//
  50.  
  51. METHOD New( nRow, nCol, bSetGet, oWnd, nWidth, nHeight, oFont, lHScroll,;
  52.             nClrFore, nClrBack, oCursor, lPixel, cMsg, lUpdate ) CLASS TMultiGet
  53.  
  54.    DEFAULT lHScroll := .f.,;
  55.            nClrFore := GetSysColor( COLOR_WINDOWTEXT ),;
  56.            nClrBack := GetSysColor( COLOR_WINDOW ),;
  57.            lPixel   := .f., lUpdate := .f.
  58.  
  59.    ::cCaption = cValToChar( Eval( bSetGet ) )
  60.    ::nTop     = nRow * If( lPixel, 1, MGET_CHARPIX_H )  //13
  61.    ::nLeft    = nCol * If( lPixel, 1, MGET_CHARPIX_W )    // 8
  62.    ::nBottom  = If( nHeight == nil, ::nTop + 11, ::nTop + nHeight )
  63.    ::nRight   = If( nWidth == nil, ::nLeft + Len( ::cCaption ) * 3.5, ;
  64.                     ::nLeft + nWidth )
  65.    ::bSetGet  = bSetGet
  66.    ::oWnd     = oWnd
  67.    ::nStyle   = nOR( WS_CHILD, WS_VISIBLE, WS_BORDER, WS_TABSTOP, ES_LEFT,;
  68.                      ES_WANTRETURN, ES_MULTILINE, WS_VSCROLL,;
  69.                      If( lHScroll, WS_HSCROLL, 0 ) )
  70.    ::nId       = ::GetNewId()
  71.    ::cCaption  = RTrim( ::cCaption )
  72.    ::lDrag     = .f.
  73.    ::lCaptured = .f.
  74.    ::oCursor   = oCursor
  75.    ::oFont     = oFont
  76.    ::cMsg      = cMsg
  77.    ::lUpdate   = lUpdate
  78.  
  79.    ::SetColor( nClrFore, nClrBack )
  80.  
  81.    if oWnd:lVisible
  82.       ::Create( "EDIT" )
  83.       oWnd:AddControl( Self )
  84.    else
  85.       oWnd:DefControl( Self )
  86.    endif
  87.  
  88. return nil
  89.  
  90. //----------------------------------------------------------------------------//
  91.  
  92. METHOD ReDefine( nId, bSetGet, oWnd, nHelpId, nClrFore, nClrBack, oFont,;
  93.                  oCursor, cMsg, lUpdate ) CLASS TMultiGet
  94.  
  95.    DEFAULT nClrFore := GetSysColor( COLOR_WINDOWTEXT ),;
  96.            nClrBack := GetSysColor( COLOR_WINDOW ),;
  97.            lUpdate  := .f.
  98.  
  99.    ::nId       = nId
  100.    ::bSetGet   = bSetGet
  101.    ::oWnd      = oWnd
  102.    ::nHelpId   = nHelpId
  103.    ::lDrag     = .f.
  104.    ::lCaptured = .f.
  105.    ::oFont     = oFont
  106.    ::oCursor   = oCursor
  107.    ::cMsg      = cMsg
  108.    ::lUpdate   = .f.
  109.  
  110.    ::SetColor( nClrFore, nClrBack )
  111.  
  112.    oWnd:DefControl( Self )
  113.  
  114. return nil
  115.  
  116. //----------------------------------------------------------------------------//
  117.  
  118. METHOD Init( hDlg ) CLASS TMultiGet
  119.  
  120.    Super:Init( hDlg )
  121.    SetWindowText( ::hWnd, cValToChar( Eval( ::bSetGet ) ) )
  122.  
  123. return nil
  124.  
  125. //----------------------------------------------------------------------------//
  126.  
  127. METHOD cText( cText ) CLASS TMultiGet
  128.  
  129.    if PCount() == 1
  130.       SetWindowText( ::hWnd, cText )
  131.    endif
  132.  
  133. return GetWindowText( ::hWnd )
  134.  
  135. //----------------------------------------------------------------------------//
  136.  
  137. METHOD GetSel() CLASS TMultiGet
  138.  
  139.    local n      := ::SendMsg( EM_GETSEL )
  140.    local nStart := nLoWord( n )
  141.    local nEnd   := nHiWord( n )
  142.  
  143. return If( nStart != nEnd, SubStr( ::cText, nStart + 1, nEnd - nStart + 1 ), "" )
  144.  
  145. //----------------------------------------------------------------------------//
  146.  
  147. METHOD MouseMove( nRow, nCol, nKeyFlags ) CLASS TMultiGet
  148.  
  149.    if ::lDrag
  150.       return Super:MouseMove( nRow, nCol, nKeyFlags )
  151.    else
  152.       if ::oCursor != nil
  153.          SetCursor( ::oCursor:hCursor )
  154.       else
  155.          CursorIBeam()
  156.       endif
  157.    endif
  158.  
  159. return nil      // We want standard MultiLine Get behavior !!!
  160.  
  161. //---------------------------------------------------------------------------//
  162.