cmCursesCacheEntryComposite.cxx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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(
  20. const std::string& key,
  21. int labelwidth,
  22. int entrywidth) :
  23. Key(key), LabelWidth(labelwidth), EntryWidth(entrywidth)
  24. {
  25. this->Label = new cmCursesLabelWidget(this->LabelWidth, 1, 1, 1, key);
  26. this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, " ");
  27. this->Entry = 0;
  28. this->Entry = new cmCursesStringWidget(this->EntryWidth, 1, 1, 1);
  29. }
  30. cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
  31. const std::string& 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().c_str()))
  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. if(it.PropertyExists("STRINGS"))
  70. {
  71. cmCursesOptionsWidget* ow =
  72. new cmCursesOptionsWidget(this->EntryWidth, 1, 1, 1);
  73. this->Entry = ow;
  74. std::vector<std::string> options;
  75. cmSystemTools::ExpandListArgument(
  76. std::string(it.GetProperty("STRINGS")), options);
  77. for(std::vector<std::string>::iterator
  78. si = options.begin(); si != options.end(); ++si)
  79. {
  80. ow->AddOption(*si);
  81. }
  82. ow->SetOption(it.GetValue());
  83. }
  84. else
  85. {
  86. this->Entry = new cmCursesStringWidget(this->EntryWidth, 1, 1, 1);
  87. static_cast<cmCursesStringWidget*>(this->Entry)->SetString(
  88. it.GetValue());
  89. }
  90. break;
  91. case cmCacheManager::UNINITIALIZED:
  92. cmSystemTools::Error("Found an undefined variable: ",
  93. it.GetName().c_str());
  94. break;
  95. default:
  96. // TODO : put warning message here
  97. break;
  98. }
  99. }
  100. cmCursesCacheEntryComposite::~cmCursesCacheEntryComposite()
  101. {
  102. delete this->Label;
  103. delete this->IsNewLabel;
  104. delete this->Entry;
  105. }
  106. const char* cmCursesCacheEntryComposite::GetValue()
  107. {
  108. if (this->Label)
  109. {
  110. return this->Label->GetValue();
  111. }
  112. else
  113. {
  114. return 0;
  115. }
  116. }