📄 cntritem.cpp
字号:
// CntrItem.cpp : implementation of the CMapCntrItem class
//
#include "stdafx.h"
#include "Map.h"
#include "MapDoc.h"
#include "MapView.h"
#include "CntrItem.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMapCntrItem implementation
IMPLEMENT_SERIAL(CMapCntrItem, COleClientItem, 0)
CMapCntrItem::CMapCntrItem(CMapDoc* pContainer)
: COleClientItem(pContainer)
{
// TODO: add one-time construction code here
m_Rect.SetRect(12,12,34,34);
m_CenterPoint.x=m_CenterPoint.y=23;
}
CMapCntrItem::~CMapCntrItem()
{
// TODO: add cleanup code here
}
void CMapCntrItem::OnChange(OLE_NOTIFICATION nCode, DWORD dwParam)
{
ASSERT_VALID(this);
COleClientItem::OnChange(nCode, dwParam);
// When an item is being edited (either in-place or fully open)
// it sends OnChange notifications for changes in the state of the
// item or visual appearance of its content.
// TODO: invalidate the item by calling UpdateAllViews
// (with hints appropriate to your application)
GetDocument()->UpdateAllViews(NULL);
// for now just update ALL views/no hints
}
BOOL CMapCntrItem::OnChangeItemPosition(const CRect& rectPos)
{
ASSERT_VALID(this);
// During in-place activation CMapCntrItem::OnChangeItemPosition
// is called by the server to change the position of the in-place
// window. Usually, this is a result of the data in the server
// document changing such that the extent has changed or as a result
// of in-place resizing.
//
// The default here is to call the base class, which will call
// COleClientItem::SetItemRects to move the item
// to the new position.
if (!COleClientItem::OnChangeItemPosition(rectPos))
return FALSE;
// TODO: update any cache you may have of the item's rectangle/extent
this->ChangePosition(rectPos);
return TRUE;
}
void CMapCntrItem::OnGetItemPosition(CRect& rPosition)
{
ASSERT_VALID(this);
// During in-place activation, CMapCntrItem::OnGetItemPosition
// will be called to determine the location of this item. The default
// implementation created from AppWizard simply returns a hard-coded
// rectangle. Usually, this rectangle would reflect the current
// position of the item relative to the view used for activation.
// You can obtain the view by calling CMapCntrItem::GetActiveView.
// TODO: return correct rectangle (in pixels) in rPosition
rPosition=m_Rect;
}
void CMapCntrItem::OnActivate()
{
// Allow only one inplace activate item per frame
CMapView* pView = GetActiveView();
ASSERT_VALID(pView);
COleClientItem* pItem = GetDocument()->GetInPlaceActiveItem(pView);
if (pItem != NULL && pItem != this)
pItem->Close();
COleClientItem::OnActivate();
}
void CMapCntrItem::OnDeactivateUI(BOOL bUndoable)
{
COleClientItem::OnDeactivateUI(bUndoable);
// Hide the object if it is not an outside-in object
DWORD dwMisc = 0;
m_lpObject->GetMiscStatus(GetDrawAspect(), &dwMisc);
if (dwMisc & OLEMISC_INSIDEOUT)
DoVerb(OLEIVERB_HIDE, NULL);
}
void CMapCntrItem::Serialize(CArchive& ar)
{
ASSERT_VALID(this);
// Call base class first to read in COleClientItem data.
// Since this sets up the m_pDocument pointer returned from
// CMapCntrItem::GetDocument, it is a good idea to call
// the base class Serialize first.
COleClientItem::Serialize(ar);
// now store/retrieve data specific to CMapCntrItem
if (ar.IsStoring())
{
// TODO: add storing code here
ar<<m_Rect;
ar<<m_Key;
ar<<m_CenterPoint;
}
else
{
// TODO: add loading code here
ar>>m_Rect;
ar>>m_Key;
ar>>m_CenterPoint;
}
}
/////////////////////////////////////////////////////////////////////////////
// CMapCntrItem diagnostics
#ifdef _DEBUG
void CMapCntrItem::AssertValid() const
{
COleClientItem::AssertValid();
}
void CMapCntrItem::Dump(CDumpContext& dc) const
{
COleClientItem::Dump(dc);
}
#endif
/////////////////////////////////////////////////////////////////////////////
#define DISTANCE(A,C,B,D) sqrt((A-B)*(A-B)+(C-D)*(C-D))
CPoint CMapCntrItem::GetBeginPoint(CPoint endPoint)
{
double d=2*DISTANCE(m_CenterPoint.x,m_CenterPoint.y,endPoint.x,endPoint.y);
endPoint.x=m_CenterPoint.x+m_Rect.Width()*(endPoint.x-m_CenterPoint.x)/d;
endPoint.y=m_CenterPoint.y+m_Rect.Height()*(endPoint.y-m_CenterPoint.y)/d;
return endPoint;
}
void CMapCntrItem::ChangePosition(CRect rect)
{
m_Rect=rect;
m_CenterPoint.x=(m_Rect.left+m_Rect.right)/2;
m_CenterPoint.y=(m_Rect.top+m_Rect.bottom)/2;
}
void CMapCntrItem::LineToItem(CDC *pdc, CMapCntrItem *Item)
{
CPoint bPoint=GetBeginPoint(Item->m_CenterPoint);
CPoint ePoint=Item->GetBeginPoint(m_CenterPoint);
if(bPoint!=ePoint)
{
pdc->MoveTo(bPoint);
pdc->LineTo(ePoint);
CPen pBoldPen,*pOldPen;
pBoldPen.CreatePen(PS_SOLID,5,RGB(0,0,0));
pOldPen=pdc->SelectObject(&pBoldPen);
CSize temp=bPoint-ePoint;
temp.cx=temp.cx/50;
temp.cy=temp.cy/50;
pdc->LineTo(ePoint+temp);
pdc->SelectObject(pOldPen);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -