1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SC_CELLLISTSOURCE_HXX
25 #define SC_CELLLISTSOURCE_HXX
26 
27 #include <com/sun/star/form/binding/XListEntrySource.hpp>
28 #include <cppuhelper/compbase4.hxx>
29 #include <comphelper/propertycontainer.hxx>
30 #include <comphelper/uno3.hxx>
31 #include <comphelper/broadcasthelper.hxx>
32 #include <comphelper/proparrhlp.hxx>
33 #include <com/sun/star/table/XCellRange.hpp>
34 #include <com/sun/star/table/CellRangeAddress.hpp>
35 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
36 #include <com/sun/star/lang/DisposedException.hpp>
37 #include <com/sun/star/lang/XServiceInfo.hpp>
38 #include <com/sun/star/lang/XInitialization.hpp>
39 #include <com/sun/star/util/XModifyListener.hpp>
40 
41 
42 //.........................................................................
43 namespace calc
44 {
45 //.........................................................................
46 
47     //=====================================================================
48     //= OCellListSource
49     //=====================================================================
50     class OCellListSource;
51     // the base for our interfaces
52     typedef ::cppu::WeakAggComponentImplHelper4 <   ::com::sun::star::form::binding::XListEntrySource
53                                                 ,   ::com::sun::star::util::XModifyListener
54                                                 ,   ::com::sun::star::lang::XServiceInfo
55                                                 ,   ::com::sun::star::lang::XInitialization
56                                                 >   OCellListSource_Base;
57     // the base for the property handling
58     typedef ::comphelper::OPropertyContainer        OCellListSource_PBase;
59     // the second base for property handling
60     typedef ::comphelper::OPropertyArrayUsageHelper< OCellListSource >
61                                                     OCellListSource_PABase;
62 
63     class OCellListSource :public ::comphelper::OBaseMutex
64                             ,public OCellListSource_Base      // order matters! before OCellListSource_PBase, so rBHelper gets initialized
65                             ,public OCellListSource_PBase
66 					        ,public OCellListSource_PABase
67     {
68     private:
69         ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheetDocument >
70                     m_xDocument;            /// the document where our cell lives
71         ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellRange >
72                     m_xRange;               /// the range of cells we're bound to
73     	::cppu::OInterfaceContainerHelper
74                     m_aListEntryListeners;  /// our listeners
75         sal_Bool    m_bInitialized;         /// has XInitialization::initialize been called?
76 
77     public:
78         OCellListSource(
79             const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheetDocument >& _rxDocument
80         );
81 
82         using OCellListSource_PBase::getFastPropertyValue;
83 
84     protected:
85         ~OCellListSource( );
86 
87     protected:
88         // XInterface
89         DECLARE_XINTERFACE()
90 
91         // XTypeProvider
92         DECLARE_XTYPEPROVIDER()
93 
94         // XListEntrySource
95         virtual sal_Int32 SAL_CALL getListEntryCount(  ) throw (::com::sun::star::uno::RuntimeException);
96         virtual ::rtl::OUString SAL_CALL getListEntry( sal_Int32 Position ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
97         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getAllListEntries(  ) throw (::com::sun::star::uno::RuntimeException);
98         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);
99         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);
100 
101         // OComponentHelper/XComponent
102         virtual void SAL_CALL disposing();
103 
104         // XServiceInfo
105         virtual ::rtl::OUString SAL_CALL getImplementationName(  ) throw (::com::sun::star::uno::RuntimeException);
106         virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException);
107         virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw (::com::sun::star::uno::RuntimeException);
108 
109         // XPropertySet
110         virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException);
111 
112         // OPropertySetHelper
113         virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
114 	    virtual void SAL_CALL getFastPropertyValue( ::com::sun::star::uno::Any& _rValue, sal_Int32 _nHandle ) const;
115 
116         // ::comphelper::OPropertyArrayUsageHelper
117 		virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
118 
119         // XModifyListener
120         virtual void SAL_CALL modified( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
121         virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
122 
123         // XInitialization
124         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);
125 
126     private:
127         void    checkDisposed( ) const
128                     SAL_THROW( ( ::com::sun::star::lang::DisposedException ) );
129         void    checkInitialized()
130                     SAL_THROW( ( ::com::sun::star::uno::RuntimeException ) );
131 
132         /** retrieves the actual address of our cell range
133             @precond
134                 our m_xRange is not <NULL/>
135         */
136         ::com::sun::star::table::CellRangeAddress
137                 getRangeAddress( ) const;
138 
139         /** retrievs the text of a cell within our range
140             @param _nRangeRelativeColumn
141                 the relative column index of the cell within our range
142             @param _nRangeRelativeRow
143                 the relative row index of the cell within our range
144             @precond
145                 our m_xRange is not <NULL/>
146         */
147         ::rtl::OUString
148                 getCellTextContent_noCheck(
149                     sal_Int32 _nRangeRelativeColumn,
150                     sal_Int32 _nRangeRelativeRow
151                 );
152 
153         void    notifyModified();
154 
155     private:
156         OCellListSource();                                      // never implemented
157         OCellListSource( const OCellListSource& );              // never implemented
158         OCellListSource& operator=( const OCellListSource& );   // never implemented
159 
160 #ifdef DBG_UTIL
161     private:
162         static  const char* checkConsistency_static( const void* _pThis );
163                 const char* checkConsistency( ) const;
164 #endif
165     };
166 
167 //.........................................................................
168 }   // namespace calc
169 //.........................................................................
170 
171 #endif // SC_CELLLISTSOURCE_HXX
172