LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sd/source/ui/unoidl - unocpres.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 128 220 58.2 %
Date: 2013-07-09 Functions: 24 42 57.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             : #include <algorithm>
      21             : 
      22             : #include <com/sun/star/lang/DisposedException.hpp>
      23             : #include <osl/mutex.hxx>
      24             : #include <vcl/svapp.hxx>
      25             : #include <svx/svdpage.hxx>
      26             : #include <comphelper/extract.hxx>
      27             : #include <comphelper/serviceinfohelper.hxx>
      28             : 
      29             : #include "unohelp.hxx"
      30             : #include "unomodel.hxx"
      31             : #include "drawdoc.hxx"
      32             : #include "unocpres.hxx"
      33             : #include "cusshow.hxx"
      34             : #include "unopage.hxx"
      35             : #include "customshowlist.hxx"
      36             : 
      37             : using namespace ::rtl;
      38             : using namespace ::com::sun::star;
      39             : 
      40             : 
      41           0 : uno::Reference< uno::XInterface > createUnoCustomShow( SdCustomShow* pShow )
      42             : {
      43           0 :     return (cppu::OWeakObject*)new SdXCustomPresentation( pShow, NULL );
      44             : }
      45             : 
      46           3 : SdXCustomPresentation::SdXCustomPresentation() throw()
      47             : :   mpSdCustomShow(NULL), mpModel(NULL),
      48             :     aDisposeListeners( aDisposeContainerMutex ),
      49           3 :     bDisposing( sal_False )
      50             : {
      51           3 : }
      52             : 
      53           0 : SdXCustomPresentation::SdXCustomPresentation( SdCustomShow* pShow, SdXImpressDocument* pMyModel) throw()
      54             : :   mpSdCustomShow(pShow), mpModel(pMyModel),
      55             :     aDisposeListeners( aDisposeContainerMutex ),
      56           0 :     bDisposing( sal_False )
      57             : {
      58           0 : }
      59             : 
      60           6 : SdXCustomPresentation::~SdXCustomPresentation() throw()
      61             : {
      62           6 : }
      63             : 
      64          12 : UNO3_GETIMPLEMENTATION_IMPL( SdXCustomPresentation );
      65             : 
      66             : // XServiceInfo
      67           0 : OUString SAL_CALL SdXCustomPresentation::getImplementationName()
      68             :     throw(uno::RuntimeException)
      69             : {
      70           0 :     return OUString( "SdXCustomPresentation" ) ;
      71             : }
      72             : 
      73           0 : sal_Bool SAL_CALL SdXCustomPresentation::supportsService( const OUString& ServiceName )
      74             :     throw(uno::RuntimeException)
      75             : {
      76           0 :     return comphelper::ServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() );
      77             : }
      78             : 
      79           0 : uno::Sequence< OUString > SAL_CALL SdXCustomPresentation::getSupportedServiceNames()
      80             :     throw(uno::RuntimeException)
      81             : {
      82           0 :     OUString aSN( "com.sun.star.presentation.CustomPresentation" );
      83           0 :     uno::Sequence< OUString > aSeq( &aSN, 1 );
      84           0 :     return aSeq;
      85             : }
      86             : 
      87             : // XIndexContainer
      88           5 : void SAL_CALL SdXCustomPresentation::insertByIndex( sal_Int32 Index, const uno::Any& Element )
      89             :     throw(lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
      90             : {
      91           5 :     SolarMutexGuard aGuard;
      92             : 
      93           5 :     if( bDisposing )
      94           0 :         throw lang::DisposedException();
      95             : 
      96           5 :     if( Index < 0 || Index > (sal_Int32)( mpSdCustomShow ? mpSdCustomShow->PagesVector().size() : 0 ) )
      97           0 :         throw lang::IndexOutOfBoundsException();
      98             : 
      99          10 :     uno::Reference< drawing::XDrawPage > xPage;
     100           5 :     Element >>= xPage;
     101             : 
     102           5 :     if(!xPage.is())
     103           2 :         throw lang::IllegalArgumentException();
     104             : 
     105           3 :     SdDrawPage* pPage = SdDrawPage::getImplementation( xPage );
     106             : 
     107           3 :     if(pPage)
     108             :     {
     109           3 :         if( NULL == mpModel )
     110           1 :             mpModel = pPage->GetModel();
     111             : 
     112           3 :         if( NULL != mpModel && NULL == mpSdCustomShow && mpModel->GetDoc() )
     113           0 :             mpSdCustomShow = new SdCustomShow( mpModel->GetDoc() );
     114             : 
     115           6 :         mpSdCustomShow->PagesVector().insert(mpSdCustomShow->PagesVector().begin() + Index,
     116           9 :             (SdPage*) pPage->GetSdrPage());
     117             :     }
     118             : 
     119           3 :     if( mpModel )
     120           8 :         mpModel->SetModified();
     121           3 : }
     122             : 
     123           6 : void SAL_CALL SdXCustomPresentation::removeByIndex( sal_Int32 Index )
     124             :     throw(lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
     125             : {
     126           6 :     SolarMutexGuard aGuard;
     127             : 
     128           6 :     if( bDisposing )
     129           0 :         throw lang::DisposedException();
     130             : 
     131           6 :     if(mpSdCustomShow)
     132             :     {
     133           6 :         uno::Reference< drawing::XDrawPage > xPage;
     134           6 :         getByIndex( Index ) >>= xPage;
     135             : 
     136           3 :         if( xPage.is() )
     137             :         {
     138           3 :             SvxDrawPage* pPage = SvxDrawPage::getImplementation( xPage );
     139           3 :             if(pPage)
     140             :             {
     141             :                 SdCustomShow::PageVec::iterator it = std::find(
     142           3 :                     mpSdCustomShow->PagesVector().begin(),
     143           3 :                     mpSdCustomShow->PagesVector().end(),
     144           9 :                     pPage->GetSdrPage());
     145           3 :                 if (it != mpSdCustomShow->PagesVector().end())
     146           3 :                     mpSdCustomShow->PagesVector().erase(it);
     147             :             }
     148           6 :         }
     149             :     }
     150             : 
     151           3 :     if( mpModel )
     152           6 :         mpModel->SetModified();
     153           3 : }
     154             : 
     155             : // XIndexReplace
     156           4 : void SAL_CALL SdXCustomPresentation::replaceByIndex( sal_Int32 Index, const uno::Any& Element )
     157             :     throw(lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
     158             : {
     159           4 :     removeByIndex( Index );
     160           2 :     insertByIndex( Index, Element );
     161           1 : }
     162             : 
     163             : // XElementAccess
     164           1 : uno::Type SAL_CALL SdXCustomPresentation::getElementType()
     165             :     throw(uno::RuntimeException)
     166             : {
     167           1 :     return ITYPE( drawing::XDrawPage );
     168             : }
     169             : 
     170           1 : sal_Bool SAL_CALL SdXCustomPresentation::hasElements()
     171             :     throw(uno::RuntimeException)
     172             : {
     173           1 :     SolarMutexGuard aGuard;
     174             : 
     175           1 :     if( bDisposing )
     176           0 :         throw lang::DisposedException();
     177             : 
     178           1 :     return getCount() > 0;
     179             : }
     180             : 
     181             : // XIndexAccess
     182           4 : sal_Int32 SAL_CALL SdXCustomPresentation::getCount()
     183             :     throw(uno::RuntimeException)
     184             : {
     185           4 :     SolarMutexGuard aGuard;
     186           4 :     if( bDisposing )
     187           0 :         throw lang::DisposedException();
     188             : 
     189           4 :     return mpSdCustomShow ? mpSdCustomShow->PagesVector().size() : 0;
     190             : }
     191             : 
     192          13 : uno::Any SAL_CALL SdXCustomPresentation::getByIndex( sal_Int32 Index )
     193             :     throw(lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
     194             : {
     195          13 :     SolarMutexGuard aGuard;
     196             : 
     197          13 :     if( bDisposing )
     198           0 :         throw lang::DisposedException();
     199             : 
     200          13 :     if( Index < 0 || Index >= (sal_Int32)mpSdCustomShow->PagesVector().size() )
     201           4 :         throw lang::IndexOutOfBoundsException();
     202             : 
     203           9 :     uno::Any aAny;
     204           9 :     if(mpSdCustomShow )
     205             :     {
     206           9 :         SdrPage* pPage = (SdrPage*)mpSdCustomShow->PagesVector()[Index];
     207             : 
     208           9 :         if( pPage )
     209             :         {
     210           9 :             uno::Reference< drawing::XDrawPage > xRef( pPage->getUnoPage(), uno::UNO_QUERY );
     211           9 :             aAny <<= xRef;
     212             :         }
     213             :     }
     214             : 
     215          13 :     return aAny;
     216             : }
     217             : 
     218             : // XNamed
     219           3 : OUString SAL_CALL SdXCustomPresentation::getName()
     220             :     throw(uno::RuntimeException)
     221             : {
     222           3 :     SolarMutexGuard aGuard;
     223             : 
     224           3 :     if( bDisposing )
     225           0 :         throw lang::DisposedException();
     226             : 
     227           3 :     if(mpSdCustomShow)
     228           3 :         return mpSdCustomShow->GetName();
     229             : 
     230           0 :     return OUString();
     231             : }
     232             : 
     233           2 : void SAL_CALL SdXCustomPresentation::setName( const OUString& aName )
     234             :     throw(uno::RuntimeException)
     235             : {
     236           2 :     SolarMutexGuard aGuard;
     237             : 
     238           2 :     if( bDisposing )
     239           0 :         throw lang::DisposedException();
     240             : 
     241           2 :     if(mpSdCustomShow)
     242           2 :         mpSdCustomShow->SetName( aName );
     243           2 : }
     244             : 
     245             : // XComponent
     246           3 : void SAL_CALL SdXCustomPresentation::dispose() throw(uno::RuntimeException)
     247             : {
     248           3 :     SolarMutexGuard aGuard;
     249             : 
     250           3 :     if( bDisposing )
     251           3 :         return; // catched a recursion
     252             : 
     253           3 :     bDisposing = sal_True;
     254             : 
     255           6 :     uno::Reference< uno::XInterface > xSource( (cppu::OWeakObject*)this );
     256             : 
     257           6 :     lang::EventObject aEvt;
     258           3 :     aEvt.Source = xSource;
     259           3 :     aDisposeListeners.disposeAndClear(aEvt);
     260             : 
     261           6 :     mpSdCustomShow = NULL;
     262             : }
     263             : 
     264             : //----------------------------------------------------------------------
     265           0 : void SAL_CALL SdXCustomPresentation::addEventListener( const uno::Reference< lang::XEventListener >& xListener )
     266             :     throw(uno::RuntimeException)
     267             : {
     268           0 :     if( bDisposing )
     269           0 :         throw lang::DisposedException();
     270             : 
     271           0 :     aDisposeListeners.addInterface(xListener);
     272           0 : }
     273             : 
     274             : //----------------------------------------------------------------------
     275           0 : void SAL_CALL SdXCustomPresentation::removeEventListener( const uno::Reference< lang::XEventListener >& aListener ) throw(uno::RuntimeException)
     276             : {
     277           0 :     if( !bDisposing )
     278           0 :         aDisposeListeners.removeInterface(aListener);
     279           0 : }
     280             : 
     281             : /*===========================================================================*
     282             :  *  class SdXCustomPresentationAccess : public XCustomPresentationAccess,    *
     283             :  *                                      public UsrObject                     *
     284             :  *===========================================================================*/
     285             : 
     286           8 : SdXCustomPresentationAccess::SdXCustomPresentationAccess(SdXImpressDocument& rMyModel) throw()
     287           8 : : mrModel(rMyModel)
     288             : {
     289           8 : }
     290             : 
     291          16 : SdXCustomPresentationAccess::~SdXCustomPresentationAccess() throw()
     292             : {
     293          16 : }
     294             : 
     295             : // XServiceInfo
     296           0 : OUString SAL_CALL SdXCustomPresentationAccess::getImplementationName()
     297             :     throw(uno::RuntimeException)
     298             : {
     299           0 :     return OUString( "SdXCustomPresentationAccess" );
     300             : }
     301             : 
     302           0 : sal_Bool SAL_CALL SdXCustomPresentationAccess::supportsService( const OUString& ServiceName )
     303             :     throw(uno::RuntimeException)
     304             : {
     305           0 :     return comphelper::ServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() );
     306             : }
     307             : 
     308           0 : uno::Sequence< OUString > SAL_CALL SdXCustomPresentationAccess::getSupportedServiceNames()
     309             :     throw(uno::RuntimeException)
     310             : {
     311           0 :     const OUString aNS( "com.sun.star.presentation.CustomPresentationAccess" );
     312           0 :     uno::Sequence< OUString > aSeq( &aNS, 1 );
     313           0 :     return aSeq;
     314             : }
     315             : 
     316             : // XSingleServiceFactory
     317           3 : uno::Reference< uno::XInterface > SAL_CALL SdXCustomPresentationAccess::createInstance()
     318             :     throw(uno::Exception, uno::RuntimeException)
     319             : {
     320           3 :     uno::Reference< uno::XInterface >  xRef( (::cppu::OWeakObject*)new SdXCustomPresentation() );
     321           3 :     return xRef;
     322             : }
     323             : 
     324           0 : uno::Reference< uno::XInterface > SAL_CALL SdXCustomPresentationAccess::createInstanceWithArguments( const uno::Sequence< uno::Any >& )
     325             :     throw(uno::Exception, uno::RuntimeException)
     326             : {
     327           0 :     return createInstance();
     328             : }
     329             : 
     330             : // XNameContainer
     331           3 : void SAL_CALL SdXCustomPresentationAccess::insertByName( const OUString& aName, const uno::Any& aElement )
     332             :     throw(lang::IllegalArgumentException, container::ElementExistException, lang::WrappedTargetException, uno::RuntimeException)
     333             : {
     334           3 :     SolarMutexGuard aGuard;
     335             : 
     336             :     // get the documents custom show list
     337           3 :     SdCustomShowList* pList = 0;
     338           3 :     if(mrModel.GetDoc())
     339           3 :         pList = mrModel.GetDoc()->GetCustomShowList(sal_True);
     340             : 
     341             :     // no list, no cookies
     342           3 :     if( NULL == pList)
     343           0 :         throw uno::RuntimeException();
     344             : 
     345             :     // do we have an container::XIndexContainer?
     346           3 :     SdXCustomPresentation* pXShow = NULL;
     347             : 
     348           6 :     uno::Reference< container::XIndexContainer > xContainer;
     349           3 :     if( (aElement >>= xContainer) && xContainer.is() )
     350           3 :         pXShow = SdXCustomPresentation::getImplementation(xContainer);
     351             : 
     352           3 :     if( NULL == pXShow )
     353           0 :         throw lang::IllegalArgumentException();
     354             : 
     355             :     // get the internal custom show from the api wrapper
     356           3 :     SdCustomShow* pShow = pXShow->GetSdCustomShow();
     357           3 :     if( NULL == pShow )
     358             :     {
     359           3 :         pShow = new SdCustomShow( mrModel.GetDoc(), xContainer );
     360           3 :         pXShow->SetSdCustomShow( pShow );
     361             :     }
     362             :     else
     363             :     {
     364           0 :         if( NULL == pXShow->GetModel() || *pXShow->GetModel() != mrModel )
     365           0 :             throw lang::IllegalArgumentException();
     366             :     }
     367             : 
     368             :     // give it a name
     369           3 :     pShow->SetName( aName);
     370             : 
     371             :     // check if this or another customshow with the same name already exists
     372           4 :     for( SdCustomShow* pCompare = pList->First();
     373             :          pCompare;
     374             :          pCompare = pList->Next() )
     375             :     {
     376           1 :         if( pCompare == pShow || pCompare->GetName() == pShow->GetName() )
     377           0 :             throw container::ElementExistException();
     378             :     }
     379             : 
     380           3 :     pList->push_back(pShow);
     381             : 
     382           6 :     mrModel.SetModified();
     383           3 : }
     384             : 
     385           0 : void SAL_CALL SdXCustomPresentationAccess::removeByName( const OUString& Name )
     386             :     throw(container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
     387             : {
     388           0 :     SolarMutexGuard aGuard;
     389             : 
     390           0 :     SdCustomShow* pShow = getSdCustomShow(Name);
     391             : 
     392           0 :     SdCustomShowList* pList = GetCustomShowList();
     393           0 :     if(pList && pShow)
     394           0 :         delete pList->Remove( pShow );
     395             :     else
     396           0 :         throw container::NoSuchElementException();
     397             : 
     398           0 :     mrModel.SetModified();
     399           0 : }
     400             : 
     401             : // XNameReplace
     402           0 : void SAL_CALL SdXCustomPresentationAccess::replaceByName( const OUString& aName, const uno::Any& aElement )
     403             :     throw(lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
     404             : {
     405           0 :     removeByName( aName );
     406           0 :     insertByName( aName, aElement );
     407           0 : }
     408             : 
     409             : // XNameAccess
     410           0 : uno::Any SAL_CALL SdXCustomPresentationAccess::getByName( const OUString& aName )
     411             :     throw(container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
     412             : {
     413           0 :     SolarMutexGuard aGuard;
     414             : 
     415           0 :     uno::Any aAny;
     416             : 
     417           0 :     SdCustomShow* pShow = getSdCustomShow(aName);
     418           0 :     if(pShow)
     419             :     {
     420           0 :         uno::Reference< container::XIndexContainer >  xRef( pShow->getUnoCustomShow(), uno::UNO_QUERY );
     421           0 :         aAny <<= xRef;
     422             :     }
     423             :     else
     424             :     {
     425           0 :         throw container::NoSuchElementException();
     426             :     }
     427             : 
     428           0 :     return aAny;
     429             : }
     430             : 
     431           2 : uno::Sequence< OUString > SAL_CALL SdXCustomPresentationAccess::getElementNames()
     432             :     throw(uno::RuntimeException)
     433             : {
     434           2 :     SolarMutexGuard aGuard;
     435             : 
     436           2 :     SdCustomShowList* pList = GetCustomShowList();
     437           2 :     const sal_uInt32 nCount = pList ? pList->size() : 0;
     438             : 
     439           2 :     uno::Sequence< OUString > aSequence( nCount );
     440           2 :     OUString* pStringList = aSequence.getArray();
     441             : 
     442           2 :     sal_uInt32 nIdx = 0;
     443           4 :     while( nIdx < nCount )
     444             :     {
     445           0 :         const SdCustomShow* pShow = (*pList)[nIdx];
     446           0 :         pStringList[nIdx] = pShow->GetName();
     447           0 :         nIdx++;
     448             :     }
     449             : 
     450           2 :     return aSequence;
     451             : }
     452             : 
     453             : 
     454           0 : sal_Bool SAL_CALL SdXCustomPresentationAccess::hasByName( const OUString& aName )
     455             :     throw(uno::RuntimeException)
     456             : {
     457           0 :     SolarMutexGuard aGuard;
     458           0 :     return getSdCustomShow(aName) != NULL;
     459             : }
     460             : 
     461             : // XElementAccess
     462           0 : uno::Type SAL_CALL SdXCustomPresentationAccess::getElementType()
     463             :     throw(uno::RuntimeException)
     464             : {
     465           0 :     return ITYPE( container::XIndexContainer );
     466             : }
     467             : 
     468           0 : sal_Bool SAL_CALL SdXCustomPresentationAccess::hasElements()
     469             :     throw(uno::RuntimeException)
     470             : {
     471           0 :     SolarMutexGuard aGuard;
     472             : 
     473           0 :     SdCustomShowList* pList = GetCustomShowList();
     474           0 :     return pList && !pList->empty();
     475             : }
     476             : 
     477           0 : SdCustomShow * SdXCustomPresentationAccess::getSdCustomShow( const OUString& Name ) const throw()
     478             : {
     479           0 :     sal_uInt32 nIdx = 0;
     480             : 
     481           0 :     SdCustomShowList* pList = GetCustomShowList();
     482           0 :     const sal_uInt32 nCount = pList ? pList->size() : 0;
     483             : 
     484           0 :     const String aName( Name );
     485             : 
     486           0 :     while( nIdx < nCount )
     487             :     {
     488           0 :         SdCustomShow* pShow = (*pList)[nIdx];
     489           0 :         if( pShow->GetName() == aName )
     490           0 :             return pShow;
     491           0 :         nIdx++;
     492             :     }
     493           0 :     return NULL;
     494          33 : }
     495             : 
     496             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10