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
29 wxFILTER_ALPHANUMERIC
= 0x8,
30 wxFILTER_DIGITS
= 0x10,
31 wxFILTER_NUMERIC
= 0x20,
32 wxFILTER_INCLUDE_LIST
= 0x40,
33 wxFILTER_INCLUDE_CHAR_LIST
= 0x80,
34 wxFILTER_EXCLUDE_LIST
= 0x100,
35 wxFILTER_EXCLUDE_CHAR_LIST
= 0x200
38 class WXDLLIMPEXP_CORE wxTextValidator
: public wxValidator
41 wxTextValidator(long style
= wxFILTER_NONE
, wxString
*val
= NULL
);
42 wxTextValidator(const wxTextValidator
& val
);
44 virtual ~wxTextValidator(){}
46 // Make a clone of this validator (or return NULL) - currently necessary
47 // if you're passing a reference to a validator.
48 // Another possibility is to always pass a pointer to a new validator
49 // (so the calling code can use a copy constructor of the relevant class).
50 virtual wxObject
*Clone() const { return new wxTextValidator(*this); }
51 bool Copy(const wxTextValidator
& val
);
53 // Called when the value in the window must be validated.
54 // This function can pop up an error message.
55 virtual bool Validate(wxWindow
*parent
);
57 // Called to transfer data to the window
58 virtual bool TransferToWindow();
60 // Called to transfer data from the window
61 virtual bool TransferFromWindow();
64 void OnChar(wxKeyEvent
& event
);
67 inline long GetStyle() const { return m_validatorStyle
; }
68 void SetStyle(long style
);
70 wxTextEntry
*GetTextEntry();
72 void SetCharIncludes(const wxString
& chars
);
73 void SetIncludes(const wxArrayString
& includes
) { m_includes
= includes
; }
74 inline wxArrayString
& GetIncludes() { return m_includes
; }
76 void SetCharExcludes(const wxString
& chars
);
77 void SetExcludes(const wxArrayString
& excludes
) { m_excludes
= excludes
; }
78 inline wxArrayString
& GetExcludes() { return m_excludes
; }
80 bool HasFlag(wxTextValidatorStyle style
) const
81 { return (m_validatorStyle
& style
) != 0; }
85 // returns true if all characters of the given string are present in m_includes
86 bool ContainsOnlyIncludedCharacters(const wxString
& val
) const;
88 // returns true if at least one character of the given string is present in m_excludes
89 bool ContainsExcludedCharacters(const wxString
& val
) const;
91 // returns the error message if the contents of 'val' are invalid
92 virtual wxString
IsValid(const wxString
& val
) const;
95 long m_validatorStyle
;
96 wxString
* m_stringValue
;
97 wxArrayString m_includes
;
98 wxArrayString m_excludes
;
101 wxDECLARE_NO_ASSIGN_CLASS(wxTextValidator
);
102 DECLARE_DYNAMIC_CLASS(wxTextValidator
)
103 DECLARE_EVENT_TABLE()
107 // wxUSE_VALIDATORS && (wxUSE_TEXTCTRL || wxUSE_COMBOBOX)
109 #endif // _WX_VALTEXT_H_