xref: /AOO41X/main/sc/source/ui/unoobj/dispuno.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 // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sc.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
34*cdf0e10cSrcweir #include <comphelper/uno3.hxx>
35*cdf0e10cSrcweir #include <svx/dataaccessdescriptor.hxx>
36*cdf0e10cSrcweir #include <svl/smplhint.hxx>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProviderInterception.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/view/XSelectionSupplier.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/sdb/CommandType.hpp>
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir #include "dispuno.hxx"
43*cdf0e10cSrcweir #include "unoguard.hxx"
44*cdf0e10cSrcweir #include "tabvwsh.hxx"
45*cdf0e10cSrcweir #include "dbdocfun.hxx"
46*cdf0e10cSrcweir #include "dbcolect.hxx"
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir using namespace com::sun::star;
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir //------------------------------------------------------------------------
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir const char* cURLInsertColumns = ".uno:DataSourceBrowser/InsertColumns"; //data into text
53*cdf0e10cSrcweir const char* cURLDocDataSource = ".uno:DataSourceBrowser/DocumentDataSource";
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir //------------------------------------------------------------------------
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir SV_IMPL_PTRARR( XStatusListenerArr_Impl, XStatusListenerPtr );
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir //------------------------------------------------------------------------
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir uno::Reference<view::XSelectionSupplier> lcl_GetSelectionSupplier( SfxViewShell* pViewShell )
62*cdf0e10cSrcweir {
63*cdf0e10cSrcweir 	if ( pViewShell )
64*cdf0e10cSrcweir 	{
65*cdf0e10cSrcweir 		SfxViewFrame* pViewFrame = pViewShell->GetViewFrame();
66*cdf0e10cSrcweir 		if (pViewFrame)
67*cdf0e10cSrcweir 		{
68*cdf0e10cSrcweir 			return uno::Reference<view::XSelectionSupplier>( pViewFrame->GetFrame().GetController(), uno::UNO_QUERY );
69*cdf0e10cSrcweir 		}
70*cdf0e10cSrcweir 	}
71*cdf0e10cSrcweir 	return uno::Reference<view::XSelectionSupplier>();
72*cdf0e10cSrcweir }
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir //------------------------------------------------------------------------
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir ScDispatchProviderInterceptor::ScDispatchProviderInterceptor(ScTabViewShell* pViewSh) :
78*cdf0e10cSrcweir 	pViewShell( pViewSh )
79*cdf0e10cSrcweir {
80*cdf0e10cSrcweir 	if ( pViewShell )
81*cdf0e10cSrcweir 	{
82*cdf0e10cSrcweir 		m_xIntercepted.set(uno::Reference<frame::XDispatchProviderInterception>(pViewShell->GetViewFrame()->GetFrame().GetFrameInterface(), uno::UNO_QUERY));
83*cdf0e10cSrcweir 		if (m_xIntercepted.is())
84*cdf0e10cSrcweir 		{
85*cdf0e10cSrcweir 			comphelper::increment( m_refCount );
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir 			m_xIntercepted->registerDispatchProviderInterceptor(
88*cdf0e10cSrcweir 						static_cast<frame::XDispatchProviderInterceptor*>(this));
89*cdf0e10cSrcweir 			// this should make us the top-level dispatch-provider for the component, via a call to our
90*cdf0e10cSrcweir 			// setDispatchProvider we should have got an fallback for requests we (i.e. our master) cannot fullfill
91*cdf0e10cSrcweir 			uno::Reference<lang::XComponent> xInterceptedComponent(m_xIntercepted, uno::UNO_QUERY);
92*cdf0e10cSrcweir 			if (xInterceptedComponent.is())
93*cdf0e10cSrcweir 				xInterceptedComponent->addEventListener(static_cast<lang::XEventListener*>(this));
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir 			comphelper::decrement( m_refCount );
96*cdf0e10cSrcweir 		}
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir 		StartListening(*pViewShell);
99*cdf0e10cSrcweir 	}
100*cdf0e10cSrcweir }
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir ScDispatchProviderInterceptor::~ScDispatchProviderInterceptor()
103*cdf0e10cSrcweir {
104*cdf0e10cSrcweir 	if (pViewShell)
105*cdf0e10cSrcweir 		EndListening(*pViewShell);
106*cdf0e10cSrcweir }
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir void ScDispatchProviderInterceptor::Notify( SfxBroadcaster&, const SfxHint& rHint )
109*cdf0e10cSrcweir {
110*cdf0e10cSrcweir 	if ( rHint.ISA( SfxSimpleHint ) &&
111*cdf0e10cSrcweir 			((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
112*cdf0e10cSrcweir 		pViewShell = NULL;
113*cdf0e10cSrcweir }
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir // XDispatchProvider
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir uno::Reference<frame::XDispatch> SAL_CALL ScDispatchProviderInterceptor::queryDispatch(
118*cdf0e10cSrcweir 						const util::URL& aURL, const rtl::OUString& aTargetFrameName,
119*cdf0e10cSrcweir 						sal_Int32 nSearchFlags )
120*cdf0e10cSrcweir 						throw(uno::RuntimeException)
121*cdf0e10cSrcweir {
122*cdf0e10cSrcweir 	ScUnoGuard aGuard;
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir 	uno::Reference<frame::XDispatch> xResult;
125*cdf0e10cSrcweir 	// create some dispatch ...
126*cdf0e10cSrcweir 	if ( pViewShell && (
127*cdf0e10cSrcweir 		!aURL.Complete.compareToAscii(cURLInsertColumns) ||
128*cdf0e10cSrcweir 		!aURL.Complete.compareToAscii(cURLDocDataSource) ) )
129*cdf0e10cSrcweir 	{
130*cdf0e10cSrcweir 		if (!m_xMyDispatch.is())
131*cdf0e10cSrcweir 			m_xMyDispatch = new ScDispatch( pViewShell );
132*cdf0e10cSrcweir 		xResult = m_xMyDispatch;
133*cdf0e10cSrcweir 	}
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir 	// ask our slave provider
136*cdf0e10cSrcweir 	if (!xResult.is() && m_xSlaveDispatcher.is())
137*cdf0e10cSrcweir 		xResult = m_xSlaveDispatcher->queryDispatch(aURL, aTargetFrameName, nSearchFlags);
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir 	return xResult;
140*cdf0e10cSrcweir }
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir uno::Sequence< uno::Reference<frame::XDispatch> > SAL_CALL
143*cdf0e10cSrcweir 						ScDispatchProviderInterceptor::queryDispatches(
144*cdf0e10cSrcweir 						const uno::Sequence<frame::DispatchDescriptor>& aDescripts )
145*cdf0e10cSrcweir 						throw(uno::RuntimeException)
146*cdf0e10cSrcweir {
147*cdf0e10cSrcweir 	ScUnoGuard aGuard;
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir 	uno::Sequence< uno::Reference< frame::XDispatch> > aReturn(aDescripts.getLength());
150*cdf0e10cSrcweir 	uno::Reference< frame::XDispatch>* pReturn = aReturn.getArray();
151*cdf0e10cSrcweir 	const frame::DispatchDescriptor* pDescripts = aDescripts.getConstArray();
152*cdf0e10cSrcweir 	for (sal_Int16 i=0; i<aDescripts.getLength(); ++i, ++pReturn, ++pDescripts)
153*cdf0e10cSrcweir 	{
154*cdf0e10cSrcweir 		*pReturn = queryDispatch(pDescripts->FeatureURL,
155*cdf0e10cSrcweir 				pDescripts->FrameName, pDescripts->SearchFlags);
156*cdf0e10cSrcweir 	}
157*cdf0e10cSrcweir 	return aReturn;
158*cdf0e10cSrcweir }
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir // XDispatchProviderInterceptor
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir uno::Reference<frame::XDispatchProvider> SAL_CALL
163*cdf0e10cSrcweir 						ScDispatchProviderInterceptor::getSlaveDispatchProvider()
164*cdf0e10cSrcweir 						throw(uno::RuntimeException)
165*cdf0e10cSrcweir {
166*cdf0e10cSrcweir 	ScUnoGuard aGuard;
167*cdf0e10cSrcweir 	return m_xSlaveDispatcher;
168*cdf0e10cSrcweir }
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir void SAL_CALL ScDispatchProviderInterceptor::setSlaveDispatchProvider(
171*cdf0e10cSrcweir 						const uno::Reference<frame::XDispatchProvider>& xNewDispatchProvider )
172*cdf0e10cSrcweir 						throw(uno::RuntimeException)
173*cdf0e10cSrcweir {
174*cdf0e10cSrcweir 	ScUnoGuard aGuard;
175*cdf0e10cSrcweir 	m_xSlaveDispatcher.set(xNewDispatchProvider);
176*cdf0e10cSrcweir }
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir uno::Reference<frame::XDispatchProvider> SAL_CALL
179*cdf0e10cSrcweir 						ScDispatchProviderInterceptor::getMasterDispatchProvider()
180*cdf0e10cSrcweir 						throw(uno::RuntimeException)
181*cdf0e10cSrcweir {
182*cdf0e10cSrcweir 	ScUnoGuard aGuard;
183*cdf0e10cSrcweir 	return m_xMasterDispatcher;
184*cdf0e10cSrcweir }
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir void SAL_CALL ScDispatchProviderInterceptor::setMasterDispatchProvider(
187*cdf0e10cSrcweir 						const uno::Reference<frame::XDispatchProvider>& xNewSupplier )
188*cdf0e10cSrcweir 						throw(uno::RuntimeException)
189*cdf0e10cSrcweir {
190*cdf0e10cSrcweir 	ScUnoGuard aGuard;
191*cdf0e10cSrcweir 	m_xMasterDispatcher.set(xNewSupplier);
192*cdf0e10cSrcweir }
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir // XEventListener
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir void SAL_CALL ScDispatchProviderInterceptor::disposing( const lang::EventObject& /* Source */ )
197*cdf0e10cSrcweir 								throw(::com::sun::star::uno::RuntimeException)
198*cdf0e10cSrcweir {
199*cdf0e10cSrcweir 	ScUnoGuard aGuard;
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir 	if (m_xIntercepted.is())
202*cdf0e10cSrcweir 	{
203*cdf0e10cSrcweir 		m_xIntercepted->releaseDispatchProviderInterceptor(
204*cdf0e10cSrcweir 				static_cast<frame::XDispatchProviderInterceptor*>(this));
205*cdf0e10cSrcweir 		uno::Reference<lang::XComponent> xInterceptedComponent(m_xIntercepted, uno::UNO_QUERY);
206*cdf0e10cSrcweir 		if (xInterceptedComponent.is())
207*cdf0e10cSrcweir 			xInterceptedComponent->removeEventListener(static_cast<lang::XEventListener*>(this));
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir 		m_xMyDispatch = NULL;
210*cdf0e10cSrcweir 	}
211*cdf0e10cSrcweir 	m_xIntercepted = NULL;
212*cdf0e10cSrcweir }
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir //------------------------------------------------------------------------
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir ScDispatch::ScDispatch(ScTabViewShell* pViewSh) :
217*cdf0e10cSrcweir 	pViewShell( pViewSh ),
218*cdf0e10cSrcweir 	bListeningToView( sal_False )
219*cdf0e10cSrcweir {
220*cdf0e10cSrcweir 	if (pViewShell)
221*cdf0e10cSrcweir 		StartListening(*pViewShell);
222*cdf0e10cSrcweir }
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir ScDispatch::~ScDispatch()
225*cdf0e10cSrcweir {
226*cdf0e10cSrcweir 	if (pViewShell)
227*cdf0e10cSrcweir 		EndListening(*pViewShell);
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir     if (bListeningToView && pViewShell)
230*cdf0e10cSrcweir     {
231*cdf0e10cSrcweir         uno::Reference<view::XSelectionSupplier> xSupplier(lcl_GetSelectionSupplier( pViewShell ));
232*cdf0e10cSrcweir         if ( xSupplier.is() )
233*cdf0e10cSrcweir 	        xSupplier->removeSelectionChangeListener(this);
234*cdf0e10cSrcweir     }
235*cdf0e10cSrcweir }
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir void ScDispatch::Notify( SfxBroadcaster&, const SfxHint& rHint )
238*cdf0e10cSrcweir {
239*cdf0e10cSrcweir 	if ( rHint.ISA( SfxSimpleHint ) &&
240*cdf0e10cSrcweir 			((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
241*cdf0e10cSrcweir 		pViewShell = NULL;
242*cdf0e10cSrcweir }
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir // XDispatch
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir void SAL_CALL ScDispatch::dispatch( const util::URL& aURL,
247*cdf0e10cSrcweir 								const uno::Sequence<beans::PropertyValue>& aArgs )
248*cdf0e10cSrcweir 								throw(uno::RuntimeException)
249*cdf0e10cSrcweir {
250*cdf0e10cSrcweir 	ScUnoGuard aGuard;
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir 	sal_Bool bDone = sal_False;
253*cdf0e10cSrcweir 	if ( pViewShell && !aURL.Complete.compareToAscii(cURLInsertColumns) )
254*cdf0e10cSrcweir 	{
255*cdf0e10cSrcweir 		ScViewData* pViewData = pViewShell->GetViewData();
256*cdf0e10cSrcweir 		ScAddress aPos( pViewData->GetCurX(), pViewData->GetCurY(), pViewData->GetTabNo() );
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir 		ScDBDocFunc aFunc( *pViewData->GetDocShell() );
259*cdf0e10cSrcweir 		bDone = aFunc.DoImportUno( aPos, aArgs );
260*cdf0e10cSrcweir 	}
261*cdf0e10cSrcweir 	// cURLDocDataSource is never dispatched
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir 	if (!bDone)
264*cdf0e10cSrcweir 		throw uno::RuntimeException();
265*cdf0e10cSrcweir }
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir void lcl_FillDataSource( frame::FeatureStateEvent& rEvent, const ScImportParam& rParam )
268*cdf0e10cSrcweir {
269*cdf0e10cSrcweir     rEvent.IsEnabled = rParam.bImport;
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir     ::svx::ODataAccessDescriptor aDescriptor;
272*cdf0e10cSrcweir     if ( rParam.bImport )
273*cdf0e10cSrcweir     {
274*cdf0e10cSrcweir         sal_Int32 nType = rParam.bSql ? sdb::CommandType::COMMAND :
275*cdf0e10cSrcweir                     ( (rParam.nType == ScDbQuery) ? sdb::CommandType::QUERY :
276*cdf0e10cSrcweir                                                     sdb::CommandType::TABLE );
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir 		aDescriptor.setDataSource(rtl::OUString( rParam.aDBName ));
279*cdf0e10cSrcweir         aDescriptor[svx::daCommand]     <<= rtl::OUString( rParam.aStatement );
280*cdf0e10cSrcweir         aDescriptor[svx::daCommandType] <<= nType;
281*cdf0e10cSrcweir     }
282*cdf0e10cSrcweir     else
283*cdf0e10cSrcweir     {
284*cdf0e10cSrcweir         //  descriptor has to be complete anyway
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir         rtl::OUString aEmpty;
287*cdf0e10cSrcweir         aDescriptor[svx::daDataSource]  <<= aEmpty;
288*cdf0e10cSrcweir         aDescriptor[svx::daCommand]     <<= aEmpty;
289*cdf0e10cSrcweir         aDescriptor[svx::daCommandType] <<= (sal_Int32)sdb::CommandType::TABLE;
290*cdf0e10cSrcweir     }
291*cdf0e10cSrcweir     rEvent.State <<= aDescriptor.createPropertyValueSequence();
292*cdf0e10cSrcweir }
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir void SAL_CALL ScDispatch::addStatusListener(
295*cdf0e10cSrcweir                                 const uno::Reference<frame::XStatusListener>& xListener,
296*cdf0e10cSrcweir                                 const util::URL& aURL )
297*cdf0e10cSrcweir                                 throw(uno::RuntimeException)
298*cdf0e10cSrcweir {
299*cdf0e10cSrcweir     ScUnoGuard aGuard;
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir     if (!pViewShell)
302*cdf0e10cSrcweir         throw uno::RuntimeException();
303*cdf0e10cSrcweir 
304*cdf0e10cSrcweir     //  initial state
305*cdf0e10cSrcweir     frame::FeatureStateEvent aEvent;
306*cdf0e10cSrcweir     aEvent.IsEnabled = sal_True;
307*cdf0e10cSrcweir     aEvent.Source.set(static_cast<cppu::OWeakObject*>(this));
308*cdf0e10cSrcweir     aEvent.FeatureURL = aURL;
309*cdf0e10cSrcweir 
310*cdf0e10cSrcweir     if ( !aURL.Complete.compareToAscii(cURLDocDataSource) )
311*cdf0e10cSrcweir     {
312*cdf0e10cSrcweir         uno::Reference<frame::XStatusListener>* pObj =
313*cdf0e10cSrcweir                 new uno::Reference<frame::XStatusListener>( xListener );
314*cdf0e10cSrcweir         aDataSourceListeners.Insert( pObj, aDataSourceListeners.Count() );
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir         if (!bListeningToView)
317*cdf0e10cSrcweir         {
318*cdf0e10cSrcweir             uno::Reference<view::XSelectionSupplier> xSupplier(lcl_GetSelectionSupplier( pViewShell ));
319*cdf0e10cSrcweir             if ( xSupplier.is() )
320*cdf0e10cSrcweir                 xSupplier->addSelectionChangeListener(this);
321*cdf0e10cSrcweir             bListeningToView = sal_True;
322*cdf0e10cSrcweir         }
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir         ScDBData* pDBData = pViewShell->GetDBData(sal_False,SC_DB_OLD);
325*cdf0e10cSrcweir         if ( pDBData )
326*cdf0e10cSrcweir             pDBData->GetImportParam( aLastImport );
327*cdf0e10cSrcweir         lcl_FillDataSource( aEvent, aLastImport );          // modifies State, IsEnabled
328*cdf0e10cSrcweir     }
329*cdf0e10cSrcweir     //! else add to listener for "enabled" changes?
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir     xListener->statusChanged( aEvent );
332*cdf0e10cSrcweir }
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir void SAL_CALL ScDispatch::removeStatusListener(
335*cdf0e10cSrcweir                                 const uno::Reference<frame::XStatusListener>& xListener,
336*cdf0e10cSrcweir                                 const util::URL& aURL )
337*cdf0e10cSrcweir                                 throw(uno::RuntimeException)
338*cdf0e10cSrcweir {
339*cdf0e10cSrcweir     ScUnoGuard aGuard;
340*cdf0e10cSrcweir 
341*cdf0e10cSrcweir     if ( !aURL.Complete.compareToAscii(cURLDocDataSource) )
342*cdf0e10cSrcweir     {
343*cdf0e10cSrcweir         sal_uInt16 nCount = aDataSourceListeners.Count();
344*cdf0e10cSrcweir         for ( sal_uInt16 n=nCount; n--; )
345*cdf0e10cSrcweir         {
346*cdf0e10cSrcweir             uno::Reference<frame::XStatusListener> *pObj = aDataSourceListeners[n];
347*cdf0e10cSrcweir             if ( *pObj == xListener )
348*cdf0e10cSrcweir             {
349*cdf0e10cSrcweir                 aDataSourceListeners.DeleteAndDestroy( n );
350*cdf0e10cSrcweir                 break;
351*cdf0e10cSrcweir             }
352*cdf0e10cSrcweir         }
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir         if ( aDataSourceListeners.Count() == 0 && pViewShell )
355*cdf0e10cSrcweir         {
356*cdf0e10cSrcweir             uno::Reference<view::XSelectionSupplier> xSupplier(lcl_GetSelectionSupplier( pViewShell ));
357*cdf0e10cSrcweir             if ( xSupplier.is() )
358*cdf0e10cSrcweir                 xSupplier->removeSelectionChangeListener(this);
359*cdf0e10cSrcweir             bListeningToView = sal_False;
360*cdf0e10cSrcweir         }
361*cdf0e10cSrcweir     }
362*cdf0e10cSrcweir }
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir // XSelectionChangeListener
365*cdf0e10cSrcweir 
366*cdf0e10cSrcweir void SAL_CALL ScDispatch::selectionChanged( const ::com::sun::star::lang::EventObject& /* aEvent */ )
367*cdf0e10cSrcweir                                 throw (::com::sun::star::uno::RuntimeException)
368*cdf0e10cSrcweir {
369*cdf0e10cSrcweir     //  currently only called for URL cURLDocDataSource
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir     if ( pViewShell )
372*cdf0e10cSrcweir     {
373*cdf0e10cSrcweir         ScImportParam aNewImport;
374*cdf0e10cSrcweir         ScDBData* pDBData = pViewShell->GetDBData(sal_False,SC_DB_OLD);
375*cdf0e10cSrcweir         if ( pDBData )
376*cdf0e10cSrcweir             pDBData->GetImportParam( aNewImport );
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir         //  notify listeners only if data source has changed
379*cdf0e10cSrcweir         if ( aNewImport.bImport    != aLastImport.bImport ||
380*cdf0e10cSrcweir              aNewImport.aDBName    != aLastImport.aDBName ||
381*cdf0e10cSrcweir              aNewImport.aStatement != aLastImport.aStatement ||
382*cdf0e10cSrcweir              aNewImport.bSql       != aLastImport.bSql ||
383*cdf0e10cSrcweir              aNewImport.nType      != aLastImport.nType )
384*cdf0e10cSrcweir         {
385*cdf0e10cSrcweir             frame::FeatureStateEvent aEvent;
386*cdf0e10cSrcweir             aEvent.Source.set(static_cast<cppu::OWeakObject*>(this));
387*cdf0e10cSrcweir             aEvent.FeatureURL.Complete = rtl::OUString::createFromAscii( cURLDocDataSource );
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir             lcl_FillDataSource( aEvent, aNewImport );       // modifies State, IsEnabled
390*cdf0e10cSrcweir 
391*cdf0e10cSrcweir             for ( sal_uInt16 n=0; n<aDataSourceListeners.Count(); n++ )
392*cdf0e10cSrcweir                 (*aDataSourceListeners[n])->statusChanged( aEvent );
393*cdf0e10cSrcweir 
394*cdf0e10cSrcweir             aLastImport = aNewImport;
395*cdf0e10cSrcweir         }
396*cdf0e10cSrcweir     }
397*cdf0e10cSrcweir }
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir // XEventListener
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir void SAL_CALL ScDispatch::disposing( const ::com::sun::star::lang::EventObject& rSource )
402*cdf0e10cSrcweir                                 throw (::com::sun::star::uno::RuntimeException)
403*cdf0e10cSrcweir {
404*cdf0e10cSrcweir     uno::Reference<view::XSelectionSupplier> xSupplier(rSource.Source, uno::UNO_QUERY);
405*cdf0e10cSrcweir     xSupplier->removeSelectionChangeListener(this);
406*cdf0e10cSrcweir     bListeningToView = sal_False;
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir     lang::EventObject aEvent;
409*cdf0e10cSrcweir     aEvent.Source.set(static_cast<cppu::OWeakObject*>(this));
410*cdf0e10cSrcweir     for ( sal_uInt16 n=0; n<aDataSourceListeners.Count(); n++ )
411*cdf0e10cSrcweir         (*aDataSourceListeners[n])->disposing( aEvent );
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir     pViewShell = NULL;
414*cdf0e10cSrcweir }
415*cdf0e10cSrcweir 
416