1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <vcl/idle.hxx>
23 #include <svl/listener.hxx>
24 #include "rangelst.hxx"
25 #include "externalrefmgr.hxx"
29 #include <string_view>
30 #include <unordered_map>
31 #include <unordered_set>
34 namespace com::sun::star::chart
{ class XChartData
; }
35 namespace com::sun::star::chart
{ class XChartDataChangeEventListener
; }
41 class SAL_DLLPUBLIC_RTTI ScChartListener final
: public SvtListener
44 class ExternalRefListener final
: public ScExternalRefManager::LinkListener
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
;}
55 ExternalRefListener(const ExternalRefListener
& r
) = delete;
57 ScChartListener
& mrParent
;
58 std::unordered_set
<sal_uInt16
> maFileIds
;
64 std::unique_ptr
<ExternalRefListener
> mpExtRefListener
;
65 std::vector
<ScTokenRef
> maTokens
;
68 std::unique_ptr
<ScChartUnoData
> pUnoData
;
70 bool bUsed
:1; // for ScChartListenerCollection::FreeUnused
73 ScChartListener
& operator=( const ScChartListener
& ) = delete;
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
,
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
117 ScChartHiddenRangeListener();
118 virtual ~ScChartHiddenRangeListener();
119 virtual void notify() = 0;
122 class ScChartListenerCollection final
125 typedef std::map
<OUString
, std::unique_ptr
<ScChartListener
>> ListenersType
;
126 typedef std::unordered_set
<OUString
> StringSetType
;
128 ListenersType m_Listeners
;
132 SC_CLCUPDATE_RUNNING
,
133 SC_CLCUPDATE_MODIFIED
134 } meModifiedDuringUpdate
;
136 std::unordered_multimap
<ScChartHiddenRangeListener
*, ScRange
> maHiddenListeners
;
138 StringSetType maNonOleObjectNames
;
143 DECL_LINK(TimerHdl
, Timer
*, void);
145 ScChartListenerCollection
& operator=( const ScChartListenerCollection
& ) = delete;
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
178 void FreeUno( const css::uno::Reference
< css::chart::XChartDataChangeEventListener
>& rListener
,
179 const css::uno::Reference
< css::chart::XChartData
>& rSource
);
181 void UpdateDirtyCharts();
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
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
208 SC_DLLPUBLIC
void EndListeningHiddenRange( ScChartHiddenRangeListener
* pListener
);
211 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */