FLTKPropertyList.cxx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. // FLTKPropertyList.cxx : implementation file
  2. //
  3. #include "FLTKPropertyList.h"
  4. #include "../cmCacheManager.h"
  5. #include "FLTKPropertyItemRow.h"
  6. #include "FL/filename.H"
  7. #include "FL/fl_file_chooser.H"
  8. #include "FL/Fl_Color_Chooser.H"
  9. #include "FL/fl_ask.H"
  10. #include "FL/Fl_Button.H"
  11. #include "CMakeSetupGUIImplementation.h"
  12. namespace fltk {
  13. /////////////////////////////////////////////////////////////////////////////
  14. // PropertyList
  15. PropertyList::PropertyList( CMakeSetupGUIImplementation * cmakeSetup )
  16. {
  17. m_CMakeSetup = cmakeSetup;
  18. PropertyItemRow::SetCMakeSetupGUI( cmakeSetup );
  19. m_Dirty = false;
  20. }
  21. PropertyList::~PropertyList()
  22. {
  23. for(std::set<PropertyItem*>::iterator i = m_PropertyItems.begin();
  24. i != m_PropertyItems.end(); ++i)
  25. {
  26. delete *i;
  27. }
  28. }
  29. int PropertyList::AddItem( std::string txt)
  30. {
  31. int nIndex =0;
  32. return nIndex;
  33. }
  34. int PropertyList::AddPropItem(PropertyItem* pItem, bool reverseOrder)
  35. {
  36. int nIndex =0;
  37. if(reverseOrder)
  38. {
  39. nIndex = 0;
  40. }
  41. else
  42. {
  43. nIndex = m_PropertyItems.size();
  44. }
  45. new PropertyItemRow( pItem ); // GUI of the new property row
  46. m_PropertyItems.insert(pItem);
  47. return nIndex;
  48. }
  49. int PropertyList::AddProperty(const char* name,
  50. const char* value,
  51. const char* helpString,
  52. int type,
  53. const char* comboItems,
  54. bool reverseOrder)
  55. {
  56. PropertyItem* pItem = 0;
  57. for(int i =0; i < this->GetCount(); ++i)
  58. {
  59. PropertyItem* item = this->GetItem(i);
  60. if(item->m_propName == name)
  61. {
  62. pItem = item;
  63. if(pItem->m_curValue != value)
  64. {
  65. pItem->m_curValue = value;
  66. pItem->m_HelpString = helpString;
  67. Invalidate();
  68. }
  69. return i;
  70. }
  71. }
  72. // if it is not found, then create a new one
  73. if(!pItem)
  74. {
  75. pItem = new PropertyItem(name, value, helpString, type, comboItems);
  76. }
  77. return this->AddPropItem(pItem,reverseOrder);
  78. }
  79. void PropertyList::RemoveProperty(const char* name)
  80. {
  81. for(int i =0; i < this->GetCount(); ++i)
  82. {
  83. PropertyItem* pItem = (PropertyItem*) GetItemDataPtr(i);
  84. if(pItem->m_propName == name)
  85. {
  86. m_PropertyItems.erase(pItem);
  87. delete pItem;
  88. return;
  89. }
  90. }
  91. }
  92. void PropertyList::RemoveAll()
  93. {
  94. int c = this->GetCount();
  95. for(int i =0; i < c; ++i)
  96. {
  97. PropertyItem* pItem = (PropertyItem*) GetItemDataPtr(0);
  98. cmCacheManager::GetInstance()->RemoveCacheEntry(pItem->m_propName.c_str());
  99. m_PropertyItems.erase(pItem);
  100. delete pItem;
  101. }
  102. Invalidate();
  103. }
  104. PropertyItem * PropertyList::GetItemDataPtr(int index)
  105. {
  106. std::set<PropertyItem*>::iterator it = m_PropertyItems.begin();
  107. for(int i=0; it != m_PropertyItems.end() && i<index; i++)
  108. {
  109. ++it;
  110. }
  111. return *it;
  112. }
  113. PropertyItem * PropertyList::GetItem(int index)
  114. {
  115. std::set<PropertyItem*>::iterator it = m_PropertyItems.begin();
  116. for(int i=0; it != m_PropertyItems.end() && i<index; i++)
  117. {
  118. ++it;
  119. }
  120. return *it;
  121. }
  122. void
  123. PropertyList
  124. ::InvalidateList(void)
  125. {
  126. Invalidate();
  127. m_Dirty = true;
  128. }
  129. } // end fltk namespace