]> git.saurik.com Git - wxWidgets.git/blob - interface/wx/validate.h
avoid GTK+ prefixes for our tree entry code, it is not part of GTK+, should have...
[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 @library{wxcore}
30 @category{validator}
31
32 @stdobjects
33 ::wxDefaultValidator
34
35 @see @ref overview_validator, wxTextValidator, wxGenericValidator,
36 wxIntegerValidator, wxFloatingPointValidator
37 */
38 class wxValidator : public wxEvtHandler
39 {
40 public:
41 /**
42 Constructor.
43 */
44 wxValidator();
45
46 /**
47 Destructor.
48 */
49 virtual ~wxValidator();
50
51 /**
52 All validator classes must implement the Clone() function, which
53 returns an identical copy of itself.
54
55 This is because validators are passed to control constructors as
56 references which must be copied. Unlike objects such as pens and
57 brushes, it does not make sense to have a reference counting scheme to
58 do this cloning because all validators should have separate data.
59
60 @return This base function returns @NULL.
61 */
62 virtual wxObject* Clone() const;
63
64 /**
65 Returns the window associated with the validator.
66 */
67 wxWindow* GetWindow() const;
68
69 /**
70 This functions switches on or turns off the error sound produced by the
71 validators if an invalid key is pressed.
72
73 @since 2.9.1
74
75 @param suppress
76 If @true, error sound is not played when a validator detects an
77 error. If @false, error sound is enabled.
78 */
79 static void SuppressBellOnError(bool suppress = true);
80
81 /**
82 Returns if the error sound is currently disabled.
83 */
84 static bool IsSilent();
85
86 /**
87 Associates a window with the validator.
88
89 This function is automatically called by wxWidgets when creating a wxWindow-derived
90 class instance which takes a wxValidator reference.
91
92 E.g.
93 @code
94 new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0,
95 wxTextValidator(wxFILTER_ALPHA, &g_data.m_string));
96 @endcode
97 will automatically link the wxTextValidator instance with the wxTextCtrl
98 instance.
99 */
100 void SetWindow(wxWindow* window);
101
102 /**
103 This overridable function is called when the value in the window must
104 be transferred to the validator.
105
106 @return @false if there is a problem.
107 */
108 virtual bool TransferFromWindow();
109
110 /**
111 This overridable function is called when the value associated with the
112 validator must be transferred to the window.
113
114 @return @false if there is a problem.
115 */
116 virtual bool TransferToWindow();
117
118 /**
119 This overridable function is called when the value in the associated
120 window must be validated.
121
122 @param parent
123 The parent of the window associated with the validator.
124
125 @return @false if the value in the window is not valid; you may pop up
126 an error dialog.
127 */
128 virtual bool Validate(wxWindow* parent);
129 };
130
131 /**
132 An empty, "null" wxValidator instance.
133 */
134 const wxValidator wxDefaultValidator;
135