home *** CD-ROM | disk | FTP | other *** search
- // CntrItem.cpp : implementation of the CContainCntrItem class
- //
-
- #include "stdafx.h"
- #include "OContain.h"
-
- #include "ContainDoc.h"
- #include "CntrItem.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CContainCntrItem implementation
-
- IMPLEMENT_SERIAL(CContainCntrItem, COleClientItem, 0)
-
- CContainCntrItem::CContainCntrItem(CContainDoc* pContainer)
- : COleClientItem(pContainer)
- {
- m_rect.SetRect(10, 10, 50, 50);
-
- }
-
- CContainCntrItem::~CContainCntrItem()
- {
- // TODO: add cleanup code here
-
- }
-
- void CContainCntrItem::OnChange(OLE_NOTIFICATION nCode, DWORD dwParam)
- {
- ASSERT_VALID(this);
-
- COleClientItem::OnChange(nCode, dwParam);
-
- // When an item is being edited (either in-place or fully open)
- // it sends OnChange notifications for changes in the state of the
- // item or visual appearance of its content.
-
- switch (nCode)
- {
- case OLE_CHANGED :
- InvalidateItem();
- UpdateFromServerExtent();
- break;
-
- case OLE_CHANGED_STATE :
- case OLE_CHANGED_ASPECT :
- InvalidateItem();
- break;
- }
- }
-
- BOOL CContainCntrItem::OnChangeItemPosition(const CRect& rectPos)
- {
- ASSERT_VALID(this);
-
- // During in-place activation CContainCntrItem::OnChangeItemPosition
- // is called by the server to change the position of the in-place
- // window. Usually, this is a result of the data in the server
- // document changing such that the extent has changed or as a result
- // of in-place resizing.
- //
- // The default here is to call the base class, which will call
- // COleClientItem::SetItemRects to move the item
- // to the new position.
-
- if (!COleClientItem::OnChangeItemPosition(rectPos))
- return FALSE;
-
- InvalidateItem();
- m_rect = rectPos;
- InvalidateItem();
-
- // Mark document as dirty
- GetDocument()->SetModifiedFlag();
-
- return TRUE;
- }
-
- void CContainCntrItem::OnGetItemPosition(CRect& rPosition)
- {
- ASSERT_VALID(this);
-
- // During in-place activation, CContainCntrItem::OnGetItemPosition
- // will be called to determine the location of this item. The default
- // implementation created from AppWizard simply returns a hard-coded
- // rectangle. Usually, this rectangle would reflect the current
- // position of the item relative to the view used for activation.
- // You can obtain the view by calling CContainCntrItem::GetActiveView.
-
- rPosition = m_rect;
- }
-
- void CContainCntrItem::OnDeactivateUI(BOOL bUndoable)
- {
- COleClientItem::OnDeactivateUI(bUndoable);
-
- // Close an in-place active item whenever it removes the user
- // interface. The action here should match as closely as possible
- // to the handling of the escape key in the view.
-
- Deactivate(); // nothing fancy here -- just deactivate the object
- }
-
- void CContainCntrItem::Serialize(CArchive& ar)
- {
- ASSERT_VALID(this);
-
- // Call base class first to read in COleClientItem data.
- // Since this sets up the m_pDocument pointer returned from
- // CContainCntrItem::GetDocument, it is a good idea to call
- // the base class Serialize first.
- COleClientItem::Serialize(ar);
-
- // now store/retrieve data specific to CContainCntrItem
- if (ar.IsStoring())
- {
- ar << m_rect;
- }
- else
- {
- ar >> m_rect;
- }
- }
-
-
-
- void CContainCntrItem::InvalidateItem()
- {
- GetDocument()->UpdateAllViews(NULL, HINT_UPDATE_ITEM, this);
- }
-
-
-
- void CContainCntrItem::UpdateFromServerExtent()
- {
- CSize size;
- if (GetExtent(&size))
- {
- // OLE returns the extent in HIMETRIC units
- // however, we need pixels.
- CClientDC dc(NULL);
- dc.HIMETRICtoDP(&size);
-
- // Only invalidate if it has actually changed
- if (size != m_rect.Size())
- {
- // Invalidate old, update, invalidate new
- InvalidateItem();
- m_rect.bottom = m_rect.top + size.cy;
- m_rect.right = m_rect.left + size.cx;
- InvalidateItem();
-
- // Mark document as modified
- GetDocument()->SetModifiedFlag();
- }
-
- }
-
- }/////////////////////////////////////////////////////////////////////////////
- // CContainCntrItem diagnostics
-
- #ifdef _DEBUG
- void CContainCntrItem::AssertValid() const
- {
- COleClientItem::AssertValid();
- }
-
- void CContainCntrItem::Dump(CDumpContext& dc) const
- {
- COleClientItem::Dump(dc);
- }
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
-