OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
validate.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1993, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Implementation of TValidator, user input validator abstract base class
7//----------------------------------------------------------------------------
8#include <owl/pch.h>
9
10#include <owl/validate.h>
11#include <owl/validate.rh>
12#include <owl/module.h>
13#include <stdlib.h>
14#include <ctype.h>
15
16namespace owl {
17
19
20
21//
22/// Constructs an abstract validator object and sets Options fields to 0.
23//
28
29//
30/// Destroys an abstract validator object.
31//
35
36//
37/// Error is an abstract function called by Valid when it detects that the user has
38/// entered invalid information. By default, TValidator::Error does nothing, but
39/// derived classes can override Error to provide feedback to the user.
40//
41void
43{
44}
45
46//
47/// Checks current input against validator. May adjust input if suppressFill
48/// isn't set & validator has the voFill option set.
49//
50/// If an edit control has an associated validator object, it calls IsValidInput
51/// after processing each keyboard event, thus giving validators such as filter
52/// validators an opportunity to catch errors before the user fills the entire item
53/// or screen.
54/// By default, IsValidInput returns true. Derived data validators can override
55/// IsValidInput to validate data as the user types it, returning true if str holds
56/// valid data and false otherwise.
57/// str is the current input string. suppressFill determines whether the validator
58/// should automatically format the string before validating it. If suppressFill is
59/// true, validation takes place on the unmodified string str. If suppressFill is
60/// false, the validator should apply any filling or padding before validating data.
61/// Of the standard validator objects, only TPXPictureValidator checks suppressFill.
62/// IsValidInput can modify the contents of the input string; for example, it can
63/// force characters to uppercase or insert literal characters from a format
64/// picture. IsValidInput should not, however, delete invalid characters from the
65/// string. By returning false, IsValidInput indicates that the edit control should
66/// erase the incorrect characters.
67//
68bool
69TValidator::IsValidInput(tchar *, bool /*suppressFill*/)
70{
71 return true;
72}
73
74//
75/// Checks input against validator for completeness. Never modifies input.
76//
77/// By default, returns true. Derived validator classes can override IsValid to
78/// validate data for a completed edit control.
79/// If an edit control has an associated validator object, and the edit control's
80/// IsValid method is called with its reportErr parameter set to true, then the
81/// validator object's Valid method, which in turn calls IsValid, is called to
82/// determine whether the contents of the edit control are valid. If the edit
83/// control's IsValid method is called with the reportErr parameter set to false,
84/// then the validator's IsValid method is called directly.
85//
86bool
88{
89 return true;
90}
91
92//
93/// Allows a validator to set and read the values of its associated edit control.
94/// This is primarily useful for validators that check non-string data, such as
95/// numeric values. For example, TRangeValidator uses Transfer to read and write
96/// values instead of transferring an entire string.
97/// By default, edit controls with validators give the validator the first chance to
98/// respond to DataSize, GetData, and SetData by calling the validator's Transfer
99/// method. If Transfer returns anything other than 0, it indicates to the edit
100/// control that it has handled the appropriate transfer. The default action of
101/// TValidator::Transfer is always to return 0. If you want the validator to
102/// transfer data, you must override its Transfer method.
103/// Transfer's first two parameters are the associated edit control's text string
104/// and the tdGetData or tdSetData data record. Depending on the value of direction,
105/// Transfer can set str from buffer or read the data from str into buffer. The
106/// return value is always the number of bytes transferred.
107/// If direction is tdSizeData, Transfer doesn't change either str or buffer; it
108/// just returns the data size. If direction is tdSetData, Transfer reads the
109/// appropriate number of bytes from buffer, converts them into the proper string
110/// form, and sets them into str, returning the number of bytes read. If direction
111/// is tdGetData, Transfer converts str into the appropriate data type and writes
112/// the value into buffer, returning the number of bytes written.
113//
114uint
116{
117 return 0;
118}
119
120//
121/// Adjusts the 'value' of the text, given a cursor position and an amount. Returns
122/// the actual amount adjusted.
123//
124int
125TValidator::Adjust(tstring& /*text*/, int& /*begPos*/, int& /*endPos*/, int /*amount*/)
126{
127 return 0;
128}
129
130//----------------------------------------------------------------------------
131
132//
133/// Constructs a TXValidator object, setting the resource ID to IDS_VALIDATORSYNTAX
134/// string resource.
135//
141
142//
143/// Copies the exception so it can be rethrown at a safer time.
144//
147{
148 return new TXValidator(*this);
149}
150
151
152//
153/// Creates an instance of TXValidator and throws it.
154//
155void
157{
158 throw *this;
159}
160
161//
162/// Creates an instance of TXValidator and throws it.
163//
164void
166{
167 TXValidator().Throw();
168}
169
170
171#if OWL_PERSISTENT_STREAMS
172
174
175//
176//
177//
178void*
179TValidator::Streamer::Read(ipstream& is, uint32 /*version*/) const
180{
181 is >> GetObject()->Options;
182 return GetObject();
183}
184
185//
186//
187//
188void
189TValidator::Streamer::Write(opstream& os) const
190{
191 os << GetObject()->Options;
192}
193
194#endif
195
196} // OWL namespace
197/* ========================================================================== */
198
A streamable class, TValidator defines an abstract data validation object.
Definition validate.h:71
uint16 Options
A bitmap member used to control options for various descendants of TValidator.
Definition validate.h:94
virtual uint Transfer(TCHAR *text, void *buffer, TTransferDirection direction)
Allows a validator to set and read the values of its associated edit control.
Definition validate.cpp:115
virtual ~TValidator()
Destroys an abstract validator object.
Definition validate.cpp:32
virtual bool IsValidInput(TCHAR *input, bool suppressFill)
Checks current input against validator.
Definition validate.cpp:69
virtual void Error(TWindow *owner)
Error is an abstract function called by Valid when it detects that the user has entered invalid infor...
Definition validate.cpp:42
virtual bool IsValid(LPCTSTR input)
Checks input against validator for completeness. Never modifies input.
Definition validate.cpp:87
TValidator()
Constructs an abstract validator object and sets Options fields to 0.
Definition validate.cpp:24
virtual int Adjust(tstring &text, int &begPos, int &endPos, int amount)
Adjusts the 'value' of the text, given a cursor position and an amount.
Definition validate.cpp:125
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
TXOwl is root class of the ObjectWindows exception hierarchy.
Definition except.h:38
A nested class, TXValidator describes an exception that results from an invalid validator object.
Definition validate.h:107
void Throw()
Creates an instance of TXValidator and throws it.
Definition validate.cpp:156
TXValidator(uint resId=IDS_VALIDATORSYNTAX)
Constructs a TXValidator object, setting the resource ID to IDS_VALIDATORSYNTAX string resource.
Definition validate.cpp:136
static void Raise()
Creates an instance of TXValidator and throws it.
Definition validate.cpp:165
TXValidator * Clone()
Copies the exception so it can be rethrown at a safer time.
Definition validate.cpp:146
ipstream, a specialized input stream derivative of pstream, is the base class for reading (extracting...
Definition objstrm.h:391
#define IMPLEMENT_STREAMABLE(cls)
Definition objstrm.h:1724
TTransferDirection
The TTransferDirection enum describes the constants that the transfer function uses to determine how ...
Definition window.h:92
Definition of class TModule.
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
unsigned long uint32
Definition number.h:34
OWL_DIAGINFO
Definition animctrl.cpp:14
std::string tstring
Definition defs.h:79
unsigned int uint
Definition number.h:25