]>
Commit | Line | Data |
---|---|---|
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 WXDLLEXPORT wxWindow; | |
22 | class WXDLLEXPORT 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 WXDLLEXPORT wxValidator : public wxEvtHandler | |
37 | { | |
38 | public: | |
39 | wxValidator(); | |
40 | virtual ~wxValidator(); | |
41 | ||
42 | // Make a clone of this validator (or return NULL) - currently necessary | |
43 | // if you're passing a reference to a validator. | |
44 | // Another possibility is to always pass a pointer to a new validator | |
45 | // (so the calling code can use a copy constructor of the relevant class). | |
46 | virtual wxObject *Clone() const | |
47 | { return (wxValidator *)NULL; } | |
48 | bool Copy(const wxValidator& val) | |
49 | { m_validatorWindow = val.m_validatorWindow; return true; } | |
50 | ||
51 | // Called when the value in the window must be validated. | |
52 | // This function can pop up an error message. | |
53 | virtual bool Validate(wxWindow *WXUNUSED(parent)) { return false; } | |
54 | ||
55 | // Called to transfer data to the window | |
56 | virtual bool TransferToWindow() { return false; } | |
57 | ||
58 | // Called to transfer data from the window | |
59 | virtual bool TransferFromWindow() { return false; } | |
60 | ||
61 | // accessors | |
62 | wxWindow *GetWindow() const { return (wxWindow *)m_validatorWindow; } | |
63 | void SetWindow(wxWindowBase *win) { m_validatorWindow = win; } | |
64 | ||
65 | // validators beep by default if invalid key is pressed, these functions | |
66 | // allow to change it | |
67 | static bool IsSilent() { return ms_isSilent; } | |
68 | static void SetBellOnError(bool doIt = true) { ms_isSilent = doIt; } | |
69 | ||
70 | protected: | |
71 | wxWindowBase *m_validatorWindow; | |
72 | ||
73 | private: | |
74 | static bool ms_isSilent; | |
75 | ||
76 | DECLARE_DYNAMIC_CLASS(wxValidator) | |
77 | DECLARE_NO_COPY_CLASS(wxValidator) | |
78 | }; | |
79 | ||
80 | extern WXDLLEXPORT_DATA(const wxValidator) wxDefaultValidator; | |
81 | ||
82 | #define wxVALIDATOR_PARAM(val) val | |
83 | ||
84 | #else // !wxUSE_VALIDATORS | |
85 | // wxWidgets is compiled without support for wxValidator, but we still | |
86 | // want to be able to pass wxDefaultValidator to the functions which take | |
87 | // a wxValidator parameter to avoid using "#if wxUSE_VALIDATORS" | |
88 | // everywhere | |
89 | class WXDLLEXPORT wxValidator; | |
90 | #define wxDefaultValidator (*((wxValidator *)NULL)) | |
91 | ||
92 | // this macro allows to avoid warnings about unused parameters when | |
93 | // wxUSE_VALIDATORS == 0 | |
94 | #define wxVALIDATOR_PARAM(val) | |
95 | #endif // wxUSE_VALIDATORS/!wxUSE_VALIDATORS | |
96 | ||
97 | #endif // _WX_VALIDATE_H_ | |
98 |