2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: validate.h
|
2008-03-10 11:24:38 -04:00
|
|
|
// Purpose: interface of wxValidator
|
2008-03-08 08:52:38 -05:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxValidator
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-04-22 02:01:48 -04:00
|
|
|
wxValidator is the base class for a family of validator classes that
|
|
|
|
mediate between a class of control, and application data.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
A validator has three major roles:
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-04-22 02:01:48 -04:00
|
|
|
-# To transfer data from a C++ variable or own storage to and from a
|
|
|
|
control.
|
|
|
|
-# To validate data in a control, and show an appropriate error message.
|
|
|
|
-# To filter events (such as keystrokes), thereby changing the behaviour
|
|
|
|
of the associated control.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
Validators can be plugged into controls dynamically.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-04-22 02:01:48 -04:00
|
|
|
To specify a default, "null" validator, use ::wxDefaultValidator.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-27 16:54:47 -04:00
|
|
|
For more information, please see @ref overview_validator.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-27 16:54:47 -04:00
|
|
|
@beginWxPythonOnly
|
2008-04-22 02:01:48 -04:00
|
|
|
If you wish to create a validator class in wxPython you should derive the
|
|
|
|
class from @c wxPyValidator in order to get Python-aware capabilities for
|
|
|
|
the various virtual methods.
|
2008-03-27 16:54:47 -04:00
|
|
|
@endWxPythonOnly
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@library{wxcore}
|
|
|
|
@category{validator}
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-27 16:54:47 -04:00
|
|
|
@stdobjects
|
|
|
|
::wxDefaultValidator
|
|
|
|
|
|
|
|
@see @ref overview_validator, wxTextValidator, wxGenericValidator
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
class wxValidator : public wxEvtHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Constructor.
|
|
|
|
*/
|
|
|
|
wxValidator();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor.
|
|
|
|
*/
|
2008-09-27 07:21:10 -04:00
|
|
|
virtual ~wxValidator();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-04-22 02:01:48 -04:00
|
|
|
All validator classes must implement the Clone() function, which
|
|
|
|
returns an identical copy of itself.
|
2008-03-27 16:54:47 -04:00
|
|
|
|
2008-04-22 02:01:48 -04:00
|
|
|
This is because validators are passed to control constructors as
|
|
|
|
references which must be copied. Unlike objects such as pens and
|
|
|
|
brushes, it does not make sense to have a reference counting scheme to
|
|
|
|
do this cloning because all validators should have separate data.
|
2008-03-27 16:54:47 -04:00
|
|
|
|
2008-05-10 21:38:53 -04:00
|
|
|
@return This base function returns @NULL.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
virtual wxObject* Clone() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the window associated with the validator.
|
|
|
|
*/
|
2008-03-09 12:24:26 -04:00
|
|
|
wxWindow* GetWindow() const;
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
This functions switches on or turns off the error sound produced by the
|
|
|
|
validators if an invalid key is pressed.
|
2009-10-15 10:44:22 -04:00
|
|
|
|
|
|
|
@since 2.9.1
|
|
|
|
|
|
|
|
@param suppress
|
|
|
|
If @true, error sound is not played when a validator detects an
|
|
|
|
error. If @false, error sound is enabled.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2009-10-15 10:44:22 -04:00
|
|
|
static void SuppressBellOnError(bool suppress = true);
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
Associates a window with the validator.
|
2009-01-31 16:28:24 -05:00
|
|
|
|
|
|
|
This function is automatically called by wxWidgets when creating a wxWindow-derived
|
|
|
|
class instance which takes a wxValidator reference.
|
|
|
|
|
|
|
|
E.g.
|
|
|
|
@code
|
|
|
|
new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0,
|
|
|
|
wxTextValidator(wxFILTER_ALPHA, &g_data.m_string));
|
|
|
|
@endcode
|
|
|
|
will automatically link the wxTextValidator instance with the wxTextCtrl
|
|
|
|
instance.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
void SetWindow(wxWindow* window);
|
|
|
|
|
|
|
|
/**
|
2008-04-22 02:01:48 -04:00
|
|
|
This overridable function is called when the value in the window must
|
|
|
|
be transferred to the validator.
|
2008-03-27 16:54:47 -04:00
|
|
|
|
|
|
|
@return @false if there is a problem.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-27 16:54:47 -04:00
|
|
|
virtual bool TransferFromWindow();
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
This overridable function is called when the value associated with the
|
2008-03-27 16:54:47 -04:00
|
|
|
validator must be transferred to the window.
|
|
|
|
|
|
|
|
@return @false if there is a problem.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
virtual bool TransferToWindow();
|
|
|
|
|
|
|
|
/**
|
2008-04-22 02:01:48 -04:00
|
|
|
This overridable function is called when the value in the associated
|
|
|
|
window must be validated.
|
2008-03-27 16:54:47 -04:00
|
|
|
|
2009-01-31 16:28:24 -05:00
|
|
|
@param parent
|
|
|
|
The parent of the window associated with the validator.
|
|
|
|
|
2008-04-22 02:01:48 -04:00
|
|
|
@return @false if the value in the window is not valid; you may pop up
|
|
|
|
an error dialog.
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
|
|
|
virtual bool Validate(wxWindow* parent);
|
|
|
|
};
|
2008-03-10 11:24:38 -04:00
|
|
|
|
2008-03-27 16:54:47 -04:00
|
|
|
/**
|
2008-04-22 02:01:48 -04:00
|
|
|
An empty, "null" wxValidator instance.
|
2008-03-27 16:54:47 -04:00
|
|
|
*/
|
|
|
|
wxValidator wxDefaultValidator;
|
2008-04-22 02:01:48 -04:00
|
|
|
|