LibreOffice Module sc (master)  1
chartlis.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 
20 #ifndef INCLUDED_SC_INC_CHARTLIS_HXX
21 #define INCLUDED_SC_INC_CHARTLIS_HXX
22 
23 #include <vcl/idle.hxx>
24 #include <svl/listener.hxx>
25 #include "rangelst.hxx"
26 #include "externalrefmgr.hxx"
27 
28 #include <memory>
29 #include <map>
30 #include <unordered_map>
31 #include <unordered_set>
32 #include <vector>
33 
34 namespace com::sun::star::chart { class XChartData; }
35 namespace com::sun::star::chart { class XChartDataChangeEventListener; }
36 
37 class Timer;
38 class ScDocument;
39 class ScChartUnoData;
40 
42 {
43 public:
44  class SAL_DLLPRIVATE ExternalRefListener final : public ScExternalRefManager::LinkListener
45  {
46  public:
48  virtual ~ExternalRefListener() override;
49  virtual void notify(sal_uInt16 nFileId, ScExternalRefManager::LinkUpdateType eType) override;
50  void addFileId(sal_uInt16 nFileId);
51  void removeFileId(sal_uInt16 nFileId);
52  std::unordered_set<sal_uInt16>& getAllFileIds() { return maFileIds;}
53 
54  private:
55  ExternalRefListener(const ExternalRefListener& r) = delete;
56 
58  std::unordered_set<sal_uInt16> maFileIds;
60  };
61 
62 private:
63 
64  std::unique_ptr<ExternalRefListener> mpExtRefListener;
65  std::unique_ptr<std::vector<ScTokenRef> > mpTokens;
66 
67  OUString maName;
68  std::unique_ptr<ScChartUnoData> pUnoData;
70  bool bUsed:1; // for ScChartListenerCollection::FreeUnused
71  bool bDirty:1;
72 
73  ScChartListener& operator=( const ScChartListener& ) = delete;
74 
75 public:
76  ScChartListener( const OUString& rName, ScDocument& rDoc,
77  const ScRangeListRef& rRangeListRef );
78  ScChartListener( const OUString& rName, ScDocument& rDoc,
79  std::unique_ptr<::std::vector<ScTokenRef>> pTokens );
80  ScChartListener( const ScChartListener& ) = delete;
81  virtual ~ScChartListener() override;
82 
83  const OUString& GetName() const { return maName;}
84 
85  void SetUno( const css::uno::Reference< css::chart::XChartDataChangeEventListener >& rListener,
86  const css::uno::Reference< css::chart::XChartData >& rSource );
87  css::uno::Reference< css::chart::XChartDataChangeEventListener > GetUnoListener() const;
88  css::uno::Reference< css::chart::XChartData > GetUnoSource() const;
89 
90  bool IsUno() const { return (pUnoData != nullptr); }
91 
92  virtual void Notify( const SfxHint& rHint ) override;
93  void StartListeningTo();
94  void EndListeningTo();
95  void ChangeListening( const ScRangeListRef& rRangeListRef,
96  bool bDirty );
97  void Update();
98  ScRangeListRef GetRangeList() const;
99  void SetRangeList( const ScRangeListRef& rNew );
100  bool IsUsed() const { return bUsed; }
101  void SetUsed( bool bFlg ) { bUsed = bFlg; }
102  bool IsDirty() const { return bDirty; }
103  void SetDirty( bool bFlg ) { bDirty = bFlg; }
104 
105  void UpdateChartIntersecting( const ScRange& rRange );
106 
107  ExternalRefListener* GetExtRefListener();
108  void SetUpdateQueue();
109 
110  bool operator==( const ScChartListener& ) const;
111  bool operator!=( const ScChartListener& r ) const;
112 };
113 
115 {
116 public:
118  virtual ~ScChartHiddenRangeListener();
119  virtual void notify() = 0;
120 };
121 
123 {
124 public:
125  typedef std::map<OUString, std::unique_ptr<ScChartListener>> ListenersType;
126  typedef std::unordered_set<OUString> StringSetType;
127 private:
128  ListenersType m_Listeners;
130  {
133  SC_CLCUPDATE_MODIFIED
134  } meModifiedDuringUpdate;
135 
136  std::unordered_multimap<ScChartHiddenRangeListener*, ScRange> maHiddenListeners;
137 
138  StringSetType maNonOleObjectNames;
139 
142 
143  DECL_LINK(TimerHdl, Timer *, void);
144 
145  ScChartListenerCollection& operator=( const ScChartListenerCollection& ) = delete;
146 
147  void Init();
148 
149 public:
153 
154  // only needed after copy-ctor, if newly added to doc
155  void StartAllListeners();
156 
157  void insert(ScChartListener* pListener);
158  ScChartListener* findByName(const OUString& rName);
159  const ScChartListener* findByName(const OUString& rName) const;
160  bool hasListeners() const;
161 
162  void removeByName(const OUString& rName);
163 
164  const ListenersType& getListeners() const { return m_Listeners; }
165  ListenersType& getListeners() { return m_Listeners; }
166  StringSetType& getNonOleObjectNames() { return maNonOleObjectNames;}
167 
172  OUString getUniqueName(const OUString& rPrefix) const;
173 
174  void ChangeListening( const OUString& rName,
175  const ScRangeListRef& rRangeListRef );
176  // use FreeUnused only the way it's used in ScDocument::UpdateChartListenerCollection
177  void FreeUnused();
178  void FreeUno( const css::uno::Reference< css::chart::XChartDataChangeEventListener >& rListener,
179  const css::uno::Reference< css::chart::XChartData >& rSource );
180  void StartTimer();
181  void UpdateDirtyCharts();
182  void SetDirty();
183  void SetDiffDirty( const ScChartListenerCollection&,
184  bool bSetChartRangeLists );
185 
186  void SetRangeDirty( const ScRange& rRange ); // for example rows/columns
187 
188  void UpdateChartsContainingTab( SCTAB nTab );
189 
190  bool operator==( const ScChartListenerCollection& r ) const;
191 
200  void StartListeningHiddenRange( const ScRange& rRange,
201  ScChartHiddenRangeListener* pListener );
202 
208  void EndListeningHiddenRange( ScChartHiddenRangeListener* pListener );
209 };
210 
211 #endif
212 
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool operator==(const XclFontData &rLeft, const XclFontData &rRight)
Definition: xlstyle.cxx:517
OUString maName
Definition: chartlis.hxx:67
void Init()
bool operator!=(const XclExpString &rLeft, const XclExpString &rRight)
Definition: xestring.hxx:246
std::unordered_set< OUString > StringSetType
Definition: chartlis.hxx:126
ScDocument & mrDoc
Definition: chartlis.hxx:69
StringSetType & getNonOleObjectNames()
Definition: chartlis.hxx:166
ListenersType m_Listeners
Definition: chartlis.hxx:128
bool IsUno() const
Definition: chartlis.hxx:90
std::unique_ptr< ExternalRefListener > mpExtRefListener
Definition: chartlis.hxx:64
const ListenersType & getListeners() const
Definition: chartlis.hxx:164
StringSetType maNonOleObjectNames
Definition: chartlis.hxx:138
std::unordered_multimap< ScChartHiddenRangeListener *, ScRange > maHiddenListeners
Definition: chartlis.hxx:136
bool IsUsed() const
Definition: chartlis.hxx:100
DocumentType eType
std::unordered_set< sal_uInt16 > & getAllFileIds()
Definition: chartlis.hxx:52
std::unique_ptr< ScChartUnoData > pUnoData
Definition: chartlis.hxx:68
std::unique_ptr< std::vector< ScTokenRef > > mpTokens
Definition: chartlis.hxx:65
Base class for objects that need to listen to link updates.
const SvtListener & operator=(const SvtListener &)=delete
const OUString & GetName() const
Definition: chartlis.hxx:83
void SetUsed(bool bFlg)
Definition: chartlis.hxx:101
std::map< OUString, std::unique_ptr< ScChartListener > > ListenersType
Definition: chartlis.hxx:125
bool IsDirty() const
Definition: chartlis.hxx:102
ListenersType & getListeners()
Definition: chartlis.hxx:165
virtual void Notify(const SfxHint &rHint)
void SetDirty(bool bFlg)
Definition: chartlis.hxx:103
std::unordered_set< sal_uInt16 > maFileIds
Definition: chartlis.hxx:58
#define SC_DLLPUBLIC
Definition: scdllapi.h:28
sal_Int16 SCTAB
Definition: types.hxx:23