33#include <wx/textctrl.h>
34#include <wx/textentry.h>
42 wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, aValue )
47 wxString illegalChars = wxS(
"%$<>\t\n\r\"\\/:" );
48 SetCharExcludes( illegalChars );
62 wxValidator::Copy( val );
76 if( !m_validatorWindow )
82 int keyCode = aEvent.GetKeyCode();
85 if( keyCode < WXK_SPACE || keyCode == WXK_DELETE || keyCode >= WXK_START )
91 wxUniChar c = (wxUChar) keyCode;
98 else if( wxIsdigit( c ) )
102 GetTextEntry()->GetSelection( &from, &to );
109 else if( wxIsalpha( c ) )
127 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( GetTextEntry() );
131 textCtrl->Connect( textCtrl->GetId(), wxEVT_COMMAND_TEXT_UPDATED,
147 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>(
event.GetEventObject() );
151 if( !textCtrl->IsModified() )
154 long insertionPoint = textCtrl->GetInsertionPoint();
155 textCtrl->ChangeValue( textCtrl->GetValue().Upper() );
156 textCtrl->SetInsertionPoint( insertionPoint );
157 textCtrl->Disconnect( textCtrl->GetId(), wxEVT_COMMAND_TEXT_UPDATED );
172 wxTextValidator( aValidator ),
188 if ( !m_validatorWindow->IsEnabled() )
191 wxTextEntry *
const text = GetTextEntry();
196 const wxString& errormsg =
IsValid(
text->GetValue() );
198 if( !errormsg.empty() )
200 m_validatorWindow->SetFocus();
201 wxMessageBox( errormsg,
_(
"Invalid signal name" ), wxOK | wxICON_EXCLAMATION, aParent );
211 if( str.Contains(
'\r' ) || str.Contains(
'\n' ) )
212 return _(
"Signal names cannot contain CR or LF characters" );
214 if( !
m_allowSpaces && ( str.Contains(
' ' ) || str.Contains(
'\t' ) ) )
215 return _(
"Signal names cannot contain spaces" );
223 wxWindow* ctrl = aValidator.GetWindow();
225 wxCHECK_RET( ctrl !=
nullptr, wxS(
"Transferring validator data without a control" ) );
227 wxEventBlocker orient_update_blocker( ctrl, wxEVT_ANY );
228 aValidator.TransferToWindow();
233 wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, aValue ),
237 wxString excludes( wxT(
"\r\n\t" ) );
242 excludes += wxT(
" " );
246 excludes += wxT(
"/" );
249 long style = GetStyle();
256 style |= wxFILTER_EMPTY;
260 SetCharExcludes( excludes );
265 wxTextValidator( aValidator ),
274 if( !m_validatorWindow->IsEnabled() )
277 wxTextEntry*
const text = GetTextEntry();
282 wxString val(
text->GetValue() );
293 if( validator.HasFlag( wxFILTER_EMPTY ) && aValue.empty() )
299 default: msg =
_(
"The value of the field cannot be empty." );
break;
303 if( msg.empty() && validator.HasFlag( wxFILTER_EXCLUDE_CHAR_LIST ) )
305 wxArrayString badCharsFound;
307 for(
const wxUniCharRef& excludeChar : validator.GetCharExcludes() )
309 if( aValue.Find( excludeChar ) != wxNOT_FOUND )
311 if( excludeChar ==
'\r' )
312 badCharsFound.Add(
_(
"carriage return" ) );
313 else if( excludeChar ==
'\n' )
314 badCharsFound.Add(
_(
"line feed" ) );
315 else if( excludeChar ==
'\t' )
316 badCharsFound.Add(
_(
"tab" ) );
317 else if( excludeChar ==
' ' )
318 badCharsFound.Add(
_(
"space" ) );
320 badCharsFound.Add( wxString::Format( wxT(
"'%c'" ), excludeChar ) );
324 if( !badCharsFound.IsEmpty() )
328 for(
size_t i = 0; i < badCharsFound.GetCount(); i++ )
330 if( !badChars.IsEmpty() )
332 if( badCharsFound.GetCount() == 2 )
334 badChars +=
_(
" or " );
338 if( i < badCharsFound.GetCount() - 2 )
339 badChars +=
_(
", or " );
341 badChars += wxT(
", " );
345 badChars += badCharsFound.Item( i );
351 msg.Printf(
_(
"The reference designator cannot contain %s character(s)." ), badChars );
355 msg.Printf(
_(
"The value field cannot contain %s character(s)." ), badChars );
359 msg.Printf(
_(
"The footprint field cannot contain %s character(s)." ), badChars );
363 msg.Printf(
_(
"The datasheet field cannot contain %s character(s)." ), badChars );
367 msg.Printf(
_(
"The sheet name cannot contain %s character(s)." ), badChars );
371 msg.Printf(
_(
"The sheet filename cannot contain %s character(s)." ), badChars );
375 msg.Printf(
_(
"The field cannot contain %s character(s)." ), badChars );
385 msg.Printf(
_(
"The reference designator cannot contain text variable references" ) );
389 msg.Printf(
_(
"References must start with a letter." ) );
403 if( m_validatorWindow )
404 m_validatorWindow->SetFocus();
406 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.