LCOV - code coverage report
Current view: top level - sd/source/ui/presenter - PresenterPreviewCache.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 145 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 30 0.0 %
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             : #include "PresenterPreviewCache.hxx"
      21             : #include "facreg.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             : class PresenterPreviewCache::PresenterCacheContext : public CacheContext
      36             : {
      37             : public:
      38             :     PresenterCacheContext();
      39             :     virtual ~PresenterCacheContext();
      40             : 
      41             :     void SetDocumentSlides (
      42             :         const Reference<container::XIndexAccess>& rxSlides,
      43             :         const Reference<XInterface>& rxDocument);
      44             :     void SetVisibleSlideRange (
      45             :         const sal_Int32 nFirstVisibleSlideIndex,
      46             :         const sal_Int32 nLastVisibleSlideIndex);
      47             :     const SdrPage* GetPage (const sal_Int32 nSlideIndex) const;
      48             :     void AddPreviewCreationNotifyListener (const Reference<drawing::XSlidePreviewCacheListener>& rxListener);
      49             :     void RemovePreviewCreationNotifyListener (const Reference<drawing::XSlidePreviewCacheListener>& rxListener);
      50             : 
      51             :     // CacheContext
      52             :     virtual void NotifyPreviewCreation (
      53             :         CacheKey aKey,
      54             :         const Bitmap& rPreview) SAL_OVERRIDE;
      55             :     virtual bool IsIdle() SAL_OVERRIDE;
      56             :     virtual bool IsVisible (CacheKey aKey) SAL_OVERRIDE;
      57             :     virtual const SdrPage* GetPage (CacheKey aKey) SAL_OVERRIDE;
      58             :     virtual ::boost::shared_ptr<std::vector<CacheKey> > GetEntryList (bool bVisible) SAL_OVERRIDE;
      59             :     virtual sal_Int32 GetPriority (CacheKey aKey) SAL_OVERRIDE;
      60             :     virtual ::com::sun::star::uno::Reference<com::sun::star::uno::XInterface> GetModel() SAL_OVERRIDE;
      61             : 
      62             : private:
      63             :     Reference<container::XIndexAccess> mxSlides;
      64             :     Reference<XInterface> mxDocument;
      65             :     sal_Int32 mnFirstVisibleSlideIndex;
      66             :     sal_Int32 mnLastVisibleSlideIndex;
      67             :     typedef ::std::vector<css::uno::Reference<css::drawing::XSlidePreviewCacheListener> > ListenerContainer;
      68             :     ListenerContainer maListeners;
      69             : 
      70             :     void CallListeners (const sal_Int32 nSlideIndex);
      71             : };
      72             : 
      73             : //===== PresenterPreviewCache =================================================
      74             : 
      75           0 : PresenterPreviewCache::PresenterPreviewCache (const Reference<XComponentContext>& rxContext)
      76             :     : PresenterPreviewCacheInterfaceBase(m_aMutex),
      77             :       maPreviewSize(Size(200,200)),
      78           0 :       mpCacheContext(new PresenterCacheContext()),
      79           0 :       mpCache(new PageCache(maPreviewSize, Bitmap::HasFastScale(), mpCacheContext))
      80             : {
      81             :     (void)rxContext;
      82           0 : }
      83             : 
      84           0 : PresenterPreviewCache::~PresenterPreviewCache()
      85             : {
      86           0 : }
      87             : 
      88             : //----- XInitialize -----------------------------------------------------------
      89             : 
      90           0 : void SAL_CALL PresenterPreviewCache::initialize (const Sequence<Any>& rArguments)
      91             :     throw(Exception, RuntimeException, std::exception)
      92             : {
      93           0 :     if (rArguments.getLength() != 0)
      94           0 :         throw RuntimeException();
      95           0 : }
      96             : 
      97             : //----- XSlidePreviewCache ----------------------------------------------------
      98             : 
      99           0 : void SAL_CALL PresenterPreviewCache::setDocumentSlides (
     100             :     const Reference<container::XIndexAccess>& rxSlides,
     101             :     const Reference<XInterface>& rxDocument)
     102             :     throw (RuntimeException, std::exception)
     103             : {
     104           0 :     ThrowIfDisposed();
     105             :     OSL_ASSERT(mpCacheContext.get()!=NULL);
     106             : 
     107           0 :     mpCacheContext->SetDocumentSlides(rxSlides, rxDocument);
     108           0 : }
     109             : 
     110           0 : void SAL_CALL PresenterPreviewCache::setVisibleRange (
     111             :     sal_Int32 nFirstVisibleSlideIndex,
     112             :     sal_Int32 nLastVisibleSlideIndex)
     113             :     throw (css::uno::RuntimeException, std::exception)
     114             : {
     115           0 :     ThrowIfDisposed();
     116             :     OSL_ASSERT(mpCacheContext.get()!=NULL);
     117             : 
     118           0 :     mpCacheContext->SetVisibleSlideRange (nFirstVisibleSlideIndex, nLastVisibleSlideIndex);
     119           0 : }
     120             : 
     121           0 : void SAL_CALL PresenterPreviewCache::setPreviewSize (
     122             :     const css::geometry::IntegerSize2D& rSize)
     123             :     throw (css::uno::RuntimeException, std::exception)
     124             : {
     125           0 :     ThrowIfDisposed();
     126             :     OSL_ASSERT(mpCache.get()!=NULL);
     127             : 
     128           0 :     maPreviewSize = Size(rSize.Width, rSize.Height);
     129           0 :     mpCache->ChangeSize(maPreviewSize, Bitmap::HasFastScale());
     130           0 : }
     131             : 
     132           0 : Reference<rendering::XBitmap> SAL_CALL PresenterPreviewCache::getSlidePreview (
     133             :     sal_Int32 nSlideIndex,
     134             :     const Reference<rendering::XCanvas>& rxCanvas)
     135             :     throw (css::uno::RuntimeException, std::exception)
     136             : {
     137           0 :     ThrowIfDisposed();
     138             :     OSL_ASSERT(mpCacheContext.get()!=NULL);
     139             : 
     140             :     cppcanvas::CanvasSharedPtr pCanvas (
     141           0 :         cppcanvas::VCLFactory::createCanvas(rxCanvas));
     142             : 
     143           0 :     const SdrPage* pPage = mpCacheContext->GetPage(nSlideIndex);
     144           0 :     if (pPage == NULL)
     145           0 :         throw RuntimeException();
     146             : 
     147           0 :     const BitmapEx aPreview (mpCache->GetPreviewBitmap(pPage,true));
     148           0 :     if (aPreview.IsEmpty())
     149           0 :         return NULL;
     150             :     else
     151             :         return cppcanvas::VCLFactory::createBitmap(
     152             :             pCanvas,
     153           0 :             aPreview)->getUNOBitmap();
     154             : }
     155             : 
     156           0 : void SAL_CALL PresenterPreviewCache::addPreviewCreationNotifyListener (
     157             :     const Reference<drawing::XSlidePreviewCacheListener>& rxListener)
     158             :     throw (css::uno::RuntimeException, std::exception)
     159             : {
     160           0 :     if (rBHelper.bDisposed || rBHelper.bInDispose)
     161           0 :         return;
     162           0 :     if (rxListener.is())
     163           0 :         mpCacheContext->AddPreviewCreationNotifyListener(rxListener);
     164             : }
     165             : 
     166           0 : void SAL_CALL PresenterPreviewCache::removePreviewCreationNotifyListener (
     167             :     const css::uno::Reference<css::drawing::XSlidePreviewCacheListener>& rxListener)
     168             :     throw (css::uno::RuntimeException, std::exception)
     169             : {
     170           0 :     ThrowIfDisposed();
     171           0 :     mpCacheContext->RemovePreviewCreationNotifyListener(rxListener);
     172           0 : }
     173             : 
     174           0 : void SAL_CALL PresenterPreviewCache::pause()
     175             :     throw (css::uno::RuntimeException, std::exception)
     176             : {
     177           0 :     ThrowIfDisposed();
     178             :     OSL_ASSERT(mpCache.get()!=NULL);
     179           0 :     mpCache->Pause();
     180           0 : }
     181             : 
     182           0 : void SAL_CALL PresenterPreviewCache::resume()
     183             :     throw (css::uno::RuntimeException, std::exception)
     184             : {
     185           0 :     ThrowIfDisposed();
     186             :     OSL_ASSERT(mpCache.get()!=NULL);
     187           0 :     mpCache->Resume();
     188           0 : }
     189             : 
     190           0 : void PresenterPreviewCache::ThrowIfDisposed()
     191             :     throw (::com::sun::star::lang::DisposedException)
     192             : {
     193           0 :     if (rBHelper.bDisposed || rBHelper.bInDispose)
     194             :     {
     195             :         throw lang::DisposedException ("PresenterPreviewCache object has already been disposed",
     196           0 :             static_cast<uno::XWeak*>(this));
     197             :     }
     198           0 : }
     199             : 
     200             : //===== PresenterPreviewCache::PresenterCacheContext ==========================
     201             : 
     202           0 : PresenterPreviewCache::PresenterCacheContext::PresenterCacheContext()
     203             :     : mxSlides(),
     204             :       mxDocument(),
     205             :       mnFirstVisibleSlideIndex(-1),
     206             :       mnLastVisibleSlideIndex(-1),
     207           0 :       maListeners()
     208             : {
     209           0 : }
     210             : 
     211           0 : PresenterPreviewCache::PresenterCacheContext::~PresenterCacheContext()
     212             : {
     213           0 : }
     214             : 
     215           0 : void PresenterPreviewCache::PresenterCacheContext::SetDocumentSlides (
     216             :     const Reference<container::XIndexAccess>& rxSlides,
     217             :     const Reference<XInterface>& rxDocument)
     218             : {
     219           0 :     mxSlides = rxSlides;
     220           0 :     mxDocument = rxDocument;
     221           0 :     mnFirstVisibleSlideIndex = -1;
     222           0 :     mnLastVisibleSlideIndex = -1;
     223           0 : }
     224             : 
     225           0 : void PresenterPreviewCache::PresenterCacheContext::SetVisibleSlideRange (
     226             :     const sal_Int32 nFirstVisibleSlideIndex,
     227             :     const sal_Int32 nLastVisibleSlideIndex)
     228             : {
     229           0 :     if (nFirstVisibleSlideIndex > nLastVisibleSlideIndex || nFirstVisibleSlideIndex<0)
     230             :     {
     231           0 :         mnFirstVisibleSlideIndex = -1;
     232           0 :         mnLastVisibleSlideIndex = -1;
     233             :     }
     234             :     else
     235             :     {
     236           0 :         mnFirstVisibleSlideIndex = nFirstVisibleSlideIndex;
     237           0 :         mnLastVisibleSlideIndex = nLastVisibleSlideIndex;
     238             :     }
     239           0 :     if (mxSlides.is() && mnLastVisibleSlideIndex >= mxSlides->getCount())
     240           0 :         mnLastVisibleSlideIndex = mxSlides->getCount() - 1;
     241           0 : }
     242             : 
     243           0 : void PresenterPreviewCache::PresenterCacheContext::AddPreviewCreationNotifyListener (
     244             :     const Reference<drawing::XSlidePreviewCacheListener>& rxListener)
     245             : {
     246           0 :     maListeners.push_back(rxListener);
     247           0 : }
     248             : 
     249           0 : void PresenterPreviewCache::PresenterCacheContext::RemovePreviewCreationNotifyListener (
     250             :     const Reference<drawing::XSlidePreviewCacheListener>& rxListener)
     251             : {
     252           0 :     ListenerContainer::iterator iListener;
     253           0 :     for (iListener=maListeners.begin(); iListener!=maListeners.end(); ++iListener)
     254           0 :         if (*iListener == rxListener)
     255             :         {
     256           0 :             maListeners.erase(iListener);
     257           0 :             return;
     258             :         }
     259             : }
     260             : 
     261             : //----- CacheContext ----------------------------------------------------------
     262             : 
     263           0 : void PresenterPreviewCache::PresenterCacheContext::NotifyPreviewCreation (
     264             :     CacheKey aKey,
     265             :     const Bitmap& rPreview)
     266             : {
     267             :     (void)rPreview;
     268             : 
     269           0 :     if ( ! mxSlides.is())
     270           0 :         return;
     271           0 :     const sal_Int32 nCount(mxSlides->getCount());
     272           0 :     for (sal_Int32 nIndex=0; nIndex<nCount; ++nIndex)
     273           0 :         if (aKey == GetPage(nIndex))
     274           0 :             CallListeners(nIndex);
     275             : }
     276             : 
     277           0 : bool PresenterPreviewCache::PresenterCacheContext::IsIdle()
     278             : {
     279           0 :     return true;
     280             : }
     281             : 
     282           0 : bool PresenterPreviewCache::PresenterCacheContext::IsVisible (CacheKey aKey)
     283             : {
     284           0 :     if (mnFirstVisibleSlideIndex < 0)
     285           0 :         return false;
     286           0 :     for (sal_Int32 nIndex=mnFirstVisibleSlideIndex; nIndex<=mnLastVisibleSlideIndex; ++nIndex)
     287             :     {
     288           0 :         const SdrPage* pPage = GetPage(nIndex);
     289           0 :         if (pPage == static_cast<const SdrPage*>(aKey))
     290           0 :             return true;
     291             :     }
     292           0 :     return false;
     293             : }
     294             : 
     295           0 : const SdrPage* PresenterPreviewCache::PresenterCacheContext::GetPage (CacheKey aKey)
     296             : {
     297           0 :     return static_cast<const SdrPage*>(aKey);
     298             : }
     299             : 
     300             : ::boost::shared_ptr<std::vector<CacheKey> >
     301           0 :     PresenterPreviewCache::PresenterCacheContext::GetEntryList (bool bVisible)
     302             : {
     303           0 :     ::boost::shared_ptr<std::vector<CacheKey> > pKeys (new std::vector<CacheKey>());
     304             : 
     305           0 :     if ( ! mxSlides.is())
     306           0 :         return pKeys;
     307             : 
     308           0 :     const sal_Int32 nFirstIndex (bVisible ? mnFirstVisibleSlideIndex : 0);
     309           0 :     const sal_Int32 nLastIndex (bVisible ? mnLastVisibleSlideIndex : mxSlides->getCount()-1);
     310             : 
     311           0 :     if (nFirstIndex < 0)
     312           0 :         return pKeys;
     313             : 
     314           0 :     for (sal_Int32 nIndex=nFirstIndex; nIndex<=nLastIndex; ++nIndex)
     315             :     {
     316           0 :         pKeys->push_back(GetPage(nIndex));
     317             :     }
     318             : 
     319           0 :     return pKeys;
     320             : }
     321             : 
     322           0 : sal_Int32 PresenterPreviewCache::PresenterCacheContext::GetPriority (CacheKey aKey)
     323             : {
     324           0 :     if ( ! mxSlides.is())
     325           0 :         return 0;
     326             : 
     327           0 :     const sal_Int32 nCount (mxSlides->getCount());
     328             : 
     329           0 :     for (sal_Int32 nIndex=mnFirstVisibleSlideIndex; nIndex<=mnLastVisibleSlideIndex; ++nIndex)
     330           0 :         if (aKey == GetPage(nIndex))
     331           0 :             return -nCount-1+nIndex;
     332             : 
     333           0 :     for (sal_Int32 nIndex=0; nIndex<=nCount; ++nIndex)
     334           0 :         if (aKey == GetPage(nIndex))
     335           0 :             return nIndex;
     336             : 
     337           0 :     return 0;
     338             : }
     339             : 
     340           0 : Reference<XInterface> PresenterPreviewCache::PresenterCacheContext::GetModel()
     341             : {
     342           0 :     return mxDocument;
     343             : }
     344             : 
     345           0 : const SdrPage* PresenterPreviewCache::PresenterCacheContext::GetPage (
     346             :     const sal_Int32 nSlideIndex) const
     347             : {
     348           0 :     if ( ! mxSlides.is())
     349           0 :         return NULL;
     350           0 :     if (nSlideIndex < 0 || nSlideIndex >= mxSlides->getCount())
     351           0 :         return NULL;
     352             : 
     353           0 :     Reference<drawing::XDrawPage> xSlide (mxSlides->getByIndex(nSlideIndex), UNO_QUERY);
     354           0 :     const SdPage* pPage = SdPage::getImplementation(xSlide);
     355           0 :     return dynamic_cast<const SdrPage*>(pPage);
     356             : }
     357             : 
     358           0 : void PresenterPreviewCache::PresenterCacheContext::CallListeners (
     359             :     const sal_Int32 nIndex)
     360             : {
     361           0 :     ListenerContainer aListeners (maListeners);
     362           0 :     ListenerContainer::const_iterator iListener;
     363           0 :     for (iListener=aListeners.begin(); iListener!=aListeners.end(); ++iListener)
     364             :     {
     365             :         try
     366             :         {
     367           0 :             (*iListener)->notifyPreviewCreation(nIndex);
     368             :         }
     369           0 :         catch (lang::DisposedException&)
     370             :         {
     371           0 :             RemovePreviewCreationNotifyListener(*iListener);
     372             :         }
     373           0 :     }
     374           0 : }
     375             : 
     376             : } } // end of namespace ::sd::presenter
     377             : 
     378             : 
     379             : extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL
     380           0 : com_sun_star_comp_Draw_PresenterPreviewCache_get_implementation(::com::sun::star::uno::XComponentContext* context,
     381             :                                                                 ::com::sun::star::uno::Sequence<css::uno::Any> const &)
     382             : {
     383           0 :     return cppu::acquire(new sd::presenter::PresenterPreviewCache(context));
     384             : }
     385             : 
     386             : 
     387             : 
     388             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11