Click here to Skip to main content
12,635,671 members (26,143 online)
Click here to Skip to main content

Stats

104.6K views
4.5K downloads
35 bookmarked
Posted

Tree control templates

, 11 Jun 2001 CPOL
Three tree control templates to easily operate with CTreeCtrl derived objects
/////////////////////////////////////////////////////////////////////
// Template: TTCIterator
// Purpose : Template to iterate all the elements of a CTreeCtrl
//				derived object
// Created : SEN (1- Jun - 2001)
// History : None
// 
// Copyright (c) 2001 by Francisco Jos� Sen del Prado
// All rights reserved.
/////////////////////////////////////////////////////////////////////


// TCIterator.h : header file
//

#if !defined(_TCITERATOR_H__INCLUDED_)
#define _TCITERATOR_H__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifndef __AFXTEMPL_H__
	#pragma message ("To avoid this warning message place #include <afxtempl.h> in your stdafx.h precompiler headers file")
	#include <afxtempl.h>
#endif

/////////////////////////////////////////////////////////////////////////////
// TTCIterator (Declaration)

template <class T>
class TTCIterator : public T
{
public:
// Construction
	TTCIterator();

// Operations
public:
	void Initialize(bool bDeepIteration= true);

	HTREEITEM GetNext();

// Implementation
private:
	bool m_bDeepIteration;

	CList<HTREEITEM, HTREEITEM> m_hlTail;
};


/////////////////////////////////////////////////////////////////////////////
// TTCIterator (Implementation)

template <class T>
TTCIterator<T>::TTCIterator()
{
	m_bDeepIteration= true;
}

template <class T>
void TTCIterator<T>::Initialize(bool bDeepIteration)
{
	m_bDeepIteration= bDeepIteration;

	m_hlTail.AddTail(GetRootItem());
}

template <class T>
HTREEITEM TTCIterator<T>::GetNext()
{
	HTREEITEM htiRet= NULL;

	if (m_hlTail.GetHeadPosition() != NULL)
	{
		htiRet= m_hlTail.GetHead();
		
		m_hlTail.RemoveHead();

		// Siblings
		if (GetNextSiblingItem(htiRet) != NULL)
			m_hlTail.AddHead(GetNextSiblingItem(htiRet));

		// Children
		if (ItemHasChildren(htiRet))
		{
			if (m_bDeepIteration)
				m_hlTail.AddHead(GetChildItem(htiRet));
			else
				m_hlTail.AddTail(GetChildItem(htiRet));
		}
	}

	return htiRet;
}

#endif // !defined(_TCITERATOR_H__INCLUDED_)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Francisco José Sen del Prado
Software Developer (Senior)
Spain Spain
I started programming in Basic language when I was 14 years old. The second programming language I learned was Z80 assembler. I've been programming with C++ for the last 20 years. I attended the 2012 C++ Now event in Aspen and it was the most exciting experience I've lived in my professional life. I met a lot of brilliant C++ minds and I have very good memories from that trip.

You may also be interested in...

Pro
Pro
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161208.2 | Last Updated 12 Jun 2001
Article Copyright 2001 by Francisco José Sen del Prado
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid