Update to m13
[ooovba.git] / embedserv / source / inprocserv / inprocembobj.cxx
blob7cbaa5a8dc3e1489b44a7ba93b05c9e73192ba53
1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: inprocembobj.cxx,v $
7 * $Revision: 1.1.8.2 $
9 * last change: $Author: mav $ $Date: 2008/10/30 11:59:06 $
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
15 * GNU Lesser General Public License Version 2.1
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License version 2.1, as published by the Free Software Foundation.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 * MA 02111-1307 USA
34 ************************************************************************/
36 #include <embservconst.h>
37 #include "inprocembobj.h"
39 namespace inprocserv
42 #ifdef OWNDEBUG
43 //-------------------------------------------------------------------------------
44 void WriteDebugInfo( DWORD pThis, char* pString, DWORD nToWrite )
46 if ( nToWrite )
48 char pNumber[12];
49 pNumber[0] = '0';
50 pNumber[1] = 'x';
51 for ( int nInd = 0; nInd < 8; nInd++ )
52 pNumber[nInd+2] = (char)( ( pThis / ( 1 << ( 7 - nInd ) ) ) % 16 ) + 48;
53 pNumber[10] = ' ';
54 pNumber[11] = 0;
56 HANDLE pFile = CreateFileA( "h:\\inproc.log", GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, 0, NULL );
57 if ( pFile )
59 DWORD dwWritten = 0;
60 SetFilePointer( pFile, 0, 0, FILE_END );
61 WriteFile( pFile, pNumber, 11, &dwWritten, NULL );
62 WriteFile( pFile, pString, nToWrite - 1, &dwWritten, NULL );
63 CloseHandle( pFile );
67 #endif
69 //-------------------------------------------------------------------------------
70 BOOL StringsEqual( LPCOLESTR pszNameFromOutside, wchar_t* pOwnName )
72 BOOL bResult = TRUE;
74 if ( pszNameFromOutside && pOwnName )
76 for ( int nInd = 0; pszNameFromOutside[nInd] != 0 || pOwnName[nInd] != 0; nInd++ )
78 if ( pszNameFromOutside[nInd] != pOwnName[nInd] )
80 bResult = FALSE;
81 break;
85 else if ( pszNameFromOutside || pOwnName )
86 bResult = FALSE;
88 return bResult;
91 //-------------------------------------------------------------------------------
92 HRESULT InprocEmbedDocument_Impl::Init()
94 return S_OK;
97 //-------------------------------------------------------------------------------
98 void InprocEmbedDocument_Impl::SetName( LPCOLESTR pszNameFromOutside, wchar_t*& pOwnName )
100 if ( !pszNameFromOutside )
101 return;
103 // copy the string
104 size_t nLen = 0;
105 while( pszNameFromOutside[nLen] != 0 )
106 nLen++;
108 if ( pOwnName )
110 delete[] pOwnName;
111 pOwnName = NULL;
114 pOwnName = new wchar_t[nLen+1];
115 for ( size_t nInd = 0; nInd < nLen; nInd++ )
116 pOwnName[nInd] = pszNameFromOutside[nInd];
117 pOwnName[nLen] = 0;
120 //-------------------------------------------------------------------------------
121 BOOL InprocEmbedDocument_Impl::CheckDefHandler()
123 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
124 // set the own listener
125 if ( m_pOleAdvises[0] == NULL )
127 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
128 m_pOleAdvises[0] = new OleWrapperAdviseSink();
130 else
132 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
133 if ( m_pOleAdvises[0]->IsClosed() )
135 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
136 if ( m_pDefHandler )
138 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
139 // deregister all the listeners
141 ComSmart< IOleObject > pOleObject;
142 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
143 if ( SUCCEEDED( hr ) && pOleObject )
145 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
146 for ( DWORD nInd = 0; nInd < DEFAULT_ARRAY_LEN; nInd++ )
147 if ( m_pOleAdvises[nInd] )
149 DWORD nID = m_pOleAdvises[nInd]->GetRegID();
150 pOleObject->Unadvise( nID );
151 m_pOleAdvises[nInd]->SetRegID( 0 );
154 pOleObject->SetClientSite( NULL );
157 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
158 ComSmart< IDataObject > pIDataObject;
159 hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject );
160 if ( SUCCEEDED( hr ) && pIDataObject )
162 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
163 for ( DWORD nInd = 0; nInd < DEFAULT_ARRAY_LEN; nInd++ )
164 if ( m_pDataAdvises[nInd] )
166 DWORD nID = m_pDataAdvises[nInd]->GetRegID();
167 pIDataObject->DUnadvise( nID );
168 m_pDataAdvises[nInd]->SetRegID( 0 );
172 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
173 ComSmart< IViewObject > pIViewObject;
174 hr = m_pDefHandler->QueryInterface( IID_IViewObject, (void**)&pIViewObject );
175 if ( SUCCEEDED( hr ) && pIViewObject )
177 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
178 if ( m_pViewAdvise )
179 pIViewObject->SetAdvise( m_pViewAdvise->GetAspect(), m_pViewAdvise->GetViewAdviseFlag(), NULL );
180 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
182 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
184 ComSmart< IPersistStorage > pPersist;
185 hr = m_pDefHandler->QueryInterface( IID_IPersistStorage, (void**)&pPersist );
186 if ( SUCCEEDED( hr ) && pPersist )
188 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
189 // disconnect the old wrapper from the storage
190 pPersist->HandsOffStorage();
193 m_pDefHandler = NULL;
196 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
197 m_pOleAdvises[0]->UnsetClosed();
201 if ( m_nCallsOnStack )
202 return FALSE;
204 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
205 if ( !m_pDefHandler )
207 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
208 // create a new default inprocess handler
209 HRESULT hr = OleCreateDefaultHandler( m_guid, NULL, IID_IUnknown, (void**)&m_pDefHandler );
210 if ( SUCCEEDED( hr ) )
212 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
213 // // reinit the handler
214 // ComSmart< IRunnableObject > pIRunObj;
215 // hr = m_pDefHandler->QueryInterface( IID_IRunnableObject, (void**)&pIRunObj );
217 // if ( SUCCEEDED( hr ) && pIRunObj )
219 // {
220 // ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
221 // hr = pIRunObj->Run( NULL );
222 // }
224 // if ( SUCCEEDED( hr ) )
226 if ( m_nInitMode == INIT_FROM_STORAGE )
228 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
229 ComSmart< IPersistStorage > pPersist;
230 hr = m_pDefHandler->QueryInterface( IID_IPersistStorage, (void**)&pPersist );
232 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
233 if ( SUCCEEDED( hr ) && pPersist && m_pStorage )
234 hr = pPersist->InitNew( m_pStorage );
236 else if ( m_nInitMode == LOAD_FROM_STORAGE )
238 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
239 ComSmart< IPersistStorage > pPersist;
240 hr = m_pDefHandler->QueryInterface( IID_IPersistStorage, (void**)&pPersist );
242 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
243 if ( SUCCEEDED( hr ) && pPersist && m_pStorage )
244 hr = pPersist->Load( m_pStorage );
246 else if ( m_nInitMode == LOAD_FROM_FILE )
248 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
249 ComSmart< IPersistFile > pPersistFile;
250 hr = m_pDefHandler->QueryInterface( IID_IPersistFile, (void**)&pPersistFile );
252 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
253 if ( SUCCEEDED( hr ) && pPersistFile && m_pFileName )
254 hr = pPersistFile->Load( m_pFileName, m_nFileOpenMode );
256 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
261 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
262 if ( !SUCCEEDED( hr ) || !m_pDefHandler )
264 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
265 m_pDefHandler = NULL;
266 return FALSE;
269 // register all the listeners new
271 ComSmart< IOleObject > pOleObject;
272 hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
273 if ( SUCCEEDED( hr ) && pOleObject )
275 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
276 if ( m_pClientSite )
277 pOleObject->SetClientSite( m_pClientSite );
279 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
280 for ( DWORD nInd = 0; nInd < DEFAULT_ARRAY_LEN; nInd++ )
281 if ( m_pOleAdvises[nInd] )
283 DWORD nRegID = 0;
284 if ( SUCCEEDED( pOleObject->Advise( m_pOleAdvises[nInd], &nRegID ) ) && nRegID > 0 )
285 m_pOleAdvises[nInd]->SetRegID( nRegID );
289 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
290 ComSmart< IDataObject > pIDataObject;
291 hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject );
292 if ( SUCCEEDED( hr ) && pIDataObject )
294 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
295 for ( DWORD nInd = 0; nInd < DEFAULT_ARRAY_LEN; nInd++ )
296 if ( m_pDataAdvises[nInd] )
298 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
299 DWORD nRegID = 0;
300 if ( SUCCEEDED( pIDataObject->DAdvise( m_pDataAdvises[nInd]->GetFormatEtc(), m_pDataAdvises[nInd]->GetDataAdviseFlag(), m_pDataAdvises[nInd], &nRegID ) ) && nRegID > 0 )
301 m_pDataAdvises[nInd]->SetRegID( nRegID );
302 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
306 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
307 ComSmart< IViewObject > pIViewObject;
308 hr = m_pDefHandler->QueryInterface( IID_IViewObject, (void**)&pIViewObject );
309 if ( SUCCEEDED( hr ) && pIViewObject )
311 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
312 if ( m_pViewAdvise )
313 pIViewObject->SetAdvise( m_pViewAdvise->GetAspect(), m_pViewAdvise->GetViewAdviseFlag(), m_pViewAdvise );
314 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
318 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
320 return TRUE;
323 //-------------------------------------------------------------------------------
324 DWORD InprocEmbedDocument_Impl::InsertAdviseLinkToList( const ComSmart<OleWrapperAdviseSink>& pOwnAdvise, ComSmart< OleWrapperAdviseSink > pAdvises[] )
326 // the result should start from 1 in case of success, the element 0 can be used for own needs
327 DWORD nResult = 0;
329 if ( pOwnAdvise )
331 for ( DWORD nInd = 1; nInd < DEFAULT_ARRAY_LEN && nResult == 0; nInd++ )
333 if ( pAdvises[nInd] == pOwnAdvise )
335 nResult = nInd;
337 else if ( pAdvises[nInd] == NULL )
339 pAdvises[nInd] = pOwnAdvise;
340 nResult = nInd;
345 return nResult;
348 //-------------------------------------------------------------------------------
349 void InprocEmbedDocument_Impl::Clean()
351 m_pDefHandler = (IUnknown*)NULL;
353 // no DisconnectOrigAdvise() call here, since it is no explicit disconnection
354 for ( DWORD nInd = 0; nInd < DEFAULT_ARRAY_LEN; nInd++ )
356 if ( m_pOleAdvises[nInd] )
358 ComSmart< OleWrapperAdviseSink > pAdvise = m_pOleAdvises[nInd];
359 m_pOleAdvises[nInd] = NULL;
362 if ( m_pDataAdvises[nInd] )
364 ComSmart< OleWrapperAdviseSink > pAdvise = m_pDataAdvises[nInd];
365 m_pDataAdvises[nInd] = NULL;
369 m_pViewAdvise = NULL;
371 m_nInitMode = NOINIT;
372 m_pStorage = NULL;
374 if ( m_pOleContainer )
376 m_pOleContainer->LockContainer( FALSE );
377 m_pOleContainer = NULL;
380 m_pClientSite = NULL;
382 m_nFileOpenMode = 0;
383 if ( m_pFileName )
385 delete m_pFileName;
386 m_pFileName = NULL;
390 // IUnknown
391 //-------------------------------------------------------------------------------
392 STDMETHODIMP InprocEmbedDocument_Impl::QueryInterface( REFIID riid, void FAR* FAR* ppv )
394 if(IsEqualIID(riid, IID_IUnknown))
396 AddRef();
397 *ppv = (IUnknown*) (IPersistStorage*) this;
398 return S_OK;
400 else if (IsEqualIID(riid, IID_IPersist))
402 AddRef();
403 *ppv = (IPersist*) (IPersistStorage*) this;
404 return S_OK;
406 else if (IsEqualIID(riid, IID_IPersistStorage))
408 AddRef();
409 *ppv = (IPersistStorage*) this;
410 return S_OK;
412 else if (IsEqualIID(riid, IID_IDataObject))
414 AddRef();
415 *ppv = (IDataObject*) this;
416 return S_OK;
418 else if (IsEqualIID(riid, IID_IOleObject))
420 AddRef();
421 *ppv = (IOleObject*) this;
422 return S_OK;
424 else if (IsEqualIID(riid, IID_IPersistFile))
426 AddRef();
427 *ppv = (IPersistFile*) this;
428 return S_OK;
430 else if (IsEqualIID(riid, IID_IRunnableObject))
432 AddRef();
433 *ppv = (IRunnableObject*) this;
434 return S_OK;
436 else if (IsEqualIID(riid, IID_IViewObject))
438 AddRef();
439 *ppv = (IViewObject*) this;
440 return S_OK;
442 else if (IsEqualIID(riid, IID_IViewObject2))
444 AddRef();
445 *ppv = (IViewObject2*) this;
446 return S_OK;
448 else if (IsEqualIID(riid, IID_IOleCache))
450 AddRef();
451 *ppv = (IOleCache*) &m_aInternalCache;
452 return S_OK;
454 else if (IsEqualIID(riid, IID_IOleCache2))
456 AddRef();
457 *ppv = (IOleCache2*) &m_aInternalCache;
458 return S_OK;
460 else if (IsEqualIID(riid, IID_IOleWindow))
462 AddRef();
463 *ppv = (IOleWindow*) this;
464 return S_OK;
466 else if (IsEqualIID(riid, IID_IOleInPlaceObject))
468 AddRef();
469 *ppv = (IOleInPlaceObject*) this;
470 return S_OK;
472 else if (IsEqualIID(riid, IID_IDispatch))
474 AddRef();
475 *ppv = (IDispatch*) this;
476 return S_OK;
479 *ppv = NULL;
480 return ResultFromScode(E_NOINTERFACE);
483 //-------------------------------------------------------------------------------
484 STDMETHODIMP_(ULONG) InprocEmbedDocument_Impl::AddRef()
486 return ++m_refCount;
489 //-------------------------------------------------------------------------------
490 STDMETHODIMP_(ULONG) InprocEmbedDocument_Impl::Release()
492 // unfortunately there are reentrance problems in mfc that have to be workarounded
493 sal_Int32 nCount = m_refCount > 0 ? --m_refCount : 0;
494 if ( nCount == 0 && !m_bDeleted )
496 // deleting of this object can trigger deleting of mfc objects that will try to delete this object one more time
497 m_bDeleted = TRUE;
499 Clean();
500 delete this;
502 return nCount;
505 // IPersist
506 //-------------------------------------------------------------------------------
507 STDMETHODIMP InprocEmbedDocument_Impl::GetClassID( CLSID* pClassId )
509 *pClassId = *&m_guid;
510 return S_OK;
513 // IPersistStorage
514 //-------------------------------------------------------------------------------
515 STDMETHODIMP InprocEmbedDocument_Impl::IsDirty()
517 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::IsDirty()1" );
518 if ( m_pDefHandler == NULL || m_pOleAdvises[0] == NULL || m_pOleAdvises[0]->IsClosed() )
519 return S_FALSE;
521 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::IsDirty()2" );
522 if ( CheckDefHandler() )
524 ComSmart< IPersistStorage > pPersist;
525 HRESULT hr = m_pDefHandler->QueryInterface( IID_IPersistStorage, (void**)&pPersist );
527 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
528 if ( SUCCEEDED( hr ) && pPersist )
529 return pPersist->IsDirty();
532 return E_FAIL;
535 //-------------------------------------------------------------------------------
536 STDMETHODIMP InprocEmbedDocument_Impl::InitNew( IStorage *pStg )
538 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InitNew( IStorage *pStg )" );
539 if ( CheckDefHandler() )
541 ComSmart< IPersistStorage > pPersist;
542 HRESULT hr = m_pDefHandler->QueryInterface( IID_IPersistStorage, (void**)&pPersist );
544 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
545 if ( SUCCEEDED( hr ) && pPersist )
547 hr = pPersist->InitNew( pStg );
548 if ( SUCCEEDED( hr ) )
550 m_nInitMode = INIT_FROM_STORAGE;
551 m_pStorage = pStg;
553 m_nFileOpenMode = 0;
554 if ( m_pFileName )
556 delete[] m_pFileName;
557 m_pFileName = NULL;
561 return hr;
565 return E_FAIL;
568 //-------------------------------------------------------------------------------
569 STDMETHODIMP InprocEmbedDocument_Impl::Load( IStorage *pStg )
571 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Load( IStorage *pStg )" );
572 if ( CheckDefHandler() )
574 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Load( IStorage *pStg )" );
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 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Load( IStorage *pStg )" );
582 hr = pPersist->Load( pStg );
583 if ( SUCCEEDED( hr ) )
585 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Load( IStorage *pStg )" );
586 m_nInitMode = LOAD_FROM_STORAGE;
587 m_pStorage = pStg;
589 m_nFileOpenMode = 0;
590 if ( m_pFileName )
592 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Load( IStorage *pStg )" );
593 delete[] m_pFileName;
594 m_pFileName = NULL;
598 return hr;
602 return E_FAIL;
605 //-------------------------------------------------------------------------------
606 STDMETHODIMP InprocEmbedDocument_Impl::Save( IStorage *pStgSave, BOOL fSameAsLoad )
608 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Save( IStorage *pStgSave, BOOL fSameAsLoad )" );
609 if ( fSameAsLoad && ( m_pDefHandler == NULL || m_pOleAdvises[0] == NULL || m_pOleAdvises[0]->IsClosed() ) )
610 return S_OK;
612 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Save( IStorage *pStgSave, BOOL fSameAsLoad )" );
613 if ( CheckDefHandler() )
615 ComSmart< IPersistStorage > pPersist;
616 HRESULT hr = m_pDefHandler->QueryInterface( IID_IPersistStorage, (void**)&pPersist );
618 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
619 if ( SUCCEEDED( hr ) && pPersist )
620 return pPersist->Save( pStgSave, fSameAsLoad );
623 return E_FAIL;
626 //-------------------------------------------------------------------------------
627 STDMETHODIMP InprocEmbedDocument_Impl::SaveCompleted( IStorage *pStgNew )
629 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SaveCompleted( IStorage *pStgNew )" );
630 if ( m_pDefHandler == NULL || m_pOleAdvises[0] == NULL || m_pOleAdvises[0]->IsClosed() )
632 if ( pStgNew )
633 m_pStorage = pStgNew;
635 return S_OK;
638 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SaveCompleted( IStorage *pStgNew )" );
639 if ( CheckDefHandler() )
641 ComSmart< IPersistStorage > pPersist;
642 HRESULT hr = m_pDefHandler->QueryInterface( IID_IPersistStorage, (void**)&pPersist );
644 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
645 if ( SUCCEEDED( hr ) && pPersist )
647 hr = pPersist->SaveCompleted( pStgNew );
648 if ( SUCCEEDED( hr ) )
650 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SaveCompleted( IStorage *pStgNew )" );
651 m_nInitMode = LOAD_FROM_STORAGE;
652 if ( pStgNew )
654 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SaveCompleted( IStorage *pStgNew )" );
655 m_pStorage = pStgNew;
658 m_nFileOpenMode = 0;
659 if ( m_pFileName )
661 delete[] m_pFileName;
662 m_pFileName = NULL;
666 return hr;
670 return E_FAIL;
673 //-------------------------------------------------------------------------------
674 STDMETHODIMP InprocEmbedDocument_Impl::HandsOffStorage()
676 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::HandsOffStorage()" );
677 if ( CheckDefHandler() )
679 ComSmart< IPersistStorage > pPersist;
680 HRESULT hr = m_pDefHandler->QueryInterface( IID_IPersistStorage, (void**)&pPersist );
682 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
683 if ( SUCCEEDED( hr ) && pPersist )
685 hr = pPersist->HandsOffStorage();
686 if ( SUCCEEDED( hr ) )
688 m_pStorage = NULL;
689 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::HandsOffStorage()" );
692 return hr;
696 return E_FAIL;
699 // IPersistFile
700 //-------------------------------------------------------------------------------
701 STDMETHODIMP InprocEmbedDocument_Impl::Load( LPCOLESTR pszFileName, DWORD dwMode )
703 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Load( LPCOLESTR pszFileName, DWORD dwMode )" );
704 if ( CheckDefHandler() && pszFileName )
706 ComSmart< IPersistFile > pPersist;
707 HRESULT hr = m_pDefHandler->QueryInterface( IID_IPersistFile, (void**)&pPersist );
709 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
710 if ( SUCCEEDED( hr ) && pPersist )
712 hr = pPersist->Load( pszFileName, dwMode );
713 if ( SUCCEEDED( hr ) )
715 m_nInitMode = LOAD_FROM_FILE;
716 if ( m_pStorage )
717 m_pStorage = NULL;
719 m_nFileOpenMode = dwMode;
720 // copy the string
721 SetName( pszFileName, m_pFileName );
724 return hr;
728 return E_FAIL;
731 //-------------------------------------------------------------------------------
732 STDMETHODIMP InprocEmbedDocument_Impl::Save( LPCOLESTR pszFileName, BOOL fRemember )
734 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Save( LPCOLESTR pszFileName, BOOL fRemember )" );
735 if ( CheckDefHandler() )
737 ComSmart< IPersistFile > pPersist;
738 HRESULT hr = m_pDefHandler->QueryInterface( IID_IPersistFile, (void**)&pPersist );
740 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
741 if ( SUCCEEDED( hr ) && pPersist )
742 return pPersist->Save( pszFileName, fRemember );
745 return E_FAIL;
748 //-------------------------------------------------------------------------------
749 STDMETHODIMP InprocEmbedDocument_Impl::SaveCompleted( LPCOLESTR pszFileName )
751 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SaveCompleted( LPCOLESTR pszFileName )" );
752 if ( CheckDefHandler() )
754 ComSmart< IPersistFile > pPersist;
755 HRESULT hr = m_pDefHandler->QueryInterface( IID_IPersistFile, (void**)&pPersist );
757 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
758 if ( SUCCEEDED( hr ) && pPersist )
760 hr = pPersist->SaveCompleted( pszFileName );
761 if ( SUCCEEDED( hr ) )
763 m_nInitMode = LOAD_FROM_STORAGE;
764 if ( m_pStorage )
765 m_pStorage = NULL;
767 m_nFileOpenMode = STGM_READWRITE; // was just written
768 // copy the string
769 SetName( pszFileName, m_pFileName );
775 return E_FAIL;
778 //-------------------------------------------------------------------------------
779 STDMETHODIMP InprocEmbedDocument_Impl::GetCurFile( LPOLESTR *ppszFileName )
781 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetCurFile( LPOLESTR *ppszFileName )" );
782 if ( CheckDefHandler() )
784 ComSmart< IPersistFile > pPersist;
785 HRESULT hr = m_pDefHandler->QueryInterface( IID_IPersistFile, (void**)&pPersist );
787 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
788 if ( SUCCEEDED( hr ) && pPersist )
789 return pPersist->GetCurFile( ppszFileName );
792 return E_FAIL;
795 // IOleObject
796 //-------------------------------------------------------------------------------
797 STDMETHODIMP InprocEmbedDocument_Impl::SetClientSite( IOleClientSite* pSite )
799 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetClientSite( IOleClientSite* pSite )" );
800 if ( pSite == m_pClientSite )
801 return S_OK;
803 if ( !pSite )
805 m_pClientSite = NULL;
806 if ( m_pOleContainer )
808 m_pOleContainer->LockContainer( FALSE );
809 m_pOleContainer = NULL;
813 if ( CheckDefHandler() )
815 ComSmart< IOleObject > pOleObject;
816 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
818 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
819 if ( SUCCEEDED( hr ) && pOleObject )
821 HRESULT hr = pOleObject->SetClientSite( pSite );
822 if ( SUCCEEDED( hr ) )
824 m_pClientSite = pSite;
826 if ( m_pOleContainer )
828 m_pOleContainer->LockContainer( FALSE );
829 m_pOleContainer = NULL;
832 m_pClientSite->GetContainer( &m_pOleContainer );
833 if ( m_pOleContainer )
834 m_pOleContainer->LockContainer( TRUE );
837 return hr;
841 return E_FAIL;
844 //-------------------------------------------------------------------------------
845 STDMETHODIMP InprocEmbedDocument_Impl::GetClientSite( IOleClientSite** pSite )
847 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetClientSite( IOleClientSite** pSite )" );
848 if ( CheckDefHandler() )
850 ComSmart< IOleObject > pOleObject;
851 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
853 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
854 if ( SUCCEEDED( hr ) && pOleObject )
855 return pOleObject->GetClientSite( pSite );
858 return E_FAIL;
861 //-------------------------------------------------------------------------------
862 STDMETHODIMP InprocEmbedDocument_Impl::SetHostNames( LPCOLESTR szContainerApp, LPCOLESTR szContainerObj )
864 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetHostNames( LPCOLESTR szContainerApp, LPCOLESTR szContainerObj )" );
866 HRESULT hr = S_OK;
867 if ( CheckDefHandler() )
869 ComSmart< IOleObject > pOleObject;
870 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
872 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
873 if ( SUCCEEDED( hr ) && pOleObject )
875 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetHostNames( LPCOLESTR szContainerApp, LPCOLESTR szContainerObj )" );
876 hr = pOleObject->SetHostNames( szContainerApp, szContainerObj );
880 return hr;
883 //-------------------------------------------------------------------------------
884 STDMETHODIMP InprocEmbedDocument_Impl::Close( DWORD dwSaveOption )
886 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Close( DWORD dwSaveOption )" );
887 if ( m_pDefHandler && CheckDefHandler() )
889 // no need to close if there is no default handler.
890 ComSmart< IOleObject > pOleObject;
891 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
893 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
894 if ( SUCCEEDED( hr ) && pOleObject )
896 hr = pOleObject->Close( dwSaveOption );
897 hr = CoDisconnectObject( (IUnknown*)(IPersistStorage*)this, 0 );
901 // if the object is closed from outside that means that it should go to uninitialized state
902 Clean();
904 return S_OK;
907 //-------------------------------------------------------------------------------
908 STDMETHODIMP InprocEmbedDocument_Impl::SetMoniker( DWORD dwWhichMoniker, IMoniker * pmk )
910 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetMoniker( DWORD dwWhichMoniker, IMoniker * pmk )" );
911 if ( CheckDefHandler() )
913 ComSmart< IOleObject > pOleObject;
914 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
916 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
917 if ( SUCCEEDED( hr ) && pOleObject )
918 return pOleObject->SetMoniker( dwWhichMoniker, pmk );
921 return E_FAIL;
924 //-------------------------------------------------------------------------------
925 STDMETHODIMP InprocEmbedDocument_Impl::GetMoniker( DWORD dwAssign, DWORD dwWhichMoniker, IMoniker ** ppmk )
927 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetMoniker( DWORD dwAssign, DWORD dwWhichMoniker, IMoniker ** ppmk )" );
928 if ( CheckDefHandler() )
930 ComSmart< IOleObject > pOleObject;
931 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
933 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
934 if ( SUCCEEDED( hr ) && pOleObject )
935 return pOleObject->GetMoniker( dwAssign, dwWhichMoniker, ppmk );
938 return E_FAIL;
941 //-------------------------------------------------------------------------------
942 STDMETHODIMP InprocEmbedDocument_Impl::InitFromData( IDataObject * pDataObject, BOOL fCreation, DWORD dwReserved )
944 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InitFromData( IDataObject * pDataObject, BOOL fCreation, DWORD dwReserved )" );
945 if ( CheckDefHandler() )
947 ComSmart< IOleObject > pOleObject;
948 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
950 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
951 if ( SUCCEEDED( hr ) && pOleObject )
952 return pOleObject->InitFromData( pDataObject, fCreation, dwReserved );
955 return E_FAIL;
958 //-------------------------------------------------------------------------------
959 STDMETHODIMP InprocEmbedDocument_Impl::GetClipboardData( DWORD dwReserved, IDataObject ** ppDataObject )
961 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetClipboardData( DWORD dwReserved, IDataObject ** ppDataObject )" );
962 if ( CheckDefHandler() )
964 ComSmart< IOleObject > pOleObject;
965 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
967 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
968 if ( SUCCEEDED( hr ) && pOleObject )
969 return pOleObject->GetClipboardData( dwReserved, ppDataObject );
972 return E_FAIL;
975 //-------------------------------------------------------------------------------
976 STDMETHODIMP InprocEmbedDocument_Impl::DoVerb(
977 LONG iVerb,
978 LPMSG pMsg,
979 IOleClientSite *pActiveSite,
980 LONG nLong,
981 HWND hWin,
982 LPCRECT pRect )
984 WRITEDEBUGINFO( "DoVerb" );
985 if ( CheckDefHandler() )
987 WRITEDEBUGINFO( "DoVerb" MY_STRING_LINE "n" );
988 ComSmart< IOleObject > pOleObject;
989 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
991 WRITEDEBUGINFO( "DoVerb" );
992 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
993 WRITEDEBUGINFO( "DoVerb" );
994 if ( SUCCEEDED( hr ) && pOleObject )
996 WRITEDEBUGINFO( "DoVerb" );
997 hr = pOleObject->DoVerb( iVerb, pMsg, pActiveSite, nLong, hWin, pRect );
998 if ( SUCCEEDED( hr ) )
1000 WRITEDEBUGINFO( "DoVerb" );
1003 return hr;
1006 WRITEDEBUGINFO( "DoVerb" );
1009 return E_FAIL;
1012 //-------------------------------------------------------------------------------
1013 STDMETHODIMP InprocEmbedDocument_Impl::EnumVerbs( IEnumOLEVERB ** ppEnumOleVerb )
1015 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::EnumVerbs( IEnumOLEVERB ** ppEnumOleVerb )" );
1016 if ( CheckDefHandler() )
1018 ComSmart< IOleObject > pOleObject;
1019 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
1021 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1022 if ( SUCCEEDED( hr ) && pOleObject )
1023 return pOleObject->EnumVerbs( ppEnumOleVerb );
1026 return E_FAIL;
1029 //-------------------------------------------------------------------------------
1030 STDMETHODIMP InprocEmbedDocument_Impl::Update()
1032 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Update()" );
1034 if ( m_pDefHandler && CheckDefHandler() )
1036 ComSmart< IOleObject > pOleObject;
1037 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
1039 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1040 if ( SUCCEEDED( hr ) && pOleObject )
1041 return pOleObject->Update();
1044 return S_OK;
1047 //-------------------------------------------------------------------------------
1048 STDMETHODIMP InprocEmbedDocument_Impl::IsUpToDate()
1050 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::IsUpToDate()" );
1051 if ( CheckDefHandler() )
1053 ComSmart< IOleObject > pOleObject;
1054 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
1056 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1057 if ( SUCCEEDED( hr ) && pOleObject )
1058 return pOleObject->IsUpToDate();
1061 return E_FAIL;
1064 //-------------------------------------------------------------------------------
1065 STDMETHODIMP InprocEmbedDocument_Impl::GetUserClassID( CLSID *pClsid )
1067 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetUserClassID( CLSID *pClsid )" );
1068 if ( pClsid )
1069 *pClsid = m_guid;
1071 return S_OK;
1074 //-------------------------------------------------------------------------------
1075 STDMETHODIMP InprocEmbedDocument_Impl::GetUserType( DWORD dwFormOfType, LPOLESTR * pszUserType )
1077 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetUserType( DWORD dwFormOfType, LPOLESTR * pszUserType )" );
1078 if ( CheckDefHandler() )
1080 ComSmart< IOleObject > pOleObject;
1081 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
1083 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1084 if ( SUCCEEDED( hr ) && pOleObject )
1085 return pOleObject->GetUserType( dwFormOfType, pszUserType );
1088 return E_FAIL;
1091 //-------------------------------------------------------------------------------
1092 STDMETHODIMP InprocEmbedDocument_Impl::SetExtent( DWORD dwDrawAspect, SIZEL *psizel )
1094 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetExtent( DWORD dwDrawAspect, SIZEL *psizel )" );
1095 if ( CheckDefHandler() )
1097 ComSmart< IOleObject > pOleObject;
1098 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
1100 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1101 if ( SUCCEEDED( hr ) && pOleObject )
1102 return pOleObject->SetExtent( dwDrawAspect, psizel );
1105 return E_FAIL;
1108 //-------------------------------------------------------------------------------
1109 STDMETHODIMP InprocEmbedDocument_Impl::GetExtent( DWORD dwDrawAspect, SIZEL * psizel )
1111 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetExtent( DWORD dwDrawAspect, SIZEL * psizel )" );
1112 if ( CheckDefHandler() )
1114 ComSmart< IOleObject > pOleObject;
1115 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
1117 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1118 if ( SUCCEEDED( hr ) && pOleObject )
1119 return pOleObject->GetExtent( dwDrawAspect, psizel );
1122 return E_FAIL;
1125 //-------------------------------------------------------------------------------
1126 STDMETHODIMP InprocEmbedDocument_Impl::Advise( IAdviseSink *pAdvSink, DWORD *pdwConnection )
1128 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Advise( IAdviseSink *pAdvSink, DWORD *pdwConnection )" );
1130 if ( !pdwConnection )
1131 return E_FAIL;
1133 // CheckDefHandler will set the listener, avoid reusing of old listener
1134 if ( DEFAULT_ARRAY_LEN > *pdwConnection && *pdwConnection > 0 && m_pOleAdvises[*pdwConnection] )
1136 m_pOleAdvises[*pdwConnection]->DisconnectOrigAdvise();
1137 m_pOleAdvises[*pdwConnection] = NULL;
1140 if ( pAdvSink && CheckDefHandler() )
1142 ComSmart< IOleObject > pOleObject;
1143 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
1145 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1146 if ( SUCCEEDED( hr ) && pOleObject )
1148 ComSmart< OleWrapperAdviseSink > pOwnAdvise( new OleWrapperAdviseSink( pAdvSink ) );
1149 DWORD nRegID = 0;
1151 if ( SUCCEEDED( pOleObject->Advise( pOwnAdvise, &nRegID ) ) && nRegID > 0 )
1153 pOwnAdvise->SetRegID( nRegID );
1154 *pdwConnection = InsertAdviseLinkToList( pOwnAdvise, m_pOleAdvises );
1155 if ( *pdwConnection )
1156 return S_OK;
1157 else
1158 pOleObject->Unadvise( nRegID );
1163 // return success always for now
1164 return S_OK;
1167 //-------------------------------------------------------------------------------
1168 STDMETHODIMP InprocEmbedDocument_Impl::Unadvise( DWORD dwConnection )
1170 if ( DEFAULT_ARRAY_LEN > dwConnection && dwConnection > 0 && m_pOleAdvises[dwConnection] )
1172 if ( m_pDefHandler )
1174 ComSmart< IOleObject > pOleObject;
1175 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
1177 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1178 if ( SUCCEEDED( hr ) && pOleObject )
1180 DWORD nID = m_pOleAdvises[dwConnection]->GetRegID();
1181 pOleObject->Unadvise( nID );
1185 m_pOleAdvises[dwConnection]->DisconnectOrigAdvise();
1186 m_pOleAdvises[dwConnection] = NULL;
1188 return S_OK;
1191 return E_FAIL;
1194 //-------------------------------------------------------------------------------
1195 STDMETHODIMP InprocEmbedDocument_Impl::EnumAdvise( IEnumSTATDATA ** /*ppenumAdvise*/ )
1197 return E_NOTIMPL;
1199 // if ( CheckDefHandler() )
1200 // {
1201 // ComSmart< IOleObject > pOleObject;
1202 // HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
1204 // ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1205 // if ( SUCCEEDED( hr ) && pOleObject )
1206 // return pOleObject->EnumAdvise( ppenumAdvise );
1207 // }
1209 // return E_FAIL;
1212 //-------------------------------------------------------------------------------
1213 STDMETHODIMP InprocEmbedDocument_Impl::GetMiscStatus( DWORD dwAspect, DWORD * pdwStatus )
1215 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetMiscStatus( DWORD dwAspect, DWORD * pdwStatus )" );
1216 if ( CheckDefHandler() )
1218 ComSmart< IOleObject > pOleObject;
1219 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
1221 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1222 if ( SUCCEEDED( hr ) && pOleObject )
1223 return pOleObject->GetMiscStatus( dwAspect, pdwStatus );
1226 return E_FAIL;
1229 //-------------------------------------------------------------------------------
1230 STDMETHODIMP InprocEmbedDocument_Impl::SetColorScheme( LOGPALETTE * pLogpal )
1232 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetColorScheme( LOGPALETTE * pLogpal )" );
1233 if ( CheckDefHandler() )
1235 ComSmart< IOleObject > pOleObject;
1236 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
1238 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1239 if ( SUCCEEDED( hr ) && pOleObject )
1240 return pOleObject->SetColorScheme( pLogpal );
1243 return E_FAIL;
1246 //IDataObject
1247 //-------------------------------------------------------------------------------
1248 STDMETHODIMP InprocEmbedDocument_Impl::GetData( FORMATETC * pFormatetc, STGMEDIUM * pMedium )
1250 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetData( FORMATETC * pFormatetc, STGMEDIUM * pMedium )" );
1251 if ( CheckDefHandler() )
1253 ComSmart< IDataObject > pIDataObject;
1254 HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject );
1256 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1257 if ( SUCCEEDED( hr ) && pIDataObject )
1258 return pIDataObject->GetData( pFormatetc, pMedium );
1261 return E_FAIL;
1264 //-------------------------------------------------------------------------------
1265 STDMETHODIMP InprocEmbedDocument_Impl::GetDataHere( FORMATETC * pFormatetc, STGMEDIUM * pMedium )
1267 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetDataHere( FORMATETC * pFormatetc, STGMEDIUM * pMedium )" );
1268 if ( CheckDefHandler() )
1270 ComSmart< IDataObject > pIDataObject;
1271 HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject );
1273 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1274 if ( SUCCEEDED( hr ) && pIDataObject )
1275 return pIDataObject->GetDataHere( pFormatetc, pMedium );
1278 return E_FAIL;
1281 //-------------------------------------------------------------------------------
1282 STDMETHODIMP InprocEmbedDocument_Impl::QueryGetData( FORMATETC * pFormatetc )
1284 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::QueryGetData( FORMATETC * pFormatetc )" );
1285 if ( CheckDefHandler() )
1287 ComSmart< IDataObject > pIDataObject;
1288 HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject );
1290 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1291 if ( SUCCEEDED( hr ) && pIDataObject )
1292 return pIDataObject->QueryGetData( pFormatetc );
1295 return E_FAIL;
1298 //-------------------------------------------------------------------------------
1299 STDMETHODIMP InprocEmbedDocument_Impl::GetCanonicalFormatEtc( FORMATETC * pFormatetcIn, FORMATETC * pFormatetcOut )
1301 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetCanonicalFormatEtc( FORMATETC * pFormatetcIn, FORMATETC * pFormatetcOut )" );
1302 if ( CheckDefHandler() )
1304 ComSmart< IDataObject > pIDataObject;
1305 HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject );
1307 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1308 if ( SUCCEEDED( hr ) && pIDataObject )
1309 return pIDataObject->GetCanonicalFormatEtc( pFormatetcIn, pFormatetcOut );
1312 return E_FAIL;
1315 //-------------------------------------------------------------------------------
1316 STDMETHODIMP InprocEmbedDocument_Impl::SetData( FORMATETC * pFormatetc, STGMEDIUM * pMedium, BOOL fRelease )
1318 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetData( FORMATETC * pFormatetc, STGMEDIUM * pMedium, BOOL fRelease )" );
1319 if ( CheckDefHandler() )
1321 ComSmart< IDataObject > pIDataObject;
1322 HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject );
1324 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1325 if ( SUCCEEDED( hr ) && pIDataObject )
1326 return pIDataObject->SetData( pFormatetc, pMedium, fRelease );
1329 return E_FAIL;
1332 //-------------------------------------------------------------------------------
1333 STDMETHODIMP InprocEmbedDocument_Impl::EnumFormatEtc( DWORD dwDirection, IEnumFORMATETC ** ppFormatetc )
1335 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::EnumFormatEtc( DWORD dwDirection, IEnumFORMATETC ** ppFormatetc )" );
1336 if ( CheckDefHandler() )
1338 ComSmart< IDataObject > pIDataObject;
1339 HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject );
1341 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1342 if ( SUCCEEDED( hr ) && pIDataObject )
1343 return pIDataObject->EnumFormatEtc( dwDirection, ppFormatetc );
1346 return E_FAIL;
1349 //-------------------------------------------------------------------------------
1350 STDMETHODIMP InprocEmbedDocument_Impl::DAdvise( FORMATETC * pFormatetc, DWORD advf, IAdviseSink * pAdvSink, DWORD * pdwConnection )
1352 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::DAdvise( FORMATETC * pFormatetc, DWORD advf, IAdviseSink * pAdvSink, DWORD * pdwConnection )" );
1354 if ( !pdwConnection )
1355 return E_FAIL;
1357 // avoid reusing of the old listener
1358 if ( m_pDefHandler && DEFAULT_ARRAY_LEN > *pdwConnection && *pdwConnection > 0 && m_pDataAdvises[*pdwConnection] )
1360 m_pDataAdvises[*pdwConnection]->DisconnectOrigAdvise();
1361 m_pDataAdvises[*pdwConnection] = NULL;
1364 if ( pAdvSink && CheckDefHandler() )
1366 ComSmart< IDataObject > pIDataObject;
1367 HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject );
1369 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1370 if ( SUCCEEDED( hr ) && pIDataObject )
1372 ComSmart< OleWrapperAdviseSink > pOwnAdvise( new OleWrapperAdviseSink( ComSmart<IAdviseSink>( pAdvSink ), pFormatetc, advf ) );
1373 DWORD nRegID = 0;
1375 if ( SUCCEEDED( pIDataObject->DAdvise( pFormatetc, advf, pOwnAdvise, &nRegID ) ) && nRegID > 0 )
1377 pOwnAdvise->SetRegID( nRegID );
1378 *pdwConnection = InsertAdviseLinkToList( pOwnAdvise, m_pDataAdvises );
1379 if ( *pdwConnection )
1380 return S_OK;
1381 else
1382 pIDataObject->DUnadvise( nRegID );
1387 // return success always for now
1388 return S_OK;
1391 //-------------------------------------------------------------------------------
1392 STDMETHODIMP InprocEmbedDocument_Impl::DUnadvise( DWORD dwConnection )
1394 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::DUnadvise( DWORD dwConnection )" );
1395 if ( m_pDefHandler && DEFAULT_ARRAY_LEN > dwConnection && dwConnection > 0 && m_pDataAdvises[dwConnection] )
1397 if ( CheckDefHandler() )
1399 ComSmart< IDataObject > pIDataObject;
1400 HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject );
1402 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1403 if ( SUCCEEDED( hr ) && pIDataObject )
1405 DWORD nID = m_pDataAdvises[dwConnection]->GetRegID();
1406 pIDataObject->DUnadvise( nID );
1410 m_pDataAdvises[dwConnection]->DisconnectOrigAdvise();
1411 m_pDataAdvises[dwConnection] = NULL;
1413 return S_OK;
1416 return E_FAIL;
1419 //-------------------------------------------------------------------------------
1420 STDMETHODIMP InprocEmbedDocument_Impl::EnumDAdvise( IEnumSTATDATA ** ppenumAdvise )
1422 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::EnumDAdvise( IEnumSTATDATA ** ppenumAdvise )" );
1423 if ( CheckDefHandler() )
1425 ComSmart< IDataObject > pIDataObject;
1426 HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject );
1428 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1429 if ( SUCCEEDED( hr ) && pIDataObject )
1430 return pIDataObject->EnumDAdvise( ppenumAdvise );
1433 return E_FAIL;
1436 // IRunnableObject
1437 //-------------------------------------------------------------------------------
1438 STDMETHODIMP InprocEmbedDocument_Impl::GetRunningClass( LPCLSID lpClsid )
1440 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetRunningClass( LPCLSID lpClsid )" );
1441 if ( CheckDefHandler() )
1443 ComSmart< IRunnableObject > pIRunObj;
1444 HRESULT hr = m_pDefHandler->QueryInterface( IID_IRunnableObject, (void**)&pIRunObj );
1446 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1447 if ( SUCCEEDED( hr ) && pIRunObj )
1448 return pIRunObj->GetRunningClass( lpClsid );
1451 return E_FAIL;
1454 //-------------------------------------------------------------------------------
1455 STDMETHODIMP InprocEmbedDocument_Impl::Run( LPBINDCTX pbc )
1457 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Run( LPBINDCTX pbc )" );
1458 if ( CheckDefHandler() )
1460 ComSmart< IRunnableObject > pIRunObj;
1461 HRESULT hr = m_pDefHandler->QueryInterface( IID_IRunnableObject, (void**)&pIRunObj );
1463 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1464 if ( SUCCEEDED( hr ) && pIRunObj )
1465 return pIRunObj->Run( pbc );
1468 return E_FAIL;
1471 //-------------------------------------------------------------------------------
1472 BOOL STDMETHODCALLTYPE InprocEmbedDocument_Impl::IsRunning()
1474 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::IsRunning()" );
1475 if ( CheckDefHandler() )
1477 ComSmart< IRunnableObject > pIRunObj;
1478 HRESULT hr = m_pDefHandler->QueryInterface( IID_IRunnableObject, (void**)&pIRunObj );
1480 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1481 if ( SUCCEEDED( hr ) && pIRunObj )
1482 return pIRunObj->IsRunning();
1485 return E_FAIL;
1489 //-------------------------------------------------------------------------------
1490 STDMETHODIMP InprocEmbedDocument_Impl::LockRunning( BOOL fLock, BOOL fLastUnlockCloses )
1492 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::LockRunning( BOOL fLock, BOOL fLastUnlockCloses )" );
1493 if ( CheckDefHandler() )
1495 ComSmart< IRunnableObject > pIRunObj;
1496 HRESULT hr = m_pDefHandler->QueryInterface( IID_IRunnableObject, (void**)&pIRunObj );
1498 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1499 if ( SUCCEEDED( hr ) && pIRunObj )
1500 return pIRunObj->LockRunning( fLock, fLastUnlockCloses );
1503 return E_FAIL;
1506 //-------------------------------------------------------------------------------
1507 STDMETHODIMP InprocEmbedDocument_Impl::SetContainedObject( BOOL fContained)
1509 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetContainedObject( BOOL fContained)" );
1510 if ( CheckDefHandler() )
1512 ComSmart< IRunnableObject > pIRunObj;
1513 HRESULT hr = m_pDefHandler->QueryInterface( IID_IRunnableObject, (void**)&pIRunObj );
1515 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1516 if ( SUCCEEDED( hr ) && pIRunObj )
1517 return pIRunObj->SetContainedObject( fContained );
1520 return E_FAIL;
1524 // IViewObject methods
1525 //-------------------------------------------------------------------------------
1526 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 )
1528 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Draw( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DVTARGETDEVICE *ptd, HDC hdcTargetDev, HDC hdcDraw, LPCRECTL lprcBounds, LPCRECTL lprcWBounds, BOOL ( STDMETHODCALLTYPE *pfnContinue )( ULONG_PTR dwContinue ), ULONG_PTR dwContinue )" );
1529 if ( CheckDefHandler() )
1531 ComSmart< IViewObject > pIViewObject;
1532 HRESULT hr = m_pDefHandler->QueryInterface( IID_IViewObject, (void**)&pIViewObject );
1534 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1535 if ( SUCCEEDED( hr ) && pIViewObject )
1536 return pIViewObject->Draw( dwDrawAspect, lindex, pvAspect, ptd, hdcTargetDev, hdcDraw, lprcBounds, lprcWBounds, pfnContinue, dwContinue );
1539 return E_FAIL;
1542 //-------------------------------------------------------------------------------
1543 STDMETHODIMP InprocEmbedDocument_Impl::GetColorSet( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet )
1545 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetColorSet( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet )" );
1546 if ( CheckDefHandler() )
1548 ComSmart< IViewObject > pIViewObject;
1549 HRESULT hr = m_pDefHandler->QueryInterface( IID_IViewObject, (void**)&pIViewObject );
1551 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1552 if ( SUCCEEDED( hr ) && pIViewObject )
1553 return pIViewObject->GetColorSet( dwDrawAspect, lindex, pvAspect, ptd, hicTargetDev, ppColorSet );
1556 return E_FAIL;
1559 //-------------------------------------------------------------------------------
1560 STDMETHODIMP InprocEmbedDocument_Impl::Freeze( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DWORD *pdwFreeze )
1562 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Freeze( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DWORD *pdwFreeze )" );
1563 if ( CheckDefHandler() )
1565 ComSmart< IViewObject > pIViewObject;
1566 HRESULT hr = m_pDefHandler->QueryInterface( IID_IViewObject, (void**)&pIViewObject );
1568 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1569 if ( SUCCEEDED( hr ) && pIViewObject )
1570 return pIViewObject->Freeze( dwDrawAspect, lindex, pvAspect, pdwFreeze );
1573 return E_FAIL;
1576 //-------------------------------------------------------------------------------
1577 STDMETHODIMP InprocEmbedDocument_Impl::Unfreeze( DWORD dwFreeze )
1579 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Unfreeze( DWORD dwFreeze )" );
1580 if ( CheckDefHandler() )
1582 ComSmart< IViewObject > pIViewObject;
1583 HRESULT hr = m_pDefHandler->QueryInterface( IID_IViewObject, (void**)&pIViewObject );
1585 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1586 if ( SUCCEEDED( hr ) && pIViewObject )
1587 return pIViewObject->Unfreeze( dwFreeze );
1590 return E_FAIL;
1593 //-------------------------------------------------------------------------------
1594 STDMETHODIMP InprocEmbedDocument_Impl::SetAdvise( DWORD aspects, DWORD advf, IAdviseSink *pAdvSink )
1596 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetAdvise( DWORD aspects, DWORD advf, IAdviseSink *pAdvSink )" );
1598 // CheckDefHandler will set the listener, avoid reusing of old listener
1599 if ( m_pViewAdvise )
1601 m_pViewAdvise->DisconnectOrigAdvise();
1602 m_pViewAdvise = NULL;
1605 if ( pAdvSink && CheckDefHandler() )
1607 ComSmart< IViewObject > pIViewObject;
1608 HRESULT hr = m_pDefHandler->QueryInterface( IID_IViewObject, (void**)&pIViewObject );
1610 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1611 if ( SUCCEEDED( hr ) && pIViewObject )
1613 ComSmart< OleWrapperAdviseSink > pOwnAdvise( new OleWrapperAdviseSink( pAdvSink, aspects, advf ) );
1615 if ( SUCCEEDED( pIViewObject->SetAdvise( aspects, advf, pOwnAdvise ) ) )
1617 m_pViewAdvise = pOwnAdvise;
1618 return S_OK;
1623 return S_OK;
1626 //-------------------------------------------------------------------------------
1627 STDMETHODIMP InprocEmbedDocument_Impl::GetAdvise( DWORD *pAspects, DWORD *pAdvf, IAdviseSink **ppAdvSink )
1629 if ( !ppAdvSink )
1630 return E_INVALIDARG;
1632 if ( m_pViewAdvise )
1634 if ( pAspects )
1635 *pAspects = m_pViewAdvise->GetAspect();
1637 if ( pAdvf )
1638 *pAdvf = m_pViewAdvise->GetViewAdviseFlag();
1640 *ppAdvSink = m_pViewAdvise->GetOrigAdvise();
1641 if ( *ppAdvSink )
1642 (*ppAdvSink)->AddRef();
1644 else
1645 *ppAdvSink = NULL;
1647 return S_OK;
1650 // IViewObject2 methods
1651 //-------------------------------------------------------------------------------
1652 STDMETHODIMP InprocEmbedDocument_Impl::GetExtent( DWORD dwDrawAspect, LONG lindex, DVTARGETDEVICE *ptd, LPSIZEL lpsizel )
1654 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetExtent( DWORD dwDrawAspect, LONG lindex, DVTARGETDEVICE *ptd, LPSIZEL lpsizel )" );
1655 if ( CheckDefHandler() )
1657 ComSmart< IViewObject2 > pIViewObject2;
1658 HRESULT hr = m_pDefHandler->QueryInterface( IID_IViewObject2, (void**)&pIViewObject2 );
1660 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1661 if ( SUCCEEDED( hr ) && pIViewObject2 )
1662 return pIViewObject2->GetExtent( dwDrawAspect, lindex, ptd, lpsizel );
1665 return E_FAIL;
1670 // IOleWindow methods
1671 //-------------------------------------------------------------------------------
1672 STDMETHODIMP InprocEmbedDocument_Impl::GetWindow( HWND *phwnd )
1674 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetWindow( HWND *phwnd )" );
1675 if ( CheckDefHandler() )
1677 ComSmart< IOleWindow > pIOleWindow;
1678 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleWindow, (void**)&pIOleWindow );
1680 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1681 if ( SUCCEEDED( hr ) && pIOleWindow )
1682 return pIOleWindow->GetWindow( phwnd );
1685 return E_FAIL;
1688 //-------------------------------------------------------------------------------
1689 STDMETHODIMP InprocEmbedDocument_Impl::ContextSensitiveHelp( BOOL fEnterMode )
1691 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::ContextSensitiveHelp( BOOL fEnterMode )" );
1692 if ( CheckDefHandler() )
1694 ComSmart< IOleWindow > pIOleWindow;
1695 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleWindow, (void**)&pIOleWindow );
1697 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1698 if ( SUCCEEDED( hr ) && pIOleWindow )
1699 return pIOleWindow->ContextSensitiveHelp( fEnterMode );
1702 return E_FAIL;
1706 // IOleInPlaceObject methods
1707 //-------------------------------------------------------------------------------
1708 STDMETHODIMP InprocEmbedDocument_Impl::InPlaceDeactivate( void )
1710 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InPlaceDeactivate( void )" );
1711 if ( CheckDefHandler() )
1713 ComSmart< IOleInPlaceObject > pIOleInPlaceObject;
1714 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleInPlaceObject, (void**)&pIOleInPlaceObject );
1716 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1717 if ( SUCCEEDED( hr ) && pIOleInPlaceObject )
1718 return pIOleInPlaceObject->InPlaceDeactivate();
1721 return E_FAIL;
1724 //-------------------------------------------------------------------------------
1725 STDMETHODIMP InprocEmbedDocument_Impl::UIDeactivate( void )
1727 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::UIDeactivate( void )" );
1728 if ( CheckDefHandler() )
1730 ComSmart< IOleInPlaceObject > pIOleInPlaceObject;
1731 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleInPlaceObject, (void**)&pIOleInPlaceObject );
1733 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1734 if ( SUCCEEDED( hr ) && pIOleInPlaceObject )
1735 return pIOleInPlaceObject->UIDeactivate();
1738 return E_FAIL;
1741 //-------------------------------------------------------------------------------
1742 STDMETHODIMP InprocEmbedDocument_Impl::SetObjectRects( LPCRECT lprcPosRect, LPCRECT lprcClipRect )
1744 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetObjectRects( LPCRECT lprcPosRect, LPCRECT lprcClipRect )" );
1745 if ( CheckDefHandler() )
1747 ComSmart< IOleInPlaceObject > pIOleInPlaceObject;
1748 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleInPlaceObject, (void**)&pIOleInPlaceObject );
1750 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1751 if ( SUCCEEDED( hr ) && pIOleInPlaceObject )
1752 return pIOleInPlaceObject->SetObjectRects( lprcPosRect, lprcClipRect );
1755 return E_FAIL;
1758 //-------------------------------------------------------------------------------
1759 STDMETHODIMP InprocEmbedDocument_Impl::ReactivateAndUndo( void )
1761 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::ReactivateAndUndo( void )" );
1762 if ( CheckDefHandler() )
1764 ComSmart< IOleInPlaceObject > pIOleInPlaceObject;
1765 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleInPlaceObject, (void**)&pIOleInPlaceObject );
1767 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1768 if ( SUCCEEDED( hr ) && pIOleInPlaceObject )
1769 return pIOleInPlaceObject->ReactivateAndUndo();
1772 return E_FAIL;
1776 // IDispatch methods
1777 //-------------------------------------------------------------------------------
1778 STDMETHODIMP InprocEmbedDocument_Impl::GetTypeInfoCount( UINT *pctinfo )
1780 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetTypeInfoCount( UINT *pctinfo )" );
1781 if ( CheckDefHandler() )
1783 ComSmart< IDispatch > pIDispatch;
1784 HRESULT hr = m_pDefHandler->QueryInterface( IID_IDispatch, (void**)&pIDispatch );
1786 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1787 if ( SUCCEEDED( hr ) && pIDispatch )
1788 return pIDispatch->GetTypeInfoCount( pctinfo );
1791 return E_FAIL;
1794 //-------------------------------------------------------------------------------
1795 STDMETHODIMP InprocEmbedDocument_Impl::GetTypeInfo( UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo )
1797 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetTypeInfo( UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo )" );
1798 if ( CheckDefHandler() )
1800 ComSmart< IDispatch > pIDispatch;
1801 HRESULT hr = m_pDefHandler->QueryInterface( IID_IDispatch, (void**)&pIDispatch );
1803 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1804 if ( SUCCEEDED( hr ) && pIDispatch )
1805 return pIDispatch->GetTypeInfo( iTInfo, lcid, ppTInfo );
1808 return E_FAIL;
1811 //-------------------------------------------------------------------------------
1812 STDMETHODIMP InprocEmbedDocument_Impl::GetIDsOfNames( REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId )
1814 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetIDsOfNames( REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId )" );
1815 if ( CheckDefHandler() )
1817 ComSmart< IDispatch > pIDispatch;
1818 HRESULT hr = m_pDefHandler->QueryInterface( IID_IDispatch, (void**)&pIDispatch );
1820 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1821 if ( SUCCEEDED( hr ) && pIDispatch )
1822 return pIDispatch->GetIDsOfNames( riid, rgszNames, cNames, lcid, rgDispId );
1825 return E_FAIL;
1828 //-------------------------------------------------------------------------------
1829 STDMETHODIMP InprocEmbedDocument_Impl::Invoke( DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr )
1831 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Invoke( DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr )" );
1832 if ( CheckDefHandler() )
1834 ComSmart< IDispatch > pIDispatch;
1835 HRESULT hr = m_pDefHandler->QueryInterface( IID_IDispatch, (void**)&pIDispatch );
1837 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1838 if ( SUCCEEDED( hr ) && pIDispatch )
1839 return pIDispatch->Invoke( dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr );
1842 return E_FAIL;
1846 // ====
1847 // InternalCacheWrapper
1848 // ====
1850 // IUnknown
1851 //-------------------------------------------------------------------------------
1852 STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::QueryInterface( REFIID riid, void FAR* FAR* ppv )
1854 return m_rOwnDocument.QueryInterface( riid, ppv );
1857 //-------------------------------------------------------------------------------
1858 STDMETHODIMP_(ULONG) InprocEmbedDocument_Impl::InternalCacheWrapper::AddRef()
1860 return m_rOwnDocument.AddRef();
1863 //-------------------------------------------------------------------------------
1864 STDMETHODIMP_(ULONG) InprocEmbedDocument_Impl::InternalCacheWrapper::Release()
1866 return m_rOwnDocument.Release();
1869 // IOleCache methods
1870 //-------------------------------------------------------------------------------
1871 STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::Cache( FORMATETC *pformatetc, DWORD advf, DWORD *pdwConnection )
1873 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::Cache( FORMATETC *pformatetc, DWORD advf, DWORD *pdwConnection )" );
1874 if ( m_rOwnDocument.CheckDefHandler() )
1876 ComSmart< IOleCache > pIOleCache;
1877 HRESULT hr = m_rOwnDocument.GetDefHandler()->QueryInterface( IID_IOleCache, (void**)&pIOleCache );
1879 ULONGGuard aGuard( &m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem
1880 if ( SUCCEEDED( hr ) && pIOleCache )
1881 return pIOleCache->Cache( pformatetc, advf, pdwConnection );
1884 return E_FAIL;
1887 //-------------------------------------------------------------------------------
1888 STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::Uncache( DWORD dwConnection )
1890 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::Uncache( DWORD dwConnection )" );
1891 if ( m_rOwnDocument.CheckDefHandler() )
1893 ComSmart< IOleCache > pIOleCache;
1894 HRESULT hr = m_rOwnDocument.GetDefHandler()->QueryInterface( IID_IOleCache, (void**)&pIOleCache );
1896 ULONGGuard aGuard( &m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem
1897 if ( SUCCEEDED( hr ) && pIOleCache )
1898 return pIOleCache->Uncache( dwConnection );
1901 return E_FAIL;
1904 //-------------------------------------------------------------------------------
1905 STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::EnumCache( IEnumSTATDATA **ppenumSTATDATA )
1907 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::EnumCache( IEnumSTATDATA **ppenumSTATDATA )" );
1908 if ( m_rOwnDocument.CheckDefHandler() )
1910 ComSmart< IOleCache > pIOleCache;
1911 HRESULT hr = m_rOwnDocument.GetDefHandler()->QueryInterface( IID_IOleCache, (void**)&pIOleCache );
1913 ULONGGuard aGuard( &m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem
1914 if ( SUCCEEDED( hr ) && pIOleCache )
1915 return pIOleCache->EnumCache( ppenumSTATDATA );
1918 return E_FAIL;
1921 //-------------------------------------------------------------------------------
1922 STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::InitCache( IDataObject *pDataObject )
1924 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::InitCache( IDataObject *pDataObject )" );
1925 if ( m_rOwnDocument.CheckDefHandler() )
1927 ComSmart< IOleCache > pIOleCache;
1928 HRESULT hr = m_rOwnDocument.GetDefHandler()->QueryInterface( IID_IOleCache, (void**)&pIOleCache );
1930 ULONGGuard aGuard( &m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem
1931 if ( SUCCEEDED( hr ) && pIOleCache )
1932 return pIOleCache->InitCache( pDataObject );
1935 return E_FAIL;
1938 //-------------------------------------------------------------------------------
1939 STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::SetData( FORMATETC *pformatetc, STGMEDIUM *pmedium, BOOL fRelease )
1941 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::SetData( FORMATETC *pformatetc, STGMEDIUM *pmedium, BOOL fRelease )" );
1942 if ( m_rOwnDocument.CheckDefHandler() )
1944 ComSmart< IOleCache > pIOleCache;
1945 HRESULT hr = m_rOwnDocument.GetDefHandler()->QueryInterface( IID_IOleCache, (void**)&pIOleCache );
1947 ULONGGuard aGuard( &m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem
1948 if ( SUCCEEDED( hr ) && pIOleCache )
1949 return pIOleCache->SetData( pformatetc, pmedium, fRelease );
1952 return E_FAIL;
1955 // IOleCache2 methods
1956 //-------------------------------------------------------------------------------
1957 STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::UpdateCache( LPDATAOBJECT pDataObject, DWORD grfUpdf, LPVOID pReserved )
1959 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::UpdateCache( LPDATAOBJECT pDataObject, DWORD grfUpdf, LPVOID pReserved )" );
1960 if ( m_rOwnDocument.CheckDefHandler() )
1962 ComSmart< IOleCache2 > pIOleCache2;
1963 HRESULT hr = m_rOwnDocument.GetDefHandler()->QueryInterface( IID_IOleCache2, (void**)&pIOleCache2 );
1965 ULONGGuard aGuard( &m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem
1966 if ( SUCCEEDED( hr ) && pIOleCache2 )
1967 return pIOleCache2->UpdateCache( pDataObject, grfUpdf, pReserved );
1970 return E_FAIL;
1973 //-------------------------------------------------------------------------------
1974 STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::DiscardCache( DWORD dwDiscardOptions )
1976 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::DiscardCache( DWORD dwDiscardOptions )" );
1977 if ( m_rOwnDocument.CheckDefHandler() )
1979 ComSmart< IOleCache2 > pIOleCache2;
1980 HRESULT hr = m_rOwnDocument.GetDefHandler()->QueryInterface( IID_IOleCache2, (void**)&pIOleCache2 );
1982 ULONGGuard aGuard( &m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem
1983 if ( SUCCEEDED( hr ) && pIOleCache2 )
1984 return pIOleCache2->DiscardCache( dwDiscardOptions );
1987 return E_FAIL;
1990 }; // namespace inprocserv