📄 leftview.cpp
字号:
// LeftView.cpp : implementation of the CLeftView class
//
#include "stdafx.h"
#include "Two.h"
#include "RichDoc.h"
#include "LeftView.h"
#include "RichView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CLeftView
IMPLEMENT_DYNCREATE(CLeftView, CScrollView)
BEGIN_MESSAGE_MAP(CLeftView, CScrollView)
//{{AFX_MSG_MAP(CLeftView)
// 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()
/////////////////////////////////////////////////////////////////////////////
// CLeftView construction/destruction
CLeftView::CLeftView()
{
m_Font.CreatePointFont (100, "Times New Roman");
m_nTopMargin = 6;
m_nLeftMargin = 6;
m_nRightMargin = 6;
m_nBottomMargin = 6;
}
CLeftView::~CLeftView()
{
}
BOOL CLeftView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CLeftView drawing
void CLeftView::OnDraw(CDC* pDC)
{
CRichDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
int nLine;
CSize sz;
CString strText;
sz = pDC->GetTextExtent (" ", 1);
RECT rc;
RECT rcClient;
GetClientRect (&rcClient);
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 < 15; ++nLine)
{
strText = m_FormatData[nLine];
if (strText.IsEmpty ())
continue;
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;
}
// 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);
}
/////////////////////////////////////////////////////////////////////////////
// CLeftView printing
BOOL CLeftView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CLeftView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CLeftView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CLeftView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CSize sizeTotal;
// TODO: calculate the total size of this view
sizeTotal.cx = sizeTotal.cy = 100;
SetScrollSizes(MM_TEXT, sizeTotal);
}
/////////////////////////////////////////////////////////////////////////////
// CLeftView diagnostics
#ifdef _DEBUG
void CLeftView::AssertValid() const
{
CScrollView::AssertValid();
}
void CLeftView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CRichDoc* CLeftView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CRichDoc)));
return (CRichDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CLeftView message handlers
void CLeftView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
if (pSender == NULL)
return;
if (pSender->IsKindOf (RUNTIME_CLASS(CRichView)))
{
CRichView *pView = (CRichView *) pSender;
switch (lHint)
{
case 0:
break;
case 1:
int x;
for (x = 0; x < 15; ++x)
m_FormatData[x].Empty ();
x = 0;
m_cf = pView->GetCharFormatSelection ();
m_pf = pView->GetParaFormatSelection ();
m_FormatData[x++] = _T("Current Font:");
m_FormatData[x++].Format (" %s", m_cf.szFaceName);
m_FormatData[x++] = _T("Effects:");
if (!(m_cf.dwEffects & (CFE_BOLD|CFE_STRIKEOUT|CFE_UNDERLINE|CFE_ITALIC)))
m_FormatData[x++] += _T(" Normal");
else
{
if ((m_cf.dwMask & CFM_BOLD) && (m_cf.dwEffects & CFE_BOLD))
m_FormatData[x++] += _T(" Bold");
if ((m_cf.dwMask & CFM_ITALIC) && (m_cf.dwEffects & CFE_ITALIC))
m_FormatData[x++] += _T(" Italic");
if ((m_cf.dwMask & CFM_UNDERLINE) && (m_cf.dwEffects & CFE_UNDERLINE))
m_FormatData[x++] += _T(" Underline");
if ((m_cf.dwMask & CFM_STRIKEOUT) && (m_cf.dwEffects & CFE_STRIKEOUT))
m_FormatData[x++] += _T(" Strikeout");
}
Invalidate();
break;
default:
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -