1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 SC_CHARTLIS_HXX
21 #define SC_CHARTLIS_HXX
23 #include <vcl/timer.hxx>
24 #include <svl/listener.hxx>
25 #include "rangelst.hxx"
27 #include "externalrefmgr.hxx"
33 #include <boost/unordered_set.hpp>
34 #include <boost/scoped_ptr.hpp>
35 #include <boost/ptr_container/ptr_map.hpp>
39 #include <com/sun/star/chart/XChartData.hpp>
40 #include <com/sun/star/chart/XChartDataChangeEventListener.hpp>
42 class SC_DLLPUBLIC ScChartListener
: public SvtListener
45 class ExternalRefListener
: public ScExternalRefManager::LinkListener
48 ExternalRefListener(ScChartListener
& rParent
, ScDocument
* pDoc
);
49 virtual ~ExternalRefListener();
50 virtual void notify(sal_uInt16 nFileId
, ScExternalRefManager::LinkUpdateType eType
);
51 void addFileId(sal_uInt16 nFileId
);
52 void removeFileId(sal_uInt16 nFileId
);
53 ::boost::unordered_set
<sal_uInt16
>& getAllFileIds();
56 ExternalRefListener();
57 ExternalRefListener(const ExternalRefListener
& r
);
59 ScChartListener
& mrParent
;
60 ::boost::unordered_set
<sal_uInt16
> maFileIds
;
66 boost::scoped_ptr
<ExternalRefListener
> mpExtRefListener
;
67 boost::scoped_ptr
<std::vector
<ScTokenRef
> > mpTokens
;
70 ScChartUnoData
* pUnoData
;
72 bool bUsed
:1; // for ScChartListenerCollection::FreeUnused
74 bool bSeriesRangesScheduled
:1;
77 ScChartListener
& operator=( const ScChartListener
& );
80 ScChartListener( const OUString
& rName
, ScDocument
* pDoc
,
81 const ScRangeListRef
& rRangeListRef
);
82 ScChartListener( const OUString
& rName
, ScDocument
* pDoc
,
83 ::std::vector
<ScTokenRef
>* pTokens
);
84 ScChartListener( const ScChartListener
& );
87 const OUString
& GetName() const;
89 void SetUno( const com::sun::star::uno::Reference
< com::sun::star::chart::XChartDataChangeEventListener
>& rListener
,
90 const com::sun::star::uno::Reference
< com::sun::star::chart::XChartData
>& rSource
);
91 com::sun::star::uno::Reference
< com::sun::star::chart::XChartDataChangeEventListener
> GetUnoListener() const;
92 com::sun::star::uno::Reference
< com::sun::star::chart::XChartData
> GetUnoSource() const;
94 bool IsUno() const { return (pUnoData
!= NULL
); }
96 virtual void Notify( SvtBroadcaster
& rBC
, const SfxHint
& rHint
);
97 void StartListeningTo();
98 void EndListeningTo();
99 void ChangeListening( const ScRangeListRef
& rRangeListRef
,
100 bool bDirty
= false );
102 ScRangeListRef
GetRangeList() const;
103 void SetRangeList( const ScRangeListRef
& rNew
);
104 bool IsUsed() const { return bUsed
; }
105 void SetUsed( bool bFlg
) { bUsed
= bFlg
; }
106 bool IsDirty() const { return bDirty
; }
107 void SetDirty( bool bFlg
) { bDirty
= bFlg
; }
109 void UpdateChartIntersecting( const ScRange
& rRange
);
111 // if chart series ranges are to be updated later on (e.g. DeleteTab, InsertTab)
112 void ScheduleSeriesRanges() { bSeriesRangesScheduled
= true; }
113 void UpdateScheduledSeriesRanges();
114 void UpdateSeriesRanges();
116 ExternalRefListener
* GetExtRefListener();
117 void SetUpdateQueue();
119 bool operator==( const ScChartListener
& ) const;
120 bool operator!=( const ScChartListener
& r
) const;
123 class ScChartHiddenRangeListener
126 ScChartHiddenRangeListener();
127 virtual ~ScChartHiddenRangeListener();
128 virtual void notify() = 0;
131 class ScChartListenerCollection
134 struct RangeListenerItem
137 ScChartHiddenRangeListener
* mpListener
;
138 explicit RangeListenerItem(const ScRange
& rRange
, ScChartHiddenRangeListener
* p
);
141 typedef boost::ptr_map
<OUString
, ScChartListener
> ListenersType
;
142 typedef boost::unordered_set
<OUString
, OUStringHash
> StringSetType
;
144 ListenersType maListeners
;
145 ::std::list
<RangeListenerItem
> maHiddenListeners
;
146 StringSetType maNonOleObjectNames
;
151 DECL_LINK(TimerHdl
, void *);
154 ScChartListenerCollection
& operator=( const ScChartListenerCollection
& );
157 ScChartListenerCollection( ScDocument
* pDoc
);
158 ScChartListenerCollection( const ScChartListenerCollection
& );
159 ~ScChartListenerCollection();
161 // only needed after copy-ctor, if newly added to doc
162 void StartAllListeners();
164 SC_DLLPUBLIC
void insert(ScChartListener
* pListener
);
165 ScChartListener
* findByName(const OUString
& rName
);
166 const ScChartListener
* findByName(const OUString
& rName
) const;
167 bool hasListeners() const;
169 void removeByName(const OUString
& rName
);
171 const ListenersType
& getListeners() const;
172 ListenersType
& getListeners();
173 StringSetType
& getNonOleObjectNames();
176 * Create a unique name that's not taken by any existing chart listener
177 * objects. The name consists of a prefix given followed by a number.
179 OUString
getUniqueName(const OUString
& rPrefix
) const;
181 void ChangeListening( const OUString
& rName
,
182 const ScRangeListRef
& rRangeListRef
,
183 bool bDirty
= false );
184 // use FreeUnused only the way it's used in ScDocument::UpdateChartListenerCollection
186 void FreeUno( const com::sun::star::uno::Reference
< com::sun::star::chart::XChartDataChangeEventListener
>& rListener
,
187 const com::sun::star::uno::Reference
< com::sun::star::chart::XChartData
>& rSource
);
189 void UpdateDirtyCharts();
190 SC_DLLPUBLIC
void SetDirty();
191 void SetDiffDirty( const ScChartListenerCollection
&,
192 bool bSetChartRangeLists
= false );
194 void SetRangeDirty( const ScRange
& rRange
); // for example rows/columns
196 void UpdateScheduledSeriesRanges();
197 void UpdateChartsContainingTab( SCTAB nTab
);
199 bool operator==( const ScChartListenerCollection
& r
) const;
200 bool operator!=( const ScChartListenerCollection
& r
) const;
203 * Start listening on hide/show change within specified cell range. A
204 * single listener may listen on multiple ranges when the caller passes
205 * the same pointer multiple times with different ranges.
207 * Note that the caller is responsible for managing the life-cycle of the
210 void StartListeningHiddenRange( const ScRange
& rRange
,
211 ScChartHiddenRangeListener
* pListener
);
214 * Remove all ranges associated with passed listener instance from the
215 * list of hidden range listeners. This does not delete the passed
218 void EndListeningHiddenRange( ScChartHiddenRangeListener
* pListener
);
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */