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.

86 lines
2.3 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2014-2015 CERN
  5. * Author: Maciej Suminski <maciej.suminski@cern.ch>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #include <wx/stattext.h>
  25. #include <wx/sizer.h>
  26. #include <wx/textctrl.h>
  27. #include <limits>
  28. #include <base_units.h>
  29. #include <wx/valnum.h>
  30. #include <boost/optional.hpp>
  31. #include "wx_unit_binder.h"
  32. WX_UNIT_BINDER::WX_UNIT_BINDER( wxWindow* aParent, wxTextCtrl* aTextInput,
  33. wxStaticText* aUnitLabel, wxSpinButton* aSpinButton ) :
  34. m_textCtrl( aTextInput ),
  35. m_unitLabel( aUnitLabel ),
  36. m_units( g_UserUnit ),
  37. m_step( 1 ),
  38. m_min( 0 ),
  39. m_max( 1 )
  40. {
  41. // Use the currently selected units
  42. m_textCtrl->SetValue( wxT( "0" ) );
  43. m_unitLabel->SetLabel( GetAbbreviatedUnitsLabel( m_units ) );
  44. }
  45. WX_UNIT_BINDER::~WX_UNIT_BINDER()
  46. {
  47. }
  48. void WX_UNIT_BINDER::SetValue( int aValue )
  49. {
  50. wxString s = StringFromValue( m_units, aValue, false );
  51. m_textCtrl->SetValue( s );
  52. m_unitLabel->SetLabel( GetAbbreviatedUnitsLabel( m_units ) );
  53. }
  54. int WX_UNIT_BINDER::GetValue() const
  55. {
  56. wxString s = m_textCtrl->GetValue();
  57. return ValueFromString( m_units, s );
  58. }
  59. bool WX_UNIT_BINDER::Valid() const
  60. {
  61. double dummy;
  62. return m_textCtrl->GetValue().ToDouble( &dummy );
  63. }
  64. void WX_UNIT_BINDER::Enable( bool aEnable )
  65. {
  66. m_textCtrl->Enable( aEnable );
  67. m_unitLabel->Enable( aEnable );
  68. }