void CDrawView::OnInsertObject() { // Invoke the standard Insert Object dialog box to obtain information // for new CDrawItem object. COleInsertDialog dlg; if (dlg.DoModal() != IDOK) return; BeginWaitCursor(); // First create the C++ object CDrawOleObj* pObj = new CDrawOleObj(GetInitialPosition()); ASSERT_VALID(pObj); CDrawItem* pItem = new CDrawItem(GetDocument(), pObj); ASSERT_VALID(pItem); pObj->m_pClientItem = pItem; // Now create the OLE object/item TRY { if (!dlg.CreateItem(pObj->m_pClientItem)) AfxThrowMemoryException(); // add the object to the document /*GetDocument()->*/g_pGuiManager->AddBack(pObj); pObj->m_pDocument = GetDocument(); GetDocument()->SetModifiedFlag(); // try to get initial presentation data pItem->UpdateLink(); pItem->UpdateExtent(); // if insert new object -- initially show the object if (dlg.GetSelectionType() == COleInsertDialog::createNewItem) pItem->DoVerb(OLEIVERB_SHOW, this); } CATCH_ALL(e) { // clean up item pItem->Delete(); pObj->m_pClientItem = NULL; /*GetDocument()->*/g_pGuiManager->Remove(pObj); GetDocument()->SetModifiedFlag(TRUE); pObj->Remove(); AfxMessageBox(IDP_FAILED_TO_CREATE); } END_CATCH_ALL EndWaitCursor(); }
CDrawObj* CDrawOleObj::Clone(CDrawDoc* pDoc) { ASSERT_VALID(this); AfxGetApp()->BeginWaitCursor(); CDrawOleObj* pClone = NULL; CDrawItem* pItem = NULL; TRY { // perform a "deep copy" -- need to copy CDrawOleObj and the CDrawItem // that it points to. pClone = new CDrawOleObj(m_position); //#pragma warning(suppress:6014) pItem = new CDrawItem(m_pDocument, pClone); if (!pItem->CreateCloneFrom(m_pClientItem)) { AfxThrowMemoryException(); } pClone->m_pClientItem = pItem; pClone->m_bPen = m_bPen; pClone->m_logpen = m_logpen; pClone->m_bBrush = m_bBrush; pClone->m_logbrush = m_logbrush; ASSERT_VALID(pClone); if (pDoc != NULL) pDoc->Add(pClone); } CATCH_ALL(e) { if(pItem) pItem->Delete(); if(pClone) { pClone->m_pClientItem = NULL; pClone->Remove(); } AfxGetApp()->EndWaitCursor(); THROW_LAST(); } END_CATCH_ALL AfxGetApp()->EndWaitCursor(); return pClone; }