I tried to use TEdit in my application, because I want an empty edit Box with unlimited text input, and it is not possible with TGet.
The problems I saw are:
- The font is not setted, it is only if you create the TEdit between Init Dialog and Activate Dialog as the example does, but with TWindow or using on Init it is not.
- There is no bUpdate/bChange support
- It works only with text, it is very minor.
- It is not possilbe use PIXEL coordinate, It is minor too.
To maintain compatibility with TGet I split the bChange in 2 notifications, 1 is bChange that can be used for accept/discard a character, and bUpdate that is called after the value updates.
So, Here the edit.prg modified:
- Code: Select all Expand view RUN
- // Class TEdit for two characters support (Chinesse, etc.)
#include "FiveWin.ch"
#include "constant.ch"
#define DEFAULT_GUI_FONT 17
#define EM_SETSEL 177
#define EM_LIMITTEXT 197
#define EM_SETCUEBANNER 0x1501
//#define EN_SETFOCUS 0x0100
//#define EN_KILLFOCUS 0x0200
//#define EN_CHANGE 0x0300
#define EN_UPDATE 0x0400
//#define EN_ERRSPACE 0x0500
//#define EN_MAXTEXT 0x0501
#define EN_HSCROLL 0x0601
//#define EN_VSCROLL 0x0602
//----------------------------------------------------------------------------//
CLASS TEdit FROM TControl
DATA cPicture, cType
DATA bHScroll, bUpdate
METHOD New( nRow, nCol, bSetGet, oWnd, nWidth, nHeight, lPixel, oFont, cPicture, ;
bChanged, bUpdate, bHScroll) CONSTRUCTOR
METHOD ReDefine( nId, oWnd, bSetGet, cPicture, bChanged, bUpdate, bHScroll ) CONSTRUCTOR
METHOD cToChar() INLINE ::Super:cToChar( "EDIT" )
METHOD Initiate( hDlg )
METHOD MouseMove() VIRTUAL
METHOD LostFocus( hWndGetFocus )
METHOD GotFocus() INLINE ::SelectAll(), ::Super:GotFocus()
METHOD SelectAll() INLINE ::SetSel( 0, -1 )
METHOD SetSel( nStart, nEnd ) INLINE ;
nStart := If( nStart == nil, 1, nStart ),;
nEnd := If( nEnd == nil, nStart, nEnd ),;
SendMessage( ::hWnd, EM_SETSEL, nStart, nEnd )
METHOD Refresh() INLINE ::SetText( If( Empty( ::cPicture ), ;
cValToChar( Eval( ::bSetGet ) ),;
Transform( Eval( ::bSetGet ), ::cPicture ) ) )
METHOD Read()
METHOD SetLimitText(n) INLINE SendMessage( ::hWnd, EM_LIMITTEXT, if(valtype(n)="N",n,0), 0 )
METHOD SetCueBanner( lOnFocus, cText ) INLINE SendMessage( ::hWnd, EM_SETCUEBANNER, lOnFocus, AnsiToWide( cText ) )
METHOD KeyChar( nKey, nFlags )
METHOD Command( nWParam, nLParam )
ENDCLASS
//----------------------------------------------------------------------------//
METHOD New( nRow, nCol, bSetGet, oWnd, nWidth, nHeight, lPixel, oFont, cPicture,;
bChanged, bUpdate, bHScroll ) CLASS TEdit
LOCAL startVal := Eval(bSetGet)
LOCAL cType :=ValType(startVal)
DEFAULT nRow := 0, nCol := 0, oWnd := GetWndDefault(), nWidth := 80,;
nHeight := 20, lPixel := .F.
if oFont == nil
oFont := TFont():New()
oFont:hFont := GetStockObject( DEFAULT_GUI_FONT )
endif
::oWnd = oWnd
::nId = ::GetNewId()
::nStyle = nOR( WS_CHILD, WS_VISIBLE, WS_BORDER, WS_TABSTOP, ES_AUTOHSCROLL )
::nTop = if( lPixel, nRow, nRow * GET_CHARPIX_H )
::nLeft = if( lPixel, nCol, nCol * GET_CHARPIX_W )
::nBottom = ::nTop + nHeight - 1
::nRight = ::nLeft + nWidth
::lDrag = .F.
::bSetGet = bSetGet
::cPicture = cPicture
::cType = cType
::oFont = oFont
::bChange = bChanged
::bUpdate = bUpdate
::bHScroll = bHScroll
::cCaption = If( Empty( cPicture ), cValToChar( startVal ),;
Transform( startVal, cPicture ) )
if ! Empty( oWnd:hWnd )
::Create( "EDIT" )
if ::oFont != nil
::SetFont( ::oFont )
else
::GetFont()
endif
oWnd:AddControl( Self )
else
oWnd:DefControl( Self )
endif
return Self
//----------------------------------------------------------------------------//
METHOD ReDefine( nId, oWnd, bSetGet, cPicture, bChanged, bUpdate, bHScroll ) CLASS TEdit
DEFAULT oWnd := GetWndDefault()
::nId = nId
::oWnd = oWnd
::bSetGet = bSetGet
::cPicture = cPicture
::bChange = bChanged
::bUpdate = bUpdate
::bHScroll = bHScroll
oWnd:DefControl( Self )
::Refresh()
return Self
//----------------------------------------------------------------------------//
METHOD Initiate( hDlg ) CLASS TEdit
::Super:Initiate( hDlg )
::Refresh()
return nil
//----------------------------------------------------------------------------//
METHOD LostFocus( hWndGetFocus ) CLASS TEdit
::Super:LostFocus( hWndGetFocus )
::Read()
return nil
//----------------------------------------------------------------------------//
METHOD Read() CLASS TEdit
if Empty( ::bSetGet )
return nil
endif
if ::cType == "C"
Eval( ::bSetGet, ::GetText() )
elseif ::cType == "N"
Eval( ::bSetGet, Val(::GetText()) )
elseif ::cType == "D"
Eval( ::bSetGet, CToD(::GetText()) )
endif
return nil
//----------------------------------------------------------------------------//
METHOD KeyChar( nKey, nFlags ) CLASS TEdit
LOCAL lAccept
if ::cType == "N"
if .not. (( nKey>=asc('0') .and. nKey<=asc('9')) .or. ;
nKey==asc('-') .or. nKey==asc('.') .or. nKey<32)
return 0
endif
endif
if ::bChange != nil
lAccept = Eval( ::bChange, nKey, nFlags, Self )
if ValType( lAccept ) == "L" .and. ! lAccept
return 0
endif
endif
return ::Super:KeyChar( nKey, nFlags )
//----------------------------------------------------------------------------//
METHOD Command( nWParam, nLParam ) CLASS TEdit
local nCode := nHiWord( nWParam )
if nCode == EN_UPDATE .and. ::bUpdate != nil
::Read()
Eval( ::bUpdate, Self )
endif
if nCode == EN_HSCROLL .and. ::bHScroll != nil
Eval( ::bHScroll, Self )
endif
return nil
//----------------------------------------------------------------------------//
to use this is necessary change the METHOD Command of TDialog and TWindow adding this case:
- Code: Select all Expand view RUN
- case GetClassName( hWndCtl ) == "Edit"
oCtrl :=oWndFromHwnd( hWndCtl )
if oCtrl!=nil .and. oCtrl:ClassName() == "TEDIT"
oCtrl:Command( nWParam, nLParam )
return nil
endif
IMHO, as user, with these modification the TEdit is usable, and the cue banner works!
some comments?
Regards,
Antonino