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