]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: 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 | |
a994f81b | 9 | // Licence: wxWindows license |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
34138703 JS |
12 | #ifndef _WX_VALIDATEH__ |
13 | #define _WX_VALIDATEH__ | |
c801d85f KB |
14 | |
15 | #ifdef __GNUG__ | |
a994f81b | 16 | #pragma interface "validate.h" |
c801d85f KB |
17 | #endif |
18 | ||
88ac883a | 19 | #if defined(wxUSE_VALIDATORS) && !wxUSE_VALIDATORS |
674ac8b9 VZ |
20 | // wxWindows is compiled without support for wxValidator, but we still |
21 | // want to be able to pass wxDefaultValidator to the functions which take | |
22 | // a wxValidator parameter to avoid using "#if wxUSE_VALIDATORS" | |
23 | // everywhere | |
88ac883a VZ |
24 | class WXDLLEXPORT wxValidator; |
25 | #define wxDefaultValidator (*((wxValidator *)NULL)) | |
26 | #else // wxUSE_VALIDATORS | |
27 | ||
674ac8b9 VZ |
28 | #include "wx/event.h" |
29 | ||
764a3a49 | 30 | class WXDLLEXPORT wxWindow; |
f03fc89f | 31 | class WXDLLEXPORT wxWindowBase; |
c801d85f KB |
32 | |
33 | /* | |
34 | A validator has up to three purposes: | |
35 | ||
36 | 1) To validate the data in the window that's associated | |
37 | with the validator. | |
38 | 2) To transfer data to and from the window. | |
39 | 3) To filter input, using its role as a wxEvtHandler | |
40 | to intercept e.g. OnChar. | |
41 | ||
42 | Note that wxValidator and derived classes use reference counting. | |
a994f81b | 43 | */ |
c801d85f | 44 | |
a994f81b | 45 | class WXDLLEXPORT wxValidator : public wxEvtHandler |
c801d85f | 46 | { |
c801d85f | 47 | public: |
a994f81b | 48 | wxValidator(); |
f03fc89f | 49 | virtual ~wxValidator(); |
c801d85f | 50 | |
a994f81b VZ |
51 | // Make a clone of this validator (or return NULL) - currently necessary |
52 | // if you're passing a reference to a validator. | |
53 | // Another possibility is to always pass a pointer to a new validator | |
54 | // (so the calling code can use a copy constructor of the relevant class). | |
ca298c88 | 55 | virtual wxObject *Clone() const |
a994f81b VZ |
56 | { return (wxValidator *)NULL; } |
57 | bool Copy(const wxValidator& val) | |
58 | { m_validatorWindow = val.m_validatorWindow; return TRUE; } | |
c801d85f | 59 | |
a994f81b VZ |
60 | // Called when the value in the window must be validated. |
61 | // This function can pop up an error message. | |
764a3a49 | 62 | virtual bool Validate(wxWindow *WXUNUSED(parent)) { return FALSE; }; |
c801d85f | 63 | |
a994f81b VZ |
64 | // Called to transfer data to the window |
65 | virtual bool TransferToWindow() { return FALSE; } | |
c801d85f | 66 | |
a994f81b VZ |
67 | // Called to transfer data from the window |
68 | virtual bool TransferFromWindow() { return FALSE; }; | |
c801d85f | 69 | |
a994f81b | 70 | // accessors |
764a3a49 | 71 | wxWindow *GetWindow() const { return (wxWindow *)m_validatorWindow; } |
f03fc89f | 72 | void SetWindow(wxWindowBase *win) { m_validatorWindow = win; } |
a994f81b VZ |
73 | |
74 | // validators beep by default if invalid key is pressed, these functions | |
75 | // allow to change it | |
76 | static bool IsSilent() { return ms_isSilent; } | |
77 | static void SetBellOnError(bool doIt = TRUE) { ms_isSilent = doIt; } | |
c801d85f KB |
78 | |
79 | protected: | |
f03fc89f | 80 | wxWindowBase *m_validatorWindow; |
a994f81b VZ |
81 | |
82 | private: | |
83 | static bool ms_isSilent; | |
84 | ||
85 | DECLARE_DYNAMIC_CLASS(wxValidator) | |
c801d85f KB |
86 | }; |
87 | ||
88 | WXDLLEXPORT_DATA(extern const wxValidator) wxDefaultValidator; | |
89 | ||
88ac883a VZ |
90 | #endif // wxUSE_VALIDATORS |
91 | ||
c801d85f | 92 | #endif |
34138703 | 93 | // _WX_VALIDATEH__ |