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>
39class GalleryThemeProvider :
public ::cppu::WeakImplHelper< css::lang::XInitialization,
40 css::gallery::XGalleryThemeProvider,
41 css::lang::XServiceInfo >
45 GalleryThemeProvider();
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;
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;
80GalleryThemeProvider::GalleryThemeProvider() :
81 mbHiddenThemes( false )
86OUString SAL_CALL GalleryThemeProvider::getImplementationName()
88 return "com.sun.star.comp.gallery.GalleryThemeProvider";
91sal_Bool SAL_CALL GalleryThemeProvider::supportsService(
const OUString& ServiceName )
96uno::Sequence< OUString > SAL_CALL GalleryThemeProvider::getSupportedServiceNames()
98 uno::Sequence<OUString>
aSeq {
"com.sun.star.gallery.GalleryThemeProvider" };
102uno::Sequence< uno::Type > SAL_CALL GalleryThemeProvider::getTypes()
104 static const uno::Sequence
aTypes {
115uno::Sequence< sal_Int8 > SAL_CALL GalleryThemeProvider::getImplementationId()
117 return css::uno::Sequence<sal_Int8>();
120void 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;
138uno::Type SAL_CALL GalleryThemeProvider::getElementType()
144sal_Bool SAL_CALL GalleryThemeProvider::hasElements()
148 return( ( mpGallery !=
nullptr ) && ( mpGallery->GetThemeCount() > 0 ) );
152uno::Any SAL_CALL GalleryThemeProvider::getByName(
const OUString& rName )
157 if( !mpGallery || !mpGallery->HasTheme( rName ) )
159 throw container::NoSuchElementException();
162 aRet <<= uno::Reference< gallery::XGalleryTheme >( new ::unogallery::GalleryTheme( rName ) );
168uno::Sequence< OUString > SAL_CALL GalleryThemeProvider::getElementNames()
171 sal_uInt32
i = 0,
nCount = ( mpGallery ? mpGallery->GetThemeCount() : 0 ), nRealCount = 0;
172 uno::Sequence< OUString >
aSeq( nCount );
173 auto aSeqRange = asNonConstRange(aSeq);
179 if( mbHiddenThemes || !pEntry->
IsHidden() )
183 aSeq.realloc( nRealCount );
189sal_Bool SAL_CALL GalleryThemeProvider::hasByName(
const OUString& rName )
195 if( mpGallery && mpGallery->HasTheme( rName ) )
196 bRet = ( mbHiddenThemes || !mpGallery->GetThemeInfo( rName )->IsHidden() );
202uno::Reference< gallery::XGalleryTheme > SAL_CALL GalleryThemeProvider::insertNewByName(
const OUString& rThemeName )
205 uno::Reference< gallery::XGalleryTheme > xRet;
209 if( mpGallery->HasTheme( rThemeName ) )
211 throw container::ElementExistException();
213 else if( mpGallery->CreateTheme( rThemeName ) )
215 xRet = new ::unogallery::GalleryTheme( rThemeName );
223void SAL_CALL GalleryThemeProvider::removeByName(
const OUString& rName )
228 !mpGallery->HasTheme( rName ) ||
229 ( !mbHiddenThemes && mpGallery->GetThemeInfo( rName )->IsHidden() ) )
231 throw container::NoSuchElementException();
234 mpGallery->RemoveTheme( rName );
239extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
241 css::uno::XComponentContext *,
242 css::uno::Sequence<css::uno::Any>
const &)
244 return cppu::acquire(
new GalleryThemeProvider);
const OUString & GetThemeName() const
static Gallery * GetGalleryInstance()
css::uno::Type const & get()
Sequence< sal_Int8 > aSeq
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_gallery_GalleryThemeProvider_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)