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