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