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