Update ooo320-m1
[ooovba.git] / sd / source / ui / unoidl / unocpres.cxx
blob5dcf080a1a7516f3199e2eb2e6a5a19aa897cb2f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unocpres.cxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
33 #include <com/sun/star/lang/DisposedException.hpp>
34 #include <osl/mutex.hxx>
35 #include <vos/mutex.hxx>
36 #include <vcl/svapp.hxx>
37 #include <svx/svdpage.hxx>
38 #include <comphelper/extract.hxx>
40 #include "unohelp.hxx"
41 #include "unomodel.hxx"
42 #include "drawdoc.hxx"
43 #include "unocpres.hxx"
44 #include "cusshow.hxx"
45 #include "unopage.hxx"
47 using namespace ::rtl;
48 using namespace ::vos;
49 using namespace ::com::sun::star;
52 uno::Reference< uno::XInterface > createUnoCustomShow( SdCustomShow* pShow )
54 return (cppu::OWeakObject*)new SdXCustomPresentation( pShow, NULL );
57 SdXCustomPresentation::SdXCustomPresentation() throw()
58 : mpSdCustomShow(NULL), mpModel(NULL),
59 aDisposeListeners( aDisposeContainerMutex ),
60 bDisposing( sal_False )
64 SdXCustomPresentation::SdXCustomPresentation( SdCustomShow* pShow, SdXImpressDocument* pMyModel) throw()
65 : mpSdCustomShow(pShow), mpModel(pMyModel),
66 aDisposeListeners( aDisposeContainerMutex ),
67 bDisposing( sal_False )
71 SdXCustomPresentation::~SdXCustomPresentation() throw()
75 UNO3_GETIMPLEMENTATION_IMPL( SdXCustomPresentation );
77 // XServiceInfo
78 OUString SAL_CALL SdXCustomPresentation::getImplementationName()
79 throw(uno::RuntimeException)
81 return OUString( RTL_CONSTASCII_USTRINGPARAM("SdXCustomPresentation") );
84 sal_Bool SAL_CALL SdXCustomPresentation::supportsService( const OUString& ServiceName )
85 throw(uno::RuntimeException)
87 return SvxServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() );
90 uno::Sequence< OUString > SAL_CALL SdXCustomPresentation::getSupportedServiceNames()
91 throw(uno::RuntimeException)
93 OUString aSN( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.CustomPresentation") );
94 uno::Sequence< OUString > aSeq( &aSN, 1 );
95 return aSeq;
98 // XIndexContainer
99 void SAL_CALL SdXCustomPresentation::insertByIndex( sal_Int32 Index, const uno::Any& Element )
100 throw(lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
102 OGuard aGuard( Application::GetSolarMutex() );
104 if( bDisposing )
105 throw lang::DisposedException();
107 if( Index < 0 || Index > (sal_Int32)( mpSdCustomShow ? mpSdCustomShow->Count() : 0 ) )
108 throw lang::IndexOutOfBoundsException();
110 uno::Reference< drawing::XDrawPage > xPage;
111 Element >>= xPage;
113 if(!xPage.is())
114 throw lang::IllegalArgumentException();
116 SdDrawPage* pPage = SdDrawPage::getImplementation( xPage );
118 if(pPage)
120 if( NULL == mpModel )
121 mpModel = pPage->GetModel();
123 if( NULL != mpModel && NULL == mpSdCustomShow && mpModel->GetDoc() )
124 mpSdCustomShow = new SdCustomShow( mpModel->GetDoc() );
126 mpSdCustomShow->Insert(pPage->GetSdrPage(), Index);
129 if( mpModel )
130 mpModel->SetModified();
133 void SAL_CALL SdXCustomPresentation::removeByIndex( sal_Int32 Index )
134 throw(lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
136 OGuard aGuard( Application::GetSolarMutex() );
138 if( bDisposing )
139 throw lang::DisposedException();
141 if(mpSdCustomShow)
143 uno::Reference< drawing::XDrawPage > xPage;
144 getByIndex( Index ) >>= xPage;
146 if( xPage.is() )
148 SvxDrawPage* pPage = SvxDrawPage::getImplementation( xPage );
149 if(pPage)
150 mpSdCustomShow->Remove(pPage->GetSdrPage());
154 if( mpModel )
155 mpModel->SetModified();
158 // XIndexReplace
159 void SAL_CALL SdXCustomPresentation::replaceByIndex( sal_Int32 Index, const uno::Any& Element )
160 throw(lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
162 removeByIndex( Index );
163 insertByIndex( Index, Element );
166 // XElementAccess
167 uno::Type SAL_CALL SdXCustomPresentation::getElementType()
168 throw(uno::RuntimeException)
170 return ITYPE( drawing::XDrawPage );
173 sal_Bool SAL_CALL SdXCustomPresentation::hasElements()
174 throw(uno::RuntimeException)
176 OGuard aGuard( Application::GetSolarMutex() );
178 if( bDisposing )
179 throw lang::DisposedException();
181 return getCount() > 0;
184 // XIndexAccess
185 sal_Int32 SAL_CALL SdXCustomPresentation::getCount()
186 throw(uno::RuntimeException)
188 OGuard aGuard( Application::GetSolarMutex() );
189 if( bDisposing )
190 throw lang::DisposedException();
192 return mpSdCustomShow?mpSdCustomShow->Count():0;
195 uno::Any SAL_CALL SdXCustomPresentation::getByIndex( sal_Int32 Index )
196 throw(lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
198 OGuard aGuard( Application::GetSolarMutex() );
200 if( bDisposing )
201 throw lang::DisposedException();
203 if( Index < 0 || Index >= (sal_Int32)mpSdCustomShow->Count() )
204 throw lang::IndexOutOfBoundsException();
206 uno::Any aAny;
207 if(mpSdCustomShow )
209 SdrPage* pPage = (SdrPage*)mpSdCustomShow->GetObject(Index);
211 if( pPage )
213 uno::Reference< drawing::XDrawPage > xRef( pPage->getUnoPage(), uno::UNO_QUERY );
214 aAny <<= xRef;
218 return aAny;
221 // XNamed
222 OUString SAL_CALL SdXCustomPresentation::getName()
223 throw(uno::RuntimeException)
225 OGuard aGuard( Application::GetSolarMutex() );
227 if( bDisposing )
228 throw lang::DisposedException();
230 if(mpSdCustomShow)
231 return mpSdCustomShow->GetName();
233 return OUString();
236 void SAL_CALL SdXCustomPresentation::setName( const OUString& aName )
237 throw(uno::RuntimeException)
239 OGuard aGuard( Application::GetSolarMutex() );
241 if( bDisposing )
242 throw lang::DisposedException();
244 if(mpSdCustomShow)
245 mpSdCustomShow->SetName( aName );
248 // XComponent
249 void SAL_CALL SdXCustomPresentation::dispose() throw(uno::RuntimeException)
251 OGuard aGuard( Application::GetSolarMutex() );
253 if( bDisposing )
254 return; // catched a recursion
256 bDisposing = sal_True;
258 uno::Reference< uno::XInterface > xSource( (cppu::OWeakObject*)this );
260 lang::EventObject aEvt;
261 aEvt.Source = xSource;
262 aDisposeListeners.disposeAndClear(aEvt);
264 mpSdCustomShow = NULL;
267 //----------------------------------------------------------------------
268 void SAL_CALL SdXCustomPresentation::addEventListener( const uno::Reference< lang::XEventListener >& xListener )
269 throw(uno::RuntimeException)
271 if( bDisposing )
272 throw lang::DisposedException();
274 aDisposeListeners.addInterface(xListener);
277 //----------------------------------------------------------------------
278 void SAL_CALL SdXCustomPresentation::removeEventListener( const uno::Reference< lang::XEventListener >& aListener ) throw(uno::RuntimeException)
280 if( !bDisposing )
281 aDisposeListeners.removeInterface(aListener);
284 /*===========================================================================*
285 * class SdXCustomPresentationAccess : public XCustomPresentationAccess, *
286 * public UsrObject *
287 *===========================================================================*/
289 SdXCustomPresentationAccess::SdXCustomPresentationAccess(SdXImpressDocument& rMyModel) throw()
290 : mrModel(rMyModel)
294 SdXCustomPresentationAccess::~SdXCustomPresentationAccess() throw()
298 // XServiceInfo
299 OUString SAL_CALL SdXCustomPresentationAccess::getImplementationName()
300 throw(uno::RuntimeException)
302 return OUString( RTL_CONSTASCII_USTRINGPARAM("SdXCustomPresentationAccess") );
305 sal_Bool SAL_CALL SdXCustomPresentationAccess::supportsService( const OUString& ServiceName )
306 throw(uno::RuntimeException)
308 return SvxServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() );
311 uno::Sequence< OUString > SAL_CALL SdXCustomPresentationAccess::getSupportedServiceNames()
312 throw(uno::RuntimeException)
314 const OUString aNS( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.CustomPresentationAccess") );
315 uno::Sequence< OUString > aSeq( &aNS, 1 );
316 return aSeq;
319 // XSingleServiceFactory
320 uno::Reference< uno::XInterface > SAL_CALL SdXCustomPresentationAccess::createInstance()
321 throw(uno::Exception, uno::RuntimeException)
323 uno::Reference< uno::XInterface > xRef( (::cppu::OWeakObject*)new SdXCustomPresentation() );
324 return xRef;
327 uno::Reference< uno::XInterface > SAL_CALL SdXCustomPresentationAccess::createInstanceWithArguments( const uno::Sequence< uno::Any >& )
328 throw(uno::Exception, uno::RuntimeException)
330 return createInstance();
333 // XNameContainer
334 void SAL_CALL SdXCustomPresentationAccess::insertByName( const OUString& aName, const uno::Any& aElement )
335 throw(lang::IllegalArgumentException, container::ElementExistException, lang::WrappedTargetException, uno::RuntimeException)
337 OGuard aGuard( Application::GetSolarMutex() );
339 // get the documents custom show list
340 List* pList = 0;
341 if(mrModel.GetDoc())
342 pList = mrModel.GetDoc()->GetCustomShowList(sal_True);
344 // no list, no cookies
345 if( NULL == pList)
346 throw uno::RuntimeException();
348 // do we have an container::XIndexContainer?
349 SdXCustomPresentation* pXShow = NULL;
351 uno::Reference< container::XIndexContainer > xContainer;
352 if( (aElement >>= xContainer) && xContainer.is() )
353 pXShow = SdXCustomPresentation::getImplementation(xContainer);
355 if( NULL == pXShow )
356 throw lang::IllegalArgumentException();
358 // get the internal custom show from the api wrapper
359 SdCustomShow* pShow = pXShow->GetSdCustomShow();
360 if( NULL == pShow )
362 pShow = new SdCustomShow( mrModel.GetDoc(), xContainer );
363 pXShow->SetSdCustomShow( pShow );
365 else
367 if( NULL == pXShow->GetModel() || *pXShow->GetModel() != mrModel )
368 throw lang::IllegalArgumentException();
371 // give it a name
372 pShow->SetName( aName);
374 // check if this or another customshow with the same name already exists
375 for( SdCustomShow* pCompare = (SdCustomShow*)pList->First();
376 pCompare;
377 pCompare = (SdCustomShow*)pList->Next() )
379 if( pCompare == pShow || pCompare->GetName() == pShow->GetName() )
380 throw container::ElementExistException();
383 pList->Insert(pShow);
385 mrModel.SetModified();
388 void SAL_CALL SdXCustomPresentationAccess::removeByName( const OUString& Name )
389 throw(container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
391 OGuard aGuard( Application::GetSolarMutex() );
393 SdCustomShow* pShow = getSdCustomShow(Name);
395 List* pList = GetCustomShowList();
396 if(pList && pShow)
397 delete (SdCustomShow*)pList->Remove( pShow );
398 else
399 throw container::NoSuchElementException();
401 mrModel.SetModified();
404 // XNameReplace
405 void SAL_CALL SdXCustomPresentationAccess::replaceByName( const OUString& aName, const uno::Any& aElement )
406 throw(lang::IllegalArgumentException, container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
408 removeByName( aName );
409 insertByName( aName, aElement );
412 // XNameAccess
413 uno::Any SAL_CALL SdXCustomPresentationAccess::getByName( const OUString& aName )
414 throw(container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
416 OGuard aGuard( Application::GetSolarMutex() );
418 uno::Any aAny;
420 SdCustomShow* pShow = getSdCustomShow(aName);
421 if(pShow)
423 uno::Reference< container::XIndexContainer > xRef( pShow->getUnoCustomShow(), uno::UNO_QUERY );
424 aAny <<= xRef;
426 else
428 throw container::NoSuchElementException();
431 return aAny;
434 uno::Sequence< OUString > SAL_CALL SdXCustomPresentationAccess::getElementNames()
435 throw(uno::RuntimeException)
437 OGuard aGuard( Application::GetSolarMutex() );
439 List* pList = GetCustomShowList();
440 const sal_uInt32 nCount = pList?pList->Count():0;
442 uno::Sequence< OUString > aSequence( nCount );
443 OUString* pStringList = aSequence.getArray();
445 sal_uInt32 nIdx = 0;
446 while( nIdx < nCount )
448 const SdCustomShow* pShow = (const SdCustomShow*)pList->GetObject(nIdx);
449 pStringList[nIdx] = pShow->GetName();
450 nIdx++;
453 return aSequence;
457 sal_Bool SAL_CALL SdXCustomPresentationAccess::hasByName( const OUString& aName )
458 throw(uno::RuntimeException)
460 OGuard aGuard( Application::GetSolarMutex() );
461 return getSdCustomShow(aName) != NULL;
464 // XElementAccess
465 uno::Type SAL_CALL SdXCustomPresentationAccess::getElementType()
466 throw(uno::RuntimeException)
468 return ITYPE( container::XIndexContainer );
471 sal_Bool SAL_CALL SdXCustomPresentationAccess::hasElements()
472 throw(uno::RuntimeException)
474 OGuard aGuard( Application::GetSolarMutex() );
476 List* pList = GetCustomShowList();
477 return pList && pList->Count() > 0;
480 SdCustomShow * SdXCustomPresentationAccess::getSdCustomShow( const OUString& Name ) const throw()
482 sal_uInt32 nIdx = 0;
484 List* pList = GetCustomShowList();
485 const sal_uInt32 nCount = pList?pList->Count():0;
487 const String aName( Name );
489 while( nIdx < nCount )
491 SdCustomShow* pShow = (SdCustomShow*)pList->GetObject(nIdx);
492 if( pShow->GetName() == aName )
493 return pShow;
494 nIdx++;
496 return NULL;
499 sal_Int32 SdXCustomPresentationAccess::getSdCustomShowIdx( const OUString& Name ) const throw()
501 sal_Int32 nIdx = 0;
503 List* pList = GetCustomShowList();
504 const sal_Int32 nCount = pList?pList->Count():0;
506 const String aName( Name );
508 while( nIdx < nCount )
510 SdCustomShow* pShow = (SdCustomShow*)pList->GetObject(nIdx);
511 if( pShow->GetName() == aName )
512 return nIdx;
513 nIdx++;
515 return -1;