DrawDoc.cpp
资源名称:组态王6.5源代码.rar [点击查看]
上传用户:seaboy_04
上传日期:2013-02-24
资源大小:284k
文件大小:5k
源码类别:
其他行业
开发平台:
Visual C++
- // DrawDoc.cpp : implementation of the CDrawDoc class
- //
- #include "stdafx.h"
- #include "DrawCli.h"
- #include "DrawDoc.h"
- #include "CntrItem.h"
- #include "DrawObj.h"
- #include "DrawVw.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CDrawDoc
- IMPLEMENT_DYNCREATE(CDrawDoc, COleDocument)
- BEGIN_MESSAGE_MAP(CDrawDoc, COleDocument)
- //{{AFX_MSG_MAP(CDrawDoc)
- ON_COMMAND(ID_VIEW_PAPERCOLOR, OnViewPapercolor)
- //}}AFX_MSG_MAP
- // Enable default OLE container implementation
- ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, COleDocument::OnUpdatePasteMenu)
- ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE_LINK, COleDocument::OnUpdatePasteLinkMenu)
- ON_UPDATE_COMMAND_UI(ID_OLE_EDIT_CONVERT, COleDocument::OnUpdateObjectVerbMenu)
- ON_COMMAND(ID_OLE_EDIT_CONVERT, COleDocument::OnEditConvert)
- ON_UPDATE_COMMAND_UI(ID_OLE_EDIT_LINKS, COleDocument::OnUpdateEditLinksMenu)
- ON_COMMAND(ID_OLE_EDIT_LINKS, COleDocument::OnEditLinks)
- ON_UPDATE_COMMAND_UI_RANGE(ID_OLE_VERB_FIRST, ID_OLE_VERB_LAST, COleDocument::OnUpdateObjectVerbMenu)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CDrawDoc construction/destruction
- CDrawDoc::CDrawDoc()
- {
- // Use OLE compound files
- EnableCompoundFile();
- m_nMapMode = MM_ANISOTROPIC;
- m_paperColor = RGB(255, 255, 255);
- ComputePageSize();
- }
- CDrawDoc::~CDrawDoc()
- {
- }
- BOOL CDrawDoc::OnNewDocument()
- {
- if (!COleDocument::OnNewDocument())
- return FALSE;
- // TODO: add reinitialization code here
- // (SDI documents will reuse this document)
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CDrawDoc serialization
- void CDrawDoc::Serialize(CArchive& ar)
- {
- if (ar.IsStoring())
- {
- ar << m_paperColor;
- m_objects.Serialize(ar);
- }
- else
- {
- ar >> m_paperColor;
- m_objects.Serialize(ar);
- }
- // Calling the base class COleDocument enables serialization
- // of the container document's COleClientItem objects.
- COleDocument::Serialize(ar);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CDrawDoc diagnostics
- #ifdef _DEBUG
- void CDrawDoc::AssertValid() const
- {
- COleDocument::AssertValid();
- }
- void CDrawDoc::Dump(CDumpContext& dc) const
- {
- COleDocument::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CDrawDoc commands
- void CDrawDoc::Add(CDrawObj *pObj)
- {
- m_objects.AddTail(pObj);
- pObj->m_pDocument = this;
- SetModifiedFlag();
- }
- CDrawObj* CDrawDoc::ObjectAt(const CPoint& point)
- {
- CRect rect(point, CSize(1, 1));
- POSITION pos = m_objects.GetTailPosition();
- while (pos != NULL)
- {
- CDrawObj* pObj = m_objects.GetPrev(pos);
- if (pObj->Intersects(rect))
- return pObj;
- }
- return NULL;
- }
- void CDrawDoc::Remove(CDrawObj* pObj)
- {
- // Find and remove from document
- POSITION pos = m_objects.Find(pObj);
- if (pos != NULL)
- m_objects.RemoveAt(pos);
- // set document modified flag
- SetModifiedFlag();
- // call remove for each view so that the view can remove from m_selection
- pos = GetFirstViewPosition();
- while (pos != NULL)
- ((CDrawView*)GetNextView(pos))->Remove(pObj);
- }
- void CDrawDoc::Draw(CDC* pDC,CDrawView* pView)
- {
- POSITION pos = m_objects.GetHeadPosition();
- while (pos != NULL)
- {
- CDrawObj* pObj = m_objects.GetNext(pos);
- pObj->Draw(pDC);
- if (pView->m_bActive && !pDC->IsPrinting() && pView->IsSelected(pObj))
- pObj->DrawTracker(pDC, CDrawObj::selected);
- }
- }
- void CDrawDoc::ComputePageSize()
- {
- CSize new_size(800, 600); // 8.5" x 11" default
- CPrintDialog dlg(FALSE);
- if (AfxGetApp()->GetPrinterDeviceDefaults(&dlg.m_pd))
- {
- // GetPrinterDC returns a HDC so attach it
- CDC dc;
- HDC hDC= dlg.CreatePrinterDC();
- ASSERT(hDC != NULL);
- dc.Attach(hDC);
- // Get the size of the page in loenglish
- new_size.cx = MulDiv(dc.GetDeviceCaps(HORZSIZE), 1000, 254);
- new_size.cy = MulDiv(dc.GetDeviceCaps(VERTSIZE), 1000, 254);
- }
- // if size changed then iterate over views and reset
- if (new_size != m_size)
- {
- m_size = new_size;
- POSITION pos = GetFirstViewPosition();
- while (pos != NULL)
- ((CDrawView*)GetNextView(pos))->SetPageSize(m_size);
- }
- }
- void CDrawDoc::OnViewPapercolor()
- {
- CColorDialog dlg;
- if (dlg.DoModal() != IDOK)
- return;
- m_paperColor = dlg.GetColor();
- SetModifiedFlag();
- UpdateAllViews(NULL);
- }