cmCursesCacheEntryComposite.cxx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 "cmCursesCacheEntryComposite.h"
  14. #include "cmCursesStringWidget.h"
  15. #include "cmCursesLabelWidget.h"
  16. #include "cmCursesBoolWidget.h"
  17. #include "cmCursesPathWidget.h"
  18. #include "cmCursesFilePathWidget.h"
  19. #include "cmCursesDummyWidget.h"
  20. #include "../cmSystemTools.h"
  21. cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(const char* key,
  22. int labelwidth,
  23. int entrywidth) :
  24. m_Key(key), m_LabelWidth(labelwidth), m_EntryWidth(entrywidth)
  25. {
  26. m_Label = new cmCursesLabelWidget(m_LabelWidth, 1, 1, 1, key);
  27. m_IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, " ");
  28. m_Entry = 0;
  29. }
  30. cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
  31. const char* key, const cmCacheManager::CacheIterator& it, bool isNew,
  32. int labelwidth, int entrywidth)
  33. : m_Key(key), m_LabelWidth(labelwidth), m_EntryWidth(entrywidth)
  34. {
  35. m_Label = new cmCursesLabelWidget(m_LabelWidth, 1, 1, 1, key);
  36. if (isNew)
  37. {
  38. m_IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, "*");
  39. }
  40. else
  41. {
  42. m_IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, " ");
  43. }
  44. m_Entry = 0;
  45. switch ( it.GetType() )
  46. {
  47. case cmCacheManager::BOOL:
  48. m_Entry = new cmCursesBoolWidget(m_EntryWidth, 1, 1, 1);
  49. if (cmSystemTools::IsOn(it.GetValue()))
  50. {
  51. static_cast<cmCursesBoolWidget*>(m_Entry)->SetValueAsBool(true);
  52. }
  53. else
  54. {
  55. static_cast<cmCursesBoolWidget*>(m_Entry)->SetValueAsBool(false);
  56. }
  57. break;
  58. case cmCacheManager::PATH:
  59. m_Entry = new cmCursesPathWidget(m_EntryWidth, 1, 1, 1);
  60. static_cast<cmCursesPathWidget*>(m_Entry)->SetString(
  61. it.GetValue());
  62. break;
  63. case cmCacheManager::FILEPATH:
  64. m_Entry = new cmCursesFilePathWidget(m_EntryWidth, 1, 1, 1);
  65. static_cast<cmCursesFilePathWidget*>(m_Entry)->SetString(
  66. it.GetValue());
  67. break;
  68. case cmCacheManager::STRING:
  69. m_Entry = new cmCursesStringWidget(m_EntryWidth, 1, 1, 1);
  70. static_cast<cmCursesStringWidget*>(m_Entry)->SetString(
  71. it.GetValue());
  72. break;
  73. case cmCacheManager::UNINITIALIZED:
  74. cmSystemTools::Error("Found an undefined variable: ", it.GetName());
  75. break;
  76. default:
  77. // TODO : put warning message here
  78. break;
  79. }
  80. }
  81. cmCursesCacheEntryComposite::~cmCursesCacheEntryComposite()
  82. {
  83. delete m_Label;
  84. delete m_IsNewLabel;
  85. delete m_Entry;
  86. }
  87. const char* cmCursesCacheEntryComposite::GetValue()
  88. {
  89. if (m_Label)
  90. {
  91. return m_Label->GetValue();
  92. }
  93. else
  94. {
  95. return 0;
  96. }
  97. }