📄 picturestreamview.cpp
字号:
// PictureStreamView.cpp : implementation of the CPictureStreamView class
//
#include "stdafx.h"
#include "PictureStream.h"
#include "PictureStreamDoc.h"
#include "PictureStreamView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CPoint CPictureStreamView::c_down(0,0);
UINT CPictureStreamView::c_nDownFlags(0);
CPoint CPictureStreamView::c_last(0,0);
/////////////////////////////////////////////////////////////////////////////
// CPictureStreamView
IMPLEMENT_DYNCREATE(CPictureStreamView, CScrollView)
BEGIN_MESSAGE_MAP(CPictureStreamView, CScrollView)
//{{AFX_MSG_MAP(CPictureStreamView)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_SIZE()
ON_COMMAND(ID_PICTURE_ZOOMIN, OnPictureZoomin)
ON_UPDATE_COMMAND_UI(ID_PICTURE_ZOOMIN, OnUpdatePictureZoomin)
ON_COMMAND(ID_PICTURE_ZOOMOUT, OnPictureZoomout)
ON_UPDATE_COMMAND_UI(ID_PICTURE_ZOOMOUT, OnUpdatePictureZoomout)
ON_COMMAND(ID_EDIT_CLEAR, OnEditClear)
ON_UPDATE_COMMAND_UI(ID_EDIT_CLEAR, OnUpdateEditClear)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPictureStreamView construction/destruction
CPictureStreamView::CPictureStreamView():
m_pSel(NULL)
{
// TODO: add construction code here
}
CPictureStreamView::~CPictureStreamView()
{
}
BOOL CPictureStreamView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CPictureStreamView drawing
void CPictureStreamView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
CScrollView::OnPrepareDC(pDC, pInfo);
}
void CPictureStreamView::OnDraw(CDC* pDC)
{
GetObjects()->Draw(pDC);
}
void CPictureStreamView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CSize sizeTotal(600,800);
SetScrollSizes(MM_TEXT, sizeTotal);
}
CPictureObjList* CPictureStreamView::GetObjects()
{
return &GetDocument()->m_objects;
}
/////////////////////////////////////////////////////////////////////////////
// CPictureStreamView printing
BOOL CPictureStreamView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CPictureStreamView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CPictureStreamView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CPictureStreamView diagnostics
#ifdef _DEBUG
void CPictureStreamView::AssertValid() const
{
CScrollView::AssertValid();
}
void CPictureStreamView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CPictureStreamDoc* CPictureStreamView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPictureStreamDoc)));
return (CPictureStreamDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CPictureStreamView message handlers
void CPictureStreamView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
pSender;pHint;
switch (lHint)
{
case HINT_UPDATE_WINDOW: // redraw entire window
{
Invalidate();
}
break;
default:
break;
}
}
void CPictureStreamView::InvalObj(CPictureObj* pObj)
{
if(pObj == NULL)
return;
CRect rect = pObj->GetPosition();
rect.InflateRect(4,4);
InvalidateRect(rect);
}
void CPictureStreamView::OnLButtonDown(UINT nFlags, CPoint point)
{
CPictureObj* pSelPrev = m_pSel;
GetObjects()->DeselectAll();
m_pSel = GetObjects()->ObjectAt(point);
bool bChanged = m_pSel != pSelPrev;
if(bChanged && pSelPrev)
{
InvalObj(pSelPrev);
}
if(m_pSel)
{
m_pSel->SetSelected(true);
m_pSel->SetVisible(false);
InvalObj(m_pSel);
}
if(bChanged)
GetDocument()->SetModifiedFlag(TRUE);
SetCapture();
c_nDownFlags = nFlags;
c_down = point;
c_last = point;
}
void CPictureStreamView::OnLButtonUp(UINT nFlags, CPoint point)
{
nFlags;
ReleaseCapture();
if(m_pSel)
{
m_pSel->SetVisible(true);
InvalidateRect(m_pSel->GetPosition());
GetDocument()->SetModifiedFlag(TRUE);
}
c_last = point;
}
void CPictureStreamView::OnMouseMove(UINT nFlags, CPoint point)
{
nFlags;
CPoint local = point;
if(GetCapture() == this)
{
CPoint delta = local - c_last;
if(m_pSel)
{
CRect position = m_pSel->GetPosition();
position += delta;
m_pSel->MoveTo(position, this);
}
}
c_last = point;
}
void CPictureStreamView::OnSize(UINT nType, int cx, int cy)
{
CScrollView::OnSize(nType, cx, cy);
}
void CPictureStreamView::OnPictureZoomin()
{
ASSERT(m_pSel);
InvalObj(m_pSel);
m_pSel->ZoomOut();
InvalObj(m_pSel);
GetDocument()->SetModifiedFlag(TRUE);
}
void CPictureStreamView::OnUpdatePictureZoomin(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_pSel != NULL);
}
void CPictureStreamView::OnPictureZoomout()
{
ASSERT(m_pSel);
InvalObj(m_pSel);
m_pSel->ZoomIn();
InvalObj(m_pSel);
GetDocument()->SetModifiedFlag(TRUE);
}
void CPictureStreamView::OnUpdatePictureZoomout(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_pSel != NULL);
}
void CPictureStreamView::OnEditClear()
{
ASSERT(m_pSel);
CRect rect = m_pSel->GetPosition();
InvalObj(m_pSel);
GetObjects()->Remove(m_pSel);
delete m_pSel;
m_pSel = NULL;
rect.InflateRect(8,8);
InvalidateRect(rect);
GetDocument()->SetModifiedFlag(TRUE);
}
void CPictureStreamView::OnUpdateEditClear(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_pSel != NULL);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -