structureview.cpp

来自「这是一个PDF文件查看的程序」· C++ 代码 · 共 128 行

CPP
128
字号
// StructureView.cpp : implementation of the CStructureView class
//

#include "stdafx.h"
#include "PdfView.h"

#include "PdfViewDoc.h"

#include "BPdfObject.h"
#include "StructureView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CStructureView

IMPLEMENT_DYNCREATE(CStructureView, CTreeView)

BEGIN_MESSAGE_MAP(CStructureView, CTreeView)
	ON_NOTIFY_REFLECT(TVN_ITEMEXPANDING, OnTvnItemexpanding)
END_MESSAGE_MAP()


// CStructureView construction/destruction

CStructureView::CStructureView()
{
	// TODO: add construction code here
	m_imagelist.Create(IDB_TREE, 16, 0, RGB(255, 0, 255));
}

CStructureView::~CStructureView()
{
}

BOOL CStructureView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying the CREATESTRUCT cs
	cs.style |= TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT | TVS_SHOWSELALWAYS;
	return CTreeView::PreCreateWindow(cs);
}

void CStructureView::OnInitialUpdate()
{
	CTreeView::OnInitialUpdate();

	// TODO: You may populate your TreeView with items by directly accessing
	//  its tree control through a call to GetTreeCtrl().
	CTreeCtrl& tree = GetTreeCtrl();
	tree.SetImageList(&m_imagelist, TVSIL_NORMAL);

	CPdfViewDoc* pdoc = GetDocument();
	CBPdf& pdf = pdoc->GetPdf();
	if (!pdf.IsOpen())
		return;

	pdf.Draw(&GetTreeCtrl());
}


// CStructureView diagnostics

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

void CStructureView::Dump(CDumpContext& dc) const
{
	CTreeView::Dump(dc);
}

CPdfViewDoc* CStructureView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPdfViewDoc)));
	return (CPdfViewDoc*)m_pDocument;
}
#endif //_DEBUG


// CStructureView message handlers

void CStructureView::OnTvnItemexpanding(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
	// TODO: Add your control notification handler code here
	TVITEM tvitem = pNMTreeView->itemNew;

	CTreeCtrl& tree = GetTreeCtrl();

	CPdfViewDoc* pdoc = GetDocument();
	CBPdf& pdf = pdoc->GetPdf();

	HTREEITEM htiLevel0 = tree.GetChildItem(tvitem.hItem);
	for (;;)
	{
		if (htiLevel0 == NULL)
			break;

		HTREEITEM htiLevel1 = tree.GetChildItem(htiLevel0);
		for (;;)
		{
			if (htiLevel1 == NULL)
				break;

			TVITEM item;
			item.hItem = htiLevel1;
			item.mask = TVIF_HANDLE | TVIF_PARAM;
			tree.GetItem(&item);

			if (item.lParam != NULL)
			{
				if (!tree.ItemHasChildren(item.hItem))
				{
					CBPdfObject* pobj = (CBPdfObject*)item.lParam;
					pobj->Draw(&pdf, &tree, item.hItem, 0, 2);
				}
			}
			htiLevel1 = tree.GetNextItem(htiLevel1, TVGN_NEXT);
		}
		htiLevel0 = tree.GetNextItem(htiLevel0, TVGN_NEXT);
	}
	*pResult = 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?