1*5b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5b190011SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5b190011SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5b190011SAndrew Rist  * distributed with this work for additional information
6*5b190011SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5b190011SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5b190011SAndrew Rist  * "License"); you may not use this file except in compliance
9*5b190011SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*5b190011SAndrew Rist  *
11*5b190011SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*5b190011SAndrew Rist  *
13*5b190011SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5b190011SAndrew Rist  * software distributed under the License is distributed on an
15*5b190011SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5b190011SAndrew Rist  * KIND, either express or implied.  See the License for the
17*5b190011SAndrew Rist  * specific language governing permissions and limitations
18*5b190011SAndrew Rist  * under the License.
19*5b190011SAndrew Rist  *
20*5b190011SAndrew Rist  *************************************************************/
21*5b190011SAndrew Rist 
22*5b190011SAndrew Rist 
23cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
24cdf0e10cSrcweir #include "precompiled_sd.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "precompiled_sd.hxx"
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include "PresenterPreviewCache.hxx"
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include "cache/SlsCacheContext.hxx"
31cdf0e10cSrcweir #include "tools/IdleDetection.hxx"
32cdf0e10cSrcweir #include "sdpage.hxx"
33cdf0e10cSrcweir #include <cppcanvas/vclfactory.hxx>
34cdf0e10cSrcweir #include <com/sun/star/drawing/XDrawPage.hpp>
35cdf0e10cSrcweir #include <com/sun/star/rendering/XBitmapCanvas.hpp>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir using namespace ::com::sun::star;
38cdf0e10cSrcweir using namespace ::com::sun::star::uno;
39cdf0e10cSrcweir using namespace ::sd::slidesorter::cache;
40cdf0e10cSrcweir using ::rtl::OUString;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir namespace sd { namespace presenter {
43cdf0e10cSrcweir 
44cdf0e10cSrcweir 
45cdf0e10cSrcweir class PresenterPreviewCache::PresenterCacheContext : public CacheContext
46cdf0e10cSrcweir {
47cdf0e10cSrcweir public:
48cdf0e10cSrcweir     PresenterCacheContext (void);
49cdf0e10cSrcweir     virtual ~PresenterCacheContext (void);
50cdf0e10cSrcweir 
51cdf0e10cSrcweir     void SetDocumentSlides (
52cdf0e10cSrcweir         const Reference<container::XIndexAccess>& rxSlides,
53cdf0e10cSrcweir         const Reference<XInterface>& rxDocument);
54cdf0e10cSrcweir     void SetVisibleSlideRange (
55cdf0e10cSrcweir         const sal_Int32 nFirstVisibleSlideIndex,
56cdf0e10cSrcweir         const sal_Int32 nLastVisibleSlideIndex);
57cdf0e10cSrcweir     const SdrPage* GetPage (const sal_Int32 nSlideIndex) const;
58cdf0e10cSrcweir     void AddPreviewCreationNotifyListener (const Reference<drawing::XSlidePreviewCacheListener>& rxListener);
59cdf0e10cSrcweir     void RemovePreviewCreationNotifyListener (const Reference<drawing::XSlidePreviewCacheListener>& rxListener);
60cdf0e10cSrcweir 
61cdf0e10cSrcweir     // CacheContext
62cdf0e10cSrcweir     virtual void NotifyPreviewCreation (
63cdf0e10cSrcweir         CacheKey aKey,
64cdf0e10cSrcweir         const Bitmap& rPreview);
65cdf0e10cSrcweir     virtual bool IsIdle (void);
66cdf0e10cSrcweir     virtual bool IsVisible (CacheKey aKey);
67cdf0e10cSrcweir     virtual const SdrPage* GetPage (CacheKey aKey);
68cdf0e10cSrcweir     virtual ::boost::shared_ptr<std::vector<CacheKey> > GetEntryList (bool bVisible);
69cdf0e10cSrcweir     virtual sal_Int32 GetPriority (CacheKey aKey);
70cdf0e10cSrcweir     virtual ::com::sun::star::uno::Reference<com::sun::star::uno::XInterface> GetModel (void);
71cdf0e10cSrcweir 
72cdf0e10cSrcweir private:
73cdf0e10cSrcweir     Reference<container::XIndexAccess> mxSlides;
74cdf0e10cSrcweir     Reference<XInterface> mxDocument;
75cdf0e10cSrcweir     sal_Int32 mnFirstVisibleSlideIndex;
76cdf0e10cSrcweir     sal_Int32 mnLastVisibleSlideIndex;
77cdf0e10cSrcweir     typedef ::std::vector<css::uno::Reference<css::drawing::XSlidePreviewCacheListener> > ListenerContainer;
78cdf0e10cSrcweir     ListenerContainer maListeners;
79cdf0e10cSrcweir 
80cdf0e10cSrcweir     void CallListeners (const sal_Int32 nSlideIndex);
81cdf0e10cSrcweir };
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 
86cdf0e10cSrcweir //===== Service ===============================================================
87cdf0e10cSrcweir 
PresenterPreviewCache_createInstance(const Reference<XComponentContext> & rxContext)88cdf0e10cSrcweir Reference<XInterface> SAL_CALL PresenterPreviewCache_createInstance (
89cdf0e10cSrcweir     const Reference<XComponentContext>& rxContext)
90cdf0e10cSrcweir {
91cdf0e10cSrcweir     return Reference<XInterface>(static_cast<XWeak*>(new PresenterPreviewCache(rxContext)));
92cdf0e10cSrcweir }
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 
PresenterPreviewCache_getImplementationName(void)97cdf0e10cSrcweir ::rtl::OUString PresenterPreviewCache_getImplementationName (void) throw(RuntimeException)
98cdf0e10cSrcweir {
99cdf0e10cSrcweir     return OUString::createFromAscii("com.sun.star.comp.Draw.PresenterPreviewCache");
100cdf0e10cSrcweir }
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 
PresenterPreviewCache_getSupportedServiceNames(void)105cdf0e10cSrcweir Sequence<rtl::OUString> SAL_CALL PresenterPreviewCache_getSupportedServiceNames (void)
106cdf0e10cSrcweir     throw (RuntimeException)
107cdf0e10cSrcweir {
108cdf0e10cSrcweir 	static const ::rtl::OUString sServiceName(
109cdf0e10cSrcweir         ::rtl::OUString::createFromAscii("com.sun.star.drawing.PresenterPreviewCache"));
110cdf0e10cSrcweir 	return Sequence<rtl::OUString>(&sServiceName, 1);
111cdf0e10cSrcweir }
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 
116cdf0e10cSrcweir //===== PresenterPreviewCache =================================================
117cdf0e10cSrcweir 
PresenterPreviewCache(const Reference<XComponentContext> & rxContext)118cdf0e10cSrcweir PresenterPreviewCache::PresenterPreviewCache (const Reference<XComponentContext>& rxContext)
119cdf0e10cSrcweir     : PresenterPreviewCacheInterfaceBase(m_aMutex),
120cdf0e10cSrcweir       maPreviewSize(Size(200,200)),
121cdf0e10cSrcweir       mpCacheContext(new PresenterCacheContext()),
122cdf0e10cSrcweir       mpCache(new PageCache(maPreviewSize, false, mpCacheContext))
123cdf0e10cSrcweir {
124cdf0e10cSrcweir     (void)rxContext;
125cdf0e10cSrcweir }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 
~PresenterPreviewCache(void)130cdf0e10cSrcweir PresenterPreviewCache::~PresenterPreviewCache (void)
131cdf0e10cSrcweir {
132cdf0e10cSrcweir }
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 
137cdf0e10cSrcweir //----- XInitialize -----------------------------------------------------------
138cdf0e10cSrcweir 
initialize(const Sequence<Any> & rArguments)139cdf0e10cSrcweir void SAL_CALL PresenterPreviewCache::initialize (const Sequence<Any>& rArguments)
140cdf0e10cSrcweir     throw(Exception, RuntimeException)
141cdf0e10cSrcweir {
142cdf0e10cSrcweir     if (rArguments.getLength() != 0)
143cdf0e10cSrcweir         throw RuntimeException();
144cdf0e10cSrcweir }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 
149cdf0e10cSrcweir //----- XSlidePreviewCache ----------------------------------------------------
150cdf0e10cSrcweir 
setDocumentSlides(const Reference<container::XIndexAccess> & rxSlides,const Reference<XInterface> & rxDocument)151cdf0e10cSrcweir void SAL_CALL PresenterPreviewCache::setDocumentSlides (
152cdf0e10cSrcweir     const Reference<container::XIndexAccess>& rxSlides,
153cdf0e10cSrcweir     const Reference<XInterface>& rxDocument)
154cdf0e10cSrcweir     throw (RuntimeException)
155cdf0e10cSrcweir {
156cdf0e10cSrcweir     ThrowIfDisposed();
157cdf0e10cSrcweir     OSL_ASSERT(mpCacheContext.get()!=NULL);
158cdf0e10cSrcweir 
159cdf0e10cSrcweir     mpCacheContext->SetDocumentSlides(rxSlides, rxDocument);
160cdf0e10cSrcweir }
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 
setVisibleRange(sal_Int32 nFirstVisibleSlideIndex,sal_Int32 nLastVisibleSlideIndex)165cdf0e10cSrcweir void SAL_CALL PresenterPreviewCache::setVisibleRange (
166cdf0e10cSrcweir     sal_Int32 nFirstVisibleSlideIndex,
167cdf0e10cSrcweir     sal_Int32 nLastVisibleSlideIndex)
168cdf0e10cSrcweir     throw (css::uno::RuntimeException)
169cdf0e10cSrcweir {
170cdf0e10cSrcweir     ThrowIfDisposed();
171cdf0e10cSrcweir     OSL_ASSERT(mpCacheContext.get()!=NULL);
172cdf0e10cSrcweir 
173cdf0e10cSrcweir     mpCacheContext->SetVisibleSlideRange (nFirstVisibleSlideIndex, nLastVisibleSlideIndex);
174cdf0e10cSrcweir }
175cdf0e10cSrcweir 
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 
178cdf0e10cSrcweir 
setPreviewSize(const css::geometry::IntegerSize2D & rSize)179cdf0e10cSrcweir void SAL_CALL PresenterPreviewCache::setPreviewSize (
180cdf0e10cSrcweir     const css::geometry::IntegerSize2D& rSize)
181cdf0e10cSrcweir     throw (css::uno::RuntimeException)
182cdf0e10cSrcweir {
183cdf0e10cSrcweir     ThrowIfDisposed();
184cdf0e10cSrcweir     OSL_ASSERT(mpCache.get()!=NULL);
185cdf0e10cSrcweir 
186cdf0e10cSrcweir     maPreviewSize = Size(rSize.Width, rSize.Height);
187cdf0e10cSrcweir     mpCache->ChangeSize(maPreviewSize, false);
188cdf0e10cSrcweir }
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 
191cdf0e10cSrcweir 
192cdf0e10cSrcweir 
getSlidePreview(sal_Int32 nSlideIndex,const Reference<rendering::XCanvas> & rxCanvas)193cdf0e10cSrcweir Reference<rendering::XBitmap> SAL_CALL PresenterPreviewCache::getSlidePreview (
194cdf0e10cSrcweir     sal_Int32 nSlideIndex,
195cdf0e10cSrcweir     const Reference<rendering::XCanvas>& rxCanvas)
196cdf0e10cSrcweir     throw (css::uno::RuntimeException)
197cdf0e10cSrcweir {
198cdf0e10cSrcweir     ThrowIfDisposed();
199cdf0e10cSrcweir     OSL_ASSERT(mpCacheContext.get()!=NULL);
200cdf0e10cSrcweir 
201cdf0e10cSrcweir     cppcanvas::BitmapCanvasSharedPtr pCanvas (
202cdf0e10cSrcweir         cppcanvas::VCLFactory::getInstance().createCanvas(
203cdf0e10cSrcweir             Reference<rendering::XBitmapCanvas>(rxCanvas, UNO_QUERY)));
204cdf0e10cSrcweir 
205cdf0e10cSrcweir     const SdrPage* pPage = mpCacheContext->GetPage(nSlideIndex);
206cdf0e10cSrcweir     if (pPage == NULL)
207cdf0e10cSrcweir         throw RuntimeException();
208cdf0e10cSrcweir 
209cdf0e10cSrcweir     const BitmapEx aPreview (mpCache->GetPreviewBitmap(pPage,true));
210cdf0e10cSrcweir     if (aPreview.IsEmpty())
211cdf0e10cSrcweir         return NULL;
212cdf0e10cSrcweir     else
213cdf0e10cSrcweir         return cppcanvas::VCLFactory::getInstance().createBitmap(
214cdf0e10cSrcweir             pCanvas,
215cdf0e10cSrcweir             aPreview)->getUNOBitmap();
216cdf0e10cSrcweir }
217cdf0e10cSrcweir 
218cdf0e10cSrcweir 
219cdf0e10cSrcweir 
220cdf0e10cSrcweir 
addPreviewCreationNotifyListener(const Reference<drawing::XSlidePreviewCacheListener> & rxListener)221cdf0e10cSrcweir void SAL_CALL PresenterPreviewCache::addPreviewCreationNotifyListener (
222cdf0e10cSrcweir     const Reference<drawing::XSlidePreviewCacheListener>& rxListener)
223cdf0e10cSrcweir     throw (css::uno::RuntimeException)
224cdf0e10cSrcweir {
225cdf0e10cSrcweir 	if (rBHelper.bDisposed || rBHelper.bInDispose)
226cdf0e10cSrcweir         return;
227cdf0e10cSrcweir     if (rxListener.is())
228cdf0e10cSrcweir         mpCacheContext->AddPreviewCreationNotifyListener(rxListener);
229cdf0e10cSrcweir }
230cdf0e10cSrcweir 
231cdf0e10cSrcweir 
232cdf0e10cSrcweir 
233cdf0e10cSrcweir 
removePreviewCreationNotifyListener(const css::uno::Reference<css::drawing::XSlidePreviewCacheListener> & rxListener)234cdf0e10cSrcweir void SAL_CALL PresenterPreviewCache::removePreviewCreationNotifyListener (
235cdf0e10cSrcweir     const css::uno::Reference<css::drawing::XSlidePreviewCacheListener>& rxListener)
236cdf0e10cSrcweir     throw (css::uno::RuntimeException)
237cdf0e10cSrcweir {
238cdf0e10cSrcweir     ThrowIfDisposed();
239cdf0e10cSrcweir     mpCacheContext->RemovePreviewCreationNotifyListener(rxListener);
240cdf0e10cSrcweir }
241cdf0e10cSrcweir 
242cdf0e10cSrcweir 
243cdf0e10cSrcweir 
244cdf0e10cSrcweir 
pause(void)245cdf0e10cSrcweir void SAL_CALL PresenterPreviewCache::pause (void)
246cdf0e10cSrcweir     throw (css::uno::RuntimeException)
247cdf0e10cSrcweir {
248cdf0e10cSrcweir     ThrowIfDisposed();
249cdf0e10cSrcweir     OSL_ASSERT(mpCache.get()!=NULL);
250cdf0e10cSrcweir     mpCache->Pause();
251cdf0e10cSrcweir }
252cdf0e10cSrcweir 
253cdf0e10cSrcweir 
254cdf0e10cSrcweir 
255cdf0e10cSrcweir 
resume(void)256cdf0e10cSrcweir void SAL_CALL PresenterPreviewCache::resume (void)
257cdf0e10cSrcweir     throw (css::uno::RuntimeException)
258cdf0e10cSrcweir {
259cdf0e10cSrcweir     ThrowIfDisposed();
260cdf0e10cSrcweir     OSL_ASSERT(mpCache.get()!=NULL);
261cdf0e10cSrcweir     mpCache->Resume();
262cdf0e10cSrcweir }
263cdf0e10cSrcweir 
264cdf0e10cSrcweir 
265cdf0e10cSrcweir 
266cdf0e10cSrcweir 
267cdf0e10cSrcweir //-----------------------------------------------------------------------------
268cdf0e10cSrcweir 
ThrowIfDisposed(void)269cdf0e10cSrcweir void PresenterPreviewCache::ThrowIfDisposed (void)
270cdf0e10cSrcweir     throw (::com::sun::star::lang::DisposedException)
271cdf0e10cSrcweir {
272cdf0e10cSrcweir 	if (rBHelper.bDisposed || rBHelper.bInDispose)
273cdf0e10cSrcweir 	{
274cdf0e10cSrcweir         throw lang::DisposedException (
275cdf0e10cSrcweir             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
276cdf0e10cSrcweir                 "PresenterPreviewCache object has already been disposed")),
277cdf0e10cSrcweir             static_cast<uno::XWeak*>(this));
278cdf0e10cSrcweir     }
279cdf0e10cSrcweir }
280cdf0e10cSrcweir 
281cdf0e10cSrcweir 
282cdf0e10cSrcweir 
283cdf0e10cSrcweir 
284cdf0e10cSrcweir //===== PresenterPreviewCache::PresenterCacheContext ==========================
285cdf0e10cSrcweir 
286cdf0e10cSrcweir 
PresenterCacheContext(void)287cdf0e10cSrcweir PresenterPreviewCache::PresenterCacheContext::PresenterCacheContext (void)
288cdf0e10cSrcweir     : mxSlides(),
289cdf0e10cSrcweir       mxDocument(),
290cdf0e10cSrcweir       mnFirstVisibleSlideIndex(-1),
291cdf0e10cSrcweir       mnLastVisibleSlideIndex(-1),
292cdf0e10cSrcweir       maListeners()
293cdf0e10cSrcweir {
294cdf0e10cSrcweir }
295cdf0e10cSrcweir 
296cdf0e10cSrcweir 
297cdf0e10cSrcweir 
298cdf0e10cSrcweir 
~PresenterCacheContext(void)299cdf0e10cSrcweir PresenterPreviewCache::PresenterCacheContext::~PresenterCacheContext (void)
300cdf0e10cSrcweir {
301cdf0e10cSrcweir }
302cdf0e10cSrcweir 
303cdf0e10cSrcweir 
304cdf0e10cSrcweir 
305cdf0e10cSrcweir 
SetDocumentSlides(const Reference<container::XIndexAccess> & rxSlides,const Reference<XInterface> & rxDocument)306cdf0e10cSrcweir void PresenterPreviewCache::PresenterCacheContext::SetDocumentSlides (
307cdf0e10cSrcweir     const Reference<container::XIndexAccess>& rxSlides,
308cdf0e10cSrcweir     const Reference<XInterface>& rxDocument)
309cdf0e10cSrcweir {
310cdf0e10cSrcweir     mxSlides = rxSlides;
311cdf0e10cSrcweir     mxDocument = rxDocument;
312cdf0e10cSrcweir     mnFirstVisibleSlideIndex = -1;
313cdf0e10cSrcweir     mnLastVisibleSlideIndex = -1;
314cdf0e10cSrcweir }
315cdf0e10cSrcweir 
316cdf0e10cSrcweir 
317cdf0e10cSrcweir 
318cdf0e10cSrcweir 
SetVisibleSlideRange(const sal_Int32 nFirstVisibleSlideIndex,const sal_Int32 nLastVisibleSlideIndex)319cdf0e10cSrcweir void PresenterPreviewCache::PresenterCacheContext::SetVisibleSlideRange (
320cdf0e10cSrcweir     const sal_Int32 nFirstVisibleSlideIndex,
321cdf0e10cSrcweir     const sal_Int32 nLastVisibleSlideIndex)
322cdf0e10cSrcweir {
323cdf0e10cSrcweir     if (nFirstVisibleSlideIndex > nLastVisibleSlideIndex || nFirstVisibleSlideIndex<0)
324cdf0e10cSrcweir     {
325cdf0e10cSrcweir         mnFirstVisibleSlideIndex = -1;
326cdf0e10cSrcweir         mnLastVisibleSlideIndex = -1;
327cdf0e10cSrcweir     }
328cdf0e10cSrcweir     else
329cdf0e10cSrcweir     {
330cdf0e10cSrcweir         mnFirstVisibleSlideIndex = nFirstVisibleSlideIndex;
331cdf0e10cSrcweir         mnLastVisibleSlideIndex = nLastVisibleSlideIndex;
332cdf0e10cSrcweir     }
333cdf0e10cSrcweir     if (mxSlides.is() && mnLastVisibleSlideIndex >= mxSlides->getCount())
334cdf0e10cSrcweir         mnLastVisibleSlideIndex = mxSlides->getCount() - 1;
335cdf0e10cSrcweir }
336cdf0e10cSrcweir 
337cdf0e10cSrcweir 
338cdf0e10cSrcweir 
339cdf0e10cSrcweir 
AddPreviewCreationNotifyListener(const Reference<drawing::XSlidePreviewCacheListener> & rxListener)340cdf0e10cSrcweir void PresenterPreviewCache::PresenterCacheContext::AddPreviewCreationNotifyListener (
341cdf0e10cSrcweir     const Reference<drawing::XSlidePreviewCacheListener>& rxListener)
342cdf0e10cSrcweir {
343cdf0e10cSrcweir     maListeners.push_back(rxListener);
344cdf0e10cSrcweir }
345cdf0e10cSrcweir 
346cdf0e10cSrcweir 
347cdf0e10cSrcweir 
348cdf0e10cSrcweir 
RemovePreviewCreationNotifyListener(const Reference<drawing::XSlidePreviewCacheListener> & rxListener)349cdf0e10cSrcweir void PresenterPreviewCache::PresenterCacheContext::RemovePreviewCreationNotifyListener (
350cdf0e10cSrcweir     const Reference<drawing::XSlidePreviewCacheListener>& rxListener)
351cdf0e10cSrcweir {
352cdf0e10cSrcweir     ListenerContainer::iterator iListener;
353cdf0e10cSrcweir     for (iListener=maListeners.begin(); iListener!=maListeners.end(); ++iListener)
354cdf0e10cSrcweir         if (*iListener == rxListener)
355cdf0e10cSrcweir         {
356cdf0e10cSrcweir             maListeners.erase(iListener);
357cdf0e10cSrcweir             return;
358cdf0e10cSrcweir         }
359cdf0e10cSrcweir }
360cdf0e10cSrcweir 
361cdf0e10cSrcweir 
362cdf0e10cSrcweir 
363cdf0e10cSrcweir 
364cdf0e10cSrcweir //----- CacheContext ----------------------------------------------------------
365cdf0e10cSrcweir 
NotifyPreviewCreation(CacheKey aKey,const Bitmap & rPreview)366cdf0e10cSrcweir void PresenterPreviewCache::PresenterCacheContext::NotifyPreviewCreation (
367cdf0e10cSrcweir     CacheKey aKey,
368cdf0e10cSrcweir     const Bitmap& rPreview)
369cdf0e10cSrcweir {
370cdf0e10cSrcweir     (void)rPreview;
371cdf0e10cSrcweir 
372cdf0e10cSrcweir     if ( ! mxSlides.is())
373cdf0e10cSrcweir         return;
374cdf0e10cSrcweir     const sal_Int32 nCount(mxSlides->getCount());
375cdf0e10cSrcweir     for (sal_Int32 nIndex=0; nIndex<nCount; ++nIndex)
376cdf0e10cSrcweir         if (aKey == GetPage(nIndex))
377cdf0e10cSrcweir             CallListeners(nIndex);
378cdf0e10cSrcweir }
379cdf0e10cSrcweir 
380cdf0e10cSrcweir 
381cdf0e10cSrcweir 
382cdf0e10cSrcweir 
IsIdle(void)383cdf0e10cSrcweir bool PresenterPreviewCache::PresenterCacheContext::IsIdle (void)
384cdf0e10cSrcweir {
385cdf0e10cSrcweir     return true;
386cdf0e10cSrcweir     /*
387cdf0e10cSrcweir     sal_Int32 nIdleState (tools::IdleDetection::GetIdleState(NULL));
388cdf0e10cSrcweir     if (nIdleState == tools::IdleDetection::IDET_IDLE)
389cdf0e10cSrcweir         return true;
390cdf0e10cSrcweir     else
391cdf0e10cSrcweir         return false;
392cdf0e10cSrcweir     */
393cdf0e10cSrcweir }
394cdf0e10cSrcweir 
395cdf0e10cSrcweir 
396cdf0e10cSrcweir 
397cdf0e10cSrcweir 
IsVisible(CacheKey aKey)398cdf0e10cSrcweir bool PresenterPreviewCache::PresenterCacheContext::IsVisible (CacheKey aKey)
399cdf0e10cSrcweir {
400cdf0e10cSrcweir     if (mnFirstVisibleSlideIndex < 0)
401cdf0e10cSrcweir         return false;
402cdf0e10cSrcweir     for (sal_Int32 nIndex=mnFirstVisibleSlideIndex; nIndex<=mnLastVisibleSlideIndex; ++nIndex)
403cdf0e10cSrcweir     {
404cdf0e10cSrcweir         const SdrPage* pPage = GetPage(nIndex);
405cdf0e10cSrcweir         if (pPage == static_cast<const SdrPage*>(aKey))
406cdf0e10cSrcweir             return true;
407cdf0e10cSrcweir     }
408cdf0e10cSrcweir     return false;
409cdf0e10cSrcweir }
410cdf0e10cSrcweir 
411cdf0e10cSrcweir 
412cdf0e10cSrcweir 
413cdf0e10cSrcweir 
GetPage(CacheKey aKey)414cdf0e10cSrcweir const SdrPage* PresenterPreviewCache::PresenterCacheContext::GetPage (CacheKey aKey)
415cdf0e10cSrcweir {
416cdf0e10cSrcweir     return static_cast<const SdrPage*>(aKey);
417cdf0e10cSrcweir }
418cdf0e10cSrcweir 
419cdf0e10cSrcweir 
420cdf0e10cSrcweir 
421cdf0e10cSrcweir 
422cdf0e10cSrcweir ::boost::shared_ptr<std::vector<CacheKey> >
GetEntryList(bool bVisible)423cdf0e10cSrcweir     PresenterPreviewCache::PresenterCacheContext::GetEntryList (bool bVisible)
424cdf0e10cSrcweir {
425cdf0e10cSrcweir     ::boost::shared_ptr<std::vector<CacheKey> > pKeys (new std::vector<CacheKey>());
426cdf0e10cSrcweir 
427cdf0e10cSrcweir     if ( ! mxSlides.is())
428cdf0e10cSrcweir         return pKeys;
429cdf0e10cSrcweir 
430cdf0e10cSrcweir     const sal_Int32 nFirstIndex (bVisible ? mnFirstVisibleSlideIndex : 0);
431cdf0e10cSrcweir     const sal_Int32 nLastIndex (bVisible ? mnLastVisibleSlideIndex : mxSlides->getCount()-1);
432cdf0e10cSrcweir 
433cdf0e10cSrcweir     if (nFirstIndex < 0)
434cdf0e10cSrcweir         return pKeys;
435cdf0e10cSrcweir 
436cdf0e10cSrcweir     for (sal_Int32 nIndex=nFirstIndex; nIndex<=nLastIndex; ++nIndex)
437cdf0e10cSrcweir     {
438cdf0e10cSrcweir         pKeys->push_back(GetPage(nIndex));
439cdf0e10cSrcweir     }
440cdf0e10cSrcweir 
441cdf0e10cSrcweir     return pKeys;
442cdf0e10cSrcweir }
443cdf0e10cSrcweir 
444cdf0e10cSrcweir 
445cdf0e10cSrcweir 
446cdf0e10cSrcweir 
GetPriority(CacheKey aKey)447cdf0e10cSrcweir sal_Int32 PresenterPreviewCache::PresenterCacheContext::GetPriority (CacheKey aKey)
448cdf0e10cSrcweir {
449cdf0e10cSrcweir     if ( ! mxSlides.is())
450cdf0e10cSrcweir         return 0;
451cdf0e10cSrcweir 
452cdf0e10cSrcweir     const sal_Int32 nCount (mxSlides->getCount());
453cdf0e10cSrcweir 
454cdf0e10cSrcweir     for (sal_Int32 nIndex=mnFirstVisibleSlideIndex; nIndex<=mnLastVisibleSlideIndex; ++nIndex)
455cdf0e10cSrcweir         if (aKey == GetPage(nIndex))
456cdf0e10cSrcweir             return -nCount-1+nIndex;
457cdf0e10cSrcweir 
458cdf0e10cSrcweir     for (sal_Int32 nIndex=0; nIndex<=nCount; ++nIndex)
459cdf0e10cSrcweir         if (aKey == GetPage(nIndex))
460cdf0e10cSrcweir             return nIndex;
461cdf0e10cSrcweir 
462cdf0e10cSrcweir     return 0;
463cdf0e10cSrcweir }
464cdf0e10cSrcweir 
465cdf0e10cSrcweir 
466cdf0e10cSrcweir 
467cdf0e10cSrcweir 
GetModel(void)468cdf0e10cSrcweir Reference<XInterface> PresenterPreviewCache::PresenterCacheContext::GetModel (void)
469cdf0e10cSrcweir {
470cdf0e10cSrcweir     return mxDocument;
471cdf0e10cSrcweir }
472cdf0e10cSrcweir 
473cdf0e10cSrcweir 
474cdf0e10cSrcweir 
475cdf0e10cSrcweir 
476cdf0e10cSrcweir //-----------------------------------------------------------------------------
477cdf0e10cSrcweir 
GetPage(const sal_Int32 nSlideIndex) const478cdf0e10cSrcweir const SdrPage* PresenterPreviewCache::PresenterCacheContext::GetPage (
479cdf0e10cSrcweir     const sal_Int32 nSlideIndex) const
480cdf0e10cSrcweir {
481cdf0e10cSrcweir     if ( ! mxSlides.is())
482cdf0e10cSrcweir         return NULL;
483cdf0e10cSrcweir     if (nSlideIndex < 0 || nSlideIndex >= mxSlides->getCount())
484cdf0e10cSrcweir         return NULL;
485cdf0e10cSrcweir 
486cdf0e10cSrcweir     Reference<drawing::XDrawPage> xSlide (mxSlides->getByIndex(nSlideIndex), UNO_QUERY);
487cdf0e10cSrcweir     const SdPage* pPage = SdPage::getImplementation(xSlide);
488cdf0e10cSrcweir     return dynamic_cast<const SdrPage*>(pPage);
489cdf0e10cSrcweir }
490cdf0e10cSrcweir 
491cdf0e10cSrcweir 
492cdf0e10cSrcweir 
493cdf0e10cSrcweir 
CallListeners(const sal_Int32 nIndex)494cdf0e10cSrcweir void PresenterPreviewCache::PresenterCacheContext::CallListeners (
495cdf0e10cSrcweir     const sal_Int32 nIndex)
496cdf0e10cSrcweir {
497cdf0e10cSrcweir     ListenerContainer aListeners (maListeners);
498cdf0e10cSrcweir     ListenerContainer::const_iterator iListener;
499cdf0e10cSrcweir     for (iListener=aListeners.begin(); iListener!=aListeners.end(); ++iListener)
500cdf0e10cSrcweir     {
501cdf0e10cSrcweir         try
502cdf0e10cSrcweir         {
503cdf0e10cSrcweir             (*iListener)->notifyPreviewCreation(nIndex);
504cdf0e10cSrcweir         }
505cdf0e10cSrcweir         catch (lang::DisposedException&)
506cdf0e10cSrcweir         {
507cdf0e10cSrcweir             RemovePreviewCreationNotifyListener(*iListener);
508cdf0e10cSrcweir         }
509cdf0e10cSrcweir     }
510cdf0e10cSrcweir }
511cdf0e10cSrcweir 
512cdf0e10cSrcweir } } // end of namespace ::sd::presenter
513