]>
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, | |
29 | wxFILTER_NUMERIC, | |
30 | wxFILTER_INCLUDE_LIST, | |
31 | wxFILTER_EXCLUDE_LIST, | |
32 | wxFILTER_INCLUDE_CHAR_LIST, | |
33 | wxFILTER_EXCLUDE_CHAR_LIST | |
34 | }; | |
c801d85f | 35 | |
53a2db12 | 36 | class WXDLLIMPEXP_CORE wxTextValidator: public wxValidator |
c801d85f | 37 | { |
c801d85f | 38 | public: |
40ae9600 FM |
39 | wxTextValidator(wxTextValidatorStyle style = wxFILTER_NONE, wxString *val = NULL); |
40 | #if WXWIN_COMPATIBILITY_2_8 | |
41 | wxDEPRECATED_CONSTRUCTOR( wxTextValidator(long style, wxString *val) ); | |
42 | #endif | |
33c5b54b | 43 | wxTextValidator(const wxTextValidator& val); |
c801d85f | 44 | |
d3c7fc99 | 45 | virtual ~wxTextValidator(){} |
c801d85f | 46 | |
33c5b54b RL |
47 | // Make a clone of this validator (or return NULL) - currently necessary |
48 | // if you're passing a reference to a validator. | |
49 | // Another possibility is to always pass a pointer to a new validator | |
50 | // (so the calling code can use a copy constructor of the relevant class). | |
51 | virtual wxObject *Clone() const { return new wxTextValidator(*this); } | |
52 | bool Copy(const wxTextValidator& val); | |
c801d85f | 53 | |
33c5b54b RL |
54 | // Called when the value in the window must be validated. |
55 | // This function can pop up an error message. | |
56 | virtual bool Validate(wxWindow *parent); | |
c801d85f | 57 | |
33c5b54b RL |
58 | // Called to transfer data to the window |
59 | virtual bool TransferToWindow(); | |
c801d85f | 60 | |
4deaa8db | 61 | // Called to transfer data from the window |
33c5b54b | 62 | virtual bool TransferFromWindow(); |
c801d85f | 63 | |
10b0f489 FM |
64 | // Filter keystrokes |
65 | void OnChar(wxKeyEvent& event); | |
66 | ||
33c5b54b | 67 | // ACCESSORS |
40ae9600 FM |
68 | inline wxTextValidatorStyle GetStyle() const { return m_validatorStyle; } |
69 | inline void SetStyle(wxTextValidatorStyle style) { m_validatorStyle = style; } | |
70 | #if WXWIN_COMPATIBILITY_2_8 | |
71 | wxDEPRECATED( void SetStyle(long style) ); | |
72 | #endif | |
c801d85f | 73 | |
472eec8a | 74 | wxTextEntry *GetTextEntry(); |
f94a790d RN |
75 | |
76 | void SetIncludes(const wxArrayString& includes) { m_includes = includes; } | |
77 | inline wxArrayString& GetIncludes() { return m_includes; } | |
78 | ||
79 | void SetExcludes(const wxArrayString& excludes) { m_excludes = excludes; } | |
80 | inline wxArrayString& GetExcludes() { return m_excludes; } | |
81 | ||
10b0f489 FM |
82 | protected: |
83 | ||
84 | // returns true if all characters of the given string are present in m_includes | |
85 | bool IsInCharIncludes(const wxString& val) const; | |
33c5b54b | 86 | |
10b0f489 FM |
87 | // returns true if all characters of the given string are NOT present in m_excludes |
88 | bool IsNotInCharExcludes(const wxString& val) const; | |
89 | ||
90 | // returns true if the contents of 'val' are valid for the current validation style | |
91 | bool IsValid(const wxString& val, wxString* errormsg) const; | |
c801d85f | 92 | |
c801d85f | 93 | protected: |
40ae9600 FM |
94 | wxTextValidatorStyle m_validatorStyle; |
95 | wxString * m_stringValue; | |
96 | wxArrayString m_includes; | |
97 | wxArrayString m_excludes; | |
33c5b54b | 98 | |
22f3361e | 99 | private: |
a2580e1c | 100 | DECLARE_NO_ASSIGN_CLASS(wxTextValidator) |
755369be FM |
101 | DECLARE_DYNAMIC_CLASS(wxTextValidator) |
102 | DECLARE_EVENT_TABLE() | |
c801d85f KB |
103 | }; |
104 | ||
105 | #endif | |
472eec8a | 106 | // wxUSE_VALIDATORS && (wxUSE_TEXTCTRL || wxUSE_COMBOBOX) |
ce4169a4 | 107 | |
92646f5a | 108 | #endif // _WX_VALTEXT_H_ |