1998-05-20 10:01:55 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2003-09-15 15:54:51 -04:00
|
|
|
// Name: wx/validate.h
|
1998-05-20 10:01:55 -04:00
|
|
|
// Purpose: wxValidator class
|
|
|
|
// Author: Julian Smart
|
|
|
|
// Modified by:
|
|
|
|
// Created: 29/01/98
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 1998 Julian Smart
|
2004-05-23 16:53:33 -04:00
|
|
|
// Licence: wxWindows licence
|
1998-05-20 10:01:55 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2003-09-15 15:54:51 -04:00
|
|
|
#ifndef _WX_VALIDATE_H_
|
|
|
|
#define _WX_VALIDATE_H_
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2003-09-15 15:54:51 -04:00
|
|
|
#include "wx/defs.h"
|
|
|
|
|
|
|
|
#if wxUSE_VALIDATORS
|
1999-06-01 11:32:12 -04:00
|
|
|
|
2000-01-06 11:47:48 -05:00
|
|
|
#include "wx/event.h"
|
|
|
|
|
2007-07-09 06:09:52 -04:00
|
|
|
class WXDLLIMPEXP_FWD_CORE wxWindow;
|
|
|
|
class WXDLLIMPEXP_FWD_CORE wxWindowBase;
|
1998-05-20 10:01:55 -04: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 09:47:18 -05:00
|
|
|
*/
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2008-03-26 11:06:00 -04:00
|
|
|
class WXDLLIMPEXP_CORE wxValidator : public wxEvtHandler
|
1998-05-20 10:01:55 -04:00
|
|
|
{
|
|
|
|
public:
|
1999-02-25 09:47:18 -05:00
|
|
|
wxValidator();
|
1999-05-09 18:17:03 -04:00
|
|
|
virtual ~wxValidator();
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1999-02-25 09:47:18 -05: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-29 22:39:50 -04:00
|
|
|
virtual wxObject *Clone() const
|
2009-01-19 08:55:27 -05:00
|
|
|
{ return NULL; }
|
1999-02-25 09:47:18 -05:00
|
|
|
bool Copy(const wxValidator& val)
|
2004-09-24 10:32:35 -04:00
|
|
|
{ m_validatorWindow = val.m_validatorWindow; return true; }
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1999-02-25 09:47:18 -05:00
|
|
|
// Called when the value in the window must be validated.
|
|
|
|
// This function can pop up an error message.
|
2007-04-14 05:58:37 -04:00
|
|
|
virtual bool Validate(wxWindow *WXUNUSED(parent)) { return false; }
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1999-02-25 09:47:18 -05:00
|
|
|
// Called to transfer data to the window
|
2004-09-24 10:32:35 -04:00
|
|
|
virtual bool TransferToWindow() { return false; }
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1999-02-25 09:47:18 -05:00
|
|
|
// Called to transfer data from the window
|
2007-04-14 05:58:37 -04:00
|
|
|
virtual bool TransferFromWindow() { return false; }
|
1998-05-20 10:01:55 -04:00
|
|
|
|
1999-02-25 09:47:18 -05:00
|
|
|
// accessors
|
1999-05-24 17:12:37 -04:00
|
|
|
wxWindow *GetWindow() const { return (wxWindow *)m_validatorWindow; }
|
1999-05-09 18:17:03 -04:00
|
|
|
void SetWindow(wxWindowBase *win) { m_validatorWindow = win; }
|
1999-02-25 09:47:18 -05:00
|
|
|
|
2009-10-15 10:44:22 -04: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 09:47:18 -05:00
|
|
|
static bool IsSilent() { return ms_isSilent; }
|
2009-10-15 10:44:22 -04: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 07:32:59 -05:00
|
|
|
static wxDEPRECATED_INLINE(
|
|
|
|
void SetBellOnError(bool doIt = true),
|
2009-10-15 10:44:22 -04:00
|
|
|
ms_isSilent = doIt;
|
|
|
|
)
|
|
|
|
#endif
|
1998-05-20 10:01:55 -04:00
|
|
|
|
|
|
|
protected:
|
1999-05-09 18:17:03 -04:00
|
|
|
wxWindowBase *m_validatorWindow;
|
1999-02-25 09:47:18 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
static bool ms_isSilent;
|
|
|
|
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxValidator)
|
2009-02-08 06:45:59 -05:00
|
|
|
wxDECLARE_NO_COPY_CLASS(wxValidator);
|
1998-05-20 10:01:55 -04:00
|
|
|
};
|
|
|
|
|
2008-03-26 11:06:00 -04:00
|
|
|
extern WXDLLIMPEXP_DATA_CORE(const wxValidator) wxDefaultValidator;
|
1998-05-20 10:01:55 -04:00
|
|
|
|
2003-09-15 15:54:51 -04:00
|
|
|
#define wxVALIDATOR_PARAM(val) val
|
|
|
|
|
|
|
|
#else // !wxUSE_VALIDATORS
|
2004-05-23 10:56:36 -04:00
|
|
|
// wxWidgets is compiled without support for wxValidator, but we still
|
2003-09-15 15:54:51 -04: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 06:09:52 -04:00
|
|
|
class WXDLLIMPEXP_FWD_CORE wxValidator;
|
2009-09-23 12:32:32 -04:00
|
|
|
#define wxDefaultValidator (*reinterpret_cast<wxValidator*>(NULL))
|
2003-09-15 15:54:51 -04:00
|
|
|
|
|
|
|
// this macro allows to avoid warnings about unused parameters when
|
|
|
|
// wxUSE_VALIDATORS == 0
|
|
|
|
#define wxVALIDATOR_PARAM(val)
|
|
|
|
#endif // wxUSE_VALIDATORS/!wxUSE_VALIDATORS
|
|
|
|
|
|
|
|
#endif // _WX_VALIDATE_H_
|
1999-06-01 11:32:12 -04:00
|
|
|
|