// TreeCtrlPro.cpp : implementation file
//

#include "stdafx.h"
#include "pixelwhippro.h"
#include "TreeCtrlPro.h"


/////////////////////////////////////////////////////////////////////////////
// CTreeCtrlPro

CTreeCtrlPro::CTreeCtrlPro()
{
	NeedUpdate=false;
}

CTreeCtrlPro::~CTreeCtrlPro()
{
}


BEGIN_MESSAGE_MAP(CTreeCtrlPro, CTreeCtrl)
//{{AFX_MSG_MAP(CTreeCtrlPro)
ON_WM_LBUTTONUP()
ON_WM_LBUTTONDOWN()
ON_NOTIFY_REFLECT(TVN_SELCHANGING, OnSelchanging)
ON_WM_MOUSEMOVE()
ON_WM_HSCROLL()
ON_WM_VSCROLL()
ON_WM_MOUSEWHEEL()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTreeCtrlPro message handlers

void CTreeCtrlPro::OnLButtonUp(UINT nFlags, CPoint point) 
{
	CTreeCtrl::OnLButtonUp(nFlags, point);
}

void CTreeCtrlPro::OnLButtonDown(UINT nFlags, CPoint point) 
{
	UINT pFlags; 
	HTREEITEM itm;
	itm=HitTest(point,&pFlags);
	if(pFlags==TVHT_ONITEMSTATEICON) 
	{
		SetCheck(itm,!GetCheck(itm));
		NMHDR nmhdr;
		nmhdr.hwndFrom=m_hWnd;
		nmhdr.idFrom=GetDlgCtrlID();
		nmhdr.code=NM_CLICK;
		
		GetParent()->SendMessage(WM_NOTIFY,GetDlgCtrlID(),(DWORD)&nmhdr);
	}
	else 
		CTreeCtrl::OnLButtonDown(nFlags, point);
}

LRESULT CTreeCtrlPro::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
{
	switch(message)
	{
	case WM_LBUTTONUP:
		
		break;
	}
	
	return CTreeCtrl::WindowProc(message, wParam, lParam);
}

void CTreeCtrlPro::OnSelchanging(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
	// TODO: Add your control notification handler code here
	
	*pResult = 0;
}

void CTreeCtrlPro::OnMouseMove(UINT nFlags, CPoint point) 
{
	
	CTreeCtrl::OnMouseMove(nFlags, point);
}

void CTreeCtrlPro::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	CTreeCtrl::OnHScroll(nSBCode, nPos, pScrollBar);
	GetParent()->SendMessage(WM_HSCROLL,nSBCode|(nPos<<16),(DWORD)m_hWnd);
	
}

void CTreeCtrlPro::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	
	CTreeCtrl::OnVScroll(nSBCode, nPos, pScrollBar);
	GetParent()->SendMessage(WM_VSCROLL,nSBCode|(nPos<<16),(DWORD)m_hWnd);
}

BOOL CTreeCtrlPro::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt) 
{
	BOOL res;	
	res=CTreeCtrl::OnMouseWheel(nFlags, zDelta, pt);
	GetParent()->SendMessage(WM_VSCROLL,0,(DWORD)m_hWnd);
	return res;
}

void CTreeCtrlPro::ExpandBranch(HTREEITEM nde)
{
	if(nde==NULL) return;
	Expand(nde,TVE_EXPAND);
	
	HTREEITEM itm;
	itm=GetChildItem(nde);
	
	while(itm!=NULL)
	{
		ExpandBranch(itm);
		itm=GetNextSiblingItem(itm);
	}
	
}
