dabiaodoc.cpp
来自「串口 操作 源码 打标机的控制程序」· C++ 代码 · 共 363 行
CPP
363 行
// dabiaoDoc.cpp : implementation of the CDabiaoDoc class
//
#include "stdafx.h"
#include "dabiao.h"
#include "dabiaoDoc.h"
#include "dabiaoView.h"
#include "EnterText.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDabiaoDoc
IMPLEMENT_DYNCREATE(CDabiaoDoc, CDocument)
BEGIN_MESSAGE_MAP(CDabiaoDoc, CDocument)
//{{AFX_MSG_MAP(CDabiaoDoc)
ON_UPDATE_COMMAND_UI(ID_FILE_NEW, OnUpdateFileNew)
ON_UPDATE_COMMAND_UI(ID_FILE_OPEN, OnUpdateFileOpen)
ON_UPDATE_COMMAND_UI(ID_FILE_SAVE, OnUpdateFileSave)
ON_UPDATE_COMMAND_UI(ID_FILE_SAVE_AS, OnUpdateFileSaveAs)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDabiaoDoc construction/destruction
extern class CDabiaoDoc* g_pDoc;
extern class CDabiaoView* g_pView;
extern int viewscale;
extern int viewx,viewy,viewwidth,viewhigh;
CDabiaoDoc::CDabiaoDoc()
{
// TODO: add one-time construction code here
g_pDoc = this;
m_pPmtEntity = NULL ;
}
CDabiaoDoc::~CDabiaoDoc()
{
}
BOOL CDabiaoDoc::OnNewDocument()
{
g_pView->OnClear();
if (!CDocument::OnNewDocument())
return FALSE;
m_EntityList.RemoveAll();
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CDabiaoDoc serialization
extern int ex;
extern int ey;
extern int sx;
extern int sy;
extern CString pathname;
void CDabiaoDoc::Serialize(CArchive& ar)
{
m_EntityList.Serialize(ar);
if(ar.IsStoring())
{
ar << ex;
ar << ey;
ar << sx;
ar << sy;
ar << pathname;
ar<<viewwidth;
ar<<viewhigh;
}
else
{
ar >> ex;
ar >> ey;
ar >> sx;
ar >> sy;
ar >> pathname;
ar>>viewwidth;
ar>>viewhigh;
g_pView->InsertPicture(sx,sy,ex,ey,pathname);
}
}
/////////////////////////////////////////////////////////////////////////////
// CDabiaoDoc diagnostics
#ifdef _DEBUG
void CDabiaoDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CDabiaoDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CDabiaoDoc commands
void CDabiaoDoc::Draw(CDC *pDC)
{
POSITION pos = m_EntityList.GetHeadPosition();
while(pos!=NULL)
{
CText* pEntity = (CText *) m_EntityList.GetNext(pos);
pEntity->Draw(pDC, 0);
}
}
void CDabiaoDoc::OnLButtonDown(UINT nFlags, const CPoint& pos)
{
CDC* pDC = g_pView->GetDC() ;// 得到视的设备环境指针
// 如果存在提示图元,那么当按下鼠标左键时,将该图元加入到选择集中
if(m_pPmtEntity){
if( !(nFlags & MK_CONTROL) ) // 如果没有按下Ctrl键,则首先清空选择集
RemoveAllSelected();
m_pPmtEntity->Draw(pDC,1); // 将图元绘制为选中状态
// pDC->TextOut(0,0,"picked!");
m_selectArray.Add(m_pPmtEntity); // 将图元放入选择集中
}
else{
if( !(nFlags & MK_CONTROL) )// 如果没有按下Ctrl键,则清空选择集
RemoveAllSelected();
}
m_pPmtEntity = NULL; // 将提示图元对象设置为空
g_pView->ReleaseDC(pDC);// 释放视的设备环境指针
}
void CDabiaoDoc::OnMouseMove(UINT nFlags, const CPoint& pos)
{
if(m_EntityList.GetCount() == 0)
return;
/// ::Prompt("拾取一个图元或按Ctrl键拾取多个图元");
BOOL bPicked = FALSE;
CText* pickedEntity = NULL;
CDC* pDC = g_pView->GetDC(); // 得到视的设备环境指
// 遍历图元链表,判断是否存在图元被拾取到
POSITION position = m_EntityList.GetHeadPosition();
while(position != NULL){
CText* pEntity = (CText *)m_EntityList.GetNext(position);
if( pEntity->Pick(pos) )
{ // 当某一个图元被拾取到后,即退出循环
bPicked = TRUE;
pickedEntity = pEntity;
break;
}
}
// CDC* pDC = g_pView->GetDC(); // 得到视的设备环境指针
if( bPicked )
{
if( m_pPmtEntity )
{
m_pPmtEntity->Draw( pDC, 1 );
m_pPmtEntity = NULL;
}
// 将拾取到的图元设置为提示图元
m_pPmtEntity = pickedEntity ;
// 如果提示图元不在选择集中,那么将它高亮显示
if( ! IsSelected(m_pPmtEntity) ){
m_pPmtEntity->Draw( pDC, 1);
}
// 如果提示图元已存在于选择集中,那么将它恢复为空
else
m_pPmtEntity = NULL;
}
else{ // 如果没有图元被拾取到
// 如果以前存在提示图元
// 那么将提示图元对象恢复到正常绘制状态,并设置为空
if( m_pPmtEntity ){
m_pPmtEntity->Draw( pDC, 0);
m_pPmtEntity = NULL;
}
}
g_pView->ReleaseDC(pDC); // 释放视的设备环境指针;
}
void CDabiaoDoc::OnLButtonDblClk(UINT nFlags, const CPoint &pos)
{
CText* pSelEntity = NULL ;
POSITION pos0 = NULL ;
for( int i = 0 ; i < m_selectArray.GetSize() ; i++ )
{
pSelEntity = (CText*)m_selectArray[i] ;
POSITION pos = g_pDoc->m_EntityList.Find(pSelEntity) ;
//-----------------------
CEnterText ctextent;
ctextent.m_string=pSelEntity->m_text;
ctextent.m_posx =pSelEntity->m_begin.x;
ctextent.m_posy =pSelEntity->m_begin.y;
ctextent.m_far =pSelEntity->m_far;
ctextent.m_high =pSelEntity->m_high;
ctextent.m_width =pSelEntity->m_width;
ctextent.m_lf =pSelEntity->m_lf;
ctextent.m_DateType=pSelEntity->m_datatype;
ctextent.m_TimeType=0;//pSelEntity->m_timetype;
if(pSelEntity->m_type== MNO)
{
ctextent.m_no=TRUE;
ctextent.m_date=FALSE;
ctextent.m_text=FALSE;
ctextent.m_time=FALSE;
}
if(pSelEntity->m_type== MDATA)
{
ctextent.m_no=FALSE;
ctextent.m_date=TRUE;
ctextent.m_text=FALSE;
ctextent.m_time=FALSE;
}
if(pSelEntity->m_type== MTIME)
{
ctextent.m_no=FALSE;
ctextent.m_date=FALSE;
ctextent.m_text=FALSE;
ctextent.m_time=TRUE;
}
if(pSelEntity->m_type==MTEXT)
{
ctextent.m_no=FALSE;
ctextent.m_date=FALSE;
ctextent.m_text=TRUE;
ctextent.m_time=FALSE;
}
if(ctextent.DoModal()==IDOK)
{
int type;
if(ctextent.m_no)
type=MNO;
if(ctextent.m_date)
type=MDATA;
if(ctextent.m_text)
type=MTEXT;
if(ctextent.m_time)
type=MTIME;
//--------------------------------------
if(ctextent.m_string=="")
{
g_pDoc->m_EntityList.RemoveAt(pos) ;
g_pDoc->UpdateAllViews(NULL) ;
m_selectArray.RemoveAll() ;
g_pDoc->SetModifiedFlag(TRUE);
return;
}
CDC* pDC = g_pView->GetDC();
CPoint begin;
begin.x = ctextent.m_posx;
begin.y = ctextent.m_posy;
CText* pNewText=new CText(begin,
ctextent.m_high,
ctextent.m_width,
ctextent.m_far,
ctextent.m_string,
type,ctextent.m_lf);
pNewText->m_datatype=ctextent.m_DateType;
pNewText->m_timetype=ctextent.m_TimeType;
pNewText->Draw(pDC,0);
g_pDoc->m_EntityList.AddTail(pNewText);
g_pView->ReleaseDC(pDC);
pos0 = m_EntityList.Find(pSelEntity) ;
m_EntityList.RemoveAt(pos0) ;
delete pSelEntity ;
pSelEntity = NULL ;
}
m_selectArray.RemoveAll() ;
UpdateAllViews(NULL) ;
g_pDoc->SetModifiedFlag(TRUE);
}
g_pDoc->UpdateAllViews(NULL) ;
}
BOOL CDabiaoDoc::IsSelected(CText *pEntity)
{
if( pEntity )
{
for( int i = 0 ; i < m_selectArray.GetSize() ; i++ )
{
if( pEntity == (CText*)m_selectArray[i] )
return TRUE ;
}
}
return FALSE;
}
void CDabiaoDoc::RemoveAllSelected()
{
CDC* pDC = g_pView->GetDC();
for( int i = 0 ; i < m_selectArray.GetSize() ; i++ ){
CText* pSelEntity = (CText*) m_selectArray[i] ;
pSelEntity->Draw(pDC, 0) ;
}
m_selectArray.RemoveAll() ;
g_pView->ReleaseDC(pDC);
}
BOOL CDabiaoDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
g_pView->OnClear();
if(!m_EntityList.IsEmpty())
m_EntityList.RemoveAll();
if (!CDocument::OnOpenDocument(lpszPathName))
return FALSE;
// TODO: Add your specialized creation code here
return TRUE;
}
void CDabiaoDoc::OnUpdateFileNew(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
// pCmdUI->Enable (!g_start);
}
void CDabiaoDoc::OnUpdateFileOpen(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
// pCmdUI->Enable (!g_start);
}
void CDabiaoDoc::OnUpdateFileSave(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
// pCmdUI->Enable (!g_start);
}
void CDabiaoDoc::OnUpdateFileSaveAs(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
// pCmdUI->Enable (!g_start);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?