wxMaxima
RegexCtrl.h
1 // -*- mode: c++; c-file-style: "linux"; c-basic-offset: 2; indent-tabs-mode: nil -*-
2 //
3 // Copyright (C) 2004-2015 Andrej Vodopivec <andrej.vodopivec@gmail.com>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 //
20 // SPDX-License-Identifier: GPL-2.0+
21 
22 #ifndef REGEXCTRL_H
23 #define REGEXCTRL_H
24 
25 #include "precomp.h"
26 #include <wx/wx.h>
27 #include <wx/regex.h>
28 #include <wx/textctrl.h>
29 #include "Configuration.h"
30 
34 class RegexCtrl : public wxTextCtrl
35 {
36  class wxLogBuffer_noStdErrFlush : public wxLogBuffer
37  {
38  public:
39  wxLogBuffer_noStdErrFlush(): wxLogBuffer() {};
40  virtual void Flush() override {}
41  ~wxLogBuffer_noStdErrFlush() override{};
42  };
43 public:
44  RegexCtrl(wxWindow *parent,
45  wxWindowID id);
46  bool Matches(wxString text);
47 
48 protected:
49  void OnTextChange(wxCommandEvent &ev);
50 
51  ~RegexCtrl();
52 
53 private:
54  wxString m_oldRegex;
55  wxRegEx m_regex;
56  enum class RegexInputState : int8_t { empty, invalid, valid };
58  RegexInputState m_regexInputState = RegexInputState::empty;
59  RegexInputState GetNewRegexInputState() const;
61  static wxString RegexTooltip_error;
63  static wxString RegexTooltip_norm;
64 };
65 
66 wxDECLARE_EVENT(REGEX_EVENT, wxCommandEvent);
67 
68 #endif // REGEXCTRL_H
RegexCtrl
Definition: RegexCtrl.h:34