home *** CD-ROM | disk | FTP | other *** search
- // contview.cpp : implementation of the CContView class
- //
-
- #include "stdafx.h"
- #include "cont.h"
-
- #include "contdoc.h"
- #include "cntritem.h"
- #include "contview.h"
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CContView
-
- IMPLEMENT_DYNCREATE(CContView, CView)
-
- BEGIN_MESSAGE_MAP(CContView, CView)
- //{{AFX_MSG_MAP(CContView)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- // DO NOT EDIT what you see in these blocks of generated code!
- ON_WM_SETFOCUS()
- ON_WM_SIZE()
- ON_COMMAND(ID_OLE_INSERT_NEW, OnInsertObject)
- ON_COMMAND(ID_CANCEL_EDIT_CNTR, OnCancelEditCntr)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CContView construction/destruction
-
- CContView::CContView()
- {
- // TODO: add construction code here
-
- }
-
- CContView::~CContView()
- {
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CContView drawing
-
- void CContView::OnDraw(CDC* pDC)
- {
- CContDoc* 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 CContCntrItem,
- // to give the effect of in-place editing.
-
- // TODO: remove this code when final draw code is complete.
-
- if (m_pSelection == NULL)
- {
- POSITION pos = pDoc->GetStartPosition();
- m_pSelection = (CContCntrItem*)pDoc->GetNextClientItem(pos);
- }
- if (m_pSelection != NULL)
- m_pSelection->Draw(pDC, CRect(10, 10, 210, 210));
- }
-
- void CContView::OnInitialUpdate()
- {
- CView::OnInitialUpdate();
-
- // TODO: remove this code when final selection model code is written
- m_pSelection = NULL; // initialize selection
-
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // OLE Client support and commands
-
- BOOL CContView::IsSelected(const CObject* pDocItem) const
- {
- // The implementation below is adequate if your selection consists of
- // only CContCntrItem 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 CContView::OnInsertObject()
- {
- // Invoke the standard Insert Object dialog box to obtain information
- // for new CContCntrItem object.
- COleInsertDialog dlg;
- if (dlg.DoModal() != IDOK)
- return;
-
- BeginWaitCursor();
-
- CContCntrItem* pItem = NULL;
- TRY
- {
- // Create new item connected to this document.
- CContDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- pItem = new CContCntrItem(pDoc);
- ASSERT_VALID(pItem);
-
- // Initialize the item from the dialog data.
- if (!dlg.CreateItem(pItem))
- AfxThrowMemoryException(); // any exception will do
- ASSERT_VALID(pItem);
-
- // If item created from class list (not from file) then launch
- // the server to edit the item.
- 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 CContView::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 CContView::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 CContView::OnSize(UINT nType, int cx, int cy)
- {
- CView::OnSize(nType, cx, cy);
- COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
- if (pActiveItem != NULL)
- pActiveItem->SetItemRects();
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CContView diagnostics
-
- #ifdef _DEBUG
- void CContView::AssertValid() const
- {
- CView::AssertValid();
- }
-
- void CContView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
-
- CContDoc* CContView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CContDoc)));
- return (CContDoc*)m_pDocument;
- }
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // CContView message handlers
-