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
10*f6e50924SAndrew Rist  *
11*f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*f6e50924SAndrew Rist  *
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.
19*f6e50924SAndrew Rist  *
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 <algorithm>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "unogaltheme.hxx"
30cdf0e10cSrcweir #include "unogalitem.hxx"
31cdf0e10cSrcweir #include "svx/galtheme.hxx"
32cdf0e10cSrcweir #include "svx/gallery1.hxx"
33cdf0e10cSrcweir #include "svx/galmisc.hxx"
34cdf0e10cSrcweir #include <svx/fmmodel.hxx>
35f020429eSPedro Giffuni #include <svx/svdpage.hxx>
36f020429eSPedro Giffuni #include <svx/unopage.hxx>
37f020429eSPedro Giffuni #include <svl/itempool.hxx>
38cdf0e10cSrcweir #include <rtl/uuid.h>
39cdf0e10cSrcweir #include <vos/mutex.hxx>
40cdf0e10cSrcweir #ifndef _SV_SVAPP_HXX_
41cdf0e10cSrcweir #include <vcl/svapp.hxx>
42cdf0e10cSrcweir #endif
43cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
44cdf0e10cSrcweir 
45cdf0e10cSrcweir using namespace ::com::sun::star;
46cdf0e10cSrcweir 
47cdf0e10cSrcweir namespace unogallery {
48cdf0e10cSrcweir 
49cdf0e10cSrcweir // -----------------
50cdf0e10cSrcweir // - GalleryTheme -
51cdf0e10cSrcweir // -----------------
52cdf0e10cSrcweir 
GalleryTheme(const::rtl::OUString & rThemeName)53cdf0e10cSrcweir GalleryTheme::GalleryTheme( const ::rtl::OUString& rThemeName )
54cdf0e10cSrcweir {
55cdf0e10cSrcweir 	mpGallery = ::Gallery::GetGalleryInstance();
56cdf0e10cSrcweir 	mpTheme = ( mpGallery ? mpGallery->AcquireTheme( rThemeName, *this ) : NULL );
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 	if( mpGallery )
59cdf0e10cSrcweir 		StartListening( *mpGallery );
60cdf0e10cSrcweir }
61cdf0e10cSrcweir 
62cdf0e10cSrcweir // ------------------------------------------------------------------------------
63cdf0e10cSrcweir 
~GalleryTheme()64cdf0e10cSrcweir GalleryTheme::~GalleryTheme()
65cdf0e10cSrcweir {
66cdf0e10cSrcweir 	const ::vos::OGuard aGuard( Application::GetSolarMutex() );
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 	DBG_ASSERT( !mpTheme || mpGallery, "Theme is living without Gallery" );
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 	implReleaseItems( NULL );
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 	if( mpGallery )
73cdf0e10cSrcweir 	{
74cdf0e10cSrcweir 		EndListening( *mpGallery );
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 		if( mpTheme )
77cdf0e10cSrcweir 			mpGallery->ReleaseTheme( mpTheme, *this );
78cdf0e10cSrcweir 	}
79cdf0e10cSrcweir }
80cdf0e10cSrcweir 
81cdf0e10cSrcweir // ------------------------------------------------------------------------------
82cdf0e10cSrcweir 
getImplementationName_Static()83cdf0e10cSrcweir ::rtl::OUString GalleryTheme::getImplementationName_Static()
84cdf0e10cSrcweir 	throw()
85cdf0e10cSrcweir {
86cdf0e10cSrcweir 	return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.gallery.GalleryTheme" ) );
87cdf0e10cSrcweir }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir // ------------------------------------------------------------------------------
90cdf0e10cSrcweir 
getSupportedServiceNames_Static()91cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > GalleryTheme::getSupportedServiceNames_Static()
92cdf0e10cSrcweir 	throw()
93cdf0e10cSrcweir {
94cdf0e10cSrcweir 	uno::Sequence< ::rtl::OUString > aSeq( 1 );
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 	aSeq.getArray()[ 0 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.gallery.GalleryTheme" ) );
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 	return aSeq;
99cdf0e10cSrcweir }
100cdf0e10cSrcweir 
101cdf0e10cSrcweir // ------------------------------------------------------------------------------
102cdf0e10cSrcweir 
getImplementationName()103cdf0e10cSrcweir ::rtl::OUString SAL_CALL GalleryTheme::getImplementationName()
104cdf0e10cSrcweir 	throw( uno::RuntimeException )
105cdf0e10cSrcweir {
106cdf0e10cSrcweir 	return getImplementationName_Static();
107cdf0e10cSrcweir }
108cdf0e10cSrcweir 
109cdf0e10cSrcweir // ------------------------------------------------------------------------------
110cdf0e10cSrcweir 
supportsService(const::rtl::OUString & ServiceName)111cdf0e10cSrcweir sal_Bool SAL_CALL GalleryTheme::supportsService( const ::rtl::OUString& ServiceName )
112cdf0e10cSrcweir 	throw( uno::RuntimeException )
113cdf0e10cSrcweir {
114cdf0e10cSrcweir     uno::Sequence< ::rtl::OUString >	aSNL( getSupportedServiceNames() );
115cdf0e10cSrcweir     const ::rtl::OUString*				pArray = aSNL.getConstArray();
116cdf0e10cSrcweir 
117cdf0e10cSrcweir     for( int i = 0; i < aSNL.getLength(); i++ )
118cdf0e10cSrcweir         if( pArray[i] == ServiceName )
119cdf0e10cSrcweir             return true;
120cdf0e10cSrcweir 
121cdf0e10cSrcweir     return false;
122cdf0e10cSrcweir }
123cdf0e10cSrcweir 
124cdf0e10cSrcweir // ------------------------------------------------------------------------------
125cdf0e10cSrcweir 
getSupportedServiceNames()126cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL GalleryTheme::getSupportedServiceNames()
127cdf0e10cSrcweir 	throw( uno::RuntimeException )
128cdf0e10cSrcweir {
129cdf0e10cSrcweir 	return getSupportedServiceNames_Static();
130cdf0e10cSrcweir }
131cdf0e10cSrcweir 
132cdf0e10cSrcweir // ------------------------------------------------------------------------------
133cdf0e10cSrcweir 
getTypes()134cdf0e10cSrcweir uno::Sequence< uno::Type > SAL_CALL GalleryTheme::getTypes()
135cdf0e10cSrcweir 	throw(uno::RuntimeException)
136cdf0e10cSrcweir {
137cdf0e10cSrcweir 	uno::Sequence< uno::Type >	aTypes( 5 );
138cdf0e10cSrcweir 	uno::Type* 					pTypes = aTypes.getArray();
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 	*pTypes++ = ::getCppuType((const uno::Reference< lang::XServiceInfo>*)0);
141cdf0e10cSrcweir 	*pTypes++ = ::getCppuType((const uno::Reference< lang::XTypeProvider>*)0);
142cdf0e10cSrcweir 	*pTypes++ = ::getCppuType((const uno::Reference< container::XElementAccess>*)0);
143cdf0e10cSrcweir 	*pTypes++ = ::getCppuType((const uno::Reference< container::XIndexAccess>*)0);
144cdf0e10cSrcweir 	*pTypes++ = ::getCppuType((const uno::Reference< gallery::XGalleryTheme>*)0);
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 	return aTypes;
147cdf0e10cSrcweir }
148cdf0e10cSrcweir 
149cdf0e10cSrcweir // ------------------------------------------------------------------------------
150cdf0e10cSrcweir 
getImplementationId()151cdf0e10cSrcweir uno::Sequence< sal_Int8 > SAL_CALL GalleryTheme::getImplementationId()
152cdf0e10cSrcweir 	throw(uno::RuntimeException)
153cdf0e10cSrcweir {
154cdf0e10cSrcweir 	const vos::OGuard 					aGuard( Application::GetSolarMutex() );
155cdf0e10cSrcweir 	static uno::Sequence< sal_Int8 >	aId;
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 	if( aId.getLength() == 0 )
158cdf0e10cSrcweir 	{
159cdf0e10cSrcweir 		aId.realloc( 16 );
160cdf0e10cSrcweir 		rtl_createUuid( reinterpret_cast< sal_uInt8* >( aId.getArray() ), 0, sal_True );
161cdf0e10cSrcweir 	}
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 	return aId;
164cdf0e10cSrcweir }
165cdf0e10cSrcweir 
166cdf0e10cSrcweir // ------------------------------------------------------------------------------
167cdf0e10cSrcweir 
getElementType()168cdf0e10cSrcweir uno::Type SAL_CALL GalleryTheme::getElementType()
169cdf0e10cSrcweir 	throw (uno::RuntimeException)
170cdf0e10cSrcweir {
171cdf0e10cSrcweir 	return ::getCppuType( (const uno::Reference< gallery::XGalleryItem >*) 0);
172cdf0e10cSrcweir }
173cdf0e10cSrcweir 
174cdf0e10cSrcweir // ------------------------------------------------------------------------------
175cdf0e10cSrcweir 
hasElements()176cdf0e10cSrcweir sal_Bool SAL_CALL GalleryTheme::hasElements()
177cdf0e10cSrcweir 	throw (uno::RuntimeException)
178cdf0e10cSrcweir {
179cdf0e10cSrcweir 	const ::vos::OGuard aGuard( Application::GetSolarMutex() );
180cdf0e10cSrcweir 
181cdf0e10cSrcweir 	return( ( mpTheme != NULL ) && ( mpTheme->GetObjectCount() > 0 ) );
182cdf0e10cSrcweir }
183cdf0e10cSrcweir 
184cdf0e10cSrcweir // ------------------------------------------------------------------------------
185cdf0e10cSrcweir 
getCount()186cdf0e10cSrcweir sal_Int32 SAL_CALL GalleryTheme::getCount()
187cdf0e10cSrcweir 	throw (uno::RuntimeException)
188cdf0e10cSrcweir {
189cdf0e10cSrcweir 	const ::vos::OGuard aGuard( Application::GetSolarMutex() );
190cdf0e10cSrcweir 
191cdf0e10cSrcweir 	return( mpTheme ? mpTheme->GetObjectCount() : 0 );
192cdf0e10cSrcweir }
193cdf0e10cSrcweir 
194cdf0e10cSrcweir // ------------------------------------------------------------------------------
195cdf0e10cSrcweir 
getByIndex(::sal_Int32 nIndex)196cdf0e10cSrcweir uno::Any SAL_CALL GalleryTheme::getByIndex( ::sal_Int32 nIndex )
197cdf0e10cSrcweir 	throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
198cdf0e10cSrcweir {
199cdf0e10cSrcweir 	const ::vos::OGuard aGuard( Application::GetSolarMutex() );
200cdf0e10cSrcweir 	uno::Any 			aRet;
201cdf0e10cSrcweir 
202cdf0e10cSrcweir 	if( mpTheme )
203cdf0e10cSrcweir 	{
204cdf0e10cSrcweir 		if( ( nIndex < 0 ) || ( nIndex >= getCount() ) )
205cdf0e10cSrcweir 		{
206cdf0e10cSrcweir 			throw lang::IndexOutOfBoundsException();
207cdf0e10cSrcweir 		}
208cdf0e10cSrcweir 		else
209cdf0e10cSrcweir 		{
210cdf0e10cSrcweir 			const GalleryObject* pObj = mpTheme->ImplGetGalleryObject( nIndex );
211cdf0e10cSrcweir 
212cdf0e10cSrcweir 			if( pObj )
213cdf0e10cSrcweir 				aRet = uno::makeAny( uno::Reference< gallery::XGalleryItem >( new GalleryItem( *this, *pObj ) ) );
214cdf0e10cSrcweir 		}
215cdf0e10cSrcweir 	}
216cdf0e10cSrcweir 
217cdf0e10cSrcweir 	return aRet;
218cdf0e10cSrcweir }
219cdf0e10cSrcweir 
220cdf0e10cSrcweir // ------------------------------------------------------------------------------
221cdf0e10cSrcweir 
getName()222cdf0e10cSrcweir ::rtl::OUString SAL_CALL GalleryTheme::getName(  )
223cdf0e10cSrcweir 	throw (uno::RuntimeException)
224cdf0e10cSrcweir {
225cdf0e10cSrcweir 	const ::vos::OGuard aGuard( Application::GetSolarMutex() );
226cdf0e10cSrcweir 	::rtl::OUString 	aRet;
227cdf0e10cSrcweir 
228cdf0e10cSrcweir 	if( mpTheme )
229cdf0e10cSrcweir 		aRet = mpTheme->GetName();
230cdf0e10cSrcweir 
231cdf0e10cSrcweir 	return aRet;
232cdf0e10cSrcweir }
233cdf0e10cSrcweir 
234cdf0e10cSrcweir // ------------------------------------------------------------------------------
235cdf0e10cSrcweir 
update()236cdf0e10cSrcweir void SAL_CALL GalleryTheme::update(  )
237cdf0e10cSrcweir 	throw (uno::RuntimeException)
238cdf0e10cSrcweir {
239cdf0e10cSrcweir 	const ::vos::OGuard aGuard( Application::GetSolarMutex() );
240cdf0e10cSrcweir 
241cdf0e10cSrcweir 	if( mpTheme )
242cdf0e10cSrcweir 	{
243cdf0e10cSrcweir 		const Link aDummyLink;
244cdf0e10cSrcweir 		mpTheme->Actualize( aDummyLink );
245cdf0e10cSrcweir 	}
246cdf0e10cSrcweir }
247cdf0e10cSrcweir 
248cdf0e10cSrcweir // ------------------------------------------------------------------------------
249cdf0e10cSrcweir 
insertURLByIndex(const::rtl::OUString & rURL,::sal_Int32 nIndex)250cdf0e10cSrcweir ::sal_Int32 SAL_CALL GalleryTheme::insertURLByIndex(
251cdf0e10cSrcweir 	const ::rtl::OUString& rURL, ::sal_Int32 nIndex )
252cdf0e10cSrcweir 	throw (lang::WrappedTargetException, uno::RuntimeException)
253cdf0e10cSrcweir {
254cdf0e10cSrcweir 	const ::vos::OGuard aGuard( Application::GetSolarMutex() );
255cdf0e10cSrcweir 	sal_Int32			nRet = -1;
256cdf0e10cSrcweir 
257cdf0e10cSrcweir 	if( mpTheme )
258cdf0e10cSrcweir 	{
259cdf0e10cSrcweir 		try
260cdf0e10cSrcweir 		{
261cdf0e10cSrcweir 			const INetURLObject aURL( rURL );
262cdf0e10cSrcweir 
263cdf0e10cSrcweir 			nIndex = ::std::max( ::std::min( nIndex, getCount() ), sal_Int32( 0 ) );
264cdf0e10cSrcweir 
265cdf0e10cSrcweir 			if( ( aURL.GetProtocol() != INET_PROT_NOT_VALID ) && mpTheme->InsertURL( aURL, nIndex ) )
266cdf0e10cSrcweir 			{
267cdf0e10cSrcweir 				const GalleryObject* pObj = mpTheme->ImplGetGalleryObject( aURL );
268cdf0e10cSrcweir 
269cdf0e10cSrcweir 				if( pObj )
270cdf0e10cSrcweir 					nRet = mpTheme->ImplGetGalleryObjectPos( pObj );
271cdf0e10cSrcweir 			}
272cdf0e10cSrcweir 		}
273cdf0e10cSrcweir 		catch( ... )
274cdf0e10cSrcweir 		{
275cdf0e10cSrcweir 		}
276cdf0e10cSrcweir 	}
277cdf0e10cSrcweir 
278cdf0e10cSrcweir 	return nRet;
279cdf0e10cSrcweir }
280cdf0e10cSrcweir 
281cdf0e10cSrcweir // ------------------------------------------------------------------------------
282cdf0e10cSrcweir 
insertGraphicByIndex(const uno::Reference<graphic::XGraphic> & rxGraphic,sal_Int32 nIndex)283cdf0e10cSrcweir ::sal_Int32 SAL_CALL GalleryTheme::insertGraphicByIndex(
284cdf0e10cSrcweir 	const uno::Reference< graphic::XGraphic >& rxGraphic, sal_Int32 nIndex )
285cdf0e10cSrcweir 	throw (lang::WrappedTargetException, uno::RuntimeException)
286cdf0e10cSrcweir {
287cdf0e10cSrcweir 	const ::vos::OGuard aGuard( Application::GetSolarMutex() );
288cdf0e10cSrcweir 	sal_Int32 			nRet = -1;
289cdf0e10cSrcweir 
290cdf0e10cSrcweir 	if( mpTheme )
291cdf0e10cSrcweir 	{
292cdf0e10cSrcweir 		try
293cdf0e10cSrcweir 		{
294cdf0e10cSrcweir 			const Graphic aGraphic( rxGraphic );
295cdf0e10cSrcweir 
296cdf0e10cSrcweir 			nIndex = ::std::max( ::std::min( nIndex, getCount() ), sal_Int32( 0 ) );
297cdf0e10cSrcweir 
298cdf0e10cSrcweir 			if( mpTheme->InsertGraphic( aGraphic, nIndex ) )
299cdf0e10cSrcweir 				nRet = nIndex;
300cdf0e10cSrcweir 		}
301cdf0e10cSrcweir 		catch( ... )
302cdf0e10cSrcweir 		{
303cdf0e10cSrcweir 		}
304cdf0e10cSrcweir 	}
305cdf0e10cSrcweir 
306cdf0e10cSrcweir 	return nRet;
307cdf0e10cSrcweir }
308cdf0e10cSrcweir 
309cdf0e10cSrcweir // ------------------------------------------------------------------------------
310cdf0e10cSrcweir 
insertDrawingByIndex(const uno::Reference<lang::XComponent> & Drawing,sal_Int32 nIndex)311cdf0e10cSrcweir ::sal_Int32 SAL_CALL GalleryTheme::insertDrawingByIndex(
312cdf0e10cSrcweir 	const uno::Reference< lang::XComponent >& Drawing, sal_Int32 nIndex )
313cdf0e10cSrcweir 	throw (lang::WrappedTargetException, uno::RuntimeException)
314cdf0e10cSrcweir {
315f020429eSPedro Giffuni     const ::vos::OGuard aGuard( Application::GetSolarMutex() );
316f020429eSPedro Giffuni     sal_Int32           nRet = -1;
317f020429eSPedro Giffuni 
318f020429eSPedro Giffuni     if( mpTheme )
319f020429eSPedro Giffuni     {
320f020429eSPedro Giffuni         GalleryDrawingModel* pModel = GalleryDrawingModel::getImplementation( Drawing );
321f020429eSPedro Giffuni 
322f020429eSPedro Giffuni         if( pModel && pModel->GetDoc() && pModel->GetDoc()->ISA( FmFormModel ) )
323f020429eSPedro Giffuni         {
324f020429eSPedro Giffuni             nIndex = ::std::max( ::std::min( nIndex, getCount() ), sal_Int32( 0 ) );
325f020429eSPedro Giffuni 
326f020429eSPedro Giffuni             if( mpTheme->InsertModel( *static_cast< FmFormModel* >( pModel->GetDoc() ), nIndex ) )
327f020429eSPedro Giffuni                 nRet = nIndex;
328f020429eSPedro Giffuni         }
329f020429eSPedro Giffuni         else if (!pModel)
330f020429eSPedro Giffuni         {
331f020429eSPedro Giffuni             try
332f020429eSPedro Giffuni             {
333f020429eSPedro Giffuni                 uno::Reference< drawing::XDrawPagesSupplier > xDrawPagesSupplier( Drawing, uno::UNO_QUERY_THROW );
334f020429eSPedro Giffuni                 uno::Reference< drawing::XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), uno::UNO_QUERY_THROW );
335f020429eSPedro Giffuni                 uno::Reference< drawing::XDrawPage > xPage( xDrawPages->getByIndex( 0 ), uno::UNO_QUERY_THROW );
336f020429eSPedro Giffuni                 SvxDrawPage* pUnoPage = xPage.is() ? SvxDrawPage::getImplementation( xPage ) : NULL;
337f020429eSPedro Giffuni                 SdrModel* pOrigModel = pUnoPage ? pUnoPage->GetSdrPage()->GetModel() : NULL;
338f020429eSPedro Giffuni                 SdrPage* pOrigPage = pUnoPage ? pUnoPage->GetSdrPage() : NULL;
339f020429eSPedro Giffuni 
340f020429eSPedro Giffuni                 if (pOrigPage && pOrigModel)
341f020429eSPedro Giffuni                 {
342f020429eSPedro Giffuni                     FmFormModel* pTmpModel = new FmFormModel(&pOrigModel->GetItemPool());
343f020429eSPedro Giffuni                     SdrPage* pNewPage = pOrigPage->Clone();
344f020429eSPedro Giffuni                     pTmpModel->InsertPage(pNewPage, 0);
345f020429eSPedro Giffuni 
346f020429eSPedro Giffuni                     uno::Reference< lang::XComponent > xDrawing( new GalleryDrawingModel( pTmpModel ) );
347f020429eSPedro Giffuni                     pTmpModel->setUnoModel( uno::Reference< uno::XInterface >::query( xDrawing ) );
348f020429eSPedro Giffuni 
349f020429eSPedro Giffuni                     nRet = insertDrawingByIndex( xDrawing, nIndex );
350f020429eSPedro Giffuni                     return nRet;
351f020429eSPedro Giffuni                 }
352f020429eSPedro Giffuni             }
353f020429eSPedro Giffuni             catch (...)
354f020429eSPedro Giffuni             {
355f020429eSPedro Giffuni             }
356f020429eSPedro Giffuni         }
357f020429eSPedro Giffuni     }
358f020429eSPedro Giffuni 
359f020429eSPedro Giffuni     return nRet;
360cdf0e10cSrcweir }
361cdf0e10cSrcweir 
362cdf0e10cSrcweir // ------------------------------------------------------------------------------
363cdf0e10cSrcweir 
removeByIndex(sal_Int32 nIndex)364cdf0e10cSrcweir void SAL_CALL GalleryTheme::removeByIndex( sal_Int32 nIndex )
365cdf0e10cSrcweir 	throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
366cdf0e10cSrcweir {
367cdf0e10cSrcweir 	const ::vos::OGuard aGuard( Application::GetSolarMutex() );
368cdf0e10cSrcweir 
369cdf0e10cSrcweir 	if( mpTheme )
370cdf0e10cSrcweir 	{
371cdf0e10cSrcweir 		if( ( nIndex < 0 ) || ( nIndex >= getCount() ) )
372cdf0e10cSrcweir 			throw lang::IndexOutOfBoundsException();
373cdf0e10cSrcweir 		else
374cdf0e10cSrcweir 			mpTheme->RemoveObject( nIndex );
375cdf0e10cSrcweir 	}
376cdf0e10cSrcweir }
377cdf0e10cSrcweir 
378cdf0e10cSrcweir // ------------------------------------------------------------------------------
379cdf0e10cSrcweir 
Notify(SfxBroadcaster &,const SfxHint & rHint)380cdf0e10cSrcweir void GalleryTheme::Notify( SfxBroadcaster&, const SfxHint& rHint )
381cdf0e10cSrcweir {
382cdf0e10cSrcweir 	const ::vos::OGuard aGuard( Application::GetSolarMutex() );
383cdf0e10cSrcweir 	const GalleryHint& 	rGalleryHint = static_cast< const GalleryHint& >( rHint );
384cdf0e10cSrcweir 
385cdf0e10cSrcweir 	switch( rGalleryHint.GetType() )
386cdf0e10cSrcweir 	{
387cdf0e10cSrcweir 		case( GALLERY_HINT_CLOSE_THEME ):
388cdf0e10cSrcweir 		{
389cdf0e10cSrcweir 			DBG_ASSERT( !mpTheme || mpGallery, "Theme is living without Gallery" );
390cdf0e10cSrcweir 
391cdf0e10cSrcweir 			implReleaseItems( NULL );
392cdf0e10cSrcweir 
393cdf0e10cSrcweir 			if( mpGallery && mpTheme )
394cdf0e10cSrcweir 			{
395cdf0e10cSrcweir 				mpGallery->ReleaseTheme( mpTheme, *this );
396cdf0e10cSrcweir 				mpTheme = NULL;
397cdf0e10cSrcweir 			}
398cdf0e10cSrcweir 		}
399cdf0e10cSrcweir 		break;
400cdf0e10cSrcweir 
401cdf0e10cSrcweir 		case( GALLERY_HINT_CLOSE_OBJECT ):
402cdf0e10cSrcweir 		{
403cdf0e10cSrcweir 			GalleryObject* pObj = reinterpret_cast< GalleryObject* >( rGalleryHint.GetData1() );
404cdf0e10cSrcweir 
405cdf0e10cSrcweir 			if( pObj )
406cdf0e10cSrcweir 				implReleaseItems( pObj );
407cdf0e10cSrcweir 		}
408cdf0e10cSrcweir 		break;
409cdf0e10cSrcweir 
410cdf0e10cSrcweir 		default:
411cdf0e10cSrcweir 		break;
412cdf0e10cSrcweir 	}
413cdf0e10cSrcweir }
414cdf0e10cSrcweir 
415cdf0e10cSrcweir // ------------------------------------------------------------------------------
416cdf0e10cSrcweir 
implReleaseItems(GalleryObject * pObj)417cdf0e10cSrcweir void GalleryTheme::implReleaseItems( GalleryObject* pObj )
418cdf0e10cSrcweir {
419cdf0e10cSrcweir 	const ::vos::OGuard aGuard( Application::GetSolarMutex() );
420cdf0e10cSrcweir 
421cdf0e10cSrcweir 	for( GalleryItemList::iterator aIter = maItemList.begin(); aIter != maItemList.end();  )
422cdf0e10cSrcweir 	{
423cdf0e10cSrcweir 		if( !pObj || ( (*aIter)->implGetObject() == pObj ) )
424cdf0e10cSrcweir 		{
425cdf0e10cSrcweir 			(*aIter)->implSetInvalid();
426cdf0e10cSrcweir 			aIter = maItemList.erase( aIter );
427cdf0e10cSrcweir 		}
428cdf0e10cSrcweir 		else
429cdf0e10cSrcweir 			++aIter;
430cdf0e10cSrcweir 	}
431cdf0e10cSrcweir }
432cdf0e10cSrcweir 
433cdf0e10cSrcweir // ------------------------------------------------------------------------------
434cdf0e10cSrcweir 
implGetTheme() const435cdf0e10cSrcweir ::GalleryTheme*	GalleryTheme::implGetTheme() const
436cdf0e10cSrcweir {
437cdf0e10cSrcweir 	return mpTheme;
438cdf0e10cSrcweir }
439cdf0e10cSrcweir 
440cdf0e10cSrcweir // ------------------------------------------------------------------------------
441cdf0e10cSrcweir 
implRegisterGalleryItem(::unogallery::GalleryItem & rItem)442cdf0e10cSrcweir void GalleryTheme::implRegisterGalleryItem( ::unogallery::GalleryItem& rItem )
443cdf0e10cSrcweir {
444cdf0e10cSrcweir 	const ::vos::OGuard aGuard( Application::GetSolarMutex() );
445cdf0e10cSrcweir 
446cdf0e10cSrcweir //	DBG_ASSERT( maItemList.find( &rItem ) == maItemList.end(), "Item already registered" );
447cdf0e10cSrcweir 	maItemList.push_back( &rItem );
448cdf0e10cSrcweir }
449cdf0e10cSrcweir 
450cdf0e10cSrcweir // ------------------------------------------------------------------------------
451cdf0e10cSrcweir 
implDeregisterGalleryItem(::unogallery::GalleryItem & rItem)452cdf0e10cSrcweir void GalleryTheme::implDeregisterGalleryItem( ::unogallery::GalleryItem& rItem )
453cdf0e10cSrcweir {
454cdf0e10cSrcweir 	const ::vos::OGuard aGuard( Application::GetSolarMutex() );
455cdf0e10cSrcweir 
456cdf0e10cSrcweir //	DBG_ASSERT( maItemList.find( &rItem ) != maItemList.end(), "Item is not registered" );
457cdf0e10cSrcweir 	maItemList.remove( &rItem );
458cdf0e10cSrcweir }
459cdf0e10cSrcweir 
460cdf0e10cSrcweir }
461