xref: /AOO41X/main/sc/source/ui/unoobj/celllistsource.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 #include "celllistsource.hxx"
31*cdf0e10cSrcweir #include <tools/debug.hxx>
32*cdf0e10cSrcweir #include <com/sun/star/text/XTextRange.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/util/XModifyBroadcaster.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/container/XIndexAccess.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp>
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir //.........................................................................
40*cdf0e10cSrcweir namespace calc
41*cdf0e10cSrcweir {
42*cdf0e10cSrcweir //.........................................................................
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir #define PROP_HANDLE_RANGE_ADDRESS  1
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir     using namespace ::com::sun::star::uno;
47*cdf0e10cSrcweir     using namespace ::com::sun::star::lang;
48*cdf0e10cSrcweir     using namespace ::com::sun::star::table;
49*cdf0e10cSrcweir     using namespace ::com::sun::star::text;
50*cdf0e10cSrcweir     using namespace ::com::sun::star::sheet;
51*cdf0e10cSrcweir     using namespace ::com::sun::star::container;
52*cdf0e10cSrcweir     using namespace ::com::sun::star::beans;
53*cdf0e10cSrcweir     using namespace ::com::sun::star::util;
54*cdf0e10cSrcweir     using namespace ::com::sun::star::form::binding;
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir     //=====================================================================
57*cdf0e10cSrcweir     //= OCellListSource
58*cdf0e10cSrcweir     //=====================================================================
59*cdf0e10cSrcweir     DBG_NAME( OCellListSource )
60*cdf0e10cSrcweir     //---------------------------------------------------------------------
61*cdf0e10cSrcweir #ifdef DBG_UTIL
62*cdf0e10cSrcweir     const char* OCellListSource::checkConsistency_static( const void* _pThis )
63*cdf0e10cSrcweir     {
64*cdf0e10cSrcweir         return static_cast< const OCellListSource* >( _pThis )->checkConsistency( );
65*cdf0e10cSrcweir     }
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir     const char* OCellListSource::checkConsistency( ) const
68*cdf0e10cSrcweir     {
69*cdf0e10cSrcweir         const char* pAssertion = NULL;
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir         // TODO: place any checks here to ensure consistency of this instance
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir         return pAssertion;
74*cdf0e10cSrcweir     }
75*cdf0e10cSrcweir #endif
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir     //---------------------------------------------------------------------
78*cdf0e10cSrcweir     OCellListSource::OCellListSource( const Reference< XSpreadsheetDocument >& _rxDocument )
79*cdf0e10cSrcweir         :OCellListSource_Base( m_aMutex )
80*cdf0e10cSrcweir         ,OCellListSource_PBase( OCellListSource_Base::rBHelper )
81*cdf0e10cSrcweir         ,m_xDocument( _rxDocument )
82*cdf0e10cSrcweir         ,m_aListEntryListeners( m_aMutex )
83*cdf0e10cSrcweir         ,m_bInitialized( sal_False )
84*cdf0e10cSrcweir     {
85*cdf0e10cSrcweir         DBG_CTOR( OCellListSource, checkConsistency_static );
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir         OSL_PRECOND( m_xDocument.is(), "OCellListSource::OCellListSource: invalid document!" );
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir         // register our property at the base class
90*cdf0e10cSrcweir         CellRangeAddress aInitialPropValue;
91*cdf0e10cSrcweir 	    registerPropertyNoMember(
92*cdf0e10cSrcweir             ::rtl::OUString::createFromAscii( "CellRange" ),
93*cdf0e10cSrcweir             PROP_HANDLE_RANGE_ADDRESS,
94*cdf0e10cSrcweir             PropertyAttribute::BOUND | PropertyAttribute::READONLY,
95*cdf0e10cSrcweir             ::getCppuType( &aInitialPropValue ),
96*cdf0e10cSrcweir             &aInitialPropValue
97*cdf0e10cSrcweir         );
98*cdf0e10cSrcweir     }
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir     //---------------------------------------------------------------------
101*cdf0e10cSrcweir     OCellListSource::~OCellListSource( )
102*cdf0e10cSrcweir     {
103*cdf0e10cSrcweir         if ( !OCellListSource_Base::rBHelper.bDisposed )
104*cdf0e10cSrcweir         {
105*cdf0e10cSrcweir             acquire();  // prevent duplicate dtor
106*cdf0e10cSrcweir             dispose();
107*cdf0e10cSrcweir         }
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir         DBG_DTOR( OCellListSource, checkConsistency_static );
110*cdf0e10cSrcweir     }
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir     //--------------------------------------------------------------------
113*cdf0e10cSrcweir     IMPLEMENT_FORWARD_XINTERFACE2( OCellListSource, OCellListSource_Base, OCellListSource_PBase )
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir     //--------------------------------------------------------------------
116*cdf0e10cSrcweir     IMPLEMENT_FORWARD_XTYPEPROVIDER2( OCellListSource, OCellListSource_Base, OCellListSource_PBase )
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir     //--------------------------------------------------------------------
119*cdf0e10cSrcweir     void SAL_CALL OCellListSource::disposing()
120*cdf0e10cSrcweir     {
121*cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
122*cdf0e10cSrcweir         DBG_CHKTHIS( OCellListSource, checkConsistency_static );
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir         Reference<XModifyBroadcaster> xBroadcaster( m_xRange, UNO_QUERY );
125*cdf0e10cSrcweir         if ( xBroadcaster.is() )
126*cdf0e10cSrcweir         {
127*cdf0e10cSrcweir             xBroadcaster->removeModifyListener( this );
128*cdf0e10cSrcweir         }
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir         EventObject aDisposeEvent( *this );
131*cdf0e10cSrcweir         m_aListEntryListeners.disposeAndClear( aDisposeEvent );
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir //        OCellListSource_Base::disposing();
134*cdf0e10cSrcweir         WeakAggComponentImplHelperBase::disposing();
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir         // TODO: clean up here whatever you need to clean up (e.g. revoking listeners etc.)
137*cdf0e10cSrcweir     }
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir     //--------------------------------------------------------------------
140*cdf0e10cSrcweir     Reference< XPropertySetInfo > SAL_CALL OCellListSource::getPropertySetInfo(  ) throw(RuntimeException)
141*cdf0e10cSrcweir     {
142*cdf0e10cSrcweir         DBG_CHKTHIS( OCellListSource, checkConsistency_static );
143*cdf0e10cSrcweir     	return createPropertySetInfo( getInfoHelper() ) ;
144*cdf0e10cSrcweir     }
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir     //--------------------------------------------------------------------
147*cdf0e10cSrcweir     ::cppu::IPropertyArrayHelper& SAL_CALL OCellListSource::getInfoHelper()
148*cdf0e10cSrcweir     {
149*cdf0e10cSrcweir 	    return *OCellListSource_PABase::getArrayHelper();
150*cdf0e10cSrcweir     }
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir     //--------------------------------------------------------------------
153*cdf0e10cSrcweir     ::cppu::IPropertyArrayHelper* OCellListSource::createArrayHelper( ) const
154*cdf0e10cSrcweir     {
155*cdf0e10cSrcweir 	    Sequence< Property > aProps;
156*cdf0e10cSrcweir 	    describeProperties( aProps );
157*cdf0e10cSrcweir 	    return new ::cppu::OPropertyArrayHelper(aProps);
158*cdf0e10cSrcweir     }
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir     //--------------------------------------------------------------------
161*cdf0e10cSrcweir 	void SAL_CALL OCellListSource::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const
162*cdf0e10cSrcweir     {
163*cdf0e10cSrcweir         DBG_CHKTHIS( OCellListSource, checkConsistency_static );
164*cdf0e10cSrcweir         DBG_ASSERT( _nHandle == PROP_HANDLE_RANGE_ADDRESS, "OCellListSource::getFastPropertyValue: invalid handle!" );
165*cdf0e10cSrcweir             // we only have this one property ....
166*cdf0e10cSrcweir         (void)_nHandle;     // avoid warning in product version
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir         _rValue <<= getRangeAddress( );
169*cdf0e10cSrcweir     }
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir     //--------------------------------------------------------------------
172*cdf0e10cSrcweir     void OCellListSource::checkDisposed( ) const SAL_THROW( ( DisposedException ) )
173*cdf0e10cSrcweir     {
174*cdf0e10cSrcweir         if ( OCellListSource_Base::rBHelper.bInDispose || OCellListSource_Base::rBHelper.bDisposed )
175*cdf0e10cSrcweir             throw DisposedException();
176*cdf0e10cSrcweir             // TODO: is it worth having an error message here?
177*cdf0e10cSrcweir     }
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir     //--------------------------------------------------------------------
180*cdf0e10cSrcweir     void OCellListSource::checkInitialized() SAL_THROW( ( RuntimeException ) )
181*cdf0e10cSrcweir     {
182*cdf0e10cSrcweir         if ( !m_bInitialized )
183*cdf0e10cSrcweir             throw RuntimeException();
184*cdf0e10cSrcweir             // TODO: error message
185*cdf0e10cSrcweir     }
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir     //--------------------------------------------------------------------
188*cdf0e10cSrcweir     ::rtl::OUString SAL_CALL OCellListSource::getImplementationName(  ) throw (RuntimeException)
189*cdf0e10cSrcweir     {
190*cdf0e10cSrcweir         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.sheet.OCellListSource" ) );
191*cdf0e10cSrcweir     }
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir     //--------------------------------------------------------------------
194*cdf0e10cSrcweir     sal_Bool SAL_CALL OCellListSource::supportsService( const ::rtl::OUString& _rServiceName ) throw (RuntimeException)
195*cdf0e10cSrcweir     {
196*cdf0e10cSrcweir         Sequence< ::rtl::OUString > aSupportedServices( getSupportedServiceNames() );
197*cdf0e10cSrcweir         const ::rtl::OUString* pLookup = aSupportedServices.getConstArray();
198*cdf0e10cSrcweir         const ::rtl::OUString* pLookupEnd = aSupportedServices.getConstArray() + aSupportedServices.getLength();
199*cdf0e10cSrcweir         while ( pLookup != pLookupEnd )
200*cdf0e10cSrcweir             if ( *pLookup++ == _rServiceName )
201*cdf0e10cSrcweir                 return sal_True;
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir         return sal_False;
204*cdf0e10cSrcweir     }
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir     //--------------------------------------------------------------------
207*cdf0e10cSrcweir     Sequence< ::rtl::OUString > SAL_CALL OCellListSource::getSupportedServiceNames(  ) throw (RuntimeException)
208*cdf0e10cSrcweir     {
209*cdf0e10cSrcweir         Sequence< ::rtl::OUString > aServices( 2 );
210*cdf0e10cSrcweir         aServices[ 0 ] =  ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.table.CellRangeListSource" ) );
211*cdf0e10cSrcweir         aServices[ 1 ] =  ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.form.binding.ListEntrySource" ) );
212*cdf0e10cSrcweir         return aServices;
213*cdf0e10cSrcweir     }
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir     //--------------------------------------------------------------------
216*cdf0e10cSrcweir     CellRangeAddress OCellListSource::getRangeAddress( ) const
217*cdf0e10cSrcweir     {
218*cdf0e10cSrcweir         OSL_PRECOND( m_xRange.is(), "OCellListSource::getRangeAddress: invalid range!" );
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir         CellRangeAddress aAddress;
221*cdf0e10cSrcweir         Reference< XCellRangeAddressable > xRangeAddress( m_xRange, UNO_QUERY );
222*cdf0e10cSrcweir         if ( xRangeAddress.is() )
223*cdf0e10cSrcweir             aAddress = xRangeAddress->getRangeAddress( );
224*cdf0e10cSrcweir         return aAddress;
225*cdf0e10cSrcweir     }
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir     //--------------------------------------------------------------------
228*cdf0e10cSrcweir     ::rtl::OUString OCellListSource::getCellTextContent_noCheck( sal_Int32 _nRangeRelativeColumn, sal_Int32 _nRangeRelativeRow )
229*cdf0e10cSrcweir     {
230*cdf0e10cSrcweir         OSL_PRECOND( m_xRange.is(), "OCellListSource::getRangeAddress: invalid range!" );
231*cdf0e10cSrcweir         Reference< XTextRange > xCellText;
232*cdf0e10cSrcweir         if ( m_xRange.is() )
233*cdf0e10cSrcweir             xCellText.set(xCellText.query( m_xRange->getCellByPosition( _nRangeRelativeColumn, _nRangeRelativeRow ) ));
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir         ::rtl::OUString sText;
236*cdf0e10cSrcweir         if ( xCellText.is() )
237*cdf0e10cSrcweir             sText = xCellText->getString();
238*cdf0e10cSrcweir         return sText;
239*cdf0e10cSrcweir     }
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir     //--------------------------------------------------------------------
242*cdf0e10cSrcweir     sal_Int32 SAL_CALL OCellListSource::getListEntryCount(  ) throw (RuntimeException)
243*cdf0e10cSrcweir     {
244*cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
245*cdf0e10cSrcweir         DBG_CHKTHIS( OCellListSource, checkConsistency_static );
246*cdf0e10cSrcweir         checkDisposed();
247*cdf0e10cSrcweir         checkInitialized();
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir         CellRangeAddress aAddress( getRangeAddress( ) );
250*cdf0e10cSrcweir         return aAddress.EndRow - aAddress.StartRow + 1;
251*cdf0e10cSrcweir     }
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir     //--------------------------------------------------------------------
254*cdf0e10cSrcweir     ::rtl::OUString SAL_CALL OCellListSource::getListEntry( sal_Int32 _nPosition ) throw (IndexOutOfBoundsException, RuntimeException)
255*cdf0e10cSrcweir     {
256*cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
257*cdf0e10cSrcweir         DBG_CHKTHIS( OCellListSource, checkConsistency_static );
258*cdf0e10cSrcweir         checkDisposed();
259*cdf0e10cSrcweir         checkInitialized();
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir         if ( _nPosition >= getListEntryCount() )
262*cdf0e10cSrcweir             throw IndexOutOfBoundsException();
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir         return getCellTextContent_noCheck( 0, _nPosition );
265*cdf0e10cSrcweir     }
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir     //--------------------------------------------------------------------
268*cdf0e10cSrcweir     Sequence< ::rtl::OUString > SAL_CALL OCellListSource::getAllListEntries(  ) throw (RuntimeException)
269*cdf0e10cSrcweir     {
270*cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
271*cdf0e10cSrcweir         DBG_CHKTHIS( OCellListSource, checkConsistency_static );
272*cdf0e10cSrcweir         checkDisposed();
273*cdf0e10cSrcweir         checkInitialized();
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir         Sequence< ::rtl::OUString > aAllEntries( getListEntryCount() );
276*cdf0e10cSrcweir         ::rtl::OUString* pAllEntries = aAllEntries.getArray();
277*cdf0e10cSrcweir         for ( sal_Int32 i = 0; i < aAllEntries.getLength(); ++i )
278*cdf0e10cSrcweir         {
279*cdf0e10cSrcweir             *pAllEntries++ = getCellTextContent_noCheck( 0, i );
280*cdf0e10cSrcweir         }
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir         return aAllEntries;
283*cdf0e10cSrcweir     }
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir     //--------------------------------------------------------------------
286*cdf0e10cSrcweir     void SAL_CALL OCellListSource::addListEntryListener( const Reference< XListEntryListener >& _rxListener ) throw (NullPointerException, RuntimeException)
287*cdf0e10cSrcweir     {
288*cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
289*cdf0e10cSrcweir         DBG_CHKTHIS( OCellListSource, checkConsistency_static );
290*cdf0e10cSrcweir         checkDisposed();
291*cdf0e10cSrcweir         checkInitialized();
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir         if ( !_rxListener.is() )
294*cdf0e10cSrcweir             throw NullPointerException();
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir         m_aListEntryListeners.addInterface( _rxListener );
297*cdf0e10cSrcweir     }
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir     //--------------------------------------------------------------------
300*cdf0e10cSrcweir     void SAL_CALL OCellListSource::removeListEntryListener( const Reference< XListEntryListener >& _rxListener ) throw (NullPointerException, RuntimeException)
301*cdf0e10cSrcweir     {
302*cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
303*cdf0e10cSrcweir         DBG_CHKTHIS( OCellListSource, checkConsistency_static );
304*cdf0e10cSrcweir         checkDisposed();
305*cdf0e10cSrcweir         checkInitialized();
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir         if ( !_rxListener.is() )
308*cdf0e10cSrcweir             throw NullPointerException();
309*cdf0e10cSrcweir 
310*cdf0e10cSrcweir         m_aListEntryListeners.removeInterface( _rxListener );
311*cdf0e10cSrcweir     }
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir     //--------------------------------------------------------------------
314*cdf0e10cSrcweir     void SAL_CALL OCellListSource::modified( const EventObject& /* aEvent */ ) throw (RuntimeException)
315*cdf0e10cSrcweir     {
316*cdf0e10cSrcweir         DBG_CHKTHIS( OCellListSource, checkConsistency_static );
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir         notifyModified();
319*cdf0e10cSrcweir     }
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir     //--------------------------------------------------------------------
322*cdf0e10cSrcweir     void OCellListSource::notifyModified()
323*cdf0e10cSrcweir     {
324*cdf0e10cSrcweir         EventObject aEvent;
325*cdf0e10cSrcweir         aEvent.Source.set(*this);
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir 		::cppu::OInterfaceIteratorHelper aIter( m_aListEntryListeners );
328*cdf0e10cSrcweir 		while ( aIter.hasMoreElements() )
329*cdf0e10cSrcweir         {
330*cdf0e10cSrcweir             try
331*cdf0e10cSrcweir             {
332*cdf0e10cSrcweir     			static_cast< XListEntryListener* >( aIter.next() )->allEntriesChanged( aEvent );
333*cdf0e10cSrcweir             }
334*cdf0e10cSrcweir             catch( const RuntimeException& )
335*cdf0e10cSrcweir             {
336*cdf0e10cSrcweir                 // silent this
337*cdf0e10cSrcweir             }
338*cdf0e10cSrcweir             catch( const Exception& )
339*cdf0e10cSrcweir             {
340*cdf0e10cSrcweir                 DBG_ERROR( "OCellListSource::notifyModified: caught a (non-runtime) exception!" );
341*cdf0e10cSrcweir             }
342*cdf0e10cSrcweir         }
343*cdf0e10cSrcweir 
344*cdf0e10cSrcweir     }
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir     //--------------------------------------------------------------------
347*cdf0e10cSrcweir     void SAL_CALL OCellListSource::disposing( const EventObject& aEvent ) throw (RuntimeException)
348*cdf0e10cSrcweir     {
349*cdf0e10cSrcweir         DBG_CHKTHIS( OCellListSource, checkConsistency_static );
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir         Reference<XInterface> xRangeInt( m_xRange, UNO_QUERY );
352*cdf0e10cSrcweir         if ( xRangeInt == aEvent.Source )
353*cdf0e10cSrcweir         {
354*cdf0e10cSrcweir             // release references to range object
355*cdf0e10cSrcweir             m_xRange.clear();
356*cdf0e10cSrcweir         }
357*cdf0e10cSrcweir     }
358*cdf0e10cSrcweir 
359*cdf0e10cSrcweir     //--------------------------------------------------------------------
360*cdf0e10cSrcweir     void SAL_CALL OCellListSource::initialize( const Sequence< Any >& _rArguments ) throw (Exception, RuntimeException)
361*cdf0e10cSrcweir     {
362*cdf0e10cSrcweir         if ( m_bInitialized )
363*cdf0e10cSrcweir             throw Exception();
364*cdf0e10cSrcweir             // TODO: error message
365*cdf0e10cSrcweir 
366*cdf0e10cSrcweir         // get the cell address
367*cdf0e10cSrcweir         CellRangeAddress aRangeAddress;
368*cdf0e10cSrcweir         sal_Bool bFoundAddress = sal_False;
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir         const Any* pLoop = _rArguments.getConstArray();
371*cdf0e10cSrcweir         const Any* pLoopEnd = _rArguments.getConstArray() + _rArguments.getLength();
372*cdf0e10cSrcweir         for ( ; ( pLoop != pLoopEnd ) && !bFoundAddress; ++pLoop )
373*cdf0e10cSrcweir         {
374*cdf0e10cSrcweir             NamedValue aValue;
375*cdf0e10cSrcweir             if ( *pLoop >>= aValue )
376*cdf0e10cSrcweir             {
377*cdf0e10cSrcweir                 if ( aValue.Name.equalsAscii( "CellRange" ) )
378*cdf0e10cSrcweir                 {
379*cdf0e10cSrcweir                     if ( aValue.Value >>= aRangeAddress )
380*cdf0e10cSrcweir                         bFoundAddress = sal_True;
381*cdf0e10cSrcweir                 }
382*cdf0e10cSrcweir             }
383*cdf0e10cSrcweir         }
384*cdf0e10cSrcweir 
385*cdf0e10cSrcweir         if ( !bFoundAddress )
386*cdf0e10cSrcweir             // TODO: error message
387*cdf0e10cSrcweir             throw Exception();
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir         // determine the range we're bound to
390*cdf0e10cSrcweir         try
391*cdf0e10cSrcweir         {
392*cdf0e10cSrcweir             if ( m_xDocument.is() )
393*cdf0e10cSrcweir             {
394*cdf0e10cSrcweir                 // first the sheets collection
395*cdf0e10cSrcweir                 Reference< XIndexAccess > xSheets(m_xDocument->getSheets( ), UNO_QUERY);
396*cdf0e10cSrcweir                 DBG_ASSERT( xSheets.is(), "OCellListSource::initialize: could not retrieve the sheets!" );
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir                 if ( xSheets.is() )
399*cdf0e10cSrcweir                 {
400*cdf0e10cSrcweir                     // the concrete sheet
401*cdf0e10cSrcweir                     Reference< XCellRange > xSheet(xSheets->getByIndex( aRangeAddress.Sheet ), UNO_QUERY);
402*cdf0e10cSrcweir                     DBG_ASSERT( xSheet.is(), "OCellListSource::initialize: NULL sheet, but no exception!" );
403*cdf0e10cSrcweir 
404*cdf0e10cSrcweir                     // the concrete cell
405*cdf0e10cSrcweir                     if ( xSheet.is() )
406*cdf0e10cSrcweir                     {
407*cdf0e10cSrcweir                         m_xRange.set(xSheet->getCellRangeByPosition(
408*cdf0e10cSrcweir                             aRangeAddress.StartColumn, aRangeAddress.StartRow,
409*cdf0e10cSrcweir                             aRangeAddress.EndColumn, aRangeAddress.EndRow));
410*cdf0e10cSrcweir                         DBG_ASSERT( Reference< XCellRangeAddressable >( m_xRange, UNO_QUERY ).is(), "OCellListSource::initialize: either NULL range, or cell without address access!" );
411*cdf0e10cSrcweir                     }
412*cdf0e10cSrcweir                 }
413*cdf0e10cSrcweir             }
414*cdf0e10cSrcweir         }
415*cdf0e10cSrcweir         catch( const Exception& )
416*cdf0e10cSrcweir         {
417*cdf0e10cSrcweir             DBG_ERROR( "OCellListSource::initialize: caught an exception while retrieving the cell object!" );
418*cdf0e10cSrcweir         }
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir 
421*cdf0e10cSrcweir         if ( !m_xRange.is() )
422*cdf0e10cSrcweir             throw Exception();
423*cdf0e10cSrcweir             // TODO error message
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir         Reference<XModifyBroadcaster> xBroadcaster( m_xRange, UNO_QUERY );
426*cdf0e10cSrcweir         if ( xBroadcaster.is() )
427*cdf0e10cSrcweir         {
428*cdf0e10cSrcweir             xBroadcaster->addModifyListener( this );
429*cdf0e10cSrcweir         }
430*cdf0e10cSrcweir 
431*cdf0e10cSrcweir         // TODO: add as XEventListener to the cell range, so we get notified when it dies,
432*cdf0e10cSrcweir         // and can dispose ourself then
433*cdf0e10cSrcweir 
434*cdf0e10cSrcweir         // TODO: somehow add as listener so we get notified when the address of the cell range changes
435*cdf0e10cSrcweir         // We need to forward this as change in our CellRange property to our property change listeners
436*cdf0e10cSrcweir 
437*cdf0e10cSrcweir         // TODO: somehow add as listener to the cells in the range, so that we get notified
438*cdf0e10cSrcweir         // when their content changes. We need to forward this to our list entry listeners then
439*cdf0e10cSrcweir 
440*cdf0e10cSrcweir         // TODO: somehow add as listener so that we get notified of insertions and removals of rows in our
441*cdf0e10cSrcweir         // range. In this case, we need to fire a change in our CellRange property, and additionally
442*cdf0e10cSrcweir         // notify our XListEntryListeners
443*cdf0e10cSrcweir 
444*cdf0e10cSrcweir         m_bInitialized = sal_True;
445*cdf0e10cSrcweir     }
446*cdf0e10cSrcweir 
447*cdf0e10cSrcweir //.........................................................................
448*cdf0e10cSrcweir }   // namespace calc
449*cdf0e10cSrcweir //.........................................................................
450