Avoid potential negative array index access to cached text.
[LibreOffice.git] / sc / inc / datauno.hxx
blobf2ee6b67412950ed92b75a53b1bf29211ed3cae1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #pragma once
22 #include "global.hxx"
23 #include "queryparam.hxx"
24 #include "subtotalparam.hxx"
26 #include <com/sun/star/sheet/GeneralFunction.hpp>
27 #include <com/sun/star/sheet/XCellRangeReferrer.hpp>
28 #include <com/sun/star/sheet/XSheetFilterDescriptor.hpp>
29 #include <com/sun/star/sheet/XSheetFilterDescriptor2.hpp>
30 #include <com/sun/star/sheet/XSheetFilterDescriptor3.hpp>
31 #include <com/sun/star/sheet/XConsolidationDescriptor.hpp>
32 #include <com/sun/star/sheet/XDatabaseRanges.hpp>
33 #include <com/sun/star/sheet/XDatabaseRange.hpp>
34 #include <com/sun/star/sheet/XUnnamedDatabaseRanges.hpp>
35 #include <com/sun/star/sheet/XSubTotalDescriptor.hpp>
36 #include <com/sun/star/sheet/XSubTotalField.hpp>
37 #include <com/sun/star/lang/XServiceInfo.hpp>
38 #include <com/sun/star/container/XEnumerationAccess.hpp>
39 #include <com/sun/star/container/XIndexAccess.hpp>
40 #include <com/sun/star/beans/XPropertySet.hpp>
41 #include <com/sun/star/container/XNamed.hpp>
42 #include <com/sun/star/util/XRefreshable.hpp>
43 #include <comphelper/servicehelper.hxx>
44 #include <cppuhelper/implbase.hxx>
45 #include <rtl/ref.hxx>
46 #include <svl/itemprop.hxx>
47 #include <svl/lstner.hxx>
49 #include <vector>
51 namespace com::sun::star::sheet { struct TableFilterField2; }
52 namespace com::sun::star::sheet { struct TableFilterField3; }
53 namespace com::sun::star::sheet { struct TableFilterField; }
55 class ScDBData;
56 class ScDocShell;
58 class ScSubTotalFieldObj;
59 class ScDatabaseRangeObj;
60 class ScDataPilotDescriptorBase;
62 struct ScSortParam;
64 class ScDataUnoConversion
66 public:
67 static css::sheet::GeneralFunction SubTotalToGeneral( ScSubTotalFunc eSubTotal );
70 // ImportDescriptor is not available as Uno-object any longer, only Property-Sequence
72 class ScImportDescriptor
74 public:
75 static void FillImportParam(
76 ScImportParam& rParam,
77 const css::uno::Sequence<css::beans::PropertyValue>& rSeq );
78 static void FillProperties(
79 css::uno::Sequence<css::beans::PropertyValue>& rSeq,
80 const ScImportParam& rParam );
81 static tools::Long GetPropertyCount() { return 4; }
84 // SortDescriptor is not available as Uno-object any longer, only Property-Sequence
86 class ScSortDescriptor
88 public:
89 static void FillSortParam(
90 ScSortParam& rParam,
91 const css::uno::Sequence<css::beans::PropertyValue>& rSeq );
92 static void FillProperties(
93 css::uno::Sequence<css::beans::PropertyValue>& rSeq,
94 const ScSortParam& rParam );
95 //! SortAscending needs to get out of the SheetSortDescriptor service description
96 static tools::Long GetPropertyCount()
98 return 9; // TableSortDescriptor and SheetSortDescriptor
103 // ScSubTotalDescriptorBase - base class for SubTotalDescriptor stand alone and in DB area (context?)
105 // to uno, both look the same
107 class ScSubTotalDescriptorBase : public cppu::WeakImplHelper<
108 css::sheet::XSubTotalDescriptor,
109 css::container::XEnumerationAccess,
110 css::container::XIndexAccess,
111 css::beans::XPropertySet,
112 css::lang::XServiceInfo >
114 private:
115 SfxItemPropertySet aPropSet;
117 rtl::Reference<ScSubTotalFieldObj> GetObjectByIndex_Impl(sal_uInt16 nIndex);
119 public:
120 ScSubTotalDescriptorBase();
121 virtual ~ScSubTotalDescriptorBase() override;
123 // in derived classes:
124 // (Fields are within the range)
125 virtual void GetData( ScSubTotalParam& rParam ) const = 0;
126 virtual void PutData( const ScSubTotalParam& rParam ) = 0;
128 // XSubTotalDescriptor
129 virtual void SAL_CALL addNew( const css::uno::Sequence< css::sheet::SubTotalColumn >& aSubTotalColumns,
130 sal_Int32 nGroupColumn ) override;
131 virtual void SAL_CALL clear() override;
133 // XIndexAccess
134 virtual sal_Int32 SAL_CALL getCount() override;
135 virtual css::uno::Any SAL_CALL getByIndex( sal_Int32 Index ) override;
137 // XEnumerationAccess
138 virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL
139 createEnumeration() override;
141 // XElementAccess
142 virtual css::uno::Type SAL_CALL getElementType() override;
143 virtual sal_Bool SAL_CALL hasElements() override;
145 // XPropertySet
146 virtual css::uno::Reference< css::beans::XPropertySetInfo >
147 SAL_CALL getPropertySetInfo() override;
148 virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName,
149 const css::uno::Any& aValue ) override;
150 virtual css::uno::Any SAL_CALL getPropertyValue(
151 const OUString& PropertyName ) override;
152 virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName,
153 const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override;
154 virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName,
155 const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override;
156 virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName,
157 const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
158 virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName,
159 const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
161 // XServiceInfo
162 virtual OUString SAL_CALL getImplementationName() override;
163 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
164 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
167 // ScSubTotalDescriptor - dummy container to use with XImportTarget
169 class ScSubTotalDescriptor final : public ScSubTotalDescriptorBase
171 private:
172 ScSubTotalParam aStoredParam;
174 public:
175 ScSubTotalDescriptor();
176 virtual ~ScSubTotalDescriptor() override;
178 // from ScSubTotalDescriptorBase:
179 virtual void GetData( ScSubTotalParam& rParam ) const override;
180 virtual void PutData( const ScSubTotalParam& rParam ) override;
182 // external access:
183 void SetParam( const ScSubTotalParam& rNew );
186 // ScRangeSubTotalDescriptor - SubTotalDescriptor of a data base area
188 class ScRangeSubTotalDescriptor final : public ScSubTotalDescriptorBase
190 private:
191 rtl::Reference<ScDatabaseRangeObj> mxParent;
193 public:
194 ScRangeSubTotalDescriptor(ScDatabaseRangeObj* pPar);
195 virtual ~ScRangeSubTotalDescriptor() override;
197 // from ScSubTotalDescriptorBase:
198 virtual void GetData( ScSubTotalParam& rParam ) const override;
199 virtual void PutData( const ScSubTotalParam& rParam ) override;
202 class ScSubTotalFieldObj final : public cppu::WeakImplHelper<
203 css::sheet::XSubTotalField,
204 css::lang::XServiceInfo >
206 private:
207 rtl::Reference<ScSubTotalDescriptorBase> xParent;
208 sal_uInt16 nPos;
210 public:
211 ScSubTotalFieldObj( ScSubTotalDescriptorBase* pDesc, sal_uInt16 nP );
212 virtual ~ScSubTotalFieldObj() override;
214 // XSubTotalField
215 virtual sal_Int32 SAL_CALL getGroupColumn() override;
216 virtual void SAL_CALL setGroupColumn( sal_Int32 nGroupColumn ) override;
217 virtual css::uno::Sequence< css::sheet::SubTotalColumn > SAL_CALL
218 getSubTotalColumns() override;
219 virtual void SAL_CALL setSubTotalColumns( const css::uno::Sequence<
220 css::sheet::SubTotalColumn >& aSubTotalColumns ) override;
222 // XServiceInfo
223 virtual OUString SAL_CALL getImplementationName() override;
224 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
225 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
228 class ScConsolidationDescriptor final : public cppu::WeakImplHelper<
229 css::sheet::XConsolidationDescriptor,
230 css::lang::XServiceInfo >
232 private:
233 ScConsolidateParam aParam;
235 public:
236 ScConsolidationDescriptor();
237 virtual ~ScConsolidationDescriptor() override;
239 void SetParam( const ScConsolidateParam& rNew );
240 const ScConsolidateParam& GetParam() const { return aParam; }
242 // XConsolidationDescriptor
243 virtual css::sheet::GeneralFunction SAL_CALL getFunction() override;
244 virtual void SAL_CALL setFunction( css::sheet::GeneralFunction nFunction ) override;
245 virtual css::uno::Sequence< css::table::CellRangeAddress > SAL_CALL
246 getSources( ) override;
247 virtual void SAL_CALL setSources( const css::uno::Sequence< css::table::CellRangeAddress >& aSources ) override;
248 virtual css::table::CellAddress SAL_CALL getStartOutputPosition() override;
249 virtual void SAL_CALL setStartOutputPosition(
250 const css::table::CellAddress& aStartOutputPosition ) override;
251 virtual sal_Bool SAL_CALL getUseColumnHeaders() override;
252 virtual void SAL_CALL setUseColumnHeaders( sal_Bool bUseColumnHeaders ) override;
253 virtual sal_Bool SAL_CALL getUseRowHeaders() override;
254 virtual void SAL_CALL setUseRowHeaders( sal_Bool bUseRowHeaders ) override;
255 virtual sal_Bool SAL_CALL getInsertLinks() override;
256 virtual void SAL_CALL setInsertLinks( sal_Bool bInsertLinks ) override;
258 // XServiceInfo
259 virtual OUString SAL_CALL getImplementationName() override;
260 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
261 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
264 // ScFilterDescriptorBase - base class for FilterDescriptor
265 // stand alone, in a DB area (or context?) and in the DataPilot
267 // to uno, all three look the same
269 class ScFilterDescriptorBase : public cppu::WeakImplHelper<
270 css::sheet::XSheetFilterDescriptor,
271 css::sheet::XSheetFilterDescriptor2,
272 css::sheet::XSheetFilterDescriptor3,
273 css::beans::XPropertySet,
274 css::lang::XServiceInfo >,
275 public SfxListener
277 private:
278 SfxItemPropertySet aPropSet;
279 ScDocShell* pDocSh;
281 public:
282 ScFilterDescriptorBase(ScDocShell* pDocShell);
283 virtual ~ScFilterDescriptorBase() override;
285 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
287 // in the derived classes(?):
288 // (nField[] here within the area)
289 virtual void GetData( ScQueryParam& rParam ) const = 0;
290 virtual void PutData( const ScQueryParam& rParam ) = 0;
292 // XSheetFilterDescriptor
293 virtual css::uno::Sequence< css::sheet::TableFilterField > SAL_CALL
294 getFilterFields() override;
295 virtual void SAL_CALL setFilterFields( const css::uno::Sequence<
296 css::sheet::TableFilterField >& aFilterFields ) override;
298 // XSheetFilterDescriptor2
299 virtual css::uno::Sequence< css::sheet::TableFilterField2 > SAL_CALL
300 getFilterFields2() override;
301 virtual void SAL_CALL setFilterFields2( const css::uno::Sequence<
302 css::sheet::TableFilterField2 >& aFilterFields ) override;
304 // XSheetFilterDescriptor3
305 virtual css::uno::Sequence< css::sheet::TableFilterField3 > SAL_CALL
306 getFilterFields3() override;
307 virtual void SAL_CALL setFilterFields3( const css::uno::Sequence<
308 css::sheet::TableFilterField3 >& aFilterFields ) override;
310 // XPropertySet
311 virtual css::uno::Reference< css::beans::XPropertySetInfo >
312 SAL_CALL getPropertySetInfo() override;
313 virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName,
314 const css::uno::Any& aValue ) override;
315 virtual css::uno::Any SAL_CALL getPropertyValue(
316 const OUString& PropertyName ) override;
317 virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName,
318 const css::uno::Reference<
319 css::beans::XPropertyChangeListener >& xListener ) override;
320 virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName,
321 const css::uno::Reference<
322 css::beans::XPropertyChangeListener >& aListener ) override;
323 virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName,
324 const css::uno::Reference<
325 css::beans::XVetoableChangeListener >& aListener ) override;
326 virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName,
327 const css::uno::Reference<
328 css::beans::XVetoableChangeListener >& aListener ) override;
330 // XServiceInfo
331 virtual OUString SAL_CALL getImplementationName() override;
332 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
333 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
336 // ScFilterDescriptor - dummy container to use with XFilterable
338 class ScFilterDescriptor final : public ScFilterDescriptorBase
340 private:
341 ScQueryParam aStoredParam; // nField[] here within the area
343 public:
344 ScFilterDescriptor(ScDocShell* pDocSh);
345 virtual ~ScFilterDescriptor() override;
347 // from ScFilterDescriptorBase:
348 virtual void GetData( ScQueryParam& rParam ) const override;
349 virtual void PutData( const ScQueryParam& rParam ) override;
351 // external access:
352 void SetParam( const ScQueryParam& rNew );
353 const ScQueryParam& GetParam() const { return aStoredParam; }
356 // ScRangeFilterDescriptor - FilterDescriptor of a data base area
358 class ScRangeFilterDescriptor final : public ScFilterDescriptorBase
360 private:
361 rtl::Reference<ScDatabaseRangeObj> mxParent;
363 public:
364 ScRangeFilterDescriptor(ScDocShell* pDocSh, ScDatabaseRangeObj* pPar);
365 virtual ~ScRangeFilterDescriptor() override;
367 // from ScFilterDescriptorBase:
368 virtual void GetData( ScQueryParam& rParam ) const override;
369 virtual void PutData( const ScQueryParam& rParam ) override;
372 // ScDataPilotFilterDescriptor - FilterDescriptor of a DataPilotDescriptors
374 class ScDataPilotFilterDescriptor final : public ScFilterDescriptorBase
376 private:
377 rtl::Reference<ScDataPilotDescriptorBase> mxParent;
379 public:
380 ScDataPilotFilterDescriptor(ScDocShell* pDocSh, ScDataPilotDescriptorBase* pPar);
381 virtual ~ScDataPilotFilterDescriptor() override;
383 // from ScFilterDescriptorBase:
384 virtual void GetData( ScQueryParam& rParam ) const override;
385 virtual void PutData( const ScQueryParam& rParam ) override;
388 class ScDatabaseRangeObj final : public cppu::WeakImplHelper<
389 css::sheet::XDatabaseRange,
390 css::util::XRefreshable,
391 css::container::XNamed,
392 css::sheet::XCellRangeReferrer,
393 css::beans::XPropertySet,
394 css::lang::XServiceInfo >,
395 public SfxListener
397 private:
398 ScDocShell* pDocShell;
399 OUString aName;
400 SfxItemPropertySet aPropSet;
401 std::vector< css::uno::Reference< css::util::XRefreshListener > >
402 aRefreshListeners;
403 bool bIsUnnamed;
404 SCTAB aTab;
406 private:
407 ScDBData* GetDBData_Impl() const;
408 void Refreshed_Impl();
410 public:
411 ScDatabaseRangeObj(ScDocShell* pDocSh, OUString aNm);
412 SC_DLLPUBLIC ScDatabaseRangeObj(ScDocShell* pDocSh, const SCTAB nTab);
413 virtual ~ScDatabaseRangeObj() override;
415 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
417 // nField[] here within the area:
418 void GetQueryParam(ScQueryParam& rQueryParam) const;
419 void SetQueryParam(const ScQueryParam& rQueryParam);
420 void GetSubTotalParam(ScSubTotalParam& rSubTotalParam) const;
421 void SetSubTotalParam(const ScSubTotalParam& rSubTotalParam);
423 // XNamed
424 virtual OUString SAL_CALL getName() override;
425 virtual void SAL_CALL setName( const OUString& aName ) override;
427 // XDatabaseRange
428 virtual css::table::CellRangeAddress SAL_CALL getDataArea() override;
429 virtual void SAL_CALL setDataArea( const css::table::CellRangeAddress& aDataArea ) override;
430 virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL
431 getSortDescriptor() override;
432 virtual css::uno::Reference< css::sheet::XSheetFilterDescriptor > SAL_CALL
433 getFilterDescriptor() override;
434 virtual css::uno::Reference< css::sheet::XSubTotalDescriptor > SAL_CALL
435 getSubTotalDescriptor() override;
436 virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL
437 getImportDescriptor() override;
439 // XRefreshable
440 virtual void SAL_CALL refresh() override;
441 virtual void SAL_CALL addRefreshListener( const css::uno::Reference<
442 css::util::XRefreshListener >& l ) override;
443 virtual void SAL_CALL removeRefreshListener( const css::uno::Reference<
444 css::util::XRefreshListener >& l ) override;
446 // XCellRangeReferrer
447 virtual css::uno::Reference< css::table::XCellRange > SAL_CALL
448 getReferredCells() override;
450 // XPropertySet
451 virtual css::uno::Reference< css::beans::XPropertySetInfo >
452 SAL_CALL getPropertySetInfo() override;
453 virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName,
454 const css::uno::Any& aValue ) override;
455 virtual css::uno::Any SAL_CALL getPropertyValue(
456 const OUString& PropertyName ) override;
457 virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName,
458 const css::uno::Reference<
459 css::beans::XPropertyChangeListener >& xListener ) override;
460 virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName,
461 const css::uno::Reference<
462 css::beans::XPropertyChangeListener >& aListener ) override;
463 virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName,
464 const css::uno::Reference<
465 css::beans::XVetoableChangeListener >& aListener ) override;
466 virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName,
467 const css::uno::Reference<
468 css::beans::XVetoableChangeListener >& aListener ) override;
470 // XServiceInfo
471 virtual OUString SAL_CALL getImplementationName() override;
472 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
473 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
476 class ScDatabaseRangesObj final : public cppu::WeakImplHelper<
477 css::sheet::XDatabaseRanges,
478 css::container::XEnumerationAccess,
479 css::container::XIndexAccess,
480 css::lang::XServiceInfo >,
481 public SfxListener
483 private:
484 ScDocShell* pDocShell;
486 rtl::Reference<ScDatabaseRangeObj> GetObjectByIndex_Impl(size_t nIndex);
487 rtl::Reference<ScDatabaseRangeObj> GetObjectByName_Impl(const OUString& aName);
489 public:
490 ScDatabaseRangesObj(ScDocShell* pDocSh);
491 virtual ~ScDatabaseRangesObj() override;
493 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
495 // XDatabaseRanges
496 virtual void SAL_CALL addNewByName( const OUString& aName,
497 const css::table::CellRangeAddress& aRange ) override;
498 virtual void SAL_CALL removeByName( const OUString& aName ) override;
500 // XEnumerationAccess
501 virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL
502 createEnumeration() override;
504 // XIndexAccess
505 virtual sal_Int32 SAL_CALL getCount() override;
506 virtual css::uno::Any SAL_CALL getByIndex( sal_Int32 Index ) override;
508 // XElementAccess
509 virtual css::uno::Type SAL_CALL getElementType() override;
510 virtual sal_Bool SAL_CALL hasElements() override;
512 // XNameAccess
513 virtual css::uno::Any SAL_CALL getByName( const OUString& aName ) override;
514 virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override;
515 virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override;
517 // XServiceInfo
518 virtual OUString SAL_CALL getImplementationName() override;
519 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
520 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
523 class ScUnnamedDatabaseRangesObj final : public cppu::WeakImplHelper<
524 css::sheet::XUnnamedDatabaseRanges>,
525 public SfxListener
527 private:
528 ScDocShell* pDocShell;
530 public:
531 ScUnnamedDatabaseRangesObj(ScDocShell* pDocSh);
532 virtual ~ScUnnamedDatabaseRangesObj() override;
534 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
536 // XUnnamedDatabaseRanges
537 virtual void SAL_CALL setByTable( const css::table::CellRangeAddress& aRange ) override;
538 virtual css::uno::Any SAL_CALL getByTable( sal_Int32 nTab ) override;
539 virtual sal_Bool SAL_CALL hasByTable( sal_Int32 nTab ) override;
542 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */