home *** CD-ROM | disk | FTP | other *** search
/ Building OCXs / Building_OCXs_Que_1995.iso / code / ch07 / cntritem.cpp next >
Encoding:
C/C++ Source or Header  |  1995-01-15  |  3.6 KB  |  136 lines

  1. // cntritem.cpp : implementation of the CContCntrItem class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "cont.h"
  6.  
  7. #include "contdoc.h"
  8. #include "cntritem.h"
  9.  
  10. #ifdef _DEBUG
  11. #undef THIS_FILE
  12. static char BASED_CODE THIS_FILE[] = __FILE__;
  13. #endif
  14.  
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CContCntrItem implementation
  17.  
  18. IMPLEMENT_SERIAL(CContCntrItem, COleClientItem, 0)
  19.  
  20. CContCntrItem::CContCntrItem(CContDoc* pContainer)
  21.     : COleClientItem(pContainer)
  22. {
  23.     // TODO: add one-time construction code here
  24.     
  25. }
  26.  
  27. CContCntrItem::~CContCntrItem()
  28. {
  29.     // TODO: add cleanup code here
  30.     
  31. }
  32.  
  33. void CContCntrItem::OnChange(OLE_NOTIFICATION nCode, DWORD dwParam)
  34. {
  35.     ASSERT_VALID(this);
  36.  
  37.     COleClientItem::OnChange(nCode, dwParam);
  38.  
  39.     // When an item is being edited (either in-place or fully open)
  40.     //  it sends OnChange notifications for changes in the state of the
  41.     //  item or visual appearance of its content.
  42.  
  43.     // TODO: invalidate the item by calling UpdateAllViews
  44.     //  (with hints appropriate to your application)
  45.  
  46.     GetDocument()->UpdateAllViews(NULL);
  47.         // for now just update ALL views/no hints
  48. }
  49.  
  50. BOOL CContCntrItem::OnChangeItemPosition(const CRect& rectPos)
  51. {
  52.     ASSERT_VALID(this);
  53.  
  54.     // During in-place activation CContCntrItem::OnChangeItemPosition
  55.     //  is called by the server to change the position of the in-place
  56.     //  window.  Usually, this is a result of the data in the server
  57.     //  document changing such that the extent has changed or as a result
  58.     //  of in-place resizing.
  59.     //
  60.     // The default here is to call the base class, which will call
  61.     //  COleClientItem::SetItemRects to move the item
  62.     //  to the new position.
  63.  
  64.     if (!COleClientItem::OnChangeItemPosition(rectPos))
  65.         return FALSE;
  66.  
  67.     // TODO: update any cache you may have of the item's rectangle/extent
  68.  
  69.     return TRUE;
  70. }
  71.  
  72. void CContCntrItem::OnGetItemPosition(CRect& rPosition)
  73. {
  74.     ASSERT_VALID(this);
  75.  
  76.     // During in-place activation, CContCntrItem::OnGetItemPosition
  77.     //  will be called to determine the location of this item.  The default
  78.     //  implementation created from AppWizard simply returns a hard-coded
  79.     //  rectangle.  Usually, this rectangle would reflect the current
  80.     //  position of the item relative to the view used for activation.
  81.     //  You can obtain the view by calling CContCntrItem::GetActiveView.
  82.  
  83.     // TODO: return correct rectangle (in pixels) in rPosition
  84.  
  85.     rPosition.SetRect(10, 10, 210, 210);
  86. }
  87.  
  88. void CContCntrItem::OnDeactivateUI(BOOL bUndoable)
  89. {
  90.     COleClientItem::OnDeactivateUI(bUndoable);
  91.  
  92.     // Close an in-place active item whenever it removes the user
  93.     //  interface.  The action here should match as closely as possible
  94.     //  to the handling of the escape key in the view.
  95.  
  96.     Deactivate();   // nothing fancy here -- just deactivate the object
  97. }
  98.  
  99. void CContCntrItem::Serialize(CArchive& ar)
  100. {
  101.     ASSERT_VALID(this);
  102.  
  103.     // Call base class first to read in COleClientItem data.
  104.     // Since this sets up the m_pDocument pointer returned from
  105.     //  CContCntrItem::GetDocument, it is a good idea to call
  106.     //  the base class Serialize first.
  107.     COleClientItem::Serialize(ar);
  108.  
  109.     // now store/retrieve data specific to CContCntrItem
  110.     if (ar.IsStoring())
  111.     {
  112.         // TODO: add storing code here
  113.     }
  114.     else
  115.     {
  116.         // TODO: add loading code here
  117.     }
  118. }
  119.  
  120. /////////////////////////////////////////////////////////////////////////////
  121. // CContCntrItem diagnostics
  122.  
  123. #ifdef _DEBUG
  124. void CContCntrItem::AssertValid() const
  125. {
  126.     COleClientItem::AssertValid();
  127. }
  128.  
  129. void CContCntrItem::Dump(CDumpContext& dc) const
  130. {
  131.     COleClientItem::Dump(dc);
  132. }
  133. #endif
  134.  
  135. /////////////////////////////////////////////////////////////////////////////
  136.