xref: /AOO41X/main/sd/source/core/stlfamily.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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_sd.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/lang/IllegalAccessException.hpp>
33*cdf0e10cSrcweir #include <comphelper/serviceinfohelper.hxx>
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include <vos/mutex.hxx>
36*cdf0e10cSrcweir #include <vcl/svapp.hxx>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir #include <svl/style.hxx>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #include <svx/unoprov.hxx>
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir #include "../ui/inc/strings.hrc"
43*cdf0e10cSrcweir #include "stlfamily.hxx"
44*cdf0e10cSrcweir #include "stlsheet.hxx"
45*cdf0e10cSrcweir #include "sdresid.hxx"
46*cdf0e10cSrcweir #include "drawdoc.hxx"
47*cdf0e10cSrcweir #include "sdpage.hxx"
48*cdf0e10cSrcweir #include "glob.hxx"
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir #include <map>
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir using ::rtl::OUString;
53*cdf0e10cSrcweir using namespace ::vos;
54*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
55*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
56*cdf0e10cSrcweir using namespace ::com::sun::star::container;
57*cdf0e10cSrcweir using namespace ::com::sun::star::style;
58*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir // ----------------------------------------------------------
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir typedef std::map< rtl::OUString, rtl::Reference< SdStyleSheet > > PresStyleMap;
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir struct SdStyleFamilyImpl
65*cdf0e10cSrcweir {
66*cdf0e10cSrcweir 	SdrPageWeakRef mxMasterPage;
67*cdf0e10cSrcweir     String maLayoutName;
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir     PresStyleMap& getStyleSheets();
70*cdf0e10cSrcweir     rtl::Reference< SfxStyleSheetPool > mxPool;
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir private:
73*cdf0e10cSrcweir     PresStyleMap maStyleSheets;
74*cdf0e10cSrcweir };
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir PresStyleMap& SdStyleFamilyImpl::getStyleSheets()
77*cdf0e10cSrcweir {
78*cdf0e10cSrcweir     if( mxMasterPage.is() && (mxMasterPage->GetLayoutName() != maLayoutName) )
79*cdf0e10cSrcweir     {
80*cdf0e10cSrcweir         maLayoutName = mxMasterPage->GetLayoutName();
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir         String aLayoutName( maLayoutName );
83*cdf0e10cSrcweir 	    const sal_uInt16 nLen = aLayoutName.Search(String( RTL_CONSTASCII_USTRINGPARAM(SD_LT_SEPARATOR)))+4;
84*cdf0e10cSrcweir 	    aLayoutName.Erase( nLen );
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir         if( (maStyleSheets.size() == 0) || !((*maStyleSheets.begin()).second->GetName().Equals( aLayoutName, 0, nLen )) )
87*cdf0e10cSrcweir         {
88*cdf0e10cSrcweir             maStyleSheets.clear();
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir     	    const SfxStyles& rStyles = mxPool->GetStyles();
91*cdf0e10cSrcweir 	        for( SfxStyles::const_iterator iter( rStyles.begin() ); iter != rStyles.end(); iter++ )
92*cdf0e10cSrcweir 	        {
93*cdf0e10cSrcweir 		        SdStyleSheet* pStyle = static_cast< SdStyleSheet* >( (*iter).get() );
94*cdf0e10cSrcweir 		        if( pStyle && (pStyle->GetFamily() == SD_STYLE_FAMILY_MASTERPAGE) && (pStyle->GetName().Equals( aLayoutName, 0, nLen )) )
95*cdf0e10cSrcweir 			        maStyleSheets[ pStyle->GetApiName() ] = rtl::Reference< SdStyleSheet >( pStyle );
96*cdf0e10cSrcweir             }
97*cdf0e10cSrcweir 	    }
98*cdf0e10cSrcweir     }
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir     return maStyleSheets;
101*cdf0e10cSrcweir }
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir // ----------------------------------------------------------
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir SdStyleFamily::SdStyleFamily( const rtl::Reference< SfxStyleSheetPool >& xPool, SfxStyleFamily nFamily )
106*cdf0e10cSrcweir : mnFamily( nFamily )
107*cdf0e10cSrcweir , mxPool( xPool )
108*cdf0e10cSrcweir , mpImpl( 0 )
109*cdf0e10cSrcweir {
110*cdf0e10cSrcweir }
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir // ----------------------------------------------------------
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir SdStyleFamily::SdStyleFamily( const rtl::Reference< SfxStyleSheetPool >& xPool, const SdPage* pMasterPage )
115*cdf0e10cSrcweir : mnFamily( SD_STYLE_FAMILY_MASTERPAGE )
116*cdf0e10cSrcweir , mxPool( xPool )
117*cdf0e10cSrcweir , mpImpl( new SdStyleFamilyImpl() )
118*cdf0e10cSrcweir {
119*cdf0e10cSrcweir 	mpImpl->mxMasterPage.reset( const_cast< SdPage* >( pMasterPage ) );
120*cdf0e10cSrcweir     mpImpl->mxPool = xPool;
121*cdf0e10cSrcweir }
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir // ----------------------------------------------------------
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir SdStyleFamily::~SdStyleFamily()
126*cdf0e10cSrcweir {
127*cdf0e10cSrcweir 	DBG_ASSERT( !mxPool.is(), "SdStyleFamily::~SdStyleFamily(), dispose me first!" );
128*cdf0e10cSrcweir 	delete mpImpl;
129*cdf0e10cSrcweir }
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir // ----------------------------------------------------------
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir void SdStyleFamily::throwIfDisposed() const throw(RuntimeException)
134*cdf0e10cSrcweir {
135*cdf0e10cSrcweir 	if( !mxPool.is() )
136*cdf0e10cSrcweir 		throw DisposedException();
137*cdf0e10cSrcweir }
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir // ----------------------------------------------------------
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir SdStyleSheet* SdStyleFamily::GetValidNewSheet( const Any& rElement ) throw(IllegalArgumentException)
142*cdf0e10cSrcweir {
143*cdf0e10cSrcweir 	Reference< XStyle > xStyle( rElement, UNO_QUERY );
144*cdf0e10cSrcweir 	SdStyleSheet* pStyle = static_cast< SdStyleSheet* >( xStyle.get() );
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir 	if( pStyle == 0 || (pStyle->GetFamily() != mnFamily) || (&pStyle->GetPool() != mxPool.get()) || (mxPool->Find( pStyle->GetName(), mnFamily) != 0) )
147*cdf0e10cSrcweir 		throw IllegalArgumentException();
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir 	return pStyle;
150*cdf0e10cSrcweir }
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir // ----------------------------------------------------------
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir SdStyleSheet* SdStyleFamily::GetSheetByName( const OUString& rName ) throw(NoSuchElementException, WrappedTargetException )
155*cdf0e10cSrcweir {
156*cdf0e10cSrcweir     SdStyleSheet* pRet = 0;
157*cdf0e10cSrcweir 	if( rName.getLength() )
158*cdf0e10cSrcweir 	{
159*cdf0e10cSrcweir 		if( mnFamily == SD_STYLE_FAMILY_MASTERPAGE )
160*cdf0e10cSrcweir 		{
161*cdf0e10cSrcweir             PresStyleMap& rStyleMap = mpImpl->getStyleSheets();
162*cdf0e10cSrcweir 			PresStyleMap::iterator iter( rStyleMap.find(rName) );
163*cdf0e10cSrcweir 			if( iter != rStyleMap.end() )
164*cdf0e10cSrcweir     			pRet = (*iter).second.get();
165*cdf0e10cSrcweir 		}
166*cdf0e10cSrcweir 		else
167*cdf0e10cSrcweir 		{
168*cdf0e10cSrcweir 			const SfxStyles& rStyles = mxPool->GetStyles();
169*cdf0e10cSrcweir 			for( SfxStyles::const_iterator iter( rStyles.begin() ); iter != rStyles.end(); iter++ )
170*cdf0e10cSrcweir 			{
171*cdf0e10cSrcweir 				SdStyleSheet* pStyle = static_cast< SdStyleSheet* >( (*iter).get() );
172*cdf0e10cSrcweir 				if( pStyle && (pStyle->GetFamily() == mnFamily) && (pStyle->GetApiName() == rName) )
173*cdf0e10cSrcweir                 {
174*cdf0e10cSrcweir 					pRet = pStyle;
175*cdf0e10cSrcweir                     break;
176*cdf0e10cSrcweir                 }
177*cdf0e10cSrcweir 			}
178*cdf0e10cSrcweir 		}
179*cdf0e10cSrcweir 	}
180*cdf0e10cSrcweir     if( pRet )
181*cdf0e10cSrcweir         return pRet;
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir     throw NoSuchElementException();
184*cdf0e10cSrcweir }
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir // ----------------------------------------------------------
187*cdf0e10cSrcweir // XServiceInfo
188*cdf0e10cSrcweir // ----------------------------------------------------------
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir OUString SAL_CALL SdStyleFamily::getImplementationName() throw(RuntimeException)
191*cdf0e10cSrcweir {
192*cdf0e10cSrcweir 	return OUString( RTL_CONSTASCII_USTRINGPARAM("SdStyleFamily") );
193*cdf0e10cSrcweir }
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir // ----------------------------------------------------------
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir sal_Bool SAL_CALL SdStyleFamily::supportsService( const OUString& ServiceName ) throw(RuntimeException)
198*cdf0e10cSrcweir {
199*cdf0e10cSrcweir 	return comphelper::ServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() );
200*cdf0e10cSrcweir }
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir // ----------------------------------------------------------
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir Sequence< OUString > SAL_CALL SdStyleFamily::getSupportedServiceNames() throw(RuntimeException)
205*cdf0e10cSrcweir {
206*cdf0e10cSrcweir 	OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.style.StyleFamily") );
207*cdf0e10cSrcweir 	Sequence< OUString > aSeq( &aServiceName, 1 );
208*cdf0e10cSrcweir 	return aSeq;
209*cdf0e10cSrcweir }
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir // ----------------------------------------------------------
212*cdf0e10cSrcweir // XNamed
213*cdf0e10cSrcweir // ----------------------------------------------------------
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir OUString SAL_CALL SdStyleFamily::getName() throw (RuntimeException)
216*cdf0e10cSrcweir {
217*cdf0e10cSrcweir 	if( mnFamily == SD_STYLE_FAMILY_MASTERPAGE )
218*cdf0e10cSrcweir 	{
219*cdf0e10cSrcweir 		SdPage* pPage = static_cast< SdPage* >( mpImpl->mxMasterPage.get() );
220*cdf0e10cSrcweir 		if( pPage == 0 )
221*cdf0e10cSrcweir 			throw DisposedException();
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir 		String aLayoutName( pPage->GetLayoutName() );
224*cdf0e10cSrcweir 		const String aSep( RTL_CONSTASCII_USTRINGPARAM( SD_LT_SEPARATOR ));
225*cdf0e10cSrcweir 		aLayoutName.Erase(aLayoutName.Search(aSep));
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir 		return OUString( aLayoutName );
228*cdf0e10cSrcweir 	}
229*cdf0e10cSrcweir 	else
230*cdf0e10cSrcweir 	{
231*cdf0e10cSrcweir 		return SdStyleSheet::GetFamilyString( mnFamily );
232*cdf0e10cSrcweir 	}
233*cdf0e10cSrcweir }
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir // ----------------------------------------------------------
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir void SAL_CALL SdStyleFamily::setName( const ::rtl::OUString& ) throw (RuntimeException)
238*cdf0e10cSrcweir {
239*cdf0e10cSrcweir }
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir // ----------------------------------------------------------
242*cdf0e10cSrcweir // XNameAccess
243*cdf0e10cSrcweir // ----------------------------------------------------------
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir Any SAL_CALL SdStyleFamily::getByName( const OUString& rName ) throw(NoSuchElementException, WrappedTargetException, RuntimeException)
246*cdf0e10cSrcweir {
247*cdf0e10cSrcweir 	OGuard aGuard( Application::GetSolarMutex() );
248*cdf0e10cSrcweir 	throwIfDisposed();
249*cdf0e10cSrcweir 	return Any( Reference< XStyle >( static_cast<SfxUnoStyleSheet*>(GetSheetByName( rName )) ) );
250*cdf0e10cSrcweir }
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir // ----------------------------------------------------------
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir Sequence< OUString > SAL_CALL SdStyleFamily::getElementNames() throw(RuntimeException)
255*cdf0e10cSrcweir {
256*cdf0e10cSrcweir 	OGuard aGuard( Application::GetSolarMutex() );
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir 	throwIfDisposed();
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir 	if( mnFamily == SD_STYLE_FAMILY_MASTERPAGE )
261*cdf0e10cSrcweir 	{
262*cdf0e10cSrcweir         PresStyleMap& rStyleMap = mpImpl->getStyleSheets();
263*cdf0e10cSrcweir 		Sequence< OUString > aNames( rStyleMap.size() );
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir 		PresStyleMap::iterator iter( rStyleMap.begin() );
266*cdf0e10cSrcweir 		OUString* pNames = aNames.getArray();
267*cdf0e10cSrcweir 		while( iter != rStyleMap.end() )
268*cdf0e10cSrcweir 		{
269*cdf0e10cSrcweir 			const OUString sName( (*iter).first );
270*cdf0e10cSrcweir 			rtl::Reference< SdStyleSheet > xStyle( (*iter++).second );
271*cdf0e10cSrcweir 			if( xStyle.is() )
272*cdf0e10cSrcweir 			{
273*cdf0e10cSrcweir 				*pNames++ = xStyle->GetApiName();
274*cdf0e10cSrcweir 			}
275*cdf0e10cSrcweir 			else
276*cdf0e10cSrcweir 			{
277*cdf0e10cSrcweir 				int i = 0;
278*cdf0e10cSrcweir 				i++;
279*cdf0e10cSrcweir 			}
280*cdf0e10cSrcweir 		}
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir //				*pNames++ = (*iter++).second->GetApiName();
283*cdf0e10cSrcweir 		return aNames;
284*cdf0e10cSrcweir 	}
285*cdf0e10cSrcweir 	else
286*cdf0e10cSrcweir 	{
287*cdf0e10cSrcweir 		std::vector< OUString > aNames;
288*cdf0e10cSrcweir 		const SfxStyles& rStyles = mxPool->GetStyles();
289*cdf0e10cSrcweir 		for( SfxStyles::const_iterator iter( rStyles.begin() ); iter != rStyles.end(); iter++ )
290*cdf0e10cSrcweir 		{
291*cdf0e10cSrcweir 			SdStyleSheet* pStyle = static_cast< SdStyleSheet* >( (*iter).get() );
292*cdf0e10cSrcweir 			if( pStyle && (pStyle->GetFamily() == mnFamily) )
293*cdf0e10cSrcweir 				aNames.push_back( pStyle->GetApiName() );
294*cdf0e10cSrcweir 		}
295*cdf0e10cSrcweir 		return Sequence< OUString >( &(*aNames.begin()), aNames.size() );
296*cdf0e10cSrcweir 	}
297*cdf0e10cSrcweir }
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir // ----------------------------------------------------------
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir sal_Bool SAL_CALL SdStyleFamily::hasByName( const OUString& aName )	throw(RuntimeException)
302*cdf0e10cSrcweir {
303*cdf0e10cSrcweir 	OGuard aGuard( Application::GetSolarMutex() );
304*cdf0e10cSrcweir 	throwIfDisposed();
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir 	if( aName.getLength() )
307*cdf0e10cSrcweir 	{
308*cdf0e10cSrcweir 		if( mnFamily == SD_STYLE_FAMILY_MASTERPAGE )
309*cdf0e10cSrcweir 		{
310*cdf0e10cSrcweir             PresStyleMap& rStyleSheets = mpImpl->getStyleSheets();
311*cdf0e10cSrcweir 			PresStyleMap::iterator iter( rStyleSheets.find(aName) );
312*cdf0e10cSrcweir 			return ( iter != rStyleSheets.end() ) ? sal_True : sal_False;
313*cdf0e10cSrcweir 		}
314*cdf0e10cSrcweir 		else
315*cdf0e10cSrcweir 		{
316*cdf0e10cSrcweir 			const SfxStyles& rStyles = mxPool->GetStyles();
317*cdf0e10cSrcweir 			for( SfxStyles::const_iterator iter( rStyles.begin() ); iter != rStyles.end(); iter++ )
318*cdf0e10cSrcweir 			{
319*cdf0e10cSrcweir 				SdStyleSheet* pStyle = static_cast< SdStyleSheet* >( (*iter).get() );
320*cdf0e10cSrcweir 				if( pStyle && (pStyle->GetFamily() == mnFamily) && ( pStyle->GetApiName() == aName ) )
321*cdf0e10cSrcweir 					return sal_True;
322*cdf0e10cSrcweir 			}
323*cdf0e10cSrcweir 		}
324*cdf0e10cSrcweir 	}
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir 	return sal_False;
327*cdf0e10cSrcweir }
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir // ----------------------------------------------------------
330*cdf0e10cSrcweir // XElementAccess
331*cdf0e10cSrcweir // ----------------------------------------------------------
332*cdf0e10cSrcweir 
333*cdf0e10cSrcweir Type SAL_CALL SdStyleFamily::getElementType() throw(RuntimeException)
334*cdf0e10cSrcweir {
335*cdf0e10cSrcweir 	return XStyle::static_type();
336*cdf0e10cSrcweir }
337*cdf0e10cSrcweir 
338*cdf0e10cSrcweir // ----------------------------------------------------------
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir sal_Bool SAL_CALL SdStyleFamily::hasElements() throw(RuntimeException)
341*cdf0e10cSrcweir {
342*cdf0e10cSrcweir 	OGuard aGuard( Application::GetSolarMutex() );
343*cdf0e10cSrcweir 	throwIfDisposed();
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir 	if( mnFamily == SD_STYLE_FAMILY_MASTERPAGE )
346*cdf0e10cSrcweir 	{
347*cdf0e10cSrcweir 		return sal_True;
348*cdf0e10cSrcweir 	}
349*cdf0e10cSrcweir 	else
350*cdf0e10cSrcweir 	{
351*cdf0e10cSrcweir 		const SfxStyles& rStyles = mxPool->GetStyles();
352*cdf0e10cSrcweir 		for( SfxStyles::const_iterator iter( rStyles.begin() ); iter != rStyles.end(); iter++ )
353*cdf0e10cSrcweir 		{
354*cdf0e10cSrcweir 			SdStyleSheet* pStyle = static_cast< SdStyleSheet* >( (*iter).get() );
355*cdf0e10cSrcweir 			if( pStyle && (pStyle->GetFamily() == mnFamily) )
356*cdf0e10cSrcweir 				return sal_True;
357*cdf0e10cSrcweir 		}
358*cdf0e10cSrcweir 	}
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir 	return sal_False;
361*cdf0e10cSrcweir }
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir // ----------------------------------------------------------
364*cdf0e10cSrcweir // XIndexAccess
365*cdf0e10cSrcweir // ----------------------------------------------------------
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir sal_Int32 SAL_CALL SdStyleFamily::getCount() throw(RuntimeException)
368*cdf0e10cSrcweir {
369*cdf0e10cSrcweir 	OGuard aGuard( Application::GetSolarMutex() );
370*cdf0e10cSrcweir 	throwIfDisposed();
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir 	sal_Int32 nCount = 0;
373*cdf0e10cSrcweir 	if( mnFamily == SD_STYLE_FAMILY_MASTERPAGE )
374*cdf0e10cSrcweir 	{
375*cdf0e10cSrcweir 		return mpImpl->getStyleSheets().size();
376*cdf0e10cSrcweir 	}
377*cdf0e10cSrcweir 	else
378*cdf0e10cSrcweir 	{
379*cdf0e10cSrcweir 		const SfxStyles& rStyles = mxPool->GetStyles();
380*cdf0e10cSrcweir 		for( SfxStyles::const_iterator iter( rStyles.begin() ); iter != rStyles.end(); iter++ )
381*cdf0e10cSrcweir 		{
382*cdf0e10cSrcweir 			SdStyleSheet* pStyle = static_cast< SdStyleSheet* >( (*iter).get() );
383*cdf0e10cSrcweir 			if( pStyle && (pStyle->GetFamily() == mnFamily) )
384*cdf0e10cSrcweir 				nCount++;
385*cdf0e10cSrcweir 		}
386*cdf0e10cSrcweir 	}
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir 	return nCount;
389*cdf0e10cSrcweir }
390*cdf0e10cSrcweir 
391*cdf0e10cSrcweir // ----------------------------------------------------------
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir Any SAL_CALL SdStyleFamily::getByIndex( sal_Int32 Index ) throw(IndexOutOfBoundsException, WrappedTargetException, RuntimeException)
394*cdf0e10cSrcweir {
395*cdf0e10cSrcweir 	OGuard aGuard( Application::GetSolarMutex() );
396*cdf0e10cSrcweir 	throwIfDisposed();
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir 	if( Index >= 0 )
399*cdf0e10cSrcweir 	{
400*cdf0e10cSrcweir 		if( mnFamily == SD_STYLE_FAMILY_MASTERPAGE )
401*cdf0e10cSrcweir 		{
402*cdf0e10cSrcweir             PresStyleMap& rStyleSheets = mpImpl->getStyleSheets();
403*cdf0e10cSrcweir 			if( !rStyleSheets.empty() )
404*cdf0e10cSrcweir 			{
405*cdf0e10cSrcweir 				PresStyleMap::iterator iter( rStyleSheets.begin() );
406*cdf0e10cSrcweir 				while( Index-- && (iter != rStyleSheets.end()) )
407*cdf0e10cSrcweir 					iter++;
408*cdf0e10cSrcweir 
409*cdf0e10cSrcweir 				if( (Index==-1) && (iter != rStyleSheets.end()) )
410*cdf0e10cSrcweir 					return Any( Reference< XStyle >( (*iter).second.get() ) );
411*cdf0e10cSrcweir 			}
412*cdf0e10cSrcweir 		}
413*cdf0e10cSrcweir 		else
414*cdf0e10cSrcweir 		{
415*cdf0e10cSrcweir 			const SfxStyles& rStyles = mxPool->GetStyles();
416*cdf0e10cSrcweir 			for( SfxStyles::const_iterator iter( rStyles.begin() ); iter != rStyles.end(); iter++ )
417*cdf0e10cSrcweir 			{
418*cdf0e10cSrcweir 				SdStyleSheet* pStyle = static_cast< SdStyleSheet* >( (*iter).get() );
419*cdf0e10cSrcweir 				if( pStyle && (pStyle->GetFamily() == mnFamily) )
420*cdf0e10cSrcweir 				{
421*cdf0e10cSrcweir 					if( Index-- == 0 )
422*cdf0e10cSrcweir 						return Any( Reference< XStyle >( pStyle ) );
423*cdf0e10cSrcweir 				}
424*cdf0e10cSrcweir 			}
425*cdf0e10cSrcweir 		}
426*cdf0e10cSrcweir 	}
427*cdf0e10cSrcweir 
428*cdf0e10cSrcweir 	throw IndexOutOfBoundsException();
429*cdf0e10cSrcweir }
430*cdf0e10cSrcweir 
431*cdf0e10cSrcweir // ----------------------------------------------------------
432*cdf0e10cSrcweir // XNameContainer
433*cdf0e10cSrcweir // ----------------------------------------------------------
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir void SAL_CALL SdStyleFamily::insertByName( const OUString& rName, const Any& rElement ) throw(IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException)
436*cdf0e10cSrcweir {
437*cdf0e10cSrcweir 	OGuard aGuard( Application::GetSolarMutex() );
438*cdf0e10cSrcweir 	throwIfDisposed();
439*cdf0e10cSrcweir 
440*cdf0e10cSrcweir 	if(rName.getLength() == 0)
441*cdf0e10cSrcweir 		throw IllegalArgumentException();
442*cdf0e10cSrcweir 
443*cdf0e10cSrcweir 	SdStyleSheet* pStyle = GetValidNewSheet( rElement );
444*cdf0e10cSrcweir 	if( !pStyle->SetName( rName ) )
445*cdf0e10cSrcweir 		throw ElementExistException();
446*cdf0e10cSrcweir 
447*cdf0e10cSrcweir 	pStyle->SetApiName( rName );
448*cdf0e10cSrcweir 	mxPool->Insert( pStyle );
449*cdf0e10cSrcweir }
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir // ----------------------------------------------------------
452*cdf0e10cSrcweir 
453*cdf0e10cSrcweir void SAL_CALL SdStyleFamily::removeByName( const OUString& rName ) throw(NoSuchElementException, WrappedTargetException, RuntimeException)
454*cdf0e10cSrcweir {
455*cdf0e10cSrcweir 	OGuard aGuard( Application::GetSolarMutex() );
456*cdf0e10cSrcweir 	throwIfDisposed();
457*cdf0e10cSrcweir 
458*cdf0e10cSrcweir 	SdStyleSheet* pStyle = GetSheetByName( rName );
459*cdf0e10cSrcweir 
460*cdf0e10cSrcweir 	if( !pStyle->IsUserDefined() )
461*cdf0e10cSrcweir 		throw WrappedTargetException();
462*cdf0e10cSrcweir 
463*cdf0e10cSrcweir 	mxPool->Remove( pStyle );
464*cdf0e10cSrcweir }
465*cdf0e10cSrcweir 
466*cdf0e10cSrcweir // ----------------------------------------------------------
467*cdf0e10cSrcweir // XNameReplace
468*cdf0e10cSrcweir // ----------------------------------------------------------
469*cdf0e10cSrcweir 
470*cdf0e10cSrcweir void SAL_CALL SdStyleFamily::replaceByName( const OUString& rName, const Any& aElement ) throw(IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException)
471*cdf0e10cSrcweir {
472*cdf0e10cSrcweir 	OGuard aGuard( Application::GetSolarMutex() );
473*cdf0e10cSrcweir 	throwIfDisposed();
474*cdf0e10cSrcweir 
475*cdf0e10cSrcweir 	SdStyleSheet* pOldStyle = GetSheetByName( rName );
476*cdf0e10cSrcweir 	SdStyleSheet* pNewStyle = GetValidNewSheet( aElement );
477*cdf0e10cSrcweir 
478*cdf0e10cSrcweir 	mxPool->Remove( pOldStyle );
479*cdf0e10cSrcweir 	mxPool->Insert( pNewStyle );
480*cdf0e10cSrcweir }
481*cdf0e10cSrcweir 
482*cdf0e10cSrcweir // ----------------------------------------------------------
483*cdf0e10cSrcweir // XSingleServiceFactory
484*cdf0e10cSrcweir // ----------------------------------------------------------
485*cdf0e10cSrcweir 
486*cdf0e10cSrcweir Reference< XInterface > SAL_CALL SdStyleFamily::createInstance() throw(Exception, RuntimeException)
487*cdf0e10cSrcweir {
488*cdf0e10cSrcweir 	OGuard aGuard( Application::GetSolarMutex() );
489*cdf0e10cSrcweir 	throwIfDisposed();
490*cdf0e10cSrcweir 
491*cdf0e10cSrcweir 	if( mnFamily == SD_STYLE_FAMILY_MASTERPAGE )
492*cdf0e10cSrcweir 	{
493*cdf0e10cSrcweir 		throw IllegalAccessException();
494*cdf0e10cSrcweir 	}
495*cdf0e10cSrcweir 	else
496*cdf0e10cSrcweir 	{
497*cdf0e10cSrcweir 		return Reference< XInterface >( static_cast< XStyle* >( SdStyleSheet::CreateEmptyUserStyle( *mxPool.get(), mnFamily ) ) );
498*cdf0e10cSrcweir 	}
499*cdf0e10cSrcweir }
500*cdf0e10cSrcweir 
501*cdf0e10cSrcweir // ----------------------------------------------------------
502*cdf0e10cSrcweir 
503*cdf0e10cSrcweir Reference< XInterface > SAL_CALL SdStyleFamily::createInstanceWithArguments( const Sequence< Any >&  ) throw(Exception, RuntimeException)
504*cdf0e10cSrcweir {
505*cdf0e10cSrcweir 	return createInstance();
506*cdf0e10cSrcweir }
507*cdf0e10cSrcweir 
508*cdf0e10cSrcweir // ----------------------------------------------------------
509*cdf0e10cSrcweir // XComponent
510*cdf0e10cSrcweir // ----------------------------------------------------------
511*cdf0e10cSrcweir 
512*cdf0e10cSrcweir void SAL_CALL SdStyleFamily::dispose(  ) throw (RuntimeException)
513*cdf0e10cSrcweir {
514*cdf0e10cSrcweir 	if( mxPool.is() )
515*cdf0e10cSrcweir 		mxPool.clear();
516*cdf0e10cSrcweir 
517*cdf0e10cSrcweir 	if( mpImpl )
518*cdf0e10cSrcweir 	{
519*cdf0e10cSrcweir 		delete mpImpl;
520*cdf0e10cSrcweir 		mpImpl = 0;
521*cdf0e10cSrcweir 	}
522*cdf0e10cSrcweir }
523*cdf0e10cSrcweir 
524*cdf0e10cSrcweir // ----------------------------------------------------------
525*cdf0e10cSrcweir 
526*cdf0e10cSrcweir void SAL_CALL SdStyleFamily::addEventListener( const Reference< XEventListener >&  ) throw (RuntimeException)
527*cdf0e10cSrcweir {
528*cdf0e10cSrcweir }
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir // ----------------------------------------------------------
531*cdf0e10cSrcweir 
532*cdf0e10cSrcweir void SAL_CALL SdStyleFamily::removeEventListener( const Reference< XEventListener >&  ) throw (RuntimeException)
533*cdf0e10cSrcweir {
534*cdf0e10cSrcweir }
535*cdf0e10cSrcweir 
536*cdf0e10cSrcweir // ----------------------------------------------------------
537*cdf0e10cSrcweir // XPropertySet
538*cdf0e10cSrcweir // ----------------------------------------------------------
539*cdf0e10cSrcweir 
540*cdf0e10cSrcweir Reference<XPropertySetInfo> SdStyleFamily::getPropertySetInfo() throw (RuntimeException)
541*cdf0e10cSrcweir {
542*cdf0e10cSrcweir     OSL_ENSURE( 0, "###unexpected!" );
543*cdf0e10cSrcweir     return Reference<XPropertySetInfo>();
544*cdf0e10cSrcweir }
545*cdf0e10cSrcweir 
546*cdf0e10cSrcweir // ----------------------------------------------------------
547*cdf0e10cSrcweir 
548*cdf0e10cSrcweir void SdStyleFamily::setPropertyValue( const OUString& , const Any&  ) throw (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
549*cdf0e10cSrcweir {
550*cdf0e10cSrcweir     OSL_ENSURE( 0, "###unexpected!" );
551*cdf0e10cSrcweir }
552*cdf0e10cSrcweir 
553*cdf0e10cSrcweir // ----------------------------------------------------------
554*cdf0e10cSrcweir 
555*cdf0e10cSrcweir Any SdStyleFamily::getPropertyValue( const OUString& PropertyName ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
556*cdf0e10cSrcweir {
557*cdf0e10cSrcweir     if (PropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("DisplayName") ))
558*cdf0e10cSrcweir 	{
559*cdf0e10cSrcweir         OGuard aGuard( Application::GetSolarMutex() );
560*cdf0e10cSrcweir 		OUString sDisplayName;
561*cdf0e10cSrcweir 		switch( mnFamily )
562*cdf0e10cSrcweir 		{
563*cdf0e10cSrcweir 			case SD_STYLE_FAMILY_MASTERPAGE:	sDisplayName = getName(); break;
564*cdf0e10cSrcweir 			case SD_STYLE_FAMILY_CELL:			sDisplayName = String( SdResId(STR_CELL_STYLE_FAMILY) ); break;
565*cdf0e10cSrcweir //			case SD_STYLE_FAMILY_GRAPHICS:
566*cdf0e10cSrcweir 			default:							sDisplayName = String( SdResId(STR_GRAPHICS_STYLE_FAMILY) ); break;
567*cdf0e10cSrcweir 		}
568*cdf0e10cSrcweir 		return Any( sDisplayName );
569*cdf0e10cSrcweir     }
570*cdf0e10cSrcweir     else
571*cdf0e10cSrcweir 	{
572*cdf0e10cSrcweir         throw UnknownPropertyException( OUString( RTL_CONSTASCII_USTRINGPARAM("unknown property: ") ) + PropertyName, static_cast<OWeakObject *>(this) );
573*cdf0e10cSrcweir 	}
574*cdf0e10cSrcweir }
575*cdf0e10cSrcweir 
576*cdf0e10cSrcweir // ----------------------------------------------------------
577*cdf0e10cSrcweir 
578*cdf0e10cSrcweir void SdStyleFamily::addPropertyChangeListener( const OUString& , const Reference<XPropertyChangeListener>&  ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
579*cdf0e10cSrcweir {
580*cdf0e10cSrcweir     OSL_ENSURE( 0, "###unexpected!" );
581*cdf0e10cSrcweir }
582*cdf0e10cSrcweir 
583*cdf0e10cSrcweir // ----------------------------------------------------------
584*cdf0e10cSrcweir 
585*cdf0e10cSrcweir void SdStyleFamily::removePropertyChangeListener( const OUString& , const Reference<XPropertyChangeListener>&  ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
586*cdf0e10cSrcweir {
587*cdf0e10cSrcweir     OSL_ENSURE( 0, "###unexpected!" );
588*cdf0e10cSrcweir }
589*cdf0e10cSrcweir 
590*cdf0e10cSrcweir // ----------------------------------------------------------
591*cdf0e10cSrcweir 
592*cdf0e10cSrcweir void SdStyleFamily::addVetoableChangeListener( const OUString& , const Reference<XVetoableChangeListener>& ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
593*cdf0e10cSrcweir {
594*cdf0e10cSrcweir     OSL_ENSURE( 0, "###unexpected!" );
595*cdf0e10cSrcweir }
596*cdf0e10cSrcweir 
597*cdf0e10cSrcweir // ----------------------------------------------------------
598*cdf0e10cSrcweir 
599*cdf0e10cSrcweir void SdStyleFamily::removeVetoableChangeListener( const OUString& , const Reference<XVetoableChangeListener>&  ) throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
600*cdf0e10cSrcweir {
601*cdf0e10cSrcweir     OSL_ENSURE( 0, "###unexpected!" );
602*cdf0e10cSrcweir }
603*cdf0e10cSrcweir 
604