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