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

  1. // CntrItem.cpp : implementation of the CContainerMFCCntrItem class
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13.  
  14. #include "stdafx.h"
  15. #include "containerMFC.h"
  16.  
  17. #include "containerMFCDoc.h"
  18. #include "containerMFCView.h"
  19. #include "CntrItem.h"
  20.  
  21. #ifdef _DEBUG
  22. #define new DEBUG_NEW
  23. #undef THIS_FILE
  24. static char THIS_FILE[] = __FILE__;
  25. #endif
  26.  
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CContainerMFCCntrItem implementation
  29.  
  30. IMPLEMENT_SERIAL(CContainerMFCCntrItem, COleClientItem, 0)
  31.  
  32. CContainerMFCCntrItem::CContainerMFCCntrItem(CContainerMFCDoc* pContainer)
  33.     : COleClientItem(pContainer)
  34. {
  35.     // TODO: add one-time construction code here
  36.  
  37. }
  38.  
  39. CContainerMFCCntrItem::~CContainerMFCCntrItem()
  40. {
  41.     // TODO: add cleanup code here
  42.  
  43. }
  44.  
  45. void CContainerMFCCntrItem::OnChange(OLE_NOTIFICATION nCode, DWORD dwParam)
  46. {
  47.     ASSERT_VALID(this);
  48.  
  49.     COleClientItem::OnChange(nCode, dwParam);
  50.  
  51.     // When an item is being edited (either in-place or fully open)
  52.     //  it sends OnChange notifications for changes in the state of the
  53.     //  item or visual appearance of its content.
  54.  
  55.     // TODO: invalidate the item by calling UpdateAllViews
  56.     //  (with hints appropriate to your application)
  57.  
  58.     GetDocument()->UpdateAllViews(NULL);
  59.         // for now just update ALL views/no hints
  60. }
  61.  
  62. BOOL CContainerMFCCntrItem::OnChangeItemPosition(const CRect& rectPos)
  63. {
  64.     ASSERT_VALID(this);
  65.  
  66.     // During in-place activation CContainerMFCCntrItem::OnChangeItemPosition
  67.     //  is called by the server to change the position of the in-place
  68.     //  window.  Usually, this is a result of the data in the server
  69.     //  document changing such that the extent has changed or as a result
  70.     //  of in-place resizing.
  71.     //
  72.     // The default here is to call the base class, which will call
  73.     //  COleClientItem::SetItemRects to move the item
  74.     //  to the new position.
  75.  
  76.     if (!COleClientItem::OnChangeItemPosition(rectPos))
  77.         return FALSE;
  78.  
  79.     // TODO: update any cache you may have of the item's rectangle/extent
  80.  
  81.     return TRUE;
  82. }
  83.  
  84. void CContainerMFCCntrItem::OnGetItemPosition(CRect& rPosition)
  85. {
  86.     ASSERT_VALID(this);
  87.  
  88.     // During in-place activation, CContainerMFCCntrItem::OnGetItemPosition
  89.     //  will be called to determine the location of this item.  The default
  90.     //  implementation created from AppWizard simply returns a hard-coded
  91.     //  rectangle.  Usually, this rectangle would reflect the current
  92.     //  position of the item relative to the view used for activation.
  93.     //  You can obtain the view by calling CContainerMFCCntrItem::GetActiveView.
  94.  
  95.     CRect   r;
  96.     GetActiveView()->GetClientRect(&r);
  97.     rPosition = r;
  98. }
  99.  
  100. void CContainerMFCCntrItem::OnActivate()
  101. {
  102.     // Allow only one inplace activate item per frame
  103.     CContainerMFCView* pView = GetActiveView();
  104.     ASSERT_VALID(pView);
  105.     COleClientItem* pItem = GetDocument()->GetInPlaceActiveItem(pView);
  106.     if (pItem != NULL && pItem != this)
  107.         pItem->Close();
  108.  
  109.     COleClientItem::OnActivate();
  110. }
  111.  
  112. void CContainerMFCCntrItem::OnDeactivateUI(BOOL bUndoable)
  113. {
  114.     COleClientItem::OnDeactivateUI(bUndoable);
  115.  
  116.     // Hide the object if it is not an outside-in object
  117.     DWORD dwMisc = 0;
  118.     m_lpObject->GetMiscStatus(GetDrawAspect(), &dwMisc);
  119.     if (dwMisc & OLEMISC_INSIDEOUT)
  120.         DoVerb(OLEIVERB_HIDE, NULL);
  121. }
  122.  
  123. void CContainerMFCCntrItem::Serialize(CArchive& ar)
  124. {
  125.     ASSERT_VALID(this);
  126.  
  127.     // Call base class first to read in COleClientItem data.
  128.     // Since this sets up the m_pDocument pointer returned from
  129.     //  CContainerMFCCntrItem::GetDocument, it is a good idea to call
  130.     //  the base class Serialize first.
  131.     COleClientItem::Serialize(ar);
  132.  
  133.     // now store/retrieve data specific to CContainerMFCCntrItem
  134.     if (ar.IsStoring())
  135.     {
  136.         // TODO: add storing code here
  137.     }
  138.     else
  139.     {
  140.         // TODO: add loading code here
  141.     }
  142. }
  143.  
  144. /////////////////////////////////////////////////////////////////////////////
  145. // CContainerMFCCntrItem diagnostics
  146.  
  147. #ifdef _DEBUG
  148. void CContainerMFCCntrItem::AssertValid() const
  149. {
  150.     COleClientItem::AssertValid();
  151. }
  152.  
  153. void CContainerMFCCntrItem::Dump(CDumpContext& dc) const
  154. {
  155.     COleClientItem::Dump(dc);
  156. }
  157. #endif
  158.  
  159. /////////////////////////////////////////////////////////////////////////////
  160.