1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
25 #include <com/sun/star/lang/XUnoTunnel.hpp>
26 #include <com/sun/star/chart2/data/XDataProvider.hpp>
27 #include <com/sun/star/chart2/data/XDataSource.hpp>
28 #include <com/sun/star/chart2/data/XDataSequence.hpp>
29 #include <com/sun/star/chart2/data/XTextualDataSequence.hpp>
30 #include <com/sun/star/chart2/data/XNumericalDataSequence.hpp>
31 #include <com/sun/star/chart2/data/XLabeledDataSequence2.hpp>
32 #include <com/sun/star/chart2/data/XRangeXMLConversion.hpp>
33 #include <com/sun/star/chart2/data/DataSequenceRole.hpp>
34 #include <com/sun/star/lang/XServiceInfo.hpp>
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include <com/sun/star/util/XCloneable.hpp>
37 #include <com/sun/star/lang/XComponent.hpp>
38 #include <com/sun/star/lang/XEventListener.hpp>
39 #include <com/sun/star/util/XModifiable.hpp>
40 #include <com/sun/star/util/XModifyListener.hpp>
42 #include <comphelper/interfacecontainer2.hxx>
43 #include <cppuhelper/implbase.hxx>
44 #include <cppuhelper/weakref.hxx>
46 #include <rtl/ref.hxx>
47 #include <svl/listener.hxx>
48 #include <tools/link.hxx>
49 #include <vcl/timer.hxx>
52 #include "unocrsr.hxx"
54 class SfxItemPropertySet
;
58 struct SwRangeDescriptor
;
60 namespace com::sun::star::table
{ class XCell
; }
62 bool FillRangeDescriptor( SwRangeDescriptor
&rDesc
, const OUString
&rCellRangeName
);
67 static void DoUpdateAllCharts( SwDoc
* pDoc
);
70 class SwChartLockController_Helper
74 DECL_LINK( DoUnlockAllCharts
, Timer
*, void );
75 Timer m_aUnlockTimer
; // timer to unlock chart controllers
78 SwChartLockController_Helper( const SwChartLockController_Helper
& ) = delete;
79 SwChartLockController_Helper
& operator = ( const SwChartLockController_Helper
& ) = delete;
81 void LockUnlockAllCharts( bool bLock
);
82 void LockAllCharts() { LockUnlockAllCharts( true ); };
83 void UnlockAllCharts() { LockUnlockAllCharts( false ); };
86 SwChartLockController_Helper( SwDoc
*pDocument
);
87 ~SwChartLockController_Helper() COVERITY_NOEXCEPT_FALSE
;
89 void StartOrContinueLocking();
93 typedef cppu::WeakImplHelper
95 css::chart2::data::XDataProvider
,
96 css::chart2::data::XRangeXMLConversion
,
97 css::lang::XComponent
,
98 css::lang::XServiceInfo
100 SwChartDataProviderBaseClass
;
102 class SwChartDataProvider final
:
103 public SwChartDataProviderBaseClass
106 // used to keep weak-references to all data-sequences of a single table
107 // see set definition below...
108 struct lt_DataSequenceRef
110 bool operator()( css::uno::WeakReference
< css::chart2::data::XDataSequence
> xWRef1
, css::uno::WeakReference
< css::chart2::data::XDataSequence
> xWRef2
) const
112 css::uno::Reference
< css::chart2::data::XDataSequence
> xRef1( xWRef1
);
113 css::uno::Reference
< css::chart2::data::XDataSequence
> xRef2( xWRef2
);
114 return xRef1
.get() < xRef2
.get();
117 typedef std::set
< css::uno::WeakReference
< css::chart2::data::XDataSequence
>, lt_DataSequenceRef
> Set_DataSequenceRef_t
;
119 // map of data-sequence sets for each table
120 typedef std::map
< const SwTable
*, Set_DataSequenceRef_t
> Map_Set_DataSequenceRef_t
;
122 // map of all data-sequences provided directly or indirectly (e.g. via
123 // data-source) by this object. Since there is only one object of this type
124 // for each document it should hold references to all used data-sequences for
125 // all tables of the document.
126 mutable Map_Set_DataSequenceRef_t m_aDataSequences
;
128 ::comphelper::OInterfaceContainerHelper2 m_aEventListeners
;
129 const SwDoc
* m_pDoc
;
132 SwChartDataProvider( const SwChartDataProvider
& ) = delete;
133 SwChartDataProvider
& operator = ( const SwChartDataProvider
& ) = delete;
135 /// @throws css::lang::IllegalArgumentException
136 /// @throws css::uno::RuntimeException
137 css::uno::Reference
< css::chart2::data::XDataSource
> Impl_createDataSource( const css::uno::Sequence
< css::beans::PropertyValue
>& aArguments
, bool bTestOnly
= false );
138 /// @throws css::lang::IllegalArgumentException
139 /// @throws css::uno::RuntimeException
140 css::uno::Reference
< css::chart2::data::XDataSequence
> Impl_createDataSequenceByRangeRepresentation( const OUString
& aRangeRepresentation
, bool bTestOnly
= false );
142 static OUString
GetBrokenCellRangeForExport( const OUString
&rCellRangeRepresentation
);
145 SwChartDataProvider( const SwDoc
& rDoc
);
146 virtual ~SwChartDataProvider() override
;
149 virtual sal_Bool SAL_CALL
createDataSourcePossible( const css::uno::Sequence
< css::beans::PropertyValue
>& aArguments
) override
;
150 virtual css::uno::Reference
< css::chart2::data::XDataSource
> SAL_CALL
createDataSource( const css::uno::Sequence
< css::beans::PropertyValue
>& aArguments
) override
;
151 virtual css::uno::Sequence
< css::beans::PropertyValue
> SAL_CALL
detectArguments( const css::uno::Reference
< css::chart2::data::XDataSource
>& xDataSource
) override
;
152 virtual sal_Bool SAL_CALL
createDataSequenceByRangeRepresentationPossible( const OUString
& aRangeRepresentation
) override
;
153 virtual css::uno::Reference
< css::chart2::data::XDataSequence
> SAL_CALL
createDataSequenceByRangeRepresentation( const OUString
& aRangeRepresentation
) override
;
154 virtual css::uno::Reference
< css::sheet::XRangeSelection
> SAL_CALL
getRangeSelection( ) override
;
156 virtual css::uno::Reference
<css::chart2::data::XDataSequence
>
157 SAL_CALL
createDataSequenceByValueArray(
158 const OUString
& aRole
, const OUString
& aRangeRepresentation
, const OUString
& aRoleQualifier
) override
;
160 // XRangeXMLConversion
161 virtual OUString SAL_CALL
convertRangeToXML( const OUString
& aRangeRepresentation
) override
;
162 virtual OUString SAL_CALL
convertRangeFromXML( const OUString
& aXMLRange
) override
;
165 virtual void SAL_CALL
dispose( ) override
;
166 virtual void SAL_CALL
addEventListener( const css::uno::Reference
< css::lang::XEventListener
>& xListener
) override
;
167 virtual void SAL_CALL
removeEventListener( const css::uno::Reference
< css::lang::XEventListener
>& aListener
) override
;
170 virtual OUString SAL_CALL
getImplementationName( ) override
;
171 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
172 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
174 void AddDataSequence( const SwTable
&rTable
, css::uno::Reference
< css::chart2::data::XDataSequence
> const &rxDataSequence
);
175 void RemoveDataSequence( const SwTable
&rTable
, css::uno::Reference
< css::chart2::data::XDataSequence
> const &rxDataSequence
);
177 // will send modified events for all data-sequences of the table
178 void InvalidateTable( const SwTable
*pTable
);
179 void DeleteBox( const SwTable
*pTable
, const SwTableBox
&rBox
);
180 void DisposeAllDataSequences( const SwTable
*pTable
);
182 // functionality needed to get notified about new added rows/cols
183 void AddRowCols( const SwTable
&rTable
, const SwSelBoxes
& rBoxes
, sal_uInt16 nLines
, bool bBehind
);
186 typedef cppu::WeakImplHelper
188 css::chart2::data::XDataSource
,
189 css::lang::XServiceInfo
191 SwChartDataSourceBaseClass
;
193 class SwChartDataSource final
:
194 public SwChartDataSourceBaseClass
197 css::uno::Reference
< css::chart2::data::XLabeledDataSequence
> > m_aLDS
;
199 SwChartDataSource( const SwChartDataSource
& ) = delete;
200 SwChartDataSource
& operator = ( const SwChartDataSource
& ) = delete;
203 SwChartDataSource( const css::uno::Sequence
< css::uno::Reference
< css::chart2::data::XLabeledDataSequence
> > &rLDS
);
204 virtual ~SwChartDataSource() override
;
207 virtual css::uno::Sequence
< css::uno::Reference
< css::chart2::data::XLabeledDataSequence
> > SAL_CALL
getDataSequences( ) override
;
210 virtual OUString SAL_CALL
getImplementationName( ) override
;
211 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
212 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
215 typedef cppu::WeakImplHelper
217 css::chart2::data::XDataSequence
,
218 css::chart2::data::XTextualDataSequence
,
219 css::chart2::data::XNumericalDataSequence
,
220 css::util::XCloneable
,
221 css::beans::XPropertySet
,
222 css::lang::XServiceInfo
,
223 css::lang::XUnoTunnel
,
224 css::util::XModifiable
,
225 css::lang::XEventListener
,
226 css::lang::XComponent
228 SwChartDataSequenceBaseClass
;
230 class SwChartDataSequence final
:
231 public SwChartDataSequenceBaseClass
,
234 SwFrameFormat
* m_pFormat
;
235 ::comphelper::OInterfaceContainerHelper2 m_aEvtListeners
;
236 ::comphelper::OInterfaceContainerHelper2 m_aModifyListeners
;
237 css::chart2::data::DataSequenceRole m_aRole
;
239 OUString m_aRowLabelText
;
240 OUString m_aColLabelText
;
242 rtl::Reference
<SwChartDataProvider
> m_xDataProvider
;
244 sw::UnoCursorPointer m_pTableCursor
; // cursor spanned over cells to use
246 const SfxItemPropertySet
* m_pPropSet
;
250 SwChartDataSequence( const SwChartDataSequence
&rObj
);
251 SwChartDataSequence
& operator = ( const SwChartDataSequence
& ) = delete;
254 SwChartDataSequence( SwChartDataProvider
&rProvider
,
255 SwFrameFormat
&rTableFormat
,
256 const std::shared_ptr
<SwUnoCursor
>& pTableCursor
);
257 virtual ~SwChartDataSequence() override
;
259 static const css::uno::Sequence
< sal_Int8
> & getUnoTunnelId();
262 virtual sal_Int64 SAL_CALL
getSomething( const css::uno::Sequence
< sal_Int8
>& aIdentifier
) override
;
265 virtual css::uno::Sequence
< css::uno::Any
> SAL_CALL
getData() override
;
266 virtual OUString SAL_CALL
getSourceRangeRepresentation() override
;
267 virtual css::uno::Sequence
< OUString
> SAL_CALL
generateLabel( css::chart2::data::LabelOrigin eLabelOrigin
) override
;
268 virtual ::sal_Int32 SAL_CALL
getNumberFormatKeyByIndex( ::sal_Int32 nIndex
) override
;
270 // XTextualDataSequence
271 virtual css::uno::Sequence
< OUString
> SAL_CALL
getTextualData() override
;
273 // XNumericalDataSequence
274 virtual css::uno::Sequence
< double > SAL_CALL
getNumericalData() override
;
277 virtual css::uno::Reference
< css::util::XCloneable
> SAL_CALL
createClone( ) override
;
280 virtual css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) override
;
281 virtual void SAL_CALL
setPropertyValue( const OUString
& aPropertyName
, const css::uno::Any
& aValue
) override
;
282 virtual css::uno::Any SAL_CALL
getPropertyValue( const OUString
& PropertyName
) override
;
283 virtual void SAL_CALL
addPropertyChangeListener( const OUString
& aPropertyName
, const css::uno::Reference
< css::beans::XPropertyChangeListener
>& xListener
) override
;
284 virtual void SAL_CALL
removePropertyChangeListener( const OUString
& aPropertyName
, const css::uno::Reference
< css::beans::XPropertyChangeListener
>& aListener
) override
;
285 virtual void SAL_CALL
addVetoableChangeListener( const OUString
& PropertyName
, const css::uno::Reference
< css::beans::XVetoableChangeListener
>& aListener
) override
;
286 virtual void SAL_CALL
removeVetoableChangeListener( const OUString
& PropertyName
, const css::uno::Reference
< css::beans::XVetoableChangeListener
>& aListener
) override
;
289 virtual OUString SAL_CALL
getImplementationName( ) override
;
290 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
291 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
294 virtual sal_Bool SAL_CALL
isModified( ) override
;
295 virtual void SAL_CALL
setModified( sal_Bool bModified
) override
;
297 // XModifyBroadcaster
298 virtual void SAL_CALL
addModifyListener( const css::uno::Reference
< css::util::XModifyListener
>& aListener
) override
;
299 virtual void SAL_CALL
removeModifyListener( const css::uno::Reference
< css::util::XModifyListener
>& aListener
) override
;
302 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
) override
;
305 virtual void SAL_CALL
dispose( ) override
;
306 virtual void SAL_CALL
addEventListener( const css::uno::Reference
< css::lang::XEventListener
>& xListener
) override
;
307 virtual void SAL_CALL
removeEventListener( const css::uno::Reference
< css::lang::XEventListener
>& aListener
) override
;
309 SwFrameFormat
* GetFrameFormat() const { return m_pFormat
; }
310 bool DeleteBox( const SwTableBox
&rBox
);
312 void FillRangeDesc( SwRangeDescriptor
&rRangeDesc
) const;
313 void ExtendTo( bool bExtendCol
, sal_Int32 nFirstNew
, sal_Int32 nCount
);
314 std::vector
< css::uno::Reference
< css::table::XCell
> > GetCells();
316 virtual void Notify(const SfxHint
& rHint
) override
;
319 typedef cppu::WeakImplHelper
321 css::chart2::data::XLabeledDataSequence2
,
322 css::lang::XServiceInfo
,
323 css::util::XModifyListener
,
324 css::lang::XComponent
326 SwChartLabeledDataSequenceBaseClass
;
328 class SwChartLabeledDataSequence final
:
329 public SwChartLabeledDataSequenceBaseClass
331 ::comphelper::OInterfaceContainerHelper2 m_aEventListeners
;
332 ::comphelper::OInterfaceContainerHelper2 m_aModifyListeners
;
334 css::uno::Reference
< css::chart2::data::XDataSequence
> m_xData
;
335 css::uno::Reference
< css::chart2::data::XDataSequence
> m_xLabels
;
339 SwChartLabeledDataSequence( const SwChartLabeledDataSequence
& ) = delete;
340 SwChartLabeledDataSequence
& operator = ( const SwChartLabeledDataSequence
& ) = delete;
342 void SetDataSequence( css::uno::Reference
< css::chart2::data::XDataSequence
>& rxDest
, const css::uno::Reference
< css::chart2::data::XDataSequence
>& rxSource
);
345 SwChartLabeledDataSequence();
346 virtual ~SwChartLabeledDataSequence() override
;
348 // XLabeledDataSequence
349 virtual css::uno::Reference
< css::chart2::data::XDataSequence
> SAL_CALL
getValues( ) override
;
350 virtual void SAL_CALL
setValues( const css::uno::Reference
< css::chart2::data::XDataSequence
>& xSequence
) override
;
351 virtual css::uno::Reference
< css::chart2::data::XDataSequence
> SAL_CALL
getLabel( ) override
;
352 virtual void SAL_CALL
setLabel( const css::uno::Reference
< css::chart2::data::XDataSequence
>& xSequence
) override
;
355 virtual css::uno::Reference
< css::util::XCloneable
> SAL_CALL
createClone( ) override
;
358 virtual OUString SAL_CALL
getImplementationName( ) override
;
359 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
360 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
363 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
) override
;
366 virtual void SAL_CALL
modified( const css::lang::EventObject
& aEvent
) override
;
368 // XModifyBroadcaster
369 virtual void SAL_CALL
addModifyListener( const css::uno::Reference
< css::util::XModifyListener
>& aListener
) override
;
370 virtual void SAL_CALL
removeModifyListener( const css::uno::Reference
< css::util::XModifyListener
>& aListener
) override
;
373 virtual void SAL_CALL
dispose( ) override
;
374 virtual void SAL_CALL
addEventListener( const css::uno::Reference
< css::lang::XEventListener
>& xListener
) override
;
375 virtual void SAL_CALL
removeEventListener( const css::uno::Reference
< css::lang::XEventListener
>& aListener
) override
;
380 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */