1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_svx.hxx" 30 31 #include "unogalthemeprovider.hxx" 32 #include "unogaltheme.hxx" 33 #include "svx/gallery1.hxx" 34 #include <rtl/uuid.h> 35 #include <vos/mutex.hxx> 36 #ifndef _SV_SVAPP_HXX_ 37 #include <vcl/svapp.hxx> 38 #endif 39 #include <unotools/pathoptions.hxx> 40 #include <com/sun/star/gallery/XGalleryTheme.hpp> 41 #include <com/sun/star/beans/PropertyValue.hpp> 42 43 using namespace ::com::sun::star; 44 45 namespace unogallery { 46 47 // -------------------- 48 // - Helper functions - 49 // -------------------- 50 51 uno::Reference< uno::XInterface > SAL_CALL GalleryThemeProvider_createInstance( 52 const uno::Reference< lang::XMultiServiceFactory > & ) 53 throw( uno::Exception ) 54 { 55 return *( new GalleryThemeProvider() ); 56 } 57 58 // ----------------------------------------------------------------------------- 59 60 uno::Sequence< ::rtl::OUString > SAL_CALL GalleryThemeProvider_getSupportedServiceNames() 61 throw() 62 { 63 return GalleryThemeProvider::getSupportedServiceNames_Static(); 64 } 65 66 // ----------------------------------------------------------------------------- 67 68 ::rtl::OUString SAL_CALL GalleryThemeProvider_getImplementationName() 69 throw() 70 { 71 return GalleryThemeProvider::getImplementationName_Static(); 72 } 73 74 // ----------------- 75 // - GalleryThemeProvider - 76 // ----------------- 77 78 GalleryThemeProvider::GalleryThemeProvider() : 79 mbHiddenThemes( sal_False ) 80 { 81 mpGallery = ::Gallery::GetGalleryInstance(); 82 } 83 84 // ------------------------------------------------------------------------------ 85 86 GalleryThemeProvider::~GalleryThemeProvider() 87 { 88 } 89 90 // ------------------------------------------------------------------------------ 91 92 SVX_DLLPUBLIC ::rtl::OUString GalleryThemeProvider::getImplementationName_Static() 93 throw() 94 { 95 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.gallery.GalleryThemeProvider" ) ); 96 } 97 98 // ------------------------------------------------------------------------------ 99 100 SVX_DLLPUBLIC uno::Sequence< ::rtl::OUString > GalleryThemeProvider::getSupportedServiceNames_Static() 101 throw() 102 { 103 uno::Sequence< ::rtl::OUString > aSeq( 1 ); 104 105 aSeq.getArray()[ 0 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.gallery.GalleryThemeProvider" ) ); 106 107 return aSeq; 108 } 109 110 // ------------------------------------------------------------------------------ 111 112 ::rtl::OUString SAL_CALL GalleryThemeProvider::getImplementationName() 113 throw( uno::RuntimeException ) 114 { 115 return getImplementationName_Static(); 116 } 117 118 // ------------------------------------------------------------------------------ 119 120 sal_Bool SAL_CALL GalleryThemeProvider::supportsService( const ::rtl::OUString& ServiceName ) 121 throw( uno::RuntimeException ) 122 { 123 uno::Sequence< ::rtl::OUString > aSNL( getSupportedServiceNames() ); 124 const ::rtl::OUString* pArray = aSNL.getConstArray(); 125 126 for( int i = 0; i < aSNL.getLength(); i++ ) 127 if( pArray[i] == ServiceName ) 128 return true; 129 130 return false; 131 } 132 133 // ------------------------------------------------------------------------------ 134 135 uno::Sequence< ::rtl::OUString > SAL_CALL GalleryThemeProvider::getSupportedServiceNames() 136 throw( uno::RuntimeException ) 137 { 138 return getSupportedServiceNames_Static(); 139 } 140 141 // ------------------------------------------------------------------------------ 142 143 uno::Sequence< uno::Type > SAL_CALL GalleryThemeProvider::getTypes() 144 throw(uno::RuntimeException) 145 { 146 uno::Sequence< uno::Type > aTypes( 6 ); 147 uno::Type* pTypes = aTypes.getArray(); 148 149 *pTypes++ = ::getCppuType((const uno::Reference< lang::XServiceInfo>*)0); 150 *pTypes++ = ::getCppuType((const uno::Reference< lang::XTypeProvider>*)0); 151 *pTypes++ = ::getCppuType((const uno::Reference< lang::XInitialization>*)0); 152 *pTypes++ = ::getCppuType((const uno::Reference< container::XElementAccess>*)0); 153 *pTypes++ = ::getCppuType((const uno::Reference< container::XNameAccess>*)0); 154 *pTypes++ = ::getCppuType((const uno::Reference< gallery::XGalleryThemeProvider>*)0); 155 156 return aTypes; 157 } 158 159 // ------------------------------------------------------------------------------ 160 161 uno::Sequence< sal_Int8 > SAL_CALL GalleryThemeProvider::getImplementationId() 162 throw(uno::RuntimeException) 163 { 164 const vos::OGuard aGuard( Application::GetSolarMutex() ); 165 static uno::Sequence< sal_Int8 > aId; 166 167 if( aId.getLength() == 0 ) 168 { 169 aId.realloc( 16 ); 170 rtl_createUuid( reinterpret_cast< sal_uInt8* >( aId.getArray() ), 0, sal_True ); 171 } 172 173 return aId; 174 } 175 176 // ------------------------------------------------------------------------------ 177 178 void SAL_CALL GalleryThemeProvider::initialize( const uno::Sequence< uno::Any >& rArguments ) 179 throw ( uno::Exception, uno::RuntimeException ) 180 { 181 uno::Sequence< beans::PropertyValue > aParams; 182 sal_Int32 i; 183 184 for( i = 0; i < rArguments.getLength(); ++i ) 185 { 186 if( rArguments[ i ] >>= aParams ) 187 break; 188 } 189 190 for( i = 0; i < aParams.getLength(); ++i ) 191 { 192 const beans::PropertyValue& rProp = aParams[ i ]; 193 194 if( rProp.Name.equalsAscii( "ProvideHiddenThemes" ) ) 195 rProp.Value >>= mbHiddenThemes; 196 } 197 } 198 199 // ------------------------------------------------------------------------------ 200 201 uno::Type SAL_CALL GalleryThemeProvider::getElementType() 202 throw (uno::RuntimeException) 203 { 204 return ::getCppuType( (const uno::Reference< gallery::XGalleryTheme >*) 0); 205 } 206 207 // ------------------------------------------------------------------------------ 208 209 sal_Bool SAL_CALL GalleryThemeProvider::hasElements() 210 throw (uno::RuntimeException) 211 { 212 const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 213 214 return( ( mpGallery != NULL ) && ( mpGallery->GetThemeCount() > 0 ) ); 215 } 216 217 // ------------------------------------------------------------------------------ 218 219 uno::Any SAL_CALL GalleryThemeProvider::getByName( const ::rtl::OUString& rName ) 220 throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) 221 { 222 const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 223 uno::Any aRet; 224 225 if( !mpGallery || !mpGallery->HasTheme( rName ) ) 226 { 227 throw container::NoSuchElementException(); 228 } 229 else 230 { 231 aRet = uno::makeAny( uno::Reference< gallery::XGalleryTheme >( new ::unogallery::GalleryTheme( rName ) ) ); 232 } 233 234 return aRet; 235 } 236 237 // ------------------------------------------------------------------------------ 238 239 uno::Sequence< ::rtl::OUString > SAL_CALL GalleryThemeProvider::getElementNames() 240 throw (uno::RuntimeException) 241 { 242 const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 243 sal_uInt32 i = 0, nCount = ( mpGallery ? mpGallery->GetThemeCount() : 0 ), nRealCount = 0; 244 uno::Sequence< ::rtl::OUString > aSeq( nCount ); 245 246 for( ; i < nCount; ++i ) 247 { 248 const GalleryThemeEntry* pEntry = mpGallery->GetThemeInfo( i ); 249 250 if( mbHiddenThemes || !pEntry->IsHidden() ) 251 aSeq[ nRealCount++ ] = pEntry->GetThemeName(); 252 } 253 254 aSeq.realloc( nRealCount ); 255 256 return aSeq; 257 } 258 259 // ------------------------------------------------------------------------------ 260 261 sal_Bool SAL_CALL GalleryThemeProvider::hasByName( const ::rtl::OUString& rName ) 262 throw (uno::RuntimeException) 263 { 264 const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 265 266 sal_Bool bRet = sal_False; 267 268 if( mpGallery && mpGallery->HasTheme( rName ) ) 269 bRet = ( mbHiddenThemes || !mpGallery->GetThemeInfo( rName )->IsHidden() ); 270 271 return( bRet ); 272 } 273 274 // ------------------------------------------------------------------------------ 275 276 uno::Reference< gallery::XGalleryTheme > SAL_CALL GalleryThemeProvider::insertNewByName( const ::rtl::OUString& rThemeName ) 277 throw (container::ElementExistException, uno::RuntimeException) 278 { 279 const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 280 uno::Reference< gallery::XGalleryTheme > xRet; 281 282 if( mpGallery ) 283 { 284 if( mpGallery->HasTheme( rThemeName ) ) 285 { 286 throw container::ElementExistException(); 287 } 288 else if( mpGallery->CreateTheme( rThemeName ) ) 289 { 290 xRet = new ::unogallery::GalleryTheme( rThemeName ); 291 } 292 } 293 294 return xRet; 295 } 296 297 // ------------------------------------------------------------------------------ 298 299 void SAL_CALL GalleryThemeProvider::removeByName( const ::rtl::OUString& rName ) 300 throw (container::NoSuchElementException, uno::RuntimeException) 301 { 302 const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 303 304 if( !mpGallery || 305 !mpGallery->HasTheme( rName ) || 306 ( !mbHiddenThemes && mpGallery->GetThemeInfo( rName )->IsHidden() ) ) 307 { 308 throw container::NoSuchElementException(); 309 } 310 else 311 { 312 mpGallery->RemoveTheme( rName ); 313 } 314 } 315 316 } 317