23#include <com/sun/star/uno/Any.hxx>
39class SvLinkSourceTimer :
public Timer
42 virtual void Invoke()
override;
44 explicit SvLinkSourceTimer( SvLinkSource * pOwn );
49SvLinkSourceTimer::SvLinkSourceTimer( SvLinkSource * pOwn )
54void SvLinkSourceTimer::Invoke()
66 pTimer.reset(
new SvLinkSourceTimer(
pOwner ) );
67 pTimer->SetTimeout( nTimeout );
74struct SvLinkSource_Entry_Impl
81 SvLinkSource_Entry_Impl( SvBaseLink*
pLink, OUString aMimeType,
87 explicit SvLinkSource_Entry_Impl( SvBaseLink*
pLink )
92class SvLinkSource_Array_Impl
94friend class SvLinkSource_EntryIter_Impl;
96 std::vector<std::unique_ptr<SvLinkSource_Entry_Impl>>
mvData;
99 SvLinkSource_Array_Impl() {}
102 SvLinkSource_Entry_Impl *operator[](
size_t idx)
const {
return mvData[
idx].get(); }
103 void push_back(SvLinkSource_Entry_Impl* rData) {
mvData.emplace_back(rData); }
105 void DeleteAndDestroy(SvLinkSource_Entry_Impl
const * p)
108 [&p](
const std::unique_ptr<SvLinkSource_Entry_Impl>& rxData) { return rxData.get() == p; });
114class SvLinkSource_EntryIter_Impl
116 std::vector<SvLinkSource_Entry_Impl*>
aArr;
120 explicit SvLinkSource_EntryIter_Impl(
const SvLinkSource_Array_Impl& rArr );
121 SvLinkSource_Entry_Impl*
Curr()
123 SvLinkSource_Entry_Impl*
Next();
124 bool IsValidCurrValue( SvLinkSource_Entry_Impl
const * pEntry );
129SvLinkSource_EntryIter_Impl::SvLinkSource_EntryIter_Impl(
130 const SvLinkSource_Array_Impl& rArr )
133 for (
auto const & i : rArr.mvData)
134 aArr.push_back(
i.get());
137bool SvLinkSource_EntryIter_Impl::IsValidCurrValue( SvLinkSource_Entry_Impl
const * pEntry )
143 for (
auto const & i :
rOrigArr.mvData)
144 if (
i.get() == pEntry)
149SvLinkSource_Entry_Impl* SvLinkSource_EntryIter_Impl::Next()
151 SvLinkSource_Entry_Impl* pRet =
nullptr;
152 if(
nPos + 1 <
static_cast<sal_uInt16
>(
aArr.size()) )
163 for (
auto const & i :
rOrigArr.mvData)
181 std::unique_ptr<SvLinkSourceTimer>
184 css::uno::Reference<css::io::XInputStream>
190 , m_bIsReadOnly(false)
195SvLinkSource::SvLinkSource()
208 pImpl->m_xInputStreamToLoadFrom,
209 pImpl->m_bIsReadOnly);
214 pImpl->m_xInputStreamToLoadFrom = xInputStream;
215 pImpl->m_bIsReadOnly = bIsReadOnly;
221 pImpl->m_xInputStreamToLoadFrom.clear();
226 SvLinkSource_EntryIter_Impl aIter(
pImpl->aArr );
227 for( SvLinkSource_Entry_Impl*
p = aIter.Curr();
p;
p = aIter.Next() )
228 if( !
p->bIsDataSink )
234 return pImpl->nTimeout;
239 pImpl->nTimeout = nTimeout;
241 pImpl->pTimer->SetTimeout( nTimeout );
246 SvLinkSource_EntryIter_Impl aIter(
pImpl->aArr );
247 for( SvLinkSource_Entry_Impl*
p = aIter.Curr();
p;
p = aIter.Next() )
251 OUString sDataMimeType(
pImpl->aDataMimeType );
252 if( sDataMimeType.isEmpty() )
253 sDataMimeType =
p->aDataMimeType;
257 GetData( aVal, sDataMimeType,
true ) )
259 p->xSink->DataChanged( sDataMimeType, aVal );
261 if ( !aIter.IsValidCurrValue(
p ) )
266 pImpl->aArr.DeleteAndDestroy(
p );
272 pImpl->pTimer.reset();
273 pImpl->aDataMimeType.clear();
278 if(
pImpl->nTimeout )
282 SvLinkSource_EntryIter_Impl aIter(
pImpl->aArr );
283 for( SvLinkSource_Entry_Impl*
p = aIter.Curr();
p;
p = aIter.Next() )
288 GetData( aVal,
p->aDataMimeType,
true ) )
290 p->xSink->DataChanged(
p->aDataMimeType, aVal );
292 if ( !aIter.IsValidCurrValue(
p ) )
297 pImpl->aArr.DeleteAndDestroy(
p );
302 pImpl->pTimer.reset();
309 const css::uno::Any & rVal )
311 if(
pImpl->nTimeout && !rVal.hasValue() )
314 pImpl->aDataMimeType = rMimeType;
319 SvLinkSource_EntryIter_Impl aIter(
pImpl->aArr );
320 for( SvLinkSource_Entry_Impl*
p = aIter.Curr();
p;
p = aIter.Next() )
324 p->xSink->DataChanged( rMimeType, rVal );
326 if ( !aIter.IsValidCurrValue(
p ) )
331 pImpl->aArr.DeleteAndDestroy(
p );
336 pImpl->pTimer.reset();
345 SvLinkSource_Entry_Impl* pNew =
new SvLinkSource_Entry_Impl(
347 pImpl->aArr.push_back( pNew );
352 SvLinkSource_EntryIter_Impl aIter(
pImpl->aArr );
353 for( SvLinkSource_Entry_Impl*
p = aIter.Curr();
p;
p = aIter.Next() )
354 if(
p->bIsDataSink &&
p->xSink.get() ==
pLink )
356 pImpl->aArr.DeleteAndDestroy(
p );
363 SvLinkSource_Entry_Impl* pNew =
new SvLinkSource_Entry_Impl(
pLink );
364 pImpl->aArr.push_back( pNew );
369 SvLinkSource_EntryIter_Impl aIter(
pImpl->aArr );
370 for( SvLinkSource_Entry_Impl*
p = aIter.Curr();
p;
p = aIter.Next() )
371 if( !
p->bIsDataSink &&
p->xSink.get() ==
pLink )
373 pImpl->aArr.DeleteAndDestroy(
p );
380 for( sal_uInt16
n = 0, nEnd =
pImpl->aArr.size();
n < nEnd; ++
n )
381 if(
pImpl->aArr[
n ]->bIsDataSink )
virtual bool GetData(css::uno::Any &rData, const OUString &rMimeType, bool bSynchron=false)
void RemoveConnectAdvise(SvBaseLink const *)
void setStreamToLoadFrom(const css::uno::Reference< css::io::XInputStream > &xInputStream, bool bIsReadOnly)
void RemoveAllDataAdvise(SvBaseLink const *)
std::unique_ptr< SvLinkSource_Impl > pImpl
void DataChanged(const OUString &rMimeType, const css::uno::Any &rVal)
void AddDataAdvise(SvBaseLink *, const OUString &rMimeType, sal_uInt16 nAdviceMode)
virtual bool IsPending() const
virtual void Edit(weld::Window *, SvBaseLink *, const Link< const OUString &, void > &rEndEditHdl)
virtual bool Connect(SvBaseLink *)
StreamToLoadFrom getStreamToLoadFrom()
sal_uInt64 GetUpdateTimeout() const
virtual ~SvLinkSource() override
void AddConnectAdvise(SvBaseLink *)
void SetUpdateTimeout(sal_uInt64 nTimeMs)
void clearStreamToLoadFrom()
virtual bool IsDataComplete() const
bool HasDataLinks() const
std::vector< std::unique_ptr< SvLinkSource_Entry_Impl > > mvData
tools::SvRef< SvBaseLink > xSink
const SvLinkSource_Array_Impl & rOrigArr
std::vector< SvLinkSource_Entry_Impl * > aArr
#define ADVISEMODE_NODATA
#define ADVISEMODE_ONLYONCE
static void StartTimer(std::unique_ptr< SvLinkSourceTimer > &pTimer, SvLinkSource *pOwner, sal_uInt64 nTimeout)
tools::SvRef< SvLinkSource > SvLinkSourceRef
const sal_Unicode *const aMimeType[]
std::unique_ptr< SvLinkSourceTimer > pTimer
css::uno::Reference< css::io::XInputStream > m_xInputStreamToLoadFrom
SvLinkSource_Array_Impl aArr