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 #include <cppuhelper/weak.hxx>
24cdf0e10cSrcweir 
25cdf0e10cSrcweir #include <embeddoc.hxx>
26cdf0e10cSrcweir #include <docholder.hxx>
27cdf0e10cSrcweir #include <intercept.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir using namespace ::com::sun::star;
30cdf0e10cSrcweir 
31cdf0e10cSrcweir 
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #define IUL 6
34cdf0e10cSrcweir 
35cdf0e10cSrcweir 
36cdf0e10cSrcweir 
37cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > Interceptor::m_aInterceptedURL(IUL);
38cdf0e10cSrcweir 
39cdf0e10cSrcweir 
40cdf0e10cSrcweir 
41cdf0e10cSrcweir 
42cdf0e10cSrcweir struct equalOUString
43cdf0e10cSrcweir {
operator ()equalOUString44cdf0e10cSrcweir 	bool operator()(
45cdf0e10cSrcweir 		const rtl::OUString& rKey1,
46cdf0e10cSrcweir 		const rtl::OUString& rKey2 ) const
47cdf0e10cSrcweir 	{
48cdf0e10cSrcweir 		return !!( rKey1 == rKey2 );
49cdf0e10cSrcweir 	}
50cdf0e10cSrcweir };
51cdf0e10cSrcweir 
52cdf0e10cSrcweir 
53cdf0e10cSrcweir struct hashOUString
54cdf0e10cSrcweir {
operator ()hashOUString55cdf0e10cSrcweir 	size_t operator()( const rtl::OUString& rName ) const
56cdf0e10cSrcweir 	{
57cdf0e10cSrcweir 		return rName.hashCode();
58cdf0e10cSrcweir 	}
59cdf0e10cSrcweir };
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 
63cdf0e10cSrcweir class StatusChangeListenerContainer
64cdf0e10cSrcweir 	: public ::cppu::OMultiTypeInterfaceContainerHelperVar<
65cdf0e10cSrcweir rtl::OUString,hashOUString,equalOUString>
66cdf0e10cSrcweir {
67cdf0e10cSrcweir public:
StatusChangeListenerContainer(::osl::Mutex & aMutex)68cdf0e10cSrcweir 	StatusChangeListenerContainer( ::osl::Mutex& aMutex )
69cdf0e10cSrcweir 		:  cppu::OMultiTypeInterfaceContainerHelperVar<
70cdf0e10cSrcweir 	rtl::OUString,hashOUString,equalOUString>(aMutex)
71cdf0e10cSrcweir 	{
72cdf0e10cSrcweir 	}
73cdf0e10cSrcweir };
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 
76cdf0e10cSrcweir void SAL_CALL
addEventListener(const uno::Reference<lang::XEventListener> & Listener)77cdf0e10cSrcweir Interceptor::addEventListener(
78cdf0e10cSrcweir 	const uno::Reference<lang::XEventListener >& Listener )
79cdf0e10cSrcweir 	throw( uno::RuntimeException )
80cdf0e10cSrcweir {
81cdf0e10cSrcweir 	osl::MutexGuard aGuard( m_aMutex );
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 	if ( ! m_pDisposeEventListeners )
84cdf0e10cSrcweir 		m_pDisposeEventListeners =
85cdf0e10cSrcweir 			new cppu::OInterfaceContainerHelper( m_aMutex );
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 	m_pDisposeEventListeners->addInterface( Listener );
88cdf0e10cSrcweir }
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 
91cdf0e10cSrcweir void SAL_CALL
removeEventListener(const uno::Reference<lang::XEventListener> & Listener)92cdf0e10cSrcweir Interceptor::removeEventListener(
93cdf0e10cSrcweir 	const uno::Reference< lang::XEventListener >& Listener )
94cdf0e10cSrcweir 	throw( uno::RuntimeException )
95cdf0e10cSrcweir {
96cdf0e10cSrcweir 	osl::MutexGuard aGuard( m_aMutex );
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 	if ( m_pDisposeEventListeners )
99cdf0e10cSrcweir 		m_pDisposeEventListeners->removeInterface( Listener );
100cdf0e10cSrcweir }
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 
dispose()103cdf0e10cSrcweir void SAL_CALL Interceptor::dispose()
104cdf0e10cSrcweir 	throw(::com::sun::star::uno::RuntimeException)
105cdf0e10cSrcweir {
106cdf0e10cSrcweir 	lang::EventObject aEvt;
107cdf0e10cSrcweir 	aEvt.Source = static_cast< frame::XDispatch* >( this );
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 	osl::MutexGuard aGuard(m_aMutex);
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 	if ( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() )
112cdf0e10cSrcweir 		m_pDisposeEventListeners->disposeAndClear( aEvt );
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 	if(m_pStatCL)
115cdf0e10cSrcweir 		m_pStatCL->disposeAndClear( aEvt );
116cdf0e10cSrcweir 
117cdf0e10cSrcweir 	m_xSlaveDispatchProvider = 0;
118cdf0e10cSrcweir 	m_xMasterDispatchProvider = 0;
119cdf0e10cSrcweir }
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 
Interceptor(const::rtl::Reference<EmbeddedDocumentInstanceAccess_Impl> & xOleAccess,DocumentHolder * pDocH,sal_Bool bLink)123cdf0e10cSrcweir Interceptor::Interceptor(
124cdf0e10cSrcweir 	const ::rtl::Reference< EmbeddedDocumentInstanceAccess_Impl >& xOleAccess,
125cdf0e10cSrcweir 	DocumentHolder* pDocH,
126cdf0e10cSrcweir 	sal_Bool bLink )
127cdf0e10cSrcweir 	: m_xOleAccess( xOleAccess ),
128cdf0e10cSrcweir 	  m_xDocHLocker( static_cast< ::cppu::OWeakObject* >( pDocH ) ),
129cdf0e10cSrcweir 	  m_pDocH(pDocH),
130cdf0e10cSrcweir 	  m_pStatCL(0),
131cdf0e10cSrcweir 	  m_pDisposeEventListeners(0),
132cdf0e10cSrcweir 	  m_bLink( bLink )
133cdf0e10cSrcweir {
134cdf0e10cSrcweir 	m_aInterceptedURL[0] = rtl::OUString(
135cdf0e10cSrcweir 		RTL_CONSTASCII_USTRINGPARAM(".uno:Save"));
136cdf0e10cSrcweir 	m_aInterceptedURL[1] = rtl::OUString(
137cdf0e10cSrcweir 		RTL_CONSTASCII_USTRINGPARAM(".uno:SaveAll"));
138cdf0e10cSrcweir 	m_aInterceptedURL[2] = rtl::OUString(
139cdf0e10cSrcweir 		RTL_CONSTASCII_USTRINGPARAM(".uno:CloseDoc"));
140cdf0e10cSrcweir 	m_aInterceptedURL[3] = rtl::OUString(
141cdf0e10cSrcweir 		RTL_CONSTASCII_USTRINGPARAM(".uno:CloseWin"));
142cdf0e10cSrcweir 	m_aInterceptedURL[4] = rtl::OUString(
143cdf0e10cSrcweir 		RTL_CONSTASCII_USTRINGPARAM(".uno:CloseFrame"));
144cdf0e10cSrcweir 	m_aInterceptedURL[5] = rtl::OUString(
145cdf0e10cSrcweir 		RTL_CONSTASCII_USTRINGPARAM(".uno:SaveAs"));
146cdf0e10cSrcweir }
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 
~Interceptor()149cdf0e10cSrcweir Interceptor::~Interceptor()
150cdf0e10cSrcweir {
151cdf0e10cSrcweir 	if( m_pDisposeEventListeners )
152cdf0e10cSrcweir 		delete m_pDisposeEventListeners;
153cdf0e10cSrcweir 
154cdf0e10cSrcweir 	if(m_pStatCL)
155cdf0e10cSrcweir 		delete m_pStatCL;
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 	DocumentHolder* pTmpDocH = NULL;
158cdf0e10cSrcweir 	uno::Reference< uno::XInterface > xLock;
159cdf0e10cSrcweir 	{
160cdf0e10cSrcweir 		osl::MutexGuard aGuard(m_aMutex);
161cdf0e10cSrcweir 		xLock = m_xDocHLocker.get();
162cdf0e10cSrcweir 		if ( xLock.is() )
163cdf0e10cSrcweir 			pTmpDocH = m_pDocH;
164cdf0e10cSrcweir 	}
165cdf0e10cSrcweir 
166cdf0e10cSrcweir 	if ( pTmpDocH )
167cdf0e10cSrcweir 		pTmpDocH->ClearInterceptor();
168cdf0e10cSrcweir }
169cdf0e10cSrcweir 
DisconnectDocHolder()170cdf0e10cSrcweir void Interceptor::DisconnectDocHolder()
171cdf0e10cSrcweir {
172cdf0e10cSrcweir 	osl::MutexGuard aGuard(m_aMutex);
173cdf0e10cSrcweir 	m_xDocHLocker.clear();
174cdf0e10cSrcweir 	m_pDocH = NULL;
175cdf0e10cSrcweir 	m_xOleAccess = NULL;
176cdf0e10cSrcweir }
177cdf0e10cSrcweir 
178cdf0e10cSrcweir //XDispatch
179cdf0e10cSrcweir void SAL_CALL
dispatch(const util::URL & URL,const uno::Sequence<beans::PropertyValue> & Arguments)180cdf0e10cSrcweir Interceptor::dispatch(
181cdf0e10cSrcweir 	const util::URL& URL,
182cdf0e10cSrcweir 	const uno::Sequence<
183cdf0e10cSrcweir 	beans::PropertyValue >& Arguments )
184cdf0e10cSrcweir 	throw (uno::RuntimeException)
185cdf0e10cSrcweir {
186cdf0e10cSrcweir 	::rtl::Reference< EmbeddedDocumentInstanceAccess_Impl > xOleAccess;
187cdf0e10cSrcweir 	{
188cdf0e10cSrcweir 		osl::MutexGuard aGuard(m_aMutex);
189cdf0e10cSrcweir 		xOleAccess = m_xOleAccess;
190cdf0e10cSrcweir 	}
191cdf0e10cSrcweir 
192cdf0e10cSrcweir 	if ( xOleAccess.is() )
193cdf0e10cSrcweir 	{
194cdf0e10cSrcweir 		LockedEmbedDocument_Impl aDocLock = xOleAccess->GetEmbedDocument();
195cdf0e10cSrcweir 		if ( aDocLock.GetEmbedDocument() )
196cdf0e10cSrcweir 		{
197cdf0e10cSrcweir             if( !m_bLink && URL.Complete == m_aInterceptedURL[0])
198cdf0e10cSrcweir                 aDocLock.GetEmbedDocument()->SaveObject();
199cdf0e10cSrcweir             else if(!m_bLink
200cdf0e10cSrcweir                  && ( URL.Complete == m_aInterceptedURL[2] ||
201cdf0e10cSrcweir                       URL.Complete == m_aInterceptedURL[3] ||
202cdf0e10cSrcweir                       URL.Complete == m_aInterceptedURL[4] ) )
203cdf0e10cSrcweir                 aDocLock.GetEmbedDocument()->Close( 0 );
204cdf0e10cSrcweir 			else if ( URL.Complete == m_aInterceptedURL[5] )
205cdf0e10cSrcweir 			{
206cdf0e10cSrcweir 				uno::Sequence< beans::PropertyValue > aNewArgs = Arguments;
207cdf0e10cSrcweir 				sal_Int32 nInd = 0;
208cdf0e10cSrcweir 
209cdf0e10cSrcweir 				while( nInd < aNewArgs.getLength() )
210cdf0e10cSrcweir 				{
211cdf0e10cSrcweir 					if ( aNewArgs[nInd].Name.equalsAscii( "SaveTo" ) )
212cdf0e10cSrcweir 					{
213cdf0e10cSrcweir 						aNewArgs[nInd].Value <<= sal_True;
214cdf0e10cSrcweir 						break;
215cdf0e10cSrcweir 					}
216cdf0e10cSrcweir 					nInd++;
217cdf0e10cSrcweir 				}
218cdf0e10cSrcweir 
219cdf0e10cSrcweir 				if ( nInd == aNewArgs.getLength() )
220cdf0e10cSrcweir 				{
221cdf0e10cSrcweir 					aNewArgs.realloc( nInd + 1 );
222cdf0e10cSrcweir 					aNewArgs[nInd].Name = ::rtl::OUString::createFromAscii( "SaveTo" );
223cdf0e10cSrcweir 					aNewArgs[nInd].Value <<= sal_True;
224cdf0e10cSrcweir 				}
225cdf0e10cSrcweir 
226cdf0e10cSrcweir 				uno::Reference< frame::XDispatch > xDispatch = m_xSlaveDispatchProvider->queryDispatch(
227cdf0e10cSrcweir 					URL, ::rtl::OUString::createFromAscii( "_self" ), 0 );
228cdf0e10cSrcweir 				if ( xDispatch.is() )
229cdf0e10cSrcweir 					xDispatch->dispatch( URL, aNewArgs );
230cdf0e10cSrcweir 			}
231cdf0e10cSrcweir 		}
232cdf0e10cSrcweir 	}
233cdf0e10cSrcweir }
234cdf0e10cSrcweir 
235cdf0e10cSrcweir 
generateFeatureStateEvent()236cdf0e10cSrcweir void Interceptor::generateFeatureStateEvent()
237cdf0e10cSrcweir {
238cdf0e10cSrcweir 	if( m_pStatCL )
239cdf0e10cSrcweir 	{
240cdf0e10cSrcweir 		DocumentHolder* pTmpDocH = NULL;
241cdf0e10cSrcweir 		uno::Reference< uno::XInterface > xLock;
242cdf0e10cSrcweir 		{
243cdf0e10cSrcweir 			osl::MutexGuard aGuard(m_aMutex);
244cdf0e10cSrcweir 			xLock = m_xDocHLocker.get();
245cdf0e10cSrcweir 			if ( xLock.is() )
246cdf0e10cSrcweir 				pTmpDocH = m_pDocH;
247cdf0e10cSrcweir 		}
248cdf0e10cSrcweir 
249cdf0e10cSrcweir 		::rtl::OUString aTitle;
250cdf0e10cSrcweir 		if ( pTmpDocH )
251cdf0e10cSrcweir 			aTitle = pTmpDocH->getTitle();
252cdf0e10cSrcweir 
253cdf0e10cSrcweir 		for(int i = 0; i < IUL; ++i)
254cdf0e10cSrcweir 		{
255cdf0e10cSrcweir 			if( i == 1 || m_bLink && i != 5 )
256cdf0e10cSrcweir 				continue;
257cdf0e10cSrcweir 
258cdf0e10cSrcweir 			cppu::OInterfaceContainerHelper* pICH =
259cdf0e10cSrcweir 				m_pStatCL->getContainer(m_aInterceptedURL[i]);
260cdf0e10cSrcweir 			uno::Sequence<uno::Reference<uno::XInterface> > aSeq;
261cdf0e10cSrcweir 			if(pICH)
262cdf0e10cSrcweir 				aSeq = pICH->getElements();
263cdf0e10cSrcweir 			if(!aSeq.getLength())
264cdf0e10cSrcweir 				continue;
265cdf0e10cSrcweir 
266cdf0e10cSrcweir 			frame::FeatureStateEvent aStateEvent;
267cdf0e10cSrcweir 			aStateEvent.IsEnabled = sal_True;
268cdf0e10cSrcweir 			aStateEvent.Requery = sal_False;
269cdf0e10cSrcweir 			if(i == 0)
270cdf0e10cSrcweir 			{
271cdf0e10cSrcweir 
272cdf0e10cSrcweir 				aStateEvent.FeatureURL.Complete = m_aInterceptedURL[0];
273cdf0e10cSrcweir 				aStateEvent.FeatureDescriptor = rtl::OUString(
274cdf0e10cSrcweir 					RTL_CONSTASCII_USTRINGPARAM("Update"));
275cdf0e10cSrcweir 				aStateEvent.State <<= (rtl::OUString(
276cdf0e10cSrcweir 					RTL_CONSTASCII_USTRINGPARAM("($1) ")) +
277cdf0e10cSrcweir 									   aTitle);
278cdf0e10cSrcweir 
279cdf0e10cSrcweir 			}
280cdf0e10cSrcweir 			else if ( i == 5 )
281cdf0e10cSrcweir 			{
282cdf0e10cSrcweir 				aStateEvent.FeatureURL.Complete = m_aInterceptedURL[5];
283cdf0e10cSrcweir 				aStateEvent.FeatureDescriptor = rtl::OUString(
284cdf0e10cSrcweir 					RTL_CONSTASCII_USTRINGPARAM("SaveCopyTo"));
285cdf0e10cSrcweir 				aStateEvent.State <<= (rtl::OUString(
286cdf0e10cSrcweir 					RTL_CONSTASCII_USTRINGPARAM("($3)")));
287cdf0e10cSrcweir 			}
288cdf0e10cSrcweir 			else
289cdf0e10cSrcweir 			{
290cdf0e10cSrcweir 				aStateEvent.FeatureURL.Complete = m_aInterceptedURL[i];
291cdf0e10cSrcweir 				aStateEvent.FeatureDescriptor = rtl::OUString(
292cdf0e10cSrcweir 					RTL_CONSTASCII_USTRINGPARAM("Close and Return"));
293cdf0e10cSrcweir 				aStateEvent.State <<= (rtl::OUString(
294cdf0e10cSrcweir 					RTL_CONSTASCII_USTRINGPARAM("($2) ")) +
295cdf0e10cSrcweir 									   aTitle);
296cdf0e10cSrcweir 
297cdf0e10cSrcweir 			}
298cdf0e10cSrcweir 
299cdf0e10cSrcweir 			for(sal_Int32 k = 0; k < aSeq.getLength(); ++k)
300cdf0e10cSrcweir 			{
301cdf0e10cSrcweir 				uno::Reference<frame::XStatusListener>
302cdf0e10cSrcweir 					Control(aSeq[k],uno::UNO_QUERY);
303cdf0e10cSrcweir 				if(Control.is())
304cdf0e10cSrcweir 					Control->statusChanged(aStateEvent);
305cdf0e10cSrcweir 
306cdf0e10cSrcweir 			}
307cdf0e10cSrcweir 		}
308cdf0e10cSrcweir 	}
309cdf0e10cSrcweir }
310cdf0e10cSrcweir 
311cdf0e10cSrcweir 
312cdf0e10cSrcweir void SAL_CALL
addStatusListener(const uno::Reference<frame::XStatusListener> & Control,const util::URL & URL)313cdf0e10cSrcweir Interceptor::addStatusListener(
314cdf0e10cSrcweir 	const uno::Reference<
315cdf0e10cSrcweir 	frame::XStatusListener >& Control,
316cdf0e10cSrcweir 	const util::URL& URL )
317cdf0e10cSrcweir 	throw (
318cdf0e10cSrcweir 		uno::RuntimeException
319cdf0e10cSrcweir 	)
320cdf0e10cSrcweir {
321cdf0e10cSrcweir 	if(!Control.is())
322cdf0e10cSrcweir 		return;
323cdf0e10cSrcweir 
324cdf0e10cSrcweir 	if( !m_bLink && URL.Complete == m_aInterceptedURL[0] )
325cdf0e10cSrcweir 	{   // Save
326cdf0e10cSrcweir 		DocumentHolder* pTmpDocH = NULL;
327cdf0e10cSrcweir 		uno::Reference< uno::XInterface > xLock;
328cdf0e10cSrcweir 		{
329cdf0e10cSrcweir 			osl::MutexGuard aGuard(m_aMutex);
330cdf0e10cSrcweir 			xLock = m_xDocHLocker.get();
331cdf0e10cSrcweir 			if ( xLock.is() )
332cdf0e10cSrcweir 				pTmpDocH = m_pDocH;
333cdf0e10cSrcweir 		}
334cdf0e10cSrcweir 
335cdf0e10cSrcweir 		::rtl::OUString aTitle;
336cdf0e10cSrcweir 		if ( pTmpDocH )
337cdf0e10cSrcweir 			aTitle = pTmpDocH->getTitle();
338cdf0e10cSrcweir 
339cdf0e10cSrcweir 		frame::FeatureStateEvent aStateEvent;
340cdf0e10cSrcweir 		aStateEvent.FeatureURL.Complete = m_aInterceptedURL[0];
341cdf0e10cSrcweir 		aStateEvent.FeatureDescriptor = rtl::OUString(
342cdf0e10cSrcweir 			RTL_CONSTASCII_USTRINGPARAM("Update"));
343cdf0e10cSrcweir 		aStateEvent.IsEnabled = sal_True;
344cdf0e10cSrcweir 		aStateEvent.Requery = sal_False;
345cdf0e10cSrcweir 		aStateEvent.State <<= (rtl::OUString(
346cdf0e10cSrcweir 			RTL_CONSTASCII_USTRINGPARAM("($1) ")) +
347cdf0e10cSrcweir 							   aTitle );
348cdf0e10cSrcweir 		Control->statusChanged(aStateEvent);
349cdf0e10cSrcweir 
350cdf0e10cSrcweir 		{
351cdf0e10cSrcweir 			osl::MutexGuard aGuard(m_aMutex);
352cdf0e10cSrcweir 			if(!m_pStatCL)
353cdf0e10cSrcweir 				m_pStatCL =
354cdf0e10cSrcweir 					new StatusChangeListenerContainer(m_aMutex);
355cdf0e10cSrcweir 		}
356cdf0e10cSrcweir 
357cdf0e10cSrcweir 		m_pStatCL->addInterface(URL.Complete,Control);
358cdf0e10cSrcweir 		return;
359cdf0e10cSrcweir 	}
360cdf0e10cSrcweir 
361cdf0e10cSrcweir 	sal_Int32 i = 2;
362cdf0e10cSrcweir 	if ( !m_bLink
363cdf0e10cSrcweir 	  && ( URL.Complete == m_aInterceptedURL[i] ||
364cdf0e10cSrcweir 	       URL.Complete == m_aInterceptedURL[++i] ||
365cdf0e10cSrcweir 	       URL.Complete == m_aInterceptedURL[++i] ) )
366cdf0e10cSrcweir 	{   // Close and return
367cdf0e10cSrcweir 		DocumentHolder* pTmpDocH = NULL;
368cdf0e10cSrcweir 		uno::Reference< uno::XInterface > xLock;
369cdf0e10cSrcweir 		{
370cdf0e10cSrcweir 			osl::MutexGuard aGuard(m_aMutex);
371cdf0e10cSrcweir 			xLock = m_xDocHLocker.get();
372cdf0e10cSrcweir 			if ( xLock.is() )
373cdf0e10cSrcweir 				pTmpDocH = m_pDocH;
374cdf0e10cSrcweir 		}
375cdf0e10cSrcweir 
376cdf0e10cSrcweir 		::rtl::OUString aTitle;
377cdf0e10cSrcweir 		if ( pTmpDocH )
378cdf0e10cSrcweir 			aTitle = pTmpDocH->getTitle();
379cdf0e10cSrcweir 
380cdf0e10cSrcweir 		frame::FeatureStateEvent aStateEvent;
381cdf0e10cSrcweir 		aStateEvent.FeatureURL.Complete = m_aInterceptedURL[i];
382cdf0e10cSrcweir 		aStateEvent.FeatureDescriptor = rtl::OUString(
383cdf0e10cSrcweir 			RTL_CONSTASCII_USTRINGPARAM("Close and Return"));
384cdf0e10cSrcweir 		aStateEvent.IsEnabled = sal_True;
385cdf0e10cSrcweir 		aStateEvent.Requery = sal_False;
386cdf0e10cSrcweir 		aStateEvent.State <<= (rtl::OUString(
387cdf0e10cSrcweir 			RTL_CONSTASCII_USTRINGPARAM("($2) ")) +
388cdf0e10cSrcweir 							   aTitle );
389cdf0e10cSrcweir 		Control->statusChanged(aStateEvent);
390cdf0e10cSrcweir 
391cdf0e10cSrcweir 
392cdf0e10cSrcweir 		{
393cdf0e10cSrcweir 			osl::MutexGuard aGuard(m_aMutex);
394cdf0e10cSrcweir 			if(!m_pStatCL)
395cdf0e10cSrcweir 				m_pStatCL =
396cdf0e10cSrcweir 					new StatusChangeListenerContainer(m_aMutex);
397cdf0e10cSrcweir 		}
398cdf0e10cSrcweir 
399cdf0e10cSrcweir 		m_pStatCL->addInterface(URL.Complete,Control);
400cdf0e10cSrcweir 		return;
401cdf0e10cSrcweir 	}
402cdf0e10cSrcweir 
403cdf0e10cSrcweir 	if(URL.Complete == m_aInterceptedURL[5])
404cdf0e10cSrcweir 	{   // SaveAs
405cdf0e10cSrcweir 		frame::FeatureStateEvent aStateEvent;
406cdf0e10cSrcweir 		aStateEvent.FeatureURL.Complete = m_aInterceptedURL[5];
407cdf0e10cSrcweir 		aStateEvent.FeatureDescriptor = rtl::OUString(
408cdf0e10cSrcweir 			RTL_CONSTASCII_USTRINGPARAM("SaveCopyTo"));
409cdf0e10cSrcweir 		aStateEvent.IsEnabled = sal_True;
410cdf0e10cSrcweir 		aStateEvent.Requery = sal_False;
411cdf0e10cSrcweir 		aStateEvent.State <<= (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("($3)")));
412cdf0e10cSrcweir 		Control->statusChanged(aStateEvent);
413cdf0e10cSrcweir 
414cdf0e10cSrcweir 		{
415cdf0e10cSrcweir 			osl::MutexGuard aGuard(m_aMutex);
416cdf0e10cSrcweir 			if(!m_pStatCL)
417cdf0e10cSrcweir 				m_pStatCL =
418cdf0e10cSrcweir 					new StatusChangeListenerContainer(m_aMutex);
419cdf0e10cSrcweir 		}
420cdf0e10cSrcweir 
421cdf0e10cSrcweir 		m_pStatCL->addInterface(URL.Complete,Control);
422cdf0e10cSrcweir 		return;
423cdf0e10cSrcweir 	}
424cdf0e10cSrcweir 
425cdf0e10cSrcweir }
426cdf0e10cSrcweir 
427cdf0e10cSrcweir 
428cdf0e10cSrcweir void SAL_CALL
removeStatusListener(const uno::Reference<frame::XStatusListener> & Control,const util::URL & URL)429cdf0e10cSrcweir Interceptor::removeStatusListener(
430cdf0e10cSrcweir 	const uno::Reference<
431cdf0e10cSrcweir 	frame::XStatusListener >& Control,
432cdf0e10cSrcweir 	const util::URL& URL )
433cdf0e10cSrcweir 	throw (
434cdf0e10cSrcweir 		uno::RuntimeException
435cdf0e10cSrcweir 	)
436cdf0e10cSrcweir {
437cdf0e10cSrcweir 	if(!(Control.is() && m_pStatCL))
438cdf0e10cSrcweir 		return;
439cdf0e10cSrcweir 	else {
440cdf0e10cSrcweir 		m_pStatCL->removeInterface(URL.Complete,Control);
441cdf0e10cSrcweir 		return;
442cdf0e10cSrcweir 	}
443cdf0e10cSrcweir }
444cdf0e10cSrcweir 
445cdf0e10cSrcweir 
446cdf0e10cSrcweir //XInterceptorInfo
447cdf0e10cSrcweir uno::Sequence< ::rtl::OUString >
448cdf0e10cSrcweir SAL_CALL
getInterceptedURLs()449cdf0e10cSrcweir Interceptor::getInterceptedURLs(  )
450cdf0e10cSrcweir 	throw (
451cdf0e10cSrcweir 		uno::RuntimeException
452cdf0e10cSrcweir 	)
453cdf0e10cSrcweir {
454cdf0e10cSrcweir 	// now implemented as update
455cdf0e10cSrcweir 	if ( m_bLink )
456cdf0e10cSrcweir 	{
457cdf0e10cSrcweir 		uno::Sequence< ::rtl::OUString > aResult( 2 );
458cdf0e10cSrcweir 		aResult[0] = m_aInterceptedURL[1];
459cdf0e10cSrcweir 		aResult[1] = m_aInterceptedURL[5];
460cdf0e10cSrcweir 
461cdf0e10cSrcweir 		return aResult;
462cdf0e10cSrcweir 	}
463cdf0e10cSrcweir 
464cdf0e10cSrcweir 	return m_aInterceptedURL;
465cdf0e10cSrcweir }
466cdf0e10cSrcweir 
467cdf0e10cSrcweir 
468cdf0e10cSrcweir // XDispatchProvider
469cdf0e10cSrcweir 
470cdf0e10cSrcweir uno::Reference< frame::XDispatch > SAL_CALL
queryDispatch(const util::URL & URL,const::rtl::OUString & TargetFrameName,sal_Int32 SearchFlags)471cdf0e10cSrcweir Interceptor::queryDispatch(
472cdf0e10cSrcweir 	const util::URL& URL,
473cdf0e10cSrcweir 	const ::rtl::OUString& TargetFrameName,
474cdf0e10cSrcweir 	sal_Int32 SearchFlags )
475cdf0e10cSrcweir 	throw (
476cdf0e10cSrcweir 		uno::RuntimeException
477cdf0e10cSrcweir 	)
478cdf0e10cSrcweir {
479cdf0e10cSrcweir 	osl::MutexGuard aGuard(m_aMutex);
480cdf0e10cSrcweir 	if( !m_bLink && URL.Complete == m_aInterceptedURL[0] )
481cdf0e10cSrcweir 		return (frame::XDispatch*)this;
482cdf0e10cSrcweir 	else if(URL.Complete == m_aInterceptedURL[1])
483cdf0e10cSrcweir 		return (frame::XDispatch*)0   ;
484cdf0e10cSrcweir 	else if( !m_bLink && URL.Complete == m_aInterceptedURL[2] )
485cdf0e10cSrcweir 		return (frame::XDispatch*)this;
486cdf0e10cSrcweir 	else if( !m_bLink && URL.Complete == m_aInterceptedURL[3] )
487cdf0e10cSrcweir 		return (frame::XDispatch*)this;
488cdf0e10cSrcweir 	else if( !m_bLink && URL.Complete == m_aInterceptedURL[4] )
489cdf0e10cSrcweir 		return (frame::XDispatch*)this;
490cdf0e10cSrcweir 	else if(URL.Complete == m_aInterceptedURL[5])
491cdf0e10cSrcweir 		return (frame::XDispatch*)this;
492cdf0e10cSrcweir 	else {
493cdf0e10cSrcweir 		if(m_xSlaveDispatchProvider.is())
494cdf0e10cSrcweir 			return m_xSlaveDispatchProvider->queryDispatch(
495cdf0e10cSrcweir 				URL,TargetFrameName,SearchFlags);
496cdf0e10cSrcweir 		else
497cdf0e10cSrcweir 			return uno::Reference<frame::XDispatch>(0);
498cdf0e10cSrcweir 	}
499cdf0e10cSrcweir }
500cdf0e10cSrcweir 
501cdf0e10cSrcweir uno::Sequence< uno::Reference< frame::XDispatch > > SAL_CALL
queryDispatches(const uno::Sequence<frame::DispatchDescriptor> & Requests)502cdf0e10cSrcweir Interceptor::queryDispatches(
503cdf0e10cSrcweir 	const uno::Sequence<frame::DispatchDescriptor >& Requests )
504cdf0e10cSrcweir 	throw (
505cdf0e10cSrcweir 		uno::RuntimeException
506cdf0e10cSrcweir 	)
507cdf0e10cSrcweir {
508cdf0e10cSrcweir 	uno::Sequence< uno::Reference< frame::XDispatch > > aRet;
509cdf0e10cSrcweir 	osl::MutexGuard aGuard(m_aMutex);
510cdf0e10cSrcweir 	if(m_xSlaveDispatchProvider.is())
511cdf0e10cSrcweir 		aRet = m_xSlaveDispatchProvider->queryDispatches(Requests);
512cdf0e10cSrcweir 	else
513cdf0e10cSrcweir 		aRet.realloc(Requests.getLength());
514cdf0e10cSrcweir 
515cdf0e10cSrcweir 	for(sal_Int32 i = 0; i < Requests.getLength(); ++i)
516cdf0e10cSrcweir 		if ( !m_bLink && m_aInterceptedURL[0] == Requests[i].FeatureURL.Complete )
517cdf0e10cSrcweir 			aRet[i] = (frame::XDispatch*) this;
518cdf0e10cSrcweir 		else if(m_aInterceptedURL[1] == Requests[i].FeatureURL.Complete)
519cdf0e10cSrcweir 			aRet[i] = (frame::XDispatch*) 0;
520cdf0e10cSrcweir 		else if( !m_bLink && m_aInterceptedURL[2] == Requests[i].FeatureURL.Complete )
521cdf0e10cSrcweir 			aRet[i] = (frame::XDispatch*) this;
522cdf0e10cSrcweir 		else if( !m_bLink && m_aInterceptedURL[3] == Requests[i].FeatureURL.Complete )
523cdf0e10cSrcweir 			aRet[i] = (frame::XDispatch*) this;
524cdf0e10cSrcweir 		else if( !m_bLink && m_aInterceptedURL[4] == Requests[i].FeatureURL.Complete )
525cdf0e10cSrcweir 			aRet[i] = (frame::XDispatch*) this;
526cdf0e10cSrcweir 		else if(m_aInterceptedURL[5] == Requests[i].FeatureURL.Complete)
527cdf0e10cSrcweir 			aRet[i] = (frame::XDispatch*) this;
528cdf0e10cSrcweir 
529cdf0e10cSrcweir 	return aRet;
530cdf0e10cSrcweir }
531cdf0e10cSrcweir 
532cdf0e10cSrcweir 
533cdf0e10cSrcweir 
534cdf0e10cSrcweir //XDispatchProviderInterceptor
535cdf0e10cSrcweir 
536cdf0e10cSrcweir uno::Reference< frame::XDispatchProvider > SAL_CALL
getSlaveDispatchProvider()537cdf0e10cSrcweir Interceptor::getSlaveDispatchProvider(  )
538cdf0e10cSrcweir 	throw (
539cdf0e10cSrcweir 		uno::RuntimeException
540cdf0e10cSrcweir 	)
541cdf0e10cSrcweir {
542cdf0e10cSrcweir 	osl::MutexGuard aGuard(m_aMutex);
543cdf0e10cSrcweir 	return m_xSlaveDispatchProvider;
544cdf0e10cSrcweir }
545cdf0e10cSrcweir 
546cdf0e10cSrcweir void SAL_CALL
setSlaveDispatchProvider(const uno::Reference<frame::XDispatchProvider> & NewDispatchProvider)547cdf0e10cSrcweir Interceptor::setSlaveDispatchProvider(
548cdf0e10cSrcweir 	const uno::Reference< frame::XDispatchProvider >& NewDispatchProvider )
549cdf0e10cSrcweir 	throw (
550cdf0e10cSrcweir 		uno::RuntimeException
551cdf0e10cSrcweir 	)
552cdf0e10cSrcweir {
553cdf0e10cSrcweir 	osl::MutexGuard aGuard(m_aMutex);
554cdf0e10cSrcweir 	m_xSlaveDispatchProvider = NewDispatchProvider;
555cdf0e10cSrcweir }
556cdf0e10cSrcweir 
557cdf0e10cSrcweir 
558cdf0e10cSrcweir uno::Reference< frame::XDispatchProvider > SAL_CALL
getMasterDispatchProvider()559cdf0e10cSrcweir Interceptor::getMasterDispatchProvider(  )
560cdf0e10cSrcweir 	throw (
561cdf0e10cSrcweir 		uno::RuntimeException
562cdf0e10cSrcweir 	)
563cdf0e10cSrcweir {
564cdf0e10cSrcweir 	osl::MutexGuard aGuard(m_aMutex);
565cdf0e10cSrcweir 	return m_xMasterDispatchProvider;
566cdf0e10cSrcweir }
567cdf0e10cSrcweir 
568cdf0e10cSrcweir 
569cdf0e10cSrcweir void SAL_CALL
setMasterDispatchProvider(const uno::Reference<frame::XDispatchProvider> & NewSupplier)570cdf0e10cSrcweir Interceptor::setMasterDispatchProvider(
571cdf0e10cSrcweir 	const uno::Reference< frame::XDispatchProvider >& NewSupplier )
572cdf0e10cSrcweir 	throw (
573cdf0e10cSrcweir 		uno::RuntimeException
574cdf0e10cSrcweir 	)
575cdf0e10cSrcweir {
576cdf0e10cSrcweir 	osl::MutexGuard aGuard(m_aMutex);
577cdf0e10cSrcweir 	m_xMasterDispatchProvider = NewSupplier;
578cdf0e10cSrcweir }
579cdf0e10cSrcweir 
580cdf0e10cSrcweir // Fix strange warnings about some
581cdf0e10cSrcweir // ATL::CAxHostWindow::QueryInterface|AddRef|Releae functions.
582cdf0e10cSrcweir // warning C4505: 'xxx' : unreferenced local function has been removed
583cdf0e10cSrcweir #if defined(_MSC_VER)
584cdf0e10cSrcweir #pragma warning(disable: 4505)
585cdf0e10cSrcweir #endif
586