]> git.saurik.com Git - wxWidgets.git/blob - include/wx/validate.h
Switched to DECLARE_NO_COPY_CLASS
[wxWidgets.git] / include / wx / validate.h
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
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_VALIDATEH__
13 #define _WX_VALIDATEH__
14
15 #ifdef __GNUG__
16 #pragma interface "validate.h"
17 #endif
18
19 #if defined(wxUSE_VALIDATORS) && !wxUSE_VALIDATORS
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
24 class WXDLLEXPORT wxValidator;
25 #define wxDefaultValidator (*((wxValidator *)NULL))
26 #else // wxUSE_VALIDATORS
27
28 #include "wx/event.h"
29
30 class WXDLLEXPORT wxWindow;
31 class WXDLLEXPORT wxWindowBase;
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.
43 */
44
45 class WXDLLEXPORT wxValidator : public wxEvtHandler
46 {
47 public:
48 wxValidator();
49 virtual ~wxValidator();
50
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).
55 virtual wxObject *Clone() const
56 { return (wxValidator *)NULL; }
57 bool Copy(const wxValidator& val)
58 { m_validatorWindow = val.m_validatorWindow; return TRUE; }
59
60 // Called when the value in the window must be validated.
61 // This function can pop up an error message.
62 virtual bool Validate(wxWindow *WXUNUSED(parent)) { return FALSE; };
63
64 // Called to transfer data to the window
65 virtual bool TransferToWindow() { return FALSE; }
66
67 // Called to transfer data from the window
68 virtual bool TransferFromWindow() { return FALSE; };
69
70 // accessors
71 wxWindow *GetWindow() const { return (wxWindow *)m_validatorWindow; }
72 void SetWindow(wxWindowBase *win) { m_validatorWindow = win; }
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; }
78
79 protected:
80 wxWindowBase *m_validatorWindow;
81
82 private:
83 static bool ms_isSilent;
84
85 DECLARE_DYNAMIC_CLASS(wxValidator)
86 };
87
88 WXDLLEXPORT_DATA(extern const wxValidator) wxDefaultValidator;
89
90 #endif // wxUSE_VALIDATORS
91
92 #endif
93 // _WX_VALIDATEH__