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