home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 16
/
CD_ASCQ_16_0994.iso
/
news
/
4611
/
fw16d.ins
/
SOURCE
/
CLASSES
/
GET.PRG
< prev
next >
Wrap
Text File
|
1994-06-12
|
12KB
|
438 lines
#include "FiveWin.ch"
#include "Constant.ch"
#include "Set.ch"
#define EM_GETSEL (WM_USER+0)
#define EM_SETSEL (WM_USER+1)
#define COLOR_WINDOW 5
#define COLOR_WINDOWTEXT 8
//----------------------------------------------------------------------------//
CLASS TGet FROM TControl
DATA oGet
DATA nClrFocusText, nClrFocusPane
METHOD New( nRow, nCol, bSetGet, oWnd, nWidth, nHeight, cPict, bValid,;
nClrFore, nClrBack, oFont, lDesign, oCursor, lPixel,;
cMsg, lUpdate ) CONSTRUCTOR
METHOD ReDefine( nId, bSetGet, oWnd, nHelpId, cPict, bValid,;
nClrFore, nClrBack, oFont, oCursor, cMsg,;
lUpdate ) CONSTRUCTOR
METHOD cToChar() INLINE Super:cToChar( "EDIT" )
METHOD Default()
METHOD cGenPrg()
METHOD GotFocus() INLINE Super:GotFocus(),;
::oGet:SetFocus(),;
SetWindowText( ::hWnd, ::oGet:buffer ), nil
METHOD HandleEvent( nMsg, nWParam, nLParam )
METHOD Init( hDlg )
METHOD KeyDown( nKey, nLData )
METHOD KeyChar( nKey )
METHOD LostFocus()
METHOD MouseMove( nRow, nCol, nKeyFlags )
METHOD cText( cText ) SETGET
METHOD Refresh() INLINE ::oGet:SetFocus(),;
::oGet:UpdateBuffer(),;
SetWindowText( ::hWnd, ::oGet:buffer )
METHOD Save() INLINE ::oGet:Assign()
METHOD GetSel()
METHOD GetSelPos( @nStart, @nEnd )
METHOD GetDelSel( nStart, nEnd )
METHOD EditUpdate()
METHOD lValid()
ENDCLASS
//----------------------------------------------------------------------------//
METHOD New( nRow, nCol, bSetGet, oWnd, nWidth, nHeight, cPict, bValid,;
nClrFore, nClrBack, oFont, lDesign, oCursor, lPixel, cMsg,;
lUpdate ) CLASS TGet
DEFAULT nClrFore := GetSysColor( COLOR_WINDOWTEXT ),;
nClrBack := GetSysColor( COLOR_WINDOW ),;
oWnd := GetWndDefault(),;
nHeight := If( oFont != nil, oFont:nHeight, 12 ),;
lDesign := .f., lPixel := .f., lUpdate := .f.
::cCaption = If( cPict == nil, cValToChar( Eval( bSetGet ) ), ;
Transform( Eval( bSetGet ), cPict ) )
::nTop = nRow * If( lPixel, 1, GET_CHARPIX_H ) //13
::nLeft = nCol * If( lPixel, 1, GET_CHARPIX_W ) // 8
::nBottom = ::nTop + nHeight - 1
::nRight = ::nLeft + If( nWidth == nil, ( 1 + Len( ::cCaption ) ) * 3.5, ;
nWidth - 1 )
::oWnd = oWnd
::nStyle = nOR( WS_CHILD, WS_VISIBLE, WS_BORDER, WS_TABSTOP, ES_LEFT,;
ES_AUTOHSCROLL, If( lDesign, WS_THICKFRAME, 0 ) )
::nId = ::GetNewId()
::bSetGet = bSetGet
::oGet = GetNew( 5000, 5000, bSetGet,, cPict )
::bValid = bValid
::lDrag = lDesign
::lCaptured = .f.
::oFont = oFont
::oCursor = oCursor
::cMsg = cMsg
::lUpdate = lUpdate
::SetColor( nClrFore, nClrBack )
::oGet:SetFocus()
::cCaption = ::oGet:Buffer
::oGet:KillFocus()
if oWnd:lVisible
::Create( "EDIT" )
::Default()
oWnd:AddControl( Self )
else
oWnd:DefControl( Self )
endif
return nil
//----------------------------------------------------------------------------//
METHOD ReDefine( nId, bSetGet, oWnd, nHelpId, cPict, bValid, nClrFore,;
nClrBack, oFont, oCursor, cMsg, lUpdate ) CLASS TGet
DEFAULT nClrFore := GetSysColor( COLOR_WINDOWTEXT ),;
nClrBack := GetSysColor( COLOR_WINDOW ),;
lUpdate := .f.
::nId = nId
::oWnd = oWnd
::nHelpId = nHelpId
::bSetGet = bSetGet
::oGet = GetNew( 5000, 5000, bSetGet,, cPict )
::bValid = bValid
::lDrag = .f.
::lCaptured = .f.
::oFont = oFont
::oCursor = oCursor
::cMsg = cMsg
::lUpdate = lUpdate
::SetColor( nClrFore, nClrBack )
oWnd:DefControl( Self )
return nil
//----------------------------------------------------------------------------//
METHOD Init( hDlg ) CLASS TGet
Super:Init( hDlg )
::oGet:SetFocus()
SetWindowText( ::hWnd, ::oGet:buffer )
::oGet:KillFocus()
return nil
//---------------------------------------------------------------------------//
// Actualiza texto y y posición del cursor del EDIT en función del oGet.
// Updates the text and the EDIT cursor position depending the oGet
METHOD EditUpdate() CLASS TGet
if ::oGet:HasFocus
SetWindowText( ::hWnd, ::oGet:buffer )
endif
CallWindowProc( ::nOldProc, ::hWnd, EM_SETSEL, 0, ;
nMakeLong( ::oGet:pos - 1, ::oGet:pos - 1 ) )
return nil
//---------------------------------------------------------------------------//
METHOD HandleEvent( nMsg, nWParam, nLParam ) CLASS TGet
static nCaretCol := 0
local nHi, nLo
do case
case nMsg == WM_PAINT
return nil
case nMsg == WM_LBUTTONDOWN
if ::lDrag
return Super:HandleEvent( nMsg, nWParam, nLParam )
else
CallWindowProc( ::nOldProc, ::hWnd, nMsg, nWParam, nLParam )
nCaretCol = GetCaretPos()[ 1 ]
return 1
endif
case nMsg == WM_LBUTTONUP
if ::lDrag
return Super:HandleEvent( nMsg, nWParam, nLParam )
else
::GetSelPos( @nLo, @nHi )
::oGet:pos = If( nCaretCol <= GetCaretPos()[ 1 ], nHi, nLo ) + 1
endif
case nMsg == WM_KEYUP
// Paste from clipboard
if nWParam == VK_INSERT .and. GetKeyState( VK_SHIFT )
::oGet:buffer = GetWindowText( ::hWnd )
::oGet:pos = nHiWord( ::SendMsg( EM_GETSEL ) ) + 1
elseif nWParam == VK_UP .or. nWParam == VK_DOWN
return 1 // We have not processed the key and we don't let
// the edit to do it
endif
endcase
return Super:HandleEvent( nMsg, nWParam, nLParam )
//----------------------------------------------------------------------------//
METHOD cText( uVal ) CLASS TGet
if PCount() == 1 // OJO Con Objects 2.0 PCount() es PCount() + 1
::oGet:VarPut( uVal )
::Refresh()
endif
return GetWindowText( ::hWnd )
//----------------------------------------------------------------------------//
METHOD GetSel() CLASS TGet
local n := ::SendMsg( EM_GETSEL )
local nStart := nLoWord( n )
local nEnd := nHiWord( n )
return If( nStart != nEnd, SubStr( ::cText, nStart, nEnd - nStart + 1 ), "" )
//----------------------------------------------------------------------------//
METHOD GetSelPos( nStart, nEnd ) CLASS TGet
local n := ::SendMsg( EM_GETSEL )
nStart := nLoWord( n )
nEnd := nHiWord( n )
return nil
//----------------------------------------------------------------------------//
METHOD GetDelSel( nStart, nEnd ) CLASS TGet
::oGet:buffer = Left( ::oGet:buffer, Min( nEnd, nStart ) ) ;
+ Right( ::oGet:buffer, ;
Len( ::oGet:buffer ) - Max( nEnd, nStart ) ) ;
+ Space( Abs( nStart - nEnd ) )
::oGet:Assign()
::oGet:Reset()
::oGet:pos := Min( nStart, nEnd ) + 1
return nil
//---------------------------------------------------------------------------//
METHOD MouseMove( nRow, nCol, nKeyFlags ) CLASS TGet
if ::lDrag
return Super:MouseMove( nRow, nCol, nKeyFlags )
else
::SetMsg( ::cMsg )
if ::oCursor != nil
SetCursor( ::oCursor:hCursor )
else
CursorIBeam()
endif
endif
return nil // We want standard Get behavior !!!
//---------------------------------------------------------------------------//
METHOD Default() CLASS TGet
if ::oFont != nil
::SetFont( ::oFont )
else
::SetFont( ::oWnd:oFont )
endif
return nil
//---------------------------------------------------------------------------//
METHOD cGenPrg() CLASS TGet
local cCode := ""
cCode += CRLF + " @ " + Str( ::nTop, 3 ) + ", " + Str( ::nLeft, 3 ) + ;
" GET oGet SIZE " + Str( ::nRight - ::nLeft + 1, 3 ) + ;
", " + Str( ::nBottom - ::nTop + 1, 3 ) + ;
" PIXEL OF oDlg " + CRLF
return cCode
//---------------------------------------------------------------------------//
METHOD KeyDown( nKey, nLData ) CLASS TGet
local nHi, nLo
do case
case nKey == VK_F1
return Super:KeyDown( nKey )
case nKey == VK_UP .or. nKey == VK_DOWN
::oWnd:FocusNext( ::hWnd, nKey == VK_UP )
return 1 // We have not processed the key and we
// don't let the edit to do it
case nKey == VK_LEFT
if GetKeyState( VK_CONTROL )
::oGet:wordLeft()
else
::oGet:left()
endif
CallWindowProc( ::nOldProc, ::hWnd, EM_SETSEL, 0, ;
nMakeLong( ::oGet:pos - 1, ::oGet:pos - 1 ) )
return 0
case nKey == VK_RIGHT
if GetKeyState( VK_CONTROL )
::oGet:wordRight()
else
::oGet:right()
endif
CallWindowProc( ::nOldProc, ::hWnd, EM_SETSEL, 0, ;
nMakeLong( ::oGet:pos - 1, ::oGet:pos - 1 ) )
return 0
case nKey == VK_DELETE
::GetSelPos( @nLo, @nHi )
// Deletes selection
if nHi != nLo
::GetDelSel( nLo, nHi )
if GetKeyState( VK_SHIFT )
CallWindowProc( ::nOldProc, ::hWnd, WM_KEYDOWN, nKey, nLData )
endif
else
::oGet:Delete()
endif
::EditUpdate()
return 1
case nKey == VK_HOME
::oGet:Home()
case nKey == VK_END
::oGet:End()
::EditUpdate()
return 1
otherwise
return Super:KeyDown( nKey, nLData )
endcase
return nil
//---------------------------------------------------------------------------//
METHOD KeyChar( nKey ) CLASS TGet
local nHi, nLo
do case
case nKey == VK_BACK
::oGet:BackSpace()
::EditUpdate()
case nKey == VK_ESCAPE
MessageBeep( -1 )
return 0
case nKey == VK_RETURN .or. nKey == VK_TAB
::oWnd:GoNextCtrl( ::hWnd )
return 0
case nKey >= 32 .or. nKey < 256
::GetSelPos( @nLo, @nHi )
// Borrar selección.
if nHi != nLo
::GetDelSel( nLo, nHi )
::EditUpdate()
endif
::oGet:Insert( Chr( nKey ) )
if ::oGet:Rejected()
MessageBeep( -1 )
else
::EditUpdate()
endif
if ::oGet:TypeOut .and. ! Set( _SET_CONFIRM )
::oWnd:GoNextCtrl( ::hWnd )
endif
otherwise
return Super:KeyChar( nKey )
endcase
return 1
//---------------------------------------------------------------------------//
METHOD lValid() CLASS TGet
if ::oGet:BadDate
MsgAlert( "Invalid date" )
return .f.
endif
return Super:lValid()
//---------------------------------------------------------------------------//
METHOD LostFocus() CLASS TGet
Super:LostFocus()
::oGet:SetFocus()
if ! ::oGet:BadDate
::oGet:Assign() // for adjust numbers
::oGet:UpdateBuffer()
endif
SetWindowText( ::hWnd, ::oGet:buffer )
if ! ::oGet:BadDate
::oGet:KillFocus()
else
::oGet:Pos = 1
endif
return nil
//----------------------------------------------------------------------------//