]> git.saurik.com Git - wxWidgets.git/blob - include/wx/valtext.h
a5fee8fb6f73e0b8f198a784617dc64bf371a7ba
[wxWidgets.git] / include / wx / valtext.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: valtext.h
3 // Purpose: wxTextValidator class
4 // Author: Julian Smart
5 // Modified by: Francesco Montorsi
6 // Created: 29/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998 Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_VALTEXT_H_
13 #define _WX_VALTEXT_H_
14
15 #include "wx/defs.h"
16
17 #if wxUSE_VALIDATORS && (wxUSE_TEXTCTRL || wxUSE_COMBOBOX)
18
19 class WXDLLIMPEXP_FWD_CORE wxTextEntry;
20
21 #include "wx/validate.h"
22
23 enum wxTextValidatorStyle
24 {
25 wxFILTER_NONE,
26 wxFILTER_ASCII,
27 wxFILTER_ALPHA,
28 wxFILTER_ALPHANUMERIC,
29 wxFILTER_SIMPLE_NUMBER,
30 wxFILTER_NUMERIC,
31 wxFILTER_INCLUDE_LIST,
32 wxFILTER_EXCLUDE_LIST,
33 wxFILTER_INCLUDE_CHAR_LIST,
34 wxFILTER_EXCLUDE_CHAR_LIST
35 };
36
37 class WXDLLIMPEXP_CORE wxTextValidator: public wxValidator
38 {
39 public:
40 wxTextValidator(wxTextValidatorStyle style = wxFILTER_NONE, wxString *val = NULL);
41 #if WXWIN_COMPATIBILITY_2_8
42 wxDEPRECATED_CONSTRUCTOR( wxTextValidator(long style, wxString *val) );
43 #endif
44 wxTextValidator(const wxTextValidator& val);
45
46 virtual ~wxTextValidator(){}
47
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);
54
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);
58
59 // Called to transfer data to the window
60 virtual bool TransferToWindow();
61
62 // Called to transfer data from the window
63 virtual bool TransferFromWindow();
64
65 // Filter keystrokes
66 void OnChar(wxKeyEvent& event);
67
68 // ACCESSORS
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) );
73 #endif
74
75 wxTextEntry *GetTextEntry();
76
77 void SetIncludes(const wxArrayString& includes) { m_includes = includes; }
78 inline wxArrayString& GetIncludes() { return m_includes; }
79
80 void SetExcludes(const wxArrayString& excludes) { m_excludes = excludes; }
81 inline wxArrayString& GetExcludes() { return m_excludes; }
82
83 protected:
84
85 // returns true if all characters of the given string are present in m_includes
86 bool ContainsOnlyIncludedCharacters(const wxString& val) const;
87
88 // returns true if all characters of the given string are NOT present in m_excludes
89 bool ContainsExcludedCharacters(const wxString& val) const;
90
91 // returns true if the contents of 'val' are valid for the current validation style
92 virtual bool IsValid(const wxString& val, wxString* errormsg) const;
93
94 protected:
95 wxTextValidatorStyle m_validatorStyle;
96 wxString * m_stringValue;
97 wxArrayString m_includes;
98 wxArrayString m_excludes;
99
100 private:
101 DECLARE_NO_ASSIGN_CLASS(wxTextValidator)
102 DECLARE_DYNAMIC_CLASS(wxTextValidator)
103 DECLARE_EVENT_TABLE()
104 };
105
106 #endif
107 // wxUSE_VALIDATORS && (wxUSE_TEXTCTRL || wxUSE_COMBOBOX)
108
109 #endif // _WX_VALTEXT_H_