-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwxBupDestPathValidatorh.h
168 lines (134 loc) · 6.27 KB
/
wxBupDestPathValidatorh.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*-----------------------------------------------------------------
* Name: wxBupDestPathValidatorh.h
* Purpose:
* Author: A. Wiegert
*
* Copyright:
* Licence: wxWidgets licence
*-------------------------------------------------------------- */
#ifndef _WX_BUP_DEST_VALIDATOR_H
#define _WX_BUP_DEST_VALIDATOR_H
#include "wxBupFrameh.h"
// ------------------------------------------------------------------
/**
* Create my own text validator patterned after the original wxTextValidator.
*
* After reviewing the comments by Vadim in http://trac.wxwidgets.org/ticket/14579
* I have decided to implemt my own validator.
* My latest tests show that I could get at the OnChar routine in the edit dialog
* but then I would have to spend some effort to get the current string from the
* derived text validator I had started with.
* Making my own validator seems to be the better and simpler way.
* The idea is to use OnChar() to recalculate the max data length and give the user
* more specific and timely feedback as he entrs text.
* The max length feedback is too late and I am sure would cause frustration.
*/
// ------------------------------------------------------------------
/**
Styles used by MyCellTextValidator.
Note that when you specify more styles in wxTextValidator the validation checks
are performed in the order in which the styles of this enumeration are defined.
*/
enum MyCellTextValidatorStyle
{
/// No filtering takes place.
wxFILTER_NONE_CELL,
#if 0
/// Empty strings are filtered out.
/// If this style is not specified then empty strings are accepted
/// only if they pass the other checks (if you use more than one wxTextValidatorStyle).
wxFILTER_EMPTY,
/// Non-ASCII characters are filtered out. See wxString::IsAscii.
wxFILTER_ASCII,
/// Non-alpha characters are filtered out.
/// Uses the wxWidgets wrapper for the standard CRT function @c isalpha
/// (which is locale-dependent) on all characters of the string.
wxFILTER_ALPHA,
/// Non-alphanumeric characters are filtered out.
/// Uses the wxWidgets wrapper for the standard CRT function @c isalnum
/// (which is locale-dependent) on all characters of the string.
wxFILTER_ALPHANUMERIC,
/// Non-numeric characters are filtered out.
/// Uses the wxWidgets wrapper for the standard CRT function @c isdigit
/// (which is locale-dependent) on all characters of the string.
wxFILTER_DIGITS,
/// Non-numeric characters are filtered out.
/// Works like @c wxFILTER_DIGITS but allows also decimal points,
/// minus/plus signs and the 'e' or 'E' character to input exponents.
/// Note that this is not the same behaviour of wxString::IsNumber().
wxFILTER_NUMERIC,
/// Use an include list. The validator checks if the user input is on
/// the list, complaining if not. See wxTextValidator::SetIncludes().
wxFILTER_INCLUDE_LIST,
/// Use an include list. The validator checks if each input character is
/// in the list (one character per list element), complaining if not.
/// See wxTextValidator::SetCharIncludes().
wxFILTER_INCLUDE_CHAR_LIST,
/// Use an exclude list. The validator checks if the user input is on
/// the list, complaining if it is. See wxTextValidator::SetExcludes().
wxFILTER_EXCLUDE_LIST,
/// Use an exclude list. The validator checks if each input character is
/// in the list (one character per list element), complaining if it is.
/// See wxTextValidator::SetCharExcludes().
wxFILTER_EXCLUDE_CHAR_LIST
#endif
};
// the class definition MUST come from
class MyCellTextValidator : public wxValidator
{
public:
MyCellTextValidator(long style = wxFILTER_NONE, wxString *val = NULL);
MyCellTextValidator(const MyCellTextValidator& val);
virtual ~MyCellTextValidator(){}
// 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).
virtual wxObject *Clone() const { return new MyCellTextValidator(*this); }
bool Copy(const MyCellTextValidator& val);
// Called when the value in the window must be validated.
// This function can pop up an error message.
virtual bool Validate(wxWindow *parent);
// Called to transfer data to the window
virtual bool TransferToWindow();
// Called to transfer data from the window
virtual bool TransferFromWindow();
// Filter keystrokes
void OnChar(wxKeyEvent& event);
// ACCESSORS
inline long GetStyle() const { return m_validatorStyle; }
void SetStyle(long style);
void SetMaxLen( long lLen );
void SetCurLen( long lLen );
wxTextEntry *GetTextEntry();
void SetCharIncludes(const wxString& chars);
void SetIncludes(const wxArrayString& includes) { m_includes = includes; }
inline wxArrayString& GetIncludes() { return m_includes; }
void SetCharExcludes(const wxString& chars);
void SetExcludes(const wxArrayString& excludes) { m_excludes = excludes; }
inline wxArrayString& GetExcludes() { return m_excludes; }
bool HasFlag(wxTextValidatorStyle style) const
{ return (m_validatorStyle & style) != 0; }
protected:
// returns true if all characters of the given string are present in m_includes
bool ContainsOnlyIncludedCharacters(const wxString& val) const;
// returns true if at least one character of the given string is present in m_excludes
bool ContainsExcludedCharacters(const wxString& val) const;
// returns the error message if the contents of 'val' are invalid
virtual wxString IsValid(const wxString& val) const;
protected:
long m_validatorStyle;
wxString* m_stringValue;
wxArrayString m_includes;
wxArrayString m_excludes;
long m_lMaxLen;
long m_lCurLen;
// intended to help with the <Enter> problem, but does NOT - yet
int m_iLastKeyCode;
private:
wxDECLARE_NO_ASSIGN_CLASS(MyCellTextValidator);
DECLARE_DYNAMIC_CLASS(MyCellTextValidator)
DECLARE_EVENT_TABLE()
};
#endif // _WX_BUP_DEST_VALIDATOR_H
// ------------------------------- eof ---------------------------