]> git.saurik.com Git - wxWidgets.git/blame - include/wx/valtext.h
Revert r62598 which removed "unnecessary wxOSX_USE_COCOA checks."
[wxWidgets.git] / include / wx / valtext.h
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: valtext.h
3// Purpose: wxTextValidator class
4// Author: Julian Smart
10b0f489 5// Modified by: Francesco Montorsi
c801d85f
KB
6// Created: 29/01/98
7// RCS-ID: $Id$
8// Copyright: (c) 1998 Julian Smart
cab1a605 9// Licence: wxWindows licence
c801d85f
KB
10/////////////////////////////////////////////////////////////////////////////
11
92646f5a
PC
12#ifndef _WX_VALTEXT_H_
13#define _WX_VALTEXT_H_
c801d85f 14
ce4169a4
RR
15#include "wx/defs.h"
16
472eec8a 17#if wxUSE_VALIDATORS && (wxUSE_TEXTCTRL || wxUSE_COMBOBOX)
88ac883a 18
92646f5a
PC
19class WXDLLIMPEXP_FWD_CORE wxTextEntry;
20
c801d85f
KB
21#include "wx/validate.h"
22
40ae9600
FM
23enum wxTextValidatorStyle
24{
58fa61db
FM
25 wxFILTER_NONE = 0x0,
26 wxFILTER_EMPTY = 0x1,
27 wxFILTER_ASCII = 0x2,
28 wxFILTER_ALPHA = 0x4,
29 wxFILTER_ALPHANUMERIC = 0x8,
30 wxFILTER_DIGITS = 0x10,
31 wxFILTER_NUMERIC = 0x20,
32 wxFILTER_INCLUDE_LIST = 0x40,
33 wxFILTER_INCLUDE_CHAR_LIST = 0x80,
34 wxFILTER_EXCLUDE_LIST = 0x100,
35 wxFILTER_EXCLUDE_CHAR_LIST = 0x200
40ae9600 36};
c801d85f 37
53a2db12 38class WXDLLIMPEXP_CORE wxTextValidator: public wxValidator
c801d85f 39{
c801d85f 40public:
58fa61db 41 wxTextValidator(long style = wxFILTER_NONE, wxString *val = NULL);
33c5b54b 42 wxTextValidator(const wxTextValidator& val);
c801d85f 43
d3c7fc99 44 virtual ~wxTextValidator(){}
c801d85f 45
33c5b54b
RL
46 // Make a clone of this validator (or return NULL) - currently necessary
47 // if you're passing a reference to a validator.
48 // Another possibility is to always pass a pointer to a new validator
49 // (so the calling code can use a copy constructor of the relevant class).
50 virtual wxObject *Clone() const { return new wxTextValidator(*this); }
51 bool Copy(const wxTextValidator& val);
c801d85f 52
33c5b54b
RL
53 // Called when the value in the window must be validated.
54 // This function can pop up an error message.
55 virtual bool Validate(wxWindow *parent);
c801d85f 56
33c5b54b
RL
57 // Called to transfer data to the window
58 virtual bool TransferToWindow();
c801d85f 59
4deaa8db 60 // Called to transfer data from the window
33c5b54b 61 virtual bool TransferFromWindow();
c801d85f 62
10b0f489
FM
63 // Filter keystrokes
64 void OnChar(wxKeyEvent& event);
65
33c5b54b 66 // ACCESSORS
58fa61db
FM
67 inline long GetStyle() const { return m_validatorStyle; }
68 void SetStyle(long style);
c801d85f 69
472eec8a 70 wxTextEntry *GetTextEntry();
f94a790d 71
fcd209b6 72 void SetCharIncludes(const wxString& chars);
f94a790d
RN
73 void SetIncludes(const wxArrayString& includes) { m_includes = includes; }
74 inline wxArrayString& GetIncludes() { return m_includes; }
75
fcd209b6 76 void SetCharExcludes(const wxString& chars);
f94a790d
RN
77 void SetExcludes(const wxArrayString& excludes) { m_excludes = excludes; }
78 inline wxArrayString& GetExcludes() { return m_excludes; }
79
58fa61db 80 bool HasFlag(wxTextValidatorStyle style) const
c77c3023 81 { return (m_validatorStyle & style) != 0; }
58fa61db 82
10b0f489
FM
83protected:
84
85 // returns true if all characters of the given string are present in m_includes
1406dc01 86 bool ContainsOnlyIncludedCharacters(const wxString& val) const;
33c5b54b 87
c78d8a70 88 // returns true if at least one character of the given string is present in m_excludes
1406dc01 89 bool ContainsExcludedCharacters(const wxString& val) const;
10b0f489 90
58fa61db
FM
91 // returns the error message if the contents of 'val' are invalid
92 virtual wxString IsValid(const wxString& val) const;
c801d85f 93
c801d85f 94protected:
58fa61db
FM
95 long m_validatorStyle;
96 wxString* m_stringValue;
40ae9600
FM
97 wxArrayString m_includes;
98 wxArrayString m_excludes;
33c5b54b 99
22f3361e 100private:
c0c133e1 101 wxDECLARE_NO_ASSIGN_CLASS(wxTextValidator);
755369be
FM
102 DECLARE_DYNAMIC_CLASS(wxTextValidator)
103 DECLARE_EVENT_TABLE()
c801d85f
KB
104};
105
106#endif
472eec8a 107 // wxUSE_VALIDATORS && (wxUSE_TEXTCTRL || wxUSE_COMBOBOX)
ce4169a4 108
92646f5a 109#endif // _WX_VALTEXT_H_