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