no need to allocate AnnotationData for every SdrObject
[LibreOffice.git] / embedserv / source / inprocserv / inprocembobj.cxx
blobb7bf89b6670af08a7e441db2dfa65904dee20099
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/types.h>
22 #include <embservconst.h>
23 #include "inprocembobj.h"
25 namespace inprocserv
28 namespace {
30 class ULONGGuard
32 ULONG& m_rValue;
34 public:
35 explicit ULONGGuard( ULONG& rValue )
36 : m_rValue( ++rValue )
40 ~ULONGGuard() { --m_rValue; }
43 void SetName( LPCOLESTR pszNameFromOutside, wchar_t*& pOwnName )
45 if ( !pszNameFromOutside )
46 return;
48 // copy the string
49 size_t nLen = 0;
50 while( pszNameFromOutside[nLen] != 0 )
51 nLen++;
53 if ( pOwnName )
55 delete[] pOwnName;
56 pOwnName = nullptr;
59 pOwnName = new wchar_t[nLen+1];
60 for ( size_t nInd = 0; nInd < nLen; nInd++ )
61 pOwnName[nInd] = pszNameFromOutside[nInd];
62 pOwnName[nLen] = 0;
65 DWORD InsertAdviseLinkToList( const sal::systools::COMReference<OleWrapperAdviseSink>& pOwnAdvise, sal::systools::COMReference< OleWrapperAdviseSink > pAdvises[] )
67 // the result should start from 1 in case of success, the element 0 can be used for own needs
68 DWORD nResult = 0;
70 if ( pOwnAdvise )
72 for ( DWORD nInd = 1; nInd < DEFAULT_ARRAY_LEN && nResult == 0; nInd++ )
74 if ( pAdvises[nInd].get() == pOwnAdvise.get() )
76 nResult = nInd;
78 else if ( pAdvises[nInd] == nullptr )
80 pAdvises[nInd] = pOwnAdvise;
81 nResult = nInd;
86 return nResult;
91 BOOL InprocEmbedDocument_Impl::CheckDefHandler()
93 // set the own listener
94 if ( m_pOleAdvises[0] == nullptr )
96 m_pOleAdvises[0] = new OleWrapperAdviseSink();
98 else
100 if ( m_pOleAdvises[0]->IsClosed() )
102 if ( m_pDefHandler )
104 // deregister all the listeners
106 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
107 if ( pOleObject )
109 for ( DWORD nInd = 0; nInd < DEFAULT_ARRAY_LEN; nInd++ )
110 if ( m_pOleAdvises[nInd] )
112 DWORD nID = m_pOleAdvises[nInd]->GetRegID();
113 pOleObject->Unadvise( nID );
114 m_pOleAdvises[nInd]->SetRegID( 0 );
117 pOleObject->SetClientSite( nullptr );
120 sal::systools::COMReference< IDataObject > pIDataObject(m_pDefHandler, sal::systools::COM_QUERY);
121 if ( pIDataObject )
123 for ( DWORD nInd = 0; nInd < DEFAULT_ARRAY_LEN; nInd++ )
124 if ( m_pDataAdvises[nInd] )
126 DWORD nID = m_pDataAdvises[nInd]->GetRegID();
127 pIDataObject->DUnadvise( nID );
128 m_pDataAdvises[nInd]->SetRegID( 0 );
132 sal::systools::COMReference< IViewObject > pIViewObject(m_pDefHandler, sal::systools::COM_QUERY);
133 if ( pIViewObject )
135 if ( m_pViewAdvise )
136 pIViewObject->SetAdvise( m_pViewAdvise->GetAspect(), m_pViewAdvise->GetViewAdviseFlag(), nullptr );
139 sal::systools::COMReference< IPersistStorage > pPersist(m_pDefHandler, sal::systools::COM_QUERY);
140 if ( pPersist )
142 // disconnect the old wrapper from the storage
143 pPersist->HandsOffStorage();
146 m_pDefHandler = nullptr;
149 m_pOleAdvises[0]->UnsetClosed();
153 if ( m_nCallsOnStack )
154 return FALSE;
156 if ( !m_pDefHandler )
158 // create a new default inprocess handler
159 HRESULT hr = OleCreateDefaultHandler( m_guid, nullptr, IID_IUnknown, reinterpret_cast<void**>(&m_pDefHandler) );
160 if ( SUCCEEDED( hr ) )
162 if ( m_nInitMode == INIT_FROM_STORAGE )
164 sal::systools::COMReference< IPersistStorage > pPersist(m_pDefHandler, sal::systools::COM_QUERY);
166 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
167 if ( pPersist && m_pStorage )
168 hr = pPersist->InitNew( m_pStorage.get() );
170 else if ( m_nInitMode == LOAD_FROM_STORAGE )
172 sal::systools::COMReference< IPersistStorage > pPersist(m_pDefHandler, sal::systools::COM_QUERY);
174 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
175 if ( pPersist && m_pStorage )
176 hr = pPersist->Load( m_pStorage.get() );
178 else if ( m_nInitMode == LOAD_FROM_FILE )
180 sal::systools::COMReference< IPersistFile > pPersistFile(m_pDefHandler, sal::systools::COM_QUERY);
182 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
183 if ( pPersistFile && m_pFileName )
184 hr = pPersistFile->Load( m_pFileName, m_nFileOpenMode );
188 if ( !SUCCEEDED( hr ) || !m_pDefHandler )
190 m_pDefHandler = nullptr;
191 return FALSE;
194 // register all the listeners new
196 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
197 if ( pOleObject )
199 if ( m_pClientSite )
200 pOleObject->SetClientSite( m_pClientSite.get() );
202 for ( DWORD nInd = 0; nInd < DEFAULT_ARRAY_LEN; nInd++ )
203 if ( m_pOleAdvises[nInd] )
205 DWORD nRegID = 0;
206 if ( SUCCEEDED( pOleObject->Advise( m_pOleAdvises[nInd].get(), &nRegID ) ) && nRegID > 0 )
207 m_pOleAdvises[nInd]->SetRegID( nRegID );
211 sal::systools::COMReference< IDataObject > pIDataObject(m_pDefHandler, sal::systools::COM_QUERY);
212 if ( pIDataObject )
214 for ( DWORD nInd = 0; nInd < DEFAULT_ARRAY_LEN; nInd++ )
215 if ( m_pDataAdvises[nInd] )
217 DWORD nRegID = 0;
218 if ( SUCCEEDED( pIDataObject->DAdvise( m_pDataAdvises[nInd]->GetFormatEtc(), m_pDataAdvises[nInd]->GetDataAdviseFlag(), m_pDataAdvises[nInd].get(), &nRegID ) ) && nRegID > 0 )
219 m_pDataAdvises[nInd]->SetRegID( nRegID );
223 sal::systools::COMReference< IViewObject > pIViewObject(m_pDefHandler, sal::systools::COM_QUERY);
224 if ( pIViewObject )
226 if ( m_pViewAdvise )
227 pIViewObject->SetAdvise( m_pViewAdvise->GetAspect(), m_pViewAdvise->GetViewAdviseFlag(), m_pViewAdvise.get() );
232 return TRUE;
235 void InprocEmbedDocument_Impl::Clean()
237 m_pDefHandler = nullptr;
239 // no DisconnectOrigAdvise() call here, since it is no explicit disconnection
240 for ( DWORD nInd = 0; nInd < DEFAULT_ARRAY_LEN; nInd++ )
242 m_pOleAdvises[nInd].clear();
243 m_pDataAdvises[nInd].clear();
246 m_pViewAdvise = nullptr;
248 m_nInitMode = NOINIT;
249 m_pStorage = nullptr;
251 if ( m_pOleContainer )
253 m_pOleContainer->LockContainer( FALSE );
254 m_pOleContainer = nullptr;
257 m_pClientSite = nullptr;
259 m_nFileOpenMode = 0;
260 if ( m_pFileName )
262 delete m_pFileName;
263 m_pFileName = nullptr;
267 // IUnknown
269 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::QueryInterface(REFIID riid, void** ppv)
271 if(IsEqualIID(riid, IID_IUnknown))
273 AddRef();
274 *ppv = static_cast<IUnknown*>(static_cast<IPersistStorage*>(this));
275 return S_OK;
277 else if (IsEqualIID(riid, IID_IPersist))
279 AddRef();
280 *ppv = static_cast<IPersist*>(static_cast<IPersistStorage*>(this));
281 return S_OK;
283 else if (IsEqualIID(riid, IID_IPersistStorage))
285 AddRef();
286 *ppv = static_cast<IPersistStorage*>(this);
287 return S_OK;
289 else if (IsEqualIID(riid, IID_IDataObject))
291 AddRef();
292 *ppv = static_cast<IDataObject*>(this);
293 return S_OK;
295 else if (IsEqualIID(riid, IID_IOleObject))
297 AddRef();
298 *ppv = static_cast<IOleObject*>(this);
299 return S_OK;
301 else if (IsEqualIID(riid, IID_IPersistFile))
303 AddRef();
304 *ppv = static_cast<IPersistFile*>(this);
305 return S_OK;
307 else if (IsEqualIID(riid, IID_IRunnableObject))
309 AddRef();
310 *ppv = static_cast<IRunnableObject*>(this);
311 return S_OK;
313 else if (IsEqualIID(riid, IID_IViewObject))
315 AddRef();
316 *ppv = static_cast<IViewObject*>(this);
317 return S_OK;
319 else if (IsEqualIID(riid, IID_IViewObject2))
321 AddRef();
322 *ppv = static_cast<IViewObject2*>(this);
323 return S_OK;
325 else if (IsEqualIID(riid, IID_IOleCache))
327 AddRef();
328 *ppv = static_cast<IOleCache*>(&m_aInternalCache);
329 return S_OK;
331 else if (IsEqualIID(riid, IID_IOleCache2))
333 AddRef();
334 *ppv = static_cast<IOleCache2*>(&m_aInternalCache);
335 return S_OK;
337 else if (IsEqualIID(riid, IID_IOleWindow))
339 AddRef();
340 *ppv = static_cast<IOleWindow*>(this);
341 return S_OK;
343 else if (IsEqualIID(riid, IID_IOleInPlaceObject))
345 AddRef();
346 *ppv = static_cast<IOleInPlaceObject*>(this);
347 return S_OK;
349 else if (IsEqualIID(riid, IID_IDispatch))
351 AddRef();
352 *ppv = static_cast<IDispatch*>(this);
353 return S_OK;
356 *ppv = nullptr;
357 return ResultFromScode(E_NOINTERFACE);
361 COM_DECLSPEC_NOTHROW STDMETHODIMP_(ULONG) InprocEmbedDocument_Impl::AddRef()
363 return ++m_refCount;
367 COM_DECLSPEC_NOTHROW STDMETHODIMP_(ULONG) InprocEmbedDocument_Impl::Release()
369 // unfortunately there are reentrance problems in mfc that have to be workarounded
370 sal_Int32 nCount = m_refCount > 0 ? --m_refCount : 0;
371 if ( nCount == 0 && !m_bDeleted )
373 // deleting of this object can trigger deleting of mfc objects that will try to delete this object one more time
374 m_bDeleted = TRUE;
376 Clean();
377 delete this;
379 return nCount;
382 // IPersist
384 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetClassID( CLSID* pClassId )
386 *pClassId = m_guid;
387 return S_OK;
390 // IPersistStorage
392 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::IsDirty()
394 if ( m_pDefHandler == nullptr || m_pOleAdvises[0] == nullptr || m_pOleAdvises[0]->IsClosed() )
395 return S_FALSE;
397 if ( CheckDefHandler() )
399 sal::systools::COMReference< IPersistStorage > pPersist(m_pDefHandler, sal::systools::COM_QUERY);
401 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
402 if ( pPersist )
403 return pPersist->IsDirty();
406 return E_FAIL;
410 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::InitNew( IStorage *pStg )
412 if ( CheckDefHandler() )
414 sal::systools::COMReference< IPersistStorage > pPersist(m_pDefHandler, sal::systools::COM_QUERY);
416 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
417 if ( pPersist )
419 HRESULT hr = pPersist->InitNew( pStg );
420 if ( SUCCEEDED( hr ) )
422 m_nInitMode = INIT_FROM_STORAGE;
423 m_pStorage = pStg;
425 m_nFileOpenMode = 0;
426 if ( m_pFileName )
428 delete[] m_pFileName;
429 m_pFileName = nullptr;
433 return hr;
437 return E_FAIL;
441 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::Load( IStorage *pStg )
443 if ( CheckDefHandler() )
445 sal::systools::COMReference< IPersistStorage > pPersist(m_pDefHandler, sal::systools::COM_QUERY);
447 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
448 if ( pPersist )
450 HRESULT hr = pPersist->Load( pStg );
451 if ( SUCCEEDED( hr ) )
453 m_nInitMode = LOAD_FROM_STORAGE;
454 m_pStorage = pStg;
456 m_nFileOpenMode = 0;
457 if ( m_pFileName )
459 delete[] m_pFileName;
460 m_pFileName = nullptr;
464 return hr;
468 return E_FAIL;
472 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::Save( IStorage *pStgSave, BOOL fSameAsLoad )
474 if ( fSameAsLoad && ( m_pDefHandler == nullptr || m_pOleAdvises[0] == nullptr || m_pOleAdvises[0]->IsClosed() ) )
475 return S_OK;
477 if ( CheckDefHandler() )
479 sal::systools::COMReference< IPersistStorage > pPersist(m_pDefHandler, sal::systools::COM_QUERY);
481 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
482 if ( pPersist )
483 return pPersist->Save( pStgSave, fSameAsLoad );
486 return E_FAIL;
490 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::SaveCompleted( IStorage *pStgNew )
492 if ( m_pDefHandler == nullptr || m_pOleAdvises[0] == nullptr || m_pOleAdvises[0]->IsClosed() )
494 if ( pStgNew )
495 m_pStorage = pStgNew;
497 return S_OK;
500 if ( CheckDefHandler() )
502 sal::systools::COMReference< IPersistStorage > pPersist(m_pDefHandler, sal::systools::COM_QUERY);
504 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
505 if ( pPersist )
507 HRESULT hr = pPersist->SaveCompleted( pStgNew );
508 if ( SUCCEEDED( hr ) )
510 m_nInitMode = LOAD_FROM_STORAGE;
511 if ( pStgNew )
513 m_pStorage = pStgNew;
516 m_nFileOpenMode = 0;
517 if ( m_pFileName )
519 delete[] m_pFileName;
520 m_pFileName = nullptr;
524 return hr;
528 return E_FAIL;
532 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::HandsOffStorage()
534 if ( CheckDefHandler() )
536 sal::systools::COMReference< IPersistStorage > pPersist(m_pDefHandler, sal::systools::COM_QUERY);
538 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
539 if ( pPersist )
541 HRESULT hr = pPersist->HandsOffStorage();
542 if ( SUCCEEDED( hr ) )
544 m_pStorage = nullptr;
547 return hr;
551 return E_FAIL;
554 // IPersistFile
556 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::Load( LPCOLESTR pszFileName, DWORD dwMode )
558 if ( CheckDefHandler() && pszFileName )
560 sal::systools::COMReference< IPersistFile > pPersist(m_pDefHandler, sal::systools::COM_QUERY);
562 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
563 if ( pPersist )
565 HRESULT hr = pPersist->Load( pszFileName, dwMode );
566 if ( SUCCEEDED( hr ) )
568 m_nInitMode = LOAD_FROM_FILE;
569 if ( m_pStorage )
570 m_pStorage = nullptr;
572 m_nFileOpenMode = dwMode;
573 // copy the string
574 SetName( pszFileName, m_pFileName );
577 return hr;
581 return E_FAIL;
585 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::Save( LPCOLESTR pszFileName, BOOL fRemember )
587 if ( CheckDefHandler() )
589 sal::systools::COMReference< IPersistFile > pPersist(m_pDefHandler, sal::systools::COM_QUERY);
591 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
592 if ( pPersist )
593 return pPersist->Save( pszFileName, fRemember );
596 return E_FAIL;
600 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::SaveCompleted( LPCOLESTR pszFileName )
602 if ( CheckDefHandler() )
604 sal::systools::COMReference< IPersistFile > pPersist(m_pDefHandler, sal::systools::COM_QUERY);
606 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
607 if ( pPersist )
609 HRESULT hr = pPersist->SaveCompleted( pszFileName );
610 if ( SUCCEEDED( hr ) )
612 m_nInitMode = LOAD_FROM_STORAGE;
613 if ( m_pStorage )
614 m_pStorage = nullptr;
616 m_nFileOpenMode = STGM_READWRITE; // was just written
617 // copy the string
618 SetName( pszFileName, m_pFileName );
624 return E_FAIL;
628 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetCurFile( LPOLESTR *ppszFileName )
630 if ( CheckDefHandler() )
632 sal::systools::COMReference< IPersistFile > pPersist(m_pDefHandler, sal::systools::COM_QUERY);
634 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
635 if ( pPersist )
636 return pPersist->GetCurFile( ppszFileName );
639 return E_FAIL;
642 // IOleObject
644 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::SetClientSite( IOleClientSite* pSite )
646 if ( pSite == m_pClientSite.get() )
647 return S_OK;
649 if ( !pSite )
651 m_pClientSite = nullptr;
652 if ( m_pOleContainer )
654 m_pOleContainer->LockContainer( FALSE );
655 m_pOleContainer = nullptr;
659 if ( CheckDefHandler() )
661 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
663 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
664 if ( pOleObject )
666 HRESULT hr2 = pOleObject->SetClientSite( pSite );
667 if ( SUCCEEDED( hr2 ) )
669 m_pClientSite = pSite;
671 if ( m_pOleContainer )
673 m_pOleContainer->LockContainer( FALSE );
674 m_pOleContainer = nullptr;
677 m_pClientSite->GetContainer( &m_pOleContainer );
678 if ( m_pOleContainer )
679 m_pOleContainer->LockContainer( TRUE );
682 return hr2;
686 return E_FAIL;
690 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetClientSite( IOleClientSite** pSite )
692 if ( CheckDefHandler() )
694 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
696 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
697 if ( pOleObject )
698 return pOleObject->GetClientSite( pSite );
701 return E_FAIL;
705 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::SetHostNames( LPCOLESTR szContainerApp, LPCOLESTR szContainerObj )
708 if ( CheckDefHandler() )
710 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
712 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
713 if ( pOleObject )
715 pOleObject->SetHostNames( szContainerApp, szContainerObj );
719 return S_OK;
723 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::Close( DWORD dwSaveOption )
725 HRESULT ret = S_OK;
726 if ( m_pDefHandler && CheckDefHandler() )
728 // no need to close if there is no default handler.
729 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
731 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
732 if ( pOleObject )
734 HRESULT hr = pOleObject->Close( dwSaveOption );
735 if (!SUCCEEDED(hr))
736 ret = hr;
737 hr = CoDisconnectObject( static_cast<IUnknown*>(static_cast<IPersistStorage*>(this)), 0 );
738 if (!SUCCEEDED(hr) && SUCCEEDED(ret))
739 ret = hr;
743 // if the object is closed from outside that means that it should go to uninitialized state
744 Clean();
746 return ret;
750 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::SetMoniker( DWORD dwWhichMoniker, IMoniker * pmk )
752 if ( CheckDefHandler() )
754 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
756 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
757 if ( pOleObject )
758 return pOleObject->SetMoniker( dwWhichMoniker, pmk );
761 return E_FAIL;
765 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetMoniker( DWORD dwAssign, DWORD dwWhichMoniker, IMoniker ** ppmk )
767 if ( CheckDefHandler() )
769 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
771 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
772 if ( pOleObject )
773 return pOleObject->GetMoniker( dwAssign, dwWhichMoniker, ppmk );
776 return E_FAIL;
780 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::InitFromData( IDataObject * pDataObject, BOOL fCreation, DWORD dwReserved )
782 if ( CheckDefHandler() )
784 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
786 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
787 if ( pOleObject )
788 return pOleObject->InitFromData( pDataObject, fCreation, dwReserved );
791 return E_FAIL;
795 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetClipboardData( DWORD dwReserved, IDataObject ** ppDataObject )
797 if ( CheckDefHandler() )
799 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
801 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
802 if ( pOleObject )
803 return pOleObject->GetClipboardData( dwReserved, ppDataObject );
806 return E_FAIL;
810 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::DoVerb(
811 LONG iVerb,
812 LPMSG pMsg,
813 IOleClientSite *pActiveSite,
814 LONG nLong,
815 HWND hWin,
816 LPCRECT pRect )
818 if ( CheckDefHandler() )
820 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
822 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
823 if ( pOleObject )
825 return pOleObject->DoVerb( iVerb, pMsg, pActiveSite, nLong, hWin, pRect );
830 return E_FAIL;
834 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::EnumVerbs( IEnumOLEVERB ** ppEnumOleVerb )
836 if ( CheckDefHandler() )
838 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
840 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
841 if ( pOleObject )
842 return pOleObject->EnumVerbs( ppEnumOleVerb );
845 return E_FAIL;
849 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::Update()
852 if ( m_pDefHandler && CheckDefHandler() )
854 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
856 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
857 if ( pOleObject )
858 return pOleObject->Update();
861 return S_OK;
865 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::IsUpToDate()
867 if ( CheckDefHandler() )
869 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
871 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
872 if ( pOleObject )
873 return pOleObject->IsUpToDate();
876 return E_FAIL;
880 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetUserClassID( CLSID *pClsid )
882 if ( pClsid )
883 *pClsid = m_guid;
885 return S_OK;
889 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetUserType( DWORD dwFormOfType, LPOLESTR * pszUserType )
891 if ( CheckDefHandler() )
893 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
895 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
896 if ( pOleObject )
897 return pOleObject->GetUserType( dwFormOfType, pszUserType );
900 return E_FAIL;
904 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::SetExtent( DWORD dwDrawAspect, SIZEL *psizel )
906 if ( CheckDefHandler() )
908 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
910 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
911 if ( pOleObject )
912 return pOleObject->SetExtent( dwDrawAspect, psizel );
915 return E_FAIL;
919 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetExtent( DWORD dwDrawAspect, SIZEL * psizel )
921 if ( CheckDefHandler() )
923 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
925 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
926 if ( pOleObject )
927 return pOleObject->GetExtent( dwDrawAspect, psizel );
930 return E_FAIL;
934 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::Advise( IAdviseSink *pAdvSink, DWORD *pdwConnection )
937 if ( !pdwConnection )
938 return E_FAIL;
940 // CheckDefHandler will set the listener, avoid reusing of old listener
941 if ( DEFAULT_ARRAY_LEN > *pdwConnection && *pdwConnection > 0 && m_pOleAdvises[*pdwConnection] )
943 m_pOleAdvises[*pdwConnection]->DisconnectOrigAdvise();
944 m_pOleAdvises[*pdwConnection] = nullptr;
947 if ( pAdvSink && CheckDefHandler() )
949 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
951 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
952 if ( pOleObject )
954 sal::systools::COMReference pOwnAdvise(new OleWrapperAdviseSink(pAdvSink));
955 DWORD nRegID = 0;
957 if ( SUCCEEDED( pOleObject->Advise( pOwnAdvise.get(), &nRegID ) ) && nRegID > 0 )
959 pOwnAdvise->SetRegID( nRegID );
960 *pdwConnection = InsertAdviseLinkToList( pOwnAdvise, m_pOleAdvises );
961 if ( *pdwConnection )
962 return S_OK;
963 else
964 pOleObject->Unadvise( nRegID );
969 // return success always for now
970 return S_OK;
974 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::Unadvise( DWORD dwConnection )
976 if ( DEFAULT_ARRAY_LEN > dwConnection && dwConnection > 0 && m_pOleAdvises[dwConnection] )
978 if ( m_pDefHandler )
980 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
982 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
983 if ( pOleObject )
985 DWORD nID = m_pOleAdvises[dwConnection]->GetRegID();
986 pOleObject->Unadvise( nID );
990 m_pOleAdvises[dwConnection]->DisconnectOrigAdvise();
991 m_pOleAdvises[dwConnection] = nullptr;
993 return S_OK;
996 return E_FAIL;
1000 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::EnumAdvise( IEnumSTATDATA ** /*ppenumAdvise*/ )
1002 return E_NOTIMPL;
1006 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetMiscStatus( DWORD dwAspect, DWORD * pdwStatus )
1008 if ( CheckDefHandler() )
1010 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
1012 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1013 if ( pOleObject )
1014 return pOleObject->GetMiscStatus( dwAspect, pdwStatus );
1017 return E_FAIL;
1021 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::SetColorScheme( LOGPALETTE * pLogpal )
1023 if ( CheckDefHandler() )
1025 sal::systools::COMReference< IOleObject > pOleObject(m_pDefHandler, sal::systools::COM_QUERY);
1027 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1028 if ( pOleObject )
1029 return pOleObject->SetColorScheme( pLogpal );
1032 return E_FAIL;
1035 //IDataObject
1037 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetData( FORMATETC * pFormatetc, STGMEDIUM * pMedium )
1039 if ( CheckDefHandler() )
1041 sal::systools::COMReference< IDataObject > pIDataObject(m_pDefHandler, sal::systools::COM_QUERY);
1043 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1044 if ( pIDataObject )
1045 return pIDataObject->GetData( pFormatetc, pMedium );
1048 return E_FAIL;
1052 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetDataHere( FORMATETC * pFormatetc, STGMEDIUM * pMedium )
1054 if ( CheckDefHandler() )
1056 sal::systools::COMReference< IDataObject > pIDataObject(m_pDefHandler, sal::systools::COM_QUERY);
1058 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1059 if ( pIDataObject )
1060 return pIDataObject->GetDataHere( pFormatetc, pMedium );
1063 return E_FAIL;
1067 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::QueryGetData( FORMATETC * pFormatetc )
1069 if ( CheckDefHandler() )
1071 sal::systools::COMReference< IDataObject > pIDataObject(m_pDefHandler, sal::systools::COM_QUERY);
1073 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1074 if ( pIDataObject )
1075 return pIDataObject->QueryGetData( pFormatetc );
1078 return E_FAIL;
1082 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetCanonicalFormatEtc( FORMATETC * pFormatetcIn, FORMATETC * pFormatetcOut )
1084 if ( CheckDefHandler() )
1086 sal::systools::COMReference< IDataObject > pIDataObject(m_pDefHandler, sal::systools::COM_QUERY);
1088 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1089 if ( pIDataObject )
1090 return pIDataObject->GetCanonicalFormatEtc( pFormatetcIn, pFormatetcOut );
1093 return E_FAIL;
1097 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::SetData( FORMATETC * pFormatetc, STGMEDIUM * pMedium, BOOL fRelease )
1099 if ( CheckDefHandler() )
1101 sal::systools::COMReference< IDataObject > pIDataObject(m_pDefHandler, sal::systools::COM_QUERY);
1103 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1104 if ( pIDataObject )
1105 return pIDataObject->SetData( pFormatetc, pMedium, fRelease );
1108 return E_FAIL;
1112 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::EnumFormatEtc( DWORD dwDirection, IEnumFORMATETC ** ppFormatetc )
1114 if ( CheckDefHandler() )
1116 sal::systools::COMReference< IDataObject > pIDataObject(m_pDefHandler, sal::systools::COM_QUERY);
1118 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1119 if ( pIDataObject )
1120 return pIDataObject->EnumFormatEtc( dwDirection, ppFormatetc );
1123 return E_FAIL;
1127 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::DAdvise( FORMATETC * pFormatetc, DWORD advf, IAdviseSink * pAdvSink, DWORD * pdwConnection )
1130 if ( !pdwConnection )
1131 return E_FAIL;
1133 // avoid reusing of the old listener
1134 if ( m_pDefHandler && DEFAULT_ARRAY_LEN > *pdwConnection && *pdwConnection > 0 && m_pDataAdvises[*pdwConnection] )
1136 m_pDataAdvises[*pdwConnection]->DisconnectOrigAdvise();
1137 m_pDataAdvises[*pdwConnection] = nullptr;
1140 if ( pAdvSink && CheckDefHandler() )
1142 sal::systools::COMReference< IDataObject > pIDataObject(m_pDefHandler, sal::systools::COM_QUERY);
1144 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1145 if ( pIDataObject )
1147 sal::systools::COMReference pOwnAdvise( new OleWrapperAdviseSink( pAdvSink, pFormatetc, advf ) );
1148 DWORD nRegID = 0;
1150 if ( SUCCEEDED( pIDataObject->DAdvise( pFormatetc, advf, pOwnAdvise.get(), &nRegID ) ) && nRegID > 0 )
1152 pOwnAdvise->SetRegID( nRegID );
1153 *pdwConnection = InsertAdviseLinkToList( pOwnAdvise, m_pDataAdvises );
1154 if ( *pdwConnection )
1155 return S_OK;
1156 else
1157 pIDataObject->DUnadvise( nRegID );
1162 // return success always for now
1163 return S_OK;
1167 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::DUnadvise( DWORD dwConnection )
1169 if ( m_pDefHandler && DEFAULT_ARRAY_LEN > dwConnection && dwConnection > 0 && m_pDataAdvises[dwConnection] )
1171 if ( CheckDefHandler() )
1173 sal::systools::COMReference< IDataObject > pIDataObject(m_pDefHandler, sal::systools::COM_QUERY);
1175 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1176 if ( pIDataObject )
1178 DWORD nID = m_pDataAdvises[dwConnection]->GetRegID();
1179 pIDataObject->DUnadvise( nID );
1183 m_pDataAdvises[dwConnection]->DisconnectOrigAdvise();
1184 m_pDataAdvises[dwConnection] = nullptr;
1186 return S_OK;
1189 return E_FAIL;
1193 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::EnumDAdvise( IEnumSTATDATA ** ppenumAdvise )
1195 if ( CheckDefHandler() )
1197 sal::systools::COMReference< IDataObject > pIDataObject(m_pDefHandler, sal::systools::COM_QUERY);
1199 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1200 if ( pIDataObject )
1201 return pIDataObject->EnumDAdvise( ppenumAdvise );
1204 return E_FAIL;
1207 // IRunnableObject
1209 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetRunningClass( LPCLSID lpClsid )
1211 if ( CheckDefHandler() )
1213 sal::systools::COMReference< IRunnableObject > pIRunObj(m_pDefHandler, sal::systools::COM_QUERY);
1215 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1216 if ( pIRunObj )
1217 return pIRunObj->GetRunningClass( lpClsid );
1220 return E_FAIL;
1224 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::Run( LPBINDCTX pbc )
1226 if ( CheckDefHandler() )
1228 sal::systools::COMReference< IRunnableObject > pIRunObj(m_pDefHandler, sal::systools::COM_QUERY);
1230 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1231 if ( pIRunObj )
1232 return pIRunObj->Run( pbc );
1235 return E_FAIL;
1238 BOOL STDMETHODCALLTYPE InprocEmbedDocument_Impl::IsRunning()
1240 if (CheckDefHandler())
1242 sal::systools::COMReference< IRunnableObject > pIRunObj(m_pDefHandler, sal::systools::COM_QUERY);
1244 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1245 if ( pIRunObj )
1246 return pIRunObj->IsRunning();
1249 return FALSE;
1252 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::LockRunning( BOOL fLock, BOOL fLastUnlockCloses )
1254 if ( CheckDefHandler() )
1256 sal::systools::COMReference< IRunnableObject > pIRunObj(m_pDefHandler, sal::systools::COM_QUERY);
1258 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1259 if ( pIRunObj )
1260 return pIRunObj->LockRunning( fLock, fLastUnlockCloses );
1263 return E_FAIL;
1267 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::SetContainedObject( BOOL fContained)
1269 if ( CheckDefHandler() )
1271 sal::systools::COMReference< IRunnableObject > pIRunObj(m_pDefHandler, sal::systools::COM_QUERY);
1273 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1274 if ( pIRunObj )
1275 return pIRunObj->SetContainedObject( fContained );
1278 return E_FAIL;
1282 // IViewObject methods
1284 COM_DECLSPEC_NOTHROW 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 )
1286 if ( CheckDefHandler() )
1288 sal::systools::COMReference< IViewObject > pIViewObject(m_pDefHandler, sal::systools::COM_QUERY);
1290 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1291 if ( pIViewObject )
1292 return pIViewObject->Draw( dwDrawAspect, lindex, pvAspect, ptd, hdcTargetDev, hdcDraw, lprcBounds, lprcWBounds, pfnContinue, dwContinue );
1295 return E_FAIL;
1299 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetColorSet( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet )
1301 if ( CheckDefHandler() )
1303 sal::systools::COMReference< IViewObject > pIViewObject(m_pDefHandler, sal::systools::COM_QUERY);
1305 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1306 if ( pIViewObject )
1307 return pIViewObject->GetColorSet( dwDrawAspect, lindex, pvAspect, ptd, hicTargetDev, ppColorSet );
1310 return E_FAIL;
1314 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::Freeze( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DWORD *pdwFreeze )
1316 if ( CheckDefHandler() )
1318 sal::systools::COMReference< IViewObject > pIViewObject(m_pDefHandler, sal::systools::COM_QUERY);
1320 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1321 if ( pIViewObject )
1322 return pIViewObject->Freeze( dwDrawAspect, lindex, pvAspect, pdwFreeze );
1325 return E_FAIL;
1329 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::Unfreeze( DWORD dwFreeze )
1331 if ( CheckDefHandler() )
1333 sal::systools::COMReference< IViewObject > pIViewObject(m_pDefHandler, sal::systools::COM_QUERY);
1335 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1336 if ( pIViewObject )
1337 return pIViewObject->Unfreeze( dwFreeze );
1340 return E_FAIL;
1344 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::SetAdvise( DWORD aspects, DWORD advf, IAdviseSink *pAdvSink )
1347 // CheckDefHandler will set the listener, avoid reusing of old listener
1348 if ( m_pViewAdvise )
1350 m_pViewAdvise->DisconnectOrigAdvise();
1351 m_pViewAdvise = nullptr;
1354 if ( pAdvSink && CheckDefHandler() )
1356 sal::systools::COMReference< IViewObject > pIViewObject(m_pDefHandler, sal::systools::COM_QUERY);
1358 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1359 if ( pIViewObject )
1361 sal::systools::COMReference pOwnAdvise(new OleWrapperAdviseSink(pAdvSink, aspects, advf));
1363 if ( SUCCEEDED( pIViewObject->SetAdvise( aspects, advf, pOwnAdvise.get() ) ) )
1365 m_pViewAdvise = pOwnAdvise;
1366 return S_OK;
1371 return S_OK;
1375 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetAdvise( DWORD *pAspects, DWORD *pAdvf, IAdviseSink **ppAdvSink )
1377 if ( !ppAdvSink )
1378 return E_INVALIDARG;
1380 if ( m_pViewAdvise )
1382 if ( pAspects )
1383 *pAspects = m_pViewAdvise->GetAspect();
1385 if ( pAdvf )
1386 *pAdvf = m_pViewAdvise->GetViewAdviseFlag();
1388 *ppAdvSink = m_pViewAdvise->GetOrigAdvise().get();
1389 if ( *ppAdvSink )
1390 (*ppAdvSink)->AddRef();
1392 else
1393 *ppAdvSink = nullptr;
1395 return S_OK;
1398 // IViewObject2 methods
1400 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetExtent( DWORD dwDrawAspect, LONG lindex, DVTARGETDEVICE *ptd, LPSIZEL lpsizel )
1402 if ( CheckDefHandler() )
1404 sal::systools::COMReference< IViewObject2 > pIViewObject2(m_pDefHandler, sal::systools::COM_QUERY);
1406 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1407 if ( pIViewObject2 )
1408 return pIViewObject2->GetExtent( dwDrawAspect, lindex, ptd, lpsizel );
1411 return E_FAIL;
1415 // IOleWindow methods
1417 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetWindow( HWND *phwnd )
1419 if ( CheckDefHandler() )
1421 sal::systools::COMReference< IOleWindow > pIOleWindow(m_pDefHandler, sal::systools::COM_QUERY);
1423 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1424 if ( pIOleWindow )
1425 return pIOleWindow->GetWindow( phwnd );
1428 return E_FAIL;
1432 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::ContextSensitiveHelp( BOOL fEnterMode )
1434 if ( CheckDefHandler() )
1436 sal::systools::COMReference< IOleWindow > pIOleWindow(m_pDefHandler, sal::systools::COM_QUERY);
1438 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1439 if ( pIOleWindow )
1440 return pIOleWindow->ContextSensitiveHelp( fEnterMode );
1443 return E_FAIL;
1447 // IOleInPlaceObject methods
1449 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::InPlaceDeactivate()
1451 if ( CheckDefHandler() )
1453 sal::systools::COMReference< IOleInPlaceObject > pIOleInPlaceObject(m_pDefHandler, sal::systools::COM_QUERY);
1455 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1456 if ( pIOleInPlaceObject )
1457 return pIOleInPlaceObject->InPlaceDeactivate();
1460 return E_FAIL;
1464 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::UIDeactivate()
1466 if ( CheckDefHandler() )
1468 sal::systools::COMReference< IOleInPlaceObject > pIOleInPlaceObject(m_pDefHandler, sal::systools::COM_QUERY);
1470 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1471 if ( pIOleInPlaceObject )
1472 return pIOleInPlaceObject->UIDeactivate();
1475 return E_FAIL;
1479 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::SetObjectRects( LPCRECT lprcPosRect, LPCRECT lprcClipRect )
1481 if ( CheckDefHandler() )
1483 sal::systools::COMReference< IOleInPlaceObject > pIOleInPlaceObject(m_pDefHandler, sal::systools::COM_QUERY);
1485 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1486 if ( pIOleInPlaceObject )
1487 return pIOleInPlaceObject->SetObjectRects( lprcPosRect, lprcClipRect );
1490 return E_FAIL;
1494 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::ReactivateAndUndo()
1496 if ( CheckDefHandler() )
1498 sal::systools::COMReference< IOleInPlaceObject > pIOleInPlaceObject(m_pDefHandler, sal::systools::COM_QUERY);
1500 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1501 if ( pIOleInPlaceObject )
1502 return pIOleInPlaceObject->ReactivateAndUndo();
1505 return E_FAIL;
1509 // IDispatch methods
1511 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetTypeInfoCount( UINT *pctinfo )
1513 if ( CheckDefHandler() )
1515 sal::systools::COMReference< IDispatch > pIDispatch(m_pDefHandler, sal::systools::COM_QUERY);
1517 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1518 if ( pIDispatch )
1519 return pIDispatch->GetTypeInfoCount( pctinfo );
1522 return E_FAIL;
1526 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetTypeInfo( UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo )
1528 if ( CheckDefHandler() )
1530 sal::systools::COMReference< IDispatch > pIDispatch(m_pDefHandler, sal::systools::COM_QUERY);
1532 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1533 if ( pIDispatch )
1534 return pIDispatch->GetTypeInfo( iTInfo, lcid, ppTInfo );
1537 return E_FAIL;
1541 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::GetIDsOfNames( REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId )
1543 if ( CheckDefHandler() )
1545 sal::systools::COMReference< IDispatch > pIDispatch(m_pDefHandler, sal::systools::COM_QUERY);
1547 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1548 if ( pIDispatch )
1549 return pIDispatch->GetIDsOfNames( riid, rgszNames, cNames, lcid, rgDispId );
1552 return E_FAIL;
1556 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::Invoke( DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr )
1558 if ( CheckDefHandler() )
1560 sal::systools::COMReference< IDispatch > pIDispatch(m_pDefHandler, sal::systools::COM_QUERY);
1562 ULONGGuard aGuard( m_nCallsOnStack ); // avoid reentrance problem
1563 if ( pIDispatch )
1564 return pIDispatch->Invoke( dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr );
1567 return E_FAIL;
1571 // InternalCacheWrapper
1574 // IUnknown
1576 COM_DECLSPEC_NOTHROW STDMETHODIMP
1577 InprocEmbedDocument_Impl::InternalCacheWrapper::QueryInterface(REFIID riid, void** ppv)
1579 return m_rOwnDocument.QueryInterface( riid, ppv );
1583 COM_DECLSPEC_NOTHROW STDMETHODIMP_(ULONG) InprocEmbedDocument_Impl::InternalCacheWrapper::AddRef()
1585 return m_rOwnDocument.AddRef();
1589 COM_DECLSPEC_NOTHROW STDMETHODIMP_(ULONG) InprocEmbedDocument_Impl::InternalCacheWrapper::Release()
1591 return m_rOwnDocument.Release();
1594 // IOleCache methods
1596 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::Cache( FORMATETC *pformatetc, DWORD advf, DWORD *pdwConnection )
1598 if ( m_rOwnDocument.CheckDefHandler() )
1600 sal::systools::COMReference< IOleCache > pIOleCache(m_rOwnDocument.GetDefHandler(), sal::systools::COM_QUERY);
1602 ULONGGuard aGuard( m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem
1603 if ( pIOleCache )
1604 return pIOleCache->Cache( pformatetc, advf, pdwConnection );
1607 return E_FAIL;
1611 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::Uncache( DWORD dwConnection )
1613 if ( m_rOwnDocument.CheckDefHandler() )
1615 sal::systools::COMReference< IOleCache > pIOleCache(m_rOwnDocument.GetDefHandler(), sal::systools::COM_QUERY);
1617 ULONGGuard aGuard( m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem
1618 if ( pIOleCache )
1619 return pIOleCache->Uncache( dwConnection );
1622 return E_FAIL;
1626 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::EnumCache( IEnumSTATDATA **ppenumSTATDATA )
1628 if ( m_rOwnDocument.CheckDefHandler() )
1630 sal::systools::COMReference< IOleCache > pIOleCache(m_rOwnDocument.GetDefHandler(), sal::systools::COM_QUERY);
1632 ULONGGuard aGuard( m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem
1633 if ( pIOleCache )
1634 return pIOleCache->EnumCache( ppenumSTATDATA );
1637 return E_FAIL;
1641 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::InitCache( IDataObject *pDataObject )
1643 if ( m_rOwnDocument.CheckDefHandler() )
1645 sal::systools::COMReference< IOleCache > pIOleCache(m_rOwnDocument.GetDefHandler(), sal::systools::COM_QUERY);
1647 ULONGGuard aGuard( m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem
1648 if ( pIOleCache )
1649 return pIOleCache->InitCache( pDataObject );
1652 return E_FAIL;
1656 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::SetData( FORMATETC *pformatetc, STGMEDIUM *pmedium, BOOL fRelease )
1658 if ( m_rOwnDocument.CheckDefHandler() )
1660 sal::systools::COMReference< IOleCache > pIOleCache(m_rOwnDocument.GetDefHandler(), sal::systools::COM_QUERY);
1662 ULONGGuard aGuard( m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem
1663 if ( pIOleCache )
1664 return pIOleCache->SetData( pformatetc, pmedium, fRelease );
1667 return E_FAIL;
1670 // IOleCache2 methods
1672 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::UpdateCache( LPDATAOBJECT pDataObject, DWORD grfUpdf, LPVOID pReserved )
1674 if ( m_rOwnDocument.CheckDefHandler() )
1676 sal::systools::COMReference< IOleCache2 > pIOleCache2(m_rOwnDocument.GetDefHandler(), sal::systools::COM_QUERY);
1678 ULONGGuard aGuard( m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem
1679 if ( pIOleCache2 )
1680 return pIOleCache2->UpdateCache( pDataObject, grfUpdf, pReserved );
1683 return E_FAIL;
1687 COM_DECLSPEC_NOTHROW STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::DiscardCache( DWORD dwDiscardOptions )
1689 if ( m_rOwnDocument.CheckDefHandler() )
1691 sal::systools::COMReference< IOleCache2 > pIOleCache2(m_rOwnDocument.GetDefHandler(), sal::systools::COM_QUERY);
1693 ULONGGuard aGuard( m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem
1694 if ( pIOleCache2 )
1695 return pIOleCache2->DiscardCache( dwDiscardOptions );
1698 return E_FAIL;
1701 }; // namespace inprocserv
1703 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */