⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 textscrollview.cpp

📁 这些源代码
💻 CPP
字号:
// TextScrollView.cpp : implementation of the CTextScrollView class
//

#include "stdafx.h"
#include "TextScroll.h"

#include "TextScrollDoc.h"
#include "TextScrollView.h"
#include	"Line.h"

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

/////////////////////////////////////////////////////////////////////////////
// CTextScrollView

IMPLEMENT_DYNCREATE(CTextScrollView, CScrollView)

BEGIN_MESSAGE_MAP(CTextScrollView, CScrollView)
	//{{AFX_MSG_MAP(CTextScrollView)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTextScrollView construction/destruction

CTextScrollView::CTextScrollView()
{
	m_Font.CreatePointFont (100, "Courier New");
	m_nTabStops = 4;
	m_nLeftMargin = m_nRightMargin = 5;
	m_nTopMargin = m_nBottomMargin = 5;
}

CTextScrollView::~CTextScrollView()
{
}

BOOL CTextScrollView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CScrollView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CTextScrollView drawing

void CTextScrollView::OnDraw(CDC* pDC)
{
	CTextScrollDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	int nLine;
	CSize sz;
	int nCount = pDoc->m_Text.GetSize ();
	if (!nCount)
		return;
	CString strText;
	sz = pDC->GetTextExtent (" ", 1);
	RECT rc;
//	Don't need these with CScrollView
	RECT rcClient;
	GetClientRect (&rcClient);
//	GetClientRect (&rc);
//	int nBottom = rc.bottom;
	rc.top = m_nTopMargin;
	rc.left = m_nLeftMargin;
	rc.bottom = sz.cy;
	CFont *fontOld = pDC->SelectObject (&m_Font);
	int nWidestLine = 0;
	int nRunningDepth = m_nTopMargin;
	for (nLine = 0; nLine < nCount; ++nLine)
	{
		strText = pDoc->m_Text[nLine].GetData();
		if (strText.IsEmpty ())
		{
			sz = pDC->GetTextExtent (" ", 1);
		}
		else if (strText.FindOneOf ("\t") < 0)
		{
			sz = pDC->GetTextExtent (strText);
		}
		else
		{
			ExpandTabs (strText);
			sz = pDC->GetTextExtent (strText);
		}
		if (sz.cx > nWidestLine)
			nWidestLine = sz.cx;
		rc.right = sz.cx + m_nRightMargin;

		pDC->TextOut (rc.left, rc.top, strText);
		nRunningDepth += sz.cy;
		rc.top += sz.cy;
		rc.bottom += sz.cy;
//	
//	This time we're not gonna bail out.
//		if (rc.top > nBottom)
//			break;
	}
// calculate the total size of this view
	sz.cx = nWidestLine + m_nLeftMargin + m_nRightMargin;
	sz.cy = nRunningDepth + m_nBottomMargin;
	SetScrollSizes(MM_TEXT, sz);

	pDC->SelectObject (fontOld);
}

void CTextScrollView::OnInitialUpdate()
{
	CScrollView::OnInitialUpdate();

	CSize sizeTotal;
	// TODO: calculate the total size of this view
	sizeTotal.cx = sizeTotal.cy = 100;
	SetScrollSizes(MM_TEXT, sizeTotal);
}

/////////////////////////////////////////////////////////////////////////////
// CTextScrollView printing

BOOL CTextScrollView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CTextScrollView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CTextScrollView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CTextScrollView diagnostics

#ifdef _DEBUG
void CTextScrollView::AssertValid() const
{
	CScrollView::AssertValid();
}

void CTextScrollView::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CTextScrollView message handlers

void CTextScrollView::ExpandTabs(CString &strText)
{
CString str;
LPCSTR	s;
int		n, nLen;
int		nPos;		// Position in converted line

	str.Empty();
	s = strText;
	nLen = strText.GetLength ();
	for (n = 0, nPos = 0; n < nLen; ++n)
	{
		if (*s == '\t')
		{
			if (m_nTabStops > 0)
			{
				int nSpaces = m_nTabStops - nPos % m_nTabStops;
				for (int x = 0; x < nSpaces; ++x)
				{
					str += ' ';
					++nPos;
				}
			}
		}
		else
		{
			str += *s;
			++nPos;
		}
		++s;
	}
	strText = str;
}

⌨️ 快捷键说明

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