Bump version to 4.3-4
[LibreOffice.git] / sc / inc / chartlis.hxx
blob7feebf36406789c8041db42d53ff68a2cb458b67
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 #ifndef INCLUDED_SC_INC_CHARTLIS_HXX
21 #define INCLUDED_SC_INC_CHARTLIS_HXX
23 #include <vcl/timer.hxx>
24 #include <svl/listener.hxx>
25 #include "rangelst.hxx"
26 #include "token.hxx"
27 #include "externalrefmgr.hxx"
29 #include <vector>
30 #include <list>
32 #include <boost/unordered_set.hpp>
33 #include <boost/scoped_ptr.hpp>
34 #include <boost/ptr_container/ptr_map.hpp>
36 class ScDocument;
37 class ScChartUnoData;
38 #include <com/sun/star/chart/XChartData.hpp>
39 #include <com/sun/star/chart/XChartDataChangeEventListener.hpp>
41 class SC_DLLPUBLIC ScChartListener : public SvtListener
43 public:
44 class ExternalRefListener : public ScExternalRefManager::LinkListener
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();
54 private:
55 ExternalRefListener();
56 ExternalRefListener(const ExternalRefListener& r);
58 ScChartListener& mrParent;
59 ::boost::unordered_set<sal_uInt16> maFileIds;
60 ScDocument* mpDoc;
63 private:
65 boost::scoped_ptr<ExternalRefListener> mpExtRefListener;
66 boost::scoped_ptr<std::vector<ScTokenRef> > mpTokens;
68 OUString maName;
69 ScChartUnoData* pUnoData;
70 ScDocument* mpDoc;
71 bool bUsed:1; // for ScChartListenerCollection::FreeUnused
72 bool bDirty:1;
73 bool bSeriesRangesScheduled:1;
75 // not implemented
76 ScChartListener& operator=( const ScChartListener& );
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();
86 const OUString& GetName() const;
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;
93 bool IsUno() const { return (pUnoData != NULL); }
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 bool IsUsed() const { return bUsed; }
104 void SetUsed( bool bFlg ) { bUsed = bFlg; }
105 bool IsDirty() const { return bDirty; }
106 void SetDirty( bool bFlg ) { bDirty = bFlg; }
108 void UpdateChartIntersecting( const ScRange& rRange );
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();
115 ExternalRefListener* GetExtRefListener();
116 void SetUpdateQueue();
118 bool operator==( const ScChartListener& ) const;
119 bool operator!=( const ScChartListener& r ) const;
122 class ScChartHiddenRangeListener
124 public:
125 ScChartHiddenRangeListener();
126 virtual ~ScChartHiddenRangeListener();
127 virtual void notify() = 0;
130 class ScChartListenerCollection
132 public:
133 struct RangeListenerItem
135 ScRange maRange;
136 ScChartHiddenRangeListener* mpListener;
137 explicit RangeListenerItem(const ScRange& rRange, ScChartHiddenRangeListener* p);
140 typedef boost::ptr_map<OUString, ScChartListener> ListenersType;
141 typedef boost::unordered_set<OUString, OUStringHash> StringSetType;
142 private:
143 ListenersType maListeners;
144 enum UpdateStatus
146 SC_CLCUPDATE_NONE,
147 SC_CLCUPDATE_RUNNING,
148 SC_CLCUPDATE_MODIFIED
149 } meModifiedDuringUpdate;
150 ::std::list<RangeListenerItem> maHiddenListeners;
151 StringSetType maNonOleObjectNames;
153 Timer aTimer;
154 ScDocument* pDoc;
156 DECL_LINK(TimerHdl, void *);
158 // not implemented
159 ScChartListenerCollection& operator=( const ScChartListenerCollection& );
161 public:
162 ScChartListenerCollection( ScDocument* pDoc );
163 ScChartListenerCollection( const ScChartListenerCollection& );
164 ~ScChartListenerCollection();
166 // only needed after copy-ctor, if newly added to doc
167 void StartAllListeners();
169 SC_DLLPUBLIC void insert(ScChartListener* pListener);
170 ScChartListener* findByName(const OUString& rName);
171 const ScChartListener* findByName(const OUString& rName) const;
172 bool hasListeners() const;
174 void removeByName(const OUString& rName);
176 const ListenersType& getListeners() const;
177 ListenersType& getListeners();
178 StringSetType& getNonOleObjectNames();
181 * Create a unique name that's not taken by any existing chart listener
182 * objects. The name consists of a prefix given followed by a number.
184 OUString getUniqueName(const OUString& rPrefix) const;
186 void ChangeListening( const OUString& rName,
187 const ScRangeListRef& rRangeListRef,
188 bool bDirty = false );
189 // use FreeUnused only the way it's used in ScDocument::UpdateChartListenerCollection
190 void FreeUnused();
191 void FreeUno( const com::sun::star::uno::Reference< com::sun::star::chart::XChartDataChangeEventListener >& rListener,
192 const com::sun::star::uno::Reference< com::sun::star::chart::XChartData >& rSource );
193 void StartTimer();
194 void UpdateDirtyCharts();
195 SC_DLLPUBLIC void SetDirty();
196 void SetDiffDirty( const ScChartListenerCollection&,
197 bool bSetChartRangeLists = false );
199 void SetRangeDirty( const ScRange& rRange ); // for example rows/columns
201 void UpdateScheduledSeriesRanges();
202 void UpdateChartsContainingTab( SCTAB nTab );
204 bool operator==( const ScChartListenerCollection& r ) const;
205 bool operator!=( const ScChartListenerCollection& r ) const;
208 * Start listening on hide/show change within specified cell range. A
209 * single listener may listen on multiple ranges when the caller passes
210 * the same pointer multiple times with different ranges.
212 * Note that the caller is responsible for managing the life-cycle of the
213 * listener instance.
215 void StartListeningHiddenRange( const ScRange& rRange,
216 ScChartHiddenRangeListener* pListener );
219 * Remove all ranges associated with passed listener instance from the
220 * list of hidden range listeners. This does not delete the passed
221 * listener instance.
223 void EndListeningHiddenRange( ScChartHiddenRangeListener* pListener );
226 #endif
228 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */