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