37#include <wx/textctrl.h>
38#include <wx/textentry.h>
50 m_validator.reset(
static_cast<wxValidator*
>( validator.Clone() ) );
64 if( event.GetSkipped() )
66 wxGridCellTextEditor::StartingKey( event );
73 wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, aValue )
78 wxString illegalChars = wxS(
"%$<>\t\n\r\"\\/:" );
79 SetCharExcludes( illegalChars );
84 wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST | wxFILTER_EMPTY, aValue )
89 wxString illegalChars = wxFileName::GetForbiddenChars( wxPATH_DOS );
90 wxTextValidator nameValidator( wxFILTER_EXCLUDE_CHAR_LIST );
91 wxArrayString illegalCharList;
93 for(
unsigned i = 0; i < illegalChars.size(); i++ )
95 if( illegalChars[i] ==
'/' )
98#if defined (__WINDOWS__)
99 if( illegalChars[i] ==
'\\' || illegalChars[i] ==
':' )
102 illegalCharList.Add( wxString( illegalChars[i] ) );
105 SetExcludes( illegalCharList );
119 wxValidator::Copy( val );
133 if( !m_validatorWindow )
139 int keyCode = aEvent.GetKeyCode();
142 if( keyCode < WXK_SPACE || keyCode == WXK_DELETE || keyCode >= WXK_START )
148 wxUniChar c = (wxUChar) keyCode;
150 if( c == wxT(
'_' ) )
155 else if( wxIsdigit( c ) )
159 GetTextEntry()->GetSelection( &from, &to );
166 else if( wxIsalpha( c ) )
184 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( GetTextEntry() );
188 textCtrl->Connect( textCtrl->GetId(), wxEVT_COMMAND_TEXT_UPDATED,
204 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>(
event.GetEventObject() );
208 if( !textCtrl->IsModified() )
211 long insertionPoint = textCtrl->GetInsertionPoint();
212 textCtrl->ChangeValue( textCtrl->GetValue().Upper() );
213 textCtrl->SetInsertionPoint( insertionPoint );
214 textCtrl->Disconnect( textCtrl->GetId(), wxEVT_COMMAND_TEXT_UPDATED );
224 if( !m_validatorWindow->IsEnabled() )
227 wxTextEntry*
const textEntry = GetTextEntry();
233 const wxString& value = textEntry->GetValue();
238 m_regEx.GetMatch( &start, &len );
240 if( start != 0 || len != value.Length() )
250 m_validatorWindow->SetFocus();
251 DisplayError( aParent, wxString::Format(
_(
"Incorrect value: %s" ), value ) );
261 if( !
m_regEx.Compile( aRegEx, aFlags ) )
263 throw std::runtime_error(
"REGEX_VALIDATOR: Invalid regular expression: "
264 + aRegEx.ToStdString() );
274 m_allowSpaces( false )
280 wxTextValidator( aValidator ),
281 m_allowSpaces( aValidator.m_allowSpaces )
288 m_allowSpaces( aAllowSpaces )
296 if ( !m_validatorWindow->IsEnabled() )
299 wxTextEntry *
const text = GetTextEntry();
304 const wxString& errormsg =
IsValid(
text->GetValue() );
306 if( !errormsg.empty() )
308 m_validatorWindow->SetFocus();
309 wxMessageBox( errormsg,
_(
"Invalid signal name" ), wxOK | wxICON_EXCLAMATION, aParent );
319 if( str.Contains(
'\r' ) || str.Contains(
'\n' ) )
320 return _(
"Signal names cannot contain CR or LF characters" );
322 if( !
m_allowSpaces && ( str.Contains(
' ' ) || str.Contains(
'\t' ) ) )
323 return _(
"Signal names cannot contain spaces" );
331 wxWindow* ctrl = aValidator.GetWindow();
333 wxCHECK_RET( ctrl !=
nullptr, wxS(
"Transferring validator data without a control" ) );
335 wxEventBlocker orient_update_blocker( ctrl, wxEVT_ANY );
336 aValidator.TransferToWindow();
341 wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, aValue ), m_fieldId( aFieldId )
344 wxString excludes( wxT(
"\r\n\t" ) );
349 excludes += wxT(
" " );
353 excludes += wxT(
"/" );
356 long style = GetStyle();
361 style |= wxFILTER_EMPTY;
365 SetCharExcludes( excludes );
370 wxTextValidator( aValidator ), m_fieldId( aValidator.m_fieldId )
378 if( !m_validatorWindow->IsEnabled() )
381 wxTextEntry*
const text = GetTextEntry();
386 wxString val(
text->GetValue() );
389 if( HasFlag( wxFILTER_EMPTY ) && val.empty() )
390 msg.Printf(
_(
"The value of the field cannot be empty." ) );
392 if( HasFlag( wxFILTER_EXCLUDE_CHAR_LIST ) && ContainsExcludedCharacters( val ) )
394 wxArrayString badCharsFound;
396 for(
const wxUniCharRef& excludeChar : GetCharExcludes() )
398 if( val.Find( excludeChar ) != wxNOT_FOUND )
400 if( excludeChar ==
'\r' )
401 badCharsFound.Add(
_(
"carriage return" ) );
402 else if( excludeChar ==
'\n' )
403 badCharsFound.Add(
_(
"line feed" ) );
404 else if( excludeChar ==
'\t' )
405 badCharsFound.Add(
_(
"tab" ) );
406 else if( excludeChar ==
' ' )
407 badCharsFound.Add(
_(
"space" ) );
409 badCharsFound.Add( wxString::Format( wxT(
"'%c'" ), excludeChar ) );
415 for(
size_t i = 0; i < badCharsFound.GetCount(); i++ )
417 if( !badChars.IsEmpty() )
419 if( badCharsFound.GetCount() == 2 )
421 badChars +=
_(
" or " );
425 if( i < badCharsFound.GetCount() - 2 )
426 badChars +=
_(
", or " );
428 badChars += wxT(
", " );
432 badChars += badCharsFound.Item( i );
438 msg.Printf(
_(
"The reference designator cannot contain %s character(s)." ), badChars );
442 msg.Printf(
_(
"The value field cannot contain %s character(s)." ), badChars );
446 msg.Printf(
_(
"The footprint field cannot contain %s character(s)." ), badChars );
450 msg.Printf(
_(
"The datasheet field cannot contain %s character(s)." ), badChars );
454 msg.Printf(
_(
"The sheet name cannot contain %s character(s)." ), badChars );
458 msg.Printf(
_(
"The sheet filename cannot contain %s character(s)." ), badChars );
462 msg.Printf(
_(
"The field cannot contain %s character(s)." ), badChars );
468 msg.Printf(
_(
"The reference designator cannot contain text variable references" ) );
473 m_validatorWindow->SetFocus();
475 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)
std::unique_ptr< wxValidator > m_validator
virtual void StartingKey(wxKeyEvent &event) override
virtual void SetValidator(const wxValidator &validator) override
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.