Bump version to 6.4-15
[LibreOffice.git] / sc / inc / chartlis.hxx
blob1b49d168f82694a8aa53118618f05498ad31d200
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SC_INC_CHARTLIS_HXX
21 #define INCLUDED_SC_INC_CHARTLIS_HXX
23 #include <vcl/idle.hxx>
24 #include <svl/listener.hxx>
25 #include "rangelst.hxx"
26 #include "externalrefmgr.hxx"
28 #include <memory>
29 #include <map>
30 #include <unordered_map>
31 #include <unordered_set>
32 #include <vector>
34 namespace com { namespace sun { namespace star { namespace chart { class XChartData; } } } }
35 namespace com { namespace sun { namespace star { namespace chart { class XChartDataChangeEventListener; } } } }
37 class Timer;
38 class ScDocument;
39 class ScChartUnoData;
41 class SC_DLLPUBLIC ScChartListener final : public SvtListener
43 public:
44 class ExternalRefListener final : public ScExternalRefManager::LinkListener
46 public:
47 ExternalRefListener(ScChartListener& rParent, ScDocument* pDoc);
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;}
54 private:
55 ExternalRefListener(const ExternalRefListener& r) = delete;
57 ScChartListener& mrParent;
58 std::unordered_set<sal_uInt16> maFileIds;
59 ScDocument* mpDoc;
62 private:
64 std::unique_ptr<ExternalRefListener> mpExtRefListener;
65 std::unique_ptr<std::vector<ScTokenRef> > mpTokens;
67 OUString const maName;
68 std::unique_ptr<ScChartUnoData> pUnoData;
69 ScDocument* mpDoc;
70 bool bUsed:1; // for ScChartListenerCollection::FreeUnused
71 bool bDirty:1;
73 ScChartListener& operator=( const ScChartListener& ) = delete;
75 public:
76 ScChartListener( const OUString& rName, ScDocument* pDoc,
77 const ScRangeListRef& rRangeListRef );
78 ScChartListener( const OUString& rName, ScDocument* pDoc,
79 std::unique_ptr<::std::vector<ScTokenRef>> pTokens );
80 ScChartListener( const ScChartListener& ) = delete;
81 virtual ~ScChartListener() override;
83 const OUString& GetName() const { return maName;}
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;
90 bool IsUno() const { return (pUnoData != nullptr); }
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; }
105 void UpdateChartIntersecting( const ScRange& rRange );
107 ExternalRefListener* GetExtRefListener();
108 void SetUpdateQueue();
110 bool operator==( const ScChartListener& ) const;
111 bool operator!=( const ScChartListener& r ) const;
114 class SC_DLLPUBLIC ScChartHiddenRangeListener
116 public:
117 ScChartHiddenRangeListener();
118 virtual ~ScChartHiddenRangeListener();
119 virtual void notify() = 0;
122 class SC_DLLPUBLIC ScChartListenerCollection final
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;
129 enum UpdateStatus
131 SC_CLCUPDATE_NONE,
132 SC_CLCUPDATE_RUNNING,
133 SC_CLCUPDATE_MODIFIED
134 } meModifiedDuringUpdate;
136 std::unordered_multimap<ScChartHiddenRangeListener*, ScRange> maHiddenListeners;
138 StringSetType maNonOleObjectNames;
140 Idle aIdle;
141 ScDocument* pDoc;
143 DECL_LINK(TimerHdl, Timer *, void);
145 ScChartListenerCollection& operator=( const ScChartListenerCollection& ) = delete;
147 void Init();
149 public:
150 ScChartListenerCollection( ScDocument* pDoc );
151 ScChartListenerCollection( const ScChartListenerCollection& );
152 ~ScChartListenerCollection();
154 // only needed after copy-ctor, if newly added to doc
155 void StartAllListeners();
157 void insert(ScChartListener* pListener);
158 ScChartListener* findByName(const OUString& rName);
159 const ScChartListener* findByName(const OUString& rName) const;
160 bool hasListeners() const;
162 void removeByName(const OUString& rName);
164 const ListenersType& getListeners() const { return m_Listeners; }
165 ListenersType& getListeners() { return m_Listeners; }
166 StringSetType& getNonOleObjectNames() { return maNonOleObjectNames;}
169 * Create a unique name that's not taken by any existing chart listener
170 * objects. The name consists of a prefix given followed by a number.
172 OUString getUniqueName(const OUString& rPrefix) const;
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 );
186 void SetRangeDirty( const ScRange& rRange ); // for example rows/columns
188 void UpdateChartsContainingTab( SCTAB nTab );
190 bool operator==( const ScChartListenerCollection& r ) const;
193 * Start listening on hide/show change within specified cell range. A
194 * single listener may listen on multiple ranges when the caller passes
195 * the same pointer multiple times with different ranges.
197 * Note that the caller is responsible for managing the life-cycle of the
198 * listener instance.
200 void StartListeningHiddenRange( const ScRange& rRange,
201 ScChartHiddenRangeListener* pListener );
204 * Remove all ranges associated with passed listener instance from the
205 * list of hidden range listeners. This does not delete the passed
206 * listener instance.
208 void EndListeningHiddenRange( ScChartHiddenRangeListener* pListener );
211 #endif
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */