1*f78e906fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f78e906fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f78e906fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f78e906fSAndrew Rist  * distributed with this work for additional information
6*f78e906fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f78e906fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f78e906fSAndrew Rist  * "License"); you may not use this file except in compliance
9*f78e906fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*f78e906fSAndrew Rist  *
11*f78e906fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*f78e906fSAndrew Rist  *
13*f78e906fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f78e906fSAndrew Rist  * software distributed under the License is distributed on an
15*f78e906fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f78e906fSAndrew Rist  * KIND, either express or implied.  See the License for the
17*f78e906fSAndrew Rist  * specific language governing permissions and limitations
18*f78e906fSAndrew Rist  * under the License.
19*f78e906fSAndrew Rist  *
20*f78e906fSAndrew Rist  *************************************************************/
21*f78e906fSAndrew Rist 
22*f78e906fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "embeddoc.hxx"
25cdf0e10cSrcweir #include <osl/diagnose.h>
26cdf0e10cSrcweir #include <com/sun/star/frame/XController.hpp>
27cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir 
30cdf0e10cSrcweir using namespace ::com::sun::star;
31cdf0e10cSrcweir 
32cdf0e10cSrcweir 
33cdf0e10cSrcweir extern ::rtl::OUString	getFilterNameFromGUID_Impl( GUID* );
34cdf0e10cSrcweir 
35cdf0e10cSrcweir //-------------------------------------------------------------------------------
36cdf0e10cSrcweir // IOleObject
37cdf0e10cSrcweir 
38cdf0e10cSrcweir 
SetClientSite(IOleClientSite * pSite)39cdf0e10cSrcweir STDMETHODIMP EmbedDocument_Impl::SetClientSite( IOleClientSite* pSite )
40cdf0e10cSrcweir {
41cdf0e10cSrcweir 	m_pClientSite = pSite;
42cdf0e10cSrcweir 	return S_OK;
43cdf0e10cSrcweir }
44cdf0e10cSrcweir 
GetClientSite(IOleClientSite ** pSite)45cdf0e10cSrcweir STDMETHODIMP EmbedDocument_Impl::GetClientSite( IOleClientSite** pSite )
46cdf0e10cSrcweir {
47cdf0e10cSrcweir 	*pSite = m_pClientSite;
48cdf0e10cSrcweir 	return S_OK;
49cdf0e10cSrcweir }
50cdf0e10cSrcweir 
SetHostNames(LPCOLESTR szContainerApp,LPCOLESTR szContainerObj)51cdf0e10cSrcweir STDMETHODIMP EmbedDocument_Impl::SetHostNames( LPCOLESTR szContainerApp, LPCOLESTR szContainerObj )
52cdf0e10cSrcweir {
53cdf0e10cSrcweir 	// the code should be ignored for links
54cdf0e10cSrcweir 	if ( !m_aFileName.getLength() )
55cdf0e10cSrcweir 	{
56cdf0e10cSrcweir 		m_pDocHolder->setTitle(
57cdf0e10cSrcweir 			rtl::OUString(
58cdf0e10cSrcweir 				(sal_Unicode*)szContainerObj));
59cdf0e10cSrcweir 		m_pDocHolder->setContainerName(
60cdf0e10cSrcweir 			rtl::OUString(
61cdf0e10cSrcweir 				(sal_Unicode*)szContainerApp));
62cdf0e10cSrcweir 	}
63cdf0e10cSrcweir 
64cdf0e10cSrcweir 	return S_OK;
65cdf0e10cSrcweir }
66cdf0e10cSrcweir 
Close(DWORD dwSaveOption)67cdf0e10cSrcweir STDMETHODIMP EmbedDocument_Impl::Close( DWORD dwSaveOption )
68cdf0e10cSrcweir {
69cdf0e10cSrcweir     HRESULT hr = S_OK;
70cdf0e10cSrcweir 
71cdf0e10cSrcweir     if ( m_pDocHolder->HasFrame() )
72cdf0e10cSrcweir     {
73cdf0e10cSrcweir         if ( dwSaveOption == 2 && m_aFileName.getLength() )
74cdf0e10cSrcweir         {
75cdf0e10cSrcweir             // ask the user about saving
76cdf0e10cSrcweir             if ( m_pDocHolder->ExecuteSuspendCloseFrame() )
77cdf0e10cSrcweir             {
78cdf0e10cSrcweir                 m_pDocHolder->CloseDocument();
79cdf0e10cSrcweir                 return S_OK;
80cdf0e10cSrcweir             }
81cdf0e10cSrcweir             else
82cdf0e10cSrcweir                 return OLE_E_PROMPTSAVECANCELLED;
83cdf0e10cSrcweir         }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir         if ( dwSaveOption != 1 )
86cdf0e10cSrcweir             hr = SaveObject(); // ADVF_DATAONSTOP);
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 	    m_pDocHolder->CloseFrame();
89cdf0e10cSrcweir         OLENotifyDeactivation();
90cdf0e10cSrcweir     }
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 	m_pDocHolder->FreeOffice();
93cdf0e10cSrcweir 	m_pDocHolder->CloseDocument();
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 	OLENotifyClosing();
96cdf0e10cSrcweir 
97cdf0e10cSrcweir 	return hr;
98cdf0e10cSrcweir }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 
OLENotifyClosing()101cdf0e10cSrcweir HRESULT EmbedDocument_Impl::OLENotifyClosing()
102cdf0e10cSrcweir {
103cdf0e10cSrcweir 	HRESULT hr = S_OK;
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 	AdviseSinkHashMap aAHM(m_aAdviseHashMap);
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 	for ( AdviseSinkHashMapIterator iAdvise = aAHM.begin();
108cdf0e10cSrcweir 		  iAdvise != aAHM.end(); iAdvise++ )
109cdf0e10cSrcweir 	{
110cdf0e10cSrcweir 		if ( iAdvise->second )
111cdf0e10cSrcweir 			iAdvise->second->OnClose();
112cdf0e10cSrcweir 	}
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 	return hr;
115cdf0e10cSrcweir 
116cdf0e10cSrcweir }
117cdf0e10cSrcweir 
SetMoniker(DWORD,IMoniker *)118cdf0e10cSrcweir STDMETHODIMP EmbedDocument_Impl::SetMoniker( DWORD /*dwWhichMoniker*/, IMoniker * /*pmk*/ )
119cdf0e10cSrcweir {
120cdf0e10cSrcweir     return E_NOTIMPL;
121cdf0e10cSrcweir }
122cdf0e10cSrcweir 
GetMoniker(DWORD,DWORD,IMoniker **)123cdf0e10cSrcweir STDMETHODIMP EmbedDocument_Impl::GetMoniker( DWORD /*dwAssign*/, DWORD /*dwWhichMoniker*/, IMoniker ** /*ppmk*/ )
124cdf0e10cSrcweir {
125cdf0e10cSrcweir     return E_NOTIMPL;
126cdf0e10cSrcweir }
127cdf0e10cSrcweir 
InitFromData(IDataObject *,BOOL,DWORD)128cdf0e10cSrcweir STDMETHODIMP EmbedDocument_Impl::InitFromData( IDataObject * /*pDataObject*/, BOOL /*fCreation*/, DWORD /*dwReserved*/ )
129cdf0e10cSrcweir {
130cdf0e10cSrcweir     return E_NOTIMPL;
131cdf0e10cSrcweir }
132cdf0e10cSrcweir 
GetClipboardData(DWORD,IDataObject **)133cdf0e10cSrcweir STDMETHODIMP EmbedDocument_Impl::GetClipboardData( DWORD /*dwReserved*/, IDataObject ** /*ppDataObject*/ )
134cdf0e10cSrcweir {
135cdf0e10cSrcweir     return E_NOTIMPL;
136cdf0e10cSrcweir }
137cdf0e10cSrcweir 
138cdf0e10cSrcweir /**
139cdf0e10cSrcweir  *  Well, this is a not so very inefficient way to deliver
140cdf0e10cSrcweir  *
141cdf0e10cSrcweir  */
142cdf0e10cSrcweir 
DoVerb(LONG iVerb,LPMSG,IOleClientSite * pActiveSite,LONG,HWND,LPCRECT)143cdf0e10cSrcweir STDMETHODIMP EmbedDocument_Impl::DoVerb(
144cdf0e10cSrcweir 	LONG iVerb,
145cdf0e10cSrcweir 	LPMSG,
146cdf0e10cSrcweir 	IOleClientSite *pActiveSite,
147cdf0e10cSrcweir 	LONG,
148cdf0e10cSrcweir 	HWND,
149cdf0e10cSrcweir 	LPCRECT )
150cdf0e10cSrcweir {
151cdf0e10cSrcweir 	// no locking is used since the OLE must use the same thread always
152cdf0e10cSrcweir 	if ( m_bIsInVerbHandling )
153cdf0e10cSrcweir         return OLEOBJ_S_CANNOT_DOVERB_NOW;
154cdf0e10cSrcweir 
155cdf0e10cSrcweir     // an object can not handle any Verbs in Hands off mode
156cdf0e10cSrcweir     if ( m_pMasterStorage == NULL || m_pOwnStream == NULL )
157cdf0e10cSrcweir         return OLE_E_CANT_BINDTOSOURCE;
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 
160cdf0e10cSrcweir 	BooleanGuard_Impl aGuard( m_bIsInVerbHandling );
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 	if ( iVerb == OLEIVERB_PRIMARY )
163cdf0e10cSrcweir 	{
164cdf0e10cSrcweir 		if ( m_aFileName.getLength() )
165cdf0e10cSrcweir 		{
166cdf0e10cSrcweir 			// that should be a link
167cdf0e10cSrcweir 			iVerb = OLEIVERB_OPEN;
168cdf0e10cSrcweir 		}
169cdf0e10cSrcweir 		else
170cdf0e10cSrcweir 			iVerb = OLEIVERB_SHOW;
171cdf0e10cSrcweir 	}
172cdf0e10cSrcweir 
173cdf0e10cSrcweir 	try
174cdf0e10cSrcweir 	{
175cdf0e10cSrcweir 		switch(iVerb) {
176cdf0e10cSrcweir 			case OLEIVERB_DISCARDUNDOSTATE:
177cdf0e10cSrcweir 				// free any undostate?
178cdf0e10cSrcweir 				break;
179cdf0e10cSrcweir 			case OLEIVERB_INPLACEACTIVATE:
180cdf0e10cSrcweir 				OSL_ENSURE(m_pDocHolder,"no document for inplace activation");
181cdf0e10cSrcweir 
182cdf0e10cSrcweir 				return m_pDocHolder->InPlaceActivate(pActiveSite,FALSE);
183cdf0e10cSrcweir 				break;
184cdf0e10cSrcweir 			case OLEIVERB_UIACTIVATE:
185cdf0e10cSrcweir 				OSL_ENSURE(m_pDocHolder,"no document for	 inplace activation");
186cdf0e10cSrcweir 
187cdf0e10cSrcweir 				return m_pDocHolder->InPlaceActivate(pActiveSite,TRUE);
188cdf0e10cSrcweir 				break;
189cdf0e10cSrcweir 			case OLEIVERB_PRIMARY:
190cdf0e10cSrcweir 			case OLEIVERB_SHOW:
191cdf0e10cSrcweir 				OSL_ENSURE(m_pDocHolder,"no document for inplace activation");
192cdf0e10cSrcweir 
193cdf0e10cSrcweir 				if(m_pDocHolder->isActive())
194cdf0e10cSrcweir 					return NOERROR; //Already active
195cdf0e10cSrcweir 
196cdf0e10cSrcweir 				if(SUCCEEDED(
197cdf0e10cSrcweir 					m_pDocHolder->InPlaceActivate(
198cdf0e10cSrcweir 						pActiveSite,TRUE)))
199cdf0e10cSrcweir 					return NOERROR;
200cdf0e10cSrcweir 
201cdf0e10cSrcweir 				// intended fall trough
202cdf0e10cSrcweir 			case OLEIVERB_OPEN:
203cdf0e10cSrcweir 				OSL_ENSURE(m_pDocHolder,"no document to open");
204cdf0e10cSrcweir 
205cdf0e10cSrcweir 				// the commented code could be usefull in case
206cdf0e10cSrcweir 				// outer window would be resized depending from inner one
207cdf0e10cSrcweir 				// RECTL aEmbArea;
208cdf0e10cSrcweir 				// m_pDocHolder->GetVisArea( &aEmbArea );
209cdf0e10cSrcweir 				// m_pDocHolder->show();
210cdf0e10cSrcweir 				// m_pDocHolder->SetVisArea( &aEmbArea );
211cdf0e10cSrcweir 
212cdf0e10cSrcweir 				if(m_pDocHolder->isActive())
213cdf0e10cSrcweir 				{
214cdf0e10cSrcweir 					m_pDocHolder->InPlaceDeactivate();
215cdf0e10cSrcweir 					m_pDocHolder->DisableInplaceActivation(true);
216cdf0e10cSrcweir 				}
217cdf0e10cSrcweir 
218cdf0e10cSrcweir 				SIZEL aEmbSize;
219cdf0e10cSrcweir 				m_pDocHolder->GetExtent( &aEmbSize );
220cdf0e10cSrcweir 				m_pDocHolder->show();
221cdf0e10cSrcweir 				m_pDocHolder->resizeWin( aEmbSize );
222cdf0e10cSrcweir 
223cdf0e10cSrcweir 				if ( m_pClientSite )
224cdf0e10cSrcweir 					m_pClientSite->OnShowWindow( TRUE );
225cdf0e10cSrcweir 
226cdf0e10cSrcweir 				notify();
227cdf0e10cSrcweir 				break;
228cdf0e10cSrcweir 			case OLEIVERB_HIDE:
229cdf0e10cSrcweir 				OSL_ENSURE(m_pDocHolder,"no document to hide");
230cdf0e10cSrcweir 
231cdf0e10cSrcweir 				if(m_pDocHolder->isActive())
232cdf0e10cSrcweir 					m_pDocHolder->InPlaceDeactivate();
233cdf0e10cSrcweir 				else {
234cdf0e10cSrcweir 					m_pDocHolder->hide();
235cdf0e10cSrcweir 
236cdf0e10cSrcweir 					if( m_pClientSite )
237cdf0e10cSrcweir 						m_pClientSite->OnShowWindow(FALSE);
238cdf0e10cSrcweir 				}
239cdf0e10cSrcweir 				break;
240cdf0e10cSrcweir 			default:
241cdf0e10cSrcweir 				break;
242cdf0e10cSrcweir 		}
243cdf0e10cSrcweir 	}
244cdf0e10cSrcweir 	catch( uno::Exception& )
245cdf0e10cSrcweir 	{
246cdf0e10cSrcweir 		return OLEOBJ_S_CANNOT_DOVERB_NOW;
247cdf0e10cSrcweir 	}
248cdf0e10cSrcweir 
249cdf0e10cSrcweir 	return NOERROR;
250cdf0e10cSrcweir }
251cdf0e10cSrcweir 
252cdf0e10cSrcweir 
253cdf0e10cSrcweir 
EnumVerbs(IEnumOLEVERB **)254cdf0e10cSrcweir STDMETHODIMP EmbedDocument_Impl::EnumVerbs( IEnumOLEVERB ** /*ppEnumOleVerb*/ )
255cdf0e10cSrcweir {
256cdf0e10cSrcweir     return OLE_S_USEREG;
257cdf0e10cSrcweir }
258cdf0e10cSrcweir 
Update()259cdf0e10cSrcweir STDMETHODIMP EmbedDocument_Impl::Update()
260cdf0e10cSrcweir {
261cdf0e10cSrcweir     return S_OK;
262cdf0e10cSrcweir //    HRESULT hr = CACHE_E_NOCACHE_UPDATED;
263cdf0e10cSrcweir //    return hr;
264cdf0e10cSrcweir }
265cdf0e10cSrcweir 
IsUpToDate()266cdf0e10cSrcweir STDMETHODIMP EmbedDocument_Impl::IsUpToDate()
267cdf0e10cSrcweir {
268cdf0e10cSrcweir     return S_OK;
269cdf0e10cSrcweir }
270cdf0e10cSrcweir 
GetUserClassID(CLSID * pClsid)271cdf0e10cSrcweir STDMETHODIMP EmbedDocument_Impl::GetUserClassID( CLSID *pClsid )
272cdf0e10cSrcweir {
273cdf0e10cSrcweir     return GetClassID( pClsid );
274cdf0e10cSrcweir }
275cdf0e10cSrcweir 
GetUserType(DWORD,LPOLESTR *)276cdf0e10cSrcweir STDMETHODIMP EmbedDocument_Impl::GetUserType( DWORD /*dwFormOfTypeUe*/, LPOLESTR * /*pszUserType*/ )
277cdf0e10cSrcweir {
278cdf0e10cSrcweir     return OLE_S_USEREG;
279cdf0e10cSrcweir }
280cdf0e10cSrcweir 
SetExtent(DWORD,SIZEL * psizel)281cdf0e10cSrcweir STDMETHODIMP EmbedDocument_Impl::SetExtent( DWORD /*dwDrawAspect*/, SIZEL *psizel )
282cdf0e10cSrcweir {
283cdf0e10cSrcweir     if ( !psizel )
284cdf0e10cSrcweir         return E_FAIL;
285cdf0e10cSrcweir 
286cdf0e10cSrcweir     m_pDocHolder->SetExtent( psizel );
287cdf0e10cSrcweir 
288cdf0e10cSrcweir     return S_OK;
289cdf0e10cSrcweir }
290cdf0e10cSrcweir 
GetExtent(DWORD,SIZEL * psizel)291cdf0e10cSrcweir STDMETHODIMP EmbedDocument_Impl::GetExtent( DWORD /*dwDrawAspect*/, SIZEL * psizel )
292cdf0e10cSrcweir {
293cdf0e10cSrcweir     if ( !psizel )
294cdf0e10cSrcweir         return E_INVALIDARG;
295cdf0e10cSrcweir 
296cdf0e10cSrcweir     if ( FAILED( m_pDocHolder->GetExtent( psizel ) ) )
297cdf0e10cSrcweir     {
298cdf0e10cSrcweir         // return default values
299cdf0e10cSrcweir         psizel->cx = 500;
300cdf0e10cSrcweir         psizel->cy = 500;
301cdf0e10cSrcweir     }
302cdf0e10cSrcweir 
303cdf0e10cSrcweir     return S_OK;
304cdf0e10cSrcweir }
305cdf0e10cSrcweir 
Advise(IAdviseSink * pAdvSink,DWORD * pdwConnection)306cdf0e10cSrcweir STDMETHODIMP EmbedDocument_Impl::Advise( IAdviseSink *pAdvSink, DWORD *pdwConnection )
307cdf0e10cSrcweir {
308cdf0e10cSrcweir     if ( m_nAdviseNum == 0xFFFFFFFF )
309cdf0e10cSrcweir         return E_OUTOFMEMORY;
310cdf0e10cSrcweir 
311cdf0e10cSrcweir     pAdvSink->AddRef();
312cdf0e10cSrcweir     m_aAdviseHashMap.insert( ::std::pair< DWORD, IAdviseSink* >( m_nAdviseNum, pAdvSink ) );
313cdf0e10cSrcweir     *pdwConnection = m_nAdviseNum++;
314cdf0e10cSrcweir 
315cdf0e10cSrcweir     return S_OK;
316cdf0e10cSrcweir }
317cdf0e10cSrcweir 
Unadvise(DWORD dwConnection)318cdf0e10cSrcweir STDMETHODIMP EmbedDocument_Impl::Unadvise( DWORD dwConnection )
319cdf0e10cSrcweir {
320cdf0e10cSrcweir 	AdviseSinkHashMapIterator iAdvise = m_aAdviseHashMap.find( dwConnection );
321cdf0e10cSrcweir 	if ( iAdvise != m_aAdviseHashMap.end() )
322cdf0e10cSrcweir 	{
323cdf0e10cSrcweir 		iAdvise->second->Release();
324cdf0e10cSrcweir 		m_aAdviseHashMap.erase( iAdvise );
325cdf0e10cSrcweir 	}
326cdf0e10cSrcweir 	else
327cdf0e10cSrcweir 		return OLE_E_NOCONNECTION;
328cdf0e10cSrcweir 
329cdf0e10cSrcweir 	return S_OK;
330cdf0e10cSrcweir }
331cdf0e10cSrcweir 
EnumAdvise(IEnumSTATDATA **)332cdf0e10cSrcweir STDMETHODIMP EmbedDocument_Impl::EnumAdvise( IEnumSTATDATA ** /*ppenumAdvise*/ )
333cdf0e10cSrcweir {
334cdf0e10cSrcweir 	return E_NOTIMPL;
335cdf0e10cSrcweir }
336cdf0e10cSrcweir 
GetMiscStatus(DWORD,DWORD *)337cdf0e10cSrcweir STDMETHODIMP EmbedDocument_Impl::GetMiscStatus( DWORD /*dwAspect*/, DWORD * /*pdwStatus*/ )
338cdf0e10cSrcweir {
339cdf0e10cSrcweir 	return OLE_S_USEREG;
340cdf0e10cSrcweir }
341cdf0e10cSrcweir 
SetColorScheme(LOGPALETTE *)342cdf0e10cSrcweir STDMETHODIMP EmbedDocument_Impl::SetColorScheme( LOGPALETTE * /*pLogpal*/ )
343cdf0e10cSrcweir {
344cdf0e10cSrcweir 	return E_NOTIMPL;
345cdf0e10cSrcweir }
346cdf0e10cSrcweir 
347cdf0e10cSrcweir //-------------------------------------------------------------------------------
348cdf0e10cSrcweir // IDispatch
349cdf0e10cSrcweir 
GetTypeInfoCount(unsigned int FAR * pctinfo)350cdf0e10cSrcweir STDMETHODIMP EmbedDocument_Impl::GetTypeInfoCount( unsigned int FAR*  pctinfo )
351cdf0e10cSrcweir {
352cdf0e10cSrcweir 	if ( m_pDocHolder->GetIDispatch() )
353cdf0e10cSrcweir 		return m_pDocHolder->GetIDispatch()->GetTypeInfoCount( pctinfo );
354cdf0e10cSrcweir 
355cdf0e10cSrcweir 	return E_NOTIMPL;
356cdf0e10cSrcweir }
357cdf0e10cSrcweir 
GetTypeInfo(unsigned int iTInfo,LCID lcid,ITypeInfo FAR * FAR * ppTInfo)358cdf0e10cSrcweir STDMETHODIMP EmbedDocument_Impl::GetTypeInfo( unsigned int iTInfo, LCID lcid, ITypeInfo FAR* FAR* ppTInfo )
359cdf0e10cSrcweir {
360cdf0e10cSrcweir 	if ( m_pDocHolder->GetIDispatch() )
361cdf0e10cSrcweir 		return m_pDocHolder->GetIDispatch()->GetTypeInfo( iTInfo, lcid, ppTInfo );
362cdf0e10cSrcweir 
363cdf0e10cSrcweir 	return DISP_E_BADINDEX; // the only error that can be returned
364cdf0e10cSrcweir }
365cdf0e10cSrcweir 
GetIDsOfNames(REFIID riid,OLECHAR FAR * FAR * rgszNames,unsigned int cNames,LCID lcid,DISPID FAR * rgDispId)366cdf0e10cSrcweir STDMETHODIMP EmbedDocument_Impl::GetIDsOfNames( REFIID riid,
367cdf0e10cSrcweir 												OLECHAR FAR* FAR* rgszNames,
368cdf0e10cSrcweir 												unsigned int cNames,
369cdf0e10cSrcweir 												LCID lcid,
370cdf0e10cSrcweir 												DISPID FAR* rgDispId )
371cdf0e10cSrcweir {
372cdf0e10cSrcweir 	if ( m_pDocHolder->GetIDispatch() )
373cdf0e10cSrcweir 		return m_pDocHolder->GetIDispatch()->GetIDsOfNames( riid, rgszNames, cNames, lcid, rgDispId );
374cdf0e10cSrcweir 
375cdf0e10cSrcweir 	for ( unsigned int ind = 0; ind < cNames; ind++ )
376cdf0e10cSrcweir 		rgDispId[ind] = DISPID_UNKNOWN;
377cdf0e10cSrcweir 
378cdf0e10cSrcweir 	return DISP_E_UNKNOWNNAME;
379cdf0e10cSrcweir }
380cdf0e10cSrcweir 
Invoke(DISPID dispIdMember,REFIID riid,LCID lcid,WORD wFlags,DISPPARAMS FAR * pDispParams,VARIANT FAR * pVarResult,EXCEPINFO FAR * pExcepInfo,unsigned int FAR * puArgErr)381cdf0e10cSrcweir STDMETHODIMP EmbedDocument_Impl::Invoke( DISPID dispIdMember,
382cdf0e10cSrcweir 										 REFIID riid,
383cdf0e10cSrcweir 										 LCID lcid,
384cdf0e10cSrcweir 										 WORD wFlags,
385cdf0e10cSrcweir 										 DISPPARAMS FAR* pDispParams,
386cdf0e10cSrcweir 										 VARIANT FAR* pVarResult,
387cdf0e10cSrcweir 										 EXCEPINFO FAR* pExcepInfo,
388cdf0e10cSrcweir 										 unsigned int FAR* puArgErr )
389cdf0e10cSrcweir {
390cdf0e10cSrcweir 	if ( m_pDocHolder->GetIDispatch() )
391cdf0e10cSrcweir 		return m_pDocHolder->GetIDispatch()->Invoke( dispIdMember,
392cdf0e10cSrcweir 													 riid,
393cdf0e10cSrcweir 													 lcid,
394cdf0e10cSrcweir 													 wFlags,
395cdf0e10cSrcweir 													 pDispParams,
396cdf0e10cSrcweir 													 pVarResult,
397cdf0e10cSrcweir 													 pExcepInfo,
398cdf0e10cSrcweir 													 puArgErr );
399cdf0e10cSrcweir 
400cdf0e10cSrcweir 	return DISP_E_MEMBERNOTFOUND;
401cdf0e10cSrcweir }
402cdf0e10cSrcweir 
403cdf0e10cSrcweir //-------------------------------------------------------------------------------
404cdf0e10cSrcweir // IExternalConnection
405cdf0e10cSrcweir 
AddConnection(DWORD,DWORD)406cdf0e10cSrcweir DWORD STDMETHODCALLTYPE EmbedDocument_Impl::AddConnection( DWORD , DWORD )
407cdf0e10cSrcweir {
408cdf0e10cSrcweir     return AddRef();
409cdf0e10cSrcweir }
410cdf0e10cSrcweir 
ReleaseConnection(DWORD,DWORD,BOOL)411cdf0e10cSrcweir DWORD STDMETHODCALLTYPE EmbedDocument_Impl::ReleaseConnection( DWORD , DWORD , BOOL )
412cdf0e10cSrcweir {
413cdf0e10cSrcweir     return Release();
414cdf0e10cSrcweir }
415cdf0e10cSrcweir 
416cdf0e10cSrcweir // C++ - methods
417cdf0e10cSrcweir 
SaveObject()418cdf0e10cSrcweir HRESULT EmbedDocument_Impl::SaveObject()
419cdf0e10cSrcweir {
420cdf0e10cSrcweir 	HRESULT hr = S_OK;
421cdf0e10cSrcweir 
422cdf0e10cSrcweir 	if(m_pClientSite) {
423cdf0e10cSrcweir 		hr = m_pClientSite->SaveObject();
424cdf0e10cSrcweir 
425cdf0e10cSrcweir 		for ( AdviseSinkHashMapIterator iAdvise =
426cdf0e10cSrcweir 				  m_aAdviseHashMap.begin();
427cdf0e10cSrcweir 			  iAdvise != m_aAdviseHashMap.end();
428cdf0e10cSrcweir 			  iAdvise++ )
429cdf0e10cSrcweir 			if ( iAdvise->second )
430cdf0e10cSrcweir 				iAdvise->second->OnSave( );
431cdf0e10cSrcweir 	}
432cdf0e10cSrcweir 	else if ( m_aFileName.getLength() && IsDirty() == S_OK )
433cdf0e10cSrcweir 	{
434cdf0e10cSrcweir 		::rtl::OUString aPreservFileName = m_aFileName;
435cdf0e10cSrcweir 
436cdf0e10cSrcweir 		// in case of links the containers does not provide client site sometimes
437cdf0e10cSrcweir 		hr = Save( (LPCOLESTR)NULL, FALSE ); // triggers saving to the link location
438cdf0e10cSrcweir 		SaveCompleted( (LPCOLESTR)aPreservFileName.getStr() );
439cdf0e10cSrcweir 	}
440cdf0e10cSrcweir 
441cdf0e10cSrcweir     notify( false );
442cdf0e10cSrcweir 
443cdf0e10cSrcweir 	return hr;
444cdf0e10cSrcweir }
445cdf0e10cSrcweir 
446cdf0e10cSrcweir 
ShowObject()447cdf0e10cSrcweir HRESULT EmbedDocument_Impl::ShowObject()
448cdf0e10cSrcweir {
449cdf0e10cSrcweir 	HRESULT hr = S_OK;
450cdf0e10cSrcweir 
451cdf0e10cSrcweir 	if(m_pClientSite)
452cdf0e10cSrcweir 		hr = m_pClientSite->ShowObject();
453cdf0e10cSrcweir 
454cdf0e10cSrcweir 	return hr;
455cdf0e10cSrcweir }
456cdf0e10cSrcweir 
457cdf0e10cSrcweir 
notify(bool bDataChanged)458cdf0e10cSrcweir void EmbedDocument_Impl::notify( bool bDataChanged )
459cdf0e10cSrcweir {
460cdf0e10cSrcweir 	for ( AdviseSinkHashMapIterator iAdvise =
461cdf0e10cSrcweir 			  m_aAdviseHashMap.begin();
462cdf0e10cSrcweir 		  iAdvise != m_aAdviseHashMap.end();
463cdf0e10cSrcweir 		  iAdvise++ )
464cdf0e10cSrcweir 		if ( iAdvise->second )
465cdf0e10cSrcweir 			iAdvise->second->OnViewChange( DVASPECT_CONTENT, -1 );
466cdf0e10cSrcweir 
467cdf0e10cSrcweir     if ( m_pDAdviseHolder && bDataChanged )
468cdf0e10cSrcweir 		m_pDAdviseHolder->SendOnDataChange( (IDataObject*)this, 0, 0 );
469cdf0e10cSrcweir }
470cdf0e10cSrcweir 
Deactivate()471cdf0e10cSrcweir void EmbedDocument_Impl::Deactivate()
472cdf0e10cSrcweir {
473cdf0e10cSrcweir     HRESULT hr = S_OK;
474cdf0e10cSrcweir 
475cdf0e10cSrcweir     if ( m_pDocHolder->HasFrame() )
476cdf0e10cSrcweir     {
477cdf0e10cSrcweir 	    hr = SaveObject();
478cdf0e10cSrcweir 	    m_pDocHolder->CloseFrame();
479cdf0e10cSrcweir 	    OLENotifyDeactivation();
480cdf0e10cSrcweir     }
481cdf0e10cSrcweir }
482cdf0e10cSrcweir 
OLENotifyDeactivation()483cdf0e10cSrcweir HRESULT EmbedDocument_Impl::OLENotifyDeactivation()
484cdf0e10cSrcweir {
485cdf0e10cSrcweir 	HRESULT hr = S_OK;
486cdf0e10cSrcweir 
487cdf0e10cSrcweir 	if ( m_pClientSite )
488cdf0e10cSrcweir 		hr = m_pClientSite->OnShowWindow( FALSE );
489cdf0e10cSrcweir 
490cdf0e10cSrcweir 	return hr;
491cdf0e10cSrcweir 
492cdf0e10cSrcweir }
493cdf0e10cSrcweir 
494cdf0e10cSrcweir // Fix strange warnings about some
495cdf0e10cSrcweir // ATL::CAxHostWindow::QueryInterface|AddRef|Releae functions.
496cdf0e10cSrcweir // warning C4505: 'xxx' : unreferenced local function has been removed
497cdf0e10cSrcweir #if defined(_MSC_VER)
498cdf0e10cSrcweir #pragma warning(disable: 4505)
499cdf0e10cSrcweir #endif
500cdf0e10cSrcweir 
501