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 <embservconst.h>
21 #include "inprocembobj.h"
26 //-------------------------------------------------------------------------------
27 BOOL
StringsEqual( LPCOLESTR pszNameFromOutside
, wchar_t* pOwnName
)
31 if ( pszNameFromOutside
&& pOwnName
)
33 for ( int nInd
= 0; pszNameFromOutside
[nInd
] != 0 || pOwnName
[nInd
] != 0; nInd
++ )
35 if ( pszNameFromOutside
[nInd
] != pOwnName
[nInd
] )
42 else if ( pszNameFromOutside
|| pOwnName
)
48 //-------------------------------------------------------------------------------
49 HRESULT
InprocEmbedDocument_Impl::Init()
54 //-------------------------------------------------------------------------------
55 void InprocEmbedDocument_Impl::SetName( LPCOLESTR pszNameFromOutside
, wchar_t*& pOwnName
)
57 if ( !pszNameFromOutside
)
62 while( pszNameFromOutside
[nLen
] != 0 )
71 pOwnName
= new wchar_t[nLen
+1];
72 for ( size_t nInd
= 0; nInd
< nLen
; nInd
++ )
73 pOwnName
[nInd
] = pszNameFromOutside
[nInd
];
77 //-------------------------------------------------------------------------------
78 BOOL
InprocEmbedDocument_Impl::CheckDefHandler()
80 // set the own listener
81 if ( m_pOleAdvises
[0] == NULL
)
83 m_pOleAdvises
[0] = new OleWrapperAdviseSink();
87 if ( m_pOleAdvises
[0]->IsClosed() )
91 // deregister all the listeners
93 ComSmart
< IOleObject
> pOleObject
;
94 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
95 if ( SUCCEEDED( hr
) && pOleObject
)
97 for ( DWORD nInd
= 0; nInd
< DEFAULT_ARRAY_LEN
; nInd
++ )
98 if ( m_pOleAdvises
[nInd
] )
100 DWORD nID
= m_pOleAdvises
[nInd
]->GetRegID();
101 pOleObject
->Unadvise( nID
);
102 m_pOleAdvises
[nInd
]->SetRegID( 0 );
105 pOleObject
->SetClientSite( NULL
);
108 ComSmart
< IDataObject
> pIDataObject
;
109 hr
= m_pDefHandler
->QueryInterface( IID_IDataObject
, (void**)&pIDataObject
);
110 if ( SUCCEEDED( hr
) && pIDataObject
)
112 for ( DWORD nInd
= 0; nInd
< DEFAULT_ARRAY_LEN
; nInd
++ )
113 if ( m_pDataAdvises
[nInd
] )
115 DWORD nID
= m_pDataAdvises
[nInd
]->GetRegID();
116 pIDataObject
->DUnadvise( nID
);
117 m_pDataAdvises
[nInd
]->SetRegID( 0 );
121 ComSmart
< IViewObject
> pIViewObject
;
122 hr
= m_pDefHandler
->QueryInterface( IID_IViewObject
, (void**)&pIViewObject
);
123 if ( SUCCEEDED( hr
) && pIViewObject
)
126 pIViewObject
->SetAdvise( m_pViewAdvise
->GetAspect(), m_pViewAdvise
->GetViewAdviseFlag(), NULL
);
129 ComSmart
< IPersistStorage
> pPersist
;
130 hr
= m_pDefHandler
->QueryInterface( IID_IPersistStorage
, (void**)&pPersist
);
131 if ( SUCCEEDED( hr
) && pPersist
)
133 // disconnect the old wrapper from the storage
134 pPersist
->HandsOffStorage();
137 m_pDefHandler
= NULL
;
140 m_pOleAdvises
[0]->UnsetClosed();
144 if ( m_nCallsOnStack
)
147 if ( !m_pDefHandler
)
149 // create a new default inprocess handler
150 HRESULT hr
= OleCreateDefaultHandler( m_guid
, NULL
, IID_IUnknown
, (void**)&m_pDefHandler
);
151 if ( SUCCEEDED( hr
) )
154 if ( m_nInitMode
== INIT_FROM_STORAGE
)
156 ComSmart
< IPersistStorage
> pPersist
;
157 hr
= m_pDefHandler
->QueryInterface( IID_IPersistStorage
, (void**)&pPersist
);
159 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
160 if ( SUCCEEDED( hr
) && pPersist
&& m_pStorage
)
161 hr
= pPersist
->InitNew( m_pStorage
);
163 else if ( m_nInitMode
== LOAD_FROM_STORAGE
)
165 ComSmart
< IPersistStorage
> pPersist
;
166 hr
= m_pDefHandler
->QueryInterface( IID_IPersistStorage
, (void**)&pPersist
);
168 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
169 if ( SUCCEEDED( hr
) && pPersist
&& m_pStorage
)
170 hr
= pPersist
->Load( m_pStorage
);
172 else if ( m_nInitMode
== LOAD_FROM_FILE
)
174 ComSmart
< IPersistFile
> pPersistFile
;
175 hr
= m_pDefHandler
->QueryInterface( IID_IPersistFile
, (void**)&pPersistFile
);
177 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
178 if ( SUCCEEDED( hr
) && pPersistFile
&& m_pFileName
)
179 hr
= pPersistFile
->Load( m_pFileName
, m_nFileOpenMode
);
184 if ( !SUCCEEDED( hr
) || !m_pDefHandler
)
186 m_pDefHandler
= NULL
;
190 // register all the listeners new
192 ComSmart
< IOleObject
> pOleObject
;
193 hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
194 if ( SUCCEEDED( hr
) && pOleObject
)
197 pOleObject
->SetClientSite( m_pClientSite
);
199 for ( DWORD nInd
= 0; nInd
< DEFAULT_ARRAY_LEN
; nInd
++ )
200 if ( m_pOleAdvises
[nInd
] )
203 if ( SUCCEEDED( pOleObject
->Advise( m_pOleAdvises
[nInd
], &nRegID
) ) && nRegID
> 0 )
204 m_pOleAdvises
[nInd
]->SetRegID( nRegID
);
208 ComSmart
< IDataObject
> pIDataObject
;
209 hr
= m_pDefHandler
->QueryInterface( IID_IDataObject
, (void**)&pIDataObject
);
210 if ( SUCCEEDED( hr
) && pIDataObject
)
212 for ( DWORD nInd
= 0; nInd
< DEFAULT_ARRAY_LEN
; nInd
++ )
213 if ( m_pDataAdvises
[nInd
] )
216 if ( SUCCEEDED( pIDataObject
->DAdvise( m_pDataAdvises
[nInd
]->GetFormatEtc(), m_pDataAdvises
[nInd
]->GetDataAdviseFlag(), m_pDataAdvises
[nInd
], &nRegID
) ) && nRegID
> 0 )
217 m_pDataAdvises
[nInd
]->SetRegID( nRegID
);
221 ComSmart
< IViewObject
> pIViewObject
;
222 hr
= m_pDefHandler
->QueryInterface( IID_IViewObject
, (void**)&pIViewObject
);
223 if ( SUCCEEDED( hr
) && pIViewObject
)
226 pIViewObject
->SetAdvise( m_pViewAdvise
->GetAspect(), m_pViewAdvise
->GetViewAdviseFlag(), m_pViewAdvise
);
234 //-------------------------------------------------------------------------------
235 DWORD
InprocEmbedDocument_Impl::InsertAdviseLinkToList( const ComSmart
<OleWrapperAdviseSink
>& pOwnAdvise
, ComSmart
< OleWrapperAdviseSink
> pAdvises
[] )
237 // the result should start from 1 in case of success, the element 0 can be used for own needs
242 for ( DWORD nInd
= 1; nInd
< DEFAULT_ARRAY_LEN
&& nResult
== 0; nInd
++ )
244 if ( pAdvises
[nInd
] == pOwnAdvise
)
248 else if ( pAdvises
[nInd
] == NULL
)
250 pAdvises
[nInd
] = pOwnAdvise
;
259 //-------------------------------------------------------------------------------
260 void InprocEmbedDocument_Impl::Clean()
262 m_pDefHandler
= (IUnknown
*)NULL
;
264 // no DisconnectOrigAdvise() call here, since it is no explicit disconnection
265 for ( DWORD nInd
= 0; nInd
< DEFAULT_ARRAY_LEN
; nInd
++ )
267 if ( m_pOleAdvises
[nInd
] )
269 ComSmart
< OleWrapperAdviseSink
> pAdvise
= m_pOleAdvises
[nInd
];
270 m_pOleAdvises
[nInd
] = NULL
;
273 if ( m_pDataAdvises
[nInd
] )
275 ComSmart
< OleWrapperAdviseSink
> pAdvise
= m_pDataAdvises
[nInd
];
276 m_pDataAdvises
[nInd
] = NULL
;
280 m_pViewAdvise
= NULL
;
282 m_nInitMode
= NOINIT
;
285 if ( m_pOleContainer
)
287 m_pOleContainer
->LockContainer( FALSE
);
288 m_pOleContainer
= NULL
;
291 m_pClientSite
= NULL
;
302 //-------------------------------------------------------------------------------
303 STDMETHODIMP
InprocEmbedDocument_Impl::QueryInterface( REFIID riid
, void FAR
* FAR
* ppv
)
305 if(IsEqualIID(riid
, IID_IUnknown
))
308 *ppv
= (IUnknown
*) (IPersistStorage
*) this;
311 else if (IsEqualIID(riid
, IID_IPersist
))
314 *ppv
= (IPersist
*) (IPersistStorage
*) this;
317 else if (IsEqualIID(riid
, IID_IPersistStorage
))
320 *ppv
= (IPersistStorage
*) this;
323 else if (IsEqualIID(riid
, IID_IDataObject
))
326 *ppv
= (IDataObject
*) this;
329 else if (IsEqualIID(riid
, IID_IOleObject
))
332 *ppv
= (IOleObject
*) this;
335 else if (IsEqualIID(riid
, IID_IPersistFile
))
338 *ppv
= (IPersistFile
*) this;
341 else if (IsEqualIID(riid
, IID_IRunnableObject
))
344 *ppv
= (IRunnableObject
*) this;
347 else if (IsEqualIID(riid
, IID_IViewObject
))
350 *ppv
= (IViewObject
*) this;
353 else if (IsEqualIID(riid
, IID_IViewObject2
))
356 *ppv
= (IViewObject2
*) this;
359 else if (IsEqualIID(riid
, IID_IOleCache
))
362 *ppv
= (IOleCache
*) &m_aInternalCache
;
365 else if (IsEqualIID(riid
, IID_IOleCache2
))
368 *ppv
= (IOleCache2
*) &m_aInternalCache
;
371 else if (IsEqualIID(riid
, IID_IOleWindow
))
374 *ppv
= (IOleWindow
*) this;
377 else if (IsEqualIID(riid
, IID_IOleInPlaceObject
))
380 *ppv
= (IOleInPlaceObject
*) this;
383 else if (IsEqualIID(riid
, IID_IDispatch
))
386 *ppv
= (IDispatch
*) this;
391 return ResultFromScode(E_NOINTERFACE
);
394 //-------------------------------------------------------------------------------
395 STDMETHODIMP_(ULONG
) InprocEmbedDocument_Impl::AddRef()
400 //-------------------------------------------------------------------------------
401 STDMETHODIMP_(ULONG
) InprocEmbedDocument_Impl::Release()
403 // unfortunately there are reentrance problems in mfc that have to be workarounded
404 sal_Int32 nCount
= m_refCount
> 0 ? --m_refCount
: 0;
405 if ( nCount
== 0 && !m_bDeleted
)
407 // deleting of this object can trigger deleting of mfc objects that will try to delete this object one more time
417 //-------------------------------------------------------------------------------
418 STDMETHODIMP
InprocEmbedDocument_Impl::GetClassID( CLSID
* pClassId
)
420 *pClassId
= *&m_guid
;
425 //-------------------------------------------------------------------------------
426 STDMETHODIMP
InprocEmbedDocument_Impl::IsDirty()
428 if ( m_pDefHandler
== NULL
|| m_pOleAdvises
[0] == NULL
|| m_pOleAdvises
[0]->IsClosed() )
431 if ( CheckDefHandler() )
433 ComSmart
< IPersistStorage
> pPersist
;
434 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IPersistStorage
, (void**)&pPersist
);
436 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
437 if ( SUCCEEDED( hr
) && pPersist
)
438 return pPersist
->IsDirty();
444 //-------------------------------------------------------------------------------
445 STDMETHODIMP
InprocEmbedDocument_Impl::InitNew( IStorage
*pStg
)
447 if ( CheckDefHandler() )
449 ComSmart
< IPersistStorage
> pPersist
;
450 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IPersistStorage
, (void**)&pPersist
);
452 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
453 if ( SUCCEEDED( hr
) && pPersist
)
455 hr
= pPersist
->InitNew( pStg
);
456 if ( SUCCEEDED( hr
) )
458 m_nInitMode
= INIT_FROM_STORAGE
;
464 delete[] m_pFileName
;
476 //-------------------------------------------------------------------------------
477 STDMETHODIMP
InprocEmbedDocument_Impl::Load( IStorage
*pStg
)
479 if ( CheckDefHandler() )
481 ComSmart
< IPersistStorage
> pPersist
;
482 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IPersistStorage
, (void**)&pPersist
);
484 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
485 if ( SUCCEEDED( hr
) && pPersist
)
487 hr
= pPersist
->Load( pStg
);
488 if ( SUCCEEDED( hr
) )
490 m_nInitMode
= LOAD_FROM_STORAGE
;
496 delete[] m_pFileName
;
508 //-------------------------------------------------------------------------------
509 STDMETHODIMP
InprocEmbedDocument_Impl::Save( IStorage
*pStgSave
, BOOL fSameAsLoad
)
511 if ( fSameAsLoad
&& ( m_pDefHandler
== NULL
|| m_pOleAdvises
[0] == NULL
|| m_pOleAdvises
[0]->IsClosed() ) )
514 if ( CheckDefHandler() )
516 ComSmart
< IPersistStorage
> pPersist
;
517 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IPersistStorage
, (void**)&pPersist
);
519 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
520 if ( SUCCEEDED( hr
) && pPersist
)
521 return pPersist
->Save( pStgSave
, fSameAsLoad
);
527 //-------------------------------------------------------------------------------
528 STDMETHODIMP
InprocEmbedDocument_Impl::SaveCompleted( IStorage
*pStgNew
)
530 if ( m_pDefHandler
== NULL
|| m_pOleAdvises
[0] == NULL
|| m_pOleAdvises
[0]->IsClosed() )
533 m_pStorage
= pStgNew
;
538 if ( CheckDefHandler() )
540 ComSmart
< IPersistStorage
> pPersist
;
541 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IPersistStorage
, (void**)&pPersist
);
543 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
544 if ( SUCCEEDED( hr
) && pPersist
)
546 hr
= pPersist
->SaveCompleted( pStgNew
);
547 if ( SUCCEEDED( hr
) )
549 m_nInitMode
= LOAD_FROM_STORAGE
;
552 m_pStorage
= pStgNew
;
558 delete[] m_pFileName
;
570 //-------------------------------------------------------------------------------
571 STDMETHODIMP
InprocEmbedDocument_Impl::HandsOffStorage()
573 if ( CheckDefHandler() )
575 ComSmart
< IPersistStorage
> pPersist
;
576 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IPersistStorage
, (void**)&pPersist
);
578 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
579 if ( SUCCEEDED( hr
) && pPersist
)
581 hr
= pPersist
->HandsOffStorage();
582 if ( SUCCEEDED( hr
) )
595 //-------------------------------------------------------------------------------
596 STDMETHODIMP
InprocEmbedDocument_Impl::Load( LPCOLESTR pszFileName
, DWORD dwMode
)
598 if ( CheckDefHandler() && pszFileName
)
600 ComSmart
< IPersistFile
> pPersist
;
601 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IPersistFile
, (void**)&pPersist
);
603 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
604 if ( SUCCEEDED( hr
) && pPersist
)
606 hr
= pPersist
->Load( pszFileName
, dwMode
);
607 if ( SUCCEEDED( hr
) )
609 m_nInitMode
= LOAD_FROM_FILE
;
613 m_nFileOpenMode
= dwMode
;
615 SetName( pszFileName
, m_pFileName
);
625 //-------------------------------------------------------------------------------
626 STDMETHODIMP
InprocEmbedDocument_Impl::Save( LPCOLESTR pszFileName
, BOOL fRemember
)
628 if ( CheckDefHandler() )
630 ComSmart
< IPersistFile
> pPersist
;
631 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IPersistFile
, (void**)&pPersist
);
633 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
634 if ( SUCCEEDED( hr
) && pPersist
)
635 return pPersist
->Save( pszFileName
, fRemember
);
641 //-------------------------------------------------------------------------------
642 STDMETHODIMP
InprocEmbedDocument_Impl::SaveCompleted( LPCOLESTR pszFileName
)
644 if ( CheckDefHandler() )
646 ComSmart
< IPersistFile
> pPersist
;
647 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IPersistFile
, (void**)&pPersist
);
649 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
650 if ( SUCCEEDED( hr
) && pPersist
)
652 hr
= pPersist
->SaveCompleted( pszFileName
);
653 if ( SUCCEEDED( hr
) )
655 m_nInitMode
= LOAD_FROM_STORAGE
;
659 m_nFileOpenMode
= STGM_READWRITE
; // was just written
661 SetName( pszFileName
, m_pFileName
);
670 //-------------------------------------------------------------------------------
671 STDMETHODIMP
InprocEmbedDocument_Impl::GetCurFile( LPOLESTR
*ppszFileName
)
673 if ( CheckDefHandler() )
675 ComSmart
< IPersistFile
> pPersist
;
676 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IPersistFile
, (void**)&pPersist
);
678 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
679 if ( SUCCEEDED( hr
) && pPersist
)
680 return pPersist
->GetCurFile( ppszFileName
);
687 //-------------------------------------------------------------------------------
688 STDMETHODIMP
InprocEmbedDocument_Impl::SetClientSite( IOleClientSite
* pSite
)
690 if ( pSite
== m_pClientSite
)
695 m_pClientSite
= NULL
;
696 if ( m_pOleContainer
)
698 m_pOleContainer
->LockContainer( FALSE
);
699 m_pOleContainer
= NULL
;
703 if ( CheckDefHandler() )
705 ComSmart
< IOleObject
> pOleObject
;
706 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
708 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
709 if ( SUCCEEDED( hr
) && pOleObject
)
711 HRESULT hr2
= pOleObject
->SetClientSite( pSite
);
712 if ( SUCCEEDED( hr2
) )
714 m_pClientSite
= pSite
;
716 if ( m_pOleContainer
)
718 m_pOleContainer
->LockContainer( FALSE
);
719 m_pOleContainer
= NULL
;
722 m_pClientSite
->GetContainer( &m_pOleContainer
);
723 if ( m_pOleContainer
)
724 m_pOleContainer
->LockContainer( TRUE
);
734 //-------------------------------------------------------------------------------
735 STDMETHODIMP
InprocEmbedDocument_Impl::GetClientSite( IOleClientSite
** pSite
)
737 if ( CheckDefHandler() )
739 ComSmart
< IOleObject
> pOleObject
;
740 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
742 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
743 if ( SUCCEEDED( hr
) && pOleObject
)
744 return pOleObject
->GetClientSite( pSite
);
750 //-------------------------------------------------------------------------------
751 STDMETHODIMP
InprocEmbedDocument_Impl::SetHostNames( LPCOLESTR szContainerApp
, LPCOLESTR szContainerObj
)
754 if ( CheckDefHandler() )
756 ComSmart
< IOleObject
> pOleObject
;
757 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
759 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
760 if ( SUCCEEDED( hr
) && pOleObject
)
762 hr
= pOleObject
->SetHostNames( szContainerApp
, szContainerObj
);
769 //-------------------------------------------------------------------------------
770 STDMETHODIMP
InprocEmbedDocument_Impl::Close( DWORD dwSaveOption
)
772 if ( m_pDefHandler
&& CheckDefHandler() )
774 // no need to close if there is no default handler.
775 ComSmart
< IOleObject
> pOleObject
;
776 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
778 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
779 if ( SUCCEEDED( hr
) && pOleObject
)
781 hr
= pOleObject
->Close( dwSaveOption
);
782 hr
= CoDisconnectObject( (IUnknown
*)(IPersistStorage
*)this, 0 );
786 // if the object is closed from outside that means that it should go to uninitialized state
792 //-------------------------------------------------------------------------------
793 STDMETHODIMP
InprocEmbedDocument_Impl::SetMoniker( DWORD dwWhichMoniker
, IMoniker
* pmk
)
795 if ( CheckDefHandler() )
797 ComSmart
< IOleObject
> pOleObject
;
798 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
800 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
801 if ( SUCCEEDED( hr
) && pOleObject
)
802 return pOleObject
->SetMoniker( dwWhichMoniker
, pmk
);
808 //-------------------------------------------------------------------------------
809 STDMETHODIMP
InprocEmbedDocument_Impl::GetMoniker( DWORD dwAssign
, DWORD dwWhichMoniker
, IMoniker
** ppmk
)
811 if ( CheckDefHandler() )
813 ComSmart
< IOleObject
> pOleObject
;
814 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
816 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
817 if ( SUCCEEDED( hr
) && pOleObject
)
818 return pOleObject
->GetMoniker( dwAssign
, dwWhichMoniker
, ppmk
);
824 //-------------------------------------------------------------------------------
825 STDMETHODIMP
InprocEmbedDocument_Impl::InitFromData( IDataObject
* pDataObject
, BOOL fCreation
, DWORD dwReserved
)
827 if ( CheckDefHandler() )
829 ComSmart
< IOleObject
> pOleObject
;
830 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
832 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
833 if ( SUCCEEDED( hr
) && pOleObject
)
834 return pOleObject
->InitFromData( pDataObject
, fCreation
, dwReserved
);
840 //-------------------------------------------------------------------------------
841 STDMETHODIMP
InprocEmbedDocument_Impl::GetClipboardData( DWORD dwReserved
, IDataObject
** ppDataObject
)
843 if ( CheckDefHandler() )
845 ComSmart
< IOleObject
> pOleObject
;
846 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
848 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
849 if ( SUCCEEDED( hr
) && pOleObject
)
850 return pOleObject
->GetClipboardData( dwReserved
, ppDataObject
);
856 //-------------------------------------------------------------------------------
857 STDMETHODIMP
InprocEmbedDocument_Impl::DoVerb(
860 IOleClientSite
*pActiveSite
,
865 if ( CheckDefHandler() )
867 ComSmart
< IOleObject
> pOleObject
;
868 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
870 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
871 if ( SUCCEEDED( hr
) && pOleObject
)
873 hr
= pOleObject
->DoVerb( iVerb
, pMsg
, pActiveSite
, nLong
, hWin
, pRect
);
874 if ( SUCCEEDED( hr
) )
886 //-------------------------------------------------------------------------------
887 STDMETHODIMP
InprocEmbedDocument_Impl::EnumVerbs( IEnumOLEVERB
** ppEnumOleVerb
)
889 if ( CheckDefHandler() )
891 ComSmart
< IOleObject
> pOleObject
;
892 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
894 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
895 if ( SUCCEEDED( hr
) && pOleObject
)
896 return pOleObject
->EnumVerbs( ppEnumOleVerb
);
902 //-------------------------------------------------------------------------------
903 STDMETHODIMP
InprocEmbedDocument_Impl::Update()
906 if ( m_pDefHandler
&& CheckDefHandler() )
908 ComSmart
< IOleObject
> pOleObject
;
909 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
911 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
912 if ( SUCCEEDED( hr
) && pOleObject
)
913 return pOleObject
->Update();
919 //-------------------------------------------------------------------------------
920 STDMETHODIMP
InprocEmbedDocument_Impl::IsUpToDate()
922 if ( CheckDefHandler() )
924 ComSmart
< IOleObject
> pOleObject
;
925 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
927 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
928 if ( SUCCEEDED( hr
) && pOleObject
)
929 return pOleObject
->IsUpToDate();
935 //-------------------------------------------------------------------------------
936 STDMETHODIMP
InprocEmbedDocument_Impl::GetUserClassID( CLSID
*pClsid
)
944 //-------------------------------------------------------------------------------
945 STDMETHODIMP
InprocEmbedDocument_Impl::GetUserType( DWORD dwFormOfType
, LPOLESTR
* pszUserType
)
947 if ( CheckDefHandler() )
949 ComSmart
< IOleObject
> pOleObject
;
950 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
952 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
953 if ( SUCCEEDED( hr
) && pOleObject
)
954 return pOleObject
->GetUserType( dwFormOfType
, pszUserType
);
960 //-------------------------------------------------------------------------------
961 STDMETHODIMP
InprocEmbedDocument_Impl::SetExtent( DWORD dwDrawAspect
, SIZEL
*psizel
)
963 if ( CheckDefHandler() )
965 ComSmart
< IOleObject
> pOleObject
;
966 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
968 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
969 if ( SUCCEEDED( hr
) && pOleObject
)
970 return pOleObject
->SetExtent( dwDrawAspect
, psizel
);
976 //-------------------------------------------------------------------------------
977 STDMETHODIMP
InprocEmbedDocument_Impl::GetExtent( DWORD dwDrawAspect
, SIZEL
* psizel
)
979 if ( CheckDefHandler() )
981 ComSmart
< IOleObject
> pOleObject
;
982 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
984 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
985 if ( SUCCEEDED( hr
) && pOleObject
)
986 return pOleObject
->GetExtent( dwDrawAspect
, psizel
);
992 //-------------------------------------------------------------------------------
993 STDMETHODIMP
InprocEmbedDocument_Impl::Advise( IAdviseSink
*pAdvSink
, DWORD
*pdwConnection
)
996 if ( !pdwConnection
)
999 // CheckDefHandler will set the listener, avoid reusing of old listener
1000 if ( DEFAULT_ARRAY_LEN
> *pdwConnection
&& *pdwConnection
> 0 && m_pOleAdvises
[*pdwConnection
] )
1002 m_pOleAdvises
[*pdwConnection
]->DisconnectOrigAdvise();
1003 m_pOleAdvises
[*pdwConnection
] = NULL
;
1006 if ( pAdvSink
&& CheckDefHandler() )
1008 ComSmart
< IOleObject
> pOleObject
;
1009 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
1011 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1012 if ( SUCCEEDED( hr
) && pOleObject
)
1014 ComSmart
< OleWrapperAdviseSink
> pOwnAdvise( new OleWrapperAdviseSink( pAdvSink
) );
1017 if ( SUCCEEDED( pOleObject
->Advise( pOwnAdvise
, &nRegID
) ) && nRegID
> 0 )
1019 pOwnAdvise
->SetRegID( nRegID
);
1020 *pdwConnection
= InsertAdviseLinkToList( pOwnAdvise
, m_pOleAdvises
);
1021 if ( *pdwConnection
)
1024 pOleObject
->Unadvise( nRegID
);
1029 // return success always for now
1033 //-------------------------------------------------------------------------------
1034 STDMETHODIMP
InprocEmbedDocument_Impl::Unadvise( DWORD dwConnection
)
1036 if ( DEFAULT_ARRAY_LEN
> dwConnection
&& dwConnection
> 0 && m_pOleAdvises
[dwConnection
] )
1038 if ( m_pDefHandler
)
1040 ComSmart
< IOleObject
> pOleObject
;
1041 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
1043 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1044 if ( SUCCEEDED( hr
) && pOleObject
)
1046 DWORD nID
= m_pOleAdvises
[dwConnection
]->GetRegID();
1047 pOleObject
->Unadvise( nID
);
1051 m_pOleAdvises
[dwConnection
]->DisconnectOrigAdvise();
1052 m_pOleAdvises
[dwConnection
] = NULL
;
1060 //-------------------------------------------------------------------------------
1061 STDMETHODIMP
InprocEmbedDocument_Impl::EnumAdvise( IEnumSTATDATA
** /*ppenumAdvise*/ )
1066 //-------------------------------------------------------------------------------
1067 STDMETHODIMP
InprocEmbedDocument_Impl::GetMiscStatus( DWORD dwAspect
, DWORD
* pdwStatus
)
1069 if ( CheckDefHandler() )
1071 ComSmart
< IOleObject
> pOleObject
;
1072 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
1074 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1075 if ( SUCCEEDED( hr
) && pOleObject
)
1076 return pOleObject
->GetMiscStatus( dwAspect
, pdwStatus
);
1082 //-------------------------------------------------------------------------------
1083 STDMETHODIMP
InprocEmbedDocument_Impl::SetColorScheme( LOGPALETTE
* pLogpal
)
1085 if ( CheckDefHandler() )
1087 ComSmart
< IOleObject
> pOleObject
;
1088 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleObject
, (void**)&pOleObject
);
1090 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1091 if ( SUCCEEDED( hr
) && pOleObject
)
1092 return pOleObject
->SetColorScheme( pLogpal
);
1099 //-------------------------------------------------------------------------------
1100 STDMETHODIMP
InprocEmbedDocument_Impl::GetData( FORMATETC
* pFormatetc
, STGMEDIUM
* pMedium
)
1102 if ( CheckDefHandler() )
1104 ComSmart
< IDataObject
> pIDataObject
;
1105 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IDataObject
, (void**)&pIDataObject
);
1107 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1108 if ( SUCCEEDED( hr
) && pIDataObject
)
1109 return pIDataObject
->GetData( pFormatetc
, pMedium
);
1115 //-------------------------------------------------------------------------------
1116 STDMETHODIMP
InprocEmbedDocument_Impl::GetDataHere( FORMATETC
* pFormatetc
, STGMEDIUM
* pMedium
)
1118 if ( CheckDefHandler() )
1120 ComSmart
< IDataObject
> pIDataObject
;
1121 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IDataObject
, (void**)&pIDataObject
);
1123 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1124 if ( SUCCEEDED( hr
) && pIDataObject
)
1125 return pIDataObject
->GetDataHere( pFormatetc
, pMedium
);
1131 //-------------------------------------------------------------------------------
1132 STDMETHODIMP
InprocEmbedDocument_Impl::QueryGetData( FORMATETC
* pFormatetc
)
1134 if ( CheckDefHandler() )
1136 ComSmart
< IDataObject
> pIDataObject
;
1137 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IDataObject
, (void**)&pIDataObject
);
1139 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1140 if ( SUCCEEDED( hr
) && pIDataObject
)
1141 return pIDataObject
->QueryGetData( pFormatetc
);
1147 //-------------------------------------------------------------------------------
1148 STDMETHODIMP
InprocEmbedDocument_Impl::GetCanonicalFormatEtc( FORMATETC
* pFormatetcIn
, FORMATETC
* pFormatetcOut
)
1150 if ( CheckDefHandler() )
1152 ComSmart
< IDataObject
> pIDataObject
;
1153 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IDataObject
, (void**)&pIDataObject
);
1155 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1156 if ( SUCCEEDED( hr
) && pIDataObject
)
1157 return pIDataObject
->GetCanonicalFormatEtc( pFormatetcIn
, pFormatetcOut
);
1163 //-------------------------------------------------------------------------------
1164 STDMETHODIMP
InprocEmbedDocument_Impl::SetData( FORMATETC
* pFormatetc
, STGMEDIUM
* pMedium
, BOOL fRelease
)
1166 if ( CheckDefHandler() )
1168 ComSmart
< IDataObject
> pIDataObject
;
1169 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IDataObject
, (void**)&pIDataObject
);
1171 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1172 if ( SUCCEEDED( hr
) && pIDataObject
)
1173 return pIDataObject
->SetData( pFormatetc
, pMedium
, fRelease
);
1179 //-------------------------------------------------------------------------------
1180 STDMETHODIMP
InprocEmbedDocument_Impl::EnumFormatEtc( DWORD dwDirection
, IEnumFORMATETC
** ppFormatetc
)
1182 if ( CheckDefHandler() )
1184 ComSmart
< IDataObject
> pIDataObject
;
1185 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IDataObject
, (void**)&pIDataObject
);
1187 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1188 if ( SUCCEEDED( hr
) && pIDataObject
)
1189 return pIDataObject
->EnumFormatEtc( dwDirection
, ppFormatetc
);
1195 //-------------------------------------------------------------------------------
1196 STDMETHODIMP
InprocEmbedDocument_Impl::DAdvise( FORMATETC
* pFormatetc
, DWORD advf
, IAdviseSink
* pAdvSink
, DWORD
* pdwConnection
)
1199 if ( !pdwConnection
)
1202 // avoid reusing of the old listener
1203 if ( m_pDefHandler
&& DEFAULT_ARRAY_LEN
> *pdwConnection
&& *pdwConnection
> 0 && m_pDataAdvises
[*pdwConnection
] )
1205 m_pDataAdvises
[*pdwConnection
]->DisconnectOrigAdvise();
1206 m_pDataAdvises
[*pdwConnection
] = NULL
;
1209 if ( pAdvSink
&& CheckDefHandler() )
1211 ComSmart
< IDataObject
> pIDataObject
;
1212 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IDataObject
, (void**)&pIDataObject
);
1214 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1215 if ( SUCCEEDED( hr
) && pIDataObject
)
1217 ComSmart
< OleWrapperAdviseSink
> pOwnAdvise( new OleWrapperAdviseSink( ComSmart
<IAdviseSink
>( pAdvSink
), pFormatetc
, advf
) );
1220 if ( SUCCEEDED( pIDataObject
->DAdvise( pFormatetc
, advf
, pOwnAdvise
, &nRegID
) ) && nRegID
> 0 )
1222 pOwnAdvise
->SetRegID( nRegID
);
1223 *pdwConnection
= InsertAdviseLinkToList( pOwnAdvise
, m_pDataAdvises
);
1224 if ( *pdwConnection
)
1227 pIDataObject
->DUnadvise( nRegID
);
1232 // return success always for now
1236 //-------------------------------------------------------------------------------
1237 STDMETHODIMP
InprocEmbedDocument_Impl::DUnadvise( DWORD dwConnection
)
1239 if ( m_pDefHandler
&& DEFAULT_ARRAY_LEN
> dwConnection
&& dwConnection
> 0 && m_pDataAdvises
[dwConnection
] )
1241 if ( CheckDefHandler() )
1243 ComSmart
< IDataObject
> pIDataObject
;
1244 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IDataObject
, (void**)&pIDataObject
);
1246 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1247 if ( SUCCEEDED( hr
) && pIDataObject
)
1249 DWORD nID
= m_pDataAdvises
[dwConnection
]->GetRegID();
1250 pIDataObject
->DUnadvise( nID
);
1254 m_pDataAdvises
[dwConnection
]->DisconnectOrigAdvise();
1255 m_pDataAdvises
[dwConnection
] = NULL
;
1263 //-------------------------------------------------------------------------------
1264 STDMETHODIMP
InprocEmbedDocument_Impl::EnumDAdvise( IEnumSTATDATA
** ppenumAdvise
)
1266 if ( CheckDefHandler() )
1268 ComSmart
< IDataObject
> pIDataObject
;
1269 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IDataObject
, (void**)&pIDataObject
);
1271 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1272 if ( SUCCEEDED( hr
) && pIDataObject
)
1273 return pIDataObject
->EnumDAdvise( ppenumAdvise
);
1280 //-------------------------------------------------------------------------------
1281 STDMETHODIMP
InprocEmbedDocument_Impl::GetRunningClass( LPCLSID lpClsid
)
1283 if ( CheckDefHandler() )
1285 ComSmart
< IRunnableObject
> pIRunObj
;
1286 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IRunnableObject
, (void**)&pIRunObj
);
1288 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1289 if ( SUCCEEDED( hr
) && pIRunObj
)
1290 return pIRunObj
->GetRunningClass( lpClsid
);
1296 //-------------------------------------------------------------------------------
1297 STDMETHODIMP
InprocEmbedDocument_Impl::Run( LPBINDCTX pbc
)
1299 if ( CheckDefHandler() )
1301 ComSmart
< IRunnableObject
> pIRunObj
;
1302 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IRunnableObject
, (void**)&pIRunObj
);
1304 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1305 if ( SUCCEEDED( hr
) && pIRunObj
)
1306 return pIRunObj
->Run( pbc
);
1312 //-------------------------------------------------------------------------------
1313 BOOL STDMETHODCALLTYPE
InprocEmbedDocument_Impl::IsRunning()
1315 if ( CheckDefHandler() )
1317 ComSmart
< IRunnableObject
> pIRunObj
;
1318 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IRunnableObject
, (void**)&pIRunObj
);
1320 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1321 if ( SUCCEEDED( hr
) && pIRunObj
)
1322 return pIRunObj
->IsRunning();
1329 //-------------------------------------------------------------------------------
1330 STDMETHODIMP
InprocEmbedDocument_Impl::LockRunning( BOOL fLock
, BOOL fLastUnlockCloses
)
1332 if ( CheckDefHandler() )
1334 ComSmart
< IRunnableObject
> pIRunObj
;
1335 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IRunnableObject
, (void**)&pIRunObj
);
1337 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1338 if ( SUCCEEDED( hr
) && pIRunObj
)
1339 return pIRunObj
->LockRunning( fLock
, fLastUnlockCloses
);
1345 //-------------------------------------------------------------------------------
1346 STDMETHODIMP
InprocEmbedDocument_Impl::SetContainedObject( BOOL fContained
)
1348 if ( CheckDefHandler() )
1350 ComSmart
< IRunnableObject
> pIRunObj
;
1351 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IRunnableObject
, (void**)&pIRunObj
);
1353 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1354 if ( SUCCEEDED( hr
) && pIRunObj
)
1355 return pIRunObj
->SetContainedObject( fContained
);
1362 // IViewObject methods
1363 //-------------------------------------------------------------------------------
1364 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
)
1366 if ( CheckDefHandler() )
1368 ComSmart
< IViewObject
> pIViewObject
;
1369 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IViewObject
, (void**)&pIViewObject
);
1371 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1372 if ( SUCCEEDED( hr
) && pIViewObject
)
1373 return pIViewObject
->Draw( dwDrawAspect
, lindex
, pvAspect
, ptd
, hdcTargetDev
, hdcDraw
, lprcBounds
, lprcWBounds
, pfnContinue
, dwContinue
);
1379 //-------------------------------------------------------------------------------
1380 STDMETHODIMP
InprocEmbedDocument_Impl::GetColorSet( DWORD dwDrawAspect
, LONG lindex
, void *pvAspect
, DVTARGETDEVICE
*ptd
, HDC hicTargetDev
, LOGPALETTE
**ppColorSet
)
1382 if ( CheckDefHandler() )
1384 ComSmart
< IViewObject
> pIViewObject
;
1385 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IViewObject
, (void**)&pIViewObject
);
1387 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1388 if ( SUCCEEDED( hr
) && pIViewObject
)
1389 return pIViewObject
->GetColorSet( dwDrawAspect
, lindex
, pvAspect
, ptd
, hicTargetDev
, ppColorSet
);
1395 //-------------------------------------------------------------------------------
1396 STDMETHODIMP
InprocEmbedDocument_Impl::Freeze( DWORD dwDrawAspect
, LONG lindex
, void *pvAspect
, DWORD
*pdwFreeze
)
1398 if ( CheckDefHandler() )
1400 ComSmart
< IViewObject
> pIViewObject
;
1401 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IViewObject
, (void**)&pIViewObject
);
1403 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1404 if ( SUCCEEDED( hr
) && pIViewObject
)
1405 return pIViewObject
->Freeze( dwDrawAspect
, lindex
, pvAspect
, pdwFreeze
);
1411 //-------------------------------------------------------------------------------
1412 STDMETHODIMP
InprocEmbedDocument_Impl::Unfreeze( DWORD dwFreeze
)
1414 if ( CheckDefHandler() )
1416 ComSmart
< IViewObject
> pIViewObject
;
1417 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IViewObject
, (void**)&pIViewObject
);
1419 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1420 if ( SUCCEEDED( hr
) && pIViewObject
)
1421 return pIViewObject
->Unfreeze( dwFreeze
);
1427 //-------------------------------------------------------------------------------
1428 STDMETHODIMP
InprocEmbedDocument_Impl::SetAdvise( DWORD aspects
, DWORD advf
, IAdviseSink
*pAdvSink
)
1431 // CheckDefHandler will set the listener, avoid reusing of old listener
1432 if ( m_pViewAdvise
)
1434 m_pViewAdvise
->DisconnectOrigAdvise();
1435 m_pViewAdvise
= NULL
;
1438 if ( pAdvSink
&& CheckDefHandler() )
1440 ComSmart
< IViewObject
> pIViewObject
;
1441 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IViewObject
, (void**)&pIViewObject
);
1443 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1444 if ( SUCCEEDED( hr
) && pIViewObject
)
1446 ComSmart
< OleWrapperAdviseSink
> pOwnAdvise( new OleWrapperAdviseSink( pAdvSink
, aspects
, advf
) );
1448 if ( SUCCEEDED( pIViewObject
->SetAdvise( aspects
, advf
, pOwnAdvise
) ) )
1450 m_pViewAdvise
= pOwnAdvise
;
1459 //-------------------------------------------------------------------------------
1460 STDMETHODIMP
InprocEmbedDocument_Impl::GetAdvise( DWORD
*pAspects
, DWORD
*pAdvf
, IAdviseSink
**ppAdvSink
)
1463 return E_INVALIDARG
;
1465 if ( m_pViewAdvise
)
1468 *pAspects
= m_pViewAdvise
->GetAspect();
1471 *pAdvf
= m_pViewAdvise
->GetViewAdviseFlag();
1473 *ppAdvSink
= m_pViewAdvise
->GetOrigAdvise();
1475 (*ppAdvSink
)->AddRef();
1483 // IViewObject2 methods
1484 //-------------------------------------------------------------------------------
1485 STDMETHODIMP
InprocEmbedDocument_Impl::GetExtent( DWORD dwDrawAspect
, LONG lindex
, DVTARGETDEVICE
*ptd
, LPSIZEL lpsizel
)
1487 if ( CheckDefHandler() )
1489 ComSmart
< IViewObject2
> pIViewObject2
;
1490 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IViewObject2
, (void**)&pIViewObject2
);
1492 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1493 if ( SUCCEEDED( hr
) && pIViewObject2
)
1494 return pIViewObject2
->GetExtent( dwDrawAspect
, lindex
, ptd
, lpsizel
);
1502 // IOleWindow methods
1503 //-------------------------------------------------------------------------------
1504 STDMETHODIMP
InprocEmbedDocument_Impl::GetWindow( HWND
*phwnd
)
1506 if ( CheckDefHandler() )
1508 ComSmart
< IOleWindow
> pIOleWindow
;
1509 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleWindow
, (void**)&pIOleWindow
);
1511 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1512 if ( SUCCEEDED( hr
) && pIOleWindow
)
1513 return pIOleWindow
->GetWindow( phwnd
);
1519 //-------------------------------------------------------------------------------
1520 STDMETHODIMP
InprocEmbedDocument_Impl::ContextSensitiveHelp( BOOL fEnterMode
)
1522 if ( CheckDefHandler() )
1524 ComSmart
< IOleWindow
> pIOleWindow
;
1525 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleWindow
, (void**)&pIOleWindow
);
1527 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1528 if ( SUCCEEDED( hr
) && pIOleWindow
)
1529 return pIOleWindow
->ContextSensitiveHelp( fEnterMode
);
1536 // IOleInPlaceObject methods
1537 //-------------------------------------------------------------------------------
1538 STDMETHODIMP
InprocEmbedDocument_Impl::InPlaceDeactivate( void )
1540 if ( CheckDefHandler() )
1542 ComSmart
< IOleInPlaceObject
> pIOleInPlaceObject
;
1543 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleInPlaceObject
, (void**)&pIOleInPlaceObject
);
1545 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1546 if ( SUCCEEDED( hr
) && pIOleInPlaceObject
)
1547 return pIOleInPlaceObject
->InPlaceDeactivate();
1553 //-------------------------------------------------------------------------------
1554 STDMETHODIMP
InprocEmbedDocument_Impl::UIDeactivate( void )
1556 if ( CheckDefHandler() )
1558 ComSmart
< IOleInPlaceObject
> pIOleInPlaceObject
;
1559 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleInPlaceObject
, (void**)&pIOleInPlaceObject
);
1561 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1562 if ( SUCCEEDED( hr
) && pIOleInPlaceObject
)
1563 return pIOleInPlaceObject
->UIDeactivate();
1569 //-------------------------------------------------------------------------------
1570 STDMETHODIMP
InprocEmbedDocument_Impl::SetObjectRects( LPCRECT lprcPosRect
, LPCRECT lprcClipRect
)
1572 if ( CheckDefHandler() )
1574 ComSmart
< IOleInPlaceObject
> pIOleInPlaceObject
;
1575 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleInPlaceObject
, (void**)&pIOleInPlaceObject
);
1577 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1578 if ( SUCCEEDED( hr
) && pIOleInPlaceObject
)
1579 return pIOleInPlaceObject
->SetObjectRects( lprcPosRect
, lprcClipRect
);
1585 //-------------------------------------------------------------------------------
1586 STDMETHODIMP
InprocEmbedDocument_Impl::ReactivateAndUndo( void )
1588 if ( CheckDefHandler() )
1590 ComSmart
< IOleInPlaceObject
> pIOleInPlaceObject
;
1591 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IOleInPlaceObject
, (void**)&pIOleInPlaceObject
);
1593 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1594 if ( SUCCEEDED( hr
) && pIOleInPlaceObject
)
1595 return pIOleInPlaceObject
->ReactivateAndUndo();
1602 // IDispatch methods
1603 //-------------------------------------------------------------------------------
1604 STDMETHODIMP
InprocEmbedDocument_Impl::GetTypeInfoCount( UINT
*pctinfo
)
1606 if ( CheckDefHandler() )
1608 ComSmart
< IDispatch
> pIDispatch
;
1609 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IDispatch
, (void**)&pIDispatch
);
1611 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1612 if ( SUCCEEDED( hr
) && pIDispatch
)
1613 return pIDispatch
->GetTypeInfoCount( pctinfo
);
1619 //-------------------------------------------------------------------------------
1620 STDMETHODIMP
InprocEmbedDocument_Impl::GetTypeInfo( UINT iTInfo
, LCID lcid
, ITypeInfo
**ppTInfo
)
1622 if ( CheckDefHandler() )
1624 ComSmart
< IDispatch
> pIDispatch
;
1625 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IDispatch
, (void**)&pIDispatch
);
1627 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1628 if ( SUCCEEDED( hr
) && pIDispatch
)
1629 return pIDispatch
->GetTypeInfo( iTInfo
, lcid
, ppTInfo
);
1635 //-------------------------------------------------------------------------------
1636 STDMETHODIMP
InprocEmbedDocument_Impl::GetIDsOfNames( REFIID riid
, LPOLESTR
*rgszNames
, UINT cNames
, LCID lcid
, DISPID
*rgDispId
)
1638 if ( CheckDefHandler() )
1640 ComSmart
< IDispatch
> pIDispatch
;
1641 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IDispatch
, (void**)&pIDispatch
);
1643 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1644 if ( SUCCEEDED( hr
) && pIDispatch
)
1645 return pIDispatch
->GetIDsOfNames( riid
, rgszNames
, cNames
, lcid
, rgDispId
);
1651 //-------------------------------------------------------------------------------
1652 STDMETHODIMP
InprocEmbedDocument_Impl::Invoke( DISPID dispIdMember
, REFIID riid
, LCID lcid
, WORD wFlags
, DISPPARAMS
*pDispParams
, VARIANT
*pVarResult
, EXCEPINFO
*pExcepInfo
, UINT
*puArgErr
)
1654 if ( CheckDefHandler() )
1656 ComSmart
< IDispatch
> pIDispatch
;
1657 HRESULT hr
= m_pDefHandler
->QueryInterface( IID_IDispatch
, (void**)&pIDispatch
);
1659 ULONGGuard
aGuard( &m_nCallsOnStack
); // avoid reentrance problem
1660 if ( SUCCEEDED( hr
) && pIDispatch
)
1661 return pIDispatch
->Invoke( dispIdMember
, riid
, lcid
, wFlags
, pDispParams
, pVarResult
, pExcepInfo
, puArgErr
);
1669 // InternalCacheWrapper
1673 //-------------------------------------------------------------------------------
1674 STDMETHODIMP
InprocEmbedDocument_Impl::InternalCacheWrapper::QueryInterface( REFIID riid
, void FAR
* FAR
* ppv
)
1676 return m_rOwnDocument
.QueryInterface( riid
, ppv
);
1679 //-------------------------------------------------------------------------------
1680 STDMETHODIMP_(ULONG
) InprocEmbedDocument_Impl::InternalCacheWrapper::AddRef()
1682 return m_rOwnDocument
.AddRef();
1685 //-------------------------------------------------------------------------------
1686 STDMETHODIMP_(ULONG
) InprocEmbedDocument_Impl::InternalCacheWrapper::Release()
1688 return m_rOwnDocument
.Release();
1691 // IOleCache methods
1692 //-------------------------------------------------------------------------------
1693 STDMETHODIMP
InprocEmbedDocument_Impl::InternalCacheWrapper::Cache( FORMATETC
*pformatetc
, DWORD advf
, DWORD
*pdwConnection
)
1695 if ( m_rOwnDocument
.CheckDefHandler() )
1697 ComSmart
< IOleCache
> pIOleCache
;
1698 HRESULT hr
= m_rOwnDocument
.GetDefHandler()->QueryInterface( IID_IOleCache
, (void**)&pIOleCache
);
1700 ULONGGuard
aGuard( &m_rOwnDocument
.m_nCallsOnStack
); // avoid reentrance problem
1701 if ( SUCCEEDED( hr
) && pIOleCache
)
1702 return pIOleCache
->Cache( pformatetc
, advf
, pdwConnection
);
1708 //-------------------------------------------------------------------------------
1709 STDMETHODIMP
InprocEmbedDocument_Impl::InternalCacheWrapper::Uncache( DWORD dwConnection
)
1711 if ( m_rOwnDocument
.CheckDefHandler() )
1713 ComSmart
< IOleCache
> pIOleCache
;
1714 HRESULT hr
= m_rOwnDocument
.GetDefHandler()->QueryInterface( IID_IOleCache
, (void**)&pIOleCache
);
1716 ULONGGuard
aGuard( &m_rOwnDocument
.m_nCallsOnStack
); // avoid reentrance problem
1717 if ( SUCCEEDED( hr
) && pIOleCache
)
1718 return pIOleCache
->Uncache( dwConnection
);
1724 //-------------------------------------------------------------------------------
1725 STDMETHODIMP
InprocEmbedDocument_Impl::InternalCacheWrapper::EnumCache( IEnumSTATDATA
**ppenumSTATDATA
)
1727 if ( m_rOwnDocument
.CheckDefHandler() )
1729 ComSmart
< IOleCache
> pIOleCache
;
1730 HRESULT hr
= m_rOwnDocument
.GetDefHandler()->QueryInterface( IID_IOleCache
, (void**)&pIOleCache
);
1732 ULONGGuard
aGuard( &m_rOwnDocument
.m_nCallsOnStack
); // avoid reentrance problem
1733 if ( SUCCEEDED( hr
) && pIOleCache
)
1734 return pIOleCache
->EnumCache( ppenumSTATDATA
);
1740 //-------------------------------------------------------------------------------
1741 STDMETHODIMP
InprocEmbedDocument_Impl::InternalCacheWrapper::InitCache( IDataObject
*pDataObject
)
1743 if ( m_rOwnDocument
.CheckDefHandler() )
1745 ComSmart
< IOleCache
> pIOleCache
;
1746 HRESULT hr
= m_rOwnDocument
.GetDefHandler()->QueryInterface( IID_IOleCache
, (void**)&pIOleCache
);
1748 ULONGGuard
aGuard( &m_rOwnDocument
.m_nCallsOnStack
); // avoid reentrance problem
1749 if ( SUCCEEDED( hr
) && pIOleCache
)
1750 return pIOleCache
->InitCache( pDataObject
);
1756 //-------------------------------------------------------------------------------
1757 STDMETHODIMP
InprocEmbedDocument_Impl::InternalCacheWrapper::SetData( FORMATETC
*pformatetc
, STGMEDIUM
*pmedium
, BOOL fRelease
)
1759 if ( m_rOwnDocument
.CheckDefHandler() )
1761 ComSmart
< IOleCache
> pIOleCache
;
1762 HRESULT hr
= m_rOwnDocument
.GetDefHandler()->QueryInterface( IID_IOleCache
, (void**)&pIOleCache
);
1764 ULONGGuard
aGuard( &m_rOwnDocument
.m_nCallsOnStack
); // avoid reentrance problem
1765 if ( SUCCEEDED( hr
) && pIOleCache
)
1766 return pIOleCache
->SetData( pformatetc
, pmedium
, fRelease
);
1772 // IOleCache2 methods
1773 //-------------------------------------------------------------------------------
1774 STDMETHODIMP
InprocEmbedDocument_Impl::InternalCacheWrapper::UpdateCache( LPDATAOBJECT pDataObject
, DWORD grfUpdf
, LPVOID pReserved
)
1776 if ( m_rOwnDocument
.CheckDefHandler() )
1778 ComSmart
< IOleCache2
> pIOleCache2
;
1779 HRESULT hr
= m_rOwnDocument
.GetDefHandler()->QueryInterface( IID_IOleCache2
, (void**)&pIOleCache2
);
1781 ULONGGuard
aGuard( &m_rOwnDocument
.m_nCallsOnStack
); // avoid reentrance problem
1782 if ( SUCCEEDED( hr
) && pIOleCache2
)
1783 return pIOleCache2
->UpdateCache( pDataObject
, grfUpdf
, pReserved
);
1789 //-------------------------------------------------------------------------------
1790 STDMETHODIMP
InprocEmbedDocument_Impl::InternalCacheWrapper::DiscardCache( DWORD dwDiscardOptions
)
1792 if ( m_rOwnDocument
.CheckDefHandler() )
1794 ComSmart
< IOleCache2
> pIOleCache2
;
1795 HRESULT hr
= m_rOwnDocument
.GetDefHandler()->QueryInterface( IID_IOleCache2
, (void**)&pIOleCache2
);
1797 ULONGGuard
aGuard( &m_rOwnDocument
.m_nCallsOnStack
); // avoid reentrance problem
1798 if ( SUCCEEDED( hr
) && pIOleCache2
)
1799 return pIOleCache2
->DiscardCache( dwDiscardOptions
);
1805 }; // namespace inprocserv
1807 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */