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
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// 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-08-09 12:38:21 +00:00
|
|
|
#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
|
1999-02-25 14:47:18 +00:00
|
|
|
#pragma interface "validate.h"
|
1998-05-20 14:01:55 +00:00
|
|
|
#endif
|
|
|
|
|
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"
|
|
|
|
|
1999-05-24 21:12:37 +00:00
|
|
|
class WXDLLEXPORT wxWindow;
|
1999-05-09 22:17:03 +00:00
|
|
|
class WXDLLEXPORT 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
|
|
|
|
1999-02-25 14:47:18 +00:00
|
|
|
class WXDLLEXPORT wxValidator : public wxEvtHandler
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
|
|
|
public:
|
1999-02-25 14:47:18 +00:00
|
|
|
wxValidator();
|
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
|
1999-02-25 14:47:18 +00:00
|
|
|
{ return (wxValidator *)NULL; }
|
|
|
|
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.
|
2004-09-24 14:32:35 +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
|
2004-09-24 14:32:35 +00:00
|
|
|
virtual bool TransferFromWindow() { return false; };
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-02-25 14:47:18 +00:00
|
|
|
// accessors
|
1999-05-24 21:12:37 +00:00
|
|
|
wxWindow *GetWindow() const { return (wxWindow *)m_validatorWindow; }
|
1999-05-09 22:17:03 +00:00
|
|
|
void SetWindow(wxWindowBase *win) { m_validatorWindow = win; }
|
1999-02-25 14:47:18 +00: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 14:32:35 +00:00
|
|
|
static void SetBellOnError(bool doIt = true) { ms_isSilent = doIt; }
|
1998-05-20 14:01:55 +00:00
|
|
|
|
|
|
|
protected:
|
1999-05-09 22:17:03 +00:00
|
|
|
wxWindowBase *m_validatorWindow;
|
1999-02-25 14:47:18 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
static bool ms_isSilent;
|
|
|
|
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxValidator)
|
2002-05-08 13:30:26 +00:00
|
|
|
DECLARE_NO_COPY_CLASS(wxValidator)
|
1998-05-20 14:01:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
WXDLLEXPORT_DATA(extern const wxValidator) wxDefaultValidator;
|
|
|
|
|
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
|
|
|
|
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 15:32:12 +00:00
|
|
|
|