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 "calbck.hxx"
52 #include "frmfmt.hxx"
53 #include "unocrsr.hxx"
54 
55 class SfxItemPropertySet;
56 class SwDoc;
57 class SwTable;
58 class SwTableBox;
59 struct SwRangeDescriptor;
60 class SwSelBoxes;
61 namespace com { namespace sun { namespace star { namespace table { class XCell; } } } }
62 
63 bool FillRangeDescriptor( SwRangeDescriptor &rDesc, const OUString &rCellRangeName );
64 
66 {
67 public:
68  static void DoUpdateAllCharts( SwDoc* pDoc );
69 };
70 
72 {
74 
75  DECL_LINK( DoUnlockAllCharts, Timer *, void );
76  Timer aUnlockTimer; // timer to unlock chart controllers
77  bool bIsLocked;
78 
81 
82  void LockUnlockAllCharts( bool bLock );
83  void LockAllCharts() { LockUnlockAllCharts( true ); };
84  void UnlockAllCharts() { LockUnlockAllCharts( false ); };
85 
86 public:
87  SwChartLockController_Helper( SwDoc *pDocument );
88  ~SwChartLockController_Helper() COVERITY_NOEXCEPT_FALSE;
89 
91  void Disconnect();
92 };
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 >
102 
105 {
106 
107  // used to keep weak-references to all data-sequences of a single table
108  // see set definition below...
110  {
111  bool operator()( css::uno::WeakReference< css::chart2::data::XDataSequence > xWRef1, css::uno::WeakReference< css::chart2::data::XDataSequence > xWRef2 ) const
112  {
113  css::uno::Reference< css::chart2::data::XDataSequence > xRef1( xWRef1 );
114  css::uno::Reference< css::chart2::data::XDataSequence > xRef2( xWRef2 );
115  return xRef1.get() < xRef2.get();
116  }
117  };
118  typedef std::set< css::uno::WeakReference < css::chart2::data::XDataSequence >, lt_DataSequenceRef > Set_DataSequenceRef_t;
119 
120  // map of data-sequence sets for each table
121  typedef std::map< const SwTable *, Set_DataSequenceRef_t > Map_Set_DataSequenceRef_t;
122 
123  // map of all data-sequences provided directly or indirectly (e.g. via
124  // data-source) by this object. Since there is only one object of this type
125  // for each document it should hold references to all used data-sequences for
126  // all tables of the document.
127  mutable Map_Set_DataSequenceRef_t aDataSequences;
128 
130  const SwDoc * pDoc;
131  bool bDisposed;
132 
133  SwChartDataProvider( const SwChartDataProvider & ) = delete;
135 
138  css::uno::Reference< css::chart2::data::XDataSource > Impl_createDataSource( const css::uno::Sequence< css::beans::PropertyValue >& aArguments, bool bTestOnly = false );
141  css::uno::Reference< css::chart2::data::XDataSequence > Impl_createDataSequenceByRangeRepresentation( const OUString& aRangeRepresentation, bool bTestOnly = false );
142 
143  static OUString GetBrokenCellRangeForExport( const OUString &rCellRangeRepresentation );
144 
145 public:
146  SwChartDataProvider( const SwDoc* pDoc );
147  virtual ~SwChartDataProvider() override;
148 
149  // XDataProvider
150  virtual sal_Bool SAL_CALL createDataSourcePossible( const css::uno::Sequence< css::beans::PropertyValue >& aArguments ) override;
151  virtual css::uno::Reference< css::chart2::data::XDataSource > SAL_CALL createDataSource( const css::uno::Sequence< css::beans::PropertyValue >& aArguments ) override;
152  virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL detectArguments( const css::uno::Reference< css::chart2::data::XDataSource >& xDataSource ) override;
153  virtual sal_Bool SAL_CALL createDataSequenceByRangeRepresentationPossible( const OUString& aRangeRepresentation ) override;
154  virtual css::uno::Reference< css::chart2::data::XDataSequence > SAL_CALL createDataSequenceByRangeRepresentation( const OUString& aRangeRepresentation ) override;
155  virtual css::uno::Reference< css::sheet::XRangeSelection > SAL_CALL getRangeSelection( ) override;
156 
157  virtual css::uno::Reference<css::chart2::data::XDataSequence>
158  SAL_CALL createDataSequenceByValueArray(
159  const OUString& aRole, const OUString& aRangeRepresentation ) override;
160 
161  // XRangeXMLConversion
162  virtual OUString SAL_CALL convertRangeToXML( const OUString& aRangeRepresentation ) override;
163  virtual OUString SAL_CALL convertRangeFromXML( const OUString& aXMLRange ) override;
164 
165  // XComponent
166  virtual void SAL_CALL dispose( ) override;
167  virtual void SAL_CALL addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener ) override;
168  virtual void SAL_CALL removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) override;
169 
170  // XServiceInfo
171  virtual OUString SAL_CALL getImplementationName( ) override;
172  virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
173  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
174 
175  void AddDataSequence( const SwTable &rTable, css::uno::Reference< css::chart2::data::XDataSequence > const &rxDataSequence );
176  void RemoveDataSequence( const SwTable &rTable, css::uno::Reference< css::chart2::data::XDataSequence > const &rxDataSequence );
177 
178  // will send modified events for all data-sequences of the table
179  void InvalidateTable( const SwTable *pTable );
180  void DeleteBox( const SwTable *pTable, const SwTableBox &rBox );
181  void DisposeAllDataSequences( const SwTable *pTable );
182 
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 );
185 };
186 
187 typedef cppu::WeakImplHelper
188 <
189  css::chart2::data::XDataSource,
190  css::lang::XServiceInfo
191 >
193 
196 {
197  css::uno::Sequence<
198  css::uno::Reference< css::chart2::data::XLabeledDataSequence > > aLDS;
199 
200  SwChartDataSource( const SwChartDataSource & ) = delete;
201  SwChartDataSource & operator = ( const SwChartDataSource & ) = delete;
202 
203 public:
204  SwChartDataSource( const css::uno::Sequence< css::uno::Reference< css::chart2::data::XLabeledDataSequence > > &rLDS );
205  virtual ~SwChartDataSource() override;
206 
207  // XDataSource
208  virtual css::uno::Sequence< css::uno::Reference< css::chart2::data::XLabeledDataSequence > > SAL_CALL getDataSequences( ) override;
209 
210  // XServiceInfo
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;
214 };
215 
216 typedef cppu::WeakImplHelper
217 <
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
228 >
230 
233  public SvtListener
234 {
238  css::chart2::data::DataSequenceRole m_aRole;
239 
240  OUString const m_aRowLabelText;
241  OUString const m_aColLabelText;
242 
244 
245  sw::UnoCursorPointer m_pTableCursor; // cursor spanned over cells to use
246 
248 
250 
253 
254 public:
256  SwFrameFormat &rTableFormat,
257  const std::shared_ptr<SwUnoCursor>& pTableCursor );
258  virtual ~SwChartDataSequence() override;
259 
260  static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId();
261 
262  //XUnoTunnel
263  virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence< sal_Int8 >& aIdentifier ) override;
264 
265  // XDataSequence
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;
270 
271  // XTextualDataSequence
272  virtual css::uno::Sequence< OUString > SAL_CALL getTextualData() override;
273 
274  // XNumericalDataSequence
275  virtual css::uno::Sequence< double > SAL_CALL getNumericalData() override;
276 
277  // XCloneable
278  virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone( ) override;
279 
280  // XPropertySet
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;
288 
289  // XServiceInfo
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;
293 
294  // XModifiable
295  virtual sal_Bool SAL_CALL isModified( ) override;
296  virtual void SAL_CALL setModified( sal_Bool bModified ) override;
297 
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;
301 
302  // XEventListener
303  virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
304 
305  // XComponent
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;
309 
310  SwFrameFormat* GetFrameFormat() const { return m_pFormat; }
311  bool DeleteBox( const SwTableBox &rBox );
312 
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();
316 
317  virtual void Notify(const SfxHint& rHint) override;
318 };
319 
320 typedef cppu::WeakImplHelper
321 <
322  css::chart2::data::XLabeledDataSequence2,
323  css::lang::XServiceInfo,
324  css::util::XModifyListener,
325  css::lang::XComponent
326 >
328 
331 {
334 
335  css::uno::Reference< css::chart2::data::XDataSequence > xData;
336  css::uno::Reference< css::chart2::data::XDataSequence > xLabels;
337 
338  bool bDisposed;
339 
342 
343  void SetDataSequence( css::uno::Reference< css::chart2::data::XDataSequence >& rxDest, const css::uno::Reference< css::chart2::data::XDataSequence >& rxSource );
344 
345 public:
347  virtual ~SwChartLabeledDataSequence() override;
348 
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;
354 
355  // XCloneable
356  virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone( ) override;
357 
358  // XServiceInfo
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;
362 
363  // XEventListener
364  virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
365 
366  // XModifyListener
367  virtual void SAL_CALL modified( const css::lang::EventObject& aEvent ) override;
368 
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;
372 
373  // XComponent
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;
377 };
378 
379 #endif
380 
381 /* 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:2921
::comphelper::OInterfaceContainerHelper2 aEvtListeners
Definition: unochart.hxx:332
SwChartLockController_Helper(const SwChartLockController_Helper &)=delete
cppu::WeakImplHelper< css::chart2::data::XDataSource, css::lang::XServiceInfo > SwChartDataSourceBaseClass
Definition: unochart.hxx:192
~SwChartLockController_Helper() COVERITY_NOEXCEPT_FALSE
Definition: unochart.cxx:97
Definition: doc.hxx:185
css::uno::Reference< css::chart2::data::XDataSequence > xLabels
Definition: unochart.hxx:336
OUString getImplementationName()
OUString const m_aRowLabelText
Definition: unochart.hxx:240
const SwDoc * pDoc
Definition: unochart.hxx:130
std::set< css::uno::WeakReference< css::chart2::data::XDataSequence >, lt_DataSequenceRef > Set_DataSequenceRef_t
Definition: unochart.hxx:118
bool operator()(css::uno::WeakReference< css::chart2::data::XDataSequence > xWRef1, css::uno::WeakReference< css::chart2::data::XDataSequence > xWRef2) const
Definition: unochart.hxx:111
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:327
css::uno::Reference< css::chart2::data::XDataSequence > xData
Definition: unochart.hxx:335
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:121
cppu::WeakImplHelper< css::chart2::data::XDataProvider, css::chart2::data::XRangeXMLConversion, css::lang::XComponent, css::lang::XServiceInfo > SwChartDataProviderBaseClass
Definition: unochart.hxx:101
Style of a layout element.
Definition: frmfmt.hxx:57
::comphelper::OInterfaceContainerHelper2 m_aEvtListeners
Definition: unochart.hxx:236
css::uno::Sequence< OUString > getSupportedServiceNames()
SwFrameFormat * m_pFormat
Definition: unochart.hxx:235
OUString const m_aColLabelText
Definition: unochart.hxx:241
rtl::Reference< SwChartDataProvider > m_xDataProvider
Definition: unochart.hxx:243
sw::UnoCursorPointer m_pTableCursor
Definition: unochart.hxx:245
SwFrameFormat * GetFrameFormat() const
Definition: unochart.hxx:310
::comphelper::OInterfaceContainerHelper2 m_aModifyListeners
Definition: unochart.hxx:237
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:247
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:229
void LockUnlockAllCharts(bool bLock)
Definition: unochart.cxx:117
::comphelper::OInterfaceContainerHelper2 aEvtListeners
Definition: unochart.hxx:129
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:386
css::chart2::data::DataSequenceRole m_aRole
Definition: unochart.hxx:238
Map_Set_DataSequenceRef_t aDataSequences
Definition: unochart.hxx:127
css::uno::Sequence< css::uno::Reference< css::chart2::data::XLabeledDataSequence > > aLDS
Definition: unochart.hxx:198
DECL_LINK(DoUnlockAllCharts, Timer *, void)
::comphelper::OInterfaceContainerHelper2 aModifyListeners
Definition: unochart.hxx:333
static void DoUpdateAllCharts(SwDoc *pDoc)
Definition: unochart.cxx:54