merge the formfield patch from ooo-build
[ooovba.git] / svx / source / unogallery / unogalthemeprovider.cxx
blobf96d569b75e5726f21af11d69cddeece602b4e56
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: unogalthemeprovider.cxx,v $
10 * $Revision: 1.7 $
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"
34 #include "unogalthemeprovider.hxx"
35 #include "unogaltheme.hxx"
36 #include "gallery1.hxx"
37 #include <rtl/uuid.h>
38 #include <vos/mutex.hxx>
39 #ifndef _SV_SVAPP_HXX_
40 #include <vcl/svapp.hxx>
41 #endif
42 #include <svtools/pathoptions.hxx>
43 #include <com/sun/star/gallery/XGalleryTheme.hpp>
44 #include <com/sun/star/beans/PropertyValue.hpp>
46 using namespace ::com::sun::star;
48 namespace unogallery {
50 // --------------------
51 // - Helper functions -
52 // --------------------
54 uno::Reference< uno::XInterface > SAL_CALL GalleryThemeProvider_createInstance(
55 const uno::Reference< lang::XMultiServiceFactory > & )
56 throw( uno::Exception )
58 return *( new GalleryThemeProvider() );
61 // -----------------------------------------------------------------------------
63 uno::Sequence< ::rtl::OUString > SAL_CALL GalleryThemeProvider_getSupportedServiceNames()
64 throw()
66 return GalleryThemeProvider::getSupportedServiceNames_Static();
69 // -----------------------------------------------------------------------------
71 ::rtl::OUString SAL_CALL GalleryThemeProvider_getImplementationName()
72 throw()
74 return GalleryThemeProvider::getImplementationName_Static();
77 // -----------------
78 // - GalleryThemeProvider -
79 // -----------------
81 GalleryThemeProvider::GalleryThemeProvider() :
82 mbHiddenThemes( sal_False )
84 mpGallery = ::Gallery::GetGalleryInstance();
87 // ------------------------------------------------------------------------------
89 GalleryThemeProvider::~GalleryThemeProvider()
93 // ------------------------------------------------------------------------------
95 SVX_DLLPUBLIC ::rtl::OUString GalleryThemeProvider::getImplementationName_Static()
96 throw()
98 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.gallery.GalleryThemeProvider" ) );
101 // ------------------------------------------------------------------------------
103 SVX_DLLPUBLIC uno::Sequence< ::rtl::OUString > GalleryThemeProvider::getSupportedServiceNames_Static()
104 throw()
106 uno::Sequence< ::rtl::OUString > aSeq( 1 );
108 aSeq.getArray()[ 0 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.gallery.GalleryThemeProvider" ) );
110 return aSeq;
113 // ------------------------------------------------------------------------------
115 ::rtl::OUString SAL_CALL GalleryThemeProvider::getImplementationName()
116 throw( uno::RuntimeException )
118 return getImplementationName_Static();
121 // ------------------------------------------------------------------------------
123 sal_Bool SAL_CALL GalleryThemeProvider::supportsService( const ::rtl::OUString& ServiceName )
124 throw( uno::RuntimeException )
126 uno::Sequence< ::rtl::OUString > aSNL( getSupportedServiceNames() );
127 const ::rtl::OUString* pArray = aSNL.getConstArray();
129 for( int i = 0; i < aSNL.getLength(); i++ )
130 if( pArray[i] == ServiceName )
131 return true;
133 return false;
136 // ------------------------------------------------------------------------------
138 uno::Sequence< ::rtl::OUString > SAL_CALL GalleryThemeProvider::getSupportedServiceNames()
139 throw( uno::RuntimeException )
141 return getSupportedServiceNames_Static();
144 // ------------------------------------------------------------------------------
146 uno::Sequence< uno::Type > SAL_CALL GalleryThemeProvider::getTypes()
147 throw(uno::RuntimeException)
149 uno::Sequence< uno::Type > aTypes( 6 );
150 uno::Type* pTypes = aTypes.getArray();
152 *pTypes++ = ::getCppuType((const uno::Reference< lang::XServiceInfo>*)0);
153 *pTypes++ = ::getCppuType((const uno::Reference< lang::XTypeProvider>*)0);
154 *pTypes++ = ::getCppuType((const uno::Reference< lang::XInitialization>*)0);
155 *pTypes++ = ::getCppuType((const uno::Reference< container::XElementAccess>*)0);
156 *pTypes++ = ::getCppuType((const uno::Reference< container::XNameAccess>*)0);
157 *pTypes++ = ::getCppuType((const uno::Reference< gallery::XGalleryThemeProvider>*)0);
159 return aTypes;
162 // ------------------------------------------------------------------------------
164 uno::Sequence< sal_Int8 > SAL_CALL GalleryThemeProvider::getImplementationId()
165 throw(uno::RuntimeException)
167 const vos::OGuard aGuard( Application::GetSolarMutex() );
168 static uno::Sequence< sal_Int8 > aId;
170 if( aId.getLength() == 0 )
172 aId.realloc( 16 );
173 rtl_createUuid( reinterpret_cast< sal_uInt8* >( aId.getArray() ), 0, sal_True );
176 return aId;
179 // ------------------------------------------------------------------------------
181 void SAL_CALL GalleryThemeProvider::initialize( const uno::Sequence< uno::Any >& rArguments )
182 throw ( uno::Exception, uno::RuntimeException )
184 uno::Sequence< beans::PropertyValue > aParams;
185 sal_Int32 i;
187 for( i = 0; i < rArguments.getLength(); ++i )
189 if( rArguments[ i ] >>= aParams )
190 break;
193 for( i = 0; i < aParams.getLength(); ++i )
195 const beans::PropertyValue& rProp = aParams[ i ];
197 if( rProp.Name.equalsAscii( "ProvideHiddenThemes" ) )
198 rProp.Value >>= mbHiddenThemes;
202 // ------------------------------------------------------------------------------
204 uno::Type SAL_CALL GalleryThemeProvider::getElementType()
205 throw (uno::RuntimeException)
207 return ::getCppuType( (const uno::Reference< gallery::XGalleryTheme >*) 0);
210 // ------------------------------------------------------------------------------
212 sal_Bool SAL_CALL GalleryThemeProvider::hasElements()
213 throw (uno::RuntimeException)
215 const ::vos::OGuard aGuard( Application::GetSolarMutex() );
217 return( ( mpGallery != NULL ) && ( mpGallery->GetThemeCount() > 0 ) );
220 // ------------------------------------------------------------------------------
222 uno::Any SAL_CALL GalleryThemeProvider::getByName( const ::rtl::OUString& rName )
223 throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
225 const ::vos::OGuard aGuard( Application::GetSolarMutex() );
226 uno::Any aRet;
228 if( !mpGallery || !mpGallery->HasTheme( rName ) )
230 throw container::NoSuchElementException();
232 else
234 aRet = uno::makeAny( uno::Reference< gallery::XGalleryTheme >( new ::unogallery::GalleryTheme( rName ) ) );
237 return aRet;
240 // ------------------------------------------------------------------------------
242 uno::Sequence< ::rtl::OUString > SAL_CALL GalleryThemeProvider::getElementNames()
243 throw (uno::RuntimeException)
245 const ::vos::OGuard aGuard( Application::GetSolarMutex() );
246 sal_uInt32 i = 0, nCount = ( mpGallery ? mpGallery->GetThemeCount() : 0 ), nRealCount = 0;
247 uno::Sequence< ::rtl::OUString > aSeq( nCount );
249 for( ; i < nCount; ++i )
251 const GalleryThemeEntry* pEntry = mpGallery->GetThemeInfo( i );
253 if( mbHiddenThemes || !pEntry->IsHidden() )
254 aSeq[ nRealCount++ ] = pEntry->GetThemeName();
257 aSeq.realloc( nRealCount );
259 return aSeq;
262 // ------------------------------------------------------------------------------
264 sal_Bool SAL_CALL GalleryThemeProvider::hasByName( const ::rtl::OUString& rName )
265 throw (uno::RuntimeException)
267 const ::vos::OGuard aGuard( Application::GetSolarMutex() );
269 sal_Bool bRet = sal_False;
271 if( mpGallery && mpGallery->HasTheme( rName ) )
272 bRet = ( mbHiddenThemes || !mpGallery->GetThemeInfo( rName )->IsHidden() );
274 return( bRet );
277 // ------------------------------------------------------------------------------
279 uno::Reference< gallery::XGalleryTheme > SAL_CALL GalleryThemeProvider::insertNewByName( const ::rtl::OUString& rThemeName )
280 throw (container::ElementExistException, uno::RuntimeException)
282 const ::vos::OGuard aGuard( Application::GetSolarMutex() );
283 uno::Reference< gallery::XGalleryTheme > xRet;
285 if( mpGallery )
287 if( mpGallery->HasTheme( rThemeName ) )
289 throw container::ElementExistException();
291 else if( mpGallery->CreateTheme( rThemeName ) )
293 xRet = new ::unogallery::GalleryTheme( rThemeName );
297 return xRet;
300 // ------------------------------------------------------------------------------
302 void SAL_CALL GalleryThemeProvider::removeByName( const ::rtl::OUString& rName )
303 throw (container::NoSuchElementException, uno::RuntimeException)
305 const ::vos::OGuard aGuard( Application::GetSolarMutex() );
307 if( !mpGallery ||
308 !mpGallery->HasTheme( rName ) ||
309 ( !mbHiddenThemes && mpGallery->GetThemeInfo( rName )->IsHidden() ) )
311 throw container::NoSuchElementException();
313 else
315 mpGallery->RemoveTheme( rName );