📄 flowcharterview.cpp
字号:
// FlowcharterView.cpp : implementation of the CFlowcharterView class
//
#include "stdafx.h"
#include "Flowcharter.h"
#include "FlowcharterDoc.h"
#include "FlowcharterView.h"
#include "FlowchartEditor/FlowchartEntityTerminator.h"
#include "FlowchartEditor/FlowchartEntityBox.h"
#include "FlowchartEditor/FlowchartEntityCondition.h"
#include "FlowchartEditor/FlowchartEntityConnector.h"
#include "FlowchartEditor/FlowchartEntityIO.h"
#include "FlowchartEditor/FlowchartLineSegment.h"
#include "FlowchartEditor/FlowchartLinkableLineSegment.h"
#include "FlowchartEditor/FlowchartLabel.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CFlowcharterView
IMPLEMENT_DYNCREATE(CFlowcharterView, CView)
BEGIN_MESSAGE_MAP(CFlowcharterView, CView)
//{{AFX_MSG_MAP(CFlowcharterView)
ON_WM_SIZE()
ON_WM_ERASEBKGND()
ON_COMMAND(ID_BUTTON_BOX, OnButtonBox)
ON_COMMAND(ID_BUTTON_CONDITION, OnButtonCondition)
ON_COMMAND(ID_BUTTON_CONNECTOR, OnButtonConnector)
ON_COMMAND(ID_BUTTON_IO, OnButtonIo)
ON_COMMAND(ID_BUTTON_LINE, OnButtonLine)
ON_COMMAND(ID_BUTTON_START, OnButtonStart)
ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateEditCopy)
ON_COMMAND(ID_EDIT_CUT, OnEditCut)
ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, OnUpdateEditCut)
ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdateEditPaste)
ON_COMMAND(ID_EDIT_UNDO, OnEditUndo)
ON_UPDATE_COMMAND_UI(ID_EDIT_UNDO, OnUpdateEditUndo)
ON_COMMAND(ID_EXPORT_TO_META, OnExportToMeta)
ON_COMMAND(ID_BUTTON_ARROW, OnButtonArrow)
ON_COMMAND(ID_BUTTON_SNAP, OnButtonSnap)
ON_UPDATE_COMMAND_UI(ID_BUTTON_SNAP, OnUpdateButtonSnap)
ON_COMMAND(ID_BUTTON_LABEL, OnButtonLabel)
ON_COMMAND(ID_BREAK_LINK, OnBreakLink)
ON_UPDATE_COMMAND_UI(ID_BREAK_LINK, OnUpdateBreakLink)
ON_COMMAND(ID_CREATE_LINK, OnCreateLink)
ON_UPDATE_COMMAND_UI(ID_CREATE_LINK, OnUpdateCreateLink)
ON_COMMAND(ID_LINK_LABEL, OnLinkLabel)
ON_UPDATE_COMMAND_UI(ID_LINK_LABEL, OnUpdateLinkLabel)
ON_COMMAND(ID_FLIP_LINK, OnFlipLink)
ON_UPDATE_COMMAND_UI(ID_FLIP_LINK, OnUpdateFlipLink)
ON_COMMAND(ID_SHOW_PROPERTIES, OnShowProperties)
ON_UPDATE_COMMAND_UI(ID_SHOW_PROPERTIES, OnUpdateShowProperties)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CFlowcharterView construction/destruction
CFlowcharterView::CFlowcharterView()
{
m_screenResolutionX = 0;
}
CFlowcharterView::~CFlowcharterView()
{
}
BOOL CFlowcharterView::PreCreateWindow(CREATESTRUCT& cs)
{
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CFlowcharterView drawing
void CFlowcharterView::OnDraw(CDC* pDC)
{
CFlowcharterDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if( pDC->IsPrinting() )
{
COLORREF col = m_editor.GetBackgroundColor();
// Print zoom is the difference between screen-
// and printer resolution.
double zoom = pDC->GetDeviceCaps( LOGPIXELSX ) / m_screenResolutionX;
CRect rect( 0,0,
( int )( ( double ) m_editor.GetVirtualSize().cx * zoom ),
( int )( ( double ) m_editor.GetVirtualSize().cy * zoom ) );
m_editor.SetRedraw( FALSE );
m_editor.SetBackgroundColor( RGB( 255, 255, 255 ) );
m_editor.Print( pDC, rect, zoom );
m_editor.SetBackgroundColor( col );
m_editor.SetRedraw( TRUE );
}
}
/////////////////////////////////////////////////////////////////////////////
// CFlowcharterView printing
BOOL CFlowcharterView::OnPreparePrinting(CPrintInfo* pInfo)
{
return DoPreparePrinting(pInfo);
}
void CFlowcharterView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
}
void CFlowcharterView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
}
/////////////////////////////////////////////////////////////////////////////
// CFlowcharterView diagnostics
#ifdef _DEBUG
void CFlowcharterView::AssertValid() const
{
CView::AssertValid();
}
void CFlowcharterView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CFlowcharterDoc* CFlowcharterView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CFlowcharterDoc)));
return (CFlowcharterDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CFlowcharterView message handlers
void CFlowcharterView::OnInitialUpdate()
{
CView::OnInitialUpdate();
if( !m_editor.m_hWnd )
{
// Creating the editor window
CFlowcharterDoc* pDoc = GetDocument();
CRect rect;
GetClientRect( rect );
pDoc->GetData()->SetClipboardHandler( &theApp.m_clip );
m_editor.Create( WS_CHILD | WS_VISIBLE, rect, this, pDoc->GetData() );
// We get the screen resolution, which we will use
// for scaling to printer. See also OnDraw.
CClientDC dc( this );
m_screenResolutionX = dc.GetDeviceCaps( LOGPIXELSX );
int horzSize = round( ( double ) dc.GetDeviceCaps( HORZSIZE ) / ( double ) m_screenResolutionX );
int vertSize = round( ( double ) dc.GetDeviceCaps( VERTSIZE ) / ( double ) m_screenResolutionX );
m_editor.SetVirtualSize( CSize( 8 * m_screenResolutionX, 11 * m_screenResolutionX ) );
m_editor.SetModified( FALSE );
}
else
m_editor.Clear();
}
void CFlowcharterView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
if( m_editor.m_hWnd )
m_editor.MoveWindow(0,0,cx,cy);
}
BOOL CFlowcharterView::OnEraseBkgnd(CDC* /*pDC*/ )
{
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CFlowcharterView command handlers
// Toolbar objects
void CFlowcharterView::OnButtonBox()
{
m_editor.StartDrawingObject( new CFlowchartEntityBox );
}
void CFlowcharterView::OnButtonCondition()
{
m_editor.StartDrawingObject( new CFlowchartEntityCondition );
}
void CFlowcharterView::OnButtonConnector()
{
m_editor.StartDrawingObject( new CFlowchartEntityConnector );
}
void CFlowcharterView::OnButtonIo()
{
m_editor.StartDrawingObject( new CFlowchartEntityIO );
}
void CFlowcharterView::OnButtonLine()
{
m_editor.StartDrawingObject( new CFlowchartLineSegment );
}
void CFlowcharterView::OnButtonStart()
{
m_editor.StartDrawingObject( new CFlowchartEntityTerminator );
}
void CFlowcharterView::OnButtonArrow()
{
m_editor.StartDrawingObject( new CFlowchartLinkableLineSegment );
}
void CFlowcharterView::OnButtonLabel()
{
m_editor.StartDrawingObject( new CFlowchartLabel );
}
void CFlowcharterView::OnButtonSnap()
{
BOOL snap = !m_editor.GetSnapToGrid();
m_editor.SetSnapToGrid( snap );
m_editor.ShowGrid( snap );
}
// Edit menu
void CFlowcharterView::OnEditCopy()
{
m_editor.Copy();
}
void CFlowcharterView::OnEditCut()
{
m_editor.Cut();
}
void CFlowcharterView::OnEditPaste()
{
m_editor.Paste();
}
void CFlowcharterView::OnEditUndo()
{
m_editor.Undo();
}
void CFlowcharterView::OnShowProperties()
{
m_editor.ShowProperties();
}
// File menu
void CFlowcharterView::OnExportToMeta()
{
CFileDialog dlg( FALSE, _T( "emf") );
if( dlg.DoModal() == IDOK )
{
CClientDC dc( this );
CMetaFileDC metaDC;
CRect rect( 0,0,
m_editor.GetVirtualSize().cx,
m_editor.GetVirtualSize().cy );
// Himetric rect
CRect r( 0, 0, 8 * 2540, 11 * 2540 );
metaDC.CreateEnhanced( &dc, dlg.GetPathName(), &r, _T( "FlowchartEditor Drawing" ) );
m_editor.SetRedraw( FALSE );
COLORREF col = m_editor.GetBackgroundColor();
m_editor.SetBackgroundColor( RGB( 255, 255, 255 ) );
m_editor.Print( &metaDC, rect, 1 );
m_editor.SetBackgroundColor( col );
m_editor.SetRedraw( TRUE );
m_editor.RedrawWindow();
::DeleteEnhMetaFile ( metaDC.CloseEnhanced() );
}
}
// Links menu
void CFlowcharterView::OnCreateLink()
{
m_editor.OnLink();
}
void CFlowcharterView::OnBreakLink()
{
m_editor.OnUnlink();
}
void CFlowcharterView::OnLinkLabel()
{
m_editor.OnLinkProperties();
}
void CFlowcharterView::OnFlipLink()
{
m_editor.OnLinkDirection();
}
/////////////////////////////////////////////////////////////////////////////
// CFlowcharterView cammand enablers
// Edit menu
void CFlowcharterView::OnUpdateEditUndo(CCmdUI* pCmdUI)
{
m_editor.UpdateUndo( pCmdUI );
}
void CFlowcharterView::OnUpdateEditCopy(CCmdUI* pCmdUI)
{
m_editor.UpdateCopy( pCmdUI );
}
void CFlowcharterView::OnUpdateEditCut(CCmdUI* pCmdUI)
{
m_editor.UpdateCut( pCmdUI );
}
void CFlowcharterView::OnUpdateEditPaste(CCmdUI* pCmdUI)
{
m_editor.UpdatePaste( pCmdUI );
}
void CFlowcharterView::OnUpdateShowProperties(CCmdUI* pCmdUI)
{
pCmdUI->Enable( m_editor.GetSelectCount() == 1 );
}
// Toolbar
void CFlowcharterView::OnUpdateButtonSnap(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck( m_editor.GetSnapToGrid() );
}
// Links menu
void CFlowcharterView::OnUpdateBreakLink(CCmdUI* pCmdUI)
{
pCmdUI->Enable( m_editor.IsLinked() );
}
void CFlowcharterView::OnUpdateCreateLink(CCmdUI* pCmdUI)
{
pCmdUI->Enable( m_editor.CanLink() );
}
void CFlowcharterView::OnUpdateLinkLabel(CCmdUI* pCmdUI)
{
pCmdUI->Enable( m_editor.IsLinked() );
}
void CFlowcharterView::OnUpdateFlipLink(CCmdUI* pCmdUI)
{
pCmdUI->Enable( m_editor.IsLinked() );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -