diff options
author | Luis Ibanez <luis.ibanez@kitware.com> | 2001-06-10 22:21:55 (GMT) |
---|---|---|
committer | Luis Ibanez <luis.ibanez@kitware.com> | 2001-06-10 22:21:55 (GMT) |
commit | b0befbde1ae69c8625af763b0bb757557345c15b (patch) | |
tree | df28cced72496b83329488e3bb3cb84dea32fa31 /Source/FLTKDialog/FLTKPropertyList.cxx | |
parent | ad0019a740413ad270df38232ddcb31120c1b540 (diff) | |
download | CMake-b0befbde1ae69c8625af763b0bb757557345c15b.zip CMake-b0befbde1ae69c8625af763b0bb757557345c15b.tar.gz CMake-b0befbde1ae69c8625af763b0bb757557345c15b.tar.bz2 |
ENH: cpp renamed cxx. Copy of data to and from the GUI is working
Diffstat (limited to 'Source/FLTKDialog/FLTKPropertyList.cxx')
-rw-r--r-- | Source/FLTKDialog/FLTKPropertyList.cxx | 201 |
1 files changed, 201 insertions, 0 deletions
diff --git a/Source/FLTKDialog/FLTKPropertyList.cxx b/Source/FLTKDialog/FLTKPropertyList.cxx new file mode 100644 index 0000000..7efbf24 --- /dev/null +++ b/Source/FLTKDialog/FLTKPropertyList.cxx @@ -0,0 +1,201 @@ +// FLTKPropertyList.cxx : implementation file +// + +#include "FLTKPropertyList.h" +#include "../cmCacheManager.h" +#include "FLTKPropertyItemRow.h" +#include "Fl/filename.H" +#include "Fl/fl_file_chooser.H" +#include "Fl/Fl_Color_Chooser.H" +#include "Fl/fl_ask.H" +#include "Fl/Fl_Button.H" +#include <cstdio> + +namespace fltk { + +///////////////////////////////////////////////////////////////////////////// +// PropertyList + +PropertyList::PropertyList() +{ + m_Dirty = false; + m_curSel = -1; +} + +PropertyList::~PropertyList() +{ + for(std::set<PropertyItem*>::iterator i = m_PropertyItems.begin(); + i != m_PropertyItems.end(); ++i) + { + delete *i; + } +} + + + + +int PropertyList::AddItem(string txt) +{ + int nIndex =0;// = AddString(txt); + return nIndex; +} + +int PropertyList::AddPropItem(PropertyItem* pItem) +{ + + int nIndex =0; //= AddString(_T("")); + // SetItemDataPtr(nIndex,pItem); + + new PropertyItemRow( pItem ); // GUI of the property row + + m_PropertyItems.insert(pItem); + + return nIndex; +} + +int PropertyList::AddProperty(const char* name, + const char* value, + const char* helpString, + int type, + const char* comboItems) +{ + + PropertyItem* pItem = 0; + for(int i =0; i < this->GetCount(); ++i) + { + PropertyItem* item = this->GetItem(i); + if(item->m_propName == name) + { + pItem = item; + if(pItem->m_curValue != value) + { + pItem->m_curValue = value; + pItem->m_HelpString = helpString; + m_Dirty = true; + Invalidate(); + } + return i; + } + } + // if it is not found, then create a new one + if(!pItem) + { + pItem = new PropertyItem(name, value, helpString, type, comboItems); + } + return this->AddPropItem(pItem); +} + + + + +void PropertyList::OnButton() +{ + PropertyItem* pItem = (PropertyItem*) GetItemDataPtr(m_curSel); + + //display the appropriate common dialog depending on what type + //of chooser is associated with the property + if (pItem->m_nItemType == PropertyList::COLOR) + { + unsigned char red = 0; + unsigned char blue = 0; + unsigned char green = 0; + fl_color_chooser("Please pick a color",red,green,blue); + char buffer[300]; + sprintf(buffer,"RGB(%d,%d,%d)",red,green,blue); + pItem->m_curValue = buffer; + m_Dirty = true; + Invalidate(); + } + else if (pItem->m_nItemType == PropertyList::FILE) + { + string currPath = pItem->m_curValue; + + const char * SelectedFile + = fl_file_chooser("Choose a file", + "*",currPath.c_str() ); + + if( SelectedFile ) + { + pItem->m_curValue = SelectedFile; + m_Dirty = true; + Invalidate(); + } + } + else if (pItem->m_nItemType == PropertyList::PATH) + { + string currPath = pItem->m_curValue; + string initialDir = currPath; + + const char * SelectedFile + = fl_file_chooser("Choose a directory", + "*/",initialDir.c_str() ); + + if( SelectedFile && filename_isdir( SelectedFile ) ) + { + pItem->m_curValue = SelectedFile; + m_Dirty = true; + Invalidate(); + } + } + else if (pItem->m_nItemType == PropertyList::FONT) + { + } +} + + + + +void PropertyList::OnHelp() +{ + if(m_curSel == -1 || this->GetCount() <= 0) + { + return; + } + PropertyItem* pItem = (PropertyItem*) GetItemDataPtr(m_curSel); + fl_message(pItem->m_HelpString.c_str()); +} + + +void PropertyList::RemoveAll() +{ + int c = this->GetCount(); + for(int i =0; i < c; ++i) + { + PropertyItem* pItem = (PropertyItem*) GetItemDataPtr(0); + cmCacheManager::GetInstance()->RemoveCacheEntry(pItem->m_propName.c_str()); + m_PropertyItems.erase(pItem); + delete pItem; + // this->DeleteString(0); + } + Invalidate(); +} + + + +PropertyItem * PropertyList::GetItemDataPtr(int index) +{ + std::set<PropertyItem*>::iterator it = m_PropertyItems.begin(); + for(int i=0; it != m_PropertyItems.end() && i<index; i++) + { + ++it; + } + return *it; +} + + +PropertyItem * PropertyList::GetItem(int index) +{ + std::set<PropertyItem*>::iterator it = m_PropertyItems.begin(); + for(int i=0; it != m_PropertyItems.end() && i<index; i++) + { + ++it; + } + return *it; +} + + + +} // end fltk namespace + + + |