CLASS TGet FROM TControl
DATA oGet, oBtn, bAction
DATA bMin, bMax
DATA nPos
DATA lReadOnly, lPassword
DATA cError, cBmpName
DATA hHeap
DATA cPicture
DATA bPostKey
DATA lSpinner
DATA nOldClrPane // Old background color, if color changed with focus
DATA nClrTextDis, nClrPaneDis
DATA nBmpWidth
DATA lAdjustBtn // Adjust buutton get
DATA lBtnTransparent
DATA cCueText
DATA nTxtStyle
DATA lKeepFocus INIT .T. // keep the focus after pressing the ACTION button
DATA lKeyUpper
METHOD New( nRow, nCol, bSetGet, oWnd, nWidth, nHeight, cPict, bValid,;
nClrFore, nClrBack, oFont, lDesign, oCursor, lPixel, cMsg,;
lUpdate, bWhen, lCenter, lRight, bChanged, lReadOnly,;
lPassword, lNoBorder, nHelpId, lSpinner,;
bUp, bDown, bMin, bMax, bAction, cBmpName, cVarName,;
cCueText ) CLASS TGet
local cText := Space( 50 )
DEFAULT nClrFore := GetSysColor( COLOR_WINDOWTEXT ),;
nClrBack := GetSysColor( COLOR_WINDOW ),;
oWnd := GetWndDefault(),;
nHeight := If( oFont != nil, oFont:nHeight, 12 ),;
lDesign := .f., lPixel := .f., lUpdate := .f.,;
lCenter := .f., lRight := .f.,;
lReadOnly := .f., lPassword := .f.,;
lSpinner := .f.,;
nRow := 0, nCol := 0, lNoBorder := .f.,;
bSetGet := bSETGET( cText )
::cCaption = If( cPict == nil, cValToChar( Eval( bSetGet ) ), ;
Transform( Eval( bSetGet ), cPict ) )
if lSpinner
nHeight := Max( 15, nHeight )
endif
::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 ) + ;
If( lSpinner, 20, 0 )
::oWnd = oWnd
::nStyle = nOR( WS_CHILD, WS_VISIBLE,;
ES_AUTOHSCROLL,;
If( ! lReadOnly, WS_TABSTOP, 0 ),;
If( lDesign, WS_CLIPSIBLINGS, 0 ),;
If( lSpinner, WS_VSCROLL, 0 ),;
If( lReadOnly, ES_READONLY, 0 ),;
If( lCenter, ES_CENTER, If( lRight, ES_RIGHT, ES_LEFT ) ) )
// If( lCenter .OR. lRight, ES_MULTILINE, 0 ),; Only needed for Win31
#ifdef __CLIPPER__
if ! lNoBorder
::nStyle = nOr( ::nStyle, WS_BORDER )
endif
#else
if ! IsAppThemed()
if ! lNoBorder
::nStyle = nOr( ::nStyle, WS_BORDER )
endif
else
if ! lNoBorder
::nStyle = nOr( ::nStyle, If( oWnd:IsKindOf( "TDIALOG" ), WS_BORDER, 0 ) )
::nExStyle = WS_EX_CLIENTEDGE
endif
endif
#endif
::nStyle = If( lNoBorder, nAnd( ::nStyle, nNot( WS_BORDER ) ), ::nStyle )
::nId = ::GetNewId()
::bSetGet = bSetGet
::oGet = FWGetNew( 20, 20, bSetGet, cVarName, cPict )
::bValid = bValid
::lDrag = lDesign
::lCaptured = .f.
::lPassword = lPassword
::oFont = oFont
::oCursor = oCursor
::cMsg = cMsg
::lUpdate = lUpdate
::bWhen = bWhen
::bChange = bChanged
::nPos = 1 // 0 14/Aug/98
::lReadOnly = lReadOnly
::lFocused = .f.
::nHelpId = nHelpId
::cPicture = cPict
::bPostKey = { | x, y | y }
::lSpinner = lSpinner
::hHeap = 0
::bAction = bAction
::cBmpName = cBmpName
::cCueText = cCueText
::nTxtStyle = nOR( ETO_CLIPPED, ETO_OPAQUE )
::SetColor( nClrFore, nClrBack )
::lAdjustBtn = .f.
::lBtnTransparent = .f.
::oGet:SetFocus()
::cCaption = ::oGet:Buffer
::oGet:KillFocus()
::nClrTextDis = nClrFore
::nClrPaneDis = ::nClrPane // nClrBack
::lKeyUpper = .f.
#ifndef __CLIPPER__
if lPassword .and. oFont == nil
DEFINE FONT ::oFont NAME "Arial" SIZE 0, -14 BOLD
endif
#endif
if ! Empty( oWnd:hWnd )
::Create( "EDIT" )
if oFont != nil
::SetFont( oFont )
endif
::GetFont()
oWnd:AddControl( Self )
::CreateButton()
else
oWnd:DefControl( Self )
endif
DEFAULT cVarName := "oGet" + ::GetCtrlIndex()
::cVarName = cVarName
if lDesign
::CheckDots()
endif
if lSpinner
::Spinner( bUp, bDown, bMin, bMax )
endif
return Self
//----------------------------------------------------------------------------//
METHOD ReDefine( nId, bSetGet, oWnd, nHelpId, cPict, bValid, nClrFore,;
nClrBack, oFont, oCursor, cMsg, lUpdate, bWhen, bChanged,;
lReadOnly, lSpinner, bUp, bDown, bMin, bMax, bAction, cBmpName,;
cVarName, cCueText ) CLASS TGet
DEFAULT oWnd := GetWndDefault(),;
nClrFore := GetSysColor( COLOR_WINDOWTEXT ),;
nClrBack := GetSysColor( COLOR_WINDOW ),;
lUpdate := .f., lReadOnly := .f., lSpinner := .f.
if Eval( bSetGet ) == nil
Eval( bSetGet, Space( 30 ) )
endif
::nId = nId
::oWnd = oWnd
::nHelpId = nHelpId
::bSetGet = bSetGet
::oGet = FWGetNew( 20, 20, bSetGet, cVarName, cPict )
::bValid = bValid
::lDrag = .f.
::lCaptured = .f.
::lPassword = .f.
::oFont = oFont
::oCursor = oCursor
::cMsg = cMsg
::lUpdate = lUpdate
::bWhen = bWhen
::bChange = bChanged
::nPos = 1 // 0 14/Aug/98
::lReadOnly = lReadOnly
::lFocused = .f.
::cPicture = cPict
::bPostKey = { | x, y | y }
::lSpinner = lSpinner
::hHeap = 0
::bAction = bAction
::cBmpName = cBmpName
::nClrTextDis = nClrFore
::nClrPaneDis = nClrBack
::lKeyUpper = .f.
::cCueText = cCueText
::nTxtStyle = nOR( ETO_CLIPPED, ETO_OPAQUE )
::SetColor( nClrFore, nClrBack )
::lAdjustBtn = .f.
::lBtnTransparent = .f.
if lSpinner
::Spinner( bUp, bDown, bMin, bMax )
endif
oWnd:DefControl( Self )
return Self
METHOD KeyChar( nKey, nFlags ) CLASS TGet
local nHi, nLo
local lAccept
local bKeyAction := SetKey( nKey )
local nDefButton
if ::bKeyChar != nil
if Eval( ::bKeyChar, nKey, nFlags, Self ) == 0
return 0
endif
endif
if nKey == VK_ESCAPE // avoids a beep!
::oWnd:KeyChar( nKey, nFlags )
return 1
endif
#ifndef __XPP__
if ! Empty( ::cPicture ) .and. '@!' $ ::cPicture
nKey = Asc( CharUpper( nKey ) )
elseif ::lKeyUpper
// acento agudo español
do case
case nKey == Chr(160) // á
nKey = Chr(181) // Á
case nKey == Chr(130) // é
nKey = Chr(144) // É
case nKey == Chr(161) // í
nKey = Chr(214) // Í
case nKey == Chr(162) // ó
nKey = Chr(224) // Ó
case nKey == Chr(163) // ú
nKey = Chr(233) // Ú
// letra ñ,N
case nKey == Chr(164) // ñ
nKey = Chr(165) // Ñ
otherwise
nKey = Asc( CharUpper( nKey ) )
endcase
endif
#endif
if bKeyAction != nil .and. lAnd( nFlags, 16777216 ) // function Key
Eval( bKeyAction, ProcName( 4 ), ProcLine( 4 ), Self )
return 0 // Already processed, API do nothing
endif
if ::lReadOnly
if nKey == VK_ESCAPE
::oWnd:End()
endif
return 0
endif
do case
case nKey == VK_BACK // Already processed at KeyDown
return 0
// case nKey == VK_ESCAPE
// return 0
case nKey == VK_TAB .and. GetKeyState( VK_SHIFT )
if ::bChange != nil .and. ( ::oGet:Changed .or. ::oGet:UnTransform() != ::oGet:Original )
lAccept = Eval( ::bChange, nKey, nFlags, Self )
if ValType( lAccept ) == "L" .and. lAccept
if ::oWnd:IsKindOf( "TCOMBOBOX" )
::oWnd:oWnd:GoPrevCtrl( ::hWnd )
else
::oWnd:GoPrevCtrl( ::hWnd )
endif
endif
else
if ::oWnd:IsKindOf( "TCOMBOBOX" )
::oWnd:oWnd:GoPrevCtrl( ::hWnd )
else
::oWnd:GoPrevCtrl( ::hWnd )
endif
endif
return 0
case nKey == VK_TAB .or. nKey == VK_RETURN
if ::bChange != nil .and. ( ::oGet:Changed .or. ::oGet:UnTransform() != ::oGet:Original )
lAccept = Eval( ::bChange, nKey, nFlags, Self )
if ValType( lAccept ) == "L"
if lAccept
::oWnd:GoNextCtrl( ::hWnd )
endif
else
::oWnd:GoNextCtrl( ::hWnd )
endif
else
::oWnd:GoNextCtrl( ::hWnd )
endif
#ifndef __CLIPPER__
if nKey == VK_RETURN // Execute DEFPUSHBUTTON Action
::Super:KeyChar( nKey, nFlags )
endif
#endif
return 0
case nKey >= 32 .and. nKey < 256
if ::oGet:buffer == nil
return 0
endif
if ::nPos > Len( ::oGet:buffer )
return 0
endif
::GetSelPos( @nLo, @nHi )
// Delete selection
if nHi != nLo
::GetDelSel( nLo, nHi )
::EditUpdate()
endif
if ::oGet:Type == "N" .and. ;
( Chr( nKey ) == "." .or. Chr( nKey ) == "," )
if ::oGet:Clear()
#ifndef __XHARBOUR__
::oGet:DelEnd()
#endif
endif
::oGet:ToDecPos()
else
if Set( _SET_INSERT ) // many thanks to HMP
::oGet:Insert( Chr( nKey ) )
else
::oGet:Overstrike( Chr( nKey ) )
end
endif
if ::oGet:Rejected
if Set( _SET_BELL )
MsgBeep()
endif
endif
::EditUpdate()
if nHi+1 == len( ::oGet:buffer )
::SetPos( nHi+2 )
endif
if ::oGet:TypeOut
if ! Set( _SET_CONFIRM )
::oWnd:nLastKey = VK_RETURN
::oWnd:GoNextCtrl( ::hWnd )
else
if Set( _SET_BELL )
MsgBeep()
endif
endif
endif
if ::bChange != nil
lAccept = Eval( ::bChange, nKey, nFlags, Self )
if ValType( lAccept ) == "L" .and. ! lAccept
return 0
endif
endif
Eval( ::bPostKey, Self, ::oGet:Buffer )
if ::oBtn != nil
::oBtn:Refresh()
endif
otherwise
return ::Super:KeyChar( nKey, nFlags )
endcase
return 0