LCOV - code coverage report
Current view: top level - sd/source/ui/presenter - PresenterPreviewCache.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 2 151 1.3 %
Date: 2014-04-11 Functions: 1 32 3.1 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10