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();
250 DisplayError( aParent, wxString::Format(
_(
"Incorrect value: %s" ), value ) );
260 if( !
m_regEx.Compile( aRegEx, aFlags ) )
262 throw std::runtime_error(
"REGEX_VALIDATOR: Invalid regular expression: "
263 + aRegEx.ToStdString() );
273 m_allowSpaces( false )
279 wxTextValidator( aValidator ),
280 m_allowSpaces( aValidator.m_allowSpaces )
287 m_allowSpaces( aAllowSpaces )
295 if ( !m_validatorWindow->IsEnabled() )
298 wxTextEntry *
const text = GetTextEntry();
303 const wxString& errormsg =
IsValid(
text->GetValue() );
305 if( !errormsg.empty() )
307 m_validatorWindow->SetFocus();
308 wxMessageBox( errormsg,
_(
"Invalid signal name" ), wxOK | wxICON_EXCLAMATION, aParent );
318 if( str.Contains(
'\r' ) || str.Contains(
'\n' ) )
319 return _(
"Signal names cannot contain CR or LF characters" );
321 if( !
m_allowSpaces && ( str.Contains(
' ' ) || str.Contains(
'\t' ) ) )
322 return _(
"Signal names cannot contain spaces" );
330 wxWindow* ctrl = aValidator.GetWindow();
332 wxCHECK_RET( ctrl !=
nullptr, wxS(
"Transferring validator data without a control" ) );
334 wxEventBlocker orient_update_blocker( ctrl, wxEVT_ANY );
335 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)
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.
Custom text control validator definitions.