cmCursesCacheEntryComposite.cxx 3.3 KB

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