Bump version to 6.4-15
[LibreOffice.git] / svx / source / unogallery / unogalthemeprovider.cxx
blob58c4234ef899a411d827cfb6c1efc357d251d7e8
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 <rtl/ref.hxx>
25 #include <vcl/svapp.hxx>
26 #include <unotools/pathoptions.hxx>
27 #include <cppuhelper/implbase.hxx>
28 #include <cppuhelper/supportsservice.hxx>
29 #include <com/sun/star/container/ElementExistException.hpp>
30 #include <com/sun/star/gallery/XGalleryTheme.hpp>
31 #include <com/sun/star/gallery/XGalleryThemeProvider.hpp>
32 #include <com/sun/star/lang/XInitialization.hpp>
33 #include <com/sun/star/lang/XServiceInfo.hpp>
34 #include <com/sun/star/beans/PropertyValue.hpp>
35 #include <com/sun/star/uno/XComponentContext.hpp>
37 using namespace ::com::sun::star;
39 namespace {
41 class GalleryThemeProvider : public ::cppu::WeakImplHelper< css::lang::XInitialization,
42 css::gallery::XGalleryThemeProvider,
43 css::lang::XServiceInfo >
45 public:
47 GalleryThemeProvider();
49 protected:
51 // XServiceInfo
52 virtual OUString SAL_CALL getImplementationName() override;
53 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
54 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
56 // XTypeProvider
57 virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override;
58 virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) override;
60 // XElementAccess
61 virtual css::uno::Type SAL_CALL getElementType() override;
62 virtual sal_Bool SAL_CALL hasElements() override;
64 // XNameAccess
65 virtual css::uno::Any SAL_CALL getByName( const OUString& aName ) override;
66 virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override;
67 virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override;
69 // XInitialization
70 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
72 // XGalleryThemeProvider
73 virtual css::uno::Reference< css::gallery::XGalleryTheme > SAL_CALL insertNewByName( const OUString& ThemeName ) override;
74 virtual void SAL_CALL removeByName( const OUString& ThemeName ) override;
76 private:
78 Gallery* mpGallery;
79 bool mbHiddenThemes;
82 GalleryThemeProvider::GalleryThemeProvider() :
83 mbHiddenThemes( false )
85 mpGallery = ::Gallery::GetGalleryInstance();
88 OUString SAL_CALL GalleryThemeProvider::getImplementationName()
90 return "com.sun.star.comp.gallery.GalleryThemeProvider";
93 sal_Bool SAL_CALL GalleryThemeProvider::supportsService( const OUString& ServiceName )
95 return cppu::supportsService( this, ServiceName );
98 uno::Sequence< OUString > SAL_CALL GalleryThemeProvider::getSupportedServiceNames()
100 uno::Sequence<OUString> aSeq { "com.sun.star.gallery.GalleryThemeProvider" };
101 return aSeq;
104 uno::Sequence< uno::Type > SAL_CALL GalleryThemeProvider::getTypes()
106 static const uno::Sequence aTypes {
107 cppu::UnoType<lang::XServiceInfo>::get(),
108 cppu::UnoType<lang::XTypeProvider>::get(),
109 cppu::UnoType<lang::XInitialization>::get(),
110 cppu::UnoType<container::XElementAccess>::get(),
111 cppu::UnoType<container::XNameAccess>::get(),
112 cppu::UnoType<gallery::XGalleryThemeProvider>::get() };
114 return aTypes;
117 uno::Sequence< sal_Int8 > SAL_CALL GalleryThemeProvider::getImplementationId()
119 return css::uno::Sequence<sal_Int8>();
122 void SAL_CALL GalleryThemeProvider::initialize( const uno::Sequence< uno::Any >& rArguments )
124 uno::Sequence< beans::PropertyValue > aParams;
126 for( const auto& rArgument : rArguments )
128 if( rArgument >>= aParams )
129 break;
132 for( const beans::PropertyValue& rProp : std::as_const(aParams) )
134 if ( rProp.Name == "ProvideHiddenThemes" )
135 rProp.Value >>= mbHiddenThemes;
140 uno::Type SAL_CALL GalleryThemeProvider::getElementType()
142 return cppu::UnoType<gallery::XGalleryTheme>::get();
146 sal_Bool SAL_CALL GalleryThemeProvider::hasElements()
148 const SolarMutexGuard aGuard;
150 return( ( mpGallery != nullptr ) && ( mpGallery->GetThemeCount() > 0 ) );
154 uno::Any SAL_CALL GalleryThemeProvider::getByName( const OUString& rName )
156 const SolarMutexGuard aGuard;
157 uno::Any aRet;
159 if( !mpGallery || !mpGallery->HasTheme( rName ) )
161 throw container::NoSuchElementException();
164 aRet <<= uno::Reference< gallery::XGalleryTheme >( new ::unogallery::GalleryTheme( rName ) );
166 return aRet;
170 uno::Sequence< OUString > SAL_CALL GalleryThemeProvider::getElementNames()
172 const SolarMutexGuard aGuard;
173 sal_uInt32 i = 0, nCount = ( mpGallery ? mpGallery->GetThemeCount() : 0 ), nRealCount = 0;
174 uno::Sequence< OUString > aSeq( nCount );
176 for( ; i < nCount; ++i )
178 const GalleryThemeEntry* pEntry = mpGallery->GetThemeInfo( i );
180 if( mbHiddenThemes || !pEntry->IsHidden() )
181 aSeq[ nRealCount++ ] = pEntry->GetThemeName();
184 aSeq.realloc( nRealCount );
186 return aSeq;
190 sal_Bool SAL_CALL GalleryThemeProvider::hasByName( const OUString& rName )
192 const SolarMutexGuard aGuard;
194 bool bRet = false;
196 if( mpGallery && mpGallery->HasTheme( rName ) )
197 bRet = ( mbHiddenThemes || !mpGallery->GetThemeInfo( rName )->IsHidden() );
199 return bRet;
203 uno::Reference< gallery::XGalleryTheme > SAL_CALL GalleryThemeProvider::insertNewByName( const OUString& rThemeName )
205 const SolarMutexGuard aGuard;
206 uno::Reference< gallery::XGalleryTheme > xRet;
208 if( mpGallery )
210 if( mpGallery->HasTheme( rThemeName ) )
212 throw container::ElementExistException();
214 else if( mpGallery->CreateTheme( rThemeName ) )
216 xRet = new ::unogallery::GalleryTheme( rThemeName );
220 return xRet;
224 void SAL_CALL GalleryThemeProvider::removeByName( const OUString& rName )
226 const SolarMutexGuard aGuard;
228 if( !mpGallery ||
229 !mpGallery->HasTheme( rName ) ||
230 ( !mbHiddenThemes && mpGallery->GetThemeInfo( rName )->IsHidden() ) )
232 throw container::NoSuchElementException();
235 mpGallery->RemoveTheme( rName );
240 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
241 com_sun_star_comp_gallery_GalleryThemeProvider_get_implementation(
242 css::uno::XComponentContext *,
243 css::uno::Sequence<css::uno::Any> const &)
245 return cppu::acquire(new GalleryThemeProvider);
248 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */