cmCursesBoolWidget.cxx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "cmCursesBoolWidget.h"
  14. #include "cmCursesMainForm.h"
  15. cmCursesBoolWidget::cmCursesBoolWidget(int width, int height,
  16. int left, int top) :
  17. cmCursesWidget(width, height, left, top)
  18. {
  19. this->Type = cmCacheManager::BOOL;
  20. set_field_fore(this->Field, A_NORMAL);
  21. set_field_back(this->Field, A_STANDOUT);
  22. field_opts_off(this->Field, O_STATIC);
  23. this->SetValueAsBool(false);
  24. }
  25. bool cmCursesBoolWidget::HandleInput(int& key, cmCursesMainForm*, WINDOW* w)
  26. {
  27. // 10 == enter
  28. if (key == 10 || key == KEY_ENTER)
  29. {
  30. if (this->GetValueAsBool())
  31. {
  32. this->SetValueAsBool(false);
  33. }
  34. else
  35. {
  36. this->SetValueAsBool(true);
  37. }
  38. touchwin(w);
  39. wrefresh(w);
  40. return true;
  41. }
  42. else
  43. {
  44. return false;
  45. }
  46. }
  47. void cmCursesBoolWidget::SetValueAsBool(bool value)
  48. {
  49. if (value)
  50. {
  51. this->SetValue("ON");
  52. }
  53. else
  54. {
  55. this->SetValue("OFF");
  56. }
  57. }
  58. bool cmCursesBoolWidget::GetValueAsBool()
  59. {
  60. if (this->Value == "ON")
  61. {
  62. return true;
  63. }
  64. else
  65. {
  66. return false;
  67. }
  68. }