home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Troubleshooting Netware Systems
/
CSTRIAL0196.BIN
/
attach
/
msj
/
v10n04
/
olecont.exe
/
CONTVIEW.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-01
|
10KB
|
383 lines
// contview.cpp : implementation of the CContainerView class
//
#include "stdafx.h"
#include "contain.h"
#include "cntlinfo.h"
#include "contdoc.h"
#include "cntlitem.h"
#include "contitem.h"
#include "contview.h"
#include "inctldlg.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// definitions
#define MARGIN_PIXELS 6
/////////////////////////////////////////////////////////////////////////////
// CContainerView
IMPLEMENT_DYNCREATE(CContainerView, CView)
BEGIN_MESSAGE_MAP(CContainerView, CView)
//{{AFX_MSG_MAP(CContainerView)
ON_WM_SETFOCUS()
ON_WM_SIZE()
ON_COMMAND(ID_OLE_INSERT_NEW, InsertObject)
ON_COMMAND(ID_CANCEL_EDIT_CNTR, OnCancelEdit)
ON_WM_LBUTTONDBLCLK()
ON_WM_LBUTTONDOWN()
ON_WM_SETCURSOR()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CContainerView construction/destruction
CContainerView::CContainerView()
{
m_pSelection = NULL;
}
CContainerView::~CContainerView()
{
}
/////////////////////////////////////////////////////////////////////////////
// CContainerView drawing
void CContainerView::SetupTracker(CRectTracker* pTracker, CContainerItem* pItem)
{
ASSERT(pTracker != NULL);
ASSERT(pItem != NULL);
pTracker->m_nHandleSize = MARGIN_PIXELS;
pTracker->m_rect = pItem->m_rect;
pTracker->m_rect.InflateRect(MARGIN_PIXELS, MARGIN_PIXELS);
if (pItem == m_pSelection)
pTracker->m_nStyle |= CRectTracker::resizeInside;
if (pItem->GetType() == OT_LINK)
pTracker->m_nStyle |= CRectTracker::dottedLine;
else
pTracker->m_nStyle |= CRectTracker::solidLine;
if (pItem->GetItemState() == COleClientItem::openState ||
pItem->GetItemState() == COleClientItem::activeUIState)
{
pTracker->m_nStyle |= CRectTracker::hatchInside;
}
}
void CContainerView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
CView::OnPrepareDC(pDC, pInfo);
}
void CContainerView::OnDraw(CDC* pDC)
{
CContainerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// Draw all CContainerItems
POSITION pos = pDoc->GetStartPosition();
while (pos != NULL)
{
CContainerItem* pItem = (CContainerItem*)pDoc->GetNextItem(pos);
pItem->Draw(pDC, pItem->m_rect);
// draw the tracker
CRectTracker tracker;
SetupTracker(&tracker, pItem);
tracker.Draw(pDC);
}
}
void CContainerView::OnInitialUpdate()
{
CView::OnInitialUpdate();
// TODO: remove this code when final selection model code is written
m_pSelection = NULL; // initialize selection
}
void CContainerView::InvalidateItem(CContainerItem* pItem)
{
pItem->Invalidate();
}
/////////////////////////////////////////////////////////////////////////////
// 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
}
/////////////////////////////////////////////////////////////////////////////
// OLE Client support and commands
BOOL CContainerView::IsSelected(const CObject* pDocItem) const
{
return pDocItem == m_pSelection;
}
CContainerItem* CContainerView::HitTestItems(CPoint point)
{
CContainerDoc* pDoc = GetDocument();
CContainerItem* pCtlHit = NULL;
POSITION pos = pDoc->GetStartPosition();
while (pos != NULL)
{
CContainerItem* pCtl = (CContainerItem*)pDoc->GetNextItem(pos);
if (pCtl->IsKindOf(RUNTIME_CLASS(CContainerItem)))
{
CRectTracker tracker;
SetupTracker(&tracker, pCtl);
if (tracker.HitTest(point) >= 0)
{
pCtlHit = pCtl;
// items later in the list are drawn on top - so keep looking
}
}
}
return pCtlHit; // return top item at point
}
void CContainerView::SetSelection(CContainerItem* pNewSel)
{
if (pNewSel != NULL && pNewSel == m_pSelection)
return;
// deactivate any in-place active item on this view!
COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
if (pActiveItem != NULL && pNewSel != pActiveItem)
{
// if we found one, deactivate it
pActiveItem->Close();
ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
}
if (m_pSelection != NULL) // invalidate the old item
InvalidateItem(m_pSelection);
if ((m_pSelection = pNewSel) != NULL) // invalidate the new item
InvalidateItem(m_pSelection);
}
void CContainerView::InsertObject()
{
// Invoke the standard Insert Object dialog box to obtain information
// for new CContainerItem object.
COleInsertCtlDlg dlg(this);
if (dlg.DoModal() != IDOK)
return;
BeginWaitCursor();
CContainerItem* pItem = NULL;
TRY
{
// Create new item connected to this document.
CContainerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pItem = new CContainerItem(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->UpdateLink();
pItem->UpdateExtent();
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.
void CContainerView::OnCancelEdit()
{
// 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);
}
CContainerDoc* CContainerView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CContainerDoc)));
return (CContainerDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CContainerView message handlers
void CContainerView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
OnLButtonDown(nFlags, point);
if (m_pSelection != NULL)
{
m_pSelection->DoVerb(GetKeyState(VK_CONTROL) < 0 ?
OLEIVERB_OPEN : OLEIVERB_PRIMARY, this);
}
CView::OnLButtonDblClk(nFlags, point);
}
void CContainerView::OnLButtonDown(UINT nFlags, CPoint point)
{
CContainerItem* pItemHit = HitTestItems(point);
SetSelection(pItemHit);
if (pItemHit != NULL)
{
CRectTracker tracker;
SetupTracker(&tracker, pItemHit);
UpdateWindow();
if (tracker.Track(this, point))
{
pItemHit->Invalidate();
tracker.m_rect.InflateRect(-MARGIN_PIXELS, -MARGIN_PIXELS);
pItemHit->Move(tracker.m_rect);
pItemHit->Invalidate();
GetDocument()->SetModifiedFlag();
}
}
CView::OnLButtonDown(nFlags, point);
}
BOOL CContainerView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
if (pWnd == this && m_pSelection != NULL)
{
// give the tracker for the selection a chance
CRectTracker tracker;
SetupTracker(&tracker, m_pSelection);
if (tracker.SetCursor(this, nHitTest))
return TRUE;
}
return CView::OnSetCursor(pWnd, nHitTest, message);
}
void CContainerView::OnDestroy()
{
CView::OnDestroy();
// Deactivate the in place active item on this view
// Note: To handle multiple inplace items, you will need to
// iterate through all of the items and deactivate those that
// apply.
COleClientItem* pItem = GetDocument()->GetInPlaceActiveItem(this);
if (pItem != NULL && pItem->GetActiveView() == this)
{
pItem->Deactivate();
ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
}
}