📄 olesvr1.cpp
字号:
m_pInPlaceFrame->m_pMainFrame : m_pInPlaceFrame->m_pDocFrame;
// if this is the active document clear temphide bits from bars
if (AfxGetThread()->m_pActiveWnd == m_pInPlaceFrame)
OnShowControlBars(pFrameWnd, TRUE);
// see how much space we need by calling reposition bars
CRect rectNeeded = rectBorder;
pFrameWnd->RepositionBars(0, 0xFFFF, 0, CWnd::reposQuery, &rectNeeded,
&rectBorder);
// request the border space from the container
CRect rectRequest(
rectNeeded.left - rectBorder.left,
rectNeeded.top - rectBorder.top,
rectBorder.right - rectNeeded.right,
rectBorder.bottom - rectNeeded.bottom);
CRect rectTemp;
rectTemp = rectRequest;
// if no border space, just call SetBorderSpace
if ((!rectRequest.IsRectNull() ||
!pFrameWnd->m_listControlBars.IsEmpty()) &&
lpUIWindow->RequestBorderSpace(&rectTemp) == S_OK)
{
// set the border space -- now this object owns it
VERIFY(lpUIWindow->SetBorderSpace(&rectRequest) == S_OK);
// move the bars into position after committing the space
pFrameWnd->RepositionBars(0, 0xFFFF, 0, CWnd::reposDefault, NULL,
&rectBorder);
// redraw all control bars
POSITION pos = pFrameWnd->m_listControlBars.GetHeadPosition();
while (pos != NULL)
{
CControlBar* pBar =
(CControlBar*)pFrameWnd->m_listControlBars.GetNext(pos);
ASSERT_VALID(pBar);
if (!pBar->IsFloating())
pBar->UpdateWindow();
}
}
else
{
// hide any toolbars (since we couldn't get border space for any)
OnShowControlBars(pFrameWnd, FALSE);
// make sure border space is cleared
CRect rect(0,0,0,0);
lpUIWindow->SetBorderSpace(&rect);
}
}
void COleServerDoc::OnDeactivate()
{
ASSERT_VALID(this);
ASSERT(m_pInPlaceFrame != NULL);
// do UI deactivate first -- this hides everything
if (m_pInPlaceFrame->m_bUIActive)
{
OnDeactivateUI(FALSE);
// some containers call OnDeactivate during OnDeactivateUI
if (m_pInPlaceFrame == NULL)
return;
}
ASSERT(m_pInPlaceFrame != NULL);
ASSERT(!m_pInPlaceFrame->m_bUIActive);
// now safe to destroy the shared menu
m_pInPlaceFrame->DestroySharedMenu();
// no longer need doc & frame window interfaces
RELEASE(m_pInPlaceFrame->m_lpFrame);
RELEASE(m_pInPlaceFrame->m_lpDocFrame);
DestroyInPlaceFrame(m_pInPlaceFrame);
m_pInPlaceFrame = NULL;
// destructor for COleIPFrameWnd or derivative should cleanup any
// toolbars etc. created during in-place activation
// last of all, call IOleClientSite::InPlaceDeactivate
ASSERT(m_lpClientSite != NULL);
LPOLEINPLACESITE lpInPlaceSite =
QUERYINTERFACE(m_lpClientSite, IOleInPlaceSite);
if (lpInPlaceSite != NULL)
{
lpInPlaceSite->OnInPlaceDeactivate();
lpInPlaceSite->Release();
}
}
void COleServerDoc::OnDeactivateUI(BOOL bUndoable)
{
ASSERT_VALID(this);
COleIPFrameWnd* pFrameWnd = m_pInPlaceFrame;
if (pFrameWnd == NULL || !pFrameWnd->m_bUIActive)
return;
// reset active object pointers
ASSERT(pFrameWnd->m_lpFrame != NULL);
pFrameWnd->m_lpFrame->SetActiveObject(NULL, NULL);
if (pFrameWnd->m_lpDocFrame != NULL)
pFrameWnd->m_lpDocFrame->SetActiveObject(NULL, NULL);
// remove frame & document level frame controls
ASSERT(pFrameWnd->m_lpFrame != NULL);
OnShowControlBars(pFrameWnd->m_pMainFrame, FALSE);
if (pFrameWnd->m_lpDocFrame != NULL)
OnShowControlBars(pFrameWnd->m_pDocFrame, FALSE);
if (m_pDocObjectServer == NULL)
{
// hide the frame and any popups owned by the frame
pFrameWnd->ShowOwnedWindows(FALSE);
pFrameWnd->ShowWindow(SW_HIDE);
pFrameWnd->m_nShowDelay = SW_HIDE;
pFrameWnd->m_pMainFrame->m_nShowDelay = SW_HIDE;
}
// set the m_hWnd members, but remove them from the maps
pFrameWnd->m_pMainFrame->m_hWnd = pFrameWnd->m_pMainFrame->Detach();
if (pFrameWnd->m_pDocFrame != NULL)
pFrameWnd->m_pDocFrame->m_hWnd = pFrameWnd->m_pDocFrame->Detach();
// no longer UI active...
pFrameWnd->m_bUIActive = FALSE;
CWinThread* pThread = AfxGetApp();
if (pThread->m_pActiveWnd == pFrameWnd)
pThread->m_pActiveWnd = NULL;
// call IOleClientSite::OnUIDeactivate
ASSERT(m_lpClientSite != NULL);
LPOLEINPLACESITE lpInPlaceSite =
QUERYINTERFACE(m_lpClientSite, IOleInPlaceSite);
if (lpInPlaceSite != NULL)
{
lpInPlaceSite->OnUIDeactivate(bUndoable);
lpInPlaceSite->Release();
}
}
void COleServerDoc::OnSetItemRects(LPCRECT lpPosRect, LPCRECT lpClipRect)
{
ASSERT_VALID(this);
ASSERT(AfxIsValidAddress(lpPosRect, sizeof(RECT), FALSE));
ASSERT(AfxIsValidAddress(lpClipRect, sizeof(RECT), FALSE));
if (m_pInPlaceFrame == NULL)
return;
ASSERT_VALID(m_pInPlaceFrame);
// tell the frame to position itself such that the view is at the given
// rectangle (relative to the frame's parent)
m_pInPlaceFrame->RepositionFrame(lpPosRect, lpClipRect);
}
BOOL COleServerDoc::OnReactivateAndUndo()
{
// default implementation doesn't support undo
return FALSE;
}
/////////////////////////////////////////////////////////////////////////////
// COleServerDoc special APIs for in-place editing
void COleServerDoc::RequestPositionChange(LPCRECT lpPosRect)
{
ASSERT_VALID(this);
ASSERT(AfxIsValidAddress(lpPosRect, sizeof(RECT), FALSE));
// get IOleInPlaceSite interface
ASSERT(m_lpClientSite != NULL);
LPOLEINPLACESITE lpInPlaceSite =
QUERYINTERFACE(m_lpClientSite, IOleInPlaceSite);
if (lpInPlaceSite != NULL)
{
// call IOleInPlaceSite::OnPosRectChange
lpInPlaceSite->OnPosRectChange(lpPosRect);
lpInPlaceSite->Release();
}
}
BOOL COleServerDoc::ScrollContainerBy(CSize sizeScroll)
{
ASSERT_VALID(this);
// get IOleInPlaceSite interface
ASSERT(m_lpClientSite != NULL);
LPOLEINPLACESITE lpInPlaceSite =
QUERYINTERFACE(m_lpClientSite, IOleInPlaceSite);
if (lpInPlaceSite == NULL)
return FALSE;
// call IOleInPlaceSite::Scroll
BOOL bResult = lpInPlaceSite->Scroll(sizeScroll) == S_OK;
lpInPlaceSite->Release();
return bResult;
}
BOOL COleServerDoc::DeactivateAndUndo()
{
ASSERT_VALID(this);
// get IOleInPlaceSite interface
ASSERT(m_lpClientSite != NULL);
LPOLEINPLACESITE lpInPlaceSite =
QUERYINTERFACE(m_lpClientSite, IOleInPlaceSite);
if (lpInPlaceSite == NULL)
return FALSE;
// call IOleInPlaceSite::DeactivateAndUndo
BOOL bResult = lpInPlaceSite->DeactivateAndUndo() == S_OK;
lpInPlaceSite->Release();
return bResult;
}
BOOL COleServerDoc::DiscardUndoState()
{
ASSERT_VALID(this);
// get IOleInPlaceSite interface
ASSERT(m_lpClientSite != NULL);
LPOLEINPLACESITE lpInPlaceSite =
QUERYINTERFACE(m_lpClientSite, IOleInPlaceSite);
if (lpInPlaceSite == NULL)
return FALSE;
// call IOleInPlaceSite::DiscardUndoState
BOOL bResult = lpInPlaceSite->DiscardUndoState() == S_OK;
lpInPlaceSite->Release();
return bResult;
}
/////////////////////////////////////////////////////////////////////////////
// COleServerDoc OLE interface implementation
BEGIN_INTERFACE_MAP(COleServerDoc, COleLinkingDoc)
INTERFACE_PART(COleServerDoc, IID_IPersistStorage, PersistStorage)
INTERFACE_PART(COleServerDoc, IID_IOleObject, OleObject)
INTERFACE_PART(COleServerDoc, IID_IDataObject, DataObject)
INTERFACE_PART(COleServerDoc, IID_IOleWindow, OleInPlaceObject)
INTERFACE_PART(COleServerDoc, IID_IOleInPlaceObject, OleInPlaceObject)
INTERFACE_PART(COleServerDoc, IID_IOleInPlaceActiveObject, OleInPlaceActiveObject)
END_INTERFACE_MAP()
/////////////////////////////////////////////////////////////////////////////
// COleServerDoc::CPersistStorage
STDMETHODIMP_(ULONG) COleServerDoc::XPersistStorage::AddRef()
{
METHOD_PROLOGUE_EX_(COleServerDoc, PersistStorage)
return pThis->ExternalAddRef();
}
STDMETHODIMP_(ULONG) COleServerDoc::XPersistStorage::Release()
{
METHOD_PROLOGUE_EX_(COleServerDoc, PersistStorage)
return pThis->ExternalRelease();
}
STDMETHODIMP COleServerDoc::XPersistStorage::QueryInterface(
REFIID iid, LPVOID* ppvObj)
{
METHOD_PROLOGUE_EX_(COleServerDoc, PersistStorage)
return pThis->ExternalQueryInterface(&iid, ppvObj);
}
STDMETHODIMP COleServerDoc::XPersistStorage::GetClassID(LPCLSID lpClassID)
{
METHOD_PROLOGUE_EX_(COleServerDoc, PersistStorage)
LPPERSISTFILE lpPersistFile = (LPPERSISTFILE)
pThis->GetInterface(&IID_IPersistFile);
return lpPersistFile->GetClassID(lpClassID);
}
STDMETHODIMP COleServerDoc::XPersistStorage::IsDirty()
{
METHOD_PROLOGUE_EX_(COleServerDoc, PersistStorage)
LPPERSISTFILE lpPersistFile = (LPPERSISTFILE)
pThis->GetInterface(&IID_IPersistFile);
return lpPersistFile->IsDirty();
}
STDMETHODIMP COleServerDoc::XPersistStorage::InitNew(LPSTORAGE pStg)
{
METHOD_PROLOGUE_EX(COleServerDoc, PersistStorage)
ASSERT_VALID(pThis);
SCODE sc = S_OK;
TRY
{
// delegate to member function in the document
pThis->OnNewEmbedding(pStg);
}
CATCH_ALL(e)
{
sc = COleException::Process(e);
DELETE_EXCEPTION(e);
}
END_CATCH_ALL
ASSERT_VALID(pThis);
return sc;
}
STDMETHODIMP COleServerDoc::XPersistStorage::Load(LPSTORAGE pStg)
{
METHOD_PROLOGUE_EX(COleServerDoc, PersistStorage)
ASSERT_VALID(pThis);
SCODE sc = S_OK;
pThis->BeginDeferErrors();
TRY
{
// delegate to member function in the document
pThis->OnOpenEmbedding(pStg);
}
CATCH_ALL(e)
{
sc = COleException::Process(e);
DELETE_EXCEPTION(e);
}
END_CATCH_ALL
sc = pThis->EndDeferErrors(sc);
ASSERT_VALID(pThis);
return sc;
}
STDMETHODIMP COleServerDoc::XPersistStorage::Save(
LPSTORAGE pStgSave, BOOL fSameAsLoad)
{
METHOD_PROLOGUE_EX(COleServerDoc, PersistStorage)
ASSERT_VALID(pThis);
// don't bother saving if destination is up-to-date
if (fSameAsLoad && !pThis->IsModified())
return S_OK;
SCODE sc = S_OK;
pThis->BeginDeferErrors();
TRY
{
// delegate through the document
ASSERT(pThis->m_bRemember);
pThis->m_bRemember = FALSE;
pThis->m_bSameAsLoad = fSameAsLoad;
pThis->OnSaveEmbedding(pStgSave);
// clear dirty flag since save to same storage successful
if (fSameAsLoad)
{
pThis->SetModifiedFlag(FALSE);
// notify clients that object has been saved
pThis->NotifySaved();
}
}
CATCH_ALL(e)
{
sc = COleException::Process(e);
DELETE_EXCEPTION(e);
}
END_CATCH_ALL
sc = pThis->EndDeferErrors(sc);
// restore default state
pThis->m_bRemember = TRUE;
ASSERT_VALID(pThis);
return sc;
}
STDMETHODIMP COleServerDoc::XPersistStorage::SaveCompleted(LPSTORAGE pStgSaved)
{
METHOD_PROLOGUE_EX(COleServerDoc, PersistStorage)
ASSERT_VALID(pThis);
// call SaveCompleted on any embedded items
pThis->CommitItems(pStgSaved != NULL);
// update state to reflect new storage
if (pStgSaved != NULL)
{
// attach new storage
pStgSaved->AddRef();
RELEASE(pThis->m_lpRootStg);
pThis->m_lpRootStg = pStgSaved;
// now this document is storage based
pThis->m_strPathName.Empty();
pThis->m_bEmbedded = TRUE;
pThis->SetModifiedFlag(FALSE);
// notify clients that object has been saved
pThis->NotifySaved();
}
ASSERT_VALID(pThis);
return S_OK;
}
STDMETHODIMP COleServerDoc::XPersistStorage::HandsOffStorage()
{
METHOD_PROLOGUE_EX_(COleServerDoc, PersistStorage)
if (pThis->m_lpRootStg != NULL)
{
// first call HandsOffStorage for all the embedded client items
POSITION pos = pThis->GetStartPosition();
COleClientItem* pItem;
while ((pItem = pThis->GetNextClientItem(pos)) != NULL)
{
ASSERT(pItem->m_lpObject != NULL);
LPPERSISTSTORAGE lpPersistStorage =
QUERYINTERFACE(pItem->m_lpObject, IPersistStorage);
ASSERT(lpPersistStorage != NULL);
lpPersistStorage->HandsOffStorage();
lpPersistStorage->Release();
}
// for now, can't access the storage
RELEASE(pThis->m_lpRootStg);
}
ASSERT_VALID(pThis);
return S_OK;
}
/////////////////////////////////////////////////////////////////////////////
// COleServerDoc::XOleObject
STDMETHODIMP_(ULONG) COleServerDoc::XOleObject::AddRef()
{
METHOD_PROLOGUE_EX_(COleServerDoc, OleObject)
return pThis->ExternalAddRef();
}
STDMETHODIMP_(ULONG) COleServerDoc::XOleObject::Release()
{
METHOD_PROLOGUE_EX_(COleServerDoc, OleObject)
return pThis->ExternalRelease();
}
STDMETHODIMP COleServerDoc::XOleObject::QueryInterface(
REFIID iid, LPVOID* ppvObj)
{
METHOD_PROLOGUE_EX_(COleServerDoc, OleObject)
return pThis->ExternalQueryInterface(&iid, ppvObj);
}
STDMETHODIMP COleServerDoc::XOleObject::SetClientSite(
LPOLECLIENTSITE pClientSite)
{
METHOD_PROLOGUE_EX_(COleServerDoc, OleObject)
// maintain reference counts
if (pClientSite != NULL)
pClientSite->AddRef();
RELEASE(pThis->m_lpClientSite);
pThis->m_lpClientSite = pClientSite;
// do we already have doc object support enabled?
if (pThis->m_pDocObjectServer != NULL)
{
// If we currently have a document site pointer,
// release it.
pThis->m_pDocObjectServer->ReleaseDocSite();
}
if (pClientSite != NULL)
{
LPOLEDOCUMENTSITE pDocSite;
if (SUCCEEDED(pClientSite->QueryInterface(IID_IOleDocumentSite,
(LPVOID*) &pDocSite)))
{
if (pThis->m_pDocObjectServer != NULL)
pThis->m_pDocObjectServer->SetDocSite(pDocSite);
else
{
pThis->m_pDocObjectServer =
pThis->GetDocObjectServer(pDocSite);
}
}
}
return S_OK;
}
STDMETHODIMP COleServerDoc::XOleObject::GetClientSite(
LPOLECLIENTSITE* ppClientSite)
{
METHOD_PROLOGUE_EX_(COleServerDoc, OleObject)
if (pThis->m_lpClientSite == NULL)
{
*ppClientSite = NULL;
return E_FAIL;
}
*ppClientSite = pThis->m_lpClientSite;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -