1998-05-20 14:01:55 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2003-09-15 19:54:51 +00:00
|
|
|
// Name: wx/validate.h
|
1998-05-20 14:01:55 +00:00
|
|
|
// Purpose: wxValidator class
|
|
|
|
// Author: Julian Smart
|
|
|
|
// Modified by:
|
|
|
|
// Created: 29/01/98
|
|
|
|
// Copyright: (c) 1998 Julian Smart
|
2004-05-23 20:53:33 +00:00
|
|
|
// Licence: wxWindows licence
|
1998-05-20 14:01:55 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2003-09-15 19:54:51 +00:00
|
|
|
#ifndef _WX_VALIDATE_H_
|
|
|
|
#define _WX_VALIDATE_H_
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2003-09-15 19:54:51 +00:00
|
|
|
#include "wx/defs.h"
|
|
|
|
|
|
|
|
#if wxUSE_VALIDATORS
|
1999-06-01 15:32:12 +00:00
|
|
|
|
2000-01-06 16:47:48 +00:00
|
|
|
#include "wx/event.h"
|
|
|
|
|
2007-07-09 10:09:52 +00:00
|
|
|
class WXDLLIMPEXP_FWD_CORE wxWindow;
|
|
|
|
class WXDLLIMPEXP_FWD_CORE wxWindowBase;
|
1998-05-20 14:01:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
A validator has up to three purposes:
|
|
|
|
|
|
|
|
1) To validate the data in the window that's associated
|
|
|
|
with the validator.
|
|
|
|
2) To transfer data to and from the window.
|
|
|
|
3) To filter input, using its role as a wxEvtHandler
|
|
|
|
to intercept e.g. OnChar.
|
|
|
|
|
|
|
|
Note that wxValidator and derived classes use reference counting.
|
1999-02-25 14:47:18 +00:00
|
|
|
*/
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2008-03-26 15:06:00 +00:00
|
|
|
class WXDLLIMPEXP_CORE wxValidator : public wxEvtHandler
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
|
|
|
public:
|
1999-02-25 14:47:18 +00:00
|
|
|
wxValidator();
|
2013-01-20 02:09:52 +00:00
|
|
|
wxValidator(const wxValidator& other)
|
2013-01-20 03:24:21 +00:00
|
|
|
: wxEvtHandler()
|
|
|
|
, m_validatorWindow(other.m_validatorWindow)
|
2013-01-20 02:09:52 +00:00
|
|
|
{
|
|
|
|
}
|
1999-05-09 22:17:03 +00:00
|
|
|
virtual ~wxValidator();
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-02-25 14:47:18 +00:00
|
|
|
// Make a clone of this validator (or return NULL) - currently necessary
|
|
|
|
// if you're passing a reference to a validator.
|
|
|
|
// Another possibility is to always pass a pointer to a new validator
|
|
|
|
// (so the calling code can use a copy constructor of the relevant class).
|
1999-04-30 02:39:50 +00:00
|
|
|
virtual wxObject *Clone() const
|
2009-01-19 13:55:27 +00:00
|
|
|
{ return NULL; }
|
1999-02-25 14:47:18 +00:00
|
|
|
bool Copy(const wxValidator& val)
|
2004-09-24 14:32:35 +00:00
|
|
|
{ m_validatorWindow = val.m_validatorWindow; return true; }
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-02-25 14:47:18 +00:00
|
|
|
// Called when the value in the window must be validated.
|
|
|
|
// This function can pop up an error message.
|
2007-04-14 09:58:37 +00:00
|
|
|
virtual bool Validate(wxWindow *WXUNUSED(parent)) { return false; }
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-02-25 14:47:18 +00:00
|
|
|
// Called to transfer data to the window
|
2004-09-24 14:32:35 +00:00
|
|
|
virtual bool TransferToWindow() { return false; }
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-02-25 14:47:18 +00:00
|
|
|
// Called to transfer data from the window
|
2007-04-14 09:58:37 +00:00
|
|
|
virtual bool TransferFromWindow() { return false; }
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2018-01-07 00:25:10 +00:00
|
|
|
// Called when the validator is associated with a window, may be useful to
|
|
|
|
// override if it needs to somehow initialize the window.
|
|
|
|
virtual void SetWindow(wxWindow *win) { m_validatorWindow = win; }
|
|
|
|
|
1999-02-25 14:47:18 +00:00
|
|
|
// accessors
|
2018-01-07 00:25:10 +00:00
|
|
|
wxWindow *GetWindow() const { return m_validatorWindow; }
|
1999-02-25 14:47:18 +00:00
|
|
|
|
2009-10-15 14:44:22 +00:00
|
|
|
// validators beep by default if invalid key is pressed, this function
|
|
|
|
// allows to change this
|
|
|
|
static void SuppressBellOnError(bool suppress = true)
|
|
|
|
{ ms_isSilent = suppress; }
|
|
|
|
|
|
|
|
// test if beep is currently disabled
|
1999-02-25 14:47:18 +00:00
|
|
|
static bool IsSilent() { return ms_isSilent; }
|
2009-10-15 14:44:22 +00:00
|
|
|
|
|
|
|
// this function is deprecated because it handled its parameter
|
|
|
|
// unnaturally: it disabled the bell when it was true, not false as could
|
|
|
|
// be expected; use SuppressBellOnError() instead
|
|
|
|
#if WXWIN_COMPATIBILITY_2_8
|
2011-02-19 12:32:59 +00:00
|
|
|
static wxDEPRECATED_INLINE(
|
|
|
|
void SetBellOnError(bool doIt = true),
|
2009-10-15 14:44:22 +00:00
|
|
|
ms_isSilent = doIt;
|
|
|
|
)
|
|
|
|
#endif
|
1998-05-20 14:01:55 +00:00
|
|
|
|
|
|
|
protected:
|
2018-01-07 00:25:10 +00:00
|
|
|
wxWindow *m_validatorWindow;
|
1999-02-25 14:47:18 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
static bool ms_isSilent;
|
|
|
|
|
2015-04-23 11:49:01 +00:00
|
|
|
wxDECLARE_DYNAMIC_CLASS(wxValidator);
|
2013-01-20 02:09:52 +00:00
|
|
|
wxDECLARE_NO_ASSIGN_CLASS(wxValidator);
|
1998-05-20 14:01:55 +00:00
|
|
|
};
|
|
|
|
|
2003-09-15 19:54:51 +00:00
|
|
|
#define wxVALIDATOR_PARAM(val) val
|
|
|
|
|
|
|
|
#else // !wxUSE_VALIDATORS
|
2004-05-23 14:56:36 +00:00
|
|
|
// wxWidgets is compiled without support for wxValidator, but we still
|
2003-09-15 19:54:51 +00:00
|
|
|
// want to be able to pass wxDefaultValidator to the functions which take
|
|
|
|
// a wxValidator parameter to avoid using "#if wxUSE_VALIDATORS"
|
|
|
|
// everywhere
|
2007-07-09 10:09:52 +00:00
|
|
|
class WXDLLIMPEXP_FWD_CORE wxValidator;
|
2003-09-15 19:54:51 +00:00
|
|
|
|
|
|
|
// this macro allows to avoid warnings about unused parameters when
|
|
|
|
// wxUSE_VALIDATORS == 0
|
|
|
|
#define wxVALIDATOR_PARAM(val)
|
|
|
|
#endif // wxUSE_VALIDATORS/!wxUSE_VALIDATORS
|
|
|
|
|
2019-04-04 17:56:14 +00:00
|
|
|
extern WXDLLIMPEXP_DATA_CORE(const wxValidator) wxDefaultValidator;
|
|
|
|
|
2003-09-15 19:54:51 +00:00
|
|
|
#endif // _WX_VALIDATE_H_
|
1999-06-01 15:32:12 +00:00
|
|
|
|