【VC开源代码栏目提醒】:网学会员为广大网友收集整理了,ContainerView.cpp,希望对大家有所帮助!
// ContainerView.cpp : implementation of the CContainerView class
//
#include "stdafx.h"
#include "Container.h"
#include "ContainerDoc.h"
#include "CntrItem.h"
#include "ContainerView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CContainerView
IMPLEMENT_DYNCREATE(CContainerView, CView)
BEGIN_MESSAGE_MAP(CContainerView, CView)
//{{AFX_MSG_MAP(CContainerView)
ON_WM_DESTROY()
ON_WM_SETFOCUS()
ON_WM_SIZE()
ON_COMMAND(ID_OLE_INSERT_NEW, OnInsertObject)
ON_COMMAND(ID_CANCEL_EDIT_CNTR, OnCancelEditCntr)
ON_WM_SETCURSOR()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONDBLCLK()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CContainerView construction/destruction
CContainerView::CContainerView()
{
m_pSelection = NULL;
// TODO: add construction code here
}
CContainerView::~CContainerView()
{
}
BOOL CContainerView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CContainerView drawing
void CContainerView::OnDraw(CDC* pDC)
{
CContainerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
// TODO: also draw all OLE items in the document
// Draw the selection at an arbitrary position. This code should be
// removed once your real drawing code is implemented. This position
// corresponds exactly to the rectangle returned by CContainerCntrItem,
// to give the effect of in-place editing.
// TODO: remove this code when final draw code is complete.
POSITION pos=pDoc->GetStartPosition();
while(pos)
{
CContainerCntrItem* pObject=
(CContainerCntrItem*) pDoc->GetNextItem(pos);
pObject->Draw(pDC,pObject->m_objectRect);
CRectTracker tracker;
SetupTracker(&tracker,pObject);
tracker.Draw(pDC);
}
}
void CContainerView::OnInitialUpdate()
{
CView::OnInitialUpdate();
// TODO: remove this code when final selection model code is written
m_pSelection = NULL; // initialize selection
}
/////////////////////////////////////////////////////////////////////////////
// CContainerView printing
BOOL CContainerView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CContainerView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CContainerView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CContainerView::OnDestroy()
{
// Deactivate the item on destruction; this is important
// when a splitter view is being used.
CView::OnDestroy();
COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
if (pActiveItem != NULL && pActiveItem->GetActiveView() == this)
{
pActiveItem->Deactivate();
ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
}
}
/////////////////////////////////////////////////////////////////////////////
// OLE Client support and commands
BOOL CContainerView::IsSelected(const CObject* pDocItem) const
{
// The implementation below is adequate if your selection consists of
// only CContainerCntrItem objects. To handle different selection
// mechanisms, the implementation here should be replaced.
// TODO: implement this function that tests for a selected OLE client item
return pDocItem == m_pSelection;
}
void CContainerView::OnInsertObject()
{
// Invoke the standard Insert Object dialog box to obtain information
// for new CContainerCntrItem object.
COleInsertDialog dlg;
if (dlg.DoModal() != IDOK)
return;
BeginWaitCursor();
CContainerCntrItem* pItem = NULL;
TRY
{
// Create new item connected to this document.
CContainerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pItem = new CContainerCntrItem(pDoc);
ASSERT_VALID(pItem);
// Initialize the item from the dialog data.
if (!dlg.CreateItem(pItem))
AfxThrowMemoryException(); // any exception will do
ASSERT_VALID(pItem);
if (dlg.GetSelectionType() == COleInsertDialog::createNewItem)
pItem->DoVerb(OLEIVERB_SHOW, this);
ASSERT_VALID(pItem);
// As an arbitrary user interface design, this sets the selection
// to the last item inserted.
// TODO: reimplement selection as appropriate for your application
m_pSelection = pItem; // set selection to last inserted item
pDoc->UpdateAllViews(NULL);
}
CATCH(CException, e)
{
if (pItem != NULL)
{
ASSERT_VALID(pItem);
pItem->Delete();
}
AfxMessageBox(IDP_FAILED_TO_CREATE);
}
END_CATCH
EndWaitCursor();
}
// The following command handler provides the standard keyboard
// user interface to cancel an in-place editing session. Here,
// the container (not the server) causes the deactivation.
void CContainerView::OnCancelEditCntr()
{
// Close any in-place active item on this view.
COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
if (pActiveItem != NULL)
{
pActiveItem->Close();
}
ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
}
// Special handling of OnSetFocus and OnSize are required for a container
// when an object is being edited in-place.
void CContainerView::OnSetFocus(CWnd* pOldWnd)
{
COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
if (pActiveItem != NULL &&
pActiveItem->GetItemState() == COleClientItem::activeUIState)
{
// need to set focus to this item if it is in the same view
CWnd* pWnd = pActiveItem->GetInPlaceWindow();
if (pWnd != NULL)
{
pWnd->SetFocus(); // don't call the base class
return;
}
}
CView::OnSetFocus(pOldWnd);
}
void CContainerView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
if (pActiveItem != NULL)
pActiveItem->SetItemRects();
}
/////////////////////////////////////////////////////////////////////////////
// CContainerView diagnostics
#ifdef _DEBUG
void CContainerView::AssertValid() const
{
CView::AssertValid();
}
void CContainerView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
上一篇:
ContainerTest.cpp
下一篇:
ASP小区停车管理系统(Access)(含录像)