bump product version to 5.0.4.1
[LibreOffice.git] / svx / source / unogallery / unogalthemeprovider.cxx
blob09c17b92bdbaeebed84c107ea9c1c5910143770d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "unogalthemeprovider.hxx"
22 #include "unogaltheme.hxx"
23 #include "svx/gallery1.hxx"
24 #include <osl/mutex.hxx>
25 #include <rtl/ref.hxx>
26 #include <vcl/svapp.hxx>
27 #include <unotools/pathoptions.hxx>
28 #include <comphelper/servicehelper.hxx>
29 #include <cppuhelper/supportsservice.hxx>
30 #include <com/sun/star/gallery/XGalleryTheme.hpp>
31 #include <com/sun/star/beans/PropertyValue.hpp>
32 #include <com/sun/star/uno/XComponentContext.hpp>
34 using namespace ::com::sun::star;
36 namespace {
38 GalleryThemeProvider::GalleryThemeProvider() :
39 mbHiddenThemes( false )
41 mpGallery = ::Gallery::GetGalleryInstance();
44 GalleryThemeProvider::~GalleryThemeProvider()
48 OUString SAL_CALL GalleryThemeProvider::getImplementationName()
49 throw( uno::RuntimeException, std::exception )
51 return OUString( "com.sun.star.comp.gallery.GalleryThemeProvider" );
54 sal_Bool SAL_CALL GalleryThemeProvider::supportsService( const OUString& ServiceName )
55 throw( uno::RuntimeException, std::exception )
57 return cppu::supportsService( this, ServiceName );
60 uno::Sequence< OUString > SAL_CALL GalleryThemeProvider::getSupportedServiceNames()
61 throw( uno::RuntimeException, std::exception )
63 uno::Sequence< OUString > aSeq( 1 );
64 aSeq.getArray()[ 0 ] = "com.sun.star.gallery.GalleryThemeProvider";
65 return aSeq;
68 uno::Sequence< uno::Type > SAL_CALL GalleryThemeProvider::getTypes()
69 throw(uno::RuntimeException, std::exception)
71 uno::Sequence< uno::Type > aTypes( 6 );
72 uno::Type* pTypes = aTypes.getArray();
74 *pTypes++ = cppu::UnoType<lang::XServiceInfo>::get();
75 *pTypes++ = cppu::UnoType<lang::XTypeProvider>::get();
76 *pTypes++ = cppu::UnoType<lang::XInitialization>::get();
77 *pTypes++ = cppu::UnoType<container::XElementAccess>::get();
78 *pTypes++ = cppu::UnoType<container::XNameAccess>::get();
79 *pTypes++ = cppu::UnoType<gallery::XGalleryThemeProvider>::get();
81 return aTypes;
84 uno::Sequence< sal_Int8 > SAL_CALL GalleryThemeProvider::getImplementationId()
85 throw(uno::RuntimeException, std::exception)
87 return css::uno::Sequence<sal_Int8>();
90 void SAL_CALL GalleryThemeProvider::initialize( const uno::Sequence< uno::Any >& rArguments )
91 throw ( uno::Exception, uno::RuntimeException, std::exception )
93 uno::Sequence< beans::PropertyValue > aParams;
94 sal_Int32 i;
96 for( i = 0; i < rArguments.getLength(); ++i )
98 if( rArguments[ i ] >>= aParams )
99 break;
102 for( i = 0; i < aParams.getLength(); ++i )
104 const beans::PropertyValue& rProp = aParams[ i ];
106 if ( rProp.Name == "ProvideHiddenThemes" )
107 rProp.Value >>= mbHiddenThemes;
113 uno::Type SAL_CALL GalleryThemeProvider::getElementType()
114 throw (uno::RuntimeException, std::exception)
116 return cppu::UnoType<gallery::XGalleryTheme>::get();
121 sal_Bool SAL_CALL GalleryThemeProvider::hasElements()
122 throw (uno::RuntimeException, std::exception)
124 const SolarMutexGuard aGuard;
126 return( ( mpGallery != NULL ) && ( mpGallery->GetThemeCount() > 0 ) );
131 uno::Any SAL_CALL GalleryThemeProvider::getByName( const OUString& rName )
132 throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
134 const SolarMutexGuard aGuard;
135 uno::Any aRet;
137 if( !mpGallery || !mpGallery->HasTheme( rName ) )
139 throw container::NoSuchElementException();
141 else
143 aRet = uno::makeAny( uno::Reference< gallery::XGalleryTheme >( new ::unogallery::GalleryTheme( rName ) ) );
146 return aRet;
151 uno::Sequence< OUString > SAL_CALL GalleryThemeProvider::getElementNames()
152 throw (uno::RuntimeException, std::exception)
154 const SolarMutexGuard aGuard;
155 sal_uInt32 i = 0, nCount = ( mpGallery ? mpGallery->GetThemeCount() : 0 ), nRealCount = 0;
156 uno::Sequence< OUString > aSeq( nCount );
158 for( ; i < nCount; ++i )
160 const GalleryThemeEntry* pEntry = mpGallery->GetThemeInfo( i );
162 if( mbHiddenThemes || !pEntry->IsHidden() )
163 aSeq[ nRealCount++ ] = pEntry->GetThemeName();
166 aSeq.realloc( nRealCount );
168 return aSeq;
173 sal_Bool SAL_CALL GalleryThemeProvider::hasByName( const OUString& rName )
174 throw (uno::RuntimeException, std::exception)
176 const SolarMutexGuard aGuard;
178 bool bRet = false;
180 if( mpGallery && mpGallery->HasTheme( rName ) )
181 bRet = ( mbHiddenThemes || !mpGallery->GetThemeInfo( rName )->IsHidden() );
183 return bRet;
188 uno::Reference< gallery::XGalleryTheme > SAL_CALL GalleryThemeProvider::insertNewByName( const OUString& rThemeName )
189 throw (container::ElementExistException, uno::RuntimeException, std::exception)
191 const SolarMutexGuard aGuard;
192 uno::Reference< gallery::XGalleryTheme > xRet;
194 if( mpGallery )
196 if( mpGallery->HasTheme( rThemeName ) )
198 throw container::ElementExistException();
200 else if( mpGallery->CreateTheme( rThemeName ) )
202 xRet = new ::unogallery::GalleryTheme( rThemeName );
206 return xRet;
211 void SAL_CALL GalleryThemeProvider::removeByName( const OUString& rName )
212 throw (container::NoSuchElementException, uno::RuntimeException, std::exception)
214 const SolarMutexGuard aGuard;
216 if( !mpGallery ||
217 !mpGallery->HasTheme( rName ) ||
218 ( !mbHiddenThemes && mpGallery->GetThemeInfo( rName )->IsHidden() ) )
220 throw container::NoSuchElementException();
222 else
224 mpGallery->RemoveTheme( rName );
230 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
231 com_sun_star_comp_gallery_GalleryThemeProvider_get_implementation(
232 css::uno::XComponentContext *,
233 css::uno::Sequence<css::uno::Any> const &)
235 return cppu::acquire(new GalleryThemeProvider);
238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */