xref: /AOO41X/main/embedserv/source/inprocserv/inprocembobj.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include <embservconst.h>
29*cdf0e10cSrcweir #include "inprocembobj.h"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir namespace inprocserv
32*cdf0e10cSrcweir {
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #ifdef OWNDEBUG
35*cdf0e10cSrcweir //-------------------------------------------------------------------------------
36*cdf0e10cSrcweir void WriteDebugInfo( DWORD pThis, char* pString, DWORD nToWrite )
37*cdf0e10cSrcweir {
38*cdf0e10cSrcweir     if ( nToWrite )
39*cdf0e10cSrcweir     {
40*cdf0e10cSrcweir         char pNumber[12];
41*cdf0e10cSrcweir         pNumber[0] = '0';
42*cdf0e10cSrcweir         pNumber[1] = 'x';
43*cdf0e10cSrcweir         for ( int nInd = 0; nInd < 8; nInd++ )
44*cdf0e10cSrcweir             pNumber[nInd+2] = (char)( ( pThis / ( 1 << ( 7 - nInd ) ) ) % 16 ) + 48;
45*cdf0e10cSrcweir         pNumber[10] = ' ';
46*cdf0e10cSrcweir         pNumber[11] = 0;
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir         HANDLE pFile = CreateFileA( "h:\\inproc.log", GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, 0, NULL );
49*cdf0e10cSrcweir         if ( pFile )
50*cdf0e10cSrcweir         {
51*cdf0e10cSrcweir             DWORD dwWritten = 0;
52*cdf0e10cSrcweir             SetFilePointer( pFile, 0, 0, FILE_END );
53*cdf0e10cSrcweir             WriteFile( pFile, pNumber, 11, &dwWritten, NULL );
54*cdf0e10cSrcweir             WriteFile( pFile, pString, nToWrite - 1, &dwWritten, NULL );
55*cdf0e10cSrcweir             CloseHandle( pFile );
56*cdf0e10cSrcweir         }
57*cdf0e10cSrcweir     }
58*cdf0e10cSrcweir }
59*cdf0e10cSrcweir #endif
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir //-------------------------------------------------------------------------------
62*cdf0e10cSrcweir BOOL StringsEqual( LPCOLESTR pszNameFromOutside, wchar_t* pOwnName )
63*cdf0e10cSrcweir {
64*cdf0e10cSrcweir     BOOL bResult = TRUE;
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir     if ( pszNameFromOutside && pOwnName )
67*cdf0e10cSrcweir     {
68*cdf0e10cSrcweir         for ( int nInd = 0; pszNameFromOutside[nInd] != 0 || pOwnName[nInd] != 0; nInd++ )
69*cdf0e10cSrcweir         {
70*cdf0e10cSrcweir             if ( pszNameFromOutside[nInd] != pOwnName[nInd] )
71*cdf0e10cSrcweir             {
72*cdf0e10cSrcweir                 bResult = FALSE;
73*cdf0e10cSrcweir                 break;
74*cdf0e10cSrcweir             }
75*cdf0e10cSrcweir         }
76*cdf0e10cSrcweir     }
77*cdf0e10cSrcweir     else if ( pszNameFromOutside || pOwnName )
78*cdf0e10cSrcweir         bResult = FALSE;
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir     return bResult;
81*cdf0e10cSrcweir }
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir //-------------------------------------------------------------------------------
84*cdf0e10cSrcweir HRESULT InprocEmbedDocument_Impl::Init()
85*cdf0e10cSrcweir {
86*cdf0e10cSrcweir 	return S_OK;
87*cdf0e10cSrcweir }
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir //-------------------------------------------------------------------------------
90*cdf0e10cSrcweir void InprocEmbedDocument_Impl::SetName( LPCOLESTR pszNameFromOutside, wchar_t*& pOwnName )
91*cdf0e10cSrcweir {
92*cdf0e10cSrcweir     if ( !pszNameFromOutside )
93*cdf0e10cSrcweir         return;
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir     // copy the string
96*cdf0e10cSrcweir     size_t nLen = 0;
97*cdf0e10cSrcweir     while( pszNameFromOutside[nLen] != 0 )
98*cdf0e10cSrcweir         nLen++;
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir     if ( pOwnName )
101*cdf0e10cSrcweir     {
102*cdf0e10cSrcweir         delete[] pOwnName;
103*cdf0e10cSrcweir         pOwnName = NULL;
104*cdf0e10cSrcweir     }
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir     pOwnName = new wchar_t[nLen+1];
107*cdf0e10cSrcweir     for ( size_t nInd = 0; nInd < nLen; nInd++ )
108*cdf0e10cSrcweir         pOwnName[nInd] = pszNameFromOutside[nInd];
109*cdf0e10cSrcweir     pOwnName[nLen] = 0;
110*cdf0e10cSrcweir }
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir //-------------------------------------------------------------------------------
113*cdf0e10cSrcweir BOOL InprocEmbedDocument_Impl::CheckDefHandler()
114*cdf0e10cSrcweir {
115*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
116*cdf0e10cSrcweir     // set the own listener
117*cdf0e10cSrcweir     if ( m_pOleAdvises[0] == NULL )
118*cdf0e10cSrcweir     {
119*cdf0e10cSrcweir         WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
120*cdf0e10cSrcweir         m_pOleAdvises[0] = new OleWrapperAdviseSink();
121*cdf0e10cSrcweir     }
122*cdf0e10cSrcweir     else
123*cdf0e10cSrcweir     {
124*cdf0e10cSrcweir         WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
125*cdf0e10cSrcweir         if ( m_pOleAdvises[0]->IsClosed() )
126*cdf0e10cSrcweir         {
127*cdf0e10cSrcweir             WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
128*cdf0e10cSrcweir             if ( m_pDefHandler )
129*cdf0e10cSrcweir             {
130*cdf0e10cSrcweir                 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
131*cdf0e10cSrcweir                 // deregister all the listeners
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir                 ComSmart< IOleObject > pOleObject;
134*cdf0e10cSrcweir                 HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
135*cdf0e10cSrcweir                 if ( SUCCEEDED( hr ) && pOleObject )
136*cdf0e10cSrcweir                 {
137*cdf0e10cSrcweir                     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
138*cdf0e10cSrcweir                     for ( DWORD nInd = 0; nInd < DEFAULT_ARRAY_LEN; nInd++ )
139*cdf0e10cSrcweir                         if ( m_pOleAdvises[nInd] )
140*cdf0e10cSrcweir                         {
141*cdf0e10cSrcweir                             DWORD nID = m_pOleAdvises[nInd]->GetRegID();
142*cdf0e10cSrcweir                             pOleObject->Unadvise( nID );
143*cdf0e10cSrcweir                             m_pOleAdvises[nInd]->SetRegID( 0 );
144*cdf0e10cSrcweir                         }
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir                     pOleObject->SetClientSite( NULL );
147*cdf0e10cSrcweir                 }
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir                 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
150*cdf0e10cSrcweir                 ComSmart< IDataObject > pIDataObject;
151*cdf0e10cSrcweir                 hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject );
152*cdf0e10cSrcweir                 if ( SUCCEEDED( hr ) && pIDataObject )
153*cdf0e10cSrcweir                 {
154*cdf0e10cSrcweir                     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
155*cdf0e10cSrcweir                     for ( DWORD nInd = 0; nInd < DEFAULT_ARRAY_LEN; nInd++ )
156*cdf0e10cSrcweir                         if ( m_pDataAdvises[nInd] )
157*cdf0e10cSrcweir                         {
158*cdf0e10cSrcweir                             DWORD nID = m_pDataAdvises[nInd]->GetRegID();
159*cdf0e10cSrcweir                             pIDataObject->DUnadvise( nID );
160*cdf0e10cSrcweir                             m_pDataAdvises[nInd]->SetRegID( 0 );
161*cdf0e10cSrcweir                         }
162*cdf0e10cSrcweir                 }
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir                 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
165*cdf0e10cSrcweir                 ComSmart< IViewObject > pIViewObject;
166*cdf0e10cSrcweir                 hr = m_pDefHandler->QueryInterface( IID_IViewObject, (void**)&pIViewObject );
167*cdf0e10cSrcweir                 if ( SUCCEEDED( hr ) && pIViewObject )
168*cdf0e10cSrcweir                 {
169*cdf0e10cSrcweir                     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
170*cdf0e10cSrcweir                     if ( m_pViewAdvise )
171*cdf0e10cSrcweir                         pIViewObject->SetAdvise( m_pViewAdvise->GetAspect(), m_pViewAdvise->GetViewAdviseFlag(), NULL );
172*cdf0e10cSrcweir                     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
173*cdf0e10cSrcweir                 }
174*cdf0e10cSrcweir                 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir                 ComSmart< IPersistStorage > pPersist;
177*cdf0e10cSrcweir                 hr = m_pDefHandler->QueryInterface( IID_IPersistStorage, (void**)&pPersist );
178*cdf0e10cSrcweir                 if ( SUCCEEDED( hr ) && pPersist )
179*cdf0e10cSrcweir                 {
180*cdf0e10cSrcweir                     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
181*cdf0e10cSrcweir                     // disconnect the old wrapper from the storage
182*cdf0e10cSrcweir                     pPersist->HandsOffStorage();
183*cdf0e10cSrcweir                 }
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir                 m_pDefHandler = NULL;
186*cdf0e10cSrcweir             }
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir             WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
189*cdf0e10cSrcweir             m_pOleAdvises[0]->UnsetClosed();
190*cdf0e10cSrcweir         }
191*cdf0e10cSrcweir     }
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir     if ( m_nCallsOnStack )
194*cdf0e10cSrcweir         return FALSE;
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
197*cdf0e10cSrcweir     if ( !m_pDefHandler )
198*cdf0e10cSrcweir     {
199*cdf0e10cSrcweir         WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
200*cdf0e10cSrcweir         // create a new default inprocess handler
201*cdf0e10cSrcweir         HRESULT hr = OleCreateDefaultHandler( m_guid, NULL, IID_IUnknown, (void**)&m_pDefHandler );
202*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) )
203*cdf0e10cSrcweir         {
204*cdf0e10cSrcweir             WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
205*cdf0e10cSrcweir //            // reinit the handler
206*cdf0e10cSrcweir //            ComSmart< IRunnableObject > pIRunObj;
207*cdf0e10cSrcweir //            hr = m_pDefHandler->QueryInterface( IID_IRunnableObject, (void**)&pIRunObj );
208*cdf0e10cSrcweir //
209*cdf0e10cSrcweir //            if ( SUCCEEDED( hr ) && pIRunObj )
210*cdf0e10cSrcweir             {
211*cdf0e10cSrcweir //                {
212*cdf0e10cSrcweir //                    ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
213*cdf0e10cSrcweir //                    hr = pIRunObj->Run( NULL );
214*cdf0e10cSrcweir //                }
215*cdf0e10cSrcweir //
216*cdf0e10cSrcweir //                if ( SUCCEEDED( hr ) )
217*cdf0e10cSrcweir                 {
218*cdf0e10cSrcweir                     if ( m_nInitMode == INIT_FROM_STORAGE )
219*cdf0e10cSrcweir                     {
220*cdf0e10cSrcweir                         WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
221*cdf0e10cSrcweir                         ComSmart< IPersistStorage > pPersist;
222*cdf0e10cSrcweir                         hr = m_pDefHandler->QueryInterface( IID_IPersistStorage, (void**)&pPersist );
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir                         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
225*cdf0e10cSrcweir                         if ( SUCCEEDED( hr ) && pPersist && m_pStorage )
226*cdf0e10cSrcweir                             hr = pPersist->InitNew( m_pStorage );
227*cdf0e10cSrcweir                     }
228*cdf0e10cSrcweir                     else if ( m_nInitMode == LOAD_FROM_STORAGE )
229*cdf0e10cSrcweir                     {
230*cdf0e10cSrcweir                         WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
231*cdf0e10cSrcweir                         ComSmart< IPersistStorage > pPersist;
232*cdf0e10cSrcweir                         hr = m_pDefHandler->QueryInterface( IID_IPersistStorage, (void**)&pPersist );
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir                         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
235*cdf0e10cSrcweir                         if ( SUCCEEDED( hr ) && pPersist && m_pStorage )
236*cdf0e10cSrcweir                             hr = pPersist->Load( m_pStorage );
237*cdf0e10cSrcweir                     }
238*cdf0e10cSrcweir                     else if ( m_nInitMode == LOAD_FROM_FILE )
239*cdf0e10cSrcweir                     {
240*cdf0e10cSrcweir                         WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
241*cdf0e10cSrcweir                         ComSmart< IPersistFile > pPersistFile;
242*cdf0e10cSrcweir                         hr = m_pDefHandler->QueryInterface( IID_IPersistFile, (void**)&pPersistFile );
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir                         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
245*cdf0e10cSrcweir                         if ( SUCCEEDED( hr ) && pPersistFile && m_pFileName )
246*cdf0e10cSrcweir                             hr = pPersistFile->Load( m_pFileName, m_nFileOpenMode );
247*cdf0e10cSrcweir                     }
248*cdf0e10cSrcweir                     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
249*cdf0e10cSrcweir                 }
250*cdf0e10cSrcweir             }
251*cdf0e10cSrcweir         }
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir         WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
254*cdf0e10cSrcweir         if ( !SUCCEEDED( hr ) || !m_pDefHandler )
255*cdf0e10cSrcweir         {
256*cdf0e10cSrcweir             WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
257*cdf0e10cSrcweir             m_pDefHandler = NULL;
258*cdf0e10cSrcweir             return FALSE;
259*cdf0e10cSrcweir         }
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir         // register all the listeners new
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir         ComSmart< IOleObject > pOleObject;
264*cdf0e10cSrcweir         hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
265*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pOleObject )
266*cdf0e10cSrcweir         {
267*cdf0e10cSrcweir             WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
268*cdf0e10cSrcweir             if ( m_pClientSite )
269*cdf0e10cSrcweir                 pOleObject->SetClientSite( m_pClientSite );
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir             WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
272*cdf0e10cSrcweir             for ( DWORD nInd = 0; nInd < DEFAULT_ARRAY_LEN; nInd++ )
273*cdf0e10cSrcweir                 if ( m_pOleAdvises[nInd] )
274*cdf0e10cSrcweir                 {
275*cdf0e10cSrcweir                     DWORD nRegID = 0;
276*cdf0e10cSrcweir                     if ( SUCCEEDED( pOleObject->Advise( m_pOleAdvises[nInd], &nRegID ) ) && nRegID > 0 )
277*cdf0e10cSrcweir                         m_pOleAdvises[nInd]->SetRegID( nRegID );
278*cdf0e10cSrcweir                 }
279*cdf0e10cSrcweir         }
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir         WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
282*cdf0e10cSrcweir         ComSmart< IDataObject > pIDataObject;
283*cdf0e10cSrcweir         hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject );
284*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIDataObject )
285*cdf0e10cSrcweir         {
286*cdf0e10cSrcweir             WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
287*cdf0e10cSrcweir             for ( DWORD nInd = 0; nInd < DEFAULT_ARRAY_LEN; nInd++ )
288*cdf0e10cSrcweir                 if ( m_pDataAdvises[nInd] )
289*cdf0e10cSrcweir                 {
290*cdf0e10cSrcweir                     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
291*cdf0e10cSrcweir                     DWORD nRegID = 0;
292*cdf0e10cSrcweir                     if ( SUCCEEDED( pIDataObject->DAdvise( m_pDataAdvises[nInd]->GetFormatEtc(), m_pDataAdvises[nInd]->GetDataAdviseFlag(), m_pDataAdvises[nInd], &nRegID ) ) && nRegID > 0 )
293*cdf0e10cSrcweir                         m_pDataAdvises[nInd]->SetRegID( nRegID );
294*cdf0e10cSrcweir                     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
295*cdf0e10cSrcweir                 }
296*cdf0e10cSrcweir         }
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir         WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
299*cdf0e10cSrcweir         ComSmart< IViewObject > pIViewObject;
300*cdf0e10cSrcweir         hr = m_pDefHandler->QueryInterface( IID_IViewObject, (void**)&pIViewObject );
301*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIViewObject )
302*cdf0e10cSrcweir         {
303*cdf0e10cSrcweir             WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
304*cdf0e10cSrcweir             if ( m_pViewAdvise )
305*cdf0e10cSrcweir                 pIViewObject->SetAdvise( m_pViewAdvise->GetAspect(), m_pViewAdvise->GetViewAdviseFlag(), m_pViewAdvise );
306*cdf0e10cSrcweir             WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
307*cdf0e10cSrcweir         }
308*cdf0e10cSrcweir     }
309*cdf0e10cSrcweir 
310*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::CheckDefHandler()" );
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir     return TRUE;
313*cdf0e10cSrcweir }
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir //-------------------------------------------------------------------------------
316*cdf0e10cSrcweir DWORD InprocEmbedDocument_Impl::InsertAdviseLinkToList( const ComSmart<OleWrapperAdviseSink>& pOwnAdvise, ComSmart< OleWrapperAdviseSink > pAdvises[] )
317*cdf0e10cSrcweir {
318*cdf0e10cSrcweir     // the result should start from 1 in case of success, the element 0 can be used for own needs
319*cdf0e10cSrcweir     DWORD nResult = 0;
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir     if ( pOwnAdvise )
322*cdf0e10cSrcweir     {
323*cdf0e10cSrcweir         for ( DWORD nInd = 1; nInd < DEFAULT_ARRAY_LEN && nResult == 0; nInd++ )
324*cdf0e10cSrcweir         {
325*cdf0e10cSrcweir             if ( pAdvises[nInd] == pOwnAdvise )
326*cdf0e10cSrcweir             {
327*cdf0e10cSrcweir                 nResult = nInd;
328*cdf0e10cSrcweir             }
329*cdf0e10cSrcweir             else if ( pAdvises[nInd] == NULL )
330*cdf0e10cSrcweir             {
331*cdf0e10cSrcweir                 pAdvises[nInd] = pOwnAdvise;
332*cdf0e10cSrcweir                 nResult = nInd;
333*cdf0e10cSrcweir             }
334*cdf0e10cSrcweir         }
335*cdf0e10cSrcweir     }
336*cdf0e10cSrcweir 
337*cdf0e10cSrcweir     return nResult;
338*cdf0e10cSrcweir }
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir //-------------------------------------------------------------------------------
341*cdf0e10cSrcweir void InprocEmbedDocument_Impl::Clean()
342*cdf0e10cSrcweir {
343*cdf0e10cSrcweir     m_pDefHandler = (IUnknown*)NULL;
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir     // no DisconnectOrigAdvise() call here, since it is no explicit disconnection
346*cdf0e10cSrcweir     for ( DWORD nInd = 0; nInd < DEFAULT_ARRAY_LEN; nInd++ )
347*cdf0e10cSrcweir     {
348*cdf0e10cSrcweir         if ( m_pOleAdvises[nInd] )
349*cdf0e10cSrcweir         {
350*cdf0e10cSrcweir             ComSmart< OleWrapperAdviseSink > pAdvise = m_pOleAdvises[nInd];
351*cdf0e10cSrcweir             m_pOleAdvises[nInd] = NULL;
352*cdf0e10cSrcweir         }
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir         if ( m_pDataAdvises[nInd] )
355*cdf0e10cSrcweir         {
356*cdf0e10cSrcweir             ComSmart< OleWrapperAdviseSink > pAdvise = m_pDataAdvises[nInd];
357*cdf0e10cSrcweir             m_pDataAdvises[nInd] = NULL;
358*cdf0e10cSrcweir         }
359*cdf0e10cSrcweir     }
360*cdf0e10cSrcweir 
361*cdf0e10cSrcweir     m_pViewAdvise = NULL;
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir     m_nInitMode = NOINIT;
364*cdf0e10cSrcweir     m_pStorage = NULL;
365*cdf0e10cSrcweir 
366*cdf0e10cSrcweir     if ( m_pOleContainer )
367*cdf0e10cSrcweir     {
368*cdf0e10cSrcweir         m_pOleContainer->LockContainer( FALSE );
369*cdf0e10cSrcweir         m_pOleContainer = NULL;
370*cdf0e10cSrcweir     }
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir     m_pClientSite = NULL;
373*cdf0e10cSrcweir 
374*cdf0e10cSrcweir     m_nFileOpenMode = 0;
375*cdf0e10cSrcweir     if ( m_pFileName )
376*cdf0e10cSrcweir     {
377*cdf0e10cSrcweir         delete m_pFileName;
378*cdf0e10cSrcweir         m_pFileName = NULL;
379*cdf0e10cSrcweir     }
380*cdf0e10cSrcweir }
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir // IUnknown
383*cdf0e10cSrcweir //-------------------------------------------------------------------------------
384*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::QueryInterface( REFIID riid, void FAR* FAR* ppv )
385*cdf0e10cSrcweir {
386*cdf0e10cSrcweir     if(IsEqualIID(riid, IID_IUnknown))
387*cdf0e10cSrcweir 	{
388*cdf0e10cSrcweir 		AddRef();
389*cdf0e10cSrcweir 		*ppv = (IUnknown*) (IPersistStorage*) this;
390*cdf0e10cSrcweir 		return S_OK;
391*cdf0e10cSrcweir     }
392*cdf0e10cSrcweir     else if (IsEqualIID(riid, IID_IPersist))
393*cdf0e10cSrcweir 	{
394*cdf0e10cSrcweir 		AddRef();
395*cdf0e10cSrcweir 		*ppv = (IPersist*) (IPersistStorage*) this;
396*cdf0e10cSrcweir 		return S_OK;
397*cdf0e10cSrcweir 	}
398*cdf0e10cSrcweir     else if (IsEqualIID(riid, IID_IPersistStorage))
399*cdf0e10cSrcweir 	{
400*cdf0e10cSrcweir 		AddRef();
401*cdf0e10cSrcweir 		*ppv = (IPersistStorage*) this;
402*cdf0e10cSrcweir 		return S_OK;
403*cdf0e10cSrcweir 	}
404*cdf0e10cSrcweir     else if (IsEqualIID(riid, IID_IDataObject))
405*cdf0e10cSrcweir 	{
406*cdf0e10cSrcweir 		AddRef();
407*cdf0e10cSrcweir 		*ppv = (IDataObject*) this;
408*cdf0e10cSrcweir 		return S_OK;
409*cdf0e10cSrcweir 	}
410*cdf0e10cSrcweir     else if (IsEqualIID(riid, IID_IOleObject))
411*cdf0e10cSrcweir 	{
412*cdf0e10cSrcweir 		AddRef();
413*cdf0e10cSrcweir 		*ppv = (IOleObject*) this;
414*cdf0e10cSrcweir 		return S_OK;
415*cdf0e10cSrcweir 	}
416*cdf0e10cSrcweir     else if (IsEqualIID(riid, IID_IPersistFile))
417*cdf0e10cSrcweir 	{
418*cdf0e10cSrcweir 		AddRef();
419*cdf0e10cSrcweir 		*ppv = (IPersistFile*) this;
420*cdf0e10cSrcweir 		return S_OK;
421*cdf0e10cSrcweir 	}
422*cdf0e10cSrcweir     else if (IsEqualIID(riid, IID_IRunnableObject))
423*cdf0e10cSrcweir 	{
424*cdf0e10cSrcweir 		AddRef();
425*cdf0e10cSrcweir 		*ppv = (IRunnableObject*) this;
426*cdf0e10cSrcweir 		return S_OK;
427*cdf0e10cSrcweir 	}
428*cdf0e10cSrcweir     else if (IsEqualIID(riid, IID_IViewObject))
429*cdf0e10cSrcweir     {
430*cdf0e10cSrcweir         AddRef();
431*cdf0e10cSrcweir         *ppv = (IViewObject*) this;
432*cdf0e10cSrcweir         return S_OK;
433*cdf0e10cSrcweir     }
434*cdf0e10cSrcweir     else if (IsEqualIID(riid, IID_IViewObject2))
435*cdf0e10cSrcweir     {
436*cdf0e10cSrcweir         AddRef();
437*cdf0e10cSrcweir         *ppv = (IViewObject2*) this;
438*cdf0e10cSrcweir         return S_OK;
439*cdf0e10cSrcweir     }
440*cdf0e10cSrcweir     else if (IsEqualIID(riid, IID_IOleCache))
441*cdf0e10cSrcweir     {
442*cdf0e10cSrcweir         AddRef();
443*cdf0e10cSrcweir         *ppv = (IOleCache*) &m_aInternalCache;
444*cdf0e10cSrcweir         return S_OK;
445*cdf0e10cSrcweir     }
446*cdf0e10cSrcweir     else if (IsEqualIID(riid, IID_IOleCache2))
447*cdf0e10cSrcweir     {
448*cdf0e10cSrcweir         AddRef();
449*cdf0e10cSrcweir         *ppv = (IOleCache2*) &m_aInternalCache;
450*cdf0e10cSrcweir         return S_OK;
451*cdf0e10cSrcweir     }
452*cdf0e10cSrcweir     else if (IsEqualIID(riid, IID_IOleWindow))
453*cdf0e10cSrcweir     {
454*cdf0e10cSrcweir         AddRef();
455*cdf0e10cSrcweir         *ppv = (IOleWindow*) this;
456*cdf0e10cSrcweir         return S_OK;
457*cdf0e10cSrcweir     }
458*cdf0e10cSrcweir     else if (IsEqualIID(riid, IID_IOleInPlaceObject))
459*cdf0e10cSrcweir     {
460*cdf0e10cSrcweir         AddRef();
461*cdf0e10cSrcweir         *ppv = (IOleInPlaceObject*) this;
462*cdf0e10cSrcweir         return S_OK;
463*cdf0e10cSrcweir     }
464*cdf0e10cSrcweir     else if (IsEqualIID(riid, IID_IDispatch))
465*cdf0e10cSrcweir     {
466*cdf0e10cSrcweir         AddRef();
467*cdf0e10cSrcweir         *ppv = (IDispatch*) this;
468*cdf0e10cSrcweir         return S_OK;
469*cdf0e10cSrcweir     }
470*cdf0e10cSrcweir 
471*cdf0e10cSrcweir     *ppv = NULL;
472*cdf0e10cSrcweir     return ResultFromScode(E_NOINTERFACE);
473*cdf0e10cSrcweir }
474*cdf0e10cSrcweir 
475*cdf0e10cSrcweir //-------------------------------------------------------------------------------
476*cdf0e10cSrcweir STDMETHODIMP_(ULONG) InprocEmbedDocument_Impl::AddRef()
477*cdf0e10cSrcweir {
478*cdf0e10cSrcweir 	return ++m_refCount;
479*cdf0e10cSrcweir }
480*cdf0e10cSrcweir 
481*cdf0e10cSrcweir //-------------------------------------------------------------------------------
482*cdf0e10cSrcweir STDMETHODIMP_(ULONG) InprocEmbedDocument_Impl::Release()
483*cdf0e10cSrcweir {
484*cdf0e10cSrcweir     // unfortunately there are reentrance problems in mfc that have to be workarounded
485*cdf0e10cSrcweir 	sal_Int32 nCount = m_refCount > 0 ? --m_refCount : 0;
486*cdf0e10cSrcweir 	if ( nCount == 0 && !m_bDeleted )
487*cdf0e10cSrcweir 	{
488*cdf0e10cSrcweir         // deleting of this object can trigger deleting of mfc objects that will try to delete this object one more time
489*cdf0e10cSrcweir         m_bDeleted = TRUE;
490*cdf0e10cSrcweir 
491*cdf0e10cSrcweir         Clean();
492*cdf0e10cSrcweir 		delete this;
493*cdf0e10cSrcweir 	}
494*cdf0e10cSrcweir     return nCount;
495*cdf0e10cSrcweir }
496*cdf0e10cSrcweir 
497*cdf0e10cSrcweir // IPersist
498*cdf0e10cSrcweir //-------------------------------------------------------------------------------
499*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::GetClassID( CLSID* pClassId )
500*cdf0e10cSrcweir {
501*cdf0e10cSrcweir 	*pClassId = *&m_guid;
502*cdf0e10cSrcweir 	return S_OK;
503*cdf0e10cSrcweir }
504*cdf0e10cSrcweir 
505*cdf0e10cSrcweir // IPersistStorage
506*cdf0e10cSrcweir //-------------------------------------------------------------------------------
507*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::IsDirty()
508*cdf0e10cSrcweir {
509*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::IsDirty()1" );
510*cdf0e10cSrcweir     if ( m_pDefHandler == NULL || m_pOleAdvises[0] == NULL || m_pOleAdvises[0]->IsClosed() )
511*cdf0e10cSrcweir         return S_FALSE;
512*cdf0e10cSrcweir 
513*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::IsDirty()2" );
514*cdf0e10cSrcweir     if ( CheckDefHandler() )
515*cdf0e10cSrcweir     {
516*cdf0e10cSrcweir         ComSmart< IPersistStorage > pPersist;
517*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IPersistStorage, (void**)&pPersist );
518*cdf0e10cSrcweir 
519*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
520*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pPersist )
521*cdf0e10cSrcweir             return pPersist->IsDirty();
522*cdf0e10cSrcweir     }
523*cdf0e10cSrcweir 
524*cdf0e10cSrcweir     return E_FAIL;
525*cdf0e10cSrcweir }
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir //-------------------------------------------------------------------------------
528*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::InitNew( IStorage *pStg )
529*cdf0e10cSrcweir {
530*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InitNew( IStorage *pStg )" );
531*cdf0e10cSrcweir     if ( CheckDefHandler() )
532*cdf0e10cSrcweir     {
533*cdf0e10cSrcweir         ComSmart< IPersistStorage > pPersist;
534*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IPersistStorage, (void**)&pPersist );
535*cdf0e10cSrcweir 
536*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
537*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pPersist )
538*cdf0e10cSrcweir         {
539*cdf0e10cSrcweir             hr = pPersist->InitNew( pStg );
540*cdf0e10cSrcweir             if ( SUCCEEDED( hr ) )
541*cdf0e10cSrcweir             {
542*cdf0e10cSrcweir                 m_nInitMode = INIT_FROM_STORAGE;
543*cdf0e10cSrcweir                 m_pStorage = pStg;
544*cdf0e10cSrcweir 
545*cdf0e10cSrcweir                 m_nFileOpenMode = 0;
546*cdf0e10cSrcweir                 if ( m_pFileName )
547*cdf0e10cSrcweir                 {
548*cdf0e10cSrcweir                     delete[] m_pFileName;
549*cdf0e10cSrcweir                     m_pFileName = NULL;
550*cdf0e10cSrcweir                 }
551*cdf0e10cSrcweir             }
552*cdf0e10cSrcweir 
553*cdf0e10cSrcweir             return hr;
554*cdf0e10cSrcweir         }
555*cdf0e10cSrcweir     }
556*cdf0e10cSrcweir 
557*cdf0e10cSrcweir     return E_FAIL;
558*cdf0e10cSrcweir }
559*cdf0e10cSrcweir 
560*cdf0e10cSrcweir //-------------------------------------------------------------------------------
561*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::Load( IStorage *pStg )
562*cdf0e10cSrcweir {
563*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Load( IStorage *pStg )" );
564*cdf0e10cSrcweir     if ( CheckDefHandler() )
565*cdf0e10cSrcweir     {
566*cdf0e10cSrcweir         WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Load( IStorage *pStg )" );
567*cdf0e10cSrcweir         ComSmart< IPersistStorage > pPersist;
568*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IPersistStorage, (void**)&pPersist );
569*cdf0e10cSrcweir 
570*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
571*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pPersist )
572*cdf0e10cSrcweir         {
573*cdf0e10cSrcweir             WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Load( IStorage *pStg )" );
574*cdf0e10cSrcweir             hr = pPersist->Load( pStg );
575*cdf0e10cSrcweir             if ( SUCCEEDED( hr ) )
576*cdf0e10cSrcweir             {
577*cdf0e10cSrcweir                 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Load( IStorage *pStg )" );
578*cdf0e10cSrcweir                 m_nInitMode = LOAD_FROM_STORAGE;
579*cdf0e10cSrcweir                 m_pStorage = pStg;
580*cdf0e10cSrcweir 
581*cdf0e10cSrcweir                 m_nFileOpenMode = 0;
582*cdf0e10cSrcweir                 if ( m_pFileName )
583*cdf0e10cSrcweir                 {
584*cdf0e10cSrcweir                     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Load( IStorage *pStg )" );
585*cdf0e10cSrcweir                     delete[] m_pFileName;
586*cdf0e10cSrcweir                     m_pFileName = NULL;
587*cdf0e10cSrcweir                 }
588*cdf0e10cSrcweir             }
589*cdf0e10cSrcweir 
590*cdf0e10cSrcweir             return hr;
591*cdf0e10cSrcweir         }
592*cdf0e10cSrcweir     }
593*cdf0e10cSrcweir 
594*cdf0e10cSrcweir     return E_FAIL;
595*cdf0e10cSrcweir }
596*cdf0e10cSrcweir 
597*cdf0e10cSrcweir //-------------------------------------------------------------------------------
598*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::Save( IStorage *pStgSave, BOOL fSameAsLoad )
599*cdf0e10cSrcweir {
600*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Save( IStorage *pStgSave, BOOL fSameAsLoad )" );
601*cdf0e10cSrcweir     if ( fSameAsLoad && ( m_pDefHandler == NULL || m_pOleAdvises[0] == NULL || m_pOleAdvises[0]->IsClosed() ) )
602*cdf0e10cSrcweir         return S_OK;
603*cdf0e10cSrcweir 
604*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Save( IStorage *pStgSave, BOOL fSameAsLoad )" );
605*cdf0e10cSrcweir     if ( CheckDefHandler() )
606*cdf0e10cSrcweir     {
607*cdf0e10cSrcweir         ComSmart< IPersistStorage > pPersist;
608*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IPersistStorage, (void**)&pPersist );
609*cdf0e10cSrcweir 
610*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
611*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pPersist )
612*cdf0e10cSrcweir             return pPersist->Save( pStgSave, fSameAsLoad );
613*cdf0e10cSrcweir     }
614*cdf0e10cSrcweir 
615*cdf0e10cSrcweir     return E_FAIL;
616*cdf0e10cSrcweir }
617*cdf0e10cSrcweir 
618*cdf0e10cSrcweir //-------------------------------------------------------------------------------
619*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::SaveCompleted( IStorage *pStgNew )
620*cdf0e10cSrcweir {
621*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SaveCompleted( IStorage *pStgNew )" );
622*cdf0e10cSrcweir     if ( m_pDefHandler == NULL || m_pOleAdvises[0] == NULL || m_pOleAdvises[0]->IsClosed() )
623*cdf0e10cSrcweir     {
624*cdf0e10cSrcweir         if ( pStgNew )
625*cdf0e10cSrcweir             m_pStorage = pStgNew;
626*cdf0e10cSrcweir 
627*cdf0e10cSrcweir         return S_OK;
628*cdf0e10cSrcweir     }
629*cdf0e10cSrcweir 
630*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SaveCompleted( IStorage *pStgNew )" );
631*cdf0e10cSrcweir     if ( CheckDefHandler() )
632*cdf0e10cSrcweir     {
633*cdf0e10cSrcweir         ComSmart< IPersistStorage > pPersist;
634*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IPersistStorage, (void**)&pPersist );
635*cdf0e10cSrcweir 
636*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
637*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pPersist )
638*cdf0e10cSrcweir         {
639*cdf0e10cSrcweir             hr = pPersist->SaveCompleted( pStgNew );
640*cdf0e10cSrcweir             if ( SUCCEEDED( hr ) )
641*cdf0e10cSrcweir             {
642*cdf0e10cSrcweir                 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SaveCompleted( IStorage *pStgNew )" );
643*cdf0e10cSrcweir                 m_nInitMode = LOAD_FROM_STORAGE;
644*cdf0e10cSrcweir                 if ( pStgNew )
645*cdf0e10cSrcweir                 {
646*cdf0e10cSrcweir                     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SaveCompleted( IStorage *pStgNew )" );
647*cdf0e10cSrcweir                     m_pStorage = pStgNew;
648*cdf0e10cSrcweir                 }
649*cdf0e10cSrcweir 
650*cdf0e10cSrcweir                 m_nFileOpenMode = 0;
651*cdf0e10cSrcweir                 if ( m_pFileName )
652*cdf0e10cSrcweir                 {
653*cdf0e10cSrcweir                     delete[] m_pFileName;
654*cdf0e10cSrcweir                     m_pFileName = NULL;
655*cdf0e10cSrcweir                 }
656*cdf0e10cSrcweir             }
657*cdf0e10cSrcweir 
658*cdf0e10cSrcweir             return hr;
659*cdf0e10cSrcweir         }
660*cdf0e10cSrcweir     }
661*cdf0e10cSrcweir 
662*cdf0e10cSrcweir     return E_FAIL;
663*cdf0e10cSrcweir }
664*cdf0e10cSrcweir 
665*cdf0e10cSrcweir //-------------------------------------------------------------------------------
666*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::HandsOffStorage()
667*cdf0e10cSrcweir {
668*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::HandsOffStorage()" );
669*cdf0e10cSrcweir     if ( CheckDefHandler() )
670*cdf0e10cSrcweir     {
671*cdf0e10cSrcweir         ComSmart< IPersistStorage > pPersist;
672*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IPersistStorage, (void**)&pPersist );
673*cdf0e10cSrcweir 
674*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
675*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pPersist )
676*cdf0e10cSrcweir         {
677*cdf0e10cSrcweir             hr = pPersist->HandsOffStorage();
678*cdf0e10cSrcweir             if ( SUCCEEDED( hr ) )
679*cdf0e10cSrcweir             {
680*cdf0e10cSrcweir                 m_pStorage = NULL;
681*cdf0e10cSrcweir                 WRITEDEBUGINFO( "InprocEmbedDocument_Impl::HandsOffStorage()" );
682*cdf0e10cSrcweir             }
683*cdf0e10cSrcweir 
684*cdf0e10cSrcweir             return hr;
685*cdf0e10cSrcweir         }
686*cdf0e10cSrcweir     }
687*cdf0e10cSrcweir 
688*cdf0e10cSrcweir     return E_FAIL;
689*cdf0e10cSrcweir }
690*cdf0e10cSrcweir 
691*cdf0e10cSrcweir // IPersistFile
692*cdf0e10cSrcweir //-------------------------------------------------------------------------------
693*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::Load( LPCOLESTR pszFileName, DWORD dwMode )
694*cdf0e10cSrcweir {
695*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Load( LPCOLESTR pszFileName, DWORD dwMode )" );
696*cdf0e10cSrcweir     if ( CheckDefHandler() && pszFileName )
697*cdf0e10cSrcweir     {
698*cdf0e10cSrcweir         ComSmart< IPersistFile > pPersist;
699*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IPersistFile, (void**)&pPersist );
700*cdf0e10cSrcweir 
701*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
702*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pPersist )
703*cdf0e10cSrcweir         {
704*cdf0e10cSrcweir             hr = pPersist->Load( pszFileName, dwMode );
705*cdf0e10cSrcweir             if ( SUCCEEDED( hr ) )
706*cdf0e10cSrcweir             {
707*cdf0e10cSrcweir                 m_nInitMode = LOAD_FROM_FILE;
708*cdf0e10cSrcweir                 if ( m_pStorage )
709*cdf0e10cSrcweir                     m_pStorage = NULL;
710*cdf0e10cSrcweir 
711*cdf0e10cSrcweir                 m_nFileOpenMode = dwMode;
712*cdf0e10cSrcweir                 // copy the string
713*cdf0e10cSrcweir                 SetName( pszFileName, m_pFileName );
714*cdf0e10cSrcweir             }
715*cdf0e10cSrcweir 
716*cdf0e10cSrcweir             return hr;
717*cdf0e10cSrcweir         }
718*cdf0e10cSrcweir     }
719*cdf0e10cSrcweir 
720*cdf0e10cSrcweir     return E_FAIL;
721*cdf0e10cSrcweir }
722*cdf0e10cSrcweir 
723*cdf0e10cSrcweir //-------------------------------------------------------------------------------
724*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::Save( LPCOLESTR pszFileName, BOOL fRemember )
725*cdf0e10cSrcweir {
726*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Save( LPCOLESTR pszFileName, BOOL fRemember )" );
727*cdf0e10cSrcweir     if ( CheckDefHandler() )
728*cdf0e10cSrcweir     {
729*cdf0e10cSrcweir         ComSmart< IPersistFile > pPersist;
730*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IPersistFile, (void**)&pPersist );
731*cdf0e10cSrcweir 
732*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
733*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pPersist )
734*cdf0e10cSrcweir             return pPersist->Save( pszFileName, fRemember );
735*cdf0e10cSrcweir     }
736*cdf0e10cSrcweir 
737*cdf0e10cSrcweir     return E_FAIL;
738*cdf0e10cSrcweir }
739*cdf0e10cSrcweir 
740*cdf0e10cSrcweir //-------------------------------------------------------------------------------
741*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::SaveCompleted( LPCOLESTR pszFileName )
742*cdf0e10cSrcweir {
743*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SaveCompleted( LPCOLESTR pszFileName )" );
744*cdf0e10cSrcweir     if ( CheckDefHandler() )
745*cdf0e10cSrcweir     {
746*cdf0e10cSrcweir         ComSmart< IPersistFile > pPersist;
747*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IPersistFile, (void**)&pPersist );
748*cdf0e10cSrcweir 
749*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
750*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pPersist )
751*cdf0e10cSrcweir         {
752*cdf0e10cSrcweir             hr = pPersist->SaveCompleted( pszFileName );
753*cdf0e10cSrcweir             if ( SUCCEEDED( hr ) )
754*cdf0e10cSrcweir             {
755*cdf0e10cSrcweir                 m_nInitMode = LOAD_FROM_STORAGE;
756*cdf0e10cSrcweir                 if ( m_pStorage )
757*cdf0e10cSrcweir                     m_pStorage = NULL;
758*cdf0e10cSrcweir 
759*cdf0e10cSrcweir                 m_nFileOpenMode = STGM_READWRITE; // was just written
760*cdf0e10cSrcweir                 // copy the string
761*cdf0e10cSrcweir                 SetName( pszFileName, m_pFileName );
762*cdf0e10cSrcweir             }
763*cdf0e10cSrcweir         }
764*cdf0e10cSrcweir 
765*cdf0e10cSrcweir     }
766*cdf0e10cSrcweir 
767*cdf0e10cSrcweir     return E_FAIL;
768*cdf0e10cSrcweir }
769*cdf0e10cSrcweir 
770*cdf0e10cSrcweir //-------------------------------------------------------------------------------
771*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::GetCurFile( LPOLESTR *ppszFileName )
772*cdf0e10cSrcweir {
773*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetCurFile( LPOLESTR *ppszFileName )" );
774*cdf0e10cSrcweir     if ( CheckDefHandler() )
775*cdf0e10cSrcweir     {
776*cdf0e10cSrcweir         ComSmart< IPersistFile > pPersist;
777*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IPersistFile, (void**)&pPersist );
778*cdf0e10cSrcweir 
779*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
780*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pPersist )
781*cdf0e10cSrcweir             return pPersist->GetCurFile( ppszFileName );
782*cdf0e10cSrcweir     }
783*cdf0e10cSrcweir 
784*cdf0e10cSrcweir     return E_FAIL;
785*cdf0e10cSrcweir }
786*cdf0e10cSrcweir 
787*cdf0e10cSrcweir // IOleObject
788*cdf0e10cSrcweir //-------------------------------------------------------------------------------
789*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::SetClientSite( IOleClientSite* pSite )
790*cdf0e10cSrcweir {
791*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetClientSite( IOleClientSite* pSite )" );
792*cdf0e10cSrcweir     if ( pSite == m_pClientSite )
793*cdf0e10cSrcweir         return S_OK;
794*cdf0e10cSrcweir 
795*cdf0e10cSrcweir     if ( !pSite )
796*cdf0e10cSrcweir     {
797*cdf0e10cSrcweir         m_pClientSite = NULL;
798*cdf0e10cSrcweir         if ( m_pOleContainer )
799*cdf0e10cSrcweir         {
800*cdf0e10cSrcweir             m_pOleContainer->LockContainer( FALSE );
801*cdf0e10cSrcweir             m_pOleContainer = NULL;
802*cdf0e10cSrcweir         }
803*cdf0e10cSrcweir     }
804*cdf0e10cSrcweir 
805*cdf0e10cSrcweir     if ( CheckDefHandler() )
806*cdf0e10cSrcweir     {
807*cdf0e10cSrcweir         ComSmart< IOleObject > pOleObject;
808*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
809*cdf0e10cSrcweir 
810*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
811*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pOleObject )
812*cdf0e10cSrcweir         {
813*cdf0e10cSrcweir             HRESULT hr = pOleObject->SetClientSite( pSite );
814*cdf0e10cSrcweir             if ( SUCCEEDED( hr ) )
815*cdf0e10cSrcweir             {
816*cdf0e10cSrcweir                 m_pClientSite = pSite;
817*cdf0e10cSrcweir 
818*cdf0e10cSrcweir                 if ( m_pOleContainer )
819*cdf0e10cSrcweir                 {
820*cdf0e10cSrcweir                     m_pOleContainer->LockContainer( FALSE );
821*cdf0e10cSrcweir                     m_pOleContainer = NULL;
822*cdf0e10cSrcweir                 }
823*cdf0e10cSrcweir 
824*cdf0e10cSrcweir                 m_pClientSite->GetContainer( &m_pOleContainer );
825*cdf0e10cSrcweir                 if ( m_pOleContainer )
826*cdf0e10cSrcweir                     m_pOleContainer->LockContainer( TRUE );
827*cdf0e10cSrcweir             }
828*cdf0e10cSrcweir 
829*cdf0e10cSrcweir             return hr;
830*cdf0e10cSrcweir         }
831*cdf0e10cSrcweir     }
832*cdf0e10cSrcweir 
833*cdf0e10cSrcweir     return E_FAIL;
834*cdf0e10cSrcweir }
835*cdf0e10cSrcweir 
836*cdf0e10cSrcweir //-------------------------------------------------------------------------------
837*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::GetClientSite( IOleClientSite** pSite )
838*cdf0e10cSrcweir {
839*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetClientSite( IOleClientSite** pSite )" );
840*cdf0e10cSrcweir     if ( CheckDefHandler() )
841*cdf0e10cSrcweir     {
842*cdf0e10cSrcweir         ComSmart< IOleObject > pOleObject;
843*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
844*cdf0e10cSrcweir 
845*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
846*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pOleObject )
847*cdf0e10cSrcweir             return pOleObject->GetClientSite( pSite );
848*cdf0e10cSrcweir     }
849*cdf0e10cSrcweir 
850*cdf0e10cSrcweir     return E_FAIL;
851*cdf0e10cSrcweir }
852*cdf0e10cSrcweir 
853*cdf0e10cSrcweir //-------------------------------------------------------------------------------
854*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::SetHostNames( LPCOLESTR szContainerApp, LPCOLESTR szContainerObj )
855*cdf0e10cSrcweir {
856*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetHostNames( LPCOLESTR szContainerApp, LPCOLESTR szContainerObj )" );
857*cdf0e10cSrcweir 
858*cdf0e10cSrcweir     if ( CheckDefHandler() )
859*cdf0e10cSrcweir     {
860*cdf0e10cSrcweir         ComSmart< IOleObject > pOleObject;
861*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
862*cdf0e10cSrcweir 
863*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
864*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pOleObject )
865*cdf0e10cSrcweir         {
866*cdf0e10cSrcweir             WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetHostNames( LPCOLESTR szContainerApp, LPCOLESTR szContainerObj )" );
867*cdf0e10cSrcweir             hr = pOleObject->SetHostNames( szContainerApp, szContainerObj );
868*cdf0e10cSrcweir         }
869*cdf0e10cSrcweir     }
870*cdf0e10cSrcweir 
871*cdf0e10cSrcweir     return S_OK;
872*cdf0e10cSrcweir }
873*cdf0e10cSrcweir 
874*cdf0e10cSrcweir //-------------------------------------------------------------------------------
875*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::Close( DWORD dwSaveOption )
876*cdf0e10cSrcweir {
877*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Close( DWORD dwSaveOption )" );
878*cdf0e10cSrcweir     if ( m_pDefHandler && CheckDefHandler() )
879*cdf0e10cSrcweir     {
880*cdf0e10cSrcweir         // no need to close if there is no default handler.
881*cdf0e10cSrcweir         ComSmart< IOleObject > pOleObject;
882*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
883*cdf0e10cSrcweir 
884*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
885*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pOleObject )
886*cdf0e10cSrcweir 		{
887*cdf0e10cSrcweir             hr = pOleObject->Close( dwSaveOption );
888*cdf0e10cSrcweir 			hr = CoDisconnectObject( (IUnknown*)(IPersistStorage*)this, 0 );
889*cdf0e10cSrcweir 		}
890*cdf0e10cSrcweir     }
891*cdf0e10cSrcweir 
892*cdf0e10cSrcweir     // if the object is closed from outside that means that it should go to uninitialized state
893*cdf0e10cSrcweir     Clean();
894*cdf0e10cSrcweir 
895*cdf0e10cSrcweir     return S_OK;
896*cdf0e10cSrcweir }
897*cdf0e10cSrcweir 
898*cdf0e10cSrcweir //-------------------------------------------------------------------------------
899*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::SetMoniker( DWORD dwWhichMoniker, IMoniker * pmk )
900*cdf0e10cSrcweir {
901*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetMoniker( DWORD dwWhichMoniker, IMoniker * pmk )" );
902*cdf0e10cSrcweir     if ( CheckDefHandler() )
903*cdf0e10cSrcweir     {
904*cdf0e10cSrcweir         ComSmart< IOleObject > pOleObject;
905*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
906*cdf0e10cSrcweir 
907*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
908*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pOleObject )
909*cdf0e10cSrcweir             return pOleObject->SetMoniker( dwWhichMoniker, pmk );
910*cdf0e10cSrcweir     }
911*cdf0e10cSrcweir 
912*cdf0e10cSrcweir     return E_FAIL;
913*cdf0e10cSrcweir }
914*cdf0e10cSrcweir 
915*cdf0e10cSrcweir //-------------------------------------------------------------------------------
916*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::GetMoniker( DWORD dwAssign, DWORD dwWhichMoniker, IMoniker ** ppmk )
917*cdf0e10cSrcweir {
918*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetMoniker( DWORD dwAssign, DWORD dwWhichMoniker, IMoniker ** ppmk )" );
919*cdf0e10cSrcweir     if ( CheckDefHandler() )
920*cdf0e10cSrcweir     {
921*cdf0e10cSrcweir         ComSmart< IOleObject > pOleObject;
922*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
923*cdf0e10cSrcweir 
924*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
925*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pOleObject )
926*cdf0e10cSrcweir             return pOleObject->GetMoniker( dwAssign, dwWhichMoniker, ppmk );
927*cdf0e10cSrcweir     }
928*cdf0e10cSrcweir 
929*cdf0e10cSrcweir     return E_FAIL;
930*cdf0e10cSrcweir }
931*cdf0e10cSrcweir 
932*cdf0e10cSrcweir //-------------------------------------------------------------------------------
933*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::InitFromData( IDataObject * pDataObject, BOOL fCreation, DWORD dwReserved )
934*cdf0e10cSrcweir {
935*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InitFromData( IDataObject * pDataObject, BOOL fCreation, DWORD dwReserved )" );
936*cdf0e10cSrcweir     if ( CheckDefHandler() )
937*cdf0e10cSrcweir     {
938*cdf0e10cSrcweir         ComSmart< IOleObject > pOleObject;
939*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
940*cdf0e10cSrcweir 
941*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
942*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pOleObject )
943*cdf0e10cSrcweir             return pOleObject->InitFromData( pDataObject, fCreation, dwReserved );
944*cdf0e10cSrcweir     }
945*cdf0e10cSrcweir 
946*cdf0e10cSrcweir     return E_FAIL;
947*cdf0e10cSrcweir }
948*cdf0e10cSrcweir 
949*cdf0e10cSrcweir //-------------------------------------------------------------------------------
950*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::GetClipboardData( DWORD dwReserved, IDataObject ** ppDataObject )
951*cdf0e10cSrcweir {
952*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetClipboardData( DWORD dwReserved, IDataObject ** ppDataObject )" );
953*cdf0e10cSrcweir     if ( CheckDefHandler() )
954*cdf0e10cSrcweir     {
955*cdf0e10cSrcweir         ComSmart< IOleObject > pOleObject;
956*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
957*cdf0e10cSrcweir 
958*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
959*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pOleObject )
960*cdf0e10cSrcweir             return pOleObject->GetClipboardData( dwReserved, ppDataObject );
961*cdf0e10cSrcweir     }
962*cdf0e10cSrcweir 
963*cdf0e10cSrcweir     return E_FAIL;
964*cdf0e10cSrcweir }
965*cdf0e10cSrcweir 
966*cdf0e10cSrcweir //-------------------------------------------------------------------------------
967*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::DoVerb(
968*cdf0e10cSrcweir 	LONG iVerb,
969*cdf0e10cSrcweir 	LPMSG pMsg,
970*cdf0e10cSrcweir 	IOleClientSite *pActiveSite,
971*cdf0e10cSrcweir 	LONG nLong,
972*cdf0e10cSrcweir 	HWND hWin,
973*cdf0e10cSrcweir 	LPCRECT pRect )
974*cdf0e10cSrcweir {
975*cdf0e10cSrcweir     WRITEDEBUGINFO( "DoVerb" );
976*cdf0e10cSrcweir     if ( CheckDefHandler() )
977*cdf0e10cSrcweir     {
978*cdf0e10cSrcweir         WRITEDEBUGINFO( "DoVerb" MY_STRING_LINE "n" );
979*cdf0e10cSrcweir         ComSmart< IOleObject > pOleObject;
980*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
981*cdf0e10cSrcweir 
982*cdf0e10cSrcweir         WRITEDEBUGINFO( "DoVerb" );
983*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
984*cdf0e10cSrcweir         WRITEDEBUGINFO( "DoVerb" );
985*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pOleObject )
986*cdf0e10cSrcweir         {
987*cdf0e10cSrcweir             WRITEDEBUGINFO( "DoVerb" );
988*cdf0e10cSrcweir             hr = pOleObject->DoVerb( iVerb, pMsg, pActiveSite, nLong, hWin, pRect );
989*cdf0e10cSrcweir             if ( SUCCEEDED( hr ) )
990*cdf0e10cSrcweir             {
991*cdf0e10cSrcweir                 WRITEDEBUGINFO( "DoVerb" );
992*cdf0e10cSrcweir             }
993*cdf0e10cSrcweir 
994*cdf0e10cSrcweir             return hr;
995*cdf0e10cSrcweir         }
996*cdf0e10cSrcweir 
997*cdf0e10cSrcweir         WRITEDEBUGINFO( "DoVerb" );
998*cdf0e10cSrcweir     }
999*cdf0e10cSrcweir 
1000*cdf0e10cSrcweir     return E_FAIL;
1001*cdf0e10cSrcweir }
1002*cdf0e10cSrcweir 
1003*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1004*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::EnumVerbs( IEnumOLEVERB ** ppEnumOleVerb )
1005*cdf0e10cSrcweir {
1006*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::EnumVerbs( IEnumOLEVERB ** ppEnumOleVerb )" );
1007*cdf0e10cSrcweir     if ( CheckDefHandler() )
1008*cdf0e10cSrcweir     {
1009*cdf0e10cSrcweir         ComSmart< IOleObject > pOleObject;
1010*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
1011*cdf0e10cSrcweir 
1012*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1013*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pOleObject )
1014*cdf0e10cSrcweir             return pOleObject->EnumVerbs( ppEnumOleVerb );
1015*cdf0e10cSrcweir     }
1016*cdf0e10cSrcweir 
1017*cdf0e10cSrcweir     return E_FAIL;
1018*cdf0e10cSrcweir }
1019*cdf0e10cSrcweir 
1020*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1021*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::Update()
1022*cdf0e10cSrcweir {
1023*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Update()" );
1024*cdf0e10cSrcweir 
1025*cdf0e10cSrcweir     if ( m_pDefHandler && CheckDefHandler() )
1026*cdf0e10cSrcweir     {
1027*cdf0e10cSrcweir         ComSmart< IOleObject > pOleObject;
1028*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
1029*cdf0e10cSrcweir 
1030*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1031*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pOleObject )
1032*cdf0e10cSrcweir             return pOleObject->Update();
1033*cdf0e10cSrcweir     }
1034*cdf0e10cSrcweir 
1035*cdf0e10cSrcweir     return S_OK;
1036*cdf0e10cSrcweir }
1037*cdf0e10cSrcweir 
1038*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1039*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::IsUpToDate()
1040*cdf0e10cSrcweir {
1041*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::IsUpToDate()" );
1042*cdf0e10cSrcweir     if ( CheckDefHandler() )
1043*cdf0e10cSrcweir     {
1044*cdf0e10cSrcweir         ComSmart< IOleObject > pOleObject;
1045*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
1046*cdf0e10cSrcweir 
1047*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1048*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pOleObject )
1049*cdf0e10cSrcweir             return pOleObject->IsUpToDate();
1050*cdf0e10cSrcweir     }
1051*cdf0e10cSrcweir 
1052*cdf0e10cSrcweir     return E_FAIL;
1053*cdf0e10cSrcweir }
1054*cdf0e10cSrcweir 
1055*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1056*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::GetUserClassID( CLSID *pClsid )
1057*cdf0e10cSrcweir {
1058*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetUserClassID( CLSID *pClsid )" );
1059*cdf0e10cSrcweir     if ( pClsid )
1060*cdf0e10cSrcweir         *pClsid = m_guid;
1061*cdf0e10cSrcweir 
1062*cdf0e10cSrcweir     return S_OK;
1063*cdf0e10cSrcweir }
1064*cdf0e10cSrcweir 
1065*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1066*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::GetUserType( DWORD dwFormOfType, LPOLESTR * pszUserType )
1067*cdf0e10cSrcweir {
1068*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetUserType( DWORD dwFormOfType, LPOLESTR * pszUserType )" );
1069*cdf0e10cSrcweir     if ( CheckDefHandler() )
1070*cdf0e10cSrcweir     {
1071*cdf0e10cSrcweir         ComSmart< IOleObject > pOleObject;
1072*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
1073*cdf0e10cSrcweir 
1074*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1075*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pOleObject )
1076*cdf0e10cSrcweir             return pOleObject->GetUserType( dwFormOfType, pszUserType );
1077*cdf0e10cSrcweir     }
1078*cdf0e10cSrcweir 
1079*cdf0e10cSrcweir     return E_FAIL;
1080*cdf0e10cSrcweir }
1081*cdf0e10cSrcweir 
1082*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1083*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::SetExtent( DWORD dwDrawAspect, SIZEL *psizel )
1084*cdf0e10cSrcweir {
1085*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetExtent( DWORD dwDrawAspect, SIZEL *psizel )" );
1086*cdf0e10cSrcweir     if ( CheckDefHandler() )
1087*cdf0e10cSrcweir     {
1088*cdf0e10cSrcweir         ComSmart< IOleObject > pOleObject;
1089*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
1090*cdf0e10cSrcweir 
1091*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1092*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pOleObject )
1093*cdf0e10cSrcweir             return pOleObject->SetExtent( dwDrawAspect, psizel );
1094*cdf0e10cSrcweir     }
1095*cdf0e10cSrcweir 
1096*cdf0e10cSrcweir     return E_FAIL;
1097*cdf0e10cSrcweir }
1098*cdf0e10cSrcweir 
1099*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1100*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::GetExtent( DWORD dwDrawAspect, SIZEL * psizel )
1101*cdf0e10cSrcweir {
1102*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetExtent( DWORD dwDrawAspect, SIZEL * psizel )" );
1103*cdf0e10cSrcweir     if ( CheckDefHandler() )
1104*cdf0e10cSrcweir     {
1105*cdf0e10cSrcweir         ComSmart< IOleObject > pOleObject;
1106*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
1107*cdf0e10cSrcweir 
1108*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1109*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pOleObject )
1110*cdf0e10cSrcweir             return pOleObject->GetExtent( dwDrawAspect, psizel );
1111*cdf0e10cSrcweir     }
1112*cdf0e10cSrcweir 
1113*cdf0e10cSrcweir     return E_FAIL;
1114*cdf0e10cSrcweir }
1115*cdf0e10cSrcweir 
1116*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1117*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::Advise( IAdviseSink *pAdvSink, DWORD *pdwConnection )
1118*cdf0e10cSrcweir {
1119*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Advise( IAdviseSink *pAdvSink, DWORD *pdwConnection )" );
1120*cdf0e10cSrcweir 
1121*cdf0e10cSrcweir     if ( !pdwConnection )
1122*cdf0e10cSrcweir         return E_FAIL;
1123*cdf0e10cSrcweir 
1124*cdf0e10cSrcweir 	// CheckDefHandler will set the listener, avoid reusing of old listener
1125*cdf0e10cSrcweir     if ( DEFAULT_ARRAY_LEN > *pdwConnection && *pdwConnection > 0 && m_pOleAdvises[*pdwConnection] )
1126*cdf0e10cSrcweir     {
1127*cdf0e10cSrcweir         m_pOleAdvises[*pdwConnection]->DisconnectOrigAdvise();
1128*cdf0e10cSrcweir         m_pOleAdvises[*pdwConnection] = NULL;
1129*cdf0e10cSrcweir     }
1130*cdf0e10cSrcweir 
1131*cdf0e10cSrcweir     if ( pAdvSink && CheckDefHandler() )
1132*cdf0e10cSrcweir     {
1133*cdf0e10cSrcweir         ComSmart< IOleObject > pOleObject;
1134*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
1135*cdf0e10cSrcweir 
1136*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1137*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pOleObject )
1138*cdf0e10cSrcweir         {
1139*cdf0e10cSrcweir             ComSmart< OleWrapperAdviseSink > pOwnAdvise( new OleWrapperAdviseSink( pAdvSink ) );
1140*cdf0e10cSrcweir             DWORD nRegID = 0;
1141*cdf0e10cSrcweir 
1142*cdf0e10cSrcweir             if ( SUCCEEDED( pOleObject->Advise( pOwnAdvise, &nRegID ) ) && nRegID > 0 )
1143*cdf0e10cSrcweir             {
1144*cdf0e10cSrcweir                 pOwnAdvise->SetRegID( nRegID );
1145*cdf0e10cSrcweir                 *pdwConnection = InsertAdviseLinkToList( pOwnAdvise, m_pOleAdvises );
1146*cdf0e10cSrcweir                 if ( *pdwConnection )
1147*cdf0e10cSrcweir                     return S_OK;
1148*cdf0e10cSrcweir                 else
1149*cdf0e10cSrcweir                     pOleObject->Unadvise( nRegID );
1150*cdf0e10cSrcweir             }
1151*cdf0e10cSrcweir         }
1152*cdf0e10cSrcweir     }
1153*cdf0e10cSrcweir 
1154*cdf0e10cSrcweir     // return success always for now
1155*cdf0e10cSrcweir     return S_OK;
1156*cdf0e10cSrcweir }
1157*cdf0e10cSrcweir 
1158*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1159*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::Unadvise( DWORD dwConnection )
1160*cdf0e10cSrcweir {
1161*cdf0e10cSrcweir     if ( DEFAULT_ARRAY_LEN > dwConnection && dwConnection > 0 && m_pOleAdvises[dwConnection] )
1162*cdf0e10cSrcweir     {
1163*cdf0e10cSrcweir         if ( m_pDefHandler )
1164*cdf0e10cSrcweir         {
1165*cdf0e10cSrcweir             ComSmart< IOleObject > pOleObject;
1166*cdf0e10cSrcweir             HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
1167*cdf0e10cSrcweir 
1168*cdf0e10cSrcweir             ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1169*cdf0e10cSrcweir             if ( SUCCEEDED( hr ) && pOleObject )
1170*cdf0e10cSrcweir             {
1171*cdf0e10cSrcweir                 DWORD nID = m_pOleAdvises[dwConnection]->GetRegID();
1172*cdf0e10cSrcweir                 pOleObject->Unadvise( nID );
1173*cdf0e10cSrcweir             }
1174*cdf0e10cSrcweir         }
1175*cdf0e10cSrcweir 
1176*cdf0e10cSrcweir         m_pOleAdvises[dwConnection]->DisconnectOrigAdvise();
1177*cdf0e10cSrcweir         m_pOleAdvises[dwConnection] = NULL;
1178*cdf0e10cSrcweir 
1179*cdf0e10cSrcweir         return S_OK;
1180*cdf0e10cSrcweir     }
1181*cdf0e10cSrcweir 
1182*cdf0e10cSrcweir     return E_FAIL;
1183*cdf0e10cSrcweir }
1184*cdf0e10cSrcweir 
1185*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1186*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::EnumAdvise( IEnumSTATDATA ** /*ppenumAdvise*/ )
1187*cdf0e10cSrcweir {
1188*cdf0e10cSrcweir     return E_NOTIMPL;
1189*cdf0e10cSrcweir 
1190*cdf0e10cSrcweir //    if ( CheckDefHandler() )
1191*cdf0e10cSrcweir //    {
1192*cdf0e10cSrcweir //        ComSmart< IOleObject > pOleObject;
1193*cdf0e10cSrcweir //        HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
1194*cdf0e10cSrcweir //
1195*cdf0e10cSrcweir //        ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1196*cdf0e10cSrcweir //        if ( SUCCEEDED( hr ) && pOleObject )
1197*cdf0e10cSrcweir //            return pOleObject->EnumAdvise( ppenumAdvise );
1198*cdf0e10cSrcweir //    }
1199*cdf0e10cSrcweir //
1200*cdf0e10cSrcweir //    return E_FAIL;
1201*cdf0e10cSrcweir }
1202*cdf0e10cSrcweir 
1203*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1204*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::GetMiscStatus( DWORD dwAspect, DWORD * pdwStatus )
1205*cdf0e10cSrcweir {
1206*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetMiscStatus( DWORD dwAspect, DWORD * pdwStatus )" );
1207*cdf0e10cSrcweir     if ( CheckDefHandler() )
1208*cdf0e10cSrcweir     {
1209*cdf0e10cSrcweir         ComSmart< IOleObject > pOleObject;
1210*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
1211*cdf0e10cSrcweir 
1212*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1213*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pOleObject )
1214*cdf0e10cSrcweir             return pOleObject->GetMiscStatus( dwAspect, pdwStatus );
1215*cdf0e10cSrcweir     }
1216*cdf0e10cSrcweir 
1217*cdf0e10cSrcweir     return E_FAIL;
1218*cdf0e10cSrcweir }
1219*cdf0e10cSrcweir 
1220*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1221*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::SetColorScheme( LOGPALETTE * pLogpal )
1222*cdf0e10cSrcweir {
1223*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetColorScheme( LOGPALETTE * pLogpal )" );
1224*cdf0e10cSrcweir     if ( CheckDefHandler() )
1225*cdf0e10cSrcweir     {
1226*cdf0e10cSrcweir         ComSmart< IOleObject > pOleObject;
1227*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleObject, (void**)&pOleObject );
1228*cdf0e10cSrcweir 
1229*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1230*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pOleObject )
1231*cdf0e10cSrcweir             return pOleObject->SetColorScheme( pLogpal );
1232*cdf0e10cSrcweir     }
1233*cdf0e10cSrcweir 
1234*cdf0e10cSrcweir     return E_FAIL;
1235*cdf0e10cSrcweir }
1236*cdf0e10cSrcweir 
1237*cdf0e10cSrcweir //IDataObject
1238*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1239*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::GetData( FORMATETC * pFormatetc, STGMEDIUM * pMedium )
1240*cdf0e10cSrcweir {
1241*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetData( FORMATETC * pFormatetc, STGMEDIUM * pMedium )" );
1242*cdf0e10cSrcweir     if ( CheckDefHandler() )
1243*cdf0e10cSrcweir     {
1244*cdf0e10cSrcweir         ComSmart< IDataObject > pIDataObject;
1245*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject );
1246*cdf0e10cSrcweir 
1247*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1248*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIDataObject )
1249*cdf0e10cSrcweir             return pIDataObject->GetData( pFormatetc, pMedium );
1250*cdf0e10cSrcweir     }
1251*cdf0e10cSrcweir 
1252*cdf0e10cSrcweir     return E_FAIL;
1253*cdf0e10cSrcweir }
1254*cdf0e10cSrcweir 
1255*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1256*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::GetDataHere( FORMATETC * pFormatetc, STGMEDIUM * pMedium )
1257*cdf0e10cSrcweir {
1258*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetDataHere( FORMATETC * pFormatetc, STGMEDIUM * pMedium )" );
1259*cdf0e10cSrcweir     if ( CheckDefHandler() )
1260*cdf0e10cSrcweir     {
1261*cdf0e10cSrcweir         ComSmart< IDataObject > pIDataObject;
1262*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject );
1263*cdf0e10cSrcweir 
1264*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1265*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIDataObject )
1266*cdf0e10cSrcweir             return pIDataObject->GetDataHere( pFormatetc, pMedium );
1267*cdf0e10cSrcweir     }
1268*cdf0e10cSrcweir 
1269*cdf0e10cSrcweir     return E_FAIL;
1270*cdf0e10cSrcweir }
1271*cdf0e10cSrcweir 
1272*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1273*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::QueryGetData( FORMATETC * pFormatetc )
1274*cdf0e10cSrcweir {
1275*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::QueryGetData( FORMATETC * pFormatetc )" );
1276*cdf0e10cSrcweir     if ( CheckDefHandler() )
1277*cdf0e10cSrcweir     {
1278*cdf0e10cSrcweir         ComSmart< IDataObject > pIDataObject;
1279*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject );
1280*cdf0e10cSrcweir 
1281*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1282*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIDataObject )
1283*cdf0e10cSrcweir             return pIDataObject->QueryGetData( pFormatetc );
1284*cdf0e10cSrcweir     }
1285*cdf0e10cSrcweir 
1286*cdf0e10cSrcweir     return E_FAIL;
1287*cdf0e10cSrcweir }
1288*cdf0e10cSrcweir 
1289*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1290*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::GetCanonicalFormatEtc( FORMATETC * pFormatetcIn, FORMATETC * pFormatetcOut )
1291*cdf0e10cSrcweir {
1292*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetCanonicalFormatEtc( FORMATETC * pFormatetcIn, FORMATETC * pFormatetcOut )" );
1293*cdf0e10cSrcweir     if ( CheckDefHandler() )
1294*cdf0e10cSrcweir     {
1295*cdf0e10cSrcweir         ComSmart< IDataObject > pIDataObject;
1296*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject );
1297*cdf0e10cSrcweir 
1298*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1299*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIDataObject )
1300*cdf0e10cSrcweir             return pIDataObject->GetCanonicalFormatEtc( pFormatetcIn, pFormatetcOut );
1301*cdf0e10cSrcweir     }
1302*cdf0e10cSrcweir 
1303*cdf0e10cSrcweir     return E_FAIL;
1304*cdf0e10cSrcweir }
1305*cdf0e10cSrcweir 
1306*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1307*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::SetData( FORMATETC * pFormatetc, STGMEDIUM * pMedium, BOOL fRelease )
1308*cdf0e10cSrcweir {
1309*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetData( FORMATETC * pFormatetc, STGMEDIUM * pMedium, BOOL fRelease )" );
1310*cdf0e10cSrcweir     if ( CheckDefHandler() )
1311*cdf0e10cSrcweir     {
1312*cdf0e10cSrcweir         ComSmart< IDataObject > pIDataObject;
1313*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject );
1314*cdf0e10cSrcweir 
1315*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1316*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIDataObject )
1317*cdf0e10cSrcweir             return pIDataObject->SetData( pFormatetc, pMedium, fRelease );
1318*cdf0e10cSrcweir     }
1319*cdf0e10cSrcweir 
1320*cdf0e10cSrcweir     return E_FAIL;
1321*cdf0e10cSrcweir }
1322*cdf0e10cSrcweir 
1323*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1324*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::EnumFormatEtc( DWORD dwDirection, IEnumFORMATETC ** ppFormatetc )
1325*cdf0e10cSrcweir {
1326*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::EnumFormatEtc( DWORD dwDirection, IEnumFORMATETC ** ppFormatetc )" );
1327*cdf0e10cSrcweir     if ( CheckDefHandler() )
1328*cdf0e10cSrcweir     {
1329*cdf0e10cSrcweir         ComSmart< IDataObject > pIDataObject;
1330*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject );
1331*cdf0e10cSrcweir 
1332*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1333*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIDataObject )
1334*cdf0e10cSrcweir             return pIDataObject->EnumFormatEtc( dwDirection, ppFormatetc );
1335*cdf0e10cSrcweir     }
1336*cdf0e10cSrcweir 
1337*cdf0e10cSrcweir     return E_FAIL;
1338*cdf0e10cSrcweir }
1339*cdf0e10cSrcweir 
1340*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1341*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::DAdvise( FORMATETC * pFormatetc, DWORD advf, IAdviseSink * pAdvSink, DWORD * pdwConnection )
1342*cdf0e10cSrcweir {
1343*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::DAdvise( FORMATETC * pFormatetc, DWORD advf, IAdviseSink * pAdvSink, DWORD * pdwConnection )" );
1344*cdf0e10cSrcweir 
1345*cdf0e10cSrcweir     if ( !pdwConnection )
1346*cdf0e10cSrcweir         return E_FAIL;
1347*cdf0e10cSrcweir 
1348*cdf0e10cSrcweir 	// avoid reusing of the old listener
1349*cdf0e10cSrcweir 	if ( m_pDefHandler && DEFAULT_ARRAY_LEN > *pdwConnection && *pdwConnection > 0 && m_pDataAdvises[*pdwConnection] )
1350*cdf0e10cSrcweir     {
1351*cdf0e10cSrcweir         m_pDataAdvises[*pdwConnection]->DisconnectOrigAdvise();
1352*cdf0e10cSrcweir         m_pDataAdvises[*pdwConnection] = NULL;
1353*cdf0e10cSrcweir     }
1354*cdf0e10cSrcweir 
1355*cdf0e10cSrcweir 	if ( pAdvSink && CheckDefHandler() )
1356*cdf0e10cSrcweir     {
1357*cdf0e10cSrcweir         ComSmart< IDataObject > pIDataObject;
1358*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject );
1359*cdf0e10cSrcweir 
1360*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1361*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIDataObject )
1362*cdf0e10cSrcweir         {
1363*cdf0e10cSrcweir             ComSmart< OleWrapperAdviseSink > pOwnAdvise( new OleWrapperAdviseSink( ComSmart<IAdviseSink>( pAdvSink ), pFormatetc, advf ) );
1364*cdf0e10cSrcweir             DWORD nRegID = 0;
1365*cdf0e10cSrcweir 
1366*cdf0e10cSrcweir             if ( SUCCEEDED( pIDataObject->DAdvise( pFormatetc, advf, pOwnAdvise, &nRegID ) ) && nRegID > 0 )
1367*cdf0e10cSrcweir             {
1368*cdf0e10cSrcweir                 pOwnAdvise->SetRegID( nRegID );
1369*cdf0e10cSrcweir                 *pdwConnection = InsertAdviseLinkToList( pOwnAdvise, m_pDataAdvises );
1370*cdf0e10cSrcweir                 if ( *pdwConnection )
1371*cdf0e10cSrcweir                     return S_OK;
1372*cdf0e10cSrcweir                 else
1373*cdf0e10cSrcweir                     pIDataObject->DUnadvise( nRegID );
1374*cdf0e10cSrcweir             }
1375*cdf0e10cSrcweir         }
1376*cdf0e10cSrcweir     }
1377*cdf0e10cSrcweir 
1378*cdf0e10cSrcweir     // return success always for now
1379*cdf0e10cSrcweir     return S_OK;
1380*cdf0e10cSrcweir }
1381*cdf0e10cSrcweir 
1382*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1383*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::DUnadvise( DWORD dwConnection )
1384*cdf0e10cSrcweir {
1385*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::DUnadvise( DWORD dwConnection )" );
1386*cdf0e10cSrcweir     if ( m_pDefHandler && DEFAULT_ARRAY_LEN > dwConnection && dwConnection > 0 && m_pDataAdvises[dwConnection] )
1387*cdf0e10cSrcweir     {
1388*cdf0e10cSrcweir         if ( CheckDefHandler() )
1389*cdf0e10cSrcweir         {
1390*cdf0e10cSrcweir             ComSmart< IDataObject > pIDataObject;
1391*cdf0e10cSrcweir             HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject );
1392*cdf0e10cSrcweir 
1393*cdf0e10cSrcweir             ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1394*cdf0e10cSrcweir             if ( SUCCEEDED( hr ) && pIDataObject )
1395*cdf0e10cSrcweir             {
1396*cdf0e10cSrcweir                 DWORD nID = m_pDataAdvises[dwConnection]->GetRegID();
1397*cdf0e10cSrcweir                 pIDataObject->DUnadvise( nID );
1398*cdf0e10cSrcweir             }
1399*cdf0e10cSrcweir         }
1400*cdf0e10cSrcweir 
1401*cdf0e10cSrcweir         m_pDataAdvises[dwConnection]->DisconnectOrigAdvise();
1402*cdf0e10cSrcweir         m_pDataAdvises[dwConnection] = NULL;
1403*cdf0e10cSrcweir 
1404*cdf0e10cSrcweir         return S_OK;
1405*cdf0e10cSrcweir     }
1406*cdf0e10cSrcweir 
1407*cdf0e10cSrcweir     return E_FAIL;
1408*cdf0e10cSrcweir }
1409*cdf0e10cSrcweir 
1410*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1411*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::EnumDAdvise( IEnumSTATDATA ** ppenumAdvise )
1412*cdf0e10cSrcweir {
1413*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::EnumDAdvise( IEnumSTATDATA ** ppenumAdvise )" );
1414*cdf0e10cSrcweir     if ( CheckDefHandler() )
1415*cdf0e10cSrcweir     {
1416*cdf0e10cSrcweir         ComSmart< IDataObject > pIDataObject;
1417*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IDataObject, (void**)&pIDataObject );
1418*cdf0e10cSrcweir 
1419*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1420*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIDataObject )
1421*cdf0e10cSrcweir             return pIDataObject->EnumDAdvise( ppenumAdvise );
1422*cdf0e10cSrcweir     }
1423*cdf0e10cSrcweir 
1424*cdf0e10cSrcweir     return E_FAIL;
1425*cdf0e10cSrcweir }
1426*cdf0e10cSrcweir 
1427*cdf0e10cSrcweir // IRunnableObject
1428*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1429*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::GetRunningClass( LPCLSID lpClsid )
1430*cdf0e10cSrcweir {
1431*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetRunningClass( LPCLSID lpClsid )" );
1432*cdf0e10cSrcweir     if ( CheckDefHandler() )
1433*cdf0e10cSrcweir     {
1434*cdf0e10cSrcweir         ComSmart< IRunnableObject > pIRunObj;
1435*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IRunnableObject, (void**)&pIRunObj );
1436*cdf0e10cSrcweir 
1437*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1438*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIRunObj )
1439*cdf0e10cSrcweir             return pIRunObj->GetRunningClass( lpClsid );
1440*cdf0e10cSrcweir     }
1441*cdf0e10cSrcweir 
1442*cdf0e10cSrcweir     return E_FAIL;
1443*cdf0e10cSrcweir }
1444*cdf0e10cSrcweir 
1445*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1446*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::Run( LPBINDCTX pbc )
1447*cdf0e10cSrcweir {
1448*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Run( LPBINDCTX pbc )" );
1449*cdf0e10cSrcweir     if ( CheckDefHandler() )
1450*cdf0e10cSrcweir     {
1451*cdf0e10cSrcweir         ComSmart< IRunnableObject > pIRunObj;
1452*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IRunnableObject, (void**)&pIRunObj );
1453*cdf0e10cSrcweir 
1454*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1455*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIRunObj )
1456*cdf0e10cSrcweir             return pIRunObj->Run( pbc );
1457*cdf0e10cSrcweir     }
1458*cdf0e10cSrcweir 
1459*cdf0e10cSrcweir     return E_FAIL;
1460*cdf0e10cSrcweir }
1461*cdf0e10cSrcweir 
1462*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1463*cdf0e10cSrcweir BOOL STDMETHODCALLTYPE InprocEmbedDocument_Impl::IsRunning()
1464*cdf0e10cSrcweir {
1465*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::IsRunning()" );
1466*cdf0e10cSrcweir    if ( CheckDefHandler() )
1467*cdf0e10cSrcweir     {
1468*cdf0e10cSrcweir         ComSmart< IRunnableObject > pIRunObj;
1469*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IRunnableObject, (void**)&pIRunObj );
1470*cdf0e10cSrcweir 
1471*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1472*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIRunObj )
1473*cdf0e10cSrcweir             return pIRunObj->IsRunning();
1474*cdf0e10cSrcweir     }
1475*cdf0e10cSrcweir 
1476*cdf0e10cSrcweir     return E_FAIL;
1477*cdf0e10cSrcweir 
1478*cdf0e10cSrcweir }
1479*cdf0e10cSrcweir 
1480*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1481*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::LockRunning( BOOL fLock, BOOL fLastUnlockCloses )
1482*cdf0e10cSrcweir {
1483*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::LockRunning( BOOL fLock, BOOL fLastUnlockCloses )" );
1484*cdf0e10cSrcweir    if ( CheckDefHandler() )
1485*cdf0e10cSrcweir     {
1486*cdf0e10cSrcweir         ComSmart< IRunnableObject > pIRunObj;
1487*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IRunnableObject, (void**)&pIRunObj );
1488*cdf0e10cSrcweir 
1489*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1490*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIRunObj )
1491*cdf0e10cSrcweir             return pIRunObj->LockRunning( fLock, fLastUnlockCloses );
1492*cdf0e10cSrcweir     }
1493*cdf0e10cSrcweir 
1494*cdf0e10cSrcweir     return E_FAIL;
1495*cdf0e10cSrcweir }
1496*cdf0e10cSrcweir 
1497*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1498*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::SetContainedObject( BOOL fContained)
1499*cdf0e10cSrcweir {
1500*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetContainedObject( BOOL fContained)" );
1501*cdf0e10cSrcweir    if ( CheckDefHandler() )
1502*cdf0e10cSrcweir     {
1503*cdf0e10cSrcweir         ComSmart< IRunnableObject > pIRunObj;
1504*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IRunnableObject, (void**)&pIRunObj );
1505*cdf0e10cSrcweir 
1506*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1507*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIRunObj )
1508*cdf0e10cSrcweir             return pIRunObj->SetContainedObject( fContained );
1509*cdf0e10cSrcweir     }
1510*cdf0e10cSrcweir 
1511*cdf0e10cSrcweir     return E_FAIL;
1512*cdf0e10cSrcweir }
1513*cdf0e10cSrcweir 
1514*cdf0e10cSrcweir 
1515*cdf0e10cSrcweir // IViewObject methods
1516*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1517*cdf0e10cSrcweir 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 )
1518*cdf0e10cSrcweir {
1519*cdf0e10cSrcweir     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 )" );
1520*cdf0e10cSrcweir     if ( CheckDefHandler() )
1521*cdf0e10cSrcweir     {
1522*cdf0e10cSrcweir         ComSmart< IViewObject > pIViewObject;
1523*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IViewObject, (void**)&pIViewObject );
1524*cdf0e10cSrcweir 
1525*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1526*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIViewObject )
1527*cdf0e10cSrcweir             return pIViewObject->Draw( dwDrawAspect, lindex, pvAspect, ptd, hdcTargetDev, hdcDraw, lprcBounds, lprcWBounds, pfnContinue, dwContinue );
1528*cdf0e10cSrcweir     }
1529*cdf0e10cSrcweir 
1530*cdf0e10cSrcweir     return E_FAIL;
1531*cdf0e10cSrcweir }
1532*cdf0e10cSrcweir 
1533*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1534*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::GetColorSet( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet )
1535*cdf0e10cSrcweir {
1536*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetColorSet( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DVTARGETDEVICE *ptd, HDC hicTargetDev, LOGPALETTE **ppColorSet )" );
1537*cdf0e10cSrcweir     if ( CheckDefHandler() )
1538*cdf0e10cSrcweir     {
1539*cdf0e10cSrcweir         ComSmart< IViewObject > pIViewObject;
1540*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IViewObject, (void**)&pIViewObject );
1541*cdf0e10cSrcweir 
1542*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1543*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIViewObject )
1544*cdf0e10cSrcweir             return pIViewObject->GetColorSet( dwDrawAspect, lindex, pvAspect, ptd, hicTargetDev, ppColorSet );
1545*cdf0e10cSrcweir     }
1546*cdf0e10cSrcweir 
1547*cdf0e10cSrcweir     return E_FAIL;
1548*cdf0e10cSrcweir }
1549*cdf0e10cSrcweir 
1550*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1551*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::Freeze( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DWORD *pdwFreeze )
1552*cdf0e10cSrcweir {
1553*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Freeze( DWORD dwDrawAspect, LONG lindex, void *pvAspect, DWORD *pdwFreeze )" );
1554*cdf0e10cSrcweir     if ( CheckDefHandler() )
1555*cdf0e10cSrcweir     {
1556*cdf0e10cSrcweir         ComSmart< IViewObject > pIViewObject;
1557*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IViewObject, (void**)&pIViewObject );
1558*cdf0e10cSrcweir 
1559*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1560*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIViewObject )
1561*cdf0e10cSrcweir             return pIViewObject->Freeze( dwDrawAspect, lindex, pvAspect, pdwFreeze );
1562*cdf0e10cSrcweir     }
1563*cdf0e10cSrcweir 
1564*cdf0e10cSrcweir     return E_FAIL;
1565*cdf0e10cSrcweir }
1566*cdf0e10cSrcweir 
1567*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1568*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::Unfreeze( DWORD dwFreeze )
1569*cdf0e10cSrcweir {
1570*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Unfreeze( DWORD dwFreeze )" );
1571*cdf0e10cSrcweir     if ( CheckDefHandler() )
1572*cdf0e10cSrcweir     {
1573*cdf0e10cSrcweir         ComSmart< IViewObject > pIViewObject;
1574*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IViewObject, (void**)&pIViewObject );
1575*cdf0e10cSrcweir 
1576*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1577*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIViewObject )
1578*cdf0e10cSrcweir             return pIViewObject->Unfreeze( dwFreeze );
1579*cdf0e10cSrcweir     }
1580*cdf0e10cSrcweir 
1581*cdf0e10cSrcweir     return E_FAIL;
1582*cdf0e10cSrcweir }
1583*cdf0e10cSrcweir 
1584*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1585*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::SetAdvise( DWORD aspects, DWORD advf, IAdviseSink *pAdvSink )
1586*cdf0e10cSrcweir {
1587*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetAdvise( DWORD aspects, DWORD advf, IAdviseSink *pAdvSink )" );
1588*cdf0e10cSrcweir 
1589*cdf0e10cSrcweir 	// CheckDefHandler will set the listener, avoid reusing of old listener
1590*cdf0e10cSrcweir     if ( m_pViewAdvise )
1591*cdf0e10cSrcweir     {
1592*cdf0e10cSrcweir         m_pViewAdvise->DisconnectOrigAdvise();
1593*cdf0e10cSrcweir 	    m_pViewAdvise = NULL;
1594*cdf0e10cSrcweir     }
1595*cdf0e10cSrcweir 
1596*cdf0e10cSrcweir     if ( pAdvSink && CheckDefHandler() )
1597*cdf0e10cSrcweir     {
1598*cdf0e10cSrcweir         ComSmart< IViewObject > pIViewObject;
1599*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IViewObject, (void**)&pIViewObject );
1600*cdf0e10cSrcweir 
1601*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1602*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIViewObject )
1603*cdf0e10cSrcweir         {
1604*cdf0e10cSrcweir             ComSmart< OleWrapperAdviseSink > pOwnAdvise( new OleWrapperAdviseSink( pAdvSink, aspects, advf ) );
1605*cdf0e10cSrcweir 
1606*cdf0e10cSrcweir             if ( SUCCEEDED( pIViewObject->SetAdvise( aspects, advf, pOwnAdvise ) ) )
1607*cdf0e10cSrcweir             {
1608*cdf0e10cSrcweir                 m_pViewAdvise = pOwnAdvise;
1609*cdf0e10cSrcweir                 return S_OK;
1610*cdf0e10cSrcweir             }
1611*cdf0e10cSrcweir         }
1612*cdf0e10cSrcweir     }
1613*cdf0e10cSrcweir 
1614*cdf0e10cSrcweir     return S_OK;
1615*cdf0e10cSrcweir }
1616*cdf0e10cSrcweir 
1617*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1618*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::GetAdvise( DWORD *pAspects, DWORD *pAdvf, IAdviseSink **ppAdvSink )
1619*cdf0e10cSrcweir {
1620*cdf0e10cSrcweir     if ( !ppAdvSink )
1621*cdf0e10cSrcweir         return E_INVALIDARG;
1622*cdf0e10cSrcweir 
1623*cdf0e10cSrcweir     if ( m_pViewAdvise )
1624*cdf0e10cSrcweir     {
1625*cdf0e10cSrcweir         if ( pAspects )
1626*cdf0e10cSrcweir             *pAspects = m_pViewAdvise->GetAspect();
1627*cdf0e10cSrcweir 
1628*cdf0e10cSrcweir         if ( pAdvf )
1629*cdf0e10cSrcweir             *pAdvf = m_pViewAdvise->GetViewAdviseFlag();
1630*cdf0e10cSrcweir 
1631*cdf0e10cSrcweir         *ppAdvSink = m_pViewAdvise->GetOrigAdvise();
1632*cdf0e10cSrcweir         if ( *ppAdvSink )
1633*cdf0e10cSrcweir             (*ppAdvSink)->AddRef();
1634*cdf0e10cSrcweir     }
1635*cdf0e10cSrcweir     else
1636*cdf0e10cSrcweir         *ppAdvSink = NULL;
1637*cdf0e10cSrcweir 
1638*cdf0e10cSrcweir     return S_OK;
1639*cdf0e10cSrcweir }
1640*cdf0e10cSrcweir 
1641*cdf0e10cSrcweir // IViewObject2 methods
1642*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1643*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::GetExtent( DWORD dwDrawAspect, LONG lindex, DVTARGETDEVICE *ptd, LPSIZEL lpsizel )
1644*cdf0e10cSrcweir {
1645*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetExtent( DWORD dwDrawAspect, LONG lindex, DVTARGETDEVICE *ptd, LPSIZEL lpsizel )" );
1646*cdf0e10cSrcweir     if ( CheckDefHandler() )
1647*cdf0e10cSrcweir     {
1648*cdf0e10cSrcweir         ComSmart< IViewObject2 > pIViewObject2;
1649*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IViewObject2, (void**)&pIViewObject2 );
1650*cdf0e10cSrcweir 
1651*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1652*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIViewObject2 )
1653*cdf0e10cSrcweir             return pIViewObject2->GetExtent( dwDrawAspect, lindex, ptd, lpsizel );
1654*cdf0e10cSrcweir     }
1655*cdf0e10cSrcweir 
1656*cdf0e10cSrcweir     return E_FAIL;
1657*cdf0e10cSrcweir }
1658*cdf0e10cSrcweir 
1659*cdf0e10cSrcweir 
1660*cdf0e10cSrcweir 
1661*cdf0e10cSrcweir // IOleWindow methods
1662*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1663*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::GetWindow( HWND *phwnd )
1664*cdf0e10cSrcweir {
1665*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetWindow( HWND *phwnd )" );
1666*cdf0e10cSrcweir     if ( CheckDefHandler() )
1667*cdf0e10cSrcweir     {
1668*cdf0e10cSrcweir         ComSmart< IOleWindow > pIOleWindow;
1669*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleWindow, (void**)&pIOleWindow );
1670*cdf0e10cSrcweir 
1671*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1672*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIOleWindow )
1673*cdf0e10cSrcweir             return pIOleWindow->GetWindow( phwnd );
1674*cdf0e10cSrcweir     }
1675*cdf0e10cSrcweir 
1676*cdf0e10cSrcweir     return E_FAIL;
1677*cdf0e10cSrcweir }
1678*cdf0e10cSrcweir 
1679*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1680*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::ContextSensitiveHelp( BOOL fEnterMode )
1681*cdf0e10cSrcweir {
1682*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::ContextSensitiveHelp( BOOL fEnterMode )" );
1683*cdf0e10cSrcweir     if ( CheckDefHandler() )
1684*cdf0e10cSrcweir     {
1685*cdf0e10cSrcweir         ComSmart< IOleWindow > pIOleWindow;
1686*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleWindow, (void**)&pIOleWindow );
1687*cdf0e10cSrcweir 
1688*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1689*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIOleWindow )
1690*cdf0e10cSrcweir             return pIOleWindow->ContextSensitiveHelp( fEnterMode );
1691*cdf0e10cSrcweir     }
1692*cdf0e10cSrcweir 
1693*cdf0e10cSrcweir     return E_FAIL;
1694*cdf0e10cSrcweir }
1695*cdf0e10cSrcweir 
1696*cdf0e10cSrcweir 
1697*cdf0e10cSrcweir // IOleInPlaceObject methods
1698*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1699*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::InPlaceDeactivate( void )
1700*cdf0e10cSrcweir {
1701*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InPlaceDeactivate( void )" );
1702*cdf0e10cSrcweir     if ( CheckDefHandler() )
1703*cdf0e10cSrcweir     {
1704*cdf0e10cSrcweir         ComSmart< IOleInPlaceObject > pIOleInPlaceObject;
1705*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleInPlaceObject, (void**)&pIOleInPlaceObject );
1706*cdf0e10cSrcweir 
1707*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1708*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIOleInPlaceObject )
1709*cdf0e10cSrcweir             return pIOleInPlaceObject->InPlaceDeactivate();
1710*cdf0e10cSrcweir     }
1711*cdf0e10cSrcweir 
1712*cdf0e10cSrcweir     return E_FAIL;
1713*cdf0e10cSrcweir }
1714*cdf0e10cSrcweir 
1715*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1716*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::UIDeactivate( void )
1717*cdf0e10cSrcweir {
1718*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::UIDeactivate( void )" );
1719*cdf0e10cSrcweir     if ( CheckDefHandler() )
1720*cdf0e10cSrcweir     {
1721*cdf0e10cSrcweir         ComSmart< IOleInPlaceObject > pIOleInPlaceObject;
1722*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleInPlaceObject, (void**)&pIOleInPlaceObject );
1723*cdf0e10cSrcweir 
1724*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1725*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIOleInPlaceObject )
1726*cdf0e10cSrcweir             return pIOleInPlaceObject->UIDeactivate();
1727*cdf0e10cSrcweir     }
1728*cdf0e10cSrcweir 
1729*cdf0e10cSrcweir     return E_FAIL;
1730*cdf0e10cSrcweir }
1731*cdf0e10cSrcweir 
1732*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1733*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::SetObjectRects( LPCRECT lprcPosRect, LPCRECT lprcClipRect )
1734*cdf0e10cSrcweir {
1735*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::SetObjectRects( LPCRECT lprcPosRect, LPCRECT lprcClipRect )" );
1736*cdf0e10cSrcweir     if ( CheckDefHandler() )
1737*cdf0e10cSrcweir     {
1738*cdf0e10cSrcweir         ComSmart< IOleInPlaceObject > pIOleInPlaceObject;
1739*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleInPlaceObject, (void**)&pIOleInPlaceObject );
1740*cdf0e10cSrcweir 
1741*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1742*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIOleInPlaceObject )
1743*cdf0e10cSrcweir             return pIOleInPlaceObject->SetObjectRects( lprcPosRect, lprcClipRect );
1744*cdf0e10cSrcweir     }
1745*cdf0e10cSrcweir 
1746*cdf0e10cSrcweir     return E_FAIL;
1747*cdf0e10cSrcweir }
1748*cdf0e10cSrcweir 
1749*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1750*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::ReactivateAndUndo( void )
1751*cdf0e10cSrcweir {
1752*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::ReactivateAndUndo( void )" );
1753*cdf0e10cSrcweir     if ( CheckDefHandler() )
1754*cdf0e10cSrcweir     {
1755*cdf0e10cSrcweir         ComSmart< IOleInPlaceObject > pIOleInPlaceObject;
1756*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IOleInPlaceObject, (void**)&pIOleInPlaceObject );
1757*cdf0e10cSrcweir 
1758*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1759*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIOleInPlaceObject )
1760*cdf0e10cSrcweir             return pIOleInPlaceObject->ReactivateAndUndo();
1761*cdf0e10cSrcweir     }
1762*cdf0e10cSrcweir 
1763*cdf0e10cSrcweir     return E_FAIL;
1764*cdf0e10cSrcweir }
1765*cdf0e10cSrcweir 
1766*cdf0e10cSrcweir 
1767*cdf0e10cSrcweir // IDispatch methods
1768*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1769*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::GetTypeInfoCount( UINT *pctinfo )
1770*cdf0e10cSrcweir {
1771*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetTypeInfoCount( UINT *pctinfo )" );
1772*cdf0e10cSrcweir     if ( CheckDefHandler() )
1773*cdf0e10cSrcweir     {
1774*cdf0e10cSrcweir         ComSmart< IDispatch > pIDispatch;
1775*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IDispatch, (void**)&pIDispatch );
1776*cdf0e10cSrcweir 
1777*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1778*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIDispatch )
1779*cdf0e10cSrcweir             return pIDispatch->GetTypeInfoCount( pctinfo );
1780*cdf0e10cSrcweir     }
1781*cdf0e10cSrcweir 
1782*cdf0e10cSrcweir     return E_FAIL;
1783*cdf0e10cSrcweir }
1784*cdf0e10cSrcweir 
1785*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1786*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::GetTypeInfo( UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo )
1787*cdf0e10cSrcweir {
1788*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetTypeInfo( UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo )" );
1789*cdf0e10cSrcweir     if ( CheckDefHandler() )
1790*cdf0e10cSrcweir     {
1791*cdf0e10cSrcweir         ComSmart< IDispatch > pIDispatch;
1792*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IDispatch, (void**)&pIDispatch );
1793*cdf0e10cSrcweir 
1794*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1795*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIDispatch )
1796*cdf0e10cSrcweir             return pIDispatch->GetTypeInfo( iTInfo, lcid, ppTInfo );
1797*cdf0e10cSrcweir     }
1798*cdf0e10cSrcweir 
1799*cdf0e10cSrcweir     return E_FAIL;
1800*cdf0e10cSrcweir }
1801*cdf0e10cSrcweir 
1802*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1803*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::GetIDsOfNames( REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId )
1804*cdf0e10cSrcweir {
1805*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::GetIDsOfNames( REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId )" );
1806*cdf0e10cSrcweir     if ( CheckDefHandler() )
1807*cdf0e10cSrcweir     {
1808*cdf0e10cSrcweir         ComSmart< IDispatch > pIDispatch;
1809*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IDispatch, (void**)&pIDispatch );
1810*cdf0e10cSrcweir 
1811*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1812*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIDispatch )
1813*cdf0e10cSrcweir             return pIDispatch->GetIDsOfNames( riid, rgszNames, cNames, lcid, rgDispId );
1814*cdf0e10cSrcweir     }
1815*cdf0e10cSrcweir 
1816*cdf0e10cSrcweir     return E_FAIL;
1817*cdf0e10cSrcweir }
1818*cdf0e10cSrcweir 
1819*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1820*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::Invoke( DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr )
1821*cdf0e10cSrcweir {
1822*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::Invoke( DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr )" );
1823*cdf0e10cSrcweir     if ( CheckDefHandler() )
1824*cdf0e10cSrcweir     {
1825*cdf0e10cSrcweir         ComSmart< IDispatch > pIDispatch;
1826*cdf0e10cSrcweir         HRESULT hr = m_pDefHandler->QueryInterface( IID_IDispatch, (void**)&pIDispatch );
1827*cdf0e10cSrcweir 
1828*cdf0e10cSrcweir         ULONGGuard aGuard( &m_nCallsOnStack ); // avoid reentrance problem
1829*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIDispatch )
1830*cdf0e10cSrcweir             return pIDispatch->Invoke( dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr );
1831*cdf0e10cSrcweir     }
1832*cdf0e10cSrcweir 
1833*cdf0e10cSrcweir     return E_FAIL;
1834*cdf0e10cSrcweir }
1835*cdf0e10cSrcweir 
1836*cdf0e10cSrcweir 
1837*cdf0e10cSrcweir // ====
1838*cdf0e10cSrcweir // InternalCacheWrapper
1839*cdf0e10cSrcweir // ====
1840*cdf0e10cSrcweir 
1841*cdf0e10cSrcweir // IUnknown
1842*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1843*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::QueryInterface( REFIID riid, void FAR* FAR* ppv )
1844*cdf0e10cSrcweir {
1845*cdf0e10cSrcweir     return m_rOwnDocument.QueryInterface( riid, ppv );
1846*cdf0e10cSrcweir }
1847*cdf0e10cSrcweir 
1848*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1849*cdf0e10cSrcweir STDMETHODIMP_(ULONG) InprocEmbedDocument_Impl::InternalCacheWrapper::AddRef()
1850*cdf0e10cSrcweir {
1851*cdf0e10cSrcweir 	return m_rOwnDocument.AddRef();
1852*cdf0e10cSrcweir }
1853*cdf0e10cSrcweir 
1854*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1855*cdf0e10cSrcweir STDMETHODIMP_(ULONG) InprocEmbedDocument_Impl::InternalCacheWrapper::Release()
1856*cdf0e10cSrcweir {
1857*cdf0e10cSrcweir     return m_rOwnDocument.Release();
1858*cdf0e10cSrcweir }
1859*cdf0e10cSrcweir 
1860*cdf0e10cSrcweir // IOleCache methods
1861*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1862*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::Cache( FORMATETC *pformatetc, DWORD advf, DWORD *pdwConnection )
1863*cdf0e10cSrcweir {
1864*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::Cache( FORMATETC *pformatetc, DWORD advf, DWORD *pdwConnection )" );
1865*cdf0e10cSrcweir     if ( m_rOwnDocument.CheckDefHandler() )
1866*cdf0e10cSrcweir     {
1867*cdf0e10cSrcweir         ComSmart< IOleCache > pIOleCache;
1868*cdf0e10cSrcweir         HRESULT hr = m_rOwnDocument.GetDefHandler()->QueryInterface( IID_IOleCache, (void**)&pIOleCache );
1869*cdf0e10cSrcweir 
1870*cdf0e10cSrcweir         ULONGGuard aGuard( &m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem
1871*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIOleCache )
1872*cdf0e10cSrcweir             return pIOleCache->Cache( pformatetc, advf, pdwConnection );
1873*cdf0e10cSrcweir     }
1874*cdf0e10cSrcweir 
1875*cdf0e10cSrcweir     return E_FAIL;
1876*cdf0e10cSrcweir }
1877*cdf0e10cSrcweir 
1878*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1879*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::Uncache( DWORD dwConnection )
1880*cdf0e10cSrcweir {
1881*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::Uncache( DWORD dwConnection )" );
1882*cdf0e10cSrcweir     if ( m_rOwnDocument.CheckDefHandler() )
1883*cdf0e10cSrcweir     {
1884*cdf0e10cSrcweir         ComSmart< IOleCache > pIOleCache;
1885*cdf0e10cSrcweir         HRESULT hr = m_rOwnDocument.GetDefHandler()->QueryInterface( IID_IOleCache, (void**)&pIOleCache );
1886*cdf0e10cSrcweir 
1887*cdf0e10cSrcweir         ULONGGuard aGuard( &m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem
1888*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIOleCache )
1889*cdf0e10cSrcweir             return pIOleCache->Uncache( dwConnection );
1890*cdf0e10cSrcweir     }
1891*cdf0e10cSrcweir 
1892*cdf0e10cSrcweir     return E_FAIL;
1893*cdf0e10cSrcweir }
1894*cdf0e10cSrcweir 
1895*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1896*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::EnumCache( IEnumSTATDATA **ppenumSTATDATA )
1897*cdf0e10cSrcweir {
1898*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::EnumCache( IEnumSTATDATA **ppenumSTATDATA )" );
1899*cdf0e10cSrcweir     if ( m_rOwnDocument.CheckDefHandler() )
1900*cdf0e10cSrcweir     {
1901*cdf0e10cSrcweir         ComSmart< IOleCache > pIOleCache;
1902*cdf0e10cSrcweir         HRESULT hr = m_rOwnDocument.GetDefHandler()->QueryInterface( IID_IOleCache, (void**)&pIOleCache );
1903*cdf0e10cSrcweir 
1904*cdf0e10cSrcweir         ULONGGuard aGuard( &m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem
1905*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIOleCache )
1906*cdf0e10cSrcweir             return pIOleCache->EnumCache( ppenumSTATDATA );
1907*cdf0e10cSrcweir     }
1908*cdf0e10cSrcweir 
1909*cdf0e10cSrcweir     return E_FAIL;
1910*cdf0e10cSrcweir }
1911*cdf0e10cSrcweir 
1912*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1913*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::InitCache( IDataObject *pDataObject )
1914*cdf0e10cSrcweir {
1915*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::InitCache( IDataObject *pDataObject )" );
1916*cdf0e10cSrcweir     if ( m_rOwnDocument.CheckDefHandler() )
1917*cdf0e10cSrcweir     {
1918*cdf0e10cSrcweir         ComSmart< IOleCache > pIOleCache;
1919*cdf0e10cSrcweir         HRESULT hr = m_rOwnDocument.GetDefHandler()->QueryInterface( IID_IOleCache, (void**)&pIOleCache );
1920*cdf0e10cSrcweir 
1921*cdf0e10cSrcweir         ULONGGuard aGuard( &m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem
1922*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIOleCache )
1923*cdf0e10cSrcweir             return pIOleCache->InitCache( pDataObject );
1924*cdf0e10cSrcweir     }
1925*cdf0e10cSrcweir 
1926*cdf0e10cSrcweir     return E_FAIL;
1927*cdf0e10cSrcweir }
1928*cdf0e10cSrcweir 
1929*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1930*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::SetData( FORMATETC *pformatetc, STGMEDIUM *pmedium, BOOL fRelease )
1931*cdf0e10cSrcweir {
1932*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::SetData( FORMATETC *pformatetc, STGMEDIUM *pmedium, BOOL fRelease )" );
1933*cdf0e10cSrcweir     if ( m_rOwnDocument.CheckDefHandler() )
1934*cdf0e10cSrcweir     {
1935*cdf0e10cSrcweir         ComSmart< IOleCache > pIOleCache;
1936*cdf0e10cSrcweir         HRESULT hr = m_rOwnDocument.GetDefHandler()->QueryInterface( IID_IOleCache, (void**)&pIOleCache );
1937*cdf0e10cSrcweir 
1938*cdf0e10cSrcweir         ULONGGuard aGuard( &m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem
1939*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIOleCache )
1940*cdf0e10cSrcweir             return pIOleCache->SetData( pformatetc, pmedium, fRelease );
1941*cdf0e10cSrcweir     }
1942*cdf0e10cSrcweir 
1943*cdf0e10cSrcweir     return E_FAIL;
1944*cdf0e10cSrcweir }
1945*cdf0e10cSrcweir 
1946*cdf0e10cSrcweir // IOleCache2 methods
1947*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1948*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::UpdateCache( LPDATAOBJECT pDataObject, DWORD grfUpdf, LPVOID pReserved )
1949*cdf0e10cSrcweir {
1950*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::UpdateCache( LPDATAOBJECT pDataObject, DWORD grfUpdf, LPVOID pReserved )" );
1951*cdf0e10cSrcweir     if ( m_rOwnDocument.CheckDefHandler() )
1952*cdf0e10cSrcweir     {
1953*cdf0e10cSrcweir         ComSmart< IOleCache2 > pIOleCache2;
1954*cdf0e10cSrcweir         HRESULT hr = m_rOwnDocument.GetDefHandler()->QueryInterface( IID_IOleCache2, (void**)&pIOleCache2 );
1955*cdf0e10cSrcweir 
1956*cdf0e10cSrcweir         ULONGGuard aGuard( &m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem
1957*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIOleCache2 )
1958*cdf0e10cSrcweir             return pIOleCache2->UpdateCache( pDataObject, grfUpdf, pReserved );
1959*cdf0e10cSrcweir     }
1960*cdf0e10cSrcweir 
1961*cdf0e10cSrcweir     return E_FAIL;
1962*cdf0e10cSrcweir }
1963*cdf0e10cSrcweir 
1964*cdf0e10cSrcweir //-------------------------------------------------------------------------------
1965*cdf0e10cSrcweir STDMETHODIMP InprocEmbedDocument_Impl::InternalCacheWrapper::DiscardCache( DWORD dwDiscardOptions )
1966*cdf0e10cSrcweir {
1967*cdf0e10cSrcweir     WRITEDEBUGINFO( "InprocEmbedDocument_Impl::InternalCacheWrapper::DiscardCache( DWORD dwDiscardOptions )" );
1968*cdf0e10cSrcweir     if ( m_rOwnDocument.CheckDefHandler() )
1969*cdf0e10cSrcweir     {
1970*cdf0e10cSrcweir         ComSmart< IOleCache2 > pIOleCache2;
1971*cdf0e10cSrcweir         HRESULT hr = m_rOwnDocument.GetDefHandler()->QueryInterface( IID_IOleCache2, (void**)&pIOleCache2 );
1972*cdf0e10cSrcweir 
1973*cdf0e10cSrcweir         ULONGGuard aGuard( &m_rOwnDocument.m_nCallsOnStack ); // avoid reentrance problem
1974*cdf0e10cSrcweir         if ( SUCCEEDED( hr ) && pIOleCache2 )
1975*cdf0e10cSrcweir             return pIOleCache2->DiscardCache( dwDiscardOptions );
1976*cdf0e10cSrcweir     }
1977*cdf0e10cSrcweir 
1978*cdf0e10cSrcweir     return E_FAIL;
1979*cdf0e10cSrcweir }
1980*cdf0e10cSrcweir 
1981*cdf0e10cSrcweir }; // namespace inprocserv
1982*cdf0e10cSrcweir 
1983