1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <vcl/svapp.hxx>
25 #include <cppuhelper/implbase.hxx>
26 #include <cppuhelper/supportsservice.hxx>
27 #include <com/sun/star/container/ElementExistException.hpp>
28 #include <com/sun/star/gallery/XGalleryTheme.hpp>
29 #include <com/sun/star/gallery/XGalleryThemeProvider.hpp>
30 #include <com/sun/star/lang/XInitialization.hpp>
31 #include <com/sun/star/lang/XServiceInfo.hpp>
32 #include <com/sun/star/beans/PropertyValue.hpp>
33 #include <com/sun/star/uno/XComponentContext.hpp>
35 using namespace ::com::sun::star
;
39 class GalleryThemeProvider
: public ::cppu::WeakImplHelper
< css::lang::XInitialization
,
40 css::gallery::XGalleryThemeProvider
,
41 css::lang::XServiceInfo
>
45 GalleryThemeProvider();
50 virtual OUString SAL_CALL
getImplementationName() override
;
51 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
52 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
55 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
getTypes( ) override
;
56 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
getImplementationId( ) override
;
59 virtual css::uno::Type SAL_CALL
getElementType() override
;
60 virtual sal_Bool SAL_CALL
hasElements() override
;
63 virtual css::uno::Any SAL_CALL
getByName( const OUString
& aName
) override
;
64 virtual css::uno::Sequence
< OUString
> SAL_CALL
getElementNames() override
;
65 virtual sal_Bool SAL_CALL
hasByName( const OUString
& aName
) override
;
68 virtual void SAL_CALL
initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
) override
;
70 // XGalleryThemeProvider
71 virtual css::uno::Reference
< css::gallery::XGalleryTheme
> SAL_CALL
insertNewByName( const OUString
& ThemeName
) override
;
72 virtual void SAL_CALL
removeByName( const OUString
& ThemeName
) override
;
80 GalleryThemeProvider::GalleryThemeProvider() :
81 mbHiddenThemes( false )
83 mpGallery
= ::Gallery::GetGalleryInstance();
86 OUString SAL_CALL
GalleryThemeProvider::getImplementationName()
88 return "com.sun.star.comp.gallery.GalleryThemeProvider";
91 sal_Bool SAL_CALL
GalleryThemeProvider::supportsService( const OUString
& ServiceName
)
93 return cppu::supportsService( this, ServiceName
);
96 uno::Sequence
< OUString
> SAL_CALL
GalleryThemeProvider::getSupportedServiceNames()
98 uno::Sequence
<OUString
> aSeq
{ "com.sun.star.gallery.GalleryThemeProvider" };
102 uno::Sequence
< uno::Type
> SAL_CALL
GalleryThemeProvider::getTypes()
104 static const uno::Sequence aTypes
{
105 cppu::UnoType
<lang::XServiceInfo
>::get(),
106 cppu::UnoType
<lang::XTypeProvider
>::get(),
107 cppu::UnoType
<lang::XInitialization
>::get(),
108 cppu::UnoType
<container::XElementAccess
>::get(),
109 cppu::UnoType
<container::XNameAccess
>::get(),
110 cppu::UnoType
<gallery::XGalleryThemeProvider
>::get() };
115 uno::Sequence
< sal_Int8
> SAL_CALL
GalleryThemeProvider::getImplementationId()
117 return css::uno::Sequence
<sal_Int8
>();
120 void SAL_CALL
GalleryThemeProvider::initialize( const uno::Sequence
< uno::Any
>& rArguments
)
122 uno::Sequence
< beans::PropertyValue
> aParams
;
124 for( const auto& rArgument
: rArguments
)
126 if( rArgument
>>= aParams
)
130 for( const beans::PropertyValue
& rProp
: std::as_const(aParams
) )
132 if ( rProp
.Name
== "ProvideHiddenThemes" )
133 rProp
.Value
>>= mbHiddenThemes
;
138 uno::Type SAL_CALL
GalleryThemeProvider::getElementType()
140 return cppu::UnoType
<gallery::XGalleryTheme
>::get();
144 sal_Bool SAL_CALL
GalleryThemeProvider::hasElements()
146 const SolarMutexGuard aGuard
;
148 return( ( mpGallery
!= nullptr ) && ( mpGallery
->GetThemeCount() > 0 ) );
152 uno::Any SAL_CALL
GalleryThemeProvider::getByName( const OUString
& rName
)
154 const SolarMutexGuard aGuard
;
157 if( !mpGallery
|| !mpGallery
->HasTheme( rName
) )
159 throw container::NoSuchElementException();
162 aRet
<<= uno::Reference
< gallery::XGalleryTheme
>( new ::unogallery::GalleryTheme( rName
) );
168 uno::Sequence
< OUString
> SAL_CALL
GalleryThemeProvider::getElementNames()
170 const SolarMutexGuard aGuard
;
171 sal_uInt32 i
= 0, nCount
= ( mpGallery
? mpGallery
->GetThemeCount() : 0 ), nRealCount
= 0;
172 uno::Sequence
< OUString
> aSeq( nCount
);
174 for( ; i
< nCount
; ++i
)
176 const GalleryThemeEntry
* pEntry
= mpGallery
->GetThemeInfo( i
);
178 if( mbHiddenThemes
|| !pEntry
->IsHidden() )
179 aSeq
[ nRealCount
++ ] = pEntry
->GetThemeName();
182 aSeq
.realloc( nRealCount
);
188 sal_Bool SAL_CALL
GalleryThemeProvider::hasByName( const OUString
& rName
)
190 const SolarMutexGuard aGuard
;
194 if( mpGallery
&& mpGallery
->HasTheme( rName
) )
195 bRet
= ( mbHiddenThemes
|| !mpGallery
->GetThemeInfo( rName
)->IsHidden() );
201 uno::Reference
< gallery::XGalleryTheme
> SAL_CALL
GalleryThemeProvider::insertNewByName( const OUString
& rThemeName
)
203 const SolarMutexGuard aGuard
;
204 uno::Reference
< gallery::XGalleryTheme
> xRet
;
208 if( mpGallery
->HasTheme( rThemeName
) )
210 throw container::ElementExistException();
212 else if( mpGallery
->CreateTheme( rThemeName
) )
214 xRet
= new ::unogallery::GalleryTheme( rThemeName
);
222 void SAL_CALL
GalleryThemeProvider::removeByName( const OUString
& rName
)
224 const SolarMutexGuard aGuard
;
227 !mpGallery
->HasTheme( rName
) ||
228 ( !mbHiddenThemes
&& mpGallery
->GetThemeInfo( rName
)->IsHidden() ) )
230 throw container::NoSuchElementException();
233 mpGallery
->RemoveTheme( rName
);
238 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
239 com_sun_star_comp_gallery_GalleryThemeProvider_get_implementation(
240 css::uno::XComponentContext
*,
241 css::uno::Sequence
<css::uno::Any
> const &)
243 return cppu::acquire(new GalleryThemeProvider
);
246 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */