1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxValidator class
4 // Author: Julian Smart
8 // Copyright: (c) 1998 Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_VALIDATE_H_
13 #define _WX_VALIDATE_H_
21 class WXDLLIMPEXP_FWD_CORE wxWindow
;
22 class WXDLLIMPEXP_FWD_CORE wxWindowBase
;
25 A validator has up to three purposes:
27 1) To validate the data in the window that's associated
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.
33 Note that wxValidator and derived classes use reference counting.
36 class WXDLLIMPEXP_CORE wxValidator
: public wxEvtHandler
40 virtual ~wxValidator();
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
48 bool Copy(const wxValidator
& val
)
49 { m_validatorWindow
= val
.m_validatorWindow
; return true; }
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; }
55 // Called to transfer data to the window
56 virtual bool TransferToWindow() { return false; }
58 // Called to transfer data from the window
59 virtual bool TransferFromWindow() { return false; }
62 wxWindow
*GetWindow() const { return (wxWindow
*)m_validatorWindow
; }
63 void SetWindow(wxWindowBase
*win
) { m_validatorWindow
= win
; }
65 // validators beep by default if invalid key is pressed, this function
66 // allows to change this
67 static void SuppressBellOnError(bool suppress
= true)
68 { ms_isSilent
= suppress
; }
70 // test if beep is currently disabled
71 static bool IsSilent() { return ms_isSilent
; }
73 // this function is deprecated because it handled its parameter
74 // unnaturally: it disabled the bell when it was true, not false as could
75 // be expected; use SuppressBellOnError() instead
76 #if WXWIN_COMPATIBILITY_2_8
78 static void SetBellOnError(bool doIt
= true),
84 wxWindowBase
*m_validatorWindow
;
87 static bool ms_isSilent
;
89 DECLARE_DYNAMIC_CLASS(wxValidator
)
90 wxDECLARE_NO_COPY_CLASS(wxValidator
);
93 extern WXDLLIMPEXP_DATA_CORE(const wxValidator
) wxDefaultValidator
;
95 #define wxVALIDATOR_PARAM(val) val
97 #else // !wxUSE_VALIDATORS
98 // wxWidgets is compiled without support for wxValidator, but we still
99 // want to be able to pass wxDefaultValidator to the functions which take
100 // a wxValidator parameter to avoid using "#if wxUSE_VALIDATORS"
102 class WXDLLIMPEXP_FWD_CORE wxValidator
;
103 #define wxDefaultValidator (*reinterpret_cast<wxValidator*>(NULL))
105 // this macro allows to avoid warnings about unused parameters when
106 // wxUSE_VALIDATORS == 0
107 #define wxVALIDATOR_PARAM(val)
108 #endif // wxUSE_VALIDATORS/!wxUSE_VALIDATORS
110 #endif // _WX_VALIDATE_H_