cmCursesBoolWidget.cxx 1004 B

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