KiCad PCB EDA Suite
validators.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2013 Wayne Stambaugh <stambaughw@verizon.net>
5  * Copyright (C) 2004-2013 KiCad Developers, see change_log.txt for contributors.
6  * Copyright (C) 2018 CERN
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
31 #ifndef VALIDATORS_H
32 #define VALIDATORS_H
33 
34 #include <wx/valtext.h>
35 #include <wx/grid.h>
36 #include <wx/regex.h>
37 
44 class GRID_CELL_TEXT_EDITOR : public wxGridCellTextEditor
45 {
46 public:
48 
49  virtual void SetValidator(const wxValidator& validator) override;
50  virtual void StartingKey(wxKeyEvent& event) override;
51 
52 protected:
53  wxScopedPtr<wxValidator> m_validator;
54 };
55 
56 
65 class FILE_NAME_CHAR_VALIDATOR : public wxTextValidator
66 {
67 public:
68  FILE_NAME_CHAR_VALIDATOR( wxString* aValue = NULL );
69 };
70 
71 
80 class FILE_NAME_WITH_PATH_CHAR_VALIDATOR : public wxTextValidator
81 {
82 public:
83  FILE_NAME_WITH_PATH_CHAR_VALIDATOR( wxString* aValue = NULL );
84 };
85 
86 
97 class ENV_VAR_NAME_VALIDATOR : public wxTextValidator
98 {
99 public:
100  ENV_VAR_NAME_VALIDATOR( wxString* aValue = NULL );
102 
103  virtual ~ENV_VAR_NAME_VALIDATOR();
104 
105  // Make a clone of this validator (or return NULL) - currently necessary
106  // if you're passing a reference to a validator.
107  virtual wxObject *Clone() const override
108  {
109  return new ENV_VAR_NAME_VALIDATOR( *this );
110  }
111 
112  void OnChar( wxKeyEvent& event );
113 
114  void OnTextChanged( wxCommandEvent& event );
115 };
116 
117 
122 class REGEX_VALIDATOR : public wxTextValidator
123 {
124 public:
131  REGEX_VALIDATOR( const wxString& aRegEx, wxString* aValue = NULL )
132  : wxTextValidator( wxFILTER_NONE, aValue )
133  {
134  compileRegEx( aRegEx, wxRE_DEFAULT );
135  }
136 
144  REGEX_VALIDATOR( const wxString& aRegEx, int aFlags, wxString* aValue = NULL )
145  : wxTextValidator( wxFILTER_NONE, aValue )
146  {
147  compileRegEx( aRegEx, aFlags );
148  }
149 
151  {
152  wxValidator::Copy( aOther );
153  compileRegEx( aOther.m_regExString, aOther.m_regExFlags );
154  }
155 
156  virtual wxObject* Clone() const override
157  {
158  return new REGEX_VALIDATOR( *this );
159  }
160 
161  bool Validate( wxWindow* aParent ) override;
162 
163 protected:
165  void compileRegEx( const wxString& aRegEx, int aFlags );
166 
168  wxString m_regExString;
169 
172 
174  wxRegEx m_regEx;
175 };
176 
177 namespace KIUI
178 {
192 void ValidatorTransferToWindowWithoutEvents( wxValidator& aValidator );
193 
194 } // namespace KIUI
195 
196 #endif // #ifndef VALIDATORS_H
ENV_VAR_NAME_VALIDATOR(wxString *aValue=NULL)
Definition: validators.cpp:114
wxString m_regExString
Original regular expression (for copy constructor)
Definition: validators.h:168
wxRegEx m_regEx
Compiled regex
Definition: validators.h:174
void compileRegEx(const wxString &aRegEx, int aFlags)
Compiles and stores a regular expression
Definition: validators.cpp:263
void ValidatorTransferToWindowWithoutEvents(wxValidator &aValidator)
Call a text validator's TransferToWindow method without firing a text change event.
Definition: validators.cpp:276
wxScopedPtr< wxValidator > m_validator
Definition: validators.h:53
bool Validate(wxWindow *aParent) override
Definition: validators.cpp:225
Class FILE_NAME_WITH_PATH_CHAR_VALIDATOR.
Definition: validators.h:80
virtual void StartingKey(wxKeyEvent &event) override
Definition: validators.cpp:55
Class GRID_CELL_TEXT_EDITOR.
Definition: validators.h:44
void OnTextChanged(wxCommandEvent &event)
Definition: validators.cpp:206
Class FILE_NAME_CHAR_VALIDATOR.
Definition: validators.h:65
virtual wxObject * Clone() const override
Definition: validators.h:156
REGEX_VALIDATOR(const wxString &aRegEx, int aFlags, wxString *aValue=NULL)
Constructor.
Definition: validators.h:144
virtual void SetValidator(const wxValidator &validator) override
Definition: validators.cpp:46
REGEX_VALIDATOR(const wxString &aRegEx, wxString *aValue=NULL)
Constructor.
Definition: validators.h:131
virtual wxObject * Clone() const override
Definition: validators.h:107
Class ENV_VAR_NAME_VALIDATOR.
Definition: validators.h:97
FILE_NAME_WITH_PATH_CHAR_VALIDATOR(wxString *aValue=NULL)
Definition: validators.cpp:88
REGEX_VALIDATOR(const REGEX_VALIDATOR &aOther)
Definition: validators.h:150
int m_regExFlags
Original compilation flags (for copy constructor)
Definition: validators.h:171
void OnChar(wxKeyEvent &event)
Definition: validators.cpp:136
Custom validator that checks verifies that a string exactly matches a regular expression.
Definition: validators.h:122
FILE_NAME_CHAR_VALIDATOR(wxString *aValue=NULL)
Definition: validators.cpp:71
virtual ~ENV_VAR_NAME_VALIDATOR()
Definition: validators.cpp:130