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 47 uno::Reference< uno::XInterface > SAL_CALL GalleryThemeProvider_createInstance( 48 const uno::Reference< lang::XMultiServiceFactory > & ) 49 throw( uno::Exception ) 50 { 51 return *( new GalleryThemeProvider() ); 52 } 53 54 // ----------------------------------------------------------------------------- 55 56 uno::Sequence< ::rtl::OUString > SAL_CALL GalleryThemeProvider_getSupportedServiceNames() 57 throw() 58 { 59 return GalleryThemeProvider::getSupportedServiceNames_Static(); 60 } 61 62 // ----------------------------------------------------------------------------- 63 64 ::rtl::OUString SAL_CALL GalleryThemeProvider_getImplementationName() 65 throw() 66 { 67 return GalleryThemeProvider::getImplementationName_Static(); 68 } 69 70 // ----------------- 71 // - GalleryThemeProvider - 72 // ----------------- 73 74 GalleryThemeProvider::GalleryThemeProvider() : 75 mbHiddenThemes( sal_False ) 76 { 77 mpGallery = ::Gallery::GetGalleryInstance(); 78 } 79 80 // ------------------------------------------------------------------------------ 81 82 GalleryThemeProvider::~GalleryThemeProvider() 83 { 84 } 85 86 // ------------------------------------------------------------------------------ 87 88 SVX_DLLPUBLIC ::rtl::OUString GalleryThemeProvider::getImplementationName_Static() 89 throw() 90 { 91 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.gallery.GalleryThemeProvider" ) ); 92 } 93 94 // ------------------------------------------------------------------------------ 95 96 SVX_DLLPUBLIC uno::Sequence< ::rtl::OUString > GalleryThemeProvider::getSupportedServiceNames_Static() 97 throw() 98 { 99 uno::Sequence< ::rtl::OUString > aSeq( 1 ); 100 101 aSeq.getArray()[ 0 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.gallery.GalleryThemeProvider" ) ); 102 103 return aSeq; 104 } 105 106 // ------------------------------------------------------------------------------ 107 108 ::rtl::OUString SAL_CALL GalleryThemeProvider::getImplementationName() 109 throw( uno::RuntimeException ) 110 { 111 return getImplementationName_Static(); 112 } 113 114 // ------------------------------------------------------------------------------ 115 116 sal_Bool SAL_CALL GalleryThemeProvider::supportsService( const ::rtl::OUString& ServiceName ) 117 throw( uno::RuntimeException ) 118 { 119 uno::Sequence< ::rtl::OUString > aSNL( getSupportedServiceNames() ); 120 const ::rtl::OUString* pArray = aSNL.getConstArray(); 121 122 for( int i = 0; i < aSNL.getLength(); i++ ) 123 if( pArray[i] == ServiceName ) 124 return true; 125 126 return false; 127 } 128 129 // ------------------------------------------------------------------------------ 130 131 uno::Sequence< ::rtl::OUString > SAL_CALL GalleryThemeProvider::getSupportedServiceNames() 132 throw( uno::RuntimeException ) 133 { 134 return getSupportedServiceNames_Static(); 135 } 136 137 // ------------------------------------------------------------------------------ 138 139 uno::Sequence< uno::Type > SAL_CALL GalleryThemeProvider::getTypes() 140 throw(uno::RuntimeException) 141 { 142 uno::Sequence< uno::Type > aTypes( 6 ); 143 uno::Type* pTypes = aTypes.getArray(); 144 145 *pTypes++ = ::getCppuType((const uno::Reference< lang::XServiceInfo>*)0); 146 *pTypes++ = ::getCppuType((const uno::Reference< lang::XTypeProvider>*)0); 147 *pTypes++ = ::getCppuType((const uno::Reference< lang::XInitialization>*)0); 148 *pTypes++ = ::getCppuType((const uno::Reference< container::XElementAccess>*)0); 149 *pTypes++ = ::getCppuType((const uno::Reference< container::XNameAccess>*)0); 150 *pTypes++ = ::getCppuType((const uno::Reference< gallery::XGalleryThemeProvider>*)0); 151 152 return aTypes; 153 } 154 155 // ------------------------------------------------------------------------------ 156 157 uno::Sequence< sal_Int8 > SAL_CALL GalleryThemeProvider::getImplementationId() 158 throw(uno::RuntimeException) 159 { 160 const vos::OGuard aGuard( Application::GetSolarMutex() ); 161 static uno::Sequence< sal_Int8 > aId; 162 163 if( aId.getLength() == 0 ) 164 { 165 aId.realloc( 16 ); 166 rtl_createUuid( reinterpret_cast< sal_uInt8* >( aId.getArray() ), 0, sal_True ); 167 } 168 169 return aId; 170 } 171 172 // ------------------------------------------------------------------------------ 173 174 void SAL_CALL GalleryThemeProvider::initialize( const uno::Sequence< uno::Any >& rArguments ) 175 throw ( uno::Exception, uno::RuntimeException ) 176 { 177 uno::Sequence< beans::PropertyValue > aParams; 178 sal_Int32 i; 179 180 for( i = 0; i < rArguments.getLength(); ++i ) 181 { 182 if( rArguments[ i ] >>= aParams ) 183 break; 184 } 185 186 for( i = 0; i < aParams.getLength(); ++i ) 187 { 188 const beans::PropertyValue& rProp = aParams[ i ]; 189 190 if( rProp.Name.equalsAscii( "ProvideHiddenThemes" ) ) 191 rProp.Value >>= mbHiddenThemes; 192 } 193 } 194 195 // ------------------------------------------------------------------------------ 196 197 uno::Type SAL_CALL GalleryThemeProvider::getElementType() 198 throw (uno::RuntimeException) 199 { 200 return ::getCppuType( (const uno::Reference< gallery::XGalleryTheme >*) 0); 201 } 202 203 // ------------------------------------------------------------------------------ 204 205 sal_Bool SAL_CALL GalleryThemeProvider::hasElements() 206 throw (uno::RuntimeException) 207 { 208 const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 209 210 return( ( mpGallery != NULL ) && ( mpGallery->GetThemeCount() > 0 ) ); 211 } 212 213 // ------------------------------------------------------------------------------ 214 215 uno::Any SAL_CALL GalleryThemeProvider::getByName( const ::rtl::OUString& rName ) 216 throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) 217 { 218 const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 219 uno::Any aRet; 220 221 if( !mpGallery || !mpGallery->HasTheme( rName ) ) 222 { 223 throw container::NoSuchElementException(); 224 } 225 else 226 { 227 aRet = uno::makeAny( uno::Reference< gallery::XGalleryTheme >( new ::unogallery::GalleryTheme( rName ) ) ); 228 } 229 230 return aRet; 231 } 232 233 // ------------------------------------------------------------------------------ 234 235 uno::Sequence< ::rtl::OUString > SAL_CALL GalleryThemeProvider::getElementNames() 236 throw (uno::RuntimeException) 237 { 238 const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 239 sal_uInt32 i = 0, nCount = ( mpGallery ? mpGallery->GetThemeCount() : 0 ), nRealCount = 0; 240 uno::Sequence< ::rtl::OUString > aSeq( nCount ); 241 242 for( ; i < nCount; ++i ) 243 { 244 const GalleryThemeEntry* pEntry = mpGallery->GetThemeInfo( i ); 245 246 if( mbHiddenThemes || !pEntry->IsHidden() ) 247 aSeq[ nRealCount++ ] = pEntry->GetThemeName(); 248 } 249 250 aSeq.realloc( nRealCount ); 251 252 return aSeq; 253 } 254 255 // ------------------------------------------------------------------------------ 256 257 sal_Bool SAL_CALL GalleryThemeProvider::hasByName( const ::rtl::OUString& rName ) 258 throw (uno::RuntimeException) 259 { 260 const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 261 262 sal_Bool bRet = sal_False; 263 264 if( mpGallery && mpGallery->HasTheme( rName ) ) 265 bRet = ( mbHiddenThemes || !mpGallery->GetThemeInfo( rName )->IsHidden() ); 266 267 return( bRet ); 268 } 269 270 // ------------------------------------------------------------------------------ 271 272 uno::Reference< gallery::XGalleryTheme > SAL_CALL GalleryThemeProvider::insertNewByName( const ::rtl::OUString& rThemeName ) 273 throw (container::ElementExistException, uno::RuntimeException) 274 { 275 const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 276 uno::Reference< gallery::XGalleryTheme > xRet; 277 278 if( mpGallery ) 279 { 280 if( mpGallery->HasTheme( rThemeName ) ) 281 { 282 throw container::ElementExistException(); 283 } 284 else if( mpGallery->CreateTheme( rThemeName ) ) 285 { 286 xRet = new ::unogallery::GalleryTheme( rThemeName ); 287 } 288 } 289 290 return xRet; 291 } 292 293 // ------------------------------------------------------------------------------ 294 295 void SAL_CALL GalleryThemeProvider::removeByName( const ::rtl::OUString& rName ) 296 throw (container::NoSuchElementException, uno::RuntimeException) 297 { 298 const ::vos::OGuard aGuard( Application::GetSolarMutex() ); 299 300 if( !mpGallery || 301 !mpGallery->HasTheme( rName ) || 302 ( !mbHiddenThemes && mpGallery->GetThemeInfo( rName )->IsHidden() ) ) 303 { 304 throw container::NoSuchElementException(); 305 } 306 else 307 { 308 mpGallery->RemoveTheme( rName ); 309 } 310 } 311 312 } 313