Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef SC_CHARTLIS_HXX
30 : : #define SC_CHARTLIS_HXX
31 : :
32 : :
33 : : #include <vcl/timer.hxx>
34 : : #include <svl/listener.hxx>
35 : : #include "rangelst.hxx"
36 : : #include "token.hxx"
37 : : #include "externalrefmgr.hxx"
38 : :
39 : : #include <memory>
40 : : #include <vector>
41 : : #include <list>
42 : :
43 : : #include <boost/unordered_set.hpp>
44 : : #include <boost/scoped_ptr.hpp>
45 : : #include <boost/ptr_container/ptr_map.hpp>
46 : :
47 : : class ScDocument;
48 : : class ScChartUnoData;
49 : : #include <com/sun/star/chart/XChartData.hpp>
50 : : #include <com/sun/star/chart/XChartDataChangeEventListener.hpp>
51 : :
52 : : class SC_DLLPUBLIC ScChartListener : public SvtListener
53 : : {
54 : : public:
55 : : class ExternalRefListener : public ScExternalRefManager::LinkListener
56 : : {
57 : : public:
58 : : ExternalRefListener(ScChartListener& rParent, ScDocument* pDoc);
59 : : virtual ~ExternalRefListener();
60 : : virtual void notify(sal_uInt16 nFileId, ScExternalRefManager::LinkUpdateType eType);
61 : : void addFileId(sal_uInt16 nFileId);
62 : : void removeFileId(sal_uInt16 nFileId);
63 : : ::boost::unordered_set<sal_uInt16>& getAllFileIds();
64 : :
65 : : private:
66 : : ExternalRefListener();
67 : : ExternalRefListener(const ExternalRefListener& r);
68 : :
69 : : ScChartListener& mrParent;
70 : : ::boost::unordered_set<sal_uInt16> maFileIds;
71 : : ScDocument* mpDoc;
72 : : };
73 : :
74 : : private:
75 : :
76 : : boost::scoped_ptr<ExternalRefListener> mpExtRefListener;
77 : : boost::scoped_ptr<std::vector<ScTokenRef> > mpTokens;
78 : :
79 : : rtl::OUString maName;
80 : : ScChartUnoData* pUnoData;
81 : : ScDocument* mpDoc;
82 : : bool bUsed:1; // for ScChartListenerCollection::FreeUnused
83 : : bool bDirty:1;
84 : : bool bSeriesRangesScheduled:1;
85 : :
86 : : // not implemented
87 : : ScChartListener& operator=( const ScChartListener& );
88 : :
89 : : public:
90 : : ScChartListener( const rtl::OUString& rName, ScDocument* pDoc,
91 : : const ScRangeListRef& rRangeListRef );
92 : : ScChartListener( const rtl::OUString& rName, ScDocument* pDoc,
93 : : ::std::vector<ScTokenRef>* pTokens );
94 : : ScChartListener( const ScChartListener& );
95 : : ~ScChartListener();
96 : :
97 : : const rtl::OUString& GetName() const;
98 : :
99 : : void SetUno( const com::sun::star::uno::Reference< com::sun::star::chart::XChartDataChangeEventListener >& rListener,
100 : : const com::sun::star::uno::Reference< com::sun::star::chart::XChartData >& rSource );
101 : : com::sun::star::uno::Reference< com::sun::star::chart::XChartDataChangeEventListener > GetUnoListener() const;
102 : : com::sun::star::uno::Reference< com::sun::star::chart::XChartData > GetUnoSource() const;
103 : :
104 : 23 : bool IsUno() const { return (pUnoData != NULL); }
105 : :
106 : : virtual void Notify( SvtBroadcaster& rBC, const SfxHint& rHint );
107 : : void StartListeningTo();
108 : : void EndListeningTo();
109 : : void ChangeListening( const ScRangeListRef& rRangeListRef,
110 : : bool bDirty = false );
111 : : void Update();
112 : : ScRangeListRef GetRangeList() const;
113 : : void SetRangeList( const ScRangeListRef& rNew );
114 : 17 : bool IsUsed() const { return bUsed; }
115 : 40 : void SetUsed( bool bFlg ) { bUsed = bFlg; }
116 : 9 : bool IsDirty() const { return bDirty; }
117 : 0 : void SetDirty( bool bFlg ) { bDirty = bFlg; }
118 : :
119 : : void UpdateChartIntersecting( const ScRange& rRange );
120 : :
121 : : // if chart series ranges are to be updated later on (e.g. DeleteTab, InsertTab)
122 : : void ScheduleSeriesRanges() { bSeriesRangesScheduled = true; }
123 : : void UpdateScheduledSeriesRanges();
124 : : void UpdateSeriesRanges();
125 : :
126 : : ExternalRefListener* GetExtRefListener();
127 : : void SetUpdateQueue();
128 : :
129 : : bool operator==( const ScChartListener& ) const;
130 : : bool operator!=( const ScChartListener& r ) const;
131 : : };
132 : :
133 : : // ============================================================================
134 : :
135 : : class ScChartHiddenRangeListener
136 : : {
137 : : public:
138 : : ScChartHiddenRangeListener();
139 : : virtual ~ScChartHiddenRangeListener();
140 : : virtual void notify() = 0;
141 : : };
142 : :
143 : : // ============================================================================
144 : :
145 : : class ScChartListenerCollection
146 : : {
147 : : public:
148 : 4770 : struct RangeListenerItem
149 : : {
150 : : ScRange maRange;
151 : : ScChartHiddenRangeListener* mpListener;
152 : : explicit RangeListenerItem(const ScRange& rRange, ScChartHiddenRangeListener* p);
153 : : };
154 : :
155 : : typedef boost::ptr_map<rtl::OUString, ScChartListener> ListenersType;
156 : : typedef boost::unordered_set<rtl::OUString, rtl::OUStringHash> StringSetType;
157 : : private:
158 : : ListenersType maListeners;
159 : : ::std::list<RangeListenerItem> maHiddenListeners;
160 : : StringSetType maNonOleObjectNames;
161 : :
162 : : Timer aTimer;
163 : : ScDocument* pDoc;
164 : :
165 : : DECL_LINK(TimerHdl, void *);
166 : :
167 : : // not implemented
168 : : ScChartListenerCollection& operator=( const ScChartListenerCollection& );
169 : :
170 : : public:
171 : : ScChartListenerCollection( ScDocument* pDoc );
172 : : ScChartListenerCollection( const ScChartListenerCollection& );
173 : : ~ScChartListenerCollection();
174 : :
175 : : // only needed after copy-ctor, if newly added to doc
176 : : void StartAllListeners();
177 : :
178 : : SC_DLLPUBLIC void insert(ScChartListener* pListener);
179 : : ScChartListener* findByName(const rtl::OUString& rName);
180 : : const ScChartListener* findByName(const rtl::OUString& rName) const;
181 : : bool hasListeners() const;
182 : :
183 : : const ListenersType& getListeners() const;
184 : : ListenersType& getListeners();
185 : : StringSetType& getNonOleObjectNames();
186 : :
187 : : /**
188 : : * Create a unique name that's not taken by any existing chart listener
189 : : * objects. The name consists of a prefix given followed by a number.
190 : : */
191 : : rtl::OUString getUniqueName(const rtl::OUString& rPrefix) const;
192 : :
193 : : void ChangeListening( const String& rName,
194 : : const ScRangeListRef& rRangeListRef,
195 : : bool bDirty = false );
196 : : // use FreeUnused only the way it's used in ScDocument::UpdateChartListenerCollection
197 : : void FreeUnused();
198 : : void FreeUno( const com::sun::star::uno::Reference< com::sun::star::chart::XChartDataChangeEventListener >& rListener,
199 : : const com::sun::star::uno::Reference< com::sun::star::chart::XChartData >& rSource );
200 : : void StartTimer();
201 : : void UpdateDirtyCharts();
202 : : SC_DLLPUBLIC void SetDirty();
203 : : void SetDiffDirty( const ScChartListenerCollection&,
204 : : bool bSetChartRangeLists = false );
205 : :
206 : : void SetRangeDirty( const ScRange& rRange ); // for example rows/columns
207 : :
208 : : void UpdateScheduledSeriesRanges();
209 : : void UpdateChartsContainingTab( SCTAB nTab );
210 : :
211 : : bool operator==( const ScChartListenerCollection& r ) const;
212 : : bool operator!=( const ScChartListenerCollection& r ) const;
213 : :
214 : : /**
215 : : * Start listening on hide/show change within specified cell range. A
216 : : * single listener may listen on multiple ranges when the caller passes
217 : : * the same pointer multiple times with different ranges.
218 : : *
219 : : * Note that the caller is responsible for managing the life-cycle of the
220 : : * listener instance.
221 : : */
222 : : void StartListeningHiddenRange( const ScRange& rRange,
223 : : ScChartHiddenRangeListener* pListener );
224 : :
225 : : /**
226 : : * Remove all ranges associated with passed listener instance from the
227 : : * list of hidden range listeners. This does not delete the passed
228 : : * listener instance.
229 : : */
230 : : void EndListeningHiddenRange( ScChartHiddenRangeListener* pListener );
231 : : };
232 : :
233 : :
234 : : #endif
235 : :
236 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|