METHOD KeyDown( nKey, nFlags ) CLASS TGet
local nHi, nLo, nPos, nLastHi := -1, uVal
::nLastKey = nKey
if ::bKeyDown != nil
if ValType( uVal := Eval( ::bKeyDown, nKey, nFlags, Self ) ) == "N" .and. ;
uVal == 0
return 0
endif
endif
do case
case nKey == VK_TAB .or. nKey == VK_RETURN
do case
case zGetKey = 1
case zGetKey = 2
derecha()
case zGetKey = 3
if zControl < 41 .OR. zControl = 43 .OR. zControl = 44 .OR. zControl = 45
abajof()
else
derechaf()
endif
case zGetKey = 4
if zControl < 38 .OR. zControl = 40 .OR. zControl = 41 .OR. zControl = 42
abajadfa()
else
dereadfa()
endif
endcase
case nKey == VK_PRIOR
do case
case zGetKey = 1
if ::lSpinner
Self--
endif
case zGetKey = 2
antediar()
case zGetKey = 3
antefact()
case zGetKey = 4
anteadfa()
endcase
case nKey == VK_NEXT
do case
case zGetKey = 1
if ::lSpinner
Self++
endif
case zGetKey = 2
sigudiar()
case zGetKey = 3
sigufact()
case zGetKey = 4
siguadfa()
endcase
case nKey == VK_UP
do case
case zGetKey = 1
if Len( ::oWnd:aControls ) > 1
::oWnd:GoPrevCtrl( ::hWnd )
return 1 // avoid default behavior
endif
case zGetKey = 2
arriba()
case zGetKey = 3
arribaf()
case zGetKey = 4
arriadfa()
endcase
case nKey == VK_DOWN
do case
case zGetKey = 1
if Len( ::oWnd:aControls ) > 1
::oWnd:GoNextCtrl( ::hWnd )
return 1
endif
case zGetKey = 2
abajo()
case zGetKey = 3
abajof()
case zGetKey = 4
abajadfa()
endcase
case nKey == VK_LEFT
do case
case zGetKey = 1
if ::oGet:buffer != nil .and. ::nPos >= Len( ::oGet:buffer )
::GetSelPos( @nLo, @nHi )
::oGet:Pos = nLo + 1
::nPos := nLo + 1
endif
if GetKeyState( VK_CONTROL )
::oGet:WordLeft()
else
::oGet:Left()
#ifndef __XHARBOUR__
::nPos--
::oGet:Pos := ::nPos
#endif
endif
::oGet:Pos = Max( ::oGet:Pos, 1 )
while .t.
CallWindowProc( ::nOldProc, ::hWnd, WM_KEYDOWN, nKey, nFlags )
::GetSelPos( @nLo, @nHi )
if nLo <= ::oGet:Pos - 1
EXIT
endif
end
::nPos = nLo + 1
if ::nPos < ::oGet:Pos
#ifndef __XHARBOUR__
::SetPos( ::oGet:Pos-1 )
#else
::SetPos( ::oGet:Pos )
#endif
else
::oGet:Pos = ::nPos
endif
if ::oBtn != nil
::oBtn:Refresh()
endif
return 0
case zGetKey = 2
izquierda()
case zGetKey = 3
izquierdaf()
case zGetKey = 4
izquadfa()
endcase
case nKey == VK_RIGHT
do case
case zGetKey = 1
nPos = ::oGet:Pos
if GetKeyState( VK_CONTROL )
::oGet:wordRight()
else
::oGet:right()
endif
if nPos <> ::oGet:Pos
while .t.
CallWindowProc( ::nOldProc, ::hWnd, WM_KEYDOWN, nKey, nFlags )
::GetSelPos( @nLo, @nHi )
if nHi + 1 >= ::oGet:Pos .or. ::lPassword .or. ;
nHi == nLastHi
EXIT
endif
nLastHi = nHi
end
::oGet:Pos = nHi + 1
::nPos = nHi + 1
elseif nPos == Len( ::oGet:buffer )
// ::nPos++
// ::oGet:Pos := ::nPos
::GetSelPos( @nLo, @nHi )
::oGet:Pos = nLo + 1
::nPos := nLo + 1
CallWindowProc( ::nOldProc, ::hWnd, WM_KEYDOWN, nKey, nFlags )
endif
if ::oBtn != nil
::oBtn:Refresh()
endif
return 0
case zGetKey = 2
derecha()
case zGetKey = 3
derechaf()
case zGetKey = 4
dereadfa()
endcase
// Many thanks to HMP
case nKey == VK_INSERT .and. ! GetKeyState( VK_SHIFT ) ;
.and. ! GetKeyState( VK_CONTROL ) // to copy to the clipboard
do case
case zGetKey = 1
Set( _SET_INSERT, ! Set( _SET_INSERT ) )
DestroyCaret()
if Set( _SET_INSERT )
CreateCaret( ::hWnd, 0, 6, ::nGetChrHeight() - 1 )
else
CreateCaret( ::hWnd, 0, 2, ::nGetChrHeight() )
endif
ShowCaret( ::hWnd )
return 0
case zGetKey = 2
case zGetKey = 3
altafact()
case zGetKey = 4
endcase
case ( nKey == VK_INSERT .and. GetKeyState( VK_SHIFT ) ) .or. ;
( nKey == ASC("V") .and. GetKeyState( VK_CONTROL ) ) .or. ;
( nKey == ASC('X') .and. GetKeyState( VK_CONTROL ) ) .and. ;
! lAnd( nFlags, 2 ** 29 )
if ! ::lReadOnly
CallWindowProc( ::nOldProc, ::hWnd, WM_KEYDOWN, nKey, nFlags )
SysRefresh()
if ValType( ::oGet:buffer ) = "C"
::oGet:buffer = Pad( GetWindowText( ::hWnd ), Len( ::oGet:buffer ) )
SetWindowText( ::hWnd, ::oGet:buffer )
else
::oGet:buffer = GetWindowText( ::hWnd )
endif
::oGet:Assign()
// ::GetSelPos( @nLo, @nHi )
// ::nPos = nHi + 1
// ::oGet:Pos = ::nPos
if ::bChange != nil
Eval( ::bChange, nKey, nFlags, Self )
endif
endif
return 0
case nKey == VK_HOME .or. nKey == VK_END
if GetKeyState( VK_SHIFT )
CallWindowProc( ::nOldProc, ::hWnd, WM_KEYDOWN, nKey, nFlags )
::GetSelPos( @nLo, @nHi )
::oGet:Pos = nLo + 1
::nPos = nLo + 1
else
if nKey == VK_HOME
::oGet:Home()
::SetPos( ::oGet:Pos )
endif
if nKey == VK_END
::oGet:End()
if ::oGet:Pos == len( ::oGet:buffer )
::SetPos( ::oGet:Pos + 1)
else
::SetPos( ::oGet:Pos )
endif
endif
endif
if ::oBtn != nil
::oBtn:Refresh()
endif
return 0
case nKey == VK_DELETE .or. nKey == VK_BACK
if ::lReadOnly
return 0
endif
if ::lDrag
return ::Super:KeyDown( nKey, nFlags )
endif
::GetSelPos( @nLo, @nHi )
// Deletes selection
if nHi != nLo
::GetDelSel( nLo, nHi )
if GetKeyState( VK_SHIFT )
CallWindowProc( ::nOldProc, ::hWnd, WM_KEYDOWN, nKey, nFlags )
endif
else
if nKey == VK_DELETE
#ifndef __XHARBOUR__
if ::nPos > len( ::oGet:buffer )
return 0
endif
#endif
::oGet:Delete()
else
#ifndef __XHARBOUR__
if ::nPos > len( ::oGet:buffer )
::oGet:Delete()
else
::oGet:BackSpace()
endif
endif
endif
::EditUpdate()
if ::bChange != nil
Eval( ::bChange, nKey, nFlags, Self )
endif
return 0
#else
::oGet:BackSpace()
endif
endif
::EditUpdate()
if ::bChange != nil
Eval( ::bChange, nKey, nFlags, Self )
endif
return 0
#endif
endcase
return ::Super:KeyDown( nKey, nFlags )