]> git.saurik.com Git - wxWidgets.git/blame - include/wx/validate.h
Mention using wxString::c_str() with vararg functions in the change log.
[wxWidgets.git] / include / wx / validate.h
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
ac8d0c11 2// Name: wx/validate.h
c801d85f
KB
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
65571936 9// Licence: wxWindows licence
c801d85f
KB
10/////////////////////////////////////////////////////////////////////////////
11
ac8d0c11
VZ
12#ifndef _WX_VALIDATE_H_
13#define _WX_VALIDATE_H_
c801d85f 14
ac8d0c11
VZ
15#include "wx/defs.h"
16
17#if wxUSE_VALIDATORS
88ac883a 18
674ac8b9
VZ
19#include "wx/event.h"
20
b5dbe15d
VS
21class WXDLLIMPEXP_FWD_CORE wxWindow;
22class WXDLLIMPEXP_FWD_CORE wxWindowBase;
c801d85f
KB
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.
a994f81b 34*/
c801d85f 35
53a2db12 36class WXDLLIMPEXP_CORE wxValidator : public wxEvtHandler
c801d85f 37{
c801d85f 38public:
a994f81b 39 wxValidator();
46286d9a 40 wxValidator(const wxValidator& other)
3e118784
PC
41 : wxEvtHandler()
42 , m_validatorWindow(other.m_validatorWindow)
46286d9a
VZ
43 {
44 }
f03fc89f 45 virtual ~wxValidator();
c801d85f 46
a994f81b
VZ
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).
ca298c88 51 virtual wxObject *Clone() const
d3b9f782 52 { return NULL; }
a994f81b 53 bool Copy(const wxValidator& val)
cab1a605 54 { m_validatorWindow = val.m_validatorWindow; return true; }
c801d85f 55
a994f81b
VZ
56 // Called when the value in the window must be validated.
57 // This function can pop up an error message.
47b378bd 58 virtual bool Validate(wxWindow *WXUNUSED(parent)) { return false; }
c801d85f 59
a994f81b 60 // Called to transfer data to the window
cab1a605 61 virtual bool TransferToWindow() { return false; }
c801d85f 62
a994f81b 63 // Called to transfer data from the window
47b378bd 64 virtual bool TransferFromWindow() { return false; }
c801d85f 65
a994f81b 66 // accessors
764a3a49 67 wxWindow *GetWindow() const { return (wxWindow *)m_validatorWindow; }
f03fc89f 68 void SetWindow(wxWindowBase *win) { m_validatorWindow = win; }
a994f81b 69
c27181d1
VZ
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; }
74
75 // test if beep is currently disabled
a994f81b 76 static bool IsSilent() { return ms_isSilent; }
c27181d1
VZ
77
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
d65e9d57
VZ
82 static wxDEPRECATED_INLINE(
83 void SetBellOnError(bool doIt = true),
c27181d1
VZ
84 ms_isSilent = doIt;
85 )
86#endif
c801d85f
KB
87
88protected:
f03fc89f 89 wxWindowBase *m_validatorWindow;
a994f81b
VZ
90
91private:
92 static bool ms_isSilent;
93
94 DECLARE_DYNAMIC_CLASS(wxValidator)
46286d9a 95 wxDECLARE_NO_ASSIGN_CLASS(wxValidator);
c801d85f
KB
96};
97
53a2db12 98extern WXDLLIMPEXP_DATA_CORE(const wxValidator) wxDefaultValidator;
c801d85f 99
ac8d0c11
VZ
100#define wxVALIDATOR_PARAM(val) val
101
102#else // !wxUSE_VALIDATORS
77ffb593 103 // wxWidgets is compiled without support for wxValidator, but we still
ac8d0c11
VZ
104 // want to be able to pass wxDefaultValidator to the functions which take
105 // a wxValidator parameter to avoid using "#if wxUSE_VALIDATORS"
106 // everywhere
b5dbe15d 107 class WXDLLIMPEXP_FWD_CORE wxValidator;
b4bde7a7 108 #define wxDefaultValidator (*reinterpret_cast<wxValidator*>(NULL))
ac8d0c11
VZ
109
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
114
115#endif // _WX_VALIDATE_H_
88ac883a 116