1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxTextValidator class
4 // Author: Julian Smart
5 // Modified by: Francesco Montorsi
8 // Copyright: (c) 1998 Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_VALTEXT_H_
13 #define _WX_VALTEXT_H_
17 #if wxUSE_VALIDATORS && (wxUSE_TEXTCTRL || wxUSE_COMBOBOX)
19 class WXDLLIMPEXP_FWD_CORE wxTextEntry
;
21 #include "wx/validate.h"
23 enum wxTextValidatorStyle
28 wxFILTER_ALPHANUMERIC
,
29 wxFILTER_SIMPLE_NUMBER
,
31 wxFILTER_INCLUDE_LIST
,
32 wxFILTER_EXCLUDE_LIST
,
33 wxFILTER_INCLUDE_CHAR_LIST
,
34 wxFILTER_EXCLUDE_CHAR_LIST
37 class WXDLLIMPEXP_CORE wxTextValidator
: public wxValidator
40 wxTextValidator(wxTextValidatorStyle style
= wxFILTER_NONE
, wxString
*val
= NULL
);
41 #if WXWIN_COMPATIBILITY_2_8
42 wxDEPRECATED_CONSTRUCTOR( wxTextValidator(long style
, wxString
*val
) );
44 wxTextValidator(const wxTextValidator
& val
);
46 virtual ~wxTextValidator(){}
48 // Make a clone of this validator (or return NULL) - currently necessary
49 // if you're passing a reference to a validator.
50 // Another possibility is to always pass a pointer to a new validator
51 // (so the calling code can use a copy constructor of the relevant class).
52 virtual wxObject
*Clone() const { return new wxTextValidator(*this); }
53 bool Copy(const wxTextValidator
& val
);
55 // Called when the value in the window must be validated.
56 // This function can pop up an error message.
57 virtual bool Validate(wxWindow
*parent
);
59 // Called to transfer data to the window
60 virtual bool TransferToWindow();
62 // Called to transfer data from the window
63 virtual bool TransferFromWindow();
66 void OnChar(wxKeyEvent
& event
);
69 inline wxTextValidatorStyle
GetStyle() const { return m_validatorStyle
; }
70 inline void SetStyle(wxTextValidatorStyle style
) { m_validatorStyle
= style
; }
71 #if WXWIN_COMPATIBILITY_2_8
72 wxDEPRECATED( void SetStyle(long style
) );
75 wxTextEntry
*GetTextEntry();
77 void SetCharIncludes(const wxString
& chars
);
78 void SetIncludes(const wxArrayString
& includes
) { m_includes
= includes
; }
79 inline wxArrayString
& GetIncludes() { return m_includes
; }
81 void SetCharExcludes(const wxString
& chars
);
82 void SetExcludes(const wxArrayString
& excludes
) { m_excludes
= excludes
; }
83 inline wxArrayString
& GetExcludes() { return m_excludes
; }
87 // returns true if all characters of the given string are present in m_includes
88 bool ContainsOnlyIncludedCharacters(const wxString
& val
) const;
90 // returns true if all characters of the given string are NOT present in m_excludes
91 bool ContainsExcludedCharacters(const wxString
& val
) const;
93 // returns true if the contents of 'val' are valid for the current validation style
94 virtual bool IsValid(const wxString
& val
, wxString
* errormsg
) const;
97 wxTextValidatorStyle m_validatorStyle
;
98 wxString
* m_stringValue
;
99 wxArrayString m_includes
;
100 wxArrayString m_excludes
;
103 DECLARE_NO_ASSIGN_CLASS(wxTextValidator
)
104 DECLARE_DYNAMIC_CLASS(wxTextValidator
)
105 DECLARE_EVENT_TABLE()
109 // wxUSE_VALIDATORS && (wxUSE_TEXTCTRL || wxUSE_COMBOBOX)
111 #endif // _WX_VALTEXT_H_