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