Forráskód Böngészése

Class to manage the list of properties displayed on the scroller

Luis Ibanez 24 éve
szülő
commit
ee8859be70
2 módosított fájl, 314 hozzáadás és 0 törlés
  1. 196 0
      Source/FLTKDialog/FLTKPropertyList.cpp
  2. 118 0
      Source/FLTKDialog/FLTKPropertyList.h

+ 196 - 0
Source/FLTKDialog/FLTKPropertyList.cpp

@@ -0,0 +1,196 @@
+// FLTKPropertyList.cpp : implementation file
+//
+
+#include "FLTKPropertyList.h"
+#include "../cmCacheManager.h"
+#include "Fl/filename.H"
+#include "Fl/fl_file_chooser.H"
+#include "Fl/fl_color_chooser.H"
+#include "Fl/fl_ask.H"
+
+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);
+  m_PropertyItems.insert(pItem);
+  return nIndex;
+}
+
+int PropertyList::AddProperty(const char* name,
+                               const char* value,
+                               const char* helpString,
+                               int type,
+                               const char* comboItems)
+{ 
+  std::cout << "Adding property type: " << type;
+  std::cout << "  Name " << name;
+  std::cout << " = " << value << std::endl;
+
+  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
+
+
+

+ 118 - 0
Source/FLTKDialog/FLTKPropertyList.h

@@ -0,0 +1,118 @@
+#ifndef FLTKPROPERTYLIST_H
+#define FLTKPROPERTYLIST_H
+
+#include "../cmStandardIncludes.h"
+#include <string>
+
+
+namespace fltk {
+
+using std::string;
+
+/////////////////////////////////////////////////////////////////////////////
+//PropertyList Items
+class PropertyItem
+{
+// Attributes
+public:
+  string m_HelpString;
+  string m_propName;
+  string m_curValue;
+  int m_nItemType;
+  string m_cmbItems;
+  bool m_Removed;
+public:
+  PropertyItem(string propName, string curValue,
+                string helpString,
+                int nItemType, string cmbItems)
+    {
+      m_HelpString = helpString;
+      m_Removed = false;
+      m_propName = propName;
+      m_curValue = curValue;
+      m_nItemType = nItemType;
+      m_cmbItems = cmbItems;
+    }
+};
+
+/////////////////////////////////////////////////////////////////////////////
+// PropertyList window
+
+class PropertyList 
+{
+// Construction
+public:
+  enum ItemType 
+    {
+      COMBO = 0,
+      EDIT,
+      COLOR,
+      FONT,
+      FILE,
+      CHECKBOX,
+      PATH
+    };
+  PropertyList();
+  
+// Attributes
+public:
+
+// Operations
+public:
+  int AddItem(string txt);
+  int AddProperty(const char* name,
+                  const char* value,
+                  const char* helpString,
+                  int type,
+                  const char* comboItems);
+  std::set<PropertyItem*> GetItems() 
+    {
+      return m_PropertyItems;
+    }
+  void Invalidate(void) 
+  {
+    // fltk redraw();
+  }
+  
+  int GetCount(void) const 
+  {
+    return m_PropertyItems.size();
+  }
+  void OnButton(void);
+  void OnHelp(void);
+  void RemoveAll();
+  PropertyItem* GetItem(int index);
+  PropertyItem* GetItemDataPtr(int m_curSel);
+
+// Implementation
+public:
+  virtual ~PropertyList();
+
+  // Generated message map functions
+protected:
+
+  int AddPropItem(PropertyItem* pItem);
+
+//  CComboBox m_cmbBox;
+//  CEdit m_editBox;
+//  CButton m_btnCtrl;
+//  CButton m_CheckBoxControl;
+  
+
+  bool m_Dirty;
+  int m_curSel;
+  int m_prevSel;
+  int m_nDivider;
+  int m_nDivTop;
+  int m_nDivBtm;
+  int m_nOldDivX;
+  int m_nLastBox;
+
+  std::set<PropertyItem*> m_PropertyItems;
+
+};
+
+
+} // end namespace fltk
+
+#endif