1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxValidator
4 // Author: wxWidgets team
5 // Licence: wxWindows licence
6 /////////////////////////////////////////////////////////////////////////////
11 wxValidator is the base class for a family of validator classes that
12 mediate between a class of control, and application data.
14 A validator has three major roles:
16 -# To transfer data from a C++ variable or own storage to and from a
18 -# To validate data in a control, and show an appropriate error message.
19 -# To filter events (such as keystrokes), thereby changing the behaviour
20 of the associated control.
22 Validators can be plugged into controls dynamically.
24 To specify a default, "null" validator, use ::wxDefaultValidator.
26 For more information, please see @ref overview_validator.
34 @see @ref overview_validator, wxTextValidator, wxGenericValidator,
35 wxIntegerValidator, wxFloatingPointValidator
37 class wxValidator
: public wxEvtHandler
48 virtual ~wxValidator();
51 All validator classes must implement the Clone() function, which
52 returns an identical copy of itself.
54 This is because validators are passed to control constructors as
55 references which must be copied. Unlike objects such as pens and
56 brushes, it does not make sense to have a reference counting scheme to
57 do this cloning because all validators should have separate data.
59 @return This base function returns @NULL.
61 virtual wxObject
* Clone() const;
64 Returns the window associated with the validator.
66 wxWindow
* GetWindow() const;
69 This functions switches on or turns off the error sound produced by the
70 validators if an invalid key is pressed.
75 If @true, error sound is not played when a validator detects an
76 error. If @false, error sound is enabled.
78 static void SuppressBellOnError(bool suppress
= true);
81 Returns if the error sound is currently disabled.
83 static bool IsSilent();
86 Associates a window with the validator.
88 This function is automatically called by wxWidgets when creating a wxWindow-derived
89 class instance which takes a wxValidator reference.
93 new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0,
94 wxTextValidator(wxFILTER_ALPHA, &g_data.m_string));
96 will automatically link the wxTextValidator instance with the wxTextCtrl
99 void SetWindow(wxWindow
* window
);
102 This overridable function is called when the value in the window must
103 be transferred to the validator.
105 @return @false if there is a problem.
107 virtual bool TransferFromWindow();
110 This overridable function is called when the value associated with the
111 validator must be transferred to the window.
113 @return @false if there is a problem.
115 virtual bool TransferToWindow();
118 This overridable function is called when the value in the associated
119 window must be validated.
122 The parent of the window associated with the validator.
124 @return @false if the value in the window is not valid; you may pop up
127 virtual bool Validate(wxWindow
* parent
);
131 An empty, "null" wxValidator instance.
133 const wxValidator wxDefaultValidator
;