cmCursesBoolWidget.cxx 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "cmCursesBoolWidget.h"
  2. #include "cmCursesMainForm.h"
  3. cmCursesBoolWidget::cmCursesBoolWidget(int width, int height,
  4. int left, int top) :
  5. cmCursesWidget(width, height, left, top)
  6. {
  7. m_Type = cmCacheManager::BOOL;
  8. set_field_fore(m_Field, A_NORMAL);
  9. set_field_back(m_Field, A_STANDOUT);
  10. field_opts_off(m_Field, O_STATIC);
  11. this->SetValueAsBool(false);
  12. }
  13. bool cmCursesBoolWidget::HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w)
  14. {
  15. // 10 == enter
  16. if (key == 10 || key == KEY_ENTER)
  17. {
  18. if (this->GetValueAsBool())
  19. {
  20. this->SetValueAsBool(false);
  21. }
  22. else
  23. {
  24. this->SetValueAsBool(true);
  25. }
  26. touchwin(w);
  27. wrefresh(w);
  28. return true;
  29. }
  30. else
  31. {
  32. return false;
  33. }
  34. }
  35. void cmCursesBoolWidget::SetValueAsBool(bool value)
  36. {
  37. if (value)
  38. {
  39. this->SetValue("ON");
  40. }
  41. else
  42. {
  43. this->SetValue("OFF");
  44. }
  45. }
  46. bool cmCursesBoolWidget::GetValueAsBool()
  47. {
  48. if (m_Value == "ON")
  49. {
  50. return true;
  51. }
  52. else
  53. {
  54. return false;
  55. }
  56. }