FLTKPropertyList.cxx 3.8 KB

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