Line data Source code
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/timer.hxx>
24 : #include <vcl/idle.hxx>
25 : #include <svl/listener.hxx>
26 : #include "rangelst.hxx"
27 : #include "token.hxx"
28 : #include "externalrefmgr.hxx"
29 :
30 : #include <vector>
31 : #include <list>
32 :
33 : #include <boost/scoped_ptr.hpp>
34 : #include <boost/ptr_container/ptr_map.hpp>
35 : #include <unordered_set>
36 :
37 : class ScDocument;
38 : class ScChartUnoData;
39 : #include <com/sun/star/chart/XChartData.hpp>
40 : #include <com/sun/star/chart/XChartDataChangeEventListener.hpp>
41 :
42 : class SC_DLLPUBLIC ScChartListener : public SvtListener
43 : {
44 : public:
45 : class ExternalRefListener : public ScExternalRefManager::LinkListener
46 : {
47 : public:
48 : ExternalRefListener(ScChartListener& rParent, ScDocument* pDoc);
49 : virtual ~ExternalRefListener();
50 : virtual void notify(sal_uInt16 nFileId, ScExternalRefManager::LinkUpdateType eType) SAL_OVERRIDE;
51 : void addFileId(sal_uInt16 nFileId);
52 : void removeFileId(sal_uInt16 nFileId);
53 0 : std::unordered_set<sal_uInt16>& getAllFileIds() { return maFileIds;}
54 :
55 : private:
56 : ExternalRefListener(const ExternalRefListener& r) SAL_DELETED_FUNCTION;
57 :
58 : ScChartListener& mrParent;
59 : std::unordered_set<sal_uInt16> maFileIds;
60 : ScDocument* mpDoc;
61 : };
62 :
63 : private:
64 :
65 : boost::scoped_ptr<ExternalRefListener> mpExtRefListener;
66 : boost::scoped_ptr<std::vector<ScTokenRef> > mpTokens;
67 :
68 : OUString maName;
69 : ScChartUnoData* pUnoData;
70 : ScDocument* mpDoc;
71 : bool bUsed:1; // for ScChartListenerCollection::FreeUnused
72 : bool bDirty:1;
73 : bool bSeriesRangesScheduled:1;
74 :
75 : ScChartListener& operator=( const ScChartListener& ) SAL_DELETED_FUNCTION;
76 :
77 : public:
78 : ScChartListener( const OUString& rName, ScDocument* pDoc,
79 : const ScRangeListRef& rRangeListRef );
80 : ScChartListener( const OUString& rName, ScDocument* pDoc,
81 : ::std::vector<ScTokenRef>* pTokens );
82 : ScChartListener( const ScChartListener& );
83 : virtual ~ScChartListener();
84 :
85 116 : const OUString& GetName() const { return maName;}
86 :
87 : void SetUno( const com::sun::star::uno::Reference< com::sun::star::chart::XChartDataChangeEventListener >& rListener,
88 : const com::sun::star::uno::Reference< com::sun::star::chart::XChartData >& rSource );
89 : com::sun::star::uno::Reference< com::sun::star::chart::XChartDataChangeEventListener > GetUnoListener() const;
90 : com::sun::star::uno::Reference< com::sun::star::chart::XChartData > GetUnoSource() const;
91 :
92 117 : bool IsUno() const { return (pUnoData != NULL); }
93 :
94 : virtual void Notify( const SfxHint& rHint ) SAL_OVERRIDE;
95 : void StartListeningTo();
96 : void EndListeningTo();
97 : void ChangeListening( const ScRangeListRef& rRangeListRef,
98 : bool bDirty = false );
99 : void Update();
100 : ScRangeListRef GetRangeList() const;
101 : void SetRangeList( const ScRangeListRef& rNew );
102 114 : bool IsUsed() const { return bUsed; }
103 274 : void SetUsed( bool bFlg ) { bUsed = bFlg; }
104 40 : bool IsDirty() const { return bDirty; }
105 30 : void SetDirty( bool bFlg ) { bDirty = bFlg; }
106 :
107 : void UpdateChartIntersecting( const ScRange& rRange );
108 :
109 : // if chart series ranges are to be updated later on (e.g. DeleteTab, InsertTab)
110 : void ScheduleSeriesRanges() { bSeriesRangesScheduled = true; }
111 : void UpdateScheduledSeriesRanges();
112 : void UpdateSeriesRanges();
113 :
114 : ExternalRefListener* GetExtRefListener();
115 : void SetUpdateQueue();
116 :
117 : bool operator==( const ScChartListener& ) const;
118 : bool operator!=( const ScChartListener& r ) const;
119 : };
120 :
121 : class ScChartHiddenRangeListener
122 : {
123 : public:
124 : ScChartHiddenRangeListener();
125 : virtual ~ScChartHiddenRangeListener();
126 : virtual void notify() = 0;
127 : };
128 :
129 : class ScChartListenerCollection
130 : {
131 : public:
132 4109 : struct RangeListenerItem
133 : {
134 : ScRange maRange;
135 : ScChartHiddenRangeListener* mpListener;
136 : explicit RangeListenerItem(const ScRange& rRange, ScChartHiddenRangeListener* p);
137 : };
138 :
139 : typedef boost::ptr_map<OUString, ScChartListener> ListenersType;
140 : typedef std::unordered_set<OUString, OUStringHash> StringSetType;
141 : private:
142 : ListenersType maListeners;
143 : enum UpdateStatus
144 : {
145 : SC_CLCUPDATE_NONE,
146 : SC_CLCUPDATE_RUNNING,
147 : SC_CLCUPDATE_MODIFIED
148 : } meModifiedDuringUpdate;
149 : ::std::list<RangeListenerItem> maHiddenListeners;
150 : StringSetType maNonOleObjectNames;
151 :
152 : Idle aIdle;
153 : ScDocument* pDoc;
154 :
155 : DECL_LINK_TYPED(TimerHdl, Idle *, void);
156 :
157 : ScChartListenerCollection& operator=( const ScChartListenerCollection& ) SAL_DELETED_FUNCTION;
158 :
159 : public:
160 : ScChartListenerCollection( ScDocument* pDoc );
161 : ScChartListenerCollection( const ScChartListenerCollection& );
162 : ~ScChartListenerCollection();
163 :
164 : // only needed after copy-ctor, if newly added to doc
165 : void StartAllListeners();
166 :
167 : SC_DLLPUBLIC void insert(ScChartListener* pListener);
168 : ScChartListener* findByName(const OUString& rName);
169 : const ScChartListener* findByName(const OUString& rName) const;
170 : bool hasListeners() const;
171 :
172 : void removeByName(const OUString& rName);
173 :
174 : const ListenersType& getListeners() const { return maListeners;}
175 190 : ListenersType& getListeners() { return maListeners;}
176 1248 : StringSetType& getNonOleObjectNames() { return maNonOleObjectNames;}
177 :
178 : /**
179 : * Create a unique name that's not taken by any existing chart listener
180 : * objects. The name consists of a prefix given followed by a number.
181 : */
182 : OUString getUniqueName(const OUString& rPrefix) const;
183 :
184 : void ChangeListening( const OUString& rName,
185 : const ScRangeListRef& rRangeListRef,
186 : bool bDirty = false );
187 : // use FreeUnused only the way it's used in ScDocument::UpdateChartListenerCollection
188 : void FreeUnused();
189 : void FreeUno( const com::sun::star::uno::Reference< com::sun::star::chart::XChartDataChangeEventListener >& rListener,
190 : const com::sun::star::uno::Reference< com::sun::star::chart::XChartData >& rSource );
191 : void StartTimer();
192 : void UpdateDirtyCharts();
193 : SC_DLLPUBLIC void SetDirty();
194 : void SetDiffDirty( const ScChartListenerCollection&,
195 : bool bSetChartRangeLists = false );
196 :
197 : void SetRangeDirty( const ScRange& rRange ); // for example rows/columns
198 :
199 : void UpdateScheduledSeriesRanges();
200 : void UpdateChartsContainingTab( SCTAB nTab );
201 :
202 : bool operator==( const ScChartListenerCollection& r ) const;
203 : bool operator!=( const ScChartListenerCollection& r ) const;
204 :
205 : /**
206 : * Start listening on hide/show change within specified cell range. A
207 : * single listener may listen on multiple ranges when the caller passes
208 : * the same pointer multiple times with different ranges.
209 : *
210 : * Note that the caller is responsible for managing the life-cycle of the
211 : * listener instance.
212 : */
213 : void StartListeningHiddenRange( const ScRange& rRange,
214 : ScChartHiddenRangeListener* pListener );
215 :
216 : /**
217 : * Remove all ranges associated with passed listener instance from the
218 : * list of hidden range listeners. This does not delete the passed
219 : * listener instance.
220 : */
221 : void EndListeningHiddenRange( ScChartHiddenRangeListener* pListener );
222 : };
223 :
224 : #endif
225 :
226 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|