1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unocpres.cxx,v $
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
);
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 );
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() );
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
;
114 throw lang::IllegalArgumentException();
116 SdDrawPage
* pPage
= SdDrawPage::getImplementation( xPage
);
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
);
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() );
139 throw lang::DisposedException();
143 uno::Reference
< drawing::XDrawPage
> xPage
;
144 getByIndex( Index
) >>= xPage
;
148 SvxDrawPage
* pPage
= SvxDrawPage::getImplementation( xPage
);
150 mpSdCustomShow
->Remove(pPage
->GetSdrPage());
155 mpModel
->SetModified();
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
);
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() );
179 throw lang::DisposedException();
181 return getCount() > 0;
185 sal_Int32 SAL_CALL
SdXCustomPresentation::getCount()
186 throw(uno::RuntimeException
)
188 OGuard
aGuard( Application::GetSolarMutex() );
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() );
201 throw lang::DisposedException();
203 if( Index
< 0 || Index
>= (sal_Int32
)mpSdCustomShow
->Count() )
204 throw lang::IndexOutOfBoundsException();
209 SdrPage
* pPage
= (SdrPage
*)mpSdCustomShow
->GetObject(Index
);
213 uno::Reference
< drawing::XDrawPage
> xRef( pPage
->getUnoPage(), uno::UNO_QUERY
);
222 OUString SAL_CALL
SdXCustomPresentation::getName()
223 throw(uno::RuntimeException
)
225 OGuard
aGuard( Application::GetSolarMutex() );
228 throw lang::DisposedException();
231 return mpSdCustomShow
->GetName();
236 void SAL_CALL
SdXCustomPresentation::setName( const OUString
& aName
)
237 throw(uno::RuntimeException
)
239 OGuard
aGuard( Application::GetSolarMutex() );
242 throw lang::DisposedException();
245 mpSdCustomShow
->SetName( aName
);
249 void SAL_CALL
SdXCustomPresentation::dispose() throw(uno::RuntimeException
)
251 OGuard
aGuard( Application::GetSolarMutex() );
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
)
272 throw lang::DisposedException();
274 aDisposeListeners
.addInterface(xListener
);
277 //----------------------------------------------------------------------
278 void SAL_CALL
SdXCustomPresentation::removeEventListener( const uno::Reference
< lang::XEventListener
>& aListener
) throw(uno::RuntimeException
)
281 aDisposeListeners
.removeInterface(aListener
);
284 /*===========================================================================*
285 * class SdXCustomPresentationAccess : public XCustomPresentationAccess, *
287 *===========================================================================*/
289 SdXCustomPresentationAccess::SdXCustomPresentationAccess(SdXImpressDocument
& rMyModel
) throw()
294 SdXCustomPresentationAccess::~SdXCustomPresentationAccess() throw()
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 );
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() );
327 uno::Reference
< uno::XInterface
> SAL_CALL
SdXCustomPresentationAccess::createInstanceWithArguments( const uno::Sequence
< uno::Any
>& )
328 throw(uno::Exception
, uno::RuntimeException
)
330 return createInstance();
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
342 pList
= mrModel
.GetDoc()->GetCustomShowList(sal_True
);
344 // no list, no cookies
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
);
356 throw lang::IllegalArgumentException();
358 // get the internal custom show from the api wrapper
359 SdCustomShow
* pShow
= pXShow
->GetSdCustomShow();
362 pShow
= new SdCustomShow( mrModel
.GetDoc(), xContainer
);
363 pXShow
->SetSdCustomShow( pShow
);
367 if( NULL
== pXShow
->GetModel() || *pXShow
->GetModel() != mrModel
)
368 throw lang::IllegalArgumentException();
372 pShow
->SetName( aName
);
374 // check if this or another customshow with the same name already exists
375 for( SdCustomShow
* pCompare
= (SdCustomShow
*)pList
->First();
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();
397 delete (SdCustomShow
*)pList
->Remove( pShow
);
399 throw container::NoSuchElementException();
401 mrModel
.SetModified();
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
);
413 uno::Any SAL_CALL
SdXCustomPresentationAccess::getByName( const OUString
& aName
)
414 throw(container::NoSuchElementException
, lang::WrappedTargetException
, uno::RuntimeException
)
416 OGuard
aGuard( Application::GetSolarMutex() );
420 SdCustomShow
* pShow
= getSdCustomShow(aName
);
423 uno::Reference
< container::XIndexContainer
> xRef( pShow
->getUnoCustomShow(), uno::UNO_QUERY
);
428 throw container::NoSuchElementException();
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();
446 while( nIdx
< nCount
)
448 const SdCustomShow
* pShow
= (const SdCustomShow
*)pList
->GetObject(nIdx
);
449 pStringList
[nIdx
] = pShow
->GetName();
457 sal_Bool SAL_CALL
SdXCustomPresentationAccess::hasByName( const OUString
& aName
)
458 throw(uno::RuntimeException
)
460 OGuard
aGuard( Application::GetSolarMutex() );
461 return getSdCustomShow(aName
) != NULL
;
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()
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
)
499 sal_Int32
SdXCustomPresentationAccess::getSdCustomShowIdx( const OUString
& Name
) const throw()
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
)