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: unogaltheme.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_svx.hxx"
36 #include "unogaltheme.hxx"
37 #include "unogalitem.hxx"
38 #include "galtheme.hxx"
39 #include "gallery1.hxx"
40 #include "galmisc.hxx"
41 #include <svx/fmmodel.hxx>
43 #include <vos/mutex.hxx>
44 #ifndef _SV_SVAPP_HXX_
45 #include <vcl/svapp.hxx>
47 #include <svtools/pathoptions.hxx>
49 using namespace ::com::sun::star
;
51 namespace unogallery
{
57 GalleryTheme::GalleryTheme( const ::rtl::OUString
& rThemeName
)
59 mpGallery
= ::Gallery::GetGalleryInstance();
60 mpTheme
= ( mpGallery
? mpGallery
->AcquireTheme( rThemeName
, *this ) : NULL
);
63 StartListening( *mpGallery
);
66 // ------------------------------------------------------------------------------
68 GalleryTheme::~GalleryTheme()
70 const ::vos::OGuard
aGuard( Application::GetSolarMutex() );
72 DBG_ASSERT( !mpTheme
|| mpGallery
, "Theme is living without Gallery" );
74 implReleaseItems( NULL
);
78 EndListening( *mpGallery
);
81 mpGallery
->ReleaseTheme( mpTheme
, *this );
85 // ------------------------------------------------------------------------------
87 ::rtl::OUString
GalleryTheme::getImplementationName_Static()
90 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.gallery.GalleryTheme" ) );
93 // ------------------------------------------------------------------------------
95 uno::Sequence
< ::rtl::OUString
> GalleryTheme::getSupportedServiceNames_Static()
98 uno::Sequence
< ::rtl::OUString
> aSeq( 1 );
100 aSeq
.getArray()[ 0 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.gallery.GalleryTheme" ) );
105 // ------------------------------------------------------------------------------
107 ::rtl::OUString SAL_CALL
GalleryTheme::getImplementationName()
108 throw( uno::RuntimeException
)
110 return getImplementationName_Static();
113 // ------------------------------------------------------------------------------
115 sal_Bool SAL_CALL
GalleryTheme::supportsService( const ::rtl::OUString
& ServiceName
)
116 throw( uno::RuntimeException
)
118 uno::Sequence
< ::rtl::OUString
> aSNL( getSupportedServiceNames() );
119 const ::rtl::OUString
* pArray
= aSNL
.getConstArray();
121 for( int i
= 0; i
< aSNL
.getLength(); i
++ )
122 if( pArray
[i
] == ServiceName
)
128 // ------------------------------------------------------------------------------
130 uno::Sequence
< ::rtl::OUString
> SAL_CALL
GalleryTheme::getSupportedServiceNames()
131 throw( uno::RuntimeException
)
133 return getSupportedServiceNames_Static();
136 // ------------------------------------------------------------------------------
138 uno::Sequence
< uno::Type
> SAL_CALL
GalleryTheme::getTypes()
139 throw(uno::RuntimeException
)
141 uno::Sequence
< uno::Type
> aTypes( 5 );
142 uno::Type
* pTypes
= aTypes
.getArray();
144 *pTypes
++ = ::getCppuType((const uno::Reference
< lang::XServiceInfo
>*)0);
145 *pTypes
++ = ::getCppuType((const uno::Reference
< lang::XTypeProvider
>*)0);
146 *pTypes
++ = ::getCppuType((const uno::Reference
< container::XElementAccess
>*)0);
147 *pTypes
++ = ::getCppuType((const uno::Reference
< container::XIndexAccess
>*)0);
148 *pTypes
++ = ::getCppuType((const uno::Reference
< gallery::XGalleryTheme
>*)0);
153 // ------------------------------------------------------------------------------
155 uno::Sequence
< sal_Int8
> SAL_CALL
GalleryTheme::getImplementationId()
156 throw(uno::RuntimeException
)
158 const vos::OGuard
aGuard( Application::GetSolarMutex() );
159 static uno::Sequence
< sal_Int8
> aId
;
161 if( aId
.getLength() == 0 )
164 rtl_createUuid( reinterpret_cast< sal_uInt8
* >( aId
.getArray() ), 0, sal_True
);
170 // ------------------------------------------------------------------------------
172 uno::Type SAL_CALL
GalleryTheme::getElementType()
173 throw (uno::RuntimeException
)
175 return ::getCppuType( (const uno::Reference
< gallery::XGalleryItem
>*) 0);
178 // ------------------------------------------------------------------------------
180 sal_Bool SAL_CALL
GalleryTheme::hasElements()
181 throw (uno::RuntimeException
)
183 const ::vos::OGuard
aGuard( Application::GetSolarMutex() );
185 return( ( mpTheme
!= NULL
) && ( mpTheme
->GetObjectCount() > 0 ) );
188 // ------------------------------------------------------------------------------
190 sal_Int32 SAL_CALL
GalleryTheme::getCount()
191 throw (uno::RuntimeException
)
193 const ::vos::OGuard
aGuard( Application::GetSolarMutex() );
195 return( mpTheme
? mpTheme
->GetObjectCount() : 0 );
198 // ------------------------------------------------------------------------------
200 uno::Any SAL_CALL
GalleryTheme::getByIndex( ::sal_Int32 nIndex
)
201 throw (lang::IndexOutOfBoundsException
, lang::WrappedTargetException
, uno::RuntimeException
)
203 const ::vos::OGuard
aGuard( Application::GetSolarMutex() );
208 if( ( nIndex
< 0 ) || ( nIndex
>= getCount() ) )
210 throw lang::IndexOutOfBoundsException();
214 const GalleryObject
* pObj
= mpTheme
->ImplGetGalleryObject( nIndex
);
217 aRet
= uno::makeAny( uno::Reference
< gallery::XGalleryItem
>( new GalleryItem( *this, *pObj
) ) );
224 // ------------------------------------------------------------------------------
226 ::rtl::OUString SAL_CALL
GalleryTheme::getName( )
227 throw (uno::RuntimeException
)
229 const ::vos::OGuard
aGuard( Application::GetSolarMutex() );
230 ::rtl::OUString aRet
;
233 aRet
= mpTheme
->GetName();
238 // ------------------------------------------------------------------------------
240 void SAL_CALL
GalleryTheme::update( )
241 throw (uno::RuntimeException
)
243 const ::vos::OGuard
aGuard( Application::GetSolarMutex() );
247 const Link aDummyLink
;
248 mpTheme
->Actualize( aDummyLink
);
252 // ------------------------------------------------------------------------------
254 ::sal_Int32 SAL_CALL
GalleryTheme::insertURLByIndex(
255 const ::rtl::OUString
& rURL
, ::sal_Int32 nIndex
)
256 throw (lang::WrappedTargetException
, uno::RuntimeException
)
258 const ::vos::OGuard
aGuard( Application::GetSolarMutex() );
265 const INetURLObject
aURL( rURL
);
267 nIndex
= ::std::max( ::std::min( nIndex
, getCount() ), sal_Int32( 0 ) );
269 if( ( aURL
.GetProtocol() != INET_PROT_NOT_VALID
) && mpTheme
->InsertURL( aURL
, nIndex
) )
271 const GalleryObject
* pObj
= mpTheme
->ImplGetGalleryObject( aURL
);
274 nRet
= mpTheme
->ImplGetGalleryObjectPos( pObj
);
285 // ------------------------------------------------------------------------------
287 ::sal_Int32 SAL_CALL
GalleryTheme::insertGraphicByIndex(
288 const uno::Reference
< graphic::XGraphic
>& rxGraphic
, sal_Int32 nIndex
)
289 throw (lang::WrappedTargetException
, uno::RuntimeException
)
291 const ::vos::OGuard
aGuard( Application::GetSolarMutex() );
298 const Graphic
aGraphic( rxGraphic
);
300 nIndex
= ::std::max( ::std::min( nIndex
, getCount() ), sal_Int32( 0 ) );
302 if( mpTheme
->InsertGraphic( aGraphic
, nIndex
) )
313 // ------------------------------------------------------------------------------
315 ::sal_Int32 SAL_CALL
GalleryTheme::insertDrawingByIndex(
316 const uno::Reference
< lang::XComponent
>& Drawing
, sal_Int32 nIndex
)
317 throw (lang::WrappedTargetException
, uno::RuntimeException
)
319 const ::vos::OGuard
aGuard( Application::GetSolarMutex() );
324 GalleryDrawingModel
* pModel
= GalleryDrawingModel::getImplementation( Drawing
);
326 if( pModel
&& pModel
->GetDoc() && pModel
->GetDoc()->ISA( FmFormModel
) )
328 nIndex
= ::std::max( ::std::min( nIndex
, getCount() ), sal_Int32( 0 ) );
330 if( mpTheme
->InsertModel( *static_cast< FmFormModel
* >( pModel
->GetDoc() ), nIndex
) )
338 // ------------------------------------------------------------------------------
340 void SAL_CALL
GalleryTheme::removeByIndex( sal_Int32 nIndex
)
341 throw (lang::IndexOutOfBoundsException
, uno::RuntimeException
)
343 const ::vos::OGuard
aGuard( Application::GetSolarMutex() );
347 if( ( nIndex
< 0 ) || ( nIndex
>= getCount() ) )
348 throw lang::IndexOutOfBoundsException();
350 mpTheme
->RemoveObject( nIndex
);
354 // ------------------------------------------------------------------------------
356 void GalleryTheme::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
358 const ::vos::OGuard
aGuard( Application::GetSolarMutex() );
359 const GalleryHint
& rGalleryHint
= static_cast< const GalleryHint
& >( rHint
);
361 switch( rGalleryHint
.GetType() )
363 case( GALLERY_HINT_CLOSE_THEME
):
365 DBG_ASSERT( !mpTheme
|| mpGallery
, "Theme is living without Gallery" );
367 implReleaseItems( NULL
);
369 if( mpGallery
&& mpTheme
)
371 mpGallery
->ReleaseTheme( mpTheme
, *this );
377 case( GALLERY_HINT_CLOSE_OBJECT
):
379 GalleryObject
* pObj
= reinterpret_cast< GalleryObject
* >( rGalleryHint
.GetData1() );
382 implReleaseItems( pObj
);
391 // ------------------------------------------------------------------------------
393 void GalleryTheme::implReleaseItems( GalleryObject
* pObj
)
395 const ::vos::OGuard
aGuard( Application::GetSolarMutex() );
397 for( GalleryItemList::iterator aIter
= maItemList
.begin(); aIter
!= maItemList
.end(); )
399 if( !pObj
|| ( (*aIter
)->implGetObject() == pObj
) )
401 (*aIter
)->implSetInvalid();
402 aIter
= maItemList
.erase( aIter
);
409 // ------------------------------------------------------------------------------
411 ::GalleryTheme
* GalleryTheme::implGetTheme() const
416 // ------------------------------------------------------------------------------
418 void GalleryTheme::implRegisterGalleryItem( ::unogallery::GalleryItem
& rItem
)
420 const ::vos::OGuard
aGuard( Application::GetSolarMutex() );
422 // DBG_ASSERT( maItemList.find( &rItem ) == maItemList.end(), "Item already registered" );
423 maItemList
.push_back( &rItem
);
426 // ------------------------------------------------------------------------------
428 void GalleryTheme::implDeregisterGalleryItem( ::unogallery::GalleryItem
& rItem
)
430 const ::vos::OGuard
aGuard( Application::GetSolarMutex() );
432 // DBG_ASSERT( maItemList.find( &rItem ) != maItemList.end(), "Item is not registered" );
433 maItemList
.remove( &rItem
);