tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / sw / inc / unochart.hxx
blob956d5f721e94215364db06e2791a0ea9105987a5
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 .
19 #ifndef INCLUDED_SW_INC_UNOCHART_HXX
20 #define INCLUDED_SW_INC_UNOCHART_HXX
22 #include <map>
23 #include <vector>
25 #include <com/sun/star/chart2/data/XDataProvider.hpp>
26 #include <com/sun/star/chart2/data/XDataSource.hpp>
27 #include <com/sun/star/chart2/data/XDataSequence.hpp>
28 #include <com/sun/star/chart2/data/XTextualDataSequence.hpp>
29 #include <com/sun/star/chart2/data/XNumericalDataSequence.hpp>
30 #include <com/sun/star/chart2/data/XLabeledDataSequence2.hpp>
31 #include <com/sun/star/chart2/data/XRangeXMLConversion.hpp>
32 #include <com/sun/star/chart2/data/DataSequenceRole.hpp>
33 #include <com/sun/star/lang/XServiceInfo.hpp>
34 #include <com/sun/star/beans/XPropertySet.hpp>
35 #include <com/sun/star/util/XCloneable.hpp>
36 #include <com/sun/star/lang/XComponent.hpp>
37 #include <com/sun/star/lang/XEventListener.hpp>
38 #include <com/sun/star/util/XModifiable.hpp>
39 #include <com/sun/star/util/XModifyListener.hpp>
41 #include <comphelper/interfacecontainer4.hxx>
42 #include <cppuhelper/implbase.hxx>
43 #include <cppuhelper/weakref.hxx>
45 #include <rtl/ref.hxx>
46 #include <svl/listener.hxx>
47 #include <tools/link.hxx>
48 #include <vcl/timer.hxx>
50 #include "frmfmt.hxx"
51 #include "unocrsr.hxx"
53 class SfxItemPropertySet;
54 class SwDoc;
55 class SwTable;
56 class SwTableBox;
57 struct SwRangeDescriptor;
58 class SwSelBoxes;
59 namespace com::sun::star::table { class XCell; }
61 bool FillRangeDescriptor( SwRangeDescriptor &rDesc, std::u16string_view rCellRangeName );
63 class SwChartHelper
65 public:
66 static void DoUpdateAllCharts( SwDoc* pDoc );
69 class SwChartLockController_Helper
71 SwDoc *m_pDoc;
73 DECL_LINK( DoUnlockAllCharts, Timer *, void );
74 Timer m_aUnlockTimer; // timer to unlock chart controllers
75 bool m_bIsLocked;
77 SwChartLockController_Helper( const SwChartLockController_Helper & ) = delete;
78 SwChartLockController_Helper & operator = ( const SwChartLockController_Helper & ) = delete;
80 void LockUnlockAllCharts( bool bLock );
81 void LockAllCharts() { LockUnlockAllCharts( true ); };
82 void UnlockAllCharts() { LockUnlockAllCharts( false ); };
84 public:
85 SwChartLockController_Helper( SwDoc *pDocument );
86 ~SwChartLockController_Helper();
88 void StartOrContinueLocking();
89 void Disconnect();
92 class SwChartDataSequence;
94 typedef cppu::WeakImplHelper
96 css::chart2::data::XDataProvider,
97 css::chart2::data::XRangeXMLConversion,
98 css::lang::XComponent,
99 css::lang::XServiceInfo
101 SwChartDataProviderBaseClass;
103 class SwChartDataProvider final :
104 public SwChartDataProviderBaseClass
107 // used to keep weak-references to all data-sequences of a single table
108 // see definition below...
109 typedef std::vector< unotools::WeakReference < SwChartDataSequence > > Vec_DataSequenceRef_t;
111 // map of data-sequence sets for each table
112 typedef std::map< const SwTable *, Vec_DataSequenceRef_t > Map_Set_DataSequenceRef_t;
114 // map of all data-sequences provided directly or indirectly (e.g. via
115 // data-source) by this object. Since there is only one object of this type
116 // for each document it should hold references to all used data-sequences for
117 // all tables of the document.
118 mutable Map_Set_DataSequenceRef_t m_aDataSequences;
120 ::comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> m_aEventListeners;
121 const SwDoc * m_pDoc;
122 bool m_bDisposed;
124 SwChartDataProvider( const SwChartDataProvider & ) = delete;
125 SwChartDataProvider & operator = ( const SwChartDataProvider & ) = delete;
127 /// @throws css::lang::IllegalArgumentException
128 /// @throws css::uno::RuntimeException
129 css::uno::Reference< css::chart2::data::XDataSource > Impl_createDataSource( const css::uno::Sequence< css::beans::PropertyValue >& aArguments, bool bTestOnly = false );
130 /// @throws css::lang::IllegalArgumentException
131 /// @throws css::uno::RuntimeException
132 css::uno::Reference< css::chart2::data::XDataSequence > Impl_createDataSequenceByRangeRepresentation( std::u16string_view aRangeRepresentation, bool bTestOnly = false );
134 static OUString GetBrokenCellRangeForExport( std::u16string_view rCellRangeRepresentation );
136 public:
137 SwChartDataProvider( const SwDoc& rDoc );
138 virtual ~SwChartDataProvider() override;
140 // XDataProvider
141 virtual sal_Bool SAL_CALL createDataSourcePossible( const css::uno::Sequence< css::beans::PropertyValue >& aArguments ) override;
142 virtual css::uno::Reference< css::chart2::data::XDataSource > SAL_CALL createDataSource( const css::uno::Sequence< css::beans::PropertyValue >& aArguments ) override;
143 virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL detectArguments( const css::uno::Reference< css::chart2::data::XDataSource >& xDataSource ) override;
144 virtual sal_Bool SAL_CALL createDataSequenceByRangeRepresentationPossible( const OUString& aRangeRepresentation ) override;
145 virtual css::uno::Reference< css::chart2::data::XDataSequence > SAL_CALL createDataSequenceByRangeRepresentation( const OUString& aRangeRepresentation ) override;
146 virtual css::uno::Reference< css::sheet::XRangeSelection > SAL_CALL getRangeSelection( ) override;
148 virtual css::uno::Reference<css::chart2::data::XDataSequence>
149 SAL_CALL createDataSequenceByValueArray(
150 const OUString& aRole, const OUString& aRangeRepresentation, const OUString& aRoleQualifier ) override;
152 // XRangeXMLConversion
153 virtual OUString SAL_CALL convertRangeToXML( const OUString& aRangeRepresentation ) override;
154 virtual OUString SAL_CALL convertRangeFromXML( const OUString& aXMLRange ) override;
156 // XComponent
157 virtual void SAL_CALL dispose( ) override;
158 virtual void SAL_CALL addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener ) override;
159 virtual void SAL_CALL removeEventListener( const css::uno::Reference< css::lang::XEventListener >& 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;
166 void AddDataSequence( const SwTable &rTable, rtl::Reference< SwChartDataSequence > const &rxDataSequence );
167 void RemoveDataSequence( const SwTable &rTable, rtl::Reference< SwChartDataSequence > const &rxDataSequence );
169 // will send modified events for all data-sequences of the table
170 // tdf#122995 added Immediate-Mode to allow non-timer-delayed Chart invalidation
171 void InvalidateTable( const SwTable *pTable, bool bImmediate = false );
172 void DeleteBox( const SwTable *pTable, const SwTableBox &rBox );
173 void DisposeAllDataSequences( const SwTable *pTable );
175 // functionality needed to get notified about new added rows/cols
176 void AddRowCols( const SwTable &rTable, const SwSelBoxes& rBoxes, sal_uInt16 nLines, bool bBehind );
179 typedef cppu::WeakImplHelper
181 css::chart2::data::XDataSource,
182 css::lang::XServiceInfo
184 SwChartDataSourceBaseClass;
186 class SwChartDataSource final :
187 public SwChartDataSourceBaseClass
189 css::uno::Sequence<
190 css::uno::Reference< css::chart2::data::XLabeledDataSequence > > m_aLDS;
192 SwChartDataSource( const SwChartDataSource & ) = delete;
193 SwChartDataSource & operator = ( const SwChartDataSource & ) = delete;
195 public:
196 SwChartDataSource( const css::uno::Sequence< css::uno::Reference< css::chart2::data::XLabeledDataSequence > > &rLDS );
197 virtual ~SwChartDataSource() override;
199 // XDataSource
200 virtual css::uno::Sequence< css::uno::Reference< css::chart2::data::XLabeledDataSequence > > SAL_CALL getDataSequences( ) override;
202 // XServiceInfo
203 virtual OUString SAL_CALL getImplementationName( ) override;
204 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
205 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
208 typedef cppu::WeakImplHelper
210 css::chart2::data::XDataSequence,
211 css::chart2::data::XTextualDataSequence,
212 css::chart2::data::XNumericalDataSequence,
213 css::util::XCloneable,
214 css::beans::XPropertySet,
215 css::lang::XServiceInfo,
216 css::util::XModifiable,
217 css::lang::XEventListener,
218 css::lang::XComponent
220 SwChartDataSequenceBaseClass;
222 class SwChartDataSequence final :
223 public SwChartDataSequenceBaseClass,
224 public SvtListener
226 SwFrameFormat* m_pFormat;
227 ::comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> m_aEvtListeners;
228 ::comphelper::OInterfaceContainerHelper4<css::util::XModifyListener> m_aModifyListeners;
229 css::chart2::data::DataSequenceRole m_aRole;
231 OUString m_aRowLabelText;
232 OUString m_aColLabelText;
234 rtl::Reference<SwChartDataProvider> m_xDataProvider;
236 sw::UnoCursorPointer m_pTableCursor; // cursor spanned over cells to use
238 const SfxItemPropertySet* m_pPropSet;
240 bool m_bDisposed;
242 SwChartDataSequence( const SwChartDataSequence &rObj );
243 SwChartDataSequence & operator = ( const SwChartDataSequence & ) = delete;
245 public:
246 SwChartDataSequence( SwChartDataProvider &rProvider,
247 SwFrameFormat &rTableFormat,
248 const std::shared_ptr<SwUnoCursor>& pTableCursor );
249 virtual ~SwChartDataSequence() override;
251 // XDataSequence
252 virtual css::uno::Sequence< css::uno::Any > SAL_CALL getData() override;
253 virtual OUString SAL_CALL getSourceRangeRepresentation() override;
254 virtual css::uno::Sequence< OUString > SAL_CALL generateLabel( css::chart2::data::LabelOrigin eLabelOrigin ) override;
255 virtual ::sal_Int32 SAL_CALL getNumberFormatKeyByIndex( ::sal_Int32 nIndex ) override;
257 // XTextualDataSequence
258 virtual css::uno::Sequence< OUString > SAL_CALL getTextualData() override;
260 // XNumericalDataSequence
261 virtual css::uno::Sequence< double > SAL_CALL getNumericalData() override;
263 // XCloneable
264 virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone( ) override;
266 // XPropertySet
267 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override;
268 virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue ) override;
269 virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
270 virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override;
271 virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override;
272 virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
273 virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
275 // XServiceInfo
276 virtual OUString SAL_CALL getImplementationName( ) override;
277 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
278 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
280 // XModifiable
281 virtual sal_Bool SAL_CALL isModified( ) override;
282 virtual void SAL_CALL setModified( sal_Bool bModified ) override;
284 // XModifyBroadcaster
285 virtual void SAL_CALL addModifyListener( const css::uno::Reference< css::util::XModifyListener >& aListener ) override;
286 virtual void SAL_CALL removeModifyListener( const css::uno::Reference< css::util::XModifyListener >& aListener ) override;
288 // XEventListener
289 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
291 // XComponent
292 virtual void SAL_CALL dispose( ) override;
293 virtual void SAL_CALL addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener ) override;
294 virtual void SAL_CALL removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) override;
296 SwFrameFormat* GetFrameFormat() const { return m_pFormat; }
297 bool DeleteBox( const SwTableBox &rBox );
299 void FillRangeDesc( SwRangeDescriptor &rRangeDesc ) const;
300 void ExtendTo( bool bExtendCol, sal_Int32 nFirstNew, sal_Int32 nCount );
301 std::vector< css::uno::Reference< css::table::XCell > > GetCells();
303 virtual void Notify(const SfxHint& rHint) override;
306 typedef cppu::WeakImplHelper
308 css::chart2::data::XLabeledDataSequence2,
309 css::lang::XServiceInfo,
310 css::util::XModifyListener,
311 css::lang::XComponent
313 SwChartLabeledDataSequenceBaseClass;
315 class SwChartLabeledDataSequence final :
316 public SwChartLabeledDataSequenceBaseClass
318 ::comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> m_aEventListeners;
319 ::comphelper::OInterfaceContainerHelper4<css::util::XModifyListener> m_aModifyListeners;
321 css::uno::Reference< css::chart2::data::XDataSequence > m_xData;
322 css::uno::Reference< css::chart2::data::XDataSequence > m_xLabels;
324 bool m_bDisposed;
326 SwChartLabeledDataSequence( const SwChartLabeledDataSequence & ) = delete;
327 SwChartLabeledDataSequence & operator = ( const SwChartLabeledDataSequence & ) = delete;
329 void SetDataSequence( css::uno::Reference< css::chart2::data::XDataSequence >& rxDest, const css::uno::Reference< css::chart2::data::XDataSequence >& rxSource );
331 public:
332 SwChartLabeledDataSequence();
333 virtual ~SwChartLabeledDataSequence() override;
335 // XLabeledDataSequence
336 virtual css::uno::Reference< css::chart2::data::XDataSequence > SAL_CALL getValues( ) override;
337 virtual void SAL_CALL setValues( const css::uno::Reference< css::chart2::data::XDataSequence >& xSequence ) override;
338 virtual css::uno::Reference< css::chart2::data::XDataSequence > SAL_CALL getLabel( ) override;
339 virtual void SAL_CALL setLabel( const css::uno::Reference< css::chart2::data::XDataSequence >& xSequence ) override;
341 // XCloneable
342 virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone( ) override;
344 // XServiceInfo
345 virtual OUString SAL_CALL getImplementationName( ) override;
346 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
347 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
349 // XEventListener
350 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
352 // XModifyListener
353 virtual void SAL_CALL modified( const css::lang::EventObject& aEvent ) override;
355 // XModifyBroadcaster
356 virtual void SAL_CALL addModifyListener( const css::uno::Reference< css::util::XModifyListener >& aListener ) override;
357 virtual void SAL_CALL removeModifyListener( const css::uno::Reference< css::util::XModifyListener >& aListener ) override;
359 // XComponent
360 virtual void SAL_CALL dispose( ) override;
361 virtual void SAL_CALL addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener ) override;
362 virtual void SAL_CALL removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) override;
365 #endif
367 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */