home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / tutorial / contain / step1 / cntritem.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  3.6 KB  |  148 lines

  1. // CntrItem.cpp : implementation of the CContainerItem class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Contain.h"
  6.  
  7. #include "ContrDoc.h"
  8. #include "CntrItem.h"
  9. #include "ContrVw.h"
  10.  
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CContainerItem implementation
  19.  
  20. IMPLEMENT_SERIAL(CContainerItem, COleClientItem, 0)
  21.  
  22. CContainerItem::CContainerItem(CContainerDoc* pContainer)
  23.     : COleClientItem(pContainer)
  24. {
  25.     // TODO: add one-time construction code here
  26.     m_rect.SetRect(10, 10, 50, 50);
  27. }
  28.  
  29. CContainerItem::~CContainerItem()
  30. {
  31.     // TODO: add cleanup code here
  32.  
  33. }
  34.  
  35.  
  36. void CContainerItem::OnChange(OLE_NOTIFICATION nCode, DWORD dwParam)
  37. {
  38.     ASSERT_VALID(this);
  39.  
  40.     COleClientItem::OnChange(nCode, dwParam);
  41.  
  42.     // When an item is being edited (either in-place or fully open)
  43.     //  it sends OnChange notifications for changes in the state of the
  44.     //  item or visual appearance of its content.
  45.  
  46.     // TODO: invalidate the item by calling UpdateAllViews
  47.     //  (with hints appropriate to your application)
  48.  
  49.     GetDocument()->UpdateAllViews(NULL);
  50.         // for now just update ALL views/no hints
  51.  
  52. }
  53.  
  54. BOOL CContainerItem::OnChangeItemPosition(const CRect& rectPos)
  55. {
  56.     ASSERT_VALID(this);
  57.  
  58.     // During in-place activation CContainerItem::OnChangeItemPosition
  59.     //  is called by the server to change the position of the in-place
  60.     //  window.  Usually, this is a result of the data in the server
  61.     //  document changing such that the extent has changed or as a result
  62.     //  of in-place resizing.
  63.     //
  64.     // The default here is to call the base class, which will call
  65.     //  COleClientItem::SetItemRects to move the item
  66.     //  to the new position.
  67.  
  68.     if (!COleClientItem::OnChangeItemPosition(rectPos))
  69.         return FALSE;
  70.     GetDocument()->UpdateAllViews(NULL);
  71.     m_rect = rectPos;
  72.  
  73.     // mark document as dirty
  74.     GetDocument()->SetModifiedFlag();
  75.  
  76.     return TRUE;
  77. }
  78.  
  79. void CContainerItem::OnGetItemPosition(CRect& rPosition)
  80. {
  81.     ASSERT_VALID(this);
  82.     // return rect relative to client area of view
  83.     rPosition = m_rect;
  84. }
  85.  
  86. void CContainerItem::OnActivate()
  87. {
  88.     // allow only one inplace active item per frame
  89.     CView* pView = GetActiveView();
  90.     ASSERT_VALID(pView);
  91.     COleClientItem* pItem = GetDocument()->GetInPlaceActiveItem(pView);
  92.     if (pItem != NULL && pItem != this)
  93.         pItem->Close();
  94.  
  95.     COleClientItem::OnActivate();
  96. }
  97.  
  98. void CContainerItem::OnDeactivateUI(BOOL bUndoable)
  99. {
  100.     COleClientItem::OnDeactivateUI(bUndoable);
  101.  
  102.     // hide the object if it is not an outside-in object
  103.     DWORD dwMisc = 0;
  104.     m_lpObject->GetMiscStatus(GetDrawAspect(), &dwMisc);
  105.     if (dwMisc & OLEMISC_INSIDEOUT)
  106.         DoVerb(OLEIVERB_HIDE, NULL);
  107. }
  108.  
  109. void CContainerItem::Serialize(CArchive& ar)
  110. {
  111.     ASSERT_VALID(this);
  112.  
  113.     // Call base class first to read in COleClientItem data.
  114.     // Since this sets up the m_pDocument pointer returned from
  115.     //  CContainerItem::GetDocument, it is a good idea to call
  116.     //  the base class Serialize first.
  117.     COleClientItem::Serialize(ar);
  118.  
  119.     // now store/retrieve data specific to CContainerItem
  120.     if (ar.IsStoring())
  121.     {
  122.         // TODO: add storing code here
  123.         ar << m_rect;
  124.     }
  125.     else
  126.     {
  127.         // TODO: add loading code here
  128.         ar >> m_rect;
  129.     }
  130. }
  131.  
  132. /////////////////////////////////////////////////////////////////////////////
  133. // CContainerItem diagnostics
  134.  
  135. #ifdef _DEBUG
  136. void CContainerItem::AssertValid() const
  137. {
  138.     COleClientItem::AssertValid();
  139. }
  140.  
  141. void CContainerItem::Dump(CDumpContext& dc) const
  142. {
  143.     COleClientItem::Dump(dc);
  144. }
  145. #endif
  146.  
  147. /////////////////////////////////////////////////////////////////////////////
  148.