KiCad PCB EDA Suite
ENV_VAR_NAME_VALIDATOR Class Reference

Class ENV_VAR_NAME_VALIDATOR. 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

Class ENV_VAR_NAME_VALIDATOR.

This class provides a custom wxValidator object for limiting the allowable characters when defining an environment varaible 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 95 of file validators.h.

Constructor & Destructor Documentation

ENV_VAR_NAME_VALIDATOR::ENV_VAR_NAME_VALIDATOR ( wxString *  aValue = NULL)

Definition at line 112 of file validators.cpp.

References OnChar().

112  :
113  wxTextValidator()
114 {
115  Connect( wxEVT_CHAR, wxKeyEventHandler( ENV_VAR_NAME_VALIDATOR::OnChar ) );
116 }
void OnChar(wxKeyEvent &event)
Definition: validators.cpp:134
ENV_VAR_NAME_VALIDATOR::ENV_VAR_NAME_VALIDATOR ( const ENV_VAR_NAME_VALIDATOR val)

Definition at line 119 of file validators.cpp.

References OnChar().

120  : wxTextValidator()
121 {
122  wxValidator::Copy( val );
123 
124  Connect( wxEVT_CHAR, wxKeyEventHandler( ENV_VAR_NAME_VALIDATOR::OnChar ) );
125 }
void OnChar(wxKeyEvent &event)
Definition: validators.cpp:134
ENV_VAR_NAME_VALIDATOR::~ENV_VAR_NAME_VALIDATOR ( )
virtual

Definition at line 128 of file validators.cpp.

References OnChar().

129 {
130  Disconnect( wxEVT_CHAR, wxKeyEventHandler( ENV_VAR_NAME_VALIDATOR::OnChar ) );
131 }
void OnChar(wxKeyEvent &event)
Definition: validators.cpp:134

Member Function Documentation

virtual wxObject* ENV_VAR_NAME_VALIDATOR::Clone ( ) const
inlineoverridevirtual

Definition at line 105 of file validators.h.

106  {
107  return new ENV_VAR_NAME_VALIDATOR( *this );
108  }
ENV_VAR_NAME_VALIDATOR(wxString *aValue=NULL)
Definition: validators.cpp:112
void ENV_VAR_NAME_VALIDATOR::OnChar ( wxKeyEvent &  event)

Definition at line 134 of file validators.cpp.

References OnTextChanged().

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

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

Definition at line 204 of file validators.cpp.

Referenced by OnChar().

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

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