home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 8090 / ModelEdit.7z / ltwintreeitem.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2006-03-08  |  2.7 KB  |  120 lines

  1. #include "ltwintreeitem.h"
  2. #include "ltwintreeitemiter.h"
  3.  
  4. //default constructor
  5. CLTWinTreeItem::CLTWinTreeItem(const char* pszText, CLTWinTreeIcon Icon) :
  6.     m_pNextSibling(NULL),
  7.     m_pFirstChild(NULL),
  8.     m_pPrevSibling(NULL),
  9.     m_pParent(NULL),
  10.     m_sText(pszText),
  11.     m_Icon(Icon),
  12.     m_bEditText(TRUE),
  13.     m_bSelected(FALSE)
  14. {
  15. }
  16.  
  17. //deault destructor
  18. CLTWinTreeItem::~CLTWinTreeItem()
  19. {
  20. }
  21.  
  22. //creates an iterator that iterates through all the siblings, starting
  23. //with this current tree item. NOTE: the callee is responsible for
  24. //deleting the iterator
  25. CLTWinTreeItemIter* CLTWinTreeItem::CreateSiblingIter()
  26. {
  27.     return new CLTWinTreeItemIter(this);
  28. }
  29.  
  30. //crates an iterator that iterates through all the children, starting
  31. //with the first child. NOTE: the callee is responsible for
  32. //deleting the iterator
  33. CLTWinTreeItemIter* CLTWinTreeItem::CreateChildIter()
  34. {
  35.     return new CLTWinTreeItemIter(m_pFirstChild);
  36. }
  37.  
  38. //used for finding equal items
  39. BOOL CLTWinTreeItem::operator==(const CLTWinTreeItem& rhs) const
  40. {
  41.     return (GetType() == rhs.GetType()) ? TRUE : FALSE;
  42. }
  43.  
  44. //gets the unique identifier for the type of item this is
  45. DWORD CLTWinTreeItem::GetType() const
  46. {
  47.     return BASE_ITEM;
  48. }
  49.  
  50. //determines if this item is selected or not
  51. BOOL CLTWinTreeItem::IsSelected() const
  52. {
  53.     return m_bSelected;
  54. }
  55.  
  56. //gets the text associated with the item
  57. const char* CLTWinTreeItem::GetText() const
  58. {
  59.     return (const char*)m_sText;
  60. }
  61.  
  62. //returns the index to the icon associated with this item
  63. CLTWinTreeIcon    CLTWinTreeItem::GetIcon() const
  64. {
  65.     return m_Icon;
  66. }
  67.  
  68. //determines if this is a valid drop target for the passed in item
  69. BOOL CLTWinTreeItem::IsDropTarget(const CLTWinTreeItem* pItem) const
  70. {
  71.     return TRUE;
  72. }
  73.  
  74.  
  75. //determines if the text can be modified by the user
  76. BOOL CLTWinTreeItem::IsTextEditable() const
  77. {
  78.     return m_bEditText;
  79. }
  80.  
  81. //sets whether or not the text is modifiable
  82. void CLTWinTreeItem::SetTextEditable(BOOL bEditable)
  83. {
  84.     m_bEditText = bEditable;
  85. }
  86.  
  87. //determines if this object is, or contains the object as a child
  88. BOOL CLTWinTreeItem::ContainsObject(const CLTWinTreeItem* pItem)
  89. {
  90.     //see if this object is the passed in one
  91.     if(this == pItem)
  92.     {
  93.         return TRUE;
  94.     }
  95.  
  96.     //it isn't, go through the children
  97.     CLTWinTreeItemIter* pIter = CreateChildIter();
  98.  
  99.     //check to make sure iterator is valid
  100.     if(pIter == FALSE)
  101.     {
  102.         return FALSE;
  103.     }
  104.  
  105.     for(; pIter->IsMore(); pIter->Next())
  106.     {
  107.         //see if this child contains it
  108.         if(pIter->Current()->ContainsObject(pItem))
  109.         {
  110.             //it does, so clean up and bail
  111.             delete pIter;
  112.             return TRUE;
  113.         }
  114.     }
  115.  
  116.     //couldn't find the item, clean up and bail
  117.     delete pIter;
  118.     return FALSE;
  119. }
  120.