cmCursesBoolWidget.cxx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmCursesBoolWidget.h"
  4. #include "cmCursesWidget.h"
  5. #include "cmStateTypes.h"
  6. #include <string>
  7. cmCursesBoolWidget::cmCursesBoolWidget(int width, int height, int left,
  8. int top)
  9. : cmCursesWidget(width, height, left, top)
  10. {
  11. this->Type = cmStateEnums::BOOL;
  12. set_field_fore(this->Field, A_NORMAL);
  13. set_field_back(this->Field, A_STANDOUT);
  14. field_opts_off(this->Field, O_STATIC);
  15. this->SetValueAsBool(false);
  16. }
  17. bool cmCursesBoolWidget::HandleInput(int& key, cmCursesMainForm* /*fm*/,
  18. WINDOW* w)
  19. {
  20. // toggle boolean values with enter or space
  21. // 10 == enter
  22. if (key == 10 || key == KEY_ENTER || key == ' ') {
  23. if (this->GetValueAsBool()) {
  24. this->SetValueAsBool(false);
  25. } else {
  26. this->SetValueAsBool(true);
  27. }
  28. touchwin(w);
  29. wrefresh(w);
  30. return true;
  31. }
  32. return false;
  33. }
  34. void cmCursesBoolWidget::SetValueAsBool(bool value)
  35. {
  36. if (value) {
  37. this->SetValue("ON");
  38. } else {
  39. this->SetValue("OFF");
  40. }
  41. }
  42. bool cmCursesBoolWidget::GetValueAsBool()
  43. {
  44. return this->Value == "ON";
  45. }