37#include <wx/textctrl.h>
38#include <wx/textentry.h>
44 wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, aValue )
49 wxString illegalChars = wxS(
"%$<>\t\n\r\"\\/:" );
50 SetCharExcludes( illegalChars );
55 wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST | wxFILTER_EMPTY, aValue )
60 wxString illegalChars = wxFileName::GetForbiddenChars( wxPATH_DOS );
61 wxTextValidator nameValidator( wxFILTER_EXCLUDE_CHAR_LIST );
62 wxArrayString illegalCharList;
64 for(
unsigned i = 0; i < illegalChars.size(); i++ )
66 if( illegalChars[i] ==
'/' )
69#if defined (__WINDOWS__)
70 if( illegalChars[i] ==
'\\' || illegalChars[i] ==
':' )
73 illegalCharList.Add( wxString( illegalChars[i] ) );
76 SetExcludes( illegalCharList );
90 wxValidator::Copy( val );
104 if( !m_validatorWindow )
110 int keyCode = aEvent.GetKeyCode();
113 if( keyCode < WXK_SPACE || keyCode == WXK_DELETE || keyCode >= WXK_START )
119 wxUniChar c = (wxUChar) keyCode;
121 if( c == wxT(
'_' ) )
126 else if( wxIsdigit( c ) )
130 GetTextEntry()->GetSelection( &from, &to );
137 else if( wxIsalpha( c ) )
155 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( GetTextEntry() );
159 textCtrl->Connect( textCtrl->GetId(), wxEVT_COMMAND_TEXT_UPDATED,
175 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>(
event.GetEventObject() );
179 if( !textCtrl->IsModified() )
182 long insertionPoint = textCtrl->GetInsertionPoint();
183 textCtrl->ChangeValue( textCtrl->GetValue().Upper() );
184 textCtrl->SetInsertionPoint( insertionPoint );
185 textCtrl->Disconnect( textCtrl->GetId(), wxEVT_COMMAND_TEXT_UPDATED );
195 if( !m_validatorWindow->IsEnabled() )
198 wxTextEntry*
const textEntry = GetTextEntry();
204 const wxString& value = textEntry->GetValue();
209 m_regEx.GetMatch( &start, &len );
211 if( start != 0 || len != value.Length() )
221 m_validatorWindow->SetFocus();
222 DisplayError( aParent, wxString::Format(
_(
"Incorrect value: %s" ), value ) );
232 if( !
m_regEx.Compile( aRegEx, aFlags ) )
234 throw std::runtime_error(
"REGEX_VALIDATOR: Invalid regular expression: "
235 + aRegEx.ToStdString() );
245 m_allowSpaces( false )
251 wxTextValidator( aValidator ),
252 m_allowSpaces( aValidator.m_allowSpaces )
259 m_allowSpaces( aAllowSpaces )
267 if ( !m_validatorWindow->IsEnabled() )
270 wxTextEntry *
const text = GetTextEntry();
275 const wxString& errormsg =
IsValid(
text->GetValue() );
277 if( !errormsg.empty() )
279 m_validatorWindow->SetFocus();
280 wxMessageBox( errormsg,
_(
"Invalid signal name" ), wxOK | wxICON_EXCLAMATION, aParent );
290 if( str.Contains(
'\r' ) || str.Contains(
'\n' ) )
291 return _(
"Signal names cannot contain CR or LF characters" );
293 if( !
m_allowSpaces && ( str.Contains(
' ' ) || str.Contains(
'\t' ) ) )
294 return _(
"Signal names cannot contain spaces" );
302 wxWindow* ctrl = aValidator.GetWindow();
304 wxCHECK_RET( ctrl !=
nullptr, wxS(
"Transferring validator data without a control" ) );
306 wxEventBlocker orient_update_blocker( ctrl, wxEVT_ANY );
307 aValidator.TransferToWindow();
312 wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, aValue ), m_fieldId( aFieldId )
315 wxString excludes( wxT(
"\r\n\t" ) );
320 excludes += wxT(
" " );
324 excludes += wxT(
"/" );
327 long style = GetStyle();
332 style |= wxFILTER_EMPTY;
336 SetCharExcludes( excludes );
341 wxTextValidator( aValidator ), m_fieldId( aValidator.m_fieldId )
349 if( !m_validatorWindow->IsEnabled() )
352 wxTextEntry*
const text = GetTextEntry();
357 wxString val(
text->GetValue() );
360 if( HasFlag( wxFILTER_EMPTY ) && val.empty() )
361 msg.Printf(
_(
"The value of the field cannot be empty." ) );
363 if( HasFlag( wxFILTER_EXCLUDE_CHAR_LIST ) && ContainsExcludedCharacters( val ) )
365 wxArrayString badCharsFound;
367 for(
const wxUniCharRef& excludeChar : GetCharExcludes() )
369 if( val.Find( excludeChar ) != wxNOT_FOUND )
371 if( excludeChar ==
'\r' )
372 badCharsFound.Add(
_(
"carriage return" ) );
373 else if( excludeChar ==
'\n' )
374 badCharsFound.Add(
_(
"line feed" ) );
375 else if( excludeChar ==
'\t' )
376 badCharsFound.Add(
_(
"tab" ) );
377 else if( excludeChar ==
' ' )
378 badCharsFound.Add(
_(
"space" ) );
380 badCharsFound.Add( wxString::Format( wxT(
"'%c'" ), excludeChar ) );
386 for(
size_t i = 0; i < badCharsFound.GetCount(); i++ )
388 if( !badChars.IsEmpty() )
390 if( badCharsFound.GetCount() == 2 )
392 badChars +=
_(
" or " );
396 if( i < badCharsFound.GetCount() - 2 )
397 badChars +=
_(
", or " );
399 badChars += wxT(
", " );
403 badChars += badCharsFound.Item( i );
409 msg.Printf(
_(
"The reference designator cannot contain %s character(s)." ), badChars );
413 msg.Printf(
_(
"The value field cannot contain %s character(s)." ), badChars );
417 msg.Printf(
_(
"The footprint field cannot contain %s character(s)." ), badChars );
421 msg.Printf(
_(
"The datasheet field cannot contain %s character(s)." ), badChars );
425 msg.Printf(
_(
"The sheet name cannot contain %s character(s)." ), badChars );
429 msg.Printf(
_(
"The sheet filename cannot contain %s character(s)." ), badChars );
433 msg.Printf(
_(
"The field cannot contain %s character(s)." ), badChars );
439 msg.Printf(
_(
"The reference designator cannot contain text variable references" ) );
444 m_validatorWindow->SetFocus();
446 wxMessageBox( msg,
_(
"Field Validation Error" ), wxOK | wxICON_EXCLAMATION, aParent );
This class provides a custom wxValidator object for limiting the allowable characters when defining a...
virtual ~ENV_VAR_NAME_VALIDATOR()
void OnChar(wxKeyEvent &event)
ENV_VAR_NAME_VALIDATOR(wxString *aValue=nullptr)
void OnTextChanged(wxCommandEvent &event)
A text control validator used for validating the text allowed in fields.
FIELD_VALIDATOR(int aFieldId, wxString *aValue=nullptr)
virtual bool Validate(wxWindow *aParent) override
Override the default Validate() function provided by wxTextValidator to provide better error messages...
FILE_NAME_WITH_PATH_CHAR_VALIDATOR(wxString *aValue=nullptr)
wxString IsValid(const wxString &aVal) const override
virtual bool Validate(wxWindow *aParent) override
NETNAME_VALIDATOR(wxString *aVal=nullptr)
bool Validate(wxWindow *aParent) override
wxString m_regExString
Original compilation flags (for copy constructor)
int m_regExFlags
Compiled regex.
void compileRegEx(const wxString &aRegEx, int aFlags)
< Compiles and stores a regular expression
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
This file is part of the common library.
void ValidatorTransferToWindowWithoutEvents(wxValidator &aValidator)
Call a text validator's TransferDataToWindow method without firing a text change event.
@ DATASHEET_FIELD
name of datasheet
@ FOOTPRINT_FIELD
Field Name Module PCB, i.e. "16DIP300".
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
Custom text control validator definitions.