]>
Commit | Line | Data |
---|---|---|
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 SetCharIncludes(const wxString& chars); | |
78 | void SetIncludes(const wxArrayString& includes) { m_includes = includes; } | |
79 | inline wxArrayString& GetIncludes() { return m_includes; } | |
80 | ||
81 | void SetCharExcludes(const wxString& chars); | |
82 | void SetExcludes(const wxArrayString& excludes) { m_excludes = excludes; } | |
83 | inline wxArrayString& GetExcludes() { return m_excludes; } | |
84 | ||
85 | protected: | |
86 | ||
87 | // returns true if all characters of the given string are present in m_includes | |
88 | bool ContainsOnlyIncludedCharacters(const wxString& val) const; | |
89 | ||
90 | // returns true if all characters of the given string are NOT present in m_excludes | |
91 | bool ContainsExcludedCharacters(const wxString& val) const; | |
92 | ||
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; | |
95 | ||
96 | protected: | |
97 | wxTextValidatorStyle m_validatorStyle; | |
98 | wxString * m_stringValue; | |
99 | wxArrayString m_includes; | |
100 | wxArrayString m_excludes; | |
101 | ||
102 | private: | |
103 | DECLARE_NO_ASSIGN_CLASS(wxTextValidator) | |
104 | DECLARE_DYNAMIC_CLASS(wxTextValidator) | |
105 | DECLARE_EVENT_TABLE() | |
106 | }; | |
107 | ||
108 | #endif | |
109 | // wxUSE_VALIDATORS && (wxUSE_TEXTCTRL || wxUSE_COMBOBOX) | |
110 | ||
111 | #endif // _WX_VALTEXT_H_ |