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"
|
|
|
|
|
1999-05-24 17:12:37 -04:00
|
|
|
class WXDLLEXPORT wxWindow;
|
1999-05-09 18:17:03 -04:00
|
|
|
class WXDLLEXPORT 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
|
|
|
|
1999-02-25 09:47:18 -05:00
|
|
|
class WXDLLEXPORT 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
|
1999-02-25 09:47:18 -05:00
|
|
|
{ return (wxValidator *)NULL; }
|
|
|
|
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
|
|
|
|
|
|
|
// validators beep by default if invalid key is pressed, these functions
|
|
|
|
// allow to change it
|
|
|
|
static bool IsSilent() { return ms_isSilent; }
|
2004-09-24 10:32:35 -04:00
|
|
|
static void SetBellOnError(bool doIt = true) { ms_isSilent = doIt; }
|
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)
|
2002-05-08 09:30:26 -04:00
|
|
|
DECLARE_NO_COPY_CLASS(wxValidator)
|
1998-05-20 10:01:55 -04:00
|
|
|
};
|
|
|
|
|
2005-01-21 13:48:22 -05:00
|
|
|
extern WXDLLEXPORT_DATA(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
|
|
|
|
class WXDLLEXPORT wxValidator;
|
|
|
|
#define wxDefaultValidator (*((wxValidator *)NULL))
|
|
|
|
|
|
|
|
// 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
|
|
|
|