1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxTextValidator class
4 // Author: Julian Smart
8 // Copyright: (c) 1998 Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_VALTEXTH__
13 #define _WX_VALTEXTH__
16 #pragma interface "valtext.h"
23 #include "wx/validate.h"
25 #define wxFILTER_NONE 0x0000
26 #define wxFILTER_ASCII 0x0001
27 #define wxFILTER_ALPHA 0x0002
28 #define wxFILTER_ALPHANUMERIC 0x0004
29 #define wxFILTER_NUMERIC 0x0008
30 #define wxFILTER_INCLUDE_LIST 0x0010
31 #define wxFILTER_EXCLUDE_LIST 0x0020
32 #define wxFILTER_INCLUDE_CHAR_LIST 0x0040
33 #define wxFILTER_EXCLUDE_CHAR_LIST 0x0080
35 class WXDLLEXPORT wxTextValidator
: public wxValidator
37 DECLARE_DYNAMIC_CLASS(wxTextValidator
)
40 wxTextValidator(long style
= wxFILTER_NONE
, wxString
*val
= 0);
41 wxTextValidator(const wxTextValidator
& val
);
45 // Make a clone of this validator (or return NULL) - currently necessary
46 // if you're passing a reference to a validator.
47 // Another possibility is to always pass a pointer to a new validator
48 // (so the calling code can use a copy constructor of the relevant class).
49 virtual wxObject
*Clone() const { return new wxTextValidator(*this); }
50 bool Copy(const wxTextValidator
& val
);
52 // Called when the value in the window must be validated.
53 // This function can pop up an error message.
54 virtual bool Validate(wxWindow
*parent
);
56 // Called to transfer data to the window
57 virtual bool TransferToWindow();
59 // Called to transfer data to the window
60 virtual bool TransferFromWindow();
63 inline long GetStyle() const { return m_validatorStyle
; }
64 inline void SetStyle(long style
) { m_validatorStyle
= style
; }
66 void SetIncludeList(const wxStringList
& list
);
67 inline wxStringList
& GetIncludeList() { return m_includeList
; }
69 void SetExcludeList(const wxStringList
& list
);
70 inline wxStringList
& GetExcludeList() { return m_excludeList
; }
73 void OnChar(wxKeyEvent
& event
);
75 bool IsInCharIncludeList(const wxString
& val
);
76 bool IsNotInCharExcludeList(const wxString
& val
);
81 long m_validatorStyle
;
82 wxString
* m_stringValue
;
83 wxStringList m_includeList
;
84 wxStringList m_excludeList
;
86 bool CheckValidator() const
88 wxCHECK_MSG( m_validatorWindow
, FALSE
,
89 _T("No window associated with validator") );
90 wxCHECK_MSG( m_validatorWindow
->IsKindOf(CLASSINFO(wxTextCtrl
)), FALSE
,
91 _T("wxTextValidator is only for wxTextCtrl's") );
92 wxCHECK_MSG( m_stringValue
, FALSE
,
93 _T("No variable storage for validator") );