]> git.saurik.com Git - wxWidgets.git/blob - include/wx/validate.h
e79a3becb533af6b7c62b45b78f1f1c6d2a347a5
[wxWidgets.git] / include / wx / validate.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/validate.h
3 // Purpose: wxValidator class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 29/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998 Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_VALIDATE_H_
13 #define _WX_VALIDATE_H_
14
15 #include "wx/defs.h"
16
17 #if wxUSE_VALIDATORS
18
19 #include "wx/event.h"
20
21 class WXDLLIMPEXP_FWD_CORE wxWindow;
22 class WXDLLIMPEXP_FWD_CORE wxWindowBase;
23
24 /*
25 A validator has up to three purposes:
26
27 1) To validate the data in the window that's associated
28 with the validator.
29 2) To transfer data to and from the window.
30 3) To filter input, using its role as a wxEvtHandler
31 to intercept e.g. OnChar.
32
33 Note that wxValidator and derived classes use reference counting.
34 */
35
36 class WXDLLIMPEXP_CORE wxValidator : public wxEvtHandler
37 {
38 public:
39 wxValidator();
40 wxValidator(const wxValidator& other)
41 : wxEvtHandler()
42 , m_validatorWindow(other.m_validatorWindow)
43 {
44 }
45 virtual ~wxValidator();
46
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
52 { return NULL; }
53 bool Copy(const wxValidator& val)
54 { m_validatorWindow = val.m_validatorWindow; return true; }
55
56 // Called when the value in the window must be validated.
57 // This function can pop up an error message.
58 virtual bool Validate(wxWindow *WXUNUSED(parent)) { return false; }
59
60 // Called to transfer data to the window
61 virtual bool TransferToWindow() { return false; }
62
63 // Called to transfer data from the window
64 virtual bool TransferFromWindow() { return false; }
65
66 // accessors
67 wxWindow *GetWindow() const { return (wxWindow *)m_validatorWindow; }
68 void SetWindow(wxWindowBase *win) { m_validatorWindow = win; }
69
70 // validators beep by default if invalid key is pressed, this function
71 // allows to change this
72 static void SuppressBellOnError(bool suppress = true)
73 { ms_isSilent = suppress; }
74
75 // test if beep is currently disabled
76 static bool IsSilent() { return ms_isSilent; }
77
78 // this function is deprecated because it handled its parameter
79 // unnaturally: it disabled the bell when it was true, not false as could
80 // be expected; use SuppressBellOnError() instead
81 #if WXWIN_COMPATIBILITY_2_8
82 static wxDEPRECATED_INLINE(
83 void SetBellOnError(bool doIt = true),
84 ms_isSilent = doIt;
85 )
86 #endif
87
88 protected:
89 wxWindowBase *m_validatorWindow;
90
91 private:
92 static bool ms_isSilent;
93
94 DECLARE_DYNAMIC_CLASS(wxValidator)
95 wxDECLARE_NO_ASSIGN_CLASS(wxValidator);
96 };
97
98 extern WXDLLIMPEXP_DATA_CORE(const wxValidator) wxDefaultValidator;
99
100 #define wxVALIDATOR_PARAM(val) val
101
102 #else // !wxUSE_VALIDATORS
103 // wxWidgets is compiled without support for wxValidator, but we still
104 // want to be able to pass wxDefaultValidator to the functions which take
105 // a wxValidator parameter to avoid using "#if wxUSE_VALIDATORS"
106 // everywhere
107 class WXDLLIMPEXP_FWD_CORE wxValidator;
108 #define wxDefaultValidator (*reinterpret_cast<wxValidator*>(NULL))
109
110 // this macro allows to avoid warnings about unused parameters when
111 // wxUSE_VALIDATORS == 0
112 #define wxVALIDATOR_PARAM(val)
113 #endif // wxUSE_VALIDATORS/!wxUSE_VALIDATORS
114
115 #endif // _WX_VALIDATE_H_
116