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