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