1998-05-20 14:01:55 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2011-03-20 00:14:35 +00:00
|
|
|
// Name: wx/valtext.h
|
1998-05-20 14:01:55 +00:00
|
|
|
// Purpose: wxTextValidator class
|
|
|
|
// Author: Julian Smart
|
2009-01-30 17:22:05 +00:00
|
|
|
// Modified by: Francesco Montorsi
|
1998-05-20 14:01:55 +00:00
|
|
|
// Created: 29/01/98
|
|
|
|
// Copyright: (c) 1998 Julian Smart
|
2004-09-24 14:32:35 +00:00
|
|
|
// Licence: wxWindows licence
|
1998-05-20 14:01:55 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2007-11-02 05:04:26 +00:00
|
|
|
#ifndef _WX_VALTEXT_H_
|
|
|
|
#define _WX_VALTEXT_H_
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-06-15 20:21:59 +00:00
|
|
|
#include "wx/defs.h"
|
|
|
|
|
2007-11-01 20:52:40 +00:00
|
|
|
#if wxUSE_VALIDATORS && (wxUSE_TEXTCTRL || wxUSE_COMBOBOX)
|
1999-06-01 15:32:12 +00:00
|
|
|
|
2007-11-02 05:04:26 +00:00
|
|
|
class WXDLLIMPEXP_FWD_CORE wxTextEntry;
|
|
|
|
|
1998-05-20 14:01:55 +00:00
|
|
|
#include "wx/validate.h"
|
|
|
|
|
2009-01-09 12:43:20 +00:00
|
|
|
enum wxTextValidatorStyle
|
|
|
|
{
|
2009-02-03 21:21:47 +00:00
|
|
|
wxFILTER_NONE = 0x0,
|
|
|
|
wxFILTER_EMPTY = 0x1,
|
|
|
|
wxFILTER_ASCII = 0x2,
|
|
|
|
wxFILTER_ALPHA = 0x4,
|
|
|
|
wxFILTER_ALPHANUMERIC = 0x8,
|
|
|
|
wxFILTER_DIGITS = 0x10,
|
|
|
|
wxFILTER_NUMERIC = 0x20,
|
|
|
|
wxFILTER_INCLUDE_LIST = 0x40,
|
|
|
|
wxFILTER_INCLUDE_CHAR_LIST = 0x80,
|
|
|
|
wxFILTER_EXCLUDE_LIST = 0x100,
|
2018-12-31 23:55:14 +00:00
|
|
|
wxFILTER_EXCLUDE_CHAR_LIST = 0x200,
|
|
|
|
wxFILTER_XDIGITS = 0x400,
|
|
|
|
wxFILTER_SPACE = 0x800,
|
|
|
|
|
|
|
|
// filter char class (for internal use only)
|
|
|
|
wxFILTER_CC = wxFILTER_SPACE|wxFILTER_ASCII|wxFILTER_NUMERIC|
|
|
|
|
wxFILTER_ALPHANUMERIC|wxFILTER_ALPHA|
|
|
|
|
wxFILTER_DIGITS|wxFILTER_XDIGITS
|
2009-01-09 12:43:20 +00:00
|
|
|
};
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2018-12-31 23:55:14 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// wxTextValidator
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2008-03-26 15:06:00 +00:00
|
|
|
class WXDLLIMPEXP_CORE wxTextValidator: public wxValidator
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
|
|
|
public:
|
2009-02-03 21:21:47 +00:00
|
|
|
wxTextValidator(long style = wxFILTER_NONE, wxString *val = NULL);
|
2001-12-24 12:12:30 +00:00
|
|
|
wxTextValidator(const wxTextValidator& val);
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2006-09-05 20:47:48 +00:00
|
|
|
virtual ~wxTextValidator(){}
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2001-12-24 12:12:30 +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).
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual wxObject *Clone() const wxOVERRIDE { return new wxTextValidator(*this); }
|
2001-12-24 12:12:30 +00:00
|
|
|
bool Copy(const wxTextValidator& val);
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2001-12-24 12:12:30 +00:00
|
|
|
// Called when the value in the window must be validated.
|
|
|
|
// This function can pop up an error message.
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual bool Validate(wxWindow *parent) wxOVERRIDE;
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2001-12-24 12:12:30 +00:00
|
|
|
// Called to transfer data to the window
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual bool TransferToWindow() wxOVERRIDE;
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2006-01-18 17:23:05 +00:00
|
|
|
// Called to transfer data from the window
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual bool TransferFromWindow() wxOVERRIDE;
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2009-01-30 17:22:05 +00:00
|
|
|
// Filter keystrokes
|
|
|
|
void OnChar(wxKeyEvent& event);
|
|
|
|
|
2001-12-24 12:12:30 +00:00
|
|
|
// ACCESSORS
|
2009-02-03 21:21:47 +00:00
|
|
|
inline long GetStyle() const { return m_validatorStyle; }
|
|
|
|
void SetStyle(long style);
|
1998-05-20 14:01:55 +00:00
|
|
|
|
2007-11-01 20:52:40 +00:00
|
|
|
wxTextEntry *GetTextEntry();
|
2005-02-07 23:46:42 +00:00
|
|
|
|
2018-12-31 23:55:14 +00:00
|
|
|
// strings & chars inclusions:
|
|
|
|
// ---------------------------
|
|
|
|
|
2009-01-31 22:41:51 +00:00
|
|
|
void SetCharIncludes(const wxString& chars);
|
2018-12-31 23:55:14 +00:00
|
|
|
void AddCharIncludes(const wxString& chars);
|
|
|
|
|
|
|
|
void SetIncludes(const wxArrayString& includes);
|
|
|
|
void AddInclude(const wxString& include);
|
|
|
|
|
|
|
|
const wxArrayString& GetIncludes() const { return m_includes; }
|
|
|
|
wxString GetCharIncludes() const { return m_charIncludes; }
|
|
|
|
|
|
|
|
// strings & chars exclusions:
|
|
|
|
// ---------------------------
|
2005-02-07 23:46:42 +00:00
|
|
|
|
2009-01-31 22:41:51 +00:00
|
|
|
void SetCharExcludes(const wxString& chars);
|
2018-12-31 23:55:14 +00:00
|
|
|
void AddCharExcludes(const wxString& chars);
|
|
|
|
|
|
|
|
void SetExcludes(const wxArrayString& excludes);
|
|
|
|
void AddExclude(const wxString& exclude);
|
|
|
|
|
|
|
|
const wxArrayString& GetExcludes() const { return m_excludes; }
|
|
|
|
wxString GetCharExcludes() const { return m_charExcludes; }
|
2005-02-07 23:46:42 +00:00
|
|
|
|
2009-02-03 21:21:47 +00:00
|
|
|
bool HasFlag(wxTextValidatorStyle style) const
|
2009-02-04 14:40:47 +00:00
|
|
|
{ return (m_validatorStyle & style) != 0; }
|
2009-02-03 21:21:47 +00:00
|
|
|
|
2018-12-31 23:55:14 +00:00
|
|
|
// implementation only
|
|
|
|
// --------------------
|
|
|
|
|
|
|
|
// returns the error message if the contents of 'str' are invalid
|
|
|
|
virtual wxString IsValid(const wxString& str) const;
|
|
|
|
|
2009-01-30 17:22:05 +00:00
|
|
|
protected:
|
|
|
|
|
2018-12-31 23:55:14 +00:00
|
|
|
bool IsCharIncluded(const wxUniChar& c) const
|
|
|
|
{
|
|
|
|
return m_charIncludes.find(c) != wxString::npos;
|
|
|
|
}
|
2001-12-24 12:12:30 +00:00
|
|
|
|
2018-12-31 23:55:14 +00:00
|
|
|
bool IsCharExcluded(const wxUniChar& c) const
|
|
|
|
{
|
|
|
|
return m_charExcludes.find(c) != wxString::npos;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsIncluded(const wxString& str) const
|
|
|
|
{
|
|
|
|
if ( HasFlag(wxFILTER_INCLUDE_LIST) )
|
|
|
|
return m_includes.Index(str) != wxNOT_FOUND;
|
|
|
|
|
|
|
|
// m_includes should be ignored (i.e. return true)
|
|
|
|
// if the style is not set.
|
|
|
|
return true;
|
|
|
|
}
|
2009-01-30 17:22:05 +00:00
|
|
|
|
2018-12-31 23:55:14 +00:00
|
|
|
bool IsExcluded(const wxString& str) const
|
|
|
|
{
|
|
|
|
return m_excludes.Index(str) != wxNOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
// returns false if the character is invalid
|
|
|
|
bool IsValidChar(const wxUniChar& c) const;
|
|
|
|
|
|
|
|
// These two functions (undocumented now) are kept for compatibility reasons.
|
|
|
|
bool ContainsOnlyIncludedCharacters(const wxString& val) const;
|
|
|
|
bool ContainsExcludedCharacters(const wxString& val) const;
|
1998-05-20 14:01:55 +00:00
|
|
|
|
|
|
|
protected:
|
2009-02-03 21:21:47 +00:00
|
|
|
long m_validatorStyle;
|
|
|
|
wxString* m_stringValue;
|
2018-12-31 23:55:14 +00:00
|
|
|
wxString m_charIncludes;
|
|
|
|
wxString m_charExcludes;
|
2009-01-09 12:43:20 +00:00
|
|
|
wxArrayString m_includes;
|
|
|
|
wxArrayString m_excludes;
|
2001-12-24 12:12:30 +00:00
|
|
|
|
2003-01-02 23:38:11 +00:00
|
|
|
private:
|
2009-02-08 11:45:59 +00:00
|
|
|
wxDECLARE_NO_ASSIGN_CLASS(wxTextValidator);
|
2015-04-23 11:49:01 +00:00
|
|
|
wxDECLARE_DYNAMIC_CLASS(wxTextValidator);
|
|
|
|
wxDECLARE_EVENT_TABLE();
|
1998-05-20 14:01:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
2007-11-01 20:52:40 +00:00
|
|
|
// wxUSE_VALIDATORS && (wxUSE_TEXTCTRL || wxUSE_COMBOBOX)
|
1999-06-15 20:21:59 +00:00
|
|
|
|
2007-11-02 05:04:26 +00:00
|
|
|
#endif // _WX_VALTEXT_H_
|