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/interfacecontainer4.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();
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::OInterfaceContainerHelper4
<css::lang::XEventListener
> 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 // tdf#122995 added Immediate-Mode to allow non-timer-delayed Chart invalidation
179 void InvalidateTable( const SwTable
*pTable
, bool bImmediate
= false );
180 void DeleteBox( const SwTable
*pTable
, const SwTableBox
&rBox
);
181 void DisposeAllDataSequences( const SwTable
*pTable
);
183 // functionality needed to get notified about new added rows/cols
184 void AddRowCols( const SwTable
&rTable
, const SwSelBoxes
& rBoxes
, sal_uInt16 nLines
, bool bBehind
);
187 typedef cppu::WeakImplHelper
189 css::chart2::data::XDataSource
,
190 css::lang::XServiceInfo
192 SwChartDataSourceBaseClass
;
194 class SwChartDataSource final
:
195 public SwChartDataSourceBaseClass
198 css::uno::Reference
< css::chart2::data::XLabeledDataSequence
> > m_aLDS
;
200 SwChartDataSource( const SwChartDataSource
& ) = delete;
201 SwChartDataSource
& operator = ( const SwChartDataSource
& ) = delete;
204 SwChartDataSource( const css::uno::Sequence
< css::uno::Reference
< css::chart2::data::XLabeledDataSequence
> > &rLDS
);
205 virtual ~SwChartDataSource() override
;
208 virtual css::uno::Sequence
< css::uno::Reference
< css::chart2::data::XLabeledDataSequence
> > SAL_CALL
getDataSequences( ) override
;
211 virtual OUString SAL_CALL
getImplementationName( ) override
;
212 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
213 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
216 typedef cppu::WeakImplHelper
218 css::chart2::data::XDataSequence
,
219 css::chart2::data::XTextualDataSequence
,
220 css::chart2::data::XNumericalDataSequence
,
221 css::util::XCloneable
,
222 css::beans::XPropertySet
,
223 css::lang::XServiceInfo
,
224 css::lang::XUnoTunnel
,
225 css::util::XModifiable
,
226 css::lang::XEventListener
,
227 css::lang::XComponent
229 SwChartDataSequenceBaseClass
;
231 class SwChartDataSequence final
:
232 public SwChartDataSequenceBaseClass
,
235 SwFrameFormat
* m_pFormat
;
236 ::comphelper::OInterfaceContainerHelper4
<css::lang::XEventListener
> m_aEvtListeners
;
237 ::comphelper::OInterfaceContainerHelper4
<css::util::XModifyListener
> m_aModifyListeners
;
238 css::chart2::data::DataSequenceRole m_aRole
;
240 OUString m_aRowLabelText
;
241 OUString m_aColLabelText
;
243 rtl::Reference
<SwChartDataProvider
> m_xDataProvider
;
245 sw::UnoCursorPointer m_pTableCursor
; // cursor spanned over cells to use
247 const SfxItemPropertySet
* m_pPropSet
;
251 SwChartDataSequence( const SwChartDataSequence
&rObj
);
252 SwChartDataSequence
& operator = ( const SwChartDataSequence
& ) = delete;
255 SwChartDataSequence( SwChartDataProvider
&rProvider
,
256 SwFrameFormat
&rTableFormat
,
257 const std::shared_ptr
<SwUnoCursor
>& pTableCursor
);
258 virtual ~SwChartDataSequence() override
;
260 static const css::uno::Sequence
< sal_Int8
> & getUnoTunnelId();
263 virtual sal_Int64 SAL_CALL
getSomething( const css::uno::Sequence
< sal_Int8
>& aIdentifier
) override
;
266 virtual css::uno::Sequence
< css::uno::Any
> SAL_CALL
getData() override
;
267 virtual OUString SAL_CALL
getSourceRangeRepresentation() override
;
268 virtual css::uno::Sequence
< OUString
> SAL_CALL
generateLabel( css::chart2::data::LabelOrigin eLabelOrigin
) override
;
269 virtual ::sal_Int32 SAL_CALL
getNumberFormatKeyByIndex( ::sal_Int32 nIndex
) override
;
271 // XTextualDataSequence
272 virtual css::uno::Sequence
< OUString
> SAL_CALL
getTextualData() override
;
274 // XNumericalDataSequence
275 virtual css::uno::Sequence
< double > SAL_CALL
getNumericalData() override
;
278 virtual css::uno::Reference
< css::util::XCloneable
> SAL_CALL
createClone( ) override
;
281 virtual css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) override
;
282 virtual void SAL_CALL
setPropertyValue( const OUString
& aPropertyName
, const css::uno::Any
& aValue
) override
;
283 virtual css::uno::Any SAL_CALL
getPropertyValue( const OUString
& PropertyName
) override
;
284 virtual void SAL_CALL
addPropertyChangeListener( const OUString
& aPropertyName
, const css::uno::Reference
< css::beans::XPropertyChangeListener
>& xListener
) override
;
285 virtual void SAL_CALL
removePropertyChangeListener( const OUString
& aPropertyName
, const css::uno::Reference
< css::beans::XPropertyChangeListener
>& aListener
) override
;
286 virtual void SAL_CALL
addVetoableChangeListener( const OUString
& PropertyName
, const css::uno::Reference
< css::beans::XVetoableChangeListener
>& aListener
) override
;
287 virtual void SAL_CALL
removeVetoableChangeListener( const OUString
& PropertyName
, const css::uno::Reference
< css::beans::XVetoableChangeListener
>& aListener
) override
;
290 virtual OUString SAL_CALL
getImplementationName( ) override
;
291 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
292 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
295 virtual sal_Bool SAL_CALL
isModified( ) override
;
296 virtual void SAL_CALL
setModified( sal_Bool bModified
) override
;
298 // XModifyBroadcaster
299 virtual void SAL_CALL
addModifyListener( const css::uno::Reference
< css::util::XModifyListener
>& aListener
) override
;
300 virtual void SAL_CALL
removeModifyListener( const css::uno::Reference
< css::util::XModifyListener
>& aListener
) override
;
303 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
) override
;
306 virtual void SAL_CALL
dispose( ) override
;
307 virtual void SAL_CALL
addEventListener( const css::uno::Reference
< css::lang::XEventListener
>& xListener
) override
;
308 virtual void SAL_CALL
removeEventListener( const css::uno::Reference
< css::lang::XEventListener
>& aListener
) override
;
310 SwFrameFormat
* GetFrameFormat() const { return m_pFormat
; }
311 bool DeleteBox( const SwTableBox
&rBox
);
313 void FillRangeDesc( SwRangeDescriptor
&rRangeDesc
) const;
314 void ExtendTo( bool bExtendCol
, sal_Int32 nFirstNew
, sal_Int32 nCount
);
315 std::vector
< css::uno::Reference
< css::table::XCell
> > GetCells();
317 virtual void Notify(const SfxHint
& rHint
) override
;
320 typedef cppu::WeakImplHelper
322 css::chart2::data::XLabeledDataSequence2
,
323 css::lang::XServiceInfo
,
324 css::util::XModifyListener
,
325 css::lang::XComponent
327 SwChartLabeledDataSequenceBaseClass
;
329 class SwChartLabeledDataSequence final
:
330 public SwChartLabeledDataSequenceBaseClass
332 ::comphelper::OInterfaceContainerHelper4
<css::lang::XEventListener
> m_aEventListeners
;
333 ::comphelper::OInterfaceContainerHelper4
<css::util::XModifyListener
> m_aModifyListeners
;
335 css::uno::Reference
< css::chart2::data::XDataSequence
> m_xData
;
336 css::uno::Reference
< css::chart2::data::XDataSequence
> m_xLabels
;
340 SwChartLabeledDataSequence( const SwChartLabeledDataSequence
& ) = delete;
341 SwChartLabeledDataSequence
& operator = ( const SwChartLabeledDataSequence
& ) = delete;
343 void SetDataSequence( css::uno::Reference
< css::chart2::data::XDataSequence
>& rxDest
, const css::uno::Reference
< css::chart2::data::XDataSequence
>& rxSource
);
346 SwChartLabeledDataSequence();
347 virtual ~SwChartLabeledDataSequence() override
;
349 // XLabeledDataSequence
350 virtual css::uno::Reference
< css::chart2::data::XDataSequence
> SAL_CALL
getValues( ) override
;
351 virtual void SAL_CALL
setValues( const css::uno::Reference
< css::chart2::data::XDataSequence
>& xSequence
) override
;
352 virtual css::uno::Reference
< css::chart2::data::XDataSequence
> SAL_CALL
getLabel( ) override
;
353 virtual void SAL_CALL
setLabel( const css::uno::Reference
< css::chart2::data::XDataSequence
>& xSequence
) override
;
356 virtual css::uno::Reference
< css::util::XCloneable
> SAL_CALL
createClone( ) override
;
359 virtual OUString SAL_CALL
getImplementationName( ) override
;
360 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
361 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
364 virtual void SAL_CALL
disposing( const css::lang::EventObject
& Source
) override
;
367 virtual void SAL_CALL
modified( const css::lang::EventObject
& aEvent
) override
;
369 // XModifyBroadcaster
370 virtual void SAL_CALL
addModifyListener( const css::uno::Reference
< css::util::XModifyListener
>& aListener
) override
;
371 virtual void SAL_CALL
removeModifyListener( const css::uno::Reference
< css::util::XModifyListener
>& aListener
) override
;
374 virtual void SAL_CALL
dispose( ) override
;
375 virtual void SAL_CALL
addEventListener( const css::uno::Reference
< css::lang::XEventListener
>& xListener
) override
;
376 virtual void SAL_CALL
removeEventListener( const css::uno::Reference
< css::lang::XEventListener
>& aListener
) override
;
381 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */