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 .
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>
33 using namespace ::com::sun::star
;
37 GalleryThemeProvider::GalleryThemeProvider() :
38 mbHiddenThemes( false )
40 mpGallery
= ::Gallery::GetGalleryInstance();
43 GalleryThemeProvider::~GalleryThemeProvider()
47 OUString SAL_CALL
GalleryThemeProvider::getImplementationName()
48 throw( uno::RuntimeException
, std::exception
)
50 return OUString( "com.sun.star.comp.gallery.GalleryThemeProvider" );
53 sal_Bool SAL_CALL
GalleryThemeProvider::supportsService( const OUString
& ServiceName
)
54 throw( uno::RuntimeException
, std::exception
)
56 return cppu::supportsService( this, ServiceName
);
59 uno::Sequence
< OUString
> SAL_CALL
GalleryThemeProvider::getSupportedServiceNames()
60 throw( uno::RuntimeException
, std::exception
)
62 uno::Sequence
< OUString
> aSeq( 1 );
63 aSeq
.getArray()[ 0 ] = "com.sun.star.gallery.GalleryThemeProvider";
67 uno::Sequence
< uno::Type
> SAL_CALL
GalleryThemeProvider::getTypes()
68 throw(uno::RuntimeException
, std::exception
)
70 uno::Sequence
< uno::Type
> aTypes( 6 );
71 uno::Type
* pTypes
= aTypes
.getArray();
73 *pTypes
++ = cppu::UnoType
<lang::XServiceInfo
>::get();
74 *pTypes
++ = cppu::UnoType
<lang::XTypeProvider
>::get();
75 *pTypes
++ = cppu::UnoType
<lang::XInitialization
>::get();
76 *pTypes
++ = cppu::UnoType
<container::XElementAccess
>::get();
77 *pTypes
++ = cppu::UnoType
<container::XNameAccess
>::get();
78 *pTypes
++ = cppu::UnoType
<gallery::XGalleryThemeProvider
>::get();
83 uno::Sequence
< sal_Int8
> SAL_CALL
GalleryThemeProvider::getImplementationId()
84 throw(uno::RuntimeException
, std::exception
)
86 return css::uno::Sequence
<sal_Int8
>();
89 void SAL_CALL
GalleryThemeProvider::initialize( const uno::Sequence
< uno::Any
>& rArguments
)
90 throw ( uno::Exception
, uno::RuntimeException
, std::exception
)
92 uno::Sequence
< beans::PropertyValue
> aParams
;
95 for( i
= 0; i
< rArguments
.getLength(); ++i
)
97 if( rArguments
[ i
] >>= aParams
)
101 for( i
= 0; i
< aParams
.getLength(); ++i
)
103 const beans::PropertyValue
& rProp
= aParams
[ i
];
105 if ( rProp
.Name
== "ProvideHiddenThemes" )
106 rProp
.Value
>>= mbHiddenThemes
;
112 uno::Type SAL_CALL
GalleryThemeProvider::getElementType()
113 throw (uno::RuntimeException
, std::exception
)
115 return cppu::UnoType
<gallery::XGalleryTheme
>::get();
120 sal_Bool SAL_CALL
GalleryThemeProvider::hasElements()
121 throw (uno::RuntimeException
, std::exception
)
123 const SolarMutexGuard aGuard
;
125 return( ( mpGallery
!= NULL
) && ( mpGallery
->GetThemeCount() > 0 ) );
130 uno::Any SAL_CALL
GalleryThemeProvider::getByName( const OUString
& rName
)
131 throw (container::NoSuchElementException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
133 const SolarMutexGuard aGuard
;
136 if( !mpGallery
|| !mpGallery
->HasTheme( rName
) )
138 throw container::NoSuchElementException();
142 aRet
= uno::makeAny( uno::Reference
< gallery::XGalleryTheme
>( new ::unogallery::GalleryTheme( rName
) ) );
150 uno::Sequence
< OUString
> SAL_CALL
GalleryThemeProvider::getElementNames()
151 throw (uno::RuntimeException
, std::exception
)
153 const SolarMutexGuard aGuard
;
154 sal_uInt32 i
= 0, nCount
= ( mpGallery
? mpGallery
->GetThemeCount() : 0 ), nRealCount
= 0;
155 uno::Sequence
< OUString
> aSeq( nCount
);
157 for( ; i
< nCount
; ++i
)
159 const GalleryThemeEntry
* pEntry
= mpGallery
->GetThemeInfo( i
);
161 if( mbHiddenThemes
|| !pEntry
->IsHidden() )
162 aSeq
[ nRealCount
++ ] = pEntry
->GetThemeName();
165 aSeq
.realloc( nRealCount
);
172 sal_Bool SAL_CALL
GalleryThemeProvider::hasByName( const OUString
& rName
)
173 throw (uno::RuntimeException
, std::exception
)
175 const SolarMutexGuard aGuard
;
179 if( mpGallery
&& mpGallery
->HasTheme( rName
) )
180 bRet
= ( mbHiddenThemes
|| !mpGallery
->GetThemeInfo( rName
)->IsHidden() );
187 uno::Reference
< gallery::XGalleryTheme
> SAL_CALL
GalleryThemeProvider::insertNewByName( const OUString
& rThemeName
)
188 throw (container::ElementExistException
, uno::RuntimeException
, std::exception
)
190 const SolarMutexGuard aGuard
;
191 uno::Reference
< gallery::XGalleryTheme
> xRet
;
195 if( mpGallery
->HasTheme( rThemeName
) )
197 throw container::ElementExistException();
199 else if( mpGallery
->CreateTheme( rThemeName
) )
201 xRet
= new ::unogallery::GalleryTheme( rThemeName
);
210 void SAL_CALL
GalleryThemeProvider::removeByName( const OUString
& rName
)
211 throw (container::NoSuchElementException
, uno::RuntimeException
, std::exception
)
213 const SolarMutexGuard aGuard
;
216 !mpGallery
->HasTheme( rName
) ||
217 ( !mbHiddenThemes
&& mpGallery
->GetThemeInfo( rName
)->IsHidden() ) )
219 throw container::NoSuchElementException();
223 mpGallery
->RemoveTheme( rName
);
229 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
230 com_sun_star_comp_gallery_GalleryThemeProvider_get_implementation(
231 css::uno::XComponentContext
*,
232 css::uno::Sequence
<css::uno::Any
> const &)
234 return cppu::acquire(new GalleryThemeProvider
);
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */