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