home *** CD-ROM | disk | FTP | other *** search
/ Media Share 13 / mediashare_13.zip / mediashare_13 / ZIPPED / PROGRAM / WTJ9403.ZIP / CONTAIN / CONTAVW.CPP < prev    next >
C/C++ Source or Header  |  1994-01-06  |  6KB  |  233 lines

  1. // contavw.cpp : implementation of the CContainView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "contain.h"
  6.  
  7. #include "contadoc.h"
  8. #include "cntritem.h"
  9. #include "contavw.h"
  10.  
  11. #ifdef _DEBUG
  12. #undef THIS_FILE
  13. static char BASED_CODE THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CContainView
  18.  
  19. IMPLEMENT_DYNCREATE(CContainView, CView)
  20.  
  21. BEGIN_MESSAGE_MAP(CContainView, CView)
  22.     //{{AFX_MSG_MAP(CContainView)
  23.         // NOTE - the ClassWizard will add and remove mapping macros here.
  24.         //    DO NOT EDIT what you see in these blocks of generated code!
  25.     ON_WM_SETFOCUS()
  26.     ON_WM_SIZE()
  27.     ON_COMMAND(ID_OLE_INSERT_NEW, OnInsertObject)
  28.     ON_COMMAND(ID_CANCEL_EDIT, OnCancelEdit)
  29.     //}}AFX_MSG_MAP
  30.     // Standard printing commands
  31.     ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  32.     ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  33. END_MESSAGE_MAP()
  34.  
  35. /////////////////////////////////////////////////////////////////////////////
  36. // CContainView construction/destruction
  37.  
  38. CContainView::CContainView()
  39. {
  40.     // TODO: add construction code here
  41. }
  42.  
  43. CContainView::~CContainView()
  44. {
  45. }
  46.  
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CContainView drawing
  49.  
  50. void CContainView::OnDraw(CDC* pDC)
  51. {
  52.     CContainDoc* pDoc = GetDocument();
  53.     ASSERT_VALID(pDoc);
  54.  
  55.     // TODO: add draw code for native data here
  56.     // TODO: also draw all OLE items in the document
  57.  
  58.     // Draw the selection at an arbitrary position.  This code should be
  59.     //  removed once your real drawing code is implemented.  This position
  60.     //  corresponds exactly to the rectangle returned by CContainCntrItem,
  61.     //  to give the effect of in-place editing.
  62.  
  63.     // TODO: remove this code when final draw code is complete.
  64.  
  65.     if (m_pSelection == NULL)
  66.     {
  67.         POSITION pos = pDoc->GetStartPosition();
  68.         m_pSelection = (CContainCntrItem*)pDoc->GetNextClientItem(pos);
  69.     }
  70.     if (m_pSelection != NULL)
  71.         m_pSelection->Draw(pDC, CRect(10, 10, 210, 210));
  72. }
  73.  
  74. void CContainView::OnInitialUpdate()
  75. {
  76.     CView::OnInitialUpdate();
  77.  
  78.     // TODO: remove this code when final selection model code is written
  79.     m_pSelection = NULL;    // initialize selection
  80.  
  81. }
  82.  
  83. /////////////////////////////////////////////////////////////////////////////
  84. // CContainView printing
  85.  
  86. BOOL CContainView::OnPreparePrinting(CPrintInfo* pInfo)
  87. {
  88.     // default preparation
  89.     return DoPreparePrinting(pInfo);
  90. }
  91.  
  92. void CContainView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  93. {
  94.     // TODO: add extra initialization before printing
  95. }
  96.  
  97. void CContainView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  98. {
  99.     // TODO: add cleanup after printing
  100. }
  101.  
  102. /////////////////////////////////////////////////////////////////////////////
  103. // OLE Client support and commands
  104.  
  105. BOOL CContainView::IsSelected(const CObject* pDocItem) const
  106. {
  107.     // The implementation below is adequate if your selection consists of
  108.     //  only CContainCntrItem objects.  To handle different selection
  109.     //  mechanisms, the implementation here should be replaced.
  110.  
  111.     // TODO: implement this function that tests for a selected OLE client item
  112.  
  113.     return pDocItem == m_pSelection;
  114. }
  115.  
  116. void CContainView::OnInsertObject()
  117. {
  118.     // Invoke the standard Insert Object dialog box to obtain information
  119.     //  for new CContainCntrItem object.
  120.     COleInsertDialog dlg;
  121.     if (dlg.DoModal() != IDOK)
  122.         return;
  123.  
  124.     BeginWaitCursor();
  125.  
  126.     CContainCntrItem* pItem = NULL;
  127.     TRY
  128.     {
  129.         // Create new item connected to this document.
  130.         CContainDoc* pDoc = GetDocument();
  131.         ASSERT_VALID(pDoc);
  132.         pItem = new CContainCntrItem(pDoc);
  133.         ASSERT_VALID(pItem);
  134.  
  135.         // Initialize the item from the dialog data.
  136.         if (!dlg.CreateItem(pItem))
  137.             AfxThrowMemoryException();  // any exception will do
  138.         ASSERT_VALID(pItem);
  139.  
  140.         // If item created from class list (not from file) then launch
  141.         //  the server to edit the item.
  142.         if (dlg.GetSelectionType() == COleInsertDialog::createNewItem)
  143.             pItem->DoVerb(OLEIVERB_SHOW, this);
  144.  
  145.         ASSERT_VALID(pItem);
  146.  
  147.         // As an arbitrary user interface design, this sets the selection
  148.         //  to the last item inserted.
  149.  
  150.         // TODO: reimplement selection as appropriate for your application
  151.  
  152.         m_pSelection = pItem;   // set selection to last inserted item
  153.         pDoc->UpdateAllViews(NULL);
  154.     }
  155.     CATCH(CException, e)
  156.     {
  157.         if (pItem != NULL)
  158.         {
  159.             ASSERT_VALID(pItem);
  160.             pItem->Delete();
  161.         }
  162.         AfxMessageBox(IDP_FAILED_TO_CREATE);
  163.     }
  164.     END_CATCH
  165.  
  166.     EndWaitCursor();
  167. }
  168.  
  169. // The following command handler provides the standard keyboard
  170. //  user interface to cancel an in-place editing session.
  171. void CContainView::OnCancelEdit()
  172. {
  173.     // Close any in-place active item on this view.
  174.     COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
  175.     if (pActiveItem != NULL)
  176.     {
  177.         pActiveItem->Close();
  178.     }
  179.     ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
  180. }
  181.  
  182. // Special handling of OnSetFocus and OnSize are required for a container
  183. //  when an object is being edited in-place.
  184. void CContainView::OnSetFocus(CWnd* pOldWnd)
  185. {
  186.     COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
  187.     if (pActiveItem != NULL &&
  188.         pActiveItem->GetItemState() == COleClientItem::activeUIState)
  189.     {
  190.         // need to set focus to this item if it is in the same view
  191.         CWnd* pWnd = pActiveItem->GetInPlaceWindow();
  192.         if (pWnd != NULL)
  193.         {
  194.             pWnd->SetFocus();   // don't call the base class
  195.             return;
  196.         }
  197.     }
  198.  
  199.     CView::OnSetFocus(pOldWnd);
  200. }
  201.  
  202. void CContainView::OnSize(UINT nType, int cx, int cy)
  203. {
  204.     CView::OnSize(nType, cx, cy);
  205.     COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
  206.     if (pActiveItem != NULL)
  207.         pActiveItem->SetItemRects();
  208. }
  209.  
  210. /////////////////////////////////////////////////////////////////////////////
  211. // CContainView diagnostics
  212.  
  213. #ifdef _DEBUG
  214. void CContainView::AssertValid() const
  215. {
  216.     CView::AssertValid();
  217. }
  218.  
  219. void CContainView::Dump(CDumpContext& dc) const
  220. {
  221.     CView::Dump(dc);
  222. }
  223.  
  224. CContainDoc* CContainView::GetDocument() // non-debug version is inline
  225. {
  226.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CContainDoc)));
  227.     return (CContainDoc*)m_pDocument;
  228. }
  229. #endif //_DEBUG
  230.  
  231. /////////////////////////////////////////////////////////////////////////////
  232. // CContainView message handlers
  233.