Update ooo320-m1
[ooovba.git] / embedserv / source / inprocserv / inprocembobj.cxx
blob3dce1d6157f29a34a5300852b1a98b0bdab5c2b0
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 if ( CheckDefHandler() )
868 ComSmart< IOleObject > pOleObject;
869 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
871 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
872 if ( SUCCEEDED( hr ) && pOleObject )
874 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetHostNames( LPCOLESTR szContainerApp, LPCOLESTR szContainerObj )" );
875 hr = pOleObject->SetHostNames( szContainerApp, szContainerObj );
879 return S_OK;
882 //-------------------------------------------------------------------------------
883 STDMETHODIMP InprocEmbedDocument_Impl::Close( DWORD dwSaveOption )
885 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Close( DWORD dwSaveOption )" );
886 if ( m_pDefHandler && CheckDefHandler() )
888 // no need to close if there is no default handler.
889 ComSmart< IOleObject > pOleObject;
890 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
892 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
893 if ( SUCCEEDED( hr ) && pOleObject )
895 hr = pOleObject->Close( dwSaveOption );
896 hr = CoDisconnectObject( (IUnknown*)(IPersistStorage*)this, 0 );
900 // if the object is closed from outside that means that it should go to uninitialized state
901 Clean();
903 return S_OK;
906 //-------------------------------------------------------------------------------
907 STDMETHODIMP InprocEmbedDocument_Impl::SetMoniker( DWORD dwWhichMoniker, IMoniker * pmk )
909 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetMoniker( DWORD dwWhichMoniker, IMoniker * pmk )" );
910 if ( CheckDefHandler() )
912 ComSmart< IOleObject > pOleObject;
913 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
915 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
916 if ( SUCCEEDED( hr ) && pOleObject )
917 return pOleObject->SetMoniker( dwWhichMoniker, pmk );
920 return E_FAIL;
923 //-------------------------------------------------------------------------------
924 STDMETHODIMP InprocEmbedDocument_Impl::GetMoniker( DWORD dwAssign, DWORD dwWhichMoniker, IMoniker ** ppmk )
926 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetMoniker( DWORD dwAssign, DWORD dwWhichMoniker, IMoniker ** ppmk )" );
927 if ( CheckDefHandler() )
929 ComSmart< IOleObject > pOleObject;
930 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
932 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
933 if ( SUCCEEDED( hr ) && pOleObject )
934 return pOleObject->GetMoniker( dwAssign, dwWhichMoniker, ppmk );
937 return E_FAIL;
940 //-------------------------------------------------------------------------------
941 STDMETHODIMP InprocEmbedDocument_Impl::InitFromData( IDataObject * pDataObject, BOOL fCreation, DWORD dwReserved )
943 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InitFromData( IDataObject * pDataObject, BOOL fCreation, DWORD dwReserved )" );
944 if ( CheckDefHandler() )
946 ComSmart< IOleObject > pOleObject;
947 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
949 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
950 if ( SUCCEEDED( hr ) && pOleObject )
951 return pOleObject->InitFromData( pDataObject, fCreation, dwReserved );
954 return E_FAIL;
957 //-------------------------------------------------------------------------------
958 STDMETHODIMP InprocEmbedDocument_Impl::GetClipboardData( DWORD dwReserved, IDataObject ** ppDataObject )
960 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetClipboardData( DWORD dwReserved, IDataObject ** ppDataObject )" );
961 if ( CheckDefHandler() )
963 ComSmart< IOleObject > pOleObject;
964 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
966 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
967 if ( SUCCEEDED( hr ) && pOleObject )
968 return pOleObject->GetClipboardData( dwReserved, ppDataObject );
971 return E_FAIL;
974 //-------------------------------------------------------------------------------
975 STDMETHODIMP InprocEmbedDocument_Impl::DoVerb(
976 LONG iVerb,
977 LPMSG pMsg,
978 IOleClientSite *pActiveSite,
979 LONG nLong,
980 HWND hWin,
981 LPCRECT pRect )
983 WRITEDEBUGINFO( "DoVerb" );
984 if ( CheckDefHandler() )
986 WRITEDEBUGINFO( "DoVerb" MY_STRING_LINE "n" );
987 ComSmart< IOleObject > pOleObject;
988 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
990 WRITEDEBUGINFO( "DoVerb" );
991 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
992 WRITEDEBUGINFO( "DoVerb" );
993 if ( SUCCEEDED( hr ) && pOleObject )
995 WRITEDEBUGINFO( "DoVerb" );
996 hr = pOleObject->DoVerb( iVerb, pMsg, pActiveSite, nLong, hWin, pRect );
997 if ( SUCCEEDED( hr ) )
999 WRITEDEBUGINFO( "DoVerb" );
1002 return hr;
1005 WRITEDEBUGINFO( "DoVerb" );
1008 return E_FAIL;
1011 //-------------------------------------------------------------------------------
1012 STDMETHODIMP InprocEmbedDocument_Impl::EnumVerbs( IEnumOLEVERB ** ppEnumOleVerb )
1014 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::EnumVerbs( IEnumOLEVERB ** ppEnumOleVerb )" );
1015 if ( CheckDefHandler() )
1017 ComSmart< IOleObject > pOleObject;
1018 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
1020 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1021 if ( SUCCEEDED( hr ) && pOleObject )
1022 return pOleObject->EnumVerbs( ppEnumOleVerb );
1025 return E_FAIL;
1028 //-------------------------------------------------------------------------------
1029 STDMETHODIMP InprocEmbedDocument_Impl::Update()
1031 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Update()" );
1033 if ( m_pDefHandler && CheckDefHandler() )
1035 ComSmart< IOleObject > pOleObject;
1036 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
1038 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1039 if ( SUCCEEDED( hr ) && pOleObject )
1040 return pOleObject->Update();
1043 return S_OK;
1046 //-------------------------------------------------------------------------------
1047 STDMETHODIMP InprocEmbedDocument_Impl::IsUpToDate()
1049 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::IsUpToDate()" );
1050 if ( CheckDefHandler() )
1052 ComSmart< IOleObject > pOleObject;
1053 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
1055 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1056 if ( SUCCEEDED( hr ) && pOleObject )
1057 return pOleObject->IsUpToDate();
1060 return E_FAIL;
1063 //-------------------------------------------------------------------------------
1064 STDMETHODIMP InprocEmbedDocument_Impl::GetUserClassID( CLSID *pClsid )
1066 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetUserClassID( CLSID *pClsid )" );
1067 if ( pClsid )
1068 *pClsid = m_guid;
1070 return S_OK;
1073 //-------------------------------------------------------------------------------
1074 STDMETHODIMP InprocEmbedDocument_Impl::GetUserType( DWORD dwFormOfType, LPOLESTR * pszUserType )
1076 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetUserType( DWORD dwFormOfType, LPOLESTR * pszUserType )" );
1077 if ( CheckDefHandler() )
1079 ComSmart< IOleObject > pOleObject;
1080 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
1082 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1083 if ( SUCCEEDED( hr ) && pOleObject )
1084 return pOleObject->GetUserType( dwFormOfType, pszUserType );
1087 return E_FAIL;
1090 //-------------------------------------------------------------------------------
1091 STDMETHODIMP InprocEmbedDocument_Impl::SetExtent( DWORD dwDrawAspect, SIZEL *psizel )
1093 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetExtent( DWORD dwDrawAspect, SIZEL *psizel )" );
1094 if ( CheckDefHandler() )
1096 ComSmart< IOleObject > pOleObject;
1097 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
1099 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1100 if ( SUCCEEDED( hr ) && pOleObject )
1101 return pOleObject->SetExtent( dwDrawAspect, psizel );
1104 return E_FAIL;
1107 //-------------------------------------------------------------------------------
1108 STDMETHODIMP InprocEmbedDocument_Impl::GetExtent( DWORD dwDrawAspect, SIZEL * psizel )
1110 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetExtent( DWORD dwDrawAspect, SIZEL * psizel )" );
1111 if ( CheckDefHandler() )
1113 ComSmart< IOleObject > pOleObject;
1114 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
1116 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1117 if ( SUCCEEDED( hr ) && pOleObject )
1118 return pOleObject->GetExtent( dwDrawAspect, psizel );
1121 return E_FAIL;
1124 //-------------------------------------------------------------------------------
1125 STDMETHODIMP InprocEmbedDocument_Impl::Advise( IAdviseSink *pAdvSink, DWORD *pdwConnection )
1127 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Advise( IAdviseSink *pAdvSink, DWORD *pdwConnection )" );
1129 if ( !pdwConnection )
1130 return E_FAIL;
1132 // CheckDefHandler will set the listener, avoid reusing of old listener
1133 if ( DEFAULT_ARRAY_LEN > *pdwConnection && *pdwConnection > 0 && m_pOleAdvises[*pdwConnection] )
1135 m_pOleAdvises[*pdwConnection]->DisconnectOrigAdvise();
1136 m_pOleAdvises[*pdwConnection] = NULL;
1139 if ( pAdvSink && CheckDefHandler() )
1141 ComSmart< IOleObject > pOleObject;
1142 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
1144 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1145 if ( SUCCEEDED( hr ) && pOleObject )
1147 ComSmart< OleWrapperAdviseSink > pOwnAdvise( new OleWrapperAdviseSink( pAdvSink ) );
1148 DWORD nRegID = 0;
1150 if ( SUCCEEDED( pOleObject->Advise( pOwnAdvise, &nRegID ) ) && nRegID > 0 )
1152 pOwnAdvise->SetRegID( nRegID );
1153 *pdwConnection = InsertAdviseLinkToList( pOwnAdvise, m_pOleAdvises );
1154 if ( *pdwConnection )
1155 return S_OK;
1156 else
1157 pOleObject->Unadvise( nRegID );
1162 // return success always for now
1163 return S_OK;
1166 //-------------------------------------------------------------------------------
1167 STDMETHODIMP InprocEmbedDocument_Impl::Unadvise( DWORD dwConnection )
1169 if ( DEFAULT_ARRAY_LEN > dwConnection && dwConnection > 0 && m_pOleAdvises[dwConnection] )
1171 if ( m_pDefHandler )
1173 ComSmart< IOleObject > pOleObject;
1174 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
1176 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1177 if ( SUCCEEDED( hr ) && pOleObject )
1179 DWORD nID = m_pOleAdvises[dwConnection]->GetRegID();
1180 pOleObject->Unadvise( nID );
1184 m_pOleAdvises[dwConnection]->DisconnectOrigAdvise();
1185 m_pOleAdvises[dwConnection] = NULL;
1187 return S_OK;
1190 return E_FAIL;
1193 //-------------------------------------------------------------------------------
1194 STDMETHODIMP InprocEmbedDocument_Impl::EnumAdvise( IEnumSTATDATA ** /*ppenumAdvise*/ )
1196 return E_NOTIMPL;
1198 // if ( CheckDefHandler() )
1199 // {
1200 // ComSmart< IOleObject > pOleObject;
1201 // HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
1203 // ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1204 // if ( SUCCEEDED( hr ) && pOleObject )
1205 // return pOleObject->EnumAdvise( ppenumAdvise );
1206 // }
1208 // return E_FAIL;
1211 //-------------------------------------------------------------------------------
1212 STDMETHODIMP InprocEmbedDocument_Impl::GetMiscStatus( DWORD dwAspect, DWORD * pdwStatus )
1214 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetMiscStatus( DWORD dwAspect, DWORD * pdwStatus )" );
1215 if ( CheckDefHandler() )
1217 ComSmart< IOleObject > pOleObject;
1218 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
1220 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1221 if ( SUCCEEDED( hr ) && pOleObject )
1222 return pOleObject->GetMiscStatus( dwAspect, pdwStatus );
1225 return E_FAIL;
1228 //-------------------------------------------------------------------------------
1229 STDMETHODIMP InprocEmbedDocument_Impl::SetColorScheme( LOGPALETTE * pLogpal )
1231 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetColorScheme( LOGPALETTE * pLogpal )" );
1232 if ( CheckDefHandler() )
1234 ComSmart< IOleObject > pOleObject;
1235 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
1237 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1238 if ( SUCCEEDED( hr ) && pOleObject )
1239 return pOleObject->SetColorScheme( pLogpal );
1242 return E_FAIL;
1245 //IDataObject
1246 //-------------------------------------------------------------------------------
1247 STDMETHODIMP InprocEmbedDocument_Impl::GetData( FORMATETC * pFormatetc, STGMEDIUM * pMedium )
1249 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetData( FORMATETC * pFormatetc, STGMEDIUM * pMedium )" );
1250 if ( CheckDefHandler() )
1252 ComSmart< IDataObject > pIDataObject;
1253 HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject );
1255 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1256 if ( SUCCEEDED( hr ) && pIDataObject )
1257 return pIDataObject->GetData( pFormatetc, pMedium );
1260 return E_FAIL;
1263 //-------------------------------------------------------------------------------
1264 STDMETHODIMP InprocEmbedDocument_Impl::GetDataHere( FORMATETC * pFormatetc, STGMEDIUM * pMedium )
1266 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetDataHere( FORMATETC * pFormatetc, STGMEDIUM * pMedium )" );
1267 if ( CheckDefHandler() )
1269 ComSmart< IDataObject > pIDataObject;
1270 HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject );
1272 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1273 if ( SUCCEEDED( hr ) && pIDataObject )
1274 return pIDataObject->GetDataHere( pFormatetc, pMedium );
1277 return E_FAIL;
1280 //-------------------------------------------------------------------------------
1281 STDMETHODIMP InprocEmbedDocument_Impl::QueryGetData( FORMATETC * pFormatetc )
1283 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::QueryGetData( FORMATETC * pFormatetc )" );
1284 if ( CheckDefHandler() )
1286 ComSmart< IDataObject > pIDataObject;
1287 HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject );
1289 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1290 if ( SUCCEEDED( hr ) && pIDataObject )
1291 return pIDataObject->QueryGetData( pFormatetc );
1294 return E_FAIL;
1297 //-------------------------------------------------------------------------------
1298 STDMETHODIMP InprocEmbedDocument_Impl::GetCanonicalFormatEtc( FORMATETC * pFormatetcIn, FORMATETC * pFormatetcOut )
1300 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetCanonicalFormatEtc( FORMATETC * pFormatetcIn, FORMATETC * pFormatetcOut )" );
1301 if ( CheckDefHandler() )
1303 ComSmart< IDataObject > pIDataObject;
1304 HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject );
1306 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1307 if ( SUCCEEDED( hr ) && pIDataObject )
1308 return pIDataObject->GetCanonicalFormatEtc( pFormatetcIn, pFormatetcOut );
1311 return E_FAIL;
1314 //-------------------------------------------------------------------------------
1315 STDMETHODIMP InprocEmbedDocument_Impl::SetData( FORMATETC * pFormatetc, STGMEDIUM * pMedium, BOOL fRelease )
1317 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetData( FORMATETC * pFormatetc, STGMEDIUM * pMedium, BOOL fRelease )" );
1318 if ( CheckDefHandler() )
1320 ComSmart< IDataObject > pIDataObject;
1321 HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject );
1323 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1324 if ( SUCCEEDED( hr ) && pIDataObject )
1325 return pIDataObject->SetData( pFormatetc, pMedium, fRelease );
1328 return E_FAIL;
1331 //-------------------------------------------------------------------------------
1332 STDMETHODIMP InprocEmbedDocument_Impl::EnumFormatEtc( DWORD dwDirection, IEnumFORMATETC ** ppFormatetc )
1334 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::EnumFormatEtc( DWORD dwDirection, IEnumFORMATETC ** ppFormatetc )" );
1335 if ( CheckDefHandler() )
1337 ComSmart< IDataObject > pIDataObject;
1338 HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject );
1340 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1341 if ( SUCCEEDED( hr ) && pIDataObject )
1342 return pIDataObject->EnumFormatEtc( dwDirection, ppFormatetc );
1345 return E_FAIL;
1348 //-------------------------------------------------------------------------------
1349 STDMETHODIMP InprocEmbedDocument_Impl::DAdvise( FORMATETC * pFormatetc, DWORD advf, IAdviseSink * pAdvSink, DWORD * pdwConnection )
1351 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::DAdvise( FORMATETC * pFormatetc, DWORD advf, IAdviseSink * pAdvSink, DWORD * pdwConnection )" );
1353 if ( !pdwConnection )
1354 return E_FAIL;
1356 // avoid reusing of the old listener
1357 if ( m_pDefHandler && DEFAULT_ARRAY_LEN > *pdwConnection && *pdwConnection > 0 && m_pDataAdvises[*pdwConnection] )
1359 m_pDataAdvises[*pdwConnection]->DisconnectOrigAdvise();
1360 m_pDataAdvises[*pdwConnection] = NULL;
1363 if ( pAdvSink && CheckDefHandler() )
1365 ComSmart< IDataObject > pIDataObject;
1366 HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject );
1368 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1369 if ( SUCCEEDED( hr ) && pIDataObject )
1371 ComSmart< OleWrapperAdviseSink > pOwnAdvise( new OleWrapperAdviseSink( ComSmart<IAdviseSink>( pAdvSink ), pFormatetc, advf ) );
1372 DWORD nRegID = 0;
1374 if ( SUCCEEDED( pIDataObject->DAdvise( pFormatetc, advf, pOwnAdvise, &nRegID ) ) && nRegID > 0 )
1376 pOwnAdvise->SetRegID( nRegID );
1377 *pdwConnection = InsertAdviseLinkToList( pOwnAdvise, m_pDataAdvises );
1378 if ( *pdwConnection )
1379 return S_OK;
1380 else
1381 pIDataObject->DUnadvise( nRegID );
1386 // return success always for now
1387 return S_OK;
1390 //-------------------------------------------------------------------------------
1391 STDMETHODIMP InprocEmbedDocument_Impl::DUnadvise( DWORD dwConnection )
1393 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::DUnadvise( DWORD dwConnection )" );
1394 if ( m_pDefHandler && DEFAULT_ARRAY_LEN > dwConnection && dwConnection > 0 && m_pDataAdvises[dwConnection] )
1396 if ( CheckDefHandler() )
1398 ComSmart< IDataObject > pIDataObject;
1399 HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject );
1401 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1402 if ( SUCCEEDED( hr ) && pIDataObject )
1404 DWORD nID = m_pDataAdvises[dwConnection]->GetRegID();
1405 pIDataObject->DUnadvise( nID );
1409 m_pDataAdvises[dwConnection]->DisconnectOrigAdvise();
1410 m_pDataAdvises[dwConnection] = NULL;
1412 return S_OK;
1415 return E_FAIL;
1418 //-------------------------------------------------------------------------------
1419 STDMETHODIMP InprocEmbedDocument_Impl::EnumDAdvise( IEnumSTATDATA ** ppenumAdvise )
1421 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::EnumDAdvise( IEnumSTATDATA ** ppenumAdvise )" );
1422 if ( CheckDefHandler() )
1424 ComSmart< IDataObject > pIDataObject;
1425 HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject );
1427 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1428 if ( SUCCEEDED( hr ) && pIDataObject )
1429 return pIDataObject->EnumDAdvise( ppenumAdvise );
1432 return E_FAIL;
1435 // IRunnableObject
1436 //-------------------------------------------------------------------------------
1437 STDMETHODIMP InprocEmbedDocument_Impl::GetRunningClass( LPCLSID lpClsid )
1439 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetRunningClass( LPCLSID lpClsid )" );
1440 if ( CheckDefHandler() )
1442 ComSmart< IRunnableObject > pIRunObj;
1443 HRESULT hr = m_pDefHandler->QueryInterface( IID_IRunnableObject, (void**)&pIRunObj );
1445 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1446 if ( SUCCEEDED( hr ) && pIRunObj )
1447 return pIRunObj->GetRunningClass( lpClsid );
1450 return E_FAIL;
1453 //-------------------------------------------------------------------------------
1454 STDMETHODIMP InprocEmbedDocument_Impl::Run( LPBINDCTX pbc )
1456 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Run( LPBINDCTX pbc )" );
1457 if ( CheckDefHandler() )
1459 ComSmart< IRunnableObject > pIRunObj;
1460 HRESULT hr = m_pDefHandler->QueryInterface( IID_IRunnableObject, (void**)&pIRunObj );
1462 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1463 if ( SUCCEEDED( hr ) && pIRunObj )
1464 return pIRunObj->Run( pbc );
1467 return E_FAIL;
1470 //-------------------------------------------------------------------------------
1471 BOOL STDMETHODCALLTYPE InprocEmbedDocument_Impl::IsRunning()
1473 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::IsRunning()" );
1474 if ( CheckDefHandler() )
1476 ComSmart< IRunnableObject > pIRunObj;
1477 HRESULT hr = m_pDefHandler->QueryInterface( IID_IRunnableObject, (void**)&pIRunObj );
1479 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1480 if ( SUCCEEDED( hr ) && pIRunObj )
1481 return pIRunObj->IsRunning();
1484 return E_FAIL;
1488 //-------------------------------------------------------------------------------
1489 STDMETHODIMP InprocEmbedDocument_Impl::LockRunning( BOOL fLock, BOOL fLastUnlockCloses )
1491 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::LockRunning( BOOL fLock, BOOL fLastUnlockCloses )" );
1492 if ( CheckDefHandler() )
1494 ComSmart< IRunnableObject > pIRunObj;
1495 HRESULT hr = m_pDefHandler->QueryInterface( IID_IRunnableObject, (void**)&pIRunObj );
1497 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1498 if ( SUCCEEDED( hr ) && pIRunObj )
1499 return pIRunObj->LockRunning( fLock, fLastUnlockCloses );
1502 return E_FAIL;
1505 //-------------------------------------------------------------------------------
1506 STDMETHODIMP InprocEmbedDocument_Impl::SetContainedObject( BOOL fContained)
1508 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetContainedObject( BOOL fContained)" );
1509 if ( CheckDefHandler() )
1511 ComSmart< IRunnableObject > pIRunObj;
1512 HRESULT hr = m_pDefHandler->QueryInterface( IID_IRunnableObject, (void**)&pIRunObj );
1514 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1515 if ( SUCCEEDED( hr ) && pIRunObj )
1516 return pIRunObj->SetContainedObject( fContained );
1519 return E_FAIL;
1523 // IViewObject methods
1524 //-------------------------------------------------------------------------------
1525 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 )
1527 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 )" );
1528 if ( CheckDefHandler() )
1530 ComSmart< IViewObject > pIViewObject;
1531 HRESULT hr = m_pDefHandler->QueryInterface( IID_IViewObject, (void**)&pIViewObject );
1533 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1534 if ( SUCCEEDED( hr ) && pIViewObject )
1535 return pIViewObject->Draw( dwDrawAspect, lindex, pvAspect, ptd, hdcTargetDev, hdcDraw, lprcBounds, lprcWBounds, pfnContinue, dwContinue );
1538 return E_FAIL;
1541 //-------------------------------------------------------------------------------
1542 STDMETHODIMP InprocEmbedDocument_Impl::GetColorSet( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet )
1544 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetColorSet( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet )" );
1545 if ( CheckDefHandler() )
1547 ComSmart< IViewObject > pIViewObject;
1548 HRESULT hr = m_pDefHandler->QueryInterface( IID_IViewObject, (void**)&pIViewObject );
1550 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1551 if ( SUCCEEDED( hr ) && pIViewObject )
1552 return pIViewObject->GetColorSet( dwDrawAspect, lindex, pvAspect, ptd, hicTargetDev, ppColorSet );
1555 return E_FAIL;
1558 //-------------------------------------------------------------------------------
1559 STDMETHODIMP InprocEmbedDocument_Impl::Freeze( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DWORD *pdwFreeze )
1561 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Freeze( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DWORD *pdwFreeze )" );
1562 if ( CheckDefHandler() )
1564 ComSmart< IViewObject > pIViewObject;
1565 HRESULT hr = m_pDefHandler->QueryInterface( IID_IViewObject, (void**)&pIViewObject );
1567 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1568 if ( SUCCEEDED( hr ) && pIViewObject )
1569 return pIViewObject->Freeze( dwDrawAspect, lindex, pvAspect, pdwFreeze );
1572 return E_FAIL;
1575 //-------------------------------------------------------------------------------
1576 STDMETHODIMP InprocEmbedDocument_Impl::Unfreeze( DWORD dwFreeze )
1578 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Unfreeze( DWORD dwFreeze )" );
1579 if ( CheckDefHandler() )
1581 ComSmart< IViewObject > pIViewObject;
1582 HRESULT hr = m_pDefHandler->QueryInterface( IID_IViewObject, (void**)&pIViewObject );
1584 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1585 if ( SUCCEEDED( hr ) && pIViewObject )
1586 return pIViewObject->Unfreeze( dwFreeze );
1589 return E_FAIL;
1592 //-------------------------------------------------------------------------------
1593 STDMETHODIMP InprocEmbedDocument_Impl::SetAdvise( DWORD aspects, DWORD advf, IAdviseSink *pAdvSink )
1595 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetAdvise( DWORD aspects, DWORD advf, IAdviseSink *pAdvSink )" );
1597 // CheckDefHandler will set the listener, avoid reusing of old listener
1598 if ( m_pViewAdvise )
1600 m_pViewAdvise->DisconnectOrigAdvise();
1601 m_pViewAdvise = NULL;
1604 if ( pAdvSink && CheckDefHandler() )
1606 ComSmart< IViewObject > pIViewObject;
1607 HRESULT hr = m_pDefHandler->QueryInterface( IID_IViewObject, (void**)&pIViewObject );
1609 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1610 if ( SUCCEEDED( hr ) && pIViewObject )
1612 ComSmart< OleWrapperAdviseSink > pOwnAdvise( new OleWrapperAdviseSink( pAdvSink, aspects, advf ) );
1614 if ( SUCCEEDED( pIViewObject->SetAdvise( aspects, advf, pOwnAdvise ) ) )
1616 m_pViewAdvise = pOwnAdvise;
1617 return S_OK;
1622 return S_OK;
1625 //-------------------------------------------------------------------------------
1626 STDMETHODIMP InprocEmbedDocument_Impl::GetAdvise( DWORD *pAspects, DWORD *pAdvf, IAdviseSink **ppAdvSink )
1628 if ( !ppAdvSink )
1629 return E_INVALIDARG;
1631 if ( m_pViewAdvise )
1633 if ( pAspects )
1634 *pAspects = m_pViewAdvise->GetAspect();
1636 if ( pAdvf )
1637 *pAdvf = m_pViewAdvise->GetViewAdviseFlag();
1639 *ppAdvSink = m_pViewAdvise->GetOrigAdvise();
1640 if ( *ppAdvSink )
1641 (*ppAdvSink)->AddRef();
1643 else
1644 *ppAdvSink = NULL;
1646 return S_OK;
1649 // IViewObject2 methods
1650 //-------------------------------------------------------------------------------
1651 STDMETHODIMP InprocEmbedDocument_Impl::GetExtent( DWORD dwDrawAspect, LONG lindex, DVTARGETDEVICE *ptd, LPSIZEL lpsizel )
1653 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetExtent( DWORD dwDrawAspect, LONG lindex, DVTARGETDEVICE *ptd, LPSIZEL lpsizel )" );
1654 if ( CheckDefHandler() )
1656 ComSmart< IViewObject2 > pIViewObject2;
1657 HRESULT hr = m_pDefHandler->QueryInterface( IID_IViewObject2, (void**)&pIViewObject2 );
1659 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1660 if ( SUCCEEDED( hr ) && pIViewObject2 )
1661 return pIViewObject2->GetExtent( dwDrawAspect, lindex, ptd, lpsizel );
1664 return E_FAIL;
1669 // IOleWindow methods
1670 //-------------------------------------------------------------------------------
1671 STDMETHODIMP InprocEmbedDocument_Impl::GetWindow( HWND *phwnd )
1673 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetWindow( HWND *phwnd )" );
1674 if ( CheckDefHandler() )
1676 ComSmart< IOleWindow > pIOleWindow;
1677 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleWindow, (void**)&pIOleWindow );
1679 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1680 if ( SUCCEEDED( hr ) && pIOleWindow )
1681 return pIOleWindow->GetWindow( phwnd );
1684 return E_FAIL;
1687 //-------------------------------------------------------------------------------
1688 STDMETHODIMP InprocEmbedDocument_Impl::ContextSensitiveHelp( BOOL fEnterMode )
1690 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::ContextSensitiveHelp( BOOL fEnterMode )" );
1691 if ( CheckDefHandler() )
1693 ComSmart< IOleWindow > pIOleWindow;
1694 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleWindow, (void**)&pIOleWindow );
1696 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1697 if ( SUCCEEDED( hr ) && pIOleWindow )
1698 return pIOleWindow->ContextSensitiveHelp( fEnterMode );
1701 return E_FAIL;
1705 // IOleInPlaceObject methods
1706 //-------------------------------------------------------------------------------
1707 STDMETHODIMP InprocEmbedDocument_Impl::InPlaceDeactivate( void )
1709 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InPlaceDeactivate( void )" );
1710 if ( CheckDefHandler() )
1712 ComSmart< IOleInPlaceObject > pIOleInPlaceObject;
1713 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleInPlaceObject, (void**)&pIOleInPlaceObject );
1715 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1716 if ( SUCCEEDED( hr ) && pIOleInPlaceObject )
1717 return pIOleInPlaceObject->InPlaceDeactivate();
1720 return E_FAIL;
1723 //-------------------------------------------------------------------------------
1724 STDMETHODIMP InprocEmbedDocument_Impl::UIDeactivate( void )
1726 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::UIDeactivate( void )" );
1727 if ( CheckDefHandler() )
1729 ComSmart< IOleInPlaceObject > pIOleInPlaceObject;
1730 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleInPlaceObject, (void**)&pIOleInPlaceObject );
1732 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1733 if ( SUCCEEDED( hr ) && pIOleInPlaceObject )
1734 return pIOleInPlaceObject->UIDeactivate();
1737 return E_FAIL;
1740 //-------------------------------------------------------------------------------
1741 STDMETHODIMP InprocEmbedDocument_Impl::SetObjectRects( LPCRECT lprcPosRect, LPCRECT lprcClipRect )
1743 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetObjectRects( LPCRECT lprcPosRect, LPCRECT lprcClipRect )" );
1744 if ( CheckDefHandler() )
1746 ComSmart< IOleInPlaceObject > pIOleInPlaceObject;
1747 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleInPlaceObject, (void**)&pIOleInPlaceObject );
1749 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1750 if ( SUCCEEDED( hr ) && pIOleInPlaceObject )
1751 return pIOleInPlaceObject->SetObjectRects( lprcPosRect, lprcClipRect );
1754 return E_FAIL;
1757 //-------------------------------------------------------------------------------
1758 STDMETHODIMP InprocEmbedDocument_Impl::ReactivateAndUndo( void )
1760 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::ReactivateAndUndo( void )" );
1761 if ( CheckDefHandler() )
1763 ComSmart< IOleInPlaceObject > pIOleInPlaceObject;
1764 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleInPlaceObject, (void**)&pIOleInPlaceObject );
1766 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1767 if ( SUCCEEDED( hr ) && pIOleInPlaceObject )
1768 return pIOleInPlaceObject->ReactivateAndUndo();
1771 return E_FAIL;
1775 // IDispatch methods
1776 //-------------------------------------------------------------------------------
1777 STDMETHODIMP InprocEmbedDocument_Impl::GetTypeInfoCount( UINT *pctinfo )
1779 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetTypeInfoCount( UINT *pctinfo )" );
1780 if ( CheckDefHandler() )
1782 ComSmart< IDispatch > pIDispatch;
1783 HRESULT hr = m_pDefHandler->QueryInterface( IID_IDispatch, (void**)&pIDispatch );
1785 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1786 if ( SUCCEEDED( hr ) && pIDispatch )
1787 return pIDispatch->GetTypeInfoCount( pctinfo );
1790 return E_FAIL;
1793 //-------------------------------------------------------------------------------
1794 STDMETHODIMP InprocEmbedDocument_Impl::GetTypeInfo( UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo )
1796 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetTypeInfo( UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo )" );
1797 if ( CheckDefHandler() )
1799 ComSmart< IDispatch > pIDispatch;
1800 HRESULT hr = m_pDefHandler->QueryInterface( IID_IDispatch, (void**)&pIDispatch );
1802 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1803 if ( SUCCEEDED( hr ) && pIDispatch )
1804 return pIDispatch->GetTypeInfo( iTInfo, lcid, ppTInfo );
1807 return E_FAIL;
1810 //-------------------------------------------------------------------------------
1811 STDMETHODIMP InprocEmbedDocument_Impl::GetIDsOfNames( REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId )
1813 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetIDsOfNames( REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId )" );
1814 if ( CheckDefHandler() )
1816 ComSmart< IDispatch > pIDispatch;
1817 HRESULT hr = m_pDefHandler->QueryInterface( IID_IDispatch, (void**)&pIDispatch );
1819 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1820 if ( SUCCEEDED( hr ) && pIDispatch )
1821 return pIDispatch->GetIDsOfNames( riid, rgszNames, cNames, lcid, rgDispId );
1824 return E_FAIL;
1827 //-------------------------------------------------------------------------------
1828 STDMETHODIMP InprocEmbedDocument_Impl::Invoke( DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr )
1830 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Invoke( DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr )" );
1831 if ( CheckDefHandler() )
1833 ComSmart< IDispatch > pIDispatch;
1834 HRESULT hr = m_pDefHandler->QueryInterface( IID_IDispatch, (void**)&pIDispatch );
1836 ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1837 if ( SUCCEEDED( hr ) && pIDispatch )
1838 return pIDispatch->Invoke( dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr );
1841 return E_FAIL;
1845 // ====
1846 // InternalCacheWrapper
1847 // ====
1849 // IUnknown
1850 //-------------------------------------------------------------------------------
1851 STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::QueryInterface( REFIID riid, void FAR* FAR* ppv )
1853 return m_rOwnDocument.QueryInterface( riid, ppv );
1856 //-------------------------------------------------------------------------------
1857 STDMETHODIMP_(ULONG) InprocEmbedDocument_Impl::InternalCacheWrapper::AddRef()
1859 return m_rOwnDocument.AddRef();
1862 //-------------------------------------------------------------------------------
1863 STDMETHODIMP_(ULONG) InprocEmbedDocument_Impl::InternalCacheWrapper::Release()
1865 return m_rOwnDocument.Release();
1868 // IOleCache methods
1869 //-------------------------------------------------------------------------------
1870 STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::Cache( FORMATETC *pformatetc, DWORD advf, DWORD *pdwConnection )
1872 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::Cache( FORMATETC *pformatetc, DWORD advf, DWORD *pdwConnection )" );
1873 if ( m_rOwnDocument.CheckDefHandler() )
1875 ComSmart< IOleCache > pIOleCache;
1876 HRESULT hr = m_rOwnDocument.GetDefHandler()->QueryInterface( IID_IOleCache, (void**)&pIOleCache );
1878 ULONGGuard aGuard( &m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem
1879 if ( SUCCEEDED( hr ) && pIOleCache )
1880 return pIOleCache->Cache( pformatetc, advf, pdwConnection );
1883 return E_FAIL;
1886 //-------------------------------------------------------------------------------
1887 STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::Uncache( DWORD dwConnection )
1889 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::Uncache( DWORD dwConnection )" );
1890 if ( m_rOwnDocument.CheckDefHandler() )
1892 ComSmart< IOleCache > pIOleCache;
1893 HRESULT hr = m_rOwnDocument.GetDefHandler()->QueryInterface( IID_IOleCache, (void**)&pIOleCache );
1895 ULONGGuard aGuard( &m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem
1896 if ( SUCCEEDED( hr ) && pIOleCache )
1897 return pIOleCache->Uncache( dwConnection );
1900 return E_FAIL;
1903 //-------------------------------------------------------------------------------
1904 STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::EnumCache( IEnumSTATDATA **ppenumSTATDATA )
1906 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::EnumCache( IEnumSTATDATA **ppenumSTATDATA )" );
1907 if ( m_rOwnDocument.CheckDefHandler() )
1909 ComSmart< IOleCache > pIOleCache;
1910 HRESULT hr = m_rOwnDocument.GetDefHandler()->QueryInterface( IID_IOleCache, (void**)&pIOleCache );
1912 ULONGGuard aGuard( &m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem
1913 if ( SUCCEEDED( hr ) && pIOleCache )
1914 return pIOleCache->EnumCache( ppenumSTATDATA );
1917 return E_FAIL;
1920 //-------------------------------------------------------------------------------
1921 STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::InitCache( IDataObject *pDataObject )
1923 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::InitCache( IDataObject *pDataObject )" );
1924 if ( m_rOwnDocument.CheckDefHandler() )
1926 ComSmart< IOleCache > pIOleCache;
1927 HRESULT hr = m_rOwnDocument.GetDefHandler()->QueryInterface( IID_IOleCache, (void**)&pIOleCache );
1929 ULONGGuard aGuard( &m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem
1930 if ( SUCCEEDED( hr ) && pIOleCache )
1931 return pIOleCache->InitCache( pDataObject );
1934 return E_FAIL;
1937 //-------------------------------------------------------------------------------
1938 STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::SetData( FORMATETC *pformatetc, STGMEDIUM *pmedium, BOOL fRelease )
1940 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::SetData( FORMATETC *pformatetc, STGMEDIUM *pmedium, BOOL fRelease )" );
1941 if ( m_rOwnDocument.CheckDefHandler() )
1943 ComSmart< IOleCache > pIOleCache;
1944 HRESULT hr = m_rOwnDocument.GetDefHandler()->QueryInterface( IID_IOleCache, (void**)&pIOleCache );
1946 ULONGGuard aGuard( &m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem
1947 if ( SUCCEEDED( hr ) && pIOleCache )
1948 return pIOleCache->SetData( pformatetc, pmedium, fRelease );
1951 return E_FAIL;
1954 // IOleCache2 methods
1955 //-------------------------------------------------------------------------------
1956 STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::UpdateCache( LPDATAOBJECT pDataObject, DWORD grfUpdf, LPVOID pReserved )
1958 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::UpdateCache( LPDATAOBJECT pDataObject, DWORD grfUpdf, LPVOID pReserved )" );
1959 if ( m_rOwnDocument.CheckDefHandler() )
1961 ComSmart< IOleCache2 > pIOleCache2;
1962 HRESULT hr = m_rOwnDocument.GetDefHandler()->QueryInterface( IID_IOleCache2, (void**)&pIOleCache2 );
1964 ULONGGuard aGuard( &m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem
1965 if ( SUCCEEDED( hr ) && pIOleCache2 )
1966 return pIOleCache2->UpdateCache( pDataObject, grfUpdf, pReserved );
1969 return E_FAIL;
1972 //-------------------------------------------------------------------------------
1973 STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::DiscardCache( DWORD dwDiscardOptions )
1975 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::DiscardCache( DWORD dwDiscardOptions )" );
1976 if ( m_rOwnDocument.CheckDefHandler() )
1978 ComSmart< IOleCache2 > pIOleCache2;
1979 HRESULT hr = m_rOwnDocument.GetDefHandler()->QueryInterface( IID_IOleCache2, (void**)&pIOleCache2 );
1981 ULONGGuard aGuard( &m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem
1982 if ( SUCCEEDED( hr ) && pIOleCache2 )
1983 return pIOleCache2->DiscardCache( dwDiscardOptions );
1986 return E_FAIL;
1989 }; // namespace inprocserv