cmCursesCacheEntryComposite.cxx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmCursesCacheEntryComposite.h"
  11. #include "cmCursesOptionsWidget.h"
  12. #include "cmCursesStringWidget.h"
  13. #include "cmCursesLabelWidget.h"
  14. #include "cmCursesBoolWidget.h"
  15. #include "cmCursesPathWidget.h"
  16. #include "cmCursesFilePathWidget.h"
  17. #include "cmCursesDummyWidget.h"
  18. #include "../cmSystemTools.h"
  19. cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(const char* key,
  20. int labelwidth,
  21. int entrywidth) :
  22. Key(key), LabelWidth(labelwidth), EntryWidth(entrywidth)
  23. {
  24. this->Label = new cmCursesLabelWidget(this->LabelWidth, 1, 1, 1, key);
  25. this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, " ");
  26. this->Entry = 0;
  27. this->Entry = new cmCursesStringWidget(this->EntryWidth, 1, 1, 1);
  28. }
  29. cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
  30. const char* key, const cmCacheManager::CacheIterator& it, bool isNew,
  31. int labelwidth, int entrywidth)
  32. : Key(key), LabelWidth(labelwidth), EntryWidth(entrywidth)
  33. {
  34. this->Label = new cmCursesLabelWidget(this->LabelWidth, 1, 1, 1, key);
  35. if (isNew)
  36. {
  37. this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, "*");
  38. }
  39. else
  40. {
  41. this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, " ");
  42. }
  43. this->Entry = 0;
  44. switch ( it.GetType() )
  45. {
  46. case cmCacheManager::BOOL:
  47. this->Entry = new cmCursesBoolWidget(this->EntryWidth, 1, 1, 1);
  48. if (cmSystemTools::IsOn(it.GetValue()))
  49. {
  50. static_cast<cmCursesBoolWidget*>(this->Entry)->SetValueAsBool(true);
  51. }
  52. else
  53. {
  54. static_cast<cmCursesBoolWidget*>(this->Entry)->SetValueAsBool(false);
  55. }
  56. break;
  57. case cmCacheManager::PATH:
  58. this->Entry = new cmCursesPathWidget(this->EntryWidth, 1, 1, 1);
  59. static_cast<cmCursesPathWidget*>(this->Entry)->SetString(
  60. it.GetValue());
  61. break;
  62. case cmCacheManager::FILEPATH:
  63. this->Entry = new cmCursesFilePathWidget(this->EntryWidth, 1, 1, 1);
  64. static_cast<cmCursesFilePathWidget*>(this->Entry)->SetString(
  65. it.GetValue());
  66. break;
  67. case cmCacheManager::STRING:
  68. if(it.PropertyExists("STRINGS"))
  69. {
  70. cmCursesOptionsWidget* ow =
  71. new cmCursesOptionsWidget(this->EntryWidth, 1, 1, 1);
  72. this->Entry = ow;
  73. std::vector<std::string> options;
  74. cmSystemTools::ExpandListArgument(
  75. std::string(it.GetProperty("STRINGS")), options);
  76. for(std::vector<std::string>::iterator
  77. si = options.begin(); si != options.end(); ++si)
  78. {
  79. ow->AddOption(*si);
  80. }
  81. ow->SetOption(it.GetValue());
  82. }
  83. else
  84. {
  85. this->Entry = new cmCursesStringWidget(this->EntryWidth, 1, 1, 1);
  86. static_cast<cmCursesStringWidget*>(this->Entry)->SetString(
  87. it.GetValue());
  88. }
  89. break;
  90. case cmCacheManager::UNINITIALIZED:
  91. cmSystemTools::Error("Found an undefined variable: ", it.GetName());
  92. break;
  93. default:
  94. // TODO : put warning message here
  95. break;
  96. }
  97. }
  98. cmCursesCacheEntryComposite::~cmCursesCacheEntryComposite()
  99. {
  100. delete this->Label;
  101. delete this->IsNewLabel;
  102. delete this->Entry;
  103. }
  104. const char* cmCursesCacheEntryComposite::GetValue()
  105. {
  106. if (this->Label)
  107. {
  108. return this->Label->GetValue();
  109. }
  110. else
  111. {
  112. return 0;
  113. }
  114. }