LibreOffice Module svx (master) 1
unogalthemeprovider.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <sal/config.h>
21
22#include "unogaltheme.hxx"
23#include <svx/gallery1.hxx>
24#include <vcl/svapp.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>
34
35using namespace ::com::sun::star;
36
37namespace {
38
39class GalleryThemeProvider : public ::cppu::WeakImplHelper< css::lang::XInitialization,
40 css::gallery::XGalleryThemeProvider,
41 css::lang::XServiceInfo >
42{
43public:
44
45 GalleryThemeProvider();
46
47protected:
48
49 // XServiceInfo
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;
53
54 // XTypeProvider
55 virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override;
56 virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId( ) override;
57
58 // XElementAccess
59 virtual css::uno::Type SAL_CALL getElementType() override;
60 virtual sal_Bool SAL_CALL hasElements() override;
61
62 // XNameAccess
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;
66
67 // XInitialization
68 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
69
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;
73
74private:
75
76 Gallery* mpGallery;
77 bool mbHiddenThemes;
78};
79
80GalleryThemeProvider::GalleryThemeProvider() :
81 mbHiddenThemes( false )
82{
84}
85
86OUString SAL_CALL GalleryThemeProvider::getImplementationName()
87{
88 return "com.sun.star.comp.gallery.GalleryThemeProvider";
89}
90
91sal_Bool SAL_CALL GalleryThemeProvider::supportsService( const OUString& ServiceName )
92{
93 return cppu::supportsService( this, ServiceName );
94}
95
96uno::Sequence< OUString > SAL_CALL GalleryThemeProvider::getSupportedServiceNames()
97{
98 uno::Sequence<OUString> aSeq { "com.sun.star.gallery.GalleryThemeProvider" };
99 return aSeq;
100}
101
102uno::Sequence< uno::Type > SAL_CALL GalleryThemeProvider::getTypes()
103{
104 static const uno::Sequence aTypes {
111
112 return aTypes;
113}
114
115uno::Sequence< sal_Int8 > SAL_CALL GalleryThemeProvider::getImplementationId()
116{
117 return css::uno::Sequence<sal_Int8>();
118}
119
120void SAL_CALL GalleryThemeProvider::initialize( const uno::Sequence< uno::Any >& rArguments )
121{
122 uno::Sequence< beans::PropertyValue > aParams;
123
124 for( const auto& rArgument : rArguments )
125 {
126 if( rArgument >>= aParams )
127 break;
128 }
129
130 for( const beans::PropertyValue& rProp : std::as_const(aParams) )
131 {
132 if ( rProp.Name == "ProvideHiddenThemes" )
133 rProp.Value >>= mbHiddenThemes;
134 }
135}
136
137
138uno::Type SAL_CALL GalleryThemeProvider::getElementType()
139{
141}
142
143
144sal_Bool SAL_CALL GalleryThemeProvider::hasElements()
145{
146 const SolarMutexGuard aGuard;
147
148 return( ( mpGallery != nullptr ) && ( mpGallery->GetThemeCount() > 0 ) );
149}
150
151
152uno::Any SAL_CALL GalleryThemeProvider::getByName( const OUString& rName )
153{
154 const SolarMutexGuard aGuard;
155 uno::Any aRet;
156
157 if( !mpGallery || !mpGallery->HasTheme( rName ) )
158 {
159 throw container::NoSuchElementException();
160 }
161
162 aRet <<= uno::Reference< gallery::XGalleryTheme >( new ::unogallery::GalleryTheme( rName ) );
163
164 return aRet;
165}
166
167
168uno::Sequence< OUString > SAL_CALL GalleryThemeProvider::getElementNames()
169{
170 const SolarMutexGuard aGuard;
171 sal_uInt32 i = 0, nCount = ( mpGallery ? mpGallery->GetThemeCount() : 0 ), nRealCount = 0;
172 uno::Sequence< OUString > aSeq( nCount );
173 auto aSeqRange = asNonConstRange(aSeq);
174
175 for( ; i < nCount; ++i )
176 {
177 const GalleryThemeEntry* pEntry = mpGallery->GetThemeInfo( i );
178
179 if( mbHiddenThemes || !pEntry->IsHidden() )
180 aSeqRange[ nRealCount++ ] = pEntry->GetThemeName();
181 }
182
183 aSeq.realloc( nRealCount );
184
185 return aSeq;
186}
187
188
189sal_Bool SAL_CALL GalleryThemeProvider::hasByName( const OUString& rName )
190{
191 const SolarMutexGuard aGuard;
192
193 bool bRet = false;
194
195 if( mpGallery && mpGallery->HasTheme( rName ) )
196 bRet = ( mbHiddenThemes || !mpGallery->GetThemeInfo( rName )->IsHidden() );
197
198 return bRet;
199}
200
201
202uno::Reference< gallery::XGalleryTheme > SAL_CALL GalleryThemeProvider::insertNewByName( const OUString& rThemeName )
203{
204 const SolarMutexGuard aGuard;
205 uno::Reference< gallery::XGalleryTheme > xRet;
206
207 if( mpGallery )
208 {
209 if( mpGallery->HasTheme( rThemeName ) )
210 {
211 throw container::ElementExistException();
212 }
213 else if( mpGallery->CreateTheme( rThemeName ) )
214 {
215 xRet = new ::unogallery::GalleryTheme( rThemeName );
216 }
217 }
218
219 return xRet;
220}
221
222
223void SAL_CALL GalleryThemeProvider::removeByName( const OUString& rName )
224{
225 const SolarMutexGuard aGuard;
226
227 if( !mpGallery ||
228 !mpGallery->HasTheme( rName ) ||
229 ( !mbHiddenThemes && mpGallery->GetThemeInfo( rName )->IsHidden() ) )
230 {
231 throw container::NoSuchElementException();
232 }
233
234 mpGallery->RemoveTheme( rName );
235}
236
237}
238
239extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
241 css::uno::XComponentContext *,
242 css::uno::Sequence<css::uno::Any> const &)
243{
244 return cppu::acquire(new GalleryThemeProvider);
245}
246
247/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const OUString & GetThemeName() const
Definition: gallery1.hxx:64
bool IsHidden() const
Definition: gallery1.hxx:69
static Gallery * GetGalleryInstance()
Definition: gallery1.cxx:239
css::uno::Type const & get()
int nCount
Sequence< sal_Int8 > aSeq
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
int i
unsigned char sal_Bool
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_gallery_GalleryThemeProvider_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
const SvXMLTokenMapEntry aTypes[]