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