📄 stmaddresseventhandle.cpp
字号:
// STMAddressEventHandle.cpp: implementation of the CSTMAddressEventHandle class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "stmeditor.h"
#include "STMAddressEventHandle.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
#include "AddNameInputDlg.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CSTMAddressEventHandle::CSTMAddressEventHandle()
{
m_pDoc=NULL;
m_bViewAddress=TRUE;
m_pMapView=NULL;
}
CSTMAddressEventHandle::~CSTMAddressEventHandle()
{
}
void CSTMAddressEventHandle::OnMouseMove(UINT nFlags, CPoint point)
{
POINT originpoint;
originpoint=m_pMapView->GetScrollPosition();
point.Offset(originpoint);
if(!(nFlags&MK_LBUTTON))// gerenal operator
{
if(m_pDoc->m_bFocusChanged)
{
if(m_pDoc->m_preFocusEI.eleType==ET_ADDRESS &&
m_pDoc->m_preFocusEI.index!=-1)// restore old focus address
{
DrawAddress(m_pDoc->m_preFocusEI.index);
}
if(m_pDoc->m_focusEI.eleType==ET_ADDRESS &&
m_pDoc->m_focusEI.index!=-1) //hilight the focus address
{
DrawAddress(m_pDoc->m_focusEI.index);
}
}
}else //drag
{
if(CanAddressMove())//move address
{
if(m_pDoc->m_activeType==ACT_ADDRESS_PICK)
m_pDoc->m_activeType=ACT_ADDRESS_MOVE;
if(m_pDoc->m_activeType==ACT_ADDRESS_MOVE)
{
ELEINFO ei=m_pDoc->m_arrSel.GetAt(0);
CRgn addressrgn;
m_pDoc->CalcAddressRgn(addressrgn,ei.index);
addressrgn.OffsetRgn(-originpoint.x,-originpoint.y);
m_pDoc->MoveAddress(ei.index,point);
m_pMapView->InvalidateRgn(&addressrgn,FALSE);
DrawAddress(ei.index);
}
}
}
}
void CSTMAddressEventHandle::OnRButtonUp(UINT nFlags, CPoint point)
{
POINT originpoint;
originpoint=m_pMapView->GetScrollPosition();
point.Offset(originpoint);
if(m_pDoc->m_focusEI.eleType==ET_ADDRESS &&
m_pDoc->m_focusEI.index !=-1)
{
if(m_pDoc->m_activeType!=ACT_ADDRESS_MOVE) //delete address
{
CRgn effectrgn;
m_pDoc->RemoveAddress(effectrgn,m_pDoc->m_focusEI.index);
effectrgn.OffsetRgn(-originpoint.x,-originpoint.y);
m_pDoc->m_focusEI.index=-1;
m_pMapView->InvalidateRgn(&effectrgn,FALSE);
}
}
}
void CSTMAddressEventHandle::OnLButtonUp(UINT nFlags, CPoint point)
{
POINT originpoint;
originpoint=m_pMapView->GetScrollPosition();
point.Offset(originpoint);
if(m_pDoc->m_focusEI.eleType==ET_NULL)//destinate focus type
{
if(m_pDoc->m_activeType==ACT_ADDRESS_PICK)
{
ADDRESSINFO ai;
CAddNameInputDlg inputdlg;
if(inputdlg.DoModal()==IDOK)
{
strcpy(ai.name,inputdlg.m_AddName);
ai.type=inputdlg.m_AddType;
ai.pos=point;
int index=m_pDoc->AddAddress(ai);
DrawAddress(index);
}
}
}else if(m_pDoc->m_focusEI.eleType==ET_ADDRESS &&
m_pDoc->m_focusEI.index!=-1) //self type
{
if(m_pDoc->m_activeType==ACT_ADDRESS_PICK)
{
if(m_pDoc->m_focusEI.eleType==ET_ADDRESS)//非法 position
{
m_pMapView->MessageBox("duplicated address position","error position!");
}
}else if(m_pDoc->m_activeType==ACT_ADDRESS_MOVE)
{
m_pDoc->m_activeType=ACT_ADDRESS_PICK;
}else if(m_pDoc->m_activeType==ACT_BROWSE)
{
CString msg;
ADDRESSINFO ai=m_pDoc->m_arrAddress.GetAt(m_pDoc->m_focusEI.index);
msg.Format("you clicked a address! name=%s,position:x=%d;y=%d",ai.name,ai.pos.x,ai.pos.y );
// m_pMapView->MessageBox(msg,"info");
}
}
}
BOOL CSTMAddressEventHandle::CanAddressMove()
{
BOOL ret=TRUE;
if(m_pDoc->m_arrSel.GetSize()!=1)
ret=FALSE;
else
{
ELEINFO ei=m_pDoc->m_arrSel.GetAt(0);
if(ei.eleType!=ET_ADDRESS||ei.index==-1)
ret=FALSE;
}
return ret;
}
void CSTMAddressEventHandle::DrawAddress(int index)
{
ADDRESSINFO ai=m_pDoc->m_arrAddress.GetAt(index);
ELEINFO ei;
ei.eleType=ET_ADDRESS;
ei.index=index;
ELESTATE state=m_pDoc->GetElementState(ei);//get element state
COLORREF color;
switch(state)
{
case ES_NORMAL:color=RGB(0,192,192);break;
case ES_FOCUS:color=RGB(255,255,0);break;
case ES_SELECTED:color=RGB(255,0,0);break;
}
POINT originpoint;
originpoint=m_pMapView->GetScrollPosition();
ai.pos.x-=originpoint.x;
ai.pos.y-=originpoint.y;
CRect rc=m_pDoc->CalcAddressRect(ai.pos);
CDC *pDC=m_pMapView->GetDC();
pDC->FillSolidRect(&rc,color);
int mode=pDC->SetBkMode(TRANSPARENT);
pDC->TextOut(rc.right,rc.top,ai.name,strlen(ai.name));
pDC->SetBkMode(mode);
m_pMapView->ReleaseDC(pDC);
}
void CSTMAddressEventHandle::DrawAllAddresses()
{
for(int i=0;i<m_pDoc->m_arrAddress.GetSize();i++)
DrawAddress(i);
}
void CSTMAddressEventHandle::OnLButtonDown(UINT nFlags, CPoint point)
{
//draw new selected cross
if(m_pDoc->m_focusEI.eleType==ET_ADDRESS &&
m_pDoc->m_focusEI.index!=-1)
{
ELEINFO ei=m_pDoc->m_focusEI;
m_pDoc->SelectElements(&ei,1);
DrawAddress(ei.index);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -