1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxTextValidator class
4 // Author: Julian Smart
5 // Modified by: Francesco Montorsi
7 // Copyright: (c) 1998 Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_VALTEXT_H_
12 #define _WX_VALTEXT_H_
16 #if wxUSE_VALIDATORS && (wxUSE_TEXTCTRL || wxUSE_COMBOBOX)
18 class WXDLLIMPEXP_FWD_CORE wxTextEntry
;
20 #include "wx/validate.h"
22 enum wxTextValidatorStyle
28 wxFILTER_ALPHANUMERIC
= 0x8,
29 wxFILTER_DIGITS
= 0x10,
30 wxFILTER_NUMERIC
= 0x20,
31 wxFILTER_INCLUDE_LIST
= 0x40,
32 wxFILTER_INCLUDE_CHAR_LIST
= 0x80,
33 wxFILTER_EXCLUDE_LIST
= 0x100,
34 wxFILTER_EXCLUDE_CHAR_LIST
= 0x200
37 class WXDLLIMPEXP_CORE wxTextValidator
: public wxValidator
40 wxTextValidator(long style
= wxFILTER_NONE
, wxString
*val
= NULL
);
41 wxTextValidator(const wxTextValidator
& val
);
43 virtual ~wxTextValidator(){}
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 from the window
60 virtual bool TransferFromWindow();
63 void OnChar(wxKeyEvent
& event
);
66 inline long GetStyle() const { return m_validatorStyle
; }
67 void SetStyle(long style
);
69 wxTextEntry
*GetTextEntry();
71 void SetCharIncludes(const wxString
& chars
);
72 void SetIncludes(const wxArrayString
& includes
) { m_includes
= includes
; }
73 inline wxArrayString
& GetIncludes() { return m_includes
; }
75 void SetCharExcludes(const wxString
& chars
);
76 void SetExcludes(const wxArrayString
& excludes
) { m_excludes
= excludes
; }
77 inline wxArrayString
& GetExcludes() { return m_excludes
; }
79 bool HasFlag(wxTextValidatorStyle style
) const
80 { return (m_validatorStyle
& style
) != 0; }
84 // returns true if all characters of the given string are present in m_includes
85 bool ContainsOnlyIncludedCharacters(const wxString
& val
) const;
87 // returns true if at least one character of the given string is present in m_excludes
88 bool ContainsExcludedCharacters(const wxString
& val
) const;
90 // returns the error message if the contents of 'val' are invalid
91 virtual wxString
IsValid(const wxString
& val
) const;
94 long m_validatorStyle
;
95 wxString
* m_stringValue
;
96 wxArrayString m_includes
;
97 wxArrayString m_excludes
;
100 wxDECLARE_NO_ASSIGN_CLASS(wxTextValidator
);
101 DECLARE_DYNAMIC_CLASS(wxTextValidator
)
102 DECLARE_EVENT_TABLE()
106 // wxUSE_VALIDATORS && (wxUSE_TEXTCTRL || wxUSE_COMBOBOX)
108 #endif // _WX_VALTEXT_H_