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