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