diff options
author | Jens-Heiner Rechtien <hr@openoffice.org> | 2008-11-20 15:13:11 +0000 |
---|---|---|
committer | Jens-Heiner Rechtien <hr@openoffice.org> | 2008-11-20 15:13:11 +0000 |
commit | e5e5ab301913a9a14218318459322d0f81cd5a30 (patch) | |
tree | c2e7915977442d2f829fa2b2cc1bbb3531a2e280 /embedserv/source/inprocserv | |
parent | aa9d036565bec14133ec5b10a7574be078914b33 (diff) |
CWS-TOOLING: integrate CWS buildid301_DEV300
Diffstat (limited to 'embedserv/source/inprocserv')
-rw-r--r-- | embedserv/source/inprocserv/advisesink.cxx | 180 | ||||
-rw-r--r-- | embedserv/source/inprocserv/advisesink.hxx | 102 | ||||
-rw-r--r-- | embedserv/source/inprocserv/dllentry.cxx | 343 | ||||
-rw-r--r-- | embedserv/source/inprocserv/exports.dxp | 5 | ||||
-rw-r--r-- | embedserv/source/inprocserv/inprocembobj.cxx | 1811 | ||||
-rw-r--r-- | embedserv/source/inprocserv/inprocembobj.h | 249 | ||||
-rw-r--r-- | embedserv/source/inprocserv/makefile.mk | 77 | ||||
-rw-r--r-- | embedserv/source/inprocserv/smartpointer.hxx | 189 |
8 files changed, 2956 insertions, 0 deletions
diff --git a/embedserv/source/inprocserv/advisesink.cxx b/embedserv/source/inprocserv/advisesink.cxx new file mode 100644 index 000000000..c65ba4dbe --- /dev/null +++ b/embedserv/source/inprocserv/advisesink.cxx @@ -0,0 +1,180 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: advisesink.cxx,v $ + * + * $Revision: 1.1.8.2 $ + * + * last change: $Author: mav $ $Date: 2008/10/30 11:59:06 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#pragma warning(disable : 4668) + +#include <advisesink.hxx> + +namespace inprocserv +{ + +OleWrapperAdviseSink::OleWrapperAdviseSink() +: m_nRefCount( 0 ) +, m_pFormatEtc( NULL ) +, m_nAspect( DVASPECT_CONTENT ) +, m_nRegID( 0 ) +, m_bObjectAdvise( TRUE ) +, m_nDataRegFlag( 0 ) +, m_nViewRegFlag( 0 ) +, m_bHandleClosed( TRUE ) +, m_bClosed( FALSE ) +{ +} + +OleWrapperAdviseSink::OleWrapperAdviseSink( const ComSmart< IAdviseSink >& pListener ) +: m_nRefCount( 0 ) +, m_pListener( pListener ) +, m_pFormatEtc( NULL ) +, m_nAspect( DVASPECT_CONTENT ) +, m_nRegID( 0 ) +, m_bObjectAdvise( TRUE ) +, m_nDataRegFlag( 0 ) +, m_nViewRegFlag( 0 ) +, m_bHandleClosed( FALSE ) +, m_bClosed( FALSE ) +{ +} + +OleWrapperAdviseSink::OleWrapperAdviseSink( const ComSmart< IAdviseSink >& pListener, FORMATETC* pFormatEtc, DWORD nDataRegFlag ) +: m_nRefCount( 0 ) +, m_pListener( pListener ) +, m_pFormatEtc( NULL ) +, m_nAspect( DVASPECT_CONTENT ) +, m_nRegID( 0 ) +, m_bObjectAdvise( FALSE ) +, m_nDataRegFlag( nDataRegFlag ) +, m_nViewRegFlag( 0 ) +, m_bHandleClosed( FALSE ) +, m_bClosed( FALSE ) +{ + if ( pFormatEtc ) + { + m_pFormatEtc = new FORMATETC; + m_pFormatEtc->cfFormat = pFormatEtc->cfFormat; + m_pFormatEtc->ptd = NULL; + m_pFormatEtc->dwAspect = pFormatEtc->dwAspect; + m_pFormatEtc->lindex = pFormatEtc->lindex; + m_pFormatEtc->tymed = pFormatEtc->tymed; + } +} + +OleWrapperAdviseSink::OleWrapperAdviseSink( const ComSmart< IAdviseSink >& pListener, DWORD nAspect, DWORD nViewRegFlag ) +: m_nRefCount( 0 ) +, m_pListener( pListener ) +, m_pFormatEtc( NULL ) +, m_nAspect( nAspect ) +, m_nRegID( 0 ) +, m_bObjectAdvise( TRUE ) +, m_nDataRegFlag( 0 ) +, m_nViewRegFlag( nViewRegFlag ) +, m_bHandleClosed( FALSE ) +, m_bClosed( FALSE ) +{ +} + +OleWrapperAdviseSink::~OleWrapperAdviseSink() +{ + if ( m_pFormatEtc ) + delete m_pFormatEtc; +} + +STDMETHODIMP OleWrapperAdviseSink::QueryInterface( REFIID riid , void** ppv ) +{ + *ppv=NULL; + + if ( riid == IID_IUnknown ) + *ppv = (IUnknown*)this; + + if ( riid == IID_IAdviseSink ) + *ppv = (IAdviseSink*)this; + + if ( *ppv != NULL ) + { + ((IUnknown*)*ppv)->AddRef(); + return S_OK; + } + + return E_NOINTERFACE; +} + +STDMETHODIMP_(ULONG) OleWrapperAdviseSink::AddRef() +{ + return ++m_nRefCount; +} + +STDMETHODIMP_(ULONG) OleWrapperAdviseSink::Release() +{ + ULONG nReturn = --m_nRefCount; + if ( m_nRefCount == 0 ) + delete this; + + return nReturn; +} + +STDMETHODIMP_(void) OleWrapperAdviseSink::OnDataChange( LPFORMATETC pFetc, LPSTGMEDIUM pMedium ) +{ + if ( m_pListener ) + m_pListener->OnDataChange( pFetc, pMedium ); +} + +STDMETHODIMP_(void) OleWrapperAdviseSink::OnViewChange( DWORD dwAspect, LONG lindex ) +{ + if ( m_pListener ) + m_pListener->OnViewChange( dwAspect, lindex ); +} + +STDMETHODIMP_(void) OleWrapperAdviseSink::OnRename( LPMONIKER pMoniker ) +{ + if ( m_pListener ) + m_pListener->OnRename( pMoniker ); +} + +STDMETHODIMP_(void) OleWrapperAdviseSink::OnSave(void) +{ + if ( m_pListener ) + m_pListener->OnSave(); +} + +STDMETHODIMP_(void) OleWrapperAdviseSink::OnClose(void) +{ + if ( m_pListener ) + m_pListener->OnClose(); + + if ( m_bHandleClosed ) + m_bClosed = TRUE; +} + +} // namespace inprocserv + diff --git a/embedserv/source/inprocserv/advisesink.hxx b/embedserv/source/inprocserv/advisesink.hxx new file mode 100644 index 000000000..f240467ed --- /dev/null +++ b/embedserv/source/inprocserv/advisesink.hxx @@ -0,0 +1,102 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: advisesink.hxx,v $ + * + * $Revision: 1.1.8.2 $ + * + * last change: $Author: mav $ $Date: 2008/10/30 11:59:06 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#include <windows.h> +#include "smartpointer.hxx" + +namespace inprocserv { + +class OleWrapperAdviseSink : public IAdviseSink +{ +protected: + ULONG m_nRefCount; + + ComSmart< IAdviseSink > m_pListener; + DWORD m_nListenerID; + + FORMATETC* m_pFormatEtc; + DWORD m_nAspect; + + DWORD m_nRegID; + DWORD m_bObjectAdvise; + DWORD m_nDataRegFlag; + DWORD m_nViewRegFlag; + + BOOL m_bHandleClosed; + BOOL m_bClosed; + +public: + // an AdviseSink for own needs, should be created always + OleWrapperAdviseSink(); + + // an AdviseSink for IOleObject interface + OleWrapperAdviseSink( const ComSmart< IAdviseSink >& pListener ); + + // an AdviseSink for IDataObject interface + OleWrapperAdviseSink( const ComSmart< IAdviseSink >& pListener, FORMATETC* pFormatEtc, DWORD nDataRegFlag ); + + // an AdviseSink for IViewObject interface + OleWrapperAdviseSink( const ComSmart< IAdviseSink >& pListener, DWORD nAspect, DWORD nViewRegFlag ); + + virtual ~OleWrapperAdviseSink(); + + void SetRegID( DWORD nRegID ) { m_nRegID = nRegID; } + DWORD GetRegID() { return m_nRegID; } + + BOOL IsOleAdvise() { return m_bObjectAdvise; } + DWORD GetDataAdviseFlag() { return m_nDataRegFlag; } + DWORD GetViewAdviseFlag() { return m_nViewRegFlag; } + + FORMATETC* GetFormatEtc() { return m_pFormatEtc; } + DWORD GetAspect() { return m_nAspect; } + ComSmart< IAdviseSink >& GetOrigAdvise() { return m_pListener; } + + void SetClosed() { m_bClosed = TRUE; } + void UnsetClosed() { m_bClosed = FALSE; } + BOOL IsClosed() { return m_bClosed; } + + STDMETHODIMP QueryInterface(REFIID, void**); + STDMETHODIMP_(ULONG) AddRef(void); + STDMETHODIMP_(ULONG) Release(void); + + STDMETHODIMP_(void) OnDataChange(LPFORMATETC, LPSTGMEDIUM); + STDMETHODIMP_(void) OnViewChange(DWORD, LONG); + STDMETHODIMP_(void) OnRename(LPMONIKER); + STDMETHODIMP_(void) OnSave(void); + STDMETHODIMP_(void) OnClose(void); +}; + +}; // namespace advisesink + diff --git a/embedserv/source/inprocserv/dllentry.cxx b/embedserv/source/inprocserv/dllentry.cxx new file mode 100644 index 000000000..a6821cb34 --- /dev/null +++ b/embedserv/source/inprocserv/dllentry.cxx @@ -0,0 +1,343 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: dllentry.cxx,v $ + * + * $Revision: 1.1.8.2 $ + * + * last change: $Author: mav $ $Date: 2008/10/30 11:59:06 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#include <stdio.h> +#include <inprocembobj.h> +#include <embservconst.h> + +static const GUID* guidList[ SUPPORTED_FACTORIES_NUM ] = { + &OID_WriterTextServer, + &OID_WriterOASISTextServer, + &OID_CalcServer, + &OID_CalcOASISServer, + &OID_DrawingServer, + &OID_DrawingOASISServer, + &OID_PresentationServer, + &OID_PresentationOASISServer, + &OID_MathServer, + &OID_MathOASISServer +}; + +static HINSTANCE g_hInstance = NULL; +static ULONG g_nObj = 0; +static ULONG g_nLock = 0; + + +namespace { + int GetStringFromClassID( const GUID& guid, char* pBuf, int nLen ) + { + if ( nLen < 27 ) + return 0; + + int nResult = sprintf( pBuf, + "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}", + guid.Data1, + guid.Data2, + guid.Data3, + guid.Data4[0], + guid.Data4[1], + guid.Data4[2], + guid.Data4[3], + guid.Data4[4], + guid.Data4[5], + guid.Data4[6], + guid.Data4[7] ); + + if ( nResult && nResult < nLen ) + return ++nResult; + + return 0; + } + + HRESULT WriteLibraryToRegistry( char* pLibrary, DWORD nLen ) + { + HRESULT hRes = E_FAIL; + if ( pLibrary && nLen ) + { + HKEY hKey = NULL; + char* pPrefix = "Software\\Classes\\CLSID\\"; + char* pPostfix = "\\InprocHandler32"; + + hRes = S_OK; + for ( int nInd = 0; nInd < SUPPORTED_FACTORIES_NUM; nInd++ ) + { + char pSubKey[513]; + char pCLSID[64]; + int nGuidLen = GetStringFromClassID( *guidList[nInd], pCLSID, 64 ); + + BOOL bLocalSuccess = FALSE; + if ( nGuidLen && nGuidLen < 64 ) + { + pCLSID[nGuidLen] = 0; + sprintf( pSubKey, "%s%s%s", pPrefix, pCLSID, pPostfix ); + if ( ERROR_SUCCESS == RegOpenKey( HKEY_LOCAL_MACHINE, pSubKey, &hKey ) ) + { + if ( ERROR_SUCCESS == RegSetValueEx( hKey, "", 0, REG_SZ, (const BYTE*)pLibrary, nLen ) ) + bLocalSuccess = TRUE; + } + + if ( hKey ) + { + RegCloseKey( hKey ); + hKey = NULL; + } + } + + if ( !bLocalSuccess ) + hRes = E_FAIL; + } + } + + return hRes; + } +}; + +// =========================== +// InprocEmbedProvider_Impl declaration +// =========================== + +namespace inprocserv +{ + +class InprocEmbedProvider_Impl : public IClassFactory, public InprocCountedObject_Impl +{ +public: + + InprocEmbedProvider_Impl( const GUID& guid ); + virtual ~InprocEmbedProvider_Impl(); + + /* IUnknown methods */ + STDMETHOD(QueryInterface)(REFIID riid, LPVOID FAR * ppvObj); + STDMETHOD_(ULONG, AddRef)(); + STDMETHOD_(ULONG, Release)(); + + /* IClassFactory methods */ + STDMETHOD(CreateInstance)(IUnknown FAR* punkOuter, REFIID riid, void FAR* FAR* ppv); + STDMETHOD(LockServer)(int fLock); + +protected: + + ULONG m_refCount; + GUID m_guid; +}; +}; // namespace inprocserv + + +// =========================== +// Entry points +// =========================== + +// ------------------------------------------------------------------------------- +extern "C" BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/ ) +{ + if (dwReason == DLL_PROCESS_ATTACH) + { + g_hInstance = hInstance; + } + else if (dwReason == DLL_PROCESS_DETACH) + { + } + + return TRUE; // ok +} + +// ------------------------------------------------------------------------------- +extern "C" STDAPI DllGetClassObject( REFCLSID rclsid, REFIID riid, LPVOID* ppv ) +{ + for( int nInd = 0; nInd < SUPPORTED_FACTORIES_NUM; nInd++ ) + if ( *guidList[nInd] == rclsid ) + { + if ( !IsEqualIID( riid, IID_IUnknown ) && !IsEqualIID( riid, IID_IClassFactory ) ) + return E_NOINTERFACE; + + *ppv = new inprocserv::InprocEmbedProvider_Impl( rclsid ); + if ( *ppv == NULL ) + return E_OUTOFMEMORY; + + ((LPUNKNOWN)*ppv)->AddRef(); + return S_OK; + } + + return E_FAIL; +} + +// ------------------------------------------------------------------------------- +extern "C" STDAPI DllCanUnloadNow() +{ + if ( !g_nObj && !g_nLock ) + return S_OK; + + return S_FALSE; +} + +// ------------------------------------------------------------------------------- +STDAPI DllRegisterServer( void ) +{ + char aLibPath[1024]; + HMODULE aCurModule = GetModuleHandleA( "inprocserv.dll" ); + if( aCurModule ) + { + DWORD nLen = GetModuleFileNameA( aCurModule, aLibPath, 1019 ); + if ( nLen && nLen < 1019 ) + { + aLibPath[nLen++] = 0; + return WriteLibraryToRegistry( aLibPath, nLen ); + } + } + + return E_FAIL; +} + +// ------------------------------------------------------------------------------- +STDAPI DllUnregisterServer( void ) +{ + return WriteLibraryToRegistry( "ole32.dll", 10 ); +} + +// =========================== +// End of entry points +// =========================== + +namespace inprocserv +{ + +// =========================== +// InprocCountedObject_Impl implementation +// =========================== + +// ------------------------------------------------------------------------------- +InprocCountedObject_Impl::InprocCountedObject_Impl() +{ + g_nObj++; +} + +// ------------------------------------------------------------------------------- +InprocCountedObject_Impl::~InprocCountedObject_Impl() +{ + g_nObj--; +} + +// =========================== +// InprocEmbedProvider_Impl implementation +// =========================== + +// ------------------------------------------------------------------------------- +InprocEmbedProvider_Impl::InprocEmbedProvider_Impl( const GUID& guid ) +: m_refCount( 0 ) +, m_guid( guid ) +{ +} + +// ------------------------------------------------------------------------------- +InprocEmbedProvider_Impl::~InprocEmbedProvider_Impl() +{ +} + +// IUnknown +// ------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedProvider_Impl::QueryInterface( REFIID riid, void FAR* FAR* ppv ) +{ + if(IsEqualIID(riid, IID_IUnknown)) + { + AddRef(); + *ppv = (IUnknown*) this; + return S_OK; + } + else if (IsEqualIID(riid, IID_IClassFactory)) + { + AddRef(); + *ppv = (IClassFactory*) this; + return S_OK; + } + + *ppv = NULL; + return E_NOINTERFACE; +} + +// ------------------------------------------------------------------------------- +STDMETHODIMP_(ULONG) InprocEmbedProvider_Impl::AddRef() +{ + return ++m_refCount; +} + +// ------------------------------------------------------------------------------- +STDMETHODIMP_(ULONG) InprocEmbedProvider_Impl::Release() +{ + sal_Int32 nCount = --m_refCount; + if ( nCount == 0 ) + delete this; + return nCount; +} + +// ------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedProvider_Impl::CreateInstance(IUnknown FAR* punkOuter, + REFIID riid, + void FAR* FAR* ppv) +{ + // TODO/LATER: should the aggregation be supported? + // if ( punkOuter != NULL && riid != IID_IUnknown ) + // return E_NOINTERFACE; + if ( punkOuter != NULL ) + return CLASS_E_NOAGGREGATION; + + InprocEmbedDocument_Impl* pEmbedDocument = new InprocEmbedDocument_Impl( m_guid ); + if ( !pEmbedDocument ) + return E_OUTOFMEMORY; + + pEmbedDocument->AddRef(); + HRESULT hr = pEmbedDocument->Init(); + if ( SUCCEEDED( hr ) ) + hr = pEmbedDocument->QueryInterface( riid, ppv ); + pEmbedDocument->Release(); + + if ( !SUCCEEDED( hr ) ) + *ppv = NULL; + + return hr; +} + +// ------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedProvider_Impl::LockServer( int fLock ) +{ + if ( fLock ) + g_nLock++; + else + g_nLock--; + + return S_OK; +} + +}; // namespace inprocserv + diff --git a/embedserv/source/inprocserv/exports.dxp b/embedserv/source/inprocserv/exports.dxp new file mode 100644 index 000000000..65a5126f1 --- /dev/null +++ b/embedserv/source/inprocserv/exports.dxp @@ -0,0 +1,5 @@ +DllGetClassObject +DllCanUnloadNow +DllMain +DllRegisterServer +DllUnregisterServer diff --git a/embedserv/source/inprocserv/inprocembobj.cxx b/embedserv/source/inprocserv/inprocembobj.cxx new file mode 100644 index 000000000..3ef2b82a3 --- /dev/null +++ b/embedserv/source/inprocserv/inprocembobj.cxx @@ -0,0 +1,1811 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: inprocembobj.cxx,v $ + * + * $Revision: 1.1.8.2 $ + * + * last change: $Author: mav $ $Date: 2008/10/30 11:59:06 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#include <stdio.h> + +#include <embservconst.h> +#include "inprocembobj.h" + +// #define OWNDEBUG + +#ifdef OWNDEBUG +#define WRITEDEBUGINFO( x ) WriteDebugInfo( x ) +#else +#define WRITEDEBUGINFO( x ) +#endif + +namespace inprocserv +{ + +//------------------------------------------------------------------------------- +#ifdef OWNDEBUG +void WriteDebugInfo( char* pString ) +{ + FILE* pFile = fopen( "c:\\inproc.log", "aw" ); + if ( pFile ) + { + fprintf( pFile, pString ); + fclose( pFile ); + } +} +#endif + +//------------------------------------------------------------------------------- +HRESULT InprocEmbedDocument_Impl::Init() +{ + return S_OK; +} + +//------------------------------------------------------------------------------- +void InprocEmbedDocument_Impl::SetFileName( LPCOLESTR pszFileName ) +{ + // copy the string + size_t nLen = wcslen( pszFileName ); + if ( m_pFileName ) + { + delete[] m_pFileName; + m_pFileName = NULL; + } + m_pFileName = new wchar_t[nLen+1]; + wcsncpy( m_pFileName, pszFileName, nLen ); + m_pFileName[nLen] = 0; +} + +//------------------------------------------------------------------------------- +BOOL InprocEmbedDocument_Impl::CheckDefHandler() +{ + // set the own listener + if ( m_pOleAdvises[0] == NULL ) + { + m_pOleAdvises[0] = new OleWrapperAdviseSink(); + } + else + { + if ( m_pOleAdvises[0]->IsClosed() ) + { + if ( m_pDefHandler ) + { + // deregister all the listeners + + ComSmart< IOleObject > pOleObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject ); + if ( SUCCEEDED( hr ) && pOleObject ) + { + for ( DWORD nInd = 0; nInd < DEFAULT_ARRAY_LEN; nInd++ ) + if ( m_pOleAdvises[nInd] ) + { + DWORD nID = m_pOleAdvises[nInd]->GetRegID(); + pOleObject->Unadvise( nID ); + m_pOleAdvises[nInd]->SetRegID( 0 ); + } + } + + ComSmart< IDataObject > pIDataObject; + hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject ); + if ( SUCCEEDED( hr ) && pIDataObject ) + { + for ( DWORD nInd = 0; nInd < DEFAULT_ARRAY_LEN; nInd++ ) + if ( m_pDataAdvises[nInd] ) + { + DWORD nID = m_pDataAdvises[nInd]->GetRegID(); + pIDataObject->DUnadvise( nID ); + m_pDataAdvises[nInd]->SetRegID( 0 ); + } + } + + ComSmart< IViewObject > pIViewObject; + hr = m_pDefHandler->QueryInterface( IID_IViewObject, (void**)&pIViewObject ); + if ( SUCCEEDED( hr ) && pIViewObject ) + { + if ( m_pViewAdvise ) + pIViewObject->SetAdvise( m_pViewAdvise->GetAspect(), m_pViewAdvise->GetViewAdviseFlag(), NULL ); + } + + m_pDefHandler = NULL; + } + + m_pOleAdvises[0]->UnsetClosed(); + } + } + + if ( m_nCallsOnStack ) + return FALSE; + + if ( !m_pDefHandler ) + { + // create a new default inprocess handler + HRESULT hr = OleCreateDefaultHandler( m_guid, NULL, IID_IUnknown, (void**)&m_pDefHandler ); + if ( SUCCEEDED( hr ) ) + { +// // reinit the handler +// ComSmart< IRunnableObject > pIRunObj; +// hr = m_pDefHandler->QueryInterface( IID_IRunnableObject, (void**)&pIRunObj ); +// +// if ( SUCCEEDED( hr ) && pIRunObj ) + { +// { +// ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem +// hr = pIRunObj->Run( NULL ); +// } +// +// if ( SUCCEEDED( hr ) ) + { + if ( m_nInitMode == INIT_FROM_STORAGE ) + { + ComSmart< IPersistStorage > pPersist; + hr = m_pDefHandler->QueryInterface( IID_IPersistStorage, (void**)&pPersist ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pPersist && m_pStorage ) + hr = pPersist->InitNew( m_pStorage ); + } + else if ( m_nInitMode == LOAD_FROM_STORAGE ) + { + ComSmart< IPersistStorage > pPersist; + hr = m_pDefHandler->QueryInterface( IID_IPersistStorage, (void**)&pPersist ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pPersist && m_pStorage ) + hr = pPersist->Load( m_pStorage ); + } + else if ( m_nInitMode == LOAD_FROM_FILE ) + { + ComSmart< IPersistFile > pPersistFile; + hr = m_pDefHandler->QueryInterface( IID_IPersistFile, (void**)&pPersistFile ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pPersistFile && m_pFileName ) + hr = pPersistFile->Load( m_pFileName, m_nFileOpenMode ); + } + } + } + } + + if ( !SUCCEEDED( hr ) || !m_pDefHandler ) + { + m_pDefHandler = NULL; + return FALSE; + } + + // register all the listeners new + + ComSmart< IOleObject > pOleObject; + hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject ); + if ( SUCCEEDED( hr ) && pOleObject ) + { + if ( m_pClientSite ) + pOleObject->SetClientSite( m_pClientSite ); + + for ( DWORD nInd = 0; nInd < DEFAULT_ARRAY_LEN; nInd++ ) + if ( m_pOleAdvises[nInd] ) + { + DWORD nRegID = 0; + if ( SUCCEEDED( pOleObject->Advise( m_pOleAdvises[nInd], &nRegID ) ) && nRegID > 0 ) + m_pOleAdvises[nInd]->SetRegID( nRegID ); + } + } + + ComSmart< IDataObject > pIDataObject; + hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject ); + if ( SUCCEEDED( hr ) && pIDataObject ) + { + for ( DWORD nInd = 0; nInd < DEFAULT_ARRAY_LEN; nInd++ ) + if ( m_pDataAdvises[nInd] ) + { + DWORD nRegID = 0; + if ( SUCCEEDED( pIDataObject->DAdvise( m_pDataAdvises[nInd]->GetFormatEtc(), m_pDataAdvises[nInd]->GetDataAdviseFlag(), m_pDataAdvises[nInd], &nRegID ) ) && nRegID > 0 ) + m_pDataAdvises[nInd]->SetRegID( nRegID ); + } + } + + ComSmart< IViewObject > pIViewObject; + hr = m_pDefHandler->QueryInterface( IID_IViewObject, (void**)&pIViewObject ); + if ( SUCCEEDED( hr ) && pIViewObject ) + { + if ( m_pViewAdvise ) + pIViewObject->SetAdvise( m_pViewAdvise->GetAspect(), m_pViewAdvise->GetViewAdviseFlag(), m_pViewAdvise ); + } + } + + return TRUE; +} + +//------------------------------------------------------------------------------- +DWORD InprocEmbedDocument_Impl::InsertAdviseLinkToList( const ComSmart<OleWrapperAdviseSink>& pOwnAdvise, ComSmart< OleWrapperAdviseSink > pAdvises[] ) +{ + // the result should start from 1 in case of success, the element 0 can be used for own needs + DWORD nResult = 0; + + if ( pOwnAdvise ) + { + for ( DWORD nInd = 1; nInd < DEFAULT_ARRAY_LEN && nResult == 0; nInd++ ) + { + if ( pAdvises[nInd] == pOwnAdvise ) + { + nResult = nInd; + } + else if ( pAdvises[nInd] == NULL ) + { + pAdvises[nInd] = pOwnAdvise; + nResult = nInd; + } + } + } + + return nResult; +} + +//------------------------------------------------------------------------------- +void InprocEmbedDocument_Impl::Clean() +{ + m_pDefHandler = (IUnknown*)NULL; + + for ( DWORD nInd = 0; nInd < DEFAULT_ARRAY_LEN; nInd++ ) + { + if ( m_pOleAdvises[nInd] ) + { + ComSmart< OleWrapperAdviseSink > pAdvice = m_pOleAdvises[nInd]; + m_pOleAdvises[nInd] = NULL; + } + + if ( m_pDataAdvises[nInd] ) + { + ComSmart< OleWrapperAdviseSink > pAdvice = m_pDataAdvises[nInd]; + m_pDataAdvises[nInd] = NULL; + } + } + + m_nInitMode = NOINIT; + m_pStorage = NULL; + m_pClientSite = NULL; + + m_nFileOpenMode = 0; + if ( m_pFileName ) + { + delete m_pFileName; + m_pFileName = NULL; + } +} + +// IUnknown +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::QueryInterface( REFIID riid, void FAR* FAR* ppv ) +{ + if(IsEqualIID(riid, IID_IUnknown)) + { + AddRef(); + *ppv = (IUnknown*) (IPersistStorage*) this; + return S_OK; + } + else if (IsEqualIID(riid, IID_IPersist)) + { + AddRef(); + *ppv = (IPersist*) (IPersistStorage*) this; + return S_OK; + } + else if (IsEqualIID(riid, IID_IPersistStorage)) + { + AddRef(); + *ppv = (IPersistStorage*) this; + return S_OK; + } + else if (IsEqualIID(riid, IID_IDataObject)) + { + AddRef(); + *ppv = (IDataObject*) this; + return S_OK; + } + else if (IsEqualIID(riid, IID_IOleObject)) + { + AddRef(); + *ppv = (IOleObject*) this; + return S_OK; + } + else if (IsEqualIID(riid, IID_IPersistFile)) + { + AddRef(); + *ppv = (IPersistFile*) this; + return S_OK; + } + else if (IsEqualIID(riid, IID_IRunnableObject)) + { + AddRef(); + *ppv = (IRunnableObject*) this; + return S_OK; + } + else if (IsEqualIID(riid, IID_IViewObject)) + { + AddRef(); + *ppv = (IViewObject*) this; + return S_OK; + } + else if (IsEqualIID(riid, IID_IViewObject2)) + { + AddRef(); + *ppv = (IViewObject2*) this; + return S_OK; + } + else if (IsEqualIID(riid, IID_IOleCache)) + { + AddRef(); + *ppv = (IOleCache*) &m_aInternalCache; + return S_OK; + } + else if (IsEqualIID(riid, IID_IOleCache2)) + { + AddRef(); + *ppv = (IOleCache2*) &m_aInternalCache; + return S_OK; + } + else if (IsEqualIID(riid, IID_IOleWindow)) + { + AddRef(); + *ppv = (IOleWindow*) this; + return S_OK; + } + else if (IsEqualIID(riid, IID_IOleInPlaceObject)) + { + AddRef(); + *ppv = (IOleInPlaceObject*) this; + return S_OK; + } + else if (IsEqualIID(riid, IID_IDispatch)) + { + AddRef(); + *ppv = (IDispatch*) this; + return S_OK; + } + + *ppv = NULL; + return ResultFromScode(E_NOINTERFACE); +} + +//------------------------------------------------------------------------------- +STDMETHODIMP_(ULONG) InprocEmbedDocument_Impl::AddRef() +{ + return ++m_refCount; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP_(ULONG) InprocEmbedDocument_Impl::Release() +{ + // unfortunately there are reentrance problems in mfc that have to be workarounded + sal_Int32 nCount = m_refCount > 0 ? --m_refCount : 0; + if ( nCount == 0 && !m_bDeleted ) + { + // deleting of this object can trigger deleting of mfc objects that will try to delete this object one more time + m_bDeleted = TRUE; + + Clean(); + delete this; + } + return nCount; +} + +// IPersist +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::GetClassID( CLSID* pClassId ) +{ + *pClassId = *&m_guid; + return S_OK; +} + +// IPersistStorage +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::IsDirty() +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::IsDirty()1\n" ); + if ( m_pDefHandler == NULL || m_pOleAdvises[0] == NULL || m_pOleAdvises[0]->IsClosed() ) + return S_FALSE; + + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::IsDirty()2\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IPersistStorage > pPersist; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IPersistStorage, (void**)&pPersist ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pPersist ) + return pPersist->IsDirty(); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::InitNew( IStorage *pStg ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InitNew( IStorage *pStg )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IPersistStorage > pPersist; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IPersistStorage, (void**)&pPersist ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pPersist ) + { + hr = pPersist->InitNew( pStg ); + if ( SUCCEEDED( hr ) ) + { + m_nInitMode = INIT_FROM_STORAGE; + m_pStorage = pStg; + + m_nFileOpenMode = 0; + if ( m_pFileName ) + { + delete[] m_pFileName; + m_pFileName = NULL; + } + } + + return hr; + } + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::Load( IStorage *pStg ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Load( IStorage *pStg )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IPersistStorage > pPersist; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IPersistStorage, (void**)&pPersist ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pPersist ) + { + hr = pPersist->Load( pStg ); + if ( SUCCEEDED( hr ) ) + { + m_nInitMode = LOAD_FROM_STORAGE; + m_pStorage = pStg; + + m_nFileOpenMode = 0; + if ( m_pFileName ) + { + delete[] m_pFileName; + m_pFileName = NULL; + } + } + + return hr; + } + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::Save( IStorage *pStgSave, BOOL fSameAsLoad ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Save( IStorage *pStgSave, BOOL fSameAsLoad )1\n" ); + if ( fSameAsLoad && ( m_pDefHandler == NULL || m_pOleAdvises[0] == NULL || m_pOleAdvises[0]->IsClosed() ) ) + return S_OK; + + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Save( IStorage *pStgSave, BOOL fSameAsLoad )2\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IPersistStorage > pPersist; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IPersistStorage, (void**)&pPersist ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pPersist ) + return pPersist->Save( pStgSave, fSameAsLoad ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::SaveCompleted( IStorage *pStgNew ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SaveCompleted( IStorage *pStgNew )1\n" ); + if ( m_pDefHandler == NULL || m_pOleAdvises[0] == NULL || m_pOleAdvises[0]->IsClosed() ) + { + if ( pStgNew ) + m_pStorage = pStgNew; + + return S_OK; + } + + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SaveCompleted( IStorage *pStgNew )2\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IPersistStorage > pPersist; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IPersistStorage, (void**)&pPersist ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pPersist ) + { + hr = pPersist->SaveCompleted( pStgNew ); + if ( SUCCEEDED( hr ) ) + { + m_nInitMode = LOAD_FROM_STORAGE; + if ( pStgNew ) + m_pStorage = pStgNew; + + m_nFileOpenMode = 0; + if ( m_pFileName ) + { + delete[] m_pFileName; + m_pFileName = NULL; + } + } + + return hr; + } + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::HandsOffStorage() +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::HandsOffStorage()\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IPersistStorage > pPersist; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IPersistStorage, (void**)&pPersist ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pPersist ) + return pPersist->HandsOffStorage(); + } + + return E_FAIL; +} + +// IPersistFile +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::Load( LPCOLESTR pszFileName, DWORD dwMode ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Load( LPCOLESTR pszFileName, DWORD dwMode )\n" ); + if ( CheckDefHandler() && pszFileName ) + { + ComSmart< IPersistFile > pPersist; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IPersistFile, (void**)&pPersist ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pPersist ) + { + hr = pPersist->Load( pszFileName, dwMode ); + if ( SUCCEEDED( hr ) ) + { + m_nInitMode = LOAD_FROM_FILE; + if ( m_pStorage ) + m_pStorage = NULL; + + m_nFileOpenMode = dwMode; + // copy the string + SetFileName( pszFileName ); + } + + return hr; + } + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::Save( LPCOLESTR pszFileName, BOOL fRemember ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Save( LPCOLESTR pszFileName, BOOL fRemember )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IPersistFile > pPersist; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IPersistFile, (void**)&pPersist ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pPersist ) + return pPersist->Save( pszFileName, fRemember ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::SaveCompleted( LPCOLESTR pszFileName ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SaveCompleted( LPCOLESTR pszFileName )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IPersistFile > pPersist; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IPersistFile, (void**)&pPersist ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pPersist ) + { + hr = pPersist->SaveCompleted( pszFileName ); + if ( SUCCEEDED( hr ) ) + { + m_nInitMode = LOAD_FROM_STORAGE; + if ( m_pStorage ) + m_pStorage = NULL; + + m_nFileOpenMode = STGM_READWRITE; // was just written + // copy the string + SetFileName( pszFileName ); + } + } + + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::GetCurFile( LPOLESTR *ppszFileName ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetCurFile( LPOLESTR *ppszFileName )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IPersistFile > pPersist; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IPersistFile, (void**)&pPersist ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pPersist ) + return pPersist->GetCurFile( ppszFileName ); + } + + return E_FAIL; +} + +// IOleObject +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::SetClientSite( IOleClientSite* pSite ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetClientSite( IOleClientSite* pSite )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IOleObject > pOleObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pOleObject ) + { + HRESULT hr = pOleObject->SetClientSite( pSite ); + if ( SUCCEEDED( hr ) ) + m_pClientSite = pSite; + + return hr; + } + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::GetClientSite( IOleClientSite** pSite ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetClientSite( IOleClientSite** pSite )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IOleObject > pOleObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pOleObject ) + return pOleObject->GetClientSite( pSite ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::SetHostNames( LPCOLESTR szContainerApp, LPCOLESTR szContainerObj ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetHostNames( LPCOLESTR szContainerApp, LPCOLESTR szContainerObj )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IOleObject > pOleObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pOleObject ) + return pOleObject->SetHostNames( szContainerApp, szContainerObj ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::Close( DWORD dwSaveOption ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Close( DWORD dwSaveOption )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IOleObject > pOleObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pOleObject ) + { + hr = pOleObject->Close( dwSaveOption ); + hr = CoDisconnectObject( (IUnknown*)(IPersistStorage*)this, 0 ); + + // if the object is closed from outside that means that it should go to uninitialized state + Clean(); + + return S_OK; + } + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::SetMoniker( DWORD dwWhichMoniker, IMoniker * pmk ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetMoniker( DWORD dwWhichMoniker, IMoniker * pmk )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IOleObject > pOleObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pOleObject ) + return pOleObject->SetMoniker( dwWhichMoniker, pmk ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::GetMoniker( DWORD dwAssign, DWORD dwWhichMoniker, IMoniker ** ppmk ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetMoniker( DWORD dwAssign, DWORD dwWhichMoniker, IMoniker ** ppmk )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IOleObject > pOleObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pOleObject ) + return pOleObject->GetMoniker( dwAssign, dwWhichMoniker, ppmk ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::InitFromData( IDataObject * pDataObject, BOOL fCreation, DWORD dwReserved ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InitFromData( IDataObject * pDataObject, BOOL fCreation, DWORD dwReserved )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IOleObject > pOleObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pOleObject ) + return pOleObject->InitFromData( pDataObject, fCreation, dwReserved ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::GetClipboardData( DWORD dwReserved, IDataObject ** ppDataObject ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetClipboardData( DWORD dwReserved, IDataObject ** ppDataObject )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IOleObject > pOleObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pOleObject ) + return pOleObject->GetClipboardData( dwReserved, ppDataObject ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::DoVerb( + LONG iVerb, + LPMSG pMsg, + IOleClientSite *pActiveSite, + LONG nLong, + HWND hWin, + LPCRECT pRect ) +{ + WRITEDEBUGINFO( "DoVerb\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IOleObject > pOleObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pOleObject ) + return pOleObject->DoVerb( iVerb, pMsg, pActiveSite, nLong, hWin, pRect ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::EnumVerbs( IEnumOLEVERB ** ppEnumOleVerb ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::EnumVerbs( IEnumOLEVERB ** ppEnumOleVerb )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IOleObject > pOleObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pOleObject ) + return pOleObject->EnumVerbs( ppEnumOleVerb ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::Update() +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Update()\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IOleObject > pOleObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pOleObject ) + return pOleObject->Update(); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::IsUpToDate() +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::IsUpToDate()\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IOleObject > pOleObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pOleObject ) + return pOleObject->IsUpToDate(); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::GetUserClassID( CLSID *pClsid ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetUserClassID( CLSID *pClsid )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IOleObject > pOleObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pOleObject ) + return pOleObject->GetUserClassID( pClsid ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::GetUserType( DWORD dwFormOfType, LPOLESTR * pszUserType ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetUserType( DWORD dwFormOfType, LPOLESTR * pszUserType )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IOleObject > pOleObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pOleObject ) + return pOleObject->GetUserType( dwFormOfType, pszUserType ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::SetExtent( DWORD dwDrawAspect, SIZEL *psizel ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetExtent( DWORD dwDrawAspect, SIZEL *psizel )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IOleObject > pOleObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pOleObject ) + return pOleObject->SetExtent( dwDrawAspect, psizel ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::GetExtent( DWORD dwDrawAspect, SIZEL * psizel ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetExtent( DWORD dwDrawAspect, SIZEL * psizel )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IOleObject > pOleObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pOleObject ) + return pOleObject->GetExtent( dwDrawAspect, psizel ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::Advise( IAdviseSink *pAdvSink, DWORD *pdwConnection ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Advise( IAdviseSink *pAdvSink, DWORD *pdwConnection )\n" ); + if ( pAdvSink && CheckDefHandler() ) + { + ComSmart< IOleObject > pOleObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pOleObject ) + { + ComSmart< OleWrapperAdviseSink > pOwnAdvise( new OleWrapperAdviseSink( pAdvSink ) ); + DWORD nRegID = 0; + + if ( SUCCEEDED( pOleObject->Advise( pOwnAdvise, &nRegID ) ) && nRegID > 0 ) + { + pOwnAdvise->SetRegID( nRegID ); + *pdwConnection = InsertAdviseLinkToList( pOwnAdvise, m_pOleAdvises ); + if ( *pdwConnection ) + return S_OK; + else + pOleObject->Unadvise( nRegID ); + } + } + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::Unadvise( DWORD dwConnection ) +{ + if ( DEFAULT_ARRAY_LEN > dwConnection && dwConnection > 0 && m_pOleAdvises[dwConnection] ) + { + if ( m_pDefHandler ) + { + ComSmart< IOleObject > pOleObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pOleObject ) + { + DWORD nID = m_pOleAdvises[dwConnection]->GetRegID(); + return pOleObject->Unadvise( nID ); + } + } + + m_pOleAdvises[dwConnection] = NULL; + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::EnumAdvise( IEnumSTATDATA ** /*ppenumAdvise*/ ) +{ + return E_NOTIMPL; + +// if ( CheckDefHandler() ) +// { +// ComSmart< IOleObject > pOleObject; +// HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject ); +// +// ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem +// if ( SUCCEEDED( hr ) && pOleObject ) +// return pOleObject->EnumAdvise( ppenumAdvise ); +// } +// +// return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::GetMiscStatus( DWORD dwAspect, DWORD * pdwStatus ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetMiscStatus( DWORD dwAspect, DWORD * pdwStatus )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IOleObject > pOleObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pOleObject ) + return pOleObject->GetMiscStatus( dwAspect, pdwStatus ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::SetColorScheme( LOGPALETTE * pLogpal ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetColorScheme( LOGPALETTE * pLogpal )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IOleObject > pOleObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pOleObject ) + return pOleObject->SetColorScheme( pLogpal ); + } + + return E_FAIL; +} + +//IDataObject +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::GetData( FORMATETC * pFormatetc, STGMEDIUM * pMedium ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetData( FORMATETC * pFormatetc, STGMEDIUM * pMedium )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IDataObject > pIDataObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIDataObject ) + return pIDataObject->GetData( pFormatetc, pMedium ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::GetDataHere( FORMATETC * pFormatetc, STGMEDIUM * pMedium ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetDataHere( FORMATETC * pFormatetc, STGMEDIUM * pMedium )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IDataObject > pIDataObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIDataObject ) + return pIDataObject->GetDataHere( pFormatetc, pMedium ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::QueryGetData( FORMATETC * pFormatetc ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::QueryGetData( FORMATETC * pFormatetc )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IDataObject > pIDataObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIDataObject ) + return pIDataObject->QueryGetData( pFormatetc ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::GetCanonicalFormatEtc( FORMATETC * pFormatetcIn, FORMATETC * pFormatetcOut ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetCanonicalFormatEtc( FORMATETC * pFormatetcIn, FORMATETC * pFormatetcOut )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IDataObject > pIDataObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIDataObject ) + return pIDataObject->GetCanonicalFormatEtc( pFormatetcIn, pFormatetcOut ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::SetData( FORMATETC * pFormatetc, STGMEDIUM * pMedium, BOOL fRelease ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetData( FORMATETC * pFormatetc, STGMEDIUM * pMedium, BOOL fRelease )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IDataObject > pIDataObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIDataObject ) + return pIDataObject->SetData( pFormatetc, pMedium, fRelease ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::EnumFormatEtc( DWORD dwDirection, IEnumFORMATETC ** ppFormatetc ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::EnumFormatEtc( DWORD dwDirection, IEnumFORMATETC ** ppFormatetc )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IDataObject > pIDataObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIDataObject ) + return pIDataObject->EnumFormatEtc( dwDirection, ppFormatetc ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::DAdvise( FORMATETC * pFormatetc, DWORD advf, IAdviseSink * pAdvSink, DWORD * pdwConnection ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::DAdvise( FORMATETC * pFormatetc, DWORD advf, IAdviseSink * pAdvSink, DWORD * pdwConnection )\n" ); + if ( pAdvSink && CheckDefHandler() ) + { + ComSmart< IDataObject > pIDataObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIDataObject ) + { + ComSmart< OleWrapperAdviseSink > pOwnAdvise( new OleWrapperAdviseSink( ComSmart<IAdviseSink>( pAdvSink ), pFormatetc, advf ) ); + DWORD nRegID = 0; + + if ( SUCCEEDED( pIDataObject->DAdvise( pFormatetc, advf, pOwnAdvise, &nRegID ) ) && nRegID > 0 ) + { + pOwnAdvise->SetRegID( nRegID ); + *pdwConnection = InsertAdviseLinkToList( pOwnAdvise, m_pDataAdvises ); + if ( *pdwConnection ) + return S_OK; + else + pIDataObject->DUnadvise( nRegID ); + } + } + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::DUnadvise( DWORD dwConnection ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::DUnadvise( DWORD dwConnection )\n" ); + if ( m_pDefHandler && DEFAULT_ARRAY_LEN > dwConnection && dwConnection > 0 && m_pDataAdvises[dwConnection] ) + { + if ( CheckDefHandler() ) + { + ComSmart< IDataObject > pIDataObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIDataObject ) + { + DWORD nID = m_pDataAdvises[dwConnection]->GetRegID(); + return pIDataObject->DUnadvise( nID ); + } + } + + m_pDataAdvises[dwConnection] = NULL; + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::EnumDAdvise( IEnumSTATDATA ** ppenumAdvise ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::EnumDAdvise( IEnumSTATDATA ** ppenumAdvise )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IDataObject > pIDataObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIDataObject ) + return pIDataObject->EnumDAdvise( ppenumAdvise ); + } + + return E_FAIL; +} + +// IRunnableObject +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::GetRunningClass( LPCLSID lpClsid ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetRunningClass( LPCLSID lpClsid )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IRunnableObject > pIRunObj; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IRunnableObject, (void**)&pIRunObj ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIRunObj ) + return pIRunObj->GetRunningClass( lpClsid ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::Run( LPBINDCTX pbc ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Run( LPBINDCTX pbc )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IRunnableObject > pIRunObj; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IRunnableObject, (void**)&pIRunObj ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIRunObj ) + return pIRunObj->Run( pbc ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +BOOL STDMETHODCALLTYPE InprocEmbedDocument_Impl::IsRunning() +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::IsRunning()\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IRunnableObject > pIRunObj; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IRunnableObject, (void**)&pIRunObj ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIRunObj ) + return pIRunObj->IsRunning(); + } + + return E_FAIL; + +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::LockRunning( BOOL fLock, BOOL fLastUnlockCloses ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::LockRunning( BOOL fLock, BOOL fLastUnlockCloses )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IRunnableObject > pIRunObj; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IRunnableObject, (void**)&pIRunObj ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIRunObj ) + return pIRunObj->LockRunning( fLock, fLastUnlockCloses ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::SetContainedObject( BOOL fContained) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetContainedObject( BOOL fContained)\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IRunnableObject > pIRunObj; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IRunnableObject, (void**)&pIRunObj ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIRunObj ) + return pIRunObj->SetContainedObject( fContained ); + } + + return E_FAIL; +} + + +// IViewObject methods +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::Draw( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DVTARGETDEVICE *ptd, HDC hdcTargetDev, HDC hdcDraw, LPCRECTL lprcBounds, LPCRECTL lprcWBounds, BOOL ( STDMETHODCALLTYPE *pfnContinue )( ULONG_PTR dwContinue ), ULONG_PTR dwContinue ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Draw( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DVTARGETDEVICE *ptd, HDC hdcTargetDev, HDC hdcDraw, LPCRECTL lprcBounds, LPCRECTL lprcWBounds, BOOL ( STDMETHODCALLTYPE *pfnContinue )( ULONG_PTR dwContinue ), ULONG_PTR dwContinue )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IViewObject > pIViewObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IViewObject, (void**)&pIViewObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIViewObject ) + return pIViewObject->Draw( dwDrawAspect, lindex, pvAspect, ptd, hdcTargetDev, hdcDraw, lprcBounds, lprcWBounds, pfnContinue, dwContinue ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::GetColorSet( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetColorSet( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IViewObject > pIViewObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IViewObject, (void**)&pIViewObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIViewObject ) + return pIViewObject->GetColorSet( dwDrawAspect, lindex, pvAspect, ptd, hicTargetDev, ppColorSet ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::Freeze( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DWORD *pdwFreeze ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Freeze( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DWORD *pdwFreeze )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IViewObject > pIViewObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IViewObject, (void**)&pIViewObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIViewObject ) + return pIViewObject->Freeze( dwDrawAspect, lindex, pvAspect, pdwFreeze ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::Unfreeze( DWORD dwFreeze ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Unfreeze( DWORD dwFreeze )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IViewObject > pIViewObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IViewObject, (void**)&pIViewObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIViewObject ) + return pIViewObject->Unfreeze( dwFreeze ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::SetAdvise( DWORD aspects, DWORD advf, IAdviseSink *pAdvSink ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetAdvise( DWORD aspects, DWORD advf, IAdviseSink *pAdvSink )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IViewObject > pIViewObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IViewObject, (void**)&pIViewObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIViewObject ) + { + ComSmart< OleWrapperAdviseSink > pOwnAdvise( new OleWrapperAdviseSink( pAdvSink, aspects, advf ) ); + + if ( SUCCEEDED( pIViewObject->SetAdvise( aspects, advf, pOwnAdvise ) ) ) + { + m_pViewAdvise = pOwnAdvise; + return S_OK; + } + } + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::GetAdvise( DWORD *pAspects, DWORD *pAdvf, IAdviseSink **ppAdvSink ) +{ + if ( !ppAdvSink ) + return E_INVALIDARG; + + if ( m_pViewAdvise ) + { + if ( pAspects ) + *pAspects = m_pViewAdvise->GetAspect(); + + if ( pAdvf ) + *pAdvf = m_pViewAdvise->GetViewAdviseFlag(); + + *ppAdvSink = m_pViewAdvise->GetOrigAdvise(); + if ( *ppAdvSink ) + (*ppAdvSink)->AddRef(); + } + else + *ppAdvSink = NULL; + + return S_OK; +} + +// IViewObject2 methods +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::GetExtent( DWORD dwDrawAspect, LONG lindex, DVTARGETDEVICE *ptd, LPSIZEL lpsizel ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetExtent( DWORD dwDrawAspect, LONG lindex, DVTARGETDEVICE *ptd, LPSIZEL lpsizel )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IViewObject2 > pIViewObject2; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IViewObject2, (void**)&pIViewObject2 ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIViewObject2 ) + return pIViewObject2->GetExtent( dwDrawAspect, lindex, ptd, lpsizel ); + } + + return E_FAIL; +} + + + +// IOleWindow methods +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::GetWindow( HWND *phwnd ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetWindow( HWND *phwnd )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IOleWindow > pIOleWindow; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleWindow, (void**)&pIOleWindow ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIOleWindow ) + return pIOleWindow->GetWindow( phwnd ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::ContextSensitiveHelp( BOOL fEnterMode ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::ContextSensitiveHelp( BOOL fEnterMode )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IOleWindow > pIOleWindow; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleWindow, (void**)&pIOleWindow ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIOleWindow ) + return pIOleWindow->ContextSensitiveHelp( fEnterMode ); + } + + return E_FAIL; +} + + +// IOleInPlaceObject methods +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::InPlaceDeactivate( void ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InPlaceDeactivate( void )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IOleInPlaceObject > pIOleInPlaceObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleInPlaceObject, (void**)&pIOleInPlaceObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIOleInPlaceObject ) + return pIOleInPlaceObject->InPlaceDeactivate(); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::UIDeactivate( void ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::UIDeactivate( void )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IOleInPlaceObject > pIOleInPlaceObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleInPlaceObject, (void**)&pIOleInPlaceObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIOleInPlaceObject ) + return pIOleInPlaceObject->UIDeactivate(); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::SetObjectRects( LPCRECT lprcPosRect, LPCRECT lprcClipRect ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetObjectRects( LPCRECT lprcPosRect, LPCRECT lprcClipRect )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IOleInPlaceObject > pIOleInPlaceObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleInPlaceObject, (void**)&pIOleInPlaceObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIOleInPlaceObject ) + return pIOleInPlaceObject->SetObjectRects( lprcPosRect, lprcClipRect ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::ReactivateAndUndo( void ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::ReactivateAndUndo( void )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IOleInPlaceObject > pIOleInPlaceObject; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleInPlaceObject, (void**)&pIOleInPlaceObject ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIOleInPlaceObject ) + return pIOleInPlaceObject->ReactivateAndUndo(); + } + + return E_FAIL; +} + + +// IDispatch methods +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::GetTypeInfoCount( UINT *pctinfo ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetTypeInfoCount( UINT *pctinfo )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IDispatch > pIDispatch; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IDispatch, (void**)&pIDispatch ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIDispatch ) + return pIDispatch->GetTypeInfoCount( pctinfo ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::GetTypeInfo( UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetTypeInfo( UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IDispatch > pIDispatch; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IDispatch, (void**)&pIDispatch ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIDispatch ) + return pIDispatch->GetTypeInfo( iTInfo, lcid, ppTInfo ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::GetIDsOfNames( REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetIDsOfNames( REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IDispatch > pIDispatch; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IDispatch, (void**)&pIDispatch ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIDispatch ) + return pIDispatch->GetIDsOfNames( riid, rgszNames, cNames, lcid, rgDispId ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::Invoke( DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Invoke( DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr )\n" ); + if ( CheckDefHandler() ) + { + ComSmart< IDispatch > pIDispatch; + HRESULT hr = m_pDefHandler->QueryInterface( IID_IDispatch, (void**)&pIDispatch ); + + ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIDispatch ) + return pIDispatch->Invoke( dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr ); + } + + return E_FAIL; +} + + +// ==== +// InternalCacheWrapper +// ==== + +// IUnknown +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::QueryInterface( REFIID riid, void FAR* FAR* ppv ) +{ + return m_rOwnDocument.QueryInterface( riid, ppv ); +} + +//------------------------------------------------------------------------------- +STDMETHODIMP_(ULONG) InprocEmbedDocument_Impl::InternalCacheWrapper::AddRef() +{ + return m_rOwnDocument.AddRef(); +} + +//------------------------------------------------------------------------------- +STDMETHODIMP_(ULONG) InprocEmbedDocument_Impl::InternalCacheWrapper::Release() +{ + return m_rOwnDocument.Release(); +} + +// IOleCache methods +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::Cache( FORMATETC *pformatetc, DWORD advf, DWORD *pdwConnection ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::Cache( FORMATETC *pformatetc, DWORD advf, DWORD *pdwConnection )\n" ); + if ( m_rOwnDocument.CheckDefHandler() ) + { + ComSmart< IOleCache > pIOleCache; + HRESULT hr = m_rOwnDocument.GetDefHandler()->QueryInterface( IID_IOleCache, (void**)&pIOleCache ); + + ULONGGuard aGuard( &m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIOleCache ) + return pIOleCache->Cache( pformatetc, advf, pdwConnection ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::Uncache( DWORD dwConnection ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::Uncache( DWORD dwConnection )\n" ); + if ( m_rOwnDocument.CheckDefHandler() ) + { + ComSmart< IOleCache > pIOleCache; + HRESULT hr = m_rOwnDocument.GetDefHandler()->QueryInterface( IID_IOleCache, (void**)&pIOleCache ); + + ULONGGuard aGuard( &m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIOleCache ) + return pIOleCache->Uncache( dwConnection ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::EnumCache( IEnumSTATDATA **ppenumSTATDATA ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::EnumCache( IEnumSTATDATA **ppenumSTATDATA )\n" ); + if ( m_rOwnDocument.CheckDefHandler() ) + { + ComSmart< IOleCache > pIOleCache; + HRESULT hr = m_rOwnDocument.GetDefHandler()->QueryInterface( IID_IOleCache, (void**)&pIOleCache ); + + ULONGGuard aGuard( &m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIOleCache ) + return pIOleCache->EnumCache( ppenumSTATDATA ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::InitCache( IDataObject *pDataObject ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::InitCache( IDataObject *pDataObject )\n" ); + if ( m_rOwnDocument.CheckDefHandler() ) + { + ComSmart< IOleCache > pIOleCache; + HRESULT hr = m_rOwnDocument.GetDefHandler()->QueryInterface( IID_IOleCache, (void**)&pIOleCache ); + + ULONGGuard aGuard( &m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIOleCache ) + return pIOleCache->InitCache( pDataObject ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::SetData( FORMATETC *pformatetc, STGMEDIUM *pmedium, BOOL fRelease ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::SetData( FORMATETC *pformatetc, STGMEDIUM *pmedium, BOOL fRelease )\n" ); + if ( m_rOwnDocument.CheckDefHandler() ) + { + ComSmart< IOleCache > pIOleCache; + HRESULT hr = m_rOwnDocument.GetDefHandler()->QueryInterface( IID_IOleCache, (void**)&pIOleCache ); + + ULONGGuard aGuard( &m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIOleCache ) + return pIOleCache->SetData( pformatetc, pmedium, fRelease ); + } + + return E_FAIL; +} + +// IOleCache2 methods +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::UpdateCache( LPDATAOBJECT pDataObject, DWORD grfUpdf, LPVOID pReserved ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::UpdateCache( LPDATAOBJECT pDataObject, DWORD grfUpdf, LPVOID pReserved )\n" ); + if ( m_rOwnDocument.CheckDefHandler() ) + { + ComSmart< IOleCache2 > pIOleCache2; + HRESULT hr = m_rOwnDocument.GetDefHandler()->QueryInterface( IID_IOleCache2, (void**)&pIOleCache2 ); + + ULONGGuard aGuard( &m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIOleCache2 ) + return pIOleCache2->UpdateCache( pDataObject, grfUpdf, pReserved ); + } + + return E_FAIL; +} + +//------------------------------------------------------------------------------- +STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::DiscardCache( DWORD dwDiscardOptions ) +{ + WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::DiscardCache( DWORD dwDiscardOptions )\n" ); + if ( m_rOwnDocument.CheckDefHandler() ) + { + ComSmart< IOleCache2 > pIOleCache2; + HRESULT hr = m_rOwnDocument.GetDefHandler()->QueryInterface( IID_IOleCache2, (void**)&pIOleCache2 ); + + ULONGGuard aGuard( &m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem + if ( SUCCEEDED( hr ) && pIOleCache2 ) + return pIOleCache2->DiscardCache( dwDiscardOptions ); + } + + return E_FAIL; +} + +}; // namespace inprocserv + diff --git a/embedserv/source/inprocserv/inprocembobj.h b/embedserv/source/inprocserv/inprocembobj.h new file mode 100644 index 000000000..f4f6fc248 --- /dev/null +++ b/embedserv/source/inprocserv/inprocembobj.h @@ -0,0 +1,249 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: inprocembobj.h,v $ + * + * $Revision: 1.1.8.2 $ + * + * last change: $Author: mav $ $Date: 2008/10/30 11:59:06 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef _INPROCEMBOBJ_HXX_ +#define _INPROCEMBOBJ_HXX_ + +#pragma warning(disable : 4668) + +#include <windows.h> +#include <oleidl.h> + +#include "smartpointer.hxx" +#include "advisesink.hxx" + +#define DEFAULT_ARRAY_LEN 256 + +namespace inprocserv { + +enum InitModes { + NOINIT, + INIT_FROM_STORAGE, + LOAD_FROM_STORAGE, + LOAD_FROM_FILE +}; + +// ================================== +// this is a common baseclass that is used to count the objects +// ================================== +class InprocCountedObject_Impl +{ +public: + InprocCountedObject_Impl(); + ~InprocCountedObject_Impl(); +}; + +// ================================== +// this is the inprocess embedded object implementation class +// ================================== +class InprocEmbedDocument_Impl : public InprocCountedObject_Impl + , public IOleObject + , public IDataObject + , public IPersistStorage + , public IPersistFile + , public IRunnableObject + , public IViewObject2 + // , public IExternalConnection + , public IOleInPlaceObject + , public IDispatch +{ + ULONG m_refCount; + BOOLEAN m_bDeleted; + + GUID m_guid; + + ComSmart< IUnknown > m_pDefHandler; + InitModes m_nInitMode; + + DWORD m_nFileOpenMode; + wchar_t* m_pFileName; + + ComSmart< IStorage > m_pStorage; + + ComSmart< IOleClientSite > m_pClientSite; + + ULONG m_nCallsOnStack; + + // the listeners have wrappers that are directly connected to the object and call the listeners, + // the wrappers will be reconnected correctly to the new default inprocess holder object + ComSmart< OleWrapperAdviseSink > m_pOleAdvises[DEFAULT_ARRAY_LEN]; + ComSmart< OleWrapperAdviseSink > m_pDataAdvises[DEFAULT_ARRAY_LEN]; + ComSmart< OleWrapperAdviseSink > m_pViewAdvise; + + class InternalCacheWrapper : public IOleCache2 + { + InprocEmbedDocument_Impl& m_rOwnDocument; + + public: + InternalCacheWrapper( InprocEmbedDocument_Impl& rOwnDocument ) + : m_rOwnDocument( rOwnDocument ) + {} + + /* IUnknown methods */ + STDMETHOD(QueryInterface)(REFIID riid, LPVOID FAR * ppvObj); + STDMETHOD_(ULONG, AddRef)(); + STDMETHOD_(ULONG, Release)(); + + /* IOleCache2 methods */ + STDMETHOD(Cache)( FORMATETC *pformatetc, DWORD advf, DWORD *pdwConnection); + STDMETHOD(Uncache)( DWORD dwConnection); + STDMETHOD(EnumCache)( IEnumSTATDATA **ppenumSTATDATA); + STDMETHOD(InitCache)( IDataObject *pDataObject); + STDMETHOD(SetData)( FORMATETC *pformatetc, STGMEDIUM *pmedium, BOOL fRelease); + STDMETHOD(UpdateCache)( LPDATAOBJECT pDataObject, DWORD grfUpdf, LPVOID pReserved); + STDMETHOD(DiscardCache)( DWORD dwDiscardOptions); + } m_aInternalCache; + + + DWORD InsertAdviseLinkToList( const ComSmart<OleWrapperAdviseSink>& pOwnAdvise, ComSmart< OleWrapperAdviseSink > pAdvises[] ); + void Clean(); + + +public: + + InprocEmbedDocument_Impl( const GUID& guid ) + : m_refCount( 0 ) + , m_bDeleted( FALSE ) + , m_guid( guid ) + , m_nInitMode( NOINIT ) + , m_nFileOpenMode( 0 ) + , m_pFileName( NULL ) + , m_nCallsOnStack( 0 ) + , m_aInternalCache( *this ) + {} + + virtual ~InprocEmbedDocument_Impl() + {} + + HRESULT Init(); + void SetFileName( LPCOLESTR pszFileName ); + + BOOL CheckDefHandler(); + ComSmart< IUnknown >& GetDefHandler() { return m_pDefHandler; } + + /* IUnknown methods */ + STDMETHOD(QueryInterface)(REFIID riid, LPVOID FAR * ppvObj); + STDMETHOD_(ULONG, AddRef)(); + STDMETHOD_(ULONG, Release)(); + + /* IOleObject methods */ + STDMETHOD(SetClientSite) ( IOleClientSite* pSite ); + STDMETHOD(GetClientSite) ( IOleClientSite** pSite ); + STDMETHOD(SetHostNames) ( LPCOLESTR szContainerApp, LPCOLESTR szContainerObj ); + STDMETHOD(Close) ( DWORD dwSaveOption); + STDMETHOD(SetMoniker) ( DWORD dwWhichMoniker, IMoniker *pmk ); + STDMETHOD(GetMoniker) ( DWORD dwAssign, DWORD dwWhichMoniker, IMoniker **ppmk ); + STDMETHOD(InitFromData) ( IDataObject *pDataObject, BOOL fCreation, DWORD dwReserved ); + STDMETHOD(GetClipboardData) ( DWORD dwReserved, IDataObject **ppDataObject ); + STDMETHOD(DoVerb) ( LONG iVerb, LPMSG lpmsg, IOleClientSite *pActiveSite, LONG lindex, HWND hwndParent, LPCRECT lprcPosRect ); + STDMETHOD(EnumVerbs) ( IEnumOLEVERB **ppEnumOleVerb ); + STDMETHOD(Update) (); + STDMETHOD(IsUpToDate) (); + STDMETHOD(GetUserClassID) ( CLSID *pClsid ); + STDMETHOD(GetUserType) ( DWORD dwFormOfType, LPOLESTR *pszUserType ); + STDMETHOD(SetExtent) ( DWORD dwDrawAspect, SIZEL *psizel ); + STDMETHOD(GetExtent) ( DWORD dwDrawAspect, SIZEL *psizel ); + STDMETHOD(Advise) ( IAdviseSink *pAdvSink, DWORD *pdwConnection ); + STDMETHOD(Unadvise) ( DWORD dwConnection ); + STDMETHOD(EnumAdvise) ( IEnumSTATDATA **ppenumAdvise ); + STDMETHOD(GetMiscStatus) ( DWORD dwAspect, DWORD *pdwStatus ); + STDMETHOD(SetColorScheme) ( LOGPALETTE *pLogpal ); + + /* IDataObject methods */ + STDMETHOD(GetData) ( FORMATETC * pFormatetc, STGMEDIUM * pMedium ); + STDMETHOD(GetDataHere) ( FORMATETC * pFormatetc, STGMEDIUM * pMedium ); + STDMETHOD(QueryGetData) ( FORMATETC * pFormatetc ); + STDMETHOD(GetCanonicalFormatEtc) ( FORMATETC * pFormatetcIn, FORMATETC * pFormatetcOut ); + STDMETHOD(SetData) ( FORMATETC * pFormatetc, STGMEDIUM * pMedium, BOOL fRelease ); + STDMETHOD(EnumFormatEtc) ( DWORD dwDirection, IEnumFORMATETC ** ppFormatetc ); + STDMETHOD(DAdvise) ( FORMATETC * pFormatetc, DWORD advf, IAdviseSink * pAdvSink, DWORD * pdwConnection ); + STDMETHOD(DUnadvise) ( DWORD dwConnection ); + STDMETHOD(EnumDAdvise) ( IEnumSTATDATA ** ppenumAdvise ); + + /* IPersistMethod */ + STDMETHOD(GetClassID)(CLSID *pClassID); + + /* IPersistStorage methods */ + STDMETHOD(IsDirty) (); + STDMETHOD(InitNew) ( IStorage *pStg ); + STDMETHOD(Load) ( IStorage* pStr ); + STDMETHOD(Save) ( IStorage *pStgSave, BOOL fSameAsLoad ); + STDMETHOD(SaveCompleted) ( IStorage *pStgNew ); + STDMETHOD(HandsOffStorage) (void); + + /* IPersistFile methods */ + STDMETHOD(Load) ( LPCOLESTR pszFileName, DWORD dwMode ); + STDMETHOD(Save) ( LPCOLESTR pszFileName, BOOL fRemember ); + STDMETHOD(SaveCompleted) ( LPCOLESTR pszFileName ); + STDMETHOD(GetCurFile) ( LPOLESTR *ppszFileName ); + + /* IRunnableObject methods */ + STDMETHOD(GetRunningClass) ( LPCLSID lpClsid); + STDMETHOD(Run) ( LPBINDCTX pbc); + virtual BOOL STDMETHODCALLTYPE IsRunning( void); + STDMETHOD(LockRunning) ( BOOL fLock, BOOL fLastUnlockCloses ); + STDMETHOD(SetContainedObject) ( BOOL fContained); + + /* IViewObject2 methods */ + STDMETHOD(Draw)( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DVTARGETDEVICE *ptd, HDC hdcTargetDev, HDC hdcDraw, LPCRECTL lprcBounds, LPCRECTL lprcWBounds, BOOL ( STDMETHODCALLTYPE *pfnContinue )( ULONG_PTR dwContinue ), ULONG_PTR dwContinue); + STDMETHOD(GetColorSet)( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet); + STDMETHOD(Freeze)( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DWORD *pdwFreeze); + STDMETHOD(Unfreeze)( DWORD dwFreeze); + STDMETHOD(SetAdvise)( DWORD aspects, DWORD advf, IAdviseSink *pAdvSink); + STDMETHOD(GetAdvise)( DWORD *pAspects, DWORD *pAdvf, IAdviseSink **ppAdvSink); + STDMETHOD(GetExtent)( DWORD dwDrawAspect, LONG lindex, DVTARGETDEVICE *ptd, LPSIZEL lpsizel); + + /* IOleWindow methods */ + STDMETHOD(GetWindow)( HWND *phwnd); + STDMETHOD(ContextSensitiveHelp)( BOOL fEnterMode); + + /* IOleInPlaceObject methods */ + STDMETHOD(InPlaceDeactivate)( void); + STDMETHOD(UIDeactivate)( void); + STDMETHOD(SetObjectRects)( LPCRECT lprcPosRect, LPCRECT lprcClipRect); + STDMETHOD(ReactivateAndUndo)( void); + + /*IDispatch methods*/ + STDMETHOD(GetTypeInfoCount)( UINT *pctinfo); + STDMETHOD(GetTypeInfo)( UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo); + STDMETHOD(GetIDsOfNames)( REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId); + STDMETHOD(Invoke)( DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr); + +}; + +} // namespace inprocserv + +#endif + diff --git a/embedserv/source/inprocserv/makefile.mk b/embedserv/source/inprocserv/makefile.mk new file mode 100644 index 000000000..07ad1b818 --- /dev/null +++ b/embedserv/source/inprocserv/makefile.mk @@ -0,0 +1,77 @@ +#************************************************************************* +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.8.2 $ +# +# last change: $Author: mav $ $Date: 2008/10/30 11:59:06 $ +# +# The Contents of this file are made available subject to +# the terms of GNU Lesser General Public License Version 2.1. +# +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2005 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +#************************************************************************* + +PRJ=..$/.. +PRJNAME=embedserv +TARGET=inprocserv + +use_shl_versions= + +# --- Settings ---------------------------------- +.INCLUDE : settings.mk + +.IF "$(GUI)" == "WNT" + +VERSIONOBJ= +LIBTARGET=NO +USE_DEFFILE=YES + +# --- Files ------------------------------------- + +SLOFILES=\ + $(SLO)$/dllentry.obj \ + $(SLO)$/advisesink.obj \ + $(SLO)$/inprocembobj.obj + +SHL1TARGET=$(TARGET) +SHL1STDLIBS=\ + uuid.lib\ + ole32.lib\ + gdi32.lib\ + advapi32.lib + +SHL1OBJS=$(SLOFILES) + +SHL1DEF=$(MISC)$/$(TARGET).def + +DEF1NAME= $(TARGET) +DEF1EXPORTFILE= exports.dxp + +.ENDIF + +# --- Targets ---------------------------------- + +.INCLUDE : target.mk + diff --git a/embedserv/source/inprocserv/smartpointer.hxx b/embedserv/source/inprocserv/smartpointer.hxx new file mode 100644 index 000000000..c4ecdb8f6 --- /dev/null +++ b/embedserv/source/inprocserv/smartpointer.hxx @@ -0,0 +1,189 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: smartpointer.hxx,v $ + * + * $Revision: 1.1.8.2 $ + * + * last change: $Author: mav $ $Date: 2008/10/30 11:59:06 $ + * + * The Contents of this file are made available subject to + * the terms of GNU Lesser General Public License Version 2.1. + * + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2005 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + ************************************************************************/ + +#ifndef _INPROCSERV_SMARTPOINTER_HXX_ +#define _INPROCSERV_SMARTPOINTER_HXX_ + +namespace inprocserv{ + +template< class T > class ComSmart +{ + T* m_pInterface; + + void OwnRelease() + { + if ( m_pInterface ) + { + T* pInterface = m_pInterface; + m_pInterface = NULL; + pInterface->Release(); + } + } + +public: + ComSmart() + : m_pInterface( NULL ) + {} + + ComSmart( const ComSmart<T>& rObj ) + : m_pInterface( rObj.m_pInterface ) + { + if ( m_pInterface != NULL ) + m_pInterface->AddRef(); + } + + ComSmart( T* pInterface ) + : m_pInterface( pInterface ) + { + if ( m_pInterface != NULL ) + m_pInterface->AddRef(); + } + + ~ComSmart() + { + OwnRelease(); + } + + ComSmart& operator=( const ComSmart<T>& rObj ) + { + OwnRelease(); + + m_pInterface = rObj.m_pInterface; + + if ( m_pInterface != NULL ) + m_pInterface->AddRef(); + + return *this; + } + + ComSmart<T>& operator=( T* pInterface ) + { + OwnRelease(); + + m_pInterface = pInterface; + + if ( m_pInterface != NULL ) + m_pInterface->AddRef(); + + return *this; + } + + operator T*() const + { + return m_pInterface; + } + + T& operator*() const + { + return *m_pInterface; + } + + T** operator&() + { + OwnRelease(); + + m_pInterface = NULL; + + return &m_pInterface; + } + + T* operator->() const + { + return m_pInterface; + } + + BOOL operator==( const ComSmart<T>& rObj ) const + { + return ( m_pInterface == rObj.m_pInterface ); + } + + BOOL operator!=( const ComSmart<T>& rObj ) const + { + return ( m_pInterface != rObj.m_pInterface ); + } + + BOOL operator==( const T* pInterface ) const + { + return ( m_pInterface == pInterface ); + } + + BOOL operator!=( const T* pInterface ) const + { + return ( m_pInterface != pInterface ); + } +}; + +class CSGuard +{ + CRITICAL_SECTION* m_pCriticalSection; + +public: + CSGuard( CRITICAL_SECTION* pCS ) + : m_pCriticalSection( pCS ) + { + if ( m_pCriticalSection ) + EnterCriticalSection( m_pCriticalSection ); + } + + ~CSGuard() + { + if ( m_pCriticalSection ) + LeaveCriticalSection( m_pCriticalSection ); + } +}; + +class ULONGGuard +{ + ULONG* m_pValue; + +public: + ULONGGuard( ULONG* pValue ) + : m_pValue( pValue ) + { + if ( m_pValue ) + (*m_pValue)++; + } + + ~ULONGGuard() + { + if ( m_pValue ) + (*m_pValue)--; + } +}; + +} // namespace inprocserv + +#endif + |