36#include <wx/textctrl.h>
37#include <wx/textentry.h>
49 m_validator.reset(
static_cast<wxValidator*
>( validator.Clone() ) );
63 if( event.GetSkipped() )
65 wxGridCellTextEditor::StartingKey( event );
72 wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, aValue )
77 wxString illegalChars = wxS(
"%$<>\t\n\r\"\\/:" );
78 SetCharExcludes( illegalChars );
83 wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST | wxFILTER_EMPTY, aValue )
88 wxString illegalChars = wxFileName::GetForbiddenChars( wxPATH_DOS );
89 wxTextValidator nameValidator( wxFILTER_EXCLUDE_CHAR_LIST );
90 wxArrayString illegalCharList;
92 for(
unsigned i = 0; i < illegalChars.size(); i++ )
94 if( illegalChars[i] ==
'/' )
97#if defined (__WINDOWS__)
98 if( illegalChars[i] ==
'\\' || illegalChars[i] ==
':' )
101 illegalCharList.Add( wxString( illegalChars[i] ) );
104 SetExcludes( illegalCharList );
118 wxValidator::Copy( val );
132 if( !m_validatorWindow )
138 int keyCode = aEvent.GetKeyCode();
141 if( keyCode < WXK_SPACE || keyCode == WXK_DELETE || keyCode >= WXK_START )
147 wxUniChar c = (wxUChar) keyCode;
149 if( c == wxT(
'_' ) )
154 else if( wxIsdigit( c ) )
158 GetTextEntry()->GetSelection( &from, &to );
165 else if( wxIsalpha( c ) )
183 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( GetTextEntry() );
187 textCtrl->Connect( textCtrl->GetId(), wxEVT_COMMAND_TEXT_UPDATED,
203 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>(
event.GetEventObject() );
207 if( !textCtrl->IsModified() )
210 long insertionPoint = textCtrl->GetInsertionPoint();
211 textCtrl->ChangeValue( textCtrl->GetValue().Upper() );
212 textCtrl->SetInsertionPoint( insertionPoint );
213 textCtrl->Disconnect( textCtrl->GetId(), wxEVT_COMMAND_TEXT_UPDATED );
223 if( !m_validatorWindow->IsEnabled() )
226 wxTextEntry*
const textEntry = GetTextEntry();
232 const wxString& value = textEntry->GetValue();
237 m_regEx.GetMatch( &start, &len );
239 if( start != 0 || len != value.Length() )
249 m_validatorWindow->SetFocus();
260 if( !
m_regEx.Compile( aRegEx, aFlags ) )
262 throw std::runtime_error(
"REGEX_VALIDATOR: Invalid regular expression: "
263 + aRegEx.ToStdString() );
276 if( !m_validatorWindow->IsEnabled() )
279 wxTextEntry*
const text = GetTextEntry();
285 wxString val(
text->GetValue() );
286 wxString tmp = val.Clone();
289 if( !(GetStyle() & wxFILTER_EMPTY) && val.IsEmpty() )
292 if( tmp.Trim() != val )
294 msg =
_(
"Entry contains trailing white space." );
296 else if( tmp.Trim(
false ) != val )
298 msg =
_(
"Entry contains leading white space." );
300 else if(
dummy.Parse( val ) != -1 || !
dummy.IsValid() )
302 msg.Printf(
_(
"'%s' is not a valid library identifier format." ), val );
307 m_validatorWindow->SetFocus();
309 wxMessageBox( msg,
_(
"Library Identifier Validation Error" ),
310 wxOK | wxICON_EXCLAMATION, aParent );
321 m_allowSpaces( false )
327 wxTextValidator( aValidator ),
328 m_allowSpaces( aValidator.m_allowSpaces )
335 m_allowSpaces( aAllowSpaces )
343 if ( !m_validatorWindow->IsEnabled() )
346 wxTextEntry *
const text = GetTextEntry();
351 const wxString& errormsg =
IsValid(
text->GetValue() );
353 if( !errormsg.empty() )
355 m_validatorWindow->SetFocus();
356 wxMessageBox( errormsg,
_(
"Invalid signal name" ), wxOK | wxICON_EXCLAMATION, aParent );
366 if( str.Contains(
'\r' ) || str.Contains(
'\n' ) )
367 return _(
"Signal names cannot contain CR or LF characters" );
369 if( !
m_allowSpaces && ( str.Contains(
' ' ) || str.Contains(
'\t' ) ) )
370 return _(
"Signal names cannot contain spaces" );
378 wxWindow* ctrl = aValidator.GetWindow();
380 wxCHECK_RET( ctrl !=
nullptr, wxS(
"Transferring validator data without a control" ) );
382 wxEventBlocker orient_update_blocker( ctrl, wxEVT_ANY );
383 aValidator.TransferToWindow();
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)
FILE_NAME_WITH_PATH_CHAR_VALIDATOR(wxString *aValue=nullptr)
wxScopedPtr< wxValidator > m_validator
virtual void StartingKey(wxKeyEvent &event) override
virtual void SetValidator(const wxValidator &validator) override
bool Validate(wxWindow *aParent) override
A logical library item identifier and consists of various portions much like a URI.
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.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
std::vector< FAB_LAYER_COLOR > dummy
Custom text control validator definitions.