tdf#48459 sw inline heading: don't apply inside frames or over 120 chars
[LibreOffice.git] / sc / inc / chartlis.hxx
blobaec202c1b18f272b169e2c94a0d40976e19bde63
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 #pragma once
22 #include <vcl/idle.hxx>
23 #include <svl/listener.hxx>
24 #include "rangelst.hxx"
25 #include "externalrefmgr.hxx"
27 #include <memory>
28 #include <map>
29 #include <string_view>
30 #include <unordered_map>
31 #include <unordered_set>
32 #include <vector>
34 namespace com::sun::star::chart { class XChartData; }
35 namespace com::sun::star::chart { class XChartDataChangeEventListener; }
37 class Timer;
38 class ScDocument;
39 class ScChartUnoData;
41 class SAL_DLLPUBLIC_RTTI ScChartListener final : public SvtListener
43 public:
44 class ExternalRefListener final : public ScExternalRefManager::LinkListener
46 public:
47 ExternalRefListener(ScChartListener& rParent, ScDocument& rDoc);
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* m_pDoc;
62 private:
64 std::unique_ptr<ExternalRefListener> mpExtRefListener;
65 std::vector<ScTokenRef> maTokens;
67 OUString maName;
68 std::unique_ptr<ScChartUnoData> pUnoData;
69 ScDocument& mrDoc;
70 bool bUsed:1; // for ScChartListenerCollection::FreeUnused
71 bool bDirty:1;
73 ScChartListener& operator=( const ScChartListener& ) = delete;
75 public:
76 ScChartListener( OUString aName, ScDocument& rDoc,
77 const ScRangeListRef& rRangeListRef );
78 SC_DLLPUBLIC ScChartListener( OUString aName, ScDocument& rDoc,
79 ::std::vector<ScTokenRef> aTokens );
80 ScChartListener( const ScChartListener& ) = delete;
81 SC_DLLPUBLIC 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 SC_DLLPUBLIC 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 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& rDoc;
143 DECL_LINK(TimerHdl, Timer *, void);
145 ScChartListenerCollection& operator=( const ScChartListenerCollection& ) = delete;
147 void Init();
149 public:
150 SC_DLLPUBLIC ScChartListenerCollection( ScDocument& rDoc );
151 ScChartListenerCollection( const ScChartListenerCollection& );
152 SC_DLLPUBLIC ~ScChartListenerCollection();
154 // only needed after copy-ctor, if newly added to doc
155 void StartAllListeners();
157 SC_DLLPUBLIC bool 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(std::u16string_view 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 SC_DLLPUBLIC 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 SC_DLLPUBLIC 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 SC_DLLPUBLIC void EndListeningHiddenRange( ScChartHiddenRangeListener* pListener );
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */