// RevLookUpView.cpp : implementation file
//

#include "stdafx.h"
#include "Peeper.h"
#include "RevLookUpView.h"
#include "hnode.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CRevLookUpView

IMPLEMENT_DYNCREATE(CRevLookUpView, CTreeView)

CRevLookUpView::CRevLookUpView()
{
	m_dwDefaultStyle |= TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS;
}

CRevLookUpView::~CRevLookUpView()
{
}


BEGIN_MESSAGE_MAP(CRevLookUpView, CTreeView)
	//{{AFX_MSG_MAP(CRevLookUpView)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRevLookUpView drawing

void CRevLookUpView::OnDraw(CDC* pDC)
{
	CDocument* pDoc = GetDocument();
	// TODO: add draw code here
}

/////////////////////////////////////////////////////////////////////////////
// CRevLookUpView diagnostics

#ifdef _DEBUG
void CRevLookUpView::AssertValid() const
{
	CTreeView::AssertValid();
}

void CRevLookUpView::Dump(CDumpContext& dc) const
{
	CTreeView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CRevLookUpView message handlers

CPeeperDoc* CRevLookUpView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPeeperDoc)));
	return (CPeeperDoc*)m_pDocument;
}

void CRevLookUpView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
	GetTreeCtrl().DeleteAllItems();	
	if(pSender==this || lHint==NULL) return;
	
	HNode *node=(HNode *)lHint;

	CPeeperDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	
	node->FillReverseTree(&GetTreeCtrl(),TVI_ROOT);
	GetTreeCtrl().Expand(GetTreeCtrl().GetChildItem(TVI_ROOT),TVE_EXPAND);

	
}

void CRevLookUpView::ExpandAll(HTREEITEM itm)
{
if(itm==NULL) return;
	GetTreeCtrl().Expand(itm,TVE_EXPAND);
HTREEITEM nitm=GetTreeCtrl().GetChildItem(itm);
		
while(nitm!=NULL)
	{
	ExpandAll(nitm);
	nitm=GetTreeCtrl().GetNextSiblingItem(nitm);
	}

}


