cmCursesBoolWidget.cxx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmCursesBoolWidget.h"
  11. #include "cmCursesMainForm.h"
  12. cmCursesBoolWidget::cmCursesBoolWidget(int width, int height,
  13. int left, int top) :
  14. cmCursesWidget(width, height, left, top)
  15. {
  16. this->Type = cmState::BOOL;
  17. set_field_fore(this->Field, A_NORMAL);
  18. set_field_back(this->Field, A_STANDOUT);
  19. field_opts_off(this->Field, O_STATIC);
  20. this->SetValueAsBool(false);
  21. }
  22. bool cmCursesBoolWidget::HandleInput(int& key, cmCursesMainForm*, WINDOW* w)
  23. {
  24. // 10 == enter
  25. if (key == 10 || key == KEY_ENTER)
  26. {
  27. if (this->GetValueAsBool())
  28. {
  29. this->SetValueAsBool(false);
  30. }
  31. else
  32. {
  33. this->SetValueAsBool(true);
  34. }
  35. touchwin(w);
  36. wrefresh(w);
  37. return true;
  38. }
  39. else
  40. {
  41. return false;
  42. }
  43. }
  44. void cmCursesBoolWidget::SetValueAsBool(bool value)
  45. {
  46. if (value)
  47. {
  48. this->SetValue("ON");
  49. }
  50. else
  51. {
  52. this->SetValue("OFF");
  53. }
  54. }
  55. bool cmCursesBoolWidget::GetValueAsBool()
  56. {
  57. if (this->Value == "ON")
  58. {
  59. return true;
  60. }
  61. else
  62. {
  63. return false;
  64. }
  65. }