Nodes now track their correct indentation levels (from the content model).

This commit is contained in:
hyatt%netscape.com 1998-12-10 00:21:44 +00:00
parent 64d2aeab3d
commit d446cfc376
6 changed files with 23 additions and 6 deletions

View File

@ -80,15 +80,21 @@ void nsHTDataModel::SetContentRootDelegate(nsIContent* pContent)
// Reconstruct our visibility list (so that all items that are visible // Reconstruct our visibility list (so that all items that are visible
// are instantiated). Need to only look for folder and item children. All other children should be ignored. // are instantiated). Need to only look for folder and item children. All other children should be ignored.
AddNodesToArray(mContentRoot); AddNodesToArray(mContentRoot, 0);
} }
void nsHTDataModel::AddNodesToArray(nsIContent* pContent) void nsHTDataModel::AddNodesToArray(nsIContent* pContent, PRUint32 indentLevel)
{ {
// Add this child to the array (unless it is the root node). // Add this child to the array (unless it is the root node).
nsHierarchicalDataItem* pDataItem = CreateDataItemWithContentNode(pContent); nsHierarchicalDataItem* pDataItem = CreateDataItemWithContentNode(pContent);
if (pContent != mContentRoot) if (pContent != mContentRoot)
{
// Add to our array
mVisibleItemArray.AppendElement(pDataItem); mVisibleItemArray.AppendElement(pDataItem);
// Set the correct indent level for the item.
pDataItem->SetIndentationLevel(indentLevel);
indentLevel++;
}
else mRootNode = pDataItem; else mRootNode = pDataItem;
nsHTItem* pItem = (nsHTItem*)(pDataItem->GetImplData()); nsHTItem* pItem = (nsHTItem*)(pDataItem->GetImplData());
@ -110,7 +116,7 @@ void nsHTDataModel::AddNodesToArray(nsIContent* pContent)
pContent->ChildAt(i, child); pContent->ChildAt(i, child);
if (child) if (child)
{ {
AddNodesToArray(child); AddNodesToArray(child, indentLevel);
} }
NS_IF_RELEASE(child); NS_IF_RELEASE(child);

View File

@ -65,7 +65,7 @@ public:
nsIImageGroup* GetImageGroup() const { NS_ADDREF(mImageGroup); return mImageGroup; } nsIImageGroup* GetImageGroup() const { NS_ADDREF(mImageGroup); return mImageGroup; }
protected: protected:
void AddNodesToArray(nsIContent* pContent); void AddNodesToArray(nsIContent* pContent, PRUint32 indentLevel);
// This recursive function is called to add nodes to the visibility array. // This recursive function is called to add nodes to the visibility array.
enum { cDMImageLoaded = 0 } ; enum { cDMImageLoaded = 0 } ;

View File

@ -26,6 +26,7 @@ nsHTItem::nsHTItem(nsIContent* pContent, nsHierarchicalDataModel* pDataModel)
NS_ADDREF(pContent); NS_ADDREF(pContent);
mContentNode = pContent; mContentNode = pContent;
mDataModel = pDataModel; mDataModel = pDataModel;
mIndentationLevel = 0;
} }
//-------------------------------------------------------------------- //--------------------------------------------------------------------
@ -41,7 +42,12 @@ PRBool nsHTItem::IsExpandedDelegate() const
PRUint32 nsHTItem::GetIndentationLevelDelegate() const PRUint32 nsHTItem::GetIndentationLevelDelegate() const
{ {
return 0; return mIndentationLevel;
}
void nsHTItem::SetIndentationLevelDelegate(PRUint32 n)
{
mIndentationLevel = n;
} }
nsIContent* nsHTItem::FindChildWithName(const nsString& name) const nsIContent* nsHTItem::FindChildWithName(const nsString& name) const

View File

@ -31,13 +31,15 @@ public:
virtual PRBool IsExpandedDelegate() const; virtual PRBool IsExpandedDelegate() const;
virtual PRUint32 GetIndentationLevelDelegate() const; virtual PRUint32 GetIndentationLevelDelegate() const;
virtual void SetIndentationLevelDelegate(PRUint32 n);
public: public:
nsIContent* FindChildWithName(const nsString& name) const; // Caller must release the content ptr. nsIContent* FindChildWithName(const nsString& name) const; // Caller must release the content ptr.
protected: protected:
nsHierarchicalDataModel* mDataModel; nsHierarchicalDataModel* mDataModel;
nsIContent* mContentNode; nsIContent* mContentNode;
PRUint32 mIndentationLevel;
}; };
#endif /* nsHTItem_h___ */ #endif /* nsHTItem_h___ */

View File

@ -56,6 +56,7 @@ public:
// the concrete implementation. // the concrete implementation.
virtual PRBool IsExpanded() const { return IsExpandedDelegate(); }; virtual PRBool IsExpanded() const { return IsExpandedDelegate(); };
virtual PRUint32 GetIndentationLevel() const { return GetIndentationLevelDelegate(); }; virtual PRUint32 GetIndentationLevel() const { return GetIndentationLevelDelegate(); };
virtual void SetIndentationLevel(PRUint32 n) { SetIndentationLevelDelegate(n); };
// End of delegated functions // End of delegated functions
virtual void GetItemStyle(nsIDeviceContext* dc, virtual void GetItemStyle(nsIDeviceContext* dc,

View File

@ -35,7 +35,9 @@ public:
virtual ~nsHierarchicalDataItem() {}; virtual ~nsHierarchicalDataItem() {};
virtual PRBool IsExpanded() const = 0; virtual PRBool IsExpanded() const = 0;
virtual PRUint32 GetIndentationLevel() const = 0; virtual PRUint32 GetIndentationLevel() const = 0;
virtual void SetIndentationLevel(PRUint32 n) = 0;
public: public:
void* GetImplData() { return mImplData; } void* GetImplData() { return mImplData; }