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.

54 lines
1.5 KiB

  1. /*
  2. * Copyright (C) 2018 CERN
  3. * Author: Maciej Suminski <maciej.suminski@cern.ch>
  4. *
  5. * This program is free software: you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation, either version 3 of the License, or (at your
  8. * option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef ENABLER_H
  19. #define ENABLER_H
  20. #include <wx/window.h>
  21. /**
  22. * Simple class to automatically enable/disable widgets.
  23. *
  24. * As long as an ENABLER object exists, the handled widget will be kept in the requested state.
  25. */
  26. class ENABLER
  27. {
  28. public:
  29. /**
  30. * Constructor.
  31. *
  32. * @param aObject is the object to be temporarily enabled or disabled.
  33. * @param aState is the requested temporary state (true for enabled, false for disabled).
  34. */
  35. ENABLER( wxWindow& aObject, bool aState )
  36. : m_object( aObject ), m_state( aState )
  37. {
  38. m_object.Enable( m_state );
  39. }
  40. ~ENABLER()
  41. {
  42. m_object.Enable( !m_state );
  43. }
  44. private:
  45. wxWindow& m_object;
  46. bool m_state;
  47. };
  48. #endif /* ENABLER_H */