KiCad PCB EDA Suite
ENV_VAR_NAME_VALIDATOR Class Reference

This class provides a custom wxValidator object for limiting the allowable characters when defining an environment variable name in a text edit control. More...

#include <validators.h>

Inheritance diagram for ENV_VAR_NAME_VALIDATOR:

Public Member Functions

 ENV_VAR_NAME_VALIDATOR (wxString *aValue=NULL)
 
 ENV_VAR_NAME_VALIDATOR (const ENV_VAR_NAME_VALIDATOR &val)
 
virtual ~ENV_VAR_NAME_VALIDATOR ()
 
virtual wxObject * Clone () const override
 
void OnChar (wxKeyEvent &event)
 
void OnTextChanged (wxCommandEvent &event)
 

Detailed Description

This class provides a custom wxValidator object for limiting the allowable characters when defining an environment variable name in a text edit control.

Only uppercase, numbers, and underscore (_) characters are valid and the first character of the name cannot start with a number. This is according to IEEE Std 1003.1-2001. Even though most systems support other characters, these characters guarantee compatibility for all shells.

Definition at line 91 of file validators.h.

Constructor & Destructor Documentation

◆ ENV_VAR_NAME_VALIDATOR() [1/2]

ENV_VAR_NAME_VALIDATOR::ENV_VAR_NAME_VALIDATOR ( wxString *  aValue = NULL)

Definition at line 114 of file validators.cpp.

114  :
115  wxTextValidator()
116 {
117  Connect( wxEVT_CHAR, wxKeyEventHandler( ENV_VAR_NAME_VALIDATOR::OnChar ) );
118 }
void OnChar(wxKeyEvent &event)
Definition: validators.cpp:136

References OnChar().

Referenced by Clone().

◆ ENV_VAR_NAME_VALIDATOR() [2/2]

ENV_VAR_NAME_VALIDATOR::ENV_VAR_NAME_VALIDATOR ( const ENV_VAR_NAME_VALIDATOR val)

Definition at line 121 of file validators.cpp.

122  : wxTextValidator()
123 {
124  wxValidator::Copy( val );
125 
126  Connect( wxEVT_CHAR, wxKeyEventHandler( ENV_VAR_NAME_VALIDATOR::OnChar ) );
127 }
void OnChar(wxKeyEvent &event)
Definition: validators.cpp:136

References OnChar().

◆ ~ENV_VAR_NAME_VALIDATOR()

ENV_VAR_NAME_VALIDATOR::~ENV_VAR_NAME_VALIDATOR ( )
virtual

Definition at line 130 of file validators.cpp.

131 {
132  Disconnect( wxEVT_CHAR, wxKeyEventHandler( ENV_VAR_NAME_VALIDATOR::OnChar ) );
133 }
void OnChar(wxKeyEvent &event)
Definition: validators.cpp:136

References OnChar().

Member Function Documentation

◆ Clone()

virtual wxObject* ENV_VAR_NAME_VALIDATOR::Clone ( ) const
inlineoverridevirtual

Definition at line 101 of file validators.h.

102  {
103  return new ENV_VAR_NAME_VALIDATOR( *this );
104  }
ENV_VAR_NAME_VALIDATOR(wxString *aValue=NULL)
Definition: validators.cpp:114

References ENV_VAR_NAME_VALIDATOR().

◆ OnChar()

void ENV_VAR_NAME_VALIDATOR::OnChar ( wxKeyEvent &  event)

Definition at line 136 of file validators.cpp.

137 {
138  if( !m_validatorWindow )
139  {
140  aEvent.Skip();
141  return;
142  }
143 
144  int keyCode = aEvent.GetKeyCode();
145 
146  // we don't filter special keys and delete
147  if( keyCode < WXK_SPACE || keyCode == WXK_DELETE || keyCode >= WXK_START )
148  {
149  aEvent.Skip();
150  return;
151  }
152 
153  wxUniChar c = (wxUChar) keyCode;
154 
155  if( c == wxT( '_' ) )
156  {
157  // OK anywhere
158  aEvent.Skip();
159  }
160  else if( wxIsdigit( c ) )
161  {
162  // not as first character
163  long from, to;
164  GetTextEntry()->GetSelection( &from, &to );
165 
166  if( from < 1 )
167  wxBell();
168  else
169  aEvent.Skip();
170  }
171  else if( wxIsalpha( c ) )
172  {
173  // Capitals only.
174 
175  if( wxIslower( c ) )
176  {
177  // You may wonder why this scope is so twisted, so make yourself comfortable and read:
178  // 1. Changing the keyCode and/or uniChar in the event and passing it on
179  // doesn't work. Some platforms look at the original copy as long as the event
180  // isn't vetoed.
181  // 2. Inserting characters by hand does not move the cursor, meaning either you insert
182  // text backwards (lp:#1798869) or always append, no matter where is the cursor.
183  // wxTextEntry::{Get/Set}InsertionPoint() do not work at all here.
184  // 3. There is wxTextEntry::ForceUpper(), but it is not yet available in common
185  // wxWidgets packages.
186  //
187  // So here we are, with a command event handler that converts
188  // the text to upper case upon every change.
189  wxTextCtrl* textCtrl = dynamic_cast<wxTextCtrl*>( GetTextEntry() );
190 
191  if( textCtrl )
192  {
193  textCtrl->Connect( textCtrl->GetId(), wxEVT_COMMAND_TEXT_UPDATED,
194  (wxObjectEventFunction) &ENV_VAR_NAME_VALIDATOR::OnTextChanged );
195  }
196  }
197 
198  aEvent.Skip();
199  }
200  else
201  {
202  wxBell();
203  }
204 }
void OnTextChanged(wxCommandEvent &event)
Definition: validators.cpp:207

References OnTextChanged().

Referenced by ENV_VAR_NAME_VALIDATOR(), and ~ENV_VAR_NAME_VALIDATOR().

◆ OnTextChanged()

void ENV_VAR_NAME_VALIDATOR::OnTextChanged ( wxCommandEvent &  event)

Definition at line 207 of file validators.cpp.

208 {
209  wxTextCtrl* textCtrl = dynamic_cast<wxTextCtrl*>( event.GetEventObject() );
210 
211  if( textCtrl )
212  {
213  if( !textCtrl->IsModified() )
214  return;
215 
216  long insertionPoint = textCtrl->GetInsertionPoint();
217  textCtrl->ChangeValue( textCtrl->GetValue().Upper() );
218  textCtrl->SetInsertionPoint( insertionPoint );
219  textCtrl->Disconnect( textCtrl->GetId(), wxEVT_COMMAND_TEXT_UPDATED );
220  }
221 
222  event.Skip();
223 }

Referenced by OnChar().


The documentation for this class was generated from the following files: