cmCursesCacheEntryComposite.cxx 3.3 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. Key(key), LabelWidth(labelwidth), EntryWidth(entrywidth)
  25. {
  26. this->Label = new cmCursesLabelWidget(this->LabelWidth, 1, 1, 1, key);
  27. this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, " ");
  28. this->Entry = 0;
  29. }
  30. cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
  31. const char* key, const cmCacheManager::CacheIterator& it, bool isNew,
  32. int labelwidth, int entrywidth)
  33. : Key(key), LabelWidth(labelwidth), EntryWidth(entrywidth)
  34. {
  35. this->Label = new cmCursesLabelWidget(this->LabelWidth, 1, 1, 1, key);
  36. if (isNew)
  37. {
  38. this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, "*");
  39. }
  40. else
  41. {
  42. this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, " ");
  43. }
  44. this->Entry = 0;
  45. switch ( it.GetType() )
  46. {
  47. case cmCacheManager::BOOL:
  48. this->Entry = new cmCursesBoolWidget(this->EntryWidth, 1, 1, 1);
  49. if (cmSystemTools::IsOn(it.GetValue()))
  50. {
  51. static_cast<cmCursesBoolWidget*>(this->Entry)->SetValueAsBool(true);
  52. }
  53. else
  54. {
  55. static_cast<cmCursesBoolWidget*>(this->Entry)->SetValueAsBool(false);
  56. }
  57. break;
  58. case cmCacheManager::PATH:
  59. this->Entry = new cmCursesPathWidget(this->EntryWidth, 1, 1, 1);
  60. static_cast<cmCursesPathWidget*>(this->Entry)->SetString(
  61. it.GetValue());
  62. break;
  63. case cmCacheManager::FILEPATH:
  64. this->Entry = new cmCursesFilePathWidget(this->EntryWidth, 1, 1, 1);
  65. static_cast<cmCursesFilePathWidget*>(this->Entry)->SetString(
  66. it.GetValue());
  67. break;
  68. case cmCacheManager::STRING:
  69. this->Entry = new cmCursesStringWidget(this->EntryWidth, 1, 1, 1);
  70. static_cast<cmCursesStringWidget*>(this->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 this->Label;
  84. delete this->IsNewLabel;
  85. delete this->Entry;
  86. }
  87. const char* cmCursesCacheEntryComposite::GetValue()
  88. {
  89. if (this->Label)
  90. {
  91. return this->Label->GetValue();
  92. }
  93. else
  94. {
  95. return 0;
  96. }
  97. }