]> git.saurik.com Git - wxWidgets.git/blob - interface/wx/validate.h
Fix int field of wxCommandEvents generated by menu items in wxMSW.
[wxWidgets.git] / interface / wx / validate.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: validate.h
3 // Purpose: interface of wxValidator
4 // Author: wxWidgets team
5 // RCS-ID: $Id$
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
8
9 /**
10 @class wxValidator
11
12 wxValidator is the base class for a family of validator classes that
13 mediate between a class of control, and application data.
14
15 A validator has three major roles:
16
17 -# To transfer data from a C++ variable or own storage to and from a
18 control.
19 -# To validate data in a control, and show an appropriate error message.
20 -# To filter events (such as keystrokes), thereby changing the behaviour
21 of the associated control.
22
23 Validators can be plugged into controls dynamically.
24
25 To specify a default, "null" validator, use ::wxDefaultValidator.
26
27 For more information, please see @ref overview_validator.
28
29 @beginWxPythonOnly
30 If you wish to create a validator class in wxPython you should derive the
31 class from @c wxPyValidator in order to get Python-aware capabilities for
32 the various virtual methods.
33 @endWxPythonOnly
34
35 @library{wxcore}
36 @category{validator}
37
38 @stdobjects
39 ::wxDefaultValidator
40
41 @see @ref overview_validator, wxTextValidator, wxGenericValidator,
42 wxIntegerValidator, wxFloatingPointValidator
43 */
44 class wxValidator : public wxEvtHandler
45 {
46 public:
47 /**
48 Constructor.
49 */
50 wxValidator();
51
52 /**
53 Destructor.
54 */
55 virtual ~wxValidator();
56
57 /**
58 All validator classes must implement the Clone() function, which
59 returns an identical copy of itself.
60
61 This is because validators are passed to control constructors as
62 references which must be copied. Unlike objects such as pens and
63 brushes, it does not make sense to have a reference counting scheme to
64 do this cloning because all validators should have separate data.
65
66 @return This base function returns @NULL.
67 */
68 virtual wxObject* Clone() const;
69
70 /**
71 Returns the window associated with the validator.
72 */
73 wxWindow* GetWindow() const;
74
75 /**
76 This functions switches on or turns off the error sound produced by the
77 validators if an invalid key is pressed.
78
79 @since 2.9.1
80
81 @param suppress
82 If @true, error sound is not played when a validator detects an
83 error. If @false, error sound is enabled.
84 */
85 static void SuppressBellOnError(bool suppress = true);
86
87 /**
88 Associates a window with the validator.
89
90 This function is automatically called by wxWidgets when creating a wxWindow-derived
91 class instance which takes a wxValidator reference.
92
93 E.g.
94 @code
95 new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0,
96 wxTextValidator(wxFILTER_ALPHA, &g_data.m_string));
97 @endcode
98 will automatically link the wxTextValidator instance with the wxTextCtrl
99 instance.
100 */
101 void SetWindow(wxWindow* window);
102
103 /**
104 This overridable function is called when the value in the window must
105 be transferred to the validator.
106
107 @return @false if there is a problem.
108 */
109 virtual bool TransferFromWindow();
110
111 /**
112 This overridable function is called when the value associated with the
113 validator must be transferred to the window.
114
115 @return @false if there is a problem.
116 */
117 virtual bool TransferToWindow();
118
119 /**
120 This overridable function is called when the value in the associated
121 window must be validated.
122
123 @param parent
124 The parent of the window associated with the validator.
125
126 @return @false if the value in the window is not valid; you may pop up
127 an error dialog.
128 */
129 virtual bool Validate(wxWindow* parent);
130 };
131
132 /**
133 An empty, "null" wxValidator instance.
134 */
135 const wxValidator wxDefaultValidator;
136