1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
29 BOOL
StringsEqual( LPCOLESTR pszNameFromOutside
, wchar_t* pOwnName
)
33 if ( pszNameFromOutside
&& pOwnName
)
35 for ( int nInd
= 0; pszNameFromOutside
[nInd
] != 0 || pOwnName
[nInd
] != 0; nInd
++ )
37 if ( pszNameFromOutside
[nInd
] != pOwnName
[nInd
] )
44 else if ( pszNameFromOutside
|| pOwnName
)
51 HRESULT
InprocEmbedDocument_Impl::Init()
57 void InprocEmbedDocument_Impl::SetName( LPCOLESTR pszNameFromOutside
, wchar_t*& pOwnName
)
59 if ( !pszNameFromOutside
)
64 while( pszNameFromOutside
[nLen
] != 0 )
73 pOwnName
= new wchar_t[nLen
+1];
74 for ( size_t nInd
= 0; nInd
< nLen
; nInd
++ )
75 pOwnName
[nInd
] = pszNameFromOutside
[nInd
];
80 BOOL
InprocEmbedDocument_Impl::CheckDefHandler()
82 // set the own listener
83 if ( m_pOleAdvises
[0] == NULL
)
85 m_pOleAdvises
[0] = new OleWrapperAdviseSink();
89 if ( m_pOleAdvises
[0]->IsClosed() )
93 // deregister all the listeners
95 ComSmart
< IOleObject
> pOleObject
;
96 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
97 if ( SUCCEEDED( hr
) && pOleObject
)
99 for ( DWORD nInd
= 0; nInd
< DEFAULT_ARRAY_LEN
; nInd
++ )
100 if ( m_pOleAdvises
[nInd
] )
102 DWORD nID
= m_pOleAdvises
[nInd
]->GetRegID();
103 pOleObject
->Unadvise( nID
);
104 m_pOleAdvises
[nInd
]->SetRegID( 0 );
107 pOleObject
->SetClientSite( NULL
);
110 ComSmart
< IDataObject
> pIDataObject
;
111 hr
= m_pDefHandler
->QueryInterface( IID_IDataObject
, (void**)&pIDataObject
);
112 if ( SUCCEEDED( hr
) && pIDataObject
)
114 for ( DWORD nInd
= 0; nInd
< DEFAULT_ARRAY_LEN
; nInd
++ )
115 if ( m_pDataAdvises
[nInd
] )
117 DWORD nID
= m_pDataAdvises
[nInd
]->GetRegID();
118 pIDataObject
->DUnadvise( nID
);
119 m_pDataAdvises
[nInd
]->SetRegID( 0 );
123 ComSmart
< IViewObject
> pIViewObject
;
124 hr
= m_pDefHandler
->QueryInterface( IID_IViewObject
, (void**)&pIViewObject
);
125 if ( SUCCEEDED( hr
) && pIViewObject
)
128 pIViewObject
->SetAdvise( m_pViewAdvise
->GetAspect(), m_pViewAdvise
->GetViewAdviseFlag(), NULL
);
131 ComSmart
< IPersistStorage
> pPersist
;
132 hr
= m_pDefHandler
->QueryInterface( IID_IPersistStorage
, (void**)&pPersist
);
133 if ( SUCCEEDED( hr
) && pPersist
)
135 // disconnect the old wrapper from the storage
136 pPersist
->HandsOffStorage();
139 m_pDefHandler
= NULL
;
142 m_pOleAdvises
[0]->UnsetClosed();
146 if ( m_nCallsOnStack
)
149 if ( !m_pDefHandler
)
151 // create a new default inprocess handler
152 HRESULT hr
= OleCreateDefaultHandler( m_guid
, NULL
, IID_IUnknown
, (void**)&m_pDefHandler
);
153 if ( SUCCEEDED( hr
) )
156 if ( m_nInitMode
== INIT_FROM_STORAGE
)
158 ComSmart
< IPersistStorage
> pPersist
;
159 hr
= m_pDefHandler
->QueryInterface( IID_IPersistStorage
, (void**)&pPersist
);
161 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
162 if ( SUCCEEDED( hr
) && pPersist
&& m_pStorage
)
163 hr
= pPersist
->InitNew( m_pStorage
);
165 else if ( m_nInitMode
== LOAD_FROM_STORAGE
)
167 ComSmart
< IPersistStorage
> pPersist
;
168 hr
= m_pDefHandler
->QueryInterface( IID_IPersistStorage
, (void**)&pPersist
);
170 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
171 if ( SUCCEEDED( hr
) && pPersist
&& m_pStorage
)
172 hr
= pPersist
->Load( m_pStorage
);
174 else if ( m_nInitMode
== LOAD_FROM_FILE
)
176 ComSmart
< IPersistFile
> pPersistFile
;
177 hr
= m_pDefHandler
->QueryInterface( IID_IPersistFile
, (void**)&pPersistFile
);
179 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
180 if ( SUCCEEDED( hr
) && pPersistFile
&& m_pFileName
)
181 hr
= pPersistFile
->Load( m_pFileName
, m_nFileOpenMode
);
186 if ( !SUCCEEDED( hr
) || !m_pDefHandler
)
188 m_pDefHandler
= NULL
;
192 // register all the listeners new
194 ComSmart
< IOleObject
> pOleObject
;
195 hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
196 if ( SUCCEEDED( hr
) && pOleObject
)
199 pOleObject
->SetClientSite( m_pClientSite
);
201 for ( DWORD nInd
= 0; nInd
< DEFAULT_ARRAY_LEN
; nInd
++ )
202 if ( m_pOleAdvises
[nInd
] )
205 if ( SUCCEEDED( pOleObject
->Advise( m_pOleAdvises
[nInd
], &nRegID
) ) && nRegID
> 0 )
206 m_pOleAdvises
[nInd
]->SetRegID( nRegID
);
210 ComSmart
< IDataObject
> pIDataObject
;
211 hr
= m_pDefHandler
->QueryInterface( IID_IDataObject
, (void**)&pIDataObject
);
212 if ( SUCCEEDED( hr
) && pIDataObject
)
214 for ( DWORD nInd
= 0; nInd
< DEFAULT_ARRAY_LEN
; nInd
++ )
215 if ( m_pDataAdvises
[nInd
] )
218 if ( SUCCEEDED( pIDataObject
->DAdvise( m_pDataAdvises
[nInd
]->GetFormatEtc(), m_pDataAdvises
[nInd
]->GetDataAdviseFlag(), m_pDataAdvises
[nInd
], &nRegID
) ) && nRegID
> 0 )
219 m_pDataAdvises
[nInd
]->SetRegID( nRegID
);
223 ComSmart
< IViewObject
> pIViewObject
;
224 hr
= m_pDefHandler
->QueryInterface( IID_IViewObject
, (void**)&pIViewObject
);
225 if ( SUCCEEDED( hr
) && pIViewObject
)
228 pIViewObject
->SetAdvise( m_pViewAdvise
->GetAspect(), m_pViewAdvise
->GetViewAdviseFlag(), m_pViewAdvise
);
237 DWORD
InprocEmbedDocument_Impl::InsertAdviseLinkToList( const ComSmart
<OleWrapperAdviseSink
>& pOwnAdvise
, ComSmart
< OleWrapperAdviseSink
> pAdvises
[] )
239 // the result should start from 1 in case of success, the element 0 can be used for own needs
244 for ( DWORD nInd
= 1; nInd
< DEFAULT_ARRAY_LEN
&& nResult
== 0; nInd
++ )
246 if ( pAdvises
[nInd
] == pOwnAdvise
)
250 else if ( pAdvises
[nInd
] == NULL
)
252 pAdvises
[nInd
] = pOwnAdvise
;
262 void InprocEmbedDocument_Impl::Clean()
264 m_pDefHandler
= (IUnknown
*)NULL
;
266 // no DisconnectOrigAdvise() call here, since it is no explicit disconnection
267 for ( DWORD nInd
= 0; nInd
< DEFAULT_ARRAY_LEN
; nInd
++ )
269 if ( m_pOleAdvises
[nInd
] )
271 ComSmart
< OleWrapperAdviseSink
> pAdvise
= m_pOleAdvises
[nInd
];
272 m_pOleAdvises
[nInd
] = NULL
;
275 if ( m_pDataAdvises
[nInd
] )
277 ComSmart
< OleWrapperAdviseSink
> pAdvise
= m_pDataAdvises
[nInd
];
278 m_pDataAdvises
[nInd
] = NULL
;
282 m_pViewAdvise
= NULL
;
284 m_nInitMode
= NOINIT
;
287 if ( m_pOleContainer
)
289 m_pOleContainer
->LockContainer( FALSE
);
290 m_pOleContainer
= NULL
;
293 m_pClientSite
= NULL
;
305 STDMETHODIMP
InprocEmbedDocument_Impl::QueryInterface( REFIID riid
, void FAR
* FAR
* ppv
)
307 if(IsEqualIID(riid
, IID_IUnknown
))
310 *ppv
= (IUnknown
*) (IPersistStorage
*) this;
313 else if (IsEqualIID(riid
, IID_IPersist
))
316 *ppv
= (IPersist
*) (IPersistStorage
*) this;
319 else if (IsEqualIID(riid
, IID_IPersistStorage
))
322 *ppv
= (IPersistStorage
*) this;
325 else if (IsEqualIID(riid
, IID_IDataObject
))
328 *ppv
= (IDataObject
*) this;
331 else if (IsEqualIID(riid
, IID_IOleObject
))
334 *ppv
= (IOleObject
*) this;
337 else if (IsEqualIID(riid
, IID_IPersistFile
))
340 *ppv
= (IPersistFile
*) this;
343 else if (IsEqualIID(riid
, IID_IRunnableObject
))
346 *ppv
= (IRunnableObject
*) this;
349 else if (IsEqualIID(riid
, IID_IViewObject
))
352 *ppv
= (IViewObject
*) this;
355 else if (IsEqualIID(riid
, IID_IViewObject2
))
358 *ppv
= (IViewObject2
*) this;
361 else if (IsEqualIID(riid
, IID_IOleCache
))
364 *ppv
= (IOleCache
*) &m_aInternalCache
;
367 else if (IsEqualIID(riid
, IID_IOleCache2
))
370 *ppv
= (IOleCache2
*) &m_aInternalCache
;
373 else if (IsEqualIID(riid
, IID_IOleWindow
))
376 *ppv
= (IOleWindow
*) this;
379 else if (IsEqualIID(riid
, IID_IOleInPlaceObject
))
382 *ppv
= (IOleInPlaceObject
*) this;
385 else if (IsEqualIID(riid
, IID_IDispatch
))
388 *ppv
= (IDispatch
*) this;
393 return ResultFromScode(E_NOINTERFACE
);
397 STDMETHODIMP_(ULONG
) InprocEmbedDocument_Impl::AddRef()
403 STDMETHODIMP_(ULONG
) InprocEmbedDocument_Impl::Release()
405 // unfortunately there are reentrance problems in mfc that have to be workarounded
406 sal_Int32 nCount
= m_refCount
> 0 ? --m_refCount
: 0;
407 if ( nCount
== 0 && !m_bDeleted
)
409 // deleting of this object can trigger deleting of mfc objects that will try to delete this object one more time
420 STDMETHODIMP
InprocEmbedDocument_Impl::GetClassID( CLSID
* pClassId
)
422 *pClassId
= *&m_guid
;
428 STDMETHODIMP
InprocEmbedDocument_Impl::IsDirty()
430 if ( m_pDefHandler
== NULL
|| m_pOleAdvises
[0] == NULL
|| m_pOleAdvises
[0]->IsClosed() )
433 if ( CheckDefHandler() )
435 ComSmart
< IPersistStorage
> pPersist
;
436 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IPersistStorage
, (void**)&pPersist
);
438 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
439 if ( SUCCEEDED( hr
) && pPersist
)
440 return pPersist
->IsDirty();
447 STDMETHODIMP
InprocEmbedDocument_Impl::InitNew( IStorage
*pStg
)
449 if ( CheckDefHandler() )
451 ComSmart
< IPersistStorage
> pPersist
;
452 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IPersistStorage
, (void**)&pPersist
);
454 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
455 if ( SUCCEEDED( hr
) && pPersist
)
457 hr
= pPersist
->InitNew( pStg
);
458 if ( SUCCEEDED( hr
) )
460 m_nInitMode
= INIT_FROM_STORAGE
;
466 delete[] m_pFileName
;
479 STDMETHODIMP
InprocEmbedDocument_Impl::Load( IStorage
*pStg
)
481 if ( CheckDefHandler() )
483 ComSmart
< IPersistStorage
> pPersist
;
484 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IPersistStorage
, (void**)&pPersist
);
486 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
487 if ( SUCCEEDED( hr
) && pPersist
)
489 hr
= pPersist
->Load( pStg
);
490 if ( SUCCEEDED( hr
) )
492 m_nInitMode
= LOAD_FROM_STORAGE
;
498 delete[] m_pFileName
;
511 STDMETHODIMP
InprocEmbedDocument_Impl::Save( IStorage
*pStgSave
, BOOL fSameAsLoad
)
513 if ( fSameAsLoad
&& ( m_pDefHandler
== NULL
|| m_pOleAdvises
[0] == NULL
|| m_pOleAdvises
[0]->IsClosed() ) )
516 if ( CheckDefHandler() )
518 ComSmart
< IPersistStorage
> pPersist
;
519 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IPersistStorage
, (void**)&pPersist
);
521 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
522 if ( SUCCEEDED( hr
) && pPersist
)
523 return pPersist
->Save( pStgSave
, fSameAsLoad
);
530 STDMETHODIMP
InprocEmbedDocument_Impl::SaveCompleted( IStorage
*pStgNew
)
532 if ( m_pDefHandler
== NULL
|| m_pOleAdvises
[0] == NULL
|| m_pOleAdvises
[0]->IsClosed() )
535 m_pStorage
= pStgNew
;
540 if ( CheckDefHandler() )
542 ComSmart
< IPersistStorage
> pPersist
;
543 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IPersistStorage
, (void**)&pPersist
);
545 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
546 if ( SUCCEEDED( hr
) && pPersist
)
548 hr
= pPersist
->SaveCompleted( pStgNew
);
549 if ( SUCCEEDED( hr
) )
551 m_nInitMode
= LOAD_FROM_STORAGE
;
554 m_pStorage
= pStgNew
;
560 delete[] m_pFileName
;
573 STDMETHODIMP
InprocEmbedDocument_Impl::HandsOffStorage()
575 if ( CheckDefHandler() )
577 ComSmart
< IPersistStorage
> pPersist
;
578 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IPersistStorage
, (void**)&pPersist
);
580 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
581 if ( SUCCEEDED( hr
) && pPersist
)
583 hr
= pPersist
->HandsOffStorage();
584 if ( SUCCEEDED( hr
) )
598 STDMETHODIMP
InprocEmbedDocument_Impl::Load( LPCOLESTR pszFileName
, DWORD dwMode
)
600 if ( CheckDefHandler() && pszFileName
)
602 ComSmart
< IPersistFile
> pPersist
;
603 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IPersistFile
, (void**)&pPersist
);
605 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
606 if ( SUCCEEDED( hr
) && pPersist
)
608 hr
= pPersist
->Load( pszFileName
, dwMode
);
609 if ( SUCCEEDED( hr
) )
611 m_nInitMode
= LOAD_FROM_FILE
;
615 m_nFileOpenMode
= dwMode
;
617 SetName( pszFileName
, m_pFileName
);
628 STDMETHODIMP
InprocEmbedDocument_Impl::Save( LPCOLESTR pszFileName
, BOOL fRemember
)
630 if ( CheckDefHandler() )
632 ComSmart
< IPersistFile
> pPersist
;
633 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IPersistFile
, (void**)&pPersist
);
635 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
636 if ( SUCCEEDED( hr
) && pPersist
)
637 return pPersist
->Save( pszFileName
, fRemember
);
644 STDMETHODIMP
InprocEmbedDocument_Impl::SaveCompleted( LPCOLESTR pszFileName
)
646 if ( CheckDefHandler() )
648 ComSmart
< IPersistFile
> pPersist
;
649 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IPersistFile
, (void**)&pPersist
);
651 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
652 if ( SUCCEEDED( hr
) && pPersist
)
654 hr
= pPersist
->SaveCompleted( pszFileName
);
655 if ( SUCCEEDED( hr
) )
657 m_nInitMode
= LOAD_FROM_STORAGE
;
661 m_nFileOpenMode
= STGM_READWRITE
; // was just written
663 SetName( pszFileName
, m_pFileName
);
673 STDMETHODIMP
InprocEmbedDocument_Impl::GetCurFile( LPOLESTR
*ppszFileName
)
675 if ( CheckDefHandler() )
677 ComSmart
< IPersistFile
> pPersist
;
678 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IPersistFile
, (void**)&pPersist
);
680 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
681 if ( SUCCEEDED( hr
) && pPersist
)
682 return pPersist
->GetCurFile( ppszFileName
);
690 STDMETHODIMP
InprocEmbedDocument_Impl::SetClientSite( IOleClientSite
* pSite
)
692 if ( pSite
== m_pClientSite
)
697 m_pClientSite
= NULL
;
698 if ( m_pOleContainer
)
700 m_pOleContainer
->LockContainer( FALSE
);
701 m_pOleContainer
= NULL
;
705 if ( CheckDefHandler() )
707 ComSmart
< IOleObject
> pOleObject
;
708 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
710 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
711 if ( SUCCEEDED( hr
) && pOleObject
)
713 HRESULT hr2
= pOleObject
->SetClientSite( pSite
);
714 if ( SUCCEEDED( hr2
) )
716 m_pClientSite
= pSite
;
718 if ( m_pOleContainer
)
720 m_pOleContainer
->LockContainer( FALSE
);
721 m_pOleContainer
= NULL
;
724 m_pClientSite
->GetContainer( &m_pOleContainer
);
725 if ( m_pOleContainer
)
726 m_pOleContainer
->LockContainer( TRUE
);
737 STDMETHODIMP
InprocEmbedDocument_Impl::GetClientSite( IOleClientSite
** pSite
)
739 if ( CheckDefHandler() )
741 ComSmart
< IOleObject
> pOleObject
;
742 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
744 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
745 if ( SUCCEEDED( hr
) && pOleObject
)
746 return pOleObject
->GetClientSite( pSite
);
753 STDMETHODIMP
InprocEmbedDocument_Impl::SetHostNames( LPCOLESTR szContainerApp
, LPCOLESTR szContainerObj
)
756 if ( CheckDefHandler() )
758 ComSmart
< IOleObject
> pOleObject
;
759 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
761 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
762 if ( SUCCEEDED( hr
) && pOleObject
)
764 hr
= pOleObject
->SetHostNames( szContainerApp
, szContainerObj
);
772 STDMETHODIMP
InprocEmbedDocument_Impl::Close( DWORD dwSaveOption
)
775 if ( m_pDefHandler
&& CheckDefHandler() )
777 // no need to close if there is no default handler.
778 ComSmart
< IOleObject
> pOleObject
;
779 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
781 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
782 if ( SUCCEEDED( hr
) && pOleObject
)
784 hr
= pOleObject
->Close( dwSaveOption
);
787 hr
= CoDisconnectObject( (IUnknown
*)(IPersistStorage
*)this, 0 );
788 if (!SUCCEEDED(hr
) && SUCCEEDED(ret
))
793 // if the object is closed from outside that means that it should go to uninitialized state
800 STDMETHODIMP
InprocEmbedDocument_Impl::SetMoniker( DWORD dwWhichMoniker
, IMoniker
* pmk
)
802 if ( CheckDefHandler() )
804 ComSmart
< IOleObject
> pOleObject
;
805 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
807 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
808 if ( SUCCEEDED( hr
) && pOleObject
)
809 return pOleObject
->SetMoniker( dwWhichMoniker
, pmk
);
816 STDMETHODIMP
InprocEmbedDocument_Impl::GetMoniker( DWORD dwAssign
, DWORD dwWhichMoniker
, IMoniker
** ppmk
)
818 if ( CheckDefHandler() )
820 ComSmart
< IOleObject
> pOleObject
;
821 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
823 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
824 if ( SUCCEEDED( hr
) && pOleObject
)
825 return pOleObject
->GetMoniker( dwAssign
, dwWhichMoniker
, ppmk
);
832 STDMETHODIMP
InprocEmbedDocument_Impl::InitFromData( IDataObject
* pDataObject
, BOOL fCreation
, DWORD dwReserved
)
834 if ( CheckDefHandler() )
836 ComSmart
< IOleObject
> pOleObject
;
837 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
839 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
840 if ( SUCCEEDED( hr
) && pOleObject
)
841 return pOleObject
->InitFromData( pDataObject
, fCreation
, dwReserved
);
848 STDMETHODIMP
InprocEmbedDocument_Impl::GetClipboardData( DWORD dwReserved
, IDataObject
** ppDataObject
)
850 if ( CheckDefHandler() )
852 ComSmart
< IOleObject
> pOleObject
;
853 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
855 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
856 if ( SUCCEEDED( hr
) && pOleObject
)
857 return pOleObject
->GetClipboardData( dwReserved
, ppDataObject
);
864 STDMETHODIMP
InprocEmbedDocument_Impl::DoVerb(
867 IOleClientSite
*pActiveSite
,
872 if ( CheckDefHandler() )
874 ComSmart
< IOleObject
> pOleObject
;
875 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
877 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
878 if ( SUCCEEDED( hr
) && pOleObject
)
880 hr
= pOleObject
->DoVerb( iVerb
, pMsg
, pActiveSite
, nLong
, hWin
, pRect
);
881 if ( SUCCEEDED( hr
) )
894 STDMETHODIMP
InprocEmbedDocument_Impl::EnumVerbs( IEnumOLEVERB
** ppEnumOleVerb
)
896 if ( CheckDefHandler() )
898 ComSmart
< IOleObject
> pOleObject
;
899 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
901 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
902 if ( SUCCEEDED( hr
) && pOleObject
)
903 return pOleObject
->EnumVerbs( ppEnumOleVerb
);
910 STDMETHODIMP
InprocEmbedDocument_Impl::Update()
913 if ( m_pDefHandler
&& CheckDefHandler() )
915 ComSmart
< IOleObject
> pOleObject
;
916 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
918 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
919 if ( SUCCEEDED( hr
) && pOleObject
)
920 return pOleObject
->Update();
927 STDMETHODIMP
InprocEmbedDocument_Impl::IsUpToDate()
929 if ( CheckDefHandler() )
931 ComSmart
< IOleObject
> pOleObject
;
932 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
934 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
935 if ( SUCCEEDED( hr
) && pOleObject
)
936 return pOleObject
->IsUpToDate();
943 STDMETHODIMP
InprocEmbedDocument_Impl::GetUserClassID( CLSID
*pClsid
)
952 STDMETHODIMP
InprocEmbedDocument_Impl::GetUserType( DWORD dwFormOfType
, LPOLESTR
* pszUserType
)
954 if ( CheckDefHandler() )
956 ComSmart
< IOleObject
> pOleObject
;
957 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
959 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
960 if ( SUCCEEDED( hr
) && pOleObject
)
961 return pOleObject
->GetUserType( dwFormOfType
, pszUserType
);
968 STDMETHODIMP
InprocEmbedDocument_Impl::SetExtent( DWORD dwDrawAspect
, SIZEL
*psizel
)
970 if ( CheckDefHandler() )
972 ComSmart
< IOleObject
> pOleObject
;
973 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
975 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
976 if ( SUCCEEDED( hr
) && pOleObject
)
977 return pOleObject
->SetExtent( dwDrawAspect
, psizel
);
984 STDMETHODIMP
InprocEmbedDocument_Impl::GetExtent( DWORD dwDrawAspect
, SIZEL
* psizel
)
986 if ( CheckDefHandler() )
988 ComSmart
< IOleObject
> pOleObject
;
989 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
991 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
992 if ( SUCCEEDED( hr
) && pOleObject
)
993 return pOleObject
->GetExtent( dwDrawAspect
, psizel
);
1000 STDMETHODIMP
InprocEmbedDocument_Impl::Advise( IAdviseSink
*pAdvSink
, DWORD
*pdwConnection
)
1003 if ( !pdwConnection
)
1006 // CheckDefHandler will set the listener, avoid reusing of old listener
1007 if ( DEFAULT_ARRAY_LEN
> *pdwConnection
&& *pdwConnection
> 0 && m_pOleAdvises
[*pdwConnection
] )
1009 m_pOleAdvises
[*pdwConnection
]->DisconnectOrigAdvise();
1010 m_pOleAdvises
[*pdwConnection
] = NULL
;
1013 if ( pAdvSink
&& CheckDefHandler() )
1015 ComSmart
< IOleObject
> pOleObject
;
1016 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
1018 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1019 if ( SUCCEEDED( hr
) && pOleObject
)
1021 ComSmart
< OleWrapperAdviseSink
> pOwnAdvise( new OleWrapperAdviseSink( pAdvSink
) );
1024 if ( SUCCEEDED( pOleObject
->Advise( pOwnAdvise
, &nRegID
) ) && nRegID
> 0 )
1026 pOwnAdvise
->SetRegID( nRegID
);
1027 *pdwConnection
= InsertAdviseLinkToList( pOwnAdvise
, m_pOleAdvises
);
1028 if ( *pdwConnection
)
1031 pOleObject
->Unadvise( nRegID
);
1036 // return success always for now
1041 STDMETHODIMP
InprocEmbedDocument_Impl::Unadvise( DWORD dwConnection
)
1043 if ( DEFAULT_ARRAY_LEN
> dwConnection
&& dwConnection
> 0 && m_pOleAdvises
[dwConnection
] )
1045 if ( m_pDefHandler
)
1047 ComSmart
< IOleObject
> pOleObject
;
1048 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
1050 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1051 if ( SUCCEEDED( hr
) && pOleObject
)
1053 DWORD nID
= m_pOleAdvises
[dwConnection
]->GetRegID();
1054 pOleObject
->Unadvise( nID
);
1058 m_pOleAdvises
[dwConnection
]->DisconnectOrigAdvise();
1059 m_pOleAdvises
[dwConnection
] = NULL
;
1068 STDMETHODIMP
InprocEmbedDocument_Impl::EnumAdvise( IEnumSTATDATA
** /*ppenumAdvise*/ )
1074 STDMETHODIMP
InprocEmbedDocument_Impl::GetMiscStatus( DWORD dwAspect
, DWORD
* pdwStatus
)
1076 if ( CheckDefHandler() )
1078 ComSmart
< IOleObject
> pOleObject
;
1079 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
1081 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1082 if ( SUCCEEDED( hr
) && pOleObject
)
1083 return pOleObject
->GetMiscStatus( dwAspect
, pdwStatus
);
1090 STDMETHODIMP
InprocEmbedDocument_Impl::SetColorScheme( LOGPALETTE
* pLogpal
)
1092 if ( CheckDefHandler() )
1094 ComSmart
< IOleObject
> pOleObject
;
1095 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
1097 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1098 if ( SUCCEEDED( hr
) && pOleObject
)
1099 return pOleObject
->SetColorScheme( pLogpal
);
1107 STDMETHODIMP
InprocEmbedDocument_Impl::GetData( FORMATETC
* pFormatetc
, STGMEDIUM
* pMedium
)
1109 if ( CheckDefHandler() )
1111 ComSmart
< IDataObject
> pIDataObject
;
1112 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IDataObject
, (void**)&pIDataObject
);
1114 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1115 if ( SUCCEEDED( hr
) && pIDataObject
)
1116 return pIDataObject
->GetData( pFormatetc
, pMedium
);
1123 STDMETHODIMP
InprocEmbedDocument_Impl::GetDataHere( FORMATETC
* pFormatetc
, STGMEDIUM
* pMedium
)
1125 if ( CheckDefHandler() )
1127 ComSmart
< IDataObject
> pIDataObject
;
1128 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IDataObject
, (void**)&pIDataObject
);
1130 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1131 if ( SUCCEEDED( hr
) && pIDataObject
)
1132 return pIDataObject
->GetDataHere( pFormatetc
, pMedium
);
1139 STDMETHODIMP
InprocEmbedDocument_Impl::QueryGetData( FORMATETC
* pFormatetc
)
1141 if ( CheckDefHandler() )
1143 ComSmart
< IDataObject
> pIDataObject
;
1144 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IDataObject
, (void**)&pIDataObject
);
1146 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1147 if ( SUCCEEDED( hr
) && pIDataObject
)
1148 return pIDataObject
->QueryGetData( pFormatetc
);
1155 STDMETHODIMP
InprocEmbedDocument_Impl::GetCanonicalFormatEtc( FORMATETC
* pFormatetcIn
, FORMATETC
* pFormatetcOut
)
1157 if ( CheckDefHandler() )
1159 ComSmart
< IDataObject
> pIDataObject
;
1160 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IDataObject
, (void**)&pIDataObject
);
1162 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1163 if ( SUCCEEDED( hr
) && pIDataObject
)
1164 return pIDataObject
->GetCanonicalFormatEtc( pFormatetcIn
, pFormatetcOut
);
1171 STDMETHODIMP
InprocEmbedDocument_Impl::SetData( FORMATETC
* pFormatetc
, STGMEDIUM
* pMedium
, BOOL fRelease
)
1173 if ( CheckDefHandler() )
1175 ComSmart
< IDataObject
> pIDataObject
;
1176 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IDataObject
, (void**)&pIDataObject
);
1178 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1179 if ( SUCCEEDED( hr
) && pIDataObject
)
1180 return pIDataObject
->SetData( pFormatetc
, pMedium
, fRelease
);
1187 STDMETHODIMP
InprocEmbedDocument_Impl::EnumFormatEtc( DWORD dwDirection
, IEnumFORMATETC
** ppFormatetc
)
1189 if ( CheckDefHandler() )
1191 ComSmart
< IDataObject
> pIDataObject
;
1192 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IDataObject
, (void**)&pIDataObject
);
1194 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1195 if ( SUCCEEDED( hr
) && pIDataObject
)
1196 return pIDataObject
->EnumFormatEtc( dwDirection
, ppFormatetc
);
1203 STDMETHODIMP
InprocEmbedDocument_Impl::DAdvise( FORMATETC
* pFormatetc
, DWORD advf
, IAdviseSink
* pAdvSink
, DWORD
* pdwConnection
)
1206 if ( !pdwConnection
)
1209 // avoid reusing of the old listener
1210 if ( m_pDefHandler
&& DEFAULT_ARRAY_LEN
> *pdwConnection
&& *pdwConnection
> 0 && m_pDataAdvises
[*pdwConnection
] )
1212 m_pDataAdvises
[*pdwConnection
]->DisconnectOrigAdvise();
1213 m_pDataAdvises
[*pdwConnection
] = NULL
;
1216 if ( pAdvSink
&& CheckDefHandler() )
1218 ComSmart
< IDataObject
> pIDataObject
;
1219 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IDataObject
, (void**)&pIDataObject
);
1221 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1222 if ( SUCCEEDED( hr
) && pIDataObject
)
1224 ComSmart
< OleWrapperAdviseSink
> pOwnAdvise( new OleWrapperAdviseSink( ComSmart
<IAdviseSink
>( pAdvSink
), pFormatetc
, advf
) );
1227 if ( SUCCEEDED( pIDataObject
->DAdvise( pFormatetc
, advf
, pOwnAdvise
, &nRegID
) ) && nRegID
> 0 )
1229 pOwnAdvise
->SetRegID( nRegID
);
1230 *pdwConnection
= InsertAdviseLinkToList( pOwnAdvise
, m_pDataAdvises
);
1231 if ( *pdwConnection
)
1234 pIDataObject
->DUnadvise( nRegID
);
1239 // return success always for now
1244 STDMETHODIMP
InprocEmbedDocument_Impl::DUnadvise( DWORD dwConnection
)
1246 if ( m_pDefHandler
&& DEFAULT_ARRAY_LEN
> dwConnection
&& dwConnection
> 0 && m_pDataAdvises
[dwConnection
] )
1248 if ( CheckDefHandler() )
1250 ComSmart
< IDataObject
> pIDataObject
;
1251 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IDataObject
, (void**)&pIDataObject
);
1253 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1254 if ( SUCCEEDED( hr
) && pIDataObject
)
1256 DWORD nID
= m_pDataAdvises
[dwConnection
]->GetRegID();
1257 pIDataObject
->DUnadvise( nID
);
1261 m_pDataAdvises
[dwConnection
]->DisconnectOrigAdvise();
1262 m_pDataAdvises
[dwConnection
] = NULL
;
1271 STDMETHODIMP
InprocEmbedDocument_Impl::EnumDAdvise( IEnumSTATDATA
** ppenumAdvise
)
1273 if ( CheckDefHandler() )
1275 ComSmart
< IDataObject
> pIDataObject
;
1276 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IDataObject
, (void**)&pIDataObject
);
1278 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1279 if ( SUCCEEDED( hr
) && pIDataObject
)
1280 return pIDataObject
->EnumDAdvise( ppenumAdvise
);
1288 STDMETHODIMP
InprocEmbedDocument_Impl::GetRunningClass( LPCLSID lpClsid
)
1290 if ( CheckDefHandler() )
1292 ComSmart
< IRunnableObject
> pIRunObj
;
1293 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IRunnableObject
, (void**)&pIRunObj
);
1295 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1296 if ( SUCCEEDED( hr
) && pIRunObj
)
1297 return pIRunObj
->GetRunningClass( lpClsid
);
1304 STDMETHODIMP
InprocEmbedDocument_Impl::Run( LPBINDCTX pbc
)
1306 if ( CheckDefHandler() )
1308 ComSmart
< IRunnableObject
> pIRunObj
;
1309 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IRunnableObject
, (void**)&pIRunObj
);
1311 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1312 if ( SUCCEEDED( hr
) && pIRunObj
)
1313 return pIRunObj
->Run( pbc
);
1320 BOOL STDMETHODCALLTYPE
InprocEmbedDocument_Impl::IsRunning()
1322 if ( CheckDefHandler() )
1324 ComSmart
< IRunnableObject
> pIRunObj
;
1325 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IRunnableObject
, (void**)&pIRunObj
);
1327 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1328 if ( SUCCEEDED( hr
) && pIRunObj
)
1329 return pIRunObj
->IsRunning();
1337 STDMETHODIMP
InprocEmbedDocument_Impl::LockRunning( BOOL fLock
, BOOL fLastUnlockCloses
)
1339 if ( CheckDefHandler() )
1341 ComSmart
< IRunnableObject
> pIRunObj
;
1342 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IRunnableObject
, (void**)&pIRunObj
);
1344 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1345 if ( SUCCEEDED( hr
) && pIRunObj
)
1346 return pIRunObj
->LockRunning( fLock
, fLastUnlockCloses
);
1353 STDMETHODIMP
InprocEmbedDocument_Impl::SetContainedObject( BOOL fContained
)
1355 if ( CheckDefHandler() )
1357 ComSmart
< IRunnableObject
> pIRunObj
;
1358 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IRunnableObject
, (void**)&pIRunObj
);
1360 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1361 if ( SUCCEEDED( hr
) && pIRunObj
)
1362 return pIRunObj
->SetContainedObject( fContained
);
1369 // IViewObject methods
1371 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
)
1373 if ( CheckDefHandler() )
1375 ComSmart
< IViewObject
> pIViewObject
;
1376 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IViewObject
, (void**)&pIViewObject
);
1378 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1379 if ( SUCCEEDED( hr
) && pIViewObject
)
1380 return pIViewObject
->Draw( dwDrawAspect
, lindex
, pvAspect
, ptd
, hdcTargetDev
, hdcDraw
, lprcBounds
, lprcWBounds
, pfnContinue
, dwContinue
);
1387 STDMETHODIMP
InprocEmbedDocument_Impl::GetColorSet( DWORD dwDrawAspect
, LONG lindex
, void *pvAspect
, DVTARGETDEVICE
*ptd
, HDC hicTargetDev
, LOGPALETTE
**ppColorSet
)
1389 if ( CheckDefHandler() )
1391 ComSmart
< IViewObject
> pIViewObject
;
1392 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IViewObject
, (void**)&pIViewObject
);
1394 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1395 if ( SUCCEEDED( hr
) && pIViewObject
)
1396 return pIViewObject
->GetColorSet( dwDrawAspect
, lindex
, pvAspect
, ptd
, hicTargetDev
, ppColorSet
);
1403 STDMETHODIMP
InprocEmbedDocument_Impl::Freeze( DWORD dwDrawAspect
, LONG lindex
, void *pvAspect
, DWORD
*pdwFreeze
)
1405 if ( CheckDefHandler() )
1407 ComSmart
< IViewObject
> pIViewObject
;
1408 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IViewObject
, (void**)&pIViewObject
);
1410 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1411 if ( SUCCEEDED( hr
) && pIViewObject
)
1412 return pIViewObject
->Freeze( dwDrawAspect
, lindex
, pvAspect
, pdwFreeze
);
1419 STDMETHODIMP
InprocEmbedDocument_Impl::Unfreeze( DWORD dwFreeze
)
1421 if ( CheckDefHandler() )
1423 ComSmart
< IViewObject
> pIViewObject
;
1424 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IViewObject
, (void**)&pIViewObject
);
1426 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1427 if ( SUCCEEDED( hr
) && pIViewObject
)
1428 return pIViewObject
->Unfreeze( dwFreeze
);
1435 STDMETHODIMP
InprocEmbedDocument_Impl::SetAdvise( DWORD aspects
, DWORD advf
, IAdviseSink
*pAdvSink
)
1438 // CheckDefHandler will set the listener, avoid reusing of old listener
1439 if ( m_pViewAdvise
)
1441 m_pViewAdvise
->DisconnectOrigAdvise();
1442 m_pViewAdvise
= NULL
;
1445 if ( pAdvSink
&& CheckDefHandler() )
1447 ComSmart
< IViewObject
> pIViewObject
;
1448 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IViewObject
, (void**)&pIViewObject
);
1450 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1451 if ( SUCCEEDED( hr
) && pIViewObject
)
1453 ComSmart
< OleWrapperAdviseSink
> pOwnAdvise( new OleWrapperAdviseSink( pAdvSink
, aspects
, advf
) );
1455 if ( SUCCEEDED( pIViewObject
->SetAdvise( aspects
, advf
, pOwnAdvise
) ) )
1457 m_pViewAdvise
= pOwnAdvise
;
1467 STDMETHODIMP
InprocEmbedDocument_Impl::GetAdvise( DWORD
*pAspects
, DWORD
*pAdvf
, IAdviseSink
**ppAdvSink
)
1470 return E_INVALIDARG
;
1472 if ( m_pViewAdvise
)
1475 *pAspects
= m_pViewAdvise
->GetAspect();
1478 *pAdvf
= m_pViewAdvise
->GetViewAdviseFlag();
1480 *ppAdvSink
= m_pViewAdvise
->GetOrigAdvise();
1482 (*ppAdvSink
)->AddRef();
1490 // IViewObject2 methods
1492 STDMETHODIMP
InprocEmbedDocument_Impl::GetExtent( DWORD dwDrawAspect
, LONG lindex
, DVTARGETDEVICE
*ptd
, LPSIZEL lpsizel
)
1494 if ( CheckDefHandler() )
1496 ComSmart
< IViewObject2
> pIViewObject2
;
1497 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IViewObject2
, (void**)&pIViewObject2
);
1499 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1500 if ( SUCCEEDED( hr
) && pIViewObject2
)
1501 return pIViewObject2
->GetExtent( dwDrawAspect
, lindex
, ptd
, lpsizel
);
1509 // IOleWindow methods
1511 STDMETHODIMP
InprocEmbedDocument_Impl::GetWindow( HWND
*phwnd
)
1513 if ( CheckDefHandler() )
1515 ComSmart
< IOleWindow
> pIOleWindow
;
1516 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleWindow
, (void**)&pIOleWindow
);
1518 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1519 if ( SUCCEEDED( hr
) && pIOleWindow
)
1520 return pIOleWindow
->GetWindow( phwnd
);
1527 STDMETHODIMP
InprocEmbedDocument_Impl::ContextSensitiveHelp( BOOL fEnterMode
)
1529 if ( CheckDefHandler() )
1531 ComSmart
< IOleWindow
> pIOleWindow
;
1532 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleWindow
, (void**)&pIOleWindow
);
1534 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1535 if ( SUCCEEDED( hr
) && pIOleWindow
)
1536 return pIOleWindow
->ContextSensitiveHelp( fEnterMode
);
1543 // IOleInPlaceObject methods
1545 STDMETHODIMP
InprocEmbedDocument_Impl::InPlaceDeactivate()
1547 if ( CheckDefHandler() )
1549 ComSmart
< IOleInPlaceObject
> pIOleInPlaceObject
;
1550 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleInPlaceObject
, (void**)&pIOleInPlaceObject
);
1552 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1553 if ( SUCCEEDED( hr
) && pIOleInPlaceObject
)
1554 return pIOleInPlaceObject
->InPlaceDeactivate();
1561 STDMETHODIMP
InprocEmbedDocument_Impl::UIDeactivate()
1563 if ( CheckDefHandler() )
1565 ComSmart
< IOleInPlaceObject
> pIOleInPlaceObject
;
1566 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleInPlaceObject
, (void**)&pIOleInPlaceObject
);
1568 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1569 if ( SUCCEEDED( hr
) && pIOleInPlaceObject
)
1570 return pIOleInPlaceObject
->UIDeactivate();
1577 STDMETHODIMP
InprocEmbedDocument_Impl::SetObjectRects( LPCRECT lprcPosRect
, LPCRECT lprcClipRect
)
1579 if ( CheckDefHandler() )
1581 ComSmart
< IOleInPlaceObject
> pIOleInPlaceObject
;
1582 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleInPlaceObject
, (void**)&pIOleInPlaceObject
);
1584 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1585 if ( SUCCEEDED( hr
) && pIOleInPlaceObject
)
1586 return pIOleInPlaceObject
->SetObjectRects( lprcPosRect
, lprcClipRect
);
1593 STDMETHODIMP
InprocEmbedDocument_Impl::ReactivateAndUndo()
1595 if ( CheckDefHandler() )
1597 ComSmart
< IOleInPlaceObject
> pIOleInPlaceObject
;
1598 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleInPlaceObject
, (void**)&pIOleInPlaceObject
);
1600 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1601 if ( SUCCEEDED( hr
) && pIOleInPlaceObject
)
1602 return pIOleInPlaceObject
->ReactivateAndUndo();
1609 // IDispatch methods
1611 STDMETHODIMP
InprocEmbedDocument_Impl::GetTypeInfoCount( UINT
*pctinfo
)
1613 if ( CheckDefHandler() )
1615 ComSmart
< IDispatch
> pIDispatch
;
1616 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IDispatch
, (void**)&pIDispatch
);
1618 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1619 if ( SUCCEEDED( hr
) && pIDispatch
)
1620 return pIDispatch
->GetTypeInfoCount( pctinfo
);
1627 STDMETHODIMP
InprocEmbedDocument_Impl::GetTypeInfo( UINT iTInfo
, LCID lcid
, ITypeInfo
**ppTInfo
)
1629 if ( CheckDefHandler() )
1631 ComSmart
< IDispatch
> pIDispatch
;
1632 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IDispatch
, (void**)&pIDispatch
);
1634 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1635 if ( SUCCEEDED( hr
) && pIDispatch
)
1636 return pIDispatch
->GetTypeInfo( iTInfo
, lcid
, ppTInfo
);
1643 STDMETHODIMP
InprocEmbedDocument_Impl::GetIDsOfNames( REFIID riid
, LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
1645 if ( CheckDefHandler() )
1647 ComSmart
< IDispatch
> pIDispatch
;
1648 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IDispatch
, (void**)&pIDispatch
);
1650 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1651 if ( SUCCEEDED( hr
) && pIDispatch
)
1652 return pIDispatch
->GetIDsOfNames( riid
, rgszNames
, cNames
, lcid
, rgDispId
);
1659 STDMETHODIMP
InprocEmbedDocument_Impl::Invoke( DISPID dispIdMember
, REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1661 if ( CheckDefHandler() )
1663 ComSmart
< IDispatch
> pIDispatch
;
1664 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IDispatch
, (void**)&pIDispatch
);
1666 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1667 if ( SUCCEEDED( hr
) && pIDispatch
)
1668 return pIDispatch
->Invoke( dispIdMember
, riid
, lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1676 // InternalCacheWrapper
1681 STDMETHODIMP
InprocEmbedDocument_Impl::InternalCacheWrapper::QueryInterface( REFIID riid
, void FAR
* FAR
* ppv
)
1683 return m_rOwnDocument
.QueryInterface( riid
, ppv
);
1687 STDMETHODIMP_(ULONG
) InprocEmbedDocument_Impl::InternalCacheWrapper::AddRef()
1689 return m_rOwnDocument
.AddRef();
1693 STDMETHODIMP_(ULONG
) InprocEmbedDocument_Impl::InternalCacheWrapper::Release()
1695 return m_rOwnDocument
.Release();
1698 // IOleCache methods
1700 STDMETHODIMP
InprocEmbedDocument_Impl::InternalCacheWrapper::Cache( FORMATETC
*pformatetc
, DWORD advf
, DWORD
*pdwConnection
)
1702 if ( m_rOwnDocument
.CheckDefHandler() )
1704 ComSmart
< IOleCache
> pIOleCache
;
1705 HRESULT hr
= m_rOwnDocument
.GetDefHandler()->QueryInterface( IID_IOleCache
, (void**)&pIOleCache
);
1707 ULONGGuard
aGuard( &m_rOwnDocument
.m_nCallsOnStack
); // avoid reentrance problem
1708 if ( SUCCEEDED( hr
) && pIOleCache
)
1709 return pIOleCache
->Cache( pformatetc
, advf
, pdwConnection
);
1716 STDMETHODIMP
InprocEmbedDocument_Impl::InternalCacheWrapper::Uncache( DWORD dwConnection
)
1718 if ( m_rOwnDocument
.CheckDefHandler() )
1720 ComSmart
< IOleCache
> pIOleCache
;
1721 HRESULT hr
= m_rOwnDocument
.GetDefHandler()->QueryInterface( IID_IOleCache
, (void**)&pIOleCache
);
1723 ULONGGuard
aGuard( &m_rOwnDocument
.m_nCallsOnStack
); // avoid reentrance problem
1724 if ( SUCCEEDED( hr
) && pIOleCache
)
1725 return pIOleCache
->Uncache( dwConnection
);
1732 STDMETHODIMP
InprocEmbedDocument_Impl::InternalCacheWrapper::EnumCache( IEnumSTATDATA
**ppenumSTATDATA
)
1734 if ( m_rOwnDocument
.CheckDefHandler() )
1736 ComSmart
< IOleCache
> pIOleCache
;
1737 HRESULT hr
= m_rOwnDocument
.GetDefHandler()->QueryInterface( IID_IOleCache
, (void**)&pIOleCache
);
1739 ULONGGuard
aGuard( &m_rOwnDocument
.m_nCallsOnStack
); // avoid reentrance problem
1740 if ( SUCCEEDED( hr
) && pIOleCache
)
1741 return pIOleCache
->EnumCache( ppenumSTATDATA
);
1748 STDMETHODIMP
InprocEmbedDocument_Impl::InternalCacheWrapper::InitCache( IDataObject
*pDataObject
)
1750 if ( m_rOwnDocument
.CheckDefHandler() )
1752 ComSmart
< IOleCache
> pIOleCache
;
1753 HRESULT hr
= m_rOwnDocument
.GetDefHandler()->QueryInterface( IID_IOleCache
, (void**)&pIOleCache
);
1755 ULONGGuard
aGuard( &m_rOwnDocument
.m_nCallsOnStack
); // avoid reentrance problem
1756 if ( SUCCEEDED( hr
) && pIOleCache
)
1757 return pIOleCache
->InitCache( pDataObject
);
1764 STDMETHODIMP
InprocEmbedDocument_Impl::InternalCacheWrapper::SetData( FORMATETC
*pformatetc
, STGMEDIUM
*pmedium
, BOOL fRelease
)
1766 if ( m_rOwnDocument
.CheckDefHandler() )
1768 ComSmart
< IOleCache
> pIOleCache
;
1769 HRESULT hr
= m_rOwnDocument
.GetDefHandler()->QueryInterface( IID_IOleCache
, (void**)&pIOleCache
);
1771 ULONGGuard
aGuard( &m_rOwnDocument
.m_nCallsOnStack
); // avoid reentrance problem
1772 if ( SUCCEEDED( hr
) && pIOleCache
)
1773 return pIOleCache
->SetData( pformatetc
, pmedium
, fRelease
);
1779 // IOleCache2 methods
1781 STDMETHODIMP
InprocEmbedDocument_Impl::InternalCacheWrapper::UpdateCache( LPDATAOBJECT pDataObject
, DWORD grfUpdf
, LPVOID pReserved
)
1783 if ( m_rOwnDocument
.CheckDefHandler() )
1785 ComSmart
< IOleCache2
> pIOleCache2
;
1786 HRESULT hr
= m_rOwnDocument
.GetDefHandler()->QueryInterface( IID_IOleCache2
, (void**)&pIOleCache2
);
1788 ULONGGuard
aGuard( &m_rOwnDocument
.m_nCallsOnStack
); // avoid reentrance problem
1789 if ( SUCCEEDED( hr
) && pIOleCache2
)
1790 return pIOleCache2
->UpdateCache( pDataObject
, grfUpdf
, pReserved
);
1797 STDMETHODIMP
InprocEmbedDocument_Impl::InternalCacheWrapper::DiscardCache( DWORD dwDiscardOptions
)
1799 if ( m_rOwnDocument
.CheckDefHandler() )
1801 ComSmart
< IOleCache2
> pIOleCache2
;
1802 HRESULT hr
= m_rOwnDocument
.GetDefHandler()->QueryInterface( IID_IOleCache2
, (void**)&pIOleCache2
);
1804 ULONGGuard
aGuard( &m_rOwnDocument
.m_nCallsOnStack
); // avoid reentrance problem
1805 if ( SUCCEEDED( hr
) && pIOleCache2
)
1806 return pIOleCache2
->DiscardCache( dwDiscardOptions
);
1812 }; // namespace inprocserv
1814 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */