Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / svx / source / unogallery / unogalthemeprovider.cxx
blob0bab17f581397cf64f47059d50fade281ec53026
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 .
20 #include <sal/config.h>
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/implbase.hxx>
30 #include <cppuhelper/supportsservice.hxx>
31 #include <com/sun/star/container/ElementExistException.hpp>
32 #include <com/sun/star/gallery/XGalleryTheme.hpp>
33 #include <com/sun/star/gallery/XGalleryThemeProvider.hpp>
34 #include <com/sun/star/lang/XInitialization.hpp>
35 #include <com/sun/star/lang/XServiceInfo.hpp>
36 #include <com/sun/star/beans/PropertyValue.hpp>
37 #include <com/sun/star/uno/XComponentContext.hpp>
39 using namespace ::com::sun::star;
41 namespace {
43 class GalleryThemeProvider : public ::cppu::WeakImplHelper< css::lang::XInitialization,
44 css::gallery::XGalleryThemeProvider,
45 css::lang::XServiceInfo >
47 public:
49 GalleryThemeProvider();
51 protected:
53 // XServiceInfo
54 virtual OUString SAL_CALL getImplementationName() override;
55 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
56 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
58 // XTypeProvider
59 virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override;
60 virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) override;
62 // XElementAccess
63 virtual css::uno::Type SAL_CALL getElementType() override;
64 virtual sal_Bool SAL_CALL hasElements() override;
66 // XNameAccess
67 virtual css::uno::Any SAL_CALL getByName( const OUString& aName ) override;
68 virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override;
69 virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override;
71 // XInitialization
72 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
74 // XGalleryThemeProvider
75 virtual css::uno::Reference< css::gallery::XGalleryTheme > SAL_CALL insertNewByName( const OUString& ThemeName ) override;
76 virtual void SAL_CALL removeByName( const OUString& ThemeName ) override;
78 private:
80 Gallery* mpGallery;
81 bool mbHiddenThemes;
84 GalleryThemeProvider::GalleryThemeProvider() :
85 mbHiddenThemes( false )
87 mpGallery = ::Gallery::GetGalleryInstance();
90 OUString SAL_CALL GalleryThemeProvider::getImplementationName()
92 return OUString( "com.sun.star.comp.gallery.GalleryThemeProvider" );
95 sal_Bool SAL_CALL GalleryThemeProvider::supportsService( const OUString& ServiceName )
97 return cppu::supportsService( this, ServiceName );
100 uno::Sequence< OUString > SAL_CALL GalleryThemeProvider::getSupportedServiceNames()
102 uno::Sequence<OUString> aSeq { "com.sun.star.gallery.GalleryThemeProvider" };
103 return aSeq;
106 uno::Sequence< uno::Type > SAL_CALL GalleryThemeProvider::getTypes()
108 uno::Sequence< uno::Type > aTypes( 6 );
109 uno::Type* pTypes = aTypes.getArray();
111 *pTypes++ = cppu::UnoType<lang::XServiceInfo>::get();
112 *pTypes++ = cppu::UnoType<lang::XTypeProvider>::get();
113 *pTypes++ = cppu::UnoType<lang::XInitialization>::get();
114 *pTypes++ = cppu::UnoType<container::XElementAccess>::get();
115 *pTypes++ = cppu::UnoType<container::XNameAccess>::get();
116 *pTypes++ = cppu::UnoType<gallery::XGalleryThemeProvider>::get();
118 return aTypes;
121 uno::Sequence< sal_Int8 > SAL_CALL GalleryThemeProvider::getImplementationId()
123 return css::uno::Sequence<sal_Int8>();
126 void SAL_CALL GalleryThemeProvider::initialize( const uno::Sequence< uno::Any >& rArguments )
128 uno::Sequence< beans::PropertyValue > aParams;
129 sal_Int32 i;
131 for( i = 0; i < rArguments.getLength(); ++i )
133 if( rArguments[ i ] >>= aParams )
134 break;
137 for( i = 0; i < aParams.getLength(); ++i )
139 const beans::PropertyValue& rProp = aParams[ i ];
141 if ( rProp.Name == "ProvideHiddenThemes" )
142 rProp.Value >>= mbHiddenThemes;
147 uno::Type SAL_CALL GalleryThemeProvider::getElementType()
149 return cppu::UnoType<gallery::XGalleryTheme>::get();
153 sal_Bool SAL_CALL GalleryThemeProvider::hasElements()
155 const SolarMutexGuard aGuard;
157 return( ( mpGallery != nullptr ) && ( mpGallery->GetThemeCount() > 0 ) );
161 uno::Any SAL_CALL GalleryThemeProvider::getByName( const OUString& rName )
163 const SolarMutexGuard aGuard;
164 uno::Any aRet;
166 if( !mpGallery || !mpGallery->HasTheme( rName ) )
168 throw container::NoSuchElementException();
170 else
172 aRet <<= uno::Reference< gallery::XGalleryTheme >( new ::unogallery::GalleryTheme( rName ) );
175 return aRet;
179 uno::Sequence< OUString > SAL_CALL GalleryThemeProvider::getElementNames()
181 const SolarMutexGuard aGuard;
182 sal_uInt32 i = 0, nCount = ( mpGallery ? mpGallery->GetThemeCount() : 0 ), nRealCount = 0;
183 uno::Sequence< OUString > aSeq( nCount );
185 for( ; i < nCount; ++i )
187 const GalleryThemeEntry* pEntry = mpGallery->GetThemeInfo( i );
189 if( mbHiddenThemes || !pEntry->IsHidden() )
190 aSeq[ nRealCount++ ] = pEntry->GetThemeName();
193 aSeq.realloc( nRealCount );
195 return aSeq;
199 sal_Bool SAL_CALL GalleryThemeProvider::hasByName( const OUString& rName )
201 const SolarMutexGuard aGuard;
203 bool bRet = false;
205 if( mpGallery && mpGallery->HasTheme( rName ) )
206 bRet = ( mbHiddenThemes || !mpGallery->GetThemeInfo( rName )->IsHidden() );
208 return bRet;
212 uno::Reference< gallery::XGalleryTheme > SAL_CALL GalleryThemeProvider::insertNewByName( const OUString& rThemeName )
214 const SolarMutexGuard aGuard;
215 uno::Reference< gallery::XGalleryTheme > xRet;
217 if( mpGallery )
219 if( mpGallery->HasTheme( rThemeName ) )
221 throw container::ElementExistException();
223 else if( mpGallery->CreateTheme( rThemeName ) )
225 xRet = new ::unogallery::GalleryTheme( rThemeName );
229 return xRet;
233 void SAL_CALL GalleryThemeProvider::removeByName( const OUString& rName )
235 const SolarMutexGuard aGuard;
237 if( !mpGallery ||
238 !mpGallery->HasTheme( rName ) ||
239 ( !mbHiddenThemes && mpGallery->GetThemeInfo( rName )->IsHidden() ) )
241 throw container::NoSuchElementException();
243 else
245 mpGallery->RemoveTheme( rName );
251 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
252 com_sun_star_comp_gallery_GalleryThemeProvider_get_implementation(
253 css::uno::XComponentContext *,
254 css::uno::Sequence<css::uno::Any> const &)
256 return cppu::acquire(new GalleryThemeProvider);
259 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */