LibreOffice Module sw (master)  1
unochart.hxx
Go to the documentation of this file.
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 <set>
24 
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>
41 
43 #include <cppuhelper/implbase.hxx>
44 #include <cppuhelper/weakref.hxx>
45 
46 #include <rtl/ref.hxx>
47 #include <svl/listener.hxx>
48 #include <tools/link.hxx>
49 #include <vcl/timer.hxx>
50 
51 #include "frmfmt.hxx"
52 #include "unocrsr.hxx"
53 
54 class SfxItemPropertySet;
55 class SwDoc;
56 class SwTable;
57 class SwTableBox;
58 struct SwRangeDescriptor;
59 class SwSelBoxes;
60 namespace com { namespace sun { namespace star { namespace table { class XCell; } } } }
61 
62 bool FillRangeDescriptor( SwRangeDescriptor &rDesc, const OUString &rCellRangeName );
63 
65 {
66 public:
67  static void DoUpdateAllCharts( SwDoc* pDoc );
68 };
69 
71 {
73 
74  DECL_LINK( DoUnlockAllCharts, Timer *, void );
75  Timer aUnlockTimer; // timer to unlock chart controllers
76  bool bIsLocked;
77 
80 
81  void LockUnlockAllCharts( bool bLock );
82  void LockAllCharts() { LockUnlockAllCharts( true ); };
83  void UnlockAllCharts() { LockUnlockAllCharts( false ); };
84 
85 public:
86  SwChartLockController_Helper( SwDoc *pDocument );
87  ~SwChartLockController_Helper() COVERITY_NOEXCEPT_FALSE;
88 
90  void Disconnect();
91 };
92 
93 typedef cppu::WeakImplHelper
94 <
95  css::chart2::data::XDataProvider,
96  css::chart2::data::XRangeXMLConversion,
97  css::lang::XComponent,
98  css::lang::XServiceInfo
99 >
101 
104 {
105 
106  // used to keep weak-references to all data-sequences of a single table
107  // see set definition below...
109  {
110  bool operator()( css::uno::WeakReference< css::chart2::data::XDataSequence > xWRef1, css::uno::WeakReference< css::chart2::data::XDataSequence > xWRef2 ) const
111  {
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();
115  }
116  };
117  typedef std::set< css::uno::WeakReference < css::chart2::data::XDataSequence >, lt_DataSequenceRef > Set_DataSequenceRef_t;
118 
119  // map of data-sequence sets for each table
120  typedef std::map< const SwTable *, Set_DataSequenceRef_t > Map_Set_DataSequenceRef_t;
121 
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 aDataSequences;
127 
129  const SwDoc * pDoc;
130  bool bDisposed;
131 
132  SwChartDataProvider( const SwChartDataProvider & ) = delete;
134 
137  css::uno::Reference< css::chart2::data::XDataSource > Impl_createDataSource( const css::uno::Sequence< css::beans::PropertyValue >& aArguments, bool bTestOnly = false );
140  css::uno::Reference< css::chart2::data::XDataSequence > Impl_createDataSequenceByRangeRepresentation( const OUString& aRangeRepresentation, bool bTestOnly = false );
141 
142  static OUString GetBrokenCellRangeForExport( const OUString &rCellRangeRepresentation );
143 
144 public:
145  SwChartDataProvider( const SwDoc* pDoc );
146  virtual ~SwChartDataProvider() override;
147 
148  // XDataProvider
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;
155 
156  virtual css::uno::Reference<css::chart2::data::XDataSequence>
157  SAL_CALL createDataSequenceByValueArray(
158  const OUString& aRole, const OUString& aRangeRepresentation ) override;
159 
160  // XRangeXMLConversion
161  virtual OUString SAL_CALL convertRangeToXML( const OUString& aRangeRepresentation ) override;
162  virtual OUString SAL_CALL convertRangeFromXML( const OUString& aXMLRange ) override;
163 
164  // XComponent
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;
168 
169  // XServiceInfo
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;
173 
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 );
176 
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 );
181 
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 );
184 };
185 
186 typedef cppu::WeakImplHelper
187 <
188  css::chart2::data::XDataSource,
189  css::lang::XServiceInfo
190 >
192 
195 {
196  css::uno::Sequence<
197  css::uno::Reference< css::chart2::data::XLabeledDataSequence > > aLDS;
198 
199  SwChartDataSource( const SwChartDataSource & ) = delete;
200  SwChartDataSource & operator = ( const SwChartDataSource & ) = delete;
201 
202 public:
203  SwChartDataSource( const css::uno::Sequence< css::uno::Reference< css::chart2::data::XLabeledDataSequence > > &rLDS );
204  virtual ~SwChartDataSource() override;
205 
206  // XDataSource
207  virtual css::uno::Sequence< css::uno::Reference< css::chart2::data::XLabeledDataSequence > > SAL_CALL getDataSequences( ) override;
208 
209  // XServiceInfo
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;
213 };
214 
215 typedef cppu::WeakImplHelper
216 <
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
227 >
229 
232  public SvtListener
233 {
237  css::chart2::data::DataSequenceRole m_aRole;
238 
239  OUString const m_aRowLabelText;
240  OUString const m_aColLabelText;
241 
243 
244  sw::UnoCursorPointer m_pTableCursor; // cursor spanned over cells to use
245 
247 
249 
252 
253 public:
255  SwFrameFormat &rTableFormat,
256  const std::shared_ptr<SwUnoCursor>& pTableCursor );
257  virtual ~SwChartDataSequence() override;
258 
259  static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId();
260 
261  //XUnoTunnel
262  virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override;
263 
264  // XDataSequence
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;
269 
270  // XTextualDataSequence
271  virtual css::uno::Sequence< OUString > SAL_CALL getTextualData() override;
272 
273  // XNumericalDataSequence
274  virtual css::uno::Sequence< double > SAL_CALL getNumericalData() override;
275 
276  // XCloneable
277  virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone( ) override;
278 
279  // XPropertySet
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;
287 
288  // XServiceInfo
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;
292 
293  // XModifiable
294  virtual sal_Bool SAL_CALL isModified( ) override;
295  virtual void SAL_CALL setModified( sal_Bool bModified ) override;
296 
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;
300 
301  // XEventListener
302  virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
303 
304  // XComponent
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;
308 
309  SwFrameFormat* GetFrameFormat() const { return m_pFormat; }
310  bool DeleteBox( const SwTableBox &rBox );
311 
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();
315 
316  virtual void Notify(const SfxHint& rHint) override;
317 };
318 
319 typedef cppu::WeakImplHelper
320 <
321  css::chart2::data::XLabeledDataSequence2,
322  css::lang::XServiceInfo,
323  css::util::XModifyListener,
324  css::lang::XComponent
325 >
327 
330 {
333 
334  css::uno::Reference< css::chart2::data::XDataSequence > xData;
335  css::uno::Reference< css::chart2::data::XDataSequence > xLabels;
336 
337  bool bDisposed;
338 
341 
342  void SetDataSequence( css::uno::Reference< css::chart2::data::XDataSequence >& rxDest, const css::uno::Reference< css::chart2::data::XDataSequence >& rxSource );
343 
344 public:
346  virtual ~SwChartLabeledDataSequence() override;
347 
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;
353 
354  // XCloneable
355  virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone( ) override;
356 
357  // XServiceInfo
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;
361 
362  // XEventListener
363  virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
364 
365  // XModifyListener
366  virtual void SAL_CALL modified( const css::lang::EventObject& aEvent ) override;
367 
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;
371 
372  // XComponent
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;
376 };
377 
378 #endif
379 
380 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void Notify(SwFlyFrame *pFly, SwPageFrame *pOld, const SwRect &rOld, const SwRect *pOldRect=nullptr)
Notify the background based on the difference between old and new rectangle.
Definition: frmtool.cxx:2924
::comphelper::OInterfaceContainerHelper2 aEvtListeners
Definition: unochart.hxx:331
SwChartLockController_Helper(const SwChartLockController_Helper &)=delete
cppu::WeakImplHelper< css::chart2::data::XDataSource, css::lang::XServiceInfo > SwChartDataSourceBaseClass
Definition: unochart.hxx:191
~SwChartLockController_Helper() COVERITY_NOEXCEPT_FALSE
Definition: unochart.cxx:97
Definition: doc.hxx:185
css::uno::Reference< css::chart2::data::XDataSequence > xLabels
Definition: unochart.hxx:335
OUString getImplementationName()
OUString const m_aRowLabelText
Definition: unochart.hxx:239
const SwDoc * pDoc
Definition: unochart.hxx:129
std::set< css::uno::WeakReference< css::chart2::data::XDataSequence >, lt_DataSequenceRef > Set_DataSequenceRef_t
Definition: unochart.hxx:117
bool operator()(css::uno::WeakReference< css::chart2::data::XDataSequence > xWRef1, css::uno::WeakReference< css::chart2::data::XDataSequence > xWRef2) const
Definition: unochart.hxx:110
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
SwChartLockController_Helper & operator=(const SwChartLockController_Helper &)=delete
cppu::WeakImplHelper< css::chart2::data::XLabeledDataSequence2, css::lang::XServiceInfo, css::util::XModifyListener, css::lang::XComponent > SwChartLabeledDataSequenceBaseClass
Definition: unochart.hxx:326
css::uno::Reference< css::chart2::data::XDataSequence > xData
Definition: unochart.hxx:334
bool FillRangeDescriptor(SwRangeDescriptor &rDesc, const OUString &rCellRangeName)
rCellRangeName needs to be of one of the following formats:
Definition: unochart.cxx:181
std::map< const SwTable *, Set_DataSequenceRef_t > Map_Set_DataSequenceRef_t
Definition: unochart.hxx:120
cppu::WeakImplHelper< css::chart2::data::XDataProvider, css::chart2::data::XRangeXMLConversion, css::lang::XComponent, css::lang::XServiceInfo > SwChartDataProviderBaseClass
Definition: unochart.hxx:100
Style of a layout element.
Definition: frmfmt.hxx:57
::comphelper::OInterfaceContainerHelper2 m_aEvtListeners
Definition: unochart.hxx:235
css::uno::Sequence< OUString > getSupportedServiceNames()
SwFrameFormat * m_pFormat
Definition: unochart.hxx:234
OUString const m_aColLabelText
Definition: unochart.hxx:240
rtl::Reference< SwChartDataProvider > m_xDataProvider
Definition: unochart.hxx:242
sw::UnoCursorPointer m_pTableCursor
Definition: unochart.hxx:244
SwFrameFormat * GetFrameFormat() const
Definition: unochart.hxx:309
::comphelper::OInterfaceContainerHelper2 m_aModifyListeners
Definition: unochart.hxx:236
unsigned char sal_Bool
bool setPropertyValue(uno::Sequence< beans::PropertyValue > &aProp, const OUString &aName, const uno::Any &aValue)
SwTable is one table in the document model, containing rows (which contain cells).
Definition: swtable.hxx:110
const SfxItemPropertySet * m_pPropSet
Definition: unochart.hxx:246
cppu::WeakImplHelper< css::chart2::data::XDataSequence, css::chart2::data::XTextualDataSequence, css::chart2::data::XNumericalDataSequence, css::util::XCloneable, css::beans::XPropertySet, css::lang::XServiceInfo, css::lang::XUnoTunnel, css::util::XModifiable, css::lang::XEventListener, css::lang::XComponent > SwChartDataSequenceBaseClass
Definition: unochart.hxx:228
void LockUnlockAllCharts(bool bLock)
Definition: unochart.cxx:117
::comphelper::OInterfaceContainerHelper2 aEvtListeners
Definition: unochart.hxx:128
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:386
css::chart2::data::DataSequenceRole m_aRole
Definition: unochart.hxx:237
Map_Set_DataSequenceRef_t aDataSequences
Definition: unochart.hxx:126
css::uno::Sequence< css::uno::Reference< css::chart2::data::XLabeledDataSequence > > aLDS
Definition: unochart.hxx:197
DECL_LINK(DoUnlockAllCharts, Timer *, void)
::comphelper::OInterfaceContainerHelper2 aModifyListeners
Definition: unochart.hxx:332
static void DoUpdateAllCharts(SwDoc *pDoc)
Definition: unochart.cxx:54