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

  1. // BindView.cpp : implementation of the CMFCBindView 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. #include "stdafx.h"
  14. #include "MFCBind.h"
  15.  
  16. #include "BindDoc.h"
  17. #include "CntrItem.h"
  18. #include "BindView.h"
  19.  
  20. #ifdef _DEBUG
  21. #define new DEBUG_NEW
  22. #undef THIS_FILE
  23. static char THIS_FILE[] = __FILE__;
  24. #endif
  25.  
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CMFCBindView
  28. //Hi Mike
  29. IMPLEMENT_DYNCREATE(CMFCBindView, CView)
  30.  
  31. BEGIN_MESSAGE_MAP(CMFCBindView, CView)
  32.     //{{AFX_MSG_MAP(CMFCBindView)
  33.         // NOTE - the ClassWizard will add and remove mapping macros here.
  34.         //    DO NOT EDIT what you see in these blocks of generated code!
  35.     ON_WM_DESTROY()
  36.     ON_WM_SETFOCUS()
  37.     ON_WM_SIZE()
  38.     ON_COMMAND(ID_CANCEL_EDIT_CNTR, OnCancelEditCntr)
  39.     //}}AFX_MSG_MAP
  40.     // Standard printing commands
  41. END_MESSAGE_MAP()
  42.  
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CMFCBindView construction/destruction
  45.  
  46. CMFCBindView::CMFCBindView()
  47. {
  48.     m_pSelection = NULL;
  49.     // TODO: add construction code here
  50.  
  51. }
  52.  
  53. CMFCBindView::~CMFCBindView()
  54. {
  55. }
  56.  
  57. BOOL CMFCBindView::PreCreateWindow(CREATESTRUCT& cs)
  58. {
  59.     // TODO: Modify the Window class or styles here by modifying
  60.     //  the CREATESTRUCT cs
  61.  
  62.     return CView::PreCreateWindow(cs);
  63. }
  64.  
  65. /////////////////////////////////////////////////////////////////////////////
  66. // CMFCBindView drawing
  67.  
  68. void CMFCBindView::OnDraw(CDC* pDC)
  69. {
  70.     CMFCBindDoc* pDoc = GetDocument();
  71.     ASSERT_VALID(pDoc);
  72.  
  73.     // DocObjects don't require any drawing
  74. }
  75.  
  76. void CMFCBindView::OnInitialUpdate()
  77. {
  78.     CView::OnInitialUpdate();
  79.  
  80.     // TODO: remove this code when final selection model code is written
  81.     m_pSelection = NULL;    // initialize selection
  82.  
  83. }
  84.  
  85.  
  86. void CMFCBindView::OnDestroy()
  87. {
  88.     // Deactivate the item on destruction; this is important
  89.     // when a splitter view is being used.
  90.    CView::OnDestroy();
  91.    COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
  92.    if (pActiveItem != NULL && pActiveItem->GetActiveView() == this)
  93.    {
  94.       pActiveItem->Deactivate();
  95.       ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
  96.    }
  97. }
  98.  
  99.  
  100. /////////////////////////////////////////////////////////////////////////////
  101. // OLE Client support and commands
  102.  
  103. BOOL CMFCBindView::IsSelected(const CObject* pDocItem) const
  104. {
  105.     // The implementation below is adequate if your selection consists of
  106.     //  only CMFCBindCntrItem objects.  To handle different selection
  107.     //  mechanisms, the implementation here should be replaced.
  108.  
  109.     // TODO: implement this function that tests for a selected OLE client item
  110.  
  111.     return pDocItem == m_pSelection;
  112. }
  113.  
  114. // The following command handler provides the standard keyboard
  115. //  user interface to cancel an in-place editing session.  Here,
  116. //  the container (not the server) causes the deactivation.
  117. void CMFCBindView::OnCancelEditCntr()
  118. {
  119.     // Close any in-place active item on this view.
  120.     COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
  121.     if (pActiveItem != NULL)
  122.     {
  123.         pActiveItem->Close();
  124.     }
  125.     ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
  126. }
  127.  
  128. // Special handling of OnSetFocus and OnSize are required for a container
  129. //  when an object is being edited in-place.
  130. void CMFCBindView::OnSetFocus(CWnd* pOldWnd)
  131. {
  132.     COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
  133.     if (pActiveItem != NULL &&
  134.         pActiveItem->GetItemState() == COleClientItem::activeUIState)
  135.     {
  136.         // need to set focus to this item if it is in the same view
  137.         CWnd* pWnd = pActiveItem->GetInPlaceWindow();
  138.         if (pWnd != NULL)
  139.         {
  140.             pWnd->SetFocus();   // don't call the base class
  141.             return;
  142.         }
  143.     }
  144.  
  145.     CView::OnSetFocus(pOldWnd);
  146. }
  147.  
  148. void CMFCBindView::OnSize(UINT nType, int cx, int cy)
  149. {
  150.     CView::OnSize(nType, cx, cy);
  151.     COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
  152.     if (pActiveItem != NULL)
  153.         pActiveItem->SetItemRects();
  154. }
  155.  
  156. /////////////////////////////////////////////////////////////////////////////
  157. // CMFCBindView diagnostics
  158.  
  159. #ifdef _DEBUG
  160. void CMFCBindView::AssertValid() const
  161. {
  162.     CView::AssertValid();
  163. }
  164.  
  165. void CMFCBindView::Dump(CDumpContext& dc) const
  166. {
  167.     CView::Dump(dc);
  168. }
  169.  
  170. CMFCBindDoc* CMFCBindView::GetDocument() // non-debug version is inline
  171. {
  172.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMFCBindDoc)));
  173.     return (CMFCBindDoc*)m_pDocument;
  174. }
  175. #endif //_DEBUG
  176.  
  177. /////////////////////////////////////////////////////////////////////////////
  178. // CMFCBindView message handlers
  179.