]> git.saurik.com Git - wxWidgets.git/blob - include/wx/valtext.h
Applied #15226 wxRichTextCtrl: Implement setting properties with undo for objects...
[wxWidgets.git] / include / wx / valtext.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/valtext.h
3 // Purpose: wxTextValidator class
4 // Author: Julian Smart
5 // Modified by: Francesco Montorsi
6 // Created: 29/01/98
7 // Copyright: (c) 1998 Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_VALTEXT_H_
12 #define _WX_VALTEXT_H_
13
14 #include "wx/defs.h"
15
16 #if wxUSE_VALIDATORS && (wxUSE_TEXTCTRL || wxUSE_COMBOBOX)
17
18 class WXDLLIMPEXP_FWD_CORE wxTextEntry;
19
20 #include "wx/validate.h"
21
22 enum wxTextValidatorStyle
23 {
24 wxFILTER_NONE = 0x0,
25 wxFILTER_EMPTY = 0x1,
26 wxFILTER_ASCII = 0x2,
27 wxFILTER_ALPHA = 0x4,
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
35 };
36
37 class WXDLLIMPEXP_CORE wxTextValidator: public wxValidator
38 {
39 public:
40 wxTextValidator(long style = wxFILTER_NONE, wxString *val = NULL);
41 wxTextValidator(const wxTextValidator& val);
42
43 virtual ~wxTextValidator(){}
44
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);
51
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);
55
56 // Called to transfer data to the window
57 virtual bool TransferToWindow();
58
59 // Called to transfer data from the window
60 virtual bool TransferFromWindow();
61
62 // Filter keystrokes
63 void OnChar(wxKeyEvent& event);
64
65 // ACCESSORS
66 inline long GetStyle() const { return m_validatorStyle; }
67 void SetStyle(long style);
68
69 wxTextEntry *GetTextEntry();
70
71 void SetCharIncludes(const wxString& chars);
72 void SetIncludes(const wxArrayString& includes) { m_includes = includes; }
73 inline wxArrayString& GetIncludes() { return m_includes; }
74
75 void SetCharExcludes(const wxString& chars);
76 void SetExcludes(const wxArrayString& excludes) { m_excludes = excludes; }
77 inline wxArrayString& GetExcludes() { return m_excludes; }
78
79 bool HasFlag(wxTextValidatorStyle style) const
80 { return (m_validatorStyle & style) != 0; }
81
82 protected:
83
84 // returns true if all characters of the given string are present in m_includes
85 bool ContainsOnlyIncludedCharacters(const wxString& val) const;
86
87 // returns true if at least one character of the given string is present in m_excludes
88 bool ContainsExcludedCharacters(const wxString& val) const;
89
90 // returns the error message if the contents of 'val' are invalid
91 virtual wxString IsValid(const wxString& val) const;
92
93 protected:
94 long m_validatorStyle;
95 wxString* m_stringValue;
96 wxArrayString m_includes;
97 wxArrayString m_excludes;
98
99 private:
100 wxDECLARE_NO_ASSIGN_CLASS(wxTextValidator);
101 DECLARE_DYNAMIC_CLASS(wxTextValidator)
102 DECLARE_EVENT_TABLE()
103 };
104
105 #endif
106 // wxUSE_VALIDATORS && (wxUSE_TEXTCTRL || wxUSE_COMBOBOX)
107
108 #endif // _WX_VALTEXT_H_