You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.5 KiB

  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 <maciej.suminski@cern.ch>
  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, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-3.0.html
  21. * or you may search the http://www.gnu.org website for the version 3 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. #ifndef TEXT_CTRL_EVAL_H
  26. #define TEXT_CTRL_EVAL_H
  27. #include <wx/window.h>
  28. #include <wx/textctrl.h>
  29. #include <libeval/numeric_evaluator.h>
  30. /**
  31. * wxTextCtrl wrapper to handle math expression evaluation.
  32. *
  33. * Expressions are evaluated after the text control loses the focus. If user decides to modify
  34. * the expression, he will get the original expression to modify.
  35. */
  36. class TEXT_CTRL_EVAL : public wxTextCtrl
  37. {
  38. public:
  39. TEXT_CTRL_EVAL( wxWindow* aParent, wxWindowID aId, const wxString& aValue = wxEmptyString,
  40. const wxPoint& aPos = wxDefaultPosition, const wxSize& aSize = wxDefaultSize,
  41. long aStyle = 0, const wxValidator& aValidator = wxDefaultValidator,
  42. const wxString& aName = wxTextCtrlNameStr );
  43. virtual ~TEXT_CTRL_EVAL()
  44. {
  45. }
  46. /**
  47. * Set a new value in evaluator buffer and display it in the wxTextCtrl.
  48. *
  49. * @param aValue is the new value to store and display
  50. * if aValue is empty, the value "0" is stored and displayed
  51. */
  52. void SetValue( const wxString& aValue ) override;
  53. protected:
  54. /// Numeric expression evaluator.
  55. NUMERIC_EVALUATOR m_eval;
  56. void onTextFocusGet( wxFocusEvent& aEvent );
  57. void onTextFocusLost( wxFocusEvent& aEvent );
  58. void onTextEnter( wxCommandEvent& aEvent );
  59. void evaluate();
  60. };
  61. #endif /* TEXT_CTRL_EVAL_H */