FLTKPropertyList.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. // FLTKPropertyList.cpp : implementation file
  2. //
  3. #include "FLTKPropertyList.h"
  4. #include "../cmCacheManager.h"
  5. #include "Fl/filename.H"
  6. #include "Fl/fl_file_chooser.H"
  7. #include "Fl/fl_color_chooser.H"
  8. #include "Fl/fl_ask.H"
  9. namespace fltk {
  10. /////////////////////////////////////////////////////////////////////////////
  11. // PropertyList
  12. PropertyList::PropertyList()
  13. {
  14. m_Dirty = false;
  15. m_curSel = -1;
  16. }
  17. PropertyList::~PropertyList()
  18. {
  19. for(std::set<PropertyItem*>::iterator i = m_PropertyItems.begin();
  20. i != m_PropertyItems.end(); ++i)
  21. {
  22. delete *i;
  23. }
  24. }
  25. int PropertyList::AddItem(string txt)
  26. {
  27. int nIndex =0;// = AddString(txt);
  28. return nIndex;
  29. }
  30. int PropertyList::AddPropItem(PropertyItem* pItem)
  31. {
  32. int nIndex =0; //= AddString(_T(""));
  33. // SetItemDataPtr(nIndex,pItem);
  34. m_PropertyItems.insert(pItem);
  35. return nIndex;
  36. }
  37. int PropertyList::AddProperty(const char* name,
  38. const char* value,
  39. const char* helpString,
  40. int type,
  41. const char* comboItems)
  42. {
  43. std::cout << "Adding property type: " << type;
  44. std::cout << " Name " << name;
  45. std::cout << " = " << value << std::endl;
  46. PropertyItem* pItem = 0;
  47. for(int i =0; i < this->GetCount(); ++i)
  48. {
  49. PropertyItem* item = this->GetItem(i);
  50. if(item->m_propName == name)
  51. {
  52. pItem = item;
  53. if(pItem->m_curValue != value)
  54. {
  55. pItem->m_curValue = value;
  56. pItem->m_HelpString = helpString;
  57. m_Dirty = true;
  58. Invalidate();
  59. }
  60. return i;
  61. }
  62. }
  63. // if it is not found, then create a new one
  64. if(!pItem)
  65. {
  66. pItem = new PropertyItem(name, value, helpString, type, comboItems);
  67. }
  68. return this->AddPropItem(pItem);
  69. }
  70. void PropertyList::OnButton()
  71. {
  72. PropertyItem* pItem = (PropertyItem*) GetItemDataPtr(m_curSel);
  73. //display the appropriate common dialog depending on what type
  74. //of chooser is associated with the property
  75. if (pItem->m_nItemType == PropertyList::COLOR)
  76. {
  77. unsigned char red = 0;
  78. unsigned char blue = 0;
  79. unsigned char green = 0;
  80. fl_color_chooser("Please pick a color",red,green,blue);
  81. char buffer[300];
  82. sprintf(buffer,"RGB(%d,%d,%d)",red,green,blue);
  83. pItem->m_curValue = buffer;
  84. m_Dirty = true;
  85. Invalidate();
  86. }
  87. else if (pItem->m_nItemType == PropertyList::FILE)
  88. {
  89. string currPath = pItem->m_curValue;
  90. const char * SelectedFile
  91. = fl_file_chooser("Choose a file",
  92. "*",currPath.c_str() );
  93. if( SelectedFile )
  94. {
  95. pItem->m_curValue = SelectedFile;
  96. m_Dirty = true;
  97. Invalidate();
  98. }
  99. }
  100. else if (pItem->m_nItemType == PropertyList::PATH)
  101. {
  102. string currPath = pItem->m_curValue;
  103. string initialDir = currPath;
  104. const char * SelectedFile
  105. = fl_file_chooser("Choose a directory",
  106. "*/",initialDir.c_str() );
  107. if( SelectedFile && filename_isdir( SelectedFile ) )
  108. {
  109. pItem->m_curValue = SelectedFile;
  110. m_Dirty = true;
  111. Invalidate();
  112. }
  113. }
  114. else if (pItem->m_nItemType == PropertyList::FONT)
  115. {
  116. }
  117. }
  118. void PropertyList::OnHelp()
  119. {
  120. if(m_curSel == -1 || this->GetCount() <= 0)
  121. {
  122. return;
  123. }
  124. PropertyItem* pItem = (PropertyItem*) GetItemDataPtr(m_curSel);
  125. fl_message(pItem->m_HelpString.c_str());
  126. }
  127. void PropertyList::RemoveAll()
  128. {
  129. int c = this->GetCount();
  130. for(int i =0; i < c; ++i)
  131. {
  132. PropertyItem* pItem = (PropertyItem*) GetItemDataPtr(0);
  133. cmCacheManager::GetInstance()->RemoveCacheEntry(pItem->m_propName.c_str());
  134. m_PropertyItems.erase(pItem);
  135. delete pItem;
  136. // this->DeleteString(0);
  137. }
  138. Invalidate();
  139. }
  140. PropertyItem * PropertyList::GetItemDataPtr(int index)
  141. {
  142. std::set<PropertyItem*>::iterator it = m_PropertyItems.begin();
  143. for(int i=0; it != m_PropertyItems.end() && i<index; i++)
  144. {
  145. ++it;
  146. }
  147. return *it;
  148. }
  149. PropertyItem * PropertyList::GetItem(int index)
  150. {
  151. std::set<PropertyItem*>::iterator it = m_PropertyItems.begin();
  152. for(int i=0; it != m_PropertyItems.end() && i<index; i++)
  153. {
  154. ++it;
  155. }
  156. return *it;
  157. }
  158. } // end fltk namespace