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 wxValidator(const wxValidator
& other
)
42 , m_validatorWindow(other
.m_validatorWindow
)
45 virtual ~wxValidator();
47 // Make a clone of this validator (or return NULL) - currently necessary
48 // if you're passing a reference to a validator.
49 // Another possibility is to always pass a pointer to a new validator
50 // (so the calling code can use a copy constructor of the relevant class).
51 virtual wxObject
*Clone() const
53 bool Copy(const wxValidator
& val
)
54 { m_validatorWindow
= val
.m_validatorWindow
; return true; }
56 // Called when the value in the window must be validated.
57 // This function can pop up an error message.
58 virtual bool Validate(wxWindow
*WXUNUSED(parent
)) { return false; }
60 // Called to transfer data to the window
61 virtual bool TransferToWindow() { return false; }
63 // Called to transfer data from the window
64 virtual bool TransferFromWindow() { return false; }
67 wxWindow
*GetWindow() const { return (wxWindow
*)m_validatorWindow
; }
68 void SetWindow(wxWindowBase
*win
) { m_validatorWindow
= win
; }
70 // validators beep by default if invalid key is pressed, this function
71 // allows to change this
72 static void SuppressBellOnError(bool suppress
= true)
73 { ms_isSilent
= suppress
; }
75 // test if beep is currently disabled
76 static bool IsSilent() { return ms_isSilent
; }
78 // this function is deprecated because it handled its parameter
79 // unnaturally: it disabled the bell when it was true, not false as could
80 // be expected; use SuppressBellOnError() instead
81 #if WXWIN_COMPATIBILITY_2_8
82 static wxDEPRECATED_INLINE(
83 void SetBellOnError(bool doIt
= true),
89 wxWindowBase
*m_validatorWindow
;
92 static bool ms_isSilent
;
94 DECLARE_DYNAMIC_CLASS(wxValidator
)
95 wxDECLARE_NO_ASSIGN_CLASS(wxValidator
);
98 extern WXDLLIMPEXP_DATA_CORE(const wxValidator
) wxDefaultValidator
;
100 #define wxVALIDATOR_PARAM(val) val
102 #else // !wxUSE_VALIDATORS
103 // wxWidgets is compiled without support for wxValidator, but we still
104 // want to be able to pass wxDefaultValidator to the functions which take
105 // a wxValidator parameter to avoid using "#if wxUSE_VALIDATORS"
107 class WXDLLIMPEXP_FWD_CORE wxValidator
;
108 #define wxDefaultValidator (*reinterpret_cast<wxValidator*>(NULL))
110 // this macro allows to avoid warnings about unused parameters when
111 // wxUSE_VALIDATORS == 0
112 #define wxVALIDATOR_PARAM(val)
113 #endif // wxUSE_VALIDATORS/!wxUSE_VALIDATORS
115 #endif // _WX_VALIDATE_H_