37#include <wx/textctrl.h>
38#include <wx/textentry.h>
46 wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, aValue )
51 wxString illegalChars = wxS(
"%$<>\t\n\r\"\\/:" );
52 SetCharExcludes( illegalChars );
66 wxValidator::Copy( val );
80 if( !m_validatorWindow )
86 int keyCode = aEvent.GetKeyCode();
89 if( keyCode < WXK_SPACE || keyCode == WXK_DELETE || keyCode >= WXK_START )
95 wxUniChar c = (wxUChar) keyCode;
102 else if( wxIsdigit( c ) )
106 GetTextEntry()->GetSelection( &from, &to );
113 else if( wxIsalpha( c ) )
131 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( GetTextEntry() );
135 textCtrl->Connect( textCtrl->GetId(), wxEVT_COMMAND_TEXT_UPDATED,
151 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>(
event.GetEventObject() );
155 if( !textCtrl->IsModified() )
158 long insertionPoint = textCtrl->GetInsertionPoint();
159 textCtrl->ChangeValue( textCtrl->GetValue().Upper() );
160 textCtrl->SetInsertionPoint( insertionPoint );
161 textCtrl->Disconnect( textCtrl->GetId(), wxEVT_COMMAND_TEXT_UPDATED );
176 wxTextValidator( aValidator ),
192 if ( !m_validatorWindow->IsEnabled() )
195 wxTextEntry *
const text = GetTextEntry();
200 const wxString& errormsg =
IsValid(
text->GetValue() );
202 if( !errormsg.empty() )
204 m_validatorWindow->SetFocus();
205 wxMessageBox( errormsg,
_(
"Invalid signal name" ), wxOK | wxICON_EXCLAMATION, aParent );
215 if( str.Contains(
'\r' ) || str.Contains(
'\n' ) )
216 return _(
"Signal names cannot contain CR or LF characters" );
218 if( !
m_allowSpaces && ( str.Contains(
' ' ) || str.Contains(
'\t' ) ) )
219 return _(
"Signal names cannot contain spaces" );
227 wxWindow* ctrl = aValidator.GetWindow();
229 wxCHECK_RET( ctrl !=
nullptr, wxS(
"Transferring validator data without a control" ) );
231 wxEventBlocker orient_update_blocker( ctrl, wxEVT_ANY );
232 aValidator.TransferToWindow();
237 wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, aValue ),
241 wxString excludes( wxT(
"\r\n\t" ) );
246 excludes += wxT(
" " );
250 excludes += wxT(
"/" );
253 long style = GetStyle();
260 style |= wxFILTER_EMPTY;
264 SetCharExcludes( excludes );
269 wxTextValidator( aValidator ),
278 if( !m_validatorWindow->IsEnabled() )
281 wxTextEntry*
const text = GetTextEntry();
286 wxString val(
text->GetValue() );
297 if( validator.HasFlag( wxFILTER_EMPTY ) && aValue.empty() )
303 default: msg =
_(
"The value of the field cannot be empty." );
break;
307 if( msg.empty() && validator.HasFlag( wxFILTER_EXCLUDE_CHAR_LIST ) )
309 wxArrayString badCharsFound;
311 for(
const wxUniCharRef& excludeChar : validator.GetCharExcludes() )
313 if( aValue.Find( excludeChar ) != wxNOT_FOUND )
315 if( excludeChar ==
'\r' )
316 badCharsFound.Add(
_(
"carriage return" ) );
317 else if( excludeChar ==
'\n' )
318 badCharsFound.Add(
_(
"line feed" ) );
319 else if( excludeChar ==
'\t' )
320 badCharsFound.Add(
_(
"tab" ) );
321 else if( excludeChar ==
' ' )
322 badCharsFound.Add(
_(
"space" ) );
324 badCharsFound.Add( wxString::Format( wxT(
"'%c'" ), excludeChar ) );
328 if( !badCharsFound.IsEmpty() )
332 for(
size_t i = 0; i < badCharsFound.GetCount(); i++ )
334 if( !badChars.IsEmpty() )
336 if( badCharsFound.GetCount() == 2 )
338 badChars +=
_(
" or " );
342 if( i < badCharsFound.GetCount() - 2 )
343 badChars +=
_(
", or " );
345 badChars += wxT(
", " );
349 badChars += badCharsFound.Item( i );
355 msg.Printf(
_(
"The reference designator cannot contain %s character(s)." ), badChars );
359 msg.Printf(
_(
"The value field cannot contain %s character(s)." ), badChars );
363 msg.Printf(
_(
"The footprint field cannot contain %s character(s)." ), badChars );
367 msg.Printf(
_(
"The datasheet field cannot contain %s character(s)." ), badChars );
371 msg.Printf(
_(
"The sheet name cannot contain %s character(s)." ), badChars );
375 msg.Printf(
_(
"The sheet filename cannot contain %s character(s)." ), badChars );
379 msg.Printf(
_(
"The field cannot contain %s character(s)." ), badChars );
389 msg.Printf(
_(
"The reference designator cannot contain text variable references" ) );
393 msg.Printf(
_(
"References must start with a letter." ) );
407 if( m_validatorWindow )
408 m_validatorWindow->SetFocus();
410 wxMessageBox( msg,
_(
"Field Validation Error" ), wxOK | wxICON_EXCLAMATION, aParent );
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.
virtual bool Validate(wxWindow *aParent) override
Override the default Validate() function provided by wxTextValidator to provide better error messages...
bool DoValidate(const wxString &aValue, wxWindow *aParent)
FIELD_VALIDATOR(FIELD_T aFieldId, wxString *aValue=nullptr)
wxString IsValid(const wxString &aVal) const override
virtual bool Validate(wxWindow *aParent) override
NETNAME_VALIDATOR(wxString *aVal=nullptr)
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.
wxString GetRefDesPrefix(const wxString &aRefDes)
Get the (non-numeric) prefix from a refdes - e.g.
Collection of utility functions for component reference designators (refdes)
FIELD_T
The set of all field indices assuming an array like sequence that a SCH_COMPONENT or LIB_PART can hol...
@ FOOTPRINT
Field Name Module PCB, i.e. "16DIP300".
@ DATASHEET
name of datasheet
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ VALUE
Field Value of part, i.e. "3.3K".
wxString GetFieldValidationErrorMessage(FIELD_T aFieldId, const wxString &aValue)
Return the error message if aValue is invalid for aFieldId.
Custom text control validator definitions.
wxString GetFieldValidationErrorMessage(FIELD_T aFieldId, const wxString &aValue)
Return the error message if aValue is invalid for aFieldId.