📄 ioleobj.cpp
字号:
/*
* IOLEOBJ.CPP
* Cosmo Chapter 23
*
* Implementation of the IOleObject interface for Polyline.
*
* Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
*
* Kraig Brockschmidt, Microsoft
* Internet : kraigb@microsoft.com
* Compuserve: >INTERNET:kraigb@microsoft.com
*/
#include "cosmo.h"
/*
* CImpIOleObject::CImpIOleObject
* CImpIOleObject::~CImpIOleObject
*
* Parameters (Constructor):
* pObj PCFigure of the object we're in.
* pUnkOuter LPUNKNOWN to which we delegate.
*/
CImpIOleObject::CImpIOleObject(PCFigure pObj, LPUNKNOWN pUnkOuter)
{
m_cRef=0;
m_pObj=pObj;
m_pUnkOuter=pUnkOuter;
return;
}
CImpIOleObject::~CImpIOleObject(void)
{
return;
}
/*
* CImpIOleObject::QueryInterface
* CImpIOleObject::AddRef
* CImpIOleObject::Release
*/
STDMETHODIMP CImpIOleObject::QueryInterface(REFIID riid, PPVOID ppv)
{
return m_pUnkOuter->QueryInterface(riid, ppv);
}
STDMETHODIMP_(ULONG) CImpIOleObject::AddRef(void)
{
++m_cRef;
return m_pUnkOuter->AddRef();
}
STDMETHODIMP_(ULONG) CImpIOleObject::Release(void)
{
--m_cRef;
return m_pUnkOuter->Release();
}
/*
* CImpIOleObject::SetClientSite
*
* Purpose:
* Provides the object with a pointer to the IOleClient site
* representing the container in which this object resides.
*
* Parameters:
* pIOleClientSite LPOLECLIENTSITE to the container's interface.
*
* Return Value:
* HRESULT NOERROR
*/
STDMETHODIMP CImpIOleObject::SetClientSite
(LPOLECLIENTSITE pIOleClientSite)
{
if (NULL!=m_pObj->m_pIOleClientSite)
m_pObj->m_pIOleClientSite->Release();
m_pObj->m_pIOleClientSite=pIOleClientSite;
m_pObj->m_pIOleClientSite->AddRef();
return NOERROR;
}
/*
* CImpIOleObject::GetClientSite
*
* Purpose:
* Asks the object for the client site provided in SetClientSite.
* If you have not seen SetClientSite yet, return a NULL in
* ppIOleClientSite.
*
* Parameters:
* ppSite LPOLECLIENTSITE * in which to store the
* pointer.
*
* Return Value:
* HRESULT NOERROR
*/
STDMETHODIMP CImpIOleObject::GetClientSite(LPOLECLIENTSITE
*ppSite)
{
//Be sure to AddRef the new pointer you are giving away.
*ppSite=m_pObj->m_pIOleClientSite;
m_pObj->m_pIOleClientSite->AddRef();
return NOERROR;
}
/*
* CImpIOleObject::SetHostNames
*
* Purpose:
* Provides the object with names of the container application and
* the object in the container to use in object user interface.
*
* Parameters:
* pszApp LPCOLESTR of the container application.
* pszObj LPCOLESTR of some name useful in window titles.
*
* Return Value:
* HRESULT NOERROR
*/
STDMETHODIMP CImpIOleObject::SetHostNames(LPCOLESTR pszApp
, LPCOLESTR pszObj)
{
m_pObj->m_fEmbedded=TRUE;
#ifdef WIN32ANSI
char szApp[80], szObj[80];
szApp[0]=0;
szObj[0]=0;
if (NULL!=pszApp)
{
WideCharToMultiByte(CP_ACP, 0, pszApp, -1, szApp, 80
, NULL, NULL);
}
if (NULL!=pszObj)
{
WideCharToMultiByte(CP_ACP, 0, pszObj, -1, szObj, 80
, NULL, NULL);
}
m_pObj->m_pFR->UpdateEmbeddingUI(TRUE, m_pObj->m_pDoc
, szApp, szObj);
#else
m_pObj->m_pFR->UpdateEmbeddingUI(TRUE, m_pObj->m_pDoc
, pszApp, pszObj);
#endif
return NOERROR;
}
/*
* CImpIOleObject::Close
*
* Purpose:
* Forces the object to close down its user interface and unload.
*
* Parameters:
* dwSaveOption DWORD describing the circumstances under which
* the object is being saved and closed.
*
* Return Value:
* HRESULT NOERROR or a general error value.
*/
STDMETHODIMP CImpIOleObject::Close(DWORD dwSaveOption)
{
HWND hWnd;
BOOL fSave=FALSE;
hWnd=m_pObj->m_pDoc->Window();
//If object is dirty and we're asked to save, save it and close.
if (OLECLOSE_SAVEIFDIRTY==dwSaveOption && m_pObj->FIsDirty())
fSave=TRUE;
/*
* If asked to prompt, only do so if dirty, then if we get a
* YES, save as usual and close. On NO, just close. On
* CANCEL return OLE_E_PROMPTSAVECANCELLED.
*/
if (OLECLOSE_PROMPTSAVE==dwSaveOption && m_pObj->FIsDirty())
{
UINT uRet;
uRet=MessageBox(hWnd, (*m_pObj->m_pST)[IDS_CLOSECAPTION]
, (*m_pObj->m_pST)[IDS_CLOSEPROMPT], MB_YESNOCANCEL);
if (IDCANCEL==uRet)
return ResultFromScode(OLE_E_PROMPTSAVECANCELLED);
if (IDYES==uRet)
fSave=TRUE;
}
if (fSave)
{
m_pObj->SendAdvise(OBJECTCODE_SAVEOBJECT);
m_pObj->SendAdvise(OBJECTCODE_SAVED);
}
//We get directly here on OLECLOSE_NOSAVE.
PostMessage(hWnd, WM_CLOSE, 0, 0L);
return NOERROR;
}
/*
* CImpIOleObject::SetMoniker
*
* Purpose:
* Informs the object of its moniker or its container's moniker
* depending on dwWhich.
*
* Parameters:
* dwWhich DWORD describing whether the moniker is the
* object's or the container's.
* pmk LPMONIKER with the name.
*
* Return Value:
* HRESULT NOERROR or a general error value.
*/
STDMETHODIMP CImpIOleObject::SetMoniker(DWORD dwWhich
, LPMONIKER pmk)
{
LPMONIKER pmkFull;
HRESULT hr=ResultFromScode(E_FAIL);
/*
* For an embedded object we might be living in a container that
* has given us away as a link. This is our indication to
* register the full moniker for this object that we obtain from
* IOleClientSite::GetMoniker(OLEWHICHMK_FULL).
*/
if (NULL!=m_pObj->m_pIOleClientSite)
{
hr=m_pObj->m_pIOleClientSite->GetMoniker
(OLEGETMONIKER_ONLYIFTHERE, OLEWHICHMK_OBJFULL
, &pmkFull);
}
if (SUCCEEDED(hr))
{
/*
* If this moniker is already running then we don't
* need to revoke and re-register the same thing again.
*/
if (NOERROR==pmkFull->IsRunning(NULL, NULL, NULL))
{
pmkFull->Release();
return NOERROR;
}
//This will revoke the old one if m_dwRegROT is nonzero.
INOLE_RegisterAsRunning(m_pObj, pmkFull
, 0, &m_pObj->m_dwRegROT);
//Inform clients of the new moniker
if (NULL!=m_pObj->m_pIOleAdviseHolder)
m_pObj->m_pIOleAdviseHolder->SendOnRename(pmkFull);
pmkFull->Release();
}
return hr;
}
/*
* CImpIOleObject::GetMoniker
*
* Purpose:
* Asks the object for a moniker that can later be used to
* reconnect to it.
*
* Parameters:
* dwAssign DWORD determining how to assign the moniker to
* to the object.
* dwWhich DWORD describing which moniker the caller wants.
* ppmk LPMONIKER * into which to store the moniker.
*
* Return Value:
* HRESULT NOERROR or a general error value.
*/
STDMETHODIMP CImpIOleObject::GetMoniker(DWORD dwAssign
, DWORD dwWhich, LPMONIKER * ppmk)
{
HRESULT hr=ResultFromScode(E_FAIL);
*ppmk=NULL;
/*
* When we support linking we either return our file moniker if
* we're linked, or out full moniker from the container if we're
* embedded.
*/
if (NULL!=m_pObj->m_pMoniker)
{
*ppmk=m_pObj->m_pMoniker; //Document file moniker
m_pObj->m_pMoniker->AddRef();
}
else
{
//Get the full container:object moniker if we're embedded
if (NULL!=m_pObj->m_pIOleClientSite)
{
hr=m_pObj->m_pIOleClientSite->GetMoniker
(OLEGETMONIKER_ONLYIFTHERE, OLEWHICHMK_OBJFULL
, ppmk);
}
}
return (NULL!=*ppmk) ? NOERROR : hr;
}
/*
* CImpIOleObject::InitFromData
*
* Purpose:
* Initializes the object from the contents of a data object.
*
* Parameters:
* pIDataObject LPDATAOBJECT containing the data.
* fCreation BOOL indicating if this is part of a new
* creation. If FALSE, the container is trying
* to paste here.
* dwReserved DWORD reserved.
*
* Return Value:
* HRESULT NOERROR or a general error value.
*/
STDMETHODIMP CImpIOleObject::InitFromData(LPDATAOBJECT pIDataObject
, BOOL fCreation, DWORD dwReserved)
{
BOOL fRet;
/*
* If we get a data object here, try to paste from it. If
* you've written clipboard code already, this is a snap.
* We don't really care about fCreation or not since pasting
* in us blasts away whatever is already here.
*/
fRet=m_pObj->m_pDoc->PasteFromData(pIDataObject);
return fRet ? NOERROR : ResultFromScode(E_FAIL);
}
/*
* CImpIOleObject::GetClipboardData
*
* Purpose:
* Returns an IDataObject pointer to the caller representing what
* would be on the clipboard if the server did an Edit/Copy using
* OleSetClipboard.
*
* Parameters:
* dwReserved DWORD reserved.
* ppIDataObj LPDATAOBJECT * into which to store the
* pointer.
*
* Return Value:
* HRESULT NOERROR or a general error value.
*/
STDMETHODIMP CImpIOleObject::GetClipboardData(DWORD dwReserved
, LPDATAOBJECT *ppIDataObj)
{
/*
* Again, if you have a function to create a data object for the
* clipboard, this is a simple implementation. The one we have
* does all the compound document formats already.
*/
*ppIDataObj=m_pObj->m_pDoc->TransferObjectCreate(FALSE);
return (NULL!=*ppIDataObj) ? NOERROR : ResultFromScode(E_FAIL);
}
/*
* CImpIOleObject::DoVerb
*
* Purpose:
* Executes an object-defined action.
*
* Parameters:
* iVerb LONG index of the verb to execute.
* pMSG LPMSG describing the event causing the
* activation.
* pActiveSite LPOLECLIENTSITE to the site involved.
* lIndex LONG the piece on which execution is happening.
* hWndParent HWND of window in which the object can play
* in-place.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -