// drView.cpp : implementation of the CDrView class
//
#include "stdafx.h"
#include "dr.h"
#include "MainFrm.h"
#include "drDoc.h"
#include "drView.h"
#include "Dot.h"
#include "Line.h"
#include "Ellipse.h"
#include "Circle.h"
#include "Rectangle.h"
#include "RoundRect.h"
#include "resource.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDrView
IMPLEMENT_DYNCREATE(CDrView, CView)
BEGIN_MESSAGE_MAP(CDrView, CView)
ON_WM_CONTEXTMENU()
//{{AFX_MSG_MAP(CDrView)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_CHAR()
ON_COMMAND(IDM_NULL, OnNull)
ON_COMMAND(IDM_DOT, OnDot)
ON_COMMAND(IDM_LINE, OnLine)
ON_COMMAND(IDM_ELLIPSE, OnEllipse)
ON_COMMAND(IDM_CIRCLE, OnCircle)
ON_COMMAND(IDM_RECTANGLE, OnRectangle)
ON_COMMAND(IDM_ROUNDRECT, OnRoundrect)
ON_COMMAND(IDM_FONT, OnFont)
ON_COMMAND(IDM_FONTSET, OnFontset)
ON_COMMAND(IDM_POLY, OnPoly)
ON_COMMAND(IDM_CURVE, OnCurve)
ON_COMMAND(IDM_FILL_FALSE, OnFillFalse)
ON_COMMAND(IDM_FILL_ROUND, OnFillRound)
ON_COMMAND(IDM_FILL_TRUE, OnFillTrue)
ON_UPDATE_COMMAND_UI(IDM_NULL, OnUpdateNull)
ON_UPDATE_COMMAND_UI(IDM_DOT, OnUpdateDot)
ON_UPDATE_COMMAND_UI(IDM_LINE, OnUpdateLine)
ON_UPDATE_COMMAND_UI(IDM_ELLIPSE, OnUpdateEllipse)
ON_UPDATE_COMMAND_UI(IDM_CIRCLE, OnUpdateCircle)
ON_UPDATE_COMMAND_UI(IDM_RECTANGLE, OnUpdateRectangle)
ON_UPDATE_COMMAND_UI(IDM_ROUNDRECT, OnUpdateRoundrect)
ON_UPDATE_COMMAND_UI(IDM_FONT, OnUpdateFont)
ON_COMMAND(IDM_WIDTH_THIN, OnWidthThin)
ON_COMMAND(IDM_WIDTH_NORMAL, OnWidthNormal)
ON_COMMAND(IDM_WIDTH_WIDE, OnWidthWide)
ON_UPDATE_COMMAND_UI(IDM_POLY, OnUpdatePoly)
ON_UPDATE_COMMAND_UI(IDM_CURVE, OnUpdateCurve)
ON_UPDATE_COMMAND_UI(IDM_WIDTH_THIN, OnUpdateWidthThin)
ON_UPDATE_COMMAND_UI(IDM_WIDTH_NORMAL, OnUpdateWidthNormal)
ON_UPDATE_COMMAND_UI(IDM_WIDTH_WIDE, OnUpdateWidthWide)
ON_COMMAND(IDM_FILL_COLOR, OnFillColor)
ON_COMMAND(IDM_COLOR_SET, OnColorSet)
ON_COMMAND(IDM_PS_SOLID, OnPsSolid)
ON_COMMAND(IDM_PS_DASH, OnPsDash)
ON_UPDATE_COMMAND_UI(IDM_PS_SOLID, OnUpdatePsSolid)
ON_UPDATE_COMMAND_UI(IDM_PS_DASH, OnUpdatePsDash)
ON_COMMAND(IDM_PS_DOT, OnPsDot)
ON_UPDATE_COMMAND_UI(IDM_PS_DOT, OnUpdatePsDot)
ON_COMMAND(IDM_PS_DASHDOT, OnPsDashdot)
ON_UPDATE_COMMAND_UI(IDM_PS_DASHDOT, OnUpdatePsDashdot)
ON_COMMAND(IDM_PS_DASHDOTDOT, OnPsDashdotdot)
ON_UPDATE_COMMAND_UI(IDM_PS_DASHDOTDOT, OnUpdatePsDashdotdot)
ON_COMMAND(IDM_WIDTH_4, OnWidth4)
ON_UPDATE_COMMAND_UI(IDM_WIDTH_4, OnUpdateWidth4)
ON_COMMAND(IDM_WIDTH_5, OnWidth5)
ON_UPDATE_COMMAND_UI(IDM_WIDTH_5, OnUpdateWidth5)
ON_COMMAND(IDM_WIDTH_6, OnWidth6)
ON_UPDATE_COMMAND_UI(IDM_WIDTH_6, OnUpdateWidth6)
ON_COMMAND(IDM_WIDTH_7, OnWidth7)
ON_UPDATE_COMMAND_UI(IDM_WIDTH_7, OnUpdateWidth7)
ON_COMMAND(IDM_WIDTH_8, OnWidth8)
ON_UPDATE_COMMAND_UI(IDM_WIDTH_8, OnUpdateWidth8)
ON_COMMAND(IDM_WIDTH_9, OnWidth9)
ON_UPDATE_COMMAND_UI(IDM_WIDTH_9, OnUpdateWidth9)
ON_COMMAND(IDM_WIDTH_10, OnWidth10)
ON_UPDATE_COMMAND_UI(IDM_WIDTH_10, OnUpdateWidth10)
ON_COMMAND(IDM_LINECOLOR_SET, OnLinecolorSet)
ON_COMMAND(IDM_FONT_SET, OnFontSet)
ON_COMMAND(IDM_COLOR_BLACK, OnColorBlack)
ON_UPDATE_COMMAND_UI(IDM_COLOR_BLACK, OnUpdateColorBlack)
ON_COMMAND(IDM_COLOR_WHITE, OnColorWhite)
ON_UPDATE_COMMAND_UI(IDM_COLOR_WHITE, OnUpdateColorWhite)
ON_COMMAND(IDM_COLOR_DARKGRAY, OnColorDarkgray)
ON_UPDATE_COMMAND_UI(IDM_COLOR_DARKGRAY, OnUpdateColorDarkgray)
ON_COMMAND(IDM_COLOR_GRAY, OnColorGray)
ON_UPDATE_COMMAND_UI(IDM_COLOR_GRAY, OnUpdateColorGray)
ON_COMMAND(IDM_COLOR_BLUE, OnColorBlue)
ON_UPDATE_COMMAND_UI(IDM_COLOR_BLUE, OnUpdateColorBlue)
ON_COMMAND(IDM_COLOR_DARKBLUE, OnColorDarkblue)
ON_UPDATE_COMMAND_UI(IDM_COLOR_DARKBLUE, OnUpdateColorDarkblue)
ON_COMMAND(IDM_COLOR_DARKGREEN, OnColorDarkgreen)
ON_UPDATE_COMMAND_UI(IDM_COLOR_DARKGREEN, OnUpdateColorDarkgreen)
ON_COMMAND(IDM_COLOR_DARKRED, OnColorDarkred)
ON_UPDATE_COMMAND_UI(IDM_COLOR_DARKRED, OnUpdateColorDarkred)
ON_COMMAND(IDM_COLOR_DARKYELLOW, OnColorDarkyellow)
ON_UPDATE_COMMAND_UI(IDM_COLOR_DARKYELLOW, OnUpdateColorDarkyellow)
ON_COMMAND(IDM_COLOR_GREEN, OnColorGreen)
ON_UPDATE_COMMAND_UI(IDM_COLOR_GREEN, OnUpdateColorGreen)
ON_COMMAND(IDM_COLOR_PINK, OnColorPink)
ON_UPDATE_COMMAND_UI(IDM_COLOR_PINK, OnUpdateColorPink)
ON_COMMAND(IDM_COLOR_PURPLE, OnColorPurple)
ON_UPDATE_COMMAND_UI(IDM_COLOR_PURPLE, OnUpdateColorPurple)
ON_COMMAND(IDM_COLOR_RED, OnColorRed)
ON_UPDATE_COMMAND_UI(IDM_COLOR_RED, OnUpdateColorRed)
ON_COMMAND(IDM_COLOR_YELLOW, OnColorYellow)
ON_UPDATE_COMMAND_UI(IDM_COLOR_YELLOW, OnUpdateColorYellow)
ON_UPDATE_COMMAND_UI(IDM_FONT_SET, OnUpdateFontSet)
ON_UPDATE_COMMAND_UI(IDM_FILL_COLOR, OnUpdateFillColor)
ON_COMMAND(IDM_COLOR_CYAN, OnColorCyan)
ON_UPDATE_COMMAND_UI(IDM_COLOR_CYAN, OnUpdateColorCyan)
ON_COMMAND(IDM_COLOR_DARKCYAN, OnColorDarkcyan)
ON_UPDATE_COMMAND_UI(IDM_COLOR_DARKCYAN, OnUpdateColorDarkcyan)
ON_UPDATE_COMMAND_UI(IDM_FILL_FALSE, OnUpdateFillFalse)
ON_UPDATE_COMMAND_UI(IDM_FILL_ROUND, OnUpdateFillRound)
ON_UPDATE_COMMAND_UI(IDM_FILL_TRUE, OnUpdateFillTrue)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDrView construction/destruction
CDrView::CDrView()
{
// TODO: add construction code here
m_bMouseDown = false;
m_hCross = AfxGetApp()->LoadStandardCursor(IDC_CROSS);
m_hArrow = AfxGetApp()->LoadStandardCursor(IDC_ARROW);
m_nLine = 0;
m_nDrawType=0;
m_nLineStyle=0;
m_nLineWidth=1;
m_cLineColor=RGB(255,0,0);
m_ptStart=0;
}
CDrView::~CDrView()
{
}
BOOL CDrView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CDrView drawing
void CDrView::OnDraw(CDC* pDC)
{
CDrDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
pDoc->DrawDot(pDC);
pDoc->DrawLine(pDC);
pDoc->DrawEllipse(pDC);
pDoc->DrawCircle(pDC);
pDoc->DrawRectangle(pDC);
pDoc->DrawRoundRect(pDC);
pDoc->DrawText(pDC);
}
/////////////////////////////////////////////////////////////////////////////
// CDrView printing
BOOL CDrView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CDrView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CDrView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CDrView diagnostics
#ifdef _DEBUG
void CDrView::AssertValid() const
{
CView::AssertValid();
}
void CDrView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CDrDoc* CDrView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDrDoc)));
return (CDrDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CDrView message handlers
void CDrView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_bMouseDown = true; // 鼠标左键按下
m_ptStart = point; // 画线的起点
m_ptOld = point; // 临时点
SetCapture(); // 将鼠标消息发送到视窗口
CRect rect;
GetClientRect(&rect); // 得