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#pragma once
21
22#include <vcl/idle.hxx>
23#include <svl/listener.hxx>
24#include "rangelst.hxx"
25#include "externalrefmgr.hxx"
26
27#include <memory>
28#include <map>
29#include <string_view>
30#include <unordered_map>
31#include <unordered_set>
32#include <vector>
33
34namespace com::sun::star::chart { class XChartData; }
35namespace com::sun::star::chart { class XChartDataChangeEventListener; }
36
37class Timer;
38class ScDocument;
39class ScChartUnoData;
40
42{
43public:
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:
56
58 std::unordered_set<sal_uInt16> maFileIds;
60 };
61
62private:
63
64 std::unique_ptr<ExternalRefListener> mpExtRefListener;
65 std::vector<ScTokenRef> maTokens;
66
67 OUString maName;
68 std::unique_ptr<ScChartUnoData> pUnoData;
70 bool bUsed:1; // for ScChartListenerCollection::FreeUnused
71 bool bDirty:1;
72
74
75public:
76 ScChartListener( OUString aName, ScDocument& rDoc,
77 const ScRangeListRef& rRangeListRef );
78 ScChartListener( OUString aName, ScDocument& rDoc,
79 ::std::vector<ScTokenRef> aTokens );
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{
116public:
119 virtual void notify() = 0;
120};
121
123{
124public:
125 typedef std::map<OUString, std::unique_ptr<ScChartListener>> ListenersType;
126 typedef std::unordered_set<OUString> StringSetType;
127private:
130 {
133 SC_CLCUPDATE_MODIFIED
134 } meModifiedDuringUpdate;
135
136 std::unordered_multimap<ScChartHiddenRangeListener*, ScRange> maHiddenListeners;
137
139
142
143 DECL_DLLPRIVATE_LINK(TimerHdl, Timer *, void);
144
146
147 void Init();
148
149public:
153
154 // only needed after copy-ctor, if newly added to doc
155 void StartAllListeners();
156
157 bool 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(std::u16string_view 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/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString maName
virtual void notify()=0
ScChartListenerCollection & operator=(const ScChartListenerCollection &)=delete
DECL_DLLPRIVATE_LINK(TimerHdl, Timer *, void)
const ListenersType & getListeners() const
Definition: chartlis.hxx:164
std::unordered_set< OUString > StringSetType
Definition: chartlis.hxx:126
std::map< OUString, std::unique_ptr< ScChartListener > > ListenersType
Definition: chartlis.hxx:125
ListenersType m_Listeners
Definition: chartlis.hxx:128
ListenersType & getListeners()
Definition: chartlis.hxx:165
StringSetType & getNonOleObjectNames()
Definition: chartlis.hxx:166
StringSetType maNonOleObjectNames
Definition: chartlis.hxx:138
std::unordered_multimap< ScChartHiddenRangeListener *, ScRange > maHiddenListeners
Definition: chartlis.hxx:136
std::unordered_set< sal_uInt16 > & getAllFileIds()
Definition: chartlis.hxx:52
std::unordered_set< sal_uInt16 > maFileIds
Definition: chartlis.hxx:58
ExternalRefListener(const ExternalRefListener &r)=delete
ScChartListener(OUString aName, ScDocument &rDoc, ::std::vector< ScTokenRef > aTokens)
bool IsUno() const
Definition: chartlis.hxx:90
std::vector< ScTokenRef > maTokens
Definition: chartlis.hxx:65
void SetUsed(bool bFlg)
Definition: chartlis.hxx:101
void SetDirty(bool bFlg)
Definition: chartlis.hxx:103
OUString maName
Definition: chartlis.hxx:67
std::unique_ptr< ScChartUnoData > pUnoData
Definition: chartlis.hxx:68
bool IsUsed() const
Definition: chartlis.hxx:100
ScChartListener & operator=(const ScChartListener &)=delete
ScChartListener(const ScChartListener &)=delete
std::unique_ptr< ExternalRefListener > mpExtRefListener
Definition: chartlis.hxx:64
bool IsDirty() const
Definition: chartlis.hxx:102
ScDocument & mrDoc
Definition: chartlis.hxx:69
const OUString & GetName() const
Definition: chartlis.hxx:83
Base class for objects that need to listen to link updates.
virtual void Notify(const SfxHint &rHint)
void Init()
DocumentType eType
#define SC_DLLPUBLIC
Definition: scdllapi.h:27
sal_Int16 SCTAB
Definition: types.hxx:22
bool operator!=(const XclExpString &rLeft, const XclExpString &rRight)
Definition: xestring.hxx:248
bool operator==(const XclFontData &rLeft, const XclFontData &rRight)
Definition: xlstyle.cxx:518