1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_svx.hxx" 26 27 #include "unogalthemeprovider.hxx" 28 #include "unogaltheme.hxx" 29 #include "svx/gallery1.hxx" 30 #include <rtl/uuid.h> 31 #include <vos/mutex.hxx> 32 #ifndef _SV_SVAPP_HXX_ 33 #include <vcl/svapp.hxx> 34 #endif 35 #include <unotools/pathoptions.hxx> 36 #include <com/sun/star/gallery/XGalleryTheme.hpp> 37 #include <com/sun/star/beans/PropertyValue.hpp> 38 39 using namespace ::com::sun::star; 40 41 namespace unogallery { 42 43 // -------------------- 44 // - Helper functions - 45 // -------------------- 46 GalleryThemeProvider_createInstance(const uno::Reference<lang::XMultiServiceFactory> &)47uno::Reference< uno::XInterface > SAL_CALL GalleryThemeProvider_createInstance( 48 const uno::Reference< lang::XMultiServiceFactory > & ) 49 { 50 return *( new GalleryThemeProvider() ); 51 } 52 53 // ----------------------------------------------------------------------------- 54 GalleryThemeProvider_getSupportedServiceNames()55uno::Sequence< ::rtl::OUString > SAL_CALL GalleryThemeProvider_getSupportedServiceNames() 56 throw() 57 { 58 return GalleryThemeProvider::getSupportedServiceNames_Static(); 59 } 60 61 // ----------------------------------------------------------------------------- 62 GalleryThemeProvider_getImplementationName()63::rtl::OUString SAL_CALL GalleryThemeProvider_getImplementationName() 64 throw() 65 { 66 return GalleryThemeProvider::getImplementationName_Static(); 67 } 68 69 // ----------------- 70 // - GalleryThemeProvider - 71 // ----------------- 72 GalleryThemeProvider()73GalleryThemeProvider::GalleryThemeProvider() : 74 mbHiddenThemes( sal_False ) 75 { 76 mpGallery = ::Gallery::GetGalleryInstance(); 77 } 78 79 // ------------------------------------------------------------------------------ 80 ~GalleryThemeProvider()81GalleryThemeProvider::~GalleryThemeProvider() 82 { 83 } 84 85 // ------------------------------------------------------------------------------ 86 getImplementationName_Static()87SVX_DLLPUBLIC ::rtl::OUString GalleryThemeProvider::getImplementationName_Static() 88 throw() 89 { 90 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.gallery.GalleryThemeProvider" ) ); 91 } 92 93 // ------------------------------------------------------------------------------ 94 getSupportedServiceNames_Static()95SVX_DLLPUBLIC uno::Sequence< ::rtl::OUString > GalleryThemeProvider::getSupportedServiceNames_Static() 96 throw() 97 { 98 uno::Sequence< ::rtl::OUString > aSeq( 1 ); 99 100 aSeq.getArray()[ 0 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.gallery.GalleryThemeProvider" ) ); 101 102 return aSeq; 103 } 104 105 // ------------------------------------------------------------------------------ 106 getImplementationName()107::rtl::OUString SAL_CALL GalleryThemeProvider::getImplementationName() 108 { 109 return getImplementationName_Static(); 110 } 111 112 // ------------------------------------------------------------------------------ 113 supportsService(const::rtl::OUString & ServiceName)114sal_Bool SAL_CALL GalleryThemeProvider::supportsService( const ::rtl::OUString& ServiceName ) 115 { 116 uno::Sequence< ::rtl::OUString > aSNL( getSupportedServiceNames() ); 117 const ::rtl::OUString* pArray = aSNL.getConstArray(); 118 119 for( int i = 0; i < aSNL.getLength(); i++ ) 120 if( pArray[i] == ServiceName ) 121 return true; 122 123 return false; 124 } 125 126 // ------------------------------------------------------------------------------ 127 getSupportedServiceNames()128uno::Sequence< ::rtl::OUString > SAL_CALL GalleryThemeProvider::getSupportedServiceNames() 129 { 130 return getSupportedServiceNames_Static(); 131 } 132 133 // ------------------------------------------------------------------------------ 134 getTypes()135uno::Sequence< uno::Type > SAL_CALL GalleryThemeProvider::getTypes() 136 { 137 uno::Sequence< uno::Type > aTypes( 6 ); 138 uno::Type* pTypes = aTypes.getArray(); 139 140 *pTypes++ = ::getCppuType((const uno::Reference< lang::XServiceInfo>*)0); 141 *pTypes++ = ::getCppuType((const uno::Reference< lang::XTypeProvider>*)0); 142 *pTypes++ = ::getCppuType((const uno::Reference< lang::XInitialization>*)0); 143 *pTypes++ = ::getCppuType((const uno::Reference< container::XElementAccess>*)0); 144 *pTypes++ = ::getCppuType((const uno::Reference< container::XNameAccess>*)0); 145 *pTypes++ = ::getCppuType((const uno::Reference< gallery::XGalleryThemeProvider>*)0); 146 147 return aTypes; 148 } 149 150 // ------------------------------------------------------------------------------ 151 getImplementationId()152uno::Sequence< sal_Int8 > SAL_CALL GalleryThemeProvider::getImplementationId() 153 { 154 const vos::OGuard aGuard( Application::GetSolarMutex() ); 155 static uno::Sequence< sal_Int8 > aId; 156 157 if( aId.getLength() == 0 ) 158 { 159 aId.realloc( 16 ); 160 rtl_createUuid( reinterpret_cast< sal_uInt8* >( aId.getArray() ), 0, sal_True ); 161 } 162 163 return aId; 164 } 165 166 // ------------------------------------------------------------------------------ 167 initialize(const uno::Sequence<uno::Any> & rArguments)168void SAL_CALL GalleryThemeProvider::initialize( const uno::Sequence< uno::Any >& rArguments ) 169 { 170 uno::Sequence< beans::PropertyValue > aParams; 171 sal_Int32 i; 172 173 for( i = 0; i < rArguments.getLength(); ++i ) 174 { 175 if( rArguments[ i ] >>= aParams ) 176 break; 177 } 178 179 for( i = 0; i < aParams.getLength(); ++i ) 180 { 181 const beans::PropertyValue& rProp = aParams[ i ]; 182 183 if( rProp.Name.equalsAscii( "ProvideHiddenThemes" ) ) 184 rProp.Value >>= mbHiddenThemes; 185 } 186 } 187 188 // ------------------------------------------------------------------------------ 189 getElementType()190uno::Type SAL_CALL GalleryThemeProvider::getElementType() 191 { 192 return ::getCppuType( (const uno::Reference< gallery::XGalleryTheme >*) 0); 193 } 194 195 // ------------------------------------------------------------------------------ 196 hasElements()197sal_Bool SAL_CALL GalleryThemeProvider::hasElements() 198 { 199 const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 200 201 return( ( mpGallery != NULL ) && ( mpGallery->GetThemeCount() > 0 ) ); 202 } 203 204 // ------------------------------------------------------------------------------ 205 getByName(const::rtl::OUString & rName)206uno::Any SAL_CALL GalleryThemeProvider::getByName( const ::rtl::OUString& rName ) 207 { 208 const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 209 uno::Any aRet; 210 211 if( !mpGallery || !mpGallery->HasTheme( rName ) ) 212 { 213 throw container::NoSuchElementException(); 214 } 215 else 216 { 217 aRet = uno::makeAny( uno::Reference< gallery::XGalleryTheme >( new ::unogallery::GalleryTheme( rName ) ) ); 218 } 219 220 return aRet; 221 } 222 223 // ------------------------------------------------------------------------------ 224 getElementNames()225uno::Sequence< ::rtl::OUString > SAL_CALL GalleryThemeProvider::getElementNames() 226 { 227 const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 228 sal_uInt32 i = 0, nCount = ( mpGallery ? mpGallery->GetThemeCount() : 0 ), nRealCount = 0; 229 uno::Sequence< ::rtl::OUString > aSeq( nCount ); 230 231 for( ; i < nCount; ++i ) 232 { 233 const GalleryThemeEntry* pEntry = mpGallery->GetThemeInfo( i ); 234 235 if( mbHiddenThemes || !pEntry->IsHidden() ) 236 aSeq[ nRealCount++ ] = pEntry->GetThemeName(); 237 } 238 239 aSeq.realloc( nRealCount ); 240 241 return aSeq; 242 } 243 244 // ------------------------------------------------------------------------------ 245 hasByName(const::rtl::OUString & rName)246sal_Bool SAL_CALL GalleryThemeProvider::hasByName( const ::rtl::OUString& rName ) 247 { 248 const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 249 250 sal_Bool bRet = sal_False; 251 252 if( mpGallery && mpGallery->HasTheme( rName ) ) 253 bRet = ( mbHiddenThemes || !mpGallery->GetThemeInfo( rName )->IsHidden() ); 254 255 return( bRet ); 256 } 257 258 // ------------------------------------------------------------------------------ 259 insertNewByName(const::rtl::OUString & rThemeName)260uno::Reference< gallery::XGalleryTheme > SAL_CALL GalleryThemeProvider::insertNewByName( const ::rtl::OUString& rThemeName ) 261 { 262 const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 263 uno::Reference< gallery::XGalleryTheme > xRet; 264 265 if( mpGallery ) 266 { 267 if( mpGallery->HasTheme( rThemeName ) ) 268 { 269 throw container::ElementExistException(); 270 } 271 else if( mpGallery->CreateTheme( rThemeName ) ) 272 { 273 xRet = new ::unogallery::GalleryTheme( rThemeName ); 274 } 275 } 276 277 return xRet; 278 } 279 280 // ------------------------------------------------------------------------------ 281 removeByName(const::rtl::OUString & rName)282void SAL_CALL GalleryThemeProvider::removeByName( const ::rtl::OUString& rName ) 283 { 284 const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 285 286 if( !mpGallery || 287 !mpGallery->HasTheme( rName ) || 288 ( !mbHiddenThemes && mpGallery->GetThemeInfo( rName )->IsHidden() ) ) 289 { 290 throw container::NoSuchElementException(); 291 } 292 else 293 { 294 mpGallery->RemoveTheme( rName ); 295 } 296 } 297 298 } 299