KiCad PCB EDA Suite
Loading...
Searching...
No Matches
text_ctrl_eval.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) 2017-2021 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Maciej Suminski <[email protected]>
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 3
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, see <https://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include <kicommon.h>
25#include <optional>
26#include <functional>
27#include <wx/window.h>
28#include <wx/textctrl.h>
30
37
38class KICOMMON_API TEXT_CTRL_EVAL : public wxTextCtrl
39{
40public:
41 TEXT_CTRL_EVAL( wxWindow* aParent, wxWindowID aId, const wxString& aValue = wxEmptyString,
42 const wxPoint& aPos = wxDefaultPosition, const wxSize& aSize = wxDefaultSize,
43 long aStyle = 0, const wxValidator& aValidator = wxDefaultValidator,
44 const wxString& aName = wxTextCtrlNameStr );
45
47 {
48 }
49
50 void SetCustomEval( std::function<void( TEXT_CTRL_EVAL* aCtrl )> aCustomEval )
51 {
52 m_customEval = std::move( aCustomEval );
53 }
54
61 void SetValue( const wxString& aValue ) override;
62
66 wxString GetFormula() const;
67
74 bool RestoreFormula( const wxString& aFormula );
75
79 void DeferToBinder() { m_deferToBinder = true; }
80
81protected:
84
85 void onTextFocusGet( wxFocusEvent& aEvent );
86 void onTextFocusLost( wxFocusEvent& aEvent );
87 void onTextEnter( wxCommandEvent& aEvent );
88
89 void evaluate();
90
91private:
92 std::optional<std::function<void( TEXT_CTRL_EVAL* aCtrl )>> m_customEval;
94};
95
void onTextFocusLost(wxFocusEvent &aEvent)
NUMERIC_EVALUATOR m_eval
Numeric expression evaluator.
virtual ~TEXT_CTRL_EVAL()
void onTextEnter(wxCommandEvent &aEvent)
std::optional< std::function< void(TEXT_CTRL_EVAL *aCtrl)> > m_customEval
void SetCustomEval(std::function< void(TEXT_CTRL_EVAL *aCtrl)> aCustomEval)
TEXT_CTRL_EVAL(wxWindow *aParent, wxWindowID aId, const wxString &aValue=wxEmptyString, const wxPoint &aPos=wxDefaultPosition, const wxSize &aSize=wxDefaultSize, long aStyle=0, const wxValidator &aValidator=wxDefaultValidator, const wxString &aName=wxTextCtrlNameStr)
void DeferToBinder()
Leave evaluation to a UNIT_BINDER bound to this control.
void onTextFocusGet(wxFocusEvent &aEvent)
#define KICOMMON_API
Definition kicommon.h:27