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