www.pudn.com > MiniFox.rar > AccMgrTreeView.cpp


// AccMgrTreeView.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "MiniFox.h" 
#include "AccMgrTreeView.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
typedef CTypedPtrList < CObList, CBox* > BoxList; 
extern CTypedPtrList< CObList, CAccProfile* > gAccList; 
extern CFile accountsFile; 
 
///////////////////////////////////////////////////////////////////////////// 
// CAccMgrTreeView 
 
IMPLEMENT_DYNCREATE(CAccMgrTreeView, CTreeView) 
 
CAccMgrTreeView::CAccMgrTreeView() 
{ 
} 
 
CAccMgrTreeView::~CAccMgrTreeView() 
{ 
} 
 
 
BEGIN_MESSAGE_MAP(CAccMgrTreeView, CTreeView) 
	//{{AFX_MSG_MAP(CAccMgrTreeView) 
		// NOTE - the ClassWizard will add and remove mapping macros here. 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CAccMgrTreeView drawing 
 
void CAccMgrTreeView::OnDraw(CDC* pDC) 
{ 
	CDocument* pDoc = GetDocument(); 
	// TODO: add draw code here 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CAccMgrTreeView diagnostics 
 
#ifdef _DEBUG 
void CAccMgrTreeView::AssertValid() const 
{ 
	CTreeView::AssertValid(); 
} 
 
void CAccMgrTreeView::Dump(CDumpContext& dc) const 
{ 
	CTreeView::Dump(dc); 
} 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CAccMgrTreeView message handlers 
 
void CAccMgrTreeView::OnInitialUpdate()  
{ 
	CTreeView::OnInitialUpdate(); 
	 
	GetTreeCtrl().ModifyStyle( NULL,  
		TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT | 
		TVS_EDITLABELS | TVS_SHOWSELALWAYS ); 
 
	// Create a image list: 
	m_imageList.Create( IDB_ACCOUNTTREE, 16, 0, RGB( 255, 0, 255 ) ); 
 
	// Set the tree control's image list: 
	GetTreeCtrl().SetImageList( &m_imageList, TVSIL_NORMAL ); 
} 
 
 
//////////////////////////////////////////////////////////////////////////////////////// 
/// Retrieve data in AccountMgr class object to populate the tree.  
void CAccMgrTreeView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)  
{ 
	CTreeCtrl& treeCtrl = GetTreeCtrl(); 
	treeCtrl.DeleteAllItems(); 
 
// If there is no account, it's no need displaying anything in the tree view pane. 
	if( !gAccList.GetCount() ) 
		return; 
 
// Insert item into the tree view control: 
	POSITION pos; 
	pos = gAccList.GetHeadPosition(); 
	CAccProfile* pAccProfile; 
	while( pos != NULL ) 
	{ 
		pAccProfile = gAccList.GetNext( pos ); 
		HTREEITEM hAccount = treeCtrl.InsertItem ( pAccProfile->m_strAccName, 0, 0, 
			TVI_ROOT, TVI_LAST ); 
		treeCtrl.SetItemData( hAccount, ( DWORD ) pAccProfile ); 
		InsertChildBoxes( hAccount, pAccProfile->m_boxList ); 
	} 
} 
 
void CAccMgrTreeView::InsertChildBoxes(HTREEITEM hParent, BoxList &rBoxList) 
{ 
	if( rBoxList.GetCount() == 0 ) 
		return; 
	CTreeCtrl& treeCtrl = GetTreeCtrl(); 
	CBox* pBox; 
	POSITION pos; 
	pos = rBoxList.GetHeadPosition(); 
	while( pos != NULL ) 
	{ 
		pBox = rBoxList.GetNext( pos ); 
 
		int nImageIndex; 
		if ( pBox->m_strFileName == "in" )			// 收件箱 
			nImageIndex = 1; 
		else if( pBox->m_strFileName == "out" )		// 发件箱 
			nImageIndex = 2; 
		else if( pBox->m_strFileName == "sent" )	// 已发送邮件箱 
			nImageIndex = 3; 
		else if( pBox->m_strFileName == "trash" )	// 废件箱 
			nImageIndex = 4; 
		else										// 新建邮件箱 
			nImageIndex = 5; 
		HTREEITEM hBox = treeCtrl.InsertItem ( pBox->m_strBoxName, nImageIndex, 
			nImageIndex, hParent, TVI_LAST ); 
		treeCtrl.SetItemData( hBox, ( DWORD ) pBox ); 
		InsertChildBoxes( hBox, pBox->m_boxList ); 
	} 
}