Coverage Report

Created: 2025-12-31 10:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sw/inc/unochart.hxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
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/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
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 .
18
 */
19
#ifndef INCLUDED_SW_INC_UNOCHART_HXX
20
#define INCLUDED_SW_INC_UNOCHART_HXX
21
22
#include <map>
23
#include <vector>
24
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>
40
41
#include <comphelper/interfacecontainer4.hxx>
42
#include <cppuhelper/implbase.hxx>
43
#include <cppuhelper/weakref.hxx>
44
45
#include <rtl/ref.hxx>
46
#include <svl/listener.hxx>
47
#include <tools/link.hxx>
48
#include <vcl/timer.hxx>
49
50
#include "frmfmt.hxx"
51
#include "unocrsr.hxx"
52
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; }
60
61
bool FillRangeDescriptor( SwRangeDescriptor &rDesc, std::u16string_view rCellRangeName );
62
63
class SwChartHelper
64
{
65
public:
66
    static void DoUpdateAllCharts( SwDoc* pDoc );
67
};
68
69
class SwChartLockController_Helper
70
{
71
    SwDoc   *m_pDoc;
72
73
    DECL_LINK( DoUnlockAllCharts, Timer *, void );
74
    Timer   m_aUnlockTimer;   // timer to unlock chart controllers
75
    bool    m_bIsLocked;
76
77
    SwChartLockController_Helper( const SwChartLockController_Helper & ) = delete;
78
    SwChartLockController_Helper & operator = ( const SwChartLockController_Helper & ) = delete;
79
80
    void LockUnlockAllCharts( bool bLock );
81
0
    void LockAllCharts()    { LockUnlockAllCharts( true ); };
82
82.5k
    void UnlockAllCharts()  { LockUnlockAllCharts( false ); };
83
84
public:
85
    SwChartLockController_Helper( SwDoc *pDocument );
86
    ~SwChartLockController_Helper();
87
88
    void StartOrContinueLocking();
89
    void Disconnect();
90
};
91
92
class SwChartDataSequence;
93
94
typedef cppu::WeakImplHelper
95
<
96
    css::chart2::data::XDataProvider,
97
    css::chart2::data::XRangeXMLConversion,
98
    css::lang::XComponent,
99
    css::lang::XServiceInfo
100
>
101
SwChartDataProviderBaseClass;
102
103
class SwChartDataProvider final :
104
    public SwChartDataProviderBaseClass
105
{
106
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;
110
111
    // map of data-sequence sets for each table
112
    typedef std::map< const SwTable *, Vec_DataSequenceRef_t > Map_Set_DataSequenceRef_t;
113
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;
119
120
    ::comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> m_aEventListeners;
121
    const SwDoc *                           m_pDoc;
122
    bool                                    m_bDisposed;
123
124
    SwChartDataProvider( const SwChartDataProvider & ) = delete;
125
    SwChartDataProvider & operator = ( const SwChartDataProvider & ) = delete;
126
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 );
133
134
    static OUString GetBrokenCellRangeForExport( std::u16string_view rCellRangeRepresentation );
135
136
public:
137
    SwChartDataProvider( const SwDoc& rDoc );
138
    virtual ~SwChartDataProvider() override;
139
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;
147
148
    virtual css::uno::Reference<css::chart2::data::XDataSequence>
149
        SAL_CALL createDataSequenceByValueArray(
150
            const OUString& aRole, const OUString& aRangeRepresentation, const OUString& aRoleQualifier ) override;
151
152
    // XRangeXMLConversion
153
    virtual OUString SAL_CALL convertRangeToXML( const OUString& aRangeRepresentation ) override;
154
    virtual OUString SAL_CALL convertRangeFromXML( const OUString& aXMLRange ) override;
155
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;
160
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;
165
166
    void        AddDataSequence( const SwTable &rTable, rtl::Reference< SwChartDataSequence > const &rxDataSequence );
167
    void        RemoveDataSequence( const SwTable &rTable, rtl::Reference< SwChartDataSequence > const &rxDataSequence );
168
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 );
174
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 );
177
};
178
179
typedef cppu::WeakImplHelper
180
<
181
    css::chart2::data::XDataSource,
182
    css::lang::XServiceInfo
183
>
184
SwChartDataSourceBaseClass;
185
186
class SwChartDataSource final :
187
    public SwChartDataSourceBaseClass
188
{
189
    css::uno::Sequence<
190
        css::uno::Reference< css::chart2::data::XLabeledDataSequence > > m_aLDS;
191
192
    SwChartDataSource( const SwChartDataSource & ) = delete;
193
    SwChartDataSource & operator = ( const SwChartDataSource & ) = delete;
194
195
public:
196
    SwChartDataSource( const css::uno::Sequence< css::uno::Reference< css::chart2::data::XLabeledDataSequence > > &rLDS );
197
    virtual ~SwChartDataSource() override;
198
199
    // XDataSource
200
    virtual css::uno::Sequence< css::uno::Reference< css::chart2::data::XLabeledDataSequence > > SAL_CALL getDataSequences(  ) override;
201
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;
206
};
207
208
typedef cppu::WeakImplHelper
209
<
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
219
>
220
SwChartDataSequenceBaseClass;
221
222
class SwChartDataSequence final :
223
    public SwChartDataSequenceBaseClass,
224
    public SvtListener
225
{
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;
230
231
    OUString  m_aRowLabelText;
232
    OUString  m_aColLabelText;
233
234
    rtl::Reference<SwChartDataProvider>                m_xDataProvider;
235
236
    sw::UnoCursorPointer m_pTableCursor;   // cursor spanned over cells to use
237
238
    const SfxItemPropertySet*   m_pPropSet;
239
240
    bool    m_bDisposed;
241
242
    SwChartDataSequence( const SwChartDataSequence &rObj );
243
    SwChartDataSequence & operator = ( const SwChartDataSequence & ) = delete;
244
245
public:
246
    SwChartDataSequence( SwChartDataProvider &rProvider,
247
                         SwFrameFormat   &rTableFormat,
248
                         const std::shared_ptr<SwUnoCursor>& pTableCursor );
249
    virtual ~SwChartDataSequence() override;
250
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;
256
257
    // XTextualDataSequence
258
    virtual css::uno::Sequence< OUString > SAL_CALL getTextualData() override;
259
260
    // XNumericalDataSequence
261
    virtual css::uno::Sequence< double > SAL_CALL getNumericalData() override;
262
263
    // XCloneable
264
    virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone(  ) override;
265
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;
274
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;
279
280
    // XModifiable
281
    virtual sal_Bool SAL_CALL isModified(  ) override;
282
    virtual void SAL_CALL setModified( sal_Bool bModified ) override;
283
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;
287
288
    // XEventListener
289
    virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
290
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;
295
296
0
    SwFrameFormat* GetFrameFormat() const { return m_pFormat; }
297
    bool DeleteBox( const SwTableBox &rBox );
298
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();
302
303
    virtual void Notify(const SfxHint& rHint) override;
304
};
305
306
typedef cppu::WeakImplHelper
307
<
308
    css::chart2::data::XLabeledDataSequence2,
309
    css::lang::XServiceInfo,
310
    css::util::XModifyListener,
311
    css::lang::XComponent
312
>
313
SwChartLabeledDataSequenceBaseClass;
314
315
class SwChartLabeledDataSequence final :
316
    public SwChartLabeledDataSequenceBaseClass
317
{
318
    ::comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> m_aEventListeners;
319
    ::comphelper::OInterfaceContainerHelper4<css::util::XModifyListener> m_aModifyListeners;
320
321
    css::uno::Reference< css::chart2::data::XDataSequence >     m_xData;
322
    css::uno::Reference< css::chart2::data::XDataSequence >     m_xLabels;
323
324
    bool    m_bDisposed;
325
326
    SwChartLabeledDataSequence( const SwChartLabeledDataSequence & ) = delete;
327
    SwChartLabeledDataSequence & operator = ( const SwChartLabeledDataSequence & ) = delete;
328
329
    void    SetDataSequence( css::uno::Reference< css::chart2::data::XDataSequence >& rxDest, const css::uno::Reference< css::chart2::data::XDataSequence >& rxSource );
330
331
public:
332
    SwChartLabeledDataSequence();
333
    virtual ~SwChartLabeledDataSequence() override;
334
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;
340
341
    // XCloneable
342
    virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone(  ) override;
343
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;
348
349
    // XEventListener
350
    virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
351
352
    // XModifyListener
353
    virtual void SAL_CALL modified( const css::lang::EventObject& aEvent ) override;
354
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;
358
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;
363
};
364
365
#endif
366
367
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */