xref: /aoo42x/main/sc/inc/nameuno.hxx (revision dffa72de)
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_NAMEUNO_HXX
25 #define SC_NAMEUNO_HXX
26 
27 #include <svl/lstner.hxx>
28 #include "address.hxx"
29 #include "formula/grammar.hxx"
30 #include <com/sun/star/sheet/XLabelRange.hpp>
31 #include <com/sun/star/sheet/XLabelRanges.hpp>
32 #include <com/sun/star/sheet/XCellRangeReferrer.hpp>
33 #include <com/sun/star/sheet/XNamedRange.hpp>
34 #include <com/sun/star/sheet/XFormulaTokens.hpp>
35 #include <com/sun/star/sheet/XNamedRanges.hpp>
36 #include <com/sun/star/container/XEnumerationAccess.hpp>
37 #include <com/sun/star/lang/XServiceName.hpp>
38 #include <com/sun/star/lang/XServiceInfo.hpp>
39 #include <com/sun/star/lang/XUnoTunnel.hpp>
40 #include <com/sun/star/beans/XPropertySet.hpp>
41 #include <com/sun/star/document/XActionLockable.hpp>
42 #include <cppuhelper/implbase2.hxx>
43 #include <cppuhelper/implbase3.hxx>
44 #include <cppuhelper/implbase5.hxx>
45 #include <cppuhelper/implbase6.hxx>
46 
47 #include <global.hxx> //for EMPTY_STRING
48 
49 class ScDocShell;
50 class ScRangeData;
51 class ScTokenArray;
52 
53 
54 class ScNamedRangeObj : public ::cppu::WeakImplHelper6<
55 							::com::sun::star::sheet::XNamedRange,
56                             ::com::sun::star::sheet::XFormulaTokens,
57 							::com::sun::star::sheet::XCellRangeReferrer,
58 							::com::sun::star::beans::XPropertySet,
59 							::com::sun::star::lang::XUnoTunnel,
60 							::com::sun::star::lang::XServiceInfo >,
61 						public SfxListener
62 {
63 private:
64 	ScDocShell*				pDocShell;
65 	String					aName;
66 	String					aScopeName;
67 
68 private:
69 	ScRangeData*			GetRangeData_Impl();
70 	void					Modify_Impl( const String* pNewName,
71                                         const ScTokenArray* pNewTokens, const String* pNewContent,
72 										const ScAddress* pNewPos, const sal_uInt16* pNewType,
73                                         const formula::FormulaGrammar::Grammar eGrammar, const String* pNewScopeName = NULL );
74 
75 public:
76 							ScNamedRangeObj(ScDocShell* pDocSh, const String& rNm, const String& rScopeName = EMPTY_STRING);
77 	virtual					~ScNamedRangeObj();
78 
79 	virtual void			Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
80 
81 							// XNamedRange
82 	virtual ::rtl::OUString SAL_CALL getContent() throw(::com::sun::star::uno::RuntimeException);
83 	virtual void SAL_CALL	setContent( const ::rtl::OUString& aContent )
84 								throw(::com::sun::star::uno::RuntimeException);
85 	virtual ::com::sun::star::table::CellAddress SAL_CALL getReferencePosition()
86 								throw(::com::sun::star::uno::RuntimeException);
87 	virtual void SAL_CALL	setReferencePosition(
88 								const ::com::sun::star::table::CellAddress& aReferencePosition )
89 									throw(::com::sun::star::uno::RuntimeException);
90 	virtual sal_Int32		SAL_CALL getType() throw(::com::sun::star::uno::RuntimeException);
91 	virtual void SAL_CALL	setType( sal_Int32 nType ) throw(::com::sun::star::uno::RuntimeException);
92 	virtual ::rtl::OUString SAL_CALL getScopeName() throw(::com::sun::star::uno::RuntimeException);
93 	virtual void SAL_CALL	setScopeAndRangeName( const ::rtl::OUString& aScopeName, const ::rtl::OUString& aRangeName ) throw(::com::sun::star::uno::RuntimeException);
94 
95                             // XFormulaTokens
96     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::FormulaToken > SAL_CALL getTokens()
97                                 throw (::com::sun::star::uno::RuntimeException);
98     virtual void SAL_CALL   setTokens( const ::com::sun::star::uno::Sequence<
99                                     ::com::sun::star::sheet::FormulaToken >& aTokens )
100                                 throw (::com::sun::star::uno::RuntimeException);
101 
102 							// XNamed
103 	virtual ::rtl::OUString SAL_CALL getName() throw(::com::sun::star::uno::RuntimeException);
104 	virtual void SAL_CALL	setName( const ::rtl::OUString& aName )
105 								throw(::com::sun::star::uno::RuntimeException);
106 
107 							// XCellRangeReferrer
108 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellRange > SAL_CALL
109 							getReferredCells() throw(::com::sun::star::uno::RuntimeException);
110 
111 							// XPropertySet
112 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >
113 							SAL_CALL getPropertySetInfo()
114 								throw(::com::sun::star::uno::RuntimeException);
115 	virtual void SAL_CALL	setPropertyValue( const ::rtl::OUString& aPropertyName,
116 									const ::com::sun::star::uno::Any& aValue )
117 								throw(::com::sun::star::beans::UnknownPropertyException,
118 									::com::sun::star::beans::PropertyVetoException,
119 									::com::sun::star::lang::IllegalArgumentException,
120 									::com::sun::star::lang::WrappedTargetException,
121 									::com::sun::star::uno::RuntimeException);
122 	virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue(
123 									const ::rtl::OUString& PropertyName )
124 								throw(::com::sun::star::beans::UnknownPropertyException,
125 									::com::sun::star::lang::WrappedTargetException,
126 									::com::sun::star::uno::RuntimeException);
127 	virtual void SAL_CALL	addPropertyChangeListener( const ::rtl::OUString& aPropertyName,
128 									const ::com::sun::star::uno::Reference<
129 										::com::sun::star::beans::XPropertyChangeListener >& xListener )
130 								throw(::com::sun::star::beans::UnknownPropertyException,
131 									::com::sun::star::lang::WrappedTargetException,
132 									::com::sun::star::uno::RuntimeException);
133 	virtual void SAL_CALL	removePropertyChangeListener( const ::rtl::OUString& aPropertyName,
134 									const ::com::sun::star::uno::Reference<
135 										::com::sun::star::beans::XPropertyChangeListener >& aListener )
136 								throw(::com::sun::star::beans::UnknownPropertyException,
137 									::com::sun::star::lang::WrappedTargetException,
138 									::com::sun::star::uno::RuntimeException);
139 	virtual void SAL_CALL	addVetoableChangeListener( const ::rtl::OUString& PropertyName,
140 									const ::com::sun::star::uno::Reference<
141 										::com::sun::star::beans::XVetoableChangeListener >& aListener )
142 								throw(::com::sun::star::beans::UnknownPropertyException,
143 									::com::sun::star::lang::WrappedTargetException,
144 									::com::sun::star::uno::RuntimeException);
145 	virtual void SAL_CALL	removeVetoableChangeListener( const ::rtl::OUString& PropertyName,
146 									const ::com::sun::star::uno::Reference<
147 										::com::sun::star::beans::XVetoableChangeListener >& aListener )
148 								throw(::com::sun::star::beans::UnknownPropertyException,
149 									::com::sun::star::lang::WrappedTargetException,
150 									::com::sun::star::uno::RuntimeException);
151 
152 							// XUnoTunnel
153 	virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence<
154 									sal_Int8 >& aIdentifier )
155 								throw(::com::sun::star::uno::RuntimeException);
156 
157 	static const com::sun::star::uno::Sequence<sal_Int8>& getUnoTunnelId();
158 	static ScNamedRangeObj* getImplementation( const com::sun::star::uno::Reference<
159 									com::sun::star::uno::XInterface> xObj );
160 
161 							// XServiceInfo
162 	virtual ::rtl::OUString SAL_CALL getImplementationName()
163 								throw(::com::sun::star::uno::RuntimeException);
164 	virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
165 								throw(::com::sun::star::uno::RuntimeException);
166 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
167 								throw(::com::sun::star::uno::RuntimeException);
168 
169                             // methods accessible via getImplementation()
170             void            SetContentWithGrammar( const ::rtl::OUString& aContent,
171                                     const formula::FormulaGrammar::Grammar eGrammar )
172                                 throw(::com::sun::star::uno::RuntimeException);
173 };
174 
175 
176 class ScNamedRangesObj : public ::cppu::WeakImplHelper5<
177 							::com::sun::star::sheet::XNamedRanges,
178 							::com::sun::star::container::XEnumerationAccess,
179 							::com::sun::star::container::XIndexAccess,
180                             ::com::sun::star::document::XActionLockable,
181 							::com::sun::star::lang::XServiceInfo >,
182 						public SfxListener
183 {
184 private:
185 	ScDocShell*				pDocShell;
186 
187 	ScNamedRangeObj*		GetObjectByIndex_Impl(sal_uInt16 nIndex);
188 	ScNamedRangeObj*		GetObjectByName_Impl(const ::rtl::OUString& aName);
189 	ScNamedRangeObj*		GetObjectByScopeName_Impl(const ::rtl::OUString& aScopeName, const ::rtl::OUString& aRangeName);
190 
191 	void ImplAddNewByScopeAndName(SCTAB aScope,const ::rtl::OUString& aRangeName, const ::rtl::OUString& aContent,
192 								const ::com::sun::star::table::CellAddress& aPosition, sal_Int32 nType)
193 								throw(::com::sun::star::uno::RuntimeException);
194 
195 	void ImplRemoveByScopeAndName(SCTAB aScope,const ::rtl::OUString& aRangeName)
196 								throw(::com::sun::star::uno::RuntimeException);
197 
198 protected:
199     /** called from the XActionLockable interface methods on initial locking */
200     virtual void            lock();
201 
202     /** called from the XActionLockable interface methods on final unlock */
203     virtual void            unlock();
204 
205 public:
206 							ScNamedRangesObj(ScDocShell* pDocSh);
207 	virtual					~ScNamedRangesObj();
208 
209 	virtual void			Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
210 
211 							// XNamedRanges
212 	virtual void SAL_CALL	addNewByName( const ::rtl::OUString& aName, const ::rtl::OUString& aContent,
213 								const ::com::sun::star::table::CellAddress& aPosition, sal_Int32 nType )
214 									throw(::com::sun::star::uno::RuntimeException);
215 
216 	virtual void SAL_CALL	addNewByScopeName( const ::rtl::OUString& aScopeName,const ::rtl::OUString& aRangeName, const ::rtl::OUString& aContent,
217 								const ::com::sun::star::table::CellAddress& aPosition, sal_Int32 nType )
218 									throw(::com::sun::star::uno::RuntimeException);
219 	virtual void SAL_CALL	addNewFromTitles( const ::com::sun::star::table::CellRangeAddress& aSource,
220 								::com::sun::star::sheet::Border aBorder )
221 									throw(::com::sun::star::uno::RuntimeException);
222 	virtual void SAL_CALL	removeByName( const ::rtl::OUString& aName )
223 								throw(::com::sun::star::uno::RuntimeException);
224 	virtual void SAL_CALL	removeByScopeName( const ::rtl::OUString& aScopeName, const ::rtl::OUString& aRangeName )
225 								throw(::com::sun::star::uno::RuntimeException);
226 	virtual void SAL_CALL	outputList( const ::com::sun::star::table::CellAddress& aOutputPosition )
227 								throw(::com::sun::star::uno::RuntimeException);
228 	virtual sal_Bool SAL_CALL hasByScopeName( const ::rtl::OUString& aScopeName, const ::rtl::OUString& aRangeName )
229 								throw(::com::sun::star::uno::RuntimeException);
230 	virtual ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::RangeScopeName > SAL_CALL getElementScopeNames()
231 								throw(::com::sun::star::uno::RuntimeException);
232 	virtual ::com::sun::star::uno::Any SAL_CALL getByScopeName( const ::rtl::OUString& aScopeName, const ::rtl::OUString& aRangeName )
233 								throw(::com::sun::star::container::NoSuchElementException,
234 									::com::sun::star::lang::WrappedTargetException,
235 									::com::sun::star::uno::RuntimeException);
236 
237 							// XNameAccess
238 	virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName )
239 								throw(::com::sun::star::container::NoSuchElementException,
240 									::com::sun::star::lang::WrappedTargetException,
241 									::com::sun::star::uno::RuntimeException);
242 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames()
243 								throw(::com::sun::star::uno::RuntimeException);
244 	virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName )
245 								throw(::com::sun::star::uno::RuntimeException);
246 
247 							// XIndexAccess
248 	virtual sal_Int32 SAL_CALL getCount() throw(::com::sun::star::uno::RuntimeException);
249 	virtual ::com::sun::star::uno::Any SAL_CALL getByIndex( sal_Int32 Index )
250 								throw(::com::sun::star::lang::IndexOutOfBoundsException,
251 									::com::sun::star::lang::WrappedTargetException,
252 									::com::sun::star::uno::RuntimeException);
253 
254 							// XEnumerationAccess
255 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL
256 							createEnumeration() throw(::com::sun::star::uno::RuntimeException);
257 
258 							// XElementAccess
259 	virtual ::com::sun::star::uno::Type SAL_CALL getElementType()
260 								throw(::com::sun::star::uno::RuntimeException);
261 	virtual sal_Bool SAL_CALL hasElements() throw(::com::sun::star::uno::RuntimeException);
262 
263                             // XActionLockable
264     virtual sal_Bool SAL_CALL isActionLocked() throw(::com::sun::star::uno::RuntimeException);
265     virtual void SAL_CALL addActionLock() throw(::com::sun::star::uno::RuntimeException);
266     virtual void SAL_CALL removeActionLock() throw(::com::sun::star::uno::RuntimeException);
267     virtual void SAL_CALL setActionLocks( sal_Int16 nLock ) throw(::com::sun::star::uno::RuntimeException);
268     virtual sal_Int16 SAL_CALL resetActionLocks() throw(::com::sun::star::uno::RuntimeException);
269 
270 							// XServiceInfo
271 	virtual ::rtl::OUString SAL_CALL getImplementationName()
272 								throw(::com::sun::star::uno::RuntimeException);
273 	virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
274 								throw(::com::sun::star::uno::RuntimeException);
275 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
276 								throw(::com::sun::star::uno::RuntimeException);
277 };
278 
279 
280 class ScLabelRangeObj : public ::cppu::WeakImplHelper2<
281 							::com::sun::star::sheet::XLabelRange,
282 							::com::sun::star::lang::XServiceInfo >,
283 						public SfxListener
284 {
285 private:
286 	ScDocShell*				pDocShell;
287 	sal_Bool				bColumn;
288 	ScRange					aRange;			// Kriterium um Bereich zu finden
289 
290 private:
291 	ScRangePair*			GetData_Impl();
292 	void					Modify_Impl( const ScRange* pLabel, const ScRange* pData );
293 
294 public:
295 							ScLabelRangeObj(ScDocShell* pDocSh, sal_Bool bCol, const ScRange& rR);
296 	virtual					~ScLabelRangeObj();
297 
298 	virtual void			Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
299 
300 							// XLabelRange
301 	virtual ::com::sun::star::table::CellRangeAddress SAL_CALL getLabelArea()
302 								throw(::com::sun::star::uno::RuntimeException);
303 	virtual void SAL_CALL	setLabelArea( const ::com::sun::star::table::CellRangeAddress& aLabelArea )
304 								throw(::com::sun::star::uno::RuntimeException);
305 	virtual ::com::sun::star::table::CellRangeAddress SAL_CALL getDataArea()
306 								throw(::com::sun::star::uno::RuntimeException);
307 	virtual void SAL_CALL	setDataArea( const ::com::sun::star::table::CellRangeAddress& aDataArea )
308 								throw(::com::sun::star::uno::RuntimeException);
309 
310 							// XServiceInfo
311 	virtual ::rtl::OUString SAL_CALL getImplementationName()
312 								throw(::com::sun::star::uno::RuntimeException);
313 	virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
314 								throw(::com::sun::star::uno::RuntimeException);
315 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
316 								throw(::com::sun::star::uno::RuntimeException);
317 };
318 
319 
320 class ScLabelRangesObj : public ::cppu::WeakImplHelper3<
321 							::com::sun::star::sheet::XLabelRanges,
322 							::com::sun::star::container::XEnumerationAccess,
323 							::com::sun::star::lang::XServiceInfo >,
324 						public SfxListener
325 {
326 private:
327 	ScDocShell*				pDocShell;
328 	sal_Bool					bColumn;
329 
330 	ScLabelRangeObj*		GetObjectByIndex_Impl(sal_uInt16 nIndex);
331 
332 public:
333 							ScLabelRangesObj(ScDocShell* pDocSh, sal_Bool bCol);
334 	virtual					~ScLabelRangesObj();
335 
336 	virtual void			Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
337 
338 							// XLabelRanges
339 	virtual void SAL_CALL	addNew( const ::com::sun::star::table::CellRangeAddress& aLabelArea,
340 								const ::com::sun::star::table::CellRangeAddress& aDataArea )
341 									throw(::com::sun::star::uno::RuntimeException);
342 	virtual void SAL_CALL	removeByIndex( sal_Int32 nIndex )
343 								throw(::com::sun::star::uno::RuntimeException);
344 
345 							// XIndexAccess
346 	virtual sal_Int32 SAL_CALL getCount() throw(::com::sun::star::uno::RuntimeException);
347 	virtual ::com::sun::star::uno::Any SAL_CALL getByIndex( sal_Int32 Index )
348 								throw(::com::sun::star::lang::IndexOutOfBoundsException,
349 									::com::sun::star::lang::WrappedTargetException,
350 									::com::sun::star::uno::RuntimeException);
351 
352 							// XEnumerationAccess
353 	virtual ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > SAL_CALL
354 							createEnumeration() throw(::com::sun::star::uno::RuntimeException);
355 
356 							// XElementAccess
357 	virtual ::com::sun::star::uno::Type SAL_CALL getElementType()
358 								throw(::com::sun::star::uno::RuntimeException);
359 	virtual sal_Bool SAL_CALL hasElements() throw(::com::sun::star::uno::RuntimeException);
360 
361 							// XServiceInfo
362 	virtual ::rtl::OUString SAL_CALL getImplementationName()
363 								throw(::com::sun::star::uno::RuntimeException);
364 	virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
365 								throw(::com::sun::star::uno::RuntimeException);
366 	virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
367 								throw(::com::sun::star::uno::RuntimeException);
368 };
369 
370 
371 
372 
373 #endif
374 
375