1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef SC_CELLLISTSOURCE_HXX
29 #define SC_CELLLISTSOURCE_HXX
30 
31 #include <com/sun/star/form/binding/XListEntrySource.hpp>
32 #include <cppuhelper/compbase4.hxx>
33 #include <comphelper/propertycontainer.hxx>
34 #include <comphelper/uno3.hxx>
35 #include <comphelper/broadcasthelper.hxx>
36 #include <comphelper/proparrhlp.hxx>
37 #include <com/sun/star/table/XCellRange.hpp>
38 #include <com/sun/star/table/CellRangeAddress.hpp>
39 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
40 #include <com/sun/star/lang/DisposedException.hpp>
41 #include <com/sun/star/lang/XServiceInfo.hpp>
42 #include <com/sun/star/lang/XInitialization.hpp>
43 #include <com/sun/star/util/XModifyListener.hpp>
44 
45 
46 //.........................................................................
47 namespace calc
48 {
49 //.........................................................................
50 
51     //=====================================================================
52     //= OCellListSource
53     //=====================================================================
54     class OCellListSource;
55     // the base for our interfaces
56     typedef ::cppu::WeakAggComponentImplHelper4 <   ::com::sun::star::form::binding::XListEntrySource
57                                                 ,   ::com::sun::star::util::XModifyListener
58                                                 ,   ::com::sun::star::lang::XServiceInfo
59                                                 ,   ::com::sun::star::lang::XInitialization
60                                                 >   OCellListSource_Base;
61     // the base for the property handling
62     typedef ::comphelper::OPropertyContainer        OCellListSource_PBase;
63     // the second base for property handling
64     typedef ::comphelper::OPropertyArrayUsageHelper< OCellListSource >
65                                                     OCellListSource_PABase;
66 
67     class OCellListSource :public ::comphelper::OBaseMutex
68                             ,public OCellListSource_Base      // order matters! before OCellListSource_PBase, so rBHelper gets initialized
69                             ,public OCellListSource_PBase
70 					        ,public OCellListSource_PABase
71     {
72     private:
73         ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheetDocument >
74                     m_xDocument;            /// the document where our cell lives
75         ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellRange >
76                     m_xRange;               /// the range of cells we're bound to
77     	::cppu::OInterfaceContainerHelper
78                     m_aListEntryListeners;  /// our listeners
79         sal_Bool    m_bInitialized;         /// has XInitialization::initialize been called?
80 
81     public:
82         OCellListSource(
83             const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheetDocument >& _rxDocument
84         );
85 
86         using OCellListSource_PBase::getFastPropertyValue;
87 
88     protected:
89         ~OCellListSource( );
90 
91     protected:
92         // XInterface
93         DECLARE_XINTERFACE()
94 
95         // XTypeProvider
96         DECLARE_XTYPEPROVIDER()
97 
98         // XListEntrySource
99         virtual sal_Int32 SAL_CALL getListEntryCount(  ) throw (::com::sun::star::uno::RuntimeException);
100         virtual ::rtl::OUString SAL_CALL getListEntry( sal_Int32 Position ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
101         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getAllListEntries(  ) throw (::com::sun::star::uno::RuntimeException);
102         virtual void SAL_CALL addListEntryListener( const ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XListEntryListener >& Listener ) throw (::com::sun::star::lang::NullPointerException, ::com::sun::star::uno::RuntimeException);
103         virtual void SAL_CALL removeListEntryListener( const ::com::sun::star::uno::Reference< ::com::sun::star::form::binding::XListEntryListener >& Listener ) throw (::com::sun::star::lang::NullPointerException, ::com::sun::star::uno::RuntimeException);
104 
105         // OComponentHelper/XComponent
106         virtual void SAL_CALL disposing();
107 
108         // XServiceInfo
109         virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw (::com::sun::star::uno::RuntimeException);
110         virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
111         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw (::com::sun::star::uno::RuntimeException);
112 
113         // XPropertySet
114         virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException);
115 
116         // OPropertySetHelper
117         virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
118 	    virtual void SAL_CALL getFastPropertyValue( ::com::sun::star::uno::Any& _rValue, sal_Int32 _nHandle ) const;
119 
120         // ::comphelper::OPropertyArrayUsageHelper
121 		virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
122 
123         // XModifyListener
124         virtual void SAL_CALL modified( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
125         virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
126 
127         // XInitialization
128         virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
129 
130     private:
131         void    checkDisposed( ) const
132                     SAL_THROW( ( ::com::sun::star::lang::DisposedException ) );
133         void    checkInitialized()
134                     SAL_THROW( ( ::com::sun::star::uno::RuntimeException ) );
135 
136         /** retrieves the actual address of our cell range
137             @precond
138                 our m_xRange is not <NULL/>
139         */
140         ::com::sun::star::table::CellRangeAddress
141                 getRangeAddress( ) const;
142 
143         /** retrievs the text of a cell within our range
144             @param _nRangeRelativeColumn
145                 the relative column index of the cell within our range
146             @param _nRangeRelativeRow
147                 the relative row index of the cell within our range
148             @precond
149                 our m_xRange is not <NULL/>
150         */
151         ::rtl::OUString
152                 getCellTextContent_noCheck(
153                     sal_Int32 _nRangeRelativeColumn,
154                     sal_Int32 _nRangeRelativeRow
155                 );
156 
157         void    notifyModified();
158 
159     private:
160         OCellListSource();                                      // never implemented
161         OCellListSource( const OCellListSource& );              // never implemented
162         OCellListSource& operator=( const OCellListSource& );   // never implemented
163 
164 #ifdef DBG_UTIL
165     private:
166         static  const char* checkConsistency_static( const void* _pThis );
167                 const char* checkConsistency( ) const;
168 #endif
169     };
170 
171 //.........................................................................
172 }   // namespace calc
173 //.........................................................................
174 
175 #endif // SC_CELLLISTSOURCE_HXX
176