COleServerItem::~COleServerItem() { m_bAutoDelete = FALSE; // no delete during destructor // release any advise holders RELEASE(m_lpOleAdviseHolder); RELEASE(m_lpDataAdviseHolder); ExternalDisconnect(); // disconnect from the document COleServerDoc* pDoc = GetDocument(); if (pDoc != NULL) { // remove external lock from it if (m_bNeedUnlock) { pDoc->LockExternal(FALSE, TRUE); m_bNeedUnlock = FALSE; } // reset m_pEmbeddedItem if destroying embedded item if (pDoc->m_pEmbeddedItem == this) pDoc->m_pEmbeddedItem = NULL; // remove from list pDoc->RemoveItem(this); } // cleanup any references AfxOleUnlockApp(); }
void COleServerItem::OnSaveEmbedding(LPSTORAGE lpStorage) { ASSERT(lpStorage != NULL); // always (logically) a "File.Save Copy As" operation COleServerDoc* pDoc = GetDocument(); LPSTORAGE lpOrigStg = pDoc->m_lpRootStg; pDoc->m_lpRootStg = lpStorage; TRY { ASSERT(pDoc->m_lpRootStg != NULL); pDoc->SaveToStorage(this); // use helper to serialize to storage } CATCH_ALL(e) { // save as failed: re-attach original storage pDoc->m_lpRootStg = lpOrigStg; THROW_LAST(); } END_CATCH_ALL // re-attach original storage pDoc->m_lpRootStg = lpOrigStg; }
void COleServerItem::OnHide() { ASSERT_VALID(this); // default implementation hides the document COleServerDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); pDoc->OnShowDocument(FALSE); }
void COleServerItem::OnOpen() { ASSERT_VALID(this); // default implementation shows the document COleServerDoc* pDoc = GetDocument(); ASSERT(pDoc != NULL); pDoc->OnShowDocument(TRUE); }
void COleIPFrameWnd::OnRequestPositionChange(LPCRECT lpRect) { COleServerDoc* pDoc = (COleServerDoc*)GetActiveDocument(); ASSERT_VALID(pDoc); ASSERT_KINDOF(COleServerDoc, pDoc); // The default behavior is to not affect the extent during the // call to RequestPositionChange. This results in consistent // scaling behavior. pDoc->RequestPositionChange(lpRect); }
void COleServerItem::OnShow() { ASSERT_VALID(this); // attempt in place activation (if not supported, fall back on "Open") COleServerDoc* pDoc = GetDocument(); if (!pDoc->ActivateInPlace()) { // by default OnShow() maps to OnOpen() if in-place activation // not supported OnOpen(); } }
void COleServerItem::GetEmbedSourceData(LPSTGMEDIUM lpStgMedium) { ASSERT_VALID(this); ASSERT(AfxIsValidAddress(lpStgMedium, sizeof(STGMEDIUM))); LPLOCKBYTES lpLockBytes; SCODE sc = ::CreateILockBytesOnHGlobal(NULL, TRUE, &lpLockBytes); if (sc != S_OK) AfxThrowOleException(sc); ASSERT(lpLockBytes != NULL); LPSTORAGE lpStorage; sc = ::StgCreateDocfileOnILockBytes(lpLockBytes, STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, &lpStorage); if (sc != S_OK) { VERIFY(lpLockBytes->Release() == 0); AfxThrowOleException(sc); } ASSERT(lpStorage != NULL); // setup for save copy as COleServerDoc* pDoc = GetDocument(); pDoc->m_bSameAsLoad = FALSE; pDoc->m_bRemember = FALSE; TRY { OnSaveEmbedding(lpStorage); pDoc->CommitItems(FALSE); } CATCH_ALL(e) { // release storage and lock bytes VERIFY(lpStorage->Release() == 0); VERIFY(lpLockBytes->Release() == 0); pDoc->m_bSameAsLoad = TRUE; pDoc->m_bRemember = TRUE; THROW_LAST(); } END_CATCH_ALL pDoc->m_bSameAsLoad = TRUE; pDoc->m_bRemember = TRUE; lpLockBytes->Release(); // add it to the data source lpStgMedium->tymed = TYMED_ISTORAGE; lpStgMedium->pstg = lpStorage; lpStgMedium->pUnkForRelease = NULL; }
void CBCGPOleCntrFrameWnd::AdjustClientArea() { COleServerDoc* pDoc = (COleServerDoc*)m_pInPlaceFrame->GetActiveDocument(); if (pDoc != NULL ) { ASSERT_VALID(pDoc); ASSERT_KINDOF(COleServerDoc, pDoc); CBCGPOleDocIPFrameWnd* pFrame = (CBCGPOleDocIPFrameWnd*)m_pInPlaceFrame; pDoc->OnResizeBorder(NULL, pFrame->m_lpFrame, TRUE); } }
void COleIPFrameWnd::OnRequestPositionChange(LPCRECT lpRect) { COleServerDoc* pDoc = (COleServerDoc*)GetActiveDocument(); ASSERT_VALID(pDoc); ASSERT_KINDOF(COleServerDoc, pDoc); // DocObjects don't need to generate OnPosRectChange calls, // so we can just return if this is a DoCobject if (pDoc->IsDocObject()) return; // The default behavior is to not affect the extent during the // call to RequestPositionChange. This results in consistent // scaling behavior. pDoc->RequestPositionChange(lpRect); }
void COleCntrFrameWnd::RecalcLayout(BOOL /*bNotify*/) { if (!m_bInRecalcLayout) { m_bInRecalcLayout = TRUE; m_nIdleFlags &= ~(idleLayout|idleNotify); ASSERT_VALID(m_pInPlaceFrame); COleServerDoc* pDoc = (COleServerDoc*)m_pInPlaceFrame->GetActiveDocument(); if (pDoc != NULL && AfxGetThread()->m_pActiveWnd == m_pInPlaceFrame) { ASSERT_VALID(pDoc); ASSERT_KINDOF(COleServerDoc, pDoc); if (this == m_pInPlaceFrame->m_pMainFrame) pDoc->OnResizeBorder(NULL, m_pInPlaceFrame->m_lpFrame, TRUE); if (this == m_pInPlaceFrame->m_pDocFrame) pDoc->OnResizeBorder(NULL, m_pInPlaceFrame->m_lpDocFrame, FALSE); } m_bInRecalcLayout = FALSE; } }
void COleIPFrameWnd::OnDestroy() { // notify the container that the rectangle has changed! COleServerDoc* pDoc = (COleServerDoc*)GetActiveDocument(); if (pDoc != NULL) { ASSERT_KINDOF(COleServerDoc, pDoc); // close and abort changes to the document pDoc->DisconnectViews(); pDoc->OnCloseDocument(); } // explicitly destroy all of the dock bars since this window // is actually in the container and will not be destroyed if (m_pMainFrame != NULL) m_pMainFrame->DestroyDockBars(); if (m_pDocFrame != NULL) m_pDocFrame->DestroyDockBars(); CFrameWnd::OnDestroy(); }
void COleIPFrameWnd::RecalcLayout(BOOL /*bNotify*/) { ASSERT_VALID(this); // better have a parent window (only used for inplace) CWnd* pParentWnd = GetParent(); ASSERT_VALID(pParentWnd); // see if this frame is supporting a normal in-place object or // a DocObject. DocObjects put scrollbars on the inside of the rect UINT nAdjustType = CWnd::adjustBorder; COleServerDoc* pDoc = (COleServerDoc*) GetActiveDocument(); if (pDoc != NULL) { ASSERT_VALID(pDoc); if (pDoc->IsDocObject()) nAdjustType = CWnd::adjustOutside; } // first call reposition bars with arbitarily large rect just to // see how much space the bars will take up CRect rectBig(0, 0, INT_MAX/2, INT_MAX/2); CRect rectLeft; RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST, reposQuery, &rectLeft, &rectBig); // grow the rect by the size of the control bars CRect rect = m_rectPos; rect.left -= rectLeft.left; rect.top -= rectLeft.top; rect.right += INT_MAX/2 - rectLeft.right; rect.bottom += INT_MAX/2 - rectLeft.bottom; // see how much extra space for non-client areas (such as scrollbars) // that the view needs. CWnd* pLeftOver = GetDlgItem(AFX_IDW_PANE_FIRST); if (pLeftOver != NULL) { rectBig = m_rectPos; pLeftOver->CalcWindowRect(&rectBig, CWnd::adjustOutside); rect.left -= m_rectPos.left - rectBig.left; rect.top -= m_rectPos.top - rectBig.top; rect.right += rectBig.right - m_rectPos.right; rect.bottom += rectBig.bottom - m_rectPos.bottom; } // adjust for non-client area on the frame window CalcWindowRect(&rect, nAdjustType); // the frame window must be clipped to the visible part in the container CRect rectVis; rectVis.IntersectRect(&rect, &m_rectClip); // move the window AfxRepositionWindow(NULL, m_hWnd, &rectVis); // now resize the control bars relative to the (now moved) frame pParentWnd->ClientToScreen(&rect); ScreenToClient(&rect); RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST, CWnd::reposDefault, NULL, &rect); }